On Fri, Jun 06, 2025 at 09:26:30PM -0400, Brian Gerst wrote:
> On Fri, Jun 6, 2025 at 3:48 AM Josh Poimboeuf <[email protected]> wrote:
> >
> > On Thu, Jun 05, 2025 at 11:58:23PM -0400, Brian Gerst wrote:
> > > On Fri, May 9, 2025 at 4:51 PM Josh Poimboeuf <[email protected]> wrote:
> > > >
> > > > In preparation for the objtool klp diff subcommand, define the entry
> > > > size for the __ex_table section in its ELF header.  This will allow
> > > > tooling to extract individual entries.
> > > >
> > > > Signed-off-by: Josh Poimboeuf <[email protected]>
> > > > ---
> > > >  arch/x86/include/asm/asm.h | 20 ++++++++++++--------
> > > >  kernel/extable.c           |  2 ++
> > > >  2 files changed, 14 insertions(+), 8 deletions(-)
> > > >
> > > > diff --git a/arch/x86/include/asm/asm.h b/arch/x86/include/asm/asm.h
> > > > index f963848024a5..62dff336f206 100644
> > > > --- a/arch/x86/include/asm/asm.h
> > > > +++ b/arch/x86/include/asm/asm.h
> > > > @@ -138,15 +138,17 @@ static __always_inline __pure void 
> > > > *rip_rel_ptr(void *p)
> > > >
> > > >  # include <asm/extable_fixup_types.h>
> > > >
> > > > +#define EXTABLE_SIZE 12
> > >
> > > Put this in asm-offsets.c instead.
> >
> > But that's only for .S code right?  This is also needed for inline asm.
> 
> <asm/asm-offsets.h> can be used in C code too.  Normally it wouldn't
> be needed but the inline asm case is a valid use.

Ah, nice.  This is much better.  Thanks!

diff --git a/arch/x86/include/asm/alternative.h 
b/arch/x86/include/asm/alternative.h
index e206e0f96568..eb24d9ba30d7 100644
--- a/arch/x86/include/asm/alternative.h
+++ b/arch/x86/include/asm/alternative.h
@@ -16,8 +16,6 @@
 #define ALT_DIRECT_CALL(feature) ((ALT_FLAG_DIRECT_CALL << ALT_FLAGS_SHIFT) | 
(feature))
 #define ALT_CALL_ALWAYS                ALT_DIRECT_CALL(X86_FEATURE_ALWAYS)
 
-#define ALTINSTR_SIZE          14
-
 #ifndef __ASSEMBLER__
 
 #include <linux/stddef.h>
@@ -200,7 +198,7 @@ static inline int alternatives_text_reserved(void *start, 
void *end)
 
 #define ALTINSTR_ENTRY(ft_flags)                                             \
        ".pushsection .altinstructions, \"aM\", @progbits, "                  \
-                     __stringify(ALTINSTR_SIZE) "\n"                         \
+                     __stringify(ALT_INSTR_SIZE) "\n"                        \
        " .long 771b - .\n"                             /* label           */ \
        " .long 774f - .\n"                             /* new instruction */ \
        " .4byte " __stringify(ft_flags) "\n"           /* feature + flags */ \
@@ -363,7 +361,7 @@ void nop_func(void);
 741:                                                                   \
        .skip -(((744f-743f)-(741b-740b)) > 0) * ((744f-743f)-(741b-740b)),0x90 
;\
 742:                                                                   \
-       .pushsection .altinstructions, "aM", @progbits, ALTINSTR_SIZE ; \
+       .pushsection .altinstructions, "aM", @progbits, ALT_INSTR_SIZE ;\
        altinstr_entry 740b,743f,flag,742b-740b,744f-743f ;             \
        .popsection ;                                                   \
        .pushsection .altinstr_replacement,"ax" ;                       \
diff --git a/arch/x86/include/asm/asm.h b/arch/x86/include/asm/asm.h
index 62dff336f206..eb0b33f02be3 100644
--- a/arch/x86/include/asm/asm.h
+++ b/arch/x86/include/asm/asm.h
@@ -138,7 +138,9 @@ static __always_inline __pure void *rip_rel_ptr(void *p)
 
 # include <asm/extable_fixup_types.h>
 
