Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3652247ybl; Tue, 21 Jan 2020 04:50:36 -0800 (PST) X-Google-Smtp-Source: APXvYqwLD5qywAtkUMo6vK1v7RraBWJM5cUFt88CwwC6OSZE6XtSMu2Pe155HuwvrdNKng99YOUS X-Received: by 2002:a9d:51ca:: with SMTP id d10mr3429675oth.76.1579611036562; Tue, 21 Jan 2020 04:50:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579611036; cv=none; d=google.com; s=arc-20160816; b=uXP/sI/RCZlJgNuVgAN9oYHc/R6cJbYMhH2fopvLp0dIymqqbAvfjbmlRJbAtVoyzo klHH9kazb5BcP3fL4FFVH+8DJGo+Cr9Fuh3VuqNdYyTi6pM7cmlavrg+kjYvMHx6vkFD Kp8mIw+506Gv6k28Gm4s+PZgLDwH0F1XyRoh9f2p0QwvrmtTzyi4YT1+vrOOP1taNpp1 eD8RCZ8SmTs6Dzy7gw34YXo2OGugsmmCoKEQnxprx+tP1FGNzf9xPI40XiCUxhIKGo8E GofLloeGm1F8CLNyhduLHy7t+bxlhQesstJWbbvx1zogUqw8kgY1pbea4SLLEZhkKaSS kyVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=Z+2o4tLso5oUZbQ0P6WnHQyi3FkjGysKMbc4Jmlcx0w=; b=ngHa0yew+EsIIpclVe1mZLeEd2+2KkHQHs7z0b8uc1fKg22Aot+eDOmToeGvx6fdix ceteASB4BMC1J4tHsSDQ0HjEv7nQbNfoIsJaWZssG0SHK0SakkeGAs8iU1Tw5h/PRsXn Hlte0uDhLcjgW4t1spbscQO+CrduwLyyshFSCbNFQl9D95gyqtJTCQDf1aCo8AgjwY5h JuTOJ3BWAC3HXHnoea1DPUEW2hK8iPO1wcQ4GIXX3lDsTyT4nMVRdNKhwrun1egcNDAd 3sqipWpt3pTaRXe9s/ekCzHdOwIMteX9jvq2/MKURPQtyheCK5cPgz24lZeTO3Ak9k4b UWqA== ARC-Authentication-Results: i=1; mx.google.com; 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 o7si22377519otk.185.2020.01.21.04.50.24; Tue, 21 Jan 2020 04:50:36 -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; 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 S1729184AbgAUMta (ORCPT + 99 others); Tue, 21 Jan 2020 07:49:30 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:57296 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726968AbgAUMt3 (ORCPT ); Tue, 21 Jan 2020 07:49:29 -0500 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 14596C7C8A9241831D23; Tue, 21 Jan 2020 20:49:27 +0800 (CST) Received: from huawei.com (10.175.124.28) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.439.0; Tue, 21 Jan 2020 20:49:16 +0800 From: Sun Ke To: , , , CC: , , Subject: [PATCH] nbd: add a flush_workqueue in nbd_start_device Date: Tue, 21 Jan 2020 20:48:13 +0800 Message-ID: <20200121124813.13332-1-sunke32@huawei.com> X-Mailer: git-send-email 2.17.2 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- drivers/block/nbd.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index b4607dd96185..dd1f8c2c6169 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -1264,7 +1264,12 @@ static int nbd_start_device(struct nbd_device *nbd) args = kzalloc(sizeof(*args), GFP_KERNEL); if (!args) { - sock_shutdown(nbd); + if (i == 0) + sock_shutdown(nbd); + else { + sock_shutdown(nbd); + flush_workqueue(nbd->recv_workq); + } return -ENOMEM; } sk_set_memalloc(config->socks[i]->sock->sk); -- 2.17.2