From mboxrd@z Thu Jan 1 00:00:00 1970 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 8F374C25B74 for ; Mon, 13 May 2024 16:39:51 +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:MIME-Version:Message-ID:Date:References :In-Reply-To:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=qofPSI2BMi1HjBD8GV+xhBGbhkDATRlE64fFF42Nr5I=; b=YUWTO8EGftE/5t w1RtXvwh+sv3kWZGI7rJOQ/OI4Y5goWbH6YFWmhz0B71hPvZmaddOzDXX8fiTpeASj+ZI1M5ZuDh0 QDYB31Qz18sVy1h0+O2SNyBKm5rqnPirBTLArDAtSq26EpuRX+fGW43u5CyVYfYfEx58Y+NtjMKAA oh1tT/fVkDMDuML8SzVYog+dE1EMjTtN7LvOEbxPb1tYJyxwVDEnWIUzuL12t7+hdQxNT8g5+2K62 0xSh4/YvPkCzpEexDhzNRIYcwv3uceJ40cEXO+XuOPY9qOaEt2Xad7mQpUdTyGcKQcb00UUj5C3Sl XTB6TiOsTdMcyOW1RyQQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s6YiC-0000000DaCW-1KGx; Mon, 13 May 2024 16:39:40 +0000 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s6Yi6-0000000Da7u-1nij for linux-arm-kernel@lists.infradead.org; Mon, 13 May 2024 16:39:36 +0000 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-41fd5dc04f0so28681505e9.0 for ; Mon, 13 May 2024 09:39:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1715618371; x=1716223171; darn=lists.infradead.org; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=JlL47WvthT5p4/6Hq0zcLfQwW5agcsSiG76b2RdCPO8=; b=EaoCCK1Ic/Na8Off1eFS0axiFSpOn7UE4Aceu1Zc2RT+2cRO31nE+roqT0hBuyYpIL H+KHhN3GCY6G2+ERlxO7yY2mFyDyYpxv1yugx3EDrvyZDUy4eh6nL2JN3b1dDljzz8pv VjAGI0aKTXWHsjfBP/6i6d0ifZi6Go32NjEqyU6XNLd30zrdaWO0M7B1O4cn+6lcXDzu SjYhoXKyZWwZ7KZ5EbLSCPFI5sXu/Ek/UzSc+LQ3YenulX1TGuYDyGkAmp4206qa3Yoo 3tjqoW7mHyLotFioIvkrz1snLXWc6Ig0kDckfmSsqf3Uq2nwFdaxnOCXTToYz8h9iznJ gPrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715618371; x=1716223171; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JlL47WvthT5p4/6Hq0zcLfQwW5agcsSiG76b2RdCPO8=; b=jb3BAmnayr9zvO6V/cIFlIAj/biMG0UKhtgeNrubiakVC6+utKttBY2D1vrvypIQmo IBtqGNPqw0q9M32EMXp9m4xdvlNEwOwcL/1x5dsh235gmTF2txKwzO4ocMSXUcXq+SMZ ud5JNpqYTkoz0ykicPEFpHmC794E89MqZqCu55if7ug2lqDXhsLq3TTAR2W7Nde1QC4o BFONED+ZNegEM75Xr91pCnh5IjyxclDbbqWfZmHNuvYgaCUvoToleRZm5Uw1r8myPPK1 2lyGty2r4iN85lY7SKqPzU9EV6UknF3mwdM+dcmhZ4974O6r7rGoAMB3kJOwOPUO2pUu hTzA== X-Forwarded-Encrypted: i=1; AJvYcCXNc7bW55ZcPHvqLM1Hkhg9nUY/ylQ/0dPWcce9Z9stm2yOpEAHMUcSNpcpBjP+tqPbxdz8v0Q/A7jW394qiXysmBy9AyIyDzF5nv5+LDdeEtXy6Jw= X-Gm-Message-State: AOJu0Yx/STyQTlqD7nav54UCtOKE2Y62B4REnO7YRh1IU6xbeyRX1Fqw oIJPZxDKZPnFLFh9EcDY8cWcWsn/pF66N4JxyNuhL/LsTyzXUQjl X-Google-Smtp-Source: AGHT+IFheMWHt8UUqBv97Se6r51eErnibj4jwd2Xsi4g0uCOA5f0VLNA4AbqyY41m1+pDF9RqD9t8Q== X-Received: by 2002:a05:600c:4714:b0:41b:13d5:7da9 with SMTP id 5b1f17b1804b1-41fead643famr128548145e9.38.1715618370680; Mon, 13 May 2024 09:39:30 -0700 (PDT) Received: from localhost (54-240-197-231.amazon.com. [54.240.197.231]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-41fccee94dasm163110125e9.32.2024.05.13.09.39.30 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 May 2024 09:39:30 -0700 (PDT) From: Puranjay Mohan To: Maxwell Bland , "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 Subject: Re: [PATCH bpf-next v4 2/3] arm64/cfi,bpf: Support kCFI + BPF on arm64 In-Reply-To: References: Date: Mon, 13 May 2024 16:39:28 +0000 Message-ID: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240513_093934_542746_0BEE433E X-CRM114-Status: GOOD ( 19.87 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Maxwell Bland writes: This patch has a subtle difference from the patch that I sent in v2[1] Unfortunately, you didn't test this. :( It will break BPF on an ARM64 kernel compiled with CONFIG_CFI_CLANG=y See below: > diff --git a/arch/arm64/net/bpf_jit_comp.c b/arch/arm64/net/bpf_jit_comp.c > index 76b91f36c729..703247457409 100644 > --- a/arch/arm64/net/bpf_jit_comp.c > +++ b/arch/arm64/net/bpf_jit_comp.c > @@ -17,6 +17,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -162,6 +163,12 @@ static inline void emit_bti(u32 insn, struct jit_ctx *ctx) > emit(insn, ctx); > } > > +static inline void emit_kcfi(u32 hash, struct jit_ctx *ctx) > +{ > + if (IS_ENABLED(CONFIG_CFI_CLANG)) > + emit(hash, ctx); > +} > + > /* > * Kernel addresses in the vmalloc space use at most 48 bits, and the > * remaining bits are guaranteed to be 0x1. So we can compose the address > @@ -337,6 +344,7 @@ static int build_prologue(struct jit_ctx *ctx, bool ebpf_from_cbpf, > * > */ In my original patch the hunk here looked something like: --- >8 --- - const int idx0 = ctx->idx; int cur_offset; /* @@ -332,6 +338,8 @@ static int build_prologue(struct jit_ctx *ctx, bool ebpf_from_cbpf, * */ + emit_kcfi(is_subprog ? cfi_bpf_subprog_hash : cfi_bpf_hash, ctx); + const int idx0 = ctx->idx; --- 8< --- moving idx0 = ctx->idx; after emit_kcfi() is important because later this 'idx0' is used like: cur_offset = ctx->idx - idx0; if (cur_offset != PROLOGUE_OFFSET) { pr_err_once("PROLOGUE_OFFSET = %d, expected %d!\n", cur_offset, PROLOGUE_OFFSET); return -1; } With the current version, when I boot the kernel I get: [ 0.499207] bpf_jit: PROLOGUE_OFFSET = 13, expected 12! and now no BPF program can be JITed! Please fix this in the next version and test it by running: ./tools/testing/selftests/bpf/test_progs Pay attention to the `rbtree_success` and the `dummy_st_ops` tests, they are the important ones for this change. [1] https://lore.kernel.org/all/20240324211518.93892-2-puranjay12@gmail.com/ Thanks, Puranjay _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel