Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp2905750iog; Mon, 27 Jun 2022 05:30:13 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sacbPd+d+OAyTXBbFpuml7lCmtjL6tnanVrfZOawAq+rhxvz9R0+Z5+BiMrX/XO9UKRxku X-Received: by 2002:a17:90b:4a8a:b0:1ed:4a56:d7e7 with SMTP id lp10-20020a17090b4a8a00b001ed4a56d7e7mr12374154pjb.1.1656333012934; Mon, 27 Jun 2022 05:30:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656333012; cv=none; d=google.com; s=arc-20160816; b=b//dEQuAHVaFAKSTApk6e2c3xAKHQzlraUnr8t/H+z8yLmt19Vc7JsZSk1+0Tkefb4 H3PqDZjhKg32kOxMaHTpBHR917st7QpBP5cljjog1FOwTACylL11lY0CYEy77n07j6sR LBHVBw6nHYlwqhluiMrGzh4trra4G9nD0Zv5JiZ4ABgv79/KHw40O5Cttx+w4vM0kdKl M9dkNk+gW4SwUc4hFmfVDSBeJmMXSpD0ZhdSRITseXmvaUIaZfw9u5plV9AnAUv+hZg0 OudvdL5KnhzJTRH1Gl6+MvXuvSUwmCYdFCR0K8RUBjAJb9jc2L2lO+jl3txycMBa824v W2hA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Vfok/mCgpSIv0uE/U8fwfVx9d3gnZ1B8QRG6F2i7ZOQ=; b=MU+03s9zSpO+j8q/8ceNy2PwTJWv71BDfePOMwIseY1PKNqmVJyhs7+REvBuA8ADRo 6DG83twb/bR0UW3us9qLjkPu9nsRitcD5tJu9Nm4R/ybMJqdEdzgdT9ZlOKgcgl7u9SI SdB7/nhW39l2ngmQKIBpu9xf0IQETHzKIIyUdcmQHxxIOU2+MZpSnWhu1TRPGumyM0Vn 1fPi7dP81ytTH6QGPitShuI67QDW1R1xtGv3wX2f8T9sWJLEwXQseH1wjjNcvbub2Z/i Z6JV7PVwpt6tzMfPDi1VlsqOdQl8NEnb4KAE19Ex9o9Gt3dW0Lc5v/1HGKf14GPZTbQW Oovg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=osz4fYd4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x2-20020a63f702000000b0040ca3580ca0si14023560pgh.651.2022.06.27.05.30.00; Mon, 27 Jun 2022 05:30:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=osz4fYd4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238349AbiF0Lvw (ORCPT + 99 others); Mon, 27 Jun 2022 07:51:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49978 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238311AbiF0LsP (ORCPT ); Mon, 27 Jun 2022 07:48:15 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0576CF59B; Mon, 27 Jun 2022 04:40:29 -0700 (PDT) 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 97F5960C16; Mon, 27 Jun 2022 11:40:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4F15C36AED; Mon, 27 Jun 2022 11:40:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1656330028; bh=i7tt2QLqXksiiPiErEk6fj3nMFk3l0zF4KVChldBfBo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=osz4fYd4M1WpzbVIPB36anxbpLTW67wZDAXKzvnh7hSWF2tdtCaGK8iDU1DWMf3iY ynd3I5izycfX8Hn90XDOkbTdWh7/hIFzMEethyLvKv4xvv/8X5Aw52iBOXeaq8SafC TFUQKZ/MfSBQdGQb/4wB8fqyMRTTuSfWt+Cl/hCU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, syzbot+3e3f419f4a7816471838@syzkaller.appspotmail.com, Christoph Hellwig , Jens Axboe , Sasha Levin Subject: [PATCH 5.18 060/181] block: disable the elevator int del_gendisk Date: Mon, 27 Jun 2022 13:20:33 +0200 Message-Id: <20220627111946.306640058@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220627111944.553492442@linuxfoundation.org> References: <20220627111944.553492442@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Christoph Hellwig [ Upstream commit 50e34d78815e474d410f342fbe783b18192ca518 ] The elevator is only used for file system requests, which are stopped in del_gendisk. Move disabling the elevator and freeing the scheduler tags to the end of del_gendisk instead of doing that work in disk_release and blk_cleanup_queue to avoid a use after free on q->tag_set from disk_release as the tag_set might not be alive at that point. Move the blk_qos_exit call as well, as it just depends on the elevator exit and would be the only reason to keep the not exactly cheap queue freeze in disk_release. Fixes: e155b0c238b2 ("blk-mq: Use shared tags for shared sbitmap support") Reported-by: syzbot+3e3f419f4a7816471838@syzkaller.appspotmail.com Signed-off-by: Christoph Hellwig Tested-by: syzbot+3e3f419f4a7816471838@syzkaller.appspotmail.com Link: https://lore.kernel.org/r/20220614074827.458955-2-hch@lst.de Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/blk-core.c | 13 ------------- block/genhd.c | 39 +++++++++++---------------------------- 2 files changed, 11 insertions(+), 41 deletions(-) diff --git a/block/blk-core.c b/block/blk-core.c index 84f7b7884d07..a7329475aba2 100644 --- a/block/blk-core.c +++ b/block/blk-core.c @@ -322,19 +322,6 @@ void blk_cleanup_queue(struct request_queue *q) blk_mq_exit_queue(q); } - /* - * In theory, request pool of sched_tags belongs to request queue. - * However, the current implementation requires tag_set for freeing - * requests, so free the pool now. - * - * Queue has become frozen, there can't be any in-queue requests, so - * it is safe to free requests now. - */ - mutex_lock(&q->sysfs_lock); - if (q->elevator) - blk_mq_sched_free_rqs(q); - mutex_unlock(&q->sysfs_lock); - /* @q is and will stay empty, shutdown and put */ blk_put_queue(q); } diff --git a/block/genhd.c b/block/genhd.c index 3008ec213654..13daac1a9aef 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -652,6 +652,17 @@ void del_gendisk(struct gendisk *disk) blk_sync_queue(q); blk_flush_integrity(); + blk_mq_cancel_work_sync(q); + + blk_mq_quiesce_queue(q); + if (q->elevator) { + mutex_lock(&q->sysfs_lock); + elevator_exit(q); + mutex_unlock(&q->sysfs_lock); + } + rq_qos_exit(q); + blk_mq_unquiesce_queue(q); + /* * Allow using passthrough request again after the queue is torn down. */ @@ -1120,31 +1131,6 @@ static const struct attribute_group *disk_attr_groups[] = { NULL }; -static void disk_release_mq(struct request_queue *q) -{ - blk_mq_cancel_work_sync(q); - - /* - * There can't be any non non-passthrough bios in flight here, but - * requests stay around longer, including passthrough ones so we - * still need to freeze the queue here. - */ - blk_mq_freeze_queue(q); - - /* - * Since the I/O scheduler exit code may access cgroup information, - * perform I/O scheduler exit before disassociating from the block - * cgroup controller. - */ - if (q->elevator) { - mutex_lock(&q->sysfs_lock); - elevator_exit(q); - mutex_unlock(&q->sysfs_lock); - } - rq_qos_exit(q); - __blk_mq_unfreeze_queue(q, true); -} - /** * disk_release - releases all allocated resources of the gendisk * @dev: the device representing this disk @@ -1166,9 +1152,6 @@ static void disk_release(struct device *dev) might_sleep(); WARN_ON_ONCE(disk_live(disk)); - if (queue_is_mq(disk->queue)) - disk_release_mq(disk->queue); - blkcg_exit_queue(disk->queue); disk_release_events(disk); -- 2.35.1