From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 455B0C4167B for ; Wed, 28 Dec 2022 16:47:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235053AbiL1QrS (ORCPT ); Wed, 28 Dec 2022 11:47:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235064AbiL1Qqz (ORCPT ); Wed, 28 Dec 2022 11:46:55 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 680611E3C0 for ; Wed, 28 Dec 2022 08:41:39 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B434D6155B for ; Wed, 28 Dec 2022 16:41:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C607EC433EF; Wed, 28 Dec 2022 16:41:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1672245698; bh=l2BHkVYWLw6jHX/Jme7hFuVqDpH+K+HDSS1syf4jgOc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rMSKeQmBzxjqjTDLi12vvx3itiDgp1una0OYe1kQO+xo0Pk/CwCOAxrkmYxnlevGO jhrHC9ALhSlqK36Dc/fr3BeB8956QrpgySA1DmjjXsmHOmt3tui6roHKkuMY8qX+RY p1/Z461if4j5wVpdbU/FjtfafggOd0l2JIRC5vXU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Christoph Hellwig , Jens Axboe , Sasha Levin Subject: [PATCH 6.1 0907/1146] block: mark blk_put_queue as potentially blocking Date: Wed, 28 Dec 2022 15:40:46 +0100 Message-Id: <20221228144354.856607879@linuxfoundation.org> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20221228144330.180012208@linuxfoundation.org> References: <20221228144330.180012208@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Christoph Hellwig [ Upstream commit 63f93fd6fa5717769a78d6d7bea6f7f9a1ccca8e ] We can't just say that the last reference release may block, as any reference dropped could be the last one. So move the might_sleep() from blk_free_queue to blk_put_queue and update the documentation. Signed-off-by: Christoph Hellwig Link: https://lore.kernel.org/r/20221114042637.1009333-6-hch@lst.de Signed-off-by: Jens Axboe Stable-dep-of: d36a9ea5e776 ("block: fix use-after-free of q->q_usage_counter") Signed-off-by: Sasha Levin --- block/blk-core.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 7de1bb16e9a7..815ffce6b988 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -260,8 +260,6 @@ static void blk_free_queue_rcu(struct rcu_head *rcu_head) static void blk_free_queue(struct request_queue *q) { - might_sleep(); - percpu_ref_exit(&q->q_usage_counter); if (q->poll_stat) @@ -285,11 +283,11 @@ static void blk_free_queue(struct request_queue *q) * Decrements the refcount of the request_queue and free it when the refcount * reaches 0. * - * Context: Any context, but the last reference must not be dropped from - * atomic context. + * Context: Can sleep. */ void blk_put_queue(struct request_queue *q) { + might_sleep(); if (refcount_dec_and_test(&q->refs)) blk_free_queue(q); } -- 2.35.1