Received: by 2002:a05:7412:7c14:b0:fa:6e18:a558 with SMTP id ii20csp258658rdb; Mon, 22 Jan 2024 03:22:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IE52hAiMN/7zk6VnH9Ih2o8943xGqUTLgdzEQq2SQQuzH5PQ2SMFLd04lDG29g2oVpstW6m X-Received: by 2002:a05:6830:611:b0:6dd:de70:6fe7 with SMTP id w17-20020a056830061100b006ddde706fe7mr1418506oti.46.1705922540750; Mon, 22 Jan 2024 03:22:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705922540; cv=pass; d=google.com; s=arc-20160816; b=k0cF8iwhVNjtfVE2EUFrNaGUps0QX292eMRFCG0zToXOOkvqWuwnzfSOiEhu5XEpLY OZsyo9AT468kjjlLDl0lHHjC9NcqgUP15Xm2cqrX4IJ/2q9ozG1bsXo+XGRqOlI4nEH8 XCqocFIhqP9xqgE4/36jYwtTXHdF2LefZkjS7SipM+Nw4jHcVDmI/ZQuAgnI69uSdMTI fPKDUpPUcpNsqaO2EnD4XSDK3lRgYWUgzdit8+QXdYyjlGJY3HlXruGBa4HBK6TJSOet 1n8YEOeaw+du2iBwVncLDT34EmS/KOQPWEm2O4ibhIdN1r7OD2wONKpSmyDCJxjS8/fd DhcA== 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; bh=TnXyOm7G+Wcer6oRsnX8NxxkF5TZmswKhl+iwYqpwQY=; fh=SAsS2eQuUitsPqkEZea+UWjJ5uX+kI9xrlYNvSAAzvc=; b=j2kIRDFHd/1/bFLBrTg/SnRskc6d1j9B8qwtDeUBXkQsxhXo9qfcsLNXh0h7ZjP6Fk 9uzwzKhgNICt/DNS8n5g3dM0wK1hzg4/bMXXVuh/dOkhL0Uod4gvL4IlsK29M9aMm8nG PfVFnb7vVGvElCmMnoJX7RrCVBMV8apTGHCDijM+CcAzbl31aBGrQoSIV/Aa314+79G6 b9103gBsPTMpMYvOwhLpl+ZuZlx2XvAM+Zri0RzQnF3opCDAb8ISYt9HWjqXpdHc37YY D3WOp6HvqLanlkfRvLrYP7VzfO/SCosfmzTZ1YzF6MU+UMHqG6cRzfSTDcX8uo28M+4h CoxA== 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-32867-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32867-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 d7-20020a05622a05c700b00429e3202babsi5454691qtb.261.2024.01.22.03.22.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jan 2024 03:22:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-32867-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-32867-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-32867-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 AA1281C263B1 for ; Mon, 22 Jan 2024 11:21:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 407D73D3A2; Mon, 22 Jan 2024 11:08:11 +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 44F373D0D5 for ; Mon, 22 Jan 2024 11:08:07 +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=1705921690; cv=none; b=TIryHFM+blS+r62nm0v5G1S6WUCLcweoaWYWMitnVaqZITi4wcimyAFU57wimwcVhQJl0oYCoNdQ6mGq7tHEpsrWvqbV5OiAQ6+3n+rJZlqZ6HXvG19pYraekDVSPt23ROYIAT5uTr6LFh9n6uEd7jsj0GaYm9ZG1yIA9OhlAOE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705921690; c=relaxed/simple; bh=tEBM8ROgFnpAjPpGkQqFn+5G7qisAii32clsfbRevhI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=lfQOIVS9uRGjXdT/APbu8qaZshgQqExVkmETZnjr/IKR+stvGLifcAdOnXPfFv3wTQmgt1aEqa+wDhKnKbpDG8rplsCRkUlPAvz9nYtURCJEcqNUaMwkR0Ag0AZmFI0FYhpoMj/YaPHGdpEwiSVnVkOeGIVNjTt3xqxnNgW9D70= 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 40MB7TmP062317; Mon, 22 Jan 2024 19:07:29 +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 4TJS153t0qz2RcY8P; Mon, 22 Jan 2024 19:00:09 +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, 22 Jan 2024 19:07:27 +0800 From: Yi Sun To: , , CC: , , , , , , , , , Subject: [PATCH 2/2] virtio-blk: Ensure no requests in virtqueues before deleting vqs. Date: Mon, 22 Jan 2024 19:07:22 +0800 Message-ID: <20240122110722.690223-3-yi.sun@unisoc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240122110722.690223-1-yi.sun@unisoc.com> References: <20240122110722.690223-1-yi.sun@unisoc.com> 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 40MB7TmP062317 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. So it is better to place blk_mq_quiesce_queue() in front of virtio_reset_device(). 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. New function blk_mq_tagset_wait_request_completed() ensure that all requests in virtqueues become complete status. Signed-off-by: Yi Sun --- drivers/block/virtio_blk.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index 3b6b9abb8ce1..380f009953dd 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -1595,14 +1595,16 @@ static int virtblk_freeze(struct virtio_device *vdev) { struct virtio_blk *vblk = vdev->priv; + /* Ensure no requests in virtqueues before deleting vqs. */ + blk_mq_quiesce_queue(vblk->disk->queue); + blk_mq_tagset_wait_request_completed(vblk->disk->queue->tag_set); + /* 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); -- 2.25.1