From patchwork Tue Jul 24 22:33:59 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nicholas A. Bellinger" X-Patchwork-Id: 173070 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 9B9032C0078 for ; Wed, 25 Jul 2012 08:37:39 +1000 (EST) Received: from localhost ([::1]:36286 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StnjV-0004Wh-JL for incoming@patchwork.ozlabs.org; Tue, 24 Jul 2012 18:37:37 -0400 Received: from eggs.gnu.org ([208.118.235.92]:60198) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StnjB-0004R5-Jt for qemu-devel@nongnu.org; Tue, 24 Jul 2012 18:37:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1StnjA-00032u-Fk for qemu-devel@nongnu.org; Tue, 24 Jul 2012 18:37:17 -0400 Received: from mail.linux-iscsi.org ([67.23.28.174]:51103 helo=linux-iscsi.org) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1StnjA-00032g-7l for qemu-devel@nongnu.org; Tue, 24 Jul 2012 18:37:16 -0400 Received: from linux-iscsi.org (localhost [127.0.0.1]) by linux-iscsi.org (Postfix) with ESMTP id 73D3F22D9DE; Tue, 24 Jul 2012 22:34:14 +0000 (UTC) From: "Nicholas A. Bellinger" To: target-devel Date: Tue, 24 Jul 2012 22:33:59 +0000 Message-Id: <1343169246-17636-3-git-send-email-nab@linux-iscsi.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1343169246-17636-1-git-send-email-nab@linux-iscsi.org> References: <1343169246-17636-1-git-send-email-nab@linux-iscsi.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 1) X-Received-From: 67.23.28.174 Cc: Jens Axboe , Anthony Liguori , Stefan Hajnoczi , kvm-devel , "Michael S. Tsirkin" , qemu-devel , Zhi Yong Wu , Anthony Liguori , Hannes Reinecke , Paolo Bonzini , lf-virt , Christoph Hellwig Subject: [Qemu-devel] [RFC 2/9] virtio-pci: support host notifiers in TCG mode 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 From: Stefan Hajnoczi Normally host notifiers are only used together with vhost-net in KVM mode. It is occassionally useful to use vhost with TCG mode, mainly for testing and development. This isn't hard to achieve, simply fall back to notifying the host notifier manually from qemu if KVM mode is disabled. Signed-off-by: Stefan Hajnoczi Cc: Anthony Liguori Cc: Paolo Bonzini Signed-off-by: Nicholas Bellinger --- hw/virtio-pci.c | 23 ++++++++++++++++++++--- hw/virtio.c | 7 +++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index 4e03f0b..538eef4 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -249,6 +249,25 @@ void virtio_pci_reset(DeviceState *d) proxy->flags &= ~VIRTIO_PCI_FLAG_BUS_MASTER_BUG; } +static void virtio_pci_queue_notify(VirtIOPCIProxy *proxy, uint32_t n) +{ + VirtQueue *vq; + EventNotifier *notifier; + + if (n >= VIRTIO_PCI_QUEUE_MAX) { + return; + } + + vq = virtio_get_queue(proxy->vdev, n); + notifier = virtio_queue_get_host_notifier(vq); + if (event_notifier_valid(notifier)) { + printf("notifying vq %u host notifier from userspace\n", n); + event_notifier_notify(notifier); + } else { + virtio_queue_notify_vq(vq); + } +} + static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val) { VirtIOPCIProxy *proxy = opaque; @@ -278,9 +297,7 @@ static void virtio_ioport_write(void *opaque, uint32_t addr, uint32_t val) vdev->queue_sel = val; break; case VIRTIO_PCI_QUEUE_NOTIFY: - if (val < VIRTIO_PCI_QUEUE_MAX) { - virtio_queue_notify(vdev, val); - } + virtio_pci_queue_notify(proxy, val); break; case VIRTIO_PCI_STATUS: if (!(val & VIRTIO_CONFIG_S_DRIVER_OK)) { diff --git a/hw/virtio.c b/hw/virtio.c index d146f86..36a18b5 100644 --- a/hw/virtio.c +++ b/hw/virtio.c @@ -536,6 +536,11 @@ void virtio_reset(void *opaque) vdev->vq[i].signalled_used = 0; vdev->vq[i].signalled_used_valid = false; vdev->vq[i].notification = true; + + assert(!event_notifier_valid(&vdev->vq[i].guest_notifier)); + assert(!event_notifier_valid(&vdev->vq[i].host_notifier)); + vdev->vq[i].guest_notifier = EVENT_NOTIFIER_INITIALIZER; + vdev->vq[i].host_notifier = EVENT_NOTIFIER_INITIALIZER; } } @@ -905,6 +910,8 @@ VirtIODevice *virtio_common_init(const char *name, uint16_t device_id, for(i = 0; i < VIRTIO_PCI_QUEUE_MAX; i++) { vdev->vq[i].vector = VIRTIO_NO_VECTOR; vdev->vq[i].vdev = vdev; + vdev->vq[i].guest_notifier = EVENT_NOTIFIER_INITIALIZER; + vdev->vq[i].host_notifier = EVENT_NOTIFIER_INITIALIZER; } vdev->name = name;