From patchwork Tue Nov 3 20:33:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kroah-Hartman X-Patchwork-Id: 316790 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CB80AC2D0A3 for ; Tue, 3 Nov 2020 22:02:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 79ED421556 for ; Tue, 3 Nov 2020 22:02:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604440979; bh=bnFbbM/iTF0EpzIJJWqApOMmpoKGyKiVkoOqqqvnD94=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=iCQwisFIsRp2reeVNHs+YzMvGjFIgBa18f6FnNl3Qww8LCj+1ZHuwVDFXo5JUNnde yg0o/elwYfMdZXeqdx32wxPRc9wudW6ofPh6SADqwO987rpZ5w0CxK7NdY3OowSmgO QP+k9X47LakO22G9rJ8WckHiHXM+WH7LPJ7jsJNw= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730315AbgKCUox (ORCPT ); Tue, 3 Nov 2020 15:44:53 -0500 Received: from mail.kernel.org ([198.145.29.99]:60592 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730951AbgKCUow (ORCPT ); Tue, 3 Nov 2020 15:44:52 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 97821223BF; Tue, 3 Nov 2020 20:44:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1604436292; bh=bnFbbM/iTF0EpzIJJWqApOMmpoKGyKiVkoOqqqvnD94=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sXE28Z8wkSHezEAz9ACLkvaZ06zdk3rP9tuFcdD7ylSQRlk5fy+SScje6LP/EQzBy wdme7yW08xkrOUEW7c2ySaOq2xn2up8sx5mW8pIuCRzTRchoVAWb9xcsB/DOQVCP9f Y62a/Z6Aul69Yf3wiaSBqx0D2DmksyZSqJfrWRq0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xiubo Li , Josef Bacik , Jens Axboe , Sasha Levin Subject: [PATCH 5.9 179/391] nbd: make the config put is called before the notifying the waiter Date: Tue, 3 Nov 2020 21:33:50 +0100 Message-Id: <20201103203358.951326537@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201103203348.153465465@linuxfoundation.org> References: <20201103203348.153465465@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Xiubo Li [ Upstream commit 87aac3a80af5cbad93e63250e8a1e19095ba0d30 ] There has one race case for ceph's rbd-nbd tool. When do mapping it may fail with EBUSY from ioctl(nbd, NBD_DO_IT), but actually the nbd device has already unmaped. It dues to if just after the wake_up(), the recv_work() is scheduled out and defers calling the nbd_config_put(), though the map process has exited the "nbd->recv_task" is not cleared. Signed-off-by: Xiubo Li Reviewed-by: Josef Bacik Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/block/nbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index edf8b632e3d27..f46e26c9d9b3c 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -801,9 +801,9 @@ static void recv_work(struct work_struct *work) if (likely(!blk_should_fake_timeout(rq->q))) blk_mq_complete_request(rq); } + nbd_config_put(nbd); atomic_dec(&config->recv_threads); wake_up(&config->recv_wq); - nbd_config_put(nbd); kfree(args); }