Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp3726151ybl; Tue, 21 Jan 2020 06:04:18 -0800 (PST) X-Google-Smtp-Source: APXvYqyPq/DjwPJropjNDaArzWLkt0TmvgqmexPqEBBBXkhKBzdg7B8nOSH7GyDUc0L7IiK5EG/n X-Received: by 2002:a05:6830:160c:: with SMTP id g12mr3576797otr.82.1579615458637; Tue, 21 Jan 2020 06:04:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579615458; cv=none; d=google.com; s=arc-20160816; b=DNqB1o13SQHJFddsE2FgEmkb6O/iqvxeBLOw+EIIwXBjKcVLg+sOnZKFyAnMBQNnFH DsCNhhnB2qWKDkGXVMVkDRPGistUG9VWvrpxBPEeIqEL+9mT57EKBb74VeBHrzYK963F mRfpsvZthTRu2cZV7tC6dPtO9mOwvjdk30h4iONkD5u4HJYCgDxIME3iiXCtKVbvnPhS FRSxkgpCnPlGxTMAZihT9grCdSUTcQnSzH2mNkmMrqg9vSAjEfPBGDt7a/sb3ku/4iWE c9/3SAX+urR+iEElBarvMIBoR2MYxHRgGYMFZgT8DmeHg48uMnfREVWbzh/iJw2fP9o1 kYOA== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=T3pQh4UckFpVVYMnTU2C2nEcKAWZ5QNLADQwFYgscxc=; b=BmqFtdS7g5pUlpgT6oU9SkAfuF89XMDB+/DUS03zwOQeyDivehU/GcXEgS/yhn8F5j tdgE+DqKJ5P3q71DbyAKrAnHQYdDsWzC/DZ3ftCd8OV5xedmVBcD5xv5I5xHa1PTZ7si /+d1uvmSr5ovGkQAFWW+8pQQLPyeELpCBD/740Pqb+wbXCmG5ZzRz9kMxBKiBgci8+bs LFWAe9T0RIV1dlOnDXGNHBrO+CnIoJVx2whq0crfC91O+t5F6kU1XsmUE4YS4egRKkOX Mkpw2TwsZjdBOY/xNMxeyCQ8vbjPuKuklMbQNV18kR9kj34+9XH83VHeQ7IQf3BEeMEd 3fBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@toxicpanda-com.20150623.gappssmtp.com header.s=20150623 header.b=s1NxKgcB; 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 g6si21921860otk.171.2020.01.21.06.03.57; Tue, 21 Jan 2020 06:04:18 -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=@toxicpanda-com.20150623.gappssmtp.com header.s=20150623 header.b=s1NxKgcB; 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 S1729009AbgAUOAj (ORCPT + 99 others); Tue, 21 Jan 2020 09:00:39 -0500 Received: from mail-qt1-f195.google.com ([209.85.160.195]:41225 "EHLO mail-qt1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726968AbgAUOAj (ORCPT ); Tue, 21 Jan 2020 09:00:39 -0500 Received: by mail-qt1-f195.google.com with SMTP id k40so2627617qtk.8 for ; Tue, 21 Jan 2020 06:00:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=T3pQh4UckFpVVYMnTU2C2nEcKAWZ5QNLADQwFYgscxc=; b=s1NxKgcB7b2fWkPqDuWtLBrJmbzy3Gu/G0nXXFUWS78t64NBLo20y2YZSuUdMCk3Yz jYaCNwqEW92+eDZplCRchAjcgns8MD3xrEKum4irgThfd6wJ3m3NEZtti3VRiBEtqZMX 0DY2DoqphpU2VTi6QKgibhWu46oYTnHcS37hDbPsTcJCdOhRNayyalaEWCBQ7N8Y/RjX pmfPS7JwWzYnQGP015HgEYi8rJA6gdT5rWXQD0vov6sjex5rC60W5fPGhwL7jEWqsIeN tnlLJRc+ykSzCTdhMqLc37iCtwOYbusZX7wFDY/ARsizrqbK6RmrObrUywI9LI8ZCauK gRRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=T3pQh4UckFpVVYMnTU2C2nEcKAWZ5QNLADQwFYgscxc=; b=kOZ9Hn9jzy0bLhtYYiQLXllyQbFrCEzLdwoMTCgDmTb/6A5ZEqsRsQwIcSKkPNpFV6 3Gd/8c2XXP71Z6o9RVa2RaUj4Rf7cvwyqv9vh3xuU70isqjgZue9VnCnSoAGu5+OJyDq XFjAbxGw7O3SKknbwddE70Aff/phCWIvwZind59CVG7IITGnM08vy6/ugNS799EhaT5E K3z8g5UzYmXE3i8tLwdYUTrxsHTqpZB4ocCbgNlb4pdr2EyufJc29Gqpb0egbj1PFW4J H5ZEssV5Ia9X3xv4k/UPJ4JlQSCMKkDw9O9Hh/7Mw1hewVwLvQVtL7sO63PCqxChpT3H X5ig== X-Gm-Message-State: APjAAAXqYKT1Hw1Og5QIMNrj7blSgqjKT56odY7hQqV05xuYGpEVUAFJ mBhsi/YAebcQkpU8UuNwfG8igwh4pRUxMA== X-Received: by 2002:ac8:4657:: with SMTP id f23mr4584941qto.378.1579615237725; Tue, 21 Jan 2020 06:00:37 -0800 (PST) Received: from ?IPv6:2620:10d:c0a8:1102:ce0:3629:8daa:1271? ([2620:10d:c091:480::822a]) by smtp.gmail.com with ESMTPSA id a36sm19768784qtk.29.2020.01.21.06.00.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 21 Jan 2020 06:00:36 -0800 (PST) Subject: Re: [PATCH] nbd: add a flush_workqueue in nbd_start_device To: Sun Ke , axboe@kernel.dk, mchristi@redhat.com Cc: linux-block@vger.kernel.org, nbd@other.debian.org, linux-kernel@vger.kernel.org References: <20200121124813.13332-1-sunke32@huawei.com> From: Josef Bacik Message-ID: <82a3eb7e-883c-a091-feec-27f3937491ab@toxicpanda.com> Date: Tue, 21 Jan 2020 09:00:35 -0500 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.4.1 MIME-Version: 1.0 In-Reply-To: <20200121124813.13332-1-sunke32@huawei.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Thanks, Josef