Received: by 2002:ab2:715a:0:b0:1fd:c064:50c with SMTP id l26csp24606lqm; Mon, 10 Jun 2024 11:27:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXHLgcC8qqanKPeMoUP9XGkNSmGvIOc3m3hGJER8ogVN0gFFy8m+JynolIirckrwI9/uaSuKBtX79g90IucrvIL6wCuGITHsvawjH6/mg== X-Google-Smtp-Source: AGHT+IGkcDwUnkaXB/dEX+awxHFGlrwJoxB4mPeleSAmyOxPnzWGJbaRnuqplQ6PLMo3gVb8yUkG X-Received: by 2002:a05:6a00:1389:b0:705:9f03:abbe with SMTP id d2e1a72fcca58-7059f03b601mr3022317b3a.33.1718044061026; Mon, 10 Jun 2024 11:27:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718044061; cv=pass; d=google.com; s=arc-20160816; b=RiDYYiqBO4TNqI6RJ4UIoydqA23dmPQvXYVRRpenDY6YpHOt5BkhrosOFnPIFZp/Gd Zs8+W4eM5mgF7xP5+FoLFtnuyPfM29evqHrnC1BnsGUVvriJfK8IEFe39hxTBE9czomw Dt/nsbNqTmHoCfoc7eq+o43SH2SFI8Xexk132LiBQ1TkBi/bDOntJ/WKuKxYybH22mFP 2wvYw2gf4rvmUM0+lSUZ+1rqcvhTfj4G2cDNVkeCVixb4oUlzwIWYH14LXs6aqGvTMQz Oh2EA8N2xjlFwab/T251M124p3WoUO9wYLzjvyBWIEGlQ/Z2/zVEFGsH8Vu844tGjJeT MQrA== 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=fpGG32Pz+fVwqm7Q0mpoPSMuO7je7B3t/MuuD+KCtN8=; fh=6T1cn+zZISETfkSQY+ffbsWoINvS+CfK4zu/XnbAny8=; b=yXCrRBKH8N+H4+xGdGLdJYOXu2GMxCIIbA3307z0QWJXQpmXM6VVbIdmBwklQnNslT n+tIKDLc/eMkcqFycp9PY52RRod+tIROFu/trioL+pI9Q5lXiaC7td+vlw0n2TVqk7SG exONnm5xegOggmy6x5l1EKYD4HXZV5dLetGN0X1UG+OVRLH2Bp1SUPUxkN2J7d+ado2n Vv1lCywUJRIhhyoFzj2vevA7+ux/mv8Yia9TeRFGkdOf8ye/5yBJMd8T8qkqfikT2a5q J+BkVPZatNysptbGZVh1d+925nqivLi02XCkSENh0pGGzn/I9rpwsB6Dx0GigT0jBiRd s1Fw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@motorola.com header.s=DKIM202306 header.b=IPoPALCw; 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-208706-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208706-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=motorola.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 41be03b00d2f7-6de20831b57si6144558a12.125.2024.06.10.11.27.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 11:27:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-208706-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@motorola.com header.s=DKIM202306 header.b=IPoPALCw; 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-208706-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-208706-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 03A3EB22BAF for ; Mon, 10 Jun 2024 18:09:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 60A4A14B95F; Mon, 10 Jun 2024 18:07:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=motorola.com header.i=@motorola.com header.b="IPoPALCw" Received: from mx0a-00823401.pphosted.com (mx0a-00823401.pphosted.com [148.163.148.104]) (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 AB31B152DF1; Mon, 10 Jun 2024 18:07:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.148.104 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718042825; cv=none; b=SxyXlZDtjPWy8DGQValAUICI39RYx6s4K9QRUs8tddy9YBKYAeOsY1vd4nTaJSU+usUt07r3Rap5RTAz7omIudytmrNHVT/se1Jp9gWeb9u315Tp6RmjCX2c3JyYmN1ltoPGXCNGrfwv35tJNm62JVqUJecAXwlzRDsSptv20Ug= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718042825; c=relaxed/simple; bh=CqjJ/MlvtyQpfI4pujmNMijprGaOs7jhJjWcFS5BX+M=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=DBvwBV70yYXcXbxuCE5RPO6zabIcGbqdtlSBIOjd1wTCsj/L9Aix4PgaQizPfKsYiNqDYeBh//h8ngZewlPP8IJYi2ZHCgrqwN3kIlmBMzzZc39FwsNDvIFyZp+p22u1A6ECXb/xVKkb7x4Oto58KOkICYZgZxpKAecy5QHXTpA= 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=IPoPALCw; arc=none smtp.client-ip=148.163.148.104 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 (m0355088.ppops.net [127.0.0.1]) by m0355088.ppops.net (8.18.1.2/8.18.1.2) with ESMTP id 45ABm98B002176; Mon, 10 Jun 2024 18:06:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=motorola.com; h= cc:content-type:date:from:in-reply-to:message-id:mime-version :references:subject:to; s=DKIM202306; bh=fpGG32Pz+fVwqm7Q0mpoPSM uO7je7B3t/MuuD+KCtN8=; b=IPoPALCwWxa3+uJURcLHaUNPkasRTKkgJH5mpoV eRrzeaaNL6jKqySrszmwJ5bFfTAKq0+2JMV9H7xgY4Vv7NsN4Z6+4lKXCvLTi6l+ y8LJvwmFCceHu/gv8ohpyEeC+jWto4M62XZiJy5klBmygU9hOH7Sy6zLekQWAt/U K3QQe3Duol94Pp25rRWGOKnLcc5NKo+lcL7eQtZjSc0PpSolGW5K9RZATiP6oh+T 75ULiWMa5x9k5ay1aaiFVMDk+KtsLuvb/jHg9URq6M3N00q/g6JCzaZJ0pSITcVt ZGNzGpHLVNLpwBEFxmDIkaITpBjbGjmoiHZli0QGon3gouQ== Received: from va32lpfpp04.lenovo.com ([104.232.228.24]) by m0355088.ppops.net (PPS) with ESMTPS id 3yn4ft2at6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 10 Jun 2024 18:06:36 +0000 (GMT) Received: from ilclmmrp01.lenovo.com (ilclmmrp01.mot.com [100.65.83.165]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by va32lpfpp04.lenovo.com (Postfix) with ESMTPS id 4VyfrW0tDvzjcK6; Mon, 10 Jun 2024 18:06:35 +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 ilclmmrp01.lenovo.com (Postfix) with ESMTPSA id 4VyfrV68fyz3nd87; Mon, 10 Jun 2024 18:06:34 +0000 (UTC) Date: Mon, 10 Jun 2024 13:06:33 -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 v5 1/3] cfi: add C CFI type macro Message-ID: 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-GUID: gOTPu_mAQFXwxHHmJHPo1fLRabODHRu1 X-Proofpoint-ORIG-GUID: gOTPu_mAQFXwxHHmJHPo1fLRabODHRu1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-10_04,2024-06-10_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 lowpriorityscore=0 adultscore=0 clxscore=1015 bulkscore=0 spamscore=0 priorityscore=1501 malwarescore=0 phishscore=0 suspectscore=0 mlxlogscore=999 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2406100136 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 --- 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 89de61243272..933d0c13a0d8 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 @@ -901,41 +902,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.39.2