Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2152264iof; Tue, 7 Jun 2022 21:30:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvU+JLTKgUeuY4ZZRFBQ1XHCspdRsBAH8CYyMXIspqg3kCmj0OdMTf9LFCB8dFWyBZSim3 X-Received: by 2002:a63:1e49:0:b0:3fd:cf48:3694 with SMTP id p9-20020a631e49000000b003fdcf483694mr10840387pgm.275.1654662627673; Tue, 07 Jun 2022 21:30:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654662627; cv=none; d=google.com; s=arc-20160816; b=RJnUgMZSTZXJNENkA7+gweDPyJFyRj49ckgRNpjQipP5luPWxiNuse0dDhrMYm4Ox/ 9Uiyy0ANBqsmBTKs/jDnGH5a8Mk81ni6S4eamclpIZEO2ptU4VbJDG1q6YxXwNBNH+Bp 12fHJXt2uqYEmJiW+tcDI78n/Gc8u1LjO1LOH2NmdEgrbbM4MBzrAPt7wimfBWJ66Bvu buIRl/R9kh71ElWgOXIqshhNgigBXO8mryJb0VWvw1ScZHNAexDDGfJq39lEFAy8d0R1 sFfSPjfWHPunoSJ6XBLh1Aa8Crq8dPc2ydw9xg/yA9US5HtR4RoDVRGytyae+Nr5wBRZ +A6g== 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=3YgnoCoCI3Fx9gut3srK1eHgP3p/DyNQL3L45JbKhKY=; b=L5opkwkYgqb3QrAXZeW137YkOSEUIXu/mZ3SZuuSFmdXVoapM4Iaoq/hOLtGTLG1hE EJk84MBc/mXqsVreDGcGQufN0MWhOSma8U7T2odZKNpEeHkpNe1L6lCQvEPhQAn45dw6 3eZc7cQtzK5e22ECvNH0/16P3fbh1L3qE/OAOoC+7GWoQ1X7NDsTCppGQjIF9M+FPYFh AB6m6+Q7Ne8p1Lr01Ep4uOgJUIRaLzY3ZDBdZNXfPqLgrmzTwihPlIkMrlgu0zcxj3HC pRcN2AFatL7Uj60zWPddkYpJUuASWnJGTjiDqQaDkCEdqP2iwQhq+IHcNCkamw3ecXrI zHyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="zR/0GN70"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id 144-20020a630696000000b003fa67e446fasi17916950pgg.549.2022.06.07.21.30.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 21:30:27 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="zR/0GN70"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8FE151F0FE4; Tue, 7 Jun 2022 20:59:06 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383977AbiFGWJx (ORCPT + 99 others); Tue, 7 Jun 2022 18:09:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379441AbiFGVF5 (ORCPT ); Tue, 7 Jun 2022 17:05:57 -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 3AFEF18F2E1; Tue, 7 Jun 2022 11:49:32 -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 C712C616C3; Tue, 7 Jun 2022 18:49:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D84DEC385A2; Tue, 7 Jun 2022 18:49:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654627771; bh=MryhVYwL20qdpycWJZzLIYovOEL+Bs5lNHa/2TnV0EA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zR/0GN70zecaWHKTYH4KotHMeNz1X10cEx2N2EVOCkiaH6NH2cVM1yCjAq+CkbQfr kvo/u1h5riHY99v0drcrUEXOPf5j2YdAlVPABp5jT6lzLSVe2RVvxDyg/BjXw00GTY RGVzbBQkMJ9zEqgFQprX7GUuot439iFYa04l3WH0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Christoph Hellwig , Jan Kara , Jens Axboe , Sasha Levin Subject: [PATCH 5.18 087/879] loop: implement ->free_disk Date: Tue, 7 Jun 2022 18:53:25 +0200 Message-Id: <20220607165005.218796914@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220607165002.659942637@linuxfoundation.org> References: <20220607165002.659942637@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=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 d2c7f56f8b5256d57f9e3fc7794c31361d43bdd9 ] Ensure that the lo_device which is stored in the gendisk private data is valid until the gendisk is freed. Currently the loop driver uses a lot of effort to make sure a device is not freed when it is still in use, but to to fix a potential deadlock this will be relaxed a bit soon. Signed-off-by: Christoph Hellwig Reviewed-by: Jan Kara Link: https://lore.kernel.org/r/20220330052917.2566582-12-hch@lst.de Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/block/loop.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index a58595f5ee2c..ed7bec11948c 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -1768,6 +1768,14 @@ static void lo_release(struct gendisk *disk, fmode_t mode) mutex_unlock(&lo->lo_mutex); } +static void lo_free_disk(struct gendisk *disk) +{ + struct loop_device *lo = disk->private_data; + + mutex_destroy(&lo->lo_mutex); + kfree(lo); +} + static const struct block_device_operations lo_fops = { .owner = THIS_MODULE, .open = lo_open, @@ -1776,6 +1784,7 @@ static const struct block_device_operations lo_fops = { #ifdef CONFIG_COMPAT .compat_ioctl = lo_compat_ioctl, #endif + .free_disk = lo_free_disk, }; /* @@ -2090,15 +2099,14 @@ static void loop_remove(struct loop_device *lo) { /* Make this loop device unreachable from pathname. */ del_gendisk(lo->lo_disk); - blk_cleanup_disk(lo->lo_disk); + blk_cleanup_queue(lo->lo_disk->queue); blk_mq_free_tag_set(&lo->tag_set); mutex_lock(&loop_ctl_mutex); idr_remove(&loop_index_idr, lo->lo_number); mutex_unlock(&loop_ctl_mutex); - /* There is no route which can find this loop device. */ - mutex_destroy(&lo->lo_mutex); - kfree(lo); + + put_disk(lo->lo_disk); } static void loop_probe(dev_t dev) -- 2.35.1