From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6048F14A0BC for ; Mon, 3 Nov 2025 06:00:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762149641; cv=none; b=o0c2EbDesoBgbu8twtTSruIFFy6ykDED7Ztrn1sQll6irZZRf28dqGbgubC46sDJBrbNkxbn5HyKGqNwv5Bd+qeg6xBUil/PeKbJ/5SXXZK5ZsjTnKw2m2+0XAffBKBgwHvJpd+sVh0Kuig8zHS/cSY7v2knDFZ2lW6DRS0UXP4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762149641; c=relaxed/simple; bh=dVwCHJXTZsWhOYA1AO/9rpvP07SF8u8wi2kPt8EuWAc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Nzn66cWjhzAzVc7O3Yz51YoSntHSlUOgv7b4glrY//BWKafuoB5SWa0h3Bwaz+GINWzQOUI2IGSMeMqHNJU9BfdHBKS1xRW9KSxZifQ5m9P0I0dM86Fy24c9YjmHmxLvl2Fo1r3veiAEUI7DA2vwoLYpZR/vpw2TmC31lC6/mwI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=UYnJbs4v; arc=none smtp.client-ip=209.85.214.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UYnJbs4v" Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-29516a36affso26681795ad.3 for ; Sun, 02 Nov 2025 22:00:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762149640; x=1762754440; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=dVwCHJXTZsWhOYA1AO/9rpvP07SF8u8wi2kPt8EuWAc=; b=UYnJbs4vIjMLsbtCjskCs16VmNkF6uhydvwRR4mlD1zmXzolRcPnfe/KxgderLfBNt 9cckavzkfNCaZop7/2tDqJjRpUedOH7L1x9HSb41HAHx0LnLQGWHihxmRYxpw++k1zbw Vc0X0MRA5zyxLVuuEBfKrW5WFFh+OERDayKUUbkmHHhAy2j7lgVQP1Jy5kQn180eqo2y aFn5NfJt1rTsjuZ6XFRt8AOOPBaFTKHLL+Q27U7akRaENTpKRzLRbZWwpdk4EUNGOknE KfertAPTHErrafxPKC4AArb2Y0Lr61P+XMjkiOe2+r3k7K0UHZ+KIzsZfwx51K7cPhzA 9yFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762149640; x=1762754440; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=dVwCHJXTZsWhOYA1AO/9rpvP07SF8u8wi2kPt8EuWAc=; b=OpL/tq5U39T0trwxZwkTbbHmdoOMRXyURCVT0TNLOR/F6ONT5I+x2CIKqe5hx0LA17 a5GE7nlygA5bBxLeRP/di0B1MPav2rHB6SLUInFc6V5b19QBOG4As/fXGGU8c5mOWRfv qi+l6km6ot/YXGrXaA9oG6g8icnZbskb44nD9jhougOPHPUlkI1eztxtOqhY4jsKKEbz +51YicHKee6AhBDtz6fb1lruWpvNBPjA2pcadAjiR9yIpCLH3ZC5nt5UmMcAqfOmnDGY +62btQW/AWkjJU88QatRnF+iLK69D06lRgqUspatrx1Siy4ZC58rusJNYWvAtvOzR4TL PHKA== X-Forwarded-Encrypted: i=1; AJvYcCW84OIF3P3rGlylhoksCOw2k/GYAjtCt7Q3mv4rr/tDhXEUdt+ZGaNI78yU40aEYFemHxRt9DsIvV1J8kyUoCHjuj8=@vger.kernel.org X-Gm-Message-State: AOJu0YzwWXAZi/6Pf+rv3ey+kuodVRUzIAmWw3kMVG68GlW7Puwyx53A 1JsOaBiW2eN4XUUa/XROXOjyGrFJec3LWJywEENUIST1DK0PhqRfDb3v X-Gm-Gg: ASbGncsSrBsDu82LkoaM9zbMJiBkw2TTEoZW/YhjhsY+piDfvlLNFcDNbSTCeZarWG/ KmO0rybT2BNfd7AW+WHdlWkZ1pV4fnUTdYSJTqk4J3Xd8FlwT+/SZ+oeUExzXxPGfhEMB4OXOv+ GSuQ3eCgb4SjmZ+8rBu1lPxwQxOqSLiX/BVT0cbqjrYoj7a+USOoHSDS0VFwxDcLYWFiCSf6tWv wtf2ZPaU9OCS/MOu2lvD+/M/rzBhoiyDDCDsG/OoN1nldzc+35DuDacI53R0RHqhLocSztzo4fs GXx3sFUfY4DFnvfwRHmd4HLzjBI9kEYD9bHlURKMO1h8+RE7SZe5JoysQyh1Wxr3dZeFypAx4Wt H0v5VIpvftvzg9D6SAhoyfvcW0ovKgqz8tBEQHYe1Ab2k6g51K6ULbN9Fuepn7s4TU422S1Ge0+ m9kQwFOw8EoOUiH3O5pQSdCQ== X-Google-Smtp-Source: AGHT+IGRzFc83vH+4aej1ZtXWsWRwhc5e/vhPzGXxyYQr93eNqozzEOLe2v+EaAyyyHN0ypSfD81jg== X-Received: by 2002:a17:902:daca:b0:27d:6f37:7b66 with SMTP id d9443c01a7336-2951a486898mr157814315ad.47.1762149639568; Sun, 02 Nov 2025 22:00:39 -0800 (PST) Received: from [10.22.64.59] ([122.11.166.8]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-29531a1965esm99055775ad.6.2025.11.02.22.00.34 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 02 Nov 2025 22:00:38 -0800 (PST) Message-ID: Date: Mon, 3 Nov 2025 14:00:33 +0800 Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH bpf-next v3 4/7] bpf,x86: add tracing session supporting for x86_64 Content-Language: en-US To: Alexei Starovoitov , Menglong Dong Cc: Alexei Starovoitov , Jiri Olsa , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Eduard , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Matt Bobrowski , Steven Rostedt , Masami Hiramatsu , Leon Hwang , jiang.biao@linux.dev, bpf , LKML , linux-trace-kernel References: <20251026030143.23807-1-dongml2@chinatelecom.cn> <20251026030143.23807-5-dongml2@chinatelecom.cn> From: Leon Hwang In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 1/11/25 01:57, Alexei Starovoitov wrote: > On Thu, Oct 30, 2025 at 8:36 PM Menglong Dong wrote: >> >> On Fri, Oct 31, 2025 at 9:42 AM Alexei Starovoitov >> wrote: >>> >>> On Sat, Oct 25, 2025 at 8:02 PM Menglong Dong wrote: [...] >> >> Without the session cookie, it will be much easier to implement >> in another arch. And with the hepler of AI(such as cursor), it can >> be done easily ;) > > The reality is the opposite. We see plenty of AI generated garbage. > Please stay human. > >> >>> At this point I'm not sure that "symmetry with kprobe_multi_session" >>> is justified as a reason to add all that. >>> We don't have a kprobe_session for individual kprobes after all. >> >> As for my case, the tracing session can make my code much >> simpler, as I always use the fentry+fexit to hook a function. And >> the fexit skipping according to the return value of fentry can also >> achieve better performance. > > I don't buy the argument that 'if (cond) goto skip_fexit_prog' > in the generated trampoline is measurably faster than > 'if (cond) return' inside the fexit program. > >> AFAIT, the mast usage of session cookie in kprobe is passing the >> function arguments to the exit. For tracing, we can get the args >> in the fexit. So the session cookie in tracing is not as important as >> in kprobe. > > Since kprobe_multi was introduced, retsnoop and tetragon adopted > it to do mass attach, and both use bpf_get_attach_cookie(). > While both don't use bpf_session_cookie(). > Searching things around I also didn't find a single real user > of bpf_session_cookie() other than selftests/bpf and Jiri's slides :) > > So, doing all this work in trampoline for bpf_session_cookie() > doesn't seem warranted, but with that doing session in trampoline > also doesn't look useful, since the only benefit vs a pair > of fentry/fexit is skip of fexit, which can be done already. > Plus complexity in all JITs... so, I say, let's shelve the whole thing for now. > As for bpfsnoop[1], the new attach type is indeed helpful. For example, when tracing hundreds of kernel functions with both fentry and fexit programs on a 48-core bare-metal server, the following results were observed: bpfsnoop -k 'tcp_connect' --output-fgraph --limit-events 1 -D 2025/11/03 13:32:11 Tracing 586 tracees costs 10.190874525s 2025/11/03 13:32:14 bpfsnoop is exiting.. 2025/11/03 13:32:45 Untracing 586 tracees costs 30.667462289s With the new attach type, about half of the time can be saved. For bpfsnoop, the return-value control could help avoid redundant filtering in fexit programs, though it's not strictly necessary. For instance, when tracing udp_rcv with both packet and argument filters: bpfsnoop -k '(b)udp_rcv' --filter-pkt 'host 1.1.1.1 and udp src port 53' --filter-arg 'skb->dev->ifindex == 6' -v 2025/11/03 13:52:55 Tracing(fentry) kernel function udp_rcv 2025/11/03 13:52:55 Tracing(fexit) kernel function udp_rcv With return-value control, the filtering in fexit could be skipped. Links: [1] https://github.com/bpfsnoop/bpfsnoop Thanks, Leon