Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp107635rwd; Wed, 7 Jun 2023 20:27:00 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5+nvY51s3Wyzz7L/pDGWy14NZOgD1HydJ+a9k9knDlRrQ+krKMztiZDldhNr7qNqDplMxI X-Received: by 2002:a05:6a00:10c9:b0:656:5182:5e61 with SMTP id d9-20020a056a0010c900b0065651825e61mr1044785pfu.2.1686194820367; Wed, 07 Jun 2023 20:27:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686194820; cv=none; d=google.com; s=arc-20160816; b=rdcm3GHHBvCEgbtwVkWtdqQStwosr75AVY0GYIJs5sPcAMGN8X9rAoOGE3CCQgP9h3 ZB3PFwRVbs0le9vZ/I6kNtfDW44y905N7NAyRcB94wiyMAQ7x9J2QXebZ9mIjNyTpACR fEEMR5GALALfrtYVa22DZzPoCnC1L6F1/pO+x/KNO/BssJbHHwkMrG+G+pgM8l1U3lG/ Mht028+zHNJ8FztkgsjURQ79uyuvW8Qj5i3Q3pX1G2n8Urg+MQz7NjNuyZTAXiEPrf2u G4hXUNh2Ktegc1wLNz/2kU0hFAQ0zzpTPJw59PSijFazD4PFFFAibbbLyQOOi+WU90Kw mNUA== 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=V7fMdE8eaW7BeuJ297fgloLKjwJdfmPyym4SYRcLyPI=; b=sPia1XKbcSyBLrKxUpNb6qp0SbpVPuRztImq3WvKIF3eIRpYlAKLIGe/YWSAmWfitz JihI2IWUHu9KxCgWsCuyL/5/FeHBFd1WEfs5q9LuiO5tqKsuR7Z8Yf6avlrzcaRVR7yc BojC8LIJGpeA0y9Aag0JlyADC2Loml5Rz4jrXb12erKq+nFY1tWw9sjTPE9bSIRSxsEE FCcBbX86EZ7xfO51Ne0RRHs3z+RQB/VM087pDjRRIWo41a+666jvUMTrXrPA7gM7M5om 66P33gWtCpkvBxSYdZjLKV39djo/On+iT9KMuhuVcnX9OBc4fFW905cEDyWqotrokD9T WFJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=gIimOiJm; 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 x10-20020aa7956a000000b0065ff87a70cbsi146055pfq.112.2023.06.07.20.26.48; Wed, 07 Jun 2023 20:27:00 -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=gIimOiJm; 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 S233965AbjFHDSA (ORCPT + 99 others); Wed, 7 Jun 2023 23:18:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231753AbjFHDR6 (ORCPT ); Wed, 7 Jun 2023 23:17:58 -0400 Received: from mail-yw1-x1141.google.com (mail-yw1-x1141.google.com [IPv6:2607:f8b0:4864:20::1141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B9EFE43; Wed, 7 Jun 2023 20:17:57 -0700 (PDT) Received: by mail-yw1-x1141.google.com with SMTP id 00721157ae682-565de553de1so3138997b3.0; Wed, 07 Jun 2023 20:17:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686194276; x=1688786276; 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=V7fMdE8eaW7BeuJ297fgloLKjwJdfmPyym4SYRcLyPI=; b=gIimOiJmtBiXZ/AfGv9nbO9GUOUxWMjMHVDRQMd8A7YFdE8Dk/pmt/ao6FozOnablT F7uU/1ol0VP7EEzjNS80q8nrViUR6/VoRT3dkTGUStdVjAQ2k0/LMN0GQ5WpJ34pRtMC yxkmwGi8jPVDb/7pHSxyno9EDCyBpjjUagh9PxB88BS4TAJqScbUXBTYFaWXuR5SPSkl 8H/cphHwNeEZKS94o/sg/g85q93Ka0Cwa3L1XpWzgHoNfp2saysc8FWyvjnM/aZoMTqH dFKdJQTnYHgny1px4n1+UyNLk1CJbSkh0Q3WmHOu4M43M0sHrJ7XmUpay7orEF/9VXpM GTiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686194276; x=1688786276; 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=V7fMdE8eaW7BeuJ297fgloLKjwJdfmPyym4SYRcLyPI=; b=cZ55G5YIQsN7n4sVeB1nAfdsbiK2m6iNzA7lnCQhHRrdh5iR0zcHq7H5Xa4rFzBvdU OYnlvm1z162YoYjVKKhoM7kI4c5b/SkKSu4xzQzaw31mBpyB/dtdrEPpLXQ3OWY0zzEl ZMHaZETmX7dt7B3iX/tKaaHnkMHfFWss16PLdfvBku5gTgZWqFt6RnFxk3T8AhirZH0G E03GJKEHFMyEo5Vzlt/j0hh8cJSqrUwF1GmcJSsbrjRMe/kEiRkfOhi1awplYueZWDWI MaCoEHQFKENdeMWo64qxHT8oKsY2+Na4gD0Ok8JM0PrCseoDGMit+lVMQxN/6RgxJGpc WjYA== X-Gm-Message-State: AC+VfDxI/h13Lmrd6YMbBuvc+xMP9IGJl9sOh1qjauT1R16kiS6gbyC3 jkFs35EhEH3EgJ4AIHO6aH9c3J+x/aaZWEwrlYgIUxQuIzwAfJ66 X-Received: by 2002:a0d:e8d2:0:b0:561:9bcc:6c81 with SMTP id r201-20020a0de8d2000000b005619bcc6c81mr1218726ywe.24.1686194276278; Wed, 07 Jun 2023 20:17:56 -0700 (PDT) MIME-Version: 1.0 References: <20230607125911.145345-1-imagedong@tencent.com> <20230607125911.145345-2-imagedong@tencent.com> <20230607200905.5tbosnupodvydezq@macbook-pro-8.dhcp.thefacebook.com> In-Reply-To: <20230607200905.5tbosnupodvydezq@macbook-pro-8.dhcp.thefacebook.com> From: Menglong Dong Date: Thu, 8 Jun 2023 11:17:45 +0800 Message-ID: Subject: Re: [PATCH bpf-next v3 1/3] bpf, x86: allow function arguments up to 12 for TRACING To: Alexei Starovoitov Cc: 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 Thu, Jun 8, 2023 at 4:09=E2=80=AFAM Alexei Starovoitov wrote: > > On Wed, Jun 07, 2023 at 08:59:09PM +0800, 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= . > > > > 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)". > > > > 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'. > > x86-64 psABI requires stack to be 16-byte aligned when args are passed on= the stack. > I don't see this logic in the patch. Yeah, it seems I missed this logic......:) I have not figure out the rule of the alignment, but after observing the behavior of the compiler, the stack seems should be like this: ------ stack frame begin rbp xxx -- this part should be aligned in 16-byte ------ end of arguments in stack xxx ------ begin of arguments in stack So the code should be: + if (nr_regs > 6 && (flags & BPF_TRAMP_F_CALL_ORIG)) { + stack_size =3D ALIGN(stack_size, 16); + stack_size +=3D (nr_regs - 6) * 8; + } Am I right? Thanks! Menglong Dong