From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56421) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YqM6K-00034G-0Y for qemu-devel@nongnu.org; Thu, 07 May 2015 09:44:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YqM6F-0006Tx-Ta for qemu-devel@nongnu.org; Thu, 07 May 2015 09:44:31 -0400 Received: from e06smtp11.uk.ibm.com ([195.75.94.107]:45648) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YqM6F-0006SE-LK for qemu-devel@nongnu.org; Thu, 07 May 2015 09:44:27 -0400 Received: from /spool/local by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 7 May 2015 14:44:25 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id 710E51B08023 for ; Thu, 7 May 2015 14:45:06 +0100 (BST) Received: from d06av03.portsmouth.uk.ibm.com (d06av03.portsmouth.uk.ibm.com [9.149.37.213]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t47DiNGm8257814 for ; Thu, 7 May 2015 13:44:23 GMT Received: from d06av03.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av03.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t47DiNF3011474 for ; Thu, 7 May 2015 07:44:23 -0600 Date: Thu, 7 May 2015 15:44:21 +0200 From: Cornelia Huck Message-ID: <20150507154421.5d93bcd7.cornelia.huck@de.ibm.com> In-Reply-To: <016101d088b3$c57d9690$5078c3b0$@samsung.com> References: <016101d088b3$c57d9690$5078c3b0$@samsung.com> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 3/3] virtio-mmio: start ioeventfd when status gets DRIVER_OK List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Pavel Fedin Cc: qemu-devel@nongnu.org On Thu, 07 May 2015 13:51:27 +0300 Pavel Fedin wrote: Would it make sense to merge this with the first patch, so that you introduce ioeventfds in one go? > Signed-off-by: Ying-Shiuan Pan > Signed-off-by: Pavel Fedin > --- > hw/virtio/virtio-mmio.c | 47 > +++++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 47 insertions(+) > > diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c > index 8756240..0ab270d 100644 > --- a/hw/virtio/virtio-mmio.c > +++ b/hw/virtio/virtio-mmio.c > @@ -22,6 +22,7 @@ > #include "hw/sysbus.h" > #include "hw/virtio/virtio.h" > #include "qemu/host-utils.h" > +#include "sysemu/kvm.h" > #include "hw/virtio/virtio-bus.h" > #include "qemu/error-report.h" > > @@ -120,6 +121,43 @@ static int > virtio_mmio_set_host_notifier_internal(VirtIOMMIOProxy *proxy, > return r; > } > > +static void virtio_mmio_start_ioeventfd(VirtIOMMIOProxy *proxy) > +{ > + VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); > + int n, r; > + > + if (!kvm_eventfds_enabled() || > + proxy->ioeventfd_disabled || > + 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, true, true); > + if (r < 0) { > + goto assign_error; > + } > + } > + proxy->ioeventfd_started = true; > + return; > + > +assign_error: > + while (--n >= 0) { > + 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; > + error_report("%s: failed. Fallback to a userspace (slower).", > __func__); > +} Again, much commonality with pci and ccw, with two differences: - the check at the beginning of the function (easily factored out) - ccw disables ioeventfds on failure, pci doesn't and mmio can't as they don't have a device where they can tack an ioeventfd property bit on - this means mmio always uses ioeventfds for all devices if supported, no? > + > static void virtio_mmio_stop_ioeventfd(VirtIOMMIOProxy *proxy) > { > int r; > @@ -318,7 +356,16 @@ static void virtio_mmio_write(void *opaque, hwaddr > offset, uint64_t value, > virtio_update_irq(vdev); > break; > case VIRTIO_MMIO_STATUS: > + if (!(value & VIRTIO_CONFIG_S_DRIVER_OK)) { > + virtio_mmio_stop_ioeventfd(proxy); > + } > + > virtio_set_status(vdev, value & 0xff); > + > + if (value & VIRTIO_CONFIG_S_DRIVER_OK) { > + virtio_mmio_start_ioeventfd(proxy); > + } > + > if (vdev->status == 0) { > virtio_reset(vdev); > } Don't you also want to stop the ioeventfd on reset?