Skip to content

Commit e777ae4

Browse files
dkrucesakpm00
authored andcommitted
XArray: add cmpxchg order test
XArray multi-index entries do not keep track of the order stored once the entry is being marked as used with cmpxchg (conditionally replaced with NULL). Add a test to check the order is actually lost. The test also verifies the order and entries for all the tied indexes before and after the NULL replacement with xa_cmpxchg. Add another entry at 1 << order that keeps the node around and the order information for the NULL-entry after xa_cmpxchg. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Daniel Gomez <[email protected]> Signed-off-by: Luis Chamberlain <[email protected]> Cc: Darrick J. Wong <[email protected]> Cc: Dave Chinner <[email protected]> Cc: Hannes Reinecke <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Pankaj Raghav <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent a60cc28 commit e777ae4

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

lib/test_xarray.c

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,59 @@ static noinline void check_cmpxchg(struct xarray *xa)
423423
XA_BUG_ON(xa, !xa_empty(xa));
424424
}
425425

426+
static noinline void check_cmpxchg_order(struct xarray *xa)
427+
{
428+
#ifdef CONFIG_XARRAY_MULTI
429+
void *FIVE = xa_mk_value(5);
430+
unsigned int i, order = 3;
431+
432+
XA_BUG_ON(xa, xa_store_order(xa, 0, order, FIVE, GFP_KERNEL));
433+
434+
/* Check entry FIVE has the order saved */
435+
XA_BUG_ON(xa, xa_get_order(xa, xa_to_value(FIVE)) != order);
436+
437+
/* Check all the tied indexes have the same entry and order */
438+
for (i = 0; i < (1 << order); i++) {
439+
XA_BUG_ON(xa, xa_load(xa, i) != FIVE);
440+
XA_BUG_ON(xa, xa_get_order(xa, i) != order);
441+
}
442+
443+
/* Ensure that nothing is stored at index '1 << order' */
444+
XA_BUG_ON(xa, xa_load(xa, 1 << order) != NULL);
445+
446+
/*
447+
* Additionally, keep the node information and the order at
448+
* '1 << order'
449+
*/
450+
XA_BUG_ON(xa, xa_store_order(xa, 1 << order, order, FIVE, GFP_KERNEL));
451+
for (i = (1 << order); i < (1 << order) + (1 << order) - 1; i++) {
452+
XA_BUG_ON(xa, xa_load(xa, i) != FIVE);
453+
XA_BUG_ON(xa, xa_get_order(xa, i) != order);
454+
}
455+
456+
/* Conditionally replace FIVE entry at index '0' with NULL */
457+
XA_BUG_ON(xa, xa_cmpxchg(xa, 0, FIVE, NULL, GFP_KERNEL) != FIVE);
458+
459+
/* Verify the order is lost at FIVE (and old) entries */
460+
XA_BUG_ON(xa, xa_get_order(xa, xa_to_value(FIVE)) != 0);
461+
462+
/* Verify the order and entries are lost in all the tied indexes */
463+
for (i = 0; i < (1 << order); i++) {
464+
XA_BUG_ON(xa, xa_load(xa, i) != NULL);
465+
XA_BUG_ON(xa, xa_get_order(xa, i) != 0);
466+
}
467+
468+
/* Verify node and order are kept at '1 << order' */
469+
for (i = (1 << order); i < (1 << order) + (1 << order) - 1; i++) {
470+
XA_BUG_ON(xa, xa_load(xa, i) != FIVE);
471+
XA_BUG_ON(xa, xa_get_order(xa, i) != order);
472+
}
473+
474+
xa_store_order(xa, 0, BITS_PER_LONG - 1, NULL, GFP_KERNEL);
475+
XA_BUG_ON(xa, !xa_empty(xa));
476+
#endif
477+
}
478+
426479
static noinline void check_reserve(struct xarray *xa)
427480
{
428481
void *entry;
@@ -1976,6 +2029,7 @@ static int xarray_checks(void)
19762029
check_xas_erase(&array);
19772030
check_insert(&array);
19782031
check_cmpxchg(&array);
2032+
check_cmpxchg_order(&array);
19792033
check_reserve(&array);
19802034
check_reserve(&xa0);
19812035
check_multi_store(&array);

0 commit comments

Comments
 (0)