[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 14/28] virtio: support setting memory region based ho
From: |
Michael S. Tsirkin |
Subject: |
[Qemu-devel] [PULL 14/28] virtio: support setting memory region based host notifier |
Date: |
Wed, 23 May 2018 17:43:08 +0300 |
From: Tiwei Bie <address@hidden>
This patch introduces the support for setting memory region
based host notifiers for virtio device. This is helpful when
using a hardware accelerator for a virtio device, because
hardware heavily depends on the notification, this will allow
the guest driver in the VM to notify the hardware directly.
Signed-off-by: Tiwei Bie <address@hidden>
Reviewed-by: Michael S. Tsirkin <address@hidden>
Signed-off-by: Michael S. Tsirkin <address@hidden>
---
include/hw/virtio/virtio-bus.h | 2 ++
include/hw/virtio/virtio.h | 2 ++
hw/virtio/virtio-pci.c | 22 ++++++++++++++++++++++
hw/virtio/virtio.c | 13 +++++++++++++
4 files changed, 39 insertions(+)
diff --git a/include/hw/virtio/virtio-bus.h b/include/hw/virtio/virtio-bus.h
index ced3d2d..7fec9dc 100644
--- a/include/hw/virtio/virtio-bus.h
+++ b/include/hw/virtio/virtio-bus.h
@@ -52,6 +52,8 @@ typedef struct VirtioBusClass {
bool (*has_extra_state)(DeviceState *d);
bool (*query_guest_notifiers)(DeviceState *d);
int (*set_guest_notifiers)(DeviceState *d, int nvqs, bool assign);
+ int (*set_host_notifier_mr)(DeviceState *d, int n,
+ MemoryRegion *mr, bool assign);
void (*vmstate_change)(DeviceState *d, bool running);
/*
* Expose the features the transport layer supports before
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index 098bdaa..9c1fa07 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -239,6 +239,8 @@ void virtio_queue_set_align(VirtIODevice *vdev, int n, int
align);
void virtio_queue_notify(VirtIODevice *vdev, int n);
uint16_t virtio_queue_vector(VirtIODevice *vdev, int n);
void virtio_queue_set_vector(VirtIODevice *vdev, int n, uint16_t vector);
+int virtio_queue_set_host_notifier_mr(VirtIODevice *vdev, int n,
+ MemoryRegion *mr, bool assign);
int virtio_set_status(VirtIODevice *vdev, uint8_t val);
void virtio_reset(void *opaque);
void virtio_update_irq(VirtIODevice *vdev);
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 1e8ab7b..5eb0c32 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -1037,6 +1037,27 @@ assign_error:
return r;
}
+static int virtio_pci_set_host_notifier_mr(DeviceState *d, int n,
+ MemoryRegion *mr, bool assign)
+{
+ VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
+ int offset;
+
+ if (n >= VIRTIO_QUEUE_MAX || !virtio_pci_modern(proxy) ||
+ virtio_pci_queue_mem_mult(proxy) != memory_region_size(mr)) {
+ return -1;
+ }
+
+ if (assign) {
+ offset = virtio_pci_queue_mem_mult(proxy) * n;
+ memory_region_add_subregion_overlap(&proxy->notify.mr, offset, mr, 1);
+ } else {
+ memory_region_del_subregion(&proxy->notify.mr, mr);
+ }
+
+ return 0;
+}
+
static void virtio_pci_vmstate_change(DeviceState *d, bool running)
{
VirtIOPCIProxy *proxy = to_virtio_pci_proxy(d);
@@ -2652,6 +2673,7 @@ static void virtio_pci_bus_class_init(ObjectClass *klass,
void *data)
k->has_extra_state = virtio_pci_has_extra_state;
k->query_guest_notifiers = virtio_pci_query_guest_notifiers;
k->set_guest_notifiers = virtio_pci_set_guest_notifiers;
+ k->set_host_notifier_mr = virtio_pci_set_host_notifier_mr;
k->vmstate_change = virtio_pci_vmstate_change;
k->pre_plugged = virtio_pci_pre_plugged;
k->device_plugged = virtio_pci_device_plugged;
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 006d3d1..1debb01 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -2454,6 +2454,19 @@ EventNotifier *virtio_queue_get_host_notifier(VirtQueue
*vq)
return &vq->host_notifier;
}
+int virtio_queue_set_host_notifier_mr(VirtIODevice *vdev, int n,
+ MemoryRegion *mr, bool assign)
+{
+ BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
+ VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(qbus);
+
+ if (k->set_host_notifier_mr) {
+ return k->set_host_notifier_mr(qbus->parent, n, mr, assign);
+ }
+
+ return -1;
+}
+
void virtio_device_set_child_bus_name(VirtIODevice *vdev, char *bus_name)
{
g_free(vdev->bus_name);
--
MST
- [Qemu-devel] [PULL 03/28] virtio-balloon: add hugetlb page allocation counts, (continued)
- [Qemu-devel] [PULL 03/28] virtio-balloon: add hugetlb page allocation counts, Michael S. Tsirkin, 2018/05/23
- [Qemu-devel] [PULL 01/28] hw/pci-host/q35: Replace hardcoded value with macro, Michael S. Tsirkin, 2018/05/23
- [Qemu-devel] [PULL 02/28] allocate pci id for mdpy, Michael S. Tsirkin, 2018/05/23
- [Qemu-devel] [PULL 04/28] vhost: add trace for IOTLB miss, Michael S. Tsirkin, 2018/05/23
- [Qemu-devel] [PULL 05/28] update-linux-headers.sh: drop kvm_para.h hacks, Michael S. Tsirkin, 2018/05/23
- [Qemu-devel] [PULL 06/28] include/standard-headers: add asm-x86/kvm_para.h, Michael S. Tsirkin, 2018/05/23
- [Qemu-devel] [PULL 08/28] linux-headers: drop kvm_para.h, Michael S. Tsirkin, 2018/05/23
- [Qemu-devel] [PULL 09/28] update-linux-headers.sh: unistd.h, kvm consistency, Michael S. Tsirkin, 2018/05/23
- [Qemu-devel] [PULL 07/28] x86/cpu: use standard-headers/asm-x86.kvm_para.h, Michael S. Tsirkin, 2018/05/23
- [Qemu-devel] [PULL 12/28] vhost-user: add Net prefix to internal state structure, Michael S. Tsirkin, 2018/05/23
- [Qemu-devel] [PULL 14/28] virtio: support setting memory region based host notifier,
Michael S. Tsirkin <=
- [Qemu-devel] [PULL 13/28] vhost-user: support receiving file descriptors in slave_read, Michael S. Tsirkin, 2018/05/23
- [Qemu-devel] [PULL 11/28] linux-headers: add kvm header for mips, Michael S. Tsirkin, 2018/05/23
- [Qemu-devel] [PULL 16/28] libvhost-user: Send messages with no data, Michael S. Tsirkin, 2018/05/23
- [Qemu-devel] [PULL 15/28] vhost-user+postcopy: Use qemu_set_nonblock, Michael S. Tsirkin, 2018/05/23
- [Qemu-devel] [PULL 10/28] linux-headers: add unistd.h on all arches, Michael S. Tsirkin, 2018/05/23
- [Qemu-devel] [PULL 17/28] hw/virtio: Fix brace Werror with clang 6.0.0, Michael S. Tsirkin, 2018/05/23
- [Qemu-devel] [PULL 20/28] intel-iommu: send PSI always even if across PDEs, Michael S. Tsirkin, 2018/05/23
- [Qemu-devel] [PULL 19/28] nvdimm: fix typo in label-size definition, Michael S. Tsirkin, 2018/05/23
- [Qemu-devel] [PULL 18/28] contrib/vhost-user-blk: enable protocol feature for vhost-user-blk, Michael S. Tsirkin, 2018/05/23
- [Qemu-devel] [PULL 21/28] intel-iommu: remove IntelIOMMUNotifierNode, Michael S. Tsirkin, 2018/05/23