From nobody Sat Feb 7 15:40:11 2026 Received: from fhigh-a4-smtp.messagingengine.com (fhigh-a4-smtp.messagingengine.com [103.168.172.155]) (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 BDF9B84A3E; Wed, 9 Apr 2025 03:34:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744169680; cv=none; b=lFz/6aUtCk8ZbiPsmfXieBvDPnc7s15ZEnCv/BciSAOLhCuvgfZzHGETm6yYmvPvZqPAVy3LlUWbsRer9/QWPGhfbah9gvGj/v6ZsPmkJbwbIYaGx4S94BtQz/F1cDnYpZhwbOmoT6dbsEhzr/DmN2ruCOYlbqFhy+pyugf0gmA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744169680; c=relaxed/simple; bh=4TX1Gm2KMzuVI9BFHu78MaAH9o4SLUiECfLlAoBMoJs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qkl8jp45KcmKv7W7LhMqUxnL0hiRKblpLVqtVICTZao5AS5hiQTPyh8gaogxNI5WA6doAHPX+aewNadof6qLgMLLg5CqVAPcq/kDOl2d3IIqrFYmkveBaElIheabNWKw+ajPgJdIG6bu+KkMAt83PB1tit5mpts6RqhiUOt2TnA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz; spf=pass smtp.mailfrom=dxuuu.xyz; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b=OssQNtC8; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=D8zA4v0j; arc=none smtp.client-ip=103.168.172.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="OssQNtC8"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="D8zA4v0j" Received: from phl-compute-08.internal (phl-compute-08.phl.internal [10.202.2.48]) by mailfhigh.phl.internal (Postfix) with ESMTP id A46AC11401AD; Tue, 8 Apr 2025 23:34:37 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-08.internal (MEProxy); Tue, 08 Apr 2025 23:34:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1744169677; x= 1744256077; bh=z4h/zfcRJIGxDV1TqbTR2lnwjK3qEaoTFOcSOKpDBY4=; b=O ssQNtC82y5PzSh7NKQ9Pc+9v2HVa5oQr7n+yNvUThBV5VS3M9B8drw/FDWBA2gj8 GQm3TlZU0kUu3SUXlUBm6NmOGNVvxZ2xQCaJn3ynq5xzPxstBClaYTXyz5of7VP6 +ZILQojFSJfrl0qCZ3POO3lYPLw9NeePs/M/wQsxbypbKIEHsnOixeotvxwnUv4y MyWbDPtLikj2j6dFv3/VShAmIiULF+0BrS15WInFYnYAMCA/qtWsH3+v74LT72D9 UHCHxk4fV4KCU2kDQ2Ue1+sCZT3N4lq1tp4FPPgCJEYCtR+3GZ6nOHPF4sJqmcJY CxZ4dh7KdKbcsOBR37gkA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1744169677; x=1744256077; bh=z 4h/zfcRJIGxDV1TqbTR2lnwjK3qEaoTFOcSOKpDBY4=; b=D8zA4v0jcvqaKdj4g /ceyIstwHniBlhbsuI7t+ELstio25QW9jn3vF3HRpTxzEAdrg3XABDBfcTxLS+fY Lfx9hZ6Yt3biIYrZXSQNwRK/gsTwzvE0DWkk8LVRP/qG/FAGfPD6pCg/f2v37qkg bjEvDrwrN6jYLRwPLCOjyHxdsTl3qSStOz5Oz3D5i6aednEufZO1Jc34OJArsE5p v1BFC4tUBNbGHohaNganGtsugCEAXX1ZgA8zrli8S+QPWWgDBnIOOiWAlf7UPhe2 8GKiK8rdUpkrJtQrxB59vHR1YAKLCMlw2rSm42FgIx0pwXHuS/xhJrVB3Yx2UERR /Sn8g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvtdegledvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffuc dljedtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhm peffrghnihgvlhcuighuuceougiguhesugiguhhuuhdrgiihiieqnecuggftrfgrthhtvg hrnhepgfefgfegjefhudeikedvueetffelieefuedvhfehjeeljeejkefgffeghfdttdet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepugiguh esugiguhhuuhdrgiihiidpnhgspghrtghpthhtohepudegpdhmohguvgepshhmthhpohhu thdprhgtphhtthhopegrnhgurhhiiheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprg hstheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepuggrnhhivghlsehiohhgvggrrhgs ohigrdhnvghtpdhrtghpthhtohepjhhohhhnrdhfrghsthgrsggvnhgusehgmhgrihhlrd gtohhmpdhrtghpthhtohepmhgrrhhtihhnrdhlrghusehlihhnuhigrdguvghvpdhrtghp thhtohepvgguugihiiekjeesghhmrghilhdrtghomhdprhgtphhtthhopehsohhngheskh gvrhhnvghlrdhorhhgpdhrtghpthhtohephihonhhghhhonhhgrdhsohhngheslhhinhhu gidruggvvhdprhgtphhtthhopehkphhsihhnghhhsehkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 8 Apr 2025 23:34:35 -0400 (EDT) From: Daniel Xu To: andrii@kernel.org, ast@kernel.org, daniel@iogearbox.net Cc: john.fastabend@gmail.com, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC bpf-next 01/13] bpf: Move bpf_prog_ctx_arg_info_init() body into header Date: Tue, 8 Apr 2025 21:33:56 -0600 Message-ID: <25332b926db78702c59e6907462fed547360e6d3.1744169424.git.dxu@dxuuu.xyz> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" In an effort to reduce the amount of external references into verifier.c, move the body of this function into the header, as it's quite small. Signed-off-by: Daniel Xu --- include/linux/bpf.h | 12 ++++++++++-- kernel/bpf/verifier.c | 9 --------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 3f0cc89c0622..f1c5356dc099 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -1976,8 +1977,15 @@ static inline void bpf_struct_ops_desc_release(struc= t bpf_struct_ops_desc *st_op =20 #endif =20 -int bpf_prog_ctx_arg_info_init(struct bpf_prog *prog, - const struct bpf_ctx_arg_aux *info, u32 cnt); +static inline int bpf_prog_ctx_arg_info_init(struct bpf_prog *prog, + const struct bpf_ctx_arg_aux *info, + u32 cnt) +{ + prog->aux->ctx_arg_info =3D kmemdup_array(info, cnt, sizeof(*info), GFP_K= ERNEL); + prog->aux->ctx_arg_info_size =3D cnt; + + return prog->aux->ctx_arg_info ? 0 : -ENOMEM; +} =20 #if defined(CONFIG_CGROUP_BPF) && defined(CONFIG_BPF_LSM) int bpf_trampoline_link_cgroup_shim(struct bpf_prog *prog, diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 54c6953a8b84..4a60e2d7c10f 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -22895,15 +22895,6 @@ static void print_verification_stats(struct bpf_ve= rifier_env *env) env->peak_states, env->longest_mark_read_walk); } =20 -int bpf_prog_ctx_arg_info_init(struct bpf_prog *prog, - const struct bpf_ctx_arg_aux *info, u32 cnt) -{ - prog->aux->ctx_arg_info =3D kmemdup_array(info, cnt, sizeof(*info), GFP_K= ERNEL); - prog->aux->ctx_arg_info_size =3D cnt; - - return prog->aux->ctx_arg_info ? 0 : -ENOMEM; -} - static int check_struct_ops_btf_id(struct bpf_verifier_env *env) { const struct btf_type *t, *func_proto; --=20 2.47.1 From nobody Sat Feb 7 15:40:11 2026 Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (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 098C01C3BEB; Wed, 9 Apr 2025 03:34:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744169683; cv=none; b=RDZvx8ZP5VQHY0k/LZnH8k24ZhfUK60CoZD0RIZqDiMcEMvxKrV7q7cXaEmi8jP5ufUvfvpBDWTEP6VuMpkE0JYVIAJhH/UyMLSKpPgk6C21QGo3OZv0wAjTwTmx2bOhreIWpX59b+uwgZ3o5Gjv4Tol3XIDyBe93+Bp5HKJnMY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744169683; c=relaxed/simple; bh=wY817n5DAPTA69dGxk/O2TEaMD8JtgdlVKaGyQPbU+g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ELSqY7P85J4EsS1fRr4LUBjBLHQWexcREdVEG5XHPBr981RJy/mafSZS8yET7xqv0QKWIFvjNhaYDvj8bFfT8Eafx0wBHeK4Yd1r51dxuCTS+r0CjL9X6SfZH5Gmmepi6ZDeavtMRRCHSK2bF7YtmMjVxvtqkjhOellE09h6Q40= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz; spf=pass smtp.mailfrom=dxuuu.xyz; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b=hZTONJY2; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Vh+FLYGp; arc=none smtp.client-ip=103.168.172.151 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="hZTONJY2"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Vh+FLYGp" Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfout.phl.internal (Postfix) with ESMTP id F34F213800F9; Tue, 8 Apr 2025 23:34:39 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Tue, 08 Apr 2025 23:34:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1744169679; x= 1744256079; bh=E8nk+vsjkr6nE/4WKh08oD2AN8Uktz4WeTY/DkruzE0=; b=h ZTONJY2BEeWCrlPb/I7nLUKo3oaJbbFczCqj2aWHbdHvOY8JzcmQFQzhPY/n8zVF r8etSeKUdACOs3qaTm9Asv+fjvqOA3bgsjlHdzJVtdeSQfCSN9b1Oru/KWA0Bzrp 6fi7jv0XIeExX4a0v6b/+vzjOIrUCBFi4hbedb2E58Wt0rdiI+oU1ft/XdpHikF7 xk796hwZ6wV3zAk5UXHOF8kesSyI9J8r7p9/bJfYfKhfsdnI3Iheocb26vJTgBjl qKc0KVw72A+hDEwC/xex0dA7LErLzyRxoPA7HQ+Vy+VnlhXLlGax+KwbjMBbnx1I zqGRt+Pan77nGC78ulJaw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1744169679; x=1744256079; bh=E 8nk+vsjkr6nE/4WKh08oD2AN8Uktz4WeTY/DkruzE0=; b=Vh+FLYGpN7KNdc3nS aD5dqwbvYIoSzOjhuHQrx/gR824hBL81JpxipWvrHpLU5YGqaPeWyyHR/FMl/13R mqPN5/lks3jVghUnA0ETsZUW6q45eNcWS+VQxTgKMCgUzlzlpE+IL+qo38ZfZneF nZizYhL1gRKaPb/Sn1V4Ue4lKPYfJ2T1a4URwBJBebRvU+9/AnZbH4T96Ig5corJ wSqNqyRxoBt7iKcRtKSbMHFuB1kMd+Rb6CyTUrf8pzntOSz8PxVEmB1eq5fevBkz Sc1qm1kpdbtnPslW2V/183zMsOAjKV/WyW36nLIfS4yj3n7Gw9V2gj3VQa3J3/Jo VY4TQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvtdegledvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffuc dljedtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhm peffrghnihgvlhcuighuuceougiguhesugiguhhuuhdrgiihiieqnecuggftrfgrthhtvg hrnhepgfefgfegjefhudeikedvueetffelieefuedvhfehjeeljeejkefgffeghfdttdet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepugiguh esugiguhhuuhdrgiihiidpnhgspghrtghpthhtohepudegpdhmohguvgepshhmthhpohhu thdprhgtphhtthhopegrnhgurhhiiheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprg hstheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepmhgrrhhtihhnrdhlrghusehlihhn uhigrdguvghvpdhrtghpthhtohepuggrnhhivghlsehiohhgvggrrhgsohigrdhnvghtpd hrtghpthhtohepvgguugihiiekjeesghhmrghilhdrtghomhdprhgtphhtthhopehsohhn gheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohephihonhhghhhonhhgrdhsohhngheslh hinhhugidruggvvhdprhgtphhtthhopehjohhhnhdrfhgrshhtrggsvghnugesghhmrghi lhdrtghomhdprhgtphhtthhopehkphhsihhnghhhsehkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 8 Apr 2025 23:34:37 -0400 (EDT) From: Daniel Xu To: andrii@kernel.org, ast@kernel.org, martin.lau@linux.dev, daniel@iogearbox.net Cc: eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC bpf-next 02/13] bpf: Move BTF related globals out of verifier.c Date: Tue, 8 Apr 2025 21:33:57 -0600 Message-ID: X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Continuing with the effort to make verifier.c a leaf node, this commit moves out bpf_verifier_lock, btf_vmlinux, and bpf_get_btf_vmlinux(). These can be owned by btf.c (perhaps rightly so). Signed-off-by: Daniel Xu --- include/linux/btf.h | 4 ++++ kernel/bpf/btf.c | 21 +++++++++++++++++++-- kernel/bpf/verifier.c | 20 +++----------------- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/include/linux/btf.h b/include/linux/btf.h index ebc0c0c9b944..c51032659c58 100644 --- a/include/linux/btf.h +++ b/include/linux/btf.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include =20 @@ -141,6 +142,9 @@ struct btf_struct_metas { =20 extern const struct file_operations btf_fops; =20 +extern struct mutex btf_mutex; +extern struct btf *btf_vmlinux; + const char *btf_get_name(const struct btf *btf); void btf_get(struct btf *btf); void btf_put(struct btf *btf); diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 16ba36f34dfa..5b38c90e1184 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -563,6 +563,18 @@ s32 btf_find_by_name_kind(const struct btf *btf, const= char *name, u8 kind) return -ENOENT; } =20 +struct btf *bpf_get_btf_vmlinux(void) +{ + if (!btf_vmlinux && IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) { + mutex_lock(&btf_mutex); + if (!btf_vmlinux) + btf_vmlinux =3D btf_parse_vmlinux(); + mutex_unlock(&btf_mutex); + } + return btf_vmlinux; +} +EXPORT_SYMBOL_GPL(bpf_get_btf_vmlinux); + s32 bpf_find_btf_id(const char *name, u32 kind, struct btf **btf_p) { struct btf *btf; @@ -5857,7 +5869,12 @@ static struct btf *btf_parse(const union bpf_attr *a= ttr, bpfptr_t uattr, u32 uat =20 extern char __start_BTF[]; extern char __stop_BTF[]; -extern struct btf *btf_vmlinux; + +DEFINE_MUTEX(btf_mutex); +EXPORT_SYMBOL_GPL(btf_mutex); + +struct btf *btf_vmlinux; +EXPORT_SYMBOL_GPL(btf_vmlinux); =20 #define BPF_MAP_TYPE(_id, _ops) #define BPF_LINK_TYPE(_id, _name) @@ -6252,7 +6269,7 @@ struct btf *btf_parse_vmlinux(void) if (IS_ERR(btf)) goto err_out; =20 - /* btf_parse_vmlinux() runs under bpf_verifier_lock */ + /* btf_parse_vmlinux() runs under btf_mutex */ bpf_ctx_convert.t =3D btf_type_by_id(btf, bpf_ctx_convert_btf_id[0]); err =3D btf_alloc_id(btf); if (err) { diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 4a60e2d7c10f..6ed302dab08b 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -345,14 +345,11 @@ struct bpf_kfunc_call_arg_meta { u64 mem_size; }; =20 -struct btf *btf_vmlinux; - static const char *btf_type_name(const struct btf *btf, u32 id) { return btf_name_by_offset(btf, btf_type_by_id(btf, id)->name_off); } =20 -static DEFINE_MUTEX(bpf_verifier_lock); static DEFINE_MUTEX(bpf_percpu_ma_lock); =20 __printf(2, 3) static void verbose(void *private_data, const char *fmt, ..= .) @@ -23518,17 +23515,6 @@ static int check_attach_btf_id(struct bpf_verifier= _env *env) return 0; } =20 -struct btf *bpf_get_btf_vmlinux(void) -{ - if (!btf_vmlinux && IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) { - mutex_lock(&bpf_verifier_lock); - if (!btf_vmlinux) - btf_vmlinux =3D btf_parse_vmlinux(); - mutex_unlock(&bpf_verifier_lock); - } - return btf_vmlinux; -} - /* * The add_fd_from_fd_array() is executed only if fd_array_cnt is non-zero= . In * this case expect that every file descriptor in the array is either a ma= p or @@ -23932,9 +23918,9 @@ int bpf_check(struct bpf_prog **prog, union bpf_att= r *attr, bpfptr_t uattr, __u3 =20 bpf_get_btf_vmlinux(); =20 - /* grab the mutex to protect few globals used by verifier */ + /* grab the mutex to protect BTF globals used by verifier */ if (!is_priv) - mutex_lock(&bpf_verifier_lock); + mutex_lock(&btf_mutex); =20 /* user could have requested verbose verifier output * and supplied buffer to store the verification trace @@ -24151,7 +24137,7 @@ int bpf_check(struct bpf_prog **prog, union bpf_att= r *attr, bpfptr_t uattr, __u3 module_put(env->attach_btf_mod); err_unlock: if (!is_priv) - mutex_unlock(&bpf_verifier_lock); + mutex_unlock(&btf_mutex); vfree(env->insn_aux_data); kvfree(env->insn_hist); err_free_env: --=20 2.47.1 From nobody Sat Feb 7 15:40:11 2026 Received: from fhigh-a4-smtp.messagingengine.com (fhigh-a4-smtp.messagingengine.com [103.168.172.155]) (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 01D0F1C8FB5; Wed, 9 Apr 2025 03:34:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744169684; cv=none; b=Er5rw0QsIm+hskrhOlfezL6CZLC0hTWAbk0t2jueGBBxfYQDftI5vuok+/2UYGjg0YH/8ScPPkh0EfOZsA6EbNx2haH77ai+tNGZXTvFbeLWssHTnfCMCzMWHKrEhVgt+6+PhePQJP3ubajphrk0tGihCLpbQWaOH8nFCvzWaSA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744169684; c=relaxed/simple; bh=WwB/iLj+kr+uR4r3HljA27uS98rQcwljoakqTDQY3QM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=joY1VLrtRObPU/wAL1OjtyMzDf4eN9Xih0u5AtII3kBKVxs8Miw+bDFRtWUuLT/spK5+GWJq2xlFD5XZ5iRErG/wLXKzKKD1V/aHx5+FU18/agUN6B5snmt3uHNMzBnWs+ZmIgvBlC2qxh8Ey4tnGiYDraEZWKYXPZ7ZgvoL4NM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz; spf=pass smtp.mailfrom=dxuuu.xyz; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b=kfqzsDZs; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Qer5rAQL; arc=none smtp.client-ip=103.168.172.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="kfqzsDZs"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Qer5rAQL" Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfhigh.phl.internal (Postfix) with ESMTP id 102CB1140252; Tue, 8 Apr 2025 23:34:42 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Tue, 08 Apr 2025 23:34:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1744169682; x= 1744256082; bh=2PzkHPaQng3j4OQOLko7zULD6UngdArPhuztPcHfJP0=; b=k fqzsDZsKIyr6TLxTmQHKMcqFskvC/rv1W3PVYYwjAQe+inFhezSAfnZ8vydOlqxH KGPOePD+By4SHRR2J8l/uSjwJmRG5bm/QSQI1/xsXBnEgDRmfeqv4Mxty2gFWBLc ZYmG+DrokwY2GEkZmcdLw8yCGFkcL5qnWjU9nV87jfgS+HhAAxhEXaIqJcvq2EcH O0AwdYB+xHP+uYLpEXDq2dRd3US4zquSfacFFqX93pYa30j5I/5SVAnA1MLscXWw sKQa2z5QpvNmvIWb+qE8q2IDjz/STxSR5c9iCbXHWsbtiw/p1jvId+11X/9eiolI DBWrupm4he+ZxCvogTLjA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1744169682; x=1744256082; bh=2 PzkHPaQng3j4OQOLko7zULD6UngdArPhuztPcHfJP0=; b=Qer5rAQLrg4GVv9hY UOryhemJ+pAsPGWNpq6ur3hRiKmpfCrXPIM1clcCj0XC8yKEXj47uld8RN9E1ws3 xM9+ObFGvCl3g+K1SU4CuDNdqZgIz7C9DQOJybL5nHw7FFPSW7+rwSZviYKVPS8a 5Ltdxh7x2pe/xnzsGO4OF/ki23/KQ3BfI6iPNAYEsA9CMOatmO+/muK4xMvj52Q2 xlZACcWF36UG5nuxr33LhQxJj1rCDGWv9yY7cAhwBuR+84qvXAANGgsXkBcAt8Av fiUYtGsYPwLsWd58zCUsxbfdGGLSk//V0WXY3BhZ7npXGhwA+htrK9a9D/6oM9pB MpcEA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvtdegledvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffuc dljedtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhm peffrghnihgvlhcuighuuceougiguhesugiguhhuuhdrgiihiieqnecuggftrfgrthhtvg hrnhepgfefgfegjefhudeikedvueetffelieefuedvhfehjeeljeejkefgffeghfdttdet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepugiguh esugiguhhuuhdrgiihiidpnhgspghrtghpthhtohepudegpdhmohguvgepshhmthhpohhu thdprhgtphhtthhopegrnhgurhhiiheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprg hstheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepuggrnhhivghlsehiohhgvggrrhgs ohigrdhnvghtpdhrtghpthhtohepjhhohhhnrdhfrghsthgrsggvnhgusehgmhgrihhlrd gtohhmpdhrtghpthhtohepmhgrrhhtihhnrdhlrghusehlihhnuhigrdguvghvpdhrtghp thhtohepvgguugihiiekjeesghhmrghilhdrtghomhdprhgtphhtthhopehsohhngheskh gvrhhnvghlrdhorhhgpdhrtghpthhtohephihonhhghhhonhhgrdhsohhngheslhhinhhu gidruggvvhdprhgtphhtthhopehkphhsihhnghhhsehkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 8 Apr 2025 23:34:40 -0400 (EDT) From: Daniel Xu To: andrii@kernel.org, ast@kernel.org, daniel@iogearbox.net Cc: john.fastabend@gmail.com, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC bpf-next 03/13] bpf: Move percpu memory allocator definition into core Date: Tue, 8 Apr 2025 21:33:58 -0600 Message-ID: <20016bd97ab4aa47c4c49f9e46bf6ac0b4c4a124.1744169424.git.dxu@dxuuu.xyz> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The BPF percpu memory allocator is used from multiple places. So move it into the core and have verifier.c simply consume it. Signed-off-by: Daniel Xu --- include/linux/bpf.h | 2 +- kernel/bpf/core.c | 6 ++++++ kernel/bpf/verifier.c | 3 --- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index f1c5356dc099..8e26141f3e7e 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -64,7 +64,7 @@ extern struct idr btf_idr; extern spinlock_t btf_idr_lock; extern struct kobject *btf_kobj; extern struct bpf_mem_alloc bpf_global_ma, bpf_global_percpu_ma; -extern bool bpf_global_ma_set; +extern bool bpf_global_ma_set, bpf_global_percpu_ma_set; =20 typedef u64 (*bpf_callback_t)(u64, u64, u64, u64, u64); typedef int (*bpf_iter_init_seq_priv_t)(void *private_data, diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index ba6b6118cf50..80ba83cb6350 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -68,6 +68,12 @@ struct bpf_mem_alloc bpf_global_ma; bool bpf_global_ma_set; =20 +struct bpf_mem_alloc bpf_global_percpu_ma; +EXPORT_SYMBOL_GPL(bpf_global_percpu_ma); + +bool bpf_global_percpu_ma_set; +EXPORT_SYMBOL_GPL(bpf_global_percpu_ma_set); + /* No hurry in this branch * * Exported for the bpf jit load helper. diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 6ed302dab08b..322c1674b626 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -44,9 +44,6 @@ static const struct bpf_verifier_ops * const bpf_verifier= _ops[] =3D { #undef BPF_LINK_TYPE }; =20 -struct bpf_mem_alloc bpf_global_percpu_ma; -static bool bpf_global_percpu_ma_set; - /* bpf_check() is a static code analyzer that walks eBPF program * instruction by instruction and updates register/stack state. * All paths of conditional branches are analyzed until 'bpf_exit' insn. --=20 2.47.1 From nobody Sat Feb 7 15:40:11 2026 Received: from fhigh-a4-smtp.messagingengine.com (fhigh-a4-smtp.messagingengine.com [103.168.172.155]) (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 025FD1B0F19; Wed, 9 Apr 2025 03:34:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744169688; cv=none; b=GyE1yFEYteY5EN6dEOcwvh1GDtjbf2naDLNbv3li7FN5RlE6UxPIYcXYTM3fVlJpab3IdusXVm4J+MqHwwUcecDejuMRDky5dkSrIf60NshC8AxB5VsolYambnZsB839dyP4Wnxyfvt2b+DNRvtYDtATtw3SaLruIIE0pXjd+m0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744169688; c=relaxed/simple; bh=QXr34y1BBnk95UOhAjZL1nmam+j0Fdcl94+3BfUENI0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uquL6QMHUCMpf/Gmh71PatDzjUb9EZbog0miyezriODFzvuA3lUbaxtLwax+TK2ouCf2Zt8x0NhRpZgijlHmbKRJbyTAwjO+IqJcsPCiJ6kIXs4VmILLWPOyYkjVRxSE28UL/GKVXvXbvpvPJg+Q5EGHd7Kzs/2rXxepxVd0w3I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz; spf=pass smtp.mailfrom=dxuuu.xyz; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b=D9hngyZa; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=mQ9JDIIv; arc=none smtp.client-ip=103.168.172.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="D9hngyZa"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="mQ9JDIIv" Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfhigh.phl.internal (Postfix) with ESMTP id F32C511401EC; Tue, 8 Apr 2025 23:34:43 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Tue, 08 Apr 2025 23:34:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1744169683; x= 1744256083; bh=OM4hK3F4t50b4B6ugerD2gic1tcnPFDEvF+QwAo4ZqA=; b=D 9hngyZaXk4RZ76LoqaTYboTmAHmENJ3fpjq2h6M4W4PskjI3mky1sSlIH+eSujg0 l9AgEUqOd7PLONNzNtV/m70NvKpFQCnn8H+mow84OBwG7XNNsp/04pcouwC7xKW+ NSjKbIwOb4HWr1EvZmL8aWbZCZPGU7fVKVK5fpTM2wpaQflaZray+zCwCO/bmvu4 fIeSW7O71mSSpkpr8/0Wrce2//Wvv85dvrbi1FTI4TcVtDA0APkzKYNIfVq/qJsp afnfQEEnaS3FGCV7vWwNZ/UIw6DyzKLCkZjwexHgHEFpXHmJDI01tsfOb3xmZM7B A+mLo6kd4eTd2ctwYodGg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1744169683; x=1744256083; bh=O M4hK3F4t50b4B6ugerD2gic1tcnPFDEvF+QwAo4ZqA=; b=mQ9JDIIvS8zcFEiw4 LKu62FmfpRk+SdSFf+0/EeVKZtvGcw8rqFrqubFZ2mBSt8fdojn7DL1Q/AUefylp 16u5GvtD7JFKvbBlc5M24nlTXOiB6xdRhUp8JPAHuDYSGXynMJQtMmfCuXWTWfsn Pauz1DCzy8HSseN9wnL4nOiQrQkngLSbKswe4wKZMwgN/oX50uTM6LN8k5u5iknZ F7qid1xeTYcUXayYDlH6jytpkEDHojpzt28T6V2QVMUrKCDn+61DVXfWdxq5XLaO L492T8gD4jGXmX9nZFQqxGfP5+hY+XJdhrdTR71Uqr1pVGo0SUxrhWGl8NGyGM1m STttw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvtdegledvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffuc dljedtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhm peffrghnihgvlhcuighuuceougiguhesugiguhhuuhdrgiihiieqnecuggftrfgrthhtvg hrnhepgfefgfegjefhudeikedvueetffelieefuedvhfehjeeljeejkefgffeghfdttdet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepugiguh esugiguhhuuhdrgiihiidpnhgspghrtghpthhtohepudegpdhmohguvgepshhmthhpohhu thdprhgtphhtthhopegrnhgurhhiiheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprg hstheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepuggrnhhivghlsehiohhgvggrrhgs ohigrdhnvghtpdhrtghpthhtohepjhhohhhnrdhfrghsthgrsggvnhgusehgmhgrihhlrd gtohhmpdhrtghpthhtohepmhgrrhhtihhnrdhlrghusehlihhnuhigrdguvghvpdhrtghp thhtohepvgguugihiiekjeesghhmrghilhdrtghomhdprhgtphhtthhopehsohhngheskh gvrhhnvghlrdhorhhgpdhrtghpthhtohephihonhhghhhonhhgrdhsohhngheslhhinhhu gidruggvvhdprhgtphhtthhopehkphhsihhnghhhsehkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 8 Apr 2025 23:34:42 -0400 (EDT) From: Daniel Xu To: andrii@kernel.org, ast@kernel.org, daniel@iogearbox.net Cc: john.fastabend@gmail.com, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC bpf-next 04/13] bpf: Move bpf_check_attach_target() to core Date: Tue, 8 Apr 2025 21:33:59 -0600 Message-ID: <9448dae93bf91b62fb6e097cf783d0277fdeb542.1744169424.git.dxu@dxuuu.xyz> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This routine is used in a few other places in BPF subsystem. In an effort to make verifier.c a leaf node, move the definition as well as some other single use helpers into core. Signed-off-by: Daniel Xu --- include/linux/bpf.h | 6 + include/linux/bpf_verifier.h | 5 - kernel/bpf/core.c | 368 +++++++++++++++++++++++++++++++++++ kernel/bpf/verifier.c | 363 ---------------------------------- 4 files changed, 374 insertions(+), 368 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 8e26141f3e7e..e0bd78ff1540 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -2002,6 +2002,12 @@ static inline void bpf_trampoline_unlink_cgroup_shim= (struct bpf_prog *prog) } #endif =20 +int bpf_check_attach_target(struct bpf_verifier_log *log, + const struct bpf_prog *prog, + const struct bpf_prog *tgt_prog, + u32 btf_id, + struct bpf_attach_target_info *tgt_info); + struct bpf_array { struct bpf_map map; u32 elem_size; diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h index 9734544b6957..f61f5429647a 100644 --- a/include/linux/bpf_verifier.h +++ b/include/linux/bpf_verifier.h @@ -879,11 +879,6 @@ static inline void bpf_trampoline_unpack_key(u64 key, = u32 *obj_id, u32 *btf_id) *btf_id =3D key & 0x7FFFFFFF; } =20 -int bpf_check_attach_target(struct bpf_verifier_log *log, - const struct bpf_prog *prog, - const struct bpf_prog *tgt_prog, - u32 btf_id, - struct bpf_attach_target_info *tgt_info); void bpf_free_kfunc_btf_tab(struct bpf_kfunc_btf_tab *tab); =20 int mark_chain_precision(struct bpf_verifier_env *env, int regno); diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 80ba83cb6350..aaf0841140c0 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -38,6 +38,8 @@ #include #include #include +#include +#include =20 #include #include @@ -74,6 +76,372 @@ EXPORT_SYMBOL_GPL(bpf_global_percpu_ma); bool bpf_global_percpu_ma_set; EXPORT_SYMBOL_GPL(bpf_global_percpu_ma_set); =20 +/* list of non-sleepable functions that are otherwise on + * ALLOW_ERROR_INJECTION list + */ +BTF_SET_START(btf_non_sleepable_error_inject) +/* Three functions below can be called from sleepable and non-sleepable co= ntext. + * Assume non-sleepable from bpf safety point of view. + */ +BTF_ID(func, __filemap_add_folio) +#ifdef CONFIG_FAIL_PAGE_ALLOC +BTF_ID(func, should_fail_alloc_page) +#endif +#ifdef CONFIG_FAILSLAB +BTF_ID(func, should_failslab) +#endif +BTF_SET_END(btf_non_sleepable_error_inject) + +#define SECURITY_PREFIX "security_" + +static int check_attach_modify_return(unsigned long addr, const char *func= _name) +{ + if (within_error_injection_list(addr) || + !strncmp(SECURITY_PREFIX, func_name, sizeof(SECURITY_PREFIX) - 1)) + return 0; + + return -EINVAL; +} + + +static int check_non_sleepable_error_inject(u32 btf_id) +{ + return btf_id_set_contains(&btf_non_sleepable_error_inject, btf_id); +} + + +int bpf_check_attach_target(struct bpf_verifier_log *log, + const struct bpf_prog *prog, + const struct bpf_prog *tgt_prog, + u32 btf_id, + struct bpf_attach_target_info *tgt_info) +{ + bool prog_extension =3D prog->type =3D=3D BPF_PROG_TYPE_EXT; + bool prog_tracing =3D prog->type =3D=3D BPF_PROG_TYPE_TRACING; + char trace_symbol[KSYM_SYMBOL_LEN]; + const char prefix[] =3D "btf_trace_"; + struct bpf_raw_event_map *btp; + int ret =3D 0, subprog =3D -1, i; + const struct btf_type *t; + bool conservative =3D true; + const char *tname, *fname; + struct btf *btf; + long addr =3D 0; + struct module *mod =3D NULL; + + if (!btf_id) { + bpf_log(log, "Tracing programs must provide btf_id\n"); + return -EINVAL; + } + btf =3D tgt_prog ? tgt_prog->aux->btf : prog->aux->attach_btf; + if (!btf) { + bpf_log(log, + "FENTRY/FEXIT program can only be attached to another program annotated= with BTF\n"); + return -EINVAL; + } + t =3D btf_type_by_id(btf, btf_id); + if (!t) { + bpf_log(log, "attach_btf_id %u is invalid\n", btf_id); + return -EINVAL; + } + tname =3D btf_name_by_offset(btf, t->name_off); + if (!tname) { + bpf_log(log, "attach_btf_id %u doesn't have a name\n", btf_id); + return -EINVAL; + } + if (tgt_prog) { + struct bpf_prog_aux *aux =3D tgt_prog->aux; + bool tgt_changes_pkt_data; + bool tgt_might_sleep; + + if (bpf_prog_is_dev_bound(prog->aux) && + !bpf_prog_dev_bound_match(prog, tgt_prog)) { + bpf_log(log, "Target program bound device mismatch"); + return -EINVAL; + } + + for (i =3D 0; i < aux->func_info_cnt; i++) + if (aux->func_info[i].type_id =3D=3D btf_id) { + subprog =3D i; + break; + } + if (subprog =3D=3D -1) { + bpf_log(log, "Subprog %s doesn't exist\n", tname); + return -EINVAL; + } + if (aux->func && aux->func[subprog]->aux->exception_cb) { + bpf_log(log, + "%s programs cannot attach to exception callback\n", + prog_extension ? "Extension" : "FENTRY/FEXIT"); + return -EINVAL; + } + conservative =3D aux->func_info_aux[subprog].unreliable; + if (prog_extension) { + if (conservative) { + bpf_log(log, + "Cannot replace static functions\n"); + return -EINVAL; + } + if (!prog->jit_requested) { + bpf_log(log, + "Extension programs should be JITed\n"); + return -EINVAL; + } + tgt_changes_pkt_data =3D aux->func + ? aux->func[subprog]->aux->changes_pkt_data + : aux->changes_pkt_data; + if (prog->aux->changes_pkt_data && !tgt_changes_pkt_data) { + bpf_log(log, + "Extension program changes packet data, while original does not\n"); + return -EINVAL; + } + + tgt_might_sleep =3D aux->func + ? aux->func[subprog]->aux->might_sleep + : aux->might_sleep; + if (prog->aux->might_sleep && !tgt_might_sleep) { + bpf_log(log, + "Extension program may sleep, while original does not\n"); + return -EINVAL; + } + } + if (!tgt_prog->jited) { + bpf_log(log, "Can attach to only JITed progs\n"); + return -EINVAL; + } + if (prog_tracing) { + if (aux->attach_tracing_prog) { + /* + * Target program is an fentry/fexit which is already attached + * to another tracing program. More levels of nesting + * attachment are not allowed. + */ + bpf_log(log, "Cannot nest tracing program attach more than once\n"); + return -EINVAL; + } + } else if (tgt_prog->type =3D=3D prog->type) { + /* + * To avoid potential call chain cycles, prevent attaching of a + * program extension to another extension. It's ok to attach + * fentry/fexit to extension program. + */ + bpf_log(log, "Cannot recursively attach\n"); + return -EINVAL; + } + if (tgt_prog->type =3D=3D BPF_PROG_TYPE_TRACING && + prog_extension && + (tgt_prog->expected_attach_type =3D=3D BPF_TRACE_FENTRY || + tgt_prog->expected_attach_type =3D=3D BPF_TRACE_FEXIT)) { + /* Program extensions can extend all program types + * except fentry/fexit. The reason is the following. + * The fentry/fexit programs are used for performance + * analysis, stats and can be attached to any program + * type. When extension program is replacing XDP function + * it is necessary to allow performance analysis of all + * functions. Both original XDP program and its program + * extension. Hence attaching fentry/fexit to + * BPF_PROG_TYPE_EXT is allowed. If extending of + * fentry/fexit was allowed it would be possible to create + * long call chain fentry->extension->fentry->extension + * beyond reasonable stack size. Hence extending fentry + * is not allowed. + */ + bpf_log(log, "Cannot extend fentry/fexit\n"); + return -EINVAL; + } + } else { + if (prog_extension) { + bpf_log(log, "Cannot replace kernel functions\n"); + return -EINVAL; + } + } + + switch (prog->expected_attach_type) { + case BPF_TRACE_RAW_TP: + if (tgt_prog) { + bpf_log(log, + "Only FENTRY/FEXIT progs are attachable to another BPF prog\n"); + return -EINVAL; + } + if (!btf_type_is_typedef(t)) { + bpf_log(log, "attach_btf_id %u is not a typedef\n", + btf_id); + return -EINVAL; + } + if (strncmp(prefix, tname, sizeof(prefix) - 1)) { + bpf_log(log, "attach_btf_id %u points to wrong type name %s\n", + btf_id, tname); + return -EINVAL; + } + tname +=3D sizeof(prefix) - 1; + + /* The func_proto of "btf_trace_##tname" is generated from typedef witho= ut argument + * names. Thus using bpf_raw_event_map to get argument names. + */ + btp =3D bpf_get_raw_tracepoint(tname); + if (!btp) + return -EINVAL; + fname =3D kallsyms_lookup((unsigned long)btp->bpf_func, NULL, NULL, NULL, + trace_symbol); + bpf_put_raw_tracepoint(btp); + + if (fname) + ret =3D btf_find_by_name_kind(btf, fname, BTF_KIND_FUNC); + + if (!fname || ret < 0) { + bpf_log(log, "Cannot find btf of tracepoint template, fall back to %s%s= .\n", + prefix, tname); + t =3D btf_type_by_id(btf, t->type); + if (!btf_type_is_ptr(t)) + /* should never happen in valid vmlinux build */ + return -EINVAL; + } else { + t =3D btf_type_by_id(btf, ret); + if (!btf_type_is_func(t)) + /* should never happen in valid vmlinux build */ + return -EINVAL; + } + + t =3D btf_type_by_id(btf, t->type); + if (!btf_type_is_func_proto(t)) + /* should never happen in valid vmlinux build */ + return -EINVAL; + + break; + case BPF_TRACE_ITER: + if (!btf_type_is_func(t)) { + bpf_log(log, "attach_btf_id %u is not a function\n", + btf_id); + return -EINVAL; + } + t =3D btf_type_by_id(btf, t->type); + if (!btf_type_is_func_proto(t)) + return -EINVAL; + ret =3D btf_distill_func_proto(log, btf, t, tname, &tgt_info->fmodel); + if (ret) + return ret; + break; + default: + if (!prog_extension) + return -EINVAL; + fallthrough; + case BPF_MODIFY_RETURN: + case BPF_LSM_MAC: + case BPF_LSM_CGROUP: + case BPF_TRACE_FENTRY: + case BPF_TRACE_FEXIT: + if (!btf_type_is_func(t)) { + bpf_log(log, "attach_btf_id %u is not a function\n", + btf_id); + return -EINVAL; + } + if (prog_extension && + btf_check_type_match(log, prog, btf, t)) + return -EINVAL; + t =3D btf_type_by_id(btf, t->type); + if (!btf_type_is_func_proto(t)) + return -EINVAL; + + if ((prog->aux->saved_dst_prog_type || prog->aux->saved_dst_attach_type)= && + (!tgt_prog || prog->aux->saved_dst_prog_type !=3D tgt_prog->type || + prog->aux->saved_dst_attach_type !=3D tgt_prog->expected_attach_typ= e)) + return -EINVAL; + + if (tgt_prog && conservative) + t =3D NULL; + + ret =3D btf_distill_func_proto(log, btf, t, tname, &tgt_info->fmodel); + if (ret < 0) + return ret; + + if (tgt_prog) { + if (subprog =3D=3D 0) + addr =3D (long) tgt_prog->bpf_func; + else + addr =3D (long) tgt_prog->aux->func[subprog]->bpf_func; + } else { + if (btf_is_module(btf)) { + mod =3D btf_try_get_module(btf); + if (mod) + addr =3D find_kallsyms_symbol_value(mod, tname); + else + addr =3D 0; + } else { + addr =3D kallsyms_lookup_name(tname); + } + if (!addr) { + module_put(mod); + bpf_log(log, + "The address of function %s cannot be found\n", + tname); + return -ENOENT; + } + } + + if (prog->sleepable) { + ret =3D -EINVAL; + switch (prog->type) { + case BPF_PROG_TYPE_TRACING: + + /* fentry/fexit/fmod_ret progs can be sleepable if they are + * attached to ALLOW_ERROR_INJECTION and are not in denylist. + */ + if (!check_non_sleepable_error_inject(btf_id) && + within_error_injection_list(addr)) + ret =3D 0; + /* fentry/fexit/fmod_ret progs can also be sleepable if they are + * in the fmodret id set with the KF_SLEEPABLE flag. + */ + else { + u32 *flags =3D btf_kfunc_is_modify_return(btf, btf_id, + prog); + + if (flags && (*flags & KF_SLEEPABLE)) + ret =3D 0; + } + break; + case BPF_PROG_TYPE_LSM: + /* LSM progs check that they are attached to bpf_lsm_*() funcs. + * Only some of them are sleepable. + */ + if (bpf_lsm_is_sleepable_hook(btf_id)) + ret =3D 0; + break; + default: + break; + } + if (ret) { + module_put(mod); + bpf_log(log, "%s is not sleepable\n", tname); + return ret; + } + } else if (prog->expected_attach_type =3D=3D BPF_MODIFY_RETURN) { + if (tgt_prog) { + module_put(mod); + bpf_log(log, "can't modify return codes of BPF programs\n"); + return -EINVAL; + } + ret =3D -EINVAL; + if (btf_kfunc_is_modify_return(btf, btf_id, prog) || + !check_attach_modify_return(addr, tname)) + ret =3D 0; + if (ret) { + module_put(mod); + bpf_log(log, "%s() is not modifiable\n", tname); + return ret; + } + } + + break; + } + tgt_info->tgt_addr =3D addr; + tgt_info->tgt_name =3D tname; + tgt_info->tgt_type =3D t; + tgt_info->tgt_mod =3D mod; + return 0; +} +EXPORT_SYMBOL_GPL(bpf_check_attach_target); + /* No hurry in this branch * * Exported for the bpf jit load helper. diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 322c1674b626..2b5e29ee8310 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -28,7 +28,6 @@ #include #include #include -#include #include =20 #include "disasm.h" @@ -22998,368 +22997,6 @@ static int check_struct_ops_btf_id(struct bpf_ver= ifier_env *env) return bpf_prog_ctx_arg_info_init(prog, st_ops_desc->arg_info[member_idx]= .info, st_ops_desc->arg_info[member_idx].cnt); } -#define SECURITY_PREFIX "security_" - -static int check_attach_modify_return(unsigned long addr, const char *func= _name) -{ - if (within_error_injection_list(addr) || - !strncmp(SECURITY_PREFIX, func_name, sizeof(SECURITY_PREFIX) - 1)) - return 0; - - return -EINVAL; -} - -/* list of non-sleepable functions that are otherwise on - * ALLOW_ERROR_INJECTION list - */ -BTF_SET_START(btf_non_sleepable_error_inject) -/* Three functions below can be called from sleepable and non-sleepable co= ntext. - * Assume non-sleepable from bpf safety point of view. - */ -BTF_ID(func, __filemap_add_folio) -#ifdef CONFIG_FAIL_PAGE_ALLOC -BTF_ID(func, should_fail_alloc_page) -#endif -#ifdef CONFIG_FAILSLAB -BTF_ID(func, should_failslab) -#endif -BTF_SET_END(btf_non_sleepable_error_inject) - -static int check_non_sleepable_error_inject(u32 btf_id) -{ - return btf_id_set_contains(&btf_non_sleepable_error_inject, btf_id); -} - -int bpf_check_attach_target(struct bpf_verifier_log *log, - const struct bpf_prog *prog, - const struct bpf_prog *tgt_prog, - u32 btf_id, - struct bpf_attach_target_info *tgt_info) -{ - bool prog_extension =3D prog->type =3D=3D BPF_PROG_TYPE_EXT; - bool prog_tracing =3D prog->type =3D=3D BPF_PROG_TYPE_TRACING; - char trace_symbol[KSYM_SYMBOL_LEN]; - const char prefix[] =3D "btf_trace_"; - struct bpf_raw_event_map *btp; - int ret =3D 0, subprog =3D -1, i; - const struct btf_type *t; - bool conservative =3D true; - const char *tname, *fname; - struct btf *btf; - long addr =3D 0; - struct module *mod =3D NULL; - - if (!btf_id) { - bpf_log(log, "Tracing programs must provide btf_id\n"); - return -EINVAL; - } - btf =3D tgt_prog ? tgt_prog->aux->btf : prog->aux->attach_btf; - if (!btf) { - bpf_log(log, - "FENTRY/FEXIT program can only be attached to another program annotated= with BTF\n"); - return -EINVAL; - } - t =3D btf_type_by_id(btf, btf_id); - if (!t) { - bpf_log(log, "attach_btf_id %u is invalid\n", btf_id); - return -EINVAL; - } - tname =3D btf_name_by_offset(btf, t->name_off); - if (!tname) { - bpf_log(log, "attach_btf_id %u doesn't have a name\n", btf_id); - return -EINVAL; - } - if (tgt_prog) { - struct bpf_prog_aux *aux =3D tgt_prog->aux; - bool tgt_changes_pkt_data; - bool tgt_might_sleep; - - if (bpf_prog_is_dev_bound(prog->aux) && - !bpf_prog_dev_bound_match(prog, tgt_prog)) { - bpf_log(log, "Target program bound device mismatch"); - return -EINVAL; - } - - for (i =3D 0; i < aux->func_info_cnt; i++) - if (aux->func_info[i].type_id =3D=3D btf_id) { - subprog =3D i; - break; - } - if (subprog =3D=3D -1) { - bpf_log(log, "Subprog %s doesn't exist\n", tname); - return -EINVAL; - } - if (aux->func && aux->func[subprog]->aux->exception_cb) { - bpf_log(log, - "%s programs cannot attach to exception callback\n", - prog_extension ? "Extension" : "FENTRY/FEXIT"); - return -EINVAL; - } - conservative =3D aux->func_info_aux[subprog].unreliable; - if (prog_extension) { - if (conservative) { - bpf_log(log, - "Cannot replace static functions\n"); - return -EINVAL; - } - if (!prog->jit_requested) { - bpf_log(log, - "Extension programs should be JITed\n"); - return -EINVAL; - } - tgt_changes_pkt_data =3D aux->func - ? aux->func[subprog]->aux->changes_pkt_data - : aux->changes_pkt_data; - if (prog->aux->changes_pkt_data && !tgt_changes_pkt_data) { - bpf_log(log, - "Extension program changes packet data, while original does not\n"); - return -EINVAL; - } - - tgt_might_sleep =3D aux->func - ? aux->func[subprog]->aux->might_sleep - : aux->might_sleep; - if (prog->aux->might_sleep && !tgt_might_sleep) { - bpf_log(log, - "Extension program may sleep, while original does not\n"); - return -EINVAL; - } - } - if (!tgt_prog->jited) { - bpf_log(log, "Can attach to only JITed progs\n"); - return -EINVAL; - } - if (prog_tracing) { - if (aux->attach_tracing_prog) { - /* - * Target program is an fentry/fexit which is already attached - * to another tracing program. More levels of nesting - * attachment are not allowed. - */ - bpf_log(log, "Cannot nest tracing program attach more than once\n"); - return -EINVAL; - } - } else if (tgt_prog->type =3D=3D prog->type) { - /* - * To avoid potential call chain cycles, prevent attaching of a - * program extension to another extension. It's ok to attach - * fentry/fexit to extension program. - */ - bpf_log(log, "Cannot recursively attach\n"); - return -EINVAL; - } - if (tgt_prog->type =3D=3D BPF_PROG_TYPE_TRACING && - prog_extension && - (tgt_prog->expected_attach_type =3D=3D BPF_TRACE_FENTRY || - tgt_prog->expected_attach_type =3D=3D BPF_TRACE_FEXIT)) { - /* Program extensions can extend all program types - * except fentry/fexit. The reason is the following. - * The fentry/fexit programs are used for performance - * analysis, stats and can be attached to any program - * type. When extension program is replacing XDP function - * it is necessary to allow performance analysis of all - * functions. Both original XDP program and its program - * extension. Hence attaching fentry/fexit to - * BPF_PROG_TYPE_EXT is allowed. If extending of - * fentry/fexit was allowed it would be possible to create - * long call chain fentry->extension->fentry->extension - * beyond reasonable stack size. Hence extending fentry - * is not allowed. - */ - bpf_log(log, "Cannot extend fentry/fexit\n"); - return -EINVAL; - } - } else { - if (prog_extension) { - bpf_log(log, "Cannot replace kernel functions\n"); - return -EINVAL; - } - } - - switch (prog->expected_attach_type) { - case BPF_TRACE_RAW_TP: - if (tgt_prog) { - bpf_log(log, - "Only FENTRY/FEXIT progs are attachable to another BPF prog\n"); - return -EINVAL; - } - if (!btf_type_is_typedef(t)) { - bpf_log(log, "attach_btf_id %u is not a typedef\n", - btf_id); - return -EINVAL; - } - if (strncmp(prefix, tname, sizeof(prefix) - 1)) { - bpf_log(log, "attach_btf_id %u points to wrong type name %s\n", - btf_id, tname); - return -EINVAL; - } - tname +=3D sizeof(prefix) - 1; - - /* The func_proto of "btf_trace_##tname" is generated from typedef witho= ut argument - * names. Thus using bpf_raw_event_map to get argument names. - */ - btp =3D bpf_get_raw_tracepoint(tname); - if (!btp) - return -EINVAL; - fname =3D kallsyms_lookup((unsigned long)btp->bpf_func, NULL, NULL, NULL, - trace_symbol); - bpf_put_raw_tracepoint(btp); - - if (fname) - ret =3D btf_find_by_name_kind(btf, fname, BTF_KIND_FUNC); - - if (!fname || ret < 0) { - bpf_log(log, "Cannot find btf of tracepoint template, fall back to %s%s= .\n", - prefix, tname); - t =3D btf_type_by_id(btf, t->type); - if (!btf_type_is_ptr(t)) - /* should never happen in valid vmlinux build */ - return -EINVAL; - } else { - t =3D btf_type_by_id(btf, ret); - if (!btf_type_is_func(t)) - /* should never happen in valid vmlinux build */ - return -EINVAL; - } - - t =3D btf_type_by_id(btf, t->type); - if (!btf_type_is_func_proto(t)) - /* should never happen in valid vmlinux build */ - return -EINVAL; - - break; - case BPF_TRACE_ITER: - if (!btf_type_is_func(t)) { - bpf_log(log, "attach_btf_id %u is not a function\n", - btf_id); - return -EINVAL; - } - t =3D btf_type_by_id(btf, t->type); - if (!btf_type_is_func_proto(t)) - return -EINVAL; - ret =3D btf_distill_func_proto(log, btf, t, tname, &tgt_info->fmodel); - if (ret) - return ret; - break; - default: - if (!prog_extension) - return -EINVAL; - fallthrough; - case BPF_MODIFY_RETURN: - case BPF_LSM_MAC: - case BPF_LSM_CGROUP: - case BPF_TRACE_FENTRY: - case BPF_TRACE_FEXIT: - if (!btf_type_is_func(t)) { - bpf_log(log, "attach_btf_id %u is not a function\n", - btf_id); - return -EINVAL; - } - if (prog_extension && - btf_check_type_match(log, prog, btf, t)) - return -EINVAL; - t =3D btf_type_by_id(btf, t->type); - if (!btf_type_is_func_proto(t)) - return -EINVAL; - - if ((prog->aux->saved_dst_prog_type || prog->aux->saved_dst_attach_type)= && - (!tgt_prog || prog->aux->saved_dst_prog_type !=3D tgt_prog->type || - prog->aux->saved_dst_attach_type !=3D tgt_prog->expected_attach_typ= e)) - return -EINVAL; - - if (tgt_prog && conservative) - t =3D NULL; - - ret =3D btf_distill_func_proto(log, btf, t, tname, &tgt_info->fmodel); - if (ret < 0) - return ret; - - if (tgt_prog) { - if (subprog =3D=3D 0) - addr =3D (long) tgt_prog->bpf_func; - else - addr =3D (long) tgt_prog->aux->func[subprog]->bpf_func; - } else { - if (btf_is_module(btf)) { - mod =3D btf_try_get_module(btf); - if (mod) - addr =3D find_kallsyms_symbol_value(mod, tname); - else - addr =3D 0; - } else { - addr =3D kallsyms_lookup_name(tname); - } - if (!addr) { - module_put(mod); - bpf_log(log, - "The address of function %s cannot be found\n", - tname); - return -ENOENT; - } - } - - if (prog->sleepable) { - ret =3D -EINVAL; - switch (prog->type) { - case BPF_PROG_TYPE_TRACING: - - /* fentry/fexit/fmod_ret progs can be sleepable if they are - * attached to ALLOW_ERROR_INJECTION and are not in denylist. - */ - if (!check_non_sleepable_error_inject(btf_id) && - within_error_injection_list(addr)) - ret =3D 0; - /* fentry/fexit/fmod_ret progs can also be sleepable if they are - * in the fmodret id set with the KF_SLEEPABLE flag. - */ - else { - u32 *flags =3D btf_kfunc_is_modify_return(btf, btf_id, - prog); - - if (flags && (*flags & KF_SLEEPABLE)) - ret =3D 0; - } - break; - case BPF_PROG_TYPE_LSM: - /* LSM progs check that they are attached to bpf_lsm_*() funcs. - * Only some of them are sleepable. - */ - if (bpf_lsm_is_sleepable_hook(btf_id)) - ret =3D 0; - break; - default: - break; - } - if (ret) { - module_put(mod); - bpf_log(log, "%s is not sleepable\n", tname); - return ret; - } - } else if (prog->expected_attach_type =3D=3D BPF_MODIFY_RETURN) { - if (tgt_prog) { - module_put(mod); - bpf_log(log, "can't modify return codes of BPF programs\n"); - return -EINVAL; - } - ret =3D -EINVAL; - if (btf_kfunc_is_modify_return(btf, btf_id, prog) || - !check_attach_modify_return(addr, tname)) - ret =3D 0; - if (ret) { - module_put(mod); - bpf_log(log, "%s() is not modifiable\n", tname); - return ret; - } - } - - break; - } - tgt_info->tgt_addr =3D addr; - tgt_info->tgt_name =3D tname; - tgt_info->tgt_type =3D t; - tgt_info->tgt_mod =3D mod; - return 0; -} =20 BTF_SET_START(btf_id_deny) BTF_ID_UNUSED --=20 2.47.1 From nobody Sat Feb 7 15:40:11 2026 Received: from fhigh-a4-smtp.messagingengine.com (fhigh-a4-smtp.messagingengine.com [103.168.172.155]) (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 E1F841D5CFE; Wed, 9 Apr 2025 03:34:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744169688; cv=none; b=UyRsoqjiDF++8a1aBhyIbHLkz3o9/ZGFmMpmdc8Ni47JRRSvDFCJClrJdGmz6XX50CX25pkuq6b505wgXQ+hgGj/+LTPZ1BI+SxkBUpv5OVL5IuRwYPcdSGxKFIi6qfIR//BMyNciH0fOZ3co6Q3dc7g53P+uqX2g76RAM6Ev6U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744169688; c=relaxed/simple; bh=RIZppefsU+3autn4NmcSi1RoSkrIV7WO4c4Uuqi9okg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MoXK2XK9UUygDNWZ1hKZiyPSkg07/CLYcfynj7y5yQ6SjXiZooA1zaxFrqmy4DAjtV7vzq6+o13L0/FhlDtsAETk1QnaByxKCcdcy82Knd6e9p44kOz0iCX5xRShvAlZ7aGJ2YcbCJ9745y+EFWmQ1s7r7MH0jI6fEFSxB2funE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz; spf=pass smtp.mailfrom=dxuuu.xyz; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b=M5QaLNvZ; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=ljteCJ2o; arc=none smtp.client-ip=103.168.172.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="M5QaLNvZ"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="ljteCJ2o" Received: from phl-compute-11.internal (phl-compute-11.phl.internal [10.202.2.51]) by mailfhigh.phl.internal (Postfix) with ESMTP id E845A1140255; Tue, 8 Apr 2025 23:34:45 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-11.internal (MEProxy); Tue, 08 Apr 2025 23:34:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1744169685; x= 1744256085; bh=PveBnY5/PTuYnXShL2+88mWJUuaL+VGQS4W+0t445Kc=; b=M 5QaLNvZAM7C8IHrA4QhTpe+73lSPTrfmzYYHIiMuSPefmQharaAXlTKd1OQUHPi/ GRznDJfaWrTZXPHcm8Dp96Gx56oen3Q+YVasekLv9dmOF0pbf+0g9Rg2WgHb6Tzr wieozc9DtdA9a3rBil0PG5d7I02keFTn6GRXQg2wx90OriRSZx4BRFE42f5l4Og6 x+aRsh00KlbkwBb9u0uwodOAphopH/LPW8eVCsEkksfWFmdDvT4qmJLIY7Hld/f+ n0UooSpR/72RHAVEj988cF3VkmEl9pVJgtfKu8K7O1F0K3JwmgTTiqQW9AbSGWWD DFiK6/1NogzitEisqTOZA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1744169685; x=1744256085; bh=P veBnY5/PTuYnXShL2+88mWJUuaL+VGQS4W+0t445Kc=; b=ljteCJ2oIWGqZqEQF HslpAjejrnlDOxexj1LPXE2gmcnQKP+iqfawNSwoAud5cQH4iLVjSBYDqpjBcgXu mAFRFvdNJVJUmF/zR/rjilI5mVBMFfj62S9pBJdLYQaoVCufugFaXEoTuhEPbAKD D9+O1msNT/L9sM3/K/tGNTlHZ/rILYc6k7+JMg7H/rTTTGqGQO5RioJ0vrpFAzrT cFXN2jO7HL541dwqpgVAkhbeCMWn5lwHWXRSIPjlCxBhOVagQTkCYWPAdmlHWFLO aNsTDe6N/xt6ebCrUw4GVFxdDkJzGEVMtYiKhZuNBwFcYuwOpYQzn2hPFglCXc4H 6e0aw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvtdegledvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffuc dljedtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhm peffrghnihgvlhcuighuuceougiguhesugiguhhuuhdrgiihiieqnecuggftrfgrthhtvg hrnhepgfefgfegjefhudeikedvueetffelieefuedvhfehjeeljeejkefgffeghfdttdet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepugiguh esugiguhhuuhdrgiihiidpnhgspghrtghpthhtohepudegpdhmohguvgepshhmthhpohhu thdprhgtphhtthhopegrnhgurhhiiheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprg hstheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepuggrnhhivghlsehiohhgvggrrhgs ohigrdhnvghtpdhrtghpthhtohepjhhohhhnrdhfrghsthgrsggvnhgusehgmhgrihhlrd gtohhmpdhrtghpthhtohepmhgrrhhtihhnrdhlrghusehlihhnuhigrdguvghvpdhrtghp thhtohepvgguugihiiekjeesghhmrghilhdrtghomhdprhgtphhtthhopehsohhngheskh gvrhhnvghlrdhorhhgpdhrtghpthhtohephihonhhghhhonhhgrdhsohhngheslhhinhhu gidruggvvhdprhgtphhtthhopehkphhsihhnghhhsehkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 8 Apr 2025 23:34:44 -0400 (EDT) From: Daniel Xu To: andrii@kernel.org, ast@kernel.org, daniel@iogearbox.net Cc: john.fastabend@gmail.com, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC bpf-next 05/13] bpf: Remove map_set_for_each_callback_args callback for maps Date: Tue, 8 Apr 2025 21:34:00 -0600 Message-ID: <21ca9709216aac7b7ab47e650f3491b8801613dd.1744169424.git.dxu@dxuuu.xyz> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Currently all iteratable maps (maps that define map_for_each_callback) use the default callback. In an effort to reduce the number of incoming references to verifier.c, just remove this level of indirection, as it's unused. Signed-off-by: Daniel Xu --- include/linux/bpf.h | 3 --- kernel/bpf/arraymap.c | 2 -- kernel/bpf/hashtab.c | 4 ---- kernel/bpf/verifier.c | 5 ++--- 4 files changed, 2 insertions(+), 12 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index e0bd78ff1540..1785901330b2 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -169,9 +169,6 @@ struct bpf_map_ops { const struct bpf_map *meta1); =20 =20 - int (*map_set_for_each_callback_args)(struct bpf_verifier_env *env, - struct bpf_func_state *caller, - struct bpf_func_state *callee); long (*map_for_each_callback)(struct bpf_map *map, bpf_callback_t callback_fn, void *callback_ctx, u64 flags); diff --git a/kernel/bpf/arraymap.c b/kernel/bpf/arraymap.c index eb28c0f219ee..e12224d479d0 100644 --- a/kernel/bpf/arraymap.c +++ b/kernel/bpf/arraymap.c @@ -800,7 +800,6 @@ const struct bpf_map_ops array_map_ops =3D { .map_check_btf =3D array_map_check_btf, .map_lookup_batch =3D generic_map_lookup_batch, .map_update_batch =3D generic_map_update_batch, - .map_set_for_each_callback_args =3D map_set_for_each_callback_args, .map_for_each_callback =3D bpf_for_each_array_elem, .map_mem_usage =3D array_map_mem_usage, .map_btf_id =3D &array_map_btf_ids[0], @@ -822,7 +821,6 @@ const struct bpf_map_ops percpu_array_map_ops =3D { .map_check_btf =3D array_map_check_btf, .map_lookup_batch =3D generic_map_lookup_batch, .map_update_batch =3D generic_map_update_batch, - .map_set_for_each_callback_args =3D map_set_for_each_callback_args, .map_for_each_callback =3D bpf_for_each_array_elem, .map_mem_usage =3D array_map_mem_usage, .map_btf_id =3D &array_map_btf_ids[0], diff --git a/kernel/bpf/hashtab.c b/kernel/bpf/hashtab.c index 5a5adc66b8e2..a91f08306682 100644 --- a/kernel/bpf/hashtab.c +++ b/kernel/bpf/hashtab.c @@ -2265,7 +2265,6 @@ const struct bpf_map_ops htab_map_ops =3D { .map_delete_elem =3D htab_map_delete_elem, .map_gen_lookup =3D htab_map_gen_lookup, .map_seq_show_elem =3D htab_map_seq_show_elem, - .map_set_for_each_callback_args =3D map_set_for_each_callback_args, .map_for_each_callback =3D bpf_for_each_hash_elem, .map_mem_usage =3D htab_map_mem_usage, BATCH_OPS(htab), @@ -2287,7 +2286,6 @@ const struct bpf_map_ops htab_lru_map_ops =3D { .map_delete_elem =3D htab_lru_map_delete_elem, .map_gen_lookup =3D htab_lru_map_gen_lookup, .map_seq_show_elem =3D htab_map_seq_show_elem, - .map_set_for_each_callback_args =3D map_set_for_each_callback_args, .map_for_each_callback =3D bpf_for_each_hash_elem, .map_mem_usage =3D htab_map_mem_usage, BATCH_OPS(htab_lru), @@ -2460,7 +2458,6 @@ const struct bpf_map_ops htab_percpu_map_ops =3D { .map_delete_elem =3D htab_map_delete_elem, .map_lookup_percpu_elem =3D htab_percpu_map_lookup_percpu_elem, .map_seq_show_elem =3D htab_percpu_map_seq_show_elem, - .map_set_for_each_callback_args =3D map_set_for_each_callback_args, .map_for_each_callback =3D bpf_for_each_hash_elem, .map_mem_usage =3D htab_map_mem_usage, BATCH_OPS(htab_percpu), @@ -2480,7 +2477,6 @@ const struct bpf_map_ops htab_lru_percpu_map_ops =3D { .map_delete_elem =3D htab_lru_map_delete_elem, .map_lookup_percpu_elem =3D htab_lru_percpu_map_lookup_percpu_elem, .map_seq_show_elem =3D htab_percpu_map_seq_show_elem, - .map_set_for_each_callback_args =3D map_set_for_each_callback_args, .map_for_each_callback =3D bpf_for_each_hash_elem, .map_mem_usage =3D htab_map_mem_usage, BATCH_OPS(htab_lru_percpu), diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 2b5e29ee8310..d3bb65f721c9 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -10638,13 +10638,12 @@ static int set_map_elem_callback_state(struct bpf= _verifier_env *env, =20 /* valid map_ptr and poison value does not matter */ map =3D insn_aux->map_ptr_state.map_ptr; - if (!map->ops->map_set_for_each_callback_args || - !map->ops->map_for_each_callback) { + if (!map->ops->map_for_each_callback) { verbose(env, "callback function not allowed for map\n"); return -ENOTSUPP; } =20 - err =3D map->ops->map_set_for_each_callback_args(env, caller, callee); + err =3D map_set_for_each_callback_args(env, caller, callee); if (err) return err; =20 --=20 2.47.1 From nobody Sat Feb 7 15:40:11 2026 Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (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 A77281D63F2; Wed, 9 Apr 2025 03:34:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744169690; cv=none; b=jbs0qxjIWjnZxmrjr8/NQgQ+b2AAL3EKpaj9wNFTbmAiJ0EAiiFh7SLE/dyCSB09/KqAQLqN/exFRUP2LVKGvmEJb5nE/EKfgto+7GD4MUA5a3jsN2brtJImC35UAdWLYOa325WkLIFYTd7yQ2qnRRBUzp3FqeoWR38zRgz9Haw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744169690; c=relaxed/simple; bh=oUssefEXTuCqXSOQfsTj9BCaoDU+LXcHBhU7+1208uI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=remZLcRF6DPh7m0CVlc1Ec+C25qhWd93aOKK6Ad7lGj7CuR6TQMTLyncRYlbxua4y+Fa60OCabmlsJMbicm6NS7d4dd6blaDE6x6aB5LQSgnDc5zqaBr0DINPlTOyFE5mTd5I+lutCCmieB06AeLLsFP0EKeuYSbc5mtSL/oC8E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz; spf=pass smtp.mailfrom=dxuuu.xyz; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b=KER+Jljr; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=IrmAc828; arc=none smtp.client-ip=103.168.172.151 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="KER+Jljr"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="IrmAc828" Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfout.phl.internal (Postfix) with ESMTP id BF21413801E2; Tue, 8 Apr 2025 23:34:47 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-12.internal (MEProxy); Tue, 08 Apr 2025 23:34:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1744169687; x= 1744256087; bh=5Fe1HL5mwA1ivcge9OaRh17cxWT60SpWc9Ewccp5/cQ=; b=K ER+Jljr7gGhoiLJkfXv65HeZ/plhwqSFos4cGKAjM55F3SfiVBOUI/BOWJ5R5HVk orpo6N5F6x2jlyC2yA/DSYx+JdZgdWMR3wlxTXRauiJ0IA2dzJJUroXJ9/wAp2D8 VI8SItTvweSsidBCjYV6A74CIxvmoI53s9mwDB6UeacvuwolkFeIgbmer6uq8rfa 9i9eRhDHDuSBgWu5GzhjrZgiLQwZrUK9HXnoVRsvw6uwKimcIQLYAZAAkFcP1zZp SKEGfHNtgP+3v3V9Z/E60jw8TBVDiIiTbeCrGsPlbVAJ1m5i/zj9/yu1JAO0LStZ 6FIGMTv1zj4Hcbox3UnOQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1744169687; x=1744256087; bh=5 Fe1HL5mwA1ivcge9OaRh17cxWT60SpWc9Ewccp5/cQ=; b=IrmAc828o/PGi/FVx ofe4gh0d2om6XxN898ALe/Ea9Cz+HnuR5XlO+bCouTaoXONsOKK6EMhsfgBSZy4V WkEP3AtVO+PBWMa2F+Yqx74A+a/RpsZGeRaQ0I2zTPjZj0IYwRXftJscZcryXfz2 a8Btto7hCxPhA+wTC1dOTfgStAndZHwo6aJD12begS+/jV7WtoKAwAqEFs4FZA1N bsJ3E9jvhPrAHeQ0V/aPFogW9Cg+cHsqOsKylhXdaZWtqPi+qQ8faD5IWG8W6nCw ib34vonCT/WV9ScYQpE6gBU0Jh90WLxB4jwvGIaO/w4g0FXVbDEr9vs5mdm5SoMD a91qQ== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvtdegledvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffuc dljedtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhm peffrghnihgvlhcuighuuceougiguhesugiguhhuuhdrgiihiieqnecuggftrfgrthhtvg hrnhepgfefgfegjefhudeikedvueetffelieefuedvhfehjeeljeejkefgffeghfdttdet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepugiguh esugiguhhuuhdrgiihiidpnhgspghrtghpthhtohepudegpdhmohguvgepshhmthhpohhu thdprhgtphhtthhopegrnhgurhhiiheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprg hstheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepuggrnhhivghlsehiohhgvggrrhgs ohigrdhnvghtpdhrtghpthhtohepjhhohhhnrdhfrghsthgrsggvnhgusehgmhgrihhlrd gtohhmpdhrtghpthhtohepmhgrrhhtihhnrdhlrghusehlihhnuhigrdguvghvpdhrtghp thhtohepvgguugihiiekjeesghhmrghilhdrtghomhdprhgtphhtthhopehsohhngheskh gvrhhnvghlrdhorhhgpdhrtghpthhtohephihonhhghhhonhhgrdhsohhngheslhhinhhu gidruggvvhdprhgtphhtthhopehkphhsihhnghhhsehkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 8 Apr 2025 23:34:46 -0400 (EDT) From: Daniel Xu To: andrii@kernel.org, ast@kernel.org, daniel@iogearbox.net Cc: john.fastabend@gmail.com, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC bpf-next 06/13] bpf: Move kfunc definitions out of verifier.c Date: Tue, 8 Apr 2025 21:34:01 -0600 Message-ID: X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Multiple files reference bpf_get_kfunc_addr(). But in order to move the definition out into core, we need to drag along the various struct definitions. Doing this also makes moving bpf_free_kfunc_btf_tab() in the next commit simpler as well. Signed-off-by: Daniel Xu --- include/linux/bpf.h | 42 ++++++++++++++++++++++++++ kernel/bpf/core.c | 29 ++++++++++++++++++ kernel/bpf/verifier.c | 68 ------------------------------------------- 3 files changed, 71 insertions(+), 68 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 1785901330b2..44133727820d 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -1470,6 +1470,38 @@ static inline bool bpf_prog_has_trampoline(const str= uct bpf_prog *prog) } #endif =20 +#define MAX_KFUNC_DESCS 256 +#define MAX_KFUNC_BTFS 256 + +struct bpf_kfunc_desc { + struct btf_func_model func_model; + u32 func_id; + s32 imm; + u16 offset; + unsigned long addr; +}; + +struct bpf_kfunc_btf { + struct btf *btf; + struct module *module; + u16 offset; +}; + +struct bpf_kfunc_desc_tab { + /* Sorted by func_id (BTF ID) and offset (fd_array offset) during + * verification. JITs do lookups by bpf_insn, where func_id may not be + * available, therefore at the end of verification do_misc_fixups() + * sorts this by imm and offset. + */ + struct bpf_kfunc_desc descs[MAX_KFUNC_DESCS]; + u32 nr_descs; +}; + +struct bpf_kfunc_btf_tab { + struct bpf_kfunc_btf descs[MAX_KFUNC_BTFS]; + u32 nr_descs; +}; + struct bpf_func_info_aux { u16 linkage; bool unreliable; @@ -2755,6 +2787,16 @@ bool bpf_prog_has_kfunc_call(const struct bpf_prog *= prog); const struct btf_func_model * bpf_jit_find_kfunc_model(const struct bpf_prog *prog, const struct bpf_insn *insn); +static inline int kfunc_desc_cmp_by_id_off(const void *a, const void *b) +{ + const struct bpf_kfunc_desc *d0 =3D a; + const struct bpf_kfunc_desc *d1 =3D b; + + /* func_id is not greater than BTF_MAX_TYPE */ + return d0->func_id - d1->func_id ?: d0->offset - d1->offset; +} +const struct bpf_kfunc_desc * +find_kfunc_desc(const struct bpf_prog *prog, u32 func_id, u16 offset); int bpf_get_kfunc_addr(const struct bpf_prog *prog, u32 func_id, u16 btf_fd_idx, u8 **func_addr); =20 diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index aaf0841140c0..8cbfe7d33c0a 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -1624,6 +1624,35 @@ void __weak bpf_jit_free(struct bpf_prog *fp) bpf_prog_unlock_free(fp); } =20 +const struct bpf_kfunc_desc * +find_kfunc_desc(const struct bpf_prog *prog, u32 func_id, u16 offset) +{ + struct bpf_kfunc_desc desc =3D { + .func_id =3D func_id, + .offset =3D offset, + }; + struct bpf_kfunc_desc_tab *tab; + + tab =3D prog->aux->kfunc_tab; + return bsearch(&desc, tab->descs, tab->nr_descs, + sizeof(tab->descs[0]), kfunc_desc_cmp_by_id_off); +} +EXPORT_SYMBOL_GPL(find_kfunc_desc); + +int bpf_get_kfunc_addr(const struct bpf_prog *prog, u32 func_id, + u16 btf_fd_idx, u8 **func_addr) +{ + const struct bpf_kfunc_desc *desc; + + desc =3D find_kfunc_desc(prog, func_id, btf_fd_idx); + if (!desc) + return -EFAULT; + + *func_addr =3D (u8 *)desc->addr; + return 0; +} +EXPORT_SYMBOL_GPL(bpf_get_kfunc_addr); + int bpf_jit_get_func_addr(const struct bpf_prog *prog, const struct bpf_insn *insn, bool extra_pass, u64 *func_addr, bool *func_addr_fixed) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index d3bb65f721c9..161280f3371f 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -2957,47 +2957,6 @@ static int bpf_find_exception_callback_insn_off(stru= ct bpf_verifier_env *env) return ret; } =20 -#define MAX_KFUNC_DESCS 256 -#define MAX_KFUNC_BTFS 256 - -struct bpf_kfunc_desc { - struct btf_func_model func_model; - u32 func_id; - s32 imm; - u16 offset; - unsigned long addr; -}; - -struct bpf_kfunc_btf { - struct btf *btf; - struct module *module; - u16 offset; -}; - -struct bpf_kfunc_desc_tab { - /* Sorted by func_id (BTF ID) and offset (fd_array offset) during - * verification. JITs do lookups by bpf_insn, where func_id may not be - * available, therefore at the end of verification do_misc_fixups() - * sorts this by imm and offset. - */ - struct bpf_kfunc_desc descs[MAX_KFUNC_DESCS]; - u32 nr_descs; -}; - -struct bpf_kfunc_btf_tab { - struct bpf_kfunc_btf descs[MAX_KFUNC_BTFS]; - u32 nr_descs; -}; - -static int kfunc_desc_cmp_by_id_off(const void *a, const void *b) -{ - const struct bpf_kfunc_desc *d0 =3D a; - const struct bpf_kfunc_desc *d1 =3D b; - - /* func_id is not greater than BTF_MAX_TYPE */ - return d0->func_id - d1->func_id ?: d0->offset - d1->offset; -} - static int kfunc_btf_cmp_by_off(const void *a, const void *b) { const struct bpf_kfunc_btf *d0 =3D a; @@ -3006,33 +2965,6 @@ static int kfunc_btf_cmp_by_off(const void *a, const= void *b) return d0->offset - d1->offset; } =20 -static const struct bpf_kfunc_desc * -find_kfunc_desc(const struct bpf_prog *prog, u32 func_id, u16 offset) -{ - struct bpf_kfunc_desc desc =3D { - .func_id =3D func_id, - .offset =3D offset, - }; - struct bpf_kfunc_desc_tab *tab; - - tab =3D prog->aux->kfunc_tab; - return bsearch(&desc, tab->descs, tab->nr_descs, - sizeof(tab->descs[0]), kfunc_desc_cmp_by_id_off); -} - -int bpf_get_kfunc_addr(const struct bpf_prog *prog, u32 func_id, - u16 btf_fd_idx, u8 **func_addr) -{ - const struct bpf_kfunc_desc *desc; - - desc =3D find_kfunc_desc(prog, func_id, btf_fd_idx); - if (!desc) - return -EFAULT; - - *func_addr =3D (u8 *)desc->addr; - return 0; -} - static struct btf *__find_kfunc_desc_btf(struct bpf_verifier_env *env, s16 offset) { --=20 2.47.1 From nobody Sat Feb 7 15:40:11 2026 Received: from fhigh-a4-smtp.messagingengine.com (fhigh-a4-smtp.messagingengine.com [103.168.172.155]) (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 A32DE1D90A9; Wed, 9 Apr 2025 03:34:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744169692; cv=none; b=JCdkiI/8952eKegbgvkd1MaG2+o6hwl8k2xIx6sK1iI0OBB821SN4M259l6gOq/nx8FPNFQGxt+QxoNdw/4gzZOty3OsRW3odW8QS/0HW7mcKkSwvgqo9fsUfTD3mnuYM5BltWpnTgHuNyYzziIFYsoDlHVzHq0iGOtb4NFNyf8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744169692; c=relaxed/simple; bh=MTO8TYXrYkS5+gZ7YoJ1hGQfE1UmPeJYID4bLAzETg8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DCY48AlwQJfRTrp6oGNVrgFFKzXuswsf7PhzIKakOsdhAtnYN/ek/OwKDUPGvhXpzTplo7KxbUA5Js/fvOzqh2KE4VtMOMFo7WIYGVoGj8eBmMUpotjzplSkCgks36whjgyh/JPIKll3z5PI2FHe2QseV/9XoZglLSxStP2YcS0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz; spf=pass smtp.mailfrom=dxuuu.xyz; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b=EWcfxSqj; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=kFkWkDyV; arc=none smtp.client-ip=103.168.172.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="EWcfxSqj"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="kFkWkDyV" Received: from phl-compute-07.internal (phl-compute-07.phl.internal [10.202.2.47]) by mailfhigh.phl.internal (Postfix) with ESMTP id EEE3411401AD; Tue, 8 Apr 2025 23:34:49 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-07.internal (MEProxy); Tue, 08 Apr 2025 23:34:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1744169689; x= 1744256089; bh=tx9FCo6R6R8yUOFOL44YRwWM5fJLHw5Y6hkN8xcha+0=; b=E WcfxSqj9/NIN/ursnGNiRluwPCu+XJrry5MIedH3aGRUlu95rEqyD4KRz03U4BiJ wZ2gCD6v+lVqE/MzuOJBfSy7ajOyoQXinSyRP0wJ1C36/EgsVZCfFX2+mYspBTX3 xch0qQeNr9zChp7LVBSt0UIsPqg7Qu1Mnd6icqhSoQiAbw6nAHH1gwav2SzxLVdZ OdzBQLUEv0CgQJEr2VGFXykNKd5Yi0ja3MN4hsGLEuzD8BHz15ILwKrDwVSPf+9Q nDfbFBjcgKenYufXPHocvjRjbG1KS806dxVEizMUIovvW+1GD2gQiExk7mrviLIJ wyZwWrmMAbihfuJhLOzHQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1744169689; x=1744256089; bh=t x9FCo6R6R8yUOFOL44YRwWM5fJLHw5Y6hkN8xcha+0=; b=kFkWkDyVJKNFWILQQ E+qRQRuEB3EWBG6yImQ5FqgtwPcb95auzy34Ynh3X3nMa9VfBbrAjhL2f+OPIg+Z VxTz3/pXHdnaWrtG86U3RypuVyuqGhi2xqJpKvCis0rSKmA/hiIix0fiKnfYa0FA lB1E2x0xIKaurDgFjUhUwvNOWCB4X4cSOCpN16KznaQ/nfk8oFVqTB3d0xQdudVS fCngNcoJo3ALefEPORd0aP46gWEOK6N9KAnREQ7LjR/smQ7wBLiBGqyHLC1N5w3E Ukyx4SX1hh6klNWWKIjetDkrkEhbzOnTAC/9Ekw8Va1x1kgjtQ9HA5N2UYMdgVyo ewHjg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvtdegledvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffuc dljedtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhm peffrghnihgvlhcuighuuceougiguhesugiguhhuuhdrgiihiieqnecuggftrfgrthhtvg hrnhepgfefgfegjefhudeikedvueetffelieefuedvhfehjeeljeejkefgffeghfdttdet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepugiguh esugiguhhuuhdrgiihiidpnhgspghrtghpthhtohepudegpdhmohguvgepshhmthhpohhu thdprhgtphhtthhopegrnhgurhhiiheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprg hstheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepuggrnhhivghlsehiohhgvggrrhgs ohigrdhnvghtpdhrtghpthhtohepmhgrrhhtihhnrdhlrghusehlihhnuhigrdguvghvpd hrtghpthhtohepvgguugihiiekjeesghhmrghilhdrtghomhdprhgtphhtthhopehsohhn gheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohephihonhhghhhonhhgrdhsohhngheslh hinhhugidruggvvhdprhgtphhtthhopehjohhhnhdrfhgrshhtrggsvghnugesghhmrghi lhdrtghomhdprhgtphhtthhopehkphhsihhnghhhsehkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 8 Apr 2025 23:34:47 -0400 (EDT) From: Daniel Xu To: andrii@kernel.org, ast@kernel.org, daniel@iogearbox.net Cc: martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC bpf-next 07/13] bpf: Make bpf_free_kfunc_btf_tab() static in core Date: Tue, 8 Apr 2025 21:34:02 -0600 Message-ID: <8ec25079f9ee20495409e08b6a1e08a9076dcc29.1744169424.git.dxu@dxuuu.xyz> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This function is only used in one place in core. However, it was defined in verifier.c b/c a bunch of struct definitions were hidden in verifier.c. Now that those definitions are shared, we can move bpf_free_kfunc_btf_tab() into core and mark it static. Signed-off-by: Daniel Xu --- include/linux/bpf_verifier.h | 2 -- kernel/bpf/core.c | 13 +++++++++++++ kernel/bpf/verifier.c | 12 ------------ 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h index f61f5429647a..f9a203e5f042 100644 --- a/include/linux/bpf_verifier.h +++ b/include/linux/bpf_verifier.h @@ -879,8 +879,6 @@ static inline void bpf_trampoline_unpack_key(u64 key, u= 32 *obj_id, u32 *btf_id) *btf_id =3D key & 0x7FFFFFFF; } =20 -void bpf_free_kfunc_btf_tab(struct bpf_kfunc_btf_tab *tab); - int mark_chain_precision(struct bpf_verifier_env *env, int regno); =20 #define BPF_BASE_TYPE_MASK GENMASK(BPF_BASE_TYPE_BITS - 1, 0) diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 8cbfe7d33c0a..e892e469061e 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -3251,6 +3251,19 @@ static void bpf_free_used_btfs(struct bpf_prog_aux *= aux) kfree(aux->used_btfs); } =20 +static void bpf_free_kfunc_btf_tab(struct bpf_kfunc_btf_tab *tab) +{ + if (!tab) + return; + + while (tab->nr_descs--) { + module_put(tab->descs[tab->nr_descs].module); + btf_put(tab->descs[tab->nr_descs].btf); + } + kfree(tab); +} + + static void bpf_prog_free_deferred(struct work_struct *work) { struct bpf_prog_aux *aux; diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 161280f3371f..7e84df2abe41 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -3029,18 +3029,6 @@ static struct btf *__find_kfunc_desc_btf(struct bpf_= verifier_env *env, return btf; } =20 -void bpf_free_kfunc_btf_tab(struct bpf_kfunc_btf_tab *tab) -{ - if (!tab) - return; - - while (tab->nr_descs--) { - module_put(tab->descs[tab->nr_descs].module); - btf_put(tab->descs[tab->nr_descs].btf); - } - kfree(tab); -} - static struct btf *find_kfunc_desc_btf(struct bpf_verifier_env *env, s16 o= ffset) { if (offset) { --=20 2.47.1 From nobody Sat Feb 7 15:40:11 2026 Received: from fhigh-a4-smtp.messagingengine.com (fhigh-a4-smtp.messagingengine.com [103.168.172.155]) (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 1DDBA1DDA1B; Wed, 9 Apr 2025 03:34:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744169694; cv=none; b=TaRWuWUVupZDNIDS3XlAvRjhLYV/uRwxEo2e5uOBoQEgBmVxrx9LDLlUe4TsGnYvrsO+RGGB3o6inWe1T45zur78b04biBVZ/0C5C+gOp8mlBzpZxwJ0VkHU6Hj5J1Mo3LNiGtpuxzMYXYxITqOpZaldo/NmGhc5MsBoYsHiuZQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744169694; c=relaxed/simple; bh=0QQJ3jdXg0Dk0Z/fgQp/zkhhtH8UYn+dBEX6hE0vJFA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nEXtK32jS0wYwNHLnM0DHjQQIR9AKtTi28aQRaisVo2Gyv/ignsNzWh1bznMOBfx0v3ID9FwLWsf1DuL5HIPIpoMK2ZfJ/15+vznht6mmjqMubWLAgUAY/HyDgCOuAeXCzqDIsGOJRTfFvKr3PP82eYLWlWTeKkTDQIuqccAiN0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz; spf=pass smtp.mailfrom=dxuuu.xyz; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b=hjbq9Vmy; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=uO5KWbPm; arc=none smtp.client-ip=103.168.172.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="hjbq9Vmy"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="uO5KWbPm" Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfhigh.phl.internal (Postfix) with ESMTP id 132581140252; Tue, 8 Apr 2025 23:34:52 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-12.internal (MEProxy); Tue, 08 Apr 2025 23:34:52 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1744169692; x= 1744256092; bh=47R6IUBo2KJ2pOAYSTre05QTjaX02+1h8+rPzsl3QyQ=; b=h jbq9VmyKBPbB7P1UcvIddgNuCrEAl0yk+FYXMRvKGOzPgKbQBKiegrWaiFoWLTRe xOmTxXvlkJUUxgFo9z/EdAGV3ROna0xYtjy61BgflqhxI1qMFz/nPTR+JYRbeMqv lW8RcWi5PIEwxhDRMmMj/NE3Swm089akm/iOKuoPTKq/MRbnP8cfmrvcVKIhVFvF Nhx2msSVFXJa4CiGaU+OH6uLUMC81jjjq9j0kpCL2QAfpSOhkq78/4drfeNYu5fs 6mwMJxwVZJmIQwDZbr4dAVVKhs6NN5jmt8BeGns0+EDwmCpKrVfeKqg00QdaXU+Q FR7UjfGovzyCWwhMez4sw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1744169692; x=1744256092; bh=4 7R6IUBo2KJ2pOAYSTre05QTjaX02+1h8+rPzsl3QyQ=; b=uO5KWbPm+dbDlzLXe 0N/ezbfGnej+xcG9aefx0Nq5SldK+zZlNGSq1FiL7MrcU5Nl8oLzdWuWGFx/a5lF 6ghzCL9MLsmKQDKTs5q8Ni6hQ+JvBfz/qEQQj8WRC8UHDtXC+f0P58zbYFLNF4QQ peS+y6gt9SEySSj4Odh4ICRyn/s+HQ/471gfGZQXJR4sKgjjrQG3A0b0qs2k8pY7 segKzEFXLaRLaEcApu8EBg9K7HWqp8P5wBkgdXuqLFXJdHKRNnj0hEclSTOKH/Os umDtqar5Tp3iRXf0BMw/qxhirnqxazI3AN+jJlSCI/d36lXaDttP59SbXzPzA0Z+ XWTgA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvtdegledvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffuc dljedtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhm peffrghnihgvlhcuighuuceougiguhesugiguhhuuhdrgiihiieqnecuggftrfgrthhtvg hrnhepgfefgfegjefhudeikedvueetffelieefuedvhfehjeeljeejkefgffeghfdttdet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepugiguh esugiguhhuuhdrgiihiidpnhgspghrtghpthhtohepudejpdhmohguvgepshhmthhpohhu thdprhgtphhtthhopehshhhurghhsehkvghrnhgvlhdrohhrghdprhgtphhtthhopegrnh gurhhiiheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepuggrnhhivghlsehiohhgvggr rhgsohigrdhnvghtpdhrtghpthhtoheprghstheskhgvrhhnvghlrdhorhhgpdhrtghpth htohepvgguugihiiekjeesghhmrghilhdrtghomhdprhgtphhtthhopehmrghrthhinhdr lhgruheslhhinhhugidruggvvhdprhgtphhtthhopehsohhngheskhgvrhhnvghlrdhorh hgpdhrtghpthhtohephihonhhghhhonhhgrdhsohhngheslhhinhhugidruggvvhdprhgt phhtthhopehjohhhnhdrfhgrshhtrggsvghnugesghhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 8 Apr 2025 23:34:50 -0400 (EDT) From: Daniel Xu To: shuah@kernel.org, andrii@kernel.org, daniel@iogearbox.net, ast@kernel.org, eddyz87@gmail.com Cc: martin.lau@linux.dev, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, mykolal@fb.com, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC bpf-next 08/13] selftests: bpf: Avoid attaching to bpf_check() Date: Tue, 8 Apr 2025 21:34:03 -0600 Message-ID: <25a4bb8f1168b955b949c703e8cb671eea2eb92e.1744169424.git.dxu@dxuuu.xyz> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" bpf_check(), as it currently exists, will soon be going away to make way for loadable BPF verifier support. Fixup selftests so they fentry attach to a more reliable location. Signed-off-by: Daniel Xu --- tools/testing/selftests/bpf/progs/exceptions_assert.c | 2 +- tools/testing/selftests/bpf/progs/exceptions_fail.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/bpf/progs/exceptions_assert.c b/tools/= testing/selftests/bpf/progs/exceptions_assert.c index 5e0a1ca96d4e..50bc52cbb2e7 100644 --- a/tools/testing/selftests/bpf/progs/exceptions_assert.c +++ b/tools/testing/selftests/bpf/progs/exceptions_assert.c @@ -124,7 +124,7 @@ int check_assert_generic(struct __sk_buff *ctx) return data[128]; } =20 -SEC("?fentry/bpf_check") +SEC("?fentry/bpf_fentry_test1") __failure __msg("At program exit the register R1 has smin=3D64 smax=3D64") int check_assert_with_return(void *ctx) { diff --git a/tools/testing/selftests/bpf/progs/exceptions_fail.c b/tools/te= sting/selftests/bpf/progs/exceptions_fail.c index 8a0fdff89927..b44cb0a6c9d9 100644 --- a/tools/testing/selftests/bpf/progs/exceptions_fail.c +++ b/tools/testing/selftests/bpf/progs/exceptions_fail.c @@ -299,7 +299,7 @@ __noinline int exception_cb_bad_ret(u64 c) return c; } =20 -SEC("?fentry/bpf_check") +SEC("?fentry/bpf_fentry_test1") __exception_cb(exception_cb_bad_ret) __failure __msg("At program exit the register R0 has unknown scalar value = should") int reject_set_exception_cb_bad_ret1(void *ctx) @@ -307,7 +307,7 @@ int reject_set_exception_cb_bad_ret1(void *ctx) return 0; } =20 -SEC("?fentry/bpf_check") +SEC("?fentry/bpf_fentry_test1") __failure __msg("At program exit the register R1 has smin=3D64 smax=3D64 s= hould") int reject_set_exception_cb_bad_ret2(void *ctx) { --=20 2.47.1 From nobody Sat Feb 7 15:40:11 2026 Received: from fhigh-a4-smtp.messagingengine.com (fhigh-a4-smtp.messagingengine.com [103.168.172.155]) (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 3DC181DED56; Wed, 9 Apr 2025 03:34:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744169698; cv=none; b=kSjjEhUglY4AGnfKnJlgO90HAqMzAhh/8aSd/zt2d+WTcW7WY0OtAiAZaOSa8HpgB/6Py9/d43FtMUWixpNaECoTRJFNjT/aEl2p7OVH9zl3d+SgbZA2YJzxd1QyCnRSSdrBvOnmjZHxnea/6zhYmPYQXk46onj/Z2o1jLXnso4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744169698; c=relaxed/simple; bh=BM4ucfaSCyd4h7/irKImxABUrQPrN5JfhG7BMBvF5CQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OEa9BD69BbK0sAjw++mty1g9Z7s7zQpmOQWkwePZi3Go1iIEoHxZ2wCwJQDU6SAOKyXtp7gNSavgQE0+7qpzDArA5ZiF7oS50baTb3RoSTp9/XqdXt3nfiy3zVl/RRE1R4H1RvZc1Q80kyqGJEGP+mItw0SJLXTsHFrcupP4tGk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz; spf=pass smtp.mailfrom=dxuuu.xyz; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b=G9vvWjxI; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=NTqvM5EK; arc=none smtp.client-ip=103.168.172.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="G9vvWjxI"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="NTqvM5EK" Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailfhigh.phl.internal (Postfix) with ESMTP id 4B2611140256; Tue, 8 Apr 2025 23:34:54 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-12.internal (MEProxy); Tue, 08 Apr 2025 23:34:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1744169694; x= 1744256094; bh=2ofeAZF/8FfFJRWxnBMYkuk948swu1mQfL37VFkVNsQ=; b=G 9vvWjxIifheFzjsi2gV0DgWF+FF6GHgo0arJ9XU9hj/xMZDdkWcq0zBan0zq4dpu SPQTHQ1It/QpcUI7KxoeaasCvW+Sumrt7bJG//Sg3cjPoxL8h1UARvI7GJKunkYI ENqRlP61agSm6kZoxqM92bCc6/hQtA8oUYFpUNt7Vg5MHthixpAVvjgPHyWSO9HQ t96opSRvZ6XInoJ1eFxdan8VfJEwi3BRjieDh5MHPuyvoV30h6zm0yBDjwm94hy/ Yts63b2iH+f/Qfry7nswLCcM2NyHqOHyWV5iXrynhVhuV9Tdna92QbtuYPYEm0Og YOyzcs2VhpY5pWKsm3+tw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1744169694; x=1744256094; bh=2 ofeAZF/8FfFJRWxnBMYkuk948swu1mQfL37VFkVNsQ=; b=NTqvM5EKESJ8UFvgn DhLjznY1MB2qjsj2QgaW47y9tdzijCJmZMMQeGZvviiahKyjIvfSyNDZ/RRlO8CG QPPBQ+seHOtZ2v+iTm9TRAvGWloFAkdaHt3cBOBnIkJdJSuI3+RvpZC5l7V6H7xi yHu6o87K3Z9tnu/v5y48kB5zN+5EKoI2U5ZqQBWncKpEmD5Uf2hBJivC7r2NxTCc Y1XAS/qEK+AOENN/0mfJiRTc9N4vFeYc59OcW64S5SuFeXtpq4uNQ5vRzC7Jwqoj KdWUAOp3RuL7CTMPYvTwRKIlJf/mAo5XM5Ik4u9C1PpuLjqj2uhZMbSO+MOcs2O0 8XHtA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvtdegledvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffuc dljedtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhm peffrghnihgvlhcuighuuceougiguhesugiguhhuuhdrgiihiieqnecuggftrfgrthhtvg hrnhepgfefgfegjefhudeikedvueetffelieefuedvhfehjeeljeejkefgffeghfdttdet necuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepugiguh esugiguhhuuhdrgiihiidpnhgspghrtghpthhtohepudefpdhmohguvgepshhmthhpohhu thdprhgtphhtthhopehnrghmhhihuhhngheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoh epmhhinhhgohesrhgvughhrghtrdgtohhmpdhrtghpthhtohepphgvthgvrhiisehinhhf rhgruggvrggurdhorhhgpdhrtghpthhtoheprggtmhgvsehkvghrnhgvlhdrohhrghdprh gtphhtthhopehmrghrkhdrrhhuthhlrghnugesrghrmhdrtghomhdprhgtphhtthhopegr lhgvgigrnhguvghrrdhshhhishhhkhhinheslhhinhhugidrihhnthgvlhdrtghomhdprh gtphhtthhopehjohhlshgrsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehirhhoghgv rhhssehgohhoghhlvgdrtghomhdprhgtphhtthhopegrughrihgrnhdrhhhunhhtvghrse hinhhtvghlrdgtohhm X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 8 Apr 2025 23:34:52 -0400 (EDT) From: Daniel Xu To: namhyung@kernel.org, mingo@redhat.com, peterz@infradead.org, acme@kernel.org Cc: mark.rutland@arm.com, alexander.shishkin@linux.intel.com, jolsa@kernel.org, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Subject: [RFC bpf-next 09/13] perf: Export perf_snapshot_branch_stack static key Date: Tue, 8 Apr 2025 21:34:04 -0600 Message-ID: <7503bb384aaeaf9a3b6f68c5347fd73f8e561cc6.1744169424.git.dxu@dxuuu.xyz> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Export the static call so that the modularized BPF verifier can run static_call_query() against it. Signed-off-by: Daniel Xu --- kernel/events/core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kernel/events/core.c b/kernel/events/core.c index 0bb21659e252..b0449209275f 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -14644,3 +14644,4 @@ struct cgroup_subsys perf_event_cgrp_subsys =3D { #endif /* CONFIG_CGROUP_PERF */ =20 DEFINE_STATIC_CALL_RET0(perf_snapshot_branch_stack, perf_snapshot_branch_s= tack_t); +EXPORT_STATIC_CALL_GPL(perf_snapshot_branch_stack); --=20 2.47.1 From nobody Sat Feb 7 15:40:11 2026 Received: from fhigh-a4-smtp.messagingengine.com (fhigh-a4-smtp.messagingengine.com [103.168.172.155]) (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 049E11DED47; Wed, 9 Apr 2025 03:34:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744169698; cv=none; b=G8gZxKPr7GcK/9qj+TpH6PGk5FAjjD1dBQi3h5vA4j2hnDPfxeK/cCnQbXET8bq88f0c2jjaqHCoDRz1jlTgwXji+/T1rkOFJzZNLtP06jfr4x7qQrLJZ6jVPT5aQ1TZ/KwS2XNCcx2mFQpll9riR8TpbPS14w2ciHhVM4DM9rs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744169698; c=relaxed/simple; bh=tTIDYioC2CywEcIZVxd/AbIARbalJ+SKwmjlNlAbe6Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oN6IxSR/8iOxYrzzqQ+ZkI2v1oSix/ygojXmBkXmUNxbMMIHNSpJTNdf13AJCRTaUePctwoYzvXsHYtC658KKwjodgy+ctvIenG9gVScPGYKAdLz/FxiIpmLydyYUQQ2M7RUrjbzPmwyXwPlX8jv88tlDFgB5FlrXfpVd8iCmhE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz; spf=pass smtp.mailfrom=dxuuu.xyz; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b=GpLeRVpd; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=a+c8bGrp; arc=none smtp.client-ip=103.168.172.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="GpLeRVpd"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="a+c8bGrp" Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfhigh.phl.internal (Postfix) with ESMTP id 5CA201140254; Tue, 8 Apr 2025 23:34:56 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Tue, 08 Apr 2025 23:34:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1744169696; x= 1744256096; bh=HXCkRXU/HBifccFnVoM0wsJm6xU/SN248lJiwoqsy/U=; b=G pLeRVpdwR4iY3jXyYMaAqQ/RCdDIIh1HuuWKhu3CsTAW53DRqup7hUHaftJjaJI4 iuQVP926MULZ31tR3q52dq7dteSZkBWmROo3kxrtg4LJ/8gSAt65ZfWBNBXOiXti zp31fHV6gwZUNlOs/Q8thO+st6KQ7NVPqsqvcZpmll7WNHvac/UxX7Pw4h5gbeEd IAgs9joiMThlJjER3jYqccCkUETh3rH53+V0P00+pZcRkYltNBZcqzgDCOMiDbWL /wQeCVeqxD8oTQLjpInQCi93apHWooakq0ViFPtdyaDOqNM02mhLf7V930ycfxFE nogeFV8RLf+xd6zEHWr1Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1744169696; x=1744256096; bh=H XCkRXU/HBifccFnVoM0wsJm6xU/SN248lJiwoqsy/U=; b=a+c8bGrpoHPn6Xelj CYJ2yoRsbu/6kBuQAAsQ+8/U3TzDOeShqQIR8W9Md8OpbJMBlrcB3yOqmf9k3yeF 47dn8QEz94QInzLgX8VYy9xRy247qgHaVTc3gEFVWguumUR8O5uSBVwg93yLGJlR 4vFmJ++0lrqgZI03cQpq58oiRe92LvIk5VvGUEK5ktdRs24fw8TYWIFiE0D+H9Qp lSqIqFo4tR+FB61vsoxKrrQV6PpS4Xzg0PTMsV7HUgNrCpP5ZUDSE3RdyuUtj19H hQVrSrObXNn9hg7RBZLt9amTRF0Z+AR4GaeHD602spXPit7hFozWMXo2ItqA7jnv YdD6w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvtdegledvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffuc dljedtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhm peffrghnihgvlhcuighuuceougiguhesugiguhhuuhdrgiihiieqnecuggftrfgrthhtvg hrnhepgfefgfegjefhudeikedvueetffelieefuedvhfehjeeljeejkefgffeghfdttdet necuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepugiguh esugiguhhuuhdrgiihiidpnhgspghrtghpthhtohepudegpdhmohguvgepshhmthhpohhu thdprhgtphhtthhopegrnhgurhhiiheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprg hstheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepuggrnhhivghlsehiohhgvggrrhgs ohigrdhnvghtpdhrtghpthhtohepjhhohhhnrdhfrghsthgrsggvnhgusehgmhgrihhlrd gtohhmpdhrtghpthhtohepmhgrrhhtihhnrdhlrghusehlihhnuhigrdguvghvpdhrtghp thhtohepvgguugihiiekjeesghhmrghilhdrtghomhdprhgtphhtthhopehsohhngheskh gvrhhnvghlrdhorhhgpdhrtghpthhtohephihonhhghhhonhhgrdhsohhngheslhhinhhu gidruggvvhdprhgtphhtthhopehkphhsihhnghhhsehkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 8 Apr 2025 23:34:54 -0400 (EDT) From: Daniel Xu To: andrii@kernel.org, ast@kernel.org, daniel@iogearbox.net Cc: john.fastabend@gmail.com, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC bpf-next 10/13] bpf: verifier: Add indirection to kallsyms_lookup_name() Date: Tue, 8 Apr 2025 21:34:05 -0600 Message-ID: <7540678e9a46c13f680f2aacab28bb88446583f5.1744169424.git.dxu@dxuuu.xyz> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" kallsyms_lookup_name() cannot be exported from the kernel for policy reasons, so add this layer of indirection to allow the verifier to still do kfunc and global variable relocations. Signed-off-by: Daniel Xu --- include/linux/bpf.h | 2 ++ kernel/bpf/core.c | 14 ++++++++++++++ kernel/bpf/verifier.c | 13 +++++-------- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 44133727820d..a5806a7b31d3 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -2797,6 +2797,8 @@ static inline int kfunc_desc_cmp_by_id_off(const void= *a, const void *b) } const struct bpf_kfunc_desc * find_kfunc_desc(const struct bpf_prog *prog, u32 func_id, u16 offset); +unsigned long bpf_lookup_type_addr(struct btf *btf, const struct btf_type = *func, + const char **name); int bpf_get_kfunc_addr(const struct bpf_prog *prog, u32 func_id, u16 btf_fd_idx, u8 **func_addr); =20 diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index e892e469061e..13301a668fe0 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -1639,6 +1639,20 @@ find_kfunc_desc(const struct bpf_prog *prog, u32 fun= c_id, u16 offset) } EXPORT_SYMBOL_GPL(find_kfunc_desc); =20 +unsigned long bpf_lookup_type_addr(struct btf *btf, const struct btf_type = *t, + const char **name) +{ + unsigned long addr; + + *name =3D btf_name_by_offset(btf, t->name_off); + addr =3D kallsyms_lookup_name(*name); + if (!addr) + return -ENOENT; + + return addr; +} +EXPORT_SYMBOL_GPL(bpf_lookup_type_addr); + int bpf_get_kfunc_addr(const struct bpf_prog *prog, u32 func_id, u16 btf_fd_idx, u8 **func_addr) { diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 7e84df2abe41..080cc380e806 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -3131,11 +3131,9 @@ static int add_kfunc_call(struct bpf_verifier_env *e= nv, u32 func_id, s16 offset) return -EINVAL; } =20 - func_name =3D btf_name_by_offset(desc_btf, func->name_off); - addr =3D kallsyms_lookup_name(func_name); - if (!addr) { - verbose(env, "cannot find address for kernel function %s\n", - func_name); + addr =3D bpf_lookup_type_addr(desc_btf, func, &func_name); + if (addr < 0) { + verbose(env, "cannot find address for kernel function %s\n", func_name); return -EINVAL; } specialize_kfunc(env, func_id, offset, &addr); @@ -19707,9 +19705,8 @@ static int __check_pseudo_btf_id(struct bpf_verifie= r_env *env, return -EINVAL; } =20 - sym_name =3D btf_name_by_offset(btf, t->name_off); - addr =3D kallsyms_lookup_name(sym_name); - if (!addr) { + addr =3D bpf_lookup_type_addr(btf, t, &sym_name); + if (addr < 0) { verbose(env, "ldimm64 failed to find the address for kernel symbol '%s'.= \n", sym_name); return -ENOENT; --=20 2.47.1 From nobody Sat Feb 7 15:40:11 2026 Received: from flow-a5-smtp.messagingengine.com (flow-a5-smtp.messagingengine.com [103.168.172.140]) (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 0374C1C3F0C; Wed, 9 Apr 2025 03:35:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.140 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744169708; cv=none; b=qehne4wlVtlO5AW+ilQrXBVGwgRCwDN4k9a3bYrzOwLbGiRx0ImT3tuLxy++0cy8thptH9H8rFYRi0XfeLHgC5Nb+17aOwLr6fQJQbOLTqQbVg5D9N2KWFMF5ZGUq0qznsX8tPPsmJ9nzVHYkJFDiroIeMfUMx+fH16kWqrgsv0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744169708; c=relaxed/simple; bh=n5IosBv2Zad0YnsHKN8TpO8KLEQyqQVSLQxhTsZpKms=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=e/tkqIbGZLp+bRTXjfn5VpimLthJbnuaJ8Foq4zD+Qgp0fyKbpgjRlNfVVcLSHZKrHArsOhkapuXP+abO/cPGWdcl1nChj9BSaePKkpljOt5bpp7xJQYK3s0ECuszpNYMcMewnJfekTqtbi9H5dpYtHUz6/byCk/H35cxbqxZeI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz; spf=pass smtp.mailfrom=dxuuu.xyz; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b=AAT+Jk5P; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=QTbYPhMs; arc=none smtp.client-ip=103.168.172.140 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="AAT+Jk5P"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="QTbYPhMs" Received: from phl-compute-12.internal (phl-compute-12.phl.internal [10.202.2.52]) by mailflow.phl.internal (Postfix) with ESMTP id E68AA2001D0; Tue, 8 Apr 2025 23:35:02 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-12.internal (MEProxy); Tue, 08 Apr 2025 23:35:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1744169702; x= 1744176902; bh=XDeVFVuyYFTjPVaGwO2YPsFAoYZ0on0V1liEOaC13SY=; b=A AT+Jk5Pg6a09ZcAG5ZYmIP5iKL5j+1mV7Xb58ahK58s4u/o1P50NBeWy0NrREMVv UKdUKdI01T7TwGZvFAGG69ZB/qwmGkhHeKbO6OqkfloAkZNoeJfcHOU5cbaQIMtG 3bJxdR1gobLfG06JLr9b1OSpeJ5MZXQgyT07GhyDlby2Sj8hQfP6gw39DXSiO1v6 qxRLpPypF++BvyL2QXZqG5l1WLxn1cLnfP4T6B+J8qTr5ltRr+TBcg6g/Wd/BFUF 4r6/rQhzTYSTEDyqAoq6S5WL2J32wOY4BidGOrO9D4CmhbdIVUuJqfanI4yLFD9Y TEqcVvLx7s5I4/XSJ1Gww== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1744169702; x=1744176902; bh=X DeVFVuyYFTjPVaGwO2YPsFAoYZ0on0V1liEOaC13SY=; b=QTbYPhMsi79NwVnaa Q97AFodLii5oRdmXufv2V0s8hxi8a4q+4fy7SU8vNZukgXuA+MoXeSWom4EDWrwS UtmxnMCavnkBPkM/3+snXVYmAOtySgXMigOs2K1zX84USS/umrlaA/1ZRoS31yv3 ZFgHrI9nhrDFTNYUqEt2Br+xdDBkc6FJtTmzr4Y2OUa84eM/lZWEHPQn1AsRE5eO aAFVQqx9XvYb2GY4xJKzu85lKR4E20bDR9+Yz+K1ndldPH/4qCOibyo4cEaDw9o+ iWZQiA1EUeUwGi1R1zeu++D7qNuoOAQbdhm/JBZF+sxeGERA87PFObd5ERZFEu4v 3lRIw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvtdegledvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffuc dljedtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhm peffrghnihgvlhcuighuuceougiguhesugiguhhuuhdrgiihiieqnecuggftrfgrthhtvg hrnhepgfefgfegjefhudeikedvueetffelieefuedvhfehjeeljeejkefgffeghfdttdet necuvehluhhsthgvrhfuihiivgepfeenucfrrghrrghmpehmrghilhhfrhhomhepugiguh esugiguhhuuhdrgiihiidpnhgspghrtghpthhtohepheehpdhmohguvgepshhmthhpohhu thdprhgtphhtthhopeihohhnghhhohhnghdrshhonhhgsehlihhnuhigrdguvghvpdhrtg hpthhtohepjhhohhhnrdhfrghsthgrsggvnhgusehgmhgrihhlrdgtohhmpdhrtghpthht ohepughsrghhvghrnheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprhhoshhtvgguth esghhoohgumhhishdrohhrghdprhgtphhtthhopegurghvvgdrhhgrnhhsvghnsehlihhn uhigrdhinhhtvghlrdgtohhmpdhrtghpthhtohepqhhmoheskhgvrhhnvghlrdhorhhgpd hrtghpthhtoheprghstheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepsghrrghunhgv rheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprghkphhmsehlihhnuhigqdhfohhunh gurghtihhonhdrohhrgh X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 8 Apr 2025 23:34:56 -0400 (EDT) From: Daniel Xu To: yonghong.song@linux.dev, john.fastabend@gmail.com, dsahern@kernel.org, rostedt@goodmis.org, dave.hansen@linux.intel.com, qmo@kernel.org, ast@kernel.org, brauner@kernel.org, Andrew Morton , kuba@kernel.org, kadlec@netfilter.org, hawk@kernel.org, peterz@infradead.org, daniel@iogearbox.net, namhyung@kernel.org, edumazet@google.com, sean@mess.org, x86@kernel.org, viro@zeniv.linux.org.uk, mhiramat@kernel.org, mattbobrowski@google.com, pabeni@redhat.com, davem@davemloft.net, acme@kernel.org, kpsingh@kernel.org, tglx@linutronix.de, song@kernel.org, andrii@kernel.org, bp@alien8.de, pablo@netfilter.org, mchehab@kernel.org, mingo@redhat.com, martin.lau@linux.dev Cc: eddyz87@gmail.com, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, hpa@zytor.com, jack@suse.cz, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, irogers@google.com, adrian.hunter@intel.com, kan.liang@linux.intel.com, mathieu.desnoyers@efficios.com, horms@kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-trace-kernel@vger.kernel.org, netfilter-devel@vger.kernel.org, coreteam@netfilter.org Subject: [RFC bpf-next 11/13] treewide: bpf: Export symbols used by verifier Date: Tue, 8 Apr 2025 21:34:06 -0600 Message-ID: <5b3433d942eaecdbcc92876c9ed8b7d17f7e1086.1744169424.git.dxu@dxuuu.xyz> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This commit EXPORT_SYMBOL_GPL()'s all the unresolved symbols from verifier.= o. This is necessary to support loads and reloads of the verifier at runtime. The list of symbols was generated using: nm -u kernel/bpf/verifier.o | grep -ve "__asan\|__ubsan\|__kasan" | awk= '{print $2}' Signed-off-by: Daniel Xu --- arch/x86/net/bpf_jit_comp.c | 2 ++ drivers/media/rc/bpf-lirc.c | 1 + fs/bpf_fs_kfuncs.c | 4 ++++ kernel/bpf/bpf_iter.c | 1 + kernel/bpf/bpf_lsm.c | 5 +++++ kernel/bpf/bpf_struct_ops.c | 2 ++ kernel/bpf/btf.c | 40 +++++++++++++++++++++++++++++++++++++ kernel/bpf/cgroup.c | 4 ++++ kernel/bpf/core.c | 29 +++++++++++++++++++++++++++ kernel/bpf/disasm.c | 4 ++++ kernel/bpf/helpers.c | 2 ++ kernel/bpf/local_storage.c | 2 ++ kernel/bpf/log.c | 12 +++++++++++ kernel/bpf/map_iter.c | 1 + kernel/bpf/memalloc.c | 3 +++ kernel/bpf/offload.c | 10 ++++++++++ kernel/bpf/syscall.c | 7 +++++++ kernel/bpf/tnum.c | 20 +++++++++++++++++++ kernel/bpf/token.c | 1 + kernel/bpf/trampoline.c | 5 +++++ kernel/events/callchain.c | 3 +++ kernel/trace/bpf_trace.c | 9 +++++++++ lib/error-inject.c | 2 ++ net/core/filter.c | 26 ++++++++++++++++++++++++ net/core/xdp.c | 2 ++ net/netfilter/nf_bpf_link.c | 1 + 26 files changed, 198 insertions(+) diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c index 9e5fe2ba858f..1319e9e47540 100644 --- a/arch/x86/net/bpf_jit_comp.c +++ b/arch/x86/net/bpf_jit_comp.c @@ -3704,6 +3704,7 @@ struct bpf_prog *bpf_int_jit_compile(struct bpf_prog = *prog) tmp : orig_prog); return prog; } +EXPORT_SYMBOL_GPL(bpf_int_jit_compile); =20 bool bpf_jit_supports_kfunc_call(void) { @@ -3762,6 +3763,7 @@ void bpf_jit_free(struct bpf_prog *prog) =20 bpf_prog_unlock_free(prog); } +EXPORT_SYMBOL_GPL(bpf_jit_free); =20 bool bpf_jit_supports_exceptions(void) { diff --git a/drivers/media/rc/bpf-lirc.c b/drivers/media/rc/bpf-lirc.c index 2f7564f26445..c9d421c3ee6f 100644 --- a/drivers/media/rc/bpf-lirc.c +++ b/drivers/media/rc/bpf-lirc.c @@ -131,6 +131,7 @@ const struct bpf_verifier_ops lirc_mode2_verifier_ops = =3D { .get_func_proto =3D lirc_mode2_func_proto, .is_valid_access =3D lirc_mode2_is_valid_access }; +EXPORT_SYMBOL_GPL(lirc_mode2_verifier_ops); =20 #define BPF_MAX_PROGS 64 =20 diff --git a/fs/bpf_fs_kfuncs.c b/fs/bpf_fs_kfuncs.c index 08412532db1b..55ee6e79de3c 100644 --- a/fs/bpf_fs_kfuncs.c +++ b/fs/bpf_fs_kfuncs.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -231,6 +232,7 @@ int bpf_set_dentry_xattr_locked(struct dentry *dentry, = const char *name__str, } return ret; } +EXPORT_SYMBOL_GPL(bpf_set_dentry_xattr_locked); =20 /** * bpf_remove_dentry_xattr_locked - remove a xattr of a dentry @@ -266,6 +268,7 @@ int bpf_remove_dentry_xattr_locked(struct dentry *dentr= y, const char *name__str) } return ret; } +EXPORT_SYMBOL_GPL(bpf_remove_dentry_xattr_locked); =20 __bpf_kfunc_start_defs(); =20 @@ -373,6 +376,7 @@ bool bpf_lsm_has_d_inode_locked(const struct bpf_prog *= prog) { return btf_id_set_contains(&d_inode_locked_hooks, prog->aux->attach_btf_i= d); } +EXPORT_SYMBOL_GPL(bpf_lsm_has_d_inode_locked); =20 static const struct btf_kfunc_id_set bpf_fs_kfunc_set =3D { .owner =3D THIS_MODULE, diff --git a/kernel/bpf/bpf_iter.c b/kernel/bpf/bpf_iter.c index 380e9a7cac75..2e015b08c6cc 100644 --- a/kernel/bpf/bpf_iter.c +++ b/kernel/bpf/bpf_iter.c @@ -366,6 +366,7 @@ int bpf_iter_prog_supported(struct bpf_prog *prog) return bpf_prog_ctx_arg_info_init(prog, tinfo->reg_info->ctx_arg_info, tinfo->reg_info->ctx_arg_info_size); } +EXPORT_SYMBOL_GPL(bpf_iter_prog_supported); =20 const struct bpf_func_proto * bpf_iter_get_func_proto(enum bpf_func_id func_id, const struct bpf_prog *p= rog) diff --git a/kernel/bpf/bpf_lsm.c b/kernel/bpf/bpf_lsm.c index 0a59df1c550a..417790c4b0f7 100644 --- a/kernel/bpf/bpf_lsm.c +++ b/kernel/bpf/bpf_lsm.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -137,6 +138,7 @@ int bpf_lsm_verify_prog(struct bpf_verifier_log *vlog, =20 return 0; } +EXPORT_SYMBOL_GPL(bpf_lsm_verify_prog); =20 /* Mask for all the currently supported BPRM option flags */ #define BPF_F_BRPM_OPTS_MASK BPF_F_BPRM_SECUREEXEC @@ -399,6 +401,7 @@ bool bpf_lsm_is_sleepable_hook(u32 btf_id) { return btf_id_set_contains(&sleepable_lsm_hooks, btf_id); } +EXPORT_SYMBOL_GPL(bpf_lsm_is_sleepable_hook); =20 bool bpf_lsm_is_trusted(const struct bpf_prog *prog) { @@ -412,6 +415,7 @@ const struct bpf_verifier_ops lsm_verifier_ops =3D { .get_func_proto =3D bpf_lsm_func_proto, .is_valid_access =3D btf_ctx_access, }; +EXPORT_SYMBOL_GPL(lsm_verifier_ops); =20 /* hooks return 0 or 1 */ BTF_SET_START(bool_lsm_hooks) @@ -445,3 +449,4 @@ int bpf_lsm_get_retval_range(const struct bpf_prog *pro= g, } return 0; } +EXPORT_SYMBOL_GPL(bpf_lsm_get_retval_range); diff --git a/kernel/bpf/bpf_struct_ops.c b/kernel/bpf/bpf_struct_ops.c index db13ee70d94d..10abed11082e 100644 --- a/kernel/bpf/bpf_struct_ops.c +++ b/kernel/bpf/bpf_struct_ops.c @@ -68,6 +68,7 @@ static DEFINE_MUTEX(update_mutex); =20 const struct bpf_verifier_ops bpf_struct_ops_verifier_ops =3D { }; +EXPORT_SYMBOL_GPL(bpf_struct_ops_verifier_ops); =20 const struct bpf_prog_ops bpf_struct_ops_prog_ops =3D { #ifdef CONFIG_NET @@ -327,6 +328,7 @@ int bpf_struct_ops_supported(const struct bpf_struct_op= s *st_ops, u32 moff) =20 return func_ptr ? 0 : -ENOTSUPP; } +EXPORT_SYMBOL_GPL(bpf_struct_ops_supported); =20 int bpf_struct_ops_desc_init(struct bpf_struct_ops_desc *st_ops_desc, struct btf *btf, diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c index 5b38c90e1184..91cc0fcd29e9 100644 --- a/kernel/bpf/btf.c +++ b/kernel/bpf/btf.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -347,6 +348,7 @@ const char *btf_type_str(const struct btf_type *t) { return btf_kind_str[BTF_INFO_KIND(t->info)]; } +EXPORT_SYMBOL_GPL(btf_type_str); =20 /* Chunk size we use in safe copy of data to be shown. */ #define BTF_SHOW_OBJ_SAFE_SIZE 32 @@ -497,6 +499,7 @@ bool btf_type_is_void(const struct btf_type *t) { return t =3D=3D &btf_void; } +EXPORT_SYMBOL_GPL(btf_type_is_void); =20 static bool btf_type_is_datasec(const struct btf_type *t) { @@ -542,6 +545,7 @@ u32 btf_nr_types(const struct btf *btf) =20 return total; } +EXPORT_SYMBOL_GPL(btf_nr_types); =20 s32 btf_find_by_name_kind(const struct btf *btf, const char *name, u8 kind) { @@ -562,6 +566,7 @@ s32 btf_find_by_name_kind(const struct btf *btf, const = char *name, u8 kind) =20 return -ENOENT; } +EXPORT_SYMBOL_GPL(btf_find_by_name_kind); =20 struct btf *bpf_get_btf_vmlinux(void) { @@ -635,6 +640,7 @@ const struct btf_type *btf_type_skip_modifiers(const st= ruct btf *btf, =20 return t; } +EXPORT_SYMBOL_GPL(btf_type_skip_modifiers); =20 const struct btf_type *btf_type_resolve_ptr(const struct btf *btf, u32 id, u32 *res_id) @@ -647,6 +653,7 @@ const struct btf_type *btf_type_resolve_ptr(const struc= t btf *btf, =20 return btf_type_skip_modifiers(btf, t->type, res_id); } +EXPORT_SYMBOL_GPL(btf_type_resolve_ptr); =20 const struct btf_type *btf_type_resolve_func_ptr(const struct btf *btf, u32 id, u32 *res_id) @@ -659,6 +666,7 @@ const struct btf_type *btf_type_resolve_func_ptr(const = struct btf *btf, =20 return NULL; } +EXPORT_SYMBOL_GPL(btf_type_resolve_func_ptr); =20 /* Types that act only as a source, not sink or intermediate * type when resolving. @@ -855,6 +863,7 @@ const char *btf_name_by_offset(const struct btf *btf, u= 32 offset) { return btf_str_by_offset(btf, offset); } +EXPORT_SYMBOL_GPL(btf_name_by_offset); =20 const struct btf_type *btf_type_by_id(const struct btf *btf, u32 type_id) { @@ -1760,11 +1769,13 @@ const char *btf_get_name(const struct btf *btf) { return btf->name; } +EXPORT_SYMBOL_GPL(btf_get_name); =20 void btf_get(struct btf *btf) { refcount_inc(&btf->refcnt); } +EXPORT_SYMBOL_GPL(btf_get); =20 void btf_put(struct btf *btf) { @@ -1773,6 +1784,7 @@ void btf_put(struct btf *btf) call_rcu(&btf->rcu, btf_free_rcu); } } +EXPORT_SYMBOL_GPL(btf_put); =20 struct btf *btf_base_btf(const struct btf *btf) { @@ -2018,6 +2030,7 @@ btf_resolve_size(const struct btf *btf, const struct = btf_type *type, { return __btf_resolve_size(btf, type, type_size, NULL, NULL, NULL, NULL); } +EXPORT_SYMBOL_GPL(btf_resolve_size); =20 static u32 btf_resolved_type_id(const struct btf *btf, u32 type_id) { @@ -3433,6 +3446,7 @@ const char *btf_find_decl_tag_value(const struct btf = *btf, const struct btf_type =20 return value; } +EXPORT_SYMBOL_GPL(btf_find_decl_tag_value); =20 static int btf_find_graph_root(const struct btf *btf, const struct btf_type *pt, @@ -5701,6 +5715,7 @@ struct btf_struct_meta *btf_find_struct_meta(const st= ruct btf *btf, u32 btf_id) return NULL; return bsearch(&btf_id, tab->types, tab->cnt, sizeof(tab->types[0]), btf_= id_cmp_func); } +EXPORT_SYMBOL_GPL(btf_find_struct_meta); =20 static int btf_check_type_tags(struct btf_verifier_env *env, struct btf *btf, int start_id) @@ -5946,6 +5961,7 @@ bool btf_is_projection_of(const char *pname, const ch= ar *tname) return true; return false; } +EXPORT_SYMBOL_GPL(btf_is_projection_of); =20 bool btf_is_prog_ctx_type(struct bpf_verifier_log *log, const struct btf *= btf, const struct btf_type *t, enum bpf_prog_type prog_type, @@ -6023,6 +6039,7 @@ bool btf_is_prog_ctx_type(struct bpf_verifier_log *lo= g, const struct btf *btf, } return true; } +EXPORT_SYMBOL_GPL(btf_is_prog_ctx_type); =20 /* forward declarations for arch-specific underlying types of * bpf_user_pt_regs_t; this avoids the need for arch-specific #ifdef @@ -6197,6 +6214,7 @@ int get_kern_ctx_btf_id(struct bpf_verifier_log *log,= enum bpf_prog_type prog_ty =20 return kctx_type_id; } +EXPORT_SYMBOL_GPL(get_kern_ctx_btf_id); =20 BTF_ID_LIST(bpf_ctx_convert_btf_id) BTF_ID(struct, bpf_ctx_convert) @@ -6280,6 +6298,7 @@ struct btf *btf_parse_vmlinux(void) btf_verifier_env_free(env); return btf; } +EXPORT_SYMBOL_GPL(btf_parse_vmlinux); =20 /* If .BTF_ids section was created with distilled base BTF, both base and * split BTF ids will need to be mapped to actual base/split ids for @@ -7257,6 +7276,7 @@ int btf_struct_access(struct bpf_verifier_log *log, =20 return -EINVAL; } +EXPORT_SYMBOL_GPL(btf_struct_access); =20 /* Check that two BTF types, each specified as an BTF object + id, are exa= ctly * the same. Trivial ID check is not enough due to module BTFs, because we= can @@ -7272,6 +7292,7 @@ bool btf_types_are_same(const struct btf *btf1, u32 i= d1, return true; return btf_type_by_id(btf1, id1) =3D=3D btf_type_by_id(btf2, id2); } +EXPORT_SYMBOL_GPL(btf_types_are_same); =20 bool btf_struct_ids_match(struct bpf_verifier_log *log, const struct btf *btf, u32 id, int off, @@ -7311,6 +7332,7 @@ bool btf_struct_ids_match(struct bpf_verifier_log *lo= g, =20 return true; } +EXPORT_SYMBOL_GPL(btf_struct_ids_match); =20 static int __get_type_size(struct btf *btf, u32 btf_id, const struct btf_type **ret_type) @@ -7417,6 +7439,7 @@ int btf_distill_func_proto(struct bpf_verifier_log *l= og, m->nr_args =3D nargs; return 0; } +EXPORT_SYMBOL_GPL(btf_distill_func_proto); =20 /* Compare BTFs of two functions assuming only scalars and pointers to con= text. * t1 points to BTF_KIND_FUNC in btf1 @@ -7559,6 +7582,7 @@ int btf_check_type_match(struct bpf_verifier_log *log= , const struct bpf_prog *pr =20 return btf_check_func_type_match(log, btf1, t1, btf2, t2); } +EXPORT_SYMBOL_GPL(btf_check_type_match); =20 static bool btf_is_dynptr_ptr(const struct btf *btf, const struct btf_type= *t) { @@ -7872,6 +7896,7 @@ int btf_prepare_func_args(struct bpf_verifier_env *en= v, int subprog) =20 return 0; } +EXPORT_SYMBOL_GPL(btf_prepare_func_args); =20 static void btf_type_show(const struct btf *btf, u32 type_id, void *obj, struct btf_show *show) @@ -7983,6 +8008,7 @@ const struct file_operations btf_fops =3D { #endif .release =3D btf_release, }; +EXPORT_SYMBOL_GPL(btf_fops); =20 static int __btf_new_fd(struct btf *btf) { @@ -8028,6 +8054,7 @@ struct btf *btf_get_by_fd(int fd) =20 return btf; } +EXPORT_SYMBOL_GPL(btf_get_by_fd); =20 int btf_get_info_by_fd(const struct btf *btf, const union bpf_attr *attr, @@ -8114,16 +8141,19 @@ u32 btf_obj_id(const struct btf *btf) { return btf->id; } +EXPORT_SYMBOL_GPL(btf_obj_id); =20 bool btf_is_kernel(const struct btf *btf) { return btf->kernel_btf; } +EXPORT_SYMBOL_GPL(btf_is_kernel); =20 bool btf_is_module(const struct btf *btf) { return btf->kernel_btf && strcmp(btf->name, "vmlinux") !=3D 0; } +EXPORT_SYMBOL_GPL(btf_is_module); =20 enum { BTF_MODULE_F_LIVE =3D (1 << 0), @@ -8289,6 +8319,7 @@ struct module *btf_try_get_module(const struct btf *b= tf) =20 return res; } +EXPORT_SYMBOL_GPL(btf_try_get_module); =20 /* Returns struct btf corresponding to the struct module. * This function can return NULL or ERR_PTR. @@ -8374,6 +8405,7 @@ BTF_ID_LIST_GLOBAL(btf_tracing_ids, MAX_BTF_TRACING_T= YPE) #define BTF_TRACING_TYPE(name, type) BTF_ID(struct, type) BTF_TRACING_TYPE_xxx #undef BTF_TRACING_TYPE +EXPORT_SYMBOL_GPL(btf_tracing_ids); =20 /* Validate well-formedness of iter argument type. * On success, return positive BTF ID of iter state's STRUCT type. @@ -8403,6 +8435,7 @@ int btf_check_iter_arg(struct btf *btf, const struct = btf_type *func, int arg_idx =20 return btf_id; } +EXPORT_SYMBOL_GPL(btf_check_iter_arg); =20 static int btf_check_iter_kfuncs(struct btf *btf, const char *func_name, const struct btf_type *func, u32 func_flags) @@ -8708,12 +8741,14 @@ u32 *btf_kfunc_id_set_contains(const struct btf *bt= f, hook =3D bpf_prog_type_to_kfunc_hook(prog_type); return __btf_kfunc_id_set_contains(btf, hook, kfunc_btf_id, prog); } +EXPORT_SYMBOL_GPL(btf_kfunc_id_set_contains); =20 u32 *btf_kfunc_is_modify_return(const struct btf *btf, u32 kfunc_btf_id, const struct bpf_prog *prog) { return __btf_kfunc_id_set_contains(btf, BTF_KFUNC_HOOK_FMODRET, kfunc_btf= _id, prog); } +EXPORT_SYMBOL_GPL(btf_kfunc_is_modify_return); =20 static int __register_btf_kfunc_id_set(enum btf_kfunc_hook hook, const struct btf_kfunc_id_set *kset) @@ -9311,6 +9346,7 @@ int bpf_core_apply(struct bpf_core_ctx *ctx, const st= ruct bpf_core_relo *relo, } return err; } +EXPORT_SYMBOL_GPL(bpf_core_apply); =20 bool btf_nested_type_is_trusted(struct bpf_verifier_log *log, const struct bpf_reg_state *reg, @@ -9358,6 +9394,7 @@ bool btf_nested_type_is_trusted(struct bpf_verifier_l= og *log, =20 return false; } +EXPORT_SYMBOL_GPL(btf_nested_type_is_trusted); =20 bool btf_type_ids_nocast_alias(struct bpf_verifier_log *log, const struct btf *reg_btf, u32 reg_id, @@ -9413,6 +9450,7 @@ bool btf_type_ids_nocast_alias(struct bpf_verifier_lo= g *log, =20 return !strncmp(reg_name, arg_name, cmp_len); } +EXPORT_SYMBOL_GPL(btf_type_ids_nocast_alias); =20 #ifdef CONFIG_BPF_JIT static int @@ -9502,6 +9540,7 @@ bpf_struct_ops_find(struct btf *btf, u32 type_id) =20 return NULL; } +EXPORT_SYMBOL_GPL(bpf_struct_ops_find); =20 int __register_bpf_struct_ops(struct bpf_struct_ops *st_ops) { @@ -9551,3 +9590,4 @@ bool btf_param_match_suffix(const struct btf *btf, param_name +=3D len - suffix_len; return !strncmp(param_name, suffix, suffix_len); } +EXPORT_SYMBOL_GPL(btf_param_match_suffix); diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c index 84f58f3d028a..3168389a2972 100644 --- a/kernel/bpf/cgroup.c +++ b/kernel/bpf/cgroup.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -1702,6 +1703,7 @@ const struct bpf_verifier_ops cg_dev_verifier_ops =3D= { .get_func_proto =3D cgroup_dev_func_proto, .is_valid_access =3D cgroup_dev_is_valid_access, }; +EXPORT_SYMBOL_GPL(cg_dev_verifier_ops); =20 /** * __cgroup_bpf_run_filter_sysctl - Run a program on sysctl @@ -2322,6 +2324,7 @@ const struct bpf_verifier_ops cg_sysctl_verifier_ops = =3D { .is_valid_access =3D sysctl_is_valid_access, .convert_ctx_access =3D sysctl_convert_ctx_access, }; +EXPORT_SYMBOL_GPL(cg_sysctl_verifier_ops); =20 const struct bpf_prog_ops cg_sysctl_prog_ops =3D { }; @@ -2550,6 +2553,7 @@ const struct bpf_verifier_ops cg_sockopt_verifier_ops= =3D { .convert_ctx_access =3D cg_sockopt_convert_ctx_access, .gen_prologue =3D cg_sockopt_get_prologue, }; +EXPORT_SYMBOL_GPL(cg_sockopt_verifier_ops); =20 const struct bpf_prog_ops cg_sockopt_prog_ops =3D { }; diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 13301a668fe0..6c8bb4cdac0f 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -69,6 +69,7 @@ =20 struct bpf_mem_alloc bpf_global_ma; bool bpf_global_ma_set; +EXPORT_SYMBOL_GPL(bpf_global_ma_set); =20 struct bpf_mem_alloc bpf_global_percpu_ma; EXPORT_SYMBOL_GPL(bpf_global_percpu_ma); @@ -510,6 +511,7 @@ struct bpf_prog *bpf_prog_alloc_no_stats(unsigned int s= ize, gfp_t gfp_extra_flag =20 return fp; } +EXPORT_SYMBOL_GPL(bpf_prog_alloc_no_stats); =20 struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags) { @@ -552,6 +554,7 @@ int bpf_prog_alloc_jited_linfo(struct bpf_prog *prog) =20 return 0; } +EXPORT_SYMBOL_GPL(bpf_prog_alloc_jited_linfo); =20 void bpf_prog_jit_attempt_done(struct bpf_prog *prog) { @@ -564,6 +567,7 @@ void bpf_prog_jit_attempt_done(struct bpf_prog *prog) kfree(prog->aux->kfunc_tab); prog->aux->kfunc_tab =3D NULL; } +EXPORT_SYMBOL_GPL(bpf_prog_jit_attempt_done); =20 /* The jit engine is responsible to provide an array * for insn_off to the jited_off mapping (insn_to_jit_off). @@ -733,6 +737,7 @@ int bpf_prog_calc_tag(struct bpf_prog *fp) vfree(raw); return 0; } +EXPORT_SYMBOL_GPL(bpf_prog_calc_tag); =20 static int bpf_adj_delta_to_imm(struct bpf_insn *insn, u32 pos, s32 end_ol= d, s32 end_new, s32 curr, const bool probe_pass) @@ -910,6 +915,7 @@ struct bpf_prog *bpf_patch_insn_single(struct bpf_prog = *prog, u32 off, =20 return prog_adj; } +EXPORT_SYMBOL_GPL(bpf_patch_insn_single); =20 int bpf_remove_insns(struct bpf_prog *prog, u32 off, u32 cnt) { @@ -926,6 +932,7 @@ int bpf_remove_insns(struct bpf_prog *prog, u32 off, u3= 2 cnt) WARN_ON_ONCE(err); return err; } +EXPORT_SYMBOL_GPL(bpf_remove_insns); =20 static void bpf_prog_kallsyms_del_subprogs(struct bpf_prog *fp) { @@ -1093,6 +1100,7 @@ void bpf_prog_kallsyms_add(struct bpf_prog *fp) bpf_ksym_add(&fp->aux->ksym_prefix); #endif } +EXPORT_SYMBOL_GPL(bpf_prog_kallsyms_add); =20 void bpf_prog_kallsyms_del(struct bpf_prog *fp) { @@ -1238,6 +1246,7 @@ int bpf_jit_add_poke_descriptor(struct bpf_prog *prog, =20 return slot; } +EXPORT_SYMBOL_GPL(bpf_jit_add_poke_descriptor); =20 /* * BPF program pack allocator. @@ -2129,6 +2138,7 @@ bool bpf_opcode_in_insntable(u8 code) #undef BPF_INSN_2_TBL return public_insntable[code]; } +EXPORT_SYMBOL_GPL(bpf_opcode_in_insntable); =20 #ifndef CONFIG_BPF_JIT_ALWAYS_ON /** @@ -3237,6 +3247,7 @@ void __bpf_free_used_maps(struct bpf_prog_aux *aux, bpf_map_put(map); } } +EXPORT_SYMBOL_GPL(__bpf_free_used_maps); =20 static void bpf_free_used_maps(struct bpf_prog_aux *aux) { @@ -3258,6 +3269,7 @@ void __bpf_free_used_btfs(struct btf_mod_pair *used_b= tfs, u32 len) } #endif } +EXPORT_SYMBOL_GPL(__bpf_free_used_btfs); =20 static void bpf_free_used_btfs(struct bpf_prog_aux *aux) { @@ -3336,6 +3348,7 @@ void bpf_user_rnd_init_once(void) { prandom_init_once(&bpf_user_rnd_state); } +EXPORT_SYMBOL_GPL(bpf_user_rnd_init_once); =20 BPF_CALL_0(bpf_user_rnd_u32) { @@ -3445,6 +3458,7 @@ bool __weak bpf_helper_changes_pkt_data(enum bpf_func= _id func_id) { return false; } +EXPORT_SYMBOL_GPL(bpf_helper_changes_pkt_data); =20 /* Return TRUE if the JIT backend wants verifier to enable sub-register us= age * analysis code and wants explicit zero extension inserted by verifier. @@ -3458,6 +3472,7 @@ bool __weak bpf_jit_needs_zext(void) { return false; } +EXPORT_SYMBOL_GPL(bpf_jit_needs_zext); =20 /* Return true if the JIT inlines the call to the helper corresponding to * the imm. @@ -3469,37 +3484,44 @@ bool __weak bpf_jit_inlines_helper_call(s32 imm) { return false; } +EXPORT_SYMBOL_GPL(bpf_jit_inlines_helper_call); =20 /* Return TRUE if the JIT backend supports mixing bpf2bpf and tailcalls. */ bool __weak bpf_jit_supports_subprog_tailcalls(void) { return false; } +EXPORT_SYMBOL_GPL(bpf_jit_supports_subprog_tailcalls); =20 bool __weak bpf_jit_supports_percpu_insn(void) { return false; } +EXPORT_SYMBOL_GPL(bpf_jit_supports_percpu_insn); =20 bool __weak bpf_jit_supports_kfunc_call(void) { return false; } +EXPORT_SYMBOL_GPL(bpf_jit_supports_kfunc_call); =20 bool __weak bpf_jit_supports_far_kfunc_call(void) { return false; } +EXPORT_SYMBOL_GPL(bpf_jit_supports_far_kfunc_call); =20 bool __weak bpf_jit_supports_arena(void) { return false; } +EXPORT_SYMBOL_GPL(bpf_jit_supports_arena); =20 bool __weak bpf_jit_supports_insn(struct bpf_insn *insn, bool in_arena) { return false; } +EXPORT_SYMBOL_GPL(bpf_jit_supports_insn); =20 u64 __weak bpf_arch_uaddress_limit(void) { @@ -3509,6 +3531,7 @@ u64 __weak bpf_arch_uaddress_limit(void) return 0; #endif } +EXPORT_SYMBOL_GPL(bpf_arch_uaddress_limit); =20 /* Return TRUE if the JIT backend satisfies the following two conditions: * 1) JIT backend supports atomic_xchg() on pointer-sized words. @@ -3519,6 +3542,7 @@ bool __weak bpf_jit_supports_ptr_xchg(void) { return false; } +EXPORT_SYMBOL_GPL(bpf_jit_supports_ptr_xchg); =20 /* To execute LD_ABS/LD_IND instructions __bpf_prog_run() may call * skb_copy_bits(), so provide a weak definition of it for NET-less config. @@ -3549,11 +3573,13 @@ bool __weak bpf_jit_supports_exceptions(void) { return false; } +EXPORT_SYMBOL_GPL(bpf_jit_supports_exceptions); =20 bool __weak bpf_jit_supports_private_stack(void) { return false; } +EXPORT_SYMBOL_GPL(bpf_jit_supports_private_stack); =20 void __weak arch_bpf_stack_walk(bool (*consume_fn)(void *cookie, u64 ip, u= 64 sp, u64 bp), void *cookie) { @@ -3563,11 +3589,13 @@ bool __weak bpf_jit_supports_timed_may_goto(void) { return false; } +EXPORT_SYMBOL_GPL(bpf_jit_supports_timed_may_goto); =20 u64 __weak arch_bpf_timed_may_goto(void) { return 0; } +EXPORT_SYMBOL_GPL(arch_bpf_timed_may_goto); =20 u64 bpf_check_timed_may_goto(struct bpf_timed_may_goto *p) { @@ -3591,6 +3619,7 @@ __weak u64 bpf_arena_get_user_vm_start(struct bpf_are= na *arena) { return 0; } +EXPORT_SYMBOL_GPL(bpf_arena_get_user_vm_start); __weak u64 bpf_arena_get_kern_vm_start(struct bpf_arena *arena) { return 0; diff --git a/kernel/bpf/disasm.c b/kernel/bpf/disasm.c index 20883c6b1546..ab441a6b8b54 100644 --- a/kernel/bpf/disasm.c +++ b/kernel/bpf/disasm.c @@ -4,6 +4,7 @@ */ =20 #include +#include =20 #include "disasm.h" =20 @@ -58,6 +59,7 @@ const char *func_id_name(int id) else return "unknown"; } +EXPORT_SYMBOL_GPL(func_id_name); =20 const char *const bpf_class_string[8] =3D { [BPF_LD] =3D "ld", @@ -86,6 +88,7 @@ const char *const bpf_alu_string[16] =3D { [BPF_ARSH >> 4] =3D "s>>=3D", [BPF_END >> 4] =3D "endian", }; +EXPORT_SYMBOL_GPL(bpf_alu_string); =20 static const char *const bpf_alu_sign_string[16] =3D { [BPF_DIV >> 4] =3D "s/=3D", @@ -388,3 +391,4 @@ void print_bpf_insn(const struct bpf_insn_cbs *cbs, insn->code, bpf_class_string[class]); } } +EXPORT_SYMBOL_GPL(print_bpf_insn); diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c index e3a2662f4e33..46816949b78f 100644 --- a/kernel/bpf/helpers.c +++ b/kernel/bpf/helpers.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -1041,6 +1042,7 @@ int bpf_bprintf_prepare(char *fmt, u32 fmt_size, cons= t u64 *raw_args, bpf_bprintf_cleanup(data); return err; } +EXPORT_SYMBOL_GPL(bpf_bprintf_prepare); =20 BPF_CALL_5(bpf_snprintf, char *, str, u32, str_size, char *, fmt, const void *, args, u32, data_len) diff --git a/kernel/bpf/local_storage.c b/kernel/bpf/local_storage.c index 3969eb0382af..1743d1f434fc 100644 --- a/kernel/bpf/local_storage.c +++ b/kernel/bpf/local_storage.c @@ -4,6 +4,7 @@ #include #include #include +#include #include #include #include @@ -478,6 +479,7 @@ int bpf_cgroup_storage_assign(struct bpf_prog_aux *aux,= struct bpf_map *_map) aux->cgroup_storage[stype] =3D _map; return 0; } +EXPORT_SYMBOL_GPL(bpf_cgroup_storage_assign); =20 static size_t bpf_cgroup_storage_calculate_size(struct bpf_map *map, u32 *= pages) { diff --git a/kernel/bpf/log.c b/kernel/bpf/log.c index 38050f4ee400..0ed4e0b89fdf 100644 --- a/kernel/bpf/log.c +++ b/kernel/bpf/log.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include =20 @@ -41,6 +42,7 @@ int bpf_vlog_init(struct bpf_verifier_log *log, u32 log_l= evel, =20 return 0; } +EXPORT_SYMBOL_GPL(bpf_vlog_init); =20 static void bpf_vlog_update_len_max(struct bpf_verifier_log *log, u32 add_= len) { @@ -145,6 +147,7 @@ void bpf_verifier_vlog(struct bpf_verifier_log *log, co= nst char *fmt, fail: log->ubuf =3D NULL; } +EXPORT_SYMBOL_GPL(bpf_verifier_vlog); =20 void bpf_vlog_reset(struct bpf_verifier_log *log, u64 new_pos) { @@ -176,6 +179,7 @@ void bpf_vlog_reset(struct bpf_verifier_log *log, u64 n= ew_pos) if (pos < log->len_total && put_user(zero, log->ubuf + pos)) log->ubuf =3D NULL; } +EXPORT_SYMBOL_GPL(bpf_vlog_reset); =20 static void bpf_vlog_reverse_kbuf(char *buf, int len) { @@ -296,6 +300,7 @@ int bpf_vlog_finalize(struct bpf_verifier_log *log, u32= *log_size_actual) =20 return 0; } +EXPORT_SYMBOL_GPL(bpf_vlog_finalize); =20 /* log_level controls verbosity level of eBPF verifier. * bpf_verifier_log_write() is used to dump the verification trace to the = log, @@ -426,6 +431,7 @@ __printf(3, 4) void verbose_linfo(struct bpf_verifier_e= nv *env, =20 env->prev_linfo =3D linfo; } +EXPORT_SYMBOL_GPL(verbose_linfo); =20 static const char *btf_type_name(const struct btf *btf, u32 id) { @@ -486,6 +492,7 @@ const char *reg_type_str(struct bpf_verifier_env *env, = enum bpf_reg_type type) prefix, str[base_type(type)], postfix); return env->tmp_str_buf; } +EXPORT_SYMBOL_GPL(reg_type_str); =20 const char *dynptr_type_str(enum bpf_dynptr_type type) { @@ -505,6 +512,7 @@ const char *dynptr_type_str(enum bpf_dynptr_type type) return ""; } } +EXPORT_SYMBOL_GPL(dynptr_type_str); =20 const char *iter_type_str(const struct btf *btf, u32 btf_id) { @@ -514,6 +522,7 @@ const char *iter_type_str(const struct btf *btf, u32 bt= f_id) /* we already validated that type is valid and has conforming name */ return btf_type_name(btf, btf_id) + sizeof(ITER_PREFIX) - 1; } +EXPORT_SYMBOL_GPL(iter_type_str); =20 const char *iter_state_str(enum bpf_iter_state state) { @@ -529,6 +538,7 @@ const char *iter_state_str(enum bpf_iter_state state) return ""; } } +EXPORT_SYMBOL_GPL(iter_state_str); =20 static char slot_type_char[] =3D { [STACK_INVALID] =3D '?', @@ -859,6 +869,7 @@ void print_verifier_state(struct bpf_verifier_env *env,= const struct bpf_verifie if (!print_all) mark_verifier_state_clean(env); } +EXPORT_SYMBOL_GPL(print_verifier_state); =20 static inline u32 vlog_alignment(u32 pos) { @@ -878,3 +889,4 @@ void print_insn_state(struct bpf_verifier_env *env, con= st struct bpf_verifier_st } print_verifier_state(env, vstate, frameno, false); } +EXPORT_SYMBOL_GPL(print_insn_state); diff --git a/kernel/bpf/map_iter.c b/kernel/bpf/map_iter.c index 9575314f40a6..e6c3142b9e91 100644 --- a/kernel/bpf/map_iter.c +++ b/kernel/bpf/map_iter.c @@ -79,6 +79,7 @@ static const struct seq_operations bpf_map_seq_ops =3D { }; =20 BTF_ID_LIST_GLOBAL_SINGLE(btf_bpf_map_id, struct, bpf_map) +EXPORT_SYMBOL_GPL(btf_bpf_map_id); =20 static const struct bpf_iter_seq_info bpf_map_seq_info =3D { .seq_ops =3D &bpf_map_seq_ops, diff --git a/kernel/bpf/memalloc.c b/kernel/bpf/memalloc.c index 889374722d0a..a35079962965 100644 --- a/kernel/bpf/memalloc.c +++ b/kernel/bpf/memalloc.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -587,6 +588,7 @@ int bpf_mem_alloc_percpu_init(struct bpf_mem_alloc *ma,= struct obj_cgroup *objcg ma->percpu =3D true; return 0; } +EXPORT_SYMBOL_GPL(bpf_mem_alloc_percpu_init); =20 int bpf_mem_alloc_percpu_unit_init(struct bpf_mem_alloc *ma, int size) { @@ -623,6 +625,7 @@ int bpf_mem_alloc_percpu_unit_init(struct bpf_mem_alloc= *ma, int size) =20 return 0; } +EXPORT_SYMBOL_GPL(bpf_mem_alloc_percpu_unit_init); =20 static void drain_mem_cache(struct bpf_mem_cache *c) { diff --git a/kernel/bpf/offload.c b/kernel/bpf/offload.c index 42ae8d595c2c..e20d0e9f5fed 100644 --- a/kernel/bpf/offload.c +++ b/kernel/bpf/offload.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -309,6 +310,7 @@ int bpf_prog_offload_verifier_prep(struct bpf_prog *pro= g) =20 return ret; } +EXPORT_SYMBOL_GPL(bpf_prog_offload_verifier_prep); =20 int bpf_prog_offload_verify_insn(struct bpf_verifier_env *env, int insn_idx, int prev_insn_idx) @@ -325,6 +327,7 @@ int bpf_prog_offload_verify_insn(struct bpf_verifier_en= v *env, =20 return ret; } +EXPORT_SYMBOL_GPL(bpf_prog_offload_verify_insn); =20 int bpf_prog_offload_finalize(struct bpf_verifier_env *env) { @@ -343,6 +346,7 @@ int bpf_prog_offload_finalize(struct bpf_verifier_env *= env) =20 return ret; } +EXPORT_SYMBOL_GPL(bpf_prog_offload_finalize); =20 void bpf_prog_offload_replace_insn(struct bpf_verifier_env *env, u32 off, @@ -362,6 +366,7 @@ bpf_prog_offload_replace_insn(struct bpf_verifier_env *= env, u32 off, } up_read(&bpf_devs_lock); } +EXPORT_SYMBOL_GPL(bpf_prog_offload_replace_insn); =20 void bpf_prog_offload_remove_insns(struct bpf_verifier_env *env, u32 off, u32 c= nt) @@ -378,6 +383,7 @@ bpf_prog_offload_remove_insns(struct bpf_verifier_env *= env, u32 off, u32 cnt) } up_read(&bpf_devs_lock); } +EXPORT_SYMBOL_GPL(bpf_prog_offload_remove_insns); =20 void bpf_prog_dev_bound_destroy(struct bpf_prog *prog) { @@ -744,6 +750,7 @@ bool bpf_prog_dev_bound_match(const struct bpf_prog *lh= s, const struct bpf_prog =20 return ret; } +EXPORT_SYMBOL_GPL(bpf_prog_dev_bound_match); =20 bool bpf_offload_prog_map_match(struct bpf_prog *prog, struct bpf_map *map) { @@ -760,6 +767,7 @@ bool bpf_offload_prog_map_match(struct bpf_prog *prog, = struct bpf_map *map) =20 return ret; } +EXPORT_SYMBOL_GPL(bpf_offload_prog_map_match); =20 int bpf_offload_dev_netdev_register(struct bpf_offload_dev *offdev, struct net_device *netdev) @@ -840,6 +848,7 @@ int bpf_dev_bound_kfunc_check(struct bpf_verifier_log *= log, =20 return 0; } +EXPORT_SYMBOL_GPL(bpf_dev_bound_kfunc_check); =20 void *bpf_dev_bound_resolve_kfunc(struct bpf_prog *prog, u32 func_id) { @@ -869,6 +878,7 @@ void *bpf_dev_bound_resolve_kfunc(struct bpf_prog *prog= , u32 func_id) =20 return p; } +EXPORT_SYMBOL_GPL(bpf_dev_bound_resolve_kfunc); =20 static int __init bpf_offload_init(void) { diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 9794446bc8c6..2ef55503ba32 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -104,6 +105,7 @@ int bpf_check_uarg_tail_zero(bpfptr_t uaddr, return res; return res ? 0 : -E2BIG; } +EXPORT_SYMBOL_GPL(bpf_check_uarg_tail_zero); =20 const struct bpf_map_ops bpf_map_offload_ops =3D { .map_meta_equal =3D bpf_map_meta_equal, @@ -112,6 +114,7 @@ const struct bpf_map_ops bpf_map_offload_ops =3D { .map_check_btf =3D map_check_no_btf, .map_mem_usage =3D bpf_map_offload_map_mem_usage, }; +EXPORT_SYMBOL_GPL(bpf_map_offload_ops); =20 static void bpf_map_write_active_inc(struct bpf_map *map) { @@ -127,6 +130,7 @@ bool bpf_map_write_active(const struct bpf_map *map) { return atomic64_read(&map->writecnt) !=3D 0; } +EXPORT_SYMBOL_GPL(bpf_map_write_active); =20 static u32 bpf_map_value_size(const struct bpf_map *map) { @@ -642,6 +646,7 @@ struct btf_field *btf_record_find(const struct btf_reco= rd *rec, u32 offset, return NULL; return field; } +EXPORT_SYMBOL_GPL(btf_record_find); =20 void btf_record_free(struct btf_record *rec) { @@ -1145,6 +1150,7 @@ const struct file_operations bpf_map_fops =3D { .poll =3D bpf_map_poll, .get_unmapped_area =3D bpf_get_unmapped_area, }; +EXPORT_SYMBOL_GPL(bpf_map_fops); =20 int bpf_map_new_fd(struct bpf_map *map, int flags) { @@ -6103,6 +6109,7 @@ const struct bpf_verifier_ops bpf_syscall_verifier_op= s =3D { .get_func_proto =3D syscall_prog_func_proto, .is_valid_access =3D syscall_prog_is_valid_access, }; +EXPORT_SYMBOL_GPL(bpf_syscall_verifier_ops); =20 const struct bpf_prog_ops bpf_syscall_prog_ops =3D { .test_run =3D bpf_prog_test_run_syscall, diff --git a/kernel/bpf/tnum.c b/kernel/bpf/tnum.c index 9dbc31b25e3d..2f815447ace7 100644 --- a/kernel/bpf/tnum.c +++ b/kernel/bpf/tnum.c @@ -12,11 +12,13 @@ #define TNUM(_v, _m) (struct tnum){.value =3D _v, .mask =3D _m} /* A completely unknown value */ const struct tnum tnum_unknown =3D { .value =3D 0, .mask =3D -1 }; +EXPORT_SYMBOL_GPL(tnum_unknown); =20 struct tnum tnum_const(u64 value) { return TNUM(value, 0); } +EXPORT_SYMBOL_GPL(tnum_const); =20 struct tnum tnum_range(u64 min, u64 max) { @@ -33,16 +35,19 @@ struct tnum tnum_range(u64 min, u64 max) delta =3D (1ULL << bits) - 1; return TNUM(min & ~delta, delta); } +EXPORT_SYMBOL_GPL(tnum_range); =20 struct tnum tnum_lshift(struct tnum a, u8 shift) { return TNUM(a.value << shift, a.mask << shift); } +EXPORT_SYMBOL_GPL(tnum_lshift); =20 struct tnum tnum_rshift(struct tnum a, u8 shift) { return TNUM(a.value >> shift, a.mask >> shift); } +EXPORT_SYMBOL_GPL(tnum_rshift); =20 struct tnum tnum_arshift(struct tnum a, u8 min_shift, u8 insn_bitness) { @@ -58,6 +63,7 @@ struct tnum tnum_arshift(struct tnum a, u8 min_shift, u8 = insn_bitness) return TNUM((s64)a.value >> min_shift, (s64)a.mask >> min_shift); } +EXPORT_SYMBOL_GPL(tnum_arshift); =20 struct tnum tnum_add(struct tnum a, struct tnum b) { @@ -70,6 +76,7 @@ struct tnum tnum_add(struct tnum a, struct tnum b) mu =3D chi | a.mask | b.mask; return TNUM(sv & ~mu, mu); } +EXPORT_SYMBOL_GPL(tnum_add); =20 struct tnum tnum_sub(struct tnum a, struct tnum b) { @@ -82,6 +89,7 @@ struct tnum tnum_sub(struct tnum a, struct tnum b) mu =3D chi | a.mask | b.mask; return TNUM(dv & ~mu, mu); } +EXPORT_SYMBOL_GPL(tnum_sub); =20 struct tnum tnum_and(struct tnum a, struct tnum b) { @@ -92,6 +100,7 @@ struct tnum tnum_and(struct tnum a, struct tnum b) v =3D a.value & b.value; return TNUM(v, alpha & beta & ~v); } +EXPORT_SYMBOL_GPL(tnum_and); =20 struct tnum tnum_or(struct tnum a, struct tnum b) { @@ -101,6 +110,7 @@ struct tnum tnum_or(struct tnum a, struct tnum b) mu =3D a.mask | b.mask; return TNUM(v, mu & ~v); } +EXPORT_SYMBOL_GPL(tnum_or); =20 struct tnum tnum_xor(struct tnum a, struct tnum b) { @@ -110,6 +120,7 @@ struct tnum tnum_xor(struct tnum a, struct tnum b) mu =3D a.mask | b.mask; return TNUM(v & ~mu, mu); } +EXPORT_SYMBOL_GPL(tnum_xor); =20 /* Generate partial products by multiplying each bit in the multiplier (tn= um a) * with the multiplicand (tnum b), and add the partial products after @@ -137,6 +148,7 @@ struct tnum tnum_mul(struct tnum a, struct tnum b) } return tnum_add(TNUM(acc_v, 0), acc_m); } +EXPORT_SYMBOL_GPL(tnum_mul); =20 /* Note that if a and b disagree - i.e. one has a 'known 1' where the othe= r has * a 'known 0' - this will return a 'known 1' for that bit. @@ -149,6 +161,7 @@ struct tnum tnum_intersect(struct tnum a, struct tnum b) mu =3D a.mask & b.mask; return TNUM(v & ~mu, mu); } +EXPORT_SYMBOL_GPL(tnum_intersect); =20 struct tnum tnum_cast(struct tnum a, u8 size) { @@ -156,6 +169,7 @@ struct tnum tnum_cast(struct tnum a, u8 size) a.mask &=3D (1ULL << (size * 8)) - 1; return a; } +EXPORT_SYMBOL_GPL(tnum_cast); =20 bool tnum_is_aligned(struct tnum a, u64 size) { @@ -163,6 +177,7 @@ bool tnum_is_aligned(struct tnum a, u64 size) return true; return !((a.value | a.mask) & (size - 1)); } +EXPORT_SYMBOL_GPL(tnum_is_aligned); =20 bool tnum_in(struct tnum a, struct tnum b) { @@ -171,6 +186,7 @@ bool tnum_in(struct tnum a, struct tnum b) b.value &=3D ~a.mask; return a.value =3D=3D b.value; } +EXPORT_SYMBOL_GPL(tnum_in); =20 int tnum_sbin(char *str, size_t size, struct tnum a) { @@ -196,18 +212,22 @@ struct tnum tnum_subreg(struct tnum a) { return tnum_cast(a, 4); } +EXPORT_SYMBOL_GPL(tnum_subreg); =20 struct tnum tnum_clear_subreg(struct tnum a) { return tnum_lshift(tnum_rshift(a, 32), 32); } +EXPORT_SYMBOL_GPL(tnum_clear_subreg); =20 struct tnum tnum_with_subreg(struct tnum reg, struct tnum subreg) { return tnum_or(tnum_clear_subreg(reg), tnum_subreg(subreg)); } +EXPORT_SYMBOL_GPL(tnum_with_subreg); =20 struct tnum tnum_const_subreg(struct tnum a, u32 value) { return tnum_with_subreg(a, tnum_const(value)); } +EXPORT_SYMBOL_GPL(tnum_const_subreg); diff --git a/kernel/bpf/token.c b/kernel/bpf/token.c index 26057aa13503..76936e8cf5af 100644 --- a/kernel/bpf/token.c +++ b/kernel/bpf/token.c @@ -25,6 +25,7 @@ bool bpf_token_capable(const struct bpf_token *token, int= cap) return false; return true; } +EXPORT_SYMBOL_GPL(bpf_token_capable); =20 void bpf_token_inc(struct bpf_token *token) { diff --git a/kernel/bpf/trampoline.c b/kernel/bpf/trampoline.c index c4b1a98ff726..0ec41c025996 100644 --- a/kernel/bpf/trampoline.c +++ b/kernel/bpf/trampoline.c @@ -2,6 +2,7 @@ /* Copyright (c) 2019 Facebook */ #include #include +#include #include #include #include @@ -17,6 +18,8 @@ /* dummy _ops. The verifier will operate on target program's ops. */ const struct bpf_verifier_ops bpf_extension_verifier_ops =3D { }; +EXPORT_SYMBOL_GPL(bpf_extension_verifier_ops); + const struct bpf_prog_ops bpf_extension_prog_ops =3D { }; =20 @@ -114,6 +117,7 @@ bool bpf_prog_has_trampoline(const struct bpf_prog *pro= g) eatype =3D=3D BPF_MODIFY_RETURN)) || (ptype =3D=3D BPF_PROG_TYPE_LSM && eatype =3D=3D BPF_LSM_MAC); } +EXPORT_SYMBOL_GPL(bpf_prog_has_trampoline); =20 void bpf_image_ksym_init(void *data, unsigned int size, struct bpf_ksym *k= sym) { @@ -836,6 +840,7 @@ struct bpf_trampoline *bpf_trampoline_get(u64 key, mutex_unlock(&tr->mutex); return tr; } +EXPORT_SYMBOL_GPL(bpf_trampoline_get); =20 void bpf_trampoline_put(struct bpf_trampoline *tr) { diff --git a/kernel/events/callchain.c b/kernel/events/callchain.c index 6c83ad674d01..5b19c4ed0c92 100644 --- a/kernel/events/callchain.c +++ b/kernel/events/callchain.c @@ -21,6 +21,8 @@ struct callchain_cpus_entries { }; =20 int sysctl_perf_event_max_stack __read_mostly =3D PERF_MAX_STACK_DEPTH; +EXPORT_SYMBOL_GPL(sysctl_perf_event_max_stack); + int sysctl_perf_event_max_contexts_per_stack __read_mostly =3D PERF_MAX_CO= NTEXTS_PER_STACK; static const int six_hundred_forty_kb =3D 640 * 1024; =20 @@ -142,6 +144,7 @@ int get_callchain_buffers(int event_max_stack) =20 return err; } +EXPORT_SYMBOL_GPL(get_callchain_buffers); =20 void put_callchain_buffers(void) { diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c index 187dc37d61d4..fd9c5903605c 100644 --- a/kernel/trace/bpf_trace.c +++ b/kernel/trace/bpf_trace.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -1645,6 +1646,7 @@ const struct bpf_verifier_ops kprobe_verifier_ops =3D= { .get_func_proto =3D kprobe_prog_func_proto, .is_valid_access =3D kprobe_prog_is_valid_access, }; +EXPORT_SYMBOL_GPL(kprobe_verifier_ops); =20 const struct bpf_prog_ops kprobe_prog_ops =3D { }; @@ -1751,6 +1753,7 @@ const struct bpf_verifier_ops tracepoint_verifier_ops= =3D { .get_func_proto =3D tp_prog_func_proto, .is_valid_access =3D tp_prog_is_valid_access, }; +EXPORT_SYMBOL_GPL(tracepoint_verifier_ops); =20 const struct bpf_prog_ops tracepoint_prog_ops =3D { }; @@ -2067,6 +2070,7 @@ const struct bpf_verifier_ops raw_tracepoint_verifier= _ops =3D { .get_func_proto =3D raw_tp_prog_func_proto, .is_valid_access =3D raw_tp_prog_is_valid_access, }; +EXPORT_SYMBOL_GPL(raw_tracepoint_verifier_ops); =20 const struct bpf_prog_ops raw_tracepoint_prog_ops =3D { #ifdef CONFIG_NET @@ -2078,6 +2082,7 @@ const struct bpf_verifier_ops tracing_verifier_ops = =3D { .get_func_proto =3D tracing_prog_func_proto, .is_valid_access =3D tracing_prog_is_valid_access, }; +EXPORT_SYMBOL_GPL(tracing_verifier_ops); =20 const struct bpf_prog_ops tracing_prog_ops =3D { .test_run =3D bpf_prog_test_run_tracing, @@ -2100,6 +2105,7 @@ const struct bpf_verifier_ops raw_tracepoint_writable= _verifier_ops =3D { .get_func_proto =3D raw_tp_prog_func_proto, .is_valid_access =3D raw_tp_writable_prog_is_valid_access, }; +EXPORT_SYMBOL_GPL(raw_tracepoint_writable_verifier_ops); =20 const struct bpf_prog_ops raw_tracepoint_writable_prog_ops =3D { }; @@ -2183,6 +2189,7 @@ const struct bpf_verifier_ops perf_event_verifier_ops= =3D { .is_valid_access =3D pe_prog_is_valid_access, .convert_ctx_access =3D pe_prog_convert_ctx_access, }; +EXPORT_SYMBOL_GPL(perf_event_verifier_ops); =20 const struct bpf_prog_ops perf_event_prog_ops =3D { }; @@ -2333,6 +2340,7 @@ struct bpf_raw_event_map *bpf_get_raw_tracepoint(cons= t char *name) =20 return bpf_get_raw_tracepoint_module(name); } +EXPORT_SYMBOL_GPL(bpf_get_raw_tracepoint); =20 void bpf_put_raw_tracepoint(struct bpf_raw_event_map *btp) { @@ -2342,6 +2350,7 @@ void bpf_put_raw_tracepoint(struct bpf_raw_event_map = *btp) mod =3D __module_address((unsigned long)btp); module_put(mod); } +EXPORT_SYMBOL_GPL(bpf_put_raw_tracepoint); =20 static __always_inline void __bpf_trace_run(struct bpf_raw_tp_link *link, u64 *args) diff --git a/lib/error-inject.c b/lib/error-inject.c index 887acd9a6ea6..10312e487843 100644 --- a/lib/error-inject.c +++ b/lib/error-inject.c @@ -2,6 +2,7 @@ // error-inject.c: Function-level error injection table #include #include +#include #include #include #include @@ -36,6 +37,7 @@ bool within_error_injection_list(unsigned long addr) mutex_unlock(&ei_mutex); return ret; } +EXPORT_SYMBOL_GPL(within_error_injection_list); =20 int get_injectable_error_type(unsigned long addr) { diff --git a/net/core/filter.c b/net/core/filter.c index bc6828761a47..5c4908fd6bf8 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -7194,6 +7195,7 @@ bool bpf_tcp_sock_is_valid_access(int off, int size, = enum bpf_access_type type, return size =3D=3D sizeof(__u32); } } +EXPORT_SYMBOL_GPL(bpf_tcp_sock_is_valid_access); =20 u32 bpf_tcp_sock_convert_ctx_access(enum bpf_access_type type, const struct bpf_insn *si, @@ -7317,6 +7319,7 @@ u32 bpf_tcp_sock_convert_ctx_access(enum bpf_access_t= ype type, =20 return insn - insn_buf; } +EXPORT_SYMBOL_GPL(bpf_tcp_sock_convert_ctx_access); =20 BPF_CALL_1(bpf_tcp_sock, struct sock *, sk) { @@ -7388,6 +7391,7 @@ bool bpf_xdp_sock_is_valid_access(int off, int size, = enum bpf_access_type type, return size =3D=3D sizeof(__u32); } } +EXPORT_SYMBOL_GPL(bpf_xdp_sock_is_valid_access); =20 u32 bpf_xdp_sock_convert_ctx_access(enum bpf_access_type type, const struct bpf_insn *si, @@ -7413,6 +7417,7 @@ u32 bpf_xdp_sock_convert_ctx_access(enum bpf_access_t= ype type, =20 return insn - insn_buf; } +EXPORT_SYMBOL_GPL(bpf_xdp_sock_convert_ctx_access); =20 static const struct bpf_func_proto bpf_skb_ecn_set_ce_proto =3D { .func =3D bpf_skb_ecn_set_ce, @@ -8879,6 +8884,7 @@ bool bpf_sock_common_is_valid_access(int off, int siz= e, return bpf_sock_is_valid_access(off, size, type, info); } } +EXPORT_SYMBOL_GPL(bpf_sock_common_is_valid_access); =20 bool bpf_sock_is_valid_access(int off, int size, enum bpf_access_type type, struct bpf_insn_access_aux *info) @@ -8916,6 +8922,7 @@ bool bpf_sock_is_valid_access(int off, int size, enum= bpf_access_type type, =20 return size =3D=3D size_default; } +EXPORT_SYMBOL_GPL(bpf_sock_is_valid_access); =20 static bool sock_filter_is_valid_access(int off, int size, enum bpf_access_type type, @@ -10156,6 +10163,7 @@ u32 bpf_sock_convert_ctx_access(enum bpf_access_typ= e type, =20 return insn - insn_buf; } +EXPORT_SYMBOL_GPL(bpf_sock_convert_ctx_access); =20 static u32 tc_cls_act_convert_ctx_access(enum bpf_access_type type, const struct bpf_insn *si, @@ -11075,6 +11083,7 @@ const struct bpf_verifier_ops sk_filter_verifier_op= s =3D { .convert_ctx_access =3D bpf_convert_ctx_access, .gen_ld_abs =3D bpf_gen_ld_abs, }; +EXPORT_SYMBOL_GPL(sk_filter_verifier_ops); =20 const struct bpf_prog_ops sk_filter_prog_ops =3D { .test_run =3D bpf_prog_test_run_skb, @@ -11088,6 +11097,7 @@ const struct bpf_verifier_ops tc_cls_act_verifier_o= ps =3D { .gen_ld_abs =3D bpf_gen_ld_abs, .btf_struct_access =3D tc_cls_act_btf_struct_access, }; +EXPORT_SYMBOL_GPL(tc_cls_act_verifier_ops); =20 const struct bpf_prog_ops tc_cls_act_prog_ops =3D { .test_run =3D bpf_prog_test_run_skb, @@ -11100,6 +11110,7 @@ const struct bpf_verifier_ops xdp_verifier_ops =3D { .gen_prologue =3D bpf_noop_prologue, .btf_struct_access =3D xdp_btf_struct_access, }; +EXPORT_SYMBOL_GPL(xdp_verifier_ops); =20 const struct bpf_prog_ops xdp_prog_ops =3D { .test_run =3D bpf_prog_test_run_xdp, @@ -11110,6 +11121,7 @@ const struct bpf_verifier_ops cg_skb_verifier_ops = =3D { .is_valid_access =3D cg_skb_is_valid_access, .convert_ctx_access =3D bpf_convert_ctx_access, }; +EXPORT_SYMBOL_GPL(cg_skb_verifier_ops); =20 const struct bpf_prog_ops cg_skb_prog_ops =3D { .test_run =3D bpf_prog_test_run_skb, @@ -11120,6 +11132,7 @@ const struct bpf_verifier_ops lwt_in_verifier_ops = =3D { .is_valid_access =3D lwt_is_valid_access, .convert_ctx_access =3D bpf_convert_ctx_access, }; +EXPORT_SYMBOL_GPL(lwt_in_verifier_ops); =20 const struct bpf_prog_ops lwt_in_prog_ops =3D { .test_run =3D bpf_prog_test_run_skb, @@ -11130,6 +11143,7 @@ const struct bpf_verifier_ops lwt_out_verifier_ops = =3D { .is_valid_access =3D lwt_is_valid_access, .convert_ctx_access =3D bpf_convert_ctx_access, }; +EXPORT_SYMBOL_GPL(lwt_out_verifier_ops); =20 const struct bpf_prog_ops lwt_out_prog_ops =3D { .test_run =3D bpf_prog_test_run_skb, @@ -11141,6 +11155,7 @@ const struct bpf_verifier_ops lwt_xmit_verifier_ops= =3D { .convert_ctx_access =3D bpf_convert_ctx_access, .gen_prologue =3D tc_cls_act_prologue, }; +EXPORT_SYMBOL_GPL(lwt_xmit_verifier_ops); =20 const struct bpf_prog_ops lwt_xmit_prog_ops =3D { .test_run =3D bpf_prog_test_run_skb, @@ -11151,6 +11166,7 @@ const struct bpf_verifier_ops lwt_seg6local_verifie= r_ops =3D { .is_valid_access =3D lwt_is_valid_access, .convert_ctx_access =3D bpf_convert_ctx_access, }; +EXPORT_SYMBOL_GPL(lwt_seg6local_verifier_ops); =20 const struct bpf_prog_ops lwt_seg6local_prog_ops =3D { }; @@ -11160,6 +11176,7 @@ const struct bpf_verifier_ops cg_sock_verifier_ops = =3D { .is_valid_access =3D sock_filter_is_valid_access, .convert_ctx_access =3D bpf_sock_convert_ctx_access, }; +EXPORT_SYMBOL_GPL(cg_sock_verifier_ops); =20 const struct bpf_prog_ops cg_sock_prog_ops =3D { }; @@ -11169,6 +11186,7 @@ const struct bpf_verifier_ops cg_sock_addr_verifier= _ops =3D { .is_valid_access =3D sock_addr_is_valid_access, .convert_ctx_access =3D sock_addr_convert_ctx_access, }; +EXPORT_SYMBOL_GPL(cg_sock_addr_verifier_ops); =20 const struct bpf_prog_ops cg_sock_addr_prog_ops =3D { }; @@ -11178,6 +11196,7 @@ const struct bpf_verifier_ops sock_ops_verifier_ops= =3D { .is_valid_access =3D sock_ops_is_valid_access, .convert_ctx_access =3D sock_ops_convert_ctx_access, }; +EXPORT_SYMBOL_GPL(sock_ops_verifier_ops); =20 const struct bpf_prog_ops sock_ops_prog_ops =3D { }; @@ -11188,6 +11207,7 @@ const struct bpf_verifier_ops sk_skb_verifier_ops = =3D { .convert_ctx_access =3D sk_skb_convert_ctx_access, .gen_prologue =3D sk_skb_prologue, }; +EXPORT_SYMBOL_GPL(sk_skb_verifier_ops); =20 const struct bpf_prog_ops sk_skb_prog_ops =3D { }; @@ -11198,6 +11218,7 @@ const struct bpf_verifier_ops sk_msg_verifier_ops = =3D { .convert_ctx_access =3D sk_msg_convert_ctx_access, .gen_prologue =3D bpf_noop_prologue, }; +EXPORT_SYMBOL_GPL(sk_msg_verifier_ops); =20 const struct bpf_prog_ops sk_msg_prog_ops =3D { }; @@ -11207,6 +11228,7 @@ const struct bpf_verifier_ops flow_dissector_verifi= er_ops =3D { .is_valid_access =3D flow_dissector_is_valid_access, .convert_ctx_access =3D flow_dissector_convert_ctx_access, }; +EXPORT_SYMBOL_GPL(flow_dissector_verifier_ops); =20 const struct bpf_prog_ops flow_dissector_prog_ops =3D { .test_run =3D bpf_prog_test_run_flow_dissector, @@ -11547,6 +11569,7 @@ const struct bpf_verifier_ops sk_reuseport_verifier= _ops =3D { .is_valid_access =3D sk_reuseport_is_valid_access, .convert_ctx_access =3D sk_reuseport_convert_ctx_access, }; +EXPORT_SYMBOL_GPL(sk_reuseport_verifier_ops); =20 const struct bpf_prog_ops sk_reuseport_prog_ops =3D { }; @@ -11759,6 +11782,7 @@ const struct bpf_verifier_ops sk_lookup_verifier_op= s =3D { .is_valid_access =3D sk_lookup_is_valid_access, .convert_ctx_access =3D sk_lookup_convert_ctx_access, }; +EXPORT_SYMBOL_GPL(sk_lookup_verifier_ops); =20 #endif /* CONFIG_INET */ =20 @@ -11773,6 +11797,7 @@ BTF_ID_LIST_GLOBAL(btf_sock_ids, MAX_BTF_SOCK_TYPE) #define BTF_SOCK_TYPE(name, type) BTF_ID(struct, type) BTF_SOCK_TYPE_xxx #undef BTF_SOCK_TYPE +EXPORT_SYMBOL_GPL(btf_sock_ids); =20 BPF_CALL_1(bpf_skc_to_tcp6_sock, struct sock *, sk) { @@ -12161,6 +12186,7 @@ int bpf_dynptr_from_skb_rdonly(struct __sk_buff *sk= b, u64 flags, =20 return 0; } +EXPORT_SYMBOL_GPL(bpf_dynptr_from_skb_rdonly); =20 BTF_KFUNCS_START(bpf_kfunc_check_set_skb) BTF_ID_FLAGS(func, bpf_dynptr_from_skb, KF_TRUSTED_ARGS) diff --git a/net/core/xdp.c b/net/core/xdp.c index f86eedad586a..a0deb63420a2 100644 --- a/net/core/xdp.c +++ b/net/core/xdp.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -984,6 +985,7 @@ bool bpf_dev_bound_kfunc_id(u32 btf_id) { return btf_id_set8_contains(&xdp_metadata_kfunc_ids, btf_id); } +EXPORT_SYMBOL_GPL(bpf_dev_bound_kfunc_id); =20 static int __init xdp_metadata_init(void) { diff --git a/net/netfilter/nf_bpf_link.c b/net/netfilter/nf_bpf_link.c index 06b084844700..0e714fb36dd7 100644 --- a/net/netfilter/nf_bpf_link.c +++ b/net/netfilter/nf_bpf_link.c @@ -326,3 +326,4 @@ const struct bpf_verifier_ops netfilter_verifier_ops = =3D { .is_valid_access =3D nf_is_valid_access, .get_func_proto =3D bpf_nf_func_proto, }; +EXPORT_SYMBOL_GPL(netfilter_verifier_ops); --=20 2.47.1 From nobody Sat Feb 7 15:40:11 2026 Received: from fout-a8-smtp.messagingengine.com (fout-a8-smtp.messagingengine.com [103.168.172.151]) (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 88F091C57B2; Wed, 9 Apr 2025 03:35:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.151 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744169707; cv=none; b=DeelSv+Wkp/K9BR4CK6TyHjUIUNHGGbpPT2uneOvd2f/D5VoBnFMM/Ug5wUR8EoAEwsplbJp4wA8dIJcsV0ex+P0HZlaZD4eICuYjLbH++CdLgOsccX/VVdo82hyFZBeQGWAPymJSNEpA+04JbY5RbXudK0+E52SKLZNfmi7+GM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744169707; c=relaxed/simple; bh=B04kxiv2MQQ7PBpdqgDE+iXkeCnRc7TBYsgOtOOsFnU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n1DwP+Y1pWgiKf9zxcRELtR8N0JHigDN2drNqk+tKHyutx/UyyUGBsEKBI4nf/h7wy2ezX7DbG4qzqJk73f11lzDzGBJWhz9PLsYDbVQEUP5poyLK6zVp1PH3QXskOe1pjcOXN/pbXZye2SUzOZszasid0UUhnsSCoO9ertjkuE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz; spf=pass smtp.mailfrom=dxuuu.xyz; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b=UXfmFIuG; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=NG95msL7; arc=none smtp.client-ip=103.168.172.151 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="UXfmFIuG"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="NG95msL7" Received: from phl-compute-01.internal (phl-compute-01.phl.internal [10.202.2.41]) by mailfout.phl.internal (Postfix) with ESMTP id B5AD613801DD; Tue, 8 Apr 2025 23:35:04 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-01.internal (MEProxy); Tue, 08 Apr 2025 23:35:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1744169704; x= 1744256104; bh=71eCra28VqFvwu+DqJB69IOBTAVWWSIfZcw9cSyC1Yo=; b=U XfmFIuG//PqtTp2caDVnfoh6yIqhFrwRYNXpC+xBN+adWC5vsbwY0hFkxlR/wWTO Gs9y+MyY0PRCU7LqRDc1Y278FKgqhkisyDyEQXC2Wb80lTkSbK1C0cFHX7ZZ7jls xzcJ+2oMx4KIoJorJiM9EuQopRHJNra/A7m1rH/xKj8n3LxYMKm+7BpoEBji8Km6 eCr+f6X/bQAi1ZowG67W841rX5f91xIKS0Ju7Wm6UWNS90gMsgAt5D6UbEYFuLSg Ts0ffNUv0z+yjB5AiVMLxFFgWrd+gOO6Y2IoWjrf7LmhSm5yocQK7mxYsOaFHP/c mrCr5OyCQLjz2OHxKgB2Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1744169704; x=1744256104; bh=7 1eCra28VqFvwu+DqJB69IOBTAVWWSIfZcw9cSyC1Yo=; b=NG95msL7C8ywuv44u tVqWfPVhpLtK2xaMMDk2+kg7Qfok/zel/WCEC0IJDcgispfkhHZmvAG8v72OqPgi gMiC2bqrbgieZOMbj2r1Q3G7uC/F9ydZEv2DCdIyqXk/+85Av81A4iBgB/ysSrXZ 4Cl4ZmtB1Ms6eb9OlSyho2sfzHQeomGkaTJhybtBWPyedIT56FPYyhoc9YYukcEa OuLEe9dg4RhRA+vV3+B8UvY005l2PwZIJokouVYPmuJxg2IpJ3DVeYnh+8t4s2ik U6FjVVyJeYLxdoAbRYwka6KN08ufNwsV9pf4qdiGs4OaTudL5P2QgGwjwkhIRMOP mYukA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvtdegledvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffuc dljedtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhm peffrghnihgvlhcuighuuceougiguhesugiguhhuuhdrgiihiieqnecuggftrfgrthhtvg hrnhepgfefgfegjefhudeikedvueetffelieefuedvhfehjeeljeejkefgffeghfdttdet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepugiguh esugiguhhuuhdrgiihiidpnhgspghrtghpthhtohepudegpdhmohguvgepshhmthhpohhu thdprhgtphhtthhopegrnhgurhhiiheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprg hstheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepuggrnhhivghlsehiohhgvggrrhgs ohigrdhnvghtpdhrtghpthhtohepmhgrrhhtihhnrdhlrghusehlihhnuhigrdguvghvpd hrtghpthhtohepvgguugihiiekjeesghhmrghilhdrtghomhdprhgtphhtthhopehsohhn gheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohephihonhhghhhonhhgrdhsohhngheslh hinhhugidruggvvhdprhgtphhtthhopehjohhhnhdrfhgrshhtrggsvghnugesghhmrghi lhdrtghomhdprhgtphhtthhopehkphhsihhnghhhsehkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 8 Apr 2025 23:35:03 -0400 (EDT) From: Daniel Xu To: andrii@kernel.org, ast@kernel.org, daniel@iogearbox.net Cc: martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC bpf-next 12/13] bpf: verifier: Make verifier loadable Date: Tue, 8 Apr 2025 21:34:07 -0600 Message-ID: <32da0f412d267be39872c4c2de1f48f12ad7571e.1744169424.git.dxu@dxuuu.xyz> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This commit makes the BPF verifier loadable, with the default being the same as before (built in). Note that no matter the build configuration, it is always possible to load a new module (evicting the previous). Signed-off-by: Daniel Xu --- include/linux/bpf.h | 15 ++++++++++++--- kernel/bpf/Kconfig | 12 ++++++++++++ kernel/bpf/Makefile | 3 ++- kernel/bpf/core.c | 4 ++++ kernel/bpf/syscall.c | 45 ++++++++++++++++++++++++++++++++++++++++++- kernel/bpf/verifier.c | 28 +++++++++++++++++++++++++-- 6 files changed, 100 insertions(+), 7 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index a5806a7b31d3..127b75ecc532 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -72,6 +72,18 @@ typedef int (*bpf_iter_init_seq_priv_t)(void *private_da= ta, typedef void (*bpf_iter_fini_seq_priv_t)(void *private_data); typedef unsigned int (*bpf_func_t)(const void *, const struct bpf_insn *); + +struct bpf_check_hook { + struct module *owner; + /* verify correctness of eBPF program */ + int (*bpf_check)(struct bpf_prog **prog, + union bpf_attr *attr, + bpfptr_t uattr, + __u32 uattr_size); +}; + +extern const struct bpf_check_hook __rcu *bpf_check; + struct bpf_iter_seq_info { const struct seq_operations *seq_ops; bpf_iter_init_seq_priv_t init_seq_private; @@ -2663,9 +2675,6 @@ int bpf_get_file_flag(int flags); int bpf_check_uarg_tail_zero(bpfptr_t uaddr, size_t expected_size, size_t actual_size); =20 -/* verify correctness of eBPF program */ -int bpf_check(struct bpf_prog **fp, union bpf_attr *attr, bpfptr_t uattr, = u32 uattr_size); - #ifndef CONFIG_BPF_JIT_ALWAYS_ON void bpf_patch_call_args(struct bpf_insn *insn, u32 stack_depth); #endif diff --git a/kernel/bpf/Kconfig b/kernel/bpf/Kconfig index 17067dcb4386..90745b6e2af1 100644 --- a/kernel/bpf/Kconfig +++ b/kernel/bpf/Kconfig @@ -39,6 +39,18 @@ config BPF_SYSCALL Enable the bpf() system call that allows to manipulate BPF programs and maps via file descriptors. =20 +config BPF_VERIFIER + tristate "BPF verifier" + default y + depends on BPF_SYSCALL + help + Controls if BPF verifier is built as a kernel module or not. + + Regardless of choice, it is possible to dynamically load a new verifier + module. + + If you are unsure how to answer this question, answer Y. + config BPF_JIT bool "Enable BPF Just In Time compiler" depends on BPF diff --git a/kernel/bpf/Makefile b/kernel/bpf/Makefile index 70502f038b92..82cf9ea39225 100644 --- a/kernel/bpf/Makefile +++ b/kernel/bpf/Makefile @@ -6,11 +6,12 @@ cflags-nogcse-$(CONFIG_X86)$(CONFIG_CC_IS_GCC) :=3D -fno-= gcse endif CFLAGS_core.o +=3D -Wno-override-init $(cflags-nogcse-yy) =20 -obj-$(CONFIG_BPF_SYSCALL) +=3D syscall.o verifier.o inode.o helpers.o tnum= .o log.o token.o +obj-$(CONFIG_BPF_SYSCALL) +=3D syscall.o inode.o helpers.o tnum.o log.o to= ken.o obj-$(CONFIG_BPF_SYSCALL) +=3D bpf_iter.o map_iter.o task_iter.o prog_iter= .o link_iter.o obj-$(CONFIG_BPF_SYSCALL) +=3D hashtab.o arraymap.o percpu_freelist.o bpf_= lru_list.o lpm_trie.o map_in_map.o bloom_filter.o obj-$(CONFIG_BPF_SYSCALL) +=3D local_storage.o queue_stack_maps.o ringbuf.o obj-$(CONFIG_BPF_SYSCALL) +=3D bpf_local_storage.o bpf_task_storage.o +obj-$(CONFIG_BPF_VERIFIER) +=3D verifier.o obj-${CONFIG_BPF_LSM} +=3D bpf_inode_storage.o obj-$(CONFIG_BPF_SYSCALL) +=3D disasm.o mprog.o obj-$(CONFIG_BPF_JIT) +=3D trampoline.o diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 6c8bb4cdac0f..25eac0e2f929 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -44,6 +45,9 @@ #include #include =20 +const struct bpf_check_hook *bpf_check __rcu __read_mostly; +EXPORT_SYMBOL_GPL(bpf_check); + /* Registers */ #define BPF_R0 regs[BPF_REG_0] #define BPF_R1 regs[BPF_REG_1] diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 2ef55503ba32..7cf65d2c37ee 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -2759,6 +2759,41 @@ static bool is_perfmon_prog_type(enum bpf_prog_type = prog_type) } } =20 +static const struct bpf_check_hook *bpf_check_get(void) +{ + const struct bpf_check_hook *hook; + int err; + + /* RCU protects us from races against module unloading */ + rcu_read_lock(); + hook =3D rcu_dereference(bpf_check); + if (!hook) { + rcu_read_unlock(); + err =3D request_module("verifier"); + if (err) + return ERR_PTR(err < 0 ? err : -ENOENT); + + rcu_read_lock(); + hook =3D rcu_dereference(bpf_check); + } + + if (hook && try_module_get(hook->owner)) { + /* Once we have a refcnt on the module, we no longer need RCU */ + hook =3D rcu_pointer_handoff(hook); + } else { + WARN_ONCE(!hook, "verifier has bad registration"); + hook =3D ERR_PTR(-ENOENT); + } + rcu_read_unlock(); + + return hook; +} + +static void bpf_check_put(const struct bpf_check_hook *c) +{ + module_put(c->owner); +} + /* last field in 'union bpf_attr' used by this command */ #define BPF_PROG_LOAD_LAST_FIELD fd_array_cnt =20 @@ -2766,6 +2801,7 @@ static int bpf_prog_load(union bpf_attr *attr, bpfptr= _t uattr, u32 uattr_size) { enum bpf_prog_type type =3D attr->prog_type; struct bpf_prog *prog, *dst_prog =3D NULL; + const struct bpf_check_hook *hook; struct btf *attach_btf =3D NULL; struct bpf_token *token =3D NULL; bool bpf_cap; @@ -2973,8 +3009,15 @@ static int bpf_prog_load(union bpf_attr *attr, bpfpt= r_t uattr, u32 uattr_size) if (err) goto free_prog_sec; =20 + hook =3D bpf_check_get(); + if (IS_ERR(hook)) { + err =3D PTR_ERR(hook); + goto free_used_maps; + } + /* run eBPF verifier */ - err =3D bpf_check(&prog, attr, uattr, uattr_size); + err =3D hook->bpf_check(&prog, attr, uattr, uattr_size); + bpf_check_put(hook); if (err < 0) goto free_used_maps; =20 diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 080cc380e806..1574400a0c76 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -18351,7 +18351,6 @@ static __init int unbound_reg_init(void) unbound_reg.live |=3D REG_LIVE_READ; return 0; } -late_initcall(unbound_reg_init); =20 static bool is_stack_all_misc(struct bpf_verifier_env *env, struct bpf_stack_state *stack) @@ -23428,7 +23427,7 @@ static int compute_live_registers(struct bpf_verifi= er_env *env) return err; } =20 -int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr= , __u32 uattr_size) +static int __bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfpt= r_t uattr, __u32 uattr_size) { u64 start_time =3D ktime_get_ns(); struct bpf_verifier_env *env; @@ -23695,3 +23694,28 @@ int bpf_check(struct bpf_prog **prog, union bpf_at= tr *attr, bpfptr_t uattr, __u3 kvfree(env); return ret; } + +static const struct bpf_check_hook verifier =3D { + .owner =3D THIS_MODULE, + .bpf_check =3D __bpf_check, +}; + +static int __init bpf_verifier_init(void) +{ + unbound_reg_init(); + rcu_assign_pointer(bpf_check, &verifier); + + return 0; +} + +static void __exit bpf_verifier_fini(void) +{ + rcu_assign_pointer(bpf_check, NULL); +} + + +module_init(bpf_verifier_init); +module_exit(bpf_verifier_fini); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("eBPF verifier"); --=20 2.47.1 From nobody Sat Feb 7 15:40:11 2026 Received: from fhigh-a4-smtp.messagingengine.com (fhigh-a4-smtp.messagingengine.com [103.168.172.155]) (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 8C0BB1E1A31; Wed, 9 Apr 2025 03:35:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744169710; cv=none; b=QTCg9vm6H85ltvKOQFXBvP4eE8RYnqXbPsuLOuPw2IgvL8Wz2x8WpkkawPAdn24yedRpNHm4He29cjSoSlKsxu0274hQJ54h1Xq6X5jZ9RCzwo33Uds9Q+6kBKjLxUJgplZmS7TGazvXPm3rrfh5VAEWATCpP1uuKVB2+xC/Vvc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744169710; c=relaxed/simple; bh=LI7NYAjX+L6pI6lrYv+zsW4Fv3P3XhRIzbOFvBz3RfY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PGTRKf8eDu/xIUgtpvsnMOksfvIbenQbXBQgHb+KKVcOggILJw5N0TX8CKqCCBJQV0ji+awkWBW8OfQf9nvvpKcKXBN6xfcgv0tLpNXF8IslWZJG4Nw0YFSCzlitUOYHya9+bLe4xggKvD6csnWi/DzYCBHlcBRpcYBBrjWDPeU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz; spf=pass smtp.mailfrom=dxuuu.xyz; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b=gCtNNbOc; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Oy6zLfoL; arc=none smtp.client-ip=103.168.172.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=dxuuu.xyz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=dxuuu.xyz header.i=@dxuuu.xyz header.b="gCtNNbOc"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Oy6zLfoL" Received: from phl-compute-02.internal (phl-compute-02.phl.internal [10.202.2.42]) by mailfhigh.phl.internal (Postfix) with ESMTP id 878D91140257; Tue, 8 Apr 2025 23:35:06 -0400 (EDT) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-02.internal (MEProxy); Tue, 08 Apr 2025 23:35:06 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dxuuu.xyz; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to; s=fm1; t=1744169706; x= 1744256106; bh=kC0vrcJINgsqsxDD2H7/EW5cKA10S1wnC+ZsymZ0u5M=; b=g CtNNbOcFECi2zHw6l7ItGoFG3J5th6+zX93oydIf37LI3TwY6fIsaeNra7Jp9Peg MWQR1Pkl1C4BoSP0WsVtiwo0xQqJ/VTKJXBR7QqiIzU9SwmEtmHJa+LQf+8nfAlq 01i1OprWCrmHXLPis/g1YHDBDP8EF3H7sYyHLjvkdf8oaFEwLeD/9Fgo5b6Fekgo TpU8yqwXXaGruzpfkt4ZngkxhAh99XUerAAkVQ0WIUtychbygPa4W4CeF9p8oMsX 8s2CZVd902sXCid5YbVJ+vBsvIoRSlg6EHZUqFiEQEArSDKG2p+d22CGOZjzSjCs inWpMk69jyV3isGCex5bQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1744169706; x=1744256106; bh=k C0vrcJINgsqsxDD2H7/EW5cKA10S1wnC+ZsymZ0u5M=; b=Oy6zLfoLBHSxYvSZq MDdhUDwXScvJaxgmCWuUwqAo8bj8Key87v878LCckrKvfGLi15/wpIr3oc5FwyJn uM8Hvf213h+EmCIU0KJyvTsbm+sOAOx/GGpjsml1YhmdM852kg2xjZVkGcd1AEe9 K4yv4KHM80BWnSelJxkZRhWBtl+Ld4QVWEfhwVLMBwiTbnlWWXPSB2GDY8oLucVO 19qSo6Djx7TYoRSt1pDPivaHiBHUzKOg+c7n0xUQT+bMwSvfjTu6B+MECKHJDEiZ sHuG0daGAbRYawOV0IJ8OxnI26q0mWGAoseaE57Sj+PRfyh+ZZX85uohUllWWhCV VDj7Q== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefvddrtddtgddvtdegledvucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggv pdfurfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucgfrhhlucfvnfffuc dljedtmdenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhm peffrghnihgvlhcuighuuceougiguhesugiguhhuuhdrgiihiieqnecuggftrfgrthhtvg hrnhepgfefgfegjefhudeikedvueetffelieefuedvhfehjeeljeejkefgffeghfdttdet necuvehluhhsthgvrhfuihiivgepvdenucfrrghrrghmpehmrghilhhfrhhomhepugiguh esugiguhhuuhdrgiihiidpnhgspghrtghpthhtohepudegpdhmohguvgepshhmthhpohhu thdprhgtphhtthhopegrnhgurhhiiheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprg hstheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepuggrnhhivghlsehiohhgvggrrhgs ohigrdhnvghtpdhrtghpthhtohepmhgrrhhtihhnrdhlrghusehlihhnuhigrdguvghvpd hrtghpthhtohepvgguugihiiekjeesghhmrghilhdrtghomhdprhgtphhtthhopehsohhn gheskhgvrhhnvghlrdhorhhgpdhrtghpthhtohephihonhhghhhonhhgrdhsohhngheslh hinhhugidruggvvhdprhgtphhtthhopehjohhhnhdrfhgrshhtrggsvghnugesghhmrghi lhdrtghomhdprhgtphhtthhopehkphhsihhnghhhsehkvghrnhgvlhdrohhrgh X-ME-Proxy: Feedback-ID: i6a694271:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 8 Apr 2025 23:35:04 -0400 (EDT) From: Daniel Xu To: andrii@kernel.org, ast@kernel.org, daniel@iogearbox.net Cc: martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Subject: [RFC bpf-next 13/13] bpf: Supporting building verifier.ko out-of-tree Date: Tue, 8 Apr 2025 21:34:08 -0600 Message-ID: <2e31904051277ecff988530b50373d11efdcfaee.1744169424.git.dxu@dxuuu.xyz> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This supports out-of-tree builds against the in-tree verifier.ko. This is intended to be used to build newer upstream verifiers against older kernel sources. You can also do an "in-tree out-of-tree" build as proof of concept: $ make clean $ make modules_prepare $ cd kernel/bpf $ make -C ../.. M=3D$PWD Signed-off-by: Daniel Xu --- kernel/bpf/Kbuild | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 kernel/bpf/Kbuild diff --git a/kernel/bpf/Kbuild b/kernel/bpf/Kbuild new file mode 100644 index 000000000000..0b4a9ce14c6f --- /dev/null +++ b/kernel/bpf/Kbuild @@ -0,0 +1,8 @@ +# Because Kbuild is preferred over Makefile for in-tree builds +# but Kbuild is necessary for an out-of-tree module, we need an +# explicit dispatch to Makefile if doing an in-tree build. +ifneq ($(M),) + obj-m =3D verifier.o +else + include $(src)/Makefile +endif --=20 2.47.1