From: Will Deacon <will@kernel.org>
To: Sami Tolvanen <samitolvanen@google.com>
Cc: bpf@vger.kernel.org, Puranjay Mohan <puranjay@kernel.org>,
Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Catalin Marinas <catalin.marinas@arm.com>,
Andrii Nakryiko <andrii@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, Maxwell Bland <mbland@motorola.com>,
Dao Huang <huangdao1@oppo.com>
Subject: Re: [PATCH bpf-next v10 1/3] cfi: add C CFI type macro
Date: Fri, 18 Jul 2025 12:33:15 +0100 [thread overview]
Message-ID: <aHow-yVsJCO2AJsn@willie-the-truck> (raw)
In-Reply-To: <20250715225733.3921432-6-samitolvanen@google.com>
On Tue, Jul 15, 2025 at 10:57:35PM +0000, Sami Tolvanen wrote:
> From: Mark Rutland <mark.rutland@arm.com>
>
> Currently x86 and riscv open-code 4 instances of the same logic to
> define a u32 variable with the KCFI typeid of a given function.
>
> Replace the duplicate logic with a common macro.
>
> Signed-off-by: Mark Rutland <mark.rutland@arm.com>
> Co-developed-by: Maxwell Bland <mbland@motorola.com>
> Signed-off-by: Maxwell Bland <mbland@motorola.com>
> Co-developed-by: Sami Tolvanen <samitolvanen@google.com>
> Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
> Tested-by: Dao Huang <huangdao1@oppo.com>
> ---
> arch/riscv/kernel/cfi.c | 35 +++--------------------------------
> arch/x86/kernel/alternative.c | 31 +++----------------------------
> include/linux/cfi_types.h | 23 +++++++++++++++++++++++
> 3 files changed, 29 insertions(+), 60 deletions(-)
[...]
> diff --git a/include/linux/cfi_types.h b/include/linux/cfi_types.h
> index 6b8713675765..e5567c0fd0b3 100644
> --- a/include/linux/cfi_types.h
> +++ b/include/linux/cfi_types.h
> @@ -41,5 +41,28 @@
> SYM_TYPED_START(name, SYM_L_GLOBAL, SYM_A_ALIGN)
> #endif
>
> +#else /* __ASSEMBLY__ */
> +
> +#ifdef CONFIG_CFI_CLANG
> +#define DEFINE_CFI_TYPE(name, func) \
> + /* \
> + * Force a reference to the function so the compiler generates \
> + * __kcfi_typeid_<func>. \
> + */ \
> + __ADDRESSABLE(func); \
> + /* u32 name __ro_after_init = __kcfi_typeid_<func> */ \
> + extern u32 name; \
> + asm ( \
> + " .pushsection .data..ro_after_init,\"aw\",@progbits \n" \
> + " .type " #name ",@object \n" \
> + " .globl " #name " \n" \
> + " .p2align 2, 0x0 \n" \
> + #name ": \n" \
> + " .4byte __kcfi_typeid_" #func " \n" \
> + " .size " #name ", 4 \n" \
> + " .popsection \n" \
> + );
> +#endif
This looks good to me. I was initially a bit worried about the portability
of the '.4byte' directive, but it seems that cfi_types.h is already using
that for the __CFI_TYPE() macro so I'm assuming it's not an issue.
In which case:
Acked-by: Will Deacon <will@kernel.org>
Thanks for cleaning it up.
Will
next prev parent reply other threads:[~2025-07-18 12:33 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-15 22:57 [PATCH bpf-next v10 0/3] Support kCFI + BPF on arm64 Sami Tolvanen
2025-07-15 22:57 ` [PATCH bpf-next v10 1/3] cfi: add C CFI type macro Sami Tolvanen
2025-07-18 11:33 ` Will Deacon [this message]
2025-07-15 22:57 ` [PATCH bpf-next v10 2/3] cfi: Move BPF CFI types and helpers to generic code Sami Tolvanen
2025-07-18 11:39 ` Will Deacon
2025-07-18 22:27 ` Sami Tolvanen
2025-07-15 22:57 ` [PATCH bpf-next v10 3/3] arm64/cfi,bpf: Support kCFI + BPF on arm64 Sami Tolvanen
2025-07-18 11:42 ` Will Deacon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aHow-yVsJCO2AJsn@willie-the-truck \
--to=will@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=catalin.marinas@arm.com \
--cc=daniel@iogearbox.net \
--cc=huangdao1@oppo.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mbland@motorola.com \
--cc=puranjay@kernel.org \
--cc=samitolvanen@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox