From: "Liam R. Howlett" <Liam.Howlett@oracle.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: maple-tree@lists.infradead.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org,
"Liam R. Howlett" <Liam.Howlett@Oracle.com>,
syzbot+036af2f0c7338a33b0cd@syzkaller.appspotmail.com
Subject: [PATCH] maple_tree: Remove rcu_read_lock() from mt_validate()
Date: Tue, 20 Aug 2024 13:54:17 -0400 [thread overview]
Message-ID: <20240820175417.2782532-1-Liam.Howlett@oracle.com> (raw)
From: "Liam R. Howlett" <Liam.Howlett@Oracle.com>
The write lock should be held when validating the tree to avoid updates
racing with checks. Holding the rcu read lock during a large tree
validation may also cause a prolonged rcu read window.
Link: https://lore.kernel.org/all/0000000000001d12d4062005aea1@google.com/
Fixes: 54a611b60590 ("Maple Tree: add new data structure")
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
Reported-by: syzbot+036af2f0c7338a33b0cd@syzkaller.appspotmail.com
---
lib/maple_tree.c | 7 ++-----
1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/lib/maple_tree.c b/lib/maple_tree.c
index 755ba8b18e14..fe1b01b29201 100644
--- a/lib/maple_tree.c
+++ b/lib/maple_tree.c
@@ -7588,14 +7588,14 @@ static void mt_validate_nulls(struct maple_tree *mt)
* 2. The gap is correctly set in the parents
*/
void mt_validate(struct maple_tree *mt)
+ __must_hold(mas->tree->ma_lock)
{
unsigned char end;
MA_STATE(mas, mt, 0, 0);
- rcu_read_lock();
mas_start(&mas);
if (!mas_is_active(&mas))
- goto done;
+ return;
while (!mte_is_leaf(mas.node))
mas_descend(&mas);
@@ -7616,9 +7616,6 @@ void mt_validate(struct maple_tree *mt)
mas_dfs_postorder(&mas, ULONG_MAX);
}
mt_validate_nulls(mt);
-done:
- rcu_read_unlock();
-
}
EXPORT_SYMBOL_GPL(mt_validate);
--
2.43.0
WARNING: multiple messages have this Message-ID
From: Hillf Danton <hdanton@sina.com>
To: "Liam R. Howlett" <Liam.Howlett@oracle.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
maple-tree@lists.infradead.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org,
"Paul E. McKenney" <paulmck@kernel.org>,
"Liam R. Howlett" <Liam.Howlett@Oracle.com>,
syzbot+036af2f0c7338a33b0cd@syzkaller.appspotmail.com
Subject: Re: [PATCH] maple_tree: Remove rcu_read_lock() from mt_validate()
Date: Wed, 21 Aug 2024 06:38:45 +0800 [thread overview]
Message-ID: <20240820175417.2782532-1-Liam.Howlett@oracle.com> (raw)
Message-ID: <20240820223845.pfNZ8kTk3qagu7kMVy4sJ8_nUCP26ftd3w4BSSQDgHc@z> (raw)
On Tue, 20 Aug 2024 13:54:17 -0400 "Liam R. Howlett" <Liam.Howlett@Oracle.com>
>
> The write lock should be held when validating the tree to avoid updates
> racing with checks. Holding the rcu read lock during a large tree
> validation may also cause a prolonged rcu read window.
>
From the rcu stall's view, holding spin lock plays the same role of rcu
read lock, so what are you fixing by simply dropping rcu read lock?
> Link: https://lore.kernel.org/all/0000000000001d12d4062005aea1@google.com/
> Fixes: 54a611b60590 ("Maple Tree: add new data structure")
> Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
> Reported-by: syzbot+036af2f0c7338a33b0cd@syzkaller.appspotmail.com
> ---
> lib/maple_tree.c | 7 ++-----
> 1 file changed, 2 insertions(+), 5 deletions(-)
>
> diff --git a/lib/maple_tree.c b/lib/maple_tree.c
> index 755ba8b18e14..fe1b01b29201 100644
> --- a/lib/maple_tree.c
> +++ b/lib/maple_tree.c
> @@ -7588,14 +7588,14 @@ static void mt_validate_nulls(struct maple_tree *mt)
> * 2. The gap is correctly set in the parents
> */
> void mt_validate(struct maple_tree *mt)
> + __must_hold(mas->tree->ma_lock)
> {
> unsigned char end;
>
lockdep_assert_held(ma_lock); instead
> MA_STATE(mas, mt, 0, 0);
> - rcu_read_lock();
> mas_start(&mas);
> if (!mas_is_active(&mas))
> - goto done;
> + return;
>
> while (!mte_is_leaf(mas.node))
> mas_descend(&mas);
> @@ -7616,9 +7616,6 @@ void mt_validate(struct maple_tree *mt)
> mas_dfs_postorder(&mas, ULONG_MAX);
> }
> mt_validate_nulls(mt);
> -done:
> - rcu_read_unlock();
> -
> }
> EXPORT_SYMBOL_GPL(mt_validate);
>
> --
> 2.43.0
next reply other threads:[~2024-08-20 17:54 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-20 17:54 Liam R. Howlett [this message]
2024-08-20 22:38 ` Hillf Danton
2024-08-20 22:53 ` Matthew Wilcox
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240820175417.2782532-1-Liam.Howlett@oracle.com \
--to=liam.howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=maple-tree@lists.infradead.org \
--cc=syzbot+036af2f0c7338a33b0cd@syzkaller.appspotmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox