From: Jesper Dangaard Brouer <brouer@redhat.com>
To: Andrii Nakryiko <andriin@fb.com>
Cc: brouer@redhat.com, <bpf@vger.kernel.org>,
<netdev@vger.kernel.org>, <ast@fb.com>, <daniel@iogearbox.net>,
<toke@redhat.com>, <kpsingh@chromium.org>,
<andrii.nakryiko@gmail.com>, <kernel-team@fb.com>
Subject: Re: [RFC][PATCH bpf-next] libbpf: add bpf_object__open_{file,mem} w/ sized opts
Date: Tue, 1 Oct 2019 18:48:13 +0200 [thread overview]
Message-ID: <20191001184813.23d004d2@carbon> (raw)
In-Reply-To: <20190930164239.3697916-1-andriin@fb.com>
On Mon, 30 Sep 2019 09:42:39 -0700
Andrii Nakryiko <andriin@fb.com> wrote:
> diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
> index 2e83a34f8c79..1cf2cf8d80f3 100644
> --- a/tools/lib/bpf/libbpf_internal.h
> +++ b/tools/lib/bpf/libbpf_internal.h
> @@ -47,6 +47,12 @@ do { \
> #define pr_info(fmt, ...) __pr(LIBBPF_INFO, fmt, ##__VA_ARGS__)
> #define pr_debug(fmt, ...) __pr(LIBBPF_DEBUG, fmt, ##__VA_ARGS__)
>
> +#define OPTS_VALID(opts) (!(opts) || (opts)->sz >= sizeof((opts)->sz))
Do be aware that C sizeof() will include the padding the compiler does.
Thus, when extending a struct (e.g. in a newer version) the size
(sizeof) might not actually increase (if compiler padding room exist).
> +#define OPTS_HAS(opts, field) \
> + ((opts) && opts->sz >= offsetofend(typeof(*(opts)), field))
> +#define OPTS_GET(opts, field, fallback_value) \
> + (OPTS_HAS(opts, field) ? (opts)->field : fallback_value)
I do think, that these two "accessor" defines address the padding issue
I described above.
p.s. I appreciate that you are working on this, and generally like the idea.
--
Best regards,
Jesper Dangaard Brouer
MSc.CS, Principal Kernel Engineer at Red Hat
LinkedIn: http://www.linkedin.com/in/brouer
next prev parent reply other threads:[~2019-10-01 16:48 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-30 16:42 [RFC][PATCH bpf-next] libbpf: add bpf_object__open_{file,mem} w/ sized opts Andrii Nakryiko
2019-10-01 8:42 ` Toke Høiland-Jørgensen
2019-10-01 18:56 ` Andrii Nakryiko
2019-10-01 21:49 ` Toke Høiland-Jørgensen
2019-10-01 23:43 ` Andrii Nakryiko
2019-10-02 6:55 ` Toke Høiland-Jørgensen
2019-10-02 16:55 ` Andrii Nakryiko
2019-10-01 16:48 ` Jesper Dangaard Brouer [this message]
2019-10-01 18:59 ` 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=20191001184813.23d004d2@carbon \
--to=brouer@redhat.com \
--cc=andrii.nakryiko@gmail.com \
--cc=andriin@fb.com \
--cc=ast@fb.com \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=kernel-team@fb.com \
--cc=kpsingh@chromium.org \
--cc=netdev@vger.kernel.org \
--cc=toke@redhat.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;
as well as URLs for NNTP newsgroup(s).