Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp484971lqh; Thu, 28 Mar 2024 07:42:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW/tLJSOl3/Dm4LSYh7fhAVUuXLCjhvJxExVG/bkJHHfFfBr6w0kqVblmcBpSH45CWYnns2VEp5Vhaxnwx0dhkMgTIMPXhf+eNxImPh+A== X-Google-Smtp-Source: AGHT+IHUxIBEWVQk13bDgu1wGaOr8xGhLKv74IwsoyitGmOCthxCPo81FIPXgfAC4PdfOeBd4jLc X-Received: by 2002:a05:6870:a68d:b0:229:cd61:e4d6 with SMTP id i13-20020a056870a68d00b00229cd61e4d6mr3358106oam.36.1711636961147; Thu, 28 Mar 2024 07:42:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711636961; cv=pass; d=google.com; s=arc-20160816; b=m18fb9NCP9gm1qRTbFjMJ5tQhkEz7yWbyN1rwqQUE0hVqla6Hmant6nceB2L7dRsGW ReVBOdSOZQf/IuLUj+4RLXQzr1j1KD6AcUTij6ZEVGfkstjc8NEqKqq3o3+btoQmHGO6 jZQR5PseoTbNfH3YlpMfGNHVMRs3u2oUD+T3Sy+2rlS7WbtZHzXH3XB0MHPPY98VHIzI 5xXCIhiILz28BamKJkHkiiksTeTd21JZEUp5jW0/J7K0gs2F8ergE8LQUqK64lGiTfqk rTVRXF+LCcZSMmcqx5jqs+Tpl2WJIO9NJu/JwQWK1JLDjfkMbCjQOxJlDdizFMPcpexe Oe/g== 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=zOp5govZZQSJRzD95rrhGtQGcUj+k1AZvhk4Bdb7Q3s=; fh=+bHiU77p1ouDxjfTQQo3fMhJP5WfGtxdcvMq/RTxaSA=; b=hEAtvv6ELE+MRBMe8zzUt2FiOqD8DmFkw3BnG+txxVFJixqRrKbbfTm3MVDqJ0RyHW 33oxuo67RYK0Ickj+ICJN3VN+1L3vqmc+5AFPQD2X8EtGwT6DWR0mni94w9PyUq/hXBp +ZK6JswfoOvPGc9BprsUqO2yBg3lLG6B+uiF8ca6Tv8YUaE3JdyXMUpNt9Ndk6Hb8Nlb o70QgEeZmR1kSXh4fOuthL5ruCEpb0/Z+G295yo1x+FzOgrS3xHE32G4/UEbHEHiP7vC 6Hm6atGbhe8sxifLeSakks8leQqmh0DS1lGljkuKuOwtBnO3k3hYRik8dGJnQwI67v/C YTGQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=Uj3GWBEf; 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-123097-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123097-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id cm8-20020a056a020a0800b005e838a618besi1794144pgb.11.2024.03.28.07.42.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 07:42:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-123097-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=Uj3GWBEf; 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-123097-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123097-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id C04482967BA for ; Thu, 28 Mar 2024 14:42:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8E2A212D747; Thu, 28 Mar 2024 14:42:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="Uj3GWBEf" Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.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 998E7127B67 for ; Thu, 28 Mar 2024 14:42:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711636949; cv=none; b=i82Ycwt/vG+FSuTvAUgKHjTF4z/+dRcZM32g+HRaYHwwZGyRoQvEPEdCFk3IRxt7rYxxzrmHUaloEm9GtxQzZle380XmcxHzfFD0JyHHLm3WhrqgNyKEoF7iwuNrxgxAmHIbxwOgzh6eM0nE2Zvhion2NXSMEdyOsVpw1nrQBS0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711636949; c=relaxed/simple; bh=Gc8satM/FTCQ1mZJea9kW64b0UoXxa5bHnts8j6XkdI=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=u6bIxt0uaK8Pz/nJrQSnghCdRIamdybykZjI1c7E0kBQ8VGYFFWooWByhDqQL+x8tHuGjNU7FAZ3asjaKBP5p1LdJzNgo8jYCw0tGKZrMAHF1Fz/QTS/ENWk9GS5XsswsZ4R99MozfEcX/WAqKShi1MkM4yS/aFKl9CPXX7tSy8= 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=Uj3GWBEf; arc=none smtp.client-ip=209.85.215.176 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-pg1-f176.google.com with SMTP id 41be03b00d2f7-5dbd519bde6so719831a12.1 for ; Thu, 28 Mar 2024 07:42:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1711636945; x=1712241745; 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=zOp5govZZQSJRzD95rrhGtQGcUj+k1AZvhk4Bdb7Q3s=; b=Uj3GWBEfDEWNV6Q9ppTZHPzRDEPC9fxtMAqn1djsqbVx20F79rNmK5bgA+C8ycXzbU oEFFP/gogMOePAlDaU9sVoBoNebgesz3ut+o36ul5HOYBJMd8FDxSpMcBn1jKhPVMvtM DOdpDn/ex6muGP4REazyeb/Gp3+Vf6TU9sEauM9bIcCGDUYSn/p3IKSRnP+fMBS21t5i /qa1vZpEOYBTcSQHBpW+JtgJaF1zEFiESDT0I/7Bw21YTEoLdZ5ZsbLSsNzml8/LiCyi 1le6TYrKh/3U7j84SubQtc6js3WFKAVLHZd+ZVJrYF1zJM3z31z5W0BC5+zFqi3Zp6l5 1w2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711636945; x=1712241745; 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=zOp5govZZQSJRzD95rrhGtQGcUj+k1AZvhk4Bdb7Q3s=; b=eF1yp+1Ml9ePkLYchjC5FJWOsBRSiuItmxbzTgojUmevvXEldUtDiqRsRWhzdew/ZJ 88fjFJ5BGaH1eoZ0P2u7xw0yCEzF7589AzXcQGtoGZOezjQ9COij19s//lNhCRHFt6v/ 4gkqCm4h8TQEnt4BUF6EFcAcn+Nl0+YI8EfaY3HK6Z7J5I5BHnb9sxe00o4bYW3hZfHR QJClWUhSiNVnZty1ioH3XKtdwZVFBUJPZPqdsdXpjAbgFXnGqT4wDhs+XsBpz4LRi+Iy BFV71ltSQ/vg4YBQacrZkmoLyPP9R5xdYzGRVtR6Puko54Gma2XDhf6iBmaC4DWpA6Wk oTjQ== X-Forwarded-Encrypted: i=1; AJvYcCUXWLSfN1QnqPI2HmHMilcfg15BZVyg4jLsIHWWJirxwOBnvb9imbQoZMJu0CI/oNj8qDloABXWY7gB7u8vbhQJ4VK9QbAz+pMzPaL7 X-Gm-Message-State: AOJu0YxuL+OtN7JSkiGKMULl6xlIfJYlpFeNUxPS9VqOAlS62teaMGN9 c1FnnBe/lHzzPBY60FzhGKY5oSsiB6g41bVIVP7TACF2satNio7A7zMVTMCExUZ3kWTVvlMmfn1 isK+nkLxvID/pfVYgR6edopzan2tTFeuBUkImGw== X-Received: by 2002:a17:90a:d481:b0:2a2:88d:19d9 with SMTP id s1-20020a17090ad48100b002a2088d19d9mr1331992pju.1.1711636945073; Thu, 28 Mar 2024 07:42:25 -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: Thu, 28 Mar 2024 22:43:46 +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: Alexei Starovoitov , Jiri Olsa Cc: 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 Fri, Mar 15, 2024 at 4:00=E2=80=AFPM =E6=A2=A6=E9=BE=99=E8=91=A3 wrote: > > On Thu, Mar 14, 2024 at 8:27=E2=80=AFAM Alexei Starovoitov > wrote: > > > > On Tue, Mar 12, 2024 at 6:53=E2=80=AFPM =E6=A2=A6=E9=BE=99=E8=91=A3 wrote: > [......] > > > 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. > > I see. Creating plenty of trampolines does take a lot of time, > and I'll do testing on it. > I have done a simple benchmark on creating 1000 trampolines. It is slow, quite slow, which consume up to 60s. We can't do it this way. Now, I have a bad idea. How about we introduce a "dynamic trampoline"? The basic logic of it can be: """ save regs bpfs =3D trampoline_lookup_ip(ip) fentry =3D bpfs->fentries while fentry: fentry(ctx) fentry =3D fentry->next call origin save return value fexit =3D bpfs->fexits while fexit: fexit(ctx) fexit =3D fexit->next xxxxxx """ And we lookup the "bpfs" by the function ip in a hash map in trampoline_lookup_ip. The type of "bpfs" is: struct bpf_array { struct bpf_prog *fentries; struct bpf_prog *fexits; struct bpf_prog *modify_returns; } When we need to attach the bpf progA to function A/B/C, we only need to create the bpf_arrayA, bpf_arrayB, bpf_arrayC and add the progA to them, and insert them to the hash map "direct_call_bpfs", and attach the "dynamic trampoline" to A/B/C. If bpf_arrayA exist, just add progA to the tail of bpf_arrayA->fentries. When we need to attach progB to B/C, just add progB to bpf_arrayB->fentries and bpf_arrayB->fentries. Compared to the trampoline, extra overhead is introduced by the hash lookuping. I have not begun to code yet, and I am not sure the overhead is acceptable. Considering that we also need to do hash lookup by the function in kprobe_multi, maybe the overhead is acceptable? Thanks! Menglong Dong > > > > > > > > > > Let's step back. > [......] > > > > 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.