Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp736995imm; Thu, 13 Sep 2018 07:03:10 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYJ/pVL4XP0Ln5U5YFZSLWCDcqMCXYZGOtJR1WiAx31p8u28K7CO/jOX0ofOaCGfVHI3Mbm X-Received: by 2002:a63:e647:: with SMTP id p7-v6mr7063720pgj.218.1536847390114; Thu, 13 Sep 2018 07:03:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536847390; cv=none; d=google.com; s=arc-20160816; b=Ycv3qTfPYqdn7Z92D5uOT3VkVLVWSkyDMge8xTpoklSudh2qNs4Go1euJduG1b+bBB UcVu4UvBhzA2rCTuloaZlF9lkvfQSOfH/bm9kzYTOCikSrb4u9QIx/ICVO+rnsOjlMWk YKpQkEBrFdDoaD0AZoxv5d4Ls5dMzLCEtF7t7nf04gQKceX8+2gaYYn3ASpi5GlM00ty RDYdsAphxhRebFI69QShVNMSRibxDT5cXO3F4/uilMSCSS6rikYCM6L25B5Zk9clp+fG EiYZ8HsnDkqFRQHzrYZ32FXXQ7ImVrazjQ9Ayg+FpWjwqzwb4wqXduOv3rzFga5rX7HR 6kPQ== 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; bh=knnR/wxpcAYEjjzaSy9ATMOrMtLIoSgyb6Jy0S1yBKM=; b=hpZvDYTnonLXqNIht0weB3CU2YQndHA5Wxq3p7uiMgWSD0SK+DvkoOI2WaT0xoLGkw Z4X4ZgAZgwI+cqjF0KIACgaHrtllG4fXO+SJy/X+3OxT4SemleSkFozXmB9RJdXllSRB wWjffMv6rmyl3aJ+F01K9pNIj9G4Cvp9C7u4EIC+M13KbdtHaR4h+Xs7gX1ziFHHvMN0 pv1OHioD3CnDqSWok4G0HSyXBxIvZCIRUwqTP61DoCUpUAXp9hh3qm+oe8bLd3yd99Ho u+TFk7nN3AK07s26voXHJ1a/LxQN4t4/kIP6nqnfNjqBn3rQxR9fwK5bBIlYQigY+Vdk uE6Q== ARC-Authentication-Results: i=1; mx.google.com; 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 u24-v6si4389233pgk.72.2018.09.13.07.02.44; Thu, 13 Sep 2018 07:03:10 -0700 (PDT) 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; 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 S1731976AbeIMTMO (ORCPT + 99 others); Thu, 13 Sep 2018 15:12:14 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:35248 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731126AbeIMTMN (ORCPT ); Thu, 13 Sep 2018 15:12:13 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 786A5D2F; Thu, 13 Sep 2018 14:02:34 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Anand Jain , David Sterba , Sasha Levin Subject: [PATCH 4.18 148/197] btrfs: lift uuid_mutex to callers of btrfs_scan_one_device Date: Thu, 13 Sep 2018 15:31:37 +0200 Message-Id: <20180913131847.474140772@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180913131841.568116777@linuxfoundation.org> References: <20180913131841.568116777@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: David Sterba [ Upstream commit 899f9307c33ce4758c30a076b10ed54d5c91c6e7 ] Prepartory work to fix race between mount and device scan. The callers will have to manage the critical section, eg. mount wants to scan and then call btrfs_open_devices without the ioctl scan walking in and modifying the fs devices in the meantime. Reviewed-by: Anand Jain Signed-off-by: David Sterba Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/super.c | 12 +++++++++++- fs/btrfs/volumes.c | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -917,8 +917,10 @@ static int btrfs_parse_early_options(con error = -ENOMEM; goto out; } + mutex_lock(&uuid_mutex); error = btrfs_scan_one_device(device_name, flags, holder, fs_devices); + mutex_unlock(&uuid_mutex); kfree(device_name); if (error) goto out; @@ -1539,7 +1541,9 @@ static struct dentry *btrfs_mount_root(s return ERR_PTR(error); } + mutex_lock(&uuid_mutex); error = btrfs_scan_one_device(device_name, mode, fs_type, &fs_devices); + mutex_unlock(&uuid_mutex); if (error) goto error_sec_opts; @@ -2236,15 +2240,21 @@ static long btrfs_control_ioctl(struct f switch (cmd) { case BTRFS_IOC_SCAN_DEV: + mutex_lock(&uuid_mutex); ret = btrfs_scan_one_device(vol->name, FMODE_READ, &btrfs_root_fs_type, &fs_devices); + mutex_unlock(&uuid_mutex); break; case BTRFS_IOC_DEVICES_READY: + mutex_lock(&uuid_mutex); ret = btrfs_scan_one_device(vol->name, FMODE_READ, &btrfs_root_fs_type, &fs_devices); - if (ret) + if (ret) { + mutex_unlock(&uuid_mutex); break; + } ret = !(fs_devices->num_devices == fs_devices->total_devices); + mutex_unlock(&uuid_mutex); break; case BTRFS_IOC_GET_SUPPORTED_FEATURES: ret = btrfs_ioctl_get_supported_features((void __user*)arg); --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1241,6 +1241,8 @@ int btrfs_scan_one_device(const char *pa int ret = 0; u64 bytenr; + lockdep_assert_held(&uuid_mutex); + /* * we would like to check all the supers, but that would make * a btrfs mount succeed after a mkfs from a different FS. @@ -1259,7 +1261,6 @@ int btrfs_scan_one_device(const char *pa goto error_bdev_put; } - mutex_lock(&uuid_mutex); device = device_list_add(path, disk_super, &new_device_added); if (IS_ERR(device)) { ret = PTR_ERR(device); @@ -1268,7 +1269,6 @@ int btrfs_scan_one_device(const char *pa if (new_device_added) btrfs_free_stale_devices(path, device); } - mutex_unlock(&uuid_mutex); btrfs_release_disk_super(page);