Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp4382032ybl; Tue, 21 Jan 2020 19:21:22 -0800 (PST) X-Google-Smtp-Source: APXvYqxn605EBZx62hhU2U1wi50O+gJuaK09xPqyxyVuhYtnSvN+8j6QMckqmaD697ql5f1nrr2W X-Received: by 2002:a9d:5885:: with SMTP id x5mr5726771otg.132.1579663282483; Tue, 21 Jan 2020 19:21:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579663282; cv=none; d=google.com; s=arc-20160816; b=BA4BGXOgfKq8+Ah1M0ydKn5IGjWBuXRnmzh9lDm3Jh3NbxNRBAFuf/j1k5XUfc3FCM N0Kf+6PnutdRXWc0ZeUnX/dmNNka/K9MeEDA3ajbV6g8MZ3b5Sq1D/2WHAc11UcVTCSc 9dA/iziu2W7QG7Ie759daxK++pAnXrp/ru4ICiLz0XIBta33EvU0PrS8y/DOdBIVYY6d j2G8CFDZTNcJy35i4X/wyzeeI6QFRMABkPnYxPUG/YPnAcR9wOuari+5ztn50k91xuoT F9/CGKRZspDfcLkd38Zy2Um8eqQVVkf8BKLGBNLalTL2uymAJYhrEU0fUdjhMuen/pjX HfoA== 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=xu2UtlP6Exj82o4GlnCBjvbXhrFlhZj+wOpkweK265E=; b=lZpaI5b6RDbs6tIkkfJn/JIKlE/KdBcidlGaEyksnAUhaR4LFQ78p4W7lrZI1JjShL RnxFu/T8gicBKcTEk7MS/Iqf1rCLeubVg0Z6QvtLai7VuinrgeDSS237KujLc6R4vyAM kTHPAO/lXoUh6ADrQgmzVYOdVIDQiRnu4BL0W4LutaH5p09lcz1EVDJr1QFQhb9WzE8B Z3ImW46Um467IsJ9EVvIEISlo2y3kJzaaFkmErMQQFR08CnNB+D+Xfz3r6NM+gfm1pH8 dCHzd71eM8LtqmliBco4JbvfM4K1iIoCoPe147ZFrtvEQR7+kIRbo+mYyHxSVzWcjrCQ 0sHw== 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 f15si20880495oib.61.2020.01.21.19.21.10; Tue, 21 Jan 2020 19:21:22 -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 S1729290AbgAVDUF (ORCPT + 99 others); Tue, 21 Jan 2020 22:20:05 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:53928 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729251AbgAVDUC (ORCPT ); Tue, 21 Jan 2020 22:20:02 -0500 Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id B5A0C6220C8716D5A6A5; Wed, 22 Jan 2020 11:20:00 +0800 (CST) Received: from huawei.com (10.175.124.28) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.439.0; Wed, 22 Jan 2020 11:19:53 +0800 From: Sun Ke To: , , , CC: , , Subject: [v2] nbd: add a flush_workqueue in nbd_start_device Date: Wed, 22 Jan 2020 11:18:57 +0800 Message-ID: <20200122031857.5859-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 | 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); -- 2.17.2