Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (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 25EE53CFF6F; Thu, 17 Sep 2026 19:02:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789671727; cv=none; b=hGowhqh20Fz7GFj8eLTZsprSxqi8HUwG8lewGpgfPvZ8r4eDOipoNZ8HIucIt1UUP1GtDXMVDi8ZAhtfhc/zR26w5tLS7vUKzwVDP1Ncd+azAvdbBUJw6bi0pMC35i1efMnAJ2HzzvIDGBI5NNDSnb9w7TCItxmDjpLBwLyQZGU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789671727; c=relaxed/simple; bh=2Ajhfzge9g6gZIQZ3hUOQWQNqwuGdyqrP56kCGlHKKI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZbbpI4BYVq9j3frsBktwFE4yOFUGmH70dRPLplO1FtBGsN9JQzdrQZdgSq4yKPmLVq/pfbdV8BKeHtDK+L27ABdiu3bIl4KrgjWaKrTTiFNB2u5FJgqAUBaXnAIpTjgYM6SXXSASxqcbUQDoSqQ0ZGYuAd6qVzuc+bO629vXXas= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=z+pwD0KV; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="z+pwD0KV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4952E1F000FF; Thu, 17 Sep 2026 19:02:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1789671725; bh=dA6oFiCllOucJ4Tm6Gj8ZNidrU06lC8+JmbmqShX31M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=z+pwD0KViWuZPKEk4HkTSnVssawHkqMssO9s8T5HFOttzur4xeSYL0GG+E44iuJYk /QUu1v2YPgMOjYKbMrQhsfkhhntjBYt6EorvhFCV3e4KR9ARSNNM4Ke7tzSTi+jNHP UKZN6L3cgNQqVAE0CvrhfswQC1NdtiJXAIR41wZc= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Jiri Olsa , Andrii Nakryiko , Sasha Levin Subject: [PATCH 6.12 1070/1102] bpf: Use stack id functions instead of __bpf_get_stackid Date: Thu, 17 Sep 2026 16:16:53 +0100 Message-ID: <20260917151607.689553760@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260917151539.408551884@linuxfoundation.org> References: <20260917151539.408551884@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.12-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jiri Olsa [ Upstream commit 09b3fd6caa0b57f8a39254ee5db3af30bdd53c18 ] Replacing __bpf_get_stackid calls with sequence of following functions: stackid_fastpath stackid_new_bucket stackid_install This makes code more structured and allows us to easily disable preemption only in bpf_get_stackid in following changes. Signed-off-by: Jiri Olsa Signed-off-by: Andrii Nakryiko Link: https://lore.kernel.org/bpf/20260803210149.296496-5-jolsa@kernel.org Stable-dep-of: 15f1bd857466 ("bpf: Disable preemption in bpf_get_stackid") Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- kernel/bpf/stackmap.c | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) --- a/kernel/bpf/stackmap.c +++ b/kernel/bpf/stackmap.c @@ -326,22 +326,13 @@ stackid_new_bucket(struct stackid *stack return bucket; } -static long __bpf_get_stackid(struct stackid *stackid, struct bpf_map *map, - struct perf_callchain_entry *trace, u64 flags) +static long stackid_install(struct stackid *stackid, struct bpf_map *map, + struct stack_map_bucket *new_bucket, u64 flags) { struct bpf_stack_map *smap = container_of(map, struct bpf_stack_map, map); - struct stack_map_bucket *new_bucket, *old_bucket; bool user = flags & BPF_F_USER_STACK; + struct stack_map_bucket *old_bucket; u32 trace_len; - int err; - - err = stackid_fastpath(stackid, map, trace, flags); - if (err != -ENOENT) - return err; - - new_bucket = stackid_new_bucket(stackid, map); - if (!new_bucket) - return -ENOMEM; if (stack_map_use_build_id(map)) { struct bpf_stack_build_id *id_offs; @@ -371,10 +362,12 @@ BPF_CALL_3(bpf_get_stackid, struct pt_re { u32 elem_size = stack_map_data_size(map); bool user = flags & BPF_F_USER_STACK; + struct stack_map_bucket *new_bucket; struct perf_callchain_entry *trace; struct stackid stackid; bool kernel = !user; u32 max_depth; + int err; if (unlikely(flags & ~(BPF_F_SKIP_FIELD_MASK | BPF_F_USER_STACK | BPF_F_FAST_STACK_CMP | BPF_F_REUSE_STACKID))) @@ -388,7 +381,15 @@ BPF_CALL_3(bpf_get_stackid, struct pt_re /* couldn't fetch the stack trace */ return -EFAULT; - return __bpf_get_stackid(&stackid, map, trace, flags); + err = stackid_fastpath(&stackid, map, trace, flags); + if (err != -ENOENT) + return err; + + new_bucket = stackid_new_bucket(&stackid, map); + if (!new_bucket) + return -ENOMEM; + + return stackid_install(&stackid, map, new_bucket, flags); } const struct bpf_func_proto bpf_get_stackid_proto = { @@ -416,6 +417,7 @@ BPF_CALL_3(bpf_get_stackid_pe, struct bp struct bpf_map *, map, u64, flags) { struct perf_event *event = ctx->event; + struct stack_map_bucket *new_bucket; struct perf_callchain_entry *trace; struct stackid stackid; bool kernel, user; @@ -443,7 +445,6 @@ BPF_CALL_3(bpf_get_stackid_pe, struct bp if (kernel) { trace->nr = nr_kernel; - ret = __bpf_get_stackid(&stackid, map, trace, flags); } else { /* user */ u64 skip = flags & BPF_F_SKIP_FIELD_MASK; @@ -452,12 +453,22 @@ BPF_CALL_3(bpf_get_stackid_pe, struct bp return -EFAULT; flags = (flags & ~BPF_F_SKIP_FIELD_MASK) | skip; - ret = __bpf_get_stackid(&stackid, map, trace, flags); } + ret = stackid_fastpath(&stackid, map, trace, flags); + if (ret != -ENOENT) + goto out; + + new_bucket = stackid_new_bucket(&stackid, map); + if (new_bucket) { + trace->nr = nr; + return stackid_install(&stackid, map, new_bucket, flags); + } + ret = -ENOMEM; + +out: /* restore nr */ trace->nr = nr; - return ret; }