XArray: Do not return sibling entries from xa_load()
authorMatthew Wilcox (Oracle) <willy@infradead.org>
Thu, 27 Jul 2023 02:58:17 +0000 (22:58 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 13 Sep 2023 07:43:00 +0000 (09:43 +0200)
commit4a3e0d51c3e10ef699fc201542593f4bbcd39fd3
tree6e6b477884002dd919facaec4cc9de16c8c2c5e3
parent7a7f11283392311741a5399672fd2657c7c6ff01
XArray: Do not return sibling entries from xa_load()

commit cbc02854331edc6dc22d8b77b6e22e38ebc7dd51 upstream.

It is possible for xa_load() to observe a sibling entry pointing to
another sibling entry.  An example:

Thread A: Thread B:
xa_store_range(xa, entry, 188, 191, gfp);
xa_load(xa, 191);
entry = xa_entry(xa, node, 63);
[entry is a sibling of 188]
xa_store_range(xa, entry, 184, 191, gfp);
if (xa_is_sibling(entry))
offset = xa_to_sibling(entry);
entry = xa_entry(xas->xa, node, offset);
[entry is now a sibling of 184]

It is sufficient to go around this loop until we hit a non-sibling entry.
Sibling entries always point earlier in the node, so we are guaranteed
to terminate this search.

Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Fixes: 6b24ca4a1a8d ("mm: Use multi-index entries in the page cache")
Cc: stable@vger.kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
lib/xarray.c
tools/testing/radix-tree/multiorder.c