From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CDA32CD4F57 for ; Sun, 17 May 2026 21:12:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=LdeAaK5wm6wVmEiHn2Fnw7XEUOSub2YXSnc/OI3UhLo=; b=F+aYqkKmxJaL/dD0NpM+vZcROo ie5IFIbGLXs4HjEzk5GvilPac6UkjAK5uZAScNvPOsr6moKK/v2JRMQfAcscuuXzO6n3jLE4unZdr pg8oGjs4dWPA46x9xfZxeI2H+k4UWaUxBOeZOzRz0jJWxP0cv/bXNTgAoJcrJ5cgFSAzyELigxg57 WBf3AWbBC8WTGAE1Sd/NkujLZvREALm7ScK+kbFiJKU1UUgMjvNVVLzc9tz4noj+/5raiZeVhGlWG 5cvEOJOH5yqox9UQL77Ebg9uOaOq07SKPvWfoUYIKN9xwOo0G2Ih9iKCptBbarkY+rx49XumqSRcQ aoyPJqxQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wOimz-0000000DTZm-1KAE; Sun, 17 May 2026 21:12:45 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wOims-0000000DTVi-47cm for linux-arm-kernel@lists.infradead.org; Sun, 17 May 2026 21:12:40 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sea.source.kernel.org (Postfix) with ESMTP id B191840AC7; Sun, 17 May 2026 21:12:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 79C6FC2BCB0; Sun, 17 May 2026 21:12:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1779052358; bh=FaQAuO2nj9X9q8AZMI9N/o/VYWh89imS0v4TwbR5loU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PGO9lDi9gvWVVueWifEgkQq7PmvNpDizNrHcRnLWG6O7GYNO/KkjBYkl9qEnxV7h5 GZwQa0pU36wiGpqNQeYyUeE2fvlu5l9TDf4hwrNag7bh5RoRz+KX8gw0ESGwXK6JXn Rs2cwVuuxCqzvKevvzZ6ebgmDATGIyz6kGf0abvOOoGEBmqxw1WvK5zIqUzSudlXl/ 52nhUz6CC09Lt8j8qZwwGMqYFUvUvXZ+X+AiLdHh//g/HIVRuR2l/qYCPEKV59OYCN SlgKt2g2APVK9xHfm8rK4stFJiwoB4slUjReS4vejaWLzV0/v7VuFDTPsZuV52AxHh 2azCz7ZIMOMvA== From: Tejun Heo To: David Vernet , Andrea Righi , Changwoo Min , Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Martin KaFai Lau , Kumar Kartikeya Dwivedi Cc: Catalin Marinas , Will Deacon , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Andrew Morton , David Hildenbrand , Mike Rapoport , Emil Tsalapatis , sched-ext@lists.linux.dev, bpf@vger.kernel.org, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Tejun Heo Subject: [PATCH 5/8] bpf/arena: Add bpf_arena_map_kern_vm_start() and bpf_prog_arena() Date: Sun, 17 May 2026 11:12:29 -1000 Message-ID: <20260517211232.1670594-6-tj@kernel.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260517211232.1670594-1-tj@kernel.org> References: <20260517211232.1670594-1-tj@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20260517_141239_063535_E765C12C X-CRM114-Status: GOOD ( 10.41 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org struct bpf_arena is opaque to callers outside arena.c. Add two helpers for struct_ops subsystems that need to reach into an arena: bpf_arena_map_kern_vm_start(struct bpf_map *map) returns @map's kern_vm_start. A sched_ext follow-up needs this to translate kern_va <-> uaddr. bpf_prog_arena(struct bpf_prog *prog) returns the bpf_map of the arena referenced by @prog (NULL if @prog references no arena). The verifier enforces at most one arena per program. Used by struct_ops callers that auto-discover an arena from a member prog and need to take a map reference. Suggested-by: Kumar Kartikeya Dwivedi Signed-off-by: Tejun Heo --- include/linux/bpf.h | 2 ++ kernel/bpf/arena.c | 26 ++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index 5b99d786e98c..e1ba57c10aaa 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -618,6 +618,8 @@ void bpf_rb_root_free(const struct btf_field *field, void *rb_root, struct bpf_spin_lock *spin_lock); u64 bpf_arena_get_kern_vm_start(struct bpf_arena *arena); u64 bpf_arena_get_user_vm_start(struct bpf_arena *arena); +u64 bpf_arena_map_kern_vm_start(struct bpf_map *map); +struct bpf_map *bpf_prog_arena(struct bpf_prog *prog); int bpf_obj_name_cpy(char *dst, const char *src, unsigned int size); struct bpf_offload_dev; diff --git a/kernel/bpf/arena.c b/kernel/bpf/arena.c index 8eb7b95f4999..5a82d39e1916 100644 --- a/kernel/bpf/arena.c +++ b/kernel/bpf/arena.c @@ -84,6 +84,32 @@ u64 bpf_arena_get_user_vm_start(struct bpf_arena *arena) return arena ? arena->user_vm_start : 0; } +/** + * bpf_arena_map_kern_vm_start - kern_vm_start lookup by struct bpf_map * + * @map: a BPF_MAP_TYPE_ARENA map + * + * Return @map's kern_vm_start. + */ +u64 bpf_arena_map_kern_vm_start(struct bpf_map *map) +{ + return bpf_arena_get_kern_vm_start(container_of(map, struct bpf_arena, map)); +} + +/** + * bpf_prog_arena - return the bpf_map of the arena referenced by @prog + * @prog: a loaded BPF program + * + * The verifier enforces at most one arena per program and stores it in + * prog->aux->arena. Return that arena's underlying bpf_map, or NULL if + * @prog does not reference an arena. + */ +struct bpf_map *bpf_prog_arena(struct bpf_prog *prog) +{ + struct bpf_arena *arena = prog->aux->arena; + + return arena ? &arena->map : NULL; +} + static long arena_map_peek_elem(struct bpf_map *map, void *value) { return -EOPNOTSUPP; -- 2.54.0