Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp997525yba; Thu, 4 Apr 2019 02:04:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqwRtEvQaoVesXkoTlDn/AVXYIhp2gp2x9NwOiDUjiDMQEwB4dFeBffOcJqGC+7Ieds/hw4H X-Received: by 2002:a17:902:1e2:: with SMTP id b89mr5226491plb.278.1554368641562; Thu, 04 Apr 2019 02:04:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554368641; cv=none; d=google.com; s=arc-20160816; b=XqPx4xipXFiJ2AxF1whHchN0gkJbL4JH4mQnpK6kn30V2+OYAviKFrKEbmoXuK21Ix 53I+rZwUsNkmKZMRU02sR2oPTz4nmUKSIB7ovQ0A47KxvANqOr51dMcoXMvD831julgx O0WSixyWWzZYgbnji0iqGozNWxUYVIN1fKU8KxV3czVwIvkyiNalp9+hH/ciwGP7u6ht ohV7zXPWv5B0iBumxtxvABK2O5ilQZ0OfTjEGYl6pMjAH1Ct0T3QyV9loUSk/Fl5QGtY Ne3SERwU/eImoFZpQER7qQU70DtuJn1GDfoBfRT7ZwB54J2LmhCexTwZCLElnNQPswSO C/Sg== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LgkBmMEnccdKYc1p0A7PQLMUwlyiuSEMtCuhkdAl0O8=; b=UQK7jeq0PmqldjM7aQXXdH6r+/JGFhdpJFW98lY+Hg+TbHbBo8GHDmHITu2MlNQ1EB ++XT2SsjU6Yc8SXdpxi2p4xl1eAVJp3gmjnepPjL5ECSJcOdTuEXV6NMJEOzU/xIh7+e UA/M9EbJvuxaQDEA+gIeCQnn4dfQ9pF4hoUEDUTNvQrndunYieRF1C/tFg8RjrRUnnx/ pYxT3FtNgROHwGlLkl8XxOMTkn8A1K1sMfTwgkjusLz4ORNXinx1MmEMYuE/wz0KZIk4 O/dtB7K00Dv9fLHw9aVKXlXl7CWV++gtf6XTV4apppf0ity04nLZou97mICrx2une3rp C9Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UMa5Slje; 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 d2si16707757pla.89.2019.04.04.02.03.46; Thu, 04 Apr 2019 02:04:01 -0700 (PDT) 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=@kernel.org header.s=default header.b=UMa5Slje; 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 S1731538AbfDDJCA (ORCPT + 99 others); Thu, 4 Apr 2019 05:02:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:39290 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731521AbfDDJB7 (ORCPT ); Thu, 4 Apr 2019 05:01:59 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 0533221741; Thu, 4 Apr 2019 09:01:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554368518; bh=ReCXjDPib65EYZYt2ERVLdD8NZTQhP04oQGom1ItsJ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UMa5Sljespp+2fwyOiiouCjmgR2ZPu/yKHRw3/LWbld4pYo77uoRVAUYtV2PKbGWZ 83MYo9ga6UwyoHs66AXe1AazdMqKrQzdVnvtnSuJ1awrkWaLht+dF9vvs5Dcnv7f2H //atpheFj47e5OEkD7zquNFN2MoQLL3I0Ns4+8VI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dongli Zhang , Jan Kara , Jens Axboe , Sasha Levin Subject: [PATCH 4.19 069/187] loop: set GENHD_FL_NO_PART_SCAN after blkdev_reread_part() Date: Thu, 4 Apr 2019 10:46:46 +0200 Message-Id: <20190404084606.297660347@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084603.119654039@linuxfoundation.org> References: <20190404084603.119654039@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 758a58d0bc67457f1215321a536226654a830eeb ] Commit 0da03cab87e6 ("loop: Fix deadlock when calling blkdev_reread_part()") moves blkdev_reread_part() out of the loop_ctl_mutex. However, GENHD_FL_NO_PART_SCAN is set before __blkdev_reread_part(). As a result, __blkdev_reread_part() will fail the check of GENHD_FL_NO_PART_SCAN and will not rescan the loop device to delete all partitions. Below are steps to reproduce the issue: step1 # dd if=/dev/zero of=tmp.raw bs=1M count=100 step2 # losetup -P /dev/loop0 tmp.raw step3 # parted /dev/loop0 mklabel gpt step4 # parted -a none -s /dev/loop0 mkpart primary 64s 1 step5 # losetup -d /dev/loop0 Step5 will not be able to delete /dev/loop0p1 (introduced by step4) and there is below kernel warning message: [ 464.414043] __loop_clr_fd: partition scan of loop0 failed (rc=-22) This patch sets GENHD_FL_NO_PART_SCAN after blkdev_reread_part(). Fixes: 0da03cab87e6 ("loop: Fix deadlock when calling blkdev_reread_part()") Signed-off-by: Dongli Zhang Reviewed-by: Jan Kara Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- drivers/block/loop.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 0c5aeab4d23a..a63da9e07341 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -1090,16 +1090,12 @@ static int __loop_clr_fd(struct loop_device *lo, bool release) kobject_uevent(&disk_to_dev(bdev->bd_disk)->kobj, KOBJ_CHANGE); } mapping_set_gfp_mask(filp->f_mapping, gfp); - lo->lo_state = Lo_unbound; /* This is safe: open() is still holding a reference. */ module_put(THIS_MODULE); blk_mq_unfreeze_queue(lo->lo_queue); partscan = lo->lo_flags & LO_FLAGS_PARTSCAN && bdev; lo_number = lo->lo_number; - lo->lo_flags = 0; - if (!part_shift) - lo->lo_disk->flags |= GENHD_FL_NO_PART_SCAN; loop_unprepare_queue(lo); out_unlock: mutex_unlock(&loop_ctl_mutex); @@ -1121,6 +1117,23 @@ out_unlock: /* Device is gone, no point in returning error */ err = 0; } + + /* + * lo->lo_state is set to Lo_unbound here after above partscan has + * finished. + * + * There cannot be anybody else entering __loop_clr_fd() as + * lo->lo_backing_file is already cleared and Lo_rundown state + * protects us from all the other places trying to change the 'lo' + * device. + */ + mutex_lock(&loop_ctl_mutex); + lo->lo_flags = 0; + if (!part_shift) + lo->lo_disk->flags |= GENHD_FL_NO_PART_SCAN; + lo->lo_state = Lo_unbound; + mutex_unlock(&loop_ctl_mutex); + /* * Need not hold loop_ctl_mutex to fput backing file. * Calling fput holding loop_ctl_mutex triggers a circular -- 2.19.1