Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6268127imu; Mon, 21 Jan 2019 06:07:36 -0800 (PST) X-Google-Smtp-Source: ALg8bN4zuoVk4A5HI02aLK0ii13EEtKwRYqrQx3aT95nWM7ljDQfmYYKAuQ1MTNWWbih1YzEjx12 X-Received: by 2002:a63:1904:: with SMTP id z4mr21221505pgl.135.1548079655956; Mon, 21 Jan 2019 06:07:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548079655; cv=none; d=google.com; s=arc-20160816; b=t1KXqlU/40UdnyNV+tJQjxV9XUirb6NVoPUH6TEnaEVhM2rI3LI5KBgstwgpM9SNuX VEs1ODpWURyUWPUjuf9BNkZebzXC2NwxeLVnxdrAYIgrk0qJVZZrC+rkvC8qxd0AGeN4 4FpcjGm1UEt91OjBB2iWpKBL1o0EkcfCqCc8SxVCUswnPKohTFzKt7k16HWIwmxSV7d9 IsnUpVS8gvcW7NUKskFtgMOnfwq7WbIv7zRFxhvzGDup5Gfof9He9uFshqHu9QfyrPU5 K0NLGqkScVlbE8AcJ8z5TwU6S72NPHeQVu+DRB0uUytDPPtp1Gp5RHE4fFba71/jEy44 Gc0Q== 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=wbJ9jux5qm4pnYnGPrSwYCC0Zc4mCq0VP6Kk01hCQVA=; b=sAI6ZYlAwesR5UHpOC4XyNDaS0m7Aaf9tL2FQIJwaW2Cc0aKnlEJA1IRCkD0im1pu4 Zy+KBAwyGOrFfZ3gOyUD1Pv1buYhJESlxOrLLelBOZB+6a80ehdXjnwIx5NUmoD3LHHF S5r0/IPM3JHeffTGcsAoUAmrscs+yBIyqdbeMt+8Uv1tmIOx2WtPxD0WN/FYFIVA85Dq zXV91fu/FgtzKCbFm0OXDZ3I6WCY5Kwx/c6BQW2QWnfrnvWQggLtAFevp1zaK8y2tU/w HQNlxnOQgqUFvuZBke2iwWRgX4ZaPjhrJXepuL01J1TUzBY84AM5Mg6TUMY3lopfh33T Q6Tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="Rcuf/VMy"; 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 l8si12181971pfc.98.2019.01.21.06.07.20; Mon, 21 Jan 2019 06:07:35 -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="Rcuf/VMy"; 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 S1732781AbfAUOCX (ORCPT + 99 others); Mon, 21 Jan 2019 09:02:23 -0500 Received: from mail.kernel.org ([198.145.29.99]:49828 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732774AbfAUOCU (ORCPT ); Mon, 21 Jan 2019 09:02:20 -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 7B3C42089F; Mon, 21 Jan 2019 14:02:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548079340; bh=JrKQi6eWSA72yLucNcMaDlmlvDPF/ZGhR4+XubhNSoc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rcuf/VMy+4ElAxbBKFaeor0HAKZiqlAfacwWh3hgfv4cevoagV9Qd8eLRQs8AR0nB pUvg8gFg/ilnwcZZrjC6h4sgxZYBUyKrym4uFTEzEBaGHCnWRqavzfG4dCxu1OA2gV ser9kyTUyjmqNaHui/RvRJQOiF9kNNtfnRgCbeEM= 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.19 91/99] loop: Move special partition reread handling in loop_clr_fd() Date: Mon, 21 Jan 2019 14:49:23 +0100 Message-Id: <20190121134918.132836499@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190121134913.924726465@linuxfoundation.org> References: <20190121134913.924726465@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. ------------------ 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 @@ -631,18 +631,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); @@ -1096,8 +1085,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;