* [PATCH bpf] libbpf: do not use __builtin_offsetof for offsetof
@ 2020-08-11 3:08 Yonghong Song
2020-08-11 4:32 ` Andrii Nakryiko
2020-08-11 13:19 ` Daniel Borkmann
0 siblings, 2 replies; 4+ messages in thread
From: Yonghong Song @ 2020-08-11 3:08 UTC (permalink / raw)
To: bpf; +Cc: Alexei Starovoitov, Daniel Borkmann, kernel-team, Ian Rogers
Commit 5fbc220862fc ("tools/libpf: Add offsetof/container_of macro
in bpf_helpers.h") added a macro offsetof() to get the offset of a
structure member:
#define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER)
In certain use cases, size_t type may not be available so
Commit da7a35062bcc ("libbpf bpf_helpers: Use __builtin_offsetof
for offsetof") changed to use __builtin_offsetof which removed
the dependency on type size_t, which I suggested.
But using __builtin_offsetof will prevent CO-RE relocation
generation in case that, e.g., TYPE is annotated with "preserve_access_info"
where a relocation is desirable in case the member offset is changed
in a different kernel version. So this patch reverted back to
the original macro but using "unsigned long" instead of "site_t".
Cc: Ian Rogers <irogers@google.com>
Fixes: da7a35062bcc ("libbpf bpf_helpers: Use __builtin_offsetof for offsetof")
Signed-off-by: Yonghong Song <yhs@fb.com>
---
tools/lib/bpf/bpf_helpers.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/lib/bpf/bpf_helpers.h b/tools/lib/bpf/bpf_helpers.h
index bc14db706b88..e9a4ecddb7a5 100644
--- a/tools/lib/bpf/bpf_helpers.h
+++ b/tools/lib/bpf/bpf_helpers.h
@@ -40,7 +40,7 @@
* Helper macro to manipulate data structures
*/
#ifndef offsetof
-#define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER)
+#define offsetof(TYPE, MEMBER) ((unsigned long)&((TYPE *)0)->MEMBER)
#endif
#ifndef container_of
#define container_of(ptr, type, member) \
--
2.24.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH bpf] libbpf: do not use __builtin_offsetof for offsetof
2020-08-11 3:08 [PATCH bpf] libbpf: do not use __builtin_offsetof for offsetof Yonghong Song
@ 2020-08-11 4:32 ` Andrii Nakryiko
2020-08-11 4:34 ` Ian Rogers
2020-08-11 13:19 ` Daniel Borkmann
1 sibling, 1 reply; 4+ messages in thread
From: Andrii Nakryiko @ 2020-08-11 4:32 UTC (permalink / raw)
To: Yonghong Song
Cc: bpf, Alexei Starovoitov, Daniel Borkmann, Kernel Team, Ian Rogers
On Mon, Aug 10, 2020 at 8:09 PM Yonghong Song <yhs@fb.com> wrote:
>
> Commit 5fbc220862fc ("tools/libpf: Add offsetof/container_of macro
> in bpf_helpers.h") added a macro offsetof() to get the offset of a
> structure member:
> #define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER)
>
> In certain use cases, size_t type may not be available so
> Commit da7a35062bcc ("libbpf bpf_helpers: Use __builtin_offsetof
> for offsetof") changed to use __builtin_offsetof which removed
> the dependency on type size_t, which I suggested.
>
> But using __builtin_offsetof will prevent CO-RE relocation
> generation in case that, e.g., TYPE is annotated with "preserve_access_info"
> where a relocation is desirable in case the member offset is changed
> in a different kernel version. So this patch reverted back to
> the original macro but using "unsigned long" instead of "site_t".
>
> Cc: Ian Rogers <irogers@google.com>
> Fixes: da7a35062bcc ("libbpf bpf_helpers: Use __builtin_offsetof for offsetof")
> Signed-off-by: Yonghong Song <yhs@fb.com>
> ---
LGTM.
Acked-by: Andrii Nakryiko <andriin@fb.com>
> tools/lib/bpf/bpf_helpers.h | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/tools/lib/bpf/bpf_helpers.h b/tools/lib/bpf/bpf_helpers.h
> index bc14db706b88..e9a4ecddb7a5 100644
> --- a/tools/lib/bpf/bpf_helpers.h
> +++ b/tools/lib/bpf/bpf_helpers.h
> @@ -40,7 +40,7 @@
> * Helper macro to manipulate data structures
> */
> #ifndef offsetof
> -#define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER)
> +#define offsetof(TYPE, MEMBER) ((unsigned long)&((TYPE *)0)->MEMBER)
> #endif
> #ifndef container_of
> #define container_of(ptr, type, member) \
> --
> 2.24.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH bpf] libbpf: do not use __builtin_offsetof for offsetof
2020-08-11 4:32 ` Andrii Nakryiko
@ 2020-08-11 4:34 ` Ian Rogers
0 siblings, 0 replies; 4+ messages in thread
From: Ian Rogers @ 2020-08-11 4:34 UTC (permalink / raw)
To: Andrii Nakryiko
Cc: Yonghong Song, bpf, Alexei Starovoitov, Daniel Borkmann, Kernel Team
On Mon, Aug 10, 2020 at 9:33 PM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Mon, Aug 10, 2020 at 8:09 PM Yonghong Song <yhs@fb.com> wrote:
> >
> > Commit 5fbc220862fc ("tools/libpf: Add offsetof/container_of macro
> > in bpf_helpers.h") added a macro offsetof() to get the offset of a
> > structure member:
> > #define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER)
> >
> > In certain use cases, size_t type may not be available so
> > Commit da7a35062bcc ("libbpf bpf_helpers: Use __builtin_offsetof
> > for offsetof") changed to use __builtin_offsetof which removed
> > the dependency on type size_t, which I suggested.
> >
> > But using __builtin_offsetof will prevent CO-RE relocation
> > generation in case that, e.g., TYPE is annotated with "preserve_access_info"
> > where a relocation is desirable in case the member offset is changed
> > in a different kernel version. So this patch reverted back to
> > the original macro but using "unsigned long" instead of "site_t".
> >
> > Cc: Ian Rogers <irogers@google.com>
> > Fixes: da7a35062bcc ("libbpf bpf_helpers: Use __builtin_offsetof for offsetof")
> > Signed-off-by: Yonghong Song <yhs@fb.com>
> > ---
>
> LGTM.
>
> Acked-by: Andrii Nakryiko <andriin@fb.com>
Acked-by: Ian Rogers <irogers@google.com>
Thanks,
Ian
> > tools/lib/bpf/bpf_helpers.h | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/tools/lib/bpf/bpf_helpers.h b/tools/lib/bpf/bpf_helpers.h
> > index bc14db706b88..e9a4ecddb7a5 100644
> > --- a/tools/lib/bpf/bpf_helpers.h
> > +++ b/tools/lib/bpf/bpf_helpers.h
> > @@ -40,7 +40,7 @@
> > * Helper macro to manipulate data structures
> > */
> > #ifndef offsetof
> > -#define offsetof(TYPE, MEMBER) __builtin_offsetof(TYPE, MEMBER)
> > +#define offsetof(TYPE, MEMBER) ((unsigned long)&((TYPE *)0)->MEMBER)
> > #endif
> > #ifndef container_of
> > #define container_of(ptr, type, member) \
> > --
> > 2.24.1
> >
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH bpf] libbpf: do not use __builtin_offsetof for offsetof
2020-08-11 3:08 [PATCH bpf] libbpf: do not use __builtin_offsetof for offsetof Yonghong Song
2020-08-11 4:32 ` Andrii Nakryiko
@ 2020-08-11 13:19 ` Daniel Borkmann
1 sibling, 0 replies; 4+ messages in thread
From: Daniel Borkmann @ 2020-08-11 13:19 UTC (permalink / raw)
To: Yonghong Song, bpf; +Cc: Alexei Starovoitov, kernel-team, Ian Rogers
On 8/11/20 5:08 AM, Yonghong Song wrote:
> Commit 5fbc220862fc ("tools/libpf: Add offsetof/container_of macro
> in bpf_helpers.h") added a macro offsetof() to get the offset of a
> structure member:
> #define offsetof(TYPE, MEMBER) ((size_t)&((TYPE *)0)->MEMBER)
>
> In certain use cases, size_t type may not be available so
> Commit da7a35062bcc ("libbpf bpf_helpers: Use __builtin_offsetof
> for offsetof") changed to use __builtin_offsetof which removed
> the dependency on type size_t, which I suggested.
>
> But using __builtin_offsetof will prevent CO-RE relocation
> generation in case that, e.g., TYPE is annotated with "preserve_access_info"
> where a relocation is desirable in case the member offset is changed
> in a different kernel version. So this patch reverted back to
> the original macro but using "unsigned long" instead of "site_t".
>
> Cc: Ian Rogers <irogers@google.com>
> Fixes: da7a35062bcc ("libbpf bpf_helpers: Use __builtin_offsetof for offsetof")
> Signed-off-by: Yonghong Song <yhs@fb.com>
Applied, thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-08-11 13:19 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-11 3:08 [PATCH bpf] libbpf: do not use __builtin_offsetof for offsetof Yonghong Song
2020-08-11 4:32 ` Andrii Nakryiko
2020-08-11 4:34 ` Ian Rogers
2020-08-11 13:19 ` Daniel Borkmann
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.