Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3700801imu; Mon, 28 Jan 2019 09:16:09 -0800 (PST) X-Google-Smtp-Source: ALg8bN6MXUWlaPErHI5nJj/jsMPAPre3Tp6hB67QVbRThYxzHaR2b+SwF5BKnK8dtu0AdZGhuG1G X-Received: by 2002:a63:20e:: with SMTP id 14mr20468216pgc.161.1548695769387; Mon, 28 Jan 2019 09:16:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548695769; cv=none; d=google.com; s=arc-20160816; b=QwnogCNm3RayPU5OGVp/UD4hvIENdj0NBBePkOu1/A0yeJHzVEyo3gE+uJ4T4mjimB p+6kSxKVwl0Ev4CD+crdHOk8t16ntye6cjAjYw2iEskZYf5QeP3hzRjlrXHLNqStinPj 6ISM8nuFsTj9/qXv9DS3g/gNdfKcXaOvESYtSDzmFdtIh2jV5fGaIU4lv7P54i/RibIg FD8aRHlwx5lUxyvy7ECEf4Aar8N7Lmqs7WyAc0Sj9U7PXEro6EyJTltiNRCUR0otOldL hbljaa4C/1JVrqAL/zB1hzJeOX8vcH/Xy44CFiSKAidZQGItXJAwD2CKKATh4jDTSK+L FxOA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=zWzbMUPsc+COfk6VxjdgdreLVBAMHSHonemcCDUsp24=; b=f05meYEJUsAMm2QD/HCVxA23ngzUuaI0NCF4b97ITS7EaUe4ng2cPgBM/7bMbhdLEt MSyOMnbc7d3C6295aHxwo4vkaybeuaIQRlN6Xg7U0+XgA6Rox58mQw3B+BiLNIvDjBzE G1PWGjEJYjS1C3SVSOAZANa8Rw4Hzyny7NOdkl4LeNDYIgqkdLdy0yB793hJ7RlcMTho PsGzwrkLsNGaHjs9tuNg9IQXxWZ4t6NoNKfcW/NZMxEtR8pxEBaBN615Qg5HrunDnF3g 78VGCqljnn547fH4V44jwkS/JDUcCW8mBNyiPGD1jTy0KFU95hLkaxRQYIqg65YwG2gA IaxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xkJEMj7o; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q3si11769018plb.209.2019.01.28.09.15.53; Mon, 28 Jan 2019 09:16:09 -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=xkJEMj7o; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732128AbfA1QHB (ORCPT + 99 others); Mon, 28 Jan 2019 11:07:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:56874 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732111AbfA1QG7 (ORCPT ); Mon, 28 Jan 2019 11:06:59 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id F3D4F21738; Mon, 28 Jan 2019 16:06:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548691618; bh=L72q0sXFpHqz3P0a9KMLYZwWjigbUy86A70gzUvyUb0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xkJEMj7o+6y3UNX7Et2hdfKFfQX4NtXFDVXGdWwzQ7mc0nkU0jEkMMF00ycnR90bG ZORLfPgMcP4bLJ3FhSwJNwhY1e7LLx1fJlYK/gteg4b0UJBkOISGpnMXuvdLzAaP74 Cjhs/8nGxdv8ScCy5AmN+bBs/tge5hAxkAp1Wxtw= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: David Sterba , Sasha Levin , linux-btrfs@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 161/258] btrfs: reada: reorder dev-replace locks before radix tree preload Date: Mon, 28 Jan 2019 10:57:47 -0500 Message-Id: <20190128155924.51521-161-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190128155924.51521-1-sashal@kernel.org> References: <20190128155924.51521-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Sterba [ Upstream commit ceb21a8db48559fd0809e03c4df9eb37743d9170 ] The device-replace read lock is going to use rw semaphore in followup commits. The semaphore might sleep which is not possible in the radix tree preload section. The lock nesting is now: * device replace * radix tree preload * readahead spinlock Signed-off-by: David Sterba Signed-off-by: Sasha Levin --- fs/btrfs/reada.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/reada.c b/fs/btrfs/reada.c index dec14b739b10..6f81f3e88b6d 100644 --- a/fs/btrfs/reada.c +++ b/fs/btrfs/reada.c @@ -376,26 +376,28 @@ static struct reada_extent *reada_find_extent(struct btrfs_fs_info *fs_info, goto error; } + /* Insert extent in reada tree + all per-device trees, all or nothing */ + btrfs_dev_replace_read_lock(&fs_info->dev_replace); ret = radix_tree_preload(GFP_KERNEL); - if (ret) + if (ret) { + btrfs_dev_replace_read_unlock(&fs_info->dev_replace); goto error; + } - /* insert extent in reada_tree + all per-device trees, all or nothing */ - btrfs_dev_replace_read_lock(&fs_info->dev_replace); spin_lock(&fs_info->reada_lock); ret = radix_tree_insert(&fs_info->reada_tree, index, re); if (ret == -EEXIST) { re_exist = radix_tree_lookup(&fs_info->reada_tree, index); re_exist->refcnt++; spin_unlock(&fs_info->reada_lock); - btrfs_dev_replace_read_unlock(&fs_info->dev_replace); radix_tree_preload_end(); + btrfs_dev_replace_read_unlock(&fs_info->dev_replace); goto error; } if (ret) { spin_unlock(&fs_info->reada_lock); - btrfs_dev_replace_read_unlock(&fs_info->dev_replace); radix_tree_preload_end(); + btrfs_dev_replace_read_unlock(&fs_info->dev_replace); goto error; } radix_tree_preload_end(); -- 2.19.1