Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp13470111ybl; Sun, 29 Dec 2019 12:39:44 -0800 (PST) X-Google-Smtp-Source: APXvYqzUybtMWo1MKF2ACQJYAu1GzoItA+zQ830CHVtDXug/DLe68S9CrY5wYiWr0FnCZnZs+vT+ X-Received: by 2002:a9d:4805:: with SMTP id c5mr34749664otf.292.1577651984701; Sun, 29 Dec 2019 12:39:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577651984; cv=none; d=google.com; s=arc-20160816; b=hXPY/XMuvycRcwUPmQ3VP7Jp2GpdRK0QZ/zWYxLc51N9cbWMdq8uNqOkVXApMnmxPL w3s5dv+UgM//XzpQKjTVCV5bdRB52cBbQSYfDjovmUGj1Sdx4PQ+Fu1QR6J2f33MXvJj yjXWYWOg+eHHahbSUHTmszllR+RDvwzx3xF8NjiscxDDIZg+4EWWhLSccSEcZqP9EtoL 6xASTtQDtACok/q17oAVC91lPM+dc+Tm+nRzv256JoG9A/QfBPdtmoL/Es3RUinoagCL OL7iU/8ti8YC8Tou75wLPpRSY/vTrxr2dK9G/EkNjYvBY2OWlYdQkjtuYI8NfGwThI6G Mvvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=iem2om40xie/EAlr1Web7vl8vjknQMPG15Zcv6QlDdM=; b=Odj4opqkQtmZyqPQIWxalTqdXr+lqVhLaBucNp+3BPkC7kGfBzJ3JW1JGcN3CJJZ99 qfnPkz3YXK8WduQh71CiNp1G7c1DddIpy73e2aGqNrJMiu9BDtkY8fBu9Ah4OahjL76R Egb03kJp+TkVLau1TZZr0c0mIMq2Z8QlytThRA//IQp9UAdqVeiF0ElrPFeXtU1E6Ah5 btILE5loDjQKa2mP2FSIcnUZ76KF1TBPFi5V1i5znYtoOr4ZQXua1Q4iYmedkh/oYrEW vAUiXroDZwGcd8sWFvxuFSCoAxMMXEA/qPGljnBuZA2ERCmGN9r4RLLKmgWpsuRAJXwW a2ZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PDOajttR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v21si22347569otj.282.2019.12.29.12.39.33; Sun, 29 Dec 2019 12:39:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PDOajttR; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730096AbfL2Rgt (ORCPT + 99 others); Sun, 29 Dec 2019 12:36:49 -0500 Received: from mail.kernel.org ([198.145.29.99]:42150 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729212AbfL2Rgj (ORCPT ); Sun, 29 Dec 2019 12:36:39 -0500 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id BEDD7206CB; Sun, 29 Dec 2019 17:36:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577640999; bh=QnVmgWYf3XP6d13kHluYYJy18H9hA7bB6ACGz6kfiSQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PDOajttRJfonNxUC2JmuFtxH0ub++M7J9lGz3esL+bCnKhQwykMGXdyKDcTK61QA8 oiciJ4CGeOfQA7M3NkqoD2OmM+DOb76vYe+aaza0JzTFxlr2iNQ7jHecLVBUcO0qLP R5a7Dc68i23xrvi2XFPmjcC9qJh48/d9zoBIbE60= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mike Christie , Jens Axboe Subject: [PATCH 4.19 219/219] nbd: fix shutdown and recv work deadlock v2 Date: Sun, 29 Dec 2019 18:20:21 +0100 Message-Id: <20191229162543.385065589@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191229162508.458551679@linuxfoundation.org> References: <20191229162508.458551679@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mike Christie commit 1c05839aa973cfae8c3db964a21f9c0eef8fcc21 upstream. This fixes a regression added with: commit e9e006f5fcf2bab59149cb38a48a4817c1b538b4 Author: Mike Christie Date: Sun Aug 4 14:10:06 2019 -0500 nbd: fix max number of supported devs where we can deadlock during device shutdown. The problem occurs if the recv_work's nbd_config_put occurs after nbd_start_device_ioctl has returned and the userspace app has droppped its reference via closing the device and running nbd_release. The recv_work nbd_config_put call would then drop the refcount to zero and try to destroy the config which would try to do destroy_workqueue from the recv work. This patch just has nbd_start_device_ioctl do a flush_workqueue when it wakes so we know after the ioctl returns running works have exited. This also fixes a possible race where we could try to reuse the device while old recv_works are still running. Cc: stable@vger.kernel.org Fixes: e9e006f5fcf2 ("nbd: fix max number of supported devs") Signed-off-by: Mike Christie Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- drivers/block/nbd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -1247,10 +1247,10 @@ static int nbd_start_device_ioctl(struct mutex_unlock(&nbd->config_lock); ret = wait_event_interruptible(config->recv_wq, atomic_read(&config->recv_threads) == 0); - if (ret) { + if (ret) sock_shutdown(nbd); - flush_workqueue(nbd->recv_workq); - } + flush_workqueue(nbd->recv_workq); + mutex_lock(&nbd->config_lock); nbd_bdev_reset(bdev); /* user requested, ignore socket errors */