public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Menglong Dong <menglong8.dong@gmail.com>, Jiri Olsa <olsajiri@gmail.com>
Cc: 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 <imagedong@tencent.com>
Subject: Re: [PATCH] bpf, x86: allow function arguments up to 12 for TRACING
Date: Wed, 31 May 2023 15:02:29 +0300	[thread overview]
Message-ID: <34fb3a9841bf4977413be799f7cbef78560aaa20.camel@gmail.com> (raw)
In-Reply-To: <CADxym3biE8WcMxWf1wok+s4pBYEi6+fYQAbZJVxm7eBfzWLjLQ@mail.gmail.com>

On Wed, 2023-05-31 at 17:03 +0800, Menglong Dong wrote:
> On Wed, May 31, 2023 at 4:01 PM Jiri Olsa <olsajiri@gmail.com> wrote:
> > 
> > On Tue, May 30, 2023 at 12:44:23PM +0800, menglong8.dong@gmail.com wrote:
> > > From: Menglong Dong <imagedong@tencent.com>
> > > 
> > > 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 should
> > > 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'.
> > > 
> > > It works well for the FENTRY and FEXIT, I'm not sure if there are other
> > > complicated cases.
> > > 
> > > Signed-off-by: Menglong Dong <imagedong@tencent.com>
> > > ---
> > >  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 %%= 2;                                       \n\
^
<inline asm>:11:5: note: instantiated into assembly here
        w1 %= 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 well.
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.

> 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
> > 
> > 
> 


  reply	other threads:[~2023-05-31 12:02 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-30  4:44 [PATCH] bpf, x86: allow function arguments up to 12 for TRACING menglong8.dong
2023-05-31  8:01 ` Jiri Olsa
2023-05-31  9:03   ` Menglong Dong
2023-05-31 12:02     ` Eduard Zingerman [this message]
2023-05-31 13:10       ` Menglong Dong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=34fb3a9841bf4977413be799f7cbef78560aaa20.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bp@alien8.de \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=dave.hansen@linux.intel.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=haoluo@google.com \
    --cc=hpa@zytor.com \
    --cc=imagedong@tencent.com \
    --cc=john.fastabend@gmail.com \
    --cc=kpsingh@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.lau@linux.dev \
    --cc=menglong8.dong@gmail.com \
    --cc=mingo@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=olsajiri@gmail.com \
    --cc=sdf@google.com \
    --cc=song@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox