Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp13331602ybl; Sun, 29 Dec 2019 09:28:50 -0800 (PST) X-Google-Smtp-Source: APXvYqxRYQNqNKuZOqVg4y1QkMDk96p2Dy/00TPRbZZQ0V7YZzr0CFKjwPEvSA+3AutOSdrbaTDh X-Received: by 2002:a9d:66ca:: with SMTP id t10mr68739813otm.352.1577640530622; Sun, 29 Dec 2019 09:28:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1577640530; cv=none; d=google.com; s=arc-20160816; b=CGYaEDH58hxJYkfY4smTFw4+oyAx2ihltzeQ0QjJM7EJ39DDpbroiw/ibixLz0tGlx XZpyUxPdp0ACwS33wBERQ3+qG8wZhyi3Uty34BV2CCsBZijbYnBGtAq9/KUN4KSwv/eV I14vJhCqDh92dnbi2bT/7H63SvfE9S6e3SlTA59rO2QIgTOBVcuDiKh3iMsCqUQil14r etZA11HvAPm1HlgxOwFwIfNUi5k7AfuGAq5k1tnau7h1wGBOhAYClVFXgSSqEWxriakm CKoWWE2uzbGCCg+jflgk2QZhIdU/vbyyhtoPpHXy8ku5QoOVjiq6eigzKru+19yGJuvT ilUA== 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=1pdMMZreT8Pb+6ZxEIdbD9Pu33sVQJFNoZySDQyRC78=; b=li+zbw5HoqhF6ZI78NQ98EOY/4xi4v0WDQyfAA78J7FmHqKFAqguNLpD1UZNkJ9A5N gFo/Fv2cg/XqHjKAvF/a/B7cfTTtFLcG3Cb91GSdckQjf3jR/GoymGsftjnwvgk+r9kh ZUuq5XkFm5QPuqhNVYUbQQUgCSKDoAf1hSSGZflf4QS5GrT0+SSAgmPICTJmZpNU+KCc rMSSBNpQZKg6MdV2DBjxuWNy08bz+4V18OI5BqWlJvy7kunCnS9t/UCOm8r5+Uxx2gwN doj8yO8Ahn7R94phpVNymOHR3wyX4ZyduSjuO5d+E+XptbWQaMSvN7Eup5d4zgZlRBwf fT7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=J0Acck0b; 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 o12si22178529otl.243.2019.12.29.09.28.40; Sun, 29 Dec 2019 09:28:50 -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=J0Acck0b; 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 S1728453AbfL2R1i (ORCPT + 99 others); Sun, 29 Dec 2019 12:27:38 -0500 Received: from mail.kernel.org ([198.145.29.99]:49856 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728427AbfL2R1a (ORCPT ); Sun, 29 Dec 2019 12:27:30 -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 CE143207FF; Sun, 29 Dec 2019 17:27:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577640450; bh=GeRHI4wtHwGBZ8S0i93TJGTNEm4NYvktmCcr2ia8CD8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=J0Acck0b740b1hUQxoRgpcIywx1XD9Of2YLrpVgQPCj9vXWcGvMPQZk0YHcAuj3A4 WMoI7X8ESxTCecULRB3zBj5GAmVWU4A29zPXJKMYvY6zq/C0fqQw5WDVOTg2NEh5G/ uA1Cscwtxsb19bI+zZ2Tj4HJnMEu+YfR3Pp9qpx8= 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.14 161/161] nbd: fix shutdown and recv work deadlock v2 Date: Sun, 29 Dec 2019 18:20:09 +0100 Message-Id: <20191229162450.809936938@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191229162355.500086350@linuxfoundation.org> References: <20191229162355.500086350@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 @@ -1234,10 +1234,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); bd_set_size(bdev, 0); /* user requested, ignore socket errors */