Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1471315rwd; Thu, 8 Jun 2023 19:29:18 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7ZA013T70YBvNyK3XVeKz8it7W3/3WM45HtADotP9mC8+m6DDdFawfJ27hJ2S/Osj6mePj X-Received: by 2002:a05:6870:8447:b0:19a:ce25:6d06 with SMTP id n7-20020a056870844700b0019ace256d06mr214455oak.56.1686277758043; Thu, 08 Jun 2023 19:29:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686277758; cv=none; d=google.com; s=arc-20160816; b=J8nnW0mMgq415MjuvUXxFqnBVHAVhxiL+zUawCrnLLE6z/ZNSfzdRc4hcG7KbdkZ6B PIBfKG7RZgl5YG3r1vUCDn6AVimdOgIAxiqoO0daDwpM+YUUHtXXTzs6eRsY0oLgEuNz iZgRUe9WFdrHm1Qj8VEqxPfsaztUZ7qfAa+4+Ghak/EGGKOMNQDCSUGKqa6HeZZ4fGYw MCYE2WGVEe0C0Yqg8UgpjNFGuvJYB9e08OplKvM6SWuoBnyOjwdF8FzFFG4zVm3wBmoP q3lJdTGBgsN0vP3JhpxgTcdWquxKFX8QVgWBY+xDuFf6nPuLeadKR1FMKeXLmOLRcCH8 3jIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=8HQ09RtNhYQYMRgz/MTAZNRoEGBp5c2gpBzsaLR5f3I=; b=0+8WOBGh++1UI+P5Ha2Xm0vPu7IKlbbf+VvUyyyv8Bxo5QcTRTFiDmteeaHfOltMFp 2/7JNzU/l5XG1J13+jw+73gR40/JlvP8pf6u8c+2FISC/Ki07/Pr/ThD082Vd2Vo6GaX c/MRlHspTqCslMgG2saoScW5lZwWcdMBWwXDPuvf0vXP68P9dcgKOHRoF5ZJoZ8oxTsF 7fh/PREZXphBCoedfc3MlBnRDM7MJGCqFMtLtN+1FiC3/lIsXMBQBD9HD9XlKjCuM6uJ skUDdi+AwGGgibXQOfa4SjSRxZafumFfx0ORQvD9uXdXuwqGGdEoVXAIM8l6ZarmSoG4 NCbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=aY7rhVzI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x5-20020a170902ec8500b001ab19e023a1si2078388plg.375.2023.06.08.19.29.04; Thu, 08 Jun 2023 19:29:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=aY7rhVzI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237646AbjFICNJ (ORCPT + 99 others); Thu, 8 Jun 2023 22:13:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37550 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231985AbjFICNH (ORCPT ); Thu, 8 Jun 2023 22:13:07 -0400 Received: from mail-yw1-x1142.google.com (mail-yw1-x1142.google.com [IPv6:2607:f8b0:4864:20::1142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96EAEC2; Thu, 8 Jun 2023 19:13:06 -0700 (PDT) Received: by mail-yw1-x1142.google.com with SMTP id 00721157ae682-565ba6aee5fso11570407b3.1; Thu, 08 Jun 2023 19:13:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686276786; x=1688868786; 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=8HQ09RtNhYQYMRgz/MTAZNRoEGBp5c2gpBzsaLR5f3I=; b=aY7rhVzIqhc8rRrSvdWjL++Ruj8VXk+nq1eI9XtJEgMala846+hHzLolKOEa/9DquL mnWdrvO53Rza8Ax3i2fe3z9osN1rZ6fj9EqhArQmTiLRT7n4IVFJ/AG2ihrhQVNXWXFd FGjYrMpFUzpBmAif8t1Zid1TrNkA4yZbuzDhyEA0bAd1pe5TXiA2fYahxH8odd4RDNfU X6D+CphhpLlPOcCHwAf5O7yjpTOIaH1j29vQd8pHUXcOZ7D7/ftNwNmwI4SiaavWXWPp lrZGsxoomIaRpoC1/FN6zuhdw3OkUvLVE6sn3Gu5q/P57VN4u4v6vczSdn1AI8oUnw+0 916Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686276786; x=1688868786; 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=8HQ09RtNhYQYMRgz/MTAZNRoEGBp5c2gpBzsaLR5f3I=; b=TL0Ncx4XGEyuD4ANezFuZPLJnt0WXoZYmnYE7JcsVqc+RtZGBUZUDiWQile92wISzl bzLDkh81CtbiJbuq4osTbNJwQ+lvKl5cnlR8XyEAiJdYvtx16YVrjJok0SqX2KAnkAQ/ FRwmvYh5B2p6P0uKe3bqKAcBJdRPFmtcz0r30p+0z22B0RG1W00YAzJkyI0VWNTngQMM AQpB4s1zhMgR6/74nQc6+LsemYEc9LS/0+ExUdjw3k0V2tzK8C1UOispB+v+q08dsg2m jCdcjG/NCy1FE3THi3YqO8mxhzhgm30OQHsbY6VbVUH2+CREr6rezOIreX50kwcSM3MY YRdw== X-Gm-Message-State: AC+VfDzyPbGZ66bB9re7QVfDeIqNoD1OTeakuc8OOKdvt29uI6p+qtPa Jm0wBnDcy6m1S5tCzDZw0rWb0dTfTdVKnA1bLkc= X-Received: by 2002:a81:91d5:0:b0:565:9d27:c5e0 with SMTP id i204-20020a8191d5000000b005659d27c5e0mr55157ywg.2.1686276785727; Thu, 08 Jun 2023 19:13:05 -0700 (PDT) MIME-Version: 1.0 References: <20230607125911.145345-1-imagedong@tencent.com> <20230607125911.145345-2-imagedong@tencent.com> <4ca27e23-b027-0e39-495b-2ba3376342cc@meta.com> In-Reply-To: <4ca27e23-b027-0e39-495b-2ba3376342cc@meta.com> From: Menglong Dong Date: Fri, 9 Jun 2023 10:12:54 +0800 Message-ID: Subject: Re: [PATCH bpf-next v3 1/3] bpf, x86: allow function arguments up to 12 for TRACING To: Yonghong Song Cc: alexei.starovoitov@gmail.com, davem@davemloft.net, dsahern@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, x86@kernel.org, imagedong@tencent.com, benbjiang@tencent.com, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jun 9, 2023 at 5:07=E2=80=AFAM Yonghong Song wrote: > > > > On 6/7/23 5:59 AM, menglong8.dong@gmail.com wrote: > > From: Menglong Dong > > > > For now, the BPF program of type BPF_PROG_TYPE_TRACING can only be used > > on the kernel functions whose arguments count less than 6. This is not > > friendly at all, as too many functions have arguments count more than 6= . > > Since you already have some statistics, maybe listed in the commit messag= e. > > > > > Therefore, let's enhance it by increasing the function arguments count > > allowed in arch_prepare_bpf_trampoline(), for now, only x86_64. > > > > For the case that we don't need to call origin function, which means > > without BPF_TRAMP_F_CALL_ORIG, we need only copy the function arguments > > that stored in the frame of the caller to current frame. The arguments > > of arg6-argN are stored in "$rbp + 0x18", we need copy them to > > "$rbp - regs_off + (6 * 8)". > > Maybe I missed something, could you explain why it is '$rbp + 0x18'? > > In the current upstream code, we have > > /* Generated trampoline stack layout: > * > * RBP + 8 [ return address ] > * RBP + 0 [ RBP ] > * > * RBP - 8 [ return value ] BPF_TRAMP_F_CALL_ORIG or > * > BPF_TRAMP_F_RET_FENTRY_RET flags > * > * [ reg_argN ] always > * [ ... ] > * RBP - regs_off [ reg_arg1 ] program's ctx pointer > * > * RBP - nregs_off [ regs count ] always > * > * RBP - ip_off [ traced function ] BPF_TRAMP_F_IP_ARG flag > * > * RBP - run_ctx_off [ bpf_tramp_run_ctx ] > */ > > Next on-stack argument will be RBP + 16, right? > Sorry for the confusing, it seems there should be some comments here. It's not the next on-stack argument, but the next next on-stack argument. The call chain is: caller -> origin call -> trampoline So, we have to skip the "RIP" in the stack frame of "origin call", which means RBP + 16 + 8. To be clear, there are only 8-byte in the stack frame of "origin call". Thanks! Menglong Dong > > > > For the case with BPF_TRAMP_F_CALL_ORIG, we need prepare the arguments > > in stack before call origin function, which means we need alloc extra > > "8 * (arg_count - 6)" memory in the top of the stack. Note, there shoul= d > > not be any data be pushed to the stack before call the origin function. > > Then, we have to store rbx with 'mov' instead of 'push'. > > > > We use EMIT3_off32() or EMIT4() for "lea" and "sub". The range of the > > imm in "lea" and "sub" is [-128, 127] if EMIT4() is used. Therefore, > > we use EMIT3_off32() instead if the imm out of the range. > > > > It works well for the FENTRY and FEXIT, I'm not sure if there are other > > complicated cases. > > MODIFY_RETURN is also impacted by this patch. > > > > > Reviewed-by: Jiang Biao > > Signed-off-by: Menglong Dong > [...]