History

Merge tag 'xarray-4.20-rc7' of git://git.infradead.org/users/willy/linux-dax

Pull XArray fixes from Matthew Wilcox: "Two bugfixes, each with test-suite updates, two improvements to the test-suite without associated bugs, and one patch adding a missing API" * tag 'xarray-4.20-rc7' of git://git.infradead.org/users/willy/linux-dax: XArray: Fix xa_alloc when id exceeds max XArray tests: Check iterating over multiorder entries XArray tests: Handle larger indices more elegantly XArray: Add xa_cmpxchg_irq and xa_cmpxchg_bh radix tree: Don't return retry entries from lookup

Linus Torvalds committed 7 years ago

Commit 880b9df2 parents 65e08c5 484836110 files · +258 −54Browse files

Unified · Split

10 files
  1. Documentation/core-api/xarray.rst +4 −1
  2. include/linux/xarray.h +54 −0
  3. lib/radix-tree.c +2 −2
  4. lib/test_xarray.c +112 −43
  5. lib/xarray.c +3 −5
  6. mm/shmem.c +1 −3
  7. tools/testing/radix-tree/Makefile +1 −0
  8. tools/testing/radix-tree/main.c +1 −0
  9. tools/testing/radix-tree/regression.h +1 −0
  10. tools/testing/radix-tree/regression4.c +79 −0
