Lines Matching +full:0 +full:xa
20 void xa_dump(const struct xarray *xa) { } in xa_dump() argument
23 #define XA_BUG_ON(xa, x) do { \ argument
27 xa_dump(xa); \
32 } while (0)
40 static void *xa_store_index(struct xarray *xa, unsigned long index, gfp_t gfp) in xa_store_index() argument
42 return xa_store(xa, index, xa_mk_index(index), gfp); in xa_store_index()
45 static void xa_insert_index(struct xarray *xa, unsigned long index) in xa_insert_index() argument
47 XA_BUG_ON(xa, xa_insert(xa, index, xa_mk_index(index), in xa_insert_index()
48 GFP_KERNEL) != 0); in xa_insert_index()
51 static void xa_alloc_index(struct xarray *xa, unsigned long index, gfp_t gfp) in xa_alloc_index() argument
55 XA_BUG_ON(xa, xa_alloc(xa, &id, xa_mk_index(index), xa_limit_32b, in xa_alloc_index()
56 gfp) != 0); in xa_alloc_index()
57 XA_BUG_ON(xa, id != index); in xa_alloc_index()
60 static void xa_erase_index(struct xarray *xa, unsigned long index) in xa_erase_index() argument
62 XA_BUG_ON(xa, xa_erase(xa, index) != xa_mk_index(index)); in xa_erase_index()
63 XA_BUG_ON(xa, xa_load(xa, index) != NULL); in xa_erase_index()
71 static void *xa_store_order(struct xarray *xa, unsigned long index, in xa_store_order() argument
74 XA_STATE_ORDER(xas, xa, index, order); in xa_store_order()
86 static noinline void check_xa_err(struct xarray *xa) in check_xa_err() argument
88 XA_BUG_ON(xa, xa_err(xa_store_index(xa, 0, GFP_NOWAIT)) != 0); in check_xa_err()
89 XA_BUG_ON(xa, xa_err(xa_erase(xa, 0)) != 0); in check_xa_err()
92 XA_BUG_ON(xa, xa_err(xa_store_index(xa, 1, GFP_NOWAIT)) != -ENOMEM); in check_xa_err()
93 XA_BUG_ON(xa, xa_err(xa_store_index(xa, 1, GFP_NOWAIT)) != -ENOMEM); in check_xa_err()
95 XA_BUG_ON(xa, xa_err(xa_store_index(xa, 1, GFP_KERNEL)) != 0); in check_xa_err()
96 XA_BUG_ON(xa, xa_err(xa_store(xa, 1, xa_mk_value(0), GFP_KERNEL)) != 0); in check_xa_err()
97 XA_BUG_ON(xa, xa_err(xa_erase(xa, 1)) != 0); in check_xa_err()
99 // XA_BUG_ON(xa, xa_err(xa_store(xa, 0, xa_mk_internal(0), 0)) != -EINVAL); in check_xa_err()
102 static noinline void check_xas_retry(struct xarray *xa) in check_xas_retry() argument
104 XA_STATE(xas, xa, 0); in check_xas_retry()
107 xa_store_index(xa, 0, GFP_KERNEL); in check_xas_retry()
108 xa_store_index(xa, 1, GFP_KERNEL); in check_xas_retry()
111 XA_BUG_ON(xa, xas_find(&xas, ULONG_MAX) != xa_mk_value(0)); in check_xas_retry()
112 xa_erase_index(xa, 1); in check_xas_retry()
113 XA_BUG_ON(xa, !xa_is_retry(xas_reload(&xas))); in check_xas_retry()
114 XA_BUG_ON(xa, xas_retry(&xas, NULL)); in check_xas_retry()
115 XA_BUG_ON(xa, xas_retry(&xas, xa_mk_value(0))); in check_xas_retry()
117 XA_BUG_ON(xa, xas.xa_node != XAS_RESTART); in check_xas_retry()
118 XA_BUG_ON(xa, xas_next_entry(&xas, ULONG_MAX) != xa_mk_value(0)); in check_xas_retry()
119 XA_BUG_ON(xa, xas.xa_node != NULL); in check_xas_retry()
122 XA_BUG_ON(xa, xa_store_index(xa, 1, GFP_KERNEL) != NULL); in check_xas_retry()
125 XA_BUG_ON(xa, !xa_is_internal(xas_reload(&xas))); in check_xas_retry()
127 XA_BUG_ON(xa, xas_next_entry(&xas, ULONG_MAX) != xa_mk_value(0)); in check_xas_retry()
132 xas_set(&xas, 0); in check_xas_retry()
137 xas_set(&xas, 0); in check_xas_retry()
143 xa_erase_index(xa, 0); in check_xas_retry()
144 xa_erase_index(xa, 1); in check_xas_retry()
147 static noinline void check_xa_load(struct xarray *xa) in check_xa_load() argument
151 for (i = 0; i < 1024; i++) { in check_xa_load()
152 for (j = 0; j < 1024; j++) { in check_xa_load()
153 void *entry = xa_load(xa, j); in check_xa_load()
155 XA_BUG_ON(xa, xa_to_value(entry) != j); in check_xa_load()
157 XA_BUG_ON(xa, entry); in check_xa_load()
159 XA_BUG_ON(xa, xa_store_index(xa, i, GFP_KERNEL) != NULL); in check_xa_load()
162 for (i = 0; i < 1024; i++) { in check_xa_load()
163 for (j = 0; j < 1024; j++) { in check_xa_load()
164 void *entry = xa_load(xa, j); in check_xa_load()
166 XA_BUG_ON(xa, xa_to_value(entry) != j); in check_xa_load()
168 XA_BUG_ON(xa, entry); in check_xa_load()
170 xa_erase_index(xa, i); in check_xa_load()
172 XA_BUG_ON(xa, !xa_empty(xa)); in check_xa_load()
175 static noinline void check_xa_mark_1(struct xarray *xa, unsigned long index) in check_xa_mark_1() argument
181 XA_BUG_ON(xa, xa_get_mark(xa, index, XA_MARK_0)); in check_xa_mark_1()
182 xa_set_mark(xa, index, XA_MARK_0); in check_xa_mark_1()
183 XA_BUG_ON(xa, xa_get_mark(xa, index, XA_MARK_0)); in check_xa_mark_1()
186 XA_BUG_ON(xa, xa_store_index(xa, index, GFP_KERNEL) != NULL); in check_xa_mark_1()
187 XA_BUG_ON(xa, xa_get_mark(xa, index, XA_MARK_0)); in check_xa_mark_1()
188 xa_set_mark(xa, index, XA_MARK_0); in check_xa_mark_1()
189 XA_BUG_ON(xa, !xa_get_mark(xa, index, XA_MARK_0)); in check_xa_mark_1()
192 XA_BUG_ON(xa, xa_get_mark(xa, index + 1, XA_MARK_0)); in check_xa_mark_1()
193 XA_BUG_ON(xa, xa_get_mark(xa, index, XA_MARK_1)); in check_xa_mark_1()
196 xa_erase_index(xa, index); in check_xa_mark_1()
197 XA_BUG_ON(xa, !xa_empty(xa)); in check_xa_mark_1()
198 XA_BUG_ON(xa, xa_get_mark(xa, index, XA_MARK_0)); in check_xa_mark_1()
199 xa_set_mark(xa, index, XA_MARK_0); in check_xa_mark_1()
200 XA_BUG_ON(xa, xa_get_mark(xa, index, XA_MARK_0)); in check_xa_mark_1()
206 BUG_ON((index % 4) != 0); in check_xa_mark_1()
212 XA_BUG_ON(xa, xa_store_index(xa, index + 1, GFP_KERNEL)); in check_xa_mark_1()
213 xa_set_mark(xa, index + 1, XA_MARK_0); in check_xa_mark_1()
214 XA_BUG_ON(xa, xa_store_index(xa, index + 2, GFP_KERNEL)); in check_xa_mark_1()
215 xa_set_mark(xa, index + 2, XA_MARK_2); in check_xa_mark_1()
216 XA_BUG_ON(xa, xa_store_index(xa, next, GFP_KERNEL)); in check_xa_mark_1()
217 xa_store_order(xa, index, order, xa_mk_index(index), in check_xa_mark_1()
220 XA_STATE(xas, xa, i); in check_xa_mark_1()
221 unsigned int seen = 0; in check_xa_mark_1()
224 XA_BUG_ON(xa, !xa_get_mark(xa, i, XA_MARK_0)); in check_xa_mark_1()
225 XA_BUG_ON(xa, xa_get_mark(xa, i, XA_MARK_1)); in check_xa_mark_1()
226 XA_BUG_ON(xa, !xa_get_mark(xa, i, XA_MARK_2)); in check_xa_mark_1()
233 XA_BUG_ON(xa, seen != 2); in check_xa_mark_1()
236 xas_set(&xas, 0); in check_xa_mark_1()
237 seen = 0; in check_xa_mark_1()
242 XA_BUG_ON(xa, seen != 1); in check_xa_mark_1()
244 XA_BUG_ON(xa, xa_get_mark(xa, next, XA_MARK_0)); in check_xa_mark_1()
245 XA_BUG_ON(xa, xa_get_mark(xa, next, XA_MARK_1)); in check_xa_mark_1()
246 XA_BUG_ON(xa, xa_get_mark(xa, next, XA_MARK_2)); in check_xa_mark_1()
247 xa_erase_index(xa, index); in check_xa_mark_1()
248 xa_erase_index(xa, next); in check_xa_mark_1()
249 XA_BUG_ON(xa, !xa_empty(xa)); in check_xa_mark_1()
251 XA_BUG_ON(xa, !xa_empty(xa)); in check_xa_mark_1()
254 static noinline void check_xa_mark_2(struct xarray *xa) in check_xa_mark_2() argument
256 XA_STATE(xas, xa, 0); in check_xa_mark_2()
258 unsigned int count = 0; in check_xa_mark_2()
261 xa_store_index(xa, 0, GFP_KERNEL); in check_xa_mark_2()
262 xa_set_mark(xa, 0, XA_MARK_0); in check_xa_mark_2()
267 XA_BUG_ON(xa, !xa_get_mark(xa, 0, XA_MARK_0) == 0); in check_xa_mark_2()
270 xa_store_index(xa, index, GFP_KERNEL); in check_xa_mark_2()
271 xa_set_mark(xa, index, XA_MARK_0); in check_xa_mark_2()
279 XA_BUG_ON(xa, count != 1000); in check_xa_mark_2()
284 XA_BUG_ON(xa, !xa_get_mark(xa, xas.xa_index, XA_MARK_0)); in check_xa_mark_2()
285 XA_BUG_ON(xa, !xas_get_mark(&xas, XA_MARK_0)); in check_xa_mark_2()
289 xa_destroy(xa); in check_xa_mark_2()
292 static noinline void check_xa_mark_3(struct xarray *xa) in check_xa_mark_3() argument
295 XA_STATE(xas, xa, 0x41); in check_xa_mark_3()
297 int count = 0; in check_xa_mark_3()
299 xa_store_order(xa, 0x40, 2, xa_mk_index(0x40), GFP_KERNEL); in check_xa_mark_3()
300 xa_set_mark(xa, 0x41, XA_MARK_0); in check_xa_mark_3()
305 XA_BUG_ON(xa, entry != xa_mk_index(0x40)); in check_xa_mark_3()
307 XA_BUG_ON(xa, count != 1); in check_xa_mark_3()
309 xa_destroy(xa); in check_xa_mark_3()
313 static noinline void check_xa_mark(struct xarray *xa) in check_xa_mark() argument
317 for (index = 0; index < 16384; index += 4) in check_xa_mark()
318 check_xa_mark_1(xa, index); in check_xa_mark()
320 check_xa_mark_2(xa); in check_xa_mark()
321 check_xa_mark_3(xa); in check_xa_mark()
324 static noinline void check_xa_shrink(struct xarray *xa) in check_xa_shrink() argument
326 XA_STATE(xas, xa, 1); in check_xa_shrink()
331 XA_BUG_ON(xa, !xa_empty(xa)); in check_xa_shrink()
332 XA_BUG_ON(xa, xa_store_index(xa, 0, GFP_KERNEL) != NULL); in check_xa_shrink()
333 XA_BUG_ON(xa, xa_store_index(xa, 1, GFP_KERNEL) != NULL); in check_xa_shrink()
340 XA_BUG_ON(xa, xas_load(&xas) != xa_mk_value(1)); in check_xa_shrink()
342 XA_BUG_ON(xa, xa_entry_locked(xa, node, 0) != xa_mk_value(0)); in check_xa_shrink()
343 XA_BUG_ON(xa, xas_store(&xas, NULL) != xa_mk_value(1)); in check_xa_shrink()
344 XA_BUG_ON(xa, xa_load(xa, 1) != NULL); in check_xa_shrink()
345 XA_BUG_ON(xa, xas.xa_node != XAS_BOUNDS); in check_xa_shrink()
346 XA_BUG_ON(xa, xa_entry_locked(xa, node, 0) != XA_RETRY_ENTRY); in check_xa_shrink()
347 XA_BUG_ON(xa, xas_load(&xas) != NULL); in check_xa_shrink()
349 XA_BUG_ON(xa, xa_load(xa, 0) != xa_mk_value(0)); in check_xa_shrink()
350 xa_erase_index(xa, 0); in check_xa_shrink()
351 XA_BUG_ON(xa, !xa_empty(xa)); in check_xa_shrink()
353 for (order = 0; order < max_order; order++) { in check_xa_shrink()
355 xa_store_order(xa, 0, order, xa_mk_value(0), GFP_KERNEL); in check_xa_shrink()
356 XA_BUG_ON(xa, xa_load(xa, max) != xa_mk_value(0)); in check_xa_shrink()
357 XA_BUG_ON(xa, xa_load(xa, max + 1) != NULL); in check_xa_shrink()
359 node = xa_head(xa); in check_xa_shrink()
361 XA_BUG_ON(xa, xa_store_index(xa, ULONG_MAX, GFP_KERNEL) != in check_xa_shrink()
364 XA_BUG_ON(xa, xa_head(xa) == node); in check_xa_shrink()
366 XA_BUG_ON(xa, xa_load(xa, max + 1) != NULL); in check_xa_shrink()
367 xa_erase_index(xa, ULONG_MAX); in check_xa_shrink()
368 XA_BUG_ON(xa, xa->xa_head != node); in check_xa_shrink()
369 xa_erase_index(xa, 0); in check_xa_shrink()
373 static noinline void check_insert(struct xarray *xa) in check_insert() argument
377 for (i = 0; i < 1024; i++) { in check_insert()
378 xa_insert_index(xa, i); in check_insert()
379 XA_BUG_ON(xa, xa_load(xa, i - 1) != NULL); in check_insert()
380 XA_BUG_ON(xa, xa_load(xa, i + 1) != NULL); in check_insert()
381 xa_erase_index(xa, i); in check_insert()
385 xa_insert_index(xa, 1UL << i); in check_insert()
386 XA_BUG_ON(xa, xa_load(xa, (1UL << i) - 1) != NULL); in check_insert()
387 XA_BUG_ON(xa, xa_load(xa, (1UL << i) + 1) != NULL); in check_insert()
388 xa_erase_index(xa, 1UL << i); in check_insert()
390 xa_insert_index(xa, (1UL << i) - 1); in check_insert()
391 XA_BUG_ON(xa, xa_load(xa, (1UL << i) - 2) != NULL); in check_insert()
392 XA_BUG_ON(xa, xa_load(xa, 1UL << i) != NULL); in check_insert()
393 xa_erase_index(xa, (1UL << i) - 1); in check_insert()
396 xa_insert_index(xa, ~0UL); in check_insert()
397 XA_BUG_ON(xa, xa_load(xa, 0UL) != NULL); in check_insert()
398 XA_BUG_ON(xa, xa_load(xa, ~1UL) != NULL); in check_insert()
399 xa_erase_index(xa, ~0UL); in check_insert()
401 XA_BUG_ON(xa, !xa_empty(xa)); in check_insert()
404 static noinline void check_cmpxchg(struct xarray *xa) in check_cmpxchg() argument
410 XA_BUG_ON(xa, !xa_empty(xa)); in check_cmpxchg()
411 XA_BUG_ON(xa, xa_store_index(xa, 12345678, GFP_KERNEL) != NULL); in check_cmpxchg()
412 XA_BUG_ON(xa, xa_insert(xa, 12345678, xa, GFP_KERNEL) != -EBUSY); in check_cmpxchg()
413 XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, SIX, FIVE, GFP_KERNEL) != LOTS); in check_cmpxchg()
414 XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, LOTS, FIVE, GFP_KERNEL) != LOTS); in check_cmpxchg()
415 XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, FIVE, LOTS, GFP_KERNEL) != FIVE); in check_cmpxchg()
416 XA_BUG_ON(xa, xa_cmpxchg(xa, 5, FIVE, NULL, GFP_KERNEL) != NULL); in check_cmpxchg()
417 XA_BUG_ON(xa, xa_cmpxchg(xa, 5, NULL, FIVE, GFP_KERNEL) != NULL); in check_cmpxchg()
418 XA_BUG_ON(xa, xa_insert(xa, 5, FIVE, GFP_KERNEL) != -EBUSY); in check_cmpxchg()
419 XA_BUG_ON(xa, xa_cmpxchg(xa, 5, FIVE, NULL, GFP_KERNEL) != FIVE); in check_cmpxchg()
420 XA_BUG_ON(xa, xa_insert(xa, 5, FIVE, GFP_KERNEL) == -EBUSY); in check_cmpxchg()
421 xa_erase_index(xa, 12345678); in check_cmpxchg()
422 xa_erase_index(xa, 5); in check_cmpxchg()
423 XA_BUG_ON(xa, !xa_empty(xa)); in check_cmpxchg()
426 static noinline void check_reserve(struct xarray *xa) in check_reserve() argument
433 XA_BUG_ON(xa, !xa_empty(xa)); in check_reserve()
434 XA_BUG_ON(xa, xa_reserve(xa, 12345678, GFP_KERNEL) != 0); in check_reserve()
435 XA_BUG_ON(xa, xa_empty(xa)); in check_reserve()
436 XA_BUG_ON(xa, xa_load(xa, 12345678)); in check_reserve()
437 xa_release(xa, 12345678); in check_reserve()
438 XA_BUG_ON(xa, !xa_empty(xa)); in check_reserve()
441 XA_BUG_ON(xa, xa_reserve(xa, 12345678, GFP_KERNEL) != 0); in check_reserve()
442 XA_BUG_ON(xa, xa_store_index(xa, 12345678, GFP_NOWAIT) != NULL); in check_reserve()
443 xa_release(xa, 12345678); in check_reserve()
444 xa_erase_index(xa, 12345678); in check_reserve()
445 XA_BUG_ON(xa, !xa_empty(xa)); in check_reserve()
448 XA_BUG_ON(xa, xa_reserve(xa, 12345678, GFP_KERNEL) != 0); in check_reserve()
449 XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, XA_ZERO_ENTRY, in check_reserve()
451 xa_release(xa, 12345678); in check_reserve()
452 xa_erase_index(xa, 12345678); in check_reserve()
453 XA_BUG_ON(xa, !xa_empty(xa)); in check_reserve()
456 XA_BUG_ON(xa, xa_reserve(xa, 12345678, GFP_KERNEL) != 0); in check_reserve()
457 XA_BUG_ON(xa, xa_insert(xa, 12345678, xa_mk_value(12345678), 0) != in check_reserve()
459 XA_BUG_ON(xa, xa_empty(xa)); in check_reserve()
460 XA_BUG_ON(xa, xa_erase(xa, 12345678) != NULL); in check_reserve()
461 XA_BUG_ON(xa, !xa_empty(xa)); in check_reserve()
464 xa_store_index(xa, 5, GFP_KERNEL); in check_reserve()
465 XA_BUG_ON(xa, xa_reserve(xa, 6, GFP_KERNEL) != 0); in check_reserve()
466 xa_store_index(xa, 7, GFP_KERNEL); in check_reserve()
468 count = 0; in check_reserve()
469 xa_for_each(xa, index, entry) { in check_reserve()
470 XA_BUG_ON(xa, index != 5 && index != 7); in check_reserve()
473 XA_BUG_ON(xa, count != 2); in check_reserve()
476 if (xa->xa_flags & XA_FLAGS_ALLOC) { in check_reserve()
479 XA_BUG_ON(xa, xa_alloc(xa, &id, xa_mk_value(8), in check_reserve()
480 XA_LIMIT(5, 10), GFP_KERNEL) != 0); in check_reserve()
481 XA_BUG_ON(xa, id != 8); in check_reserve()
483 xa_release(xa, 6); in check_reserve()
484 XA_BUG_ON(xa, xa_alloc(xa, &id, xa_mk_value(6), in check_reserve()
485 XA_LIMIT(5, 10), GFP_KERNEL) != 0); in check_reserve()
486 XA_BUG_ON(xa, id != 6); in check_reserve()
489 xa_destroy(xa); in check_reserve()
492 static noinline void check_xas_erase(struct xarray *xa) in check_xas_erase() argument
494 XA_STATE(xas, xa, 0); in check_xas_erase()
498 for (i = 0; i < 200; i++) { in check_xas_erase()
511 xas_store(&xas, xa_mk_value(0)); in check_xas_erase()
518 xas_set(&xas, 0); in check_xas_erase()
521 XA_BUG_ON(xa, entry != xa_mk_index(j)); in check_xas_erase()
526 XA_BUG_ON(xa, !xa_empty(xa)); in check_xas_erase()
531 static noinline void check_multi_store_1(struct xarray *xa, unsigned long index, in check_multi_store_1() argument
534 XA_STATE(xas, xa, index); in check_multi_store_1()
538 xa_store_order(xa, index, order, xa_mk_index(index), GFP_KERNEL); in check_multi_store_1()
539 XA_BUG_ON(xa, xa_load(xa, min) != xa_mk_index(index)); in check_multi_store_1()
540 XA_BUG_ON(xa, xa_load(xa, max - 1) != xa_mk_index(index)); in check_multi_store_1()
541 XA_BUG_ON(xa, xa_load(xa, max) != NULL); in check_multi_store_1()
542 XA_BUG_ON(xa, xa_load(xa, min - 1) != NULL); in check_multi_store_1()
545 XA_BUG_ON(xa, xas_store(&xas, xa_mk_index(min)) != xa_mk_index(index)); in check_multi_store_1()
547 XA_BUG_ON(xa, xa_load(xa, min) != xa_mk_index(min)); in check_multi_store_1()
548 XA_BUG_ON(xa, xa_load(xa, max - 1) != xa_mk_index(min)); in check_multi_store_1()
549 XA_BUG_ON(xa, xa_load(xa, max) != NULL); in check_multi_store_1()
550 XA_BUG_ON(xa, xa_load(xa, min - 1) != NULL); in check_multi_store_1()
552 xa_erase_index(xa, min); in check_multi_store_1()
553 XA_BUG_ON(xa, !xa_empty(xa)); in check_multi_store_1()
556 static noinline void check_multi_store_2(struct xarray *xa, unsigned long index, in check_multi_store_2() argument
559 XA_STATE(xas, xa, index); in check_multi_store_2()
560 xa_store_order(xa, index, order, xa_mk_value(0), GFP_KERNEL); in check_multi_store_2()
563 XA_BUG_ON(xa, xas_store(&xas, xa_mk_value(1)) != xa_mk_value(0)); in check_multi_store_2()
564 XA_BUG_ON(xa, xas.xa_index != index); in check_multi_store_2()
565 XA_BUG_ON(xa, xas_store(&xas, NULL) != xa_mk_value(1)); in check_multi_store_2()
567 XA_BUG_ON(xa, !xa_empty(xa)); in check_multi_store_2()
570 static noinline void check_multi_store_3(struct xarray *xa, unsigned long index, in check_multi_store_3() argument
573 XA_STATE(xas, xa, 0); in check_multi_store_3()
575 int n = 0; in check_multi_store_3()
577 xa_store_order(xa, index, order, xa_mk_index(index), GFP_KERNEL); in check_multi_store_3()
581 XA_BUG_ON(xa, entry != xa_mk_index(index)); in check_multi_store_3()
584 XA_BUG_ON(xa, n != 1); in check_multi_store_3()
587 XA_BUG_ON(xa, entry != xa_mk_index(index)); in check_multi_store_3()
590 XA_BUG_ON(xa, n != 2); in check_multi_store_3()
593 xa_destroy(xa); in check_multi_store_3()
597 static noinline void check_multi_store(struct xarray *xa) in check_multi_store() argument
604 xa_store_order(xa, 0, 1, xa_mk_value(0), GFP_KERNEL); in check_multi_store()
605 XA_BUG_ON(xa, xa_load(xa, 0) != xa_mk_value(0)); in check_multi_store()
606 XA_BUG_ON(xa, xa_load(xa, 1) != xa_mk_value(0)); in check_multi_store()
607 XA_BUG_ON(xa, xa_load(xa, 2) != NULL); in check_multi_store()
609 XA_BUG_ON(xa, xa_to_node(xa_head(xa))->count != 2); in check_multi_store()
610 XA_BUG_ON(xa, xa_to_node(xa_head(xa))->nr_values != 2); in check_multi_store()
614 xa_store(xa, 3, xa, GFP_KERNEL); in check_multi_store()
615 XA_BUG_ON(xa, xa_load(xa, 0) != xa_mk_value(0)); in check_multi_store()
616 XA_BUG_ON(xa, xa_load(xa, 1) != xa_mk_value(0)); in check_multi_store()
617 XA_BUG_ON(xa, xa_load(xa, 2) != NULL); in check_multi_store()
619 XA_BUG_ON(xa, xa_to_node(xa_head(xa))->count != 3); in check_multi_store()
620 XA_BUG_ON(xa, xa_to_node(xa_head(xa))->nr_values != 2); in check_multi_store()
624 xa_store_order(xa, 0, 2, xa_mk_value(1), GFP_KERNEL); in check_multi_store()
625 XA_BUG_ON(xa, xa_load(xa, 0) != xa_mk_value(1)); in check_multi_store()
626 XA_BUG_ON(xa, xa_load(xa, 1) != xa_mk_value(1)); in check_multi_store()
627 XA_BUG_ON(xa, xa_load(xa, 2) != xa_mk_value(1)); in check_multi_store()
628 XA_BUG_ON(xa, xa_load(xa, 3) != xa_mk_value(1)); in check_multi_store()
629 XA_BUG_ON(xa, xa_load(xa, 4) != NULL); in check_multi_store()
631 XA_BUG_ON(xa, xa_to_node(xa_head(xa))->count != 4); in check_multi_store()
632 XA_BUG_ON(xa, xa_to_node(xa_head(xa))->nr_values != 4); in check_multi_store()
636 xa_store_order(xa, 0, BITS_PER_LONG - 1, NULL, GFP_KERNEL); in check_multi_store()
637 XA_BUG_ON(xa, !xa_empty(xa)); in check_multi_store()
640 xa_store_index(xa, 1, GFP_KERNEL); in check_multi_store()
641 xa_store_index(xa, 2, GFP_KERNEL); in check_multi_store()
642 xa_store_order(xa, 0, 2, NULL, GFP_KERNEL); in check_multi_store()
643 XA_BUG_ON(xa, !xa_empty(xa)); in check_multi_store()
645 for (i = 0; i < max_order; i++) { in check_multi_store()
646 for (j = 0; j < max_order; j++) { in check_multi_store()
647 xa_store_order(xa, 0, i, xa_mk_index(i), GFP_KERNEL); in check_multi_store()
648 xa_store_order(xa, 0, j, xa_mk_index(j), GFP_KERNEL); in check_multi_store()
650 for (k = 0; k < max_order; k++) { in check_multi_store()
651 void *entry = xa_load(xa, (1UL << k) - 1); in check_multi_store()
653 XA_BUG_ON(xa, entry != NULL); in check_multi_store()
655 XA_BUG_ON(xa, entry != xa_mk_index(j)); in check_multi_store()
658 xa_erase(xa, 0); in check_multi_store()
659 XA_BUG_ON(xa, !xa_empty(xa)); in check_multi_store()
663 for (i = 0; i < 20; i++) { in check_multi_store()
664 check_multi_store_1(xa, 200, i); in check_multi_store()
665 check_multi_store_1(xa, 0, i); in check_multi_store()
666 check_multi_store_1(xa, (1UL << i) + 1, i); in check_multi_store()
668 check_multi_store_2(xa, 4095, 9); in check_multi_store()
671 check_multi_store_3(xa, 0, i); in check_multi_store()
672 check_multi_store_3(xa, 1UL << i, i); in check_multi_store()
677 static noinline void check_xa_alloc_1(struct xarray *xa, unsigned int base) in check_xa_alloc_1() argument
682 XA_BUG_ON(xa, !xa_empty(xa)); in check_xa_alloc_1()
684 xa_alloc_index(xa, base, GFP_KERNEL); in check_xa_alloc_1()
687 xa_erase_index(xa, base); in check_xa_alloc_1()
688 XA_BUG_ON(xa, !xa_empty(xa)); in check_xa_alloc_1()
691 xa_alloc_index(xa, base, GFP_KERNEL); in check_xa_alloc_1()
695 xa_alloc_index(xa, i, GFP_KERNEL); in check_xa_alloc_1()
697 xa_erase_index(xa, i); in check_xa_alloc_1()
698 xa_alloc_index(xa, base, GFP_KERNEL); in check_xa_alloc_1()
701 xa_destroy(xa); in check_xa_alloc_1()
704 xa_alloc_index(xa, base, GFP_KERNEL); in check_xa_alloc_1()
707 xa_alloc_index(xa, base + 1, GFP_KERNEL); in check_xa_alloc_1()
708 xa_erase_index(xa, base + 1); in check_xa_alloc_1()
711 xa_store_index(xa, base + 1, GFP_KERNEL); in check_xa_alloc_1()
712 xa_alloc_index(xa, base + 2, GFP_KERNEL); in check_xa_alloc_1()
715 xa_erase_index(xa, base); in check_xa_alloc_1()
716 xa_alloc_index(xa, base, GFP_KERNEL); in check_xa_alloc_1()
718 xa_erase_index(xa, base + 1); in check_xa_alloc_1()
719 xa_erase_index(xa, base + 2); in check_xa_alloc_1()
722 xa_alloc_index(xa, base + i, GFP_KERNEL); in check_xa_alloc_1()
725 xa_destroy(xa); in check_xa_alloc_1()
728 XA_BUG_ON(xa, xa_alloc(xa, &id, xa_mk_index(UINT_MAX - 1), in check_xa_alloc_1()
730 GFP_KERNEL) != 0); in check_xa_alloc_1()
731 XA_BUG_ON(xa, id != 0xfffffffeU); in check_xa_alloc_1()
732 XA_BUG_ON(xa, xa_alloc(xa, &id, xa_mk_index(UINT_MAX), in check_xa_alloc_1()
734 GFP_KERNEL) != 0); in check_xa_alloc_1()
735 XA_BUG_ON(xa, id != 0xffffffffU); in check_xa_alloc_1()
737 XA_BUG_ON(xa, xa_alloc(xa, &id, xa_mk_index(0), in check_xa_alloc_1()
740 XA_BUG_ON(xa, id != 3); in check_xa_alloc_1()
741 xa_destroy(xa); in check_xa_alloc_1()
743 XA_BUG_ON(xa, xa_alloc(xa, &id, xa_mk_index(10), XA_LIMIT(10, 5), in check_xa_alloc_1()
745 XA_BUG_ON(xa, xa_store_index(xa, 3, GFP_KERNEL) != 0); in check_xa_alloc_1()
746 XA_BUG_ON(xa, xa_alloc(xa, &id, xa_mk_index(10), XA_LIMIT(10, 5), in check_xa_alloc_1()
748 xa_erase_index(xa, 3); in check_xa_alloc_1()
749 XA_BUG_ON(xa, !xa_empty(xa)); in check_xa_alloc_1()
752 static noinline void check_xa_alloc_2(struct xarray *xa, unsigned int base) in check_xa_alloc_2() argument
759 XA_BUG_ON(xa, !xa_empty(xa)); in check_xa_alloc_2()
760 XA_BUG_ON(xa, xa_alloc(xa, &id, NULL, xa_limit_32b, GFP_KERNEL) != 0); in check_xa_alloc_2()
761 XA_BUG_ON(xa, id != base); in check_xa_alloc_2()
762 XA_BUG_ON(xa, xa_empty(xa)); in check_xa_alloc_2()
763 XA_BUG_ON(xa, xa_erase(xa, id) != NULL); in check_xa_alloc_2()
764 XA_BUG_ON(xa, !xa_empty(xa)); in check_xa_alloc_2()
767 XA_BUG_ON(xa, !xa_empty(xa)); in check_xa_alloc_2()
768 XA_BUG_ON(xa, xa_alloc(xa, &id, NULL, xa_limit_32b, GFP_KERNEL) != 0); in check_xa_alloc_2()
769 XA_BUG_ON(xa, id != base); in check_xa_alloc_2()
770 XA_BUG_ON(xa, xa_empty(xa)); in check_xa_alloc_2()
771 xa_destroy(xa); in check_xa_alloc_2()
772 XA_BUG_ON(xa, !xa_empty(xa)); in check_xa_alloc_2()
775 XA_BUG_ON(xa, xa_alloc(xa, &id, NULL, xa_limit_32b, in check_xa_alloc_2()
776 GFP_KERNEL) != 0); in check_xa_alloc_2()
777 XA_BUG_ON(xa, id != i); in check_xa_alloc_2()
780 XA_BUG_ON(xa, xa_store(xa, 3, xa_mk_index(3), GFP_KERNEL) != NULL); in check_xa_alloc_2()
781 XA_BUG_ON(xa, xa_store(xa, 4, xa_mk_index(4), GFP_KERNEL) != NULL); in check_xa_alloc_2()
782 XA_BUG_ON(xa, xa_store(xa, 4, NULL, GFP_KERNEL) != xa_mk_index(4)); in check_xa_alloc_2()
783 XA_BUG_ON(xa, xa_erase(xa, 5) != NULL); in check_xa_alloc_2()
784 XA_BUG_ON(xa, xa_alloc(xa, &id, NULL, xa_limit_32b, GFP_KERNEL) != 0); in check_xa_alloc_2()
785 XA_BUG_ON(xa, id != 5); in check_xa_alloc_2()
787 xa_for_each(xa, index, entry) { in check_xa_alloc_2()
788 xa_erase_index(xa, index); in check_xa_alloc_2()
792 XA_BUG_ON(xa, xa_erase(xa, i) != NULL); in check_xa_alloc_2()
793 XA_BUG_ON(xa, xa_empty(xa)); in check_xa_alloc_2()
795 XA_BUG_ON(xa, xa_erase(xa, 8) != NULL); in check_xa_alloc_2()
796 XA_BUG_ON(xa, xa_empty(xa)); in check_xa_alloc_2()
797 XA_BUG_ON(xa, xa_erase(xa, base + 9) != NULL); in check_xa_alloc_2()
798 XA_BUG_ON(xa, !xa_empty(xa)); in check_xa_alloc_2()
800 xa_destroy(xa); in check_xa_alloc_2()
803 static noinline void check_xa_alloc_3(struct xarray *xa, unsigned int base) in check_xa_alloc_3() argument
805 struct xa_limit limit = XA_LIMIT(1, 0x3fff); in check_xa_alloc_3()
806 u32 next = 0; in check_xa_alloc_3()
811 XA_BUG_ON(xa, xa_alloc_cyclic(xa, &id, xa_mk_index(1), limit, in check_xa_alloc_3()
812 &next, GFP_KERNEL) != 0); in check_xa_alloc_3()
813 XA_BUG_ON(xa, id != 1); in check_xa_alloc_3()
815 next = 0x3ffd; in check_xa_alloc_3()
816 XA_BUG_ON(xa, xa_alloc_cyclic(xa, &id, xa_mk_index(0x3ffd), limit, in check_xa_alloc_3()
817 &next, GFP_KERNEL) != 0); in check_xa_alloc_3()
818 XA_BUG_ON(xa, id != 0x3ffd); in check_xa_alloc_3()
819 xa_erase_index(xa, 0x3ffd); in check_xa_alloc_3()
820 xa_erase_index(xa, 1); in check_xa_alloc_3()
821 XA_BUG_ON(xa, !xa_empty(xa)); in check_xa_alloc_3()
823 for (i = 0x3ffe; i < 0x4003; i++) { in check_xa_alloc_3()
824 if (i < 0x4000) in check_xa_alloc_3()
827 entry = xa_mk_index(i - 0x3fff); in check_xa_alloc_3()
828 XA_BUG_ON(xa, xa_alloc_cyclic(xa, &id, entry, limit, in check_xa_alloc_3()
830 XA_BUG_ON(xa, xa_mk_index(id) != entry); in check_xa_alloc_3()
834 if (base != 0) in check_xa_alloc_3()
835 xa_erase_index(xa, base); in check_xa_alloc_3()
836 xa_erase_index(xa, base + 1); in check_xa_alloc_3()
838 XA_BUG_ON(xa, xa_alloc_cyclic(xa, &id, xa_mk_index(UINT_MAX), in check_xa_alloc_3()
839 xa_limit_32b, &next, GFP_KERNEL) != 0); in check_xa_alloc_3()
840 XA_BUG_ON(xa, id != UINT_MAX); in check_xa_alloc_3()
841 XA_BUG_ON(xa, xa_alloc_cyclic(xa, &id, xa_mk_index(base), in check_xa_alloc_3()
843 XA_BUG_ON(xa, id != base); in check_xa_alloc_3()
844 XA_BUG_ON(xa, xa_alloc_cyclic(xa, &id, xa_mk_index(base + 1), in check_xa_alloc_3()
845 xa_limit_32b, &next, GFP_KERNEL) != 0); in check_xa_alloc_3()
846 XA_BUG_ON(xa, id != base + 1); in check_xa_alloc_3()
848 xa_for_each(xa, index, entry) in check_xa_alloc_3()
849 xa_erase_index(xa, index); in check_xa_alloc_3()
851 XA_BUG_ON(xa, !xa_empty(xa)); in check_xa_alloc_3()
859 check_xa_alloc_1(&xa0, 0); in check_xa_alloc()
861 check_xa_alloc_2(&xa0, 0); in check_xa_alloc()
863 check_xa_alloc_3(&xa0, 0); in check_xa_alloc()
867 static noinline void __check_store_iter(struct xarray *xa, unsigned long start, in __check_store_iter() argument
870 XA_STATE_ORDER(xas, xa, start, order); in __check_store_iter()
872 unsigned int count = 0; in __check_store_iter()
877 XA_BUG_ON(xa, !xa_is_value(entry)); in __check_store_iter()
878 XA_BUG_ON(xa, entry < xa_mk_index(start)); in __check_store_iter()
879 XA_BUG_ON(xa, entry > xa_mk_index(start + (1UL << order) - 1)); in __check_store_iter()
885 count = 0; in __check_store_iter()
888 XA_BUG_ON(xa, xas_error(&xas)); in __check_store_iter()
889 XA_BUG_ON(xa, count != present); in __check_store_iter()
890 XA_BUG_ON(xa, xa_load(xa, start) != xa_mk_index(start)); in __check_store_iter()
891 XA_BUG_ON(xa, xa_load(xa, start + (1UL << order) - 1) != in __check_store_iter()
893 xa_erase_index(xa, start); in __check_store_iter()
896 static noinline void check_store_iter(struct xarray *xa) in check_store_iter() argument
901 for (i = 0; i < max_order; i++) { in check_store_iter()
904 __check_store_iter(xa, 0, i, 0); in check_store_iter()
905 XA_BUG_ON(xa, !xa_empty(xa)); in check_store_iter()
906 __check_store_iter(xa, min, i, 0); in check_store_iter()
907 XA_BUG_ON(xa, !xa_empty(xa)); in check_store_iter()
909 xa_store_index(xa, min, GFP_KERNEL); in check_store_iter()
910 __check_store_iter(xa, min, i, 1); in check_store_iter()
911 XA_BUG_ON(xa, !xa_empty(xa)); in check_store_iter()
912 xa_store_index(xa, max, GFP_KERNEL); in check_store_iter()
913 __check_store_iter(xa, min, i, 1); in check_store_iter()
914 XA_BUG_ON(xa, !xa_empty(xa)); in check_store_iter()
916 for (j = 0; j < min; j++) in check_store_iter()
917 xa_store_index(xa, j, GFP_KERNEL); in check_store_iter()
918 __check_store_iter(xa, 0, i, min); in check_store_iter()
919 XA_BUG_ON(xa, !xa_empty(xa)); in check_store_iter()
920 for (j = 0; j < min; j++) in check_store_iter()
921 xa_store_index(xa, min + j, GFP_KERNEL); in check_store_iter()
922 __check_store_iter(xa, min, i, min); in check_store_iter()
923 XA_BUG_ON(xa, !xa_empty(xa)); in check_store_iter()
926 xa_store_index(xa, 63, GFP_KERNEL); in check_store_iter()
927 xa_store_index(xa, 65, GFP_KERNEL); in check_store_iter()
928 __check_store_iter(xa, 64, 2, 1); in check_store_iter()
929 xa_erase_index(xa, 63); in check_store_iter()
931 XA_BUG_ON(xa, !xa_empty(xa)); in check_store_iter()
934 static noinline void check_multi_find_1(struct xarray *xa, unsigned order) in check_multi_find_1() argument
941 xa_store_order(xa, multi, order, xa_mk_value(multi), GFP_KERNEL); in check_multi_find_1()
942 XA_BUG_ON(xa, xa_store_index(xa, next, GFP_KERNEL) != NULL); in check_multi_find_1()
943 XA_BUG_ON(xa, xa_store_index(xa, next + 1, GFP_KERNEL) != NULL); in check_multi_find_1()
945 index = 0; in check_multi_find_1()
946 XA_BUG_ON(xa, xa_find(xa, &index, ULONG_MAX, XA_PRESENT) != in check_multi_find_1()
948 XA_BUG_ON(xa, index != multi); in check_multi_find_1()
950 XA_BUG_ON(xa, xa_find(xa, &index, ULONG_MAX, XA_PRESENT) != in check_multi_find_1()
952 XA_BUG_ON(xa, (index < multi) || (index >= next)); in check_multi_find_1()
953 XA_BUG_ON(xa, xa_find_after(xa, &index, ULONG_MAX, XA_PRESENT) != in check_multi_find_1()
955 XA_BUG_ON(xa, index != next); in check_multi_find_1()
956 XA_BUG_ON(xa, xa_find_after(xa, &index, next, XA_PRESENT) != NULL); in check_multi_find_1()
957 XA_BUG_ON(xa, index != next); in check_multi_find_1()
959 xa_erase_index(xa, multi); in check_multi_find_1()
960 xa_erase_index(xa, next); in check_multi_find_1()
961 xa_erase_index(xa, next + 1); in check_multi_find_1()
962 XA_BUG_ON(xa, !xa_empty(xa)); in check_multi_find_1()
966 static noinline void check_multi_find_2(struct xarray *xa) in check_multi_find_2() argument
972 for (i = 0; i < max_order; i++) { in check_multi_find_2()
974 for (j = 0; j < index; j++) { in check_multi_find_2()
975 XA_STATE(xas, xa, j + index); in check_multi_find_2()
976 xa_store_index(xa, index - 1, GFP_KERNEL); in check_multi_find_2()
977 xa_store_order(xa, index, i, xa_mk_index(index), in check_multi_find_2()
981 xa_erase_index(xa, index); in check_multi_find_2()
984 xa_erase_index(xa, index - 1); in check_multi_find_2()
985 XA_BUG_ON(xa, !xa_empty(xa)); in check_multi_find_2()
990 static noinline void check_multi_find_3(struct xarray *xa) in check_multi_find_3() argument
997 XA_BUG_ON(xa, !xa_empty(xa)); in check_multi_find_3()
998 xa_store_order(xa, 0, order - 4, xa_mk_index(0), GFP_KERNEL); in check_multi_find_3()
999 XA_BUG_ON(xa, xa_find_after(xa, &index, ULONG_MAX, XA_PRESENT)); in check_multi_find_3()
1000 xa_erase_index(xa, 0); in check_multi_find_3()
1004 static noinline void check_find_1(struct xarray *xa) in check_find_1() argument
1008 XA_BUG_ON(xa, !xa_empty(xa)); in check_find_1()
1011 * Check xa_find with all pairs between 0 and 99 inclusive, in check_find_1()
1012 * starting at every index between 0 and 99 in check_find_1()
1014 for (i = 0; i < 100; i++) { in check_find_1()
1015 XA_BUG_ON(xa, xa_store_index(xa, i, GFP_KERNEL) != NULL); in check_find_1()
1016 xa_set_mark(xa, i, XA_MARK_0); in check_find_1()
1017 for (j = 0; j < i; j++) { in check_find_1()
1018 XA_BUG_ON(xa, xa_store_index(xa, j, GFP_KERNEL) != in check_find_1()
1020 xa_set_mark(xa, j, XA_MARK_0); in check_find_1()
1021 for (k = 0; k < 100; k++) { in check_find_1()
1023 void *entry = xa_find(xa, &index, ULONG_MAX, in check_find_1()
1026 XA_BUG_ON(xa, index != j); in check_find_1()
1028 XA_BUG_ON(xa, index != i); in check_find_1()
1030 XA_BUG_ON(xa, entry != NULL); in check_find_1()
1033 entry = xa_find(xa, &index, ULONG_MAX, in check_find_1()
1036 XA_BUG_ON(xa, index != j); in check_find_1()
1038 XA_BUG_ON(xa, index != i); in check_find_1()
1040 XA_BUG_ON(xa, entry != NULL); in check_find_1()
1042 xa_erase_index(xa, j); in check_find_1()
1043 XA_BUG_ON(xa, xa_get_mark(xa, j, XA_MARK_0)); in check_find_1()
1044 XA_BUG_ON(xa, !xa_get_mark(xa, i, XA_MARK_0)); in check_find_1()
1046 xa_erase_index(xa, i); in check_find_1()
1047 XA_BUG_ON(xa, xa_get_mark(xa, i, XA_MARK_0)); in check_find_1()
1049 XA_BUG_ON(xa, !xa_empty(xa)); in check_find_1()
1052 static noinline void check_find_2(struct xarray *xa) in check_find_2() argument
1057 xa_for_each(xa, index, entry) { in check_find_2()
1058 XA_BUG_ON(xa, true); in check_find_2()
1061 for (i = 0; i < 1024; i++) { in check_find_2()
1062 xa_store_index(xa, index, GFP_KERNEL); in check_find_2()
1063 j = 0; in check_find_2()
1064 xa_for_each(xa, index, entry) { in check_find_2()
1065 XA_BUG_ON(xa, xa_mk_index(index) != entry); in check_find_2()
1066 XA_BUG_ON(xa, index != j++); in check_find_2()
1070 xa_destroy(xa); in check_find_2()
1073 static noinline void check_find_3(struct xarray *xa) in check_find_3() argument
1075 XA_STATE(xas, xa, 0); in check_find_3()
1079 for (i = 0; i < 100; i++) { in check_find_3()
1080 for (j = 0; j < 100; j++) { in check_find_3()
1082 for (k = 0; k < 100; k++) { in check_find_3()
1087 XA_BUG_ON(xa, in check_find_3()
1092 xa_store_index(xa, i, GFP_KERNEL); in check_find_3()
1093 xa_set_mark(xa, i, XA_MARK_0); in check_find_3()
1095 xa_destroy(xa); in check_find_3()
1098 static noinline void check_find_4(struct xarray *xa) in check_find_4() argument
1100 unsigned long index = 0; in check_find_4()
1103 xa_store_index(xa, ULONG_MAX, GFP_KERNEL); in check_find_4()
1105 entry = xa_find_after(xa, &index, ULONG_MAX, XA_PRESENT); in check_find_4()
1106 XA_BUG_ON(xa, entry != xa_mk_index(ULONG_MAX)); in check_find_4()
1108 entry = xa_find_after(xa, &index, ULONG_MAX, XA_PRESENT); in check_find_4()
1109 XA_BUG_ON(xa, entry); in check_find_4()
1111 xa_erase_index(xa, ULONG_MAX); in check_find_4()
1114 static noinline void check_find(struct xarray *xa) in check_find() argument
1118 check_find_1(xa); in check_find()
1119 check_find_2(xa); in check_find()
1120 check_find_3(xa); in check_find()
1121 check_find_4(xa); in check_find()
1124 check_multi_find_1(xa, i); in check_find()
1125 check_multi_find_2(xa); in check_find()
1126 check_multi_find_3(xa); in check_find()
1130 static noinline unsigned long xa_find_entry(struct xarray *xa, void *item) in xa_find_entry() argument
1132 XA_STATE(xas, xa, 0); in xa_find_entry()
1133 unsigned int checked = 0; in xa_find_entry()
1143 if ((checked % 4) != 0) in xa_find_entry()
1152 static noinline void check_find_entry(struct xarray *xa) in check_find_entry() argument
1158 for (order = 0; order < 20; order++) { in check_find_entry()
1159 for (offset = 0; offset < (1UL << (order + 3)); in check_find_entry()
1161 for (index = 0; index < (1UL << (order + 5)); in check_find_entry()
1163 xa_store_order(xa, index, order, in check_find_entry()
1165 XA_BUG_ON(xa, xa_load(xa, index) != in check_find_entry()
1167 XA_BUG_ON(xa, xa_find_entry(xa, in check_find_entry()
1170 XA_BUG_ON(xa, xa_find_entry(xa, xa) != -1); in check_find_entry()
1171 xa_destroy(xa); in check_find_entry()
1176 XA_BUG_ON(xa, xa_find_entry(xa, xa) != -1); in check_find_entry()
1177 xa_store_index(xa, ULONG_MAX, GFP_KERNEL); in check_find_entry()
1178 XA_BUG_ON(xa, xa_find_entry(xa, xa) != -1); in check_find_entry()
1179 XA_BUG_ON(xa, xa_find_entry(xa, xa_mk_index(ULONG_MAX)) != -1); in check_find_entry()
1180 xa_erase_index(xa, ULONG_MAX); in check_find_entry()
1181 XA_BUG_ON(xa, !xa_empty(xa)); in check_find_entry()
1184 static noinline void check_pause(struct xarray *xa) in check_pause() argument
1186 XA_STATE(xas, xa, 0); in check_pause()
1190 unsigned int count = 0; in check_pause()
1192 for (order = 0; order < order_limit; order++) { in check_pause()
1193 XA_BUG_ON(xa, xa_store_order(xa, index, order, in check_pause()
1200 XA_BUG_ON(xa, entry != xa_mk_index(1UL << count)); in check_pause()
1204 XA_BUG_ON(xa, count != order_limit); in check_pause()
1206 count = 0; in check_pause()
1207 xas_set(&xas, 0); in check_pause()
1210 XA_BUG_ON(xa, entry != xa_mk_index(1UL << count)); in check_pause()
1215 XA_BUG_ON(xa, count != order_limit); in check_pause()
1217 xa_destroy(xa); in check_pause()
1220 static noinline void check_move_tiny(struct xarray *xa) in check_move_tiny() argument
1222 XA_STATE(xas, xa, 0); in check_move_tiny()
1224 XA_BUG_ON(xa, !xa_empty(xa)); in check_move_tiny()
1226 XA_BUG_ON(xa, xas_next(&xas) != NULL); in check_move_tiny()
1227 XA_BUG_ON(xa, xas_next(&xas) != NULL); in check_move_tiny()
1229 xa_store_index(xa, 0, GFP_KERNEL); in check_move_tiny()
1231 xas_set(&xas, 0); in check_move_tiny()
1232 XA_BUG_ON(xa, xas_next(&xas) != xa_mk_index(0)); in check_move_tiny()
1233 XA_BUG_ON(xa, xas_next(&xas) != NULL); in check_move_tiny()
1234 xas_set(&xas, 0); in check_move_tiny()
1235 XA_BUG_ON(xa, xas_prev(&xas) != xa_mk_index(0)); in check_move_tiny()
1236 XA_BUG_ON(xa, xas_prev(&xas) != NULL); in check_move_tiny()
1238 xa_erase_index(xa, 0); in check_move_tiny()
1239 XA_BUG_ON(xa, !xa_empty(xa)); in check_move_tiny()
1242 static noinline void check_move_max(struct xarray *xa) in check_move_max() argument
1244 XA_STATE(xas, xa, 0); in check_move_max()
1246 xa_store_index(xa, ULONG_MAX, GFP_KERNEL); in check_move_max()
1248 XA_BUG_ON(xa, xas_find(&xas, ULONG_MAX) != xa_mk_index(ULONG_MAX)); in check_move_max()
1249 XA_BUG_ON(xa, xas_find(&xas, ULONG_MAX) != NULL); in check_move_max()
1252 xas_set(&xas, 0); in check_move_max()
1254 XA_BUG_ON(xa, xas_find(&xas, ULONG_MAX) != xa_mk_index(ULONG_MAX)); in check_move_max()
1256 XA_BUG_ON(xa, xas_find(&xas, ULONG_MAX) != NULL); in check_move_max()
1259 xa_erase_index(xa, ULONG_MAX); in check_move_max()
1260 XA_BUG_ON(xa, !xa_empty(xa)); in check_move_max()
1263 static noinline void check_move_small(struct xarray *xa, unsigned long idx) in check_move_small() argument
1265 XA_STATE(xas, xa, 0); in check_move_small()
1268 xa_store_index(xa, 0, GFP_KERNEL); in check_move_small()
1269 xa_store_index(xa, idx, GFP_KERNEL); in check_move_small()
1272 for (i = 0; i < idx * 4; i++) { in check_move_small()
1275 XA_BUG_ON(xa, xas.xa_node == XAS_RESTART); in check_move_small()
1276 XA_BUG_ON(xa, xas.xa_index != i); in check_move_small()
1277 if (i == 0 || i == idx) in check_move_small()
1278 XA_BUG_ON(xa, entry != xa_mk_index(i)); in check_move_small()
1280 XA_BUG_ON(xa, entry != NULL); in check_move_small()
1283 XA_BUG_ON(xa, xas.xa_index != i); in check_move_small()
1289 XA_BUG_ON(xa, xas.xa_node == XAS_RESTART); in check_move_small()
1290 XA_BUG_ON(xa, xas.xa_index != i); in check_move_small()
1291 if (i == 0 || i == idx) in check_move_small()
1292 XA_BUG_ON(xa, entry != xa_mk_index(i)); in check_move_small()
1294 XA_BUG_ON(xa, entry != NULL); in check_move_small()
1295 } while (i > 0); in check_move_small()
1298 XA_BUG_ON(xa, xas_next(&xas) != NULL); in check_move_small()
1299 XA_BUG_ON(xa, xas.xa_index != ULONG_MAX); in check_move_small()
1300 XA_BUG_ON(xa, xas_next(&xas) != xa_mk_value(0)); in check_move_small()
1301 XA_BUG_ON(xa, xas.xa_index != 0); in check_move_small()
1302 XA_BUG_ON(xa, xas_prev(&xas) != NULL); in check_move_small()
1303 XA_BUG_ON(xa, xas.xa_index != ULONG_MAX); in check_move_small()
1306 xa_erase_index(xa, 0); in check_move_small()
1307 xa_erase_index(xa, idx); in check_move_small()
1308 XA_BUG_ON(xa, !xa_empty(xa)); in check_move_small()
1311 static noinline void check_move(struct xarray *xa) in check_move() argument
1313 XA_STATE(xas, xa, (1 << 16) - 1); in check_move()
1316 for (i = 0; i < (1 << 16); i++) in check_move()
1317 XA_BUG_ON(xa, xa_store_index(xa, i, GFP_KERNEL) != NULL); in check_move()
1323 XA_BUG_ON(xa, entry != xa_mk_index(i)); in check_move()
1324 XA_BUG_ON(xa, i != xas.xa_index); in check_move()
1325 } while (i != 0); in check_move()
1327 XA_BUG_ON(xa, xas_prev(&xas) != NULL); in check_move()
1328 XA_BUG_ON(xa, xas.xa_index != ULONG_MAX); in check_move()
1332 XA_BUG_ON(xa, entry != xa_mk_index(i)); in check_move()
1333 XA_BUG_ON(xa, i != xas.xa_index); in check_move()
1339 xa_erase_index(xa, i); in check_move()
1348 XA_BUG_ON(xa, entry != xa_mk_index(i)); in check_move()
1350 XA_BUG_ON(xa, entry != NULL); in check_move()
1351 XA_BUG_ON(xa, i != xas.xa_index); in check_move()
1352 } while (i != 0); in check_move()
1354 XA_BUG_ON(xa, xas_prev(&xas) != NULL); in check_move()
1355 XA_BUG_ON(xa, xas.xa_index != ULONG_MAX); in check_move()
1360 XA_BUG_ON(xa, entry != xa_mk_index(i)); in check_move()
1362 XA_BUG_ON(xa, entry != NULL); in check_move()
1363 XA_BUG_ON(xa, i != xas.xa_index); in check_move()
1368 xa_destroy(xa); in check_move()
1370 check_move_tiny(xa); in check_move()
1371 check_move_max(xa); in check_move()
1373 for (i = 0; i < 16; i++) in check_move()
1374 check_move_small(xa, 1UL << i); in check_move()
1377 check_move_small(xa, (1UL << i) - 1); in check_move()
1380 static noinline void xa_store_many_order(struct xarray *xa, in xa_store_many_order() argument
1383 XA_STATE_ORDER(xas, xa, index, order); in xa_store_many_order()
1384 unsigned int i = 0; in xa_store_many_order()
1388 XA_BUG_ON(xa, xas_find_conflict(&xas)); in xa_store_many_order()
1392 for (i = 0; i < (1U << order); i++) { in xa_store_many_order()
1393 XA_BUG_ON(xa, xas_store(&xas, xa_mk_index(index + i))); in xa_store_many_order()
1400 XA_BUG_ON(xa, xas_error(&xas)); in xa_store_many_order()
1403 static noinline void check_create_range_1(struct xarray *xa, in check_create_range_1() argument
1408 xa_store_many_order(xa, index, order); in check_create_range_1()
1410 xa_erase_index(xa, i); in check_create_range_1()
1411 XA_BUG_ON(xa, !xa_empty(xa)); in check_create_range_1()
1414 static noinline void check_create_range_2(struct xarray *xa, unsigned order) in check_create_range_2() argument
1419 for (i = 0; i < nr * nr; i += nr) in check_create_range_2()
1420 xa_store_many_order(xa, i, order); in check_create_range_2()
1421 for (i = 0; i < nr * nr; i++) in check_create_range_2()
1422 xa_erase_index(xa, i); in check_create_range_2()
1423 XA_BUG_ON(xa, !xa_empty(xa)); in check_create_range_2()
1428 XA_STATE(xas, NULL, 0); in check_create_range_3()
1434 static noinline void check_create_range_4(struct xarray *xa, in check_create_range_4() argument
1437 XA_STATE_ORDER(xas, xa, index, order); in check_create_range_4()
1439 unsigned long i = 0; in check_create_range_4()
1441 xa_store_index(xa, index, GFP_KERNEL); in check_create_range_4()
1447 for (i = 0; i < (1UL << order); i++) { in check_create_range_4()
1450 XA_BUG_ON(xa, old != xa_mk_index(base + i)); in check_create_range_4()
1452 XA_BUG_ON(xa, old != NULL); in check_create_range_4()
1459 XA_BUG_ON(xa, xas_error(&xas)); in check_create_range_4()
1462 xa_erase_index(xa, i); in check_create_range_4()
1463 XA_BUG_ON(xa, !xa_empty(xa)); in check_create_range_4()
1466 static noinline void check_create_range(struct xarray *xa) in check_create_range() argument
1471 for (order = 0; order < max_order; order++) { in check_create_range()
1472 check_create_range_1(xa, 0, order); in check_create_range()
1473 check_create_range_1(xa, 1U << order, order); in check_create_range()
1474 check_create_range_1(xa, 2U << order, order); in check_create_range()
1475 check_create_range_1(xa, 3U << order, order); in check_create_range()
1476 check_create_range_1(xa, 1U << 24, order); in check_create_range()
1478 check_create_range_2(xa, order); in check_create_range()
1480 check_create_range_4(xa, 0, order); in check_create_range()
1481 check_create_range_4(xa, 1U << order, order); in check_create_range()
1482 check_create_range_4(xa, 2U << order, order); in check_create_range()
1483 check_create_range_4(xa, 3U << order, order); in check_create_range()
1484 check_create_range_4(xa, 1U << 24, order); in check_create_range()
1486 check_create_range_4(xa, 1, order); in check_create_range()
1487 check_create_range_4(xa, (1U << order) + 1, order); in check_create_range()
1488 check_create_range_4(xa, (2U << order) + 1, order); in check_create_range()
1489 check_create_range_4(xa, (2U << order) - 1, order); in check_create_range()
1490 check_create_range_4(xa, (3U << order) + 1, order); in check_create_range()
1491 check_create_range_4(xa, (3U << order) - 1, order); in check_create_range()
1492 check_create_range_4(xa, (1U << 24) + 1, order); in check_create_range()
1498 static noinline void __check_store_range(struct xarray *xa, unsigned long first, in __check_store_range() argument
1502 xa_store_range(xa, first, last, xa_mk_index(first), GFP_KERNEL); in __check_store_range()
1504 XA_BUG_ON(xa, xa_load(xa, first) != xa_mk_index(first)); in __check_store_range()
1505 XA_BUG_ON(xa, xa_load(xa, last) != xa_mk_index(first)); in __check_store_range()
1506 XA_BUG_ON(xa, xa_load(xa, first - 1) != NULL); in __check_store_range()
1507 XA_BUG_ON(xa, xa_load(xa, last + 1) != NULL); in __check_store_range()
1509 xa_store_range(xa, first, last, NULL, GFP_KERNEL); in __check_store_range()
1512 XA_BUG_ON(xa, !xa_empty(xa)); in __check_store_range()
1515 static noinline void check_store_range(struct xarray *xa) in check_store_range() argument
1519 for (i = 0; i < 128; i++) { in check_store_range()
1521 __check_store_range(xa, i, j); in check_store_range()
1522 __check_store_range(xa, 128 + i, 128 + j); in check_store_range()
1523 __check_store_range(xa, 4095 + i, 4095 + j); in check_store_range()
1524 __check_store_range(xa, 4096 + i, 4096 + j); in check_store_range()
1525 __check_store_range(xa, 123456 + i, 123456 + j); in check_store_range()
1526 __check_store_range(xa, (1 << 24) + i, (1 << 24) + j); in check_store_range()
1532 static void check_split_1(struct xarray *xa, unsigned long index, in check_split_1() argument
1535 XA_STATE(xas, xa, index); in check_split_1()
1537 unsigned int i = 0; in check_split_1()
1539 xa_store_order(xa, index, order, xa, GFP_KERNEL); in check_split_1()
1541 xas_split_alloc(&xas, xa, order, GFP_KERNEL); in check_split_1()
1543 xas_split(&xas, xa, order); in check_split_1()
1546 xa_for_each(xa, index, entry) { in check_split_1()
1547 XA_BUG_ON(xa, entry != xa); in check_split_1()
1550 XA_BUG_ON(xa, i != 1 << order); in check_split_1()
1552 xa_set_mark(xa, index, XA_MARK_0); in check_split_1()
1553 XA_BUG_ON(xa, !xa_get_mark(xa, index, XA_MARK_0)); in check_split_1()
1555 xa_destroy(xa); in check_split_1()
1558 static noinline void check_split(struct xarray *xa) in check_split() argument
1562 XA_BUG_ON(xa, !xa_empty(xa)); in check_split()
1565 check_split_1(xa, 0, order); in check_split()
1566 check_split_1(xa, 1UL << order, order); in check_split()
1567 check_split_1(xa, 3UL << order, order); in check_split()
1571 static void check_split(struct xarray *xa) { } in check_split() argument
1574 static void check_align_1(struct xarray *xa, char *name) in check_align_1() argument
1581 for (i = 0; i < 8; i++) { in check_align_1()
1582 XA_BUG_ON(xa, xa_alloc(xa, &id, name + i, xa_limit_32b, in check_align_1()
1583 GFP_KERNEL) != 0); in check_align_1()
1584 XA_BUG_ON(xa, id != i); in check_align_1()
1586 xa_for_each(xa, index, entry) in check_align_1()
1587 XA_BUG_ON(xa, xa_is_err(entry)); in check_align_1()
1588 xa_destroy(xa); in check_align_1()
1595 static void check_align_2(struct xarray *xa, char *name) in check_align_2() argument
1599 XA_BUG_ON(xa, !xa_empty(xa)); in check_align_2()
1601 for (i = 0; i < 8; i++) { in check_align_2()
1602 XA_BUG_ON(xa, xa_store(xa, 0, name + i, GFP_KERNEL) != NULL); in check_align_2()
1603 xa_erase(xa, 0); in check_align_2()
1606 for (i = 0; i < 8; i++) { in check_align_2()
1607 XA_BUG_ON(xa, xa_reserve(xa, 0, GFP_KERNEL) != 0); in check_align_2()
1608 XA_BUG_ON(xa, xa_store(xa, 0, name + i, 0) != NULL); in check_align_2()
1609 xa_erase(xa, 0); in check_align_2()
1612 XA_BUG_ON(xa, !xa_empty(xa)); in check_align_2()
1615 static noinline void check_align(struct xarray *xa) in check_align() argument
1619 check_align_1(xa, name); in check_align()
1620 check_align_1(xa, name + 1); in check_align()
1621 check_align_1(xa, name + 2); in check_align()
1622 check_align_1(xa, name + 3); in check_align()
1623 check_align_2(xa, name); in check_align()
1639 static noinline void shadow_remove(struct xarray *xa) in shadow_remove() argument
1643 xa_lock(xa); in shadow_remove()
1646 XA_BUG_ON(xa, node->array != xa); in shadow_remove()
1650 xa_unlock(xa); in shadow_remove()
1653 static noinline void check_workingset(struct xarray *xa, unsigned long index) in check_workingset() argument
1655 XA_STATE(xas, xa, index); in check_workingset()
1660 xas_store(&xas, xa_mk_value(0)); in check_workingset()
1666 XA_BUG_ON(xa, list_empty(&shadow_nodes)); in check_workingset()
1671 XA_BUG_ON(xa, !list_empty(&shadow_nodes)); in check_workingset()
1675 XA_BUG_ON(xa, list_empty(&shadow_nodes)); in check_workingset()
1677 shadow_remove(xa); in check_workingset()
1678 XA_BUG_ON(xa, !list_empty(&shadow_nodes)); in check_workingset()
1679 XA_BUG_ON(xa, !xa_empty(xa)); in check_workingset()
1686 static noinline void check_account(struct xarray *xa) in check_account() argument
1692 XA_STATE(xas, xa, 1 << order); in check_account()
1694 xa_store_order(xa, 0, order, xa, GFP_KERNEL); in check_account()
1697 XA_BUG_ON(xa, xas.xa_node->count == 0); in check_account()
1698 XA_BUG_ON(xa, xas.xa_node->count > (1 << order)); in check_account()
1699 XA_BUG_ON(xa, xas.xa_node->nr_values != 0); in check_account()
1702 xa_store_order(xa, 1 << order, order, xa_mk_index(1UL << order), in check_account()
1704 XA_BUG_ON(xa, xas.xa_node->count != xas.xa_node->nr_values * 2); in check_account()
1706 xa_erase(xa, 1 << order); in check_account()
1707 XA_BUG_ON(xa, xas.xa_node->nr_values != 0); in check_account()
1709 xa_erase(xa, 0); in check_account()
1710 XA_BUG_ON(xa, !xa_empty(xa)); in check_account()
1715 static noinline void check_get_order(struct xarray *xa) in check_get_order() argument
1721 for (i = 0; i < 3; i++) in check_get_order()
1722 XA_BUG_ON(xa, xa_get_order(xa, i) != 0); in check_get_order()
1724 for (order = 0; order < max_order; order++) { in check_get_order()
1725 for (i = 0; i < 10; i++) { in check_get_order()
1726 xa_store_order(xa, i << order, order, in check_get_order()
1729 XA_BUG_ON(xa, xa_get_order(xa, j) != order); in check_get_order()
1730 xa_erase(xa, i << order); in check_get_order()
1735 static noinline void check_destroy(struct xarray *xa) in check_destroy() argument
1739 XA_BUG_ON(xa, !xa_empty(xa)); in check_destroy()
1742 xa_destroy(xa); in check_destroy()
1743 XA_BUG_ON(xa, !xa_empty(xa)); in check_destroy()
1746 for (index = 0; index < 1000; index++) { in check_destroy()
1747 xa_store_index(xa, index, GFP_KERNEL); in check_destroy()
1748 XA_BUG_ON(xa, xa_empty(xa)); in check_destroy()
1749 xa_destroy(xa); in check_destroy()
1750 XA_BUG_ON(xa, !xa_empty(xa)); in check_destroy()
1754 xa_store(xa, ULONG_MAX, xa, GFP_KERNEL); in check_destroy()
1755 XA_BUG_ON(xa, xa_empty(xa)); in check_destroy()
1756 xa_destroy(xa); in check_destroy()
1757 XA_BUG_ON(xa, !xa_empty(xa)); in check_destroy()
1761 xa_store_order(xa, 1 << 11, 11, xa, GFP_KERNEL); in check_destroy()
1762 XA_BUG_ON(xa, xa_empty(xa)); in check_destroy()
1763 xa_destroy(xa); in check_destroy()
1764 XA_BUG_ON(xa, !xa_empty(xa)); in check_destroy()
1797 check_workingset(&array, 0); in xarray_checks()
1802 return (tests_run == tests_passed) ? 0 : -EINVAL; in xarray_checks()