From patchwork Sun Oct 30 21:23:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 689089 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 3t6WFG386qz9t17 for ; Mon, 31 Oct 2016 08:42:58 +1100 (AEDT) Received: from localhost ([::1]:60143 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c0xsV-0002py-Mg for incoming@patchwork.ozlabs.org; Sun, 30 Oct 2016 17:42:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54963) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c0xaC-00036I-Uv for qemu-devel@nongnu.org; Sun, 30 Oct 2016 17:24:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c0xa9-0006mo-LQ for qemu-devel@nongnu.org; Sun, 30 Oct 2016 17:24:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59862) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1c0xa9-0006mX-Dz for qemu-devel@nongnu.org; Sun, 30 Oct 2016 17:23:57 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id ADC9B6A6AB; Sun, 30 Oct 2016 21:23:56 +0000 (UTC) Received: from redhat.com (ovpn-112-24.rdu2.redhat.com [10.10.112.24]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id u9ULNth3001491; Sun, 30 Oct 2016 17:23:55 -0400 Date: Sun, 30 Oct 2016 23:23:55 +0200 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <1477850917-1214-13-git-send-email-mst@redhat.com> References: <1477850917-1214-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1477850917-1214-1-git-send-email-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sun, 30 Oct 2016 21:23:56 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 12/47] virtio: remove ioeventfd_disabled altogether X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cornelia Huck , Peter Maydell , Paolo Bonzini Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Paolo Bonzini Now that there is not anymore a switch from the generic ioeventfd handler to the dataplane handler, virtio_bus_set_host_notifier(assign=true) is always called with !bus->ioeventfd_started, hence virtio_bus_stop_ioeventfd does nothing in this case. Move the invocation to vhost.c, which is the only place that needs it. Reviewed-by: Cornelia Huck Signed-off-by: Paolo Bonzini Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/virtio-bus.h | 6 ------ hw/virtio/vhost.c | 3 +++ hw/virtio/virtio-bus.c | 23 ++++++++--------------- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/include/hw/virtio/virtio-bus.h b/include/hw/virtio/virtio-bus.h index af6b5c4..cbdf745 100644 --- a/include/hw/virtio/virtio-bus.h +++ b/include/hw/virtio/virtio-bus.h @@ -94,12 +94,6 @@ struct VirtioBusState { BusState parent_obj; /* - * Set if the default ioeventfd handlers are disabled by vhost - * or dataplane. - */ - bool ioeventfd_disabled; - - /* * Set if ioeventfd has been started. */ bool ioeventfd_started; diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 501a5f4..131f164 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1196,6 +1196,7 @@ int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev) goto fail; } + virtio_device_stop_ioeventfd(vdev); for (i = 0; i < hdev->nvqs; ++i) { r = virtio_bus_set_host_notifier(VIRTIO_BUS(qbus), hdev->vq_index + i, true); @@ -1215,6 +1216,7 @@ fail_vq: } assert (e >= 0); } + virtio_device_start_ioeventfd(vdev); fail: return r; } @@ -1237,6 +1239,7 @@ void vhost_dev_disable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev) } assert (r >= 0); } + virtio_device_start_ioeventfd(vdev); } /* Test and clear event pending status. diff --git a/hw/virtio/virtio-bus.c b/hw/virtio/virtio-bus.c index a619445..b0e4544 100644 --- a/hw/virtio/virtio-bus.c +++ b/hw/virtio/virtio-bus.c @@ -190,7 +190,7 @@ int virtio_bus_start_ioeventfd(VirtioBusState *bus) if (!k->ioeventfd_assign || !k->ioeventfd_enabled(proxy)) { return -ENOSYS; } - if (bus->ioeventfd_started || bus->ioeventfd_disabled) { + if (bus->ioeventfd_started) { return 0; } r = vdc->start_ioeventfd(vdev); @@ -226,8 +226,8 @@ bool virtio_bus_ioeventfd_enabled(VirtioBusState *bus) } /* - * This function switches from/to the generic ioeventfd handler. - * assign==false means 'use generic ioeventfd handler'. + * This function switches ioeventfd on/off in the device. + * The caller must set or clear the handlers for the EventNotifier. */ int virtio_bus_set_host_notifier(VirtioBusState *bus, int n, bool assign) { @@ -237,19 +237,12 @@ int virtio_bus_set_host_notifier(VirtioBusState *bus, int n, bool assign) if (!k->ioeventfd_assign) { return -ENOSYS; } - bus->ioeventfd_disabled = assign; if (assign) { - /* - * Stop using the generic ioeventfd, we are doing eventfd handling - * ourselves below - * - * FIXME: We should just switch the handler and not deassign the - * ioeventfd. - * Otherwise, there's a window where we don't have an - * ioeventfd and we may end up with a notification where - * we don't expect one. - */ - virtio_bus_stop_ioeventfd(bus); + assert(!bus->ioeventfd_started); + } else { + if (!bus->ioeventfd_started) { + return 0; + } } return set_host_notifier_internal(proxy, bus, n, assign); }