Skip to content

Commit

Permalink
test_xarray: fix failure in check_pause when CONFIG_XARRAY_MULTI is n…
Browse files Browse the repository at this point in the history
…ot defined

In case CONFIG_XARRAY_MULTI is not defined, xa_store_order can store a
multi-index entry but xas_for_each can't tell sbiling entry from valid
entry.  So the check_pause failed when we store a multi-index entry and
wish xas_for_each can handle it normally.  Avoid to store multi-index
entry when CONFIG_XARRAY_MULTI is disabled to fix the failure.

Link: https://lkml.kernel.org/r/[email protected]
Fixes: c9ba524 ("Xarray: move forward index correctly in xas_pause()")
Signed-off-by: Kemeng Shi <[email protected]>
Reported-by: Geert Uytterhoeven <[email protected]>
Closes: https://lore.kernel.org/r/CAMuHMdU_bfadUO=0OZ=AoQ9EAmQPA4wsLCBqohXR+QCeCKRn4A@mail.gmail.com
Tested-by: Geert Uytterhoeven <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
Kemeng Shi authored and akpm00 committed Feb 18, 2025
1 parent ac7af1f commit 8344017
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/test_xarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -1418,7 +1418,7 @@ static noinline void check_pause(struct xarray *xa)
{
XA_STATE(xas, xa, 0);
void *entry;
unsigned int order;
int order;
unsigned long index = 1;
unsigned int count = 0;

Expand Down Expand Up @@ -1450,7 +1450,7 @@ static noinline void check_pause(struct xarray *xa)
xa_destroy(xa);

index = 0;
for (order = XA_CHUNK_SHIFT; order > 0; order--) {
for (order = order_limit - 1; order >= 0; order--) {
XA_BUG_ON(xa, xa_store_order(xa, index, order,
xa_mk_index(index), GFP_KERNEL));
index += 1UL << order;
Expand All @@ -1462,24 +1462,25 @@ static noinline void check_pause(struct xarray *xa)
rcu_read_lock();
xas_for_each(&xas, entry, ULONG_MAX) {
XA_BUG_ON(xa, entry != xa_mk_index(index));
index += 1UL << (XA_CHUNK_SHIFT - count);
index += 1UL << (order_limit - count - 1);
count++;
}
rcu_read_unlock();
XA_BUG_ON(xa, count != XA_CHUNK_SHIFT);
XA_BUG_ON(xa, count != order_limit);

index = 0;
count = 0;
xas_set(&xas, XA_CHUNK_SIZE / 2 + 1);
/* test unaligned index */
xas_set(&xas, 1 % (1UL << (order_limit - 1)));
rcu_read_lock();
xas_for_each(&xas, entry, ULONG_MAX) {
XA_BUG_ON(xa, entry != xa_mk_index(index));
index += 1UL << (XA_CHUNK_SHIFT - count);
index += 1UL << (order_limit - count - 1);
count++;
xas_pause(&xas);
}
rcu_read_unlock();
XA_BUG_ON(xa, count != XA_CHUNK_SHIFT);
XA_BUG_ON(xa, count != order_limit);

xa_destroy(xa);

Expand Down

0 comments on commit 8344017

Please sign in to comment.