virtio-gpio and various virtio cleanups
Subsystems (2)
v3 cover virtio-gpio and various virtio cleanups
Hi,
After much slogging through the vhost-user code I've gotten the virtio-gpio device working again. The core change in pushing the responsibility for VHOST_USER_F_PROTOCOL_FEATURES down to the vhost-user layer (which knows it needs it). We still need to account for that in virtio-gpio because the result of the negotiating protocol features is the vrings start disabled so the stub needs to explicitly enable them. I did consider pushing this behaviour explicitly into vhost_dev_start but that would have required un-picking it from vhost-net (which is the only other device which uses protocol features AFAICT - but is a measure more complex in it's setup).
As last time there are a whole series of clean-ups and doc tweaks. I don't know if any are trivial enough to sneak into later RCs but it shouldn't be a problem to wait until the tree re-opens.
There is a remaining issue that a --enable-sanitizers build fails for qos-test due to leaks. It shows up as a leak from:
Direct leak of 240 byte(s) in 1 object(s) allocated from:
#0 0x7fc5a3f2a037 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154
#1 0x7fc5a2e5cda0 in g_malloc0 ../../../glib/gmem.c:136
#2 0x55ce773cc728 in virtio_device_realize ../../hw/virtio/virtio.c:3691
#3 0x55ce7784ed7e in device_set_realized ../../hw/core/qdev.c:553
#4 0x55ce77862d0c in property_set_bool ../../qom/object.c:2273 I'm not entirely sure what the allocation is because it gets inlined in the virtio_device_realize call. Perhaps it's the QOM object itself which is never gracefully torn down at the end of the test?
However when I attempted to bisect I found master was broken as well. For example in my arm/aarch64-softmmu build we see 5 failures:
Summary of Failures:
3/48 qemu:qtest+qtest-aarch64 / qtest-aarch64/migration-test ERROR 96.15s killed by signal 6 SIGABRT 9/48 qemu:qtest+qtest-aarch64 / qtest-aarch64/qos-test ERROR 32.50s killed by signal 6 SIGABRT 11/48 qemu:qtest+qtest-arm / qtest-arm/qos-test ERROR 26.93s killed by signal 6 SIGABRT 20/48 qemu:qtest+qtest-aarch64 / qtest-aarch64/device-introspect-test ERROR 5.17s killed by signal 6 SIGABRT 45/48 qemu:qtest+qtest-arm / qtest-arm/device-introspect-test ERROR 4.97s killed by signal 6 SIGABRT
Of which the qos-tests are the only new ones. I suspect something must be preventing the other stuff being exercised in our CI system.
Alex Bennée (19):
include/hw/virtio: more comment for VIRTIO_F_BAD_FEATURE include/hw: document vhost_dev feature life-cycle hw/virtio: fix some coding style issues
hw/virtio: log potentially buggy guest drivers block/vhost-user-blk-server: don't expose
VHOST_USER_F_PROTOCOL_FEATURES
hw/virtio: incorporate backend features in features hw/virtio: gracefully handle unset vhost_dev vdev hw/virtio: handle un-configured shutdown in virtio-pci hw/virtio: fix vhost_user_read tracepoint
hw/virtio: add some vhost-user trace events tests/qtest: pass stdout/stderr down to subtests tests/qtest: add a timeout for subprocess_run_one_test tests/qtest: use qos_printf instead of g_test_message tests/qtest: catch unhandled vhost-user messages tests/qtest: plain g_assert for VHOST_USER_F_PROTOCOL_FEATURES tests/qtest: add assert to catch bad features tests/qtest: implement stub for VHOST_USER_GET_CONFIG tests/qtest: add a get_features op to vhost-user-test tests/qtest: enable tests for virtio-gpio
Viresh Kumar (2):
hw/virtio: add boilerplate for vhost-user-gpio device hw/virtio: add vhost-user-gpio-pci boilerplate
include/hw/virtio/vhost-user-gpio.h | 35 +++ include/hw/virtio/vhost.h | 3 + include/hw/virtio/virtio.h | 7 +- tests/qtest/libqos/virtio-gpio.h | 35 +++ block/export/vhost-user-blk-server.c | 3 +- hw/virtio/vhost-user-gpio-pci.c | 69 +++++ hw/virtio/vhost-user-gpio.c | 414 +++++++++++++++++++++++++++ hw/virtio/vhost-user.c | 20 +- hw/virtio/vhost.c | 16 +- hw/virtio/virtio-pci.c | 9 +- hw/virtio/virtio.c | 7 + tests/qtest/libqos/virtio-gpio.c | 171 +++++++++++ tests/qtest/libqos/virtio.c | 4 +- tests/qtest/qos-test.c | 8 +- tests/qtest/vhost-user-test.c | 172 +++++++++-- hw/virtio/Kconfig | 5 + hw/virtio/meson.build | 2 + hw/virtio/trace-events | 9 + tests/qtest/libqos/meson.build | 1 + 19 files changed, 956 insertions(+), 34 deletions(-) create mode 100644 include/hw/virtio/vhost-user-gpio.h create mode 100644 tests/qtest/libqos/virtio-gpio.h create mode 100644 hw/virtio/vhost-user-gpio-pci.c create mode 100644 hw/virtio/vhost-user-gpio.c create mode 100644 tests/qtest/libqos/virtio-gpio.c
Signature · 1 line
2.30.2
PATCH v3 1/21 include/hw/virtio: more comment for VIRTIO_F_BAD_FEATURE
When debugging a new vhost user you may be surprised to see VHOST_USER_F_PROTOCOL getting squashed in the maze of backend_features, acked_features and guest_features. Expand the description here to help the next poor soul trying to work through this.
---
v3
- s/vhost/vhost-user/
--- include/hw/virtio/virtio.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
include/hw/virtio/virtio.h +6 -1
@@ -24,7 +24,12 @@#include "qom/object.h" #include "hw/virtio/vhost.h" -/* A guest should never accept this. It implies negotiation is broken. */ +/* +* A guest should never accept this. It implies negotiation is broken +* between the driver frontend and the device. This bit is re-used for +* vhost-user to advertise VHOST_USER_F_PROTOCOL_FEATURES between QEMU +* and a vhost-user backend. +*/ #define VIRTIO_F_BAD_FEATURE 30#define VIRTIO_LEGACY_FEATURES ((0x1ULL << VIRTIO_F_BAD_FEATURE) | \
Signature · 1 line
2.30.2
PATCH v3 2/21 include/hw: document vhost_dev feature life-cycle
In reply to Alex BennéeTry and explicitly document the various state of feature bits as related to the vhost_dev structure. Importantly the backend_features can advertise things like VHOST_USER_F_PROTOCOL_FEATURES which is never exposed to the driver and is only present in the vhost-user feature negotiation.
--- include/hw/virtio/vhost.h | 3 +++ 1 file changed, 3 insertions(+)
include/hw/virtio/vhost.h +3 -0
@@ -86,8 +86,11 @@ struct vhost_dev {/* if non-zero, minimum required value for max_queues */ int num_queues;uint64_t features; +/** @acked_features: final set of negotiated features */ uint64_t acked_features; +/** @backend_features: backend specific feature bits */ uint64_t backend_features; +/** @protocol_features: final negotiated protocol features */ uint64_t protocol_features;uint64_t max_queues;uint64_t backend_cap;
Signature · 1 line
2.30.2
Re: [PATCH v3 02/21] include/hw: document vhost_dev feature life-cycle
Quoted 7 lines · Alex Bennée
Try and explicitly document the various state of feature bits as related to the
vhost_devstructure. Importantly thebackend_featurescan advertise things likeVHOST_USER_F_PROTOCOL_FEATURESwhich is never exposed to the driver and is only present in the vhost-user feature negotiation.Signed-off-by Alex Bennée <[email protected]>
Maybe it's better to document backend_cap as well which is only used for vhost-kernel/vdpa.
And in the future we should try to unify them.
Thanks
Quoted 20 lines
--- include/hw/virtio/vhost.h | 3 +++ 1 file changed, 3 insertions(+)include/hw/virtio/vhost.h +3
-0@@ -86,8 +86,11 @@ struct vhost_dev {/* if non-zero, minimum required value for max_queues */ int num_queues;uint64_t features; +/** @acked_features: final set of negotiated features */ uint64_t acked_features; +/** @backend_features: backend specific feature bits */ uint64_t backend_features; +/** @protocol_features: final negotiated protocol features */ uint64_t protocol_features;uint64_t max_queues;uint64_t backend_cap;
Re: [PATCH v3 02/21] include/hw: document vhost_dev feature life-cycle
Quoted 10 lines · Jason Wang
Quoted 7 lines · Alex Bennée
Try and explicitly document the various state of feature bits as related to the
vhost_devstructure. Importantly thebackend_featurescan advertise things likeVHOST_USER_F_PROTOCOL_FEATURESwhich is never exposed to the driver and is only present in the vhost-user feature negotiation.Signed-off-by Alex Bennée <[email protected]>
Quoted 6 lines
Acked-by Jason Wang <[email protected]>Maybe it's better to document
backend_capas well which is only used for vhost-kernel/vdpa.And in the future we should try to unify them.
I'm fairly sure there is a lot of duplication across the various vhost_dev, VirtIO, and individual virtio structures. Documenting is a first step to cleaning that up but ideally we need more coverage to make sure we aren't inadvertently breaking things when we refactor.
Quoted 24 lines
Thanks
Quoted 20 lines
--- include/hw/virtio/vhost.h | 3 +++ 1 file changed, 3 insertions(+)include/hw/virtio/vhost.h +3
-0@@ -86,8 +86,11 @@ struct vhost_dev {/* if non-zero, minimum required value for max_queues */ int num_queues;uint64_t features; +/** @acked_features: final set of negotiated features */ uint64_t acked_features; +/** @backend_features: backend specific feature bits */ uint64_t backend_features; +/** @protocol_features: final negotiated protocol features */ uint64_t protocol_features;uint64_t max_queues;uint64_t backend_cap;
Signature · 1 line
Alex Bennée
PATCH v3 3/21 hw/virtio: fix some coding style issues
In reply to Alex Bennée--- hw/virtio/vhost-user.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
hw/virtio/vhost-user.c +4 -3
@@ -200,7 +200,7 @@ typedef struct {VhostUserRequest request;#define VHOST_USER_VERSION_MASK (0x3) -#define VHOST_USER_REPLY_MASK (0x1<<2) +#define VHOST_USER_REPLY_MASK (0x1 << 2)#define VHOST_USER_NEED_REPLY_MASK (0x1 << 3)uint32_t flags;uint32_t size;/* the following payload size */
@@ -208,7 +208,7 @@ typedef struct { typedef union { #define VHOST_USER_VRING_IDX_MASK (0xff) -#define VHOST_USER_VRING_NOFD_MASK (0x1<<8) +#define VHOST_USER_VRING_NOFD_MASK (0x1 << 8) uint64_t u64; struct vhost_vring_state state; struct vhost_vring_addr addr;
@@ -248,7 +248,8 @@ struct vhost_user {size_t region_rb_len;/* RAMBlock associated with a given region */ RAMBlock **region_rb; -/* The offset from the start of the RAMBlock to the start of the +/* +* The offset from the start of the RAMBlock to the start of the * vhost region. */ ram_addr_t *region_rb_offset;
Signature · 1 line
2.30.2
Re: [PATCH v3 03/21] hw/virtio: fix some coding style issues
Quoted 1 line · Alex Bennée
Signed-off-by Alex Bennée <[email protected]>
Quoted 36 lines
--- hw/virtio/vhost-user.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)hw/virtio/vhost-user.c +4
-3@@ -200,7 +200,7 @@ typedef struct {VhostUserRequest request;#define VHOST_USER_VERSION_MASK (0x3) -#define VHOST_USER_REPLY_MASK (0x1<<2) +#define VHOST_USER_REPLY_MASK (0x1 << 2)#define VHOST_USER_NEED_REPLY_MASK (0x1 << 3)uint32_t flags;uint32_t size;/* the following payload size */ @@ -208,7 +208,7 @@ typedef struct { typedef union { #define VHOST_USER_VRING_IDX_MASK (0xff) -#define VHOST_USER_VRING_NOFD_MASK (0x1<<8) +#define VHOST_USER_VRING_NOFD_MASK (0x1 << 8) uint64_t u64; struct vhost_vring_state state; struct vhost_vring_addr addr;@@ -248,7 +248,8 @@ struct vhost_user {size_t region_rb_len;/* RAMBlock associated with a given region */ RAMBlock **region_rb; -/* The offset from the start of the RAMBlock to the start of the +/* +* The offset from the start of the RAMBlock to the start of the * vhost region. */ ram_addr_t *region_rb_offset;
PATCH v3 4/21 hw/virtio: log potentially buggy guest drivers
In reply to Alex BennéeIf the guest driver attempts to use the UNUSED(30) bit it is potentially buggy as 6.3 Legacy Interface: Reserved Feature Bits states it "SHOULD NOT be negotiated". For now just log this guest error.
--- hw/virtio/virtio.c | 7 +++++++ 1 file changed, 7 insertions(+)
hw/virtio/virtio.c +7 -0
@@ -2980,6 +2980,13 @@ int virtio_set_features(VirtIODevice *vdev, uint64_t val)if (vdev->status &VIRTIO_CONFIG_S_FEATURES_OK ) {return -EINVAL ; } + +if (val & (1ull <<VIRTIO_F_BAD_FEATURE )) { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: guest driver for %s has enabled UNUSED(30) feature bit!\n" , + __func__, vdev->name); + } + ret =virtio_set_features_nocheck (vdev, val);if (virtio_vdev_has_feature (vdev,VIRTIO_RING_F_EVENT_IDX )) {/* VIRTIO_RING_F_EVENT_IDX changes the size of the caches. */
Signature · 1 line
2.30.2
Re: [PATCH v3 04/21] hw/virtio: log potentially buggy guest drivers
Quoted 6 lines · Alex Bennée
If the guest driver attempts to use the UNUSED(30) bit it is potentially buggy as 6.3 Legacy Interface: Reserved Feature Bits states it "SHOULD NOT be negotiated". For now just log this guest error.
Signed-off-by Alex Bennée <[email protected]>
Quoted 22 lines
--- hw/virtio/virtio.c | 7 +++++++ 1 file changed, 7 insertions(+)hw/virtio/virtio.c +7
-0@@ -2980,6 +2980,13 @@ int virtio_set_features(VirtIODevice *vdev, uint64_t val)if (vdev->status &VIRTIO_CONFIG_S_FEATURES_OK ) {return -EINVAL ; } + +if (val & (1ull <<VIRTIO_F_BAD_FEATURE )) { +qemu_log_mask (LOG_GUEST_ERROR , +"%s: guest driver for %s has enabled UNUSED(30) feature bit!\n" , + __func__, vdev->name); + } + ret =virtio_set_features_nocheck (vdev, val);if (virtio_vdev_has_feature (vdev,VIRTIO_RING_F_EVENT_IDX )) {/* VIRTIO_RING_F_EVENT_IDX changes the size of the caches. */
PATCH v3 5/21 block/vhost-user-blk-server: don't expose VHOST_USER_F_PROTOCOL_FEATURES
In reply to Alex BennéeThis bit is unused in actual VirtIO feature negotiation and should only appear in the vhost-user messages between master and slave.
[AJB: experiment, this doesn't break the tests but I'm not super confident of the range of tests]
--- block/export/vhost-user-blk-server.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
block/export/vhost-user-blk-server.c +1 -2
@@ -125,8 +125,7 @@ static uint64_t vu_blk_get_features(VuDev *dev)1ull <<VIRTIO_BLK_F_MQ |1ull <<VIRTIO_F_VERSION_1 |1ull <<VIRTIO_RING_F_INDIRECT_DESC | -1ull <<VIRTIO_RING_F_EVENT_IDX | -1ull <<VHOST_USER_F_PROTOCOL_FEATURES ; +1ull <<VIRTIO_RING_F_EVENT_IDX ;if (!vexp->handler.writable) { features |=1ull <<VIRTIO_BLK_F_RO ;
Signature · 1 line
2.30.2
Re: [PATCH v3 05/21] block/vhost-user-blk-server: don't expose VHOST_USER_F_PROTOCOL_FEATURES
Am 26.07.2022 um 21:21 hat Alex Bennée geschrieben:
Quoted 7 lines
This bit is unused in actual VirtIO feature negotiation and should only appear in the vhost-user messages between master and slave.
[AJB: experiment, this doesn't break the tests but I'm not super confident of the range of tests]
Signed-off-by Alex Bennée <[email protected]>
I guess the rationale is that this doesn't make a difference because vu_get_features_exec(), which is the only caller of .get_features(), adds the VHOST_USER_F_PROTOCOL_FEATURES bit back before sending a response.
Can you please add this to the commit message?
Quoted 8 lines
block/export/vhost-user-blk-server.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)block/export/vhost-user-blk-server.c +0
-0
block/export/vhost-user-blk-server.c static uint64_t vu_blk_get_features(VuDev *dev) · line 128
Quoted 6 lines
block/export/vhost-user-blk-server.c +1
-2@@ -125,8 +125,7 @@ static uint64_t vu_blk_get_features(VuDev *dev)1ull <<VIRTIO_BLK_F_MQ |1ull <<VIRTIO_F_VERSION_1 |1ull <<VIRTIO_RING_F_INDIRECT_DESC | -1ull <<VIRTIO_RING_F_EVENT_IDX | -1ull <<VHOST_USER_F_PROTOCOL_FEATURES ; +1ull <<VIRTIO_RING_F_EVENT_IDX ;
This has an extra space before the semicolon.
Kevin
Re: [PATCH v3 05/21] block/vhost-user-blk-server: don't expose VHOST_USER_F_PROTOCOL_FEATURES
In reply to Alex BennéeQuoted 2 lines · Alex Bennée
This bit is unused in actual VirtIO feature negotiation and should only appear in the vhost-user messages between master and slave.
I might be wrong, but this is actually used between master and slave not the device and driver?
Thanks
Quoted 23 lines
[AJB: experiment, this doesn't break the tests but I'm not super confident of the range of tests]
Signed-off-by Alex Bennée <[email protected]>--- block/export/vhost-user-blk-server.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)block/export/vhost-user-blk-server.c +1
-2@@ -125,8 +125,7 @@ static uint64_t vu_blk_get_features(VuDev *dev)1ull <<VIRTIO_BLK_F_MQ |1ull <<VIRTIO_F_VERSION_1 |1ull <<VIRTIO_RING_F_INDIRECT_DESC | -1ull <<VIRTIO_RING_F_EVENT_IDX | -1ull <<VHOST_USER_F_PROTOCOL_FEATURES ; +1ull <<VIRTIO_RING_F_EVENT_IDX ;if (!vexp->handler.writable) { features |=1ull <<VIRTIO_BLK_F_RO ;
Re: [PATCH v3 05/21] block/vhost-user-blk-server: don't expose VHOST_USER_F_PROTOCOL_FEATURES
Quoted 7 lines · Jason Wang
Quoted 2 lines · Alex Bennée
This bit is unused in actual VirtIO feature negotiation and should only appear in the vhost-user messages between master and slave.
I might be wrong, but this is actually used between master and slave not the device and driver?
Argh you may be right. However got confused with grepping:
static const VuDevIface vu_blk_iface = {
.get_features = vu_blk_get_features,
.queue_set_started = vu_blk_queue_set_started,
.get_protocol_features = vu_blk_get_protocol_features,
.get_config = vu_blk_get_config,
.set_config = vu_blk_set_config,
.process_msg = vu_blk_process_msg,
};and this is all part of libvhostuser but vhost-user-blk-server is in the main tree. I guess it isn't moved into tools/ because it also re-uses bits of the block layer?
Anyway I shall drop this patch.
Quoted 26 lines
Thanks
Quoted 22 lines
[AJB: experiment, this doesn't break the tests but I'm not super confident of the range of tests]
Signed-off-by Alex Bennée <[email protected]>--- block/export/vhost-user-blk-server.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)block/export/vhost-user-blk-server.c +1
-2@@ -125,8 +125,7 @@ static uint64_t vu_blk_get_features(VuDev *dev)1ull <<VIRTIO_BLK_F_MQ |1ull <<VIRTIO_F_VERSION_1 |1ull <<VIRTIO_RING_F_INDIRECT_DESC | -1ull <<VIRTIO_RING_F_EVENT_IDX | -1ull <<VHOST_USER_F_PROTOCOL_FEATURES ; +1ull <<VIRTIO_RING_F_EVENT_IDX ;if (!vexp->handler.writable) { features |=1ull <<VIRTIO_BLK_F_RO ;
Signature · 1 line
Alex Bennée
PATCH v3 6/21 hw/virtio: incorporate backend features in features
In reply to Alex BennéeThere are some extra bits used over a vhost-user connection which are hidden from the device itself. We need to set them here to ensure we enable things like the protocol extensions.
Currently net/vhost-user.c has it's own inscrutable way of persisting this data but it really should live in the core vhost_user code.
--- hw/virtio/vhost-user.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
hw/virtio/vhost-user.c +8 -1
@@ -1461,7 +1461,14 @@ static int vhost_user_set_features(struct vhost_dev *dev,*/ bool log_enabled = features & (0x1ULL <<VHOST_F_LOG_ALL ); -return vhost_user_set_u64 (dev,VHOST_USER_SET_FEATURES , features, +/* +* We need to include any extra backend only feature bits that +* might be needed by our device. Currently this includes the +* VHOST_USER_F_PROTOCOL_FEATURES bit for enabling protocol +* features. +*/ +return vhost_user_set_u64 (dev,VHOST_USER_SET_FEATURES , + features | dev->backend_features, log_enabled); }
Signature · 1 line
2.30.2
PATCH v3 7/21 hw/virtio: gracefully handle unset vhost_dev vdev
In reply to Alex BennéeI've noticed asserts firing because we query the status of vdev after a vhost connection is closed down. Rather than faulting on the NULL indirect just quietly reply false.
--- hw/virtio/vhost.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
hw/virtio/vhost.c +7 -3
@@ -306,7 +306,7 @@ static inline void vhost_dev_log_resize(struct vhost_dev *dev, uint64_t size) dev->log_size = size; } -static int vhost_dev_has_iommu (struct vhost_dev *dev) +static bool vhost_dev_has_iommu (struct vhost_dev *dev) {VirtIODevice *vdev = dev->vdev;
@@ -316,8 +316,12 @@ static int vhost_dev_has_iommu(struct vhost_dev *dev)* does not have IOMMU, there's no need to enable this feature * which may cause unnecessary IOTLB miss/update transactions. */ -return virtio_bus_device_iommu_enabled (vdev) && -virtio_host_has_feature (vdev,VIRTIO_F_IOMMU_PLATFORM ); +if (vdev) { +return virtio_bus_device_iommu_enabled (vdev) && +virtio_host_has_feature (vdev,VIRTIO_F_IOMMU_PLATFORM ); + }else { +return false; + } } static void *vhost_memory_map(struct vhost_dev *dev, hwaddr addr,
Signature · 1 line
2.30.2
PATCH v3 8/21 hw/virtio: handle un-configured shutdown in virtio-pci
In reply to Alex BennéeThe assert() protecting against leakage is a little aggressive and causes needless crashes if a device is shutdown without having been configured. In this case no descriptors are lost because none have been assigned.
--- hw/virtio/virtio-pci.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
hw/virtio/virtio-pci.c +7 -2
@@ -996,9 +996,14 @@ static int virtio_pci_set_guest_notifiers(DeviceState *d, int nvqs, bool assign) nvqs =MIN (nvqs,VIRTIO_QUEUE_MAX ); -/* When deassigning, pass a consistent nvqs value -* to avoid leaking notifiers. +/* +* When deassigning, pass a consistent nvqs value to avoid leaking +* notifiers. But first check we've actually been configured, exit +* early if we haven't. */ +if (!assign && !proxy->nvqs_with_notifiers) { +return 0 ; + }assert (assign || nvqs == proxy->nvqs_with_notifiers); proxy->nvqs_with_notifiers = nvqs;
Signature · 1 line
2.30.2
Re: [PATCH v3 08/21] hw/virtio: handle un-configured shutdown in virtio-pci
Quoted 18 lines · Alex Bennée
The
assert()protecting against leakage is a little aggressive and causes needless crashes if a device is shutdown without having been configured. In this case no descriptors are lost because none have been assigned.Signed-off-by Alex Bennée <[email protected]>--- hw/virtio/virtio-pci.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)hw/virtio/virtio-pci.c +0
-0@@ -996,9 +996,14 @@ static int virtio_pci_set_guest_notifiers(DeviceState *d, int nvqs, bool assign) nvqs =MIN (nvqs,VIRTIO_QUEUE_MAX );
hw/virtio/virtio-pci.c static int virtio_pci_set_guest_notifiers(DeviceState *d, int nvqs, bool assign) · line 1006
Quoted 10 lines
hw/virtio/virtio-pci.c +7
-2-/* When deassigning, pass a consistent nvqs value -* to avoid leaking notifiers. +/* +* When deassigning, pass a consistent nvqs value to avoid leaking +* notifiers. But first check we've actually been configured, exit +* early if we haven't. */ +if (!assign && !proxy->nvqs_with_notifiers) { +return 0 ; + }
I think the logic is the caller is in charge of tracking whether the vhost device is started so it can avoid calling this function?
Thanks
Quoted 3 lines
hw/virtio/virtio-pci.c +0
-0assert (assign || nvqs == proxy->nvqs_with_notifiers); proxy->nvqs_with_notifiers = nvqs;
PATCH v3 9/21 hw/virtio: fix vhost_user_read tracepoint
In reply to Alex BennéeAs reads happen in the callback we were never seeing them. We only really care about the header so move the tracepoint to when the header is complete.
--- hw/virtio/vhost-user.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
hw/virtio/vhost-user.c +2 -2
@@ -296,6 +296,8 @@ static int vhost_user_read_header(struct vhost_dev *dev, VhostUserMsg *msg)return -EPROTO ; } +trace_vhost_user_read (msg->hdr.request, msg->hdr.flags); +return 0 ; }
@@ -545,8 +547,6 @@ static int vhost_user_set_log_base(struct vhost_dev *dev, uint64_t base, } } -trace_vhost_user_read (msg.hdr.request, msg.hdr.flags); -return 0 ; }
Signature · 1 line
2.30.2
Re: [PATCH v3 09/21] hw/virtio: fix vhost_user_read tracepoint
Quoted 6 lines · Alex Bennée
As reads happen in the callback we were never seeing them. We only really care about the header so move the tracepoint to when the header is complete.
Fixes 6ca6d8ee9d (hw/virtio: add vhost_user_[read|write] trace points)Signed-off-by Alex Bennée <[email protected]>
Quoted 26 lines
--- hw/virtio/vhost-user.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)hw/virtio/vhost-user.c +2
-2@@ -296,6 +296,8 @@ static int vhost_user_read_header(struct vhost_dev *dev, VhostUserMsg *msg)return -EPROTO ; } +trace_vhost_user_read (msg->hdr.request, msg->hdr.flags); +return 0 ; }@@ -545,8 +547,6 @@ static int vhost_user_set_log_base(struct vhost_dev *dev, uint64_t base, } } -trace_vhost_user_read (msg.hdr.request, msg.hdr.flags); -return 0 ; }
PATCH v3 10/21 hw/virtio: add some vhost-user trace events
In reply to Alex BennéeThese are useful for tracing the lifetime of vhost-user connections.
--- hw/virtio/vhost.c | 6 ++++++ hw/virtio/trace-events | 4 ++++ 2 files changed, 10 insertions(+)
hw/virtio/vhost.c +6 -0
@@ -1477,6 +1477,8 @@ void vhost_dev_cleanup(struct vhost_dev *hdev) {int i; +trace_vhost_dev_cleanup (hdev); +for (i =0 ; i < hdev->nvqs; ++i) {vhost_virtqueue_cleanup (hdev->vqs + i); }
@@ -1783,6 +1785,8 @@ int vhost_dev_start(struct vhost_dev *hdev, VirtIODevice *vdev)/* should only be called after backend is connected */ assert (hdev->vhost_ops); +trace_vhost_dev_start (hdev, vdev->name); + vdev->vhost_started = true; hdev->started = true; hdev->vdev = vdev;
@@ -1869,6 +1873,8 @@ void vhost_dev_stop(struct vhost_dev *hdev, VirtIODevice *vdev)/* should only be called after backend is connected */ assert (hdev->vhost_ops); +trace_vhost_dev_stop (hdev, vdev->name); +if (hdev->vhost_ops->vhost_dev_start) { hdev->vhost_ops->vhost_dev_start (hdev, false); }
hw/virtio/trace-events +4 -0
@@ -8,6 +8,10 @@ vhost_region_add_section_aligned(const char *name, uint64_t gpa, uint64_t size, vhost_section(const char *name) "%s" vhost_reject_section(const char *name, int d) "%s:%d" vhost_iotlb_miss(void *dev, int step) "%p step %d" +vhost_dev_cleanup(void *dev) "%p" +vhost_dev_start(void *dev, const char *name) "%p:%s" +vhost_dev_stop(void *dev, const char *name) "%p:%s" + # vhost-user.c vhost_user_postcopy_end_entry(void) ""
Signature · 1 line
2.30.2
PATCH v3 11/21 hw/virtio: add boilerplate for vhost-user-gpio device
In reply to Alex BennéeFrom: Viresh Kumar <[email protected]>
This creates the QEMU side of the vhost-user-gpio device which connects to the remote daemon. It is based of vhost-user-i2c code.
Message-Id: <5390324a748194a21bc99b1538e19761a8c64092.1641987128.git.viresh.kumar@linaro.org>
---
v2
- set VIRTIO_F_VERSION_1
- set VHOST_USER_F_PROTOCOL_FEATURES
- terminate feature_bits with VHOST_INVALID_FEATURE_BIT
- ensure vdev->backend_features set
- ensure vhost_dev.acked_features set
v3
- break out vhost_dev structure for code flow reasons
- use the vhost-user-blk connection lifecycle code
- follow ->parent_obj style for VHostUserGPIO object
- add all feature bits supported by the rust-vmm backend
- clean-up errp propagation to avoid local_err and use ERRP_GAURD
- s/vhost_dev->features/vdev->guest_features/ when calling vhost_ack_features
- drop VHOST_USER_F_PROTOCOL_FEATURES definition (pushed to vhost-user)
- explicitly call vhost_set_vring_enable due to properly negotiated VHOST_USER_F_PROTOCOL_FEATURES
--- include/hw/virtio/vhost-user-gpio.h | 35 +++ hw/virtio/vhost-user-gpio.c | 414 ++++++++++++++++++++++++++++ hw/virtio/Kconfig | 5 + hw/virtio/meson.build | 1 + hw/virtio/trace-events | 5 + 5 files changed, 460 insertions(+) create mode 100644 include/hw/virtio/vhost-user-gpio.h create mode 100644 hw/virtio/vhost-user-gpio.c
include/hw/virtio/vhost-user-gpio.h new file +35 -0
@@ -0,0 +1,35 @@ +/* +* Vhost-user GPIO virtio device +* +* Copyright (c) 2021 Viresh Kumar <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef _QEMU_VHOST_USER_GPIO_H +#define _QEMU_VHOST_USER_GPIO_H + +#include "hw/virtio/virtio.h" +#include "hw/virtio/vhost.h" +#include "hw/virtio/vhost-user.h" +#include "standard-headers/linux/virtio_gpio.h" +#include "chardev/char-fe.h" + +#define TYPE_VHOST_USER_GPIO "vhost-user-gpio-device" +OBJECT_DECLARE_SIMPLE_TYPE (VHostUserGPIO,VHOST_USER_GPIO ); + +struct VHostUserGPIO { +/*< private >*/ +VirtIODevice parent_obj; +CharBackend chardev; +struct virtio_gpio_config config; +struct vhost_virtqueue *vhost_vq; +struct vhost_dev vhost_dev; +VhostUserState vhost_user; +VirtQueue *command_vq; +VirtQueue *interrupt_vq; +bool connected; +/*< public >*/ +}; + +#endif /* _QEMU_VHOST_USER_GPIO_H */
hw/virtio/vhost-user-gpio.c new file +414 -0
414 lines not on this page · raw message
hw/virtio/Kconfig +5 -0
@@ -80,3 +80,8 @@ config VHOST_USER_FS bool default y depends on VIRTIO && VHOST_USER + +config VHOST_USER_GPIO + bool + default y + depends on VIRTIO && VHOST_USER
hw/virtio/meson.build +1 -0
@@ -29,6 +29,7 @@ virtio_ss.add(when: 'CONFIG_VIRTIO_IOMMU', if_true: files('virtio-iommu.c')) virtio_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-mem.c')) virtio_ss.add(when: 'CONFIG_VHOST_USER_I2C', if_true: files('vhost-user-i2c.c')) virtio_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vhost-user-rng.c')) +virtio_ss.add(when: 'CONFIG_VHOST_USER_GPIO', if_true: files('vhost-user-gpio.c')) virtio_pci_ss = ss.source_set() virtio_pci_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-pci.c'))
hw/virtio/trace-events +5 -0
@@ -144,3 +144,8 @@ virtio_mem_state_response(uint16_t state) "state=%" PRIu16 virtio_pmem_flush_request(void) "flush request" virtio_pmem_response(void) "flush response" virtio_pmem_flush_done(int type) "fsync return=%d" + +# virtio-gpio.c +virtio_gpio_start(void) "start" +virtio_gpio_stop(void) "stop" +virtio_gpio_set_status(uint8_t status) "0x%x"
Signature · 1 line
2.30.2
PATCH v3 12/21 hw/virtio: add vhost-user-gpio-pci boilerplate
In reply to Alex BennéeFrom: Viresh Kumar <[email protected]>
This allows is to instantiate a vhost-user-gpio device as part of a PCI bus. It is mostly boilerplate which looks pretty similar to the vhost-user-fs-pci device.
Message-Id: <5f560cab92d0d789b1c94295ec74b9952907d69d.1641987128.git.viresh.kumar@linaro.org>
--- hw/virtio/vhost-user-gpio-pci.c | 69 +++++++++++++++++++++++++++++++++ hw/virtio/meson.build | 1 + 2 files changed, 70 insertions(+) create mode 100644 hw/virtio/vhost-user-gpio-pci.c
hw/virtio/vhost-user-gpio-pci.c new file +69 -0
@@ -0,0 +1,69 @@ +/* +* Vhost-user gpio virtio device PCI glue +* +* Copyright (c) 2022 Viresh Kumar <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "hw/qdev-properties.h" +#include "hw/virtio/vhost-user-gpio.h" +#include "hw/virtio/virtio-pci.h" + +struct VHostUserGPIOPCI { +VirtIOPCIProxy parent_obj; +VHostUserGPIO vdev; +}; + +typedef struct VHostUserGPIOPCI VHostUserGPIOPCI ; + +#define TYPE_VHOST_USER_GPIO_PCI "vhost-user-gpio-pci-base" + +DECLARE_INSTANCE_CHECKER (VHostUserGPIOPCI,VHOST_USER_GPIO_PCI , + TYPE_VHOST_USER_GPIO_PCI) + +static void vhost_user_gpio_pci_realize (VirtIOPCIProxy *vpci_dev,Error **errp) +{ +VHostUserGPIOPCI *dev =VHOST_USER_GPIO_PCI (vpci_dev); +DeviceState *vdev =DEVICE (&dev->vdev); + + vpci_dev->nvectors =1 ; +qdev_realize (vdev,BUS (&vpci_dev->bus), errp); +} + +static void vhost_user_gpio_pci_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +VirtioPCIClass *k =VIRTIO_PCI_CLASS (klass); +PCIDeviceClass *pcidev_k =PCI_DEVICE_CLASS (klass); + k->realize = vhost_user_gpio_pci_realize; +set_bit (DEVICE_CATEGORY_INPUT , dc->categories); + pcidev_k->vendor_id =PCI_VENDOR_ID_REDHAT_QUMRANET ; + pcidev_k->device_id =0 ;/* Set by virtio-pci based on virtio id */ + pcidev_k->revision =0x00 ; + pcidev_k->class_id =PCI_CLASS_COMMUNICATION_OTHER ; +} + +static void vhost_user_gpio_pci_instance_init (Object *obj) +{ +VHostUserGPIOPCI *dev =VHOST_USER_GPIO_PCI (obj); + +virtio_instance_init_common (obj, &dev->vdev,sizeof (dev->vdev), +TYPE_VHOST_USER_GPIO ); +} + +static const VirtioPCIDeviceTypeInfo vhost_user_gpio_pci_info = { + .base_name =TYPE_VHOST_USER_GPIO_PCI , + .non_transitional_name ="vhost-user-gpio-pci" , + .instance_size =sizeof (VHostUserGPIOPCI), + .instance_init = vhost_user_gpio_pci_instance_init, + .class_init = vhost_user_gpio_pci_class_init, +}; + +static void vhost_user_gpio_pci_register (void ) +{ +virtio_pci_types_register (&vhost_user_gpio_pci_info); +} + +type_init (vhost_user_gpio_pci_register);
hw/virtio/meson.build +1 -0
@@ -30,6 +30,7 @@ virtio_ss.add(when: 'CONFIG_VIRTIO_MEM', if_true: files('virtio-mem.c')) virtio_ss.add(when: 'CONFIG_VHOST_USER_I2C', if_true: files('vhost-user-i2c.c')) virtio_ss.add(when: 'CONFIG_VHOST_USER_RNG', if_true: files('vhost-user-rng.c')) virtio_ss.add(when: 'CONFIG_VHOST_USER_GPIO', if_true: files('vhost-user-gpio.c')) +virtio_ss.add(when: ['CONFIG_VIRTIO_PCI', 'CONFIG_VHOST_USER_GPIO'], if_true: files('vhost-user-gpio-pci.c')) virtio_pci_ss = ss.source_set() virtio_pci_ss.add(when: 'CONFIG_VHOST_VSOCK', if_true: files('vhost-vsock-pci.c'))
Signature · 1 line
2.30.2
PATCH v3 13/21 tests/qtest: pass stdout/stderr down to subtests
In reply to Alex BennéeWhen trying to work out what the virtio-net-tests where doing it was hard because the g_test_trap_subprocess redirects all output to /dev/null. Lift this restriction by using the appropriate flags so you can see something similar to what the vhost-user-blk tests show when running.
Message-Id: <[email protected]>
---
v2
- keep dumping of CLI behind the g_test_verbose flag
--- tests/qtest/qos-test.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
tests/qtest/qos-test.c +2 -1
@@ -185,7 +185,8 @@ static void run_one_test(const void *arg)static void subprocess_run_one_test (const void *arg) {const gchar *path = arg; -g_test_trap_subprocess (path,0 ,0 ); +g_test_trap_subprocess (path,0 , +G_TEST_SUBPROCESS_INHERIT_STDOUT |G_TEST_SUBPROCESS_INHERIT_STDERR );g_test_trap_assert_passed (); }
Signature · 1 line
2.30.2
PATCH v3 14/21 tests/qtest: add a timeout for subprocess_run_one_test
In reply to Alex BennéeHangs have been observed in the tests and currently we don't timeout if a subprocess hangs. Rectify that.
---
v3
- expand timeout to 180 at Thomas' suggestion
--- tests/qtest/qos-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tests/qtest/qos-test.c +1 -1
@@ -185,7 +185,7 @@ static void run_one_test(const void *arg)static void subprocess_run_one_test (const void *arg) {const gchar *path = arg; -g_test_trap_subprocess (path,0 , +g_test_trap_subprocess (path,180 *G_USEC_PER_SEC ,G_TEST_SUBPROCESS_INHERIT_STDOUT |G_TEST_SUBPROCESS_INHERIT_STDERR );g_test_trap_assert_passed (); }
Signature · 1 line
2.30.2
Re: [PATCH v3 14/21] tests/qtest: add a timeout for subprocess_run_one_test
Quoted 17 lines · Alex Bennée
Hangs have been observed in the tests and currently we don't timeout if a subprocess hangs. Rectify that.
Signed-off-by Alex Bennée <[email protected]>---
v3
- expand timeout to 180 at Thomas' suggestion--- tests/qtest/qos-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)tests/qtest/qos-test.c +0
-0
tests/qtest/qos-test.c static void run_one_test(const void *arg) · line 191
Quoted 8 lines
tests/qtest/qos-test.c +1
-1@@ -185,7 +185,7 @@ static void run_one_test(const void *arg)static void subprocess_run_one_test (const void *arg) {const gchar *path = arg; -g_test_trap_subprocess (path,0 , +g_test_trap_subprocess (path,180 *G_USEC_PER_SEC ,G_TEST_SUBPROCESS_INHERIT_STDOUT |G_TEST_SUBPROCESS_INHERIT_STDERR );g_test_trap_assert_passed (); }
PATCH v3 15/21 tests/qtest: use qos_printf instead of g_test_message
In reply to Alex BennéeThe vhost-user tests respawn qos-test as a standalone process. As a result the gtester framework squashes all messages coming out of it which make it hard to debug. As the test does not care about asserting certain messages just convert the tests to use the direct qos_printf.
--- tests/qtest/qos-test.c | 5 +++++ tests/qtest/vhost-user-test.c | 13 +++++++------ 2 files changed, 12 insertions(+), 6 deletions(-)
tests/qtest/qos-test.c +5 -0
@@ -320,6 +320,11 @@ static void walk_path(QOSGraphNode *orig_path, int len)int main (int argc,char **argv,char ** envp) {g_test_init (&argc, &argv,NULL ); + +if (g_test_subprocess ()) { +qos_printf ("qos_test running single test in subprocess\n" ); + } +if (g_test_verbose ()) {qos_printf ("ENVIRONMENT VARIABLES: {\n" );for (char **env = envp; *env !=0 ; env++) {
tests/qtest/vhost-user-test.c +7 -6
@@ -26,6 +26,7 @@#include "libqos/virtio-pci.h" #include "libqos/malloc-pc.h" +#include "libqos/qgraph_internal.h" #include "hw/virtio/virtio-net.h" #include "standard-headers/linux/vhost_types.h"
@@ -316,7 +317,7 @@ static void chr_read(void *opaque, const uint8_t *buf, int size) }if (size !=VHOST_USER_HDR_SIZE ) { -g_test_message ("Wrong message size received %d" , size); +qos_printf ("%s: Wrong message size received %d\n" , __func__, size);return ; }
@@ -327,8 +328,8 @@ static void chr_read(void *opaque, const uint8_t *buf, int size) p +=VHOST_USER_HDR_SIZE ; size =qemu_chr_fe_read_all (chr, p, msg.size);if (size != msg.size) { -g_test_message ("Wrong message size received %d != %d" , - size, msg.size); +qos_printf ("%s: Wrong message size received %d != %d\n" , + __func__, size, msg.size);return ; } }
@@ -450,7 +451,7 @@ static const char *init_hugepagefs(void) }if (access (path,R_OK |W_OK |X_OK )) { -g_test_message ("access on path (%s): %s" , path,strerror (errno)); +qos_printf ("access on path (%s): %s" , path,strerror (errno));g_test_fail ();return NULL ; }
@@ -460,13 +461,13 @@ static const char *init_hugepagefs(void) }while (ret !=0 && errno ==EINTR );if (ret !=0 ) { -g_test_message ("statfs on path (%s): %s" , path,strerror (errno)); +qos_printf ("statfs on path (%s): %s" , path,strerror (errno));g_test_fail ();return NULL ; }if (fs.f_type !=HUGETLBFS_MAGIC ) { -g_test_message ("Warning: path not on HugeTLBFS: %s" , path); +qos_printf ("Warning: path not on HugeTLBFS: %s" , path);g_test_fail ();return NULL ; }
Signature · 1 line
2.30.2
PATCH v3 16/21 tests/qtest: catch unhandled vhost-user messages
In reply to Alex BennéeWe don't need to action every message but lets document the ones we are expecting to consume so future tests don't get confused about unhandled bits.
---
v1
- drop g_test_fail() when we get unexpected result, that just hangs
--- tests/qtest/vhost-user-test.c | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+)
tests/qtest/vhost-user-test.c +40 -0
@@ -358,12 +358,41 @@ static void chr_read(void *opaque, const uint8_t *buf, int size) }break ; +case VHOST_USER_SET_OWNER : +/* +* We don't need to do anything here, the remote is just +* letting us know it is in charge. Just log it. +*/ +qos_printf ("set_owner: start of session\n" ); +break ; +case VHOST_USER_GET_PROTOCOL_FEATURES :if (s->vu_ops->get_protocol_features) { s->vu_ops->get_protocol_features (s, chr, &msg); }break ; +case VHOST_USER_SET_PROTOCOL_FEATURES : +/* +* We did set VHOST_USER_F_PROTOCOL_FEATURES so its valid for +* the remote end to send this. There is no handshake reply so +* just log the details for debugging. +*/ +qos_printf ("set_protocol_features: 0x%" PRIx64"\n" , msg.payload.u64); +break ; + +/* +* A real vhost-user backend would actually set the size and +* address of the vrings but we can simply report them. +*/ +case VHOST_USER_SET_VRING_NUM : +qos_printf ("set_vring_num: %d/%d\n" , + msg.payload.state.index, msg.payload.state.num); +break ; +case VHOST_USER_SET_VRING_ADDR : +qos_printf ("set_vring_addr:\n" ); +break ; +case VHOST_USER_GET_VRING_BASE :/* send back vring base to qemu */ msg.flags |=VHOST_USER_REPLY_MASK ;
@@ -428,7 +457,18 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)qemu_chr_fe_write_all (chr, p,VHOST_USER_HDR_SIZE + msg.size);break ; +case VHOST_USER_SET_VRING_ENABLE : +/* +* Another case we ignore as we don't need to respond. With a +* fully functioning vhost-user we would enable/disable the +* vring monitoring. +*/ +qos_printf ("set_vring(%d)=%s\n" , msg.payload.state.index, + msg.payload.state.num ?"enabled" :"disabled" ); +break ; +default : +qos_printf ("vhost-user: un-handled message: %d\n" , msg.request);break ; }
Signature · 1 line
2.30.2
PATCH v3 17/21 tests/qtest: plain g_assert for VHOST_USER_F_PROTOCOL_FEATURES
In reply to Alex Bennéecheckpatch.pl warns that non-plain asserts should be avoided so convert the check to a plain g_assert.
--- tests/qtest/vhost-user-test.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
tests/qtest/vhost-user-test.c +1 -2
@@ -980,8 +980,7 @@ static void test_multiqueue(void *obj, void *arg, QGuestAllocator *alloc)static void vu_net_set_features (TestServer *s,CharBackend *chr,VhostUserMsg *msg) { -g_assert_cmpint (msg->payload.u64 & - (0x1ULL << VHOST_USER_F_PROTOCOL_FEATURES), !=, 0ULL); +g_assert (msg->payload.u64 & (0x1ULL <<VHOST_USER_F_PROTOCOL_FEATURES ));if (s->test_flags ==TEST_FLAGS_DISCONNECT ) {qemu_chr_fe_disconnect (chr); s->test_flags =TEST_FLAGS_BAD ;
Signature · 1 line
2.30.2
PATCH v3 18/21 tests/qtest: add assert to catch bad features
In reply to Alex BennéeNo device driver (which is what the qvirtio_ access functions represent) should be setting UNUSED(30) in the feature space. Although existing libqos users mask it out lets ensure nothing sneaks through.
--- tests/qtest/libqos/virtio.c | 2 ++ 1 file changed, 2 insertions(+)
tests/qtest/libqos/virtio.c +2 -0
@@ -101,6 +101,8 @@ uint64_t qvirtio_get_features(QVirtioDevice *d)void qvirtio_set_features (QVirtioDevice *d,uint64_t features) { +g_assert (!(features &QVIRTIO_F_BAD_FEATURE )); + d->features = features; d->bus->set_features (d, features);
Signature · 1 line
2.30.2
PATCH v3 19/21 tests/qtest: implement stub for VHOST_USER_GET_CONFIG
In reply to Alex BennéeWe don't implement the full solution because frankly none of the tests need to at the moment. We may end up re-implementing libvhostuser in the end.
--- tests/qtest/vhost-user-test.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
tests/qtest/vhost-user-test.c +13 -0
@@ -79,6 +79,8 @@ typedef enum VhostUserRequest {VHOST_USER_SET_PROTOCOL_FEATURES =16 ,VHOST_USER_GET_QUEUE_NUM =17 ,VHOST_USER_SET_VRING_ENABLE =18 , +VHOST_USER_GET_CONFIG =24 , +VHOST_USER_SET_CONFIG =25 , VHOST_USER_MAX } VhostUserRequest;
@@ -372,6 +374,17 @@ static void chr_read(void *opaque, const uint8_t *buf, int size) }break ; +case VHOST_USER_GET_CONFIG : +/* +* Treat GET_CONFIG as a NOP and just reply and let the guest +* consider we have updated its memory. Tests currently don't +* require working configs. +*/ + msg.flags |=VHOST_USER_REPLY_MASK ; + p = (uint8_t *) &msg; +qemu_chr_fe_write_all (chr, p,VHOST_USER_HDR_SIZE + msg.size); +break ; +case VHOST_USER_SET_PROTOCOL_FEATURES :/* * We did set VHOST_USER_F_PROTOCOL_FEATURES so its valid for
Signature · 1 line
2.30.2
PATCH v3 20/21 tests/qtest: add a get_features op to vhost-user-test
In reply to Alex BennéeAs we expand this test for more virtio devices we will need to support different feature sets. Add a mandatory op field to fetch the list of features needed for the test itself.
--- tests/qtest/vhost-user-test.c | 37 +++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-)
tests/qtest/vhost-user-test.c +27 -10
@@ -171,10 +171,11 @@ struct vhost_user_ops { const char *chr_opts);/* VHOST-USER commands. */ +uint64_t (*get_features)(TestServer *s);void (*set_features)(TestServer *s,CharBackend *chr, -VhostUserMsg *msg); +VhostUserMsg *msg);void (*get_protocol_features)(TestServer *s, -CharBackend *chr,VhostUserMsg *msg); +CharBackend *chr,VhostUserMsg *msg); };static const char *init_hugepagefs (void );
@@ -338,20 +339,22 @@ static void chr_read(void *opaque, const uint8_t *buf, int size)switch (msg.request) {case VHOST_USER_GET_FEATURES : +/* Mandatory for tests to define get_features */ +g_assert (s->vu_ops->get_features); +/* send back features to qemu */ msg.flags |=VHOST_USER_REPLY_MASK ; msg.size =sizeof (m.payload.u64); - msg.payload.u64 =0x1ULL <<VHOST_F_LOG_ALL | -0x1ULL <<VHOST_USER_F_PROTOCOL_FEATURES ; -if (s->queues >1 ) { - msg.payload.u64 |=0x1ULL <<VIRTIO_NET_F_MQ ; - } +if (s->test_flags >=TEST_FLAGS_BAD ) { msg.payload.u64 =0 ; s->test_flags =TEST_FLAGS_END ; + }else { + msg.payload.u64 = s->vu_ops->get_features (s); } - p = (uint8_t *) &msg; -qemu_chr_fe_write_all (chr, p,VHOST_USER_HDR_SIZE + msg.size); + +qemu_chr_fe_write_all (chr, (uint8_t *) &msg, +VHOST_USER_HDR_SIZE + msg.size);break ;case VHOST_USER_SET_FEATURES :
@@ -990,8 +993,21 @@ static void test_multiqueue(void *obj, void *arg, QGuestAllocator *alloc)wait_for_rings_started (s, s->queues *2 ); } + +static uint64_t vu_net_get_features (TestServer *s) +{ +uint64_t features =0x1ULL <<VHOST_F_LOG_ALL | +0x1ULL <<VHOST_USER_F_PROTOCOL_FEATURES ; + +if (s->queues >1 ) { + features |=0x1ULL <<VIRTIO_NET_F_MQ ; + } + +return features; +} +static void vu_net_set_features (TestServer *s,CharBackend *chr, -VhostUserMsg *msg) +VhostUserMsg *msg) {g_assert (msg->payload.u64 & (0x1ULL <<VHOST_USER_F_PROTOCOL_FEATURES ));if (s->test_flags ==TEST_FLAGS_DISCONNECT ) {
@@ -1020,6 +1036,7 @@ static struct vhost_user_ops g_vu_net_ops = { .append_opts = append_vhost_net_opts, + .get_features = vu_net_get_features, .set_features = vu_net_set_features, .get_protocol_features = vu_net_get_protocol_features, };
Signature · 1 line
2.30.2
PATCH v3 21/21 tests/qtest: enable tests for virtio-gpio
In reply to Alex BennéeWe don't have a virtio-gpio implementation in QEMU and only support a vhost-user backend. The QEMU side of the code is minimal so it should be enough to instantiate the device and pass some vhost-user messages over the control socket. To do this we hook into the existing vhost-user-test code and just add the bits required for gpio.
Message-Id: <[email protected]>
---
v2
- add more of the missing boilerplate
- don't request LOG_SHMD
- use get_features op
- report VIRTIO_F_VERSION_1
- more comments
--- tests/qtest/libqos/virtio-gpio.h | 35 +++++++ tests/qtest/libqos/virtio-gpio.c | 171 +++++++++++++++++++++++++++++++ tests/qtest/libqos/virtio.c | 2 +- tests/qtest/vhost-user-test.c | 66 ++++++++++++ tests/qtest/libqos/meson.build | 1 + 5 files changed, 274 insertions(+), 1 deletion(-) create mode 100644 tests/qtest/libqos/virtio-gpio.h create mode 100644 tests/qtest/libqos/virtio-gpio.c
tests/qtest/libqos/virtio-gpio.h new file +35 -0
@@ -0,0 +1,35 @@ +/* +* virtio-gpio structures +* +* Copyright (c) 2022 Linaro Ltd +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef TESTS_LIBQOS_VIRTIO_GPIO_H +#define TESTS_LIBQOS_VIRTIO_GPIO_H + +#include "qgraph.h" +#include "virtio.h" +#include "virtio-pci.h" + +typedef struct QVhostUserGPIO QVhostUserGPIO ; +typedef struct QVhostUserGPIOPCI QVhostUserGPIOPCI ; +typedef struct QVhostUserGPIODevice QVhostUserGPIODevice ; + +struct QVhostUserGPIO { +QVirtioDevice *vdev; +QVirtQueue **queues; +}; + +struct QVhostUserGPIOPCI { +QVirtioPCIDevice pci_vdev; +QVhostUserGPIO gpio; +}; + +struct QVhostUserGPIODevice { +QOSGraphObject obj; +QVhostUserGPIO gpio; +}; + +#endif
tests/qtest/libqos/virtio-gpio.c new file +171 -0
171 lines not on this page · raw message
tests/qtest/libqos/virtio.c +1 -1
@@ -110,7 +110,7 @@ void qvirtio_set_features(QVirtioDevice *d, uint64_t features)* This could be a separate function for drivers that want to access * configuration space before setting FEATURES_OK, but no existing users * need that and it's less code for callers if this is done implicitly. -*/ +*/ if (features & (1ull <<VIRTIO_F_VERSION_1 )) {uint8_t status = d->bus->get_status (d) |VIRTIO_CONFIG_S_FEATURES_OK ;
tests/qtest/vhost-user-test.c +66 -0
96 lines not on this page · raw message
tests/qtest/libqos/meson.build +1 -0
@@ -45,6 +45,7 @@ libqos_srcs = files( 'virtio-scsi.c', 'virtio-serial.c', 'virtio-iommu.c', + 'virtio-gpio.c', 'generic-pcihost.c', # qgraph machines:
Signature · 1 line
2.30.2
Quoted 13 lines · Alex Bennée
Hi,
After much slogging through the vhost-user code I've gotten the virtio-gpio device working again. The core change in pushing the responsibility for
VHOST_USER_F_PROTOCOL_FEATURESdown to the vhost-user layer (which knows it needs it). We still need to account for that in virtio-gpio because the result of the negotiating protocol features is the vrings start disabled so the stub needs to explicitly enable them. I did consider pushing this behaviour explicitly intovhost_dev_startbut that would have required un-picking it from vhost-net (which is the only other device which uses protocol features AFAICT - but is a measure more complex in it's setup).
Quoted 3 lines
As last time there are a whole series of clean-ups and doc tweaks. I don't know if any are trivial enough to sneak into later RCs but it shouldn't be a problem to wait until the tree re-opens.
Right. Still I think some are fixes we should merge now. I am thinking patches 5, 7,8,9 ? 6 if it makes backporting much easier. WDYT? If you agree pls separate bugfixes in series I can apply. Thanks!
Quoted 82 lines
There is a remaining issue that a --enable-sanitizers build fails for qos-test due to leaks. It shows up as a leak from:
Direct leak of 240 byte(s) in 1 object(s) allocated from:
#0 0x7fc5a3f2a037 in __interceptor_calloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:154 #1 0x7fc5a2e5cda0 in g_malloc0 ../../../glib/gmem.c:136 #2 0x55ce773cc728 in virtio_device_realize ../../hw/virtio/virtio.c:3691 #3 0x55ce7784ed7e in device_set_realized ../../hw/core/qdev.c:553 #4 0x55ce77862d0c in property_set_bool ../../qom/object.c:2273I'm not entirely sure what the allocation is because it gets inlined in the
virtio_device_realizecall. Perhaps it's the QOM object itself which is never gracefully torn down at the end of the test?However when I attempted to bisect I found master was broken as well. For example in my arm/aarch64-softmmu build we see 5 failures:
Summary of Failures:
3/48 qemu:qtest+qtest-aarch64 / qtest-aarch64/migration-test ERROR 96.15s killed by signal 6 SIGABRT 9/48 qemu:qtest+qtest-aarch64 / qtest-aarch64/qos-test ERROR 32.50s killed by signal 6 SIGABRT 11/48 qemu:qtest+qtest-arm / qtest-arm/qos-test ERROR 26.93s killed by signal 6 SIGABRT 20/48 qemu:qtest+qtest-aarch64 / qtest-aarch64/device-introspect-test ERROR 5.17s killed by signal 6 SIGABRT 45/48 qemu:qtest+qtest-arm / qtest-arm/device-introspect-test ERROR 4.97s killed by signal 6 SIGABRTOf which the qos-tests are the only new ones. I suspect something must be preventing the other stuff being exercised in our CI system.
Alex Bennée (19):
include/hw/virtio: more comment forVIRTIO_F_BAD_FEATUREinclude/hw: documentvhost_devfeature life-cycle hw/virtio: fix some coding style issues
hw/virtio: log potentially buggy guest driversblock/vhost-user-blk-server: don't expose
VHOST_USER_F_PROTOCOL_FEATURES
hw/virtio: incorporate backend features in features hw/virtio: gracefully handle unsetvhost_devvdev hw/virtio: handle un-configured shutdown in virtio-pci hw/virtio: fixvhost_user_readtracepoint
hw/virtio: add some vhost-user trace events tests/qtest: pass stdout/stderr down to subtests tests/qtest: add a timeout forsubprocess_run_one_testtests/qtest: useqos_printfinstead ofg_test_messagetests/qtest: catch unhandled vhost-user messages tests/qtest: plaing_assertforVHOST_USER_F_PROTOCOL_FEATUREStests/qtest: add assert to catch bad features tests/qtest: implement stub forVHOST_USER_GET_CONFIGtests/qtest: add aget_featuresop to vhost-user-test tests/qtest: enable tests for virtio-gpioViresh Kumar (2):
hw/virtio: add boilerplate for vhost-user-gpio device hw/virtio: add vhost-user-gpio-pci boilerplateinclude/hw/virtio/vhost-user-gpio.h | 35 +++ include/hw/virtio/vhost.h | 3 + include/hw/virtio/virtio.h | 7 +- tests/qtest/libqos/virtio-gpio.h | 35 +++ block/export/vhost-user-blk-server.c | 3 +- hw/virtio/vhost-user-gpio-pci.c | 69 +++++ hw/virtio/vhost-user-gpio.c | 414 +++++++++++++++++++++++++++ hw/virtio/vhost-user.c | 20 +- hw/virtio/vhost.c | 16 +- hw/virtio/virtio-pci.c | 9 +- hw/virtio/virtio.c | 7 + tests/qtest/libqos/virtio-gpio.c | 171 +++++++++++ tests/qtest/libqos/virtio.c | 4 +- tests/qtest/qos-test.c | 8 +- tests/qtest/vhost-user-test.c | 172 +++++++++-- hw/virtio/Kconfig | 5 + hw/virtio/meson.build | 2 + hw/virtio/trace-events | 9 + tests/qtest/libqos/meson.build | 1 + 19 files changed, 956 insertions(+), 34 deletions(-) create mode 100644 include/hw/virtio/vhost-user-gpio.h create mode 100644 tests/qtest/libqos/virtio-gpio.h create mode 100644 hw/virtio/vhost-user-gpio-pci.c create mode 100644 hw/virtio/vhost-user-gpio.c create mode 100644 tests/qtest/libqos/virtio-gpio.cSignature · 1 line
2.30.2