From: "Björn Töpel" <bjorn.topel@gmail.com>
To: ast@kernel.org, daniel@iogearbox.net, netdev@vger.kernel.org,
bpf@vger.kernel.org, andrii@kernel.org
Cc: "Björn Töpel" <bjorn.topel@intel.com>,
magnus.karlsson@intel.com, jonathan.lemon@gmail.com,
maximmi@nvidia.com, ciara.loftus@intel.com
Subject: [PATCH bpf-next 1/2] libbpf: xsk: remove linux/compiler.h header
Date: Wed, 10 Mar 2021 09:09:28 +0100 [thread overview]
Message-ID: <20210310080929.641212-2-bjorn.topel@gmail.com> (raw)
In-Reply-To: <20210310080929.641212-1-bjorn.topel@gmail.com>
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
next prev parent reply other threads:[~2021-03-10 8:10 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
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=20210310080929.641212-2-bjorn.topel@gmail.com \
--to=bjorn.topel@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bjorn.topel@intel.com \
--cc=bpf@vger.kernel.org \
--cc=ciara.loftus@intel.com \
--cc=daniel@iogearbox.net \
--cc=jonathan.lemon@gmail.com \
--cc=magnus.karlsson@intel.com \
--cc=maximmi@nvidia.com \
--cc=netdev@vger.kernel.org \
/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).