Received: by 2002:a05:7412:d1aa:b0:fc:a2b0:25d7 with SMTP id ba42csp258103rdb; Mon, 29 Jan 2024 00:55:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IGCXvZUz5TfkfbSmNJoFzERyQpcOwJhyV7kL1os0rAl96JQQKLwvGEod+POf1zDKxEhJ9pW X-Received: by 2002:ae9:e716:0:b0:783:4e2:de7f with SMTP id m22-20020ae9e716000000b0078304e2de7fmr5034475qka.113.1706518512936; Mon, 29 Jan 2024 00:55:12 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706518512; cv=pass; d=google.com; s=arc-20160816; b=gC+M0ISgQMQLivB/YfaJY1VSfgXD5V6izZGFr35GVrekBrNyis0GRgipKb6MRcBM73 V+flybvUR63nJzJtoh5nQpgV2YN9G8muEEWe+VkkdD1GRmyyCa4ERp4lOfdEmct9Jwin PARd5utEB/ijdu/k7L03N19ihvpDt5wDWxE+Q2qceJjXs9EiL+kpgQfgtIQgHqFoaAxb eTbdPV1sdVrXBLmzvxmIzDqEShuqQaM5esbqpC6qZSc2cfFdEjwMsXejS6beiAhYlQfH ufsmNpiWG9oSLdCpShuJvyUbrFpFsdCSLxkiSm1Qzr0ATerzUyrphHdZ4DocrOeTZBAV 36Ew== 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:message-id:date:subject:cc:to :from; bh=hcrLhXOY9TGCa5xJtBdnSQZBV2U343FAPfEhDPFXAsA=; fh=RYK58banZiBm65Xs9gfS5X2NFGq0adeV9fko05hVdBM=; b=Z4R8PxhLXuNlSCk4aR1R+B5jujfw2CEB1bPjMzMbeKJQqyL9QpfSod5ZVaeXFMozuY QqBFpfEyPdB+0kLtBMccuVBHcmgnmY3ynneyxyexhlokG1Pi411H4qvi2E7RBrydQRgE snO3DeXxLL/VBcDq6vuydCjEO5UCM0yHrAyIs/8G95SD761I3sIx/O7tVao/mLQOFCZA Y94IWJ9QTBoU/LCoExiaDhjRefqLxJ08qzbgtMI3Nt8N3sBCeLlc3MpXuBVQnwnSMouv TnRbWtsc6LHKossBYF+uUe+6jrrKPZQZ942fRa4B8bsQYiMBFGtPKUqBhnQcqzeyRUJ3 h5DA== ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-42387-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42387-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id h28-20020a05620a21dc00b00783f2040be5si3866873qka.535.2024.01.29.00.55.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Jan 2024 00:55:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-42387-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=unisoc.com); spf=pass (google.com: domain of linux-kernel+bounces-42387-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-42387-linux.lists.archive=gmail.com@vger.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 76FFE1C22602 for ; Mon, 29 Jan 2024 08:55:06 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 89B9754F8F; Mon, 29 Jan 2024 08:55:00 +0000 (UTC) Received: from SHSQR01.spreadtrum.com (mx1.unisoc.com [222.66.158.135]) (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 102A454F82 for ; Mon, 29 Jan 2024 08:54:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=222.66.158.135 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706518500; cv=none; b=tumjvvdtgEep9ai6MwRA93/k22tWKJ/i6cEXq1MkEC2q3KXkfcsSJ6HYsOk+qnR1kFFQ9fGP6+JXJsc+PcmuzzatR620RymH5decBEAF2zgF4mfU5vSTiBa5lpxmgbV/6knNIJ405eDzMZQXXQJVRXeps//NH8vgsYpi2MGQChc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706518500; c=relaxed/simple; bh=Ey0T0NpVcUZVPAB7X0i7MndAEhRfLqJyUuHr9Wwueak=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=PVVCCh2oDVV2QdoS7HZ4j+Whk9A8jQm8LHmO6yeMJBLstuM+vbMZHJt5GazGRCwtsuEbbwWgrSawxw8H/BMCWpTXinFbjACHLpvph6XpIfx0xL4FJUdjF9uDc6AdC+FWU4JJM76kpmri4fChSRYFJAMtH2bxOZ82fNjdQeH0L8M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com; spf=pass smtp.mailfrom=unisoc.com; arc=none smtp.client-ip=222.66.158.135 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=unisoc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=unisoc.com Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 40T8quam034189; Mon, 29 Jan 2024 16:52:56 +0800 (+08) (envelope-from Yi.Sun@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4TNhhL73qlz2S36N9; Mon, 29 Jan 2024 16:45:22 +0800 (CST) Received: from tj10379pcu.spreadtrum.com (10.5.32.15) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Mon, 29 Jan 2024 16:52:53 +0800 From: Yi Sun To: , , , CC: , , , , , , , , Subject: [PATCH V2] virtio-blk: Ensure no requests in virtqueues before deleting vqs. Date: Mon, 29 Jan 2024 16:52:50 +0800 Message-ID: <20240129085250.1550594-1-yi.sun@unisoc.com> X-Mailer: git-send-email 2.25.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL:SHSQR01.spreadtrum.com 40T8quam034189 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 --- 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 3b6b9abb8ce1..14ecc14ce8db 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -1595,14 +1595,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); @@ -1620,7 +1621,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.25.1