From patchwork Mon May 13 14:14:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxwell Bland X-Patchwork-Id: 13663492 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E9669C25B5F for ; Mon, 13 May 2024 14:15:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Nhp4DdzhWZ6hA4gnVsRHohWsl9hvm2KXZFJUwkzvX0I=; b=ebpvGY4kAdPlKP dYDdvDU+vzqj6XBQ/U+7TlhO8mOKmNBD1uZdw6inG9/xLSM/9vNaZX3sNZ8Yk8NMc0U1Vmb91LRW+ 9UxGxNij7cEaWPLeWCGG+PYbdvAsdIngQ0YLUvAePY6iqQpKQXNNodbmVaaMHDPHw9uWinSF2Hd9R Yd6Q4GrcIuFueZEAwB0hgH2v9y6fzi8xqRpqCzr0BU4vxWURnhKe7Lis9plogNE5UVl2uW0MNMahM CMp1MhWN5x3Nz5b5ZLp9eZ2KXXTpUiGFwYoTPLfxvP2G94sbQdtoNKStngtsw8XcoCSR0kfjfjhYp YGtOgcquhkNE5yh9OA9A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s6WS8-0000000D9At-3zOa; Mon, 13 May 2024 14:14:56 +0000 Received: from mx0b-00823401.pphosted.com ([148.163.152.46]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s6WS6-0000000D9A1-2TBd for linux-arm-kernel@lists.infradead.org; Mon, 13 May 2024 14:14:55 +0000 Received: from pps.filterd (m0355091.ppops.net [127.0.0.1]) by mx0b-00823401.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 44D8L2M2009106; Mon, 13 May 2024 14:14:36 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=FdxN5qFp6MoVErrH5QHe 3LkBFgBJ9NheMIyMy9pry2s=; b=TACf0VYbDPMCX0OE4JNy0nGlAviTf3TODoMQ XP17gE708/pc0ygl58pjCramAzizQUd5xc8XxQW2KR0cksdUOTm2nzAis+fj/8os C6gDfWWwYj2UE1UmNEKsMQ4OIzh16ZeTndbeJj+eVasZ/FedduLL3nmdsCyPN5us cKxjftxyS0VwQX90xMoMmlE3Kn1ea/HKBCkSIDH4IWtvsemL8UB8uPrWRVodHm7N s9QOnH+DGI7pdt6nOAlhZq70m/QoK3Z/F7qBANobywZ7MoDosD3z0IhxUAUPzhZ8 vfywqGUch3U41uBly1gcNd0DgP/SqEbEE5KrMTrniydxT3jjuw== Received: from va32lpfpp02.lenovo.com ([104.232.228.22]) by mx0b-00823401.pphosted.com (PPS) with ESMTPS id 3y30gh9tfw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 13 May 2024 14:14:35 +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 va32lpfpp02.lenovo.com (Postfix) with ESMTPS id 4VdM1l1TmPz50TkW; Mon, 13 May 2024 14:14: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 va32lmmrp01.lenovo.com (Postfix) with ESMTPSA id 4VdM1k536Nz2VZRw; Mon, 13 May 2024 14:14:34 +0000 (UTC) Date: Mon, 13 May 2024 09:14: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 v4 3/3] arm64/cfi,bpf: Use DEFINE_CFI_TYPE in arm64 Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Proofpoint-GUID: ejn-Tuy6x7RGGoUP3mZrfDZYJKj-CR2c X-Proofpoint-ORIG-GUID: ejn-Tuy6x7RGGoUP3mZrfDZYJKj-CR2c 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_09,2024-05-10_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 phishscore=0 clxscore=1015 mlxlogscore=999 priorityscore=1501 mlxscore=0 spamscore=0 impostorscore=0 bulkscore=0 lowpriorityscore=0 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405010000 definitions=main-2405130089 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240513_071454_765383_CA26F485 X-CRM114-Status: GOOD ( 14.66 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Corrects Puranjay Mohan's commit to adopt Mark Rutland's suggestion of using a C CFI type macro in kCFI+BPF. Signed-off-by: Maxwell Bland --- arch/arm64/kernel/alternative.c | 46 ++++----------------------------- 1 file changed, 5 insertions(+), 41 deletions(-) diff --git a/arch/arm64/kernel/alternative.c b/arch/arm64/kernel/alternative.c index 1715da7df137..d7a58eca7665 100644 --- a/arch/arm64/kernel/alternative.c +++ b/arch/arm64/kernel/alternative.c @@ -8,6 +8,7 @@ #define pr_fmt(fmt) "alternatives: " fmt +#include #include #include #include @@ -302,53 +303,16 @@ EXPORT_SYMBOL(alt_cb_patch_nops); #ifdef CONFIG_CFI_CLANG 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) { - u32 hash; - - if (get_kernel_nofault(hash, func - cfi_get_offset())) - return 0; - - return hash; + u32 *hashp = func - cfi_get_offset(); + return READ_ONCE(*hashp); } #endif