From patchwork Fri Apr 1 13:19:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 8724551 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5F783C0553 for ; Fri, 1 Apr 2016 13:23:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 91FE3203AE for ; Fri, 1 Apr 2016 13:23:19 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BD52920303 for ; Fri, 1 Apr 2016 13:23:18 +0000 (UTC) Received: from localhost ([::1]:44352 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alz2k-0005G7-1V for patchwork-qemu-devel@patchwork.kernel.org; Fri, 01 Apr 2016 09:23:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56294) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alyzf-0008Pi-Ov for qemu-devel@nongnu.org; Fri, 01 Apr 2016 09:20:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1alyzb-0001rt-Og for qemu-devel@nongnu.org; Fri, 01 Apr 2016 09:20:07 -0400 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:35738) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1alyzb-0001rf-E5 for qemu-devel@nongnu.org; Fri, 01 Apr 2016 09:20:03 -0400 Received: by mail-wm0-x244.google.com with SMTP id 139so4567464wmn.2 for ; Fri, 01 Apr 2016 06:20:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=fMhXvoEJJ0+/hZdxrhvttkP8J0R+iJ2xBdIbCEPRndE=; b=NWExj3DirL6zPaTx+gHhlfYyHfABa4T/DDIIBw5l2QhL6SJLnFCVLVZ8V4XrTSqA/B CYCrKmaOP7cscVpGP2qIE3A/3htxzEn698EA1r9817muFYlD0IM7zBQtX5whfRgDG4Av WtjN2dmGrBHIxGCUvNjnxR+oawoVIV9MqwEhdpr5sWemSurSoMoc2a0Ohz2pjDDabGlt wnqhViPUvwyi1MNWji6KlVucos2Itt3mo6paXX550LU82/nliztPOslWNebx4s1fYI86 HCdG0m03SMz0aJOUfWSiwTmYuQLC2pYLVQLZeLaPIxKUevI9aL3XnoPwKSjD51UCOP/w 8lqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=fMhXvoEJJ0+/hZdxrhvttkP8J0R+iJ2xBdIbCEPRndE=; b=gBaq58VPe0gh128yDpq+VIU7KdHhcOuHrcg1raHwhmvK4e+pY3p4t2UI8UTtZGzCWm 8XwWB18h/WqKzRTGM4YXswx6pc9xzmB5WV4Y2qFP3on0aMhyhZPPqt0xAm3X6iPDa+T1 gu84t+IDGno3Sa7SEwwDAhI+yMI+FgOKbpyL5ZsIYrny7nuF3KWa96Q6r26awyZk6nHA 2yxnSKmbB1MBWJBp3FRRvHRJ1nAH0oG+ZnrDBGxzNvmUEDsq67MNwVDfaN/Hx3CvARFn nBfsWraHzqadHfMIBc/T4aDVuLVzjObY9HV/fmykbPTyn6sjTrmygoM4HMSdUN/3XcWx p2sQ== X-Gm-Message-State: AD7BkJJNzPUM7EOoOuqUF0FDvkHcXFUsPyIhpEMImgJkqgEnEdA4YBSzD+r24cfQFXXn8w== X-Received: by 10.194.75.196 with SMTP id e4mr4681906wjw.134.1459516802905; Fri, 01 Apr 2016 06:20:02 -0700 (PDT) Received: from 640k.lan (94-39-141-76.adsl-ull.clienti.tiscali.it. [94.39.141.76]) by smtp.gmail.com with ESMTPSA id a1sm14032334wje.43.2016.04.01.06.20.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Apr 2016 06:20:02 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 1 Apr 2016 15:19:50 +0200 Message-Id: <1459516794-23629-6-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1459516794-23629-1-git-send-email-pbonzini@redhat.com> References: <1459516794-23629-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::244 Cc: famz@redhat.com, tubo@linux.vnet.ibm.com, mst@redhat.com, borntraeger@de.ibm.com, stefanha@redhat.com, cornelia.huck@de.ibm.com Subject: [Qemu-devel] [PATCH 5/9] virtio: add aio handler 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+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: "Michael S. Tsirkin" In addition to handling IO in vcpu thread and in io thread, blk dataplane introduces yet another mode: handling it by aio. This reuses the same handler as previous modes, which triggers races as these were not designed to be reentrant. As a temporary fix, add a separate handler just for aio, this will make it possible to disable regular handlers when dataplane is active. Signed-off-by: Michael S. Tsirkin Signed-off-by: Paolo Bonzini Reviewed-by: Cornelia Huck --- hw/virtio/virtio.c | 36 ++++++++++++++++++++++++++++++++---- include/hw/virtio/virtio.h | 3 +++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 264d4f6..eb04ac0 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -96,6 +96,7 @@ struct VirtQueue uint16_t vector; void (*handle_output)(VirtIODevice *vdev, VirtQueue *vq); + void (*handle_aio_output)(VirtIODevice *vdev, VirtQueue *vq); VirtIODevice *vdev; EventNotifier guest_notifier; EventNotifier host_notifier; @@ -1088,6 +1089,16 @@ void virtio_queue_set_align(VirtIODevice *vdev, int n, int align) virtio_queue_update_rings(vdev, n); } +static void virtio_queue_notify_aio_vq(VirtQueue *vq) +{ + if (vq->vring.desc && vq->handle_aio_output) { + VirtIODevice *vdev = vq->vdev; + + trace_virtio_queue_notify(vdev, vq - vdev->vq, vq); + vq->handle_aio_output(vdev, vq); + } +} + static void virtio_queue_notify_vq(VirtQueue *vq) { if (vq->vring.desc && vq->handle_output) { @@ -1143,10 +1154,19 @@ VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size, vdev->vq[i].vring.num_default = queue_size; vdev->vq[i].vring.align = VIRTIO_PCI_VRING_ALIGN; vdev->vq[i].handle_output = handle_output; + vdev->vq[i].handle_aio_output = NULL; return &vdev->vq[i]; } +void virtio_set_queue_aio(VirtQueue *vq, + void (*handle_output)(VirtIODevice *, VirtQueue *)) +{ + assert(vq->handle_output); + + vq->handle_aio_output = handle_output; +} + void virtio_del_queue(VirtIODevice *vdev, int n) { if (n < 0 || n >= VIRTIO_QUEUE_MAX) { @@ -1780,11 +1800,11 @@ EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq) return &vq->guest_notifier; } -static void virtio_queue_host_notifier_read(EventNotifier *n) +static void virtio_queue_host_notifier_aio_read(EventNotifier *n) { VirtQueue *vq = container_of(n, VirtQueue, host_notifier); if (event_notifier_test_and_clear(n)) { - virtio_queue_notify_vq(vq); + virtio_queue_notify_aio_vq(vq); } } @@ -1793,14 +1813,22 @@ void virtio_queue_aio_set_host_notifier_handler(VirtQueue *vq, AioContext *ctx, { if (assign && set_handler) { aio_set_event_notifier(ctx, &vq->host_notifier, true, - virtio_queue_host_notifier_read); + virtio_queue_host_notifier_aio_read); } else { aio_set_event_notifier(ctx, &vq->host_notifier, true, NULL); } if (!assign) { /* Test and clear notifier before after disabling event, * in case poll callback didn't have time to run. */ - virtio_queue_host_notifier_read(&vq->host_notifier); + virtio_queue_host_notifier_aio_read(&vq->host_notifier); + } +} + +static void virtio_queue_host_notifier_read(EventNotifier *n) +{ + VirtQueue *vq = container_of(n, VirtQueue, host_notifier); + if (event_notifier_test_and_clear(n)) { + virtio_queue_notify_vq(vq); } } diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 5afb51c..fa3f93b 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -142,6 +142,9 @@ VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size, void (*handle_output)(VirtIODevice *, VirtQueue *)); +void virtio_set_queue_aio(VirtQueue *vq, + void (*handle_output)(VirtIODevice *, VirtQueue *)); + void virtio_del_queue(VirtIODevice *vdev, int n); void *virtqueue_alloc_element(size_t sz, unsigned out_num, unsigned in_num);