Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5650441img; Wed, 27 Mar 2019 12:26:58 -0700 (PDT) X-Google-Smtp-Source: APXvYqyVSiXD8UKD5pGYV35dQd4r8OshrOz+GoBg6SAfN/9NirQih2xP1Pd/enYs5vtfI7+0WUOr X-Received: by 2002:a63:3244:: with SMTP id y65mr35941203pgy.417.1553714818858; Wed, 27 Mar 2019 12:26:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553714818; cv=none; d=google.com; s=arc-20160816; b=XJ1sc+hyHOzRqmXuPpZ1UTQtlX01OrWNQ5VPTv5BWPA5zmDAy2IsQzLGB/g+SBORVW HWUaHlND8DOn9w15hZv57OWeatMTGKm1n1cNgmVPenU3l5Bohqa8VqVqnkn4V2ZkuePC vVcSTZTNJZdcpv7gAHb1JBiDWwZlNRltno6uPG4ZrnuIwbupUSg0dy7cqDtYDbM35MVr xcPdP3ExGIWVB37G1UoS11JCcJlctUpP8gtaX8x9yxp7IcoInVak6mu7T4JSuahWVwht l6FiqB6LNDMBGLG8saz8gN3GYpikhJId1xK667W5o1T8Jv+/1FrAhZrGp9Dtjp1FJwnC 3UbQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rNFMlJc8+G+LCbz/5bsJDbt72Y52Zt7/AEOV+LMS3W8=; b=jlmM0H+Erhr0Ks503bNW0nr3xyihxlkrEfeqDiez54dsaeicWTGPTiWHjuNa5lzQxz ak0ISpb/r/7bf8RgMxaxSbusOP1pzGAdbNnOjNI/1Ye9ZoRd5bprXtIOtiQXrBNzCV5+ +qFsExeF6TjV+mjIb5mU+SYVt189wibL2ZEbfeVANAM9mmpxUtEhhTACLeQJ4drvMcc8 wzNwwd70jHeUEcLhi8lgt86hUC/YRph1UD4yprlB/dtdKE75CRoRVjK+GfvKBegoy5Pu gS/Ulj9EOsNXtv15M+l4S68sZHTJSwe4pXSLyJreSQeGnXzzxQ+PUm7UhhqjHEAAnMnO nQ0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=WAHcTycu; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x3si19287747plv.424.2019.03.27.12.26.43; Wed, 27 Mar 2019 12:26:58 -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=WAHcTycu; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732572AbfC0T0K (ORCPT + 99 others); Wed, 27 Mar 2019 15:26:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:46034 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387569AbfC0SFF (ORCPT ); Wed, 27 Mar 2019 14:05:05 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 09BEA2075C; Wed, 27 Mar 2019 18:05:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553709903; bh=3us/v9f8j5BYRgqxZZlbrsxO9WOuZuT2mCaJ0oYJW1E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WAHcTycuuDmfjghDP7bWRJKsTGKnQCk6jamcI63P42wSaAztCMiJj+fpJRMrfcTpk T2n8efCNyGmXmVBWZ6P3JYnOT0QSwYyxLQrqTAq60oZTR2zD3lMR8j7JYFi5XvoTwr DurAGrSN3E1Rhqyhqj0+ZaH6SFuDTRwip6oxX3Dc= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Dongli Zhang , Jens Axboe , Sasha Levin , linux-block@vger.kernel.org Subject: [PATCH AUTOSEL 5.0 101/262] loop: set GENHD_FL_NO_PART_SCAN after blkdev_reread_part() Date: Wed, 27 Mar 2019 13:59:16 -0400 Message-Id: <20190327180158.10245-101-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dongli Zhang [ 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 cf5538942834..23aa2e9b3be0 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -1089,16 +1089,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); @@ -1120,6 +1116,23 @@ static int __loop_clr_fd(struct loop_device *lo, bool release) /* 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