On 10/10/2025 6:42 AM, Philippe Mathieu-Daudé wrote:
Replace compile-time #ifdef with a runtime check to ensure all code
paths are built and tested. This reduces build-time configuration
complexity and improves maintainability.

No functional change intended.

Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
---
  include/hw/virtio/virtio-access.h | 6 +-----
  hw/virtio/vhost.c                 | 7 +++----
  2 files changed, 4 insertions(+), 9 deletions(-)

diff --git a/include/hw/virtio/virtio-access.h 
b/include/hw/virtio/virtio-access.h
index 07aae69042a..80328912ad3 100644
--- a/include/hw/virtio/virtio-access.h
+++ b/include/hw/virtio/virtio-access.h
@@ -149,11 +149,7 @@ static inline uint64_t virtio_ldq_p(VirtIODevice *vdev, 
const void *ptr)
static inline uint16_t virtio_tswap16(VirtIODevice *vdev, uint16_t s)
  {
-#if HOST_BIG_ENDIAN
-    return virtio_access_is_big_endian(vdev) ? s : bswap16(s);
-#else
-    return virtio_access_is_big_endian(vdev) ? bswap16(s) : s;
-#endif
+    return HOST_BIG_ENDIAN ^ virtio_access_is_big_endian(vdev) ? s : 
bswap16(s);

This patch breaks virtio devices(at least input/net devices) on s390x. I am not sure if ^ is the right check here? Changing the logic back to how it was fixes it for me.

Thanks

Farhan

  }
static inline uint16_t virtio_lduw_phys_cached(VirtIODevice *vdev,
diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
index 266a11514a1..6343477b42f 100644
--- a/hw/virtio/vhost.c
+++ b/hw/virtio/vhost.c
@@ -1168,11 +1168,10 @@ static inline bool 
vhost_needs_vring_endian(VirtIODevice *vdev)
      if (virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)) {
          return false;
      }
-#if HOST_BIG_ENDIAN
-    return vdev->device_endian == VIRTIO_DEVICE_ENDIAN_LITTLE;
-#else
+    if (HOST_BIG_ENDIAN) {
+        return vdev->device_endian == VIRTIO_DEVICE_ENDIAN_LITTLE;
+    }
      return vdev->device_endian == VIRTIO_DEVICE_ENDIAN_BIG;
-#endif
  }
static int vhost_virtqueue_set_vring_endian_legacy(struct vhost_dev *dev,

Reply via email to