Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2775036rdb; Mon, 12 Feb 2024 16:57:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU/qkdY8EpnEwA+eLjVT5Ih9GMTPA+ijQnkWVBu7pi307HMNQKt6lB65MCAZdTSSo4+ykgnAniYdczSNNzi5nf3Phla2a2jcw+mq+GPQg== X-Google-Smtp-Source: AGHT+IECeHQqVd4Q6sdSWyGAYan8nNM2hcd9lpBaHo1/CuuFlhoBwtKyJqVTLx4SjSM8PEvcs372 X-Received: by 2002:a17:906:3e50:b0:a3b:eaa3:ecc4 with SMTP id t16-20020a1709063e5000b00a3beaa3ecc4mr5478867eji.60.1707785867938; Mon, 12 Feb 2024 16:57:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707785867; cv=pass; d=google.com; s=arc-20160816; b=uo40Z2+9GPx3zTC1zWCfxuY8yjtsGQuGBiJWCn9bYuDmZmB5mRLjVUR32xzHHvYvv8 W+XJvURno2d5pVaY2YuTBNoFlLKY+aIKqDgVhvgYmE+oAC4UEgufgpgEWZM0g6Xc7Rje RFZQ6QKlmqxG/1cqioWr+FKHyiR/ST3vW9UxOlNFQoW8DUApXiYvvy4RcJ/6gY3iK066 YDzKqmF0lzHTetGtXM2f60eNaCnu3KrzbgESv2hiZefUt446zCD0gF/wbe6Wu4tzYpzi 8Db5ezbb8Z61WwBs9nWnQl0OlsRFqdmZahcLySQk5EvsmAdWgMaK68MYc/127IxkktzN qYSg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=SKkaCKVtNDMTxA55ye4BLJLIrg0pHk8yzJAQMLTDqBY=; fh=U2RHeGuKY0YRCaHif5vqLXSYJXreIRJzFtSM99+v92g=; b=1ES1SFhhEZr0wS6t2fESISHUUzGy5jKVS7/hxPPfcZu6d2A4XZsyy7331kJej05wA7 1yAX8kRMJMvyWMSfnsS3CNMvD32f/RrbzPU400jUQW516rFE7+rBPpOAdLmYEQ8UuOqw sLpzM1OjHkaEDfOv/Fy9BiGEdxhrmrA4LM+KNKNcQZZhbjjslbmHKVXfULiVC9f7qUFh X5HYRDc8rM5rA1wU69oKHs9rPNUmHUaV7VWdyIWRmF0oigka/ajNOAdI9kbBu1dxBNcQ s1Xr45spfbR3qwbxLVkaS8QCxKYR/0HtOobwOtQbiX5ZkpOIbqq2uXiwbDRlPqMftln3 vzEQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ESADVmR4; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-62711-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62711-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCXbnpy+IpkXOhFsi/zPEiufZLN7KBDYx2uHiLqg1+jWsvsm1TlVielwHHxSP0APi9V7Lwk8FdxTuy9bVs4ewF1tVdvSey/QdhqHOlvgbg== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id a4-20020a17090680c400b00a3c123f120bsi653276ejx.608.2024.02.12.16.57.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 16:57:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62711-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ESADVmR4; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-62711-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62711-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id AFE5A1F21A62 for ; Tue, 13 Feb 2024 00:57:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E86F084FB7; Tue, 13 Feb 2024 00:23:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ESADVmR4" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EDB7084A2B; Tue, 13 Feb 2024 00:23:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707783803; cv=none; b=S4CiE+0NNlA8tp5pGIFnx2hnG5MEtgV14cW3s/0aTLMXxLvqwUzwO+9Lqpa2guLWhLTOKnTutQDbCQynoFPiNIctO5CxcHFUZlM0mb/+8FqbxULXKRXmHWvXXJ7cjPgI03mdUX0+CaMozu8S/vZg5ZQ0ni7iTjnJ07CooBv2jpU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707783803; c=relaxed/simple; bh=ee/Eq08r7U8onjKVLB5ysFDesQFgbqc77E/WGIAnGyA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CQxfMv4qF4DNhM+yiFtUGNPlBYRrUzP0n7JAVPVfY3m96ZxPwqmcuZAZWfMyUHvDo+WxC9pXffuvLveEPv3CYBQnuvL7h4o5y79Cq4moCBEyppJU4jocpbVy2GLt5AerKKhk7q33ZMx+tg9bKhj5jPowc72gMQou5smKI2/ci/A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ESADVmR4; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A965C43390; Tue, 13 Feb 2024 00:23:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707783802; bh=ee/Eq08r7U8onjKVLB5ysFDesQFgbqc77E/WGIAnGyA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ESADVmR492P/YybK+D+ARZhXlNd60MCBNhqESBdzgiI67NQa2BhBxHC4x+ZE/LEmj +OHruH46JW8WO3KszXq+KZcJTUnvKIb5GBmVR4wZHtgPViAmzymhoMNlvE2Iv3bAKR nMkQlxDHD1Uv98lB0GQG5E2PbdTgaqkaP5qRqhkH/9nAFUn+cZxxNpRP+Q+wgkOFQV qilX/ZRmZEKzGKCgSdN4k3VgqhRIeaCs3p4ZBBpcIAwcV8Vfjt71C1cnDXDCWuCCXZ tVrsqzP9R1qwW+Yqu1AOydj2uXGt/gpJZzbwPX8rHU4ZkDh7ffktX/hkpHBEU0wNCz FEjOxgiOrMwqQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Yi Sun , Stefan Hajnoczi , Jens Axboe , Sasha Levin , mst@redhat.com, jasowang@redhat.com, virtualization@lists.linux.dev, linux-block@vger.kernel.org Subject: [PATCH AUTOSEL 6.1 27/28] virtio-blk: Ensure no requests in virtqueues before deleting vqs. Date: Mon, 12 Feb 2024 19:22:25 -0500 Message-ID: <20240213002235.671934-27-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240213002235.671934-1-sashal@kernel.org> References: <20240213002235.671934-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.1.77 Content-Transfer-Encoding: 8bit From: Yi Sun [ Upstream commit 4ce6e2db00de8103a0687fb0f65fd17124a51aaa ] Ensure no remaining requests in virtqueues before resetting vdev and deleting virtqueues. Otherwise these requests will never be completed. It may cause the system to become unresponsive. Function blk_mq_quiesce_queue() can ensure that requests have become in_flight status, but it cannot guarantee that requests have been processed by the device. Virtqueues should never be deleted before all requests become complete status. Function blk_mq_freeze_queue() ensure that all requests in virtqueues become complete status. And no requests can enter in virtqueues. Signed-off-by: Yi Sun Reviewed-by: Stefan Hajnoczi Link: https://lore.kernel.org/r/20240129085250.1550594-1-yi.sun@unisoc.com Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/block/virtio_blk.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index 3124837aa406..505026f0025c 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -1206,14 +1206,15 @@ static int virtblk_freeze(struct virtio_device *vdev) { struct virtio_blk *vblk = vdev->priv; + /* Ensure no requests in virtqueues before deleting vqs. */ + blk_mq_freeze_queue(vblk->disk->queue); + /* Ensure we don't receive any more interrupts */ virtio_reset_device(vdev); /* Make sure no work handler is accessing the device. */ flush_work(&vblk->config_work); - blk_mq_quiesce_queue(vblk->disk->queue); - vdev->config->del_vqs(vdev); kfree(vblk->vqs); @@ -1231,7 +1232,7 @@ static int virtblk_restore(struct virtio_device *vdev) virtio_device_ready(vdev); - blk_mq_unquiesce_queue(vblk->disk->queue); + blk_mq_unfreeze_queue(vblk->disk->queue); return 0; } #endif -- 2.43.0