Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6280270imu; Mon, 21 Jan 2019 06:18:19 -0800 (PST) X-Google-Smtp-Source: ALg8bN6nHQ6hSpO6r3p3dv7Jjl4g7aFCKM8Cu+KCrGOvhzuFN6p4HtFJrMQQpc9e2TnNyUtTpgP+ X-Received: by 2002:a17:902:a5ca:: with SMTP id t10mr30207521plq.139.1548080299225; Mon, 21 Jan 2019 06:18:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548080299; cv=none; d=google.com; s=arc-20160816; b=Hlwiv9o2dG4rgp18lhsFhEynYyDIP9efaJX1H4qXS0mNSymkn7DC3flFDKhxAeDOUU D3lAH/aDdHcgSzFhlG/vQNCcgOeNwznIF2MJz0h5YbdhMTZApgu8mmQOFTGhI73OYOz4 ZQpvdqQpAYW2cmEvtJ1kL927J5lvALMHWFL/e+Z8hz4eY9d3SlKq3GoXbBHRsUjSWOGm 9wO+7ydFAl12lwflYcPTGqe5tXKzMPxthoHyp2AYMSbP4AQaXCZCWMS1/jMlsxz8NthR gVR/u9wcfRHeQ8cz0cMqGU6kycKnlCzunskaSVIQsfuaMRqsUDHYWuRSQmexMFtlp0SG Tp4Q== 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=Flsk+ahLs8RRf/NQpn2aW6+WP7nodhP+CIJe4L6uyzU=; b=rKCc2MzLDnqE3VVb7eGWcJkDpb/NEC5s8uuU6i9ih/mQNDDJ2FZpqWDo3vClWgzVaB 2xb6YVe2EuX0L6kyI02s2bXEj7oM7Mh/rsgFj5eOwQhWiQWoIoMt0zYQDnPI0333UspF hY38Yn/g8VSgeI+Wgb8rwVdPIfkvDbLMt+cKIbMOX2GKpV9XQfWyw3OOHDrU8oBraRRS pOJ48z9f/PsXR1GAyo7FZOWBoQ96iuxqDMs5dLhSEFnSk0vvDRPPr/rxGk7yQUGhQdky YytHZJ9Ext3w+gi2g8AovLs8LsQVBSqQMx7WFYzCF7+IyPLTY6OO7iOpntrzBICzEhdm K5Dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CZTDEfM8; 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 m38si12618934pgl.125.2019.01.21.06.18.03; Mon, 21 Jan 2019 06:18:19 -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=@kernel.org header.s=default header.b=CZTDEfM8; 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 S1729722AbfAUNur (ORCPT + 99 others); Mon, 21 Jan 2019 08:50:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:33424 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730598AbfAUNun (ORCPT ); Mon, 21 Jan 2019 08:50:43 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.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 BFCED2063F; Mon, 21 Jan 2019 13:50:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548078642; bh=DnN6pPw8GWy+0sl/cX74ssCqKGNKyvbkxfzSwdV+sdk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CZTDEfM811UgD3nWFx6KvTyPafgJvzYftZi6utSVRcv9GLNO8ZngMJSnypFcoVCIv +G7pZALQNgNv9mZnF59rnh14lqE5etGH9Airh+Nl8cxOlboAc4vGNBZc7inlkpJLvt xpCJC9Lu1u7yyN6EZoYSO/FFhb74EJl08si8P0H8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jan Kara , Jens Axboe Subject: [PATCH 4.20 104/111] loop: Move special partition reread handling in loop_clr_fd() Date: Mon, 21 Jan 2019 14:43:38 +0100 Message-Id: <20190121122506.834318752@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190121122455.819406896@linuxfoundation.org> References: <20190121122455.819406896@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.20-stable review patch. If anyone has any objections, please let me know. ------------------ From: Jan Kara commit d57f3374ba4817f7c8d26fae8a13d20ac8d31b92 upstream. The call of __blkdev_reread_part() from loop_reread_partition() happens only when we need to invalidate partitions from loop_release(). Thus move a detection for this into loop_clr_fd() and simplify loop_reread_partition(). This makes loop_reread_partition() safe to use without loop_ctl_mutex because we use only lo->lo_number and lo->lo_file_name in case of error for reporting purposes (thus possibly reporting outdate information is not a big deal) and we are safe from 'lo' going away under us by elevated lo->lo_refcnt. Signed-off-by: Jan Kara Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- drivers/block/loop.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -630,18 +630,7 @@ static void loop_reread_partitions(struc { int rc; - /* - * bd_mutex has been held already in release path, so don't - * acquire it if this function is called in such case. - * - * If the reread partition isn't from release path, lo_refcnt - * must be at least one and it can only become zero when the - * current holder is released. - */ - if (!atomic_read(&lo->lo_refcnt)) - rc = __blkdev_reread_part(bdev); - else - rc = blkdev_reread_part(bdev); + rc = blkdev_reread_part(bdev); if (rc) pr_warn("%s: partition scan of loop%d (%s) failed (rc=%d)\n", __func__, lo->lo_number, lo->lo_file_name, rc); @@ -1095,8 +1084,24 @@ static int __loop_clr_fd(struct loop_dev module_put(THIS_MODULE); blk_mq_unfreeze_queue(lo->lo_queue); - if (lo->lo_flags & LO_FLAGS_PARTSCAN && bdev) - loop_reread_partitions(lo, bdev); + if (lo->lo_flags & LO_FLAGS_PARTSCAN && bdev) { + /* + * bd_mutex has been held already in release path, so don't + * acquire it if this function is called in such case. + * + * If the reread partition isn't from release path, lo_refcnt + * must be at least one and it can only become zero when the + * current holder is released. + */ + if (!atomic_read(&lo->lo_refcnt)) + err = __blkdev_reread_part(bdev); + else + err = blkdev_reread_part(bdev); + pr_warn("%s: partition scan of loop%d failed (rc=%d)\n", + __func__, lo->lo_number, err); + /* Device is gone, no point in returning error */ + err = 0; + } lo->lo_flags = 0; if (!part_shift) lo->lo_disk->flags |= GENHD_FL_NO_PART_SCAN;