cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-virtio-support-setting-memory-region-based-host-noti.patch

ae23c9
From cc1a69d28dd21da529d0d2f7a34547c03277243c Mon Sep 17 00:00:00 2001
ae23c9
From: "plai@redhat.com" <plai@redhat.com>
ae23c9
Date: Thu, 21 Jun 2018 18:54:37 +0200
ae23c9
Subject: [PATCH 158/268] virtio: support setting memory region based host
ae23c9
 notifier
ae23c9
ae23c9
RH-Author: plai@redhat.com
ae23c9
Message-id: <1529607285-9942-3-git-send-email-plai@redhat.com>
ae23c9
Patchwork-id: 80937
ae23c9
O-Subject: [RHEL7.6 PATCH BZ 1526645 02/10] virtio: support setting memory region based host notifier
ae23c9
Bugzilla: 1526645
ae23c9
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
ae23c9
RH-Acked-by: Maxime Coquelin <maxime.coquelin@redhat.com>
ae23c9
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
ae23c9
ae23c9
From: Tiwei Bie <tiwei.bie@intel.com>
ae23c9
ae23c9
This patch introduces the support for setting memory region
ae23c9
based host notifiers for virtio device. This is helpful when
ae23c9
using a hardware accelerator for a virtio device, because
ae23c9
hardware heavily depends on the notification, this will allow
ae23c9
the guest driver in the VM to notify the hardware directly.
ae23c9
ae23c9
Signed-off-by: Tiwei Bie <tiwei.bie@intel.com>
ae23c9
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
ae23c9
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
ae23c9
(cherry picked from commit 6f80e6170ede13605817e5c0ca73db0de7bdf261)
ae23c9
Signed-off-by: Paul Lai <plai@redhat.com>
ae23c9
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
ae23c9
---
ae23c9
 hw/virtio/virtio-pci.c         | 22 ++++++++++++++++++++++
ae23c9
 hw/virtio/virtio.c             | 13 +++++++++++++
ae23c9
 include/hw/virtio/virtio-bus.h |  2 ++
ae23c9
 include/hw/virtio/virtio.h     |  2 ++
ae23c9
 4 files changed, 39 insertions(+)
ae23c9
ae23c9
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
ae23c9
index 92bdc9e..070ad0f 100644
ae23c9
--- a/hw/virtio/virtio-pci.c
ae23c9
+++ b/hw/virtio/virtio-pci.c
ae23c9
@@ -1037,6 +1037,27 @@ assign_error:
ae23c9
     return r;
ae23c9
 }
ae23c9
 
ae23c9
+static int virtio_pci_set_host_notifier_mr(DeviceState *d, int n,
ae23c9
+                                           MemoryRegion *mr, bool assign)
ae23c9
+{
ae23c9
+    VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
ae23c9
+    int offset;
ae23c9
+
ae23c9
+    if (n >= VIRTIO_QUEUE_MAX || !virtio_pci_modern(proxy) ||
ae23c9
+        virtio_pci_queue_mem_mult(proxy) != memory_region_size(mr)) {
ae23c9
+        return -1;
ae23c9
+    }
ae23c9
+
ae23c9
+    if (assign) {
ae23c9
+        offset = virtio_pci_queue_mem_mult(proxy) * n;
ae23c9
+        memory_region_add_subregion_overlap(&proxy->notify.mr, offset, mr, 1);
ae23c9
+    } else {
ae23c9
+        memory_region_del_subregion(&proxy->notify.mr, mr);
ae23c9
+    }
ae23c9
+
ae23c9
+    return 0;
ae23c9
+}
ae23c9
+
ae23c9
 static void virtio_pci_vmstate_change(DeviceState *d, bool running)
ae23c9
 {
ae23c9
     VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
ae23c9
@@ -2652,6 +2673,7 @@ static void virtio_pci_bus_class_init(ObjectClass *klass, void *data)
ae23c9
     k->has_extra_state = virtio_pci_has_extra_state;
ae23c9
     k->query_guest_notifiers = virtio_pci_query_guest_notifiers;
ae23c9
     k->set_guest_notifiers = virtio_pci_set_guest_notifiers;
ae23c9
+    k->set_host_notifier_mr = virtio_pci_set_host_notifier_mr;
ae23c9
     k->vmstate_change = virtio_pci_vmstate_change;
ae23c9
     k->pre_plugged = virtio_pci_pre_plugged;
ae23c9
     k->device_plugged = virtio_pci_device_plugged;
ae23c9
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
ae23c9
index 006d3d1..1debb01 100644
ae23c9
--- a/hw/virtio/virtio.c
ae23c9
+++ b/hw/virtio/virtio.c
ae23c9
@@ -2454,6 +2454,19 @@ EventNotifier *virtio_queue_get_host_notifier(VirtQueue *vq)
ae23c9
     return &vq->host_notifier;
ae23c9
 }
ae23c9
 
ae23c9
+int virtio_queue_set_host_notifier_mr(VirtIODevice *vdev, int n,
ae23c9
+                                      MemoryRegion *mr, bool assign)
ae23c9
+{
ae23c9
+    BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
ae23c9
+    VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
ae23c9
+
ae23c9
+    if (k->set_host_notifier_mr) {
ae23c9
+        return k->set_host_notifier_mr(qbus->parent, n, mr, assign);
ae23c9
+    }
ae23c9
+
ae23c9
+    return -1;
ae23c9
+}
ae23c9
+
ae23c9
 void virtio_device_set_child_bus_name(VirtIODevice *vdev, char *bus_name)
ae23c9
 {
ae23c9
     g_free(vdev->bus_name);
ae23c9
diff --git a/include/hw/virtio/virtio-bus.h b/include/hw/virtio/virtio-bus.h
ae23c9
index ced3d2d..7fec9dc 100644
ae23c9
--- a/include/hw/virtio/virtio-bus.h
ae23c9
+++ b/include/hw/virtio/virtio-bus.h
ae23c9
@@ -52,6 +52,8 @@ typedef struct VirtioBusClass {
ae23c9
     bool (*has_extra_state)(DeviceState *d);
ae23c9
     bool (*query_guest_notifiers)(DeviceState *d);
ae23c9
     int (*set_guest_notifiers)(DeviceState *d, int nvqs, bool assign);
ae23c9
+    int (*set_host_notifier_mr)(DeviceState *d, int n,
ae23c9
+                                MemoryRegion *mr, bool assign);
ae23c9
     void (*vmstate_change)(DeviceState *d, bool running);
ae23c9
     /*
ae23c9
      * Expose the features the transport layer supports before
ae23c9
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
ae23c9
index 098bdaa..9c1fa07 100644
ae23c9
--- a/include/hw/virtio/virtio.h
ae23c9
+++ b/include/hw/virtio/virtio.h
ae23c9
@@ -239,6 +239,8 @@ void virtio_queue_set_align(VirtIODevice *vdev, int n, int align);
ae23c9
 void virtio_queue_notify(VirtIODevice *vdev, int n);
ae23c9
 uint16_t virtio_queue_vector(VirtIODevice *vdev, int n);
ae23c9
 void virtio_queue_set_vector(VirtIODevice *vdev, int n, uint16_t vector);
ae23c9
+int virtio_queue_set_host_notifier_mr(VirtIODevice *vdev, int n,
ae23c9
+                                      MemoryRegion *mr, bool assign);
ae23c9
 int virtio_set_status(VirtIODevice *vdev, uint8_t val);
ae23c9
 void virtio_reset(void *opaque);
ae23c9
 void virtio_update_irq(VirtIODevice *vdev);
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9