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

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