BPF List
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Mykyta Yatsenko <mykyta.yatsenko5@gmail.com>,
	bpf@vger.kernel.org,  ast@kernel.org, andrii@kernel.org,
	daniel@iogearbox.net, kafai@meta.com,  kernel-team@meta.com
Cc: Mykyta Yatsenko <yatsenko@meta.com>
Subject: Re: [PATCH bpf-next v2] selftests/bpf: support struct/union presets in veristat
Date: Thu, 27 Mar 2025 12:39:57 -0700	[thread overview]
Message-ID: <d61ff86c079461d8a4885638cead067290e148e3.camel@gmail.com> (raw)
In-Reply-To: <20250324123455.35888-1-mykyta.yatsenko5@gmail.com>

On Mon, 2025-03-24 at 12:34 +0000, Mykyta Yatsenko wrote:
> From: Mykyta Yatsenko <yatsenko@meta.com>
> 
> Extend commit e3c9abd0d14b ("selftests/bpf: Implement setting global
> variables in veristat") to support applying presets to members of
> the global structs or unions in veristat.
> For example:
> ```
> ./veristat set_global_vars.bpf.o  -G "union1.struct3.var_u8_h = 0xBB"
> ```
> 
> Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
> ---

Thank you for addressing comments from my previous review.
Sorry for the delay, didn't look at patches while travelling.

Acked-by: Eduard Zingerman <eddyz87@gmail.com>

[...]

> +static int adjust_var_secinfo_tok(char **name_tok, const struct btf *btf,
> +				  const struct btf_type *t, struct btf_var_secinfo *sinfo)
> +{
> +	char *name = strtok_r(NULL, ".", name_tok);
> +	const struct btf_type *member_type;
> +	const struct btf_member *member;
> +	int member_tid;
> +	__u32 anon_offset = 0;
> +
> +	if (!name)
> +		return 0;
> +
> +	member = btf_find_member(btf, t, name, &anon_offset);
> +	if (IS_ERR(member)) {
> +		fprintf(stderr, "Could not find member %s\n", name);
> +		return -EINVAL;
> +	}
> +
> +	member_tid = btf__resolve_type(btf, member->type);
> +	member_type = btf__type_by_id(btf, member_tid);
> +
> +	if (btf_kflag(t)) {
> +		fprintf(stderr, "Bitfield presets are not supported %s\n", name);
> +		return -EINVAL;
> +	}
> +	sinfo->offset += (member->offset + anon_offset) / 8;
> +	sinfo->size = member_type->size;
> +	sinfo->type = member_tid;

Nit: I'd push this assignment down to `btf_find_member` and avoid
     `&anon_offset` parameter. It would be easier to read this way,
     as all offset manipulations would be in one place.

> +
> +	return adjust_var_secinfo_tok(name_tok, btf, member_type, sinfo);
> +}
> +
> +static int adjust_var_secinfo(struct btf *btf, const struct btf_type *t,
> +			      struct btf_var_secinfo *sinfo, const char *var)
> +{
> +	char expr[256], *saveptr;
> +	const struct btf_type *base_type;
> +	int err;
> +
> +	base_type = btf__type_by_id(btf, btf__resolve_type(btf, t->type));
> +	strncpy(expr, var, 256);

Nit: strncpy does not null terminate if strlen(src) == N.

> +	strtok_r(expr, ".", &saveptr);
> +	err = adjust_var_secinfo_tok(&saveptr, btf, base_type, sinfo);
> +	if (err)
> +		return err;
> +
> +	return 0;
> +}
> +
> +static int set_global_var(struct bpf_object *obj, struct btf *btf,
>  			  struct bpf_map *map, struct btf_var_secinfo *sinfo,
>  			  struct var_preset *preset)
>  {

[...]


  reply	other threads:[~2025-03-27 19:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-24 12:34 [PATCH bpf-next v2] selftests/bpf: support struct/union presets in veristat Mykyta Yatsenko
2025-03-27 19:39 ` Eduard Zingerman [this message]
2025-03-28 17:03 ` Andrii Nakryiko
  -- strict thread matches above, loose matches on Subject: below --
2025-03-31 21:12 Mykyta Yatsenko
2025-04-04 18:39 ` Andrii Nakryiko
2025-04-07 16:35   ` Mykyta Yatsenko
2025-04-07 17:26     ` Andrii Nakryiko

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=d61ff86c079461d8a4885638cead067290e148e3.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=kafai@meta.com \
    --cc=kernel-team@meta.com \
    --cc=mykyta.yatsenko5@gmail.com \
    --cc=yatsenko@meta.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