-#define EXTABLE_SIZE 12
+#ifndef COMPILE_OFFSETS
+#include <asm/asm-offsets.h>
+#endif
 
 /* Exception table entry */
 #ifdef __ASSEMBLER__
diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index d01ab5fa631f..4888e1c8be6a 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -593,8 +593,6 @@ void __init_or_module noinline apply_alternatives(struct 
alt_instr *start,
        u8 *instr, *replacement;
        struct alt_instr *a, *b;
 
-       BUILD_BUG_ON(ALTINSTR_SIZE != sizeof(struct alt_instr));
-
        DPRINTK(ALT, "alt table %px, -> %px", start, end);
 
        /*
diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
index 6259b474073b..805da27854ee 100644
--- a/arch/x86/kernel/asm-offsets.c
+++ b/arch/x86/kernel/asm-offsets.c
@@ -123,4 +123,8 @@ static void __used common(void)
        OFFSET(ARIA_CTX_rounds, aria_ctx, rounds);
 #endif
 
+       BLANK();
+       DEFINE(EXTABLE_SIZE,     sizeof(struct exception_table_entry));
+       DEFINE(UNWIND_HINT_SIZE, sizeof(struct unwind_hint));
+       DEFINE(ALT_INSTR_SIZE,   sizeof(struct alt_instr));
 }
diff --git a/arch/x86/kernel/unwind_orc.c b/arch/x86/kernel/unwind_orc.c
index 4624d6d916a2..977ee75e047c 100644
--- a/arch/x86/kernel/unwind_orc.c
+++ b/arch/x86/kernel/unwind_orc.c
@@ -199,8 +199,6 @@ static struct orc_entry *orc_find(unsigned long ip)
 {
        static struct orc_entry *orc;
 
-       BUILD_BUG_ON(UNWIND_HINT_SIZE != sizeof(struct unwind_hint));
-
        if (ip == 0)
                return &null_orc_entry;
 
diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
index d4aae98b3739..bf8dab18be97 100644
--- a/arch/x86/mm/extable.c
+++ b/arch/x86/mm/extable.c
@@ -303,8 +303,6 @@ int fixup_exception(struct pt_regs *regs, int trapnr, 
unsigned long error_code,
        const struct exception_table_entry *e;
        int type, reg, imm;
 
-       BUILD_BUG_ON(EXTABLE_SIZE != sizeof(struct exception_table_entry));
-
 #ifdef CONFIG_PNPBIOS
        if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
                extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
diff --git a/include/linux/objtool.h b/include/linux/objtool.h
index d4137a46ee70..e93f0c28b54b 100644
--- a/include/linux/objtool.h
+++ b/include/linux/objtool.h
@@ -8,8 +8,6 @@
 
 #include <asm/asm.h>
 
-#define UNWIND_HINT_SIZE 12
-
 #ifndef __ASSEMBLY__
 
 #define UNWIND_HINT(type, sp_reg, sp_offset, signal)           \
diff --git a/kernel/bounds.c b/kernel/bounds.c
index 29b2cd00df2c..02b619eb6106 100644
--- a/kernel/bounds.c
+++ b/kernel/bounds.c
@@ -6,6 +6,7 @@
  */
 
 #define __GENERATING_BOUNDS_H
+#define COMPILE_OFFSETS
 /* Include headers that define the enum constants of interest */
 #include <linux/page-flags.h>
 #include <linux/mmzone.h>
diff --git a/scripts/mod/devicetable-offsets.c 
b/scripts/mod/devicetable-offsets.c
index d3d00e85edf7..ef2ffb68f69d 100644
--- a/scripts/mod/devicetable-offsets.c
+++ b/scripts/mod/devicetable-offsets.c
@@ -1,4 +1,5 @@
 // SPDX-License-Identifier: GPL-2.0
+#define COMPILE_OFFSETS
 #include <linux/kbuild.h>
 #include <linux/mod_devicetable.h>
 


Reply via email to