From: Eduard Zingerman <eddyz87@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: bpf@vger.kernel.org, ast@kernel.org, andrii@kernel.org,
daniel@iogearbox.net, martin.lau@linux.dev, kernel-team@fb.com,
yonghong.song@linux.dev, yatsenko@meta.com
Subject: Re: [PATCH bpf-next v1] veristat: load struct_ops programs only once
Date: Thu, 16 Jan 2025 15:18:32 -0800 [thread overview]
Message-ID: <39fd5e3ffdf54483bafab59abb9183275f558177.camel@gmail.com> (raw)
In-Reply-To: <CAEf4BzYctSGEU3jELirr50W3Mxf0zBt6s2GpCSsdjDY6bva0Tw@mail.gmail.com>
On Thu, 2025-01-16 at 15:15 -0800, Andrii Nakryiko wrote:
[...]
> > +/* Make sure only target program is referenced from struct_ops map,
> > + * otherwise libbpf would automatically set autocreate for all
> > + * referenced programs.
> > + * See libbpf.c:bpf_object_adjust_struct_ops_autoload.
> > + */
> > +static void mask_unrelated_struct_ops_progs(struct bpf_object *obj,
> > + struct bpf_map *map,
> > + struct bpf_program *prog)
> > +{
> > + struct btf *btf = bpf_object__btf(obj);
> > + const struct btf_type *t, *mt;
> > + struct btf_member *m;
> > + int i, ptr_sz, moff;
> > + size_t data_sz;
> > + void *data;
> > +
> > + t = btf__type_by_id(btf, bpf_map__btf_value_type_id(map));
> > + if (!btf_is_struct(t))
> > + return;
> > +
> > + data = bpf_map__initial_value(map, &data_sz);
> > + ptr_sz = min(btf__pointer_size(btf), sizeof(void *));
>
> btf__pointer_size() for .bpf.o should always be 8, so this min is
> pointless, I think. I can simplify to just ptr_sz = sizeof(void *)
> while applying, if you agree. Let me know.
I wanted to be pedantic, but am ok if you prefer to switch it to
'ptr_sz = sizeof(void *)'. Can send v2, or if you change it when
applying, that would be great.
>
> Other than that looks good.
>
> > + for (i = 0; i < btf_vlen(t); i++) {
> > + m = &btf_members(t)[i];
> > + mt = btf__type_by_id(btf, m->type);
> > + if (!btf_is_ptr(mt))
> > + continue;
> > + moff = m->offset / 8;
> > + if (moff + ptr_sz > data_sz)
> > + continue;
> > + if (memcmp(data + moff, &prog, ptr_sz) == 0)
> > + continue;
> > + memset(data + moff, 0, ptr_sz);
> > + }
> > +}
> > +
[...]
next prev parent reply other threads:[~2025-01-16 23:18 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-15 22:38 [PATCH bpf-next v1] veristat: load struct_ops programs only once Eduard Zingerman
2025-01-16 23:15 ` Andrii Nakryiko
2025-01-16 23:18 ` Eduard Zingerman [this message]
2025-01-16 23:40 ` patchwork-bot+netdevbpf
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=39fd5e3ffdf54483bafab59abb9183275f558177.camel@gmail.com \
--to=eddyz87@gmail.com \
--cc=andrii.nakryiko@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=martin.lau@linux.dev \
--cc=yatsenko@meta.com \
--cc=yonghong.song@linux.dev \
/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