From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A4A3221F04; Fri, 18 Jul 2025 11:33:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752838401; cv=none; b=oUO4gwPq94zceEdH+3BoI1ZNlu+h7Hq81S1UNOEDxZx5s7tdQPayjXsoCaPZCgiTEYkKhCRD1POaqVZw4qF7ysU8bUdeM1dg9rk+tkVTZ5qVJnYqsR6zpbs/tknhgzSc9z1J/OhqPCPjyDNL984xcD/HWl2pBiEuYOeCt1SZ7b4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752838401; c=relaxed/simple; bh=92arq/Wo1/KhOpoRdEXUKIc1y6xuILihx9THlijFiR0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=TjVq/qbyBJH2d4hikvH2BzQDi89E4Xcwz0ZTFoky4OJZgw16320d+xBZ+VtnY3sIDIzePfoqqOvQsGPGCBmskCoVw7J2wPtkXWgRQCQ+pnmNUXgQQW6whr84oeU/n5DLGFHbb2vND/yyK+wVfhSTZ7PQAME0i1dfgHaqd86WJes= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XFwPSbbk; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XFwPSbbk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A11AC4CEEB; Fri, 18 Jul 2025 11:33:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1752838400; bh=92arq/Wo1/KhOpoRdEXUKIc1y6xuILihx9THlijFiR0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=XFwPSbbkzFb40PzhDQ/wJAwKW3YmtkzoutTGTkV/zX1+GLT4rYBnnKNNYzGDui87P Yi7IOtoXvaRhL5fa1rWumqqxtuAhQae5fbYevDcyF+Lxo0ccUSuMoguYPO/egRL/Qm EQeCo/h2G3/kiEcq4oJQnk+8G+3ev4ZIRyyke8n1bh/8qHk9kyldId2MUKh5ePVkjP lcCkEdu1CxQu9uFDq34mw7pvxII3CRaE2y464pDItUdJhiCri28vwejHJU0WqreC7G 7BXZuGgFrCPbtERV8zuJ/vRXT1P1j0zzRzJhZ+1NFvXe3udHk/iOi+ANqxnMqWa2ud 2yZwCecPVUMaw== Date: Fri, 18 Jul 2025 12:33:15 +0100 From: Will Deacon To: Sami Tolvanen Cc: bpf@vger.kernel.org, Puranjay Mohan , Alexei Starovoitov , Daniel Borkmann , Catalin Marinas , Andrii Nakryiko , Mark Rutland , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Maxwell Bland , Dao Huang Subject: Re: [PATCH bpf-next v10 1/3] cfi: add C CFI type macro Message-ID: References: <20250715225733.3921432-5-samitolvanen@google.com> <20250715225733.3921432-6-samitolvanen@google.com> 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=us-ascii Content-Disposition: inline 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 > > 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 > Co-developed-by: Maxwell Bland > Signed-off-by: Maxwell Bland > Co-developed-by: Sami Tolvanen > Signed-off-by: Sami Tolvanen > Tested-by: Dao Huang > --- > 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_. \ > + */ \ > + __ADDRESSABLE(func); \ > + /* u32 name __ro_after_init = __kcfi_typeid_ */ \ > + 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 Thanks for cleaning it up. Will