Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp264044lqz; Fri, 29 Mar 2024 16:29:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVnqTgIdoLaG53beX1mvmV9dZUPdre/NuAaRFBxZszsacwLVRPIZYF7C7g4BN6SnD7eTTJB1hqXQAoAiMyuOpNs3GTJ5FSN8aETpG6DYg== X-Google-Smtp-Source: AGHT+IETPZLhssp9tFUL0H6wKYQsF0YtPc9N3VHZl/+A/MsaJ2tci6Ic0ghon2hJgJBdTM9nFmT0 X-Received: by 2002:a05:6a20:9c9a:b0:1a1:3d87:422d with SMTP id mj26-20020a056a209c9a00b001a13d87422dmr3736939pzb.45.1711754943806; Fri, 29 Mar 2024 16:29:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711754943; cv=pass; d=google.com; s=arc-20160816; b=dFfC5jwscxVbFWm592jGfGKi728HvAqq7o6121ffafgZiKnOo6GO9LTMZCew+D5Os+ 05cSGpkFslvqY851QhXhqYbex5mWr7MPmTFgTcYXCbeBJulQBsYTWUJnQCAmd7WTd132 IGGt4G5zzW0eJ3IDS/YRCSFjlq2UWmXajCLyBywge0yPEqdcY17DonddDTdN9l2Mpqfp qlrh3udprl12nWgEpi09qkynhXXmXTCcxZhYIc606Fb9HMi+Xn7pgSJMZ2jLWW5xkB1T KJIMokZz9gTtUXANPfQyZGOAOrfAlNn9Xm14nzf8a8DOEb5JmIs0qQyjQRDdtb1gnQCS E2XQ== 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=rvV1tZGanDBSafK6edOdycvbQYDEdHbTCxngJvsvk3c=; fh=HRlmLxiZPe6ufvrmicRohnB5e4z7ykxXwg7ZjXMf9bE=; b=rCZhkb9wlQB8m7BS8qGM4kHAiyvsLpk9zUZ44v8EgDx0EMumHb54MiK3gAeyoOGePs +PZJL7Zbn0ll8npDseaxhbnI6HnetpnRcLEtrxQO8KyxHEb1QA0Ke3k/MjRm7hl7zODd dx1p1MieSaQSFxDbuV5+CyqwSc0d0xtGSXz2LUKqCo/Xm2blF6FXUVIja/9UeHctciAW /D+ETSk1dYZJibDCQjLI4hTllo0vLW6VB0r0aX3RIKBMSoHUnE1SYRJ4zFGUbFv6QaoG XI5z18e+QRt/X869oBkMHEEwgpc4nwwGwHH4aMs6qaM0EafGnogPQhskQUBl27E2qtc5 Dexg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Fm8qb98v; 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-125526-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-125526-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id gu9-20020a056a004e4900b006eac6cce958si4465794pfb.97.2024.03.29.16.29.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 16:29:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-125526-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=Fm8qb98v; 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-125526-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-125526-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 84E1AB21B5A for ; Fri, 29 Mar 2024 23:29:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6E4E813E417; Fri, 29 Mar 2024 23:28:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Fm8qb98v" Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (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 EEAE5347B6; Fri, 29 Mar 2024 23:28:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711754928; cv=none; b=BiF0sOPYXhrbjY9cOS6Nmj4VXF++Yx8MtZjBDxanMefli+BulHO4QXKn7qwpW3i+7uN65u5cLGhThPJZ2akcLjIgY9UcOJfH9j6D484gs+N5O8HXdnQzg8eZ93GRBeBoDesuvP5WyVY1RlteRQZLbYRhS27z9mKgIzxIt2bJ+Zo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711754928; c=relaxed/simple; bh=M+CkTC/9QOPKjcAq26pJFK75aD0g4y2+LXJsB0P1JY0=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=lu4xUrtWjk3J0kbVbPD5XAlV9JEyhRuyqvveB8mIxkffhtOM1Y7m4+o5XzftYMKn592GD5CBw41tS2CCKYzMtaJurKzqjxkWsFCCe3ELmR9AEyVvEBDa4PpVwvE2aS0et1z2P9rOIk0ldc7OMYPnDpWEu3jfzLxb8Y4CGi6sJbE= 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=Fm8qb98v; arc=none smtp.client-ip=209.85.215.169 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-pg1-f169.google.com with SMTP id 41be03b00d2f7-5d3907ff128so1860607a12.3; Fri, 29 Mar 2024 16:28:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1711754926; x=1712359726; 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=rvV1tZGanDBSafK6edOdycvbQYDEdHbTCxngJvsvk3c=; b=Fm8qb98vO+2rZQDr4ACVbzWOOBhMbNP973of56VDx+7dzKarS23b4VDs0QCZjE/zey IJ/g2gwkTlDZp557gqFy6HVirUKvvI/RhzQOrPjsYmqnt0OS+LXZWxBGcD9ooJmS1u1N Wdq60dFcb/ee3JYL5bUFYzr07cJmwvvmIZoI/b1KQpo+K6ftMzexzXAN8iXh1nJo1QdC 4CFMaxfeoUIzc6fyg2ScGW/5rPdZFOXPIXIjGrA7V7Ij1KqAkHvKfDNzy1QS7jMz6z0E /W8l0QAzZuWpon/+MGFe6iPNG81xSsUfka4lIyvOK31ZY63E/sqixJRnh7RpDV18WsJY CtMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711754926; x=1712359726; 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=rvV1tZGanDBSafK6edOdycvbQYDEdHbTCxngJvsvk3c=; b=RU6CYGdij3I8SMDFuLcEkXFxxuMDLhpfo6RmyHf+rD3z+RBxrsmoJ1YligUcYT3VoL YtUHguMvFF7xT9YjyGrK4ujkEA13NT+X1hwUNhKsWaXhpLBG2Wyh4eNaw4zkHN28eYkq dj4reqkSxtXQvjpns3NtubA0ld6+woHqICxMQVR26maDt91aYEPooASIjOoCRnxMnIpI KqBMby8F8aarmJfc6c16rp9hDJK1Cr34usuvnIOrnJ2bdp2qTCOMpl6ARzTAtPA9p7n7 9p9R345kssoRHOmDzo2WcF/0oG4wRjb+owNVpsCTExoqfee0d+FSjcyFxitgRQvMQzcC 9Pqw== X-Forwarded-Encrypted: i=1; AJvYcCVlnHyNUDZ0fbOQSV0NEVvOtJTaOmaxwPgZy047hqztaIz7SMsnLeomStI1EizImJzlky/xJNYIS4RJsXEX2rbQoVyo7MFG2+RfwxWnjGonfBHU0k5JSlRGPFtF8Te8neu3qxCi25AWVXDje1k1qkzJLjDnQ+s4R4WJmDmbw/KdNN4l/EBnMx0Wq+GOvmC+DkjFlyebAZoKGfgwdw8BgI1xISF1T+wxXijKToVLbwSSua486L4tXm8nE4lXExEMG+QxE02AxDYDKshvWmyLqPiNewg+cXpbihxLyg== X-Gm-Message-State: AOJu0YwCezoL4rml44Ulwt5kaSYk47W3cr0evd5PMAYC8La4m9gnILHN FRelRR6zMz1Bz2qJo3eFKeNyq28N5Yo0kJIQ72rv0EkZFGKfSnjbac0fnT9zQAwbNl/tFnTmfuG Y3REKAMgIbWmVvmHWWGOk0v3R69U= X-Received: by 2002:a17:90a:be04:b0:2a2:1415:723d with SMTP id a4-20020a17090abe0400b002a21415723dmr3177860pjs.42.1711754926271; Fri, 29 Mar 2024 16:28:46 -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: Andrii Nakryiko Date: Fri, 29 Mar 2024 16:28:33 -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?= , Alexei Starovoitov , Jiri Olsa , 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 , 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. > I thought I'll just ask instead of digging through code, sorry for being lazy :) Is there any way to pass pt_regs/ftrace_regs captured before function execution to a return probe (fexit/kretprobe)? I.e., how hard is it to pass input function arguments to a kretprobe? That's the biggest advantage of fexit over kretprobe, and if we can make these original pt_regs/ftrace_regs available to kretprobe, then multi-kretprobe will effectively be this multi-fexit. > -- Steve