Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp767049lqh; Thu, 28 Mar 2024 16:17:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUlZ6ClhEiN+85c/1NFA0QC4Nrjtw3bEuyqJqyUZ2pKT1BDBBCDmTwGQq/As8+vooTPZHzSDY5WlwfsdpoyELAkrTSDj1V2g06I8tCC9g== X-Google-Smtp-Source: AGHT+IEycHmDnEuj/fjRayz/9VCvvo+4KgTeiY7R2yWi7E7IpJL1Paz0x7Y2k6ovdsVG2liuBs1y X-Received: by 2002:a17:907:3186:b0:a4e:2cd6:8ac2 with SMTP id xe6-20020a170907318600b00a4e2cd68ac2mr510327ejb.56.1711667870711; Thu, 28 Mar 2024 16:17:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711667870; cv=pass; d=google.com; s=arc-20160816; b=luJBRmlQh1MF264gEv8vgFZZ4RBA1/tk1LLa6Oh7pCZOq67wECZcfVLfMDosBi+HAi F30wWwqGIw9DVlOjARRaf0Eu4sDj8TuQ6oHfhTUQvVfI7HVdatZrgQ6bjeyNIG/10B6E 4Fav0Pwgib90SleGtl/F1zlRuArY3cFsfVVRdoZHJbwtRejABg3IvcYT9aoxGSNhCu+z ZD3HYTQ/sSaePSH63yVmwU0TmoCFbF5EinuwXVo5gC9X7R3ETrVtF4VvMpNii26OpT8U Iad7T2apwqmsUCuBjLoS1td+PjkD/5w1DZ5JXEyaJhGKH0xniexpI3DXOWgu31B0T2U2 LquQ== 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=VBPtswbRJVFEjRlZATnnC5PXpnMT+l8bd9tpx27HnBM=; fh=9SudGciYKXPBMMUVfLAEmxfpuAZigU9o7fbdRdus1o0=; b=wwsaZekeQL+VhVx0OCV01kTowqBR0s3gtJI5SOh4NqsldVjlmXL19S3FmfFY/OQIcO 89SQaXGHOjiyiIcqpKLVdHT+0lzxlYSmh5D+nEbhkNeHacbSESduBRfH1v/t0cD/Z/2X +gxX0nuLdQaweNa+nBaJ2E/fSoATSR0i7xhSd7fF8kMVnLjQh7uqVjyM+HK6+/a0kMdv lVpOH1g60/UtidVsTM+cq1Zyf0dlhrozpz0SsKxMj+tTWg2eNCJTfVYUUEzGlylGqESj lfIgLqDNKBMW/KqAfbsQaU/UVDw/IUEAlTM7LdkND1pBB1D/jdwAzCllxcPTttmf7n2/ Gniw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FZORLLVM; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-123810-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123810-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id b12-20020a17090636cc00b00a474c466e1bsi1166435ejc.955.2024.03.28.16.17.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 16:17:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-123810-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FZORLLVM; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-123810-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123810-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.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 am.mirrors.kernel.org (Postfix) with ESMTPS id 499AD1F24702 for ; Thu, 28 Mar 2024 23:17:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 64C071327F6; Thu, 28 Mar 2024 23:17:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FZORLLVM" Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.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 B89F73BBF1; Thu, 28 Mar 2024 23:17:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711667854; cv=none; b=GXxLly7f42ZVPohQUJrkguieuROh8N+zEdKyQb56kiNhdvp8POAgArD5exAMwV6QkDULSaoYxipMDgWgU2Nfv9RheM7nQsRuoabVtkzsLZaXnBaP2tcxYAd1BngnxixHwJa6NJy47kYInW+nAh24wzgqv0dASW7JVqpd2kSebPk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711667854; c=relaxed/simple; bh=lxs2ZFR/bExqKNMSEhSfupLSlYECG6xtGJZ2Htju2B4=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=FIHMp4GUzrUUQ3yTRz/G/FMagjavFSfHSAJrrYmzV7/hTROS/LtudG66Fm/dZ0199SEms9GgsmwvQmVjkXoORw/rIdTZ5VB+sOE40K7GzykLs5AOmru4r53RlmfsmiWuCM6ZiAef1Gh6t7E7diOrBeLx+KgrekEJNREJAwu0wQs= 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=FZORLLVM; arc=none smtp.client-ip=209.85.208.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 Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-2d717603aa5so586161fa.0; Thu, 28 Mar 2024 16:17:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711667851; x=1712272651; 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=VBPtswbRJVFEjRlZATnnC5PXpnMT+l8bd9tpx27HnBM=; b=FZORLLVM4zTQrqx2Nmbsi0cxFMKlY+f0aT4H8rCdE6yZSJYjqMDcdjuqe/TEn+Wo7F ghBvacZZoOJOcpwzMcXvG0TG3S/0fOKIdwHFmFRxu2LYqVYBt+rMN7bjgyQnaJBxPkf9 h+liqXbkE9MUNcLcxMa0vOhpY7I582D/xgj+HRQALIYoSnC6YUy45xGAbxV5SB/1JeCy 6BMhl4d9G3np8DiZMRhYLdJ2NDZd9berzJVlhWriMAj/RaXWcZ2fqquz1dnEdRGvTgGw cT79hNvmyuCk+jFeZoKG0m2pdrOzjq4LEZYArlYYR9pzXxo4ZxayLmm+RDHtfH7PcfSu u3mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711667851; x=1712272651; 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=VBPtswbRJVFEjRlZATnnC5PXpnMT+l8bd9tpx27HnBM=; b=xBC3yMEy+HMKWfXGDitVEIWuIyFzdFfJiXpOKiUUO55CbpduuFFsIX6Q1nmtUIiqAa yrh0Z7vpFFSJbot1mO0B24HeDaMMxLSdUgOElK38mwLLx/JvhSShIKrH6zcCEwgzCFz0 EjIVA8mk/ITVub1JKA1wPoflbfpkYtdZWUqpIr3wxmVRMmDBw3VASGu2r5MDfvStJP/3 EiZ/w40Vwv7pAb7wrcVkSCcYva05Fy1SZ7lAuezqiZdBD03BB0kiagmOIiTcri9SUOCx FEgcPpaDRxaW6WU9myeJA6xhY8P4eBl++2bSBMep53snjpUDpxqH0Wn3m4khbZkdzx1Z dIdQ== X-Forwarded-Encrypted: i=1; AJvYcCUrEhk9ZCNz2T3dkDxm800rRE2SbENK0BG54VELoFgUmeu90XQvXJYAaBWTJb0R/vKfbyGH1N+YU+X4V6FmXQZhvezuJm96cn+XHgqFU/L7f+19eWedq3rADJ3G6q2Y4iTpjdYR3e1CuDm7MUcY7d+Hu1xZxHYiBEshJBjQU/NIS33K7Hx5f3u+u2mk5hjYCHQjjZvuyu3Q0gNUpiOA+w36R7dhy7k4zS9tUlEmDs6kXHb9HgvmU72zuHkzrunOk3HnMrroQzgUNW1kPcmiBr06JnzXwNwo7keA5A== X-Gm-Message-State: AOJu0YzLkPKp0+yi/a53yiskBjpLMm/atVgfDkEzvBTNZVeSz9RK3D39 0c6gtF6WEEu20HS2BbEKxaMfXuNlIJXO6MBhMDxIvA0xoCXpUQq3YmQb+BLMhmo6KjNFzPleVX6 jUb/86upMXvx4sSYsD90CpFmTiPs= X-Received: by 2002:a05:651c:1692:b0:2d6:c7b5:989c with SMTP id bd18-20020a05651c169200b002d6c7b5989cmr378385ljb.28.1711667850565; Thu, 28 Mar 2024 16:17:30 -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> <20240328111330.194dcbe5@gandalf.local.home> In-Reply-To: <20240328111330.194dcbe5@gandalf.local.home> From: Alexei Starovoitov Date: Thu, 28 Mar 2024 16:17:19 -0700 Message-ID: Subject: Re: [External] Re: [PATCH bpf-next v2 1/9] bpf: tracing: add support to record and check the accessed args To: Steven Rostedt Cc: =?UTF-8?B?5qKm6b6Z6JGj?= , Jiri Olsa , Andrii Nakryiko , Alexei Starovoitov , Daniel Borkmann , Martin KaFai Lau , 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 , 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 28, 2024 at 8:10=E2=80=AFAM Steven Rostedt wrote: > > On Thu, 28 Mar 2024 22:43:46 +0800 > =E6=A2=A6=E9=BE=99=E8=91=A3 wrote: > > > 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? > > Sounds like you are just recreating the function management that ftrace > has. It also can add thousands of trampolines very quickly, because it do= es > it in batches. It takes special synchronization steps to attach to fentry= . > ftrace (and I believe multi-kprobes) updates all the attachments for each > step, so the synchronization needed is only done once. > > If you really want to have thousands of functions, why not just register = it > with ftrace itself. It will give you the arguments via the ftrace_regs > structure. Can't you just register a program as the callback? > > It will probably make your accounting much easier, and just let ftrace > handle the fentry logic. That's what it was made to do. Absolutely agree. There is no point re-inventing this logic. Menlong, before you hook up into ftrace check whether it's going to be any different from kprobe-multi, since it's the same ftrace underneath. I suspect it will look exactly the same. So it sounds like multi-fentry idea will be shelved once again.