Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp506141lqh; Thu, 28 Mar 2024 08:11:09 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCURMfS8XuIv3QjSiXNlpCJXkuK0ZwNu8CEFEyrVnz9mPdQSMFj+dV0Fv3M5RZgYl/5DKAxYU/hKYOrx18So3cXNtKRqQeXD03ZYJYVFOA== X-Google-Smtp-Source: AGHT+IF3uXYuIXOah/IjsUHOCLhtfCMh8qiN99yCRLziCnXN7zDdhSMIzYMAKGJmupOXRXcECzhs X-Received: by 2002:a17:902:d487:b0:1e0:b697:d3ae with SMTP id c7-20020a170902d48700b001e0b697d3aemr4457653plg.19.1711638669044; Thu, 28 Mar 2024 08:11:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711638669; cv=pass; d=google.com; s=arc-20160816; b=gXoFXmiIy3VF+986R2UG03bgvj9Z/7f+SqXKmM4OYzTRDk6mjGWfSYVicDkkMg5zQS iDHZQANZ79yAhTK4xTki5c6mxC1eKT/hWwDkhekRF1xdMYOEBZ0vmeSpO5LbD7GjsDGQ wo15wh+SYxo0dS0mOaJ5mbilw8qmzO7e/BhR+fa/LOJ3skt6o5lmrY2UE73qIXnmmxcW AWAmJo7NnYjzWD2PR+xA4t33mkeIz2PKvSNhYC9z5VyOKXwf6i2MAWYMV2kCNPXNcel0 /z+1CNQ7c2nSfiJetPBrlTs+SL1O2ESausJSk9+M1Azf8fyhEMdxh8BELkHvsBpqjloe WqPA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :subject:cc:to:from:date; bh=rpmOpVcxyaLlEASlfwkqxzFyMnAKk38q5QHSSA+dwfc=; fh=vud8XuGoTzKZUbXmvvIOnRH0inmpUotHSHOikfyCb88=; b=d03Ir2cZ09QA5DAfOu4Zt1V6pTsda4y6LO+kG5JrF4eOxpm7tRz2VRW8FLmcJNUjZ7 Og5kQZzHQmDrhfbePc+MkeyvS80wlrINyOlYR9Uj9LhMeBaIp6rcoho3UBXoZFpY08Z4 aNrEHA3jq+cAvFNfWTqrmrRW55I6QZolmRYOOWPq8Zcsh9OuVyHtyZz9RJLJKwifPPBN aFGUdlENIg2dBDXZSQIgmXSFO4q0Xgvf3iba82IFrvk3bg9rlxK3rI8n2HdLcPfbHuSB OmRUpBUTaJFRAdOOaYQFtzb3R01Eyz7ZScHK5XdzSIQhFoI4Gkd0zw8pPVfAfw4iXo/z 4XsA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-123136-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123136-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id m11-20020a170902768b00b001e20578b541si1528167pll.346.2024.03.28.08.11.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 08:11:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-123136-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; arc=pass (i=1); spf=pass (google.com: domain of linux-kernel+bounces-123136-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-123136-linux.lists.archive=gmail.com@vger.kernel.org" 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 9EFD5B22627 for ; Thu, 28 Mar 2024 15:11:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EAE9512EBF3; Thu, 28 Mar 2024 15:10:51 +0000 (UTC) Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 54B2A2C6AD; Thu, 28 Mar 2024 15:10:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711638651; cv=none; b=RTF9NSHXD+5MhH16WmzEsgBTAMHv5ymC3bHdaNYbwEbeBwYZmuhtjESbIG32YEAU/3A9o9B9sRqpH813TbJ1VJlV9ScMQoC5me7S318cwAXy0IDCcrc/rueWivK4dn2euhCnfWdvrVO79K6rnoW+CmrqWHIywX9Mu3knaQYMK1A= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711638651; c=relaxed/simple; bh=r2D0EqkpCrFqFode/ZlZv88Dg4Xknt6j7iyrIgxbYTU=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ZrLs/p/darscR+NvP4+RVCZY73NhOQzeshRJ3qXd6r1FWuvJGfJv0F4JqW6gZYetnh3TH61LJ9Zc1Ch7Kb0z0CYuRI+BHxvs9E5PKPZqVeFXneU3UMXcNHyTC7QUddAc6/+WXNB0fbW87TAnaNWrSnH93X9jJXa8kxH/O/lhXDU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95D2BC433C7; Thu, 28 Mar 2024 15:10:47 +0000 (UTC) Date: Thu, 28 Mar 2024 11:13:30 -0400 From: Steven Rostedt To: =?UTF-8?B?5qKm6b6Z6JGj?= Cc: 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 Subject: Re: [External] Re: [PATCH bpf-next v2 1/9] bpf: tracing: add support to record and check the accessed args Message-ID: <20240328111330.194dcbe5@gandalf.local.home> In-Reply-To: References: <20240311093526.1010158-1-dongmenglong.8@bytedance.com> <20240311093526.1010158-2-dongmenglong.8@bytedance.com> X-Mailer: Claws Mail 3.19.1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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. >=20 > Now, I have a bad idea. How about we introduce > a "dynamic trampoline"? The basic logic of it can be: >=20 > """ > save regs > bpfs =3D trampoline_lookup_ip(ip) > fentry =3D bpfs->fentries > while fentry: > fentry(ctx) > fentry =3D fentry->next >=20 > call origin > save return value >=20 > fexit =3D bpfs->fexits > while fexit: > fexit(ctx) > fexit =3D fexit->next >=20 > xxxxxx > """ >=20 > And we lookup the "bpfs" by the function ip in a hash map > in trampoline_lookup_ip. The type of "bpfs" is: >=20 > struct bpf_array { > struct bpf_prog *fentries; > struct bpf_prog *fexits; > struct bpf_prog *modify_returns; > } >=20 > 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. >=20 > Compared to the trampoline, extra overhead is introduced > by the hash lookuping. >=20 > 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 does 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. -- Steve