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
...

Changed files
+486 -680
arch
powerpc
mm
platforms
powernv
drivers
block
mtip32xx
rsxx
dma
gpu
media
misc
cb710
scsi
target
fs
include
linux
lib
net
tools
testing
+4 -40
arch/powerpc/mm/mmu_context_book3s64.c
··· 26 26 #include <asm/mmu_context.h> 27 27 #include <asm/pgalloc.h> 28 28 29 - static DEFINE_SPINLOCK(mmu_context_lock); 30 29 static DEFINE_IDA(mmu_context_ida); 31 30 32 31 static int alloc_context_id(int min_id, int max_id) 33 32 { 34 - int index, err; 35 - 36 - again: 37 - if (!ida_pre_get(&mmu_context_ida, GFP_KERNEL)) 38 - return -ENOMEM; 39 - 40 - spin_lock(&mmu_context_lock); 41 - err = ida_get_new_above(&mmu_context_ida, min_id, &index); 42 - spin_unlock(&mmu_context_lock); 43 - 44 - if (err == -EAGAIN) 45 - goto again; 46 - else if (err) 47 - return err; 48 - 49 - if (index > max_id) { 50 - spin_lock(&mmu_context_lock); 51 - ida_remove(&mmu_context_ida, index); 52 - spin_unlock(&mmu_context_lock); 53 - return -ENOMEM; 54 - } 55 - 56 - return index; 33 + return ida_alloc_range(&mmu_context_ida, min_id, max_id, GFP_KERNEL); 57 34 } 58 35 59 36 void hash__reserve_context_id(int id) 60 37 { 61 - int rc, result = 0; 62 - 63 - do { 64 - if (!ida_pre_get(&mmu_context_ida, GFP_KERNEL)) 65 - break; 66 - 67 - spin_lock(&mmu_context_lock); 68 - rc = ida_get_new_above(&mmu_context_ida, id, &result); 69 - spin_unlock(&mmu_context_lock); 70 - } while (rc == -EAGAIN); 38 + int result = ida_alloc_range(&mmu_context_ida, id, id, GFP_KERNEL); 71 39 72 40 WARN(result != id, "mmu: Failed to reserve context id %d (rc %d)\n", id, result); 73 41 } ··· 140 172 141 173 void __destroy_context(int context_id) 142 174 { 143 - spin_lock(&mmu_context_lock); 144 - ida_remove(&mmu_context_ida, context_id); 145 - spin_unlock(&mmu_context_lock); 175 + ida_free(&mmu_context_ida, context_id); 146 176 } 147 177 EXPORT_SYMBOL_GPL(__destroy_context); 148 178 ··· 148 182 { 149 183 int index, context_id; 150 184 151 - spin_lock(&mmu_context_lock); 152 185 for (index = 0; index < ARRAY_SIZE(ctx->extended_id); index++) { 153 186 context_id = ctx->extended_id[index]; 154 187 if (context_id) 155 - ida_remove(&mmu_context_ida, context_id); 188 + ida_free(&mmu_context_ida, context_id); 156 189 } 157 - spin_unlock(&mmu_context_lock); 158 190 } 159 191 160 192 static void pte_frag_destroy(void *pte_frag)
+4 -22
arch/powerpc/platforms/powernv/vas-window.c
··· 515 515 return 0; 516 516 } 517 517 518 - static DEFINE_SPINLOCK(vas_ida_lock); 519 - 520 518 static void vas_release_window_id(struct ida *ida, int winid) 521 519 { 522 - spin_lock(&vas_ida_lock); 523 - ida_remove(ida, winid); 524 - spin_unlock(&vas_ida_lock); 520 + ida_free(ida, winid); 525 521 } 526 522 527 523 static int vas_assign_window_id(struct ida *ida) 528 524 { 529 - int rc, winid; 525 + int winid = ida_alloc_max(ida, VAS_WINDOWS_PER_CHIP - 1, GFP_KERNEL); 530 526 531 - do { 532 - rc = ida_pre_get(ida, GFP_KERNEL); 533 - if (!rc) 534 - return -EAGAIN; 535 - 536 - spin_lock(&vas_ida_lock); 537 - rc = ida_get_new(ida, &winid); 538 - spin_unlock(&vas_ida_lock); 539 - } while (rc == -EAGAIN); 540 - 541 - if (rc) 542 - return rc; 543 - 544 - if (winid > VAS_WINDOWS_PER_CHIP) { 545 - pr_err("Too many (%d) open windows\n", winid); 546 - vas_release_window_id(ida, winid); 527 + if (winid == -ENOSPC) { 528 + pr_err("Too many (%d) open windows\n", VAS_WINDOWS_PER_CHIP); 547 529 return -EAGAIN; 548 530 } 549 531
+6 -23
drivers/block/mtip32xx/mtip32xx.c
··· 118 118 119 119 static u32 cpu_use[NR_CPUS]; 120 120 121 - static DEFINE_SPINLOCK(rssd_index_lock); 122 121 static DEFINE_IDA(rssd_index_ida); 123 122 124 123 static int mtip_block_initialize(struct driver_data *dd); ··· 3766 3767 goto alloc_disk_error; 3767 3768 } 3768 3769 3769 - /* Generate the disk name, implemented same as in sd.c */ 3770 - do { 3771 - if (!ida_pre_get(&rssd_index_ida, GFP_KERNEL)) { 3772 - rv = -ENOMEM; 3773 - goto ida_get_error; 3774 - } 3775 - 3776 - spin_lock(&rssd_index_lock); 3777 - rv = ida_get_new(&rssd_index_ida, &index); 3778 - spin_unlock(&rssd_index_lock); 3779 - } while (rv == -EAGAIN); 3780 - 3781 - if (rv) 3770 + rv = ida_alloc(&rssd_index_ida, GFP_KERNEL); 3771 + if (rv < 0) 3782 3772 goto ida_get_error; 3773 + index = rv; 3783 3774 3784 3775 rv = rssd_disk_name_format("rssd", 3785 3776 index, ··· 3911 3922 block_queue_alloc_tag_error: 3912 3923 mtip_hw_debugfs_exit(dd); 3913 3924 disk_index_error: 3914 - spin_lock(&rssd_index_lock); 3915 - ida_remove(&rssd_index_ida, index); 3916 - spin_unlock(&rssd_index_lock); 3925 + ida_free(&rssd_index_ida, index); 3917 3926 3918 3927 ida_get_error: 3919 3928 put_disk(dd->disk); ··· 3999 4012 } 4000 4013 dd->disk = NULL; 4001 4014 4002 - spin_lock(&rssd_index_lock); 4003 - ida_remove(&rssd_index_ida, dd->index); 4004 - spin_unlock(&rssd_index_lock); 4015 + ida_free(&rssd_index_ida, dd->index); 4005 4016 4006 4017 /* De-initialize the protocol layer. */ 4007 4018 mtip_hw_exit(dd); ··· 4039 4054 dd->queue = NULL; 4040 4055 } 4041 4056 4042 - spin_lock(&rssd_index_lock); 4043 - ida_remove(&rssd_index_ida, dd->index); 4044 - spin_unlock(&rssd_index_lock); 4057 + ida_free(&rssd_index_ida, dd->index); 4045 4058 return 0; 4046 4059 } 4047 4060
+5 -16
drivers/block/rsxx/core.c
··· 58 58 "until the card startup has completed."); 59 59 60 60 static DEFINE_IDA(rsxx_disk_ida); 61 - static DEFINE_SPINLOCK(rsxx_ida_lock); 62 61 63 62 /* --------------------Debugfs Setup ------------------- */ 64 63 ··· 770 771 card->dev = dev; 771 772 pci_set_drvdata(dev, card); 772 773 773 - do { 774 - if (!ida_pre_get(&rsxx_disk_ida, GFP_KERNEL)) { 775 - st = -ENOMEM; 776 - goto failed_ida_get; 777 - } 778 - 779 - spin_lock(&rsxx_ida_lock); 780 - st = ida_get_new(&rsxx_disk_ida, &card->disk_id); 781 - spin_unlock(&rsxx_ida_lock); 782 - } while (st == -EAGAIN); 783 - 784 - if (st) 774 + st = ida_alloc(&rsxx_disk_ida, GFP_KERNEL); 775 + if (st < 0) 785 776 goto failed_ida_get; 777 + card->disk_id = st; 786 778 787 779 st = pci_enable_device(dev); 788 780 if (st) ··· 975 985 failed_dma_mask: 976 986 pci_disable_device(dev); 977 987 failed_enable: 978 - spin_lock(&rsxx_ida_lock); 979 - ida_remove(&rsxx_disk_ida, card->disk_id); 980 - spin_unlock(&rsxx_ida_lock); 988 + ida_free(&rsxx_disk_ida, card->disk_id); 981 989 failed_ida_get: 982 990 kfree(card); 983 991 ··· 1038 1050 pci_disable_device(dev); 1039 1051 pci_release_regions(dev); 1040 1052 1053 + ida_free(&rsxx_disk_ida, card->disk_id); 1041 1054 kfree(card); 1042 1055 } 1043 1056
+7 -16
drivers/dma/dmaengine.c
··· 161 161 162 162 chan_dev = container_of(dev, typeof(*chan_dev), device); 163 163 if (atomic_dec_and_test(chan_dev->idr_ref)) { 164 - mutex_lock(&dma_list_mutex); 165 - ida_remove(&dma_ida, chan_dev->dev_id); 166 - mutex_unlock(&dma_list_mutex); 164 + ida_free(&dma_ida, chan_dev->dev_id); 167 165 kfree(chan_dev->idr_ref); 168 166 } 169 167 kfree(chan_dev); ··· 896 898 897 899 static int get_dma_id(struct dma_device *device) 898 900 { 899 - int rc; 901 + int rc = ida_alloc(&dma_ida, GFP_KERNEL); 900 902 901 - do { 902 - if (!ida_pre_get(&dma_ida, GFP_KERNEL)) 903 - return -ENOMEM; 904 - mutex_lock(&dma_list_mutex); 905 - rc = ida_get_new(&dma_ida, &device->dev_id); 906 - mutex_unlock(&dma_list_mutex); 907 - } while (rc == -EAGAIN); 908 - 909 - return rc; 903 + if (rc < 0) 904 + return rc; 905 + device->dev_id = rc; 906 + return 0; 910 907 } 911 908 912 909 /** ··· 1085 1092 err_out: 1086 1093 /* if we never registered a channel just release the idr */ 1087 1094 if (atomic_read(idr_ref) == 0) { 1088 - mutex_lock(&dma_list_mutex); 1089 - ida_remove(&dma_ida, device->dev_id); 1090 - mutex_unlock(&dma_list_mutex); 1095 + ida_free(&dma_ida, device->dev_id); 1091 1096 kfree(idr_ref); 1092 1097 return rc; 1093 1098 }
+12 -29
drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
··· 51 51 { 52 52 struct vmwgfx_gmrid_man *gman = 53 53 (struct vmwgfx_gmrid_man *)man->priv; 54 - int ret = 0; 55 54 int id; 56 55 57 56 mem->mm_node = NULL; 57 + 58 + id = ida_alloc_max(&gman->gmr_ida, gman->max_gmr_ids - 1, GFP_KERNEL); 59 + if (id < 0) 60 + return id; 58 61 59 62 spin_lock(&gman->lock); 60 63 61 64 if (gman->max_gmr_pages > 0) { 62 65 gman->used_gmr_pages += bo->num_pages; 63 66 if (unlikely(gman->used_gmr_pages > gman->max_gmr_pages)) 64 - goto out_err_locked; 67 + goto nospace; 65 68 } 66 69 67 - do { 68 - spin_unlock(&gman->lock); 69 - if (unlikely(ida_pre_get(&gman->gmr_ida, GFP_KERNEL) == 0)) { 70 - ret = -ENOMEM; 71 - goto out_err; 72 - } 73 - spin_lock(&gman->lock); 74 - 75 - ret = ida_get_new(&gman->gmr_ida, &id); 76 - if (unlikely(ret == 0 && id >= gman->max_gmr_ids)) { 77 - ida_remove(&gman->gmr_ida, id); 78 - ret = 0; 79 - goto out_err_locked; 80 - } 81 - } while (ret == -EAGAIN); 82 - 83 - if (likely(ret == 0)) { 84 - mem->mm_node = gman; 85 - mem->start = id; 86 - mem->num_pages = bo->num_pages; 87 - } else 88 - goto out_err_locked; 70 + mem->mm_node = gman; 71 + mem->start = id; 72 + mem->num_pages = bo->num_pages; 89 73 90 74 spin_unlock(&gman->lock); 91 75 return 0; 92 76 93 - out_err: 94 - spin_lock(&gman->lock); 95 - out_err_locked: 77 + nospace: 96 78 gman->used_gmr_pages -= bo->num_pages; 97 79 spin_unlock(&gman->lock); 98 - return ret; 80 + ida_free(&gman->gmr_ida, id); 81 + return 0; 99 82 } 100 83 101 84 static void vmw_gmrid_man_put_node(struct ttm_mem_type_manager *man, ··· 88 105 (struct vmwgfx_gmrid_man *)man->priv; 89 106 90 107 if (mem->mm_node) { 108 + ida_free(&gman->gmr_ida, mem->start); 91 109 spin_lock(&gman->lock); 92 - ida_remove(&gman->gmr_ida, mem->start); 93 110 gman->used_gmr_pages -= mem->num_pages; 94 111 spin_unlock(&gman->lock); 95 112 mem->mm_node = NULL;
+5 -11
drivers/media/media-device.c
··· 585 585 entity->num_links = 0; 586 586 entity->num_backlinks = 0; 587 587 588 - if (!ida_pre_get(&mdev->entity_internal_idx, GFP_KERNEL)) 589 - return -ENOMEM; 588 + ret = ida_alloc_min(&mdev->entity_internal_idx, 1, GFP_KERNEL); 589 + if (ret < 0) 590 + return ret; 591 + entity->internal_idx = ret; 590 592 591 593 mutex_lock(&mdev->graph_mutex); 592 - 593 - ret = ida_get_new_above(&mdev->entity_internal_idx, 1, 594 - &entity->internal_idx); 595 - if (ret < 0) { 596 - mutex_unlock(&mdev->graph_mutex); 597 - return ret; 598 - } 599 - 600 594 mdev->entity_internal_idx_max = 601 595 max(mdev->entity_internal_idx_max, entity->internal_idx); 602 596 ··· 636 642 struct media_interface *intf; 637 643 unsigned int i; 638 644 639 - ida_simple_remove(&mdev->entity_internal_idx, entity->internal_idx); 645 + ida_free(&mdev->entity_internal_idx, entity->internal_idx); 640 646 641 647 /* Remove all interface links pointing to this entity */ 642 648 list_for_each_entry(intf, &mdev->interfaces, graph_obj.list) {
+5 -18
drivers/misc/cb710/core.c
··· 16 16 #include <linux/gfp.h> 17 17 18 18 static DEFINE_IDA(cb710_ida); 19 - static DEFINE_SPINLOCK(cb710_ida_lock); 20 19 21 20 void cb710_pci_update_config_reg(struct pci_dev *pdev, 22 21 int reg, uint32_t mask, uint32_t xor) ··· 204 205 const struct pci_device_id *ent) 205 206 { 206 207 struct cb710_chip *chip; 207 - unsigned long flags; 208 208 u32 val; 209 209 int err; 210 210 int n = 0; ··· 254 256 if (err) 255 257 return err; 256 258 257 - do { 258 - if (!ida_pre_get(&cb710_ida, GFP_KERNEL)) 259 - return -ENOMEM; 260 - 261 - spin_lock_irqsave(&cb710_ida_lock, flags); 262 - err = ida_get_new(&cb710_ida, &chip->platform_id); 263 - spin_unlock_irqrestore(&cb710_ida_lock, flags); 264 - 265 - if (err && err != -EAGAIN) 266 - return err; 267 - } while (err); 268 - 259 + err = ida_alloc(&cb710_ida, GFP_KERNEL); 260 + if (err < 0) 261 + return err; 262 + chip->platform_id = err; 269 263 270 264 dev_info(&pdev->dev, "id %d, IO 0x%p, IRQ %d\n", 271 265 chip->platform_id, chip->iobase, pdev->irq); ··· 298 308 static void cb710_remove_one(struct pci_dev *pdev) 299 309 { 300 310 struct cb710_chip *chip = pci_get_drvdata(pdev); 301 - unsigned long flags; 302 311 303 312 cb710_unregister_slot(chip, CB710_SLOT_SM); 304 313 cb710_unregister_slot(chip, CB710_SLOT_MS); ··· 306 317 BUG_ON(atomic_read(&chip->slot_refs_count) != 0); 307 318 #endif 308 319 309 - spin_lock_irqsave(&cb710_ida_lock, flags); 310 - ida_remove(&cb710_ida, chip->platform_id); 311 - spin_unlock_irqrestore(&cb710_ida_lock, flags); 320 + ida_free(&cb710_ida, chip->platform_id); 312 321 } 313 322 314 323 static const struct pci_device_id cb710_pci_tbl[] = {
+7 -15
drivers/scsi/osd/osd_uld.c
··· 423 423 if (scsi_device->type != TYPE_OSD) 424 424 return -ENODEV; 425 425 426 - do { 427 - if (!ida_pre_get(&osd_minor_ida, GFP_KERNEL)) 428 - return -ENODEV; 429 - 430 - error = ida_get_new(&osd_minor_ida, &minor); 431 - } while (error == -EAGAIN); 432 - 433 - if (error) 434 - return error; 435 - if (minor >= SCSI_OSD_MAX_MINOR) { 436 - error = -EBUSY; 437 - goto err_retract_minor; 438 - } 426 + minor = ida_alloc_max(&osd_minor_ida, SCSI_OSD_MAX_MINOR, GFP_KERNEL); 427 + if (minor == -ENOSPC) 428 + return -EBUSY; 429 + if (minor < 0) 430 + return -ENODEV; 439 431 440 432 error = -ENOMEM; 441 433 oud = kzalloc(sizeof(*oud), GFP_KERNEL); ··· 491 499 err_free_osd: 492 500 put_device(&oud->class_dev); 493 501 err_retract_minor: 494 - ida_remove(&osd_minor_ida, minor); 502 + ida_free(&osd_minor_ida, minor); 495 503 return error; 496 504 } 497 505 ··· 506 514 } 507 515 508 516 cdev_device_del(&oud->cdev, &oud->class_dev); 509 - ida_remove(&osd_minor_ida, oud->minor); 517 + ida_free(&osd_minor_ida, oud->minor); 510 518 put_device(&oud->class_dev); 511 519 512 520 return 0;
+4 -17
drivers/scsi/sd.c
··· 123 123 static void sd_print_sense_hdr(struct scsi_disk *, struct scsi_sense_hdr *); 124 124 static void sd_print_result(const struct scsi_disk *, const char *, int); 125 125 126 - static DEFINE_SPINLOCK(sd_index_lock); 127 126 static DEFINE_IDA(sd_index_ida); 128 127 129 128 /* This semaphore is used to mediate the 0->1 reference get in the ··· 3339 3340 if (!gd) 3340 3341 goto out_free; 3341 3342 3342 - do { 3343 - if (!ida_pre_get(&sd_index_ida, GFP_KERNEL)) 3344 - goto out_put; 3345 - 3346 - spin_lock(&sd_index_lock); 3347 - error = ida_get_new(&sd_index_ida, &index); 3348 - spin_unlock(&sd_index_lock); 3349 - } while (error == -EAGAIN); 3350 - 3351 - if (error) { 3343 + index = ida_alloc(&sd_index_ida, GFP_KERNEL); 3344 + if (index < 0) { 3352 3345 sdev_printk(KERN_WARNING, sdp, "sd_probe: memory exhausted.\n"); 3353 3346 goto out_put; 3354 3347 } ··· 3384 3393 return 0; 3385 3394 3386 3395 out_free_index: 3387 - spin_lock(&sd_index_lock); 3388 - ida_remove(&sd_index_ida, index); 3389 - spin_unlock(&sd_index_lock); 3396 + ida_free(&sd_index_ida, index); 3390 3397 out_put: 3391 3398 put_disk(gd); 3392 3399 out_free: ··· 3449 3460 struct scsi_disk *sdkp = to_scsi_disk(dev); 3450 3461 struct gendisk *disk = sdkp->disk; 3451 3462 3452 - spin_lock(&sd_index_lock); 3453 - ida_remove(&sd_index_ida, sdkp->index); 3454 - spin_unlock(&sd_index_lock); 3463 + ida_free(&sd_index_ida, sdkp->index); 3455 3464 3456 3465 disk->private_data = NULL; 3457 3466 put_disk(disk);
+2 -8
drivers/target/iscsi/iscsi_target.c
··· 57 57 static DEFINE_MUTEX(np_lock); 58 58 59 59 static struct idr tiqn_idr; 60 - struct idr sess_idr; 60 + DEFINE_IDA(sess_ida); 61 61 struct mutex auth_id_lock; 62 - spinlock_t sess_idr_lock; 63 62 64 63 struct iscsit_global *iscsit_global; 65 64 ··· 699 700 700 701 spin_lock_init(&iscsit_global->ts_bitmap_lock); 701 702 mutex_init(&auth_id_lock); 702 - spin_lock_init(&sess_idr_lock); 703 703 idr_init(&tiqn_idr); 704 - idr_init(&sess_idr); 705 704 706 705 ret = target_register_template(&iscsi_ops); 707 706 if (ret) ··· 4372 4375 pr_debug("Decremented number of active iSCSI Sessions on" 4373 4376 " iSCSI TPG: %hu to %u\n", tpg->tpgt, tpg->nsessions); 4374 4377 4375 - spin_lock(&sess_idr_lock); 4376 - idr_remove(&sess_idr, sess->session_index); 4377 - spin_unlock(&sess_idr_lock); 4378 - 4378 + ida_free(&sess_ida, sess->session_index); 4379 4379 kfree(sess->sess_ops); 4380 4380 sess->sess_ops = NULL; 4381 4381 spin_unlock_bh(&se_tpg->session_lock);
+1 -3
drivers/target/iscsi/iscsi_target.h
··· 55 55 extern struct kmem_cache *lio_qr_cache; 56 56 extern struct kmem_cache *lio_r2t_cache; 57 57 58 - extern struct idr sess_idr; 58 + extern struct ida sess_ida; 59 59 extern struct mutex auth_id_lock; 60 - extern spinlock_t sess_idr_lock; 61 - 62 60 63 61 #endif /*** ISCSI_TARGET_H ***/
+18 -23
drivers/target/iscsi/iscsi_target_login.c
··· 336 336 timer_setup(&sess->time2retain_timer, 337 337 iscsit_handle_time2retain_timeout, 0); 338 338 339 - idr_preload(GFP_KERNEL); 340 - spin_lock_bh(&sess_idr_lock); 341 - ret = idr_alloc(&sess_idr, NULL, 0, 0, GFP_NOWAIT); 342 - if (ret >= 0) 343 - sess->session_index = ret; 344 - spin_unlock_bh(&sess_idr_lock); 345 - idr_preload_end(); 346 - 339 + ret = ida_alloc(&sess_ida, GFP_KERNEL); 347 340 if (ret < 0) { 348 - pr_err("idr_alloc() for sess_idr failed\n"); 341 + pr_err("Session ID allocation failed %d\n", ret); 349 342 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, 350 343 ISCSI_LOGIN_STATUS_NO_RESOURCES); 351 - kfree(sess); 352 - return -ENOMEM; 344 + goto free_sess; 353 345 } 354 346 347 + sess->session_index = ret; 355 348 sess->creation_time = get_jiffies_64(); 356 349 /* 357 350 * The FFP CmdSN window values will be allocated from the TPG's ··· 358 365 ISCSI_LOGIN_STATUS_NO_RESOURCES); 359 366 pr_err("Unable to allocate memory for" 360 367 " struct iscsi_sess_ops.\n"); 361 - kfree(sess); 362 - return -ENOMEM; 368 + goto free_id; 363 369 } 364 370 365 371 sess->se_sess = transport_alloc_session(TARGET_PROT_NORMAL); 366 372 if (IS_ERR(sess->se_sess)) { 367 373 iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, 368 374 ISCSI_LOGIN_STATUS_NO_RESOURCES); 369 - kfree(sess->sess_ops); 370 - kfree(sess); 371 - return -ENOMEM; 375 + goto free_ops; 372 376 } 373 377 374 378 return 0; 379 + 380 + free_ops: 381 + kfree(sess->sess_ops); 382 + free_id: 383 + ida_free(&sess_ida, sess->session_index); 384 + free_sess: 385 + kfree(sess); 386 + conn->sess = NULL; 387 + return -ENOMEM; 375 388 } 376 389 377 390 static int iscsi_login_zero_tsih_s2( ··· 1160 1161 ISCSI_LOGIN_STATUS_INIT_ERR); 1161 1162 if (!zero_tsih || !conn->sess) 1162 1163 goto old_sess_out; 1163 - if (conn->sess->se_sess) 1164 - transport_free_session(conn->sess->se_sess); 1165 - if (conn->sess->session_index != 0) { 1166 - spin_lock_bh(&sess_idr_lock); 1167 - idr_remove(&sess_idr, conn->sess->session_index); 1168 - spin_unlock_bh(&sess_idr_lock); 1169 - } 1164 + 1165 + transport_free_session(conn->sess->se_sess); 1166 + ida_free(&sess_ida, conn->sess->session_index); 1170 1167 kfree(conn->sess->sess_ops); 1171 1168 kfree(conn->sess); 1172 1169 conn->sess = NULL;
+12 -33
fs/devpts/inode.c
··· 46 46 static int pty_reserve = NR_UNIX98_PTY_RESERVE; 47 47 static int pty_limit_min; 48 48 static int pty_limit_max = INT_MAX; 49 - static int pty_count; 49 + static atomic_t pty_count = ATOMIC_INIT(0); 50 50 51 51 static struct ctl_table pty_table[] = { 52 52 { ··· 92 92 }, 93 93 {} 94 94 }; 95 - 96 - static DEFINE_MUTEX(allocated_ptys_lock); 97 95 98 96 struct pts_mount_opts { 99 97 int setuid; ··· 531 533 532 534 int devpts_new_index(struct pts_fs_info *fsi) 533 535 { 534 - int index; 535 - int ida_ret; 536 + int index = -ENOSPC; 536 537 537 - retry: 538 - if (!ida_pre_get(&fsi->allocated_ptys, GFP_KERNEL)) 539 - return -ENOMEM; 538 + if (atomic_inc_return(&pty_count) >= (pty_limit - 539 + (fsi->mount_opts.reserve ? 0 : pty_reserve))) 540 + goto out; 540 541 541 - mutex_lock(&allocated_ptys_lock); 542 - if (pty_count >= (pty_limit - 543 - (fsi->mount_opts.reserve ? 0 : pty_reserve))) { 544 - mutex_unlock(&allocated_ptys_lock); 545 - return -ENOSPC; 546 - } 542 + index = ida_alloc_max(&fsi->allocated_ptys, fsi->mount_opts.max - 1, 543 + GFP_KERNEL); 547 544 548 - ida_ret = ida_get_new(&fsi->allocated_ptys, &index); 549 - if (ida_ret < 0) { 550 - mutex_unlock(&allocated_ptys_lock); 551 - if (ida_ret == -EAGAIN) 552 - goto retry; 553 - return -EIO; 554 - } 555 - 556 - if (index >= fsi->mount_opts.max) { 557 - ida_remove(&fsi->allocated_ptys, index); 558 - mutex_unlock(&allocated_ptys_lock); 559 - return -ENOSPC; 560 - } 561 - pty_count++; 562 - mutex_unlock(&allocated_ptys_lock); 545 + out: 546 + if (index < 0) 547 + atomic_dec(&pty_count); 563 548 return index; 564 549 } 565 550 566 551 void devpts_kill_index(struct pts_fs_info *fsi, int idx) 567 552 { 568 - mutex_lock(&allocated_ptys_lock); 569 - ida_remove(&fsi->allocated_ptys, idx); 570 - pty_count--; 571 - mutex_unlock(&allocated_ptys_lock); 553 + ida_free(&fsi->allocated_ptys, idx); 554 + atomic_dec(&pty_count); 572 555 } 573 556 574 557 /**
+12 -38
fs/namespace.c
··· 61 61 static u64 event; 62 62 static DEFINE_IDA(mnt_id_ida); 63 63 static DEFINE_IDA(mnt_group_ida); 64 - static DEFINE_SPINLOCK(mnt_id_lock); 65 - static int mnt_id_start = 0; 66 - static int mnt_group_start = 1; 67 64 68 65 static struct hlist_head *mount_hashtable __read_mostly; 69 66 static struct hlist_head *mountpoint_hashtable __read_mostly; ··· 98 101 99 102 static int mnt_alloc_id(struct mount *mnt) 100 103 { 101 - int res; 104 + int res = ida_alloc(&mnt_id_ida, GFP_KERNEL); 102 105 103 - retry: 104 - ida_pre_get(&mnt_id_ida, GFP_KERNEL); 105 - spin_lock(&mnt_id_lock); 106 - res = ida_get_new_above(&mnt_id_ida, mnt_id_start, &mnt->mnt_id); 107 - if (!res) 108 - mnt_id_start = mnt->mnt_id + 1; 109 - spin_unlock(&mnt_id_lock); 110 - if (res == -EAGAIN) 111 - goto retry; 112 - 113 - return res; 106 + if (res < 0) 107 + return res; 108 + mnt->mnt_id = res; 109 + return 0; 114 110 } 115 111 116 112 static void mnt_free_id(struct mount *mnt) 117 113 { 118 - int id = mnt->mnt_id; 119 - spin_lock(&mnt_id_lock); 120 - ida_remove(&mnt_id_ida, id); 121 - if (mnt_id_start > id) 122 - mnt_id_start = id; 123 - spin_unlock(&mnt_id_lock); 114 + ida_free(&mnt_id_ida, mnt->mnt_id); 124 115 } 125 116 126 117 /* 127 118 * Allocate a new peer group ID 128 - * 129 - * mnt_group_ida is protected by namespace_sem 130 119 */ 131 120 static int mnt_alloc_group_id(struct mount *mnt) 132 121 { 133 - int res; 122 + int res = ida_alloc_min(&mnt_group_ida, 1, GFP_KERNEL); 134 123 135 - if (!ida_pre_get(&mnt_group_ida, GFP_KERNEL)) 136 - return -ENOMEM; 137 - 138 - res = ida_get_new_above(&mnt_group_ida, 139 - mnt_group_start, 140 - &mnt->mnt_group_id); 141 - if (!res) 142 - mnt_group_start = mnt->mnt_group_id + 1; 143 - 144 - return res; 124 + if (res < 0) 125 + return res; 126 + mnt->mnt_group_id = res; 127 + return 0; 145 128 } 146 129 147 130 /* ··· 129 152 */ 130 153 void mnt_release_group_id(struct mount *mnt) 131 154 { 132 - int id = mnt->mnt_group_id; 133 - ida_remove(&mnt_group_ida, id); 134 - if (mnt_group_start > id) 135 - mnt_group_start = id; 155 + ida_free(&mnt_group_ida, mnt->mnt_group_id); 136 156 mnt->mnt_group_id = 0; 137 157 } 138 158
+23 -42
fs/super.c
··· 981 981 } 982 982 } 983 983 984 - /* 985 - * Unnamed block devices are dummy devices used by virtual 986 - * filesystems which don't use real block-devices. -- jrs 987 - */ 988 - 989 984 static DEFINE_IDA(unnamed_dev_ida); 990 - static DEFINE_SPINLOCK(unnamed_dev_lock);/* protects the above */ 991 - /* Many userspace utilities consider an FSID of 0 invalid. 992 - * Always return at least 1 from get_anon_bdev. 993 - */ 994 - static int unnamed_dev_start = 1; 995 985 986 + /** 987 + * get_anon_bdev - Allocate a block device for filesystems which don't have one. 988 + * @p: Pointer to a dev_t. 989 + * 990 + * Filesystems which don't use real block devices can call this function 991 + * to allocate a virtual block device. 992 + * 993 + * Context: Any context. Frequently called while holding sb_lock. 994 + * Return: 0 on success, -EMFILE if there are no anonymous bdevs left 995 + * or -ENOMEM if memory allocation failed. 996 + */ 996 997 int get_anon_bdev(dev_t *p) 997 998 { 998 999 int dev; 999 - int error; 1000 1000 1001 - retry: 1002 - if (ida_pre_get(&unnamed_dev_ida, GFP_ATOMIC) == 0) 1003 - return -ENOMEM; 1004 - spin_lock(&unnamed_dev_lock); 1005 - error = ida_get_new_above(&unnamed_dev_ida, unnamed_dev_start, &dev); 1006 - if (!error) 1007 - unnamed_dev_start = dev + 1; 1008 - spin_unlock(&unnamed_dev_lock); 1009 - if (error == -EAGAIN) 1010 - /* We raced and lost with another CPU. */ 1011 - goto retry; 1012 - else if (error) 1013 - return -EAGAIN; 1001 + /* 1002 + * Many userspace utilities consider an FSID of 0 invalid. 1003 + * Always return at least 1 from get_anon_bdev. 1004 + */ 1005 + dev = ida_alloc_range(&unnamed_dev_ida, 1, (1 << MINORBITS) - 1, 1006 + GFP_ATOMIC); 1007 + if (dev == -ENOSPC) 1008 + dev = -EMFILE; 1009 + if (dev < 0) 1010 + return dev; 1014 1011 1015 - if (dev >= (1 << MINORBITS)) { 1016 - spin_lock(&unnamed_dev_lock); 1017 - ida_remove(&unnamed_dev_ida, dev); 1018 - if (unnamed_dev_start > dev) 1019 - unnamed_dev_start = dev; 1020 - spin_unlock(&unnamed_dev_lock); 1021 - return -EMFILE; 1022 - } 1023 - *p = MKDEV(0, dev & MINORMASK); 1012 + *p = MKDEV(0, dev); 1024 1013 return 0; 1025 1014 } 1026 1015 EXPORT_SYMBOL(get_anon_bdev); 1027 1016 1028 1017 void free_anon_bdev(dev_t dev) 1029 1018 { 1030 - int slot = MINOR(dev); 1031 - spin_lock(&unnamed_dev_lock); 1032 - ida_remove(&unnamed_dev_ida, slot); 1033 - if (slot < unnamed_dev_start) 1034 - unnamed_dev_start = slot; 1035 - spin_unlock(&unnamed_dev_lock); 1019 + ida_free(&unnamed_dev_ida, MINOR(dev)); 1036 1020 } 1037 1021 EXPORT_SYMBOL(free_anon_bdev); 1038 1022 ··· 1024 1040 { 1025 1041 return get_anon_bdev(&s->s_dev); 1026 1042 } 1027 - 1028 1043 EXPORT_SYMBOL(set_anon_super); 1029 1044 1030 1045 void kill_anon_super(struct super_block *sb) ··· 1032 1049 generic_shutdown_super(sb); 1033 1050 free_anon_bdev(dev); 1034 1051 } 1035 - 1036 1052 EXPORT_SYMBOL(kill_anon_super); 1037 1053 1038 1054 void kill_litter_super(struct super_block *sb) ··· 1040 1058 d_genocide(sb->s_root); 1041 1059 kill_anon_super(sb); 1042 1060 } 1043 - 1044 1061 EXPORT_SYMBOL(kill_litter_super); 1045 1062 1046 1063 static int ns_test_super(struct super_block *sb, void *data)
+57 -17
include/linux/idr.h
··· 236 236 } 237 237 #define DEFINE_IDA(name) struct ida name = IDA_INIT(name) 238 238 239 - int ida_pre_get(struct ida *ida, gfp_t gfp_mask); 240 - int ida_get_new_above(struct ida *ida, int starting_id, int *p_id); 241 - void ida_remove(struct ida *ida, int id); 239 + int ida_alloc_range(struct ida *, unsigned int min, unsigned int max, gfp_t); 240 + void ida_free(struct ida *, unsigned int id); 242 241 void ida_destroy(struct ida *ida); 243 242 244 - int ida_simple_get(struct ida *ida, unsigned int start, unsigned int end, 245 - gfp_t gfp_mask); 246 - void ida_simple_remove(struct ida *ida, unsigned int id); 243 + /** 244 + * ida_alloc() - Allocate an unused ID. 245 + * @ida: IDA handle. 246 + * @gfp: Memory allocation flags. 247 + * 248 + * Allocate an ID between 0 and %INT_MAX, inclusive. 249 + * 250 + * Context: Any context. 251 + * Return: The allocated ID, or %-ENOMEM if memory could not be allocated, 252 + * or %-ENOSPC if there are no free IDs. 253 + */ 254 + static inline int ida_alloc(struct ida *ida, gfp_t gfp) 255 + { 256 + return ida_alloc_range(ida, 0, ~0, gfp); 257 + } 258 + 259 + /** 260 + * ida_alloc_min() - Allocate an unused ID. 261 + * @ida: IDA handle. 262 + * @min: Lowest ID to allocate. 263 + * @gfp: Memory allocation flags. 264 + * 265 + * Allocate an ID between @min and %INT_MAX, inclusive. 266 + * 267 + * Context: Any context. 268 + * Return: The allocated ID, or %-ENOMEM if memory could not be allocated, 269 + * or %-ENOSPC if there are no free IDs. 270 + */ 271 + static inline int ida_alloc_min(struct ida *ida, unsigned int min, gfp_t gfp) 272 + { 273 + return ida_alloc_range(ida, min, ~0, gfp); 274 + } 275 + 276 + /** 277 + * ida_alloc_max() - Allocate an unused ID. 278 + * @ida: IDA handle. 279 + * @max: Highest ID to allocate. 280 + * @gfp: Memory allocation flags. 281 + * 282 + * Allocate an ID between 0 and @max, inclusive. 283 + * 284 + * Context: Any context. 285 + * Return: The allocated ID, or %-ENOMEM if memory could not be allocated, 286 + * or %-ENOSPC if there are no free IDs. 287 + */ 288 + static inline int ida_alloc_max(struct ida *ida, unsigned int max, gfp_t gfp) 289 + { 290 + return ida_alloc_range(ida, 0, max, gfp); 291 + } 247 292 248 293 static inline void ida_init(struct ida *ida) 249 294 { 250 295 INIT_RADIX_TREE(&ida->ida_rt, IDR_RT_MARKER | GFP_NOWAIT); 251 296 } 252 297 253 - /** 254 - * ida_get_new - allocate new ID 255 - * @ida: idr handle 256 - * @p_id: pointer to the allocated handle 257 - * 258 - * Simple wrapper around ida_get_new_above() w/ @starting_id of zero. 259 - */ 260 - static inline int ida_get_new(struct ida *ida, int *p_id) 261 - { 262 - return ida_get_new_above(ida, 0, p_id); 263 - } 298 + #define ida_simple_get(ida, start, end, gfp) \ 299 + ida_alloc_range(ida, start, (end) - 1, gfp) 300 + #define ida_simple_remove(ida, id) ida_free(ida, id) 264 301 265 302 static inline bool ida_is_empty(const struct ida *ida) 266 303 { 267 304 return radix_tree_empty(&ida->ida_rt); 268 305 } 306 + 307 + /* in lib/radix-tree.c */ 308 + int ida_pre_get(struct ida *ida, gfp_t gfp_mask); 269 309 #endif /* __IDR_H__ */
+3
lib/Kconfig.debug
··· 1833 1833 This is intended to help people writing architecture-specific 1834 1834 optimized versions. If unsure, say N. 1835 1835 1836 + config TEST_IDA 1837 + tristate "Perform selftest on IDA functions" 1838 + 1836 1839 config TEST_PARMAN 1837 1840 tristate "Perform selftest on priority array manager" 1838 1841 depends on PARMAN
+1
lib/Makefile
··· 50 50 obj-$(CONFIG_TEST_FIRMWARE) += test_firmware.o 51 51 obj-$(CONFIG_TEST_SYSCTL) += test_sysctl.o 52 52 obj-$(CONFIG_TEST_HASH) += test_hash.o test_siphash.o 53 + obj-$(CONFIG_TEST_IDA) += test_ida.o 53 54 obj-$(CONFIG_TEST_KASAN) += test_kasan.o 54 55 CFLAGS_test_kasan.o += -fno-builtin 55 56 obj-$(CONFIG_TEST_UBSAN) += test_ubsan.o
+56 -99
lib/idr.c
··· 317 317 * bit per ID, and so is more space efficient than an IDR. To use an IDA, 318 318 * define it using DEFINE_IDA() (or embed a &struct ida in a data structure, 319 319 * then initialise it using ida_init()). To allocate a new ID, call 320 - * ida_simple_get(). To free an ID, call ida_simple_remove(). 320 + * ida_alloc(), ida_alloc_min(), ida_alloc_max() or ida_alloc_range(). 321 + * To free an ID, call ida_free(). 321 322 * 322 - * If you have more complex locking requirements, use a loop around 323 - * ida_pre_get() and ida_get_new() to allocate a new ID. Then use 324 - * ida_remove() to free an ID. You must make sure that ida_get_new() and 325 - * ida_remove() cannot be called at the same time as each other for the 326 - * same IDA. 327 - * 328 - * You can also use ida_get_new_above() if you need an ID to be allocated 329 - * above a particular number. ida_destroy() can be used to dispose of an 330 - * IDA without needing to free the individual IDs in it. You can use 331 - * ida_is_empty() to find out whether the IDA has any IDs currently allocated. 323 + * ida_destroy() can be used to dispose of an IDA without needing to 324 + * free the individual IDs in it. You can use ida_is_empty() to find 325 + * out whether the IDA has any IDs currently allocated. 332 326 * 333 327 * IDs are currently limited to the range [0-INT_MAX]. If this is an awkward 334 328 * limitation, it should be quite straightforward to raise the maximum. ··· 363 369 364 370 #define IDA_MAX (0x80000000U / IDA_BITMAP_BITS - 1) 365 371 366 - /** 367 - * ida_get_new_above - allocate new ID above or equal to a start id 368 - * @ida: ida handle 369 - * @start: id to start search at 370 - * @id: pointer to the allocated handle 371 - * 372 - * Allocate new ID above or equal to @start. It should be called 373 - * with any required locks to ensure that concurrent calls to 374 - * ida_get_new_above() / ida_get_new() / ida_remove() are not allowed. 375 - * Consider using ida_simple_get() if you do not have complex locking 376 - * requirements. 377 - * 378 - * If memory is required, it will return %-EAGAIN, you should unlock 379 - * and go back to the ida_pre_get() call. If the ida is full, it will 380 - * return %-ENOSPC. On success, it will return 0. 381 - * 382 - * @id returns a value in the range @start ... %0x7fffffff. 383 - */ 384 - int ida_get_new_above(struct ida *ida, int start, int *id) 372 + static int ida_get_new_above(struct ida *ida, int start) 385 373 { 386 374 struct radix_tree_root *root = &ida->ida_rt; 387 375 void __rcu **slot; ··· 402 426 if (ebit < BITS_PER_LONG) { 403 427 tmp |= 1UL << ebit; 404 428 rcu_assign_pointer(*slot, (void *)tmp); 405 - *id = new + ebit - RADIX_TREE_EXCEPTIONAL_SHIFT; 406 - return 0; 429 + return new + ebit - 430 + RADIX_TREE_EXCEPTIONAL_SHIFT; 407 431 } 408 432 bitmap = this_cpu_xchg(ida_bitmap, NULL); 409 433 if (!bitmap) ··· 434 458 RADIX_TREE_EXCEPTIONAL_ENTRY); 435 459 radix_tree_iter_replace(root, &iter, slot, 436 460 bitmap); 437 - *id = new; 438 - return 0; 461 + return new; 439 462 } 440 463 bitmap = this_cpu_xchg(ida_bitmap, NULL); 441 464 if (!bitmap) ··· 443 468 radix_tree_iter_replace(root, &iter, slot, bitmap); 444 469 } 445 470 446 - *id = new; 447 - return 0; 471 + return new; 448 472 } 449 473 } 450 - EXPORT_SYMBOL(ida_get_new_above); 451 474 452 - /** 453 - * ida_remove - Free the given ID 454 - * @ida: ida handle 455 - * @id: ID to free 456 - * 457 - * This function should not be called at the same time as ida_get_new_above(). 458 - */ 459 - void ida_remove(struct ida *ida, int id) 475 + static void ida_remove(struct ida *ida, int id) 460 476 { 461 477 unsigned long index = id / IDA_BITMAP_BITS; 462 478 unsigned offset = id % IDA_BITMAP_BITS; ··· 484 518 } 485 519 return; 486 520 err: 487 - WARN(1, "ida_remove called for id=%d which is not allocated.\n", id); 521 + WARN(1, "ida_free called for id=%d which is not allocated.\n", id); 488 522 } 489 - EXPORT_SYMBOL(ida_remove); 490 523 491 524 /** 492 - * ida_destroy - Free the contents of an ida 493 - * @ida: ida handle 525 + * ida_destroy() - Free all IDs. 526 + * @ida: IDA handle. 494 527 * 495 - * Calling this function releases all resources associated with an IDA. When 496 - * this call returns, the IDA is empty and can be reused or freed. The caller 497 - * should not allow ida_remove() or ida_get_new_above() to be called at the 498 - * same time. 528 + * Calling this function frees all IDs and releases all resources used 529 + * by an IDA. When this call returns, the IDA is empty and can be reused 530 + * or freed. If the IDA is already empty, there is no need to call this 531 + * function. 532 + * 533 + * Context: Any context. 499 534 */ 500 535 void ida_destroy(struct ida *ida) 501 536 { 537 + unsigned long flags; 502 538 struct radix_tree_iter iter; 503 539 void __rcu **slot; 504 540 541 + xa_lock_irqsave(&ida->ida_rt, flags); 505 542 radix_tree_for_each_slot(slot, &ida->ida_rt, &iter, 0) { 506 543 struct ida_bitmap *bitmap = rcu_dereference_raw(*slot); 507 544 if (!radix_tree_exception(bitmap)) 508 545 kfree(bitmap); 509 546 radix_tree_iter_delete(&ida->ida_rt, &iter, slot); 510 547 } 548 + xa_unlock_irqrestore(&ida->ida_rt, flags); 511 549 } 512 550 EXPORT_SYMBOL(ida_destroy); 513 551 514 552 /** 515 - * ida_simple_get - get a new id. 516 - * @ida: the (initialized) ida. 517 - * @start: the minimum id (inclusive, < 0x8000000) 518 - * @end: the maximum id (exclusive, < 0x8000000 or 0) 519 - * @gfp_mask: memory allocation flags 553 + * ida_alloc_range() - Allocate an unused ID. 554 + * @ida: IDA handle. 555 + * @min: Lowest ID to allocate. 556 + * @max: Highest ID to allocate. 557 + * @gfp: Memory allocation flags. 520 558 * 521 - * Allocates an id in the range start <= id < end, or returns -ENOSPC. 522 - * On memory allocation failure, returns -ENOMEM. 559 + * Allocate an ID between @min and @max, inclusive. The allocated ID will 560 + * not exceed %INT_MAX, even if @max is larger. 523 561 * 524 - * Compared to ida_get_new_above() this function does its own locking, and 525 - * should be used unless there are special requirements. 526 - * 527 - * Use ida_simple_remove() to get rid of an id. 562 + * Context: Any context. 563 + * Return: The allocated ID, or %-ENOMEM if memory could not be allocated, 564 + * or %-ENOSPC if there are no free IDs. 528 565 */ 529 - int ida_simple_get(struct ida *ida, unsigned int start, unsigned int end, 530 - gfp_t gfp_mask) 566 + int ida_alloc_range(struct ida *ida, unsigned int min, unsigned int max, 567 + gfp_t gfp) 531 568 { 532 - int ret, id; 533 - unsigned int max; 569 + int id = 0; 534 570 unsigned long flags; 535 571 536 - BUG_ON((int)start < 0); 537 - BUG_ON((int)end < 0); 572 + if ((int)min < 0) 573 + return -ENOSPC; 538 574 539 - if (end == 0) 540 - max = 0x80000000; 541 - else { 542 - BUG_ON(end < start); 543 - max = end - 1; 544 - } 575 + if ((int)max < 0) 576 + max = INT_MAX; 545 577 546 578 again: 547 - if (!ida_pre_get(ida, gfp_mask)) 548 - return -ENOMEM; 549 - 550 579 xa_lock_irqsave(&ida->ida_rt, flags); 551 - ret = ida_get_new_above(ida, start, &id); 552 - if (!ret) { 553 - if (id > max) { 554 - ida_remove(ida, id); 555 - ret = -ENOSPC; 556 - } else { 557 - ret = id; 558 - } 580 + id = ida_get_new_above(ida, min); 581 + if (id > (int)max) { 582 + ida_remove(ida, id); 583 + id = -ENOSPC; 559 584 } 560 585 xa_unlock_irqrestore(&ida->ida_rt, flags); 561 586 562 - if (unlikely(ret == -EAGAIN)) 587 + if (unlikely(id == -EAGAIN)) { 588 + if (!ida_pre_get(ida, gfp)) 589 + return -ENOMEM; 563 590 goto again; 591 + } 564 592 565 - return ret; 593 + return id; 566 594 } 567 - EXPORT_SYMBOL(ida_simple_get); 595 + EXPORT_SYMBOL(ida_alloc_range); 568 596 569 597 /** 570 - * ida_simple_remove - remove an allocated id. 571 - * @ida: the (initialized) ida. 572 - * @id: the id returned by ida_simple_get. 598 + * ida_free() - Release an allocated ID. 599 + * @ida: IDA handle. 600 + * @id: Previously allocated ID. 573 601 * 574 - * Use to release an id allocated with ida_simple_get(). 575 - * 576 - * Compared to ida_remove() this function does its own locking, and should be 577 - * used unless there are special requirements. 602 + * Context: Any context. 578 603 */ 579 - void ida_simple_remove(struct ida *ida, unsigned int id) 604 + void ida_free(struct ida *ida, unsigned int id) 580 605 { 581 606 unsigned long flags; 582 607 ··· 576 619 ida_remove(ida, id); 577 620 xa_unlock_irqrestore(&ida->ida_rt, flags); 578 621 } 579 - EXPORT_SYMBOL(ida_simple_remove); 622 + EXPORT_SYMBOL(ida_free);
+1 -10
lib/radix-tree.c
··· 120 120 static inline unsigned long 121 121 get_slot_offset(const struct radix_tree_node *parent, void __rcu **slot) 122 122 { 123 - return slot - parent->slots; 123 + return parent ? slot - parent->slots : 0; 124 124 } 125 125 126 126 static unsigned int radix_tree_descend(const struct radix_tree_node *parent, ··· 2106 2106 } 2107 2107 EXPORT_SYMBOL(idr_preload); 2108 2108 2109 - /** 2110 - * ida_pre_get - reserve resources for ida allocation 2111 - * @ida: ida handle 2112 - * @gfp: memory allocation flags 2113 - * 2114 - * This function should be called before calling ida_get_new_above(). If it 2115 - * is unable to allocate memory, it will return %0. On success, it returns %1. 2116 - */ 2117 2109 int ida_pre_get(struct ida *ida, gfp_t gfp) 2118 2110 { 2119 2111 /* ··· 2126 2134 2127 2135 return 1; 2128 2136 } 2129 - EXPORT_SYMBOL(ida_pre_get); 2130 2137 2131 2138 void __rcu **idr_get_free(struct radix_tree_root *root, 2132 2139 struct radix_tree_iter *iter, gfp_t gfp,
+177
lib/test_ida.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * test_ida.c: Test the IDA API 4 + * Copyright (c) 2016-2018 Microsoft Corporation 5 + * Copyright (c) 2018 Oracle Corporation 6 + * Author: Matthew Wilcox <willy@infradead.org> 7 + */ 8 + 9 + #include <linux/idr.h> 10 + #include <linux/module.h> 11 + 12 + static unsigned int tests_run; 13 + static unsigned int tests_passed; 14 + 15 + #ifdef __KERNEL__ 16 + void ida_dump(struct ida *ida) { } 17 + #endif 18 + #define IDA_BUG_ON(ida, x) do { \ 19 + tests_run++; \ 20 + if (x) { \ 21 + ida_dump(ida); \ 22 + dump_stack(); \ 23 + } else { \ 24 + tests_passed++; \ 25 + } \ 26 + } while (0) 27 + 28 + /* 29 + * Straightforward checks that allocating and freeing IDs work. 30 + */ 31 + static void ida_check_alloc(struct ida *ida) 32 + { 33 + int i, id; 34 + 35 + for (i = 0; i < 10000; i++) 36 + IDA_BUG_ON(ida, ida_alloc(ida, GFP_KERNEL) != i); 37 + 38 + ida_free(ida, 20); 39 + ida_free(ida, 21); 40 + for (i = 0; i < 3; i++) { 41 + id = ida_alloc(ida, GFP_KERNEL); 42 + IDA_BUG_ON(ida, id < 0); 43 + if (i == 2) 44 + IDA_BUG_ON(ida, id != 10000); 45 + } 46 + 47 + for (i = 0; i < 5000; i++) 48 + ida_free(ida, i); 49 + 50 + IDA_BUG_ON(ida, ida_alloc_min(ida, 5000, GFP_KERNEL) != 10001); 51 + ida_destroy(ida); 52 + 53 + IDA_BUG_ON(ida, !ida_is_empty(ida)); 54 + } 55 + 56 + /* Destroy an IDA with a single entry at @base */ 57 + static void ida_check_destroy_1(struct ida *ida, unsigned int base) 58 + { 59 + IDA_BUG_ON(ida, ida_alloc_min(ida, base, GFP_KERNEL) != base); 60 + IDA_BUG_ON(ida, ida_is_empty(ida)); 61 + ida_destroy(ida); 62 + IDA_BUG_ON(ida, !ida_is_empty(ida)); 63 + } 64 + 65 + /* Check that ida_destroy and ida_is_empty work */ 66 + static void ida_check_destroy(struct ida *ida) 67 + { 68 + /* Destroy an already-empty IDA */ 69 + IDA_BUG_ON(ida, !ida_is_empty(ida)); 70 + ida_destroy(ida); 71 + IDA_BUG_ON(ida, !ida_is_empty(ida)); 72 + 73 + ida_check_destroy_1(ida, 0); 74 + ida_check_destroy_1(ida, 1); 75 + ida_check_destroy_1(ida, 1023); 76 + ida_check_destroy_1(ida, 1024); 77 + ida_check_destroy_1(ida, 12345678); 78 + } 79 + 80 + /* 81 + * Check what happens when we fill a leaf and then delete it. This may 82 + * discover mishandling of IDR_FREE. 83 + */ 84 + static void ida_check_leaf(struct ida *ida, unsigned int base) 85 + { 86 + unsigned long i; 87 + 88 + for (i = 0; i < IDA_BITMAP_BITS; i++) { 89 + IDA_BUG_ON(ida, ida_alloc_min(ida, base, GFP_KERNEL) != 90 + base + i); 91 + } 92 + 93 + ida_destroy(ida); 94 + IDA_BUG_ON(ida, !ida_is_empty(ida)); 95 + 96 + IDA_BUG_ON(ida, ida_alloc(ida, GFP_KERNEL) != 0); 97 + IDA_BUG_ON(ida, ida_is_empty(ida)); 98 + ida_free(ida, 0); 99 + IDA_BUG_ON(ida, !ida_is_empty(ida)); 100 + } 101 + 102 + /* 103 + * Check allocations up to and slightly above the maximum allowed (2^31-1) ID. 104 + * Allocating up to 2^31-1 should succeed, and then allocating the next one 105 + * should fail. 106 + */ 107 + static void ida_check_max(struct ida *ida) 108 + { 109 + unsigned long i, j; 110 + 111 + for (j = 1; j < 65537; j *= 2) { 112 + unsigned long base = (1UL << 31) - j; 113 + for (i = 0; i < j; i++) { 114 + IDA_BUG_ON(ida, ida_alloc_min(ida, base, GFP_KERNEL) != 115 + base + i); 116 + } 117 + IDA_BUG_ON(ida, ida_alloc_min(ida, base, GFP_KERNEL) != 118 + -ENOSPC); 119 + ida_destroy(ida); 120 + IDA_BUG_ON(ida, !ida_is_empty(ida)); 121 + } 122 + } 123 + 124 + /* 125 + * Check handling of conversions between exceptional entries and full bitmaps. 126 + */ 127 + static void ida_check_conv(struct ida *ida) 128 + { 129 + unsigned long i; 130 + 131 + for (i = 0; i < IDA_BITMAP_BITS * 2; i += IDA_BITMAP_BITS) { 132 + IDA_BUG_ON(ida, ida_alloc_min(ida, i + 1, GFP_KERNEL) != i + 1); 133 + IDA_BUG_ON(ida, ida_alloc_min(ida, i + BITS_PER_LONG, 134 + GFP_KERNEL) != i + BITS_PER_LONG); 135 + ida_free(ida, i + 1); 136 + ida_free(ida, i + BITS_PER_LONG); 137 + IDA_BUG_ON(ida, !ida_is_empty(ida)); 138 + } 139 + 140 + for (i = 0; i < IDA_BITMAP_BITS * 2; i++) 141 + IDA_BUG_ON(ida, ida_alloc(ida, GFP_KERNEL) != i); 142 + for (i = IDA_BITMAP_BITS * 2; i > 0; i--) 143 + ida_free(ida, i - 1); 144 + IDA_BUG_ON(ida, !ida_is_empty(ida)); 145 + 146 + for (i = 0; i < IDA_BITMAP_BITS + BITS_PER_LONG - 4; i++) 147 + IDA_BUG_ON(ida, ida_alloc(ida, GFP_KERNEL) != i); 148 + for (i = IDA_BITMAP_BITS + BITS_PER_LONG - 4; i > 0; i--) 149 + ida_free(ida, i - 1); 150 + IDA_BUG_ON(ida, !ida_is_empty(ida)); 151 + } 152 + 153 + static int ida_checks(void) 154 + { 155 + DEFINE_IDA(ida); 156 + 157 + IDA_BUG_ON(&ida, !ida_is_empty(&ida)); 158 + ida_check_alloc(&ida); 159 + ida_check_destroy(&ida); 160 + ida_check_leaf(&ida, 0); 161 + ida_check_leaf(&ida, 1024); 162 + ida_check_leaf(&ida, 1024 * 64); 163 + ida_check_max(&ida); 164 + ida_check_conv(&ida); 165 + 166 + printk("IDA: %u of %u tests passed\n", tests_passed, tests_run); 167 + return (tests_run != tests_passed) ? 0 : -EINVAL; 168 + } 169 + 170 + static void ida_exit(void) 171 + { 172 + } 173 + 174 + module_init(ida_checks); 175 + module_exit(ida_exit); 176 + MODULE_AUTHOR("Matthew Wilcox <willy@infradead.org>"); 177 + MODULE_LICENSE("GPL");
+6 -10
net/core/net_namespace.c
··· 1001 1001 int error; 1002 1002 1003 1003 if (ops->id) { 1004 - again: 1005 - error = ida_get_new_above(&net_generic_ids, MIN_PERNET_OPS_ID, ops->id); 1006 - if (error < 0) { 1007 - if (error == -EAGAIN) { 1008 - ida_pre_get(&net_generic_ids, GFP_KERNEL); 1009 - goto again; 1010 - } 1004 + error = ida_alloc_min(&net_generic_ids, MIN_PERNET_OPS_ID, 1005 + GFP_KERNEL); 1006 + if (error < 0) 1011 1007 return error; 1012 - } 1008 + *ops->id = error; 1013 1009 max_gen_ptrs = max(max_gen_ptrs, *ops->id + 1); 1014 1010 } 1015 1011 error = __register_pernet_operations(list, ops); 1016 1012 if (error) { 1017 1013 rcu_barrier(); 1018 1014 if (ops->id) 1019 - ida_remove(&net_generic_ids, *ops->id); 1015 + ida_free(&net_generic_ids, *ops->id); 1020 1016 } 1021 1017 1022 1018 return error; ··· 1023 1027 __unregister_pernet_operations(ops); 1024 1028 rcu_barrier(); 1025 1029 if (ops->id) 1026 - ida_remove(&net_generic_ids, *ops->id); 1030 + ida_free(&net_generic_ids, *ops->id); 1027 1031 } 1028 1032 1029 1033 /**
+4 -2
tools/testing/radix-tree/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 3 - CFLAGS += -I. -I../../include -g -O2 -Wall -D_LGPL_SOURCE -fsanitize=address 4 - LDFLAGS += -fsanitize=address 3 + CFLAGS += -I. -I../../include -g -Og -Wall -D_LGPL_SOURCE -fsanitize=address \ 4 + -fsanitize=undefined 5 + LDFLAGS += -fsanitize=address -fsanitize=undefined 5 6 LDLIBS+= -lpthread -lurcu 6 7 TARGETS = main idr-test multiorder 7 8 CORE_OFILES := radix-tree.o idr.o linux.o test.o find_bit.o ··· 22 21 23 22 main: $(OFILES) 24 23 24 + idr-test.o: ../../../lib/test_ida.c 25 25 idr-test: idr-test.o $(CORE_OFILES) 26 26 27 27 multiorder: multiorder.o $(CORE_OFILES)
+39 -175
tools/testing/radix-tree/idr-test.c
··· 309 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) 317 + void ida_dump(struct ida *); 318 + 319 + #include "../../../lib/test_ida.c" 320 + 312 321 /* 313 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 324 * The first test is for not having a bitmap available, and the second test 316 325 * is for not being able to allocate a level of the radix tree. 317 326 */ 318 327 void ida_check_nomem(void) 319 328 { 320 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 - */ 333 - void ida_check_leaf(void) 334 - { 335 - DEFINE_IDA(ida); 336 330 int id; 337 - unsigned long i; 338 331 339 - for (i = 0; i < IDA_BITMAP_BITS; i++) { 340 - assert(ida_pre_get(&ida, GFP_KERNEL)); 341 - assert(!ida_get_new(&ida, &id)); 342 - assert(id == i); 343 - } 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)); 332 + id = ida_alloc_min(&ida, 256, GFP_NOWAIT); 333 + IDA_BUG_ON(&ida, id != -ENOMEM); 334 + id = ida_alloc_min(&ida, 1UL << 30, GFP_NOWAIT); 335 + IDA_BUG_ON(&ida, id != -ENOMEM); 336 + IDA_BUG_ON(&ida, !ida_is_empty(&ida)); 353 337 } 354 338 355 339 /* 356 340 * Check handling of conversions between exceptional entries and full bitmaps. 357 341 */ 358 - void ida_check_conv(void) 342 + void ida_check_conv_user(void) 359 343 { 360 344 DEFINE_IDA(ida); 361 - int id; 362 345 unsigned long i; 363 - 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 346 399 347 radix_tree_cpu_dead(1); 400 348 for (i = 0; i < 1000000; i++) { 401 - int err = ida_get_new(&ida, &id); 402 - if (err == -EAGAIN) { 403 - assert((i % IDA_BITMAP_BITS) == (BITS_PER_LONG - 2)); 404 - assert(ida_pre_get(&ida, GFP_KERNEL)); 405 - err = ida_get_new(&ida, &id); 349 + int id = ida_alloc(&ida, GFP_NOWAIT); 350 + if (id == -ENOMEM) { 351 + IDA_BUG_ON(&ida, (i % IDA_BITMAP_BITS) != 352 + BITS_PER_LONG - 2); 353 + id = ida_alloc(&ida, GFP_KERNEL); 406 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); 410 - assert(id == i); 358 + IDA_BUG_ON(&ida, id != i); 411 359 } 412 360 ida_destroy(&ida); 413 - } 414 - 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 - */ 420 - void 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 361 } 441 362 442 363 void ida_check_random(void) 443 364 { 444 365 DEFINE_IDA(ida); 445 366 DECLARE_BITMAP(bitmap, 2048); 446 - int id, err; 447 367 unsigned int i; 448 368 time_t s = time(NULL); 449 369 ··· 374 454 int bit = i & 2047; 375 455 if (test_bit(bit, bitmap)) { 376 456 __clear_bit(bit, bitmap); 377 - ida_remove(&ida, bit); 457 + ida_free(&ida, bit); 378 458 } else { 379 459 __set_bit(bit, bitmap); 380 - do { 381 - ida_pre_get(&ida, GFP_KERNEL); 382 - err = ida_get_new_above(&ida, bit, &id); 383 - } while (err == -EAGAIN); 384 - assert(!err); 385 - assert(id == bit); 460 + IDA_BUG_ON(&ida, ida_alloc_min(&ida, bit, GFP_KERNEL) 461 + != bit); 386 462 } 387 463 } 388 464 ida_destroy(&ida); ··· 404 488 ida_destroy(&ida); 405 489 } 406 490 407 - void ida_checks(void) 491 + void user_ida_checks(void) 408 492 { 409 - DEFINE_IDA(ida); 410 - int id; 411 - unsigned long i; 412 - 413 493 radix_tree_cpu_dead(1); 494 + 414 495 ida_check_nomem(); 415 - 416 - for (i = 0; i < 10000; i++) { 417 - assert(ida_pre_get(&ida, GFP_KERNEL)); 418 - assert(!ida_get_new(&ida, &id)); 419 - assert(id == i); 420 - } 421 - 422 - ida_remove(&ida, 20); 423 - ida_remove(&ida, 21); 424 - for (i = 0; i < 3; i++) { 425 - assert(ida_pre_get(&ida, GFP_KERNEL)); 426 - assert(!ida_get_new(&ida, &id)); 427 - if (i == 2) 428 - assert(id == 10000); 429 - } 430 - 431 - for (i = 0; i < 5000; i++) 432 - ida_remove(&ida, i); 433 - 434 - assert(ida_pre_get(&ida, GFP_KERNEL)); 435 - assert(!ida_get_new_above(&ida, 5000, &id)); 436 - assert(id == 10001); 437 - 438 - ida_destroy(&ida); 439 - 440 - assert(ida_is_empty(&ida)); 441 - 442 - assert(ida_pre_get(&ida, GFP_KERNEL)); 443 - assert(!ida_get_new_above(&ida, 1, &id)); 444 - assert(id == 1); 445 - 446 - ida_remove(&ida, id); 447 - assert(ida_is_empty(&ida)); 448 - ida_destroy(&ida); 449 - assert(ida_is_empty(&ida)); 450 - 451 - assert(ida_pre_get(&ida, GFP_KERNEL)); 452 - assert(!ida_get_new_above(&ida, 1, &id)); 453 - ida_destroy(&ida); 454 - assert(ida_is_empty(&ida)); 455 - 456 - assert(ida_pre_get(&ida, GFP_KERNEL)); 457 - assert(!ida_get_new_above(&ida, 1, &id)); 458 - assert(id == 1); 459 - assert(ida_pre_get(&ida, GFP_KERNEL)); 460 - assert(!ida_get_new_above(&ida, 1025, &id)); 461 - assert(id == 1025); 462 - assert(ida_pre_get(&ida, GFP_KERNEL)); 463 - assert(!ida_get_new_above(&ida, 10000, &id)); 464 - assert(id == 10000); 465 - ida_remove(&ida, 1025); 466 - ida_destroy(&ida); 467 - assert(ida_is_empty(&ida)); 468 - 469 - ida_check_leaf(); 470 - ida_check_max(); 471 - ida_check_conv(); 496 + ida_check_conv_user(); 472 497 ida_check_random(); 473 498 ida_simple_get_remove_test(); 474 499 ··· 439 582 pthread_join(threads[i], NULL); 440 583 } 441 584 585 + void ida_tests(void) 586 + { 587 + user_ida_checks(); 588 + ida_checks(); 589 + ida_exit(); 590 + ida_thread_tests(); 591 + } 592 + 442 593 int __weak main(void) 443 594 { 444 595 radix_tree_init(); 445 596 idr_checks(); 446 - ida_checks(); 447 - ida_thread_tests(); 597 + ida_tests(); 448 598 radix_tree_cpu_dead(1); 449 599 rcu_barrier(); 450 600 if (nr_allocated)
+2
tools/testing/radix-tree/linux/xarray.h
··· 1 + #include "generated/map-shift.h" 2 + #include "../../../../include/linux/xarray.h"
+12 -11
tools/testing/radix-tree/main.c
··· 27 27 item_check_present(&tree, middle + idx); 28 28 item_check_absent(&tree, middle + up); 29 29 30 - item_gang_check_present(&tree, middle - down, 31 - up + down, chunk, hop); 32 - item_full_scan(&tree, middle - down, down + up, chunk); 30 + if (chunk > 0) { 31 + item_gang_check_present(&tree, middle - down, up + down, 32 + chunk, hop); 33 + item_full_scan(&tree, middle - down, down + up, chunk); 34 + } 33 35 item_kill_tree(&tree); 34 36 } 35 37 36 38 void gang_check(void) 37 39 { 38 - __gang_check(1 << 30, 128, 128, 35, 2); 39 - __gang_check(1 << 31, 128, 128, 32, 32); 40 - __gang_check(1 << 31, 128, 128, 32, 100); 41 - __gang_check(1 << 31, 128, 128, 17, 7); 42 - __gang_check(0xffff0000, 0, 65536, 17, 7); 43 - __gang_check(0xfffffffe, 1, 1, 17, 7); 40 + __gang_check(1UL << 30, 128, 128, 35, 2); 41 + __gang_check(1UL << 31, 128, 128, 32, 32); 42 + __gang_check(1UL << 31, 128, 128, 32, 100); 43 + __gang_check(1UL << 31, 128, 128, 17, 7); 44 + __gang_check(0xffff0000UL, 0, 65536, 17, 7); 45 + __gang_check(0xfffffffeUL, 1, 1, 17, 7); 44 46 } 45 47 46 48 void __big_gang_check(void) ··· 324 322 printv(2, "after dynamic_height_check: %d allocated, preempt %d\n", 325 323 nr_allocated, preempt_count); 326 324 idr_checks(); 327 - ida_checks(); 325 + ida_tests(); 328 326 rcu_barrier(); 329 327 printv(2, "after idr_checks: %d allocated, preempt %d\n", 330 328 nr_allocated, preempt_count); ··· 371 369 iteration_test(0, 10 + 90 * long_run); 372 370 iteration_test(7, 10 + 90 * long_run); 373 371 single_thread_tests(long_run); 374 - ida_thread_tests(); 375 372 376 373 /* Free any remaining preallocated nodes */ 377 374 radix_tree_cpu_dead(0);
+1 -2
tools/testing/radix-tree/test.h
··· 39 39 void iteration_test(unsigned order, unsigned duration); 40 40 void benchmark(void); 41 41 void idr_checks(void); 42 - void ida_checks(void); 43 - void ida_thread_tests(void); 42 + void ida_tests(void); 44 43 45 44 struct item * 46 45 item_tag_set(struct radix_tree_root *root, unsigned long index, int tag);