Skip to content

Commit 2aaba39

Browse files
mcgrofakpm00
authored andcommitted
lib/test_xarray.c: fix error assumptions on check_xa_multi_store_adv_add()
While testing lib/test_xarray in userspace I've noticed we can fail with: make -C tools/testing/radix-tree ./tools/testing/radix-tree/xarray BUG at check_xa_multi_store_adv_add:749 xarray: 0x55905fb21a00x head 0x55905fa1d8e0x flags 0 marks 0 0 0 0: 0x55905fa1d8e0x xarray: ../../../lib/test_xarray.c:749: check_xa_multi_store_adv_add: Assertion `0' failed. Aborted We get a failure with a BUG_ON(), and that is because we actually can fail due to -ENOMEM, the check in xas_nomem() will fix this for us so it makes no sense to expect no failure inside the loop. So modify the check and since this is also useful for instructional purposes clarify the situation. The check for XA_BUG_ON(xa, xa_load(xa, index) != p) is already done at the end of the loop so just remove the bogus on inside the loop. With this we now pass the test in both kernel and userspace: In userspace: ./tools/testing/radix-tree/xarray XArray: 149092856 of 149092856 tests passed In kernel space: XArray: 148257077 of 148257077 tests passed Link: https://lkml.kernel.org/r/20240423192221.301095-3-mcgrof@kernel.org Fixes: a60cc28 ("test_xarray: add tests for advanced multi-index use") Signed-off-by: Luis Chamberlain <mcgrof@kernel.org> Cc: Daniel Gomez <da.gomez@samsung.com> Cc: Darrick J. Wong <djwong@kernel.org> Cc: Dave Chinner <david@fromorbit.com> Cc: "Liam R. Howlett" <Liam.Howlett@oracle.com> Cc: Matthew Wilcox (Oracle) <willy@infradead.org> Cc: Pankaj Raghav <p.raghav@samsung.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
1 parent a7575bc commit 2aaba39

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

lib/test_xarray.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -744,15 +744,20 @@ static noinline void check_xa_multi_store_adv_add(struct xarray *xa,
744744

745745
do {
746746
xas_lock_irq(&xas);
747-
748747
xas_store(&xas, p);
749-
XA_BUG_ON(xa, xas_error(&xas));
750-
XA_BUG_ON(xa, xa_load(xa, index) != p);
751-
752748
xas_unlock_irq(&xas);
749+
/*
750+
* In our selftest case the only failure we can expect is for
751+
* there not to be enough memory as we're not mimicking the
752+
* entire page cache, so verify that's the only error we can run
753+
* into here. The xas_nomem() which follows will ensure to fix
754+
* that condition for us so to chug on on the loop.
755+
*/
756+
XA_BUG_ON(xa, xas_error(&xas) && xas_error(&xas) != -ENOMEM);
753757
} while (xas_nomem(&xas, GFP_KERNEL));
754758

755759
XA_BUG_ON(xa, xas_error(&xas));
760+
XA_BUG_ON(xa, xa_load(xa, index) != p);
756761
}
757762

758763
/* mimics page_cache_delete() */

0 commit comments

Comments
 (0)