From patchwork Tue Nov 29 16:06:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Zetao X-Patchwork-Id: 13058719 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3106DC433FE for ; Tue, 29 Nov 2022 15:19:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235891AbiK2PTI (ORCPT ); Tue, 29 Nov 2022 10:19:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235277AbiK2PS1 (ORCPT ); Tue, 29 Nov 2022 10:18:27 -0500 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0493A1F629; Tue, 29 Nov 2022 07:18:24 -0800 (PST) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4NM5Yg4n79z15Mgf; Tue, 29 Nov 2022 23:17:43 +0800 (CST) Received: from huawei.com (10.67.175.21) by kwepemi500012.china.huawei.com (7.221.188.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 29 Nov 2022 23:18:21 +0800 From: Li Zetao To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v2 4/5] virtio-blk: Fix probe failed when modprobe virtio_blk Date: Wed, 30 Nov 2022 00:06:14 +0800 Message-ID: <20221129160615.3343036-5-lizetao1@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221129160615.3343036-1-lizetao1@huawei.com> References: <20221128021005.232105-1-lizetao1@huawei.com> <20221129160615.3343036-1-lizetao1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.175.21] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To kwepemi500012.china.huawei.com (7.221.188.12) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org When doing the following test steps, an error was found: step 1: modprobe virtio_blk succeeded # modprobe virtio_blk <-- OK step 2: fault injection in __blk_mq_alloc_disk() # modprobe -r virtio_blk <-- OK # ... CPU: 0 PID: 4578 Comm: modprobe Tainted: G W 6.1.0-rc6-00308-g644e9524388a-dirty Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), Call Trace: should_failslab+0xa/0x20 ... blk_alloc_queue+0x3a4/0x780 __blk_mq_alloc_disk+0x91/0x1f0 virtblk_probe+0x6ff/0x1f20 [virtio_blk] ... virtio_blk: probe of virtio1 failed with error -12 step 3: modprobe virtio_blk failed # modprobe virtio_blk <-- failed virtio_blk: probe of virtio1 failed with error -2 The root cause of the problem is that the virtqueues are not stopped on the error handling path when __blk_mq_alloc_disk() fails in virtblk_probe(), resulting in an error "-ENOENT" returned in the next modprobe call in setup_vq(). virtio_pci_modern_device uses virtqueues to send or receive message, and "queue_enable" records whether the queues are available. In vp_modern_find_vqs(), all queues will be selected and activated, but once queues are enabled there is no way to go back except reset. Fix it by reset virtio device on error handling path. After init_vq() succeeded, all virtqueues should be stopped on error handling path. Signed-off-by: Li Zetao --- v1 -> v2: modify the description error. drivers/block/virtio_blk.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index 19da5defd734..f401546d4e85 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -1157,6 +1157,7 @@ static int virtblk_probe(struct virtio_device *vdev) put_disk(vblk->disk); out_free_tags: blk_mq_free_tag_set(&vblk->tag_set); + virtio_reset_device(vdev); out_free_vq: vdev->config->del_vqs(vdev); kfree(vblk->vqs);