* [PATCH bpf-next 0/2] libbpf/xsk cleanups
@ 2021-03-10 8:09 Björn Töpel
2021-03-10 8:09 ` [PATCH bpf-next 1/2] libbpf: xsk: remove linux/compiler.h header Björn Töpel
2021-03-10 8:09 ` [PATCH bpf-next 2/2] libbpf: xsk: move barriers from libbpf_util.h to xsk.h Björn Töpel
0 siblings, 2 replies; 7+ messages in thread
From: Björn Töpel @ 2021-03-10 8:09 UTC (permalink / raw)
To: ast, daniel, netdev, bpf, andrii
Cc: Björn Töpel, bjorn.topel, magnus.karlsson,
jonathan.lemon, maximmi, ciara.loftus
This series removes a header dependency from xsk.h, and moves
libbpf_util.h into xsk.h.
More details in each commit!
Thank you,
Björn
Björn Töpel (2):
libbpf: xsk: remove linux/compiler.h header
libbpf: xsk: move barriers from libbpf_util.h to xsk.h
tools/lib/bpf/Makefile | 1 -
tools/lib/bpf/libbpf_util.h | 75 -------------------------------------
tools/lib/bpf/xsk.h | 68 ++++++++++++++++++++++++++++++++-
3 files changed, 67 insertions(+), 77 deletions(-)
delete mode 100644 tools/lib/bpf/libbpf_util.h
base-commit: 32f91529e2bdbe0d92edb3ced41dfba4beffa84a
--
2.27.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH bpf-next 1/2] libbpf: xsk: remove linux/compiler.h header
2021-03-10 8:09 [PATCH bpf-next 0/2] libbpf/xsk cleanups Björn Töpel
@ 2021-03-10 8:09 ` Björn Töpel
2021-03-10 8:09 ` [PATCH bpf-next 2/2] libbpf: xsk: move barriers from libbpf_util.h to xsk.h Björn Töpel
1 sibling, 0 replies; 7+ messages in thread
From: Björn Töpel @ 2021-03-10 8:09 UTC (permalink / raw)
To: ast, daniel, netdev, bpf, andrii
Cc: Björn Töpel, magnus.karlsson, jonathan.lemon, maximmi,
ciara.loftus
From: Björn Töpel <bjorn.topel@intel.com>
In commit 291471dd1559 ("libbpf, xsk: Add libbpf_smp_store_release
libbpf_smp_load_acquire") linux/compiler.h was added as a dependency
to xsk.h, which is the user-facing API. This makes it harder for
userspace application to consume the library. Here the header
inclusion is removed, and instead {READ,WRITE}_ONCE() is added
explicitly.
Signed-off-by: Björn Töpel <bjorn.topel@intel.com>
---
tools/lib/bpf/libbpf_util.h | 27 +++++++++++++++++----------
1 file changed, 17 insertions(+), 10 deletions(-)
diff --git a/tools/lib/bpf/libbpf_util.h b/tools/lib/bpf/libbpf_util.h
index cfbcfc063c81..954da9b34a34 100644
--- a/tools/lib/bpf/libbpf_util.h
+++ b/tools/lib/bpf/libbpf_util.h
@@ -5,25 +5,30 @@
#define __LIBBPF_LIBBPF_UTIL_H
#include <stdbool.h>
-#include <linux/compiler.h>
#ifdef __cplusplus
extern "C" {
#endif
-/* Use these barrier functions instead of smp_[rw]mb() when they are
- * used in a libbpf header file. That way they can be built into the
- * application that uses libbpf.
+/* Load-Acquire Store-Release barriers used by the XDP socket
+ * library. The following macros should *NOT* be considered part of
+ * the xsk.h API, and is subject to change anytime.
+ *
+ * LIBRARY INTERNAL
*/
+
+#define __XSK_READ_ONCE(x) (*(volatile typeof(x) *)&x)
+#define __XSK_WRITE_ONCE(x, v) (*(volatile typeof(x) *)&x) = (v)
+
#if defined(__i386__) || defined(__x86_64__)
# define libbpf_smp_store_release(p, v) \
do { \
asm volatile("" : : : "memory"); \
- WRITE_ONCE(*p, v); \
+ __XSK_WRITE_ONCE(*p, v); \
} while (0)
# define libbpf_smp_load_acquire(p) \
({ \
- typeof(*p) ___p1 = READ_ONCE(*p); \
+ typeof(*p) ___p1 = __XSK_READ_ONCE(*p); \
asm volatile("" : : : "memory"); \
___p1; \
})
@@ -41,11 +46,11 @@ extern "C" {
# define libbpf_smp_store_release(p, v) \
do { \
asm volatile ("fence rw,w" : : : "memory"); \
- WRITE_ONCE(*p, v); \
+ __XSK_WRITE_ONCE(*p, v); \
} while (0)
# define libbpf_smp_load_acquire(p) \
({ \
- typeof(*p) ___p1 = READ_ONCE(*p); \
+ typeof(*p) ___p1 = __XSK_READ_ONCE(*p); \
asm volatile ("fence r,rw" : : : "memory"); \
___p1; \
})
@@ -55,19 +60,21 @@ extern "C" {
#define libbpf_smp_store_release(p, v) \
do { \
__sync_synchronize(); \
- WRITE_ONCE(*p, v); \
+ __XSK_WRITE_ONCE(*p, v); \
} while (0)
#endif
#ifndef libbpf_smp_load_acquire
#define libbpf_smp_load_acquire(p) \
({ \
- typeof(*p) ___p1 = READ_ONCE(*p); \
+ typeof(*p) ___p1 = __XSK_READ_ONCE(*p); \
__sync_synchronize(); \
___p1; \
})
#endif
+/* LIBRARY INTERNAL -- END */
+
#ifdef __cplusplus
} /* extern "C" */
#endif
--
2.27.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH bpf-next 2/2] libbpf: xsk: move barriers from libbpf_util.h to xsk.h
2021-03-10 8:09 [PATCH bpf-next 0/2] libbpf/xsk cleanups Björn Töpel
2021-03-10 8:09 ` [PATCH bpf-next 1/2] libbpf: xsk: remove linux/compiler.h header Björn Töpel
@ 2021-03-10 8:09 ` Björn Töpel
2021-03-10 22:00 ` Andrii Nakryiko
2021-03-11 0:06 ` Jonathan Lemon
1 sibling, 2 replies; 7+ messages in thread
From: Björn Töpel @ 2021-03-10 8:09 UTC (permalink / raw)
To: ast, daniel, netdev, bpf, andrii
Cc: Björn Töpel, magnus.karlsson, jonathan.lemon, maximmi,
ciara.loftus
From: Björn Töpel <bjorn.topel@intel.com>
The only user of libbpf_util.h is xsk.h. Move the barriers to xsk.h,
and remove libbpf_util.h. The barriers are used as an implementation
detail, and should not be considered part of the stable API.
Signed-off-by: Björn Töpel <bjorn.topel@intel.com>
---
tools/lib/bpf/Makefile | 1 -
tools/lib/bpf/libbpf_util.h | 82 -------------------------------------
tools/lib/bpf/xsk.h | 68 +++++++++++++++++++++++++++++-
3 files changed, 67 insertions(+), 84 deletions(-)
delete mode 100644 tools/lib/bpf/libbpf_util.h
diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
index 8170f88e8ea6..f45bacbaa3d5 100644
--- a/tools/lib/bpf/Makefile
+++ b/tools/lib/bpf/Makefile
@@ -228,7 +228,6 @@ install_headers: $(BPF_HELPER_DEFS)
$(call do_install,bpf.h,$(prefix)/include/bpf,644); \
$(call do_install,libbpf.h,$(prefix)/include/bpf,644); \
$(call do_install,btf.h,$(prefix)/include/bpf,644); \
- $(call do_install,libbpf_util.h,$(prefix)/include/bpf,644); \
$(call do_install,libbpf_common.h,$(prefix)/include/bpf,644); \
$(call do_install,xsk.h,$(prefix)/include/bpf,644); \
$(call do_install,bpf_helpers.h,$(prefix)/include/bpf,644); \
diff --git a/tools/lib/bpf/libbpf_util.h b/tools/lib/bpf/libbpf_util.h
deleted file mode 100644
index 954da9b34a34..000000000000
--- a/tools/lib/bpf/libbpf_util.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/* SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause) */
-/* Copyright (c) 2019 Facebook */
-
-#ifndef __LIBBPF_LIBBPF_UTIL_H
-#define __LIBBPF_LIBBPF_UTIL_H
-
-#include <stdbool.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Load-Acquire Store-Release barriers used by the XDP socket
- * library. The following macros should *NOT* be considered part of
- * the xsk.h API, and is subject to change anytime.
- *
- * LIBRARY INTERNAL
- */
-
-#define __XSK_READ_ONCE(x) (*(volatile typeof(x) *)&x)
-#define __XSK_WRITE_ONCE(x, v) (*(volatile typeof(x) *)&x) = (v)
-
-#if defined(__i386__) || defined(__x86_64__)
-# define libbpf_smp_store_release(p, v) \
- do { \
- asm volatile("" : : : "memory"); \
- __XSK_WRITE_ONCE(*p, v); \
- } while (0)
-# define libbpf_smp_load_acquire(p) \
- ({ \
- typeof(*p) ___p1 = __XSK_READ_ONCE(*p); \
- asm volatile("" : : : "memory"); \
- ___p1; \
- })
-#elif defined(__aarch64__)
-# define libbpf_smp_store_release(p, v) \
- asm volatile ("stlr %w1, %0" : "=Q" (*p) : "r" (v) : "memory")
-# define libbpf_smp_load_acquire(p) \
- ({ \
- typeof(*p) ___p1; \
- asm volatile ("ldar %w0, %1" \
- : "=r" (___p1) : "Q" (*p) : "memory"); \
- ___p1; \
- })
-#elif defined(__riscv)
-# define libbpf_smp_store_release(p, v) \
- do { \
- asm volatile ("fence rw,w" : : : "memory"); \
- __XSK_WRITE_ONCE(*p, v); \
- } while (0)
-# define libbpf_smp_load_acquire(p) \
- ({ \
- typeof(*p) ___p1 = __XSK_READ_ONCE(*p); \
- asm volatile ("fence r,rw" : : : "memory"); \
- ___p1; \
- })
-#endif
-
-#ifndef libbpf_smp_store_release
-#define libbpf_smp_store_release(p, v) \
- do { \
- __sync_synchronize(); \
- __XSK_WRITE_ONCE(*p, v); \
- } while (0)
-#endif
-
-#ifndef libbpf_smp_load_acquire
-#define libbpf_smp_load_acquire(p) \
- ({ \
- typeof(*p) ___p1 = __XSK_READ_ONCE(*p); \
- __sync_synchronize(); \
- ___p1; \
- })
-#endif
-
-/* LIBRARY INTERNAL -- END */
-
-#ifdef __cplusplus
-} /* extern "C" */
-#endif
-
-#endif
diff --git a/tools/lib/bpf/xsk.h b/tools/lib/bpf/xsk.h
index a9fdea87b5cd..1d846a419d21 100644
--- a/tools/lib/bpf/xsk.h
+++ b/tools/lib/bpf/xsk.h
@@ -4,6 +4,7 @@
* AF_XDP user-space access library.
*
* Copyright(c) 2018 - 2019 Intel Corporation.
+ * Copyright (c) 2019 Facebook
*
* Author(s): Magnus Karlsson <magnus.karlsson@intel.com>
*/
@@ -13,15 +14,80 @@
#include <stdio.h>
#include <stdint.h>
+#include <stdbool.h>
#include <linux/if_xdp.h>
#include "libbpf.h"
-#include "libbpf_util.h"
#ifdef __cplusplus
extern "C" {
#endif
+/* Load-Acquire Store-Release barriers used by the XDP socket
+ * library. The following macros should *NOT* be considered part of
+ * the xsk.h API, and is subject to change anytime.
+ *
+ * LIBRARY INTERNAL
+ */
+
+#define __XSK_READ_ONCE(x) (*(volatile typeof(x) *)&x)
+#define __XSK_WRITE_ONCE(x, v) (*(volatile typeof(x) *)&x) = (v)
+
+#if defined(__i386__) || defined(__x86_64__)
+# define libbpf_smp_store_release(p, v) \
+ do { \
+ asm volatile("" : : : "memory"); \
+ __XSK_WRITE_ONCE(*p, v); \
+ } while (0)
+# define libbpf_smp_load_acquire(p) \
+ ({ \
+ typeof(*p) ___p1 = __XSK_READ_ONCE(*p); \
+ asm volatile("" : : : "memory"); \
+ ___p1; \
+ })
+#elif defined(__aarch64__)
+# define libbpf_smp_store_release(p, v) \
+ asm volatile ("stlr %w1, %0" : "=Q" (*p) : "r" (v) : "memory")
+# define libbpf_smp_load_acquire(p) \
+ ({ \
+ typeof(*p) ___p1; \
+ asm volatile ("ldar %w0, %1" \
+ : "=r" (___p1) : "Q" (*p) : "memory"); \
+ ___p1; \
+ })
+#elif defined(__riscv)
+# define libbpf_smp_store_release(p, v) \
+ do { \
+ asm volatile ("fence rw,w" : : : "memory"); \
+ __XSK_WRITE_ONCE(*p, v); \
+ } while (0)
+# define libbpf_smp_load_acquire(p) \
+ ({ \
+ typeof(*p) ___p1 = __XSK_READ_ONCE(*p); \
+ asm volatile ("fence r,rw" : : : "memory"); \
+ ___p1; \
+ })
+#endif
+
+#ifndef libbpf_smp_store_release
+#define libbpf_smp_store_release(p, v) \
+ do { \
+ __sync_synchronize(); \
+ __XSK_WRITE_ONCE(*p, v); \
+ } while (0)
+#endif
+
+#ifndef libbpf_smp_load_acquire
+#define libbpf_smp_load_acquire(p) \
+ ({ \
+ typeof(*p) ___p1 = __XSK_READ_ONCE(*p); \
+ __sync_synchronize(); \
+ ___p1; \
+ })
+#endif
+
+/* LIBRARY INTERNAL -- END */
+
/* Do not access these members directly. Use the functions below. */
#define DEFINE_XSK_RING(name) \
struct name { \
--
2.27.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH bpf-next 2/2] libbpf: xsk: move barriers from libbpf_util.h to xsk.h
2021-03-10 8:09 ` [PATCH bpf-next 2/2] libbpf: xsk: move barriers from libbpf_util.h to xsk.h Björn Töpel
@ 2021-03-10 22:00 ` Andrii Nakryiko
2021-03-11 0:06 ` Jonathan Lemon
1 sibling, 0 replies; 7+ messages in thread
From: Andrii Nakryiko @ 2021-03-10 22:00 UTC (permalink / raw)
To: Björn Töpel
Cc: Alexei Starovoitov, Daniel Borkmann, Networking, bpf,
Andrii Nakryiko, Björn Töpel, Magnus Karlsson,
Jonathan Lemon, maximmi, ciara.loftus
On Wed, Mar 10, 2021 at 12:09 AM Björn Töpel <bjorn.topel@gmail.com> wrote:
>
> From: Björn Töpel <bjorn.topel@intel.com>
>
> The only user of libbpf_util.h is xsk.h. Move the barriers to xsk.h,
> and remove libbpf_util.h. The barriers are used as an implementation
> detail, and should not be considered part of the stable API.
>
> Signed-off-by: Björn Töpel <bjorn.topel@intel.com>
> ---
> tools/lib/bpf/Makefile | 1 -
> tools/lib/bpf/libbpf_util.h | 82 -------------------------------------
> tools/lib/bpf/xsk.h | 68 +++++++++++++++++++++++++++++-
> 3 files changed, 67 insertions(+), 84 deletions(-)
> delete mode 100644 tools/lib/bpf/libbpf_util.h
>
[...]
> diff --git a/tools/lib/bpf/xsk.h b/tools/lib/bpf/xsk.h
> index a9fdea87b5cd..1d846a419d21 100644
> --- a/tools/lib/bpf/xsk.h
> +++ b/tools/lib/bpf/xsk.h
> @@ -4,6 +4,7 @@
> * AF_XDP user-space access library.
> *
> * Copyright(c) 2018 - 2019 Intel Corporation.
Couldn't unsee ^this mismatch. Added space there.
Also, removing libbpf_util.h caused incremental build failure for the
kernel due to cached dependency files. make clean solved the issue. So
just FYI for everyone.
Applied to bpf-next, thanks.
> + * Copyright (c) 2019 Facebook
> *
> * Author(s): Magnus Karlsson <magnus.karlsson@intel.com>
> */
> @@ -13,15 +14,80 @@
>
> #include <stdio.h>
> #include <stdint.h>
> +#include <stdbool.h>
> #include <linux/if_xdp.h>
>
> #include "libbpf.h"
> -#include "libbpf_util.h"
>
> #ifdef __cplusplus
> extern "C" {
> #endif
>
[...]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH bpf-next 2/2] libbpf: xsk: move barriers from libbpf_util.h to xsk.h
2021-03-10 8:09 ` [PATCH bpf-next 2/2] libbpf: xsk: move barriers from libbpf_util.h to xsk.h Björn Töpel
2021-03-10 22:00 ` Andrii Nakryiko
@ 2021-03-11 0:06 ` Jonathan Lemon
2021-03-11 6:59 ` Björn Töpel
1 sibling, 1 reply; 7+ messages in thread
From: Jonathan Lemon @ 2021-03-11 0:06 UTC (permalink / raw)
To: Björn Töpel
Cc: ast, daniel, netdev, bpf, andrii, Björn Töpel,
magnus.karlsson, maximmi, ciara.loftus
On Wed, Mar 10, 2021 at 09:09:29AM +0100, Björn Töpel wrote:
> From: Björn Töpel <bjorn.topel@intel.com>
>
> The only user of libbpf_util.h is xsk.h. Move the barriers to xsk.h,
> and remove libbpf_util.h. The barriers are used as an implementation
> detail, and should not be considered part of the stable API.
Does that mean that anything else which uses the same type of
shared rings (bpf ringbuffer, io_uring, zctap) have to implement
the same primitives that xsk.h has?
--
Jonathan
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH bpf-next 2/2] libbpf: xsk: move barriers from libbpf_util.h to xsk.h
2021-03-11 0:06 ` Jonathan Lemon
@ 2021-03-11 6:59 ` Björn Töpel
2021-03-11 18:56 ` Andrii Nakryiko
0 siblings, 1 reply; 7+ messages in thread
From: Björn Töpel @ 2021-03-11 6:59 UTC (permalink / raw)
To: Jonathan Lemon, Björn Töpel
Cc: ast, daniel, netdev, bpf, andrii, magnus.karlsson, maximmi, ciara.loftus
On 2021-03-11 01:06, Jonathan Lemon wrote:
> On Wed, Mar 10, 2021 at 09:09:29AM +0100, Björn Töpel wrote:
>> From: Björn Töpel <bjorn.topel@intel.com>
>>
>> The only user of libbpf_util.h is xsk.h. Move the barriers to xsk.h,
>> and remove libbpf_util.h. The barriers are used as an implementation
>> detail, and should not be considered part of the stable API.
>
> Does that mean that anything else which uses the same type of
> shared rings (bpf ringbuffer, io_uring, zctap) have to implement
> the same primitives that xsk.h has?
>
Jonathan, there's a longer explanation on back-/forward-compatibility in
the commit message [1]. Again, this is for the XDP socket rings, so I
wont comment on the other rings. I would not assume compatibility
between different rings (e.g. the bpf ringbuffer and XDP sockets rings),
not even prior the barrier change.
Björn
[1]
https://lore.kernel.org/bpf/20210305094113.413544-2-bjorn.topel@gmail.com/
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH bpf-next 2/2] libbpf: xsk: move barriers from libbpf_util.h to xsk.h
2021-03-11 6:59 ` Björn Töpel
@ 2021-03-11 18:56 ` Andrii Nakryiko
0 siblings, 0 replies; 7+ messages in thread
From: Andrii Nakryiko @ 2021-03-11 18:56 UTC (permalink / raw)
To: Björn Töpel
Cc: Jonathan Lemon, Björn Töpel, Alexei Starovoitov,
Daniel Borkmann, Networking, bpf, Andrii Nakryiko,
Magnus Karlsson, maximmi, ciara.loftus
On Wed, Mar 10, 2021 at 10:59 PM Björn Töpel <bjorn.topel@intel.com> wrote:
>
> On 2021-03-11 01:06, Jonathan Lemon wrote:
> > On Wed, Mar 10, 2021 at 09:09:29AM +0100, Björn Töpel wrote:
> >> From: Björn Töpel <bjorn.topel@intel.com>
> >>
> >> The only user of libbpf_util.h is xsk.h. Move the barriers to xsk.h,
> >> and remove libbpf_util.h. The barriers are used as an implementation
> >> detail, and should not be considered part of the stable API.
> >
> > Does that mean that anything else which uses the same type of
> > shared rings (bpf ringbuffer, io_uring, zctap) have to implement
> > the same primitives that xsk.h has?
> >
>
> Jonathan, there's a longer explanation on back-/forward-compatibility in
> the commit message [1]. Again, this is for the XDP socket rings, so I
> wont comment on the other rings. I would not assume compatibility
> between different rings (e.g. the bpf ringbuffer and XDP sockets rings),
> not even prior the barrier change.
>
>
BPF ringbuf is using smp_store_release()/smp_load_acquire(), which are
coming from asm/barrier.h. But libbpf abstracts all the low-level
details, so users don't have to use such low-level primitives
directly.
> Björn
>
> [1]
> https://lore.kernel.org/bpf/20210305094113.413544-2-bjorn.topel@gmail.com/
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-03-11 18:58 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-10 8:09 [PATCH bpf-next 0/2] libbpf/xsk cleanups Björn Töpel
2021-03-10 8:09 ` [PATCH bpf-next 1/2] libbpf: xsk: remove linux/compiler.h header Björn Töpel
2021-03-10 8:09 ` [PATCH bpf-next 2/2] libbpf: xsk: move barriers from libbpf_util.h to xsk.h Björn Töpel
2021-03-10 22:00 ` Andrii Nakryiko
2021-03-11 0:06 ` Jonathan Lemon
2021-03-11 6:59 ` Björn Töpel
2021-03-11 18:56 ` Andrii Nakryiko
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).