hw/virtio/virtio-access.h: remove target specific code
v2 cover hw/virtio/virtio-access.h: remove target specific code
v2:
- Rebased
- Removed virtio_vdev_is_modern (Zoltan, myself)
- Include Stefan's Acked-by tag
- Include "make compilation unit common" patches from [3]
This series eliminates some target specifics in hw/virtio and replace them with runtime functions where needed, to be able to link virtio code in single-binary. After a first try on a series [0] doing this change and making all virtio files common, Richard asked to refactor this part, thus this independent series.
By diving into virtio initialization, I noticed that device_endian is always storing endianness of cpu associated on device reset. The root issue, is when dealing with target who dynamically change their endianness during execution. ppc64 is the main use case, as cpu always boot in BE and most of OS use LE. arm use case is more limited, as big endian systems are mostly dead nowadays.
Because of this, initialization is tricky, and goes through different hoops to have the expected value. My first approach has been to try to change this, by simply setting endianness on the first access. However, it fell flat, because current_cpu is not always available at this time.
A second approach was to set endianness to LE by default, and change it only when setting device features, and potentially discovering it's a legacy virtio device. It brought other issues, that showed that current initialization code, even though it's complex, does the right thing.
Thus, I focused on refactoring virtio_access_is_big_endian, and noticed that it was not even needed at this point.
Patches 1 and 2 are refactoring names to clear some confusion. Patch 3 eliminates virtio_access_is_big_endian, with a lenghty commit message explaining the change. By doing this, we remove target specifics from hw/virtio/virtio-access.h.
Of course, performance has been tested, and it is on par with upstream/master.
Results are on 20 runs and expressed in kIOPS:
reference: mean=239.2 std_dev=3.48with_series: mean=238.1 std_dev=3.56
---
Performance has been measured with this automated fio benchmark [1], with original instructions from Stefan [2].
Download artifacts and run benchmark with:
$ wget https://github.com/pbo-linaro/qemu-linux-stack/releases/download/build/x86_64_io_benchmark-a55f2d6.tar.xz $ tar xvf x86_64_io_benchmark-a55f2d6.tar.xz $ ./run.sh /path/to/qemu-system-x86_64
[0] https://lore.kernel.org/qemu-devel/[email protected]/
[1] https://github.com/pbo-linaro/qemu-linux-stack/tree/x86_64_io_benchmark
[2] https://lore.kernel.org/qemu-devel/20260202185233.GC405548@fedora/
[3] https://lore.kernel.org/qemu-devel/[email protected]/
Pierrick Bouvier (6):
hw/virtio: Add virtio_vdev_is_legacy() hw/virtio: Simplify virtio_access_is_big_endian() hw/virtio: Inline virtio_access_is_big_endian() hw/virtio/vhost-user: make compilation unit common hw/virtio/virtio-qmp: make compilation unit common hw/virtio/: make all compilation units common
include/hw/virtio/virtio-access.h | 43 ++++++------------- include/hw/virtio/virtio.h | 7 +++- hw/virtio/vhost-user.c | 11 ++--- hw/virtio/vhost.c | 12 +++--- hw/virtio/virtio-pci.c | 6 +-- hw/virtio/virtio-qmp.c | 70 ------------------------------- hw/virtio/virtio.c | 12 +++--- hw/9pfs/meson.build | 2 +- hw/block/meson.build | 4 +- hw/char/meson.build | 2 +- hw/net/meson.build | 2 +- hw/scsi/meson.build | 6 +-- hw/virtio/meson.build | 17 ++++---- 13 files changed, 50 insertions(+), 144 deletions(-)
Signature · 1 line
2.52.0
PATCH v2 1/6 hw/virtio: Add virtio_vdev_is_legacy()
From: Pierrick Bouvier <[email protected]>
This simplifies code compared to having virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1) or !virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1).
--- include/hw/virtio/virtio-access.h | 2 +- include/hw/virtio/virtio.h | 7 ++++++- hw/virtio/vhost.c | 12 +++++------- hw/virtio/virtio-pci.c | 6 +++--- hw/virtio/virtio.c | 8 ++++---- 5 files changed, 19 insertions(+), 16 deletions(-)
include/hw/virtio/virtio-access.h +1 -1
@@ -30,7 +30,7 @@ static inline bool virtio_access_is_big_endian(VirtIODevice *vdev)#if defined(LEGACY_VIRTIO_IS_BIENDIAN )return virtio_vdev_is_big_endian (vdev);#elif TARGET_BIG_ENDIAN -if (virtio_vdev_has_feature (vdev,VIRTIO_F_VERSION_1 )) { +if (!virtio_vdev_is_legacy (vdev)) {/* Devices conforming to VIRTIO 1.0 or later are always LE. */ return false; }
include/hw/virtio/virtio.h +6 -1
@@ -468,9 +468,14 @@ static inline bool virtio_host_has_feature(VirtIODevice *vdev,return virtio_has_feature (vdev->host_features, fbit); } +static inline bool virtio_vdev_is_legacy (const VirtIODevice *vdev) +{ +return !virtio_vdev_has_feature (vdev,VIRTIO_F_VERSION_1 ); +} +static inline bool virtio_vdev_is_big_endian (const VirtIODevice *vdev) { -if (!virtio_vdev_has_feature (vdev,VIRTIO_F_VERSION_1 )) { +if (virtio_vdev_is_legacy (vdev)) {assert (vdev->device_endian !=VIRTIO_DEVICE_ENDIAN_UNKNOWN );return vdev->device_endian ==VIRTIO_DEVICE_ENDIAN_BIG ; }
hw/virtio/vhost.c +5 -7
@@ -1168,14 +1168,12 @@ static void vhost_log_stop(MemoryListener *listener,*/ static inline bool vhost_needs_vring_endian (VirtIODevice *vdev) { -if (virtio_vdev_has_feature (vdev,VIRTIO_F_VERSION_1 )) { -return false; +if (virtio_vdev_is_legacy (vdev)) { +return vdev->device_endian == (HOST_BIG_ENDIAN + ?VIRTIO_DEVICE_ENDIAN_LITTLE + :VIRTIO_DEVICE_ENDIAN_BIG ); } -#if HOST_BIG_ENDIAN -return vdev->device_endian ==VIRTIO_DEVICE_ENDIAN_LITTLE ; -#else -return vdev->device_endian ==VIRTIO_DEVICE_ENDIAN_BIG ; -#endif +return false; } static int vhost_virtqueue_set_vring_endian_legacy(struct vhost_dev *dev,
hw/virtio/virtio-pci.c +3 -3
@@ -1449,11 +1449,11 @@ static bool virtio_pci_queue_enabled(DeviceState *d, int n)VirtIOPCIProxy *proxy =VIRTIO_PCI (d);VirtIODevice *vdev =virtio_bus_get_device (&proxy->bus); -if (virtio_vdev_has_feature (vdev,VIRTIO_F_VERSION_1 )) { -return proxy->vqs[n].enabled; +if (virtio_vdev_is_legacy (vdev)) { +return virtio_queue_enabled_legacy (vdev, n); } -return virtio_queue_enabled_legacy (vdev, n); +return proxy->vqs[n].enabled; } static int virtio_pci_add_mem_cap(VirtIOPCIProxy *proxy,
hw/virtio/virtio.c +4 -4
@@ -2753,7 +2753,7 @@ static bool virtio_device_endian_needed(void *opaque)VirtIODevice *vdev = opaque;assert (vdev->device_endian !=VIRTIO_DEVICE_ENDIAN_UNKNOWN ); -if (!virtio_vdev_has_feature (vdev,VIRTIO_F_VERSION_1 )) { +if (virtio_vdev_is_legacy (vdev)) {return vdev->device_endian !=virtio_default_endian (); }/* Devices conforming to VIRTIO 1.0 or later are always LE. */
@@ -3460,10 +3460,10 @@ virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)* to calculate used and avail ring addresses based on the desc * address. */ -if (virtio_vdev_has_feature (vdev,VIRTIO_F_VERSION_1 )) { -virtio_init_region_cache (vdev, i); - }else { +if (virtio_vdev_is_legacy (vdev)) {virtio_queue_update_rings (vdev, i); + }else { +virtio_init_region_cache (vdev, i); }if (virtio_vdev_has_feature (vdev,VIRTIO_F_RING_PACKED )) {
Signature · 1 line
2.52.0
Re: [PATCH v2 1/6] hw/virtio: Add virtio_vdev_is_legacy()
Quoted 9 lines · Philippe Mathieu-Daudé
From: Pierrick Bouvier<[email protected]>
This simplifies code compared to having
virtio_vdev_has_feature(vdev, VIRTIO_F_VERSION_1)or !virtio_vdev_has_feature(vdev,VIRTIO_F_VERSION_1).Acked-by Stefan Hajnoczi<[email protected]>Signed-off-by Pierrick Bouvier<[email protected]>Signed-off-by Philippe Mathieu-Daudé<[email protected]>
Quoted 7 lines
--- include/hw/virtio/virtio-access.h | 2 +- include/hw/virtio/virtio.h | 7 ++++++- hw/virtio/vhost.c | 12 +++++------- hw/virtio/virtio-pci.c | 6 +++--- hw/virtio/virtio.c | 8 ++++---- 5 files changed, 19 insertions(+), 16 deletions(-)
r~
PATCH v2 2/6 hw/virtio: Simplify virtio_access_is_big_endian()
In reply to Philippe Mathieu-DaudéFrom: Pierrick Bouvier <[email protected]>
Thanks to previous refactoring, we can see more easily it is strictly equivalent to always call virtio_vdev_is_big_endian.
static inline bool virtio_vdev_is_big_endian(VirtIODevice *vdev)
{
if (virtio_vdev_is_legacy(vdev)) {
assert(vdev->device_endian != VIRTIO_DEVICE_ENDIAN_UNKNOWN);
return vdev->device_endian == VIRTIO_DEVICE_ENDIAN_BIG;
}
/* Devices conforming to VIRTIO 1.0 or later are always LE. */
return false;
}The key is to understand that vdev->device_endian is initialized as expected. It always contains cpu endianness, and not device endianness, ignoring if device is legacy or not.
By default, it's initialized to vdev->device_endian = virtio_default_endian(), which matches target default endianness. Then, on virtio_reset, it will be initialized with current_cpu endianness (if there is one current_cpu).
void virtio_reset() {
...
if (current_cpu) {
/* Guest initiated reset */
vdev->device_endian = virtio_current_cpu_endian();
} else {
/* System reset */
vdev->device_endian = virtio_default_endian();
}Now, we can see how existing virtio_access_is_big_endian is equivalent to virtio_vdev_is_big_endian. Let's break the existing function in its 3 variants, and compare that to virtio_vdev_is_big_endian.
static inline bool virtio_access_is_big_endian(VirtIODevice *vdev)
- #if defined(LEGACY_VIRTIO_IS_BIENDIAN)
return virtio_vdev_is_big_endian(vdev);
This is the exact replacement we did, so equivalent.
- #elif TARGET_BIG_ENDIAN
if (!virtio_vdev_is_legacy(vdev)) {
return false;
}
return true; we know target_is_big_endian(), so vdev->device_endian == VIRTIO_DEVICE_ENDIAN_BIG.
if (virtio_vdev_is_legacy(vdev)) {
return VIRTIO_DEVICE_ENDIAN_BIG == VIRTIO_DEVICE_ENDIAN_BIG; }
return false;
It's written in opposite style compared to existing code (if legacy vs if modern), but it's strictly equivalent.
- #else
return false;
we know !target_is_big_endian(), so
vdev->device_endian == VIRTIO_DEVICE_ENDIAN_LITTLE.
if virtio_vdev_is_legacy(vdev) {
return VIRTIO_DEVICE_ENDIAN_LITTLE == VIRTIO_DEVICE_ENDIAN_BIG; }
return false;
So it always return false, as expected.
--- include/hw/virtio/virtio-access.h | 14 -------------- 1 file changed, 14 deletions(-)
include/hw/virtio/virtio-access.h +0 -14
@@ -21,23 +21,9 @@#include "hw/virtio/virtio.h" #include "hw/virtio/virtio-bus.h" -#if defined(TARGET_PPC64 ) || defined(TARGET_ARM ) -#define LEGACY_VIRTIO_IS_BIENDIAN 1 -#endif -static inline bool virtio_access_is_big_endian (VirtIODevice *vdev) { -#if defined(LEGACY_VIRTIO_IS_BIENDIAN )return virtio_vdev_is_big_endian (vdev); -#elif TARGET_BIG_ENDIAN -if (!virtio_vdev_is_legacy (vdev)) { -/* Devices conforming to VIRTIO 1.0 or later are always LE. */ -return false; - } -return true; -#else -return false; -#endif }static inline void virtio_stw_p (VirtIODevice *vdev,void *ptr,uint16_t v)
Signature · 1 line
2.52.0
Re: [PATCH v2 2/6] hw/virtio: Simplify virtio_access_is_big_endian()
Quoted 66 lines · Philippe Mathieu-Daudé
From: Pierrick Bouvier <[email protected]>
Thanks to previous refactoring, we can see more easily it is strictly equivalent to always call
virtio_vdev_is_big_endian.static inline bool
virtio_vdev_is_big_endian(VirtIODevice *vdev){ if (virtio_vdev_is_legacy(vdev)) { assert(vdev->device_endian != VIRTIO_DEVICE_ENDIAN_UNKNOWN); return vdev->device_endian == VIRTIO_DEVICE_ENDIAN_BIG; } /* Devices conforming to VIRTIO 1.0 or later are always LE. */ return false; }The key is to understand that
vdev->device_endianis initialized as expected. It always contains cpu endianness, and not device endianness, ignoring if device is legacy or not.By default, it's initialized to
vdev->device_endian=virtio_default_endian(), which matches target default endianness. Then, onvirtio_reset, it will be initialized withcurrent_cpuendianness (if there is onecurrent_cpu).void virtio_reset() { ... if (current_cpu) { /* Guest initiated reset */ vdev->device_endian = virtio_current_cpu_endian(); } else { /* System reset */ vdev->device_endian = virtio_default_endian(); }Now, we can see how existing
virtio_access_is_big_endianis equivalent tovirtio_vdev_is_big_endian. Let's break the existing function in its 3 variants, and compare that tovirtio_vdev_is_big_endian.static inline bool
virtio_access_is_big_endian(VirtIODevice *vdev)
- #ifdefined(LEGACY_VIRTIO_IS_BIENDIAN)return virtio_vdev_is_big_endian(vdev); This is the exact replacement we did, so equivalent. - #elif TARGET_BIG_ENDIAN if (!virtio_vdev_is_legacy(vdev)) { return false; } return true;we know target_is_big_endian(), so vdev->device_endian == VIRTIO_DEVICE_ENDIAN_BIG. if (virtio_vdev_is_legacy(vdev)) { return VIRTIO_DEVICE_ENDIAN_BIG == VIRTIO_DEVICE_ENDIAN_BIG; } return false; It's written in opposite style compared to existing code (if legacy vs if modern), but it's strictly equivalent. - #else return false; we know !target_is_big_endian(), so vdev->device_endian == VIRTIO_DEVICE_ENDIAN_LITTLE. if virtio_vdev_is_legacy(vdev) { return VIRTIO_DEVICE_ENDIAN_LITTLE == VIRTIO_DEVICE_ENDIAN_BIG;}
return false;
So it always return false, as expected.
Quoted 7 lines
Signed-off-by Pierrick Bouvier <[email protected]>Reviewed-by Philippe Mathieu-Daudé <[email protected]>Acked-by Stefan Hajnoczi <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- include/hw/virtio/virtio-access.h | 14 -------------- 1 file changed, 14 deletions(-)
r~
Quoted 29 lines
include/hw/virtio/virtio-access.h +0
-14@@ -21,23 +21,9 @@#include "hw/virtio/virtio.h" #include "hw/virtio/virtio-bus.h" -#if defined(TARGET_PPC64 ) || defined(TARGET_ARM ) -#define LEGACY_VIRTIO_IS_BIENDIAN 1 -#endif -static inline bool virtio_access_is_big_endian (VirtIODevice *vdev) { -#if defined(LEGACY_VIRTIO_IS_BIENDIAN )return virtio_vdev_is_big_endian (vdev); -#elif TARGET_BIG_ENDIAN -if (!virtio_vdev_is_legacy (vdev)) { -/* Devices conforming to VIRTIO 1.0 or later are always LE. */ -return false; - } -return true; -#else -return false; -#endif }static inline void virtio_stw_p (VirtIODevice *vdev,void *ptr,uint16_t v)
PATCH v2 3/6 hw/virtio: Inline virtio_access_is_big_endian()
In reply to Philippe Mathieu-DaudéFrom: Pierrick Bouvier <[email protected]>
--- include/hw/virtio/virtio-access.h | 29 ++++++++++++----------------- hw/virtio/virtio.c | 4 ++-- 2 files changed, 14 insertions(+), 19 deletions(-)
include/hw/virtio/virtio-access.h +12 -17
@@ -21,14 +21,9 @@#include "hw/virtio/virtio.h" #include "hw/virtio/virtio-bus.h" -static inline bool virtio_access_is_big_endian (VirtIODevice *vdev) -{ -return virtio_vdev_is_big_endian (vdev); -} -static inline void virtio_stw_p (VirtIODevice *vdev,void *ptr,uint16_t v) { -if (virtio_access_is_big_endian (vdev)) { +if (virtio_vdev_is_big_endian (vdev)) {stw_be_p (ptr, v); }else {stw_le_p (ptr, v);
@@ -37,7 +32,7 @@ static inline void virtio_stw_p(VirtIODevice *vdev, void *ptr, uint16_t v)static inline void virtio_stl_p (VirtIODevice *vdev,void *ptr,uint32_t v) { -if (virtio_access_is_big_endian (vdev)) { +if (virtio_vdev_is_big_endian (vdev)) {stl_be_p (ptr, v); }else {stl_le_p (ptr, v);
@@ -46,7 +41,7 @@ static inline void virtio_stl_p(VirtIODevice *vdev, void *ptr, uint32_t v)static inline void virtio_stq_p (VirtIODevice *vdev,void *ptr,uint64_t v) { -if (virtio_access_is_big_endian (vdev)) { +if (virtio_vdev_is_big_endian (vdev)) {stq_be_p (ptr, v); }else {stq_le_p (ptr, v);
@@ -55,7 +50,7 @@ static inline void virtio_stq_p(VirtIODevice *vdev, void *ptr, uint64_t v)static inline int virtio_lduw_p (VirtIODevice *vdev,const void *ptr) { -if (virtio_access_is_big_endian (vdev)) { +if (virtio_vdev_is_big_endian (vdev)) {return lduw_be_p (ptr); }else {return lduw_le_p (ptr);
@@ -64,7 +59,7 @@ static inline int virtio_lduw_p(VirtIODevice *vdev, const void *ptr)static inline int virtio_ldl_p (VirtIODevice *vdev,const void *ptr) { -if (virtio_access_is_big_endian (vdev)) { +if (virtio_vdev_is_big_endian (vdev)) {return ldl_be_p (ptr); }else {return ldl_le_p (ptr);
@@ -73,7 +68,7 @@ static inline int virtio_ldl_p(VirtIODevice *vdev, const void *ptr)static inline uint64_t virtio_ldq_p (VirtIODevice *vdev,const void *ptr) { -if (virtio_access_is_big_endian (vdev)) { +if (virtio_vdev_is_big_endian (vdev)) {return ldq_be_p (ptr); }else {return ldq_le_p (ptr);
@@ -83,9 +78,9 @@ 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); +return virtio_vdev_is_big_endian (vdev) ? s :bswap16 (s);#else -return virtio_access_is_big_endian (vdev) ?bswap16 (s) : s; +return virtio_vdev_is_big_endian (vdev) ?bswap16 (s) : s;#endif }
@@ -97,9 +92,9 @@ static inline void virtio_tswap16s(VirtIODevice *vdev, uint16_t *s)static inline uint32_t virtio_tswap32 (VirtIODevice *vdev,uint32_t s) {#if HOST_BIG_ENDIAN -return virtio_access_is_big_endian (vdev) ? s :bswap32 (s); +return virtio_vdev_is_big_endian (vdev) ? s :bswap32 (s);#else -return virtio_access_is_big_endian (vdev) ?bswap32 (s) : s; +return virtio_vdev_is_big_endian (vdev) ?bswap32 (s) : s;#endif }
@@ -111,9 +106,9 @@ static inline void virtio_tswap32s(VirtIODevice *vdev, uint32_t *s)static inline uint64_t virtio_tswap64 (VirtIODevice *vdev,uint64_t s) {#if HOST_BIG_ENDIAN -return virtio_access_is_big_endian (vdev) ? s :bswap64 (s); +return virtio_vdev_is_big_endian (vdev) ? s :bswap64 (s);#else -return virtio_access_is_big_endian (vdev) ?bswap64 (s) : s; +return virtio_vdev_is_big_endian (vdev) ?bswap64 (s) : s;#endif }
hw/virtio/virtio.c +2 -2
@@ -222,7 +222,7 @@ static inline uint16_t virtio_lduw_phys_cached(VirtIODevice *vdev,MemoryRegionCache *cache, hwaddr pa) { - if (virtio_access_is_big_endian(vdev)) { + if (virtio_vdev_is_big_endian(vdev)) { return lduw_be_phys_cached(cache, pa); }return lduw_le_phys_cached (cache, pa);
@@ -232,7 +232,7 @@ static inline void virtio_stw_phys_cached(VirtIODevice *vdev,MemoryRegionCache *cache, hwaddr pa, uint16_t value) { - if (virtio_access_is_big_endian(vdev)) { + if (virtio_vdev_is_big_endian(vdev)) {stw_be_phys_cached (cache ,pa ,value ); } else {stw_le_phys_cached (cache, pa, value);
Signature · 1 line
2.52.0
Re: [PATCH v2 3/6] hw/virtio: Inline virtio_access_is_big_endian()
Quoted 10 lines · Philippe Mathieu-Daudé
From: Pierrick Bouvier<[email protected]>
Signed-off-by Pierrick Bouvier<[email protected]>Reviewed-by Philippe Mathieu-Daudé<[email protected]>Acked-by Stefan Hajnoczi<[email protected]>Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- include/hw/virtio/virtio-access.h | 29 ++++++++++++----------------- hw/virtio/virtio.c | 4 ++-- 2 files changed, 14 insertions(+), 19 deletions(-)
r~
PATCH v2 4/6 hw/virtio/vhost-user: make compilation unit common
In reply to Philippe Mathieu-DaudéFrom: Pierrick Bouvier <[email protected]>
PPC architectures use a custom value for VHOST_USER_MAX_RAM_SLOTS (32 instead of 512).
vhost_user struct and several functions use VHOST_USER_MAX_RAM_SLOTS to define stack allocated buffers. To avoid changing all functions to use heap allocated buffers, we keep this max, and simply add a target_base_ppc() conditional for the single place where size really matters.
--- hw/virtio/vhost-user.c | 11 ++++------- hw/virtio/meson.build | 3 +-- 2 files changed, 5 insertions(+), 9 deletions(-)
hw/virtio/vhost-user.c +4 -7
@@ -44,13 +44,8 @@#define VHOST_USER_F_PROTOCOL_FEATURES 30#define VHOST_USER_BACKEND_MAX_FDS 8 -#if defined(TARGET_PPC ) || defined(TARGET_PPC64 ) -#include "hw/ppc/spapr.h" -#define VHOST_USER_MAX_RAM_SLOTS SPAPR_MAX_RAM_SLOTS - -#else +#include "hw/ppc/spapr_common.h" #define VHOST_USER_MAX_RAM_SLOTS 512 -#endif /* * Maximum size of virtio device config space
@@ -2287,7 +2282,9 @@ static int vhost_user_backend_init(struct vhost_dev *dev, void *opaque,return -EINVAL ; } - u->user->memory_slots =MIN (ram_slots,VHOST_USER_MAX_RAM_SLOTS ); +const uint64_t vhost_user_max_ram_slots =target_base_ppc () ? +SPAPR_MAX_RAM_SLOTS :VHOST_USER_MAX_RAM_SLOTS ; + u->user->memory_slots =MIN (ram_slots, vhost_user_max_ram_slots); } }
hw/virtio/meson.build +1 -2
@@ -17,8 +17,7 @@ if have_vhost system_virtio_ss.add(files('vhost.c')) system_virtio_ss.add(files('vhost-backend.c', 'vhost-iova-tree.c')) if have_vhost_user - # fixme - this really should be generic - specific_virtio_ss.add(files('vhost-user.c')) + system_virtio_ss.add(files('vhost-user.c')) system_virtio_ss.add(files('vhost-user-base.c')) # MMIO Stubs
Signature · 1 line
2.52.0
PATCH v2 5/6 hw/virtio/virtio-qmp: make compilation unit common
In reply to Philippe Mathieu-DaudéFrom: Pierrick Bouvier <[email protected]>
All compile time conditionals have no impact at runtime, since they are representing only possible features for devices present at runtime.
In case they are not present, associated features table will never be used. In case they are present but some features are not, matching bits will never be enabled, so those entries will be unused.
Thus, simply expose everything and call it a day.
--- hw/virtio/virtio-qmp.c | 70 ------------------------------------------ hw/virtio/meson.build | 2 +- 2 files changed, 1 insertion(+), 71 deletions(-)
hw/virtio/virtio-qmp.c +0 -70
@@ -33,21 +33,17 @@#include "standard-headers/linux/virtio_vsock.h" #include "standard-headers/linux/virtio_gpio.h" -#include CONFIG_DEVICES -#define FEATURE_ENTRY (name, desc) (qmp_virtio_feature_map_t) \ { .virtio_bit = name, .feature_desc = desc }/* Virtio transport features mapping */ static const qmp_virtio_feature_map_t virtio_transport_map[] = {/* Virtio device transport features */ -#ifndef VIRTIO_CONFIG_NO_LEGACYFEATURE_ENTRY (VIRTIO_F_NOTIFY_ON_EMPTY , \"VIRTIO_F_NOTIFY_ON_EMPTY: Notify when device runs out of avail. " "descs. on VQ" ),FEATURE_ENTRY (VIRTIO_F_ANY_LAYOUT , \"VIRTIO_F_ANY_LAYOUT: Device accepts arbitrary desc. layouts" ), -#endif /* !VIRTIO_CONFIG_NO_LEGACY */FEATURE_ENTRY (VIRTIO_F_VERSION_1 , \"VIRTIO_F_VERSION_1: Device compliant for v1 spec (legacy)" ), FEATURE_ENTRY(VIRTIO_F_IOMMU_PLATFORM, \
@@ -149,7 +145,6 @@ static const qmp_virtio_feature_map_t virtio_config_status_map[] = { };/* virtio-blk features mapping */ -#ifdef CONFIG_VIRTIO_BLK static const qmp_virtio_feature_map_t virtio_blk_feature_map[] = {FEATURE_ENTRY (VIRTIO_BLK_F_SIZE_MAX , \"VIRTIO_BLK_F_SIZE_MAX: Max segment size is size_max" ),
@@ -173,7 +168,6 @@ static const qmp_virtio_feature_map_t virtio_blk_feature_map[] = { "VIRTIO_BLK_F_SECURE_ERASE: Secure erase supported"),FEATURE_ENTRY (VIRTIO_BLK_F_ZONED , \"VIRTIO_BLK_F_ZONED: Zoned block devices" ), -#ifndef VIRTIO_BLK_NO_LEGACYFEATURE_ENTRY (VIRTIO_BLK_F_BARRIER , \"VIRTIO_BLK_F_BARRIER: Request barriers supported" ), FEATURE_ENTRY(VIRTIO_BLK_F_SCSI, \
@@ -183,7 +177,6 @@ static const qmp_virtio_feature_map_t virtio_blk_feature_map[] = {FEATURE_ENTRY (VIRTIO_BLK_F_CONFIG_WCE , \"VIRTIO_BLK_F_CONFIG_WCE: Cache writeback and writethrough modes " "supported" ), -#endif /* !VIRTIO_BLK_NO_LEGACY */FEATURE_ENTRY (VHOST_F_LOG_ALL , \"VHOST_F_LOG_ALL: Logging write descriptors supported" ), FEATURE_ENTRY(VHOST_USER_F_PROTOCOL_FEATURES, \
@@ -191,10 +184,8 @@ static const qmp_virtio_feature_map_t virtio_blk_feature_map[] = { "negotiation supported"), { -1, "" } }; -#endif /* virtio-serial features mapping */ -#ifdef CONFIG_VIRTIO_SERIAL static const qmp_virtio_feature_map_t virtio_serial_feature_map[] = {FEATURE_ENTRY (VIRTIO_CONSOLE_F_SIZE , \"VIRTIO_CONSOLE_F_SIZE: Host providing console size" ),
@@ -204,10 +195,8 @@ static const qmp_virtio_feature_map_t virtio_serial_feature_map[] = { "VIRTIO_CONSOLE_F_EMERG_WRITE: Emergency write supported"), { -1, "" } }; -#endif /* virtio-gpu features mapping */ -#ifdef CONFIG_VIRTIO_GPU static const qmp_virtio_feature_map_t virtio_gpu_feature_map[] = {FEATURE_ENTRY (VIRTIO_GPU_F_VIRGL , \"VIRTIO_GPU_F_VIRGL: Virgl 3D mode supported" ),
@@ -227,10 +216,8 @@ static const qmp_virtio_feature_map_t virtio_gpu_feature_map[] = { "negotiation supported"), { -1, "" } }; -#endif /* virtio-input features mapping */ -#ifdef CONFIG_VIRTIO_INPUT static const qmp_virtio_feature_map_t virtio_input_feature_map[] = {FEATURE_ENTRY (VHOST_F_LOG_ALL , \"VHOST_F_LOG_ALL: Logging write descriptors supported" ),
@@ -239,10 +226,8 @@ static const qmp_virtio_feature_map_t virtio_input_feature_map[] = { "negotiation supported"), { -1, "" } }; -#endif /* virtio-net features mapping */ -#ifdef CONFIG_VIRTIO_NETstatic const qmp_virtio_feature_map_t virtio_net_feature_map[] = { FEATURE_ENTRY(VIRTIO_NET_F_CSUM, \ "VIRTIO_NET_F_CSUM: Device handling packets with partial checksum "
@@ -313,10 +298,8 @@ static const qmp_virtio_feature_map_t virtio_net_feature_map[] = { "device with same MAC addr. supported"),FEATURE_ENTRY (VIRTIO_NET_F_SPEED_DUPLEX , \"VIRTIO_NET_F_SPEED_DUPLEX: Device set linkspeed and duplex" ), -#ifndef VIRTIO_NET_NO_LEGACYFEATURE_ENTRY (VIRTIO_NET_F_GSO , \"VIRTIO_NET_F_GSO: Handling GSO-type packets supported" ), -#endif /* !VIRTIO_NET_NO_LEGACY */FEATURE_ENTRY (VHOST_NET_F_VIRTIO_NET_HDR , \"VHOST_NET_F_VIRTIO_NET_HDR: Virtio-net headers for RX and TX " "packets supported"),
@@ -341,10 +324,8 @@ static const qmp_virtio_feature_map_t virtio_net_feature_map[] = { "header"), { -1, "" } }; -#endif /* virtio-scsi features mapping */ -#ifdef CONFIG_VIRTIO_SCSIstatic const qmp_virtio_feature_map_t virtio_scsi_feature_map[] = { FEATURE_ENTRY(VIRTIO_SCSI_F_INOUT, \ "VIRTIO_SCSI_F_INOUT: Requests including read and writable data "
@@ -364,10 +345,8 @@ static const qmp_virtio_feature_map_t virtio_scsi_feature_map[] = { "negotiation supported"), { -1, "" } }; -#endif /* virtio/vhost-user-fs features mapping */ -#ifdef CONFIG_VHOST_USER_FS static const qmp_virtio_feature_map_t virtio_fs_feature_map[] = {FEATURE_ENTRY (VHOST_F_LOG_ALL , \"VHOST_F_LOG_ALL: Logging write descriptors supported" ),
@@ -376,10 +355,8 @@ static const qmp_virtio_feature_map_t virtio_fs_feature_map[] = { "negotiation supported"), { -1, "" } }; -#endif /* virtio/vhost-user-i2c features mapping */ -#ifdef CONFIG_VIRTIO_I2C_ADAPTER static const qmp_virtio_feature_map_t virtio_i2c_feature_map[] = {FEATURE_ENTRY (VIRTIO_I2C_F_ZERO_LENGTH_REQUEST , \"VIRTIO_I2C_F_ZERO_LEGNTH_REQUEST: Zero length requests supported" ),
@@ -390,10 +367,8 @@ static const qmp_virtio_feature_map_t virtio_i2c_feature_map[] = { "negotiation supported"), { -1, "" } }; -#endif /* virtio/vhost-vsock features mapping */ -#ifdef CONFIG_VHOST_VSOCK static const qmp_virtio_feature_map_t virtio_vsock_feature_map[] = {FEATURE_ENTRY (VIRTIO_VSOCK_F_SEQPACKET , \"VIRTIO_VSOCK_F_SEQPACKET: SOCK_SEQPACKET supported" ),
@@ -404,10 +379,8 @@ static const qmp_virtio_feature_map_t virtio_vsock_feature_map[] = { "negotiation supported"), { -1, "" } }; -#endif /* virtio-balloon features mapping */ -#ifdef CONFIG_VIRTIO_BALLOONstatic const qmp_virtio_feature_map_t virtio_balloon_feature_map[] = { FEATURE_ENTRY(VIRTIO_BALLOON_F_MUST_TELL_HOST, \ "VIRTIO_BALLOON_F_MUST_TELL_HOST: Tell host before reclaiming "
@@ -424,19 +397,15 @@ static const qmp_virtio_feature_map_t virtio_balloon_feature_map[] = { "VIRTIO_BALLOON_F_REPORTING: Page reporting VQ enabled"), { -1, "" } }; -#endif /* virtio-crypto features mapping */ -#ifdef CONFIG_VIRTIO_CRYPTO static const qmp_virtio_feature_map_t virtio_crypto_feature_map[] = {FEATURE_ENTRY (VHOST_F_LOG_ALL , \"VHOST_F_LOG_ALL: Logging write descriptors supported" ), {-1 ,"" } }; -#endif /* virtio-iommu features mapping */ -#ifdef CONFIG_VIRTIO_IOMMUstatic const qmp_virtio_feature_map_t virtio_iommu_feature_map[] = { FEATURE_ENTRY(VIRTIO_IOMMU_F_INPUT_RANGE, \ "VIRTIO_IOMMU_F_INPUT_RANGE: Range of available virtual addrs. "
@@ -458,15 +427,11 @@ static const qmp_virtio_feature_map_t virtio_iommu_feature_map[] = { "available"), { -1, "" } }; -#endif /* virtio-mem features mapping */ -#ifdef CONFIG_VIRTIO_MEM static const qmp_virtio_feature_map_t virtio_mem_feature_map[] = { -#ifndef CONFIG_ACPIFEATURE_ENTRY (VIRTIO_MEM_F_ACPI_PXM , \"VIRTIO_MEM_F_ACPI_PXM: node_id is an ACPI PXM and is valid" ), -#endif /* !CONFIG_ACPI */FEATURE_ENTRY (VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE , \"VIRTIO_MEM_F_UNPLUGGED_INACCESSIBLE: Unplugged memory cannot be " "accessed" ),
@@ -475,10 +440,8 @@ static const qmp_virtio_feature_map_t virtio_mem_feature_map[] = { "plugged when suspending+resuming"), { -1, "" } }; -#endif /* virtio-rng features mapping */ -#ifdef CONFIG_VIRTIO_RNG static const qmp_virtio_feature_map_t virtio_rng_feature_map[] = {FEATURE_ENTRY (VHOST_F_LOG_ALL , \"VHOST_F_LOG_ALL: Logging write descriptors supported" ),
@@ -487,10 +450,8 @@ static const qmp_virtio_feature_map_t virtio_rng_feature_map[] = { "negotiation supported"), { -1, "" } }; -#endif /* virtio/vhost-gpio features mapping */ -#ifdef CONFIG_VHOST_USER_GPIO static const qmp_virtio_feature_map_t virtio_gpio_feature_map[] = {FEATURE_ENTRY (VIRTIO_GPIO_F_IRQ , \"VIRTIO_GPIO_F_IRQ: Device supports interrupts on GPIO lines" ),
@@ -499,7 +460,6 @@ static const qmp_virtio_feature_map_t virtio_gpio_feature_map[] = { "negotiation supported"), { -1, "" } }; -#endif #define CONVERT_FEATURES (type, map, is_status, bitmap) \ ({ \
@@ -595,96 +555,66 @@ VirtioDeviceFeatures *qmp_decode_features(uint16_t device_id,/* device features */ switch (device_id) { -#ifdef CONFIG_VIRTIO_SERIAL case VIRTIO_ID_CONSOLE : features->dev_features =CONVERT_FEATURES_EX (strList, virtio_serial_feature_map, bitmap);break ; -#endif -#ifdef CONFIG_VIRTIO_BLK case VIRTIO_ID_BLOCK : features->dev_features =CONVERT_FEATURES_EX (strList, virtio_blk_feature_map, bitmap);break ; -#endif -#ifdef CONFIG_VIRTIO_GPU case VIRTIO_ID_GPU : features->dev_features =CONVERT_FEATURES_EX (strList, virtio_gpu_feature_map, bitmap);break ; -#endif -#ifdef CONFIG_VIRTIO_NET case VIRTIO_ID_NET : features->dev_features =CONVERT_FEATURES_EX (strList, virtio_net_feature_map, bitmap);break ; -#endif -#ifdef CONFIG_VIRTIO_SCSI case VIRTIO_ID_SCSI : features->dev_features =CONVERT_FEATURES_EX (strList, virtio_scsi_feature_map, bitmap);break ; -#endif -#ifdef CONFIG_VIRTIO_BALLOON case VIRTIO_ID_BALLOON : features->dev_features =CONVERT_FEATURES_EX (strList, virtio_balloon_feature_map, bitmap);break ; -#endif -#ifdef CONFIG_VIRTIO_IOMMU case VIRTIO_ID_IOMMU : features->dev_features =CONVERT_FEATURES_EX (strList, virtio_iommu_feature_map, bitmap);break ; -#endif -#ifdef CONFIG_VIRTIO_INPUT case VIRTIO_ID_INPUT : features->dev_features =CONVERT_FEATURES_EX (strList, virtio_input_feature_map, bitmap);break ; -#endif -#ifdef CONFIG_VHOST_USER_FS case VIRTIO_ID_FS : features->dev_features =CONVERT_FEATURES_EX (strList, virtio_fs_feature_map, bitmap);break ; -#endif -#ifdef CONFIG_VHOST_VSOCK case VIRTIO_ID_VSOCK : features->dev_features =CONVERT_FEATURES_EX (strList, virtio_vsock_feature_map, bitmap);break ; -#endif -#ifdef CONFIG_VIRTIO_CRYPTO case VIRTIO_ID_CRYPTO : features->dev_features =CONVERT_FEATURES_EX (strList, virtio_crypto_feature_map, bitmap);break ; -#endif -#ifdef CONFIG_VIRTIO_MEM case VIRTIO_ID_MEM : features->dev_features =CONVERT_FEATURES_EX (strList, virtio_mem_feature_map, bitmap);break ; -#endif -#ifdef CONFIG_VIRTIO_I2C_ADAPTER case VIRTIO_ID_I2C_ADAPTER : features->dev_features =CONVERT_FEATURES_EX (strList, virtio_i2c_feature_map, bitmap);break ; -#endif -#ifdef CONFIG_VIRTIO_RNG case VIRTIO_ID_RNG : features->dev_features =CONVERT_FEATURES_EX (strList, virtio_rng_feature_map, bitmap);break ; -#endif -#ifdef CONFIG_VHOST_USER_GPIO case VIRTIO_ID_GPIO : features->dev_features =CONVERT_FEATURES_EX (strList, virtio_gpio_feature_map, bitmap);break ; -#endif /* No features */ case VIRTIO_ID_9P :case VIRTIO_ID_PMEM :
hw/virtio/meson.build +1 -1
@@ -11,7 +11,7 @@ system_virtio_ss.add(when: 'CONFIG_VHOST_VDPA_DEV', if_true: files('vdpa-dev.c') specific_virtio_ss = ss.source_set() specific_virtio_ss.add(files('virtio.c')) -specific_virtio_ss.add(files('virtio-qmp.c')) +system_virtio_ss.add(files('virtio-qmp.c')) if have_vhost system_virtio_ss.add(files('vhost.c'))
Signature · 1 line
2.52.0
Re: [PATCH v2 5/6] hw/virtio/virtio-qmp: make compilation unit common
Quoted 9 lines · Philippe Mathieu-Daudé
From: Pierrick Bouvier<[email protected]>
All compile time conditionals have no impact at runtime, since they are representing only possible features for devices present at runtime.
In case they are not present, associated features table will never be used. In case they are present but some features are not, matching bits will never be enabled, so those entries will be unused.
Quoted 8 lines
Thus, simply expose everything and call it a day.
Signed-off-by Pierrick Bouvier<[email protected]>Signed-off-by Philippe Mathieu-Daudé<[email protected]>--- hw/virtio/virtio-qmp.c | 70 ------------------------------------------ hw/virtio/meson.build | 2 +- 2 files changed, 1 insertion(+), 71 deletions(-)
r~
PATCH v2 6/6 hw/virtio/: make all compilation units common
In reply to Philippe Mathieu-DaudéFrom: Pierrick Bouvier <[email protected]>
--- hw/9pfs/meson.build | 2 +- hw/block/meson.build | 4 ++-- hw/char/meson.build | 2 +- hw/net/meson.build | 2 +- hw/scsi/meson.build | 6 ++---- hw/virtio/meson.build | 12 +++++------- 6 files changed, 12 insertions(+), 16 deletions(-)
hw/9pfs/meson.build +1 -1
@@ -23,4 +23,4 @@ endif fs_ss.add(when: 'CONFIG_XEN_BUS', if_true: files('xen-9p-backend.c')) system_ss.add_all(when: 'CONFIG_FSDEV_9P', if_true: fs_ss) -specific_ss.add(when: 'CONFIG_VIRTIO_9P', if_true: files('virtio-9p-device.c')) +system_ss.add(when: 'CONFIG_VIRTIO_9P', if_true: files('virtio-9p-device.c'))
hw/block/meson.build +2 -2
@@ -13,9 +13,9 @@ system_ss.add(when: 'CONFIG_SSI_M25P80', if_true: files('m25p80_sfdp.c')) system_ss.add(when: 'CONFIG_SWIM', if_true: files('swim.c')) system_ss.add(when: 'CONFIG_XEN_BUS', if_true: files('xen-block.c')) -specific_ss.add(when: 'CONFIG_VIRTIO_BLK', if_true: files('virtio-blk.c')) +system_ss.add(when: 'CONFIG_VIRTIO_BLK', if_true: files('virtio-blk.c')) system_ss.add(when: 'CONFIG_VIRTIO_BLK', if_true: files('virtio-blk-common.c')) -specific_ss.add(when: 'CONFIG_VHOST_USER_BLK', if_true: files('vhost-user-blk.c')) +system_ss.add(when: 'CONFIG_VHOST_USER_BLK', if_true: files('vhost-user-blk.c')) system_ss.add(when: 'CONFIG_VHOST_USER_BLK', if_true: files('virtio-blk-common.c')) subdir('dataplane')
hw/char/meson.build +1 -1
@@ -17,6 +17,7 @@ system_ss.add(when: 'CONFIG_SERIAL_MM', if_true: files('serial-mm.c')) system_ss.add(when: 'CONFIG_SERIAL_PCI', if_true: files('serial-pci.c')) system_ss.add(when: 'CONFIG_SERIAL_PCI_MULTI', if_true: files('serial-pci-multi.c')) system_ss.add(when: 'CONFIG_SHAKTI_UART', if_true: files('shakti_uart.c')) +system_ss.add(when: 'CONFIG_VIRTIO', if_true: files('virtio-serial-bus.c')) system_ss.add(when: 'CONFIG_VIRTIO_SERIAL', if_true: files('virtio-console.c')) system_ss.add(when: 'CONFIG_XEN_BUS', if_true: files('xen_console.c')) system_ss.add(when: 'CONFIG_XILINX', if_true: files('xilinx_uartlite.c'))
@@ -39,5 +40,4 @@ system_ss.add(when: 'CONFIG_HTIF', if_true: files('riscv_htif.c')) system_ss.add(when: 'CONFIG_GOLDFISH_TTY', if_true: files('goldfish_tty.c')) specific_ss.add(when: 'CONFIG_TERMINAL3270', if_true: files('terminal3270.c')) -specific_ss.add(when: 'CONFIG_VIRTIO', if_true: files('virtio-serial-bus.c')) specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr_vty.c'))
hw/net/meson.build +1 -1
@@ -46,7 +46,7 @@ specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr_llan.c')) system_ss.add(when: 'CONFIG_XILINX_ETHLITE', if_true: files('xilinx_ethlite.c')) system_ss.add(when: 'CONFIG_VIRTIO_NET', if_true: files('net_rx_pkt.c')) -specific_ss.add(when: 'CONFIG_VIRTIO_NET', if_true: files('virtio-net.c')) +system_ss.add(when: 'CONFIG_VIRTIO_NET', if_true: files('virtio-net.c')) if have_vhost_net system_ss.add(when: 'CONFIG_VIRTIO_NET', if_true: files('vhost_net.c'), if_false: files('vhost_net-stub.c'))
hw/scsi/meson.build +2 -4
@@ -1,7 +1,6 @@ scsi_ss = ss.source_set() specific_scsi_ss = ss.source_set() virtio_scsi_ss = ss.source_set() -specific_virtio_scsi_ss = ss.source_set() scsi_ss.add(files( 'emulation.c',
@@ -21,10 +20,9 @@ virtio_scsi_ss.add(files('virtio-scsi-dataplane.c')) virtio_scsi_ss.add(when: 'CONFIG_VHOST_SCSI', if_true: files('vhost-scsi.c')) virtio_scsi_ss.add(when: 'CONFIG_VHOST_USER_SCSI', if_true: files('vhost-user-scsi.c')) -specific_virtio_scsi_ss.add(files('virtio-scsi.c')) -specific_virtio_scsi_ss.add(when: 'CONFIG_VHOST_SCSI_COMMON', if_true: files('vhost-scsi-common.c')) +virtio_scsi_ss.add(files('virtio-scsi.c')) +virtio_scsi_ss.add(when: 'CONFIG_VHOST_SCSI_COMMON', if_true: files('vhost-scsi-common.c')) -specific_scsi_ss.add_all(when: 'CONFIG_VIRTIO_SCSI', if_true: specific_virtio_scsi_ss) scsi_ss.add_all(when: 'CONFIG_VIRTIO_SCSI', if_true: virtio_scsi_ss) specific_scsi_ss.add(when: 'CONFIG_SPAPR_VSCSI', if_true: files('spapr_vscsi.c'))
hw/virtio/meson.build +5 -7
@@ -9,8 +9,7 @@ system_virtio_ss.add(when: 'CONFIG_VHOST_VSOCK_COMMON', if_true: files('vhost-vs system_virtio_ss.add(when: 'CONFIG_VIRTIO_IOMMU', if_true: files('virtio-iommu.c')) system_virtio_ss.add(when: 'CONFIG_VHOST_VDPA_DEV', if_true: files('vdpa-dev.c')) -specific_virtio_ss = ss.source_set() -specific_virtio_ss.add(files('virtio.c')) +system_virtio_ss.add(files('virtio.c')) system_virtio_ss.add(files('virtio-qmp.c')) if have_vhost
@@ -53,10 +52,10 @@ endif system_virtio_ss.add(when: 'CONFIG_VHOST_USER_VSOCK', if_true: files('vhost-user-vsock.c')) system_virtio_ss.add(when: 'CONFIG_VIRTIO_RNG', if_true: files('virtio-rng.c')) -specific_virtio_ss.add(when: 'CONFIG_VIRTIO_BALLOON', if_true: files('virtio-balloon.c')) -specific_virtio_ss.add(when: 'CONFIG_VHOST_USER_FS', if_true: files('vhost-user-fs.c')) -specific_virtio_ss.add(when: 'CONFIG_VIRTIO_PMEM', if_true: files('virtio-pmem.c')) -specific_virtio_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock.c')) +system_virtio_ss.add(when: 'CONFIG_VIRTIO_BALLOON', if_true: files('virtio-balloon.c')) +system_virtio_ss.add(when: 'CONFIG_VHOST_USER_FS', if_true: files('vhost-user-fs.c')) +system_virtio_ss.add(when: 'CONFIG_VIRTIO_PMEM', if_true: files('virtio-pmem.c')) +system_virtio_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock.c')) system_virtio_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-mem.c')) system_virtio_ss.add(when: 'CONFIG_VIRTIO_NSM', if_true: files('virtio-nsm.c')) system_virtio_ss.add(when: 'CONFIG_VIRTIO_NSM', if_true: [files('cbor-helpers.c'), libcbor])
@@ -97,5 +96,4 @@ stub_ss.add(files('virtio-md-stubs.c')) system_ss.add(files('virtio-hmp-cmds.c')) -specific_ss.add_all(when: 'CONFIG_VIRTIO', if_true: specific_virtio_ss) system_ss.add(when: 'CONFIG_ACPI', if_true: files('virtio-acpi.c'))
Signature · 1 line
2.52.0
Quoted 62 lines · Philippe Mathieu-Daudé
v2:
- Rebased
- Removedvirtio_vdev_is_modern(Zoltan, myself)
- Include Stefan's Acked-by tag
- Include "make compilation unit common" patches from [3]This series eliminates some target specifics in hw/virtio and replace them with runtime functions where needed, to be able to link virtio code in single-binary. After a first try on a series [0] doing this change and making all virtio files common, Richard asked to refactor this part, thus this independent series.
By diving into virtio initialization, I noticed that
device_endianis always storing endianness of cpu associated on device reset. The root issue, is when dealing with target who dynamically change their endianness during execution. ppc64 is the main use case, as cpu always boot in BE and most of OS use LE. arm use case is more limited, as big endian systems are mostly dead nowadays.Because of this, initialization is tricky, and goes through different hoops to have the expected value. My first approach has been to try to change this, by simply setting endianness on the first access. However, it fell flat, because
current_cpuis not always available at this time.
A second approach was to set endianness to LE by default, and change it only when setting device features, and potentially discovering it's a legacy virtio device. It brought other issues, that showed that current initialization code, even though it's complex, does the right thing.
Thus, I focused on refactoringvirtio_access_is_big_endian, and noticed that it was not even needed at this point.Patches 1 and 2 are refactoring names to clear some confusion. Patch 3 eliminates
virtio_access_is_big_endian, with a lenghty commit message explaining the change. By doing this, we remove target specifics fromhw/virtio/virtio-access.h.Of course, performance has been tested, and it is on par with upstream/master.
Results are on 20 runs and expressed in kIOPS:
reference: mean=239.2 std_dev=3.48with_series: mean=238.1 std_dev=3.56---
Performance has been measured with this automated fio benchmark [1], with original instructions from Stefan [2].
Download artifacts and run benchmark with:
$ wget https://github.com/pbo-linaro/qemu-linux-stack/releases/download/build/x86_64_io_benchmark-a55f2d6.tar.xz $ tar xvf x86_64_io_benchmark-a55f2d6.tar.xz $ ./run.sh /path/to/qemu-system-x86_64[0] https://lore.kernel.org/qemu-devel/[email protected]/
[1] https://github.com/pbo-linaro/qemu-linux-stack/tree/x86_64_io_benchmark
[2] https://lore.kernel.org/qemu-devel/20260202185233.GC405548@fedora/
[3] https://lore.kernel.org/qemu-devel/[email protected]/Pierrick Bouvier (6):
hw/virtio: Addvirtio_vdev_is_legacy()hw/virtio: Simplifyvirtio_access_is_big_endian()hw/virtio: Inlinevirtio_access_is_big_endian()hw/virtio/vhost-user: make compilation unit common hw/virtio/virtio-qmp: make compilation unit common hw/virtio/: make all compilation units common
Quoted 15 lines
include/hw/virtio/virtio-access.h | 43 ++++++------------- include/hw/virtio/virtio.h | 7 +++- hw/virtio/vhost-user.c | 11 ++--- hw/virtio/vhost.c | 12 +++--- hw/virtio/virtio-pci.c | 6 +-- hw/virtio/virtio-qmp.c | 70 ------------------------------- hw/virtio/virtio.c | 12 +++--- hw/9pfs/meson.build | 2 +- hw/block/meson.build | 4 +- hw/char/meson.build | 2 +- hw/net/meson.build | 2 +- hw/scsi/meson.build | 6 +-- hw/virtio/meson.build | 17 ++++---- 13 files changed, 50 insertions(+), 144 deletions(-)
This was merged into master (2940018747e31842cf34334394c7d32517e73fbd).
Regards,
Pierrick