From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-185.mta0.migadu.com (out-185.mta0.migadu.com [91.218.175.185]) (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 3C51C27A900 for ; Sat, 18 Oct 2025 07:51:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.185 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760773913; cv=none; b=JOF45TC4jnWTrWIRHDZfWp1UPdsP6qrbUbvNoGIHJI1YYWXiRcHd2U0Av+R38xvNchuT86phwthpbWi4ChTmOEWQzsJWz050IZKalU1FsJqqNSqVbePCsDi4crHZsEapcmwiwUJuFaRUkjx4xjOTsuDWqoaGtHsPZzlJCOVJU0E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760773913; c=relaxed/simple; bh=YDaatv130rfc9YWd+DrPk6GZoVEeS24QutfZ+cuZR60=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=pebyKQTCUb4OBg4m46Z1JeJjmc2ED7xdwC5Xj3vfED3EHGxVd2xk2YG+6EqX5a/no3ggrB0eTezmaLiR75IJx/i/LEBl8YzD7QhLKBiTHkrhL92Samqg5gIO4DI6vseJfr6hCJYwJGYfytMthp8uiTgMMS3wIttHKvCWygUclYw= 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=Y2qR6SgL; arc=none smtp.client-ip=91.218.175.185 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="Y2qR6SgL" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1760773898; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UzIpLxhpXHd7W2m8i5xoFIEHI3nftwPx3RFrt+zivx4=; b=Y2qR6SgLX/fevxvhax5l9j1nNiPMyAzIjswtZ/PyI81C4v9mK2TYwh/cGOx+r8/PD575cP vitqOxHpHWSIzpZLxeUAdGLJM6bCqNLwnJBf+o9RFFeqoGY6q5+qrIuuZhs7G4kAsmvxPR 1WK48uBsFzLbfw89fu9B2z4A+aLy83s= Date: Sat, 18 Oct 2025 15:51:22 +0800 Precedence: bulk X-Mailing-List: linux-perf-users@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [RFC PATCH bpf-next v2 2/2] bpf: Pass external callchain entry to get_perf_callchain To: Andrii Nakryiko , Alexei Starovoitov Cc: Jiri Olsa , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Namhyung Kim , Mark Rutland , Alexander Shishkin , Ian Rogers , Adrian Hunter , Kan Liang , Song Liu , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , "linux-perf-use." , LKML , bpf References: <20251014100128.2721104-1-chen.dylane@linux.dev> <20251014100128.2721104-3-chen.dylane@linux.dev> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Tao Chen In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT 在 2025/10/17 04:39, Andrii Nakryiko 写道: > On Tue, Oct 14, 2025 at 8:02 AM Alexei Starovoitov > wrote: >> >> On Tue, Oct 14, 2025 at 5:14 AM Jiri Olsa wrote: >>> >>> On Tue, Oct 14, 2025 at 06:01:28PM +0800, Tao Chen wrote: >>>> As Alexei noted, get_perf_callchain() return values may be reused >>>> if a task is preempted after the BPF program enters migrate disable >>>> mode. Drawing on the per-cpu design of bpf_perf_callchain_entries, >>>> stack-allocated memory of bpf_perf_callchain_entry is used here. >>>> >>>> Signed-off-by: Tao Chen >>>> --- >>>> kernel/bpf/stackmap.c | 19 +++++++++++-------- >>>> 1 file changed, 11 insertions(+), 8 deletions(-) >>>> >>>> diff --git a/kernel/bpf/stackmap.c b/kernel/bpf/stackmap.c >>>> index 94e46b7f340..acd72c021c0 100644 >>>> --- a/kernel/bpf/stackmap.c >>>> +++ b/kernel/bpf/stackmap.c >>>> @@ -31,6 +31,11 @@ struct bpf_stack_map { >>>> struct stack_map_bucket *buckets[] __counted_by(n_buckets); >>>> }; >>>> >>>> +struct bpf_perf_callchain_entry { >>>> + u64 nr; >>>> + u64 ip[PERF_MAX_STACK_DEPTH]; >>>> +}; >>>> + > > we shouldn't introduce another type, there is perf_callchain_entry in > linux/perf_event.h, what's the problem with using that? perf_callchain_entry uses flexible array, DEFINE_PER_CPU seems do not create buffer for this, for ease of use, the size of the ip array has been explicitly defined. struct perf_callchain_entry { u64 nr; u64 ip[]; /* /proc/sys/kernel/perf_event_max_stack */ }; > >>>> static inline bool stack_map_use_build_id(struct bpf_map *map) >>>> { >>>> return (map->map_flags & BPF_F_STACK_BUILD_ID); >>>> @@ -305,6 +310,7 @@ BPF_CALL_3(bpf_get_stackid, struct pt_regs *, regs, struct bpf_map *, map, >>>> bool user = flags & BPF_F_USER_STACK; >>>> struct perf_callchain_entry *trace; >>>> bool kernel = !user; >>>> + struct bpf_perf_callchain_entry entry = { 0 }; >>> >>> so IIUC having entries on stack we do not need to do preempt_disable >>> you had in the previous version, right? >>> >>> I saw Andrii's justification to have this on the stack, I think it's >>> fine, but does it have to be initialized? it seems that only used >>> entries are copied to map >> >> No. We're not adding 1k stack consumption. > > Right, and I thought we concluded as much last time, so it's a bit > surprising to see this in this patch. > Ok, I feel like I'm missing some context from our previous exchange. > Tao, you should go with 3 entries per CPU used in a stack-like > fashion. And then passing that entry into get_perf_callchain() (to > avoid one extra copy). > Got it. It is more clearer, will change it in v3. >> >> pw-bot: cr -- Best Regards Tao Chen