Skip to contentSkip to conversation

tools/virtio: support aarch64 cross compiling

PATCH New Peng Fan (OSS) 1 participant 4 messages Dec 9, 2020 virtio core

lore
Share & tools
lore
#0 lore raw

cover tools/virtio: support aarch64 cross compiling

From: Peng Fan <[email protected]>

Not sure whether this is correct fix for aarch64 build, just a try. I still need to drop -Werror to make it build, but not included in this patchset.

Peng Fan (3):
tools/virtio: include asm/bug.h
tools/virtio: add krealloc_array
tools/virtio: add barrier for aarch64

 tools/virtio/asm/barrier.h  | 10 ++++++++++
 tools/virtio/linux/bug.h    |  2 ++
 tools/virtio/linux/kernel.h | 13 +++++++++++--
 3 files changed, 23 insertions(+), 2 deletions(-)
Signature · 1 line
2.28.0
#1 lore raw

PATCH 1/3 tools/virtio: include asm/bug.h

From: Peng Fan <[email protected]>

WARN_ON is used in drivers/vhost/vringh.c, to avoid build failure, need include asm/bug.h

---
 tools/virtio/linux/bug.h | 2 ++
 1 file changed, 2 insertions(+)
tools/virtio/linux/bug.h +2 -0
index b14c2c3b6b85..813baf13f62a 100644
@@ -2,6 +2,8 @@
 #ifndef BUG_H
 #define BUG_H
 
+#include <asm/bug.h>
+
 #define BUG_ON(__BUG_ON_cond) assert(!(__BUG_ON_cond))
 
 #define BUILD_BUG_ON(x)
Signature · 1 line
2.28.0
#2 lore raw

PATCH 2/3 tools/virtio: add krealloc_array

In reply to Peng Fan (OSS)

From: Peng Fan <[email protected]>

krealloc_array is used in drivers/vhost/vringh.c, add it to avoid build failure.

Drop WARN_ON_ONCE, because duplicated with the one in bug.h

---
 tools/virtio/linux/kernel.h | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
tools/virtio/linux/kernel.h +11 -2
index 315e85cabeda..0b493542e61a 100644
@@ -11,6 +11,7 @@
 
 #include <linux/compiler.h>
 #include <linux/types.h>
+#include <linux/overflow.h>
 #include <linux/list.h>
 #include <linux/printk.h>
 #include <linux/bug.h>
@@ -117,6 +118,16 @@ static inline void free_page(unsigned long addr)
 #  define unlikely(x)	(__builtin_expect(!!(x), 0))
 # endif
 
+static inline void *krealloc_array(void *p, size_t new_n, size_t new_size, gfp_t gfp)
+{
+	size_t bytes;
+
+	if (unlikely(check_mul_overflow(new_n, new_size, &bytes)))
+		return NULL;
+
+	return krealloc(p, bytes, gfp);
+}
+
 #define pr_err(format, ...) fprintf (stderr, format, ## __VA_ARGS__)
 #ifdef DEBUG
 #define pr_debug(format, ...) fprintf (stderr, format, ## __VA_ARGS__)
@@ -126,8 +137,6 @@ static inline void free_page(unsigned long addr)
 #define dev_err(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__)
 #define dev_warn(dev, format, ...) fprintf (stderr, format, ## __VA_ARGS__)
 
-#define WARN_ON_ONCE(cond) (unlikely(cond) ? fprintf (stderr, "WARNING\n") : 0)
-
 #define min(x, y) ({				\
 	typeof(x) _min1 = (x);			\
 	typeof(y) _min2 = (y);			\
Signature · 1 line
2.28.0
#3 lore raw

PATCH 3/3 tools/virtio: add barrier for aarch64

In reply to Peng Fan (OSS)

From: Peng Fan <[email protected]>

Add barrier for aarch64 for cross compiling, and most are from Linux Kernel.

---
 tools/virtio/asm/barrier.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
tools/virtio/asm/barrier.h +10 -0
index 04d563fc9b95..468435ed64e6 100644
@@ -16,6 +16,16 @@
 # define mb() abort()
 # define dma_rmb() abort()
 # define dma_wmb() abort()
+#elif defined(__aarch64__)
+#define dmb(opt) asm volatile("dmb " #opt : : : "memory")
+#define virt_mb() __sync_synchronize()
+#define virt_rmb() dmb(ishld)
+#define virt_wmb() dmb(ishst)
+#define virt_store_mb(var, value)  do { WRITE_ONCE(var, value); dmb(ish); } while (0)
+/* Weak barriers should be used. If not - it's a bug */
+# define mb() abort()
+# define dma_rmb() abort()
+# define dma_wmb() abort()
 #else
 #error Please fill in barrier macros
 #endif
Signature · 1 line
2.28.0