From patchwork Thu May 7 10:48:20 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Fedin X-Patchwork-Id: 469594 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 97C78140134 for ; Thu, 7 May 2015 20:48:46 +1000 (AEST) Received: from localhost ([::1]:49970 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YqJMC-0000SQ-Li for incoming@patchwork.ozlabs.org; Thu, 07 May 2015 06:48:44 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60455) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YqJLw-0000A7-QD for qemu-devel@nongnu.org; Thu, 07 May 2015 06:48:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YqJLt-00079r-FS for qemu-devel@nongnu.org; Thu, 07 May 2015 06:48:28 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:22534) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YqJLt-00079n-7F for qemu-devel@nongnu.org; Thu, 07 May 2015 06:48:25 -0400 Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout2.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0NNZ009A17COQF20@mailout2.w1.samsung.com> for qemu-devel@nongnu.org; Thu, 07 May 2015 11:48:24 +0100 (BST) X-AuditID: cbfec7f5-f794b6d000001495-8d-554b42f73dae Received: from eusync1.samsung.com ( [203.254.199.211]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id C2.79.05269.7F24B455; Thu, 7 May 2015 11:48:23 +0100 (BST) Received: from fedinw7x64 ([106.109.131.169]) by eusync1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0NNZ003XY7CKTU00@eusync1.samsung.com> for qemu-devel@nongnu.org; Thu, 07 May 2015 11:48:23 +0100 (BST) From: Pavel Fedin To: qemu-devel@nongnu.org Date: Thu, 07 May 2015 13:48:20 +0300 Message-id: <015f01d088b3$57350380$059f0a80$@samsung.com> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-index: AdCIs0dB37saaPKGRoCeK/HhFzwQDg== Content-language: ru X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrNLMWRmVeSWpSXmKPExsVy+t/xy7rfnbxDDZZ/tbA43ruDxYHR48m1 zUwBjFFcNimpOZllqUX6dglcGS837WQs2KNYsX3maZYGxtsSXYycHBICJhLfWhYyQthiEhfu rWfrYuTiEBJYyijxsOsDE4QzkUni/JXP7CBVbALqEqe/fmABsUUEJCV+d51mBrGFBZwkjn+d AGazCKhKLP8yBayGV8BSovHNBzYIW1Dix+R7YHFmAS2J9TuPM0HY8hKb17xlhrhCQWLH2deM EPP1JPatecYIUSMiMe3fPeYJjPyzkIyahWTULCSjZiFpWcDIsopRNLU0uaA4KT3XSK84Mbe4 NC9dLzk/dxMjJAi/7mBceszqEKMAB6MSD+8KO+9QIdbEsuLK3EOMEhzMSiK8M62AQrwpiZVV qUX58UWlOanFhxilOViUxHln7nofIiSQnliSmp2aWpBaBJNl4uCUamA82ruAQ2AjO1vF6Ws7 KpiCN6mVt67f8zDl6dzyid8LP6Sc+aDRHlHhpxpg8Xjdw//5ls6L+FsnOr2eXdzjMdHur0yg luU068vXDNMzb57/0mi4V88nf4Ea0zvDqo+CsX/FH+xLqdmcFtHP9DQv6duU+jVRKzPz1d0S L6xdt/LdAd1r9l3myWxKLMUZiYZazEXFiQCZG/4yPgIAAA== X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 210.118.77.12 Subject: [Qemu-devel] [PATCH v2 1/3] virtio-mmio: introduce set_host_notifier() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org set_host_notifier() is introduced into virtio-mmio now. Most of codes came from virtio-pci. Signed-off-by: Ying-Shiuan Pan Signed-off-by: Pavel Fedin --- hw/virtio/virtio-mmio.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) size) { VirtIOMMIOProxy *proxy = (VirtIOMMIOProxy *)opaque; @@ -342,6 +394,25 @@ static void virtio_mmio_reset(DeviceState *d) proxy->guest_page_shift = 0; } +static int virtio_mmio_set_host_notifier(DeviceState *opaque, int n, + bool assign) +{ + VirtIOMMIOProxy *proxy = VIRTIO_MMIO(opaque); + + /* Stop using ioeventfd for virtqueue kick if the device starts using host + * notifiers. This makes it easy to avoid stepping on each others' toes. + */ + proxy->ioeventfd_disabled = assign; + if (assign) { + virtio_mmio_stop_ioeventfd(proxy); + } + /* We don't need to start here: it's not needed because backend + * currently only stops on status change away from ok, + * reset, vmstop and such. If we do add code to start here, + * need to check vmstate, device state etc. */ + return virtio_mmio_set_host_notifier_internal(proxy, n, assign, false); +} + /* virtio-mmio device */ /* This is called by virtio-bus just after the device is plugged. */ @@ -399,6 +470,7 @@ static void virtio_mmio_bus_class_init(ObjectClass *klass, void *data) k->notify = virtio_mmio_update_irq; k->save_config = virtio_mmio_save_config; k->load_config = virtio_mmio_load_config; + k->set_host_notifier = virtio_mmio_set_host_notifier; k->get_features = virtio_mmio_get_features; k->device_plugged = virtio_mmio_device_plugged; k->has_variable_vring_alignment = true; diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c index 10123f3..6b40d56 100644 --- a/hw/virtio/virtio-mmio.c +++ b/hw/virtio/virtio-mmio.c @@ -23,6 +23,7 @@ #include "hw/virtio/virtio.h" #include "qemu/host-utils.h" #include "hw/virtio/virtio-bus.h" +#include "qemu/error-report.h" /* #define DEBUG_VIRTIO_MMIO */ @@ -87,8 +88,59 @@ typedef struct { uint32_t guest_page_shift; /* virtio-bus */ VirtioBusState bus; + bool ioeventfd_disabled; + bool ioeventfd_started; } VirtIOMMIOProxy; +static int virtio_mmio_set_host_notifier_internal(VirtIOMMIOProxy *proxy, + int n, bool assign, + bool set_handler) +{ + VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); + VirtQueue *vq = virtio_get_queue(vdev, n); + EventNotifier *notifier = virtio_queue_get_host_notifier(vq); + int r = 0; + + if (assign) { + r = event_notifier_init(notifier, 1); + if (r < 0) { + error_report("%s: unable to init event notifier: %d", + __func__, r); + return r; + } + virtio_queue_set_host_notifier_fd_handler(vq, true, set_handler); + memory_region_add_eventfd(&proxy->iomem, VIRTIO_MMIO_QUEUENOTIFY, 4, + true, n, notifier); + } else { + memory_region_del_eventfd(&proxy->iomem, VIRTIO_MMIO_QUEUENOTIFY, 4, + true, n, notifier); + virtio_queue_set_host_notifier_fd_handler(vq, false, false); + event_notifier_cleanup(notifier); + } + return r; +} + +static void virtio_mmio_stop_ioeventfd(VirtIOMMIOProxy *proxy) +{ + int r; + int n; + VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); + + if (!proxy->ioeventfd_started) { + return; + } + + for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) { + if (!virtio_queue_get_num(vdev, n)) { + continue; + } + + r = virtio_mmio_set_host_notifier_internal(proxy, n, false, false); + assert(r >= 0); + } + proxy->ioeventfd_started = false; +} + static uint64_t virtio_mmio_read(void *opaque, hwaddr offset, unsigned