summary refs log tree commit diff stats
path: root/tests
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@redhat.com>2019-10-23 11:04:16 +0100
committerMichael S. Tsirkin <mst@redhat.com>2019-10-25 07:46:22 -0400
commit56140fbb8f2bb717eb2670aa1056aeaefe8b0246 (patch)
treed976fd447f5688d0f2cb2b8036364e5bfdbf0285 /tests
parentc5bd6d02e6eb6ae868abbcbeb5c3a3be8c5379a5 (diff)
downloadfocaccia-qemu-56140fbb8f2bb717eb2670aa1056aeaefe8b0246.tar.gz
focaccia-qemu-56140fbb8f2bb717eb2670aa1056aeaefe8b0246.zip
libqos: enforce Device Initialization order
According to VIRTIO 1.1 "3.1.1 Driver Requirements: Device
Initialization", configuration space and virtqueues cannot be accessed
before features have been negotiated.  Enforce this requirement.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-Id: <20191023100425.12168-8-stefanha@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/libqos/virtio.c7
-rw-r--r--tests/libqos/virtio.h1
2 files changed, 8 insertions, 0 deletions
diff --git a/tests/libqos/virtio.c b/tests/libqos/virtio.c
index 4f7e6bb8a1..6049ff3b3e 100644
--- a/tests/libqos/virtio.c
+++ b/tests/libqos/virtio.c
@@ -15,21 +15,25 @@
 
 uint8_t qvirtio_config_readb(QVirtioDevice *d, uint64_t addr)
 {
+    g_assert_true(d->features_negotiated);
     return d->bus->config_readb(d, addr);
 }
 
 uint16_t qvirtio_config_readw(QVirtioDevice *d, uint64_t addr)
 {
+    g_assert_true(d->features_negotiated);
     return d->bus->config_readw(d, addr);
 }
 
 uint32_t qvirtio_config_readl(QVirtioDevice *d, uint64_t addr)
 {
+    g_assert_true(d->features_negotiated);
     return d->bus->config_readl(d, addr);
 }
 
 uint64_t qvirtio_config_readq(QVirtioDevice *d, uint64_t addr)
 {
+    g_assert_true(d->features_negotiated);
     return d->bus->config_readq(d, addr);
 }
 
@@ -42,11 +46,13 @@ void qvirtio_set_features(QVirtioDevice *d, uint64_t features)
 {
     d->features = features;
     d->bus->set_features(d, features);
+    d->features_negotiated = true;
 }
 
 QVirtQueue *qvirtqueue_setup(QVirtioDevice *d,
                              QGuestAllocator *alloc, uint16_t index)
 {
+    g_assert_true(d->features_negotiated);
     return d->bus->virtqueue_setup(d, alloc, index);
 }
 
@@ -60,6 +66,7 @@ void qvirtio_reset(QVirtioDevice *d)
 {
     d->bus->set_status(d, 0);
     g_assert_cmphex(d->bus->get_status(d), ==, 0);
+    d->features_negotiated = false;
 }
 
 void qvirtio_set_acknowledge(QVirtioDevice *d)
diff --git a/tests/libqos/virtio.h b/tests/libqos/virtio.h
index a5c99fb3c9..0e8f823c7b 100644
--- a/tests/libqos/virtio.h
+++ b/tests/libqos/virtio.h
@@ -23,6 +23,7 @@ typedef struct QVirtioDevice {
     uint16_t device_type;
     uint64_t features;
     bool big_endian;
+    bool features_negotiated;
 } QVirtioDevice;
 
 typedef struct QVirtQueue {