Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp595247imp; Thu, 21 Feb 2019 07:28:43 -0800 (PST) X-Google-Smtp-Source: AHgI3IYcC+RPTJN+dJvezBNH8C3+Q7GrXB4lhZMhnsyGg51B9EL/IKeq3A6dup6BM/FC5qhePZoN X-Received: by 2002:a17:902:7686:: with SMTP id m6mr34517998pll.262.1550762923006; Thu, 21 Feb 2019 07:28:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550762922; cv=none; d=google.com; s=arc-20160816; b=OHzLo8S7F0EJ5IAAYtVToVovA27z+5V1VA+g2NZt9pYwsBZfAP+GBsv8xF7MqkWjDX e3+Mx67wx4fENtjM/lBqbll2c7O8RFcpphSs1tLW45GK6rKmoQQ++HlrO4Lo4Bc+sUXx IBaBut7f/T0lcX1J8DKHj4F0xqqr+MVV3SPHd45tAeiVoYABIx0fvW/MY2dWWL0ILkT0 zms+3WuD+iglgWSz0T49UmZCi814gEuZFcbnjxQD8uD1eTCx9whLpb3FfDUoZyNrOrnz wegfKc9ag7NAm/NCF/5ZDO4BCU8rlqBWYwllHeEBQ3SA66WwDFbGm1En0G6rioOD/l5A 7jNg== 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:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject:dkim-signature; bh=6KbppNFHzraf80vko23Id4VTbMn3llPdPtTeI4mmcyc=; b=FGzLlRjb7bW8ayhsgYjiWehdUJUoHqNyHpflTx1aHjHqIBb4m+FwGm6693uH/9uhtP npPbz+4fZ1F5JUpqODQiWOUyeAifHDmy4rVSmOsp2teYS7ecDrvWyd0+FAcL+GALAHph N3RFy851O4qwReee4VFAS3BriQWUpUob+8eUqZh/UES1YN72L5eQCHwSA2mjw5g9hm9t 8bBz4dWzKoEzq8ty06wy4o7/Wug52FBl13/qbYpkWLNPIiDbkIMFDVZ7+mixHcoiF9Uj cnbX46zIf2mAqCrp0AULNWh9gbTMDBXzrxTOm/ohxCIcrTTKfhjtiiQFCV9cqLIX/fFG /DHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2018-07-02 header.b=pLpkN5c0; 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 y35si17458770pgl.569.2019.02.21.07.28.27; Thu, 21 Feb 2019 07:28:42 -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=pLpkN5c0; 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 S1728382AbfBUP0S (ORCPT + 99 others); Thu, 21 Feb 2019 10:26:18 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:53322 "EHLO userp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728248AbfBUP0F (ORCPT ); Thu, 21 Feb 2019 10:26:05 -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 x1LFIYQH024651; Thu, 21 Feb 2019 15:26:01 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : to : references : cc : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=corp-2018-07-02; bh=6KbppNFHzraf80vko23Id4VTbMn3llPdPtTeI4mmcyc=; b=pLpkN5c0HULP4SsCIbI1I4DQ1vKVF1DO/bYsHQyoLEY8fnfdrCiYh/xZPgL9UsKhGEop SIodqiTl1oqTMv/gr2Slq4u0QeSYxEihWKAmMAtAREYlq7jFJf2Asqnw59TmAEnEYTUk DNzmVjistO+O1IuNNiC5EsaCcGBcGpo9EisayHN6HKKMC9pKJ7/ASuXIQlpOcxtHZrol N3I0FEcgpELiu7RG3hZV0kU0beMtau2R3ftYzvgdD6WW0RMSnCm9mZP/X4yZf20SBpd8 n/mEOAJs3v+5+k+X1EPKDbPSled2zWwmyqJyFYoeYbe7EEM+wKv9HGn2LCI8zz9M83p4 9A== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2qpb5rrkm6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 21 Feb 2019 15:26:00 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x1LFPxrA015766 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 21 Feb 2019 15:26:00 GMT Received: from abhmp0002.oracle.com (abhmp0002.oracle.com [141.146.116.8]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x1LFPxBb011586; Thu, 21 Feb 2019 15:25:59 GMT Received: from [10.191.27.185] (/10.191.27.185) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 21 Feb 2019 07:25:59 -0800 Subject: Re: [PATCH 2/2] loop: set GENHD_FL_NO_PART_SCAN after blkdev_reread_part() To: Jan Kara References: <1550722655-15102-1-git-send-email-dongli.zhang@oracle.com> <1550722655-15102-3-git-send-email-dongli.zhang@oracle.com> <20190221113005.GF27474@quack2.suse.cz> Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, axboe@kernel.dk From: Dongli Zhang Message-ID: Date: Thu, 21 Feb 2019 23:25:51 +0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 In-Reply-To: <20190221113005.GF27474@quack2.suse.cz> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit 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-1902210111 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/21/2019 07:30 PM, Jan Kara wrote: > On Thu 21-02-19 12:17:35, Dongli Zhang wrote: >> 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 > > Can you perhaps write a blktest for this? Thanks! I will write a blktest for above case. Thanks for the suggestion. > >> 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 >> --- >> drivers/block/loop.c | 15 ++++++++++++--- >> 1 file changed, 12 insertions(+), 3 deletions(-) >> >> diff --git a/drivers/block/loop.c b/drivers/block/loop.c >> index 7908673..736e55b 100644 >> --- a/drivers/block/loop.c >> +++ b/drivers/block/loop.c >> @@ -1034,6 +1034,15 @@ 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; >> + mutex_unlock(&loop_ctl_mutex); >> +} >> + >> static int __loop_clr_fd(struct loop_device *lo, bool release) >> { >> struct file *filp = NULL; >> @@ -1096,9 +1105,6 @@ static int __loop_clr_fd(struct loop_device *lo, bool release) >> >> 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,9 @@ static int __loop_clr_fd(struct loop_device *lo, bool release) >> /* Device is gone, no point in returning error */ >> err = 0; >> } >> + >> + loop_disable_partscan(lo); >> + >> /* >> * Need not hold loop_ctl_mutex to fput backing file. >> * Calling fput holding loop_ctl_mutex triggers a circular > > So I don't think this change is actually correct. The problem is that once > lo->lo_state is set to Lo_unbound and loop_ctl_mutex is unlocked, the loop > device structure can be reused for a new device (bound to a new file). So > you cannot safely manipulate flags on lo->lo_disk anymore. But I think we > can just move the setting of lo->lo_state to Lo_unbound after partscan has > finished as well. 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 (please make > this last sentence into a comment in the code explaining why setting > lo->lo_state so late is fine). Thanks! I will set lo->lo_state to Lo_unbound after partscan in v2. Thank you very much! Dongli Zhang > > Honza >