Skip to contentSkip to conversation

qemu/bswap: Use compiler __builtin_bswap()

PATCH In review Philippe Mathieu-Daudé 8 participants 23 messages Sep 28, 2020 – Oct 19, 2020

lore
Share & tools
lore
#0 lore raw

v2 cover qemu/bswap: Use compiler __builtin_bswap()

Implement Richard's suggestion to use __builtin_bswap().

const_XX() not updated. We could use le_bswap() definitions but they are undefined, not sure yet what is the best way. Meanwhile I figure this out, these patches are ready for review.

Since v1:
- Remove the Haiku/BSD ifdef'ry (Peter)
- Include the Haiku VM image from Alexander

Alexander von Gluck IV (1):
tests/vm: Add Haiku test based on their vagrant images

Philippe Mathieu-Daudé (7):
qemu/bswap: Remove unused qemu_bswap_len() qemu/bswap: Replace bswapXX() by compiler __builtin_bswap() qemu/bswap: Replace bswapXXs() by compiler __builtin_bswap() qemu/bswap: Remove <byteswap.h> dependency qemu/bswap: Use compiler __builtin_bswap() on Haiku qemu/bswap: Use compiler __builtin_bswap() on FreeBSD qemu/bswap: Use compiler __builtin_bswap() on NetBSD

 configure                 |  28 ---------
 include/qemu/bswap.h      |  79 +++++---------------------
 tests/keys/vagrant        |  27 +++++++++
 tests/keys/vagrant.pub    |   1 +
 tests/vm/Makefile.include |   3 +-
 tests/vm/basevm.py        |   5 +-
 tests/vm/haiku.x86_64     | 116 ++++++++++++++++++++++++++++++++++++++
 7 files changed, 164 insertions(+), 95 deletions(-)
 create mode 100644 tests/keys/vagrant
 create mode 100644 tests/keys/vagrant.pub
 create mode 100755 tests/vm/haiku.x86_64
Signature · 1 line
2.26.2
#1 lore raw

PATCH v2 1/8 qemu/bswap: Remove unused qemu_bswap_len()

Last use of qemu_bswap_len() has been removed in commit e5fd1eb05ec ("apb: add busA qdev property to PBM PCI bridge").

---
 include/qemu/bswap.h | 6 ------
 1 file changed, 6 deletions(-)
include/qemu/bswap.h +0 -6
index 1d3e4c24e41..8b01c38040c 100644
@@ -169,12 +169,6 @@ CPU_CONVERT(le, 16, uint16_t)
 CPU_CONVERT(le, 32, uint32_t)
 CPU_CONVERT(le, 64, uint64_t)
 
-/* len must be one of 1, 2, 4 */
-static inline uint32_t qemu_bswap_len(uint32_t value, int len)
-{
-    return bswap32(value) >> (32 - 8 * len);
-}
-
 /*
  * Same as cpu_to_le{16,32}, except that gcc will figure the result is
  * a compile-time constant if you pass in a constant.  So this can be
Signature · 1 line
2.26.2
#2 lore raw

PATCH v2 2/8 qemu/bswap: Replace bswapXX() by compiler __builtin_bswap()

In reply to Philippe Mathieu-Daudé

Use the compiler built-in function to byte swap values, as the compiler is clever and will fold constants.

---
 include/qemu/bswap.h | 33 +++++++--------------------------
 1 file changed, 7 insertions(+), 26 deletions(-)
include/qemu/bswap.h +7 -26
index 8b01c38040c..41131d3d76e 100644
@@ -27,32 +27,13 @@ static inline uint64_t bswap64(uint64_t x)
 {
     return bswap_64(x);
 }
-# else
-static inline uint16_t bswap16(uint16_t x)
-{
-    return (((x & 0x00ff) << 8) |
-            ((x & 0xff00) >> 8));
-}
-
-static inline uint32_t bswap32(uint32_t x)
-{
-    return (((x & 0x000000ffU) << 24) |
-            ((x & 0x0000ff00U) <<  8) |
-            ((x & 0x00ff0000U) >>  8) |
-            ((x & 0xff000000U) >> 24));
-}
-
-static inline uint64_t bswap64(uint64_t x)
-{
-    return (((x & 0x00000000000000ffULL) << 56) |
-            ((x & 0x000000000000ff00ULL) << 40) |
-            ((x & 0x0000000000ff0000ULL) << 24) |
-            ((x & 0x00000000ff000000ULL) <<  8) |
-            ((x & 0x000000ff00000000ULL) >>  8) |
-            ((x & 0x0000ff0000000000ULL) >> 24) |
-            ((x & 0x00ff000000000000ULL) >> 40) |
-            ((x & 0xff00000000000000ULL) >> 56));
-}
+#else
+#undef  bswap16
+#define bswap16(_x) __builtin_bswap16(_x)
+#undef  bswap32
+#define bswap32(_x) __builtin_bswap32(_x)
+#undef  bswap64
+#define bswap64(_x) __builtin_bswap64(_x)
 #endif /* ! CONFIG_MACHINE_BSWAP_H */
 
 static inline void bswap16s(uint16_t *s)
Signature · 1 line
2.26.2
#3 lore raw

PATCH v2 3/8 qemu/bswap: Replace bswapXXs() by compiler __builtin_bswap()

