Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4359565ybl; Tue, 21 Jan 2020 18:46:54 -0800 (PST) X-Google-Smtp-Source: APXvYqxSrCWckVRM480DDeEUYnlCZ8tcFObUr+UKj44e7utTNeyhbSp+8ixfd8p+m14fT58IMe/P X-Received: by 2002:a9d:7c90:: with SMTP id q16mr6010551otn.191.1579661214316; Tue, 21 Jan 2020 18:46:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579661214; cv=none; d=google.com; s=arc-20160816; b=jHqYrNlVCebR2vcVTnrUM8HgRUsvHQuSnsTUcGfqARhImydGlZKfh27hEwYE+HkPbD /IV6vSOF+1h3XjmsxFP+NMiZXYcdsTRa7KbLmDhfcw2GQ6y37dLzKDcryt50OijLs2sl Vc1HEb8jz01EsQ4VD0iJqq10ZEN4NVnHPfgbqOgB6KhxHXZfFvXm1meNUxp1F+tzrww8 yEWYImGl4nEmrx+1kWLIvy+t9JbEyFbHdH7Kj0YzxZGCcQmHrBiLnJ7Kzy4U/ovo9vRn W02kpk+c++9LhytMxrngUCOTO8W9B320PFAZ00mqbMxO3LYI90Rvajjtqsl8Y/S/32rm L5/Q== 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:in-reply-to :mime-version:user-agent:date:message-id:from:references:cc:to :subject; bh=Ornu5MD883F/SJDkcd2kRD054y6LU/iN2dadXsOKJNA=; b=VqzRexY70SsyMV3hH45CpSTI9EWBRkMAKlMkNQHQCjJ/I8EzP25ii6yQIiFldu9Fp6 pBI3DflYZWuFTw5XmMjY1v0c6zcFkvaXy4ojrKpC5qwuW/24EfnUxORC5ITa6UMx0h4o OEMrn6JNrJSBwKtU+GNv0AGgdoksAk0z9qIkaPycBhzG8JXSiue2tdpEjK3co9dtPsh6 I7zZ7HQCnuNWfaUeZDDUhgIGI5g7ap7sKaQofh/PSAF7aQYx5RXIUTyEiu2hPrEbvYBm shSU8ZHv8hWbvqGjInZqvxw2LoPQm+vC3qvWNYfNwOGILq6dEILNQSW94kbalY0xZlH9 PU7A== 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 u16si22688218otq.92.2020.01.21.18.46.41; Tue, 21 Jan 2020 18:46:54 -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 S1729012AbgAVCpo (ORCPT + 99 others); Tue, 21 Jan 2020 21:45:44 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:10125 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727141AbgAVCpo (ORCPT ); Tue, 21 Jan 2020 21:45:44 -0500 Received: from DGGEMS406-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id A014D63E922200D617CC; Wed, 22 Jan 2020 10:45:41 +0800 (CST) Received: from [127.0.0.1] (10.173.222.66) by DGGEMS406-HUB.china.huawei.com (10.3.19.206) with Microsoft SMTP Server id 14.3.439.0; Wed, 22 Jan 2020 10:45:40 +0800 Subject: Re: [PATCH] nbd: add a flush_workqueue in nbd_start_device To: Jens Axboe , Josef Bacik , CC: , , References: <20200121124813.13332-1-sunke32@huawei.com> <82a3eb7e-883c-a091-feec-27f3937491ab@toxicpanda.com> <83d21549-66a0-0e76-89e5-1303c5b19102@kernel.dk> From: "sunke (E)" Message-ID: Date: Wed, 22 Jan 2020 10:45:39 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.2.2 MIME-Version: 1.0 In-Reply-To: <83d21549-66a0-0e76-89e5-1303c5b19102@kernel.dk> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.173.222.66] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2020/1/22 5:25, Jens Axboe 写道: > On 1/21/20 7:00 AM, Josef Bacik wrote: >> On 1/21/20 7:48 AM, Sun Ke wrote: >>> 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); >>> + } >> >> Just for readability sake why don't we just flush_workqueue() >> unconditionally, and add a comment so we know why in the future. > > Or maybe just make it: > > sock_shutdown(nbd); > if (i) > flush_workqueue(nbd->recv_workq); > > which does the same thing, but is still readable. The current code with > the shutdown duplication is just a bit odd. Needs a comment either way. > OK, I will improve it in my v2 patch. Thanks, Sun Ke