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.48 with_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/ Pierrick Bouvier (3): hw/virtio: add virtio_vdev_is_{modern, legacy} hw/virtio: rename virtio_is_big_endian to virtio_vdev_is_big_endian hw/virtio: remove virtio_access_is_big_endian include/hw/virtio/virtio-access.h | 43 +++++++++---------------------- include/hw/virtio/virtio.h | 14 ++++++++-- hw/net/virtio-net.c | 6 ++--- hw/virtio/vhost.c | 6 ++--- hw/virtio/virtio-pci.c | 10 +++---- hw/virtio/virtio.c | 20 +++++++------- 6 files changed, 45 insertions(+), 54 deletions(-) -- 2.47.3