In reply to Philippe Mathieu-Daudé
---
 include/qemu/bswap.h | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
include/qemu/bswap.h +9 -7
index 41131d3d76e..fed96dddd7a 100644
@@ -38,29 +38,31 @@ static inline uint64_t bswap64(uint64_t x)
 
 static inline void bswap16s(uint16_t *s)
 {
-    *s = bswap16(*s);
+    *s = __builtin_bswap16(*s);
 }
 
 static inline void bswap32s(uint32_t *s)
 {
-    *s = bswap32(*s);
+    *s = __builtin_bswap32(*s);
 }
 
 static inline void bswap64s(uint64_t *s)
 {
-    *s = bswap64(*s);
+    *s = __builtin_bswap64(*s);
 }
 
 #if defined(HOST_WORDS_BIGENDIAN)
 #define be_bswap(v, size) (v)
-#define le_bswap(v, size) glue(bswap, size)(v)
+#define le_bswap(v, size) glue(__builtin_bswap, size)(v)
 #define be_bswaps(v, size)
-#define le_bswaps(p, size) do { *p = glue(bswap, size)(*p); } while(0)
+#define le_bswaps(p, size) \
+            do { *p = glue(__builtin_bswap, size)(*p); } while (0)
 #else
 #define le_bswap(v, size) (v)
-#define be_bswap(v, size) glue(bswap, size)(v)
+#define be_bswap(v, size) glue(__builtin_bswap, size)(v)
 #define le_bswaps(v, size)
