Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6264779imu; Mon, 21 Jan 2019 06:04:58 -0800 (PST) X-Google-Smtp-Source: ALg8bN73VA5t53BxuPIn69BNTkzwf7r85prrntYtlBULen2nVYBBhJW8/8N7R4lljdePeZrie9wb X-Received: by 2002:a63:1204:: with SMTP id h4mr28254054pgl.51.1548079498260; Mon, 21 Jan 2019 06:04:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548079498; cv=none; d=google.com; s=arc-20160816; b=m5S/SmkmtwQEp1ke0+03KwqkGPH6cAKX3jXeQ8KrRSbyuRIjo9yHE7jndY0D9D0RjS pG3jte38C3TOK2+T2YCKBfXl6OVZxScoc6qBC42KFeRD8fGnudHOGvErOeh641OnyXBO 17xUqzaCvJ079z+9tVPIw1JIKTktM9pAllxhMGJzVTS2VKpbAvij5EKsOacJtD5jUih9 s3w3HufjXeA2nEAuXhIfsHcKh74Rg1/NXP1l/ElXfKJX9DGkRuB8QRqQ4OO/4+MqZXPG i2miT9QJmJKIQPjHDbuF11Z+jyCKbPSq1JStYtJMZvtkNpanuksJu0q8E7WVlJRsjN2l ZAzQ== 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=+sPFz1SyyuQROYl7jsGNXpdVwa4O02jzbI86D1+3IMM=; b=fRllmhgM145RtiAygMjoeDcUHdZE3qQzrwEMpVn30ocKO8NIOFHR+JPJaIKN5fwPb4 YyvAOy18pDhkUV0OlWzyD7EpFiLUjR6HkfNqvTZwVEY1Xpht1fpFsDXGk8Grsin5TIl8 ot/NUhDQYjhc855VhQGcwdCzI7NqrQNCjfFhq045hyU1AsNKVAID7wTjC/unjBor4k7p EgzQS4Mwwm7XiGz7/wUkkOwErvrrv7FTqGx0gF5HRy6N1KbcjdYVSkx/1bpUonn4W+vb M9iSkPBUuhE3BRpz3RG2IbDVd3zSFBAis98SNKjLaF/OvPM5Ff1YyMIA2UX9uwPa4Mko x3Jg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Jm9EsUxj; 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 r6si12297071pli.248.2019.01.21.06.04.31; Mon, 21 Jan 2019 06:04:58 -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=Jm9EsUxj; 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 S1732750AbfAUOCR (ORCPT + 99 others); Mon, 21 Jan 2019 09:02:17 -0500 Received: from mail.kernel.org ([198.145.29.99]:49686 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731825AbfAUOCO (ORCPT ); Mon, 21 Jan 2019 09:02:14 -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 B80FD2089F; Mon, 21 Jan 2019 14:02:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548079334; bh=zyOGgXxNaXkoCtFbRZTOGjWsAlDgturv1hQqNlyvRPA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jm9EsUxjI/s4t2lE9B2f/JfDdiywnLsFBS5IvLl+WlF9UVyFCk5TW+IAsG2K+Uh6B 6RmSsoxAjxJXVo70amTkZ4vSBk3UqDiuMYSlUe+qc39h9M/xHHxtpBAe9btxJ+TVJO yOhZpCBHTqwbD0IRLmUuyIxPYHE2IOBDCrfWDrMs= 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 89/99] loop: Push loop_ctl_mutex down to loop_set_fd() Date: Mon, 21 Jan 2019 14:49:21 +0100 Message-Id: <20190121134917.712702505@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 757ecf40b7e029529768eb5f9562d5eeb3002106 upstream. Push lo_ctl_mutex down to loop_set_fd(). We will need this to be able to call loop_reread_partitions() without lo_ctl_mutex. Signed-off-by: Jan Kara Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- drivers/block/loop.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -919,13 +919,17 @@ static int loop_set_fd(struct loop_devic if (!file) goto out; + error = mutex_lock_killable_nested(&loop_ctl_mutex, 1); + if (error) + goto out_putf; + error = -EBUSY; if (lo->lo_state != Lo_unbound) - goto out_putf; + goto out_unlock; error = loop_validate_file(file, bdev); if (error) - goto out_putf; + goto out_unlock; mapping = file->f_mapping; inode = mapping->host; @@ -937,10 +941,10 @@ static int loop_set_fd(struct loop_devic error = -EFBIG; size = get_loop_size(lo, file); if ((loff_t)(sector_t)size != size) - goto out_putf; + goto out_unlock; error = loop_prepare_queue(lo); if (error) - goto out_putf; + goto out_unlock; error = 0; @@ -979,11 +983,14 @@ static int loop_set_fd(struct loop_devic * put /dev/loopXX inode. Later in __loop_clr_fd() we bdput(bdev). */ bdgrab(bdev); + mutex_unlock(&loop_ctl_mutex); return 0; - out_putf: +out_unlock: + mutex_unlock(&loop_ctl_mutex); +out_putf: fput(file); - out: +out: /* This is safe: open() is still holding a reference. */ module_put(THIS_MODULE); return error; @@ -1461,12 +1468,7 @@ static int lo_ioctl(struct block_device switch (cmd) { case LOOP_SET_FD: - err = mutex_lock_killable_nested(&loop_ctl_mutex, 1); - if (err) - return err; - err = loop_set_fd(lo, mode, bdev, arg); - mutex_unlock(&loop_ctl_mutex); - break; + return loop_set_fd(lo, mode, bdev, arg); case LOOP_CHANGE_FD: err = mutex_lock_killable_nested(&loop_ctl_mutex, 1); if (err)