From nobody Thu May 16 10:41:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1591176826; cv=none; d=zohomail.com; s=zohoarc; b=S5TkDV4XzxctAkROl3Gg3ArQvwPXc3K+vxx8fgsxTslNLk+PdRCLP0zelN/rHdHja2CA/frwFgk6naqOmhHtyfNiOUk9NF72lmFj2WKg085+ntSZXLgUJvAMBJYrHkMJJmqoEgnkVCqsiaxO4QbKSuUznofcpR31qcy83p4qnXY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591176826; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=1iUdiZJpEX3lon84Q5YiPusCWhIjyJg4I48QM9lLous=; b=hmUgEdcAEyzLTnXpD0ZYrNkaS1lZPQR43IN/HHyHQozRiI7X/U9VBP41GGJya6XTgQkYzqvbplMScAhYR1d9LXw2iyq0dboTlc4IpPYtPx5WJQZjQeNx+mRa/GZomKtGp35hhTEEi760n3bQO43iDc9F3yXNOUuqpZYb8JQJD8Y= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 159117682677362.43917297609437; Wed, 3 Jun 2020 02:33:46 -0700 (PDT) Received: from localhost ([::1]:39444 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jgPmL-0002A3-Jh for importer@patchew.org; Wed, 03 Jun 2020 05:33:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48936) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jgPla-0000ju-K0 for qemu-devel@nongnu.org; Wed, 03 Jun 2020 05:32:58 -0400 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:40918 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jgPlZ-0007zf-Cn for qemu-devel@nongnu.org; Wed, 03 Jun 2020 05:32:58 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-469-11PEysy5MhmsDXvTAos8eg-1; Wed, 03 Jun 2020 05:32:54 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 43EE8107ACCD; Wed, 3 Jun 2020 09:32:53 +0000 (UTC) Received: from dritchie.redhat.com (ovpn-112-109.rdu2.redhat.com [10.10.112.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 771045C5D9; Wed, 3 Jun 2020 09:32:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591176775; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1iUdiZJpEX3lon84Q5YiPusCWhIjyJg4I48QM9lLous=; b=JbxmGq6tcVpUNcQ2fCmnQOOa12kqrjcByn2Et4hsRMf+nHjirnx79MIe4hywthQLSEWctK Tl45slRIG3uICc85kWO/cVWWWbaU56R+iMM6Ye9/KqdeECXsI1OF4B3b+S4AdGVfHYBjvc FKuxTF41MXppeNygQux3z/ygx0MQr5o= X-MC-Unique: 11PEysy5MhmsDXvTAos8eg-1 From: Sergio Lopez To: qemu-devel@nongnu.org Subject: [PATCH 1/2] virtio-blk: Refactor the code that processes queued requests Date: Wed, 3 Jun 2020 11:32:39 +0200 Message-Id: <20200603093240.40489-2-slp@redhat.com> In-Reply-To: <20200603093240.40489-1-slp@redhat.com> References: <20200603093240.40489-1-slp@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=207.211.31.120; envelope-from=slp@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/02 23:55:42 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-block@nongnu.org, Sergio Lopez , "Michael S. Tsirkin" , Max Reitz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Move the code that processes queued requests from virtio_blk_dma_restart_bh() to its own, non-static, function. This will allow us to call it from the virtio_blk_data_plane_start() in a future patch. Signed-off-by: Sergio Lopez --- include/hw/virtio/virtio-blk.h | 1 + hw/block/virtio-blk.c | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h index 1e62f869b2..f584ad9b86 100644 --- a/include/hw/virtio/virtio-blk.h +++ b/include/hw/virtio/virtio-blk.h @@ -86,5 +86,6 @@ typedef struct MultiReqBuffer { } MultiReqBuffer; =20 bool virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq); +void virtio_blk_process_queued_requests(VirtIOBlock *s); =20 #endif diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index f5f6fc925e..978574e4da 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -819,15 +819,11 @@ static void virtio_blk_handle_output(VirtIODevice *vd= ev, VirtQueue *vq) virtio_blk_handle_output_do(s, vq); } =20 -static void virtio_blk_dma_restart_bh(void *opaque) +void virtio_blk_process_queued_requests(VirtIOBlock *s) { - VirtIOBlock *s =3D opaque; VirtIOBlockReq *req =3D s->rq; MultiReqBuffer mrb =3D {}; =20 - qemu_bh_delete(s->bh); - s->bh =3D NULL; - s->rq =3D NULL; =20 aio_context_acquire(blk_get_aio_context(s->conf.conf.blk)); @@ -855,6 +851,16 @@ static void virtio_blk_dma_restart_bh(void *opaque) aio_context_release(blk_get_aio_context(s->conf.conf.blk)); } =20 +static void virtio_blk_dma_restart_bh(void *opaque) +{ + VirtIOBlock *s =3D opaque; + + qemu_bh_delete(s->bh); + s->bh =3D NULL; + + virtio_blk_process_queued_requests(s); +} + static void virtio_blk_dma_restart_cb(void *opaque, int running, RunState state) { --=20 2.26.2 From nobody Thu May 16 10:41:31 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1591176838; cv=none; d=zohomail.com; s=zohoarc; b=OAgichPFV1VKe2jgnf1E4/RacxbanFVRZT/KlQlvRIIjp5fK3zO3nOQoP9np+amTro6CEYKa1zVFofrBzjXFmfaXh4+h3802GTEQPBHpjwcAtrdh6Udy98kOZ/rN+iuDeyBAFK175RJ/8EUfO27F1Q2LUhedZh3Y497TwHEkhBo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591176838; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=c1EjJhzX0wupXCxnkX6AE7TJM3GTVFXykPqO+DDN4v8=; b=gYfxxbE4QeYqV2rVhLH4kdETXY9PNjmP2gwKxgF8UOiLmc1KxwG0qSqzgHfYatM4+3F7a1o/5gcm9nJn1mpDnQ83o58wvD100KrPBcC/1Cv/WqRIp3/mZyrfUXjRwZThZLD8GIm3W3vc7qHFtV5XeuZh2SEDzg5Sao7UtmvR6/s= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1591176838435150.106829065228; Wed, 3 Jun 2020 02:33:58 -0700 (PDT) Received: from localhost ([::1]:40212 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jgPmX-0002VU-0A for importer@patchew.org; Wed, 03 Jun 2020 05:33:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:48952) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jgPlc-0000mx-6j for qemu-devel@nongnu.org; Wed, 03 Jun 2020 05:33:00 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:57983 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1jgPlb-00080D-8U for qemu-devel@nongnu.org; Wed, 03 Jun 2020 05:32:59 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-124-pyFip4xEOFSKWLfrFhocuQ-1; Wed, 03 Jun 2020 05:32:56 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9DB1B835B4F; Wed, 3 Jun 2020 09:32:55 +0000 (UTC) Received: from dritchie.redhat.com (ovpn-112-109.rdu2.redhat.com [10.10.112.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id A14665C220; Wed, 3 Jun 2020 09:32:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1591176778; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=c1EjJhzX0wupXCxnkX6AE7TJM3GTVFXykPqO+DDN4v8=; b=V7crTZwCQatp2bQOHCdrsq2ZWEW9/P6nta0Kn2eUa7zHbXrullqKAog5CeIfRCapDV8kjh dwRBc1G7WAEsYNsOegpkYaq01j5ZLzbTqM/VTT8CzToYK56bxTiIvSqBKIRPqhrfym8pXX 56OocFmSBAbcqVC40ht3xJjm1NWPw3Q= X-MC-Unique: pyFip4xEOFSKWLfrFhocuQ-1 From: Sergio Lopez To: qemu-devel@nongnu.org Subject: [PATCH 2/2] virtio-blk: On restart, process queued requests in the proper context Date: Wed, 3 Jun 2020 11:32:40 +0200 Message-Id: <20200603093240.40489-3-slp@redhat.com> In-Reply-To: <20200603093240.40489-1-slp@redhat.com> References: <20200603093240.40489-1-slp@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=205.139.110.120; envelope-from=slp@redhat.com; helo=us-smtp-1.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/06/03 01:04:35 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_PASS=-0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , qemu-block@nongnu.org, Sergio Lopez , "Michael S. Tsirkin" , Max Reitz , Stefan Hajnoczi Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" On restart, we were scheduling a BH to process queued requests, which would run before starting up the data plane, leading to those requests being assigned and started on coroutines on the main context. This could cause requests to be wrongly processed in parallel from different threads (the main thread and the iothread managing the data plane), potentially leading to multiple issues. For example, stopping and resuming a VM multiple times while the guest is generating I/O on a virtio_blk device can trigger a crash with a stack tracing looking like this one: <------> Thread 2 (Thread 0x7ff736765700 (LWP 1062503)): #0 0x00005567a13b99d6 in iov_memset (iov=3D0x6563617073206f4e, iov_cnt=3D1717922848, offset=3D516096, fill= c=3D0, bytes=3D7018105756081554803) at util/iov.c:69 #1 0x00005567a13bab73 in qemu_iovec_memset (qiov=3D0x7ff73ec99748, offset=3D516096, fillc=3D0, bytes=3D7018105756= 081554803) at util/iov.c:530 #2 0x00005567a12f411c in qemu_laio_process_completion (laiocb=3D0x7ff6512= ee6c0) at block/linux-aio.c:86 #3 0x00005567a12f42ff in qemu_laio_process_completions (s=3D0x7ff7182e842= 0) at block/linux-aio.c:217 #4 0x00005567a12f480d in ioq_submit (s=3D0x7ff7182e8420) at block/linux-a= io.c:323 #5 0x00005567a12f43d9 in qemu_laio_process_completions_and_submit (s=3D0x= 7ff7182e8420) at block/linux-aio.c:236 #6 0x00005567a12f44c2 in qemu_laio_poll_cb (opaque=3D0x7ff7182e8430) at b= lock/linux-aio.c:267 #7 0x00005567a13aed83 in run_poll_handlers_once (ctx=3D0x5567a2b58c70, ti= meout=3D0x7ff7367645f8) at util/aio-posix.c:520 #8 0x00005567a13aee9f in run_poll_handlers (ctx=3D0x5567a2b58c70, max_ns= =3D16000, timeout=3D0x7ff7367645f8) at util/aio-posix.c:562 #9 0x00005567a13aefde in try_poll_mode (ctx=3D0x5567a2b58c70, timeout=3D0= x7ff7367645f8) at util/aio-posix.c:597 #10 0x00005567a13af115 in aio_poll (ctx=3D0x5567a2b58c70, blocking=3Dtrue)= at util/aio-posix.c:639 #11 0x00005567a109acca in iothread_run (opaque=3D0x5567a2b29760) at iothre= ad.c:75 #12 0x00005567a13b2790 in qemu_thread_start (args=3D0x5567a2b694c0) at uti= l/qemu-thread-posix.c:519 #13 0x00007ff73eedf2de in start_thread () at /lib64/libpthread.so.0 #14 0x00007ff73ec10e83 in clone () at /lib64/libc.so.6 Thread 1 (Thread 0x7ff743986f00 (LWP 1062500)): #0 0x00005567a13b99d6 in iov_memset (iov=3D0x6563617073206f4e, iov_cnt=3D1717922848, offset=3D516096, fill= c=3D0, bytes=3D7018105756081554803) at util/iov.c:69 #1 0x00005567a13bab73 in qemu_iovec_memset (qiov=3D0x7ff73ec99748, offset=3D516096, fillc=3D0, bytes=3D7018105756= 081554803) at util/iov.c:530 #2 0x00005567a12f411c in qemu_laio_process_completion (laiocb=3D0x7ff6512= ee6c0) at block/linux-aio.c:86 #3 0x00005567a12f42ff in qemu_laio_process_completions (s=3D0x7ff7182e842= 0) at block/linux-aio.c:217 #4 0x00005567a12f480d in ioq_submit (s=3D0x7ff7182e8420) at block/linux-a= io.c:323 #5 0x00005567a12f4a2f in laio_do_submit (fd=3D19, laiocb=3D0x7ff5f4ff9ae0= , offset=3D472363008, type=3D2) at block/linux-aio.c:375 #6 0x00005567a12f4af2 in laio_co_submit (bs=3D0x5567a2b8c460, s=3D0x7ff7182e8420, fd=3D19, offset=3D472363008,= qiov=3D0x7ff5f4ff9ca0, type=3D2) at block/linux-aio.c:394 #7 0x00005567a12f1803 in raw_co_prw (bs=3D0x5567a2b8c460, offset=3D472363008, bytes=3D20480, qiov=3D0x7ff5= f4ff9ca0, type=3D2) at block/file-posix.c:1892 #8 0x00005567a12f1941 in raw_co_pwritev (bs=3D0x5567a2b8c460, offset=3D472363008, bytes=3D20480, qiov=3D0x7ff5= f4ff9ca0, flags=3D0) at block/file-posix.c:1925 #9 0x00005567a12fe3e1 in bdrv_driver_pwritev (bs=3D0x5567a2b8c460, offset=3D472363008, bytes=3D20480, qiov=3D0x7ff5= f4ff9ca0, qiov_offset=3D0, flags=3D0) at block/io.c:1183 #10 0x00005567a1300340 in bdrv_aligned_pwritev (child=3D0x5567a2b5b070, req=3D0x7ff5f4ff9db0, offset=3D472363008, byt= es=3D20480, align=3D512, qiov=3D0x7ff72c0425b8, qiov_offset=3D0, flags=3D0)= at block/io.c:1980 #11 0x00005567a1300b29 in bdrv_co_pwritev_part (child=3D0x5567a2b5b070, offset=3D472363008, bytes=3D20480, qiov=3D0x7= ff72c0425b8, qiov_offset=3D0, flags=3D0) at block/io.c:2137 #12 0x00005567a12baba1 in qcow2_co_pwritev_task (bs=3D0x5567a2b92740, file_cluster_offset=3D472317952, offset=3D487305= 216, bytes=3D20480, qiov=3D0x7ff72c0425b8, qiov_offset=3D0, l2meta=3D0x0) a= t block/qcow2.c:2444 #13 0x00005567a12bacdb in qcow2_co_pwritev_task_entry (task=3D0x5567a2b485= 40) at block/qcow2.c:2475 #14 0x00005567a13167d8 in aio_task_co (opaque=3D0x5567a2b48540) at block/a= io_task.c:45 #15 0x00005567a13cf00c in coroutine_trampoline (i0=3D738245600, i1=3D32759= ) at util/coroutine-ucontext.c:115 #16 0x00007ff73eb622e0 in __start_context () at /lib64/libc.so.6 #17 0x00007ff6626f1350 in () #18 0x0000000000000000 in () <------> This is also known to cause crashes with this message (assertion failed): aio_co_schedule: Co-routine was already scheduled in 'aio_co_schedule' RHBZ: https://bugzilla.redhat.com/show_bug.cgi?id=3D1812765 Signed-off-by: Sergio Lopez --- include/hw/virtio/virtio-blk.h | 2 +- hw/block/dataplane/virtio-blk.c | 8 ++++++++ hw/block/virtio-blk.c | 18 ++++++++++++------ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/include/hw/virtio/virtio-blk.h b/include/hw/virtio/virtio-blk.h index f584ad9b86..b1334c3904 100644 --- a/include/hw/virtio/virtio-blk.h +++ b/include/hw/virtio/virtio-blk.h @@ -86,6 +86,6 @@ typedef struct MultiReqBuffer { } MultiReqBuffer; =20 bool virtio_blk_handle_vq(VirtIOBlock *s, VirtQueue *vq); -void virtio_blk_process_queued_requests(VirtIOBlock *s); +void virtio_blk_process_queued_requests(VirtIOBlock *s, bool is_bh); =20 #endif diff --git a/hw/block/dataplane/virtio-blk.c b/hw/block/dataplane/virtio-bl= k.c index 1b52e8159c..37499c5564 100644 --- a/hw/block/dataplane/virtio-blk.c +++ b/hw/block/dataplane/virtio-blk.c @@ -220,6 +220,9 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev) goto fail_guest_notifiers; } =20 + /* Process queued requests before the ones in vring */ + virtio_blk_process_queued_requests(vblk, false); + /* Kick right away to begin processing requests already in vring */ for (i =3D 0; i < nvqs; i++) { VirtQueue *vq =3D virtio_get_queue(s->vdev, i); @@ -239,6 +242,11 @@ int virtio_blk_data_plane_start(VirtIODevice *vdev) return 0; =20 fail_guest_notifiers: + /* + * If we failed to set up the guest notifiers queued requests will be + * processed on the main context. + */ + virtio_blk_process_queued_requests(vblk, false); vblk->dataplane_disabled =3D true; s->starting =3D false; vblk->dataplane_started =3D true; diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c index 978574e4da..8882a1d1d4 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -819,7 +819,7 @@ static void virtio_blk_handle_output(VirtIODevice *vdev= , VirtQueue *vq) virtio_blk_handle_output_do(s, vq); } =20 -void virtio_blk_process_queued_requests(VirtIOBlock *s) +void virtio_blk_process_queued_requests(VirtIOBlock *s, bool is_bh) { VirtIOBlockReq *req =3D s->rq; MultiReqBuffer mrb =3D {}; @@ -847,7 +847,9 @@ void virtio_blk_process_queued_requests(VirtIOBlock *s) if (mrb.num_reqs) { virtio_blk_submit_multireq(s->blk, &mrb); } - blk_dec_in_flight(s->conf.conf.blk); + if (is_bh) { + blk_dec_in_flight(s->conf.conf.blk); + } aio_context_release(blk_get_aio_context(s->conf.conf.blk)); } =20 @@ -858,21 +860,25 @@ static void virtio_blk_dma_restart_bh(void *opaque) qemu_bh_delete(s->bh); s->bh =3D NULL; =20 - virtio_blk_process_queued_requests(s); + virtio_blk_process_queued_requests(s, true); } =20 static void virtio_blk_dma_restart_cb(void *opaque, int running, RunState state) { VirtIOBlock *s =3D opaque; + BusState *qbus =3D BUS(qdev_get_parent_bus(DEVICE(s))); + VirtioBusState *bus =3D VIRTIO_BUS(qbus); =20 if (!running) { return; } =20 - if (!s->bh) { - /* FIXME The data plane is not started yet, so these requests are - * processed in the main thread. */ + /* + * If ioeventfd is enabled, don't schedule the BH here as queued + * requests will be processed while starting the data plane. + */ + if (!s->bh && !virtio_bus_ioeventfd_enabled(bus)) { s->bh =3D aio_bh_new(blk_get_aio_context(s->conf.conf.blk), virtio_blk_dma_restart_bh, s); blk_inc_in_flight(s->conf.conf.blk); --=20 2.26.2