From mboxrd@z Thu Jan 1 00:00:00 1970 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 8EB65451996 for ; Tue, 8 Sep 2026 13:21:54 +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=1788873716; cv=none; b=tSB+F5ZW3FcT7p9UpXvYELEbxgO/6RzUMUgAu2BVNqdLUajf8/ODdEgOgfsbRWNy6YKmyWmAdasl62r2UAom9RtQlyYx1gNfLWEQlH51WOeMwATF9VHTsYTCeXtNr4hfIvnD88TNmboryr5PeYPywbGDJBl1vj+hUQ7y0SRW4Lo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1788873716; c=relaxed/simple; bh=6t27Q0b8OurFU6z4jUF21Ev9Hu9KRlZKrJ5Kn7xItxg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cnebQq/VZH1R3CejtKQeo90QflJRSys82219ebrzKD2nZoGf8RYbnUa0+jN0ZTgtGXRyl3qze7Qv52wzUlBNW1Z5us2X9g1t3zOF7IleRP26DHf5AfnsL8xiHR2aOJwQPtZeuq0B60V2khbCFyaRZPJ4lyH+613Z3YECTRP82uo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 68A791F01558; Tue, 8 Sep 2026 13:21:53 +0000 (UTC) From: Sasha Levin To: stable@vger.kernel.org Cc: Jiri Olsa , Tao Chen , Andrii Nakryiko , Sasha Levin Subject: [PATCH 6.12.y 5/5] bpf: Disable preemption in bpf_get_stackid Date: Tue, 8 Sep 2026 09:21:48 -0400 Message-ID: <20260908132148.2288072-5-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260908132148.2288072-1-sashal@kernel.org> References: <2026090349-donor-crunching-700c@gregkh> <20260908132148.2288072-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Jiri Olsa [ Upstream commit 15f1bd8574662f1b7b26aaa2e23ebf4066f0117d ] The get_perf_callchain call needs disabled preemption plus we need it disabled as long as we access its returned trace entries buffer. Note the bpf_get_stackid_pe function is executed already with preemption disabled. Fixes: d5a3b1f69186 ("bpf: introduce BPF_MAP_TYPE_STACK_TRACE") Reported-by: Tao Chen Signed-off-by: Jiri Olsa Signed-off-by: Andrii Nakryiko Cc: stable@vger.kernel.org Link: https://lore.kernel.org/bpf/20260803210149.296496-6-jolsa@kernel.org Closes: https://lore.kernel.org/bpf/20260206090653.1336687-2-chen.dylane@linux.dev/ [ adapted get_perf_callchain() to the older six-argument form ] Signed-off-by: Sasha Levin --- kernel/bpf/stackmap.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c index 3678d1952e1e9..e1dbf43bc3aaf 100644 --- a/kernel/bpf/stackmap.c +++ b/kernel/bpf/stackmap.c @@ -374,20 +374,22 @@ BPF_CALL_3(bpf_get_stackid, struct pt_regs *, regs, struct bpf_map *, map, return -EINVAL; max_depth = stack_map_calculate_max_depth(map->value_size, elem_size, flags); - trace = get_perf_callchain(regs, kernel, user, max_depth, - false, false); - if (unlikely(!trace)) - /* couldn't fetch the stack trace */ - return -EFAULT; + scoped_guard(preempt) { + trace = get_perf_callchain(regs, kernel, user, max_depth, + false, false); + if (unlikely(!trace)) + /* couldn't fetch the stack trace */ + return -EFAULT; - err = stackid_fastpath(&stackid, map, trace, flags); - if (err != -ENOENT) - return 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; + new_bucket = stackid_new_bucket(&stackid, map); + if (!new_bucket) + return -ENOMEM; + } return stackid_install(&stackid, map, new_bucket, flags); } -- 2.53.0