From patchwork Mon Apr 22 09:11:48 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cornelia Huck X-Patchwork-Id: 238372 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 7ABBA2C00FF for ; Mon, 22 Apr 2013 19:14:12 +1000 (EST) Received: from localhost ([::1]:56121 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUCp8-000539-Lb for incoming@patchwork.ozlabs.org; Mon, 22 Apr 2013 05:14:10 -0400 Received: from eggs.gnu.org ([208.118.235.92]:57439) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUCn9-0002e7-Er for qemu-devel@nongnu.org; Mon, 22 Apr 2013 05:12:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UUCn0-000511-LT for qemu-devel@nongnu.org; Mon, 22 Apr 2013 05:12:07 -0400 Received: from e06smtp16.uk.ibm.com ([195.75.94.112]:48911) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UUCn0-0004yj-CM for qemu-devel@nongnu.org; Mon, 22 Apr 2013 05:11:58 -0400 Received: from /spool/local by e06smtp16.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 22 Apr 2013 10:08:20 +0100 Received: from d06dlp02.portsmouth.uk.ibm.com (9.149.20.14) by e06smtp16.uk.ibm.com (192.168.101.146) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 22 Apr 2013 10:08:18 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id E8AED219002D for ; Mon, 22 Apr 2013 10:14:15 +0100 (BST) Received: from d06av03.portsmouth.uk.ibm.com (d06av03.portsmouth.uk.ibm.com [9.149.37.213]) by b06cxnps3075.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r3M9BilX52691010 for ; Mon, 22 Apr 2013 09:11:44 GMT Received: from d06av03.portsmouth.uk.ibm.com (localhost.localdomain [127.0.0.1]) by d06av03.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r3M9Br8l009667 for ; Mon, 22 Apr 2013 03:11:53 -0600 Received: from gondolin.boeblingen.de.ibm.com (dyn-9-152-224-122.boeblingen.de.ibm.com [9.152.224.122]) by d06av03.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r3M9BqlZ009566; Mon, 22 Apr 2013 03:11:53 -0600 From: Cornelia Huck To: qemu-devel@nongnu.org Date: Mon, 22 Apr 2013 11:11:48 +0200 Message-Id: <1366621908-16373-4-git-send-email-cornelia.huck@de.ibm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1366621908-16373-1-git-send-email-cornelia.huck@de.ibm.com> References: <1366621908-16373-1-git-send-email-cornelia.huck@de.ibm.com> In-Reply-To: <516FA6E0.8050707@de.ibm.com> References: <516FA6E0.8050707@de.ibm.com> X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13042209-3548-0000-0000-0000052BF9F0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4.x-2.6.x [generic] X-Received-From: 195.75.94.112 Cc: Christian Borntraeger , Alexander Graf , "Michael S. Tsirkin" Subject: [Qemu-devel] [PATCH RFC 3/3] virtio-ccw: Wire up guest and host notifies. 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 Guest and host notifiers are needed by vhost. We use ioeventfds for the guest notifiers, but need to fall back on qemu injecting interrupts for the host notifiers. Signed-off-by: Cornelia Huck --- hw/s390x/virtio-ccw.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/s390x/virtio-ccw.h | 1 + 2 files changed, 91 insertions(+) diff --git a/hw/s390x/virtio-ccw.c b/hw/s390x/virtio-ccw.c index 7acd39d..89dad0d 100644 --- a/hw/s390x/virtio-ccw.c +++ b/hw/s390x/virtio-ccw.c @@ -95,6 +95,7 @@ static void virtio_ccw_start_ioeventfd(VirtioCcwDevice *dev) int n, r; if (!(dev->flags & VIRTIO_CCW_FLAG_USE_IOEVENTFD) || + dev->ioeventfd_disabled || dev->ioeventfd_started) { return; } @@ -859,12 +860,98 @@ static void virtio_ccw_vmstate_change(DeviceState *d, bool running) } } +static bool virtio_ccw_query_guest_notifiers(DeviceState *d) +{ + VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d); + + return !!(dev->sch->curr_status.pmcw.flags & PMCW_FLAGS_MASK_ENA); +} + +static int virtio_ccw_set_host_notifier(DeviceState *d, int n, bool assign) +{ + VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d); + + /* Stop using the generic ioeventfd, we are doing eventfd handling + * ourselves below */ + dev->ioeventfd_disabled = assign; + if (assign) { + virtio_ccw_stop_ioeventfd(dev); + } + return virtio_ccw_set_guest2host_notifier(dev, n, assign, false); +} + +static int virtio_ccw_set_guest_notifier(VirtioCcwDevice *dev, int n, + bool assign, bool with_irqfd) +{ + VirtQueue *vq = virtio_get_queue(dev->vdev, n); + EventNotifier *notifier = virtio_queue_get_guest_notifier(vq); + + if (assign) { + int r = event_notifier_init(notifier, 0); + + if (r < 0) { + return r; + } + virtio_queue_set_guest_notifier_fd_handler(vq, true, with_irqfd); + /* We do not support irqfd for classic I/O interrupts, because the + * classic interrupts are intermixed with the subchannel status, that + * is queried with test subchannel. We want to use vhost, though. + * Lets make sure to have vhost running and wire up the irq fd to + * land in qemu (and only the irq fd) in this code. + */ + if (dev->vdev->guest_notifier_mask) { + dev->vdev->guest_notifier_mask(dev->vdev, n, false); + } + /* get lost events and re-inject */ + if (dev->vdev->guest_notifier_pending && + dev->vdev->guest_notifier_pending(dev->vdev, n)) { + event_notifier_set(notifier); + } + } else { + if (dev->vdev->guest_notifier_mask) { + dev->vdev->guest_notifier_mask(dev->vdev, n, true); + } + virtio_queue_set_guest_notifier_fd_handler(vq, false, with_irqfd); + event_notifier_cleanup(notifier); + } + return 0; +} + +static int virtio_ccw_set_guest_notifiers(DeviceState *d, int nvqs, + bool assigned) +{ + VirtioCcwDevice *dev = VIRTIO_CCW_DEVICE(d); + VirtIODevice *vdev = dev->vdev; + int r, n; + + for (n = 0; n < nvqs; n++) { + if (!virtio_queue_get_num(vdev, n)) { + break; + } + /* false -> true, as soon as irqfd works */ + r = virtio_ccw_set_guest_notifier(dev, n, assigned, false); + if (r < 0) { + goto assign_error; + } + } + return 0; + +assign_error: + while (--n >= 0) { + virtio_ccw_set_guest_notifier(dev, n, !assigned, false); + } + return r; +} + /**************** Virtio-ccw Bus Device Descriptions *******************/ static const VirtIOBindings virtio_ccw_bindings = { .notify = virtio_ccw_notify, .get_features = virtio_ccw_get_features, .vmstate_change = virtio_ccw_vmstate_change, + .query_guest_notifiers = virtio_ccw_query_guest_notifiers, + .set_host_notifier = virtio_ccw_set_host_notifier, + .set_guest_notifiers = virtio_ccw_set_guest_notifiers, }; static Property virtio_ccw_net_properties[] = { @@ -1148,6 +1235,9 @@ static void virtio_ccw_bus_class_init(ObjectClass *klass, void *data) k->notify = virtio_ccw_notify; k->get_features = virtio_ccw_get_features; k->vmstate_change = virtio_ccw_vmstate_change; + k->query_guest_notifiers = virtio_ccw_query_guest_notifiers; + k->set_host_notifier = virtio_ccw_set_host_notifier; + k->set_guest_notifiers = virtio_ccw_set_guest_notifiers; } static const TypeInfo virtio_ccw_bus_info = { diff --git a/hw/s390x/virtio-ccw.h b/hw/s390x/virtio-ccw.h index 1a7a860..4ae01cb 100644 --- a/hw/s390x/virtio-ccw.h +++ b/hw/s390x/virtio-ccw.h @@ -82,6 +82,7 @@ struct VirtioCcwDevice { VirtIORNGConf rng; VirtioBusState bus; bool ioeventfd_started; + bool ioeventfd_disabled; uint32_t flags; /* Guest provided values: */ hwaddr indicators;