Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4411028ybl; Mon, 3 Feb 2020 18:30:22 -0800 (PST) X-Google-Smtp-Source: APXvYqxerLsr7wOlfIadyLxYRCX5YFAZvRP9Um0oZIcljFfs1v6jO8v6SKpDDtbU/NpBSiUYnLpo X-Received: by 2002:a05:6808:b23:: with SMTP id t3mr1792542oij.88.1580783421946; Mon, 03 Feb 2020 18:30:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580783421; cv=none; d=google.com; s=arc-20160816; b=OA7fVR7sqvqpyMY3XrvJN8QVxWj/CsEzTg38ZkG0HEMyaHQbP7cqWWIfliHQJ+KJZX NmZYjSkah+uG+cdWQB+xfHHygsQC+nRdskxHtoEDpqBq/hZH86au4GOhuvPltDJOeSFY 17NBroZh08EJ8EO0WnuGem5f76Q6G92gwefnApvaSf1w5Rs36RDjYsOGcLtY271o8bbQ 08XouOEtOh4taK3TVXXavh06UaIEz4p7eylkZ1Fjs/aLNMc/GFl9BGUJxdYkYxHGySqu tnZVKI3q4oyxEU6ExuyJXf+c+72Hyfz3B6MM/WHg6BHgw6xl4r/baJ6M8CVydfcNY8vh v9cw== 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=jADfV3YIb55f646nzjQJQ7adRbOhFpQQzAyFMbYjkKQ=; b=anyjxBF3cvI1L1qRCR5IBoz52BnL5X9Xb2XVygyDTFx4ogxpKKsCTQcmFpZB4HhZND 2cHblt7GEhgoZS848q+parl+4ybLC7lB5VGbVgDi3/IaVk3ZyermG4UcaMG0UhX2F3tt WKh+AR7tvV6oEphqAK8ZrOekJtpEkRuJAJ/yDMQuDJbKBi6oUEbKmk4AzGwHeoYA5whk yPvFBWBRFM/WIYd+j0hEzeYNAKEI3r6vaBnumGtm2vDB07OXaxWSM5kcCzBnjuJztFrH XXex3gKFdhllrK6nzALXPVT9zEhwFmtQ+TllzQFJc3hzGhX6v5QHqT96MSPDouSKK3+R Z5Hw== 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 d19si11125422ote.3.2020.02.03.18.30.09; Mon, 03 Feb 2020 18:30:21 -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 S1727097AbgBDC26 (ORCPT + 99 others); Mon, 3 Feb 2020 21:28:58 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:9685 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726561AbgBDC25 (ORCPT ); Mon, 3 Feb 2020 21:28:57 -0500 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id BDF6794BC6A9C7913AE0; Tue, 4 Feb 2020 10:28:55 +0800 (CST) Received: from [127.0.0.1] (10.173.222.66) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.439.0; Tue, 4 Feb 2020 10:28:54 +0800 Subject: Re: [v2] nbd: add a flush_workqueue in nbd_start_device To: , , CC: , , References: <20200122031857.5859-1-sunke32@huawei.com> From: "sunke (E)" Message-ID: Date: Tue, 4 Feb 2020 10:28:53 +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: <20200122031857.5859-1-sunke32@huawei.com> Content-Type: text/plain; charset="gbk"; 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 ping ?? 2020/1/22 11:18, Sun Ke ะด??: > 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 | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c > index b4607dd96185..78181908f0df 100644 > --- a/drivers/block/nbd.c > +++ b/drivers/block/nbd.c > @@ -1265,6 +1265,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); >