Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp2071822lqo; Mon, 13 May 2024 07:11:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU4HR8w6fmfp7esI/pnQNFXoal+C79mZyNqFengw9FEB/chh8uNp1oZtdpKHyt5JypO07pxvIDxO+8Axc/KsY/RD7WYiGGoEeoPvmr+Bg== X-Google-Smtp-Source: AGHT+IFYrjQZ+Soo7Yt5/uaRLNAe7C7+3zGY1fsyS6ZaOsI9r34XP6wZrB05yTp5OD5Xhe8qxPPA X-Received: by 2002:a50:d615:0:b0:56c:522f:53e1 with SMTP id 4fb4d7f45d1cf-5734d5d13b1mr10329387a12.17.1715609479966; Mon, 13 May 2024 07:11:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715609479; cv=pass; d=google.com; s=arc-20160816; b=o6J6PKtqPma2prcr/VrgU94bIME+2Cd/7/Ypq+P74xBVX9rknbVfZuzVcGYYhT/zaZ 0qIKcXgi37yvt1oJ/rbhFztupvLiItUciuhPdNly9rx3uUir4D9opvCaZWhmrSc7kwxe hANN0uGMwrED1r7FcHG6jfJA8OD1YonMOb2F0GMe2qRqT813z/UZTvbtdii71vcgptW4 SqM0d48C51W56Hthj1YyX54QX4jLFFbMRTXXp4xtkCEUICj+JqCRkY+wMJkv9tzAXojS wBshqVJ1F9gygJaZMhtZroomZPUgNpx0vHixesYrOp3nHTtwfIG25Q1+EWEGp+o1sj3b jQjA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=5qkYBuj6g1aDDL5qkS70kdMJikkh6fHF1+W4OrpQf/4=; fh=6T1cn+zZISETfkSQY+ffbsWoINvS+CfK4zu/XnbAny8=; b=vHLXEcootvsQ7/9uaMAPHxIKyr6wSGIT0or8fD71umakxUCcshRy1ehXvjx5pHwG/x 5UD36NE+VoxknlOmMkVtimdgbxQczDQwEKRg5ctBGNLkAOia4AyQyEsAzdNjUzOwVluX PCuWexLdFKlefdpyimUBbyE0r9yO7MSFdPeJ6gxbkr4mii8cD4j3TkA9cTBBtePpAVQR npFVodNtORq22Qk4b5rE3L7un0YIhYAupSOC1TFQ9Igmz5gTpL46idfoGaSSaIGxYtcA +YbBH7mMZ0vwfgdmwSEO+RUKDRiBpOUWgkFPftJH1a9tWGRxjmR8eepF/X7AE+aicd4t 3jtw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@motorola.com header.s=DKIM202306 header.b=Nb3LaEVW; arc=pass (i=1 spf=pass spfdomain=motorola.com dkim=pass dkdomain=motorola.com dmarc=pass fromdomain=motorola.com); spf=pass (google.com: domain of linux-kernel+bounces-177675-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177675-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=motorola.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-5733beace92si5127994a12.89.2024.05.13.07.11.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 May 2024 07:11:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-177675-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@motorola.com header.s=DKIM202306 header.b=Nb3LaEVW; arc=pass (i=1 spf=pass spfdomain=motorola.com dkim=pass dkdomain=motorola.com dmarc=pass fromdomain=motorola.com); spf=pass (google.com: domain of linux-kernel+bounces-177675-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-177675-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=motorola.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 881661F219F0 for ; Mon, 13 May 2024 14:11:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 14D6D153833; Mon, 13 May 2024 14:11:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=motorola.com header.i=@motorola.com header.b="Nb3LaEVW" Received: from mx0b-00823401.pphosted.com (mx0b-00823401.pphosted.com [148.163.152.46]) (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 4D12D1E497; Mon, 13 May 2024 14:11:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.152.46 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715609471; cv=none; b=R/WNYumt9GwZ7D16EpaQZXcVDgdRKFHZC1Sm5SaLcTbXrRqxaQxjIkrXCeVitLcO6pr5x9m5p90eI6xckxq0qtkOZ64cW9wC+RZj69VrgcgsIGOPEUpyc7T1XIsKMbql5dBfadN/mz9iv5O+kPp2VCnjG4fDMfRLex6KKEdjwyw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715609471; c=relaxed/simple; bh=XYfTQtbozqYGz8FXiqbmvbG1f9p7jiF4C3zcjiKgzJc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=lW20WoB8s2wCS2Gj6WU6ZtF+IVYcnpJMBEqcmx8z5umB1/uKMjQ+bjIdHn2bzKRJARNucqnBm9XyB1IiUznYKlanbLN5DCM/lwGGir5f9EWCZnlbLQhXtRKP+zyJSRd7ZjL2z1NR2/ZcTpjlaCEsgWWD7gnyK1TDFP0h3z53R3c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=motorola.com; spf=pass smtp.mailfrom=motorola.com; dkim=pass (2048-bit key) header.d=motorola.com header.i=@motorola.com header.b=Nb3LaEVW; arc=none smtp.client-ip=148.163.152.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=motorola.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=motorola.com Received: from pps.filterd (m0355092.ppops.net [127.0.0.1]) by mx0b-00823401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 44DBhsUW025313; Mon, 13 May 2024 14:10:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=motorola.com; h= date:from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=DKIM202306; bh=5qkYBuj6g1aDDL5qkS70 kdMJikkh6fHF1+W4OrpQf/4=; b=Nb3LaEVW0s4JhmOXZW6Jm2Jz053Q1YWwzM6o JcaQbcQpy5LsjXknZycvC4PEWn+MpmW/5yS/VKA93hz6BBhGDZF83dBAx/mGBDNf kQCNF46NBYb7klLl9X/rvkx97ct4uxQkvbkP2jM0TxHye5v8RkOAKb8lOKQXF2EH kS3J8iEuUdBZja6AYMChvSUtVMib+P13h/Rkr3zaLvna2bO1UKwW/CQlRS9bY7vo rDOr+FIMvMqQHroa7XHSa2lKdJD2jH+YcTwW8MnzHVMHJZbPnxATl3RNbEqdvdVc RomB7WvZzz+5i+yN+S64qlZMTRnN2owYeu7EDxC+LOE2vy0atw== Received: from ilclpfpp02.lenovo.com ([144.188.128.68]) by mx0b-00823401.pphosted.com (PPS) with ESMTPS id 3y3d7ps12c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 13 May 2024 14:10:39 +0000 (GMT) Received: from va32lmmrp01.lenovo.com (va32lmmrp01.mot.com [10.62.177.113]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ilclpfpp02.lenovo.com (Postfix) with ESMTPS id 4VdLxC07RDzc3HR; Mon, 13 May 2024 14:10:39 +0000 (UTC) Received: from ilclasset02 (ilclasset02.mot.com [100.64.49.13]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: mbland) by va32lmmrp01.lenovo.com (Postfix) with ESMTPSA id 4VdLxB0GXnz2VZRw; Mon, 13 May 2024 14:10:38 +0000 (UTC) Date: Mon, 13 May 2024 09:10:36 -0500 From: Maxwell Bland To: "open list:BPF [GENERAL] (Safe Dynamic Programs and Tools)" Cc: Catalin Marinas , Will Deacon , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Zi Shen Lim , Mark Rutland , Suzuki K Poulose , Mark Brown , linux-arm-kernel@lists.infradead.org, open list , Josh Poimboeuf , Puranjay Mohan Subject: [PATCH bpf-next v4 1/3] cfi: add C CFI type macro Message-ID: <6hawcu7saygxwndxkzmhn7qt5vgqjha3goodr7p7v3e6k2erpi@hj775dv6h6xv> References: 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: X-Proofpoint-ORIG-GUID: iLE-iQwapet5NBCQsW6CPfv4pXtpT57W X-Proofpoint-GUID: iLE-iQwapet5NBCQsW6CPfv4pXtpT57W X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.650,FMLib:17.11.176.26 definitions=2024-05-13_10,2024-05-10_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 phishscore=0 malwarescore=0 suspectscore=0 mlxscore=0 bulkscore=0 spamscore=0 impostorscore=0 clxscore=1015 mlxlogscore=999 lowpriorityscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405010000 definitions=main-2405130089 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 --- Minor fix of authorship attribution by adding "From:" field! arch/riscv/kernel/cfi.c | 34 ++-------------------------------- arch/x86/kernel/alternative.c | 35 +++-------------------------------- include/linux/cfi_types.h | 23 +++++++++++++++++++++++ 3 files changed, 28 insertions(+), 64 deletions(-) diff --git a/arch/riscv/kernel/cfi.c b/arch/riscv/kernel/cfi.c index 64bdd3e1ab8c..b78a6f41df22 100644 --- a/arch/riscv/kernel/cfi.c +++ b/arch/riscv/kernel/cfi.c @@ -82,41 +82,11 @@ 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) { diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 45a280f2161c..a822699a40dd 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only #define pr_fmt(fmt) "SMP alternatives: " fmt +#include #include #include #include @@ -918,41 +919,11 @@ 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" -" .long __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" -" .long __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) { diff --git a/include/linux/cfi_types.h b/include/linux/cfi_types.h index 6b8713675765..f510e62ca8b1 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 = __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" \ + " .long __kcfi_typeid_" #func " \n" \ + " .size " #name ", 4 \n" \ + " .popsection \n" \ + ); +#endif + #endif /* __ASSEMBLY__ */ #endif /* _LINUX_CFI_TYPES_H */ -- 2.34.1