Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1615698ybv; Fri, 21 Feb 2020 00:20:28 -0800 (PST) X-Google-Smtp-Source: APXvYqz5uREX0nPEg7vyPi48bFR523SecQx76XkcB9uw47W8bN5nLvWY1SvMG26JzXNHEHf2VfwX X-Received: by 2002:a9d:7083:: with SMTP id l3mr25837033otj.193.1582273228732; Fri, 21 Feb 2020 00:20:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582273228; cv=none; d=google.com; s=arc-20160816; b=HZ5YopR7ZXBRF9UruwT3dwFWtFq1U4vgPCfAi5q1dbqRjFZYjf299rcWCf+pJtfD8T ZSIs1D0elSVX56pjLRfxMxOQENAW9lO+1FLymXTi54twv7nXupSM+NGzzLgQXoLRfRbc bmB0Zdd94K1iZ9aGhmvHk1efgdM4uPFM/G5nLfXb5nz3trsrtYtZz5kjs/UkblLv+sR6 AaMDTNNLZUnmis7M0I86v4pGeQ1AtWVLtMG8K2+x+rjC+YI5m4XuGNZdhSyw6XtcR6rq OeDVkoDBxEMVdxPv13JI8jvqLvdmpeTI8P5Oj2E399LjfVZanWDC60tj5qlRrYm9tXmc eYXg== 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=4l4OO/AvJeRyh7y+DZPpo0RQUkqMmEI5SGmWaPLlYdg=; b=UcZ/Hd/ZUMKookGIxFjKBSqCdXDJfmPp22/tzuLSMJDy6wiIcY3qlXPOc+3j6wCIPL 4vQD36TbYQjUcBPabEOWN4QFjW6sCyqRTrlYQqB1tl5O0S2QPvHAxv3Z5lnCXyMYEtDC uuO13J2jT4RzmVdB0oBUYapAMBKsGXjqos8tV8sR656e27IHRezZ97+tK9WOQv7DqoOt GSuHi2dCwGTxEQmDlbfFxYEZvit9pr7cQAWITUOL+q0bH1H0rRMAXhBwBpu0a6as48Iu SMxtEp8poCV48JSGpmfliAlrLa0ReLftwIS2nCFs5ZdpDrtG0isQZDH4Yaeu4JkZKcdQ CzGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WUyoQuaP; 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 u14si1154624otg.10.2020.02.21.00.20.16; Fri, 21 Feb 2020 00:20:28 -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=WUyoQuaP; 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 S2388049AbgBUITj (ORCPT + 99 others); Fri, 21 Feb 2020 03:19:39 -0500 Received: from mail.kernel.org ([198.145.29.99]:58302 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388045AbgBUITi (ORCPT ); Fri, 21 Feb 2020 03:19:38 -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 DD96F24694; Fri, 21 Feb 2020 08:19:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582273177; bh=sgwlTZtHceOcXQlBCBMlRKJUHnRjwhhrQxZY8HOsp7I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WUyoQuaPRrrrx+E/0bVXYsPC7P8Nnh1wcFRff0on1UhFOT0mZbNxfFswDcbmIz0GF rU/VqyVl3xiSZ/61ULgQkYbma683eYAOAvZM3I1h97P2jJfn/hw9eJ6oJ9dU14Y6qn cZY1x/O9HHFFjci6EcOCf+BK+rCvst9xy9Qysav8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sun Ke , Jens Axboe , Sasha Levin Subject: [PATCH 4.19 047/191] nbd: add a flush_workqueue in nbd_start_device Date: Fri, 21 Feb 2020 08:40:20 +0100 Message-Id: <20200221072257.378789807@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200221072250.732482588@linuxfoundation.org> References: <20200221072250.732482588@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: Sun Ke [ Upstream commit 5c0dd228b5fc30a3b732c7ae2657e0161ec7ed80 ] When kzalloc fail, may cause trying to destroy the workqueue from inside the workqueue. If num_connections is m (2 < m), and NO.1 ~ NO.n (1 < n < m) kzalloc are successful. The NO.(n + 1) failed. Then, nbd_start_device will return ENOMEM to nbd_start_device_ioctl, and nbd_start_device_ioctl will return immediately without running flush_workqueue. However, we still have n recv threads. If nbd_release run first, recv threads may have to drop the last config_refs and try to destroy the workqueue from inside the workqueue. To fix it, add a flush_workqueue in nbd_start_device. Fixes: e9e006f5fcf2 ("nbd: fix max number of supported devs") Signed-off-by: Sun Ke Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/block/nbd.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index b9d321bdaa8a7..226103af30f05 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -1216,6 +1216,16 @@ static int nbd_start_device(struct nbd_device *nbd) args = kzalloc(sizeof(*args), GFP_KERNEL); if (!args) { sock_shutdown(nbd); + /* + * If num_connections is m (2 < m), + * and NO.1 ~ NO.n(1 < n < m) kzallocs are successful. + * But NO.(n + 1) failed. We still have n recv threads. + * So, add flush_workqueue here to prevent recv threads + * dropping the last config_refs and trying to destroy + * the workqueue from inside the workqueue. + */ + if (i) + flush_workqueue(nbd->recv_workq); return -ENOMEM; } sk_set_memalloc(config->socks[i]->sock->sk); -- 2.20.1