From patchwork Tue Apr 7 10:45:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 458625 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 2BA841402AC for ; Tue, 7 Apr 2015 20:46:31 +1000 (AEST) Received: from localhost ([::1]:44194 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YfR1Z-0004Tt-Dl for incoming@patchwork.ozlabs.org; Tue, 07 Apr 2015 06:46:29 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49086) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YfR17-0003m3-Hb for qemu-devel@nongnu.org; Tue, 07 Apr 2015 06:46:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YfR15-000889-KM for qemu-devel@nongnu.org; Tue, 07 Apr 2015 06:46:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49606) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YfR15-000885-D1 for qemu-devel@nongnu.org; Tue, 07 Apr 2015 06:45:59 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id DC6C2C2FF8 for ; Tue, 7 Apr 2015 10:45:58 +0000 (UTC) Received: from redhat.com (ovpn-116-20.ams2.redhat.com [10.36.116.20]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with SMTP id t37AjuPG022612; Tue, 7 Apr 2015 06:45:57 -0400 Date: Tue, 7 Apr 2015 12:45:56 +0200 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <1428403546-31914-2-git-send-email-mst@redhat.com> References: <1428403546-31914-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1428403546-31914-1-git-send-email-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Jason Wang Subject: [Qemu-devel] [PATCH 1/3] virtio: interface to enable/disable host notifiers 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 generalize and move these from vhost to virtio. Signed-off-by: Michael S. Tsirkin --- include/hw/virtio/virtio.h | 3 +++ hw/virtio/vhost.c | 45 ++-------------------------------------- hw/virtio/virtio.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 43 deletions(-) diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index d95f8b6..e1cff22 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -219,6 +219,9 @@ void virtio_queue_set_host_notifier_fd_handler(VirtQueue *vq, bool assign, void virtio_queue_notify_vq(VirtQueue *vq); void virtio_irq(VirtQueue *vq); +int virtio_enable_host_notifiers(VirtIODevice *vdev, int startvq, int nvqs); +void virtio_disable_host_notifiers(VirtIODevice *vdev, int startvq, int nvqs); + static inline void virtio_add_feature(uint32_t *features, unsigned int fbit) { assert(fbit < 32); diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 5a12861..8dd2f59 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -918,36 +918,7 @@ bool vhost_dev_query(struct vhost_dev *hdev, VirtIODevice *vdev) */ int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev) { - BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); - VirtioBusState *vbus = VIRTIO_BUS(qbus); - VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus); - int i, r; - if (!k->set_host_notifier) { - fprintf(stderr, "binding does not support host notifiers\n"); - r = -ENOSYS; - goto fail; - } - - for (i = 0; i < hdev->nvqs; ++i) { - r = k->set_host_notifier(qbus->parent, hdev->vq_index + i, true); - if (r < 0) { - fprintf(stderr, "vhost VQ %d notifier binding failed: %d\n", i, -r); - goto fail_vq; - } - } - - return 0; -fail_vq: - while (--i >= 0) { - r = k->set_host_notifier(qbus->parent, hdev->vq_index + i, false); - if (r < 0) { - fprintf(stderr, "vhost VQ %d notifier cleanup error: %d\n", i, -r); - fflush(stderr); - } - assert (r >= 0); - } -fail: - return r; + return virtio_enable_host_notifiers(vdev, hdev->vq_index, hdev->nvqs); } /* Stop processing guest IO notifications in vhost. @@ -957,19 +928,7 @@ fail: */ void vhost_dev_disable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev) { - BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); - VirtioBusState *vbus = VIRTIO_BUS(qbus); - VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus); - int i, r; - - for (i = 0; i < hdev->nvqs; ++i) { - r = k->set_host_notifier(qbus->parent, hdev->vq_index + i, false); - if (r < 0) { - fprintf(stderr, "vhost VQ %d notifier cleanup failed: %d\n", i, -r); - fflush(stderr); - } - assert (r >= 0); - } + virtio_disable_host_notifiers(vdev, hdev->vq_index, hdev->nvqs); } /* Test and clear event pending status. diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 17c1260..e7ee069 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -1283,6 +1283,57 @@ void virtio_device_set_child_bus_name(VirtIODevice *vdev, char *bus_name) vdev->bus_name = g_strdup(bus_name); } +int virtio_enable_host_notifiers(VirtIODevice *vdev, int startvq, int nvqs) +{ + BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusState *vbus = VIRTIO_BUS(qbus); + VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus); + int i, r; + if (!k->set_host_notifier) { + fprintf(stderr, "binding does not support host notifiers\n"); + r = -ENOSYS; + goto fail; + } + + for (i = 0; i < nvqs; ++i) { + r = k->set_host_notifier(qbus->parent, startvq + i, true); + if (r < 0) { + fprintf(stderr, "vhost VQ %d notifier binding failed: %d\n", i, -r); + goto fail_vq; + } + } + + return 0; +fail_vq: + while (--i >= 0) { + r = k->set_host_notifier(qbus->parent, startvq + i, false); + if (r < 0) { + fprintf(stderr, "vhost VQ %d notifier cleanup error: %d\n", i, -r); + fflush(stderr); + } + assert (r >= 0); + } +fail: + return r; +} + +void virtio_disable_host_notifiers(VirtIODevice *vdev, int startvq, int nvqs) +{ + BusState *qbus = BUS(qdev_get_parent_bus(DEVICE(vdev))); + VirtioBusState *vbus = VIRTIO_BUS(qbus); + VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(vbus); + int i, r; + + for (i = 0; i < nvqs; ++i) { + r = k->set_host_notifier(qbus->parent, startvq + i, false); + if (r < 0) { + fprintf(stderr, "vhost VQ %d notifier cleanup failed: %d\n", i, -r); + fflush(stderr); + } + assert (r >= 0); + } +} + static void virtio_device_realize(DeviceState *dev, Error **errp) { VirtIODevice *vdev = VIRTIO_DEVICE(dev);