yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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