diff options
Diffstat (limited to 'lib/test_xarray.c')
-rw-r--r-- | lib/test_xarray.c | 203 |
1 files changed, 158 insertions, 45 deletions
diff --git a/lib/test_xarray.c b/lib/test_xarray.c index aa47754150ce..4676c0a1eeca 100644 --- a/lib/test_xarray.c +++ b/lib/test_xarray.c | |||
@@ -28,23 +28,28 @@ void xa_dump(const struct xarray *xa) { } | |||
28 | } while (0) | 28 | } while (0) |
29 | #endif | 29 | #endif |
30 | 30 | ||
31 | static void *xa_mk_index(unsigned long index) | ||
32 | { | ||
33 | return xa_mk_value(index & LONG_MAX); | ||
34 | } | ||
35 | |||
31 | static void *xa_store_index(struct xarray *xa, unsigned long index, gfp_t gfp) | 36 | static void *xa_store_index(struct xarray *xa, unsigned long index, gfp_t gfp) |
32 | { | 37 | { |
33 | return xa_store(xa, index, xa_mk_value(index & LONG_MAX), gfp); | 38 | return xa_store(xa, index, xa_mk_index(index), gfp); |
34 | } | 39 | } |
35 | 40 | ||
36 | static void xa_alloc_index(struct xarray *xa, unsigned long index, gfp_t gfp) | 41 | static void xa_alloc_index(struct xarray *xa, unsigned long index, gfp_t gfp) |
37 | { | 42 | { |
38 | u32 id = 0; | 43 | u32 id = 0; |
39 | 44 | ||
40 | XA_BUG_ON(xa, xa_alloc(xa, &id, UINT_MAX, xa_mk_value(index & LONG_MAX), | 45 | XA_BUG_ON(xa, xa_alloc(xa, &id, UINT_MAX, xa_mk_index(index), |
41 | gfp) != 0); | 46 | gfp) != 0); |
42 | XA_BUG_ON(xa, id != index); | 47 | XA_BUG_ON(xa, id != index); |
43 | } | 48 | } |
44 | 49 | ||
45 | static void xa_erase_index(struct xarray *xa, unsigned long index) | 50 | static void xa_erase_index(struct xarray *xa, unsigned long index) |
46 | { | 51 | { |
47 | XA_BUG_ON(xa, xa_erase(xa, index) != xa_mk_value(index & LONG_MAX)); | 52 | XA_BUG_ON(xa, xa_erase(xa, index) != xa_mk_index(index)); |
48 | XA_BUG_ON(xa, xa_load(xa, index) != NULL); | 53 | XA_BUG_ON(xa, xa_load(xa, index) != NULL); |
49 | } | 54 | } |
50 | 55 | ||
@@ -118,7 +123,7 @@ static noinline void check_xas_retry(struct xarray *xa) | |||
118 | 123 | ||
119 | xas_set(&xas, 0); | 124 | xas_set(&xas, 0); |
120 | xas_for_each(&xas, entry, ULONG_MAX) { | 125 | xas_for_each(&xas, entry, ULONG_MAX) { |
121 | xas_store(&xas, xa_mk_value(xas.xa_index)); | 126 | xas_store(&xas, xa_mk_index(xas.xa_index)); |
122 | } | 127 | } |
123 | xas_unlock(&xas); | 128 | xas_unlock(&xas); |
124 | 129 | ||
@@ -196,7 +201,7 @@ static noinline void check_xa_mark_1(struct xarray *xa, unsigned long index) | |||
196 | XA_BUG_ON(xa, xa_store_index(xa, index + 2, GFP_KERNEL)); | 201 | XA_BUG_ON(xa, xa_store_index(xa, index + 2, GFP_KERNEL)); |
197 | xa_set_mark(xa, index + 2, XA_MARK_1); | 202 | xa_set_mark(xa, index + 2, XA_MARK_1); |
198 | XA_BUG_ON(xa, xa_store_index(xa, next, GFP_KERNEL)); | 203 | XA_BUG_ON(xa, xa_store_index(xa, next, GFP_KERNEL)); |
199 | xa_store_order(xa, index, order, xa_mk_value(index), | 204 | xa_store_order(xa, index, order, xa_mk_index(index), |
200 | GFP_KERNEL); | 205 | GFP_KERNEL); |
201 | for (i = base; i < next; i++) { | 206 | for (i = base; i < next; i++) { |
202 | XA_STATE(xas, xa, i); | 207 | XA_STATE(xas, xa, i); |
@@ -208,15 +213,19 @@ static noinline void check_xa_mark_1(struct xarray *xa, unsigned long index) | |||
208 | XA_BUG_ON(xa, xa_get_mark(xa, i, XA_MARK_2)); | 213 | XA_BUG_ON(xa, xa_get_mark(xa, i, XA_MARK_2)); |
209 | 214 | ||
210 | /* We should see two elements in the array */ | 215 | /* We should see two elements in the array */ |
216 | rcu_read_lock(); | ||
211 | xas_for_each(&xas, entry, ULONG_MAX) | 217 | xas_for_each(&xas, entry, ULONG_MAX) |
212 | seen++; | 218 | seen++; |
219 | rcu_read_unlock(); | ||
213 | XA_BUG_ON(xa, seen != 2); | 220 | XA_BUG_ON(xa, seen != 2); |
214 | 221 | ||
215 | /* One of which is marked */ | 222 | /* One of which is marked */ |
216 | xas_set(&xas, 0); | 223 | xas_set(&xas, 0); |
217 | seen = 0; | 224 | seen = 0; |
225 | rcu_read_lock(); | ||
218 | xas_for_each_marked(&xas, entry, ULONG_MAX, XA_MARK_0) | 226 | xas_for_each_marked(&xas, entry, ULONG_MAX, XA_MARK_0) |
219 | seen++; | 227 | seen++; |
228 | rcu_read_unlock(); | ||
220 | XA_BUG_ON(xa, seen != 1); | 229 | XA_BUG_ON(xa, seen != 1); |
221 | } | 230 | } |
222 | XA_BUG_ON(xa, xa_get_mark(xa, next, XA_MARK_0)); | 231 | XA_BUG_ON(xa, xa_get_mark(xa, next, XA_MARK_0)); |
@@ -373,6 +382,12 @@ static noinline void check_reserve(struct xarray *xa) | |||
373 | xa_erase_index(xa, 12345678); | 382 | xa_erase_index(xa, 12345678); |
374 | XA_BUG_ON(xa, !xa_empty(xa)); | 383 | XA_BUG_ON(xa, !xa_empty(xa)); |
375 | 384 | ||
385 | /* And so does xa_insert */ | ||
386 | xa_reserve(xa, 12345678, GFP_KERNEL); | ||
387 | XA_BUG_ON(xa, xa_insert(xa, 12345678, xa_mk_value(12345678), 0) != 0); | ||
388 | xa_erase_index(xa, 12345678); | ||
389 | XA_BUG_ON(xa, !xa_empty(xa)); | ||
390 | |||
376 | /* Can iterate through a reserved entry */ | 391 | /* Can iterate through a reserved entry */ |
377 | xa_store_index(xa, 5, GFP_KERNEL); | 392 | xa_store_index(xa, 5, GFP_KERNEL); |
378 | xa_reserve(xa, 6, GFP_KERNEL); | 393 | xa_reserve(xa, 6, GFP_KERNEL); |
@@ -395,7 +410,7 @@ static noinline void check_xas_erase(struct xarray *xa) | |||
395 | xas_set(&xas, j); | 410 | xas_set(&xas, j); |
396 | do { | 411 | do { |
397 | xas_lock(&xas); | 412 | xas_lock(&xas); |
398 | xas_store(&xas, xa_mk_value(j)); | 413 | xas_store(&xas, xa_mk_index(j)); |
399 | xas_unlock(&xas); | 414 | xas_unlock(&xas); |
400 | } while (xas_nomem(&xas, GFP_KERNEL)); | 415 | } while (xas_nomem(&xas, GFP_KERNEL)); |
401 | } | 416 | } |
@@ -413,7 +428,7 @@ static noinline void check_xas_erase(struct xarray *xa) | |||
413 | xas_set(&xas, 0); | 428 | xas_set(&xas, 0); |
414 | j = i; | 429 | j = i; |
415 | xas_for_each(&xas, entry, ULONG_MAX) { | 430 | xas_for_each(&xas, entry, ULONG_MAX) { |
416 | XA_BUG_ON(xa, entry != xa_mk_value(j)); | 431 | XA_BUG_ON(xa, entry != xa_mk_index(j)); |
417 | xas_store(&xas, NULL); | 432 | xas_store(&xas, NULL); |
418 | j++; | 433 | j++; |
419 | } | 434 | } |
@@ -430,15 +445,17 @@ static noinline void check_multi_store_1(struct xarray *xa, unsigned long index, | |||
430 | unsigned long min = index & ~((1UL << order) - 1); | 445 | unsigned long min = index & ~((1UL << order) - 1); |
431 | unsigned long max = min + (1UL << order); | 446 | unsigned long max = min + (1UL << order); |
432 | 447 | ||
433 | xa_store_order(xa, index, order, xa_mk_value(index), GFP_KERNEL); | 448 | xa_store_order(xa, index, order, xa_mk_index(index), GFP_KERNEL); |
434 | XA_BUG_ON(xa, xa_load(xa, min) != xa_mk_value(index)); | 449 | XA_BUG_ON(xa, xa_load(xa, min) != xa_mk_index(index)); |
435 | XA_BUG_ON(xa, xa_load(xa, max - 1) != xa_mk_value(index)); | 450 | XA_BUG_ON(xa, xa_load(xa, max - 1) != xa_mk_index(index)); |
436 | XA_BUG_ON(xa, xa_load(xa, max) != NULL); | 451 | XA_BUG_ON(xa, xa_load(xa, max) != NULL); |
437 | XA_BUG_ON(xa, xa_load(xa, min - 1) != NULL); | 452 | XA_BUG_ON(xa, xa_load(xa, min - 1) != NULL); |
438 | 453 | ||
439 | XA_BUG_ON(xa, xas_store(&xas, xa_mk_value(min)) != xa_mk_value(index)); | 454 | xas_lock(&xas); |
440 | XA_BUG_ON(xa, xa_load(xa, min) != xa_mk_value(min)); | 455 | XA_BUG_ON(xa, xas_store(&xas, xa_mk_index(min)) != xa_mk_index(index)); |
441 | XA_BUG_ON(xa, xa_load(xa, max - 1) != xa_mk_value(min)); | 456 | xas_unlock(&xas); |
457 | XA_BUG_ON(xa, xa_load(xa, min) != xa_mk_index(min)); | ||
458 | XA_BUG_ON(xa, xa_load(xa, max - 1) != xa_mk_index(min)); | ||
442 | XA_BUG_ON(xa, xa_load(xa, max) != NULL); | 459 | XA_BUG_ON(xa, xa_load(xa, max) != NULL); |
443 | XA_BUG_ON(xa, xa_load(xa, min - 1) != NULL); | 460 | XA_BUG_ON(xa, xa_load(xa, min - 1) != NULL); |
444 | 461 | ||
@@ -452,11 +469,39 @@ static noinline void check_multi_store_2(struct xarray *xa, unsigned long index, | |||
452 | XA_STATE(xas, xa, index); | 469 | XA_STATE(xas, xa, index); |
453 | xa_store_order(xa, index, order, xa_mk_value(0), GFP_KERNEL); | 470 | xa_store_order(xa, index, order, xa_mk_value(0), GFP_KERNEL); |
454 | 471 | ||
472 | xas_lock(&xas); | ||
455 | XA_BUG_ON(xa, xas_store(&xas, xa_mk_value(1)) != xa_mk_value(0)); | 473 | XA_BUG_ON(xa, xas_store(&xas, xa_mk_value(1)) != xa_mk_value(0)); |
456 | XA_BUG_ON(xa, xas.xa_index != index); | 474 | XA_BUG_ON(xa, xas.xa_index != index); |
457 | XA_BUG_ON(xa, xas_store(&xas, NULL) != xa_mk_value(1)); | 475 | XA_BUG_ON(xa, xas_store(&xas, NULL) != xa_mk_value(1)); |
476 | xas_unlock(&xas); | ||
458 | XA_BUG_ON(xa, !xa_empty(xa)); | 477 | XA_BUG_ON(xa, !xa_empty(xa)); |
459 | } | 478 | } |
479 | |||
480 | static noinline void check_multi_store_3(struct xarray *xa, unsigned long index, | ||
481 | unsigned int order) | ||
482 | { | ||
483 | XA_STATE(xas, xa, 0); | ||
484 | void *entry; | ||
485 | int n = 0; | ||
486 | |||
487 | xa_store_order(xa, index, order, xa_mk_index(index), GFP_KERNEL); | ||
488 | |||
489 | xas_lock(&xas); | ||
490 | xas_for_each(&xas, entry, ULONG_MAX) { | ||
491 | XA_BUG_ON(xa, entry != xa_mk_index(index)); | ||
492 | n++; | ||
493 | } | ||
494 | XA_BUG_ON(xa, n != 1); | ||
495 | xas_set(&xas, index + 1); | ||
496 | xas_for_each(&xas, entry, ULONG_MAX) { | ||
497 | XA_BUG_ON(xa, entry != xa_mk_index(index)); | ||
498 | n++; | ||
499 | } | ||
500 | XA_BUG_ON(xa, n != 2); | ||
501 | xas_unlock(&xas); | ||
502 | |||
503 | xa_destroy(xa); | ||
504 | } | ||
460 | #endif | 505 | #endif |
461 | 506 | ||
462 | static noinline void check_multi_store(struct xarray *xa) | 507 | static noinline void check_multi_store(struct xarray *xa) |
@@ -498,7 +543,7 @@ static noinline void check_multi_store(struct xarray *xa) | |||
498 | rcu_read_unlock(); | 543 | rcu_read_unlock(); |
499 | 544 | ||
500 | /* We can erase multiple values with a single store */ | 545 | /* We can erase multiple values with a single store */ |
501 | xa_store_order(xa, 0, 63, NULL, GFP_KERNEL); | 546 | xa_store_order(xa, 0, BITS_PER_LONG - 1, NULL, GFP_KERNEL); |
502 | XA_BUG_ON(xa, !xa_empty(xa)); | 547 | XA_BUG_ON(xa, !xa_empty(xa)); |
503 | 548 | ||
504 | /* Even when the first slot is empty but the others aren't */ | 549 | /* Even when the first slot is empty but the others aren't */ |
@@ -509,15 +554,15 @@ static noinline void check_multi_store(struct xarray *xa) | |||
509 | 554 | ||
510 | for (i = 0; i < max_order; i++) { | 555 | for (i = 0; i < max_order; i++) { |
511 | for (j = 0; j < max_order; j++) { | 556 | for (j = 0; j < max_order; j++) { |
512 | xa_store_order(xa, 0, i, xa_mk_value(i), GFP_KERNEL); | 557 | xa_store_order(xa, 0, i, xa_mk_index(i), GFP_KERNEL); |
513 | xa_store_order(xa, 0, j, xa_mk_value(j), GFP_KERNEL); | 558 | xa_store_order(xa, 0, j, xa_mk_index(j), GFP_KERNEL); |
514 | 559 | ||
515 | for (k = 0; k < max_order; k++) { | 560 | for (k = 0; k < max_order; k++) { |
516 | void *entry = xa_load(xa, (1UL << k) - 1); | 561 | void *entry = xa_load(xa, (1UL << k) - 1); |
517 | if ((i < k) && (j < k)) | 562 | if ((i < k) && (j < k)) |
518 | XA_BUG_ON(xa, entry != NULL); | 563 | XA_BUG_ON(xa, entry != NULL); |
519 | else | 564 | else |
520 | XA_BUG_ON(xa, entry != xa_mk_value(j)); | 565 | XA_BUG_ON(xa, entry != xa_mk_index(j)); |
521 | } | 566 | } |
522 | 567 | ||
523 | xa_erase(xa, 0); | 568 | xa_erase(xa, 0); |
@@ -531,6 +576,11 @@ static noinline void check_multi_store(struct xarray *xa) | |||
531 | check_multi_store_1(xa, (1UL << i) + 1, i); | 576 | check_multi_store_1(xa, (1UL << i) + 1, i); |
532 | } | 577 | } |
533 | check_multi_store_2(xa, 4095, 9); | 578 | check_multi_store_2(xa, 4095, 9); |
579 | |||
580 | for (i = 1; i < 20; i++) { | ||
581 | check_multi_store_3(xa, 0, i); | ||
582 | check_multi_store_3(xa, 1UL << i, i); | ||
583 | } | ||
534 | #endif | 584 | #endif |
535 | } | 585 | } |
536 | 586 | ||
@@ -573,16 +623,25 @@ static noinline void check_xa_alloc(void) | |||
573 | xa_destroy(&xa0); | 623 | xa_destroy(&xa0); |
574 | 624 | ||
575 | id = 0xfffffffeU; | 625 | id = 0xfffffffeU; |
576 | XA_BUG_ON(&xa0, xa_alloc(&xa0, &id, UINT_MAX, xa_mk_value(0), | 626 | XA_BUG_ON(&xa0, xa_alloc(&xa0, &id, UINT_MAX, xa_mk_index(id), |
577 | GFP_KERNEL) != 0); | 627 | GFP_KERNEL) != 0); |
578 | XA_BUG_ON(&xa0, id != 0xfffffffeU); | 628 | XA_BUG_ON(&xa0, id != 0xfffffffeU); |
579 | XA_BUG_ON(&xa0, xa_alloc(&xa0, &id, UINT_MAX, xa_mk_value(0), | 629 | XA_BUG_ON(&xa0, xa_alloc(&xa0, &id, UINT_MAX, xa_mk_index(id), |
580 | GFP_KERNEL) != 0); | 630 | GFP_KERNEL) != 0); |
581 | XA_BUG_ON(&xa0, id != 0xffffffffU); | 631 | XA_BUG_ON(&xa0, id != 0xffffffffU); |
582 | XA_BUG_ON(&xa0, xa_alloc(&xa0, &id, UINT_MAX, xa_mk_value(0), | 632 | XA_BUG_ON(&xa0, xa_alloc(&xa0, &id, UINT_MAX, xa_mk_index(id), |
583 | GFP_KERNEL) != -ENOSPC); | 633 | GFP_KERNEL) != -ENOSPC); |
584 | XA_BUG_ON(&xa0, id != 0xffffffffU); | 634 | XA_BUG_ON(&xa0, id != 0xffffffffU); |
585 | xa_destroy(&xa0); | 635 | xa_destroy(&xa0); |
636 | |||
637 | id = 10; | ||
638 | XA_BUG_ON(&xa0, xa_alloc(&xa0, &id, 5, xa_mk_index(id), | ||
639 | GFP_KERNEL) != -ENOSPC); | ||
640 | XA_BUG_ON(&xa0, xa_store_index(&xa0, 3, GFP_KERNEL) != 0); | ||
641 | XA_BUG_ON(&xa0, xa_alloc(&xa0, &id, 5, xa_mk_index(id), | ||
642 | GFP_KERNEL) != -ENOSPC); | ||
643 | xa_erase_index(&xa0, 3); | ||
644 | XA_BUG_ON(&xa0, !xa_empty(&xa0)); | ||
586 | } | 645 | } |
587 | 646 | ||
588 | static noinline void __check_store_iter(struct xarray *xa, unsigned long start, | 647 | static noinline void __check_store_iter(struct xarray *xa, unsigned long start, |
@@ -596,11 +655,11 @@ retry: | |||
596 | xas_lock(&xas); | 655 | xas_lock(&xas); |
597 | xas_for_each_conflict(&xas, entry) { | 656 | xas_for_each_conflict(&xas, entry) { |
598 | XA_BUG_ON(xa, !xa_is_value(entry)); | 657 | XA_BUG_ON(xa, !xa_is_value(entry)); |
599 | XA_BUG_ON(xa, entry < xa_mk_value(start)); | 658 | XA_BUG_ON(xa, entry < xa_mk_index(start)); |
600 | XA_BUG_ON(xa, entry > xa_mk_value(start + (1UL << order) - 1)); | 659 | XA_BUG_ON(xa, entry > xa_mk_index(start + (1UL << order) - 1)); |
601 | count++; | 660 | count++; |
602 | } | 661 | } |
603 | xas_store(&xas, xa_mk_value(start)); | 662 | xas_store(&xas, xa_mk_index(start)); |
604 | xas_unlock(&xas); | 663 | xas_unlock(&xas); |
605 | if (xas_nomem(&xas, GFP_KERNEL)) { | 664 | if (xas_nomem(&xas, GFP_KERNEL)) { |
606 | count = 0; | 665 | count = 0; |
@@ -608,9 +667,9 @@ retry: | |||
608 | } | 667 | } |
609 | XA_BUG_ON(xa, xas_error(&xas)); | 668 | XA_BUG_ON(xa, xas_error(&xas)); |
610 | XA_BUG_ON(xa, count != present); | 669 | XA_BUG_ON(xa, count != present); |
611 | XA_BUG_ON(xa, xa_load(xa, start) != xa_mk_value(start)); | 670 | XA_BUG_ON(xa, xa_load(xa, start) != xa_mk_index(start)); |
612 | XA_BUG_ON(xa, xa_load(xa, start + (1UL << order) - 1) != | 671 | XA_BUG_ON(xa, xa_load(xa, start + (1UL << order) - 1) != |
613 | xa_mk_value(start)); | 672 | xa_mk_index(start)); |
614 | xa_erase_index(xa, start); | 673 | xa_erase_index(xa, start); |
615 | } | 674 | } |
616 | 675 | ||
@@ -689,7 +748,7 @@ static noinline void check_multi_find_2(struct xarray *xa) | |||
689 | for (j = 0; j < index; j++) { | 748 | for (j = 0; j < index; j++) { |
690 | XA_STATE(xas, xa, j + index); | 749 | XA_STATE(xas, xa, j + index); |
691 | xa_store_index(xa, index - 1, GFP_KERNEL); | 750 | xa_store_index(xa, index - 1, GFP_KERNEL); |
692 | xa_store_order(xa, index, i, xa_mk_value(index), | 751 | xa_store_order(xa, index, i, xa_mk_index(index), |
693 | GFP_KERNEL); | 752 | GFP_KERNEL); |
694 | rcu_read_lock(); | 753 | rcu_read_lock(); |
695 | xas_for_each(&xas, entry, ULONG_MAX) { | 754 | xas_for_each(&xas, entry, ULONG_MAX) { |
@@ -702,7 +761,7 @@ static noinline void check_multi_find_2(struct xarray *xa) | |||
702 | } | 761 | } |
703 | } | 762 | } |
704 | 763 | ||
705 | static noinline void check_find(struct xarray *xa) | 764 | static noinline void check_find_1(struct xarray *xa) |
706 | { | 765 | { |
707 | unsigned long i, j, k; | 766 | unsigned long i, j, k; |
708 | 767 | ||
@@ -748,6 +807,58 @@ static noinline void check_find(struct xarray *xa) | |||
748 | XA_BUG_ON(xa, xa_get_mark(xa, i, XA_MARK_0)); | 807 | XA_BUG_ON(xa, xa_get_mark(xa, i, XA_MARK_0)); |
749 | } | 808 | } |
750 | XA_BUG_ON(xa, !xa_empty(xa)); | 809 | XA_BUG_ON(xa, !xa_empty(xa)); |
810 | } | ||
811 | |||
812 | static noinline void check_find_2(struct xarray *xa) | ||
813 | { | ||
814 | void *entry; | ||
815 | unsigned long i, j, index = 0; | ||
816 | |||
817 | xa_for_each(xa, entry, index, ULONG_MAX, XA_PRESENT) { | ||
818 | XA_BUG_ON(xa, true); | ||
819 | } | ||
820 | |||
821 | for (i = 0; i < 1024; i++) { | ||
822 | xa_store_index(xa, index, GFP_KERNEL); | ||
823 | j = 0; | ||
824 | index = 0; | ||
825 | xa_for_each(xa, entry, index, ULONG_MAX, XA_PRESENT) { | ||
826 | XA_BUG_ON(xa, xa_mk_index(index) != entry); | ||
827 | XA_BUG_ON(xa, index != j++); | ||
828 | } | ||
829 | } | ||
830 | |||
831 | xa_destroy(xa); | ||
832 | } | ||
833 | |||
834 | static noinline void check_find_3(struct xarray *xa) | ||
835 | { | ||
836 | XA_STATE(xas, xa, 0); | ||
837 | unsigned long i, j, k; | ||
838 | void *entry; | ||
839 | |||
840 | for (i = 0; i < 100; i++) { | ||
841 | for (j = 0; j < 100; j++) { | ||
842 | for (k = 0; k < 100; k++) { | ||
843 | xas_set(&xas, j); | ||
844 | xas_for_each_marked(&xas, entry, k, XA_MARK_0) | ||
845 | ; | ||
846 | if (j > k) | ||
847 | XA_BUG_ON(xa, | ||
848 | xas.xa_node != XAS_RESTART); | ||
849 | } | ||
850 | } | ||
851 | xa_store_index(xa, i, GFP_KERNEL); | ||
852 | xa_set_mark(xa, i, XA_MARK_0); | ||
853 | } | ||
854 | xa_destroy(xa); | ||
855 | } | ||
856 | |||
857 | static noinline void check_find(struct xarray *xa) | ||
858 | { | ||
859 | check_find_1(xa); | ||
860 | check_find_2(xa); | ||
861 | check_find_3(xa); | ||
751 | check_multi_find(xa); | 862 | check_multi_find(xa); |
752 | check_multi_find_2(xa); | 863 | check_multi_find_2(xa); |
753 | } | 864 | } |
@@ -787,11 +898,11 @@ static noinline void check_find_entry(struct xarray *xa) | |||
787 | for (index = 0; index < (1UL << (order + 5)); | 898 | for (index = 0; index < (1UL << (order + 5)); |
788 | index += (1UL << order)) { | 899 | index += (1UL << order)) { |
789 | xa_store_order(xa, index, order, | 900 | xa_store_order(xa, index, order, |
790 | xa_mk_value(index), GFP_KERNEL); | 901 | xa_mk_index(index), GFP_KERNEL); |
791 | XA_BUG_ON(xa, xa_load(xa, index) != | 902 | XA_BUG_ON(xa, xa_load(xa, index) != |
792 | xa_mk_value(index)); | 903 | xa_mk_index(index)); |
793 | XA_BUG_ON(xa, xa_find_entry(xa, | 904 | XA_BUG_ON(xa, xa_find_entry(xa, |
794 | xa_mk_value(index)) != index); | 905 | xa_mk_index(index)) != index); |
795 | } | 906 | } |
796 | XA_BUG_ON(xa, xa_find_entry(xa, xa) != -1); | 907 | XA_BUG_ON(xa, xa_find_entry(xa, xa) != -1); |
797 | xa_destroy(xa); | 908 | xa_destroy(xa); |
@@ -802,7 +913,7 @@ static noinline void check_find_entry(struct xarray *xa) | |||
802 | XA_BUG_ON(xa, xa_find_entry(xa, xa) != -1); | 913 | XA_BUG_ON(xa, xa_find_entry(xa, xa) != -1); |
803 | xa_store_index(xa, ULONG_MAX, GFP_KERNEL); | 914 | xa_store_index(xa, ULONG_MAX, GFP_KERNEL); |
804 | XA_BUG_ON(xa, xa_find_entry(xa, xa) != -1); | 915 | XA_BUG_ON(xa, xa_find_entry(xa, xa) != -1); |
805 | XA_BUG_ON(xa, xa_find_entry(xa, xa_mk_value(LONG_MAX)) != -1); | 916 | XA_BUG_ON(xa, xa_find_entry(xa, xa_mk_index(ULONG_MAX)) != -1); |
806 | xa_erase_index(xa, ULONG_MAX); | 917 | xa_erase_index(xa, ULONG_MAX); |
807 | XA_BUG_ON(xa, !xa_empty(xa)); | 918 | XA_BUG_ON(xa, !xa_empty(xa)); |
808 | } | 919 | } |
@@ -822,7 +933,7 @@ static noinline void check_move_small(struct xarray *xa, unsigned long idx) | |||
822 | XA_BUG_ON(xa, xas.xa_node == XAS_RESTART); | 933 | XA_BUG_ON(xa, xas.xa_node == XAS_RESTART); |
823 | XA_BUG_ON(xa, xas.xa_index != i); | 934 | XA_BUG_ON(xa, xas.xa_index != i); |
824 | if (i == 0 || i == idx) | 935 | if (i == 0 || i == idx) |
825 | XA_BUG_ON(xa, entry != xa_mk_value(i)); | 936 | XA_BUG_ON(xa, entry != xa_mk_index(i)); |
826 | else | 937 | else |
827 | XA_BUG_ON(xa, entry != NULL); | 938 | XA_BUG_ON(xa, entry != NULL); |
828 | } | 939 | } |
@@ -836,7 +947,7 @@ static noinline void check_move_small(struct xarray *xa, unsigned long idx) | |||
836 | XA_BUG_ON(xa, xas.xa_node == XAS_RESTART); | 947 | XA_BUG_ON(xa, xas.xa_node == XAS_RESTART); |
837 | XA_BUG_ON(xa, xas.xa_index != i); | 948 | XA_BUG_ON(xa, xas.xa_index != i); |
838 | if (i == 0 || i == idx) | 949 | if (i == 0 || i == idx) |
839 | XA_BUG_ON(xa, entry != xa_mk_value(i)); | 950 | XA_BUG_ON(xa, entry != xa_mk_index(i)); |
840 | else | 951 | else |
841 | XA_BUG_ON(xa, entry != NULL); | 952 | XA_BUG_ON(xa, entry != NULL); |
842 | } while (i > 0); | 953 | } while (i > 0); |
@@ -867,7 +978,7 @@ static noinline void check_move(struct xarray *xa) | |||
867 | do { | 978 | do { |
868 | void *entry = xas_prev(&xas); | 979 | void *entry = xas_prev(&xas); |
869 | i--; | 980 | i--; |
870 | XA_BUG_ON(xa, entry != xa_mk_value(i)); | 981 | XA_BUG_ON(xa, entry != xa_mk_index(i)); |
871 | XA_BUG_ON(xa, i != xas.xa_index); | 982 | XA_BUG_ON(xa, i != xas.xa_index); |
872 | } while (i != 0); | 983 | } while (i != 0); |
873 | 984 | ||
@@ -876,7 +987,7 @@ static noinline void check_move(struct xarray *xa) | |||
876 | 987 | ||
877 | do { | 988 | do { |
878 | void *entry = xas_next(&xas); | 989 | void *entry = xas_next(&xas); |
879 | XA_BUG_ON(xa, entry != xa_mk_value(i)); | 990 | XA_BUG_ON(xa, entry != xa_mk_index(i)); |
880 | XA_BUG_ON(xa, i != xas.xa_index); | 991 | XA_BUG_ON(xa, i != xas.xa_index); |
881 | i++; | 992 | i++; |
882 | } while (i < (1 << 16)); | 993 | } while (i < (1 << 16)); |
@@ -892,7 +1003,7 @@ static noinline void check_move(struct xarray *xa) | |||
892 | void *entry = xas_prev(&xas); | 1003 | void *entry = xas_prev(&xas); |
893 | i--; | 1004 | i--; |
894 | if ((i < (1 << 8)) || (i >= (1 << 15))) | 1005 | if ((i < (1 << 8)) || (i >= (1 << 15))) |
895 | XA_BUG_ON(xa, entry != xa_mk_value(i)); | 1006 | XA_BUG_ON(xa, entry != xa_mk_index(i)); |
896 | else | 1007 | else |
897 | XA_BUG_ON(xa, entry != NULL); | 1008 | XA_BUG_ON(xa, entry != NULL); |
898 | XA_BUG_ON(xa, i != xas.xa_index); | 1009 | XA_BUG_ON(xa, i != xas.xa_index); |
@@ -904,7 +1015,7 @@ static noinline void check_move(struct xarray *xa) | |||
904 | do { | 1015 | do { |
905 | void *entry = xas_next(&xas); | 1016 | void *entry = xas_next(&xas); |
906 | if ((i < (1 << 8)) || (i >= (1 << 15))) | 1017 | if ((i < (1 << 8)) || (i >= (1 << 15))) |
907 | XA_BUG_ON(xa, entry != xa_mk_value(i)); | 1018 | XA_BUG_ON(xa, entry != xa_mk_index(i)); |
908 | else | 1019 | else |
909 | XA_BUG_ON(xa, entry != NULL); | 1020 | XA_BUG_ON(xa, entry != NULL); |
910 | XA_BUG_ON(xa, i != xas.xa_index); | 1021 | XA_BUG_ON(xa, i != xas.xa_index); |
@@ -934,7 +1045,7 @@ static noinline void xa_store_many_order(struct xarray *xa, | |||
934 | if (xas_error(&xas)) | 1045 | if (xas_error(&xas)) |
935 | goto unlock; | 1046 | goto unlock; |
936 | for (i = 0; i < (1U << order); i++) { | 1047 | for (i = 0; i < (1U << order); i++) { |
937 | XA_BUG_ON(xa, xas_store(&xas, xa_mk_value(index + i))); | 1048 | XA_BUG_ON(xa, xas_store(&xas, xa_mk_index(index + i))); |
938 | xas_next(&xas); | 1049 | xas_next(&xas); |
939 | } | 1050 | } |
940 | unlock: | 1051 | unlock: |
@@ -989,9 +1100,9 @@ static noinline void check_create_range_4(struct xarray *xa, | |||
989 | if (xas_error(&xas)) | 1100 | if (xas_error(&xas)) |
990 | goto unlock; | 1101 | goto unlock; |
991 | for (i = 0; i < (1UL << order); i++) { | 1102 | for (i = 0; i < (1UL << order); i++) { |
992 | void *old = xas_store(&xas, xa_mk_value(base + i)); | 1103 | void *old = xas_store(&xas, xa_mk_index(base + i)); |
993 | if (xas.xa_index == index) | 1104 | if (xas.xa_index == index) |
994 | XA_BUG_ON(xa, old != xa_mk_value(base + i)); | 1105 | XA_BUG_ON(xa, old != xa_mk_index(base + i)); |
995 | else | 1106 | else |
996 | XA_BUG_ON(xa, old != NULL); | 1107 | XA_BUG_ON(xa, old != NULL); |
997 | xas_next(&xas); | 1108 | xas_next(&xas); |
@@ -1043,10 +1154,10 @@ static noinline void __check_store_range(struct xarray *xa, unsigned long first, | |||
1043 | unsigned long last) | 1154 | unsigned long last) |
1044 | { | 1155 | { |
1045 | #ifdef CONFIG_XARRAY_MULTI | 1156 | #ifdef CONFIG_XARRAY_MULTI |
1046 | xa_store_range(xa, first, last, xa_mk_value(first), GFP_KERNEL); | 1157 | xa_store_range(xa, first, last, xa_mk_index(first), GFP_KERNEL); |
1047 | 1158 | ||
1048 | XA_BUG_ON(xa, xa_load(xa, first) != xa_mk_value(first)); | 1159 | XA_BUG_ON(xa, xa_load(xa, first) != xa_mk_index(first)); |
1049 | XA_BUG_ON(xa, xa_load(xa, last) != xa_mk_value(first)); | 1160 | XA_BUG_ON(xa, xa_load(xa, last) != xa_mk_index(first)); |
1050 | XA_BUG_ON(xa, xa_load(xa, first - 1) != NULL); | 1161 | XA_BUG_ON(xa, xa_load(xa, first - 1) != NULL); |
1051 | XA_BUG_ON(xa, xa_load(xa, last + 1) != NULL); | 1162 | XA_BUG_ON(xa, xa_load(xa, last + 1) != NULL); |
1052 | 1163 | ||
@@ -1067,7 +1178,7 @@ static noinline void check_store_range(struct xarray *xa) | |||
1067 | __check_store_range(xa, 4095 + i, 4095 + j); | 1178 | __check_store_range(xa, 4095 + i, 4095 + j); |
1068 | __check_store_range(xa, 4096 + i, 4096 + j); | 1179 | __check_store_range(xa, 4096 + i, 4096 + j); |
1069 | __check_store_range(xa, 123456 + i, 123456 + j); | 1180 | __check_store_range(xa, 123456 + i, 123456 + j); |
1070 | __check_store_range(xa, UINT_MAX + i, UINT_MAX + j); | 1181 | __check_store_range(xa, (1 << 24) + i, (1 << 24) + j); |
1071 | } | 1182 | } |
1072 | } | 1183 | } |
1073 | } | 1184 | } |
@@ -1146,12 +1257,14 @@ static noinline void check_account(struct xarray *xa) | |||
1146 | XA_STATE(xas, xa, 1 << order); | 1257 | XA_STATE(xas, xa, 1 << order); |
1147 | 1258 | ||
1148 | xa_store_order(xa, 0, order, xa, GFP_KERNEL); | 1259 | xa_store_order(xa, 0, order, xa, GFP_KERNEL); |
1260 | rcu_read_lock(); | ||
1149 | xas_load(&xas); | 1261 | xas_load(&xas); |
1150 | XA_BUG_ON(xa, xas.xa_node->count == 0); | 1262 | XA_BUG_ON(xa, xas.xa_node->count == 0); |
1151 | XA_BUG_ON(xa, xas.xa_node->count > (1 << order)); | 1263 | XA_BUG_ON(xa, xas.xa_node->count > (1 << order)); |
1152 | XA_BUG_ON(xa, xas.xa_node->nr_values != 0); | 1264 | XA_BUG_ON(xa, xas.xa_node->nr_values != 0); |
1265 | rcu_read_unlock(); | ||
1153 | 1266 | ||
1154 | xa_store_order(xa, 1 << order, order, xa_mk_value(1 << order), | 1267 | xa_store_order(xa, 1 << order, order, xa_mk_index(1UL << order), |
1155 | GFP_KERNEL); | 1268 | GFP_KERNEL); |
1156 | XA_BUG_ON(xa, xas.xa_node->count != xas.xa_node->nr_values * 2); | 1269 | XA_BUG_ON(xa, xas.xa_node->count != xas.xa_node->nr_values * 2); |
1157 | 1270 | ||