From nobody Sat Feb 7 15:02:32 2026 Received: from out-170.mta1.migadu.com (out-170.mta1.migadu.com [95.215.58.170]) (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 5A07F2FF164 for ; Wed, 28 Jan 2026 16:57:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769619476; cv=none; b=RAvUere6ele3Hej8/Jv5xd3c+OaOPmcE03kOO7cF1bYwt40K9NhyLgz6scsx0COYu/JU+taHR1Qzu8xvTsz1qz6x3lTfbstzvM3DiqZzXrtrWvLdj5my1vY6SlrZwet5/tVSEjY+JVDBr+XNYzT69siNNprsjpTguHD5FWEtHxw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769619476; c=relaxed/simple; bh=Xy7l4IlBMtdLVWEB1jQFsT2TwL189a03RVDzG0zKLaM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=JpZ1geqj/+o6pKoIcorx6ZZXUUpuonSY+WxGBylIJjslV52ILoLYN76KVhQuGfEwG+QRhiXqPZEudeXvkoId9k1Gqm0slN3l7nu0grAY5rh4Yx0FZsT4QQEhiujO6pqxOTfov5LMEVdEPbONFXR7EsF5PJWcF4+m8exEXnUJEXg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=aIsWDTqp; arc=none smtp.client-ip=95.215.58.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="aIsWDTqp" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1769619463; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=CNtNv8rSuyb0z68K1rJhYYJu0H3XVoM8UAx9pK28RfA=; b=aIsWDTqpJkGeg95V8d4OQJADHv7uXvd085isyj0LXZbKxMfK3e1p7amWNvSylY7L5Vp5PN X9EnfN8+nq6MGjl+8eOFDe+1i586IeXjgBYmUBRXkIISXTI6QatdlZywKBfCSRH2Jpl1Nm jXbSH0+sXAIVdjZMqftDHWbdC0RzcFY= From: Tao Chen To: song@kernel.org, jolsa@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, yonghong.song@linux.dev, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com Cc: bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Tao Chen Subject: [PATCH bpf-next] bpf: Remove RCU lock for perf callchain buffer Date: Thu, 29 Jan 2026 00:57:10 +0800 Message-ID: <20260128165710.928294-1-chen.dylane@linux.dev> 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 X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" As Andrii suggested, BPF can guarantee perf callchain buffer won't be released during use, for bpf_get_stack_id, BPF stack map will keep them alive by delaying put_callchain_buffer() until freeing time or for bpf_get_stack/bpf_get_task_stack, BPF program itself will hold these buffers alive again, until freeing time which is delayed until after RCU Tasks Trace + RCU grace period. Suggested-by: Andrii Nakryiko Signed-off-by: Tao Chen --- kernel/bpf/stackmap.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c index da3d328f5c1..2e682d8697b 100644 --- a/kernel/bpf/stackmap.c +++ b/kernel/bpf/stackmap.c @@ -460,9 +460,6 @@ static long __bpf_get_stack(struct pt_regs *regs, struc= t task_struct *task, =20 max_depth =3D stack_map_calculate_max_depth(size, elem_size, flags); =20 - if (may_fault) - rcu_read_lock(); /* need RCU for perf's callchain below */ - if (trace_in) { trace =3D trace_in; trace->nr =3D min_t(u32, trace->nr, max_depth); @@ -473,11 +470,8 @@ static long __bpf_get_stack(struct pt_regs *regs, stru= ct task_struct *task, crosstask, false, 0); } =20 - if (unlikely(!trace) || trace->nr < skip) { - if (may_fault) - rcu_read_unlock(); + if (unlikely(!trace) || trace->nr < skip) goto err_fault; - } =20 trace_nr =3D trace->nr - skip; copy_len =3D trace_nr * elem_size; @@ -493,10 +487,6 @@ static long __bpf_get_stack(struct pt_regs *regs, stru= ct task_struct *task, memcpy(buf, ips, copy_len); } =20 - /* trace/ips should not be dereferenced after this point */ - if (may_fault) - rcu_read_unlock(); - if (user_build_id) stack_map_get_build_id_offset(buf, trace_nr, user, may_fault); =20 --=20 2.48.1