From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D21AC2D0CE for ; Sun, 29 Dec 2019 17:59:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6F4C8206A4 for ; Sun, 29 Dec 2019 17:59:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577642376; bh=dHRwzpPqWS31c63uJzvIkG9cMjZ+i+2d4qzPZ5BDkPI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=d0QCR4JXeRbmnoZFWnsA9sH67unffkWGAr+KaUlCTBdCkWRboLy6DwVejeGQk0sre AXx98vHY2aUfQm4ZWnfUbjfg4x3pB2Z4svyQO5x/I5pPvcy6VeJYU6kyjXuk394Nts gJAS5F30f8zB5RZYpyOzTSjD170Cre5pwd3ZM3P4= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733255AbfL2R6k (ORCPT ); Sun, 29 Dec 2019 12:58:40 -0500 Received: from mail.kernel.org ([198.145.29.99]:49764 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387567AbfL2R6h (ORCPT ); Sun, 29 Dec 2019 12:58:37 -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 06807208C4; Sun, 29 Dec 2019 17:58:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1577642316; bh=dHRwzpPqWS31c63uJzvIkG9cMjZ+i+2d4qzPZ5BDkPI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y/S9twYKbeapqnpW6sMc777XP4n0PR3/I6OZXim9eshrwiOrjFJTchz9NmZM4MjAf UnQrrU+P+Hkblvfu2lE/+6jPJ6mG/sI9+OhbHvBkxtrPnEindS3PSErBPeWy9PkRxJ sMr/vDljoVwXEDalj5vEsIGrd8c1Qew2KUv/P9EM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mike Christie , Jens Axboe Subject: [PATCH 5.4 433/434] nbd: fix shutdown and recv work deadlock v2 Date: Sun, 29 Dec 2019 18:28:06 +0100 Message-Id: <20191229172732.169449971@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191229172702.393141737@linuxfoundation.org> References: <20191229172702.393141737@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@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 @@ -1296,10 +1296,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 */