On Wed, Jun 12, 2024 at 8:32 AM Maxwell Bland <mbland@xxxxxxxxxxxx> wrote: > > Corrects Puranjay Mohan's commit to adopt Mark Rutland's > suggestion of using a C CFI type macro in kCFI+BPF. > > Signed-off-by: Maxwell Bland <mbland@xxxxxxxxxxxx> > --- > arch/arm64/kernel/alternative.c | 46 ++++----------------------------- > 1 file changed, 5 insertions(+), 41 deletions(-) > > diff --git a/arch/arm64/kernel/alternative.c b/arch/arm64/kernel/alternative.c > index 1715da7df137..d7a58eca7665 100644 > --- a/arch/arm64/kernel/alternative.c > +++ b/arch/arm64/kernel/alternative.c > @@ -8,6 +8,7 @@ > > #define pr_fmt(fmt) "alternatives: " fmt > > +#include <linux/cfi_types.h> > #include <linux/init.h> > #include <linux/cpu.h> > #include <linux/elf.h> > @@ -302,53 +303,16 @@ EXPORT_SYMBOL(alt_cb_patch_nops); > > #ifdef CONFIG_CFI_CLANG > struct bpf_insn; > - > /* Must match bpf_func_t / DEFINE_BPF_PROG_RUN() */ > extern unsigned int __bpf_prog_runX(const void *ctx, > const struct bpf_insn *insn); > - > -/* > - * Force a reference to the external symbol so the compiler generates > - * __kcfi_typid. > - */ > -__ADDRESSABLE(__bpf_prog_runX); > - > -/* u32 __ro_after_init cfi_bpf_hash = __kcfi_typeid___bpf_prog_runX; */ > -asm ( > -" .pushsection .data..ro_after_init,\"aw\",@progbits \n" > -" .type cfi_bpf_hash,@object \n" > -" .globl cfi_bpf_hash \n" > -" .p2align 2, 0x0 \n" > -"cfi_bpf_hash: \n" > -" .word __kcfi_typeid___bpf_prog_runX \n" > -" .size cfi_bpf_hash, 4 \n" > -" .popsection \n" > -); > - > +DEFINE_CFI_TYPE(cfi_bpf_hash, __bpf_prog_runX); > /* Must match bpf_callback_t */ > extern u64 __bpf_callback_fn(u64, u64, u64, u64, u64); > - > -__ADDRESSABLE(__bpf_callback_fn); > - > -/* u32 __ro_after_init cfi_bpf_subprog_hash = __kcfi_typeid___bpf_callback_fn; */ > -asm ( > -" .pushsection .data..ro_after_init,\"aw\",@progbits \n" > -" .type cfi_bpf_subprog_hash,@object \n" > -" .globl cfi_bpf_subprog_hash \n" > -" .p2align 2, 0x0 \n" > -"cfi_bpf_subprog_hash: \n" > -" .word __kcfi_typeid___bpf_callback_fn \n" > -" .size cfi_bpf_subprog_hash, 4 \n" > -" .popsection \n" > -); > - > +DEFINE_CFI_TYPE(cfi_bpf_subprog_hash, __bpf_callback_fn); > u32 cfi_get_func_hash(void *func) > { > - u32 hash; > - > - if (get_kernel_nofault(hash, func - cfi_get_offset())) > - return 0; > - > - return hash; > + u32 *hashp = func - cfi_get_offset(); > + return READ_ONCE(*hashp); Please avoid the code churn. Just squash it into the previous patch. pw-bot: cr