Documentation/core-api/xarray.rst+4−1
@@ -187,6 +187,8 @@ Takes xa_lock internally: · 186 unmodified lines
187187 * :c:func:`xa_erase_bh`
188188 * :c:func:`xa_erase_irq`
189189 * :c:func:`xa_cmpxchg`
190+ * :c:func:`xa_cmpxchg_bh`
191+ * :c:func:`xa_cmpxchg_irq`
190192 * :c:func:`xa_store_range`
191193 * :c:func:`xa_alloc`
192194 * :c:func:`xa_alloc_bh`
@@ -263,7 +265,8 @@ using :c:func:`xa_lock_irqsave` in both the interrupt handler and process · 70 unmodified lines
263265 context, or :c:func:`xa_lock_irq` in process context and :c:func:`xa_lock`
264266 in the interrupt handler. Some of the more common patterns have helper
265267 functions such as :c:func:`xa_store_bh`, :c:func:`xa_store_irq`,
266−:c:func:`xa_erase_bh` and :c:func:`xa_erase_irq`.
268+:c:func:`xa_erase_bh`, :c:func:`xa_erase_irq`, :c:func:`xa_cmpxchg_bh`
269+and :c:func:`xa_cmpxchg_irq`.
267270
268271 Sometimes you need to protect access to the XArray with a mutex because
269272 that lock sits above another mutex in the locking hierarchy. That does
include/linux/xarray.h+54−0
@@ -553,6 +553,60 @@ static inline void *xa_cmpxchg(struct xarray *xa, unsigned long index, · 552 unmodified lines
553553 return curr;
554554 }
555555
556+/**
557+ * xa_cmpxchg_bh() - Conditionally replace an entry in the XArray.
558+ * @xa: XArray.
559+ * @index: Index into array.
560+ * @old: Old value to test against.
561+ * @entry: New value to place in array.
562+ * @gfp: Memory allocation flags.
563+ *
564+ * This function is like calling xa_cmpxchg() except it disables softirqs
565+ * while holding the array lock.
566+ *
567+ * Context: Any context. Takes and releases the xa_lock while
568+ * disabling softirqs. May sleep if the @gfp flags permit.
569+ * Return: The old value at this index or xa_err() if an error happened.
570+ */
571+static inline void *xa_cmpxchg_bh(struct xarray *xa, unsigned long index,
572+ void *old, void *entry, gfp_t gfp)
573+{
574+ void *curr;
575+
576+ xa_lock_bh(xa);
577+ curr = __xa_cmpxchg(xa, index, old, entry, gfp);
578+ xa_unlock_bh(xa);
579+
580+ return curr;
581+}
582+
583+/**
584+ * xa_cmpxchg_irq() - Conditionally replace an entry in the XArray.
585+ * @xa: XArray.
586+ * @index: Index into array.
587+ * @old: Old value to test against.
588+ * @entry: New value to place in array.
589+ * @gfp: Memory allocation flags.
590+ *
591+ * This function is like calling xa_cmpxchg() except it disables interrupts
592+ * while holding the array lock.
593+ *
594+ * Context: Process context. Takes and releases the xa_lock while
595+ * disabling interrupts. May sleep if the @gfp flags permit.
596+ * Return: The old value at this index or xa_err() if an error happened.
597+ */
598+static inline void *xa_cmpxchg_irq(struct xarray *xa, unsigned long index,
599+ void *old, void *entry, gfp_t gfp)
600+{
601+ void *curr;
602+
603+ xa_lock_irq(xa);
604+ curr = __xa_cmpxchg(xa, index, old, entry, gfp);
605+ xa_unlock_irq(xa);
606+
607+ return curr;
608+}
609+
556610 /**
557611 * xa_insert() - Store this entry in the XArray unless another entry is
558612 * already present.
lib/radix-tree.c+2−2
@@ -784,11 +784,11 @@ void *__radix_tree_lookup(const struct radix_tree_root *root, · 783 unmodified lines
784784 while (radix_tree_is_internal_node(node)) {
785785 unsigned offset;
786786
787− if (node == RADIX_TREE_RETRY)
788− goto restart;
789787 parent = entry_to_node(node);
790788 offset = radix_tree_descend(parent, &node, index);
791789 slot = parent->slots + offset;
790+ if (node == RADIX_TREE_RETRY)
791+ goto restart;
792792 if (parent->shift == 0)
793793 break;
794794 }
lib/test_xarray.c+112−43
@@ -28,23 +28,28 @@ void xa_dump(const struct xarray *xa) { } · 27 unmodified lines
2828 } while (0)
2929 #endif
3030
31+static void *xa_mk_index(unsigned long index)
32+{
33+ return xa_mk_value(index & LONG_MAX);
34+}
35+
3136 static void *xa_store_index(struct xarray *xa, unsigned long index, gfp_t gfp)
3237 {
33− return xa_store(xa, index, xa_mk_value(index & LONG_MAX), gfp);
38+ return xa_store(xa, index, xa_mk_index(index), gfp);
3439 }
3540
3641 static void xa_alloc_index(struct xarray *xa, unsigned long index, gfp_t gfp)
3742 {
3843 u32 id = 0;
3944
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),
4146 gfp) != 0);
4247 XA_BUG_ON(xa, id != index);
4348 }
4449
4550 static void xa_erase_index(struct xarray *xa, unsigned long index)
4651 {
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));
4853 XA_BUG_ON(xa, xa_load(xa, index) != NULL);
4954 }
5055
@@ -118,7 +123,7 @@ static noinline void check_xas_retry(struct xarray *xa) · 67 unmodified lines
118123
119124 xas_set(&xas, 0);
120125 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));
122127 }
123128 xas_unlock(&xas);
124129
@@ -196,7 +201,7 @@ static noinline void check_xa_mark_1(struct xarray *xa, unsigned long index) · 71 unmodified lines
196201 XA_BUG_ON(xa, xa_store_index(xa, index + 2, GFP_KERNEL));
197202 xa_set_mark(xa, index + 2, XA_MARK_1);
198203 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),
200205 GFP_KERNEL);
201206 for (i = base; i < next; i++) {
202207 XA_STATE(xas, xa, i);
@@ -405,7 +410,7 @@ static noinline void check_xas_erase(struct xarray *xa) · 202 unmodified lines
405410 xas_set(&xas, j);
406411 do {
407412 xas_lock(&xas);
408− xas_store(&xas, xa_mk_value(j));
413+ xas_store(&xas, xa_mk_index(j));
409414 xas_unlock(&xas);
410415 } while (xas_nomem(&xas, GFP_KERNEL));
411416 }
@@ -423,7 +428,7 @@ static noinline void check_xas_erase(struct xarray *xa) · 11 unmodified lines
423428 xas_set(&xas, 0);
424429 j = i;
425430 xas_for_each(&xas, entry, ULONG_MAX) {
426− XA_BUG_ON(xa, entry != xa_mk_value(j));
431+ XA_BUG_ON(xa, entry != xa_mk_index(j));
427432 xas_store(&xas, NULL);
428433 j++;
429434 }
@@ -440,17 +445,17 @@ static noinline void check_multi_store_1(struct xarray *xa, unsigned long index, · 10 unmodified lines
440445 unsigned long min = index & ~((1UL << order) - 1);
441446 unsigned long max = min + (1UL << order);
442447
443− xa_store_order(xa, index, order, xa_mk_value(index), GFP_KERNEL);
444− XA_BUG_ON(xa, xa_load(xa, min) != xa_mk_value(index));
445− XA_BUG_ON(xa, xa_load(xa, max - 1) != xa_mk_value(index));
448+ xa_store_order(xa, index, order, xa_mk_index(index), GFP_KERNEL);
449+ XA_BUG_ON(xa, xa_load(xa, min) != xa_mk_index(index));
450+ XA_BUG_ON(xa, xa_load(xa, max - 1) != xa_mk_index(index));
446451 XA_BUG_ON(xa, xa_load(xa, max) != NULL);
447452 XA_BUG_ON(xa, xa_load(xa, min - 1) != NULL);
448453
449454 xas_lock(&xas);
450− XA_BUG_ON(xa, xas_store(&xas, xa_mk_value(min)) != xa_mk_value(index));
455+ XA_BUG_ON(xa, xas_store(&xas, xa_mk_index(min)) != xa_mk_index(index));
451456 xas_unlock(&xas);
452− XA_BUG_ON(xa, xa_load(xa, min) != xa_mk_value(min));
453− XA_BUG_ON(xa, xa_load(xa, max - 1) != xa_mk_value(min));
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));
454459 XA_BUG_ON(xa, xa_load(xa, max) != NULL);
455460 XA_BUG_ON(xa, xa_load(xa, min - 1) != NULL);
456461
@@ -471,6 +476,32 @@ static noinline void check_multi_store_2(struct xarray *xa, unsigned long index, · 14 unmodified lines
471476 xas_unlock(&xas);
472477 XA_BUG_ON(xa, !xa_empty(xa));
473478 }
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+}
474505 #endif
475506
476507 static noinline void check_multi_store(struct xarray *xa)
@@ -523,15 +554,15 @@ static noinline void check_multi_store(struct xarray *xa) · 46 unmodified lines
523554
524555 for (i = 0; i < max_order; i++) {
525556 for (j = 0; j < max_order; j++) {
526− xa_store_order(xa, 0, i, xa_mk_value(i), GFP_KERNEL);
527− xa_store_order(xa, 0, j, xa_mk_value(j), GFP_KERNEL);
557+ xa_store_order(xa, 0, i, xa_mk_index(i), GFP_KERNEL);
558+ xa_store_order(xa, 0, j, xa_mk_index(j), GFP_KERNEL);
528559
529560 for (k = 0; k < max_order; k++) {
530561 void *entry = xa_load(xa, (1UL << k) - 1);
531562 if ((i < k) && (j < k))
532563 XA_BUG_ON(xa, entry != NULL);
533564 else
534− XA_BUG_ON(xa, entry != xa_mk_value(j));
565+ XA_BUG_ON(xa, entry != xa_mk_index(j));
535566 }
536567
537568 xa_erase(xa, 0);
@@ -545,6 +576,11 @@ static noinline void check_multi_store(struct xarray *xa) · 7 unmodified lines
545576 check_multi_store_1(xa, (1UL << i) + 1, i);
546577 }
547578 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+ }
548584 #endif
549585 }
550586
@@ -587,16 +623,25 @@ static noinline void check_xa_alloc(void) · 36 unmodified lines
587623 xa_destroy(&xa0);
588624
589625 id = 0xfffffffeU;
590− 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),
591627 GFP_KERNEL) != 0);
592628 XA_BUG_ON(&xa0, id != 0xfffffffeU);
593− 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),
594630 GFP_KERNEL) != 0);
595631 XA_BUG_ON(&xa0, id != 0xffffffffU);
596− 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),
597633 GFP_KERNEL) != -ENOSPC);
598634 XA_BUG_ON(&xa0, id != 0xffffffffU);
599635 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));
600645 }
601646
602647 static noinline void __check_store_iter(struct xarray *xa, unsigned long start,
@@ -610,11 +655,11 @@ retry: · 7 unmodified lines
610655 xas_lock(&xas);
611656 xas_for_each_conflict(&xas, entry) {
612657 XA_BUG_ON(xa, !xa_is_value(entry));
613− XA_BUG_ON(xa, entry < xa_mk_value(start));
614− XA_BUG_ON(xa, entry > xa_mk_value(start + (1UL << order) - 1));
658+ XA_BUG_ON(xa, entry < xa_mk_index(start));
659+ XA_BUG_ON(xa, entry > xa_mk_index(start + (1UL << order) - 1));
615660 count++;
616661 }
617− xas_store(&xas, xa_mk_value(start));
662+ xas_store(&xas, xa_mk_index(start));
618663 xas_unlock(&xas);
619664 if (xas_nomem(&xas, GFP_KERNEL)) {
620665 count = 0;
@@ -622,9 +667,9 @@ retry: · 1 unmodified line
622667 }
623668 XA_BUG_ON(xa, xas_error(&xas));
624669 XA_BUG_ON(xa, count != present);
625− 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));
626671 XA_BUG_ON(xa, xa_load(xa, start + (1UL << order) - 1) !=
627− xa_mk_value(start));
672+ xa_mk_index(start));
628673 xa_erase_index(xa, start);
629674 }
630675
@@ -703,7 +748,7 @@ static noinline void check_multi_find_2(struct xarray *xa) · 72 unmodified lines
703748 for (j = 0; j < index; j++) {
704749 XA_STATE(xas, xa, j + index);
705750 xa_store_index(xa, index - 1, GFP_KERNEL);
706− xa_store_order(xa, index, i, xa_mk_value(index),
751+ xa_store_order(xa, index, i, xa_mk_index(index),
707752 GFP_KERNEL);
708753 rcu_read_lock();
709754 xas_for_each(&xas, entry, ULONG_MAX) {
@@ -778,7 +823,7 @@ static noinline void check_find_2(struct xarray *xa) · 68 unmodified lines
778823 j = 0;
779824 index = 0;
780825 xa_for_each(xa, entry, index, ULONG_MAX, XA_PRESENT) {
781− XA_BUG_ON(xa, xa_mk_value(index) != entry);
826+ XA_BUG_ON(xa, xa_mk_index(index) != entry);
782827 XA_BUG_ON(xa, index != j++);
783828 }
784829 }
@@ -786,10 +831,34 @@ static noinline void check_find_2(struct xarray *xa) · 1 unmodified line
786831 xa_destroy(xa);
787832 }
788833
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+
789857 static noinline void check_find(struct xarray *xa)
790858 {
791859 check_find_1(xa);
792860 check_find_2(xa);
861+ check_find_3(xa);
793862 check_multi_find(xa);
794863 check_multi_find_2(xa);
795864 }
@@ -829,11 +898,11 @@ static noinline void check_find_entry(struct xarray *xa) · 33 unmodified lines
829898 for (index = 0; index < (1UL << (order + 5));
830899 index += (1UL << order)) {
831900 xa_store_order(xa, index, order,
832− xa_mk_value(index), GFP_KERNEL);
901+ xa_mk_index(index), GFP_KERNEL);
833902 XA_BUG_ON(xa, xa_load(xa, index) !=
834− xa_mk_value(index));
903+ xa_mk_index(index));
835904 XA_BUG_ON(xa, xa_find_entry(xa,
836− xa_mk_value(index)) != index);
905+ xa_mk_index(index)) != index);
837906 }
838907 XA_BUG_ON(xa, xa_find_entry(xa, xa) != -1);
839908 xa_destroy(xa);
@@ -844,7 +913,7 @@ static noinline void check_find_entry(struct xarray *xa) · 4 unmodified lines
844913 XA_BUG_ON(xa, xa_find_entry(xa, xa) != -1);
845914 xa_store_index(xa, ULONG_MAX, GFP_KERNEL);
846915 XA_BUG_ON(xa, xa_find_entry(xa, xa) != -1);
847− 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);
848917 xa_erase_index(xa, ULONG_MAX);
849918 XA_BUG_ON(xa, !xa_empty(xa));
850919 }
@@ -864,7 +933,7 @@ static noinline void check_move_small(struct xarray *xa, unsigned long idx) · 13 unmodified lines
864933 XA_BUG_ON(xa, xas.xa_node == XAS_RESTART);
865934 XA_BUG_ON(xa, xas.xa_index != i);
866935 if (i == 0 || i == idx)
867− XA_BUG_ON(xa, entry != xa_mk_value(i));
936+ XA_BUG_ON(xa, entry != xa_mk_index(i));
868937 else
869938 XA_BUG_ON(xa, entry != NULL);
870939 }
@@ -878,7 +947,7 @@ static noinline void check_move_small(struct xarray *xa, unsigned long idx) · 7 unmodified lines
878947 XA_BUG_ON(xa, xas.xa_node == XAS_RESTART);
879948 XA_BUG_ON(xa, xas.xa_index != i);
880949 if (i == 0 || i == idx)
881− XA_BUG_ON(xa, entry != xa_mk_value(i));
950+ XA_BUG_ON(xa, entry != xa_mk_index(i));
882951 else
883952 XA_BUG_ON(xa, entry != NULL);
884953 } while (i > 0);
@@ -909,7 +978,7 @@ static noinline void check_move(struct xarray *xa) · 24 unmodified lines
909978 do {
910979 void *entry = xas_prev(&xas);
911980 i--;
912− XA_BUG_ON(xa, entry != xa_mk_value(i));
981+ XA_BUG_ON(xa, entry != xa_mk_index(i));
913982 XA_BUG_ON(xa, i != xas.xa_index);
914983 } while (i != 0);
915984
@@ -918,7 +987,7 @@ static noinline void check_move(struct xarray *xa) · 2 unmodified lines
918987
919988 do {
920989 void *entry = xas_next(&xas);
921− XA_BUG_ON(xa, entry != xa_mk_value(i));
990+ XA_BUG_ON(xa, entry != xa_mk_index(i));
922991 XA_BUG_ON(xa, i != xas.xa_index);
923992 i++;
924993 } while (i < (1 << 16));
@@ -934,7 +1003,7 @@ static noinline void check_move(struct xarray *xa) · 9 unmodified lines
9341003 void *entry = xas_prev(&xas);
9351004 i--;
9361005 if ((i < (1 << 8)) || (i >= (1 << 15)))
937− XA_BUG_ON(xa, entry != xa_mk_value(i));
1006+ XA_BUG_ON(xa, entry != xa_mk_index(i));
9381007 else
9391008 XA_BUG_ON(xa, entry != NULL);
9401009 XA_BUG_ON(xa, i != xas.xa_index);
@@ -946,7 +1015,7 @@ static noinline void check_move(struct xarray *xa) · 5 unmodified lines
9461015 do {
9471016 void *entry = xas_next(&xas);
9481017 if ((i < (1 << 8)) || (i >= (1 << 15)))
949− XA_BUG_ON(xa, entry != xa_mk_value(i));
1018+ XA_BUG_ON(xa, entry != xa_mk_index(i));
9501019 else
9511020 XA_BUG_ON(xa, entry != NULL);
9521021 XA_BUG_ON(xa, i != xas.xa_index);
@@ -976,7 +1045,7 @@ static noinline void xa_store_many_order(struct xarray *xa, · 23 unmodified lines
9761045 if (xas_error(&xas))
9771046 goto unlock;
9781047 for (i = 0; i < (1U << order); i++) {
979− 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)));
9801049 xas_next(&xas);
9811050 }
9821051 unlock:
@@ -1031,9 +1100,9 @@ static noinline void check_create_range_4(struct xarray *xa, · 48 unmodified lines
10311100 if (xas_error(&xas))
10321101 goto unlock;
10331102 for (i = 0; i < (1UL << order); i++) {
1034− void *old = xas_store(&xas, xa_mk_value(base + i));
1103+ void *old = xas_store(&xas, xa_mk_index(base + i));
10351104 if (xas.xa_index == index)
1036− XA_BUG_ON(xa, old != xa_mk_value(base + i));
1105+ XA_BUG_ON(xa, old != xa_mk_index(base + i));
10371106 else
10381107 XA_BUG_ON(xa, old != NULL);
10391108 xas_next(&xas);
@@ -1085,10 +1154,10 @@ static noinline void __check_store_range(struct xarray *xa, unsigned long first, · 45 unmodified lines
10851154 unsigned long last)
10861155 {
10871156 #ifdef CONFIG_XARRAY_MULTI
1088− 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);
10891158
1090− XA_BUG_ON(xa, xa_load(xa, first) != xa_mk_value(first));
1091− XA_BUG_ON(xa, xa_load(xa, last) != xa_mk_value(first));
1159+ XA_BUG_ON(xa, xa_load(xa, first) != xa_mk_index(first));
1160+ XA_BUG_ON(xa, xa_load(xa, last) != xa_mk_index(first));
10921161 XA_BUG_ON(xa, xa_load(xa, first - 1) != NULL);
10931162 XA_BUG_ON(xa, xa_load(xa, last + 1) != NULL);
10941163
@@ -1195,7 +1264,7 @@ static noinline void check_account(struct xarray *xa) · 100 unmodified lines
11951264 XA_BUG_ON(xa, xas.xa_node->nr_values != 0);
11961265 rcu_read_unlock();
11971266
1198− 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),
11991268 GFP_KERNEL);
12001269 XA_BUG_ON(xa, xas.xa_node->count != xas.xa_node->nr_values * 2);
12011270
lib/xarray.c+3−5
@@ -1131,7 +1131,7 @@ void *xas_find_marked(struct xa_state *xas, unsigned long max, xa_mark_t mark) · 1130 unmodified lines
11311131 entry = xa_head(xas->xa);
11321132 xas->xa_node = NULL;
11331133 if (xas->xa_index > max_index(entry))
1134− goto bounds;
1134+ goto out;
11351135 if (!xa_is_node(entry)) {
11361136 if (xa_marked(xas->xa, mark))
11371137 return entry;
@@ -1180,11 +1180,9 @@ void *xas_find_marked(struct xa_state *xas, unsigned long max, xa_mark_t mark) · 42 unmodified lines
11801180 }
11811181
11821182 out:
1183− if (!max)
1183+ if (xas->xa_index > max)
11841184 goto max;
1185−bounds:
1186− xas->xa_node = XAS_BOUNDS;
1187− return NULL;
1185+ return set_bounds(xas);
11881186 max:
11891187 xas->xa_node = XAS_RESTART;
11901188 return NULL;
mm/shmem.c+1−3
@@ -661,9 +661,7 @@ static int shmem_free_swap(struct address_space *mapping, · 660 unmodified lines
661661 {
662662 void *old;
663663
664− xa_lock_irq(&mapping->i_pages);
665− old = __xa_cmpxchg(&mapping->i_pages, index, radswap, NULL, 0);
666− xa_unlock_irq(&mapping->i_pages);
664+ old = xa_cmpxchg_irq(&mapping->i_pages, index, radswap, NULL, 0);
667665 if (old != radswap)
668666 return -ENOENT;
669667 free_swap_and_cache(radix_to_swp_entry(radswap));
tools/testing/radix-tree/Makefile+1−0
@@ -7,6 +7,7 @@ LDLIBS+= -lpthread -lurcu · 6 unmodified lines
77 TARGETS = main idr-test multiorder xarray
88 CORE_OFILES := xarray.o radix-tree.o idr.o linux.o test.o find_bit.o bitmap.o
99 OFILES = main.o $(CORE_OFILES) regression1.o regression2.o regression3.o \
10+ regression4.o \
1011 tag_check.o multiorder.o idr-test.o iteration_check.o benchmark.o
1112
1213 ifndef SHIFT
tools/testing/radix-tree/main.c+1−0
@@ -308,6 +308,7 @@ int main(int argc, char **argv) · 307 unmodified lines
308308 regression1_test();
309309 regression2_test();
310310 regression3_test();
311+ regression4_test();
311312 iteration_test(0, 10 + 90 * long_run);
312313 iteration_test(7, 10 + 90 * long_run);
313314 single_thread_tests(long_run);
tools/testing/radix-tree/regression.h+1−0
@@ -5,5 +5,6 @@ · 4 unmodified lines
55 void regression1_test(void);
66 void regression2_test(void);
77 void regression3_test(void);
8+void regression4_test(void);
89
910 #endif
tools/testing/radix-tree/regression4.c+79−0
@@ -0,0 +1,79 @@
1+// SPDX-License-Identifier: GPL-2.0
2+#include <linux/kernel.h>
3+#include <linux/gfp.h>
4+#include <linux/slab.h>
5+#include <linux/radix-tree.h>
6+#include <linux/rcupdate.h>
7+#include <stdlib.h>
8+#include <pthread.h>
9+#include <stdio.h>
10+#include <assert.h>
11+
12+#include "regression.h"
13+
14+static pthread_barrier_t worker_barrier;
15+static int obj0, obj1;
16+static RADIX_TREE(mt_tree, GFP_KERNEL);
17+
18+static void *reader_fn(void *arg)
19+{
20+ int i;
21+ void *entry;
22+
23+ rcu_register_thread();
24+ pthread_barrier_wait(&worker_barrier);
25+
26+ for (i = 0; i < 1000000; i++) {
27+ rcu_read_lock();
28+ entry = radix_tree_lookup(&mt_tree, 0);
29+ rcu_read_unlock();
30+ if (entry != &obj0) {
31+ printf("iteration %d bad entry = %p\n", i, entry);
32+ abort();
33+ }
34+ }
35+
36+ rcu_unregister_thread();
37+
38+ return NULL;
39+}
40+
41+static void *writer_fn(void *arg)
42+{
43+ int i;
44+
45+ rcu_register_thread();
46+ pthread_barrier_wait(&worker_barrier);
47+
48+ for (i = 0; i < 1000000; i++) {
49+ radix_tree_insert(&mt_tree, 1, &obj1);
50+ radix_tree_delete(&mt_tree, 1);
51+ }
52+
53+ rcu_unregister_thread();
54+
55+ return NULL;
56+}
57+
58+void regression4_test(void)
59+{
60+ pthread_t reader, writer;
61+
62+ printv(1, "regression test 4 starting\n");
63+
64+ radix_tree_insert(&mt_tree, 0, &obj0);
65+ pthread_barrier_init(&worker_barrier, NULL, 2);
66+
67+ if (pthread_create(&reader, NULL, reader_fn, NULL) ||
68+ pthread_create(&writer, NULL, writer_fn, NULL)) {
69+ perror("pthread_create");
70+ exit(1);
71+ }
72+
73+ if (pthread_join(reader, NULL) || pthread_join(writer, NULL)) {
74+ perror("pthread_join");
75+ exit(1);
76+ }
77+
78+ printv(1, "regression test 4 passed\n");
79+}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t