From patchwork Tue Mar 7 13:16:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Halil Pasic X-Patchwork-Id: 9608877 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 70EEC60414 for ; Tue, 7 Mar 2017 13:17:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26A73283C9 for ; Tue, 7 Mar 2017 13:17:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1765F2850E; Tue, 7 Mar 2017 13:17:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 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.wl.linuxfoundation.org (Postfix) with ESMTPS id 6D438283C9 for ; Tue, 7 Mar 2017 13:17:51 +0000 (UTC) Received: from localhost ([::1]:49885 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clEzu-0007Dq-75 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 07 Mar 2017 08:17:50 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55084) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1clEzf-0007DL-GV for qemu-devel@nongnu.org; Tue, 07 Mar 2017 08:17:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1clEzc-00040l-6M for qemu-devel@nongnu.org; Tue, 07 Mar 2017 08:17:35 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:58391) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1clEzb-00040E-Sf for qemu-devel@nongnu.org; Tue, 07 Mar 2017 08:17:32 -0500 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v27DDZBi145024 for ; Tue, 7 Mar 2017 08:17:30 -0500 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0a-001b2d01.pphosted.com with ESMTP id 291w62he03-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Tue, 07 Mar 2017 08:17:30 -0500 Received: from localhost by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 7 Mar 2017 13:17:27 -0000 Received: from d06dlp02.portsmouth.uk.ibm.com (9.149.20.14) by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 7 Mar 2017 13:17:23 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id 436F72190061; Tue, 7 Mar 2017 13:16:23 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v27DHNYv12910998; Tue, 7 Mar 2017 13:17:23 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2F5DAAE05A; Tue, 7 Mar 2017 13:17:15 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EF188AE045; Tue, 7 Mar 2017 13:17:14 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Tue, 7 Mar 2017 13:17:14 +0000 (GMT) From: Halil Pasic To: qemu-devel@nongnu.org, "Michael S. Tsirkin" Date: Tue, 7 Mar 2017 14:16:50 +0100 X-Mailer: git-send-email 2.8.4 X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 17030713-0016-0000-0000-0000044D73FD X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17030713-0017-0000-0000-000026B35994 Message-Id: <20170307131650.90167-1-pasic@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-03-07_08:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1703070112 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH v2 1/1] virtio-blk: fix race on guest notifiers 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 , Paolo Bonzini , Halil Pasic , qemu-stable@nongnu.org, Stefan Hajnoczi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The commits 03de2f527 "virtio-blk: do not use vring in dataplane" and 9ffe337c08 "virtio-blk: always use dataplane path if ioeventfd is active" changed how notifications are done for virtio-blk substantially. Due to a race condition, interrupts are lost when irqfd behind the guest notifier is torn down after notify_guest_bh was scheduled but before it actually runs. Let's fix this by forcing guest notifications before cleaning up the irqfd's. Let's also add some explanatory comments. Cc: qemu-stable@nongnu.org Signed-off-by: Halil Pasic Reported-by: Michael A. Tebolt Tested-by: Michael A. Tebolt Suggested-by: Paolo Bonzini --- This patch withstood the test case which discovered the problem for several days (as reported by Michale Tebolt). v1 --> v2: * Fixed typo pointed out by Connie * Added Tested-by --- hw/block/dataplane/virtio-blk.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-blk.c index 5556f0e..045a580 100644 --- a/hw/block/dataplane/virtio-blk.c +++ b/hw/block/dataplane/virtio-blk.c @@ -258,9 +258,16 @@ void virtio_blk_data_plane_stop(VirtIODevice *vdev) virtio_queue_aio_set_host_notifier_handler(vq, s->ctx, NULL); } - /* Drain and switch bs back to the QEMU main loop */ + /* Drain and switch bs back to the QEMU main loop. After drain, the + * device will not submit (nor complete) any requests until dataplane + * starts again. + */ blk_set_aio_context(s->conf->conf.blk, qemu_get_aio_context()); + /* Notify guest before the guest notifiers get cleaned up */ + qemu_bh_cancel(s->bh); + notify_guest_bh(s); + aio_context_release(s->ctx); for (i = 0; i < nvqs; i++) {