aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-08-26 14:48:42 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-08-26 14:48:42 -0400
commitaba16dc5cf9318b4e0fe92f8261779cd9f1d2d77 (patch)
tree1f53d2cee40e82efe6a727208307af475327af9a /tools
parentc4726e774ed27680c418e138234dfd2b8e1e89ac (diff)
parent1df895190233fcc30d46beca4550bcafb7b959a6 (diff)
Merge branch 'ida-4.19' of git://git.infradead.org/users/willy/linux-dax
Pull IDA updates from Matthew Wilcox: "A better IDA API: id = ida_alloc(ida, GFP_xxx); ida_free(ida, id); rather than the cumbersome ida_simple_get(), ida_simple_remove(). The new IDA API is similar to ida_simple_get() but better named. The internal restructuring of the IDA code removes the bitmap preallocation nonsense. I hope the net -200 lines of code is convincing" * 'ida-4.19' of git://git.infradead.org/users/willy/linux-dax: (29 commits) ida: Change ida_get_new_above to return the id ida: Remove old API test_ida: check_ida_destroy and check_ida_alloc test_ida: Convert check_ida_conv to new API test_ida: Move ida_check_max test_ida: Move ida_check_leaf idr-test: Convert ida_check_nomem to new API ida: Start new test_ida module target/iscsi: Allocate session IDs from an IDA iscsi target: fix session creation failure handling drm/vmwgfx: Convert to new IDA API dmaengine: Convert to new IDA API ppc: Convert vas ID allocation to new IDA API media: Convert entity ID allocation to new IDA API ppc: Convert mmu context allocation to new IDA API Convert net_namespace to new IDA API cb710: Convert to new IDA API rsxx: Convert to new IDA API osd: Convert to new IDA API sd: Convert to new IDA API ...
Diffstat (limited to 'tools')
-rw-r--r--tools/testing/radix-tree/Makefile6
-rw-r--r--tools/testing/radix-tree/idr-test.c214
-rw-r--r--tools/testing/radix-tree/linux/xarray.h2
-rw-r--r--tools/testing/radix-tree/main.c23
-rw-r--r--tools/testing/radix-tree/test.h3
5 files changed, 58 insertions, 190 deletions
diff --git a/tools/testing/radix-tree/Makefile b/tools/testing/radix-tree/Makefile
index db66f8a0d4be..37baecc3766f 100644
--- a/tools/testing/radix-tree/Makefile
+++ b/tools/testing/radix-tree/Makefile
@@ -1,7 +1,8 @@
1# SPDX-License-Identifier: GPL-2.0 1# SPDX-License-Identifier: GPL-2.0
2 2
3CFLAGS += -I. -I../../include -g -O2 -Wall -D_LGPL_SOURCE -fsanitize=address 3CFLAGS += -I. -I../../include -g -Og -Wall -D_LGPL_SOURCE -fsanitize=address \
4LDFLAGS += -fsanitize=address 4 -fsanitize=undefined
5LDFLAGS += -fsanitize=address -fsanitize=undefined
5LDLIBS+= -lpthread -lurcu 6LDLIBS+= -lpthread -lurcu
6TARGETS = main idr-test multiorder 7TARGETS = main idr-test multiorder
7CORE_OFILES := radix-tree.o idr.o linux.o test.o find_bit.o 8CORE_OFILES := radix-tree.o idr.o linux.o test.o find_bit.o
@@ -21,6 +22,7 @@ targets: generated/map-shift.h $(TARGETS)
21 22
22main: $(OFILES) 23main: $(OFILES)
23 24
25idr-test.o: ../../../lib/test_ida.c
24idr-test: idr-test.o $(CORE_OFILES) 26idr-test: idr-test.o $(CORE_OFILES)
25 27
26multiorder: multiorder.o $(CORE_OFILES) 28multiorder: multiorder.o $(CORE_OFILES)
diff --git a/tools/testing/radix-tree/idr-test.c b/tools/testing/radix-tree/idr-test.c
index ee820fcc29b0..321ba92c70d2 100644
--- a/tools/testing/radix-tree/idr-test.c
+++ b/tools/testing/radix-tree/idr-test.c
@@ -309,141 +309,61 @@ void idr_checks(void)
309 idr_u32_test(0); 309 idr_u32_test(0);
310} 310}
311 311
312#define module_init(x)
313#define module_exit(x)
314#define MODULE_AUTHOR(x)
315#define MODULE_LICENSE(x)
316#define dump_stack() assert(0)
317void ida_dump(struct ida *);
318
319#include "../../../lib/test_ida.c"
320
312/* 321/*
313 * Check that we get the correct error when we run out of memory doing 322 * Check that we get the correct error when we run out of memory doing
314 * allocations. To ensure we run out of memory, just "forget" to preload. 323 * allocations. In userspace, GFP_NOWAIT will always fail an allocation.
315 * The first test is for not having a bitmap available, and the second test 324 * The first test is for not having a bitmap available, and the second test
316 * is for not being able to allocate a level of the radix tree. 325 * is for not being able to allocate a level of the radix tree.
317 */ 326 */
318void ida_check_nomem(void) 327void ida_check_nomem(void)
319{ 328{
320 DEFINE_IDA(ida); 329 DEFINE_IDA(ida);
321 int id, err;
322
323 err = ida_get_new_above(&ida, 256, &id);
324 assert(err == -EAGAIN);
325 err = ida_get_new_above(&ida, 1UL << 30, &id);
326 assert(err == -EAGAIN);
327}
328
329/*
330 * Check what happens when we fill a leaf and then delete it. This may
331 * discover mishandling of IDR_FREE.
332 */
333void ida_check_leaf(void)
334{
335 DEFINE_IDA(ida);
336 int id; 330 int id;
337 unsigned long i;
338 331
339 for (i = 0; i < IDA_BITMAP_BITS; i++) { 332 id = ida_alloc_min(&ida, 256, GFP_NOWAIT);
340 assert(ida_pre_get(&ida, GFP_KERNEL)); 333 IDA_BUG_ON(&ida, id != -ENOMEM);
341 assert(!ida_get_new(&ida, &id)); 334 id = ida_alloc_min(&ida, 1UL << 30, GFP_NOWAIT);
342 assert(id == i); 335 IDA_BUG_ON(&ida, id != -ENOMEM);
343 } 336 IDA_BUG_ON(&ida, !ida_is_empty(&ida));
344
345 ida_destroy(&ida);
346 assert(ida_is_empty(&ida));
347
348 assert(ida_pre_get(&ida, GFP_KERNEL));
349 assert(!ida_get_new(&ida, &id));
350 assert(id == 0);
351 ida_destroy(&ida);
352 assert(ida_is_empty(&ida));
353} 337}
354 338
355/* 339/*
356 * Check handling of conversions between exceptional entries and full bitmaps. 340 * Check handling of conversions between exceptional entries and full bitmaps.
357 */ 341 */
358void ida_check_conv(void) 342void ida_check_conv_user(void)
359{ 343{
360 DEFINE_IDA(ida); 344 DEFINE_IDA(ida);
361 int id;
362 unsigned long i; 345 unsigned long i;
363 346
364 for (i = 0; i < IDA_BITMAP_BITS * 2; i += IDA_BITMAP_BITS) {
365 assert(ida_pre_get(&ida, GFP_KERNEL));
366 assert(!ida_get_new_above(&ida, i + 1, &id));
367 assert(id == i + 1);
368 assert(!ida_get_new_above(&ida, i + BITS_PER_LONG, &id));
369 assert(id == i + BITS_PER_LONG);
370 ida_remove(&ida, i + 1);
371 ida_remove(&ida, i + BITS_PER_LONG);
372 assert(ida_is_empty(&ida));
373 }
374
375 assert(ida_pre_get(&ida, GFP_KERNEL));
376
377 for (i = 0; i < IDA_BITMAP_BITS * 2; i++) {
378 assert(ida_pre_get(&ida, GFP_KERNEL));
379 assert(!ida_get_new(&ida, &id));
380 assert(id == i);
381 }
382
383 for (i = IDA_BITMAP_BITS * 2; i > 0; i--) {
384 ida_remove(&ida, i - 1);
385 }
386 assert(ida_is_empty(&ida));
387
388 for (i = 0; i < IDA_BITMAP_BITS + BITS_PER_LONG - 4; i++) {
389 assert(ida_pre_get(&ida, GFP_KERNEL));
390 assert(!ida_get_new(&ida, &id));
391 assert(id == i);
392 }
393
394 for (i = IDA_BITMAP_BITS + BITS_PER_LONG - 4; i > 0; i--) {
395 ida_remove(&ida, i - 1);
396 }
397 assert(ida_is_empty(&ida));
398
399 radix_tree_cpu_dead(1); 347 radix_tree_cpu_dead(1);
400 for (i = 0; i < 1000000; i++) { 348 for (i = 0; i < 1000000; i++) {
401 int err = ida_get_new(&ida, &id); 349 int id = ida_alloc(&ida, GFP_NOWAIT);
402 if (err == -EAGAIN) { 350 if (id == -ENOMEM) {
403 assert((i % IDA_BITMAP_BITS) == (BITS_PER_LONG - 2)); 351 IDA_BUG_ON(&ida, (i % IDA_BITMAP_BITS) !=
404 assert(ida_pre_get(&ida, GFP_KERNEL)); 352 BITS_PER_LONG - 2);
405 err = ida_get_new(&ida, &id); 353 id = ida_alloc(&ida, GFP_KERNEL);
406 } else { 354 } else {
407 assert((i % IDA_BITMAP_BITS) != (BITS_PER_LONG - 2)); 355 IDA_BUG_ON(&ida, (i % IDA_BITMAP_BITS) ==
356 BITS_PER_LONG - 2);
408 } 357 }
409 assert(!err); 358 IDA_BUG_ON(&ida, id != i);
410 assert(id == i);
411 } 359 }
412 ida_destroy(&ida); 360 ida_destroy(&ida);
413} 361}
414 362
415/*
416 * Check allocations up to and slightly above the maximum allowed (2^31-1) ID.
417 * Allocating up to 2^31-1 should succeed, and then allocating the next one
418 * should fail.
419 */
420void ida_check_max(void)
421{
422 DEFINE_IDA(ida);
423 int id, err;
424 unsigned long i, j;
425
426 for (j = 1; j < 65537; j *= 2) {
427 unsigned long base = (1UL << 31) - j;
428 for (i = 0; i < j; i++) {
429 assert(ida_pre_get(&ida, GFP_KERNEL));
430 assert(!ida_get_new_above(&ida, base, &id));
431 assert(id == base + i);
432 }
433 assert(ida_pre_get(&ida, GFP_KERNEL));
434 err = ida_get_new_above(&ida, base, &id);
435 assert(err == -ENOSPC);
436 ida_destroy(&ida);
437 assert(ida_is_empty(&ida));
438 rcu_barrier();
439 }
440}
441
442void ida_check_random(void) 363void ida_check_random(void)
443{ 364{
444 DEFINE_IDA(ida); 365 DEFINE_IDA(ida);
445 DECLARE_BITMAP(bitmap, 2048); 366 DECLARE_BITMAP(bitmap, 2048);
446 int id, err;
447 unsigned int i; 367 unsigned int i;
448 time_t s = time(NULL); 368 time_t s = time(NULL);
449 369
@@ -454,15 +374,11 @@ void ida_check_random(void)
454 int bit = i & 2047; 374 int bit = i & 2047;
455 if (test_bit(bit, bitmap)) { 375 if (test_bit(bit, bitmap)) {
456 __clear_bit(bit, bitmap); 376 __clear_bit(bit, bitmap);
457 ida_remove(&ida, bit); 377 ida_free(&ida, bit);
458 } else { 378 } else {
459 __set_bit(bit, bitmap); 379 __set_bit(bit, bitmap);
460 do { 380 IDA_BUG_ON(&ida, ida_alloc_min(&ida, bit, GFP_KERNEL)
461 ida_pre_get(&ida, GFP_KERNEL); 381 != bit);
462 err = ida_get_new_above(&ida, bit, &id);
463 } while (err == -EAGAIN);
464 assert(!err);
465 assert(id == bit);
466 } 382 }
467 } 383 }
468 ida_destroy(&ida); 384 ida_destroy(&ida);
@@ -488,71 +404,12 @@ void ida_simple_get_remove_test(void)
488 ida_destroy(&ida); 404 ida_destroy(&ida);
489} 405}
490 406
491void ida_checks(void) 407void user_ida_checks(void)
492{ 408{
493 DEFINE_IDA(ida);
494 int id;
495 unsigned long i;
496
497 radix_tree_cpu_dead(1); 409 radix_tree_cpu_dead(1);
498 ida_check_nomem();
499
500 for (i = 0; i < 10000; i++) {
501 assert(ida_pre_get(&ida, GFP_KERNEL));
502 assert(!ida_get_new(&ida, &id));
503 assert(id == i);
504 }
505
506 ida_remove(&ida, 20);
507 ida_remove(&ida, 21);
508 for (i = 0; i < 3; i++) {
509 assert(ida_pre_get(&ida, GFP_KERNEL));
510 assert(!ida_get_new(&ida, &id));
511 if (i == 2)
512 assert(id == 10000);
513 }
514
515 for (i = 0; i < 5000; i++)
516 ida_remove(&ida, i);
517
518 assert(ida_pre_get(&ida, GFP_KERNEL));
519 assert(!ida_get_new_above(&ida, 5000, &id));
520 assert(id == 10001);
521
522 ida_destroy(&ida);
523
524 assert(ida_is_empty(&ida));
525 410
526 assert(ida_pre_get(&ida, GFP_KERNEL)); 411 ida_check_nomem();
527 assert(!ida_get_new_above(&ida, 1, &id)); 412 ida_check_conv_user();
528 assert(id == 1);
529
530 ida_remove(&ida, id);
531 assert(ida_is_empty(&ida));
532 ida_destroy(&ida);
533 assert(ida_is_empty(&ida));
534
535 assert(ida_pre_get(&ida, GFP_KERNEL));
536 assert(!ida_get_new_above(&ida, 1, &id));
537 ida_destroy(&ida);
538 assert(ida_is_empty(&ida));
539
540 assert(ida_pre_get(&ida, GFP_KERNEL));
541 assert(!ida_get_new_above(&ida, 1, &id));
542 assert(id == 1);
543 assert(ida_pre_get(&ida, GFP_KERNEL));
544 assert(!ida_get_new_above(&ida, 1025, &id));
545 assert(id == 1025);
546 assert(ida_pre_get(&ida, GFP_KERNEL));
547 assert(!ida_get_new_above(&ida, 10000, &id));
548 assert(id == 10000);
549 ida_remove(&ida, 1025);
550 ida_destroy(&ida);
551 assert(ida_is_empty(&ida));
552
553 ida_check_leaf();
554 ida_check_max();
555 ida_check_conv();
556 ida_check_random(); 413 ida_check_random();
557 ida_simple_get_remove_test(); 414 ida_simple_get_remove_test();
558 415
@@ -582,12 +439,19 @@ void ida_thread_tests(void)
582 pthread_join(threads[i], NULL); 439 pthread_join(threads[i], NULL);
583} 440}
584 441
442void ida_tests(void)
443{
444 user_ida_checks();
445 ida_checks();
446 ida_exit();
447 ida_thread_tests();
448}
449
585int __weak main(void) 450int __weak main(void)
586{ 451{
587 radix_tree_init(); 452 radix_tree_init();
588 idr_checks(); 453 idr_checks();
589 ida_checks(); 454 ida_tests();
590 ida_thread_tests();
591 radix_tree_cpu_dead(1); 455 radix_tree_cpu_dead(1);
592 rcu_barrier(); 456 rcu_barrier();
593 if (nr_allocated) 457 if (nr_allocated)
diff --git a/tools/testing/radix-tree/linux/xarray.h b/tools/testing/radix-tree/linux/xarray.h
new file mode 100644
index 000000000000..df3812cda376
--- /dev/null
+++ b/tools/testing/radix-tree/linux/xarray.h
@@ -0,0 +1,2 @@
1#include "generated/map-shift.h"
2#include "../../../../include/linux/xarray.h"
diff --git a/tools/testing/radix-tree/main.c b/tools/testing/radix-tree/main.c
index 257f3f8aacaa..b741686e53d6 100644
--- a/tools/testing/radix-tree/main.c
+++ b/tools/testing/radix-tree/main.c
@@ -27,20 +27,22 @@ void __gang_check(unsigned long middle, long down, long up, int chunk, int hop)
27 item_check_present(&tree, middle + idx); 27 item_check_present(&tree, middle + idx);
28 item_check_absent(&tree, middle + up); 28 item_check_absent(&tree, middle + up);
29 29
30 item_gang_check_present(&tree, middle - down, 30 if (chunk > 0) {
31 up + down, chunk, hop); 31 item_gang_check_present(&tree, middle - down, up + down,
32 item_full_scan(&tree, middle - down, down + up, chunk); 32 chunk, hop);
33 item_full_scan(&tree, middle - down, down + up, chunk);
34 }
33 item_kill_tree(&tree); 35 item_kill_tree(&tree);
34} 36}
35 37
36void gang_check(void) 38void gang_check(void)
37{ 39{
38 __gang_check(1 << 30, 128, 128, 35, 2); 40 __gang_check(1UL << 30, 128, 128, 35, 2);
39 __gang_check(1 << 31, 128, 128, 32, 32); 41 __gang_check(1UL << 31, 128, 128, 32, 32);
40 __gang_check(1 << 31, 128, 128, 32, 100); 42 __gang_check(1UL << 31, 128, 128, 32, 100);
41 __gang_check(1 << 31, 128, 128, 17, 7); 43 __gang_check(1UL << 31, 128, 128, 17, 7);
42 __gang_check(0xffff0000, 0, 65536, 17, 7); 44 __gang_check(0xffff0000UL, 0, 65536, 17, 7);
43 __gang_check(0xfffffffe, 1, 1, 17, 7); 45 __gang_check(0xfffffffeUL, 1, 1, 17, 7);
44} 46}
45 47
46void __big_gang_check(void) 48void __big_gang_check(void)
@@ -322,7 +324,7 @@ static void single_thread_tests(bool long_run)
322 printv(2, "after dynamic_height_check: %d allocated, preempt %d\n", 324 printv(2, "after dynamic_height_check: %d allocated, preempt %d\n",
323 nr_allocated, preempt_count); 325 nr_allocated, preempt_count);
324 idr_checks(); 326 idr_checks();
325 ida_checks(); 327 ida_tests();
326 rcu_barrier(); 328 rcu_barrier();
327 printv(2, "after idr_checks: %d allocated, preempt %d\n", 329 printv(2, "after idr_checks: %d allocated, preempt %d\n",
328 nr_allocated, preempt_count); 330 nr_allocated, preempt_count);
@@ -369,7 +371,6 @@ int main(int argc, char **argv)
369 iteration_test(0, 10 + 90 * long_run); 371 iteration_test(0, 10 + 90 * long_run);
370 iteration_test(7, 10 + 90 * long_run); 372 iteration_test(7, 10 + 90 * long_run);
371 single_thread_tests(long_run); 373 single_thread_tests(long_run);
372 ida_thread_tests();
373 374
374 /* Free any remaining preallocated nodes */ 375 /* Free any remaining preallocated nodes */
375 radix_tree_cpu_dead(0); 376 radix_tree_cpu_dead(0);
diff --git a/tools/testing/radix-tree/test.h b/tools/testing/radix-tree/test.h
index 31f1d9b6f506..92d901eacf49 100644
--- a/tools/testing/radix-tree/test.h
+++ b/tools/testing/radix-tree/test.h
@@ -39,8 +39,7 @@ void multiorder_checks(void);
39void iteration_test(unsigned order, unsigned duration); 39void iteration_test(unsigned order, unsigned duration);
40void benchmark(void); 40void benchmark(void);
41void idr_checks(void); 41void idr_checks(void);
42void ida_checks(void); 42void ida_tests(void);
43void ida_thread_tests(void);
44 43
45struct item * 44struct item *
46item_tag_set(struct radix_tree_root *root, unsigned long index, int tag); 45item_tag_set(struct radix_tree_root *root, unsigned long index, int tag);