-#define be_bswaps(p, size) do { *p = glue(bswap, size)(*p); } while(0)
+#define be_bswaps(p, size) \
+            do { *p = glue(__builtin_bswap, size)(*p); } while (0)
 #endif
 
 /**
Signature · 1 line
2.26.2
#4 lore raw

Re: [PATCH v2 3/8] qemu/bswap: Replace bswapXXs() by compiler __builtin_bswap()

Quoted 37 lines · Philippe Mathieu-Daudé
---
 include/qemu/bswap.h | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
include/qemu/bswap.h +5 -5
index 41131d3d76e..fed96dddd7a 100644
@@ -38,29 +38,31 @@ static inline uint64_t bswap64(uint64_t x)
 
 static inline void bswap16s(uint16_t *s)
 {
-    *s = bswap16(*s);
+    *s = __builtin_bswap16(*s);
 }
 
 static inline void bswap32s(uint32_t *s)
 {
-    *s = bswap32(*s);
+    *s = __builtin_bswap32(*s);
 }
 
 static inline void bswap64s(uint64_t *s)
 {
-    *s = bswap64(*s);
+    *s = __builtin_bswap64(*s);
 }
 
 #if defined(HOST_WORDS_BIGENDIAN)
 #define be_bswap(v, size) (v)
-#define le_bswap(v, size) glue(bswap, size)(v)
+#define le_bswap(v, size) glue(__builtin_bswap, size)(v)
 #define be_bswaps(v, size)
-#define le_bswaps(p, size) do { *p = glue(bswap, size)(*p); } while(0)
+#define le_bswaps(p, size) \

include/qemu/bswap.h static inline uint64_t bswap64(uint64_t x) · line 66

Quoted 10 lines
include/qemu/bswap.h +4 -2
+            do { *p = glue(__builtin_bswap, size)(*p); } while (0)
 #else
 #define le_bswap(v, size) (v)
-#define be_bswap(v, size) glue(bswap, size)(v)
+#define be_bswap(v, size) glue(__builtin_bswap, size)(v)
 #define le_bswaps(v, size)
-#define be_bswaps(p, size) do { *p = glue(bswap, size)(*p); } while(0)
+#define be_bswaps(p, size) \
+            do { *p = glue(__builtin_bswap, size)(*p); } while (0)
 #endif

What's the advantage of the renaming here if bswap is already #defined to the builtin function (or another useful function from a system header)? This just looks like code churn to me?

Thomas

#5 lore raw

PATCH v2 4/8 qemu/bswap: Remove <byteswap.h> dependency

In reply to Philippe Mathieu-Daudé

Since commit efc6c070aca ("configure: Add a test for the minimum compiler version") the minimum compiler version required for GCC is 4.8, which supports __builtin_bswap().
Drop the <byteswap.h> dependency.

---
 configure            | 13 -------------
 include/qemu/bswap.h | 17 -----------------
 2 files changed, 30 deletions(-)
configure +0 -13
index e8e8e984f24..bff787daea7 100755
@@ -4886,16 +4886,6 @@ if test "$docs" != "no" ; then
   fi
 fi
 
-# Search for bswap_32 function
-byteswap_h=no
-cat > $TMPC << EOF
-#include <byteswap.h>
-int main(void) { return bswap_32(0); }
-EOF
-if compile_prog "" "" ; then
-  byteswap_h=yes
-fi
-
 # Search for bswap32 function
 bswap_h=no
 cat > $TMPC << EOF
@@ -6789,9 +6779,6 @@ fi
 if test "$st_atim" = "yes" ; then
   echo "HAVE_STRUCT_STAT_ST_ATIM=y" >> $config_host_mak
 fi
-if test "$byteswap_h" = "yes" ; then
-  echo "CONFIG_BYTESWAP_H=y" >> $config_host_mak
-fi
 if test "$bswap_h" = "yes" ; then
   echo "CONFIG_MACHINE_BSWAP_H=y" >> $config_host_mak
 fi
include/qemu/bswap.h +0 -17
index fed96dddd7a..55916670d39 100644
@@ -10,23 +10,6 @@
 # include <sys/endian.h>
 #elif defined(__HAIKU__)
 # include <endian.h>
-#elif defined(CONFIG_BYTESWAP_H)
-# include <byteswap.h>
-
-static inline uint16_t bswap16(uint16_t x)
-{
-    return bswap_16(x);
-}
-
-static inline uint32_t bswap32(uint32_t x)
-{
-    return bswap_32(x);
-}
-
-static inline uint64_t bswap64(uint64_t x)
-{
-    return bswap_64(x);
-}
 #else
 #undef  bswap16
 #define bswap16(_x) __builtin_bswap16(_x)
Signature · 1 line
2.26.2
#6 lore raw

PATCH v2 5/8 qemu/bswap: Use compiler __builtin_bswap() on Haiku

In reply to Philippe Mathieu-Daudé

Since commit efc6c070aca ("configure: Add a test for the minimum compiler version") the minimum compiler version required for GCC is 4.8, which supports __builtin_bswap().
Remove the Haiku specific ifdef'ry.

This reverts commit 652a46ebba970017c7a23767dcc983265cdb8eb7 ("bswap.h: Include <endian.h> on Haiku for bswap operations").

---
Cc: David Carlier <[email protected]>
Cc: Carlo Arenas <[email protected]>

---
 include/qemu/bswap.h | 2 --
 1 file changed, 2 deletions(-)
include/qemu/bswap.h +0 -2
index 55916670d39..719d620bfe6 100644
@@ -8,8 +8,6 @@
 # include <machine/bswap.h>
 #elif defined(__FreeBSD__)
 # include <sys/endian.h>
-#elif defined(__HAIKU__)
-# include <endian.h>
 #else
 #undef  bswap16
 #define bswap16(_x) __builtin_bswap16(_x)
Signature · 1 line
2.26.2
#7 lore raw

Re: [PATCH v2 5/8] qemu/bswap: Use compiler __builtin_bswap() on Haiku

Unfortunately it breaks the build.
Regards.

Quoted 33 lines · Philippe Mathieu-Daudé

Since commit efc6c070aca ("configure: Add a test for the minimum compiler version") the minimum compiler version required for GCC is 4.8, which supports __builtin_bswap().
Remove the Haiku specific ifdef'ry.

This reverts commit 652a46ebba970017c7a23767dcc983265cdb8eb7 ("bswap.h: Include <endian.h> on Haiku for bswap operations").

---
Cc: David Carlier <[email protected]>
Cc: Carlo Arenas <[email protected]>

---
 include/qemu/bswap.h | 2 --
 1 file changed, 2 deletions(-)
include/qemu/bswap.h +0 -3
index 55916670d39..719d620bfe6 100644
@@ -8,8 +8,6 @@
 # include <machine/bswap.h>
 #elif defined(__FreeBSD__)
 # include <sys/endian.h>
-#elif defined(__HAIKU__)
-# include <endian.h>
 #else
 #undef  bswap16
 #define bswap16(_x) __builtin_bswap16(_x)
--

2.26.2

#8 lore raw

Re: [PATCH v2 5/8] qemu/bswap: Use compiler __builtin_bswap() on Haiku

Quoted 1 line · David CARLIER

Unfortunately it breaks the build.

Can you provide details of the errors seen and toolchain versions.

I notice we don't have any CI support for Haiku right now, nor any recipe in tests/vm/ for enabling users to setup a VM with Haiku installed. This very much makes Haiku a second class citizen right now in terms of QEMU's supported platforms, with no expectation of whether it'll work at any point in time.

Quoted 18 lines · Philippe Mathieu-Daudé
Quoted 17 lines

Since commit efc6c070aca ("configure: Add a test for the minimum compiler version") the minimum compiler version required for GCC is 4.8, which supports __builtin_bswap().
Remove the Haiku specific ifdef'ry.

This reverts commit 652a46ebba970017c7a23767dcc983265cdb8eb7 ("bswap.h: Include <endian.h> on Haiku for bswap operations").

---
Cc: David Carlier <[email protected]>
Cc: Carlo Arenas <[email protected]>

---
 include/qemu/bswap.h | 2 --
 1 file changed, 2 deletions(-)
Quoted 17 lines
Quoted 14 lines
include/qemu/bswap.h +0 -3
index 55916670d39..719d620bfe6 100644
@@ -8,8 +8,6 @@
 # include <machine/bswap.h>
 #elif defined(__FreeBSD__)
 # include <sys/endian.h>
-#elif defined(__HAIKU__)
-# include <endian.h>
 #else
 #undef  bswap16
 #define bswap16(_x) __builtin_bswap16(_x)
--
Quoted 2 lines

2.26.2

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#9 lore raw

Re: [PATCH v2 5/8] qemu/bswap: Use compiler __builtin_bswap() on Haiku

Quoted 10 lines · Daniel P. Berrangé
Quoted 1 line · David CARLIER

Unfortunately it breaks the build.

Can you provide details of the errors seen and toolchain versions.

I notice we don't have any CI support for Haiku right now, nor any recipe in tests/vm/ for enabling users to setup a VM with Haiku installed. This very much makes Haiku a second class citizen right now in terms of QEMU's supported platforms, with no expectation of whether it'll work at any point in time.

I provided the tests/vm/ build script from Alexander as patch 8/8 of this series:
https://lists.gnu.org/archive/html/qemu-devel/2020-09/msg10022.html

This is what I used to test this patch/series.

Quoted 40 lines
Quoted 19 lines · Philippe Mathieu-Daudé
Quoted 17 lines

Since commit efc6c070aca ("configure: Add a test for the minimum compiler version") the minimum compiler version required for GCC is 4.8, which supports __builtin_bswap().
Remove the Haiku specific ifdef'ry.

This reverts commit 652a46ebba970017c7a23767dcc983265cdb8eb7 ("bswap.h: Include <endian.h> on Haiku for bswap operations").

---
Cc: David Carlier <[email protected]>
Cc: Carlo Arenas <[email protected]>

---
 include/qemu/bswap.h | 2 --
 1 file changed, 2 deletions(-)
Quoted 17 lines
Quoted 14 lines
include/qemu/bswap.h +0 -3
index 55916670d39..719d620bfe6 100644
@@ -8,8 +8,6 @@
 # include <machine/bswap.h>
 #elif defined(__FreeBSD__)
 # include <sys/endian.h>
-#elif defined(__HAIKU__)
-# include <endian.h>
 #else
 #undef  bswap16
 #define bswap16(_x) __builtin_bswap16(_x)
--
Quoted 2 lines

2.26.2

Regards,
Daniel

#10 lore raw

Re: [PATCH v2 5/8] qemu/bswap: Use compiler __builtin_bswap() on Haiku

Quoted 12 lines · Philippe Mathieu-Daudé
Quoted 10 lines · Daniel P. Berrangé
Quoted 1 line · David CARLIER

Unfortunately it breaks the build.

Can you provide details of the errors seen and toolchain versions.

I notice we don't have any CI support for Haiku right now, nor any recipe in tests/vm/ for enabling users to setup a VM with Haiku installed. This very much makes Haiku a second class citizen right now in terms of QEMU's supported platforms, with no expectation of whether it'll work at any point in time.

Quoted 5 lines

I provided the tests/vm/ build script from Alexander as patch 8/8 of this series:
https://lists.gnu.org/archive/html/qemu-devel/2020-09/msg10022.html

This is what I used to test this patch/series.

I suppose the Haiku VM patch got lost, so I'll repost it separate.

Which tree should I Cc:? Ah, Alex testing tree :)

#11 lore raw

Re: [PATCH v2 5/8] qemu/bswap: Use compiler __builtin_bswap() on Haiku

In reply to Daniel P. Berrangé

errors as
...
expected '=', ',', ';', 'asm' r "__attribute__' before "builtin_swap16'
...

base gcc 8.3

Quoted 56 lines · Daniel P. Berrangé
Quoted 1 line · David CARLIER

Unfortunately it breaks the build.

Can you provide details of the errors seen and toolchain versions.

I notice we don't have any CI support for Haiku right now, nor any recipe in tests/vm/ for enabling users to setup a VM with Haiku installed. This very much makes Haiku a second class citizen right now in terms of QEMU's supported platforms, with no expectation of whether it'll work at any point in time.

Quoted 18 lines · Philippe Mathieu-Daudé
Quoted 17 lines

Since commit efc6c070aca ("configure: Add a test for the minimum compiler version") the minimum compiler version required for GCC is 4.8, which supports __builtin_bswap().
Remove the Haiku specific ifdef'ry.

This reverts commit 652a46ebba970017c7a23767dcc983265cdb8eb7 ("bswap.h: Include <endian.h> on Haiku for bswap operations").

---
Cc: David Carlier <[email protected]>
Cc: Carlo Arenas <[email protected]>

---
 include/qemu/bswap.h | 2 --
 1 file changed, 2 deletions(-)
Quoted 17 lines
Quoted 14 lines
include/qemu/bswap.h +0 -3
index 55916670d39..719d620bfe6 100644
@@ -8,8 +8,6 @@
 # include <machine/bswap.h>
 #elif defined(__FreeBSD__)
 # include <sys/endian.h>
-#elif defined(__HAIKU__)
-# include <endian.h>
 #else
 #undef  bswap16
 #define bswap16(_x) __builtin_bswap16(_x)
--
Quoted 2 lines

2.26.2

Regards,
Daniel
--

|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#12 lore raw

Re: [PATCH v2 5/8] qemu/bswap: Use compiler __builtin_bswap() on Haiku

In reply to Philippe Mathieu-Daudé
Quoted 21 lines · Philippe Mathieu-Daudé

Since commit efc6c070aca ("configure: Add a test for the minimum compiler version") the minimum compiler version required for GCC is 4.8, which supports __builtin_bswap().
Remove the Haiku specific ifdef'ry.

This reverts commit 652a46ebba970017c7a23767dcc983265cdb8eb7 ("bswap.h: Include <endian.h> on Haiku for bswap operations").

---
Cc: David Carlier <[email protected]>
Cc: Carlo Arenas <[email protected]>

---
 include/qemu/bswap.h | 2 --
 1 file changed, 2 deletions(-)
include/qemu/bswap.h +0 -0
index 55916670d39..719d620bfe6 100644

include/qemu/bswap.h line 13

Quoted 8 lines
include/qemu/bswap.h +0 -2
@@ -8,8 +8,6 @@
 # include <machine/bswap.h>
 #elif defined(__FreeBSD__)
 # include <sys/endian.h>
-#elif defined(__HAIKU__)
-# include <endian.h>
 #else
 #undef  bswap16
 #define bswap16(_x) __builtin_bswap16(_x)

Why don't we simply always use the builtin functions on all systems? I assume the compiler can handle these the best in all cases... or do you see any advantage in using <machine/bswap.h> or <sys/endian.h> in certain cases?

Thomas

Thomas

#13 lore raw

PATCH v2 6/8 qemu/bswap: Use compiler __builtin_bswap() on FreeBSD

In reply to Philippe Mathieu-Daudé

Since commit efc6c070aca ("configure: Add a test for the minimum compiler version") the minimum compiler version required for GCC is 4.8, which supports __builtin_bswap().
Remove the FreeBSD specific ifdef'ry.

This reverts commit de03c3164accc21311c39327601fcdd95da301f3 ("bswap: Fix build on FreeBSD 10.0").

---
Cc: Ed Maste <[email protected]>

---
 include/qemu/bswap.h | 2 --
 1 file changed, 2 deletions(-)
include/qemu/bswap.h +0 -2
index 719d620bfe6..1a297bfec22 100644
@@ -6,8 +6,6 @@
 #ifdef CONFIG_MACHINE_BSWAP_H
 # include <sys/endian.h>
 # include <machine/bswap.h>
-#elif defined(__FreeBSD__)
-# include <sys/endian.h>
 #else
 #undef  bswap16
 #define bswap16(_x) __builtin_bswap16(_x)
Signature · 1 line
2.26.2
#14 lore raw

Re: [PATCH v2 6/8] qemu/bswap: Use compiler __builtin_bswap() on FreeBSD

Quoted 20 lines · Philippe Mathieu-Daudé

Since commit efc6c070aca ("configure: Add a test for the minimum compiler version") the minimum compiler version required for GCC is 4.8, which supports __builtin_bswap().
Remove the FreeBSD specific ifdef'ry.

This reverts commit de03c3164accc21311c39327601fcdd95da301f3 ("bswap: Fix build on FreeBSD 10.0").

---
Cc: Ed Maste <[email protected]>

---
 include/qemu/bswap.h | 2 --
 1 file changed, 2 deletions(-)
include/qemu/bswap.h +0 -0
index 719d620bfe6..1a297bfec22 100644

include/qemu/bswap.h line 10

Quoted 5 lines
include/qemu/bswap.h +0 -2
@@ -6,8 +6,6 @@
 #ifdef CONFIG_MACHINE_BSWAP_H
 # include <sys/endian.h>
 # include <machine/bswap.h>
-#elif defined(__FreeBSD__)
-# include <sys/endian.h>

Ah, well, no I get it ... you're removing this stuff bit by bit. Quite confusing, IMHO, I'd remove them all in one patch instead.

Thomas

#15 lore raw

Re: [PATCH v2 6/8] qemu/bswap: Use compiler __builtin_bswap() on FreeBSD

Quoted 16 lines · Thomas Huth
Quoted 15 lines · Philippe Mathieu-Daudé

Since commit efc6c070aca ("configure: Add a test for the minimum compiler version") the minimum compiler version required for GCC is 4.8, which supports __builtin_bswap().
Remove the FreeBSD specific ifdef'ry.

This reverts commit de03c3164accc21311c39327601fcdd95da301f3 ("bswap: Fix build on FreeBSD 10.0").

---
Cc: Ed Maste <[email protected]>

---
 include/qemu/bswap.h | 2 --
 1 file changed, 2 deletions(-)
Quoted 13 lines

include/qemu/bswap.h line 10

Quoted 10 lines
include/qemu/bswap.h +0 -2
index 719d620bfe6..1a297bfec22 100644
@@ -6,8 +6,6 @@
 #ifdef CONFIG_MACHINE_BSWAP_H
 # include <sys/endian.h>
 # include <machine/bswap.h>
-#elif defined(__FreeBSD__)
-# include <sys/endian.h>

Ah, well, no I get it ... you're removing this stuff bit by bit. Quite confusing, IMHO, I'd remove them all in one patch instead.

Sure. I did it that way because I was testing OS after OS, when one was successful I committed the change and went for the next one.

Quoted 3 lines

Thomas

#16 lore raw

Re: [PATCH v2 6/8] qemu/bswap: Use compiler __builtin_bswap() on FreeBSD

Quoted 17 lines · Philippe Mathieu-Daudé
Quoted 16 lines · Thomas Huth
Quoted 15 lines · Philippe Mathieu-Daudé

Since commit efc6c070aca ("configure: Add a test for the minimum compiler version") the minimum compiler version required for GCC is 4.8, which supports __builtin_bswap().
Remove the FreeBSD specific ifdef'ry.

This reverts commit de03c3164accc21311c39327601fcdd95da301f3 ("bswap: Fix build on FreeBSD 10.0").

---
Cc: Ed Maste <[email protected]>

---
 include/qemu/bswap.h | 2 --
 1 file changed, 2 deletions(-)
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
include/qemu/bswap.h +0 -0
index 719d620bfe6..1a297bfec22 100644
@@ -6,8 +6,6 @@
Quoted 8 lines

include/qemu/bswap.h line 10

Quoted 5 lines
include/qemu/bswap.h +0 -2
 #ifdef CONFIG_MACHINE_BSWAP_H
 # include <sys/endian.h>
 # include <machine/bswap.h>
-#elif defined(__FreeBSD__)
-# include <sys/endian.h>

Ah, well, no I get it ... you're removing this stuff bit by bit. Quite confusing, IMHO, I'd remove them all in one patch instead.

Actually I thought it would be easier for each OS maintainer to review the corresponding patch.

Quoted 9 lines

Sure. I did it that way because I was testing OS after OS, when one was successful I committed the change and went for the next one.

Quoted 3 lines

Thomas

Reviewed-by on v2 6/8
#17 lore raw

Re: [PATCH v2 6/8] qemu/bswap: Use compiler __builtin_bswap() on FreeBSD

In reply to Philippe Mathieu-Daudé
Quoted 10 lines · Philippe Mathieu-Daudé

Since commit efc6c070aca ("configure: Add a test for the minimum compiler version") the minimum compiler version required for GCC is 4.8, which supports __builtin_bswap().
Remove the FreeBSD specific ifdef'ry.

This reverts commit de03c3164accc21311c39327601fcdd95da301f3 ("bswap: Fix build on FreeBSD 10.0").

Aside, to test building with this change on Clang 11 (default compiler in FreeBSD-CURRENT) I needed a few other changes to avoid warnings:

hw/s390x/ipl.h, hw/usb/dev-uas.c variable sized type warnings

../hw/usb/dev-uas.c:157:31: error: field 'status' with variable sized type 'uas_iu' not at the end of a struct or class is a GNU extension [-Werror,-Wgnu-variable-sized-type-not-at-end]

    uas_iu                    status;
                              ^

target/s390x/cpu_models.c pointer to smaller integer type cast

../target/s390x/cpu_models.c:984:21: error: cast to smaller integer type 'S390Feat' from 'void *' [-Werror,-Wvoid-pointer-to-enum-cast]

    S390Feat feat = (S390Feat) opaque;
                    ^~~~~~~~~~~~~~~~~
#18 lore raw

PATCH v2 7/8 qemu/bswap: Use compiler __builtin_bswap() on NetBSD

In reply to Philippe Mathieu-Daudé

Since commit efc6c070aca ("configure: Add a test for the minimum compiler version") the minimum compiler version required for GCC is 4.8, which supports __builtin_bswap().
Remove the NetBSD specific ifdef'ry.

This reverts commit 1360677cfe3ca8f945fa1de77823df21a77e4500 ("makes NetBSD use the native bswap functions").

---
 configure            | 15 ---------------
 include/qemu/bswap.h |  5 -----
 2 files changed, 20 deletions(-)
configure +0 -15
index bff787daea7..1b0a02a0af8 100755
@@ -4886,18 +4886,6 @@ if test "$docs" != "no" ; then
   fi
 fi
 
-# Search for bswap32 function
-bswap_h=no
-cat > $TMPC << EOF
-#include <sys/endian.h>
-#include <sys/types.h>
-#include <machine/bswap.h>
-int main(void) { return bswap32(0); }
-EOF
-if compile_prog "" "" ; then
-  bswap_h=yes
-fi
-
 ##########################################
 # Do we have libiscsi >= 1.9.0
 if test "$libiscsi" != "no" ; then
@@ -6779,9 +6767,6 @@ fi
 if test "$st_atim" = "yes" ; then
   echo "HAVE_STRUCT_STAT_ST_ATIM=y" >> $config_host_mak
 fi
-if test "$bswap_h" = "yes" ; then
-  echo "CONFIG_MACHINE_BSWAP_H=y" >> $config_host_mak
-fi
 if test "$curl" = "yes" ; then
   echo "CONFIG_CURL=y" >> $config_host_mak
   echo "CURL_CFLAGS=$curl_cflags" >> $config_host_mak
include/qemu/bswap.h +0 -5
index 1a297bfec22..7e586531c09 100644
@@ -3,17 +3,12 @@
 
 #include "fpu/softfloat-types.h"
 
-#ifdef CONFIG_MACHINE_BSWAP_H
-# include <sys/endian.h>
-# include <machine/bswap.h>
-#else
 #undef  bswap16
 #define bswap16(_x) __builtin_bswap16(_x)
 #undef  bswap32
 #define bswap32(_x) __builtin_bswap32(_x)
 #undef  bswap64
 #define bswap64(_x) __builtin_bswap64(_x)
-#endif /* ! CONFIG_MACHINE_BSWAP_H */
 
 static inline void bswap16s(uint16_t *s)
 {
Signature · 1 line
2.26.2
#19 lore raw

Re: [PATCH v2 7/8] qemu/bswap: Use compiler __builtin_bswap() on NetBSD

Quoted 8 lines · Philippe Mathieu-Daudé

Since commit efc6c070aca ("configure: Add a test for the minimum compiler version") the minimum compiler version required for GCC is 4.8, which supports __builtin_bswap().
Remove the NetBSD specific ifdef'ry.

This reverts commit 1360677cfe3ca8f945fa1de77823df21a77e4500 ("makes NetBSD use the native bswap functions").

Personally, I prefer using the system headers. but if you want to use the GCC builtins, please go for it.

Quoted 62 lines
---
 configure            | 15 ---------------
 include/qemu/bswap.h |  5 -----
 2 files changed, 20 deletions(-)
configure +0 -15
index bff787daea7..1b0a02a0af8 100755
@@ -4886,18 +4886,6 @@ if test "$docs" != "no" ; then
   fi
 fi
 
-# Search for bswap32 function
-bswap_h=no
-cat > $TMPC << EOF
-#include <sys/endian.h>
-#include <sys/types.h>
-#include <machine/bswap.h>
-int main(void) { return bswap32(0); }
-EOF
-if compile_prog "" "" ; then
-  bswap_h=yes
-fi
-
 ##########################################
 # Do we have libiscsi >= 1.9.0
 if test "$libiscsi" != "no" ; then
@@ -6779,9 +6767,6 @@ fi
 if test "$st_atim" = "yes" ; then
   echo "HAVE_STRUCT_STAT_ST_ATIM=y" >> $config_host_mak
 fi
-if test "$bswap_h" = "yes" ; then
-  echo "CONFIG_MACHINE_BSWAP_H=y" >> $config_host_mak
-fi
 if test "$curl" = "yes" ; then
   echo "CONFIG_CURL=y" >> $config_host_mak
   echo "CURL_CFLAGS=$curl_cflags" >> $config_host_mak
include/qemu/bswap.h +0 -5
index 1a297bfec22..7e586531c09 100644
@@ -3,17 +3,12 @@
 
 #include "fpu/softfloat-types.h"
 
-#ifdef CONFIG_MACHINE_BSWAP_H
-# include <sys/endian.h>
-# include <machine/bswap.h>
-#else
 #undef  bswap16
 #define bswap16(_x) __builtin_bswap16(_x)
 #undef  bswap32
 #define bswap32(_x) __builtin_bswap32(_x)
 #undef  bswap64
 #define bswap64(_x) __builtin_bswap64(_x)
-#endif /* ! CONFIG_MACHINE_BSWAP_H */
 
 static inline void bswap16s(uint16_t *s)
 {
#20 lore raw

Re: [PATCH v2 7/8] qemu/bswap: Use compiler __builtin_bswap() on NetBSD

Quoted 3 lines · Kamil Rytarowski

Personally, I prefer using the system headers. but if you want to use the GCC builtins, please go for it.

I'd agree if the system header approach was cross-platform or if this was a BSD-only program or if we were aiming for complete compiler-implementation independence, but since we rely on GCC/clang all over the place already it seems nicer to avoid all the machinery for identifying which of the multiple different system header implementations is present, and instead just have a single implementation that works on all the hosts we care about...

thanks
-- PMM

#21 lore raw

Re: [PATCH v2 7/8] qemu/bswap: Use compiler __builtin_bswap() on NetBSD

Quoted 5 lines · Peter Maydell
Quoted 3 lines · Kamil Rytarowski

Personally, I prefer using the system headers. but if you want to use the GCC builtins, please go for it.

Quoted 9 lines

I'd agree if the system header approach was cross-platform or if this was a BSD-only program or if we were aiming for complete compiler-implementation independence, but since we rely on GCC/clang all over the place already it seems nicer to avoid all the machinery for identifying which of the multiple different system header implementations is present, and instead just have a single implementation that works on all the hosts we care about...

This is already a part of POSIX:

https://www.austingroupbugs.net/view.php?id=162

We have got everything needed from the standard now to implement bswap without relying on compiler builtins. Every modern enough POSIX-like OS already ships with <endian.h>.

Quoted 3 lines

thanks
-- PMM

#22 lore raw

RFC PATCH v2 8/8 tests/vm: Add Haiku test based on their vagrant images

In reply to Philippe Mathieu-Daudé

From: Alexander von Gluck IV <[email protected]>

[PMD: Avoid to recreate the image each time]

---
RFC because Alexander will probably add more comments to this patch.

 tests/keys/vagrant        |  27 +++++++++
 tests/keys/vagrant.pub    |   1 +
 tests/vm/Makefile.include |   3 +-
 tests/vm/basevm.py        |   5 +-
 tests/vm/haiku.x86_64     | 116 ++++++++++++++++++++++++++++++++++++++
 5 files changed, 149 insertions(+), 3 deletions(-)
 create mode 100644 tests/keys/vagrant
 create mode 100644 tests/keys/vagrant.pub
 create mode 100755 tests/vm/haiku.x86_64
tests/keys/vagrant new file +27 -0
new file mode 100644
index 00000000000..7d6a083909e
@@ -0,0 +1,27 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIIEogIBAAKCAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzI
+w+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoP
+kcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2
+hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NO
+Td0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcW
+yLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQIBIwKCAQEA4iqWPJXtzZA68mKd
+ELs4jJsdyky+ewdZeNds5tjcnHU5zUYE25K+ffJED9qUWICcLZDc81TGWjHyAqD1
+Bw7XpgUwFgeUJwUlzQurAv+/ySnxiwuaGJfhFM1CaQHzfXphgVml+fZUvnJUTvzf
+TK2Lg6EdbUE9TarUlBf/xPfuEhMSlIE5keb/Zz3/LUlRg8yDqz5w+QWVJ4utnKnK
+iqwZN0mwpwU7YSyJhlT4YV1F3n4YjLswM5wJs2oqm0jssQu/BT0tyEXNDYBLEF4A
+sClaWuSJ2kjq7KhrrYXzagqhnSei9ODYFShJu8UWVec3Ihb5ZXlzO6vdNQ1J9Xsf
+4m+2ywKBgQD6qFxx/Rv9CNN96l/4rb14HKirC2o/orApiHmHDsURs5rUKDx0f9iP
+cXN7S1uePXuJRK/5hsubaOCx3Owd2u9gD6Oq0CsMkE4CUSiJcYrMANtx54cGH7Rk
+EjFZxK8xAv1ldELEyxrFqkbE4BKd8QOt414qjvTGyAK+OLD3M2QdCQKBgQDtx8pN
+CAxR7yhHbIWT1AH66+XWN8bXq7l3RO/ukeaci98JfkbkxURZhtxV/HHuvUhnPLdX
+3TwygPBYZFNo4pzVEhzWoTtnEtrFueKxyc3+LjZpuo+mBlQ6ORtfgkr9gBVphXZG
+YEzkCD3lVdl8L4cw9BVpKrJCs1c5taGjDgdInQKBgHm/fVvv96bJxc9x1tffXAcj
+3OVdUN0UgXNCSaf/3A/phbeBQe9xS+3mpc4r6qvx+iy69mNBeNZ0xOitIjpjBo2+
+dBEjSBwLk5q5tJqHmy/jKMJL4n9ROlx93XS+njxgibTvU6Fp9w+NOFD/HvxB3Tcz
+6+jJF85D5BNAG3DBMKBjAoGBAOAxZvgsKN+JuENXsST7F89Tck2iTcQIT8g5rwWC
+P9Vt74yboe2kDT531w8+egz7nAmRBKNM751U/95P9t88EDacDI/Z2OwnuFQHCPDF
+llYOUI+SpLJ6/vURRbHSnnn8a/XG+nzedGH5JGqEJNQsz+xT2axM0/W/CRknmGaJ
+kda/AoGANWrLCz708y7VYgAtW2Uf1DPOIYMdvo6fxIB5i9ZfISgcJ/bbCUkFrhoH
++vq/5CIWxCPp0f85R4qxxQ5ihxJ0YDQT9Jpx4TMss4PSavPaBH3RXow5Ohe+bYoQ
+NE5OgEXk2wVfZczCZpigBKbKZHNYcelXtTt/nP3rsCuGcM4h53s=
+-----END RSA PRIVATE KEY-----
tests/keys/vagrant.pub new file +1 -0
new file mode 100644
index 00000000000..b8d012d787f
@@ -0,0 +1 @@
+ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ== well-known vagrant key for qemu-test, do not use on any machine exposed to an external network
tests/vm/Makefile.include +2 -1
index 61f893ffdc0..e94d95ec541 100644
@@ -4,7 +4,7 @@
 
 EFI_AARCH64 = $(wildcard $(BUILD_DIR)/pc-bios/edk2-aarch64-code.fd)
 
-IMAGES := freebsd netbsd openbsd centos fedora
+IMAGES := freebsd netbsd openbsd centos fedora haiku.x86_64
 ifneq ($(GENISOIMAGE),)
 IMAGES += ubuntu.i386 centos
 ifneq ($(EFI_AARCH64),)
@@ -41,6 +41,7 @@ endif
 else
 	@echo "  (install genisoimage to build centos/ubuntu images)"
 endif
+	@echo "  vm-build-haiku.x86_64           - Build QEMU in Haiku VM"
 	@echo ""
 	@echo "  vm-build-all                    - Build QEMU in all VMs"
 	@echo "  vm-clean-all                    - Clean up VM images"
tests/vm/basevm.py +3 -2
index 3fac20e929a..00f1d5ca8da 100644
@@ -44,6 +44,7 @@
     'machine'         : 'pc',
     'guest_user'      : "qemu",
     'guest_pass'      : "qemupass",
+    'root_user'       : "root",
     'root_pass'       : "qemupass",
     'ssh_key_file'    : SSH_KEY_FILE,
     'ssh_pub_key_file': SSH_PUB_KEY_FILE,
@@ -245,13 +246,13 @@ def ssh(self, *cmd):
         return self._ssh_do(self._config["guest_user"], cmd, False)
 
     def ssh_root(self, *cmd):
-        return self._ssh_do("root", cmd, False)
+        return self._ssh_do(self._config["root_user"], cmd, False)
 
     def ssh_check(self, *cmd):
         self._ssh_do(self._config["guest_user"], cmd, True)
 
     def ssh_root_check(self, *cmd):
-        self._ssh_do("root", cmd, True)
+        self._ssh_do(self._config["root_user"], cmd, True)
 
     def build_image(self, img):
         raise NotImplementedError
tests/vm/haiku.x86_64 new file +116 -0

116 lines not on this page · raw message

Signature · 1 line
2.26.2