Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp450107iog; Mon, 13 Jun 2022 06:12:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx6SrKYURYzaZCBtvn2YaPiqpw3IBJYsgmqHpdq6qA7DDGNx44fwB491kIgWOOJL+1CkiyA X-Received: by 2002:a17:902:d102:b0:167:4f35:9580 with SMTP id w2-20020a170902d10200b001674f359580mr48755585plw.38.1655125542267; Mon, 13 Jun 2022 06:05:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655125542; cv=none; d=google.com; s=arc-20160816; b=uGFn8fdDCCCoWcqgygRNkdEUDrgf4UVFUSNqvzhBEu/x4e9nNAAYz13V1Z/dHzlZ8T dMDUwYMAnaBLsJDE/+tAKHbKUE5sECP0LaJmCWRm6hrkHn6Ch15FOOW+0JNMcs0oNb1O x7iCnCqQqZJ1QUJ1SqhxRw1B0te1J7ddTyxszgP9uVIed0g31a4nojYB+qh+rctxSY+F b3G2fgBLakFGtHLootjgb8dyrumppjhKnmXXrUoji6aQXd99B0i5Y9f/fapXqdOaeOCm +j337VE6x9p5w0r3QlraEm4jHidPxspoyid0ZwfjJ/K1nDcTnhA/oxQ09AyKfcz86BSN Bolg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=I3Vv2WH3FkX5FCQRTg5b9J4dOm0TPxO1wDeaK8UGU8g=; b=QhsgrqvBC9GrBEmMECMWs9JzGEGCSXSJIkhofeIFIp0ujzzqFetbgyYVrg+QcAuS6K KiUytrb/ZQx+qtK73JdraC1iLVvBor59+rNh5c/UsiCZ1N8gUweTac/PMLHfObY1NBkh 5bY58vXPkiwOhaI2A4IlE0Tzi9SjvbrR/USDroMHEEZh8Ec2lUS5nHY6AItxt0foRwuT Q5LXsOCbasBrh5QUfy50Wp2P/kAEVszbD2u6vXwAIq9ozDRQ1Dzw3A85UX6KNQKnZOug q8InRMLt4amrJMErtYxLkC/Dt63SjOOiP9jTjwrYITkwvzKJqDfoMT5CVQBSBUSnSLVq lNJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Fx2kVZVy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k30-20020a634b5e000000b003f5cfdbddadsi9642095pgl.396.2022.06.13.06.05.25; Mon, 13 Jun 2022 06:05:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Fx2kVZVy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352213AbiFMLLP (ORCPT + 99 others); Mon, 13 Jun 2022 07:11:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351744AbiFMLIC (ORCPT ); Mon, 13 Jun 2022 07:08:02 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3637D33A04; Mon, 13 Jun 2022 03:35:14 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 64CF5B80E93; Mon, 13 Jun 2022 10:35:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D37B9C36AFE; Mon, 13 Jun 2022 10:35:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655116503; bh=jdxYV56eY7XhApEmOlDXD1XspYqjrLg6jh431dpAOcQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fx2kVZVypyHujTft7z+y9VjZyCEXAMFm3GCk3s/AOaeAVv6mvc/0hqT2KJxjUoaF4 6cA8eYPmimihVTlQJ5/FhupnetP8Hcnj337fC14KEXKAWO5cMDZJAovNzae6mMoXbd G9n6sewi/38GXL8hNRaj6cCxP9nqZuxzTA1JQks8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yu Kuai , Josef Bacik , Jens Axboe , Sasha Levin Subject: [PATCH 4.14 203/218] nbd: fix io hung while disconnecting device Date: Mon, 13 Jun 2022 12:11:01 +0200 Message-Id: <20220613094926.779729747@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094908.257446132@linuxfoundation.org> References: <20220613094908.257446132@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yu Kuai [ Upstream commit 09dadb5985023e27d4740ebd17e6fea4640110e5 ] In our tests, "qemu-nbd" triggers a io hung: INFO: task qemu-nbd:11445 blocked for more than 368 seconds. Not tainted 5.18.0-rc3-next-20220422-00003-g2176915513ca #884 "echo 0 > /proc/sys/kernel/hung_task_timeout_secs" disables this message. task:qemu-nbd state:D stack: 0 pid:11445 ppid: 1 flags:0x00000000 Call Trace: __schedule+0x480/0x1050 ? _raw_spin_lock_irqsave+0x3e/0xb0 schedule+0x9c/0x1b0 blk_mq_freeze_queue_wait+0x9d/0xf0 ? ipi_rseq+0x70/0x70 blk_mq_freeze_queue+0x2b/0x40 nbd_add_socket+0x6b/0x270 [nbd] nbd_ioctl+0x383/0x510 [nbd] blkdev_ioctl+0x18e/0x3e0 __x64_sys_ioctl+0xac/0x120 do_syscall_64+0x35/0x80 entry_SYSCALL_64_after_hwframe+0x44/0xae RIP: 0033:0x7fd8ff706577 RSP: 002b:00007fd8fcdfebf8 EFLAGS: 00000246 ORIG_RAX: 0000000000000010 RAX: ffffffffffffffda RBX: 0000000040000000 RCX: 00007fd8ff706577 RDX: 000000000000000d RSI: 000000000000ab00 RDI: 000000000000000f RBP: 000000000000000f R08: 000000000000fbe8 R09: 000055fe497c62b0 R10: 00000002aff20000 R11: 0000000000000246 R12: 000000000000006d R13: 0000000000000000 R14: 00007ffe82dc5e70 R15: 00007fd8fcdff9c0 "qemu-ndb -d" will call ioctl 'NBD_DISCONNECT' first, however, following message was found: block nbd0: Send disconnect failed -32 Which indicate that something is wrong with the server. Then, "qemu-nbd -d" will call ioctl 'NBD_CLEAR_SOCK', however ioctl can't clear requests after commit 2516ab1543fd("nbd: only clear the queue on device teardown"). And in the meantime, request can't complete through timeout because nbd_xmit_timeout() will always return 'BLK_EH_RESET_TIMER', which means such request will never be completed in this situation. Now that the flag 'NBD_CMD_INFLIGHT' can make sure requests won't complete multiple times, switch back to call nbd_clear_sock() in nbd_clear_sock_ioctl(), so that inflight requests can be cleared. Signed-off-by: Yu Kuai Reviewed-by: Josef Bacik Link: https://lore.kernel.org/r/20220521073749.3146892-5-yukuai3@huawei.com Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/block/nbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 9596f93d98b2..338d02a67afb 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -1275,7 +1275,7 @@ static int nbd_start_device_ioctl(struct nbd_device *nbd, struct block_device *b static void nbd_clear_sock_ioctl(struct nbd_device *nbd, struct block_device *bdev) { - sock_shutdown(nbd); + nbd_clear_sock(nbd); __invalidate_device(bdev, true); nbd_bdev_reset(bdev); if (test_and_clear_bit(NBD_HAS_CONFIG_REF, -- 2.35.1