BPF List
 help / color / mirror / Atom feed
From: Kui-Feng Lee <kuifeng@fb.com>
To: Yonghong Song <yhs@fb.com>, "bpf@vger.kernel.org" <bpf@vger.kernel.org>
Cc: "daniel@iogearbox.net" <daniel@iogearbox.net>,
	Kernel Team <Kernel-team@fb.com>,
	"ast@kernel.org" <ast@kernel.org>,
	"andrii@kernel.org" <andrii@kernel.org>
Subject: Re: [RFC PATCH bpf-next 0/7] bpf: Support struct value argument for trampoline base progs
Date: Thu, 28 Jul 2022 19:57:50 +0000	[thread overview]
Message-ID: <17dbbb831db12049ebfb5161e380c9078fbddad5.camel@fb.com> (raw)
In-Reply-To: <18273e85-4e45-c395-0aa9-a10125d59e50@fb.com>

On Thu, 2022-07-28 at 10:46 -0700, Yonghong Song wrote:
> 
> 
> On 7/28/22 8:46 AM, Kui-Feng Lee wrote:
> > On Tue, 2022-07-26 at 10:11 -0700, Yonghong Song wrote:
> > > Currently struct arguments are not supported for trampoline based
> > > progs.
> > > One of major reason is that struct argument may pass by value
> > > which
> > > may
> > > use more than one registers. This breaks trampoline progs where
> > > each argument is assumed to take one register. bcc community
> > > reported
> > > the
> > > issue ([1]) where struct argument is not supported for fentry
> > > program.
> > >    typedef struct {
> > >          uid_t val;
> > >    } kuid_t;
> > >    typedef struct {
> > >          gid_t val;
> > >    } kgid_t;
> > >    int security_path_chown(struct path *path, kuid_t uid, kgid_t
> > > gid);
> > > Inside Meta, we also have a use case to attach to
> > > tcp_setsockopt()
> > >    typedef struct {
> > >          union {
> > >                  void            *kernel;
> > >                  void __user     *user;
> > >          };
> > >          bool            is_kernel : 1;
> > >    } sockptr_t;
> > >    int tcp_setsockopt(struct sock *sk, int level, int optname,
> > >                       sockptr_t optval, unsigned int optlen);
> > > 
> > > This patch added struct value support for bpf tracing programs
> > > which
> > > uses trampoline. struct argument size needs to be 16 or less so
> > > it can fit in one or two registers. Based on analysis on llvm and
> > > experiments, atruct argument size greater than 16 will be passed
> > > as pointer to the struct.
> > 
> > Is it possible to force llvm to always pass a pointer to a struct
> > over
> > 8 bytes (the size of single register) for the BPF traget?
> 
> This is already the case for bpf target. Any struct parameter (1
> byte, 2 
> bytes, ..., 8 types, ..., 16 bytes, ...) will be passed as a
> reference.
> 
> But this is not the case for most other architectures. For example,
> for
> x86_64, in most cases, struct size <= 16 will be passed with two
> registers instead of as a reference.

I ask this question because you modify the signature of a bpf program
to a pointer to a struct in patch #4.  Is that necessary if the
compiler passes a struct paramter as a reference?



  reply	other threads:[~2022-07-28 19:58 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-26 17:11 [RFC PATCH bpf-next 0/7] bpf: Support struct value argument for trampoline base progs Yonghong Song
2022-07-26 17:11 ` [RFC PATCH bpf-next 1/7] bpf: Always return corresponding btf_type in __get_type_size() Yonghong Song
2022-07-26 17:11 ` [RFC PATCH bpf-next 2/7] bpf: Add struct argument info in btf_func_model Yonghong Song
2022-08-09  0:02   ` Andrii Nakryiko
2022-08-09 17:38     ` Yonghong Song
2022-08-10  0:25       ` Andrii Nakryiko
2022-08-11  6:24         ` Yonghong Song
2022-07-26 17:11 ` [RFC PATCH bpf-next 3/7] bpf: x86: Rename stack_size to regs_off in {save,restore}_regs() Yonghong Song
2022-07-26 17:11 ` [RFC PATCH bpf-next 4/7] bpf: x86: Support in-register struct arguments Yonghong Song
2022-07-29 11:10   ` Jiri Olsa
2022-07-31 17:00     ` Yonghong Song
2022-07-26 17:11 ` [RFC PATCH bpf-next 5/7] bpf: arm64: No support of struct value argument Yonghong Song
2022-07-26 17:12 ` [RFC PATCH bpf-next 6/7] bpf: Populate struct value info in btf_func_model Yonghong Song
2022-07-26 17:12 ` [RFC PATCH bpf-next 7/7] selftests/bpf: Add struct value tests with fentry programs Yonghong Song
2022-07-28 15:46 ` [RFC PATCH bpf-next 0/7] bpf: Support struct value argument for trampoline base progs Kui-Feng Lee
2022-07-28 17:46   ` Yonghong Song
2022-07-28 19:57     ` Kui-Feng Lee [this message]
2022-07-28 23:30       ` Yonghong Song
2022-07-29 18:04         ` Kui-Feng Lee
2022-08-02 23:46           ` Yonghong Song

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=17dbbb831db12049ebfb5161e380c9078fbddad5.camel@fb.com \
    --to=kuifeng@fb.com \
    --cc=Kernel-team@fb.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --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