BPF List
 help / color / mirror / Atom feed
From: Jiri Olsa <olsajiri@gmail.com>
To: Yonghong Song <yhs@fb.com>
Cc: bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	kernel-team@fb.com
Subject: Re: [PATCH bpf-next v3 1/7] bpf: Allow struct argument in trampoline based programs
Date: Tue, 30 Aug 2022 14:11:09 +0200	[thread overview]
Message-ID: <Yw3+XcnFkT16Z3dx@krava> (raw)
In-Reply-To: <20220828025443.143456-1-yhs@fb.com>

On Sat, Aug 27, 2022 at 07:54:43PM -0700, Yonghong Song wrote:

SNIP

> diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
> index 903719b89238..4a081bfb4c8a 100644
> --- a/kernel/bpf/btf.c
> +++ b/kernel/bpf/btf.c
> @@ -5328,6 +5328,31 @@ static bool is_int_ptr(struct btf *btf, const struct btf_type *t)
>  	return btf_type_is_int(t);
>  }
>  
> +static u32 get_ctx_arg_idx(struct btf *btf, const struct btf_type *func_proto,
> +			   int off)
> +{
> +	const struct btf_param *args;
> +	const struct btf_type *t;
> +	u32 offset = 0, nr_args;
> +	int i;
> +
> +	nr_args = btf_type_vlen(func_proto);
> +	args = (const struct btf_param *)(func_proto + 1);
> +	for (i = 0; i < nr_args; i++) {
> +		t = btf_type_skip_modifiers(btf, args[i].type, NULL);
> +		offset += btf_type_is_ptr(t) ? 8 : roundup(t->size, 8);
> +		if (off < offset)
> +			return i;
> +	}
> +
> +	t = btf_type_skip_modifiers(btf, func_proto->type, NULL);
> +	offset += btf_type_is_ptr(t) ? 8 : roundup(t->size, 8);
> +	if (off < offset)
> +		return nr_args;
> +
> +	return nr_args + 1;
> +}
> +
>  bool btf_ctx_access(int off, int size, enum bpf_access_type type,
>  		    const struct bpf_prog *prog,
>  		    struct bpf_insn_access_aux *info)
> @@ -5347,7 +5372,7 @@ bool btf_ctx_access(int off, int size, enum bpf_access_type type,
>  			tname, off);
>  		return false;
>  	}
> -	arg = off / 8;
> +	arg = t == NULL ? (off / 8) :  get_ctx_arg_idx(btf, t, off);

is the t == NULL check needed? we relied on t being defined later in the code

jirka

>  	args = (const struct btf_param *)(t + 1);
>  	/* if (t == NULL) Fall back to default BPF prog with
>  	 * MAX_BPF_FUNC_REG_ARGS u64 arguments.
> @@ -5417,7 +5442,7 @@ bool btf_ctx_access(int off, int size, enum bpf_access_type type,
>  	/* skip modifiers */
>  	while (btf_type_is_modifier(t))
>  		t = btf_type_by_id(btf, t->type);
> -	if (btf_type_is_small_int(t) || btf_is_any_enum(t))
> +	if (btf_type_is_small_int(t) || btf_is_any_enum(t) || __btf_type_is_struct(t))
>  		/* accessing a scalar */
>  		return true;
>  	if (!btf_type_is_ptr(t)) {
> @@ -5881,7 +5906,7 @@ static int __get_type_size(struct btf *btf, u32 btf_id,
>  	if (btf_type_is_ptr(t))
>  		/* kernel size of pointer. Not BPF's size of pointer*/
>  		return sizeof(void *);
> -	if (btf_type_is_int(t) || btf_is_any_enum(t))
> +	if (btf_type_is_int(t) || btf_is_any_enum(t) || __btf_type_is_struct(t))
>  		return t->size;
>  	return -EINVAL;

SNIP

  reply	other threads:[~2022-08-30 12:11 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-28  2:54 [PATCH bpf-next v3 0/7] bpf: Support struct argument for trampoline base progs Yonghong Song
2022-08-28  2:54 ` [PATCH bpf-next v3 1/7] bpf: Allow struct argument in trampoline based programs Yonghong Song
2022-08-30 12:11   ` Jiri Olsa [this message]
2022-08-30 17:03     ` Yonghong Song
2022-08-28  2:54 ` [PATCH bpf-next v3 2/7] bpf: x86: Support in-register struct arguments in trampoline programs Yonghong Song
2022-08-28  2:54 ` [PATCH bpf-next v3 3/7] bpf: Update descriptions for helpers bpf_get_func_arg[_cnt]() Yonghong Song
2022-08-28  2:54 ` [PATCH bpf-next v3 4/7] bpf: arm64: No support of struct argument in trampoline programs Yonghong Song
2022-08-28  2:55 ` [PATCH bpf-next v3 5/7] libbpf: Add new BPF_PROG2 macro Yonghong Song
2022-08-30  0:32   ` Kui-Feng Lee
2022-08-30 16:50     ` Yonghong Song
2022-08-28  2:55 ` [PATCH bpf-next v3 6/7] selftests/bpf: Add struct argument tests with fentry/fexit programs Yonghong Song
2022-08-29 22:12   ` Daniel Borkmann
2022-08-30 12:11     ` Jiri Olsa
2022-08-30 17:20       ` Yonghong Song
2022-08-30 16:36     ` Yonghong Song
2022-08-28  2:55 ` [PATCH bpf-next v3 7/7] selftests/bpf: Use BPF_PROG2 for some fentry programs without struct arguments 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=Yw3+XcnFkT16Z3dx@krava \
    --to=olsajiri@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --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