From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mta1.migadu.com (out-72.mta1.migadu.com [95.215.58.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C688043CEC8 for ; Thu, 24 Sep 2026 22:37:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.72 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790289447; cv=none; b=I9BrxPwdw6ZSfvTntKY/jDiVpNvrExOEWn7FpVhm6239qFXOMsb8cgoMx8not7L9+vq60zVDYYhfycXBCVkL8Dc8dSVw2uWlediP16aneOLQG/d/kcTNJPwN54Lqih6f75MhhWhSCLaC4ZOMsnfCTy0Iv/uvY2sJayw/gUyCGwo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790289447; c=relaxed/simple; bh=tZJ/wAc28PZRoYc+gt5SIvQmNZsWYF2NkAMRmp4Gagw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=sAuz+YNHsFoGk3Bx9liJTEbbP6CkvDuGUl06CJJnr/U5AAhIY/ozm/HQQuA+BQYrjZ9lP9U2HUs/dtbeeLmDQVCAmAro1cDPSFbb/ZgK5bf7XDkG7KwgMpiybBFWp88F+paf6m+ibm99X2gH+tdoPcJ3z5yLy9cI6lyETmx1Lg0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=bQQpNlyt; arc=none smtp.client-ip=95.215.58.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="bQQpNlyt" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=tZJ/wAc28PZRoYc+gt5SIvQmNZsWYF2NkAMRmp4Gagw=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1790289442; v=1; x=1790894242; b=bQQpNlytiRhPmulr7zR8GJLjTFICEjRYuC4AQc8hnH2K+YzECPDaa/Guel+bZRZIRq7+q2Bu 91yZ1eX6WeDjwdX90IjZtfRs4qfgE8pmG0W5nHJS/jDR/8naHiJOfJz+VLXdj0BFAH1Qiwv2Z8I IR2BUn+zpMRBK5UoETWikJlE= X-Envelope-To: linux-kernel@vger.kernel.org Received: by smtp.migadu.com with ESMTPS id 157ee26d80a48e9b; Thu, 24 Sep 2026 22:37:22 +0000 X-Mizu-Trace-ID: 157ee26d80a48e9b X-Migadu-Flow: FLOW_OUT From: "Jose Fernandez (Anthropic)" Date: Thu, 24 Sep 2026 22:35:50 +0000 Subject: [PATCH v2 6/9] arm64: cfi: Use CONFIG_ARM64_FUNCTION_PREFIX_NOPS for the type hash offset Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20260924-b4-arm64-callops-kcfi-v2-6-587865b6d991@linux.dev> References: <20260924-b4-arm64-callops-kcfi-v2-0-587865b6d991@linux.dev> In-Reply-To: <20260924-b4-arm64-callops-kcfi-v2-0-587865b6d991@linux.dev> To: Steven Rostedt , Masami Hiramatsu , Mark Rutland , Mathieu Desnoyers , Nathan Chancellor , Nicolas Schier , Nick Desaulniers , Bill Wendling , Justin Stitt , Catalin Marinas , Will Deacon , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Eduard Zingerman , Kumar Kartikeya Dwivedi , Martin KaFai Lau , Song Liu , Yonghong Song , Jiri Olsa , Emil Tsalapatis , Puranjay Mohan , Xu Kuohai , Ard Biesheuvel , Ilias Apalodimas , Miguel Ojeda , Boqun Feng , Gary Guo , =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= , Benno Lossin , Andreas Hindborg , Alice Ryhl , Trevor Gross , Danilo Krummrich , Daniel Almeida , Tamir Duberstein , Alexandre Courbot , =?utf-8?q?Onur_=C3=96zkan?= , Sami Tolvanen , Kees Cook Cc: Leon Hwang , Ihor Solodrai , Josh Poimboeuf , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, llvm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, bpf@vger.kernel.org, linux-efi@vger.kernel.org, rust-for-linux@vger.kernel.org, Ben Cressey , "Florent Revest (Anthropic)" , "Jose Fernandez (Anthropic)" X-Mailer: b4 0.15.2 Make cfi_get_offset(), SYM_TYPED_FUNC_START and the BPF JIT use CONFIG_ARM64_FUNCTION_PREFIX_NOPS instead of hardcoding four bytes. kCFI kernels with CALL_OPS need three NOPs, or five with ThinLTO and BTI. CONFIG_ARM64_FUNCTION_PREFIX_NOPS is 0 on every CFI kernel today, so no functional change. Reviewed-by: Ben Cressey Reviewed-by: Florent Revest (Anthropic) Assisted-by: LLM Signed-off-by: Jose Fernandez (Anthropic) --- arch/arm64/include/asm/cfi.h | 8 ++++++++ arch/arm64/include/asm/linkage.h | 11 +++++++++++ arch/arm64/net/bpf_jit_comp.c | 8 ++++++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/arch/arm64/include/asm/cfi.h b/arch/arm64/include/asm/cfi.h index ab90f0351b7ae..03f02d4614c23 100644 --- a/arch/arm64/include/asm/cfi.h +++ b/arch/arm64/include/asm/cfi.h @@ -4,4 +4,12 @@ #define __bpfcall +#ifdef CONFIG_CFI +static inline int cfi_get_offset(void) +{ + return 4 + 4 * CONFIG_ARM64_FUNCTION_PREFIX_NOPS; +} +#define cfi_get_offset cfi_get_offset +#endif /* CONFIG_CFI */ + #endif /* _ASM_ARM64_CFI_H */ diff --git a/arch/arm64/include/asm/linkage.h b/arch/arm64/include/asm/linkage.h index d1f7a16729d25..14bc3c67c38b3 100644 --- a/arch/arm64/include/asm/linkage.h +++ b/arch/arm64/include/asm/linkage.h @@ -39,6 +39,17 @@ SYM_START(name, SYM_L_WEAK, SYM_A_NONE) \ bti c ; +/* + * The compiler emits CONFIG_ARM64_FUNCTION_PREFIX_NOPS NOPs between a C + * function's kCFI type hash and its entry point. Callers check the hash + * at that offset. + */ +#define __CFI_TYPE(name) \ + .4byte __kcfi_typeid_##name ASM_NL \ + .rept CONFIG_ARM64_FUNCTION_PREFIX_NOPS ASM_NL \ + nop ASM_NL \ + .endr + #define SYM_TYPED_FUNC_START(name) \ SYM_TYPED_START(name, SYM_L_GLOBAL, SYM_A_ALIGN) \ bti c ; diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c index c18e005a41dbe..7ad14d9847138 100644 --- a/arch/arm64/net/bpf_jit_comp.c +++ b/arch/arm64/net/bpf_jit_comp.c @@ -185,8 +185,12 @@ static inline void emit_bti(u32 insn, struct jit_ctx *ctx) static inline void emit_kcfi(u32 hash, struct jit_ctx *ctx) { - if (IS_ENABLED(CONFIG_CFI)) - emit_u32_data(hash, ctx); + if (!IS_ENABLED(CONFIG_CFI)) + return; + + emit_u32_data(hash, ctx); + for (int i = 0; i < CONFIG_ARM64_FUNCTION_PREFIX_NOPS; i++) + emit(A64_NOP, ctx); } /* -- 2.52.0