Received: by 2002:ab2:2994:0:b0:1ef:ca3e:3cd5 with SMTP id n20csp622125lqb; Fri, 15 Mar 2024 01:17:44 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWVwI62xcytPCTqflBB98UjsWkXRLutcXYfu5a1TXj5MaFEnQMJY0H3qLF9DEIXOdEFNSGMMcK/sAfICYHcYX2Las4PE01hdfWoBzvh8w== X-Google-Smtp-Source: AGHT+IEv7uQyhCtae2Uk+3p4xDhJO/sCcsEsUm6klb3iyidP1Z87emqudereAtmeUvshcFgSr3q6 X-Received: by 2002:a05:622a:4b:b0:42e:ec1a:1607 with SMTP id y11-20020a05622a004b00b0042eec1a1607mr6627178qtw.30.1710490664599; Fri, 15 Mar 2024 01:17:44 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710490664; cv=pass; d=google.com; s=arc-20160816; b=uI4xNbDt1lFF1OSNDMkyX0maFkx/1NMf6WYtUWGF3Jm9wjv22U3Fyf3Zpef5T7dsEQ GnXwrzakB9YFThC58KXl5WIau+qOUyuthrzVDUR8I4PFsNoH/3V+mtCPN0UeKdcrk0yM WtigXMQr/xL08ZyZVygyIW7tlg/CdY5A/l2a6MWkR1f6bqyXpTC1N68VzNtGC22uPhRC cYmxQRpRAO/eJ4053muIh5Sog6ZqSh0KmBAZnXrNoqcJK4hifvBSIF7pHEeLbujMScAh 0iD3SF6XLxVxsiL9VGzPrtfW0HrGfQxxUX1TmMSnLlU9djyS6yD7L6K4529yZykRU/7n 8/7A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=ux+mgvQeyHLipAJjQDCARUR07kgvWhujuDpfd9PKvNE=; fh=rL6xcMeVKii5m//iJmUazAcyy9JGGNIrs7Vwy5DKrfw=; b=hZD5ZWhSF82T9oau6ZYYLZYyQdFnOjBf+cCMYRlQ2NSY+tz5Pi00sbr9qgMsNlnObt b8NqRTRLiTtHVGyQKi2AxD3ROzQwUd4eR1MHw9g/8G/iJSfwtUEKZR/aiuYiFZM+2KWM fYY+zcEpFytWP/SW+pa1f4bhCxaQGrA6VBENW5ag0WaX3mBWyQuKlFnOP3p8iwcJiIQZ OzwNvZdq9IPqxhX0zsjNqPH5YyYI8wQoTKxbkn/jLmcnO6xzvj560lPdVb9EaoK5ioR7 dY6c0LGNwOmrKPVzoSSc6C6pP6vSkfPFTHuU45jRfOpw8SyUB5JsZ9GNLbME49I3T/da XueQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=BnLnF6jp; arc=pass (i=1 spf=pass spfdomain=bytedance.com dkim=pass dkdomain=bytedance.com dmarc=pass fromdomain=bytedance.com); spf=pass (google.com: domain of linux-kernel+bounces-104151-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104151-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id c7-20020ac80547000000b004309ea27fe0si2508876qth.137.2024.03.15.01.17.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Mar 2024 01:17:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-104151-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=BnLnF6jp; arc=pass (i=1 spf=pass spfdomain=bytedance.com dkim=pass dkdomain=bytedance.com dmarc=pass fromdomain=bytedance.com); spf=pass (google.com: domain of linux-kernel+bounces-104151-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-104151-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 46E8E1C2238E for ; Fri, 15 Mar 2024 08:17:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1BDA71757A; Fri, 15 Mar 2024 08:17:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="BnLnF6jp" Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) (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 99E6C17592 for ; Fri, 15 Mar 2024 08:17:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710490647; cv=none; b=WnHp8GpO4Q6Z7fuA3OCX3Ha30KVgKGF5iXyid8/0bWPoVrNPmuLRd02ZRNDfgKOFZuG2hM7hTE02rtFmiktl+1yuIjhh6FLHJnwb8u4GzkfRT+Hmlu9QTErPtwuufRKpNID/GMeOQmGnoLOv18JwAWyDTz0QWpnTsKAJSGiY9QM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710490647; c=relaxed/simple; bh=3Veip/OxCnGKCQ+Abe6TiS3hdoh9knWDIAqJQrDZQBc=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Nt+jo6LcpTfnNlbQNfA7RD+RwB8UXDGub2XxoxxM2paXyXzywwsHuRtNe5PqSaJtQffJx0gPKNOI4wpWIk0xNnT1jmkc+TXqRThoVKKKYyOFBeiGpKfTNZY+bXZBQPxjXhBYOCIIvnGSPMRaS39CzVu/nmeZnKFr4fEhrEnIrUM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=BnLnF6jp; arc=none smtp.client-ip=209.85.216.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Received: by mail-pj1-f54.google.com with SMTP id 98e67ed59e1d1-29c52a90417so1337356a91.1 for ; Fri, 15 Mar 2024 01:17:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1710490644; x=1711095444; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=ux+mgvQeyHLipAJjQDCARUR07kgvWhujuDpfd9PKvNE=; b=BnLnF6jpTf0M3GTFjcSWetvSvIQOQ369PIgwF3aG0VASfibFMiCxnhy8vtyqhOsjyx 4iCua5b7xLUAUwDsGjXK/pp/XgXWUnBG6c/CKGhyio9pC/GzFGLP2/VFJWSe+yw6/QC2 SLs4tMFzW1MrA6ts1TTFeTkDa7eHXNIoux2jcNUZcTWqGHBe6mTwr32HfYOFkkZcXOe2 z2RVX0Hq5om3SYzgJ9iR3RM98+/Fv0UMU7l6EP5buU4YPD8LDhyAIISras9vEeQp4wfc 3SPkE0rovMXGjiRmz7PzUbWxW1Z1HmnSlwKnklK6x/rX5v3TAVv47PoG9ldtlB1sAHTd tnGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710490644; x=1711095444; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ux+mgvQeyHLipAJjQDCARUR07kgvWhujuDpfd9PKvNE=; b=NDUCMhvAsydF7W3g60wQ21wO+V9gBbjWuI8l9QS21ALXqW3ChIcnfMkaZyX4wC+r46 ylwrOenBfnaDip4msbfPev9UIYmaaVwSTKs1bpIZSoEEtWjXSLpDPxUXiaG81nGTGKIJ zjRMozO1X0LwYXweyPco8A/1z79v36ohrLcQZumUDAATsczS5RVnXFbDHnxKVDEC73Da PdV3V3LeDUrAO216gKAEUpA9MTOBwDHplg/zZXdvDve+rGIPWeY96AYkg9VYevl+T+s4 sfSiOJEW4Ov0HsAr+Tqz7EgPH8tIr4NpWp0iJUUm7YMGOdyePqSLxzDbEKRy28vQvvhk ULUQ== X-Forwarded-Encrypted: i=1; AJvYcCXVq3M4tWbJXYiFKYTahxbI9PJsbExE0y7nc3h50aeeaTkifIrMS9xdPnRTgdg4qSGcXqp5kOmnjKkLnAL6gd0y+VZiArBA0Xy6ErFb X-Gm-Message-State: AOJu0YybAhDzOZ3CecZa3zxD8xAd12fGzrRv0AWLimJiD40lz82Mm5cD CIBXMAnvLL+Fjf0ikg/X2JX75P1knX1YUyEhjM9aCmtJIGhqwxLwVXDAMquS/mlNaqk+X/Yt6j1 cCJUDA6hG66IZUt2PAHiZRSKEhLefUsEAur7wbw== X-Received: by 2002:a17:90a:fa18:b0:29c:735:a758 with SMTP id cm24-20020a17090afa1800b0029c0735a758mr6401475pjb.19.1710490643623; Fri, 15 Mar 2024 01:17:23 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240311093526.1010158-1-dongmenglong.8@bytedance.com> <20240311093526.1010158-2-dongmenglong.8@bytedance.com> In-Reply-To: From: =?UTF-8?B?5qKm6b6Z6JGj?= Date: Fri, 15 Mar 2024 16:17:12 +0800 Message-ID: Subject: Re: [External] Re: [PATCH bpf-next v2 1/9] bpf: tracing: add support to record and check the accessed args To: Jiri Olsa Cc: Alexei Starovoitov , Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , Eddy Z , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Alexander Gordeev , Christian Borntraeger , Sven Schnelle , "David S. Miller" , David Ahern , Dave Hansen , X86 ML , Steven Rostedt , Mathieu Desnoyers , Quentin Monnet , bpf , linux-arm-kernel , LKML , linux-riscv , linux-s390 , Network Development , linux-trace-kernel@vger.kernel.org, "open list:KERNEL SELFTEST FRAMEWORK" , linux-stm32@st-md-mailman.stormreply.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Mar 14, 2024 at 2:29=E2=80=AFPM Jiri Olsa wrot= e: > > On Wed, Mar 13, 2024 at 05:25:35PM -0700, Alexei Starovoitov wrote: > > On Tue, Mar 12, 2024 at 6:53=E2=80=AFPM =E6=A2=A6=E9=BE=99=E8=91=A3 wrote: > > > > > > On Wed, Mar 13, 2024 at 12:42=E2=80=AFAM Alexei Starovoitov > > > wrote: > > > > > > > > On Mon, Mar 11, 2024 at 7:42=E2=80=AFPM =E6=A2=A6=E9=BE=99=E8=91=A3= wrote: > > > > > > > > [......] > > > > > > > > I see. > > > > I thought you're sharing the trampoline across attachments. > > > > (since bpf prog is the same). > > > > > > That seems to be a good idea, which I hadn't thought before. > > > > > > > But above approach cannot possibly work with a shared trampoline. > > > > You need to create individual trampoline for all attachment > > > > and point them to single bpf prog. > > > > > > > > tbh I'm less excited about this feature now, since sharing > > > > the prog across different attachments is nice, but it won't scale > > > > to thousands of attachments. > > > > I assumed that there will be a single trampoline with max(argno) > > > > across attachments and attach/detach will scale to thousands. > > > > > > > > With individual trampoline this will work for up to a hundred > > > > attachments max. > > > > > > What does "a hundred attachments max" means? Can't I > > > trace thousands of kernel functions with a bpf program of > > > tracing multi-link? > > > > I mean what time does it take to attach one program > > to 100 fentry-s ? > > What is the time for 1k and for 10k ? > > > > The kprobe multi test attaches to pretty much all funcs in > > /sys/kernel/tracing/available_filter_functions > > and it's fast enough to run in test_progs on every commit in bpf CI. > > See get_syms() in prog_tests/kprobe_multi_test.c > > > > Can this new multi fentry do that? > > and at what speed? > > The answer will decide how applicable this api is going to be. > > Generating different trampolines for every attach point > > is an approach as well. Pls benchmark it too. > > > > > > > > > > Let's step back. > > > > What is the exact use case you're trying to solve? > > > > Not an artificial one as selftest in patch 9, but the real use case= ? > > > > > > I have a tool, which is used to diagnose network problems, > > > and its name is "nettrace". It will trace many kernel functions, whos= e > > > function args contain "skb", like this: > > > > > > ./nettrace -p icmp > > > begin trace... > > > ***************** ffff889be8fbd500,ffff889be8fbcd00 *************** > > > [1272349.614564] [dev_gro_receive ] ICMP: 169.254.128.15 -> > > > 172.27.0.6 ping request, seq: 48220 > > > [1272349.614579] [__netif_receive_skb_core] ICMP: 169.254.128.15 -> > > > 172.27.0.6 ping request, seq: 48220 > > > [1272349.614585] [ip_rcv ] ICMP: 169.254.128.15 -> > > > 172.27.0.6 ping request, seq: 48220 > > > [1272349.614592] [ip_rcv_core ] ICMP: 169.254.128.15 -> > > > 172.27.0.6 ping request, seq: 48220 > > > [1272349.614599] [skb_clone ] ICMP: 169.254.128.15 -> > > > 172.27.0.6 ping request, seq: 48220 > > > [1272349.614616] [nf_hook_slow ] ICMP: 169.254.128.15 -> > > > 172.27.0.6 ping request, seq: 48220 > > > [1272349.614629] [nft_do_chain ] ICMP: 169.254.128.15 -> > > > 172.27.0.6 ping request, seq: 48220 > > > [1272349.614635] [ip_rcv_finish ] ICMP: 169.254.128.15 -> > > > 172.27.0.6 ping request, seq: 48220 > > > [1272349.614643] [ip_route_input_slow ] ICMP: 169.254.128.15 -> > > > 172.27.0.6 ping request, seq: 48220 > > > [1272349.614647] [fib_validate_source ] ICMP: 169.254.128.15 -> > > > 172.27.0.6 ping request, seq: 48220 > > > [1272349.614652] [ip_local_deliver ] ICMP: 169.254.128.15 -> > > > 172.27.0.6 ping request, seq: 48220 > > > [1272349.614658] [nf_hook_slow ] ICMP: 169.254.128.15 -> > > > 172.27.0.6 ping request, seq: 48220 > > > [1272349.614663] [ip_local_deliver_finish] ICMP: 169.254.128.15 -> > > > 172.27.0.6 ping request, seq: 48220 > > > [1272349.614666] [icmp_rcv ] ICMP: 169.254.128.15 -> > > > 172.27.0.6 ping request, seq: 48220 > > > [1272349.614671] [icmp_echo ] ICMP: 169.254.128.15 -> > > > 172.27.0.6 ping request, seq: 48220 > > > [1272349.614675] [icmp_reply ] ICMP: 169.254.128.15 -> > > > 172.27.0.6 ping request, seq: 48220 > > > [1272349.614715] [consume_skb ] ICMP: 169.254.128.15 -> > > > 172.27.0.6 ping request, seq: 48220 > > > [1272349.614722] [packet_rcv ] ICMP: 169.254.128.15 -> > > > 172.27.0.6 ping request, seq: 48220 > > > [1272349.614725] [consume_skb ] ICMP: 169.254.128.15 -> > > > 172.27.0.6 ping request, seq: 48220 > > > > > > For now, I have to create a bpf program for every kernel > > > function that I want to trace, which is up to 200. > > > > > > With this multi-link, I only need to create 5 bpf program, > > > like this: > > > > > > int BPF_PROG(trace_skb_1, struct *skb); > > > int BPF_PROG(trace_skb_2, u64 arg0, struct *skb); > > > int BPF_PROG(trace_skb_3, u64 arg0, u64 arg1, struct *skb); > > > int BPF_PROG(trace_skb_4, u64 arg0, u64 arg1, u64 arg2, struct *skb); > > > int BPF_PROG(trace_skb_5, u64 arg0, u64 arg1, u64 arg2, u64 arg3, str= uct *skb); > > > > > > Then, I can attach trace_skb_1 to all the kernel functions that > > > I want to trace and whose first arg is skb; attach trace_skb_2 to ker= nel > > > functions whose 2nd arg is skb, etc. > > > > > > Or, I can create only one bpf program and store the index > > > of skb to the attachment cookie, and attach this program to all > > > the kernel functions that I want to trace. > > > > > > This is my use case. With the multi-link, now I only have > > > 1 bpf program, 1 bpf link, 200 trampolines, instead of 200 > > > bpf programs, 200 bpf link and 200 trampolines. > > > > I see. The use case makes sense to me. > > Andrii's retsnoop is used to do similar thing before kprobe multi was > > introduced. > > > > > The shared trampoline you mentioned seems to be a > > > wonderful idea, which can make the 200 trampolines > > > to one. Let me have a look, we create a trampoline and > > > record the max args count of all the target functions, let's > > > mark it as arg_count. > > > > > > During generating the trampoline, we assume that the > > > function args count is arg_count. During attaching, we > > > check the consistency of all the target functions, just like > > > what we do now. > > > > For one trampoline to handle all attach points we might > > need some arch support, but we can start simple. > > Make btf_func_model with MAX_BPF_FUNC_REG_ARGS > > by calling btf_distill_func_proto() with func=3D=3DNULL. > > And use that to build a trampoline. > > > > The challenge is how to use minimal number of trampolines > > when bpf_progA is attached for func1, func2, func3 > > and bpf_progB is attached to func3, func4, func5. > > We'd still need 3 trampolines: > > for func[12] to call bpf_progA, > > for func3 to call bpf_progA and bpf_progB, > > for func[45] to call bpf_progB. > > > > Jiri was trying to solve it in the past. His slides from LPC: > > https://lpc.events/event/16/contributions/1350/attachments/1033/1983/pl= umbers.pdf > > > > Pls study them and his prior patchsets to avoid stepping on the same ra= kes. > > yep, I refrained from commenting not to take you down the same path > I did, but if you insist.. ;-) > > I managed to forgot almost all of it, but the IIRC the main pain point > was that at some point I had to split existing trampoline which caused > the whole trampolines management and error paths to become a mess > > I tried to explain things in [1] changelog and the latest patchset is in = [0] > > feel free to use/take anything, but I advice strongly against it ;-) > please let me know if I can help I have to say that I have not gone far enough to encounter this problem, and I didn't dig enough to be aware of the complexity. I suspect that I can't overcome this challenge. The only thing that I thought when I hear about the "shared trampoline" is to fallback and not use the shared trampoline for the kernel functions who already have a trampoline. Anyway, let's have a try on it, based on your research. Thanks! Menglong Dong > > jirka > > > [0] https://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git/log/?h= =3Dbpf/batch > [1] https://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git/commit= /?h=3Dbpf/batch&id=3D52a1d4acdf55df41e99ca2cea51865e6821036ce