From: Tiwei Bie <tiwei.bie@intel.com>
To: mst@redhat.com, jasowang@redhat.com, alex.williamson@redhat.com,
pbonzini@redhat.com, stefanha@redhat.com, qemu-devel@nongnu.org,
virtio-dev@lists.oasis-open.org
Cc: cunming.liang@intel.com, dan.daly@intel.com,
jianfeng.tan@intel.com, zhihong.wang@intel.com,
xiao.w.wang@intel.com, tiwei.bie@intel.com
Subject: [Qemu-devel] [PATCH v3 4/6] virtio: support setting memory region based host notifier
Date: Thu, 12 Apr 2018 23:12:30 +0800 [thread overview]
Message-ID: <20180412151232.17506-5-tiwei.bie@intel.com> (raw)
In-Reply-To: <20180412151232.17506-1-tiwei.bie@intel.com>
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 <tiwei.bie@intel.com>
---
hw/virtio/virtio-pci.c | 22 ++++++++++++++++++++++
hw/virtio/virtio.c | 13 +++++++++++++
include/hw/virtio/virtio-bus.h | 2 ++
include/hw/virtio/virtio.h | 2 ++
4 files changed, 39 insertions(+)
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 1e8ab7bbc5..5eb0c323ca 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 006d3d1148..1debb0147b 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);
diff --git a/include/hw/virtio/virtio-bus.h b/include/hw/virtio/virtio-bus.h
index ced3d2d2b0..7fec9dc929 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 098bdaaea3..9c1fa07d6d 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);
--
2.11.0
next prev parent reply other threads:[~2018-04-12 15:15 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-12 15:12 [Qemu-devel] [PATCH v3 0/6] Extend vhost-user to support registering external host notifiers Tiwei Bie
2018-04-12 15:12 ` [Qemu-devel] [PATCH v3 1/6] vhost-user: add Net prefix to internal state structure Tiwei Bie
2018-04-12 15:12 ` [Qemu-devel] [PATCH v3 2/6] vhost-user: introduce shared vhost-user state Tiwei Bie
2018-05-23 13:44 ` Michael S. Tsirkin
2018-05-23 15:36 ` Michael S. Tsirkin
2018-05-23 15:43 ` Michael S. Tsirkin
2018-05-23 23:21 ` Tiwei Bie
2018-05-24 2:24 ` Tiwei Bie
2018-05-24 7:03 ` Tiwei Bie
2018-05-24 10:59 ` Tiwei Bie
2018-05-24 13:55 ` Michael S. Tsirkin
2018-05-24 14:54 ` [Qemu-devel] [virtio-dev] " Tiwei Bie
2018-05-24 14:30 ` [Qemu-devel] " Michael S. Tsirkin
2018-05-24 15:22 ` Tiwei Bie
2018-05-24 13:50 ` Michael S. Tsirkin
2018-04-12 15:12 ` [Qemu-devel] [PATCH v3 3/6] vhost-user: support receiving file descriptors in slave_read Tiwei Bie
2018-05-23 21:25 ` Michael S. Tsirkin
2018-05-23 23:12 ` [Qemu-devel] [virtio-dev] " Tiwei Bie
2018-05-24 13:48 ` Michael S. Tsirkin
2018-05-24 14:56 ` Tiwei Bie
2018-04-12 15:12 ` Tiwei Bie [this message]
2018-04-12 15:12 ` [Qemu-devel] [PATCH v3 5/6] vhost: allow backends to filter memory sections Tiwei Bie
2018-04-12 15:12 ` [Qemu-devel] [PATCH v3 6/6] vhost-user: support registering external host notifiers Tiwei Bie
2018-04-18 16:34 ` Michael S. Tsirkin
2018-04-19 11:14 ` Tiwei Bie
2018-04-19 12:43 ` Liang, Cunming
2018-04-19 13:02 ` [Qemu-devel] [virtio-dev] " Paolo Bonzini
2018-04-19 15:19 ` Michael S. Tsirkin
2018-04-19 15:51 ` Paolo Bonzini
2018-04-19 15:59 ` Michael S. Tsirkin
2018-04-19 16:07 ` Paolo Bonzini
2018-04-19 16:48 ` Michael S. Tsirkin
2018-04-19 16:24 ` Liang, Cunming
2018-04-19 16:55 ` Michael S. Tsirkin
2018-04-20 3:01 ` Liang, Cunming
2018-04-19 15:42 ` [Qemu-devel] " Michael S. Tsirkin
2018-04-19 15:52 ` Paolo Bonzini
2018-04-19 16:34 ` Michael S. Tsirkin
2018-04-19 16:52 ` Liang, Cunming
2018-04-19 16:59 ` [Qemu-devel] [virtio-dev] " Paolo Bonzini
2018-04-19 17:27 ` Michael S. Tsirkin
2018-04-19 17:35 ` Paolo Bonzini
2018-04-19 17:39 ` Michael S. Tsirkin
2018-04-19 17:00 ` [Qemu-devel] " Michael S. Tsirkin
2018-04-19 23:05 ` Liang, Cunming
2018-04-19 16:27 ` Liang, Cunming
2018-05-02 10:32 ` Tiwei Bie
2018-05-16 1:41 ` [Qemu-devel] [PATCH v3 0/6] Extend vhost-user to " Michael S. Tsirkin
2018-05-16 1:56 ` Tiwei Bie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180412151232.17506-5-tiwei.bie@intel.com \
--to=tiwei.bie@intel.com \
--cc=alex.williamson@redhat.com \
--cc=cunming.liang@intel.com \
--cc=dan.daly@intel.com \
--cc=jasowang@redhat.com \
--cc=jianfeng.tan@intel.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=virtio-dev@lists.oasis-open.org \
--cc=xiao.w.wang@intel.com \
--cc=zhihong.wang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).