From nobody Fri Nov 14 09:17:55 2025 Delivered-To: importer@patchew.org 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; 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=1585910867; cv=none; d=zohomail.com; s=zohoarc; b=ct4MlG+CWaCpH1iVltdxwmkVVjtK/98LUfXHExNjxUI2BJBZH9Pm4eV+c+u2pF+nOuOgCa+KCS3ssxwf/Z5+MGMDtuOgJVGhoDPu26yL0ct4LB4StlJnAlhO1PUdtL30cP45kE55oTMci0NEMUk3b9G/oZUQXgnmr+GeKS6Ogh8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1585910867; 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=hWJ3MgFYCUe9wil/UcV5TKzmCD6udz1cDHjGIDwnDVI=; b=AmnfD1FI+QpFQjjOkCseIVVqpneup52qRUDAc8BO3QPEwwqfMaHlwHuzRQ3loK1Chct2yibm7ZVPl+7/H+JLRfIs0XXxh8v5NOucYu4jRHDJqRi1GwbnMHxhsXtmj5+oQ8SHGQXnjBNlhm++khLFvu8AXoU0nu4MzmK8EbSi0xc= 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 1585910867692305.2212631612372; Fri, 3 Apr 2020 03:47:47 -0700 (PDT) Received: from localhost ([::1]:53506 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jKJrW-0007Nv-HC for importer@patchew.org; Fri, 03 Apr 2020 06:47:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39581) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jKJoR-0003zH-5t for qemu-devel@nongnu.org; Fri, 03 Apr 2020 06:44:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jKJoQ-0006Tx-13 for qemu-devel@nongnu.org; Fri, 03 Apr 2020 06:44:35 -0400 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:34956 helo=us-smtp-1.mimecast.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1jKJoP-0006TY-Tb for qemu-devel@nongnu.org; Fri, 03 Apr 2020 06:44:33 -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-358-oTZH3IZaO9SXNHyz7cdoYA-1; Fri, 03 Apr 2020 06:44:32 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BFF15800D5C; Fri, 3 Apr 2020 10:44:30 +0000 (UTC) Received: from linux.fritz.box.com (ovpn-113-132.ams2.redhat.com [10.36.113.132]) by smtp.corp.redhat.com (Postfix) with ESMTP id 06D6C8EA1A; Fri, 3 Apr 2020 10:44:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585910673; 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=hWJ3MgFYCUe9wil/UcV5TKzmCD6udz1cDHjGIDwnDVI=; b=iFhdz3oupyEHYZyhr24xksxpn5uM0jdR9CASKo9SAb/jQzSXD4n+uzzNp1nZ5lzfhQ7A2/ 4mx2fmqWpNhxV5Z51EmlvI8ASSbAt0tK8fOblM4LG7KCgQ0cvGxnspoucnGj3PY4yKTEC/ QhKHn0PyXuvTBnKg/lJ+mGmZGQOlMrw= X-MC-Unique: oTZH3IZaO9SXNHyz7cdoYA-1 From: Kevin Wolf To: qemu-block@nongnu.org Subject: [PATCH for-5.0 2/2] block: Fix blk->in_flight during blk_wait_while_drained() Date: Fri, 3 Apr 2020 12:44:15 +0200 Message-Id: <20200403104415.20963-3-kwolf@redhat.com> In-Reply-To: <20200403104415.20963-1-kwolf@redhat.com> References: <20200403104415.20963-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 205.139.110.120 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: kwolf@redhat.com, vsementsov@virtuozzo.com, s.reiter@proxmox.com, qemu-devel@nongnu.org, dietmar@proxmox.com, stefanha@redhat.com, mreitz@redhat.com, t.lamprecht@proxmox.com 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" Calling blk_wait_while_drained() while blk->in_flight is increased for the current request is wrong because it will cause the drain operation to deadlock. Many callers of blk_wait_while_drained() have already increased blk->in_flight when called in a blk_aio_*() path, but can also be called in synchonous code paths where blk->in_flight isn't increased. This means that these calls of blk_wait_while_drained() are wrong at least in some cases. In order to fix this, increase blk->in_flight even for synchronous operations and temporarily decrease the counter again in blk_wait_while_drained(). Fixes: cf3129323f900ef5ddbccbe86e4fa801e88c566e Signed-off-by: Kevin Wolf --- block/block-backend.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/block/block-backend.c b/block/block-backend.c index 3124e367b3..7bd16402b8 100644 --- a/block/block-backend.c +++ b/block/block-backend.c @@ -1143,7 +1143,9 @@ static int blk_check_byte_request(BlockBackend *blk, = int64_t offset, static void coroutine_fn blk_wait_while_drained(BlockBackend *blk) { if (blk->quiesce_counter && !blk->disable_request_queuing) { + blk_dec_in_flight(blk); qemu_co_queue_wait(&blk->queued_requests, NULL); + blk_inc_in_flight(blk); } } =20 @@ -1260,6 +1262,7 @@ static int blk_prw(BlockBackend *blk, int64_t offset,= uint8_t *buf, .ret =3D NOT_DONE, }; =20 + blk_inc_in_flight(blk); if (qemu_in_coroutine()) { /* Fast-path if already in coroutine context */ co_entry(&rwco); @@ -1268,6 +1271,7 @@ static int blk_prw(BlockBackend *blk, int64_t offset,= uint8_t *buf, bdrv_coroutine_enter(blk_bs(blk), co); BDRV_POLL_WHILE(blk_bs(blk), rwco.ret =3D=3D NOT_DONE); } + blk_dec_in_flight(blk); =20 return rwco.ret; } @@ -1386,9 +1390,7 @@ static void blk_aio_read_entry(void *opaque) QEMUIOVector *qiov =3D rwco->iobuf; =20 if (rwco->blk->quiesce_counter) { - blk_dec_in_flight(rwco->blk); blk_wait_while_drained(rwco->blk); - blk_inc_in_flight(rwco->blk); } =20 assert(qiov->size =3D=3D acb->bytes); @@ -1404,9 +1406,7 @@ static void blk_aio_write_entry(void *opaque) QEMUIOVector *qiov =3D rwco->iobuf; =20 if (rwco->blk->quiesce_counter) { - blk_dec_in_flight(rwco->blk); blk_wait_while_drained(rwco->blk); - blk_inc_in_flight(rwco->blk); } =20 assert(!qiov || qiov->size =3D=3D acb->bytes); --=20 2.20.1