Blame SOURCES/kvm-virtio-update-MemoryRegionCaches-when-guest-negotiat.patch

7711c0
From 6d719f4240ad6bbd2ae434cad1d56c5b6c16b7f3 Mon Sep 17 00:00:00 2001
7711c0
From: John Snow <jsnow@redhat.com>
7711c0
Date: Fri, 25 Jan 2019 22:50:05 +0100
7711c0
Subject: [PATCH 05/23] virtio: update MemoryRegionCaches when guest negotiates
7711c0
 features
7711c0
7711c0
RH-Author: John Snow <jsnow@redhat.com>
7711c0
Message-id: <20190125225007.8197-6-jsnow@redhat.com>
7711c0
Patchwork-id: 84121
7711c0
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH v2 5/7] virtio: update MemoryRegionCaches when guest negotiates features
7711c0
Bugzilla: 1597482
7711c0
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
7711c0
RH-Acked-by: Peter Xu <peterx@redhat.com>
7711c0
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
7711c0
7711c0
From: Paolo Bonzini <pbonzini@redhat.com>
7711c0
7711c0
Because the cache is sized to include the rings and the event indices,
7711c0
negotiating the VIRTIO_RING_F_EVENT_IDX feature will result in the size
7711c0
of the cache changing.  And because MemoryRegionCache accesses are
7711c0
range-checked, if we skip this we end up with an assertion failure.
7711c0
This happens with OpenBSD 6.3.
7711c0
7711c0
Reported-by: Fam Zheng <famz@redhat.com>
7711c0
Fixes: 97cd965c070152bc626c7507df9fb356bbe1cd81
7711c0
Cc: qemu-stable@nongnu.org
7711c0
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
7711c0
Tested-by: Fam Zheng <famz@redhat.com>
7711c0
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
7711c0
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
7711c0
(cherry picked from commit db812c4073c77c8a64db8d6663b3416a587c7b4a)
7711c0
Signed-off-by: John Snow <jsnow@redhat.com>
7711c0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
7711c0
---
7711c0
 hw/virtio/virtio.c | 15 +++++++++++++--
7711c0
 1 file changed, 13 insertions(+), 2 deletions(-)
7711c0
7711c0
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
7711c0
index 5549bb4..77eadaa 100644
7711c0
--- a/hw/virtio/virtio.c
7711c0
+++ b/hw/virtio/virtio.c
7711c0
@@ -2021,14 +2021,25 @@ static int virtio_set_features_nocheck(VirtIODevice *vdev, uint64_t val)
7711c0
 
7711c0
 int virtio_set_features(VirtIODevice *vdev, uint64_t val)
7711c0
 {
7711c0
-   /*
7711c0
+    int ret;
7711c0
+    /*
7711c0
      * The driver must not attempt to set features after feature negotiation
7711c0
      * has finished.
7711c0
      */
7711c0
     if (vdev->status & VIRTIO_CONFIG_S_FEATURES_OK) {
7711c0
         return -EINVAL;
7711c0
     }
7711c0
-    return virtio_set_features_nocheck(vdev, val);
7711c0
+    ret = virtio_set_features_nocheck(vdev, val);
7711c0
+    if (!ret && virtio_vdev_has_feature(vdev, VIRTIO_RING_F_EVENT_IDX)) {
7711c0
+        /* VIRTIO_RING_F_EVENT_IDX changes the size of the caches.  */
7711c0
+        int i;
7711c0
+        for (i = 0; i < VIRTIO_QUEUE_MAX; i++) {
7711c0
+            if (vdev->vq[i].vring.num != 0) {
7711c0
+                virtio_init_region_cache(vdev, i);
7711c0
+            }
7711c0
+        }
7711c0
+    }
7711c0
+    return ret;
7711c0
 }
7711c0
 
7711c0
 int virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id)
7711c0
-- 
7711c0
1.8.3.1
7711c0