Received: by 2002:ab2:6c55:0:b0:1fd:c486:4f03 with SMTP id v21csp652385lqp; Wed, 12 Jun 2024 11:59:28 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXAMyzkR76R7i2cHezPjNsEK19no8riSoH53vaJhXFzkHyi6xy3BJin+4jxBtUqqxiKlWn59c1bF1ui40n/FiadLMI/Ld98Gnmz2Mn18A== X-Google-Smtp-Source: AGHT+IEeOKljrbnM3hC8gL0jOhmUfp9iiCGdXnqyJyAsxeDGkYguErz5j3ZdAfHfHgE6WKCfKRkX X-Received: by 2002:a17:903:41c7:b0:1f7:13db:527b with SMTP id d9443c01a7336-1f83b566d5emr29927925ad.7.1718218767781; Wed, 12 Jun 2024 11:59:27 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718218767; cv=pass; d=google.com; s=arc-20160816; b=aUBqSpoKKgMta86PVeLlPEmbXsmbX71GtwiRfk8PD6GXHC4Vw8nJqjrh5JvPK55/aC HVHLF8yXglyZdXgk+fVADJWJtryJv6p1yn+JzNV6PBKL98P6Pd7AKRZmhkoU3UlF3pML /noWWuF4mkghW7BexWKzA03HBK22C8lviJ9UJdUDfJaEiWudGrI1CRZOVk9XunD261yS j0jkE8q8eVRedNB4kMNRHB7y5ZqgO/UGcaTtINa1B8g5NTMzl9c9/qNskm1kf35iMCHU loU/9teTcOxYoP3u+t1H0HvOpYBmAcDjk9YiD9Ytcb3PhC5tsGpbC/CLbXnkvDEEK70B gR+w== 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=8WJALL82Sk9HW31XdlI5/qJF14ASSC7G53mFaIDlTHE=; fh=6T1cn+zZISETfkSQY+ffbsWoINvS+CfK4zu/XnbAny8=; b=Vfsby/qGbfsohRPTKDsYCsstKPGMAGDIUufzmdlc0FhfDsUnxOtxcTUX4R3DqqSHli nyIxdznPIjutMEGf7sJIBRBQRVH4MZ9b/4FTOCa8umlJn/GlHAVboth1dyDwtIUkZaLH o9mBENwlLIBvNFokuUkBVygvrGKRTaj6raPfOyaPMAzzaz8y3h+vagR2AqZEnW5Spozb YRAFFzFrKXHX1ddhOf3LtMOd6/0Z16TWnMsDHbsx43X0J7rPFYGwo/7IogTAA8v9vCTv wp/3wNmO4L9ZoYZB1bFe31oCZJ3r35fQF/SSeYuozG2mXi6paGNOl9XI2JRE4hQYjof8 Ruog==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@motorola.com header.s=DKIM202306 header.b=u+K8j4Zl; 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-212099-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212099-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 d9443c01a7336-1f71b597088si55953455ad.579.2024.06.12.11.59.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 11:59:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-212099-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=u+K8j4Zl; 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-212099-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212099-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 2F6C5B221F1 for ; Wed, 12 Jun 2024 18:40:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2666A4AEF5; Wed, 12 Jun 2024 18:40:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=motorola.com header.i=@motorola.com header.b="u+K8j4Zl" 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 44AC14A9B0; Wed, 12 Jun 2024 18:40:02 +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=1718217605; cv=none; b=JqmdIf7frGpUvS7LY3PPar0NzStQb4gM6RNAoQVc2LfqfCb9RN5IEvTodMdPI0J3Uizoswh+sBezsFT8liAMrbzWZfQJjnB0YTNL+aiIM82AB1WqLNcSiqoDrAJCPwbIA+MX6+ELpHm49x+YqZk+GL7jP+UeojskOmFkN12eAlw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718217605; c=relaxed/simple; bh=Bjuj+h31fXZSJTP947nQ6wd95zco9N/KLLRlENy27RI=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=anyLKl4UwCzwaP1IPyITo+QngT85qFujnB/o2JaaixlYOteptfaYCjUZ2pOP8z8i+7KjjcmwgHSp5SAytjL1Ok0eVr8roC0oKFu+bRpL5PjEg9Vceq2Nsrt2Dx/9ceugSbygtIyqI8mfryUZn3dn5P8Nb6NqS0j5glwEutqsBNE= 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=u+K8j4Zl; 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 45CCP1ED025711; Wed, 12 Jun 2024 15:30:08 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=8WJALL82Sk9HW31XdlI5/qJ F14ASSC7G53mFaIDlTHE=; b=u+K8j4Zl0SL5R8jo7tx1yB96WVYiDjz3XIHWfj3 jgzaoZjTVDGWEuOcXRIn4az7tt5yUowZK5vqHhb+RLyTlkTvN2MXO3sza5Xk9RLU QXq9+ZI8EbevxNapOgfwB+BcWL4Vij8sOh8DgrGx8CLNUB80KZ1qaZXb95hhJrEL I0FtV5FwJnr+wsMj7f/CgtBcQzTf1YTgzccP3sKoBcvYNNOS3R5mt69ww4H3xKJY WdsaNxHr/+2QMWDTGobddDW1bKCcl5wMNq/MJWHlRlmzJRg8TuzphID8tRTSgZwp WoqugM4TfrnWSgvoQW0hOgiE6Bpa2ouiVPIpS9FHDmIEeGw== Received: from va32lpfpp04.lenovo.com ([104.232.228.24]) by mx0b-00823401.pphosted.com (PPS) with ESMTPS id 3yn5mcqfpp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 12 Jun 2024 15:30:08 +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 4VzqH4149Fzg1bn; Wed, 12 Jun 2024 15:30:08 +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 4VzqH36rykz3nd88; Wed, 12 Jun 2024 15:30:07 +0000 (UTC) Date: Wed, 12 Jun 2024 10:30:06 -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 v6 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: BKW5k9w-_tNY6AftGe2uCC95v5P6L0jn X-Proofpoint-ORIG-GUID: BKW5k9w-_tNY6AftGe2uCC95v5P6L0jn 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-12_08,2024-06-12_02,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 spamscore=0 clxscore=1015 malwarescore=0 mlxlogscore=999 mlxscore=0 lowpriorityscore=0 bulkscore=0 impostorscore=0 adultscore=0 phishscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2406120111 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 Signed-off-by: Maxwell Bland --- arch/riscv/kernel/cfi.c | 35 +++-------------------------------- arch/x86/kernel/alternative.c | 35 +++-------------------------------- include/linux/cfi_types.h | 23 +++++++++++++++++++++++ 3 files changed, 29 insertions(+), 64 deletions(-) diff --git a/arch/riscv/kernel/cfi.c b/arch/riscv/kernel/cfi.c index 64bdd3e1ab8c..e7aec5f36dd5 100644 --- a/arch/riscv/kernel/cfi.c +++ b/arch/riscv/kernel/cfi.c @@ -4,6 +4,7 @@ * * Copyright (C) 2023 Google LLC */ +#include #include #include @@ -82,41 +83,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.43.0