Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp872487rwd; Wed, 31 May 2023 06:38:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7ndzlIkrmPSpp0BxYI6qfmbSn6E4dcEg3X3HKGyiZJUtF6l1kj0W20o847Cwbi2fhd5Jzr X-Received: by 2002:a05:6a00:841:b0:643:6aed:3a9 with SMTP id q1-20020a056a00084100b006436aed03a9mr5882326pfk.0.1685540322011; Wed, 31 May 2023 06:38:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685540321; cv=none; d=google.com; s=arc-20160816; b=HodqjeTSh+cpdcofrU9AvGskZxyFRH0DhujFtbsyPyL6SLa4yp+PVGKhPyJmQVakpu 27q+yiK4shzLr0kTcsN6HAOCXl+/cQ2g2o5ackga0tTp2RvLFufby4Jjsg2rj7ZtkDUA DSnjleViAMpMKCxYLrqPtioZ0KyfcrHH88lLoDHdeJfnCVsNKcmaTi7+5iJLKSPo4Chw SEDD+oqTm8Nh5GQhiPvFtk1ZHI0MkInU6ZCvdEKw+yJr3IVYNVLvG9kXHu9JdelZ0O9H PILNGVnrqwhj0XHMEdUhxPwC29kcNq9tGD5dRGfCNyLPkXY3oM2ZBkmjCrKl6sW7iOem Qdaw== 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=YMHNxtLliZ2AvZ7BdWhgd9VB7EbsZ/iFVPRdfnAvAIs=; b=1IFiW7ivtqnrP4IicbVNPLwowlcWx9IjoGqUvRiHHUji0GiTQljpJH4yGgwEhrXRnf 8d06VN24JcyAbdF5QpENRA6hcb9Mfs0GXWNbq/HXk6mNMmigq7VJF6tSg6cD5CwAsHqJ WG7l2m2oUUVObAqI7yTmrh3ZNskLbFNPLaiz4zXz/469ULcogF8YjIeKOSRuNwbhFmvw Ln0AEv1goPcS2Q2fH121YKbNoa8W6hu5GKxD1ncEPWRHv25Qf1q9c22EqPciGgpDljH3 xfcgJ9SNssU4qVcHncPwZRLemJzqBq9mwvAO9NbXNc+Ef95eTinVj2x2xjxhXnT0Atkt TqHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=FErNm+Wv; 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 16-20020a621910000000b0064a15fc65d5si3464559pfz.83.2023.05.31.06.38.27; Wed, 31 May 2023 06:38:41 -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=FErNm+Wv; 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 S236334AbjEaNLH (ORCPT + 99 others); Wed, 31 May 2023 09:11:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235241AbjEaNLF (ORCPT ); Wed, 31 May 2023 09:11:05 -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 1EA92D9; Wed, 31 May 2023 06:11:04 -0700 (PDT) Received: by mail-yw1-x1142.google.com with SMTP id 00721157ae682-565aa2cc428so48690577b3.1; Wed, 31 May 2023 06:11:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685538663; x=1688130663; 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=YMHNxtLliZ2AvZ7BdWhgd9VB7EbsZ/iFVPRdfnAvAIs=; b=FErNm+WvV6cZHL75kBQyo2UBm9dre99Bc4zbXu1EsL86LWG/M1G9jhs49GXQorpayQ LEbTVwOGVskxVKJjr6KqoqEXkxC+gCWd2VpGLyIxS/t7VYWRW6Q/B0ElLGT2H+STbq8H 6YMUDb333LuJKwLV9PfjlomlcZ7bns6zPqXhjzXZT20v9ZzAqczpbOnPsk8VCsFuX+IO cQmrtCQW6c4TBX3ms+ZY/Cqv8IV21/q08GvuMot/9UJgleQaeupdYAj+Y5YbBvXwhG8d ZuGDTYC9JtpUe4g08lfSvENlyoDbvilNr602dLEtXm4wihlhJl+oCa4Zmt22LcLspH/c e7Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685538663; x=1688130663; 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=YMHNxtLliZ2AvZ7BdWhgd9VB7EbsZ/iFVPRdfnAvAIs=; b=IW443/tYyzKYrwYJGaUnOj5weyYbXo8BlGM+mII02Lk4h45cGQg2WBAObnUAWrguU0 5QcQ83H8nmaLolDQfksvjPYwTZUPvJmUfcdjs+ypA26U4NnZi8IwRicSu4tcoeTIxgBd ZJ7rkiXhbcYeEf2I8Zax1alaf29q8hExgHmdJfYin3sU1cyC3faZ0wQ6WjnuSij5iT9U 4yfTdyfYo0R9y/CDDP4olp2JrjxRZD86izUdi6LE4BTXsIfHqjfxOHNlVpuIF41DgIaK 7I/Z2v93Sn96gj3MEGbctvxvAG2MmSG9fZQ59fT6oYENEoIF/A1T6MLn7tQ5GEuFToN3 01Tw== X-Gm-Message-State: AC+VfDzN9fNjyCFJRjahUWF0kVHznSbK8MxpS/LoHSAyzVztQgaeEbeH Hk7Wemsx6XnKX6Gc2D+LUjmbktnzth+GlPtRaRY= X-Received: by 2002:a25:ca86:0:b0:bb1:38a:f0b with SMTP id a128-20020a25ca86000000b00bb1038a0f0bmr5282809ybg.65.1685538663191; Wed, 31 May 2023 06:11:03 -0700 (PDT) MIME-Version: 1.0 References: <20230530044423.3897681-1-imagedong@tencent.com> <34fb3a9841bf4977413be799f7cbef78560aaa20.camel@gmail.com> In-Reply-To: <34fb3a9841bf4977413be799f7cbef78560aaa20.camel@gmail.com> From: Menglong Dong Date: Wed, 31 May 2023 21:10:51 +0800 Message-ID: Subject: Re: [PATCH] bpf, x86: allow function arguments up to 12 for TRACING To: Eduard Zingerman Cc: Jiri Olsa , dsahern@kernel.org, andrii@kernel.org, davem@davemloft.net, ast@kernel.org, daniel@iogearbox.net, martin.lau@linux.dev, song@kernel.org, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, sdf@google.com, haoluo@google.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-kernel@vger.kernel.org, Menglong Dong 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 Wed, May 31, 2023 at 8:02=E2=80=AFPM Eduard Zingerman wrote: > > On Wed, 2023-05-31 at 17:03 +0800, Menglong Dong wrote: > > On Wed, May 31, 2023 at 4:01=E2=80=AFPM Jiri Olsa = wrote: > > > > > > On Tue, May 30, 2023 at 12:44:23PM +0800, menglong8.dong@gmail.com wr= ote: > > > > 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 th= an 6. > > > > > > > > Therefore, let's enhance it by increasing the function arguments co= unt > > > > allowed in arch_prepare_bpf_trampoline(), for now, only x86_64. > > > > > > > > For the case that we don't need to call origin function, which mean= s > > > > without BPF_TRAMP_F_CALL_ORIG, we need only copy the function argum= ents > > > > that stored in the frame of the caller to current frame. The argume= nts > > > > 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 argume= nts > > > > in stack before call origin function, which means we need alloc ext= ra > > > > "8 * (arg_count - 6)" memory in the top of the stack. Note, there s= hould > > > > not be any data be pushed to the stack before call the origin funct= ion. > > > > Then, we have to store rbx with 'mov' instead of 'push'. > > > > > > > > It works well for the FENTRY and FEXIT, I'm not sure if there are o= ther > > > > complicated cases. > > > > > > > > Signed-off-by: Menglong Dong > > > > --- > > > > arch/x86/net/bpf_jit_comp.c | 88 ++++++++++++++++++++++++++++++++-= ---- > > > > > > please add selftests for this.. I had to add one to be able to check > > > the generated trampoline > > > > > > > Okay! > > > > BTW, I failed to compile the latest selftests/bpf with > > the following errors: > > > > progs/verifier_and.c:58:16: error: invalid operand for instruction > > asm volatile (" \ > > > > These tests were moved to use inline assembly recently (2 month ago). > Discussion at the time was whether to use \n\ or \ terminators at the > end of each line. People opted for \ as easier to read. > Replacing \ with \n\ and compiling this test using clang 14 shows > more informative error message: > > $ make -j14 `pwd`/verifier_and.bpf.o > CLNG-BPF [test_maps] verifier_and.bpf.o > progs/verifier_and.c:68:1: error: invalid operand for instruction > w1 %%=3D 2; \n\ > ^ > :11:5: note: instantiated into assembly here > w1 %=3D 2; > > My guess is that clang 14 does not know how to handle operations on > 32-bit sub-registers w[0-9]. > > But using clang 14 I get some errors not related to inline assembly as we= ll. > Also, I recall that there were runtime issues with clang 14 and > tests using enum64. > > All-in-all, you need newer version of clang for tests nowadays, > sorry for inconvenience. Thanks for your explanation! It works well after I update my clang to a newer version. Menglong Dong > > > The version of clang I used is: > > > > clang --version > > Debian clang version 14.0.6 > > Target: x86_64-pc-linux-gnu > > Thread model: posix > > InstalledDir: /usr/bin > > > > Does anyone know the reason? > > > > Thanks! > > Menglong Dong > > > > > jirka > > > > > > > > >