Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp598502imp; Thu, 21 Feb 2019 07:32:05 -0800 (PST) X-Google-Smtp-Source: AHgI3IbH0mOD/N5e+m9wbhrix071SlbIPibT16Z8gxnKkAPOE5nZl3lDz6fUETLmWs2heQiuenIX X-Received: by 2002:a62:29c3:: with SMTP id p186mr41424489pfp.117.1550763125622; Thu, 21 Feb 2019 07:32:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550763125; cv=none; d=google.com; s=arc-20160816; b=S3INgSYNU4uQ5Z56MhPquh+nB6vllZN6E0YvbkqXL7hv7F9stJsdg66ehP2/ItLaHs O4c1GgqdW0Nuagtphefd17HXV2ox+1hR4dy0nGoTHGV8I/npbSKoVqyLMX6WdkFLYBpD E7/bUunqd/5GErGV+UAictWubqvCGq02ooKeomMYxh4QBGCAEuLklT7oFfckrUZjdAsZ Vj0G54xUXIfR3WJhgwOK5ENng4cpYYnmlVuWuM8a+Et3EstWNAkPyd0Ao7o0DwjsA5h4 EN8i+4ib6yfDiLF2GApZXhiIxTvdv8ZGuEksfT4lheVZ72u89x1nRTgLyi9f715IVvca HNkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=0jr6pMmYk/w6OiYL4H77HqpSIEDJZp1hkdQy563ts0s=; b=nnRG/MAwTV2CiIjf97v3rzj1pkM4sBetvZo7C07GyrjGFhi5Lc0PSXwDr6IyVZxolw DqOX+9+4lYWE9RsQvOTTdvh7ozF8b0i45ekS7gi3w213P+dRorvbrDyWWVuxBie35iBX GTBOMblgkI/ynpknxA1dPVumZl3tEo/LjYhvo5YFswqJAYqf1AdjV4UYRZoHPAe0Uu49 ujU3Z4RBKIya7vT0/djfC6CfSHsBG/y7eMK1cNPVXxG6JS5M/9DEFgXkMNrCv0YuSf1X HNm0UJdokW0k2evkk7u+J36DtBMo3AwUeshlChyfA/0qTBB8NcfesXehRqUfbOmDdMe9 8l9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b="o/aNC0UP"; 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=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d21si799757pll.437.2019.02.21.07.31.50; Thu, 21 Feb 2019 07:32:05 -0800 (PST) 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=@oracle.com header.s=corp-2018-07-02 header.b="o/aNC0UP"; 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=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728398AbfBUPas (ORCPT + 99 others); Thu, 21 Feb 2019 10:30:48 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:58828 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728305AbfBUPaq (ORCPT ); Thu, 21 Feb 2019 10:30:46 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x1LFSs5p034479; Thu, 21 Feb 2019 15:30:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=0jr6pMmYk/w6OiYL4H77HqpSIEDJZp1hkdQy563ts0s=; b=o/aNC0UPOKotLTSwo7NaxHoNNLBJw8AGXPk/kffNlego7EzHLhV1BN8NeAcHP290LrlV s/u2FN2RPreBg6707yTeY7jLwUuME83tugWUAZotGaQNa+YmNlCoEKm4yP7Ahf3gAErX xOgxXzT2jGsnWLswsB+eFvg4EaJ3He+zXzSZgfdsoQuGhuKd/sG2EhKTDj6OU7/YGFwV XWocZn3FoyuAnjVkox35cchMjK123ew1F3LgBQfk+iqxf5kODhAVUm5heM8ryzT69iYH YdXItaFlw/KIN/uC3KR7+YmdkGZMmf+w5T5mhRnbk0CAwc2I871+TYEJiA1nD0wt3zWo Fg== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2qpb5rrmja-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 21 Feb 2019 15:30:42 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x1LFUffC002005 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 21 Feb 2019 15:30:42 GMT Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x1LFUfBc006545; Thu, 21 Feb 2019 15:30:41 GMT Received: from linux.cn.oracle.com (/10.182.69.106) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 21 Feb 2019 07:30:41 -0800 From: Dongli Zhang To: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Cc: axboe@kernel.dk, jack@suse.cz Subject: [PATCH v2 2/2] loop: set GENHD_FL_NO_PART_SCAN after blkdev_reread_part() Date: Thu, 21 Feb 2019 23:33:43 +0800 Message-Id: <1550763223-21764-3-git-send-email-dongli.zhang@oracle.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1550763223-21764-1-git-send-email-dongli.zhang@oracle.com> References: <1550763223-21764-1-git-send-email-dongli.zhang@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9174 signatures=668684 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902210112 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- Changed since v1: * move the setting of lo->lo_state to Lo_unbound after partscan has finished as well (suggested by Jan Kara) drivers/block/loop.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/drivers/block/loop.c b/drivers/block/loop.c index 7908673..a13f5dc 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -1034,6 +1034,16 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer, return err; } +static void loop_disable_partscan(struct loop_device *lo) +{ + 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); +} + static int __loop_clr_fd(struct loop_device *lo, bool release) { struct file *filp = NULL; @@ -1089,16 +1099,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 +1127,18 @@ 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 inside loop_disable_partscan() + * 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. + */ + loop_disable_partscan(lo); + /* * Need not hold loop_ctl_mutex to fput backing file. * Calling fput holding loop_ctl_mutex triggers a circular -- 2.7.4