Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'locking-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull locking updates from Ingo Molnar:
"The main changes in this cycle were:

- Implement wraparound-safe refcount_t and kref_t types based on
generic atomic primitives (Peter Zijlstra)

- Improve and fix the ww_mutex code (Nicolai Hähnle)

- Add self-tests to the ww_mutex code (Chris Wilson)

- Optimize percpu-rwsems with the 'rcuwait' mechanism (Davidlohr
Bueso)

- Micro-optimize the current-task logic all around the core kernel
(Davidlohr Bueso)

- Tidy up after recent optimizations: remove stale code and APIs,
clean up the code (Waiman Long)

- ... plus misc fixes, updates and cleanups"

* 'locking-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (50 commits)
fork: Fix task_struct alignment
locking/spinlock/debug: Remove spinlock lockup detection code
lockdep: Fix incorrect condition to print bug msgs for MAX_LOCKDEP_CHAIN_HLOCKS
lkdtm: Convert to refcount_t testing
kref: Implement 'struct kref' using refcount_t
refcount_t: Introduce a special purpose refcount type
sched/wake_q: Clarify queue reinit comment
sched/wait, rcuwait: Fix typo in comment
locking/mutex: Fix lockdep_assert_held() fail
locking/rtmutex: Flip unlikely() branch to likely() in __rt_mutex_slowlock()
locking/rwsem: Reinit wake_q after use
locking/rwsem: Remove unnecessary atomic_long_t casts
jump_labels: Move header guard #endif down where it belongs
locking/atomic, kref: Implement kref_put_lock()
locking/ww_mutex: Turn off __must_check for now
locking/atomic, kref: Avoid more abuse
locking/atomic, kref: Use kref_get_unless_zero() more
locking/atomic, kref: Kill kref_sub()
locking/atomic, kref: Add kref_read()
locking/atomic, kref: Add KREF_INIT()
...

+1872 -769
+8 -4
Documentation/locking/ww-mutex-design.txt
··· 309 309 normal mutex locks, which are far more common. As such there is only a small 310 310 increase in code size if wait/wound mutexes are not used. 311 311 312 + We maintain the following invariants for the wait list: 313 + (1) Waiters with an acquire context are sorted by stamp order; waiters 314 + without an acquire context are interspersed in FIFO order. 315 + (2) Among waiters with contexts, only the first one can have other locks 316 + acquired already (ctx->acquired > 0). Note that this waiter may come 317 + after other waiters without contexts in the list. 318 + 312 319 In general, not much contention is expected. The locks are typically used to 313 - serialize access to resources for devices. The only way to make wakeups 314 - smarter would be at the cost of adding a field to struct mutex_waiter. This 315 - would add overhead to all cases where normal mutexes are used, and 316 - ww_mutexes are generally less performance sensitive. 320 + serialize access to resources for devices. 317 321 318 322 Lockdep: 319 323 Special care has been taken to warn for as many cases of api abuse
+1 -1
arch/um/drivers/random.c
··· 76 76 add_sigio_fd(random_fd); 77 77 78 78 add_wait_queue(&host_read_wait, &wait); 79 - set_task_state(current, TASK_INTERRUPTIBLE); 79 + set_current_state(TASK_INTERRUPTIBLE); 80 80 81 81 schedule(); 82 82 remove_wait_queue(&host_read_wait, &wait);
-3
arch/x86/include/asm/spinlock.h
··· 23 23 /* How long a lock should spin before we consider blocking */ 24 24 #define SPIN_THRESHOLD (1 << 15) 25 25 26 - extern struct static_key paravirt_ticketlocks_enabled; 27 - static __always_inline bool static_key_false(struct static_key *key); 28 - 29 26 #include <asm/qspinlock.h> 30 27 31 28 /*
+1 -2
arch/x86/kernel/jump_label.c
··· 32 32 * Something went wrong. Crash the box, as something could be 33 33 * corrupting the kernel. 34 34 */ 35 - pr_warning("Unexpected op at %pS [%p] (%02x %02x %02x %02x %02x) %s:%d\n", 36 - ip, ip, ip[0], ip[1], ip[2], ip[3], ip[4], __FILE__, line); 35 + pr_crit("jump_label: Fatal kernel bug, unexpected op at %pS [%p] (%5ph) %d\n", ip, ip, ip, line); 37 36 BUG(); 38 37 } 39 38
-14
arch/x86/kernel/kvm.c
··· 620 620 } 621 621 } 622 622 623 - static __init int kvm_spinlock_init_jump(void) 624 - { 625 - if (!kvm_para_available()) 626 - return 0; 627 - if (!kvm_para_has_feature(KVM_FEATURE_PV_UNHALT)) 628 - return 0; 629 - 630 - static_key_slow_inc(&paravirt_ticketlocks_enabled); 631 - printk(KERN_INFO "KVM setup paravirtual spinlock\n"); 632 - 633 - return 0; 634 - } 635 - early_initcall(kvm_spinlock_init_jump); 636 - 637 623 #endif /* CONFIG_PARAVIRT_SPINLOCKS */
-3
arch/x86/kernel/paravirt-spinlocks.c
··· 42 42 #endif /* SMP */ 43 43 }; 44 44 EXPORT_SYMBOL(pv_lock_ops); 45 - 46 - struct static_key paravirt_ticketlocks_enabled = STATIC_KEY_INIT_FALSE; 47 - EXPORT_SYMBOL(paravirt_ticketlocks_enabled);
-19
arch/x86/xen/spinlock.c
··· 141 141 pv_lock_ops.vcpu_is_preempted = PV_CALLEE_SAVE(xen_vcpu_stolen); 142 142 } 143 143 144 - /* 145 - * While the jump_label init code needs to happend _after_ the jump labels are 146 - * enabled and before SMP is started. Hence we use pre-SMP initcall level 147 - * init. We cannot do it in xen_init_spinlocks as that is done before 148 - * jump labels are activated. 149 - */ 150 - static __init int xen_init_spinlocks_jump(void) 151 - { 152 - if (!xen_pvspin) 153 - return 0; 154 - 155 - if (!xen_domain()) 156 - return 0; 157 - 158 - static_key_slow_inc(&paravirt_ticketlocks_enabled); 159 - return 0; 160 - } 161 - early_initcall(xen_init_spinlocks_jump); 162 - 163 144 static __init int xen_parse_nopvspin(char *arg) 164 145 { 165 146 xen_pvspin = false;
+1 -1
drivers/block/drbd/drbd_bitmap.c
··· 1070 1070 .done = 0, 1071 1071 .flags = flags, 1072 1072 .error = 0, 1073 - .kref = { ATOMIC_INIT(2) }, 1073 + .kref = KREF_INIT(2), 1074 1074 }; 1075 1075 1076 1076 if (!get_ldev_if_state(device, D_ATTACHING)) { /* put is in drbd_bm_aio_ctx_destroy() */
+4 -3
drivers/block/drbd/drbd_main.c
··· 2948 2948 struct drbd_resource *resource = device->resource; 2949 2949 struct drbd_connection *connection; 2950 2950 struct drbd_peer_device *peer_device; 2951 - int refs = 3; 2952 2951 2953 2952 /* move to free_peer_device() */ 2954 2953 for_each_peer_device(peer_device, device) ··· 2955 2956 drbd_debugfs_device_cleanup(device); 2956 2957 for_each_connection(connection, resource) { 2957 2958 idr_remove(&connection->peer_devices, device->vnr); 2958 - refs++; 2959 + kref_put(&device->kref, drbd_destroy_device); 2959 2960 } 2960 2961 idr_remove(&resource->devices, device->vnr); 2962 + kref_put(&device->kref, drbd_destroy_device); 2961 2963 idr_remove(&drbd_devices, device_to_minor(device)); 2964 + kref_put(&device->kref, drbd_destroy_device); 2962 2965 del_gendisk(device->vdisk); 2963 2966 synchronize_rcu(); 2964 - kref_sub(&device->kref, refs, drbd_destroy_device); 2967 + kref_put(&device->kref, drbd_destroy_device); 2965 2968 } 2966 2969 2967 2970 static int __init drbd_init(void)
+10 -21
drivers/block/drbd/drbd_req.c
··· 421 421 struct drbd_peer_device *peer_device = first_peer_device(device); 422 422 unsigned s = req->rq_state; 423 423 int c_put = 0; 424 - int k_put = 0; 425 424 426 425 if (drbd_suspended(device) && !((s | clear) & RQ_COMPLETION_SUSP)) 427 426 set |= RQ_COMPLETION_SUSP; ··· 435 436 return; 436 437 437 438 /* intent: get references */ 439 + 440 + kref_get(&req->kref); 438 441 439 442 if (!(s & RQ_LOCAL_PENDING) && (set & RQ_LOCAL_PENDING)) 440 443 atomic_inc(&req->completion_ref); ··· 474 473 475 474 if (!(s & RQ_LOCAL_ABORTED) && (set & RQ_LOCAL_ABORTED)) { 476 475 D_ASSERT(device, req->rq_state & RQ_LOCAL_PENDING); 477 - /* local completion may still come in later, 478 - * we need to keep the req object around. */ 479 - kref_get(&req->kref); 480 476 ++c_put; 481 477 } 482 478 483 479 if ((s & RQ_LOCAL_PENDING) && (clear & RQ_LOCAL_PENDING)) { 484 480 if (req->rq_state & RQ_LOCAL_ABORTED) 485 - ++k_put; 481 + kref_put(&req->kref, drbd_req_destroy); 486 482 else 487 483 ++c_put; 488 484 list_del_init(&req->req_pending_local); ··· 501 503 if (s & RQ_NET_SENT) 502 504 atomic_sub(req->i.size >> 9, &device->ap_in_flight); 503 505 if (s & RQ_EXP_BARR_ACK) 504 - ++k_put; 506 + kref_put(&req->kref, drbd_req_destroy); 505 507 req->net_done_jif = jiffies; 506 508 507 509 /* in ahead/behind mode, or just in case, ··· 514 516 515 517 /* potentially complete and destroy */ 516 518 517 - if (k_put || c_put) { 518 - /* Completion does it's own kref_put. If we are going to 519 - * kref_sub below, we need req to be still around then. */ 520 - int at_least = k_put + !!c_put; 521 - int refcount = atomic_read(&req->kref.refcount); 522 - if (refcount < at_least) 523 - drbd_err(device, 524 - "mod_rq_state: Logic BUG: %x -> %x: refcount = %d, should be >= %d\n", 525 - s, req->rq_state, refcount, at_least); 526 - } 527 - 528 519 /* If we made progress, retry conflicting peer requests, if any. */ 529 520 if (req->i.waiting) 530 521 wake_up(&device->misc_wait); 531 522 532 - if (c_put) 533 - k_put += drbd_req_put_completion_ref(req, m, c_put); 534 - if (k_put) 535 - kref_sub(&req->kref, k_put, drbd_req_destroy); 523 + if (c_put) { 524 + if (drbd_req_put_completion_ref(req, m, c_put)) 525 + kref_put(&req->kref, drbd_req_destroy); 526 + } else { 527 + kref_put(&req->kref, drbd_req_destroy); 528 + } 536 529 } 537 530 538 531 static void drbd_report_io_error(struct drbd_device *device, struct drbd_request *req)
+4 -4
drivers/block/rbd.c
··· 1535 1535 static void rbd_obj_request_get(struct rbd_obj_request *obj_request) 1536 1536 { 1537 1537 dout("%s: obj %p (was %d)\n", __func__, obj_request, 1538 - atomic_read(&obj_request->kref.refcount)); 1538 + kref_read(&obj_request->kref)); 1539 1539 kref_get(&obj_request->kref); 1540 1540 } 1541 1541 ··· 1544 1544 { 1545 1545 rbd_assert(obj_request != NULL); 1546 1546 dout("%s: obj %p (was %d)\n", __func__, obj_request, 1547 - atomic_read(&obj_request->kref.refcount)); 1547 + kref_read(&obj_request->kref)); 1548 1548 kref_put(&obj_request->kref, rbd_obj_request_destroy); 1549 1549 } 1550 1550 1551 1551 static void rbd_img_request_get(struct rbd_img_request *img_request) 1552 1552 { 1553 1553 dout("%s: img %p (was %d)\n", __func__, img_request, 1554 - atomic_read(&img_request->kref.refcount)); 1554 + kref_read(&img_request->kref)); 1555 1555 kref_get(&img_request->kref); 1556 1556 } 1557 1557 ··· 1562 1562 { 1563 1563 rbd_assert(img_request != NULL); 1564 1564 dout("%s: img %p (was %d)\n", __func__, img_request, 1565 - atomic_read(&img_request->kref.refcount)); 1565 + kref_read(&img_request->kref)); 1566 1566 if (img_request_child_test(img_request)) 1567 1567 kref_put(&img_request->kref, rbd_parent_request_destroy); 1568 1568 else
+1 -1
drivers/block/virtio_blk.c
··· 770 770 /* Stop all the virtqueues. */ 771 771 vdev->config->reset(vdev); 772 772 773 - refc = atomic_read(&disk_to_dev(vblk->disk)->kobj.kref.refcount); 773 + refc = kref_read(&disk_to_dev(vblk->disk)->kobj.kref); 774 774 put_disk(vblk->disk); 775 775 vdev->config->del_vqs(vdev); 776 776 kfree(vblk->vqs);
+1 -1
drivers/gpu/drm/drm_gem_cma_helper.c
··· 376 376 off = drm_vma_node_start(&obj->vma_node); 377 377 378 378 seq_printf(m, "%2d (%2d) %08llx %pad %p %zu", 379 - obj->name, obj->refcount.refcount.counter, 379 + obj->name, kref_read(&obj->refcount), 380 380 off, &cma_obj->paddr, cma_obj->vaddr, obj->size); 381 381 382 382 seq_printf(m, "\n");
+1 -1
drivers/gpu/drm/drm_info.c
··· 118 118 seq_printf(m, "%6d %8zd %7d %8d\n", 119 119 obj->name, obj->size, 120 120 obj->handle_count, 121 - atomic_read(&obj->refcount.refcount)); 121 + kref_read(&obj->refcount)); 122 122 return 0; 123 123 } 124 124
+2 -2
drivers/gpu/drm/drm_mode_object.c
··· 159 159 void drm_mode_object_unreference(struct drm_mode_object *obj) 160 160 { 161 161 if (obj->free_cb) { 162 - DRM_DEBUG("OBJ ID: %d (%d)\n", obj->id, atomic_read(&obj->refcount.refcount)); 162 + DRM_DEBUG("OBJ ID: %d (%d)\n", obj->id, kref_read(&obj->refcount)); 163 163 kref_put(&obj->refcount, obj->free_cb); 164 164 } 165 165 } ··· 176 176 void drm_mode_object_reference(struct drm_mode_object *obj) 177 177 { 178 178 if (obj->free_cb) { 179 - DRM_DEBUG("OBJ ID: %d (%d)\n", obj->id, atomic_read(&obj->refcount.refcount)); 179 + DRM_DEBUG("OBJ ID: %d (%d)\n", obj->id, kref_read(&obj->refcount)); 180 180 kref_get(&obj->refcount); 181 181 } 182 182 }
+1 -1
drivers/gpu/drm/etnaviv/etnaviv_gem.c
··· 486 486 487 487 seq_printf(m, "%08x: %c %2d (%2d) %08lx %p %zd\n", 488 488 etnaviv_obj->flags, is_active(etnaviv_obj) ? 'A' : 'I', 489 - obj->name, obj->refcount.refcount.counter, 489 + obj->name, kref_read(&obj->refcount), 490 490 off, etnaviv_obj->vaddr, obj->size); 491 491 492 492 rcu_read_lock();
+1 -1
drivers/gpu/drm/i915/i915_gem_object.h
··· 256 256 static inline bool 257 257 i915_gem_object_is_dead(const struct drm_i915_gem_object *obj) 258 258 { 259 - return atomic_read(&obj->base.refcount.refcount) == 0; 259 + return kref_read(&obj->base.refcount) == 0; 260 260 } 261 261 262 262 static inline bool
+1 -1
drivers/gpu/drm/msm/msm_gem.c
··· 642 642 643 643 seq_printf(m, "%08x: %c %2d (%2d) %08llx %p\t", 644 644 msm_obj->flags, is_active(msm_obj) ? 'A' : 'I', 645 - obj->name, obj->refcount.refcount.counter, 645 + obj->name, kref_read(&obj->refcount), 646 646 off, msm_obj->vaddr); 647 647 648 648 for (id = 0; id < priv->num_aspaces; id++)
+1 -1
drivers/gpu/drm/nouveau/nouveau_fence.c
··· 527 527 * caller should have a reference on the fence, 528 528 * else fence could get freed here 529 529 */ 530 - WARN_ON(atomic_read(&fence->base.refcount.refcount) <= 1); 530 + WARN_ON(kref_read(&fence->base.refcount) <= 1); 531 531 532 532 /* 533 533 * This needs uevents to work correctly, but dma_fence_add_callback relies on
+1 -1
drivers/gpu/drm/omapdrm/omap_gem.c
··· 1033 1033 off = drm_vma_node_start(&obj->vma_node); 1034 1034 1035 1035 seq_printf(m, "%08x: %2d (%2d) %08llx %pad (%2d) %p %4d", 1036 - omap_obj->flags, obj->name, obj->refcount.refcount.counter, 1036 + omap_obj->flags, obj->name, kref_read(&obj->refcount), 1037 1037 off, &omap_obj->paddr, omap_obj->paddr_cnt, 1038 1038 omap_obj->vaddr, omap_obj->roll); 1039 1039
+18 -45
drivers/gpu/drm/ttm/ttm_bo.c
··· 140 140 struct ttm_bo_device *bdev = bo->bdev; 141 141 size_t acc_size = bo->acc_size; 142 142 143 - BUG_ON(atomic_read(&bo->list_kref.refcount)); 144 - BUG_ON(atomic_read(&bo->kref.refcount)); 143 + BUG_ON(kref_read(&bo->list_kref)); 144 + BUG_ON(kref_read(&bo->kref)); 145 145 BUG_ON(atomic_read(&bo->cpu_writers)); 146 146 BUG_ON(bo->mem.mm_node != NULL); 147 147 BUG_ON(!list_empty(&bo->lru)); ··· 181 181 } 182 182 EXPORT_SYMBOL(ttm_bo_add_to_lru); 183 183 184 - int ttm_bo_del_from_lru(struct ttm_buffer_object *bo) 184 + static void ttm_bo_ref_bug(struct kref *list_kref) 185 + { 186 + BUG(); 187 + } 188 + 189 + void ttm_bo_del_from_lru(struct ttm_buffer_object *bo) 185 190 { 186 191 struct ttm_bo_device *bdev = bo->bdev; 187 - int put_count = 0; 188 192 189 193 if (bdev->driver->lru_removal) 190 194 bdev->driver->lru_removal(bo); 191 195 192 196 if (!list_empty(&bo->swap)) { 193 197 list_del_init(&bo->swap); 194 - ++put_count; 198 + kref_put(&bo->list_kref, ttm_bo_ref_bug); 195 199 } 196 200 if (!list_empty(&bo->lru)) { 197 201 list_del_init(&bo->lru); 198 - ++put_count; 202 + kref_put(&bo->list_kref, ttm_bo_ref_bug); 199 203 } 200 - 201 - return put_count; 202 - } 203 - 204 - static void ttm_bo_ref_bug(struct kref *list_kref) 205 - { 206 - BUG(); 207 - } 208 - 209 - void ttm_bo_list_ref_sub(struct ttm_buffer_object *bo, int count, 210 - bool never_free) 211 - { 212 - kref_sub(&bo->list_kref, count, 213 - (never_free) ? ttm_bo_ref_bug : ttm_bo_release_list); 214 204 } 215 205 216 206 void ttm_bo_del_sub_from_lru(struct ttm_buffer_object *bo) 217 207 { 218 - int put_count; 219 - 220 208 spin_lock(&bo->glob->lru_lock); 221 - put_count = ttm_bo_del_from_lru(bo); 209 + ttm_bo_del_from_lru(bo); 222 210 spin_unlock(&bo->glob->lru_lock); 223 - ttm_bo_list_ref_sub(bo, put_count, true); 224 211 } 225 212 EXPORT_SYMBOL(ttm_bo_del_sub_from_lru); 226 213 227 214 void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo) 228 215 { 229 216 struct ttm_bo_device *bdev = bo->bdev; 230 - int put_count = 0; 231 217 232 218 lockdep_assert_held(&bo->resv->lock.base); 233 219 234 220 if (bdev->driver->lru_removal) 235 221 bdev->driver->lru_removal(bo); 236 222 237 - put_count = ttm_bo_del_from_lru(bo); 238 - ttm_bo_list_ref_sub(bo, put_count, true); 223 + ttm_bo_del_from_lru(bo); 239 224 ttm_bo_add_to_lru(bo); 240 225 } 241 226 EXPORT_SYMBOL(ttm_bo_move_to_lru_tail); ··· 432 447 { 433 448 struct ttm_bo_device *bdev = bo->bdev; 434 449 struct ttm_bo_global *glob = bo->glob; 435 - int put_count; 436 450 int ret; 437 451 438 452 spin_lock(&glob->lru_lock); ··· 439 455 440 456 if (!ret) { 441 457 if (!ttm_bo_wait(bo, false, true)) { 442 - put_count = ttm_bo_del_from_lru(bo); 443 - 458 + ttm_bo_del_from_lru(bo); 444 459 spin_unlock(&glob->lru_lock); 445 460 ttm_bo_cleanup_memtype_use(bo); 446 - 447 - ttm_bo_list_ref_sub(bo, put_count, true); 448 461 449 462 return; 450 463 } else ··· 485 504 bool no_wait_gpu) 486 505 { 487 506 struct ttm_bo_global *glob = bo->glob; 488 - int put_count; 489 507 int ret; 490 508 491 509 ret = ttm_bo_wait(bo, false, true); ··· 534 554 return ret; 535 555 } 536 556 537 - put_count = ttm_bo_del_from_lru(bo); 557 + ttm_bo_del_from_lru(bo); 538 558 list_del_init(&bo->ddestroy); 539 - ++put_count; 559 + kref_put(&bo->list_kref, ttm_bo_ref_bug); 540 560 541 561 spin_unlock(&glob->lru_lock); 542 562 ttm_bo_cleanup_memtype_use(bo); 543 - 544 - ttm_bo_list_ref_sub(bo, put_count, true); 545 563 546 564 return 0; 547 565 } ··· 718 740 struct ttm_bo_global *glob = bdev->glob; 719 741 struct ttm_mem_type_manager *man = &bdev->man[mem_type]; 720 742 struct ttm_buffer_object *bo; 721 - int ret = -EBUSY, put_count; 743 + int ret = -EBUSY; 722 744 723 745 spin_lock(&glob->lru_lock); 724 746 list_for_each_entry(bo, &man->lru, lru) { ··· 749 771 return ret; 750 772 } 751 773 752 - put_count = ttm_bo_del_from_lru(bo); 774 + ttm_bo_del_from_lru(bo); 753 775 spin_unlock(&glob->lru_lock); 754 776 755 777 BUG_ON(ret != 0); 756 - 757 - ttm_bo_list_ref_sub(bo, put_count, true); 758 778 759 779 ret = ttm_bo_evict(bo, interruptible, no_wait_gpu); 760 780 ttm_bo_unreserve(bo); ··· 1645 1669 container_of(shrink, struct ttm_bo_global, shrink); 1646 1670 struct ttm_buffer_object *bo; 1647 1671 int ret = -EBUSY; 1648 - int put_count; 1649 1672 uint32_t swap_placement = (TTM_PL_FLAG_CACHED | TTM_PL_FLAG_SYSTEM); 1650 1673 1651 1674 spin_lock(&glob->lru_lock); ··· 1667 1692 return ret; 1668 1693 } 1669 1694 1670 - put_count = ttm_bo_del_from_lru(bo); 1695 + ttm_bo_del_from_lru(bo); 1671 1696 spin_unlock(&glob->lru_lock); 1672 - 1673 - ttm_bo_list_ref_sub(bo, put_count, true); 1674 1697 1675 1698 /** 1676 1699 * Move to system cached
+1 -3
drivers/gpu/drm/ttm/ttm_execbuf_util.c
··· 48 48 49 49 list_for_each_entry(entry, list, head) { 50 50 struct ttm_buffer_object *bo = entry->bo; 51 - unsigned put_count = ttm_bo_del_from_lru(bo); 52 - 53 - ttm_bo_list_ref_sub(bo, put_count, true); 51 + ttm_bo_del_from_lru(bo); 54 52 } 55 53 } 56 54
+1 -1
drivers/gpu/drm/ttm/ttm_object.c
··· 304 304 * Verify that the ref->obj pointer was actually valid! 305 305 */ 306 306 rmb(); 307 - if (unlikely(atomic_read(&ref->kref.refcount) == 0)) 307 + if (unlikely(kref_read(&ref->kref) == 0)) 308 308 goto out_false; 309 309 310 310 rcu_read_unlock();
+3 -3
drivers/infiniband/hw/cxgb3/iwch_cm.h
··· 55 55 56 56 #define put_ep(ep) { \ 57 57 PDBG("put_ep (via %s:%u) ep %p refcnt %d\n", __func__, __LINE__, \ 58 - ep, atomic_read(&((ep)->kref.refcount))); \ 59 - WARN_ON(atomic_read(&((ep)->kref.refcount)) < 1); \ 58 + ep, kref_read(&((ep)->kref))); \ 59 + WARN_ON(kref_read(&((ep)->kref)) < 1); \ 60 60 kref_put(&((ep)->kref), __free_ep); \ 61 61 } 62 62 63 63 #define get_ep(ep) { \ 64 64 PDBG("get_ep (via %s:%u) ep %p, refcnt %d\n", __func__, __LINE__, \ 65 - ep, atomic_read(&((ep)->kref.refcount))); \ 65 + ep, kref_read(&((ep)->kref))); \ 66 66 kref_get(&((ep)->kref)); \ 67 67 } 68 68
+1 -1
drivers/infiniband/hw/cxgb3/iwch_qp.c
··· 961 961 case IWCH_QP_STATE_RTS: 962 962 switch (attrs->next_state) { 963 963 case IWCH_QP_STATE_CLOSING: 964 - BUG_ON(atomic_read(&qhp->ep->com.kref.refcount) < 2); 964 + BUG_ON(kref_read(&qhp->ep->com.kref) < 2); 965 965 qhp->attr.state = IWCH_QP_STATE_CLOSING; 966 966 if (!internal) { 967 967 abort=0;
+3 -3
drivers/infiniband/hw/cxgb4/iw_cxgb4.h
··· 672 672 673 673 #define c4iw_put_ep(ep) { \ 674 674 PDBG("put_ep (via %s:%u) ep %p refcnt %d\n", __func__, __LINE__, \ 675 - ep, atomic_read(&((ep)->kref.refcount))); \ 676 - WARN_ON(atomic_read(&((ep)->kref.refcount)) < 1); \ 675 + ep, kref_read(&((ep)->kref))); \ 676 + WARN_ON(kref_read(&((ep)->kref)) < 1); \ 677 677 kref_put(&((ep)->kref), _c4iw_free_ep); \ 678 678 } 679 679 680 680 #define c4iw_get_ep(ep) { \ 681 681 PDBG("get_ep (via %s:%u) ep %p, refcnt %d\n", __func__, __LINE__, \ 682 - ep, atomic_read(&((ep)->kref.refcount))); \ 682 + ep, kref_read(&((ep)->kref))); \ 683 683 kref_get(&((ep)->kref)); \ 684 684 } 685 685 void _c4iw_free_ep(struct kref *kref);
+1 -1
drivers/infiniband/hw/cxgb4/qp.c
··· 1580 1580 case C4IW_QP_STATE_RTS: 1581 1581 switch (attrs->next_state) { 1582 1582 case C4IW_QP_STATE_CLOSING: 1583 - BUG_ON(atomic_read(&qhp->ep->com.kref.refcount) < 2); 1583 + BUG_ON(kref_read(&qhp->ep->com.kref) < 2); 1584 1584 t4_set_wq_in_error(&qhp->wq); 1585 1585 set_state(qhp, C4IW_QP_STATE_CLOSING); 1586 1586 ep = qhp->ep;
+3 -3
drivers/infiniband/hw/usnic/usnic_ib_sysfs.c
··· 80 80 left = PAGE_SIZE; 81 81 82 82 mutex_lock(&us_ibdev->usdev_lock); 83 - if (atomic_read(&us_ibdev->vf_cnt.refcount) > 0) { 83 + if (kref_read(&us_ibdev->vf_cnt) > 0) { 84 84 char *busname; 85 85 86 86 /* ··· 99 99 PCI_FUNC(us_ibdev->pdev->devfn), 100 100 netdev_name(us_ibdev->netdev), 101 101 us_ibdev->ufdev->mac, 102 - atomic_read(&us_ibdev->vf_cnt.refcount)); 102 + kref_read(&us_ibdev->vf_cnt)); 103 103 UPDATE_PTR_LEFT(n, ptr, left); 104 104 105 105 for (res_type = USNIC_VNIC_RES_TYPE_EOL; ··· 147 147 us_ibdev = container_of(device, struct usnic_ib_dev, ib_dev.dev); 148 148 149 149 return scnprintf(buf, PAGE_SIZE, "%u\n", 150 - atomic_read(&us_ibdev->vf_cnt.refcount)); 150 + kref_read(&us_ibdev->vf_cnt)); 151 151 } 152 152 153 153 static ssize_t
+2 -2
drivers/infiniband/hw/usnic/usnic_ib_verbs.c
··· 291 291 qp_per_vf = max(us_ibdev->vf_res_cnt[USNIC_VNIC_RES_TYPE_WQ], 292 292 us_ibdev->vf_res_cnt[USNIC_VNIC_RES_TYPE_RQ]); 293 293 props->max_qp = qp_per_vf * 294 - atomic_read(&us_ibdev->vf_cnt.refcount); 294 + kref_read(&us_ibdev->vf_cnt); 295 295 props->device_cap_flags = IB_DEVICE_PORT_ACTIVE_EVENT | 296 296 IB_DEVICE_SYS_IMAGE_GUID | IB_DEVICE_BLOCK_MULTICAST_LOOPBACK; 297 297 props->max_cq = us_ibdev->vf_res_cnt[USNIC_VNIC_RES_TYPE_CQ] * 298 - atomic_read(&us_ibdev->vf_cnt.refcount); 298 + kref_read(&us_ibdev->vf_cnt); 299 299 props->max_pd = USNIC_UIOM_MAX_PD_CNT; 300 300 props->max_mr = USNIC_UIOM_MAX_MR_CNT; 301 301 props->local_ca_ack_delay = 0;
+1 -1
drivers/md/dm-bufio.c
··· 794 794 DECLARE_WAITQUEUE(wait, current); 795 795 796 796 add_wait_queue(&c->free_buffer_wait, &wait); 797 - set_task_state(current, TASK_UNINTERRUPTIBLE); 797 + set_current_state(TASK_UNINTERRUPTIBLE); 798 798 dm_bufio_unlock(c); 799 799 800 800 io_schedule();
+2 -2
drivers/md/dm-crypt.c
··· 1210 1210 spin_unlock_irq(&cc->write_thread_wait.lock); 1211 1211 1212 1212 if (unlikely(kthread_should_stop())) { 1213 - set_task_state(current, TASK_RUNNING); 1213 + set_current_state(TASK_RUNNING); 1214 1214 remove_wait_queue(&cc->write_thread_wait, &wait); 1215 1215 break; 1216 1216 } 1217 1217 1218 1218 schedule(); 1219 1219 1220 - set_task_state(current, TASK_RUNNING); 1220 + set_current_state(TASK_RUNNING); 1221 1221 spin_lock_irq(&cc->write_thread_wait.lock); 1222 1222 __remove_wait_queue(&cc->write_thread_wait, &wait); 1223 1223 goto continue_locked;
+2 -2
drivers/md/persistent-data/dm-block-manager.c
··· 120 120 static void __wait(struct waiter *w) 121 121 { 122 122 for (;;) { 123 - set_task_state(current, TASK_UNINTERRUPTIBLE); 123 + set_current_state(TASK_UNINTERRUPTIBLE); 124 124 125 125 if (!w->task) 126 126 break; ··· 128 128 schedule(); 129 129 } 130 130 131 - set_task_state(current, TASK_RUNNING); 131 + set_current_state(TASK_RUNNING); 132 132 } 133 133 134 134 static void __wake_waiter(struct waiter *w)
+1 -1
drivers/misc/genwqe/card_dev.c
··· 1396 1396 * application which will decrease this reference from 1397 1397 * 1/unused to 0/illegal and not from 2/used 1/empty. 1398 1398 */ 1399 - rc = atomic_read(&cd->cdev_genwqe.kobj.kref.refcount); 1399 + rc = kref_read(&cd->cdev_genwqe.kobj.kref); 1400 1400 if (rc != 1) { 1401 1401 dev_err(&pci_dev->dev, 1402 1402 "[%s] err: cdev_genwqe...refcount=%d\n", __func__, rc);
+6 -2
drivers/misc/lkdtm.h
··· 19 19 void lkdtm_HARDLOCKUP(void); 20 20 void lkdtm_SPINLOCKUP(void); 21 21 void lkdtm_HUNG_TASK(void); 22 - void lkdtm_ATOMIC_UNDERFLOW(void); 23 - void lkdtm_ATOMIC_OVERFLOW(void); 22 + void lkdtm_REFCOUNT_SATURATE_INC(void); 23 + void lkdtm_REFCOUNT_SATURATE_ADD(void); 24 + void lkdtm_REFCOUNT_ZERO_DEC(void); 25 + void lkdtm_REFCOUNT_ZERO_INC(void); 26 + void lkdtm_REFCOUNT_ZERO_SUB(void); 27 + void lkdtm_REFCOUNT_ZERO_ADD(void); 24 28 void lkdtm_CORRUPT_LIST_ADD(void); 25 29 void lkdtm_CORRUPT_LIST_DEL(void); 26 30
+73 -14
drivers/misc/lkdtm_bugs.c
··· 6 6 */ 7 7 #include "lkdtm.h" 8 8 #include <linux/list.h> 9 + #include <linux/refcount.h> 9 10 #include <linux/sched.h> 10 11 11 12 struct lkdtm_list { ··· 130 129 schedule(); 131 130 } 132 131 133 - void lkdtm_ATOMIC_UNDERFLOW(void) 132 + void lkdtm_REFCOUNT_SATURATE_INC(void) 134 133 { 135 - atomic_t under = ATOMIC_INIT(INT_MIN); 134 + refcount_t over = REFCOUNT_INIT(UINT_MAX - 1); 136 135 137 - pr_info("attempting good atomic increment\n"); 138 - atomic_inc(&under); 139 - atomic_dec(&under); 136 + pr_info("attempting good refcount decrement\n"); 137 + refcount_dec(&over); 138 + refcount_inc(&over); 140 139 141 - pr_info("attempting bad atomic underflow\n"); 142 - atomic_dec(&under); 140 + pr_info("attempting bad refcount inc overflow\n"); 141 + refcount_inc(&over); 142 + refcount_inc(&over); 143 + if (refcount_read(&over) == UINT_MAX) 144 + pr_err("Correctly stayed saturated, but no BUG?!\n"); 145 + else 146 + pr_err("Fail: refcount wrapped\n"); 143 147 } 144 148 145 - void lkdtm_ATOMIC_OVERFLOW(void) 149 + void lkdtm_REFCOUNT_SATURATE_ADD(void) 146 150 { 147 - atomic_t over = ATOMIC_INIT(INT_MAX); 151 + refcount_t over = REFCOUNT_INIT(UINT_MAX - 1); 148 152 149 - pr_info("attempting good atomic decrement\n"); 150 - atomic_dec(&over); 151 - atomic_inc(&over); 153 + pr_info("attempting good refcount decrement\n"); 154 + refcount_dec(&over); 155 + refcount_inc(&over); 152 156 153 - pr_info("attempting bad atomic overflow\n"); 154 - atomic_inc(&over); 157 + pr_info("attempting bad refcount add overflow\n"); 158 + refcount_add(2, &over); 159 + if (refcount_read(&over) == UINT_MAX) 160 + pr_err("Correctly stayed saturated, but no BUG?!\n"); 161 + else 162 + pr_err("Fail: refcount wrapped\n"); 163 + } 164 + 165 + void lkdtm_REFCOUNT_ZERO_DEC(void) 166 + { 167 + refcount_t zero = REFCOUNT_INIT(1); 168 + 169 + pr_info("attempting bad refcount decrement to zero\n"); 170 + refcount_dec(&zero); 171 + if (refcount_read(&zero) == 0) 172 + pr_err("Stayed at zero, but no BUG?!\n"); 173 + else 174 + pr_err("Fail: refcount went crazy\n"); 175 + } 176 + 177 + void lkdtm_REFCOUNT_ZERO_SUB(void) 178 + { 179 + refcount_t zero = REFCOUNT_INIT(1); 180 + 181 + pr_info("attempting bad refcount subtract past zero\n"); 182 + if (!refcount_sub_and_test(2, &zero)) 183 + pr_info("wrap attempt was noticed\n"); 184 + if (refcount_read(&zero) == 1) 185 + pr_err("Correctly stayed above 0, but no BUG?!\n"); 186 + else 187 + pr_err("Fail: refcount wrapped\n"); 188 + } 189 + 190 + void lkdtm_REFCOUNT_ZERO_INC(void) 191 + { 192 + refcount_t zero = REFCOUNT_INIT(0); 193 + 194 + pr_info("attempting bad refcount increment from zero\n"); 195 + refcount_inc(&zero); 196 + if (refcount_read(&zero) == 0) 197 + pr_err("Stayed at zero, but no BUG?!\n"); 198 + else 199 + pr_err("Fail: refcount went past zero\n"); 200 + } 201 + 202 + void lkdtm_REFCOUNT_ZERO_ADD(void) 203 + { 204 + refcount_t zero = REFCOUNT_INIT(0); 205 + 206 + pr_info("attempting bad refcount addition from zero\n"); 207 + refcount_add(2, &zero); 208 + if (refcount_read(&zero) == 0) 209 + pr_err("Stayed at zero, but no BUG?!\n"); 210 + else 211 + pr_err("Fail: refcount went past zero\n"); 155 212 } 156 213 157 214 void lkdtm_CORRUPT_LIST_ADD(void)
+6 -2
drivers/misc/lkdtm_core.c
··· 220 220 CRASHTYPE(WRITE_RO), 221 221 CRASHTYPE(WRITE_RO_AFTER_INIT), 222 222 CRASHTYPE(WRITE_KERN), 223 - CRASHTYPE(ATOMIC_UNDERFLOW), 224 - CRASHTYPE(ATOMIC_OVERFLOW), 223 + CRASHTYPE(REFCOUNT_SATURATE_INC), 224 + CRASHTYPE(REFCOUNT_SATURATE_ADD), 225 + CRASHTYPE(REFCOUNT_ZERO_DEC), 226 + CRASHTYPE(REFCOUNT_ZERO_INC), 227 + CRASHTYPE(REFCOUNT_ZERO_SUB), 228 + CRASHTYPE(REFCOUNT_ZERO_ADD), 225 229 CRASHTYPE(USERCOPY_HEAP_SIZE_TO), 226 230 CRASHTYPE(USERCOPY_HEAP_SIZE_FROM), 227 231 CRASHTYPE(USERCOPY_HEAP_FLAG_TO),
+1 -1
drivers/misc/mei/debugfs.c
··· 67 67 me_cl->props.max_number_of_connections, 68 68 me_cl->props.max_msg_length, 69 69 me_cl->props.single_recv_buf, 70 - atomic_read(&me_cl->refcnt.refcount)); 70 + kref_read(&me_cl->refcnt)); 71 71 72 72 mei_me_cl_put(me_cl); 73 73 }
+1 -1
drivers/pci/hotplug/pnv_php.c
··· 155 155 pnv_php_detach_device_nodes(dn); 156 156 157 157 of_node_put(dn); 158 - refcount = atomic_read(&dn->kobj.kref.refcount); 158 + refcount = kref_read(&dn->kobj.kref); 159 159 if (refcount != 1) 160 160 pr_warn("Invalid refcount %d on <%s>\n", 161 161 refcount, of_node_full_name(dn));
+1 -1
drivers/pci/slot.c
··· 345 345 void pci_destroy_slot(struct pci_slot *slot) 346 346 { 347 347 dev_dbg(&slot->bus->dev, "dev %02x, dec refcount to %d\n", 348 - slot->number, atomic_read(&slot->kobj.kref.refcount) - 1); 348 + slot->number, kref_read(&slot->kobj.kref) - 1); 349 349 350 350 mutex_lock(&pci_slot_mutex); 351 351 kobject_put(&slot->kobj);
+4 -4
drivers/scsi/bnx2fc/bnx2fc_io.c
··· 74 74 &io_req->req_flags)) { 75 75 /* Handle internally generated ABTS timeout */ 76 76 BNX2FC_IO_DBG(io_req, "ABTS timed out refcnt = %d\n", 77 - io_req->refcount.refcount.counter); 77 + kref_read(&io_req->refcount)); 78 78 if (!(test_and_set_bit(BNX2FC_FLAG_ABTS_DONE, 79 79 &io_req->req_flags))) { 80 80 /* ··· 1141 1141 return SUCCESS; 1142 1142 } 1143 1143 BNX2FC_IO_DBG(io_req, "eh_abort - refcnt = %d\n", 1144 - io_req->refcount.refcount.counter); 1144 + kref_read(&io_req->refcount)); 1145 1145 1146 1146 /* Hold IO request across abort processing */ 1147 1147 kref_get(&io_req->refcount); ··· 1299 1299 { 1300 1300 BNX2FC_IO_DBG(io_req, "Entered process_cleanup_compl " 1301 1301 "refcnt = %d, cmd_type = %d\n", 1302 - io_req->refcount.refcount.counter, io_req->cmd_type); 1302 + kref_read(&io_req->refcount), io_req->cmd_type); 1303 1303 bnx2fc_scsi_done(io_req, DID_ERROR); 1304 1304 kref_put(&io_req->refcount, bnx2fc_cmd_release); 1305 1305 if (io_req->wait_for_comp) ··· 1318 1318 BNX2FC_IO_DBG(io_req, "Entered process_abts_compl xid = 0x%x" 1319 1319 "refcnt = %d, cmd_type = %d\n", 1320 1320 io_req->xid, 1321 - io_req->refcount.refcount.counter, io_req->cmd_type); 1321 + kref_read(&io_req->refcount), io_req->cmd_type); 1322 1322 1323 1323 if (test_and_set_bit(BNX2FC_FLAG_ABTS_DONE, 1324 1324 &io_req->req_flags)) {
+2 -2
drivers/scsi/cxgbi/libcxgbi.h
··· 301 301 { 302 302 log_debug(1 << CXGBI_DBG_SOCK, 303 303 "%s, put csk 0x%p, ref %u-1.\n", 304 - fn, csk, atomic_read(&csk->refcnt.refcount)); 304 + fn, csk, kref_read(&csk->refcnt)); 305 305 kref_put(&csk->refcnt, cxgbi_sock_free); 306 306 } 307 307 #define cxgbi_sock_put(csk) __cxgbi_sock_put(__func__, csk) ··· 310 310 { 311 311 log_debug(1 << CXGBI_DBG_SOCK, 312 312 "%s, get csk 0x%p, ref %u+1.\n", 313 - fn, csk, atomic_read(&csk->refcnt.refcount)); 313 + fn, csk, kref_read(&csk->refcnt)); 314 314 kref_get(&csk->refcnt); 315 315 } 316 316 #define cxgbi_sock_get(csk) __cxgbi_sock_get(__func__, csk)
+1 -1
drivers/scsi/lpfc/lpfc_debugfs.c
··· 607 607 len += snprintf(buf+len, size-len, "usgmap:%x ", 608 608 ndlp->nlp_usg_map); 609 609 len += snprintf(buf+len, size-len, "refcnt:%x", 610 - atomic_read(&ndlp->kref.refcount)); 610 + kref_read(&ndlp->kref)); 611 611 len += snprintf(buf+len, size-len, "\n"); 612 612 } 613 613 spin_unlock_irq(shost->host_lock);
+1 -1
drivers/scsi/lpfc/lpfc_els.c
··· 3690 3690 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE, 3691 3691 "0006 rpi%x DID:%x flg:%x %d map:%x %p\n", 3692 3692 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, 3693 - atomic_read(&ndlp->kref.refcount), 3693 + kref_read(&ndlp->kref), 3694 3694 ndlp->nlp_usg_map, ndlp); 3695 3695 if (NLP_CHK_NODE_ACT(ndlp)) { 3696 3696 lpfc_nlp_put(ndlp);
+20 -20
drivers/scsi/lpfc/lpfc_hbadisc.c
··· 3440 3440 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, 3441 3441 "0002 rpi:%x DID:%x flg:%x %d map:%x %p\n", 3442 3442 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, 3443 - atomic_read(&ndlp->kref.refcount), 3443 + kref_read(&ndlp->kref), 3444 3444 ndlp->nlp_usg_map, ndlp); 3445 3445 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND) 3446 3446 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND; ··· 3861 3861 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, 3862 3862 "0003 rpi:%x DID:%x flg:%x %d map%x %p\n", 3863 3863 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, 3864 - atomic_read(&ndlp->kref.refcount), 3864 + kref_read(&ndlp->kref), 3865 3865 ndlp->nlp_usg_map, ndlp); 3866 3866 3867 3867 if (vport->port_state < LPFC_VPORT_READY) { ··· 4238 4238 "0277 lpfc_enable_node: ndlp:x%p " 4239 4239 "usgmap:x%x refcnt:%d\n", 4240 4240 (void *)ndlp, ndlp->nlp_usg_map, 4241 - atomic_read(&ndlp->kref.refcount)); 4241 + kref_read(&ndlp->kref)); 4242 4242 return NULL; 4243 4243 } 4244 4244 /* The ndlp should not already be in active mode */ ··· 4248 4248 "0278 lpfc_enable_node: ndlp:x%p " 4249 4249 "usgmap:x%x refcnt:%d\n", 4250 4250 (void *)ndlp, ndlp->nlp_usg_map, 4251 - atomic_read(&ndlp->kref.refcount)); 4251 + kref_read(&ndlp->kref)); 4252 4252 return NULL; 4253 4253 } 4254 4254 ··· 4272 4272 "0008 rpi:%x DID:%x flg:%x refcnt:%d " 4273 4273 "map:%x %p\n", ndlp->nlp_rpi, ndlp->nlp_DID, 4274 4274 ndlp->nlp_flag, 4275 - atomic_read(&ndlp->kref.refcount), 4275 + kref_read(&ndlp->kref), 4276 4276 ndlp->nlp_usg_map, ndlp); 4277 4277 } 4278 4278 ··· 4546 4546 (bf_get(lpfc_sli_intf_if_type, 4547 4547 &phba->sli4_hba.sli_intf) == 4548 4548 LPFC_SLI_INTF_IF_TYPE_2) && 4549 - (atomic_read(&ndlp->kref.refcount) > 0)) { 4549 + (kref_read(&ndlp->kref) > 0)) { 4550 4550 mbox->context1 = lpfc_nlp_get(ndlp); 4551 4551 mbox->mbox_cmpl = 4552 4552 lpfc_sli4_unreg_rpi_cmpl_clr; ··· 4695 4695 "0280 lpfc_cleanup_node: ndlp:x%p " 4696 4696 "usgmap:x%x refcnt:%d\n", 4697 4697 (void *)ndlp, ndlp->nlp_usg_map, 4698 - atomic_read(&ndlp->kref.refcount)); 4698 + kref_read(&ndlp->kref)); 4699 4699 lpfc_dequeue_node(vport, ndlp); 4700 4700 } else { 4701 4701 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE, 4702 4702 "0281 lpfc_cleanup_node: ndlp:x%p " 4703 4703 "usgmap:x%x refcnt:%d\n", 4704 4704 (void *)ndlp, ndlp->nlp_usg_map, 4705 - atomic_read(&ndlp->kref.refcount)); 4705 + kref_read(&ndlp->kref)); 4706 4706 lpfc_disable_node(vport, ndlp); 4707 4707 } 4708 4708 ··· 4791 4791 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE, 4792 4792 "0005 rpi:%x DID:%x flg:%x %d map:%x %p\n", 4793 4793 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, 4794 - atomic_read(&ndlp->kref.refcount), 4794 + kref_read(&ndlp->kref), 4795 4795 ndlp->nlp_usg_map, ndlp); 4796 4796 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) 4797 4797 != NULL) { ··· 5557 5557 lpfc_printf_vlog(vport, KERN_INFO, LOG_SLI, 5558 5558 "0004 rpi:%x DID:%x flg:%x %d map:%x %p\n", 5559 5559 ndlp->nlp_rpi, ndlp->nlp_DID, ndlp->nlp_flag, 5560 - atomic_read(&ndlp->kref.refcount), 5560 + kref_read(&ndlp->kref), 5561 5561 ndlp->nlp_usg_map, ndlp); 5562 5562 /* 5563 5563 * Start issuing Fabric-Device Management Interface (FDMI) command to ··· 5728 5728 "0007 rpi:%x DID:%x flg:%x refcnt:%d " 5729 5729 "map:%x %p\n", ndlp->nlp_rpi, ndlp->nlp_DID, 5730 5730 ndlp->nlp_flag, 5731 - atomic_read(&ndlp->kref.refcount), 5731 + kref_read(&ndlp->kref), 5732 5732 ndlp->nlp_usg_map, ndlp); 5733 5733 5734 5734 ndlp->active_rrqs_xri_bitmap = ··· 5767 5767 "0279 lpfc_nlp_release: ndlp:x%p did %x " 5768 5768 "usgmap:x%x refcnt:%d rpi:%x\n", 5769 5769 (void *)ndlp, ndlp->nlp_DID, ndlp->nlp_usg_map, 5770 - atomic_read(&ndlp->kref.refcount), ndlp->nlp_rpi); 5770 + kref_read(&ndlp->kref), ndlp->nlp_rpi); 5771 5771 5772 5772 /* remove ndlp from action. */ 5773 5773 lpfc_nlp_remove(ndlp->vport, ndlp); ··· 5804 5804 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, 5805 5805 "node get: did:x%x flg:x%x refcnt:x%x", 5806 5806 ndlp->nlp_DID, ndlp->nlp_flag, 5807 - atomic_read(&ndlp->kref.refcount)); 5807 + kref_read(&ndlp->kref)); 5808 5808 /* The check of ndlp usage to prevent incrementing the 5809 5809 * ndlp reference count that is in the process of being 5810 5810 * released. ··· 5817 5817 "0276 lpfc_nlp_get: ndlp:x%p " 5818 5818 "usgmap:x%x refcnt:%d\n", 5819 5819 (void *)ndlp, ndlp->nlp_usg_map, 5820 - atomic_read(&ndlp->kref.refcount)); 5820 + kref_read(&ndlp->kref)); 5821 5821 return NULL; 5822 5822 } else 5823 5823 kref_get(&ndlp->kref); ··· 5844 5844 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, 5845 5845 "node put: did:x%x flg:x%x refcnt:x%x", 5846 5846 ndlp->nlp_DID, ndlp->nlp_flag, 5847 - atomic_read(&ndlp->kref.refcount)); 5847 + kref_read(&ndlp->kref)); 5848 5848 phba = ndlp->phba; 5849 5849 spin_lock_irqsave(&phba->ndlp_lock, flags); 5850 5850 /* Check the ndlp memory free acknowledge flag to avoid the ··· 5857 5857 "0274 lpfc_nlp_put: ndlp:x%p " 5858 5858 "usgmap:x%x refcnt:%d\n", 5859 5859 (void *)ndlp, ndlp->nlp_usg_map, 5860 - atomic_read(&ndlp->kref.refcount)); 5860 + kref_read(&ndlp->kref)); 5861 5861 return 1; 5862 5862 } 5863 5863 /* Check the ndlp inactivate log flag to avoid the possible ··· 5870 5870 "0275 lpfc_nlp_put: ndlp:x%p " 5871 5871 "usgmap:x%x refcnt:%d\n", 5872 5872 (void *)ndlp, ndlp->nlp_usg_map, 5873 - atomic_read(&ndlp->kref.refcount)); 5873 + kref_read(&ndlp->kref)); 5874 5874 return 1; 5875 5875 } 5876 5876 /* For last put, mark the ndlp usage flags to make sure no ··· 5878 5878 * in between the process when the final kref_put has been 5879 5879 * invoked on this ndlp. 5880 5880 */ 5881 - if (atomic_read(&ndlp->kref.refcount) == 1) { 5881 + if (kref_read(&ndlp->kref) == 1) { 5882 5882 /* Indicate ndlp is put to inactive state. */ 5883 5883 NLP_SET_IACT_REQ(ndlp); 5884 5884 /* Acknowledge ndlp memory free has been seen. */ ··· 5906 5906 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE, 5907 5907 "node not used: did:x%x flg:x%x refcnt:x%x", 5908 5908 ndlp->nlp_DID, ndlp->nlp_flag, 5909 - atomic_read(&ndlp->kref.refcount)); 5910 - if (atomic_read(&ndlp->kref.refcount) == 1) 5909 + kref_read(&ndlp->kref)); 5910 + if (kref_read(&ndlp->kref) == 1) 5911 5911 if (lpfc_nlp_put(ndlp)) 5912 5912 return 1; 5913 5913 return 0;
+1 -2
drivers/scsi/lpfc/lpfc_init.c
··· 2660 2660 "usgmap:x%x refcnt:%d\n", 2661 2661 ndlp->nlp_DID, (void *)ndlp, 2662 2662 ndlp->nlp_usg_map, 2663 - atomic_read( 2664 - &ndlp->kref.refcount)); 2663 + kref_read(&ndlp->kref)); 2665 2664 } 2666 2665 break; 2667 2666 }
+2 -2
drivers/scsi/qla2xxx/tcm_qla2xxx.c
··· 371 371 */ 372 372 pr_debug("write_pending aborted cmd[%p] refcount %d " 373 373 "transport_state %x, t_state %x, se_cmd_flags %x\n", 374 - cmd,cmd->se_cmd.cmd_kref.refcount.counter, 374 + cmd, kref_read(&cmd->se_cmd.cmd_kref), 375 375 cmd->se_cmd.transport_state, 376 376 cmd->se_cmd.t_state, 377 377 cmd->se_cmd.se_cmd_flags); ··· 584 584 */ 585 585 pr_debug("queue_data_in aborted cmd[%p] refcount %d " 586 586 "transport_state %x, t_state %x, se_cmd_flags %x\n", 587 - cmd,cmd->se_cmd.cmd_kref.refcount.counter, 587 + cmd, kref_read(&cmd->se_cmd.cmd_kref), 588 588 cmd->se_cmd.transport_state, 589 589 cmd->se_cmd.t_state, 590 590 cmd->se_cmd.se_cmd_flags);
+1 -1
drivers/staging/android/ion/ion.c
··· 1300 1300 seq_printf(s, "%16s %16u %16zu %d %d\n", 1301 1301 buffer->task_comm, buffer->pid, 1302 1302 buffer->size, buffer->kmap_cnt, 1303 - atomic_read(&buffer->ref.refcount)); 1303 + kref_read(&buffer->ref)); 1304 1304 total_orphaned_size += buffer->size; 1305 1305 } 1306 1306 }
+1 -1
drivers/staging/comedi/comedi_buf.c
··· 188 188 { 189 189 struct comedi_buf_map *bm = s->async->buf_map; 190 190 191 - return bm && (atomic_read(&bm->refcount.refcount) > 1); 191 + return bm && (kref_read(&bm->refcount) > 1); 192 192 } 193 193 194 194 int comedi_buf_alloc(struct comedi_device *dev, struct comedi_subdevice *s,
+1 -1
drivers/staging/lustre/lnet/libcfs/linux/linux-debug.c
··· 107 107 libcfs_debug_dumplog(); 108 108 if (libcfs_panic_on_lbug) 109 109 panic("LBUG"); 110 - set_task_state(current, TASK_UNINTERRUPTIBLE); 110 + set_current_state(TASK_UNINTERRUPTIBLE); 111 111 while (1) 112 112 schedule(); 113 113 }
+5 -5
drivers/target/target_core_pr.c
··· 788 788 * __core_scsi3_add_registration() 789 789 */ 790 790 dest_lun = rcu_dereference_check(deve_tmp->se_lun, 791 - atomic_read(&deve_tmp->pr_kref.refcount) != 0); 791 + kref_read(&deve_tmp->pr_kref) != 0); 792 792 793 793 pr_reg_atp = __core_scsi3_do_alloc_registration(dev, 794 794 nacl_tmp, dest_lun, deve_tmp, ··· 1463 1463 * For nacl->dynamic_node_acl=1 1464 1464 */ 1465 1465 lun_acl = rcu_dereference_check(se_deve->se_lun_acl, 1466 - atomic_read(&se_deve->pr_kref.refcount) != 0); 1466 + kref_read(&se_deve->pr_kref) != 0); 1467 1467 if (!lun_acl) 1468 1468 return 0; 1469 1469 ··· 1478 1478 * For nacl->dynamic_node_acl=1 1479 1479 */ 1480 1480 lun_acl = rcu_dereference_check(se_deve->se_lun_acl, 1481 - atomic_read(&se_deve->pr_kref.refcount) != 0); 1481 + kref_read(&se_deve->pr_kref) != 0); 1482 1482 if (!lun_acl) { 1483 1483 kref_put(&se_deve->pr_kref, target_pr_kref_release); 1484 1484 return; ··· 1759 1759 * 2nd loop which will never fail. 1760 1760 */ 1761 1761 dest_lun = rcu_dereference_check(dest_se_deve->se_lun, 1762 - atomic_read(&dest_se_deve->pr_kref.refcount) != 0); 1762 + kref_read(&dest_se_deve->pr_kref) != 0); 1763 1763 1764 1764 dest_pr_reg = __core_scsi3_alloc_registration(cmd->se_dev, 1765 1765 dest_node_acl, dest_lun, dest_se_deve, ··· 3466 3466 iport_ptr); 3467 3467 if (!dest_pr_reg) { 3468 3468 struct se_lun *dest_lun = rcu_dereference_check(dest_se_deve->se_lun, 3469 - atomic_read(&dest_se_deve->pr_kref.refcount) != 0); 3469 + kref_read(&dest_se_deve->pr_kref) != 0); 3470 3470 3471 3471 spin_unlock(&dev->dev_reservation_lock); 3472 3472 if (core_scsi3_alloc_registration(cmd->se_dev, dest_node_acl,
+1 -1
drivers/target/tcm_fc/tfc_sess.c
··· 454 454 455 455 void ft_sess_put(struct ft_sess *sess) 456 456 { 457 - int sess_held = atomic_read(&sess->kref.refcount); 457 + int sess_held = kref_read(&sess->kref); 458 458 459 459 BUG_ON(!sess_held); 460 460 kref_put(&sess->kref, ft_sess_free);
+8 -10
drivers/tty/tty_ldsem.c
··· 200 200 down_read_failed(struct ld_semaphore *sem, long count, long timeout) 201 201 { 202 202 struct ldsem_waiter waiter; 203 - struct task_struct *tsk = current; 204 203 long adjust = -LDSEM_ACTIVE_BIAS + LDSEM_WAIT_BIAS; 205 204 206 205 /* set up my own style of waitqueue */ ··· 220 221 list_add_tail(&waiter.list, &sem->read_wait); 221 222 sem->wait_readers++; 222 223 223 - waiter.task = tsk; 224 - get_task_struct(tsk); 224 + waiter.task = current; 225 + get_task_struct(current); 225 226 226 227 /* if there are no active locks, wake the new lock owner(s) */ 227 228 if ((count & LDSEM_ACTIVE_MASK) == 0) ··· 231 232 232 233 /* wait to be given the lock */ 233 234 for (;;) { 234 - set_task_state(tsk, TASK_UNINTERRUPTIBLE); 235 + set_current_state(TASK_UNINTERRUPTIBLE); 235 236 236 237 if (!waiter.task) 237 238 break; ··· 240 241 timeout = schedule_timeout(timeout); 241 242 } 242 243 243 - __set_task_state(tsk, TASK_RUNNING); 244 + __set_current_state(TASK_RUNNING); 244 245 245 246 if (!timeout) { 246 247 /* lock timed out but check if this task was just ··· 267 268 down_write_failed(struct ld_semaphore *sem, long count, long timeout) 268 269 { 269 270 struct ldsem_waiter waiter; 270 - struct task_struct *tsk = current; 271 271 long adjust = -LDSEM_ACTIVE_BIAS; 272 272 int locked = 0; 273 273 ··· 287 289 288 290 list_add_tail(&waiter.list, &sem->write_wait); 289 291 290 - waiter.task = tsk; 292 + waiter.task = current; 291 293 292 - set_task_state(tsk, TASK_UNINTERRUPTIBLE); 294 + set_current_state(TASK_UNINTERRUPTIBLE); 293 295 for (;;) { 294 296 if (!timeout) 295 297 break; 296 298 raw_spin_unlock_irq(&sem->wait_lock); 297 299 timeout = schedule_timeout(timeout); 298 300 raw_spin_lock_irq(&sem->wait_lock); 299 - set_task_state(tsk, TASK_UNINTERRUPTIBLE); 301 + set_current_state(TASK_UNINTERRUPTIBLE); 300 302 locked = writer_trylock(sem); 301 303 if (locked) 302 304 break; ··· 307 309 list_del(&waiter.list); 308 310 raw_spin_unlock_irq(&sem->wait_lock); 309 311 310 - __set_task_state(tsk, TASK_RUNNING); 312 + __set_current_state(TASK_RUNNING); 311 313 312 314 /* lock wait may have timed out */ 313 315 if (!locked)
+1 -1
drivers/usb/gadget/function/f_fs.c
··· 3698 3698 goto done; 3699 3699 3700 3700 if (opts->no_configfs || !opts->func_inst.group.cg_item.ci_parent 3701 - || !atomic_read(&opts->func_inst.group.cg_item.ci_kref.refcount)) 3701 + || !kref_read(&opts->func_inst.group.cg_item.ci_kref)) 3702 3702 goto done; 3703 3703 3704 3704 ci = opts->func_inst.group.cg_item.ci_parent->ci_parent;
+1 -1
drivers/usb/mon/mon_main.c
··· 409 409 printk(KERN_ERR TAG 410 410 ": Outstanding opens (%d) on usb%d, leaking...\n", 411 411 mbus->nreaders, mbus->u_bus->busnum); 412 - atomic_set(&mbus->ref.refcount, 2); /* Force leak */ 412 + kref_get(&mbus->ref); /* Force leak */ 413 413 } 414 414 415 415 mon_dissolve(mbus, mbus->u_bus);
+1 -1
fs/exofs/sys.c
··· 122 122 list_for_each_entry_safe(k_name, k_tmp, &exofs_kset->list, entry) { 123 123 printk(KERN_INFO "%s: name %s ref %d\n", 124 124 __func__, kobject_name(k_name), 125 - (int)atomic_read(&k_name->kref.refcount)); 125 + (int)kref_read(&k_name->kref)); 126 126 } 127 127 #endif 128 128 }
+1 -1
fs/fuse/fuse_i.h
··· 256 256 257 257 #define FUSE_IO_PRIV_SYNC(f) \ 258 258 { \ 259 - .refcnt = { ATOMIC_INIT(1) }, \ 259 + .refcnt = KREF_INIT(1), \ 260 260 .async = 0, \ 261 261 .file = f, \ 262 262 }
+1 -1
fs/ocfs2/cluster/netdebug.c
··· 349 349 " func key: 0x%08x\n" 350 350 " func type: %u\n", 351 351 sc, 352 - atomic_read(&sc->sc_kref.refcount), 352 + kref_read(&sc->sc_kref), 353 353 &saddr, inet ? ntohs(sport) : 0, 354 354 &daddr, inet ? ntohs(dport) : 0, 355 355 sc->sc_node->nd_name,
+1 -1
fs/ocfs2/cluster/tcp.c
··· 97 97 typeof(sc) __sc = (sc); \ 98 98 mlog(ML_SOCKET, "[sc %p refs %d sock %p node %u page %p " \ 99 99 "pg_off %zu] " fmt, __sc, \ 100 - atomic_read(&__sc->sc_kref.refcount), __sc->sc_sock, \ 100 + kref_read(&__sc->sc_kref), __sc->sc_sock, \ 101 101 __sc->sc_node->nd_num, __sc->sc_page, __sc->sc_page_off , \ 102 102 ##args); \ 103 103 } while (0)
+6 -6
fs/ocfs2/dlm/dlmdebug.c
··· 81 81 lock->ml.type, lock->ml.convert_type, lock->ml.node, 82 82 dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)), 83 83 dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)), 84 - atomic_read(&lock->lock_refs.refcount), 84 + kref_read(&lock->lock_refs), 85 85 (list_empty(&lock->ast_list) ? 'y' : 'n'), 86 86 (lock->ast_pending ? 'y' : 'n'), 87 87 (list_empty(&lock->bast_list) ? 'y' : 'n'), ··· 106 106 printk("lockres: %s, owner=%u, state=%u\n", 107 107 buf, res->owner, res->state); 108 108 printk(" last used: %lu, refcnt: %u, on purge list: %s\n", 109 - res->last_used, atomic_read(&res->refs.refcount), 109 + res->last_used, kref_read(&res->refs), 110 110 list_empty(&res->purge) ? "no" : "yes"); 111 111 printk(" on dirty list: %s, on reco list: %s, " 112 112 "migrating pending: %s\n", ··· 298 298 mle_type, mle->master, mle->new_master, 299 299 !list_empty(&mle->hb_events), 300 300 !!mle->inuse, 301 - atomic_read(&mle->mle_refs.refcount)); 301 + kref_read(&mle->mle_refs)); 302 302 303 303 out += snprintf(buf + out, len - out, "Maybe="); 304 304 out += stringify_nodemap(mle->maybe_map, O2NM_MAX_NODES, ··· 494 494 lock->ast_pending, lock->bast_pending, 495 495 lock->convert_pending, lock->lock_pending, 496 496 lock->cancel_pending, lock->unlock_pending, 497 - atomic_read(&lock->lock_refs.refcount)); 497 + kref_read(&lock->lock_refs)); 498 498 spin_unlock(&lock->spinlock); 499 499 500 500 return out; ··· 521 521 !list_empty(&res->recovering), 522 522 res->inflight_locks, res->migration_pending, 523 523 atomic_read(&res->asts_reserved), 524 - atomic_read(&res->refs.refcount)); 524 + kref_read(&res->refs)); 525 525 526 526 /* refmap */ 527 527 out += snprintf(buf + out, len - out, "RMAP:"); ··· 777 777 /* Purge Count: xxx Refs: xxx */ 778 778 out += snprintf(buf + out, len - out, 779 779 "Purge Count: %d Refs: %d\n", dlm->purge_count, 780 - atomic_read(&dlm->dlm_refs.refcount)); 780 + kref_read(&dlm->dlm_refs)); 781 781 782 782 /* Dead Node: xxx */ 783 783 out += snprintf(buf + out, len - out,
+1 -1
fs/ocfs2/dlm/dlmdomain.c
··· 2072 2072 INIT_LIST_HEAD(&dlm->dlm_eviction_callbacks); 2073 2073 2074 2074 mlog(0, "context init: refcount %u\n", 2075 - atomic_read(&dlm->dlm_refs.refcount)); 2075 + kref_read(&dlm->dlm_refs)); 2076 2076 2077 2077 leave: 2078 2078 if (ret < 0 && dlm) {
+4 -4
fs/ocfs2/dlm/dlmmaster.c
··· 233 233 234 234 assert_spin_locked(&dlm->spinlock); 235 235 assert_spin_locked(&dlm->master_lock); 236 - if (!atomic_read(&mle->mle_refs.refcount)) { 236 + if (!kref_read(&mle->mle_refs)) { 237 237 /* this may or may not crash, but who cares. 238 238 * it's a BUG. */ 239 239 mlog(ML_ERROR, "bad mle: %p\n", mle); ··· 1124 1124 unsigned long timeo = msecs_to_jiffies(DLM_MASTERY_TIMEOUT_MS); 1125 1125 1126 1126 /* 1127 - if (atomic_read(&mle->mle_refs.refcount) < 2) 1127 + if (kref_read(&mle->mle_refs) < 2) 1128 1128 mlog(ML_ERROR, "mle (%p) refs=%d, name=%.*s\n", mle, 1129 - atomic_read(&mle->mle_refs.refcount), 1129 + kref_read(&mle->mle_refs), 1130 1130 res->lockname.len, res->lockname.name); 1131 1131 */ 1132 1132 atomic_set(&mle->woken, 0); ··· 1979 1979 * on this mle. */ 1980 1980 spin_lock(&dlm->master_lock); 1981 1981 1982 - rr = atomic_read(&mle->mle_refs.refcount); 1982 + rr = kref_read(&mle->mle_refs); 1983 1983 if (mle->inuse > 0) { 1984 1984 if (extra_ref && rr < 3) 1985 1985 err = 1;
+1 -1
fs/ocfs2/dlm/dlmunlock.c
··· 251 251 mlog(0, "lock %u:%llu should be gone now! refs=%d\n", 252 252 dlm_get_lock_cookie_node(be64_to_cpu(lock->ml.cookie)), 253 253 dlm_get_lock_cookie_seq(be64_to_cpu(lock->ml.cookie)), 254 - atomic_read(&lock->lock_refs.refcount)-1); 254 + kref_read(&lock->lock_refs)-1); 255 255 dlm_lock_put(lock); 256 256 } 257 257 if (actions & DLM_UNLOCK_CALL_AST)
+6 -7
include/asm-generic/rwsem.h
··· 33 33 */ 34 34 static inline void __down_read(struct rw_semaphore *sem) 35 35 { 36 - if (unlikely(atomic_long_inc_return_acquire((atomic_long_t *)&sem->count) <= 0)) 36 + if (unlikely(atomic_long_inc_return_acquire(&sem->count) <= 0)) 37 37 rwsem_down_read_failed(sem); 38 38 } 39 39 ··· 58 58 long tmp; 59 59 60 60 tmp = atomic_long_add_return_acquire(RWSEM_ACTIVE_WRITE_BIAS, 61 - (atomic_long_t *)&sem->count); 61 + &sem->count); 62 62 if (unlikely(tmp != RWSEM_ACTIVE_WRITE_BIAS)) 63 63 rwsem_down_write_failed(sem); 64 64 } ··· 68 68 long tmp; 69 69 70 70 tmp = atomic_long_add_return_acquire(RWSEM_ACTIVE_WRITE_BIAS, 71 - (atomic_long_t *)&sem->count); 71 + &sem->count); 72 72 if (unlikely(tmp != RWSEM_ACTIVE_WRITE_BIAS)) 73 73 if (IS_ERR(rwsem_down_write_failed_killable(sem))) 74 74 return -EINTR; ··· 91 91 { 92 92 long tmp; 93 93 94 - tmp = atomic_long_dec_return_release((atomic_long_t *)&sem->count); 94 + tmp = atomic_long_dec_return_release(&sem->count); 95 95 if (unlikely(tmp < -1 && (tmp & RWSEM_ACTIVE_MASK) == 0)) 96 96 rwsem_wake(sem); 97 97 } ··· 102 102 static inline void __up_write(struct rw_semaphore *sem) 103 103 { 104 104 if (unlikely(atomic_long_sub_return_release(RWSEM_ACTIVE_WRITE_BIAS, 105 - (atomic_long_t *)&sem->count) < 0)) 105 + &sem->count) < 0)) 106 106 rwsem_wake(sem); 107 107 } 108 108 ··· 120 120 * read-locked region is ok to be re-ordered into the 121 121 * write side. As such, rely on RELEASE semantics. 122 122 */ 123 - tmp = atomic_long_add_return_release(-RWSEM_WAITING_BIAS, 124 - (atomic_long_t *)&sem->count); 123 + tmp = atomic_long_add_return_release(-RWSEM_WAITING_BIAS, &sem->count); 125 124 if (tmp < 0) 126 125 rwsem_downgrade_wake(sem); 127 126 }
+1 -1
include/drm/drm_framebuffer.h
··· 247 247 */ 248 248 static inline uint32_t drm_framebuffer_read_refcount(struct drm_framebuffer *fb) 249 249 { 250 - return atomic_read(&fb->base.refcount.refcount); 250 + return kref_read(&fb->base.refcount); 251 251 } 252 252 253 253 /**
+1 -14
include/drm/ttm/ttm_bo_api.h
··· 332 332 */ 333 333 extern void ttm_bo_unref(struct ttm_buffer_object **bo); 334 334 335 - 336 - /** 337 - * ttm_bo_list_ref_sub 338 - * 339 - * @bo: The buffer object. 340 - * @count: The number of references with which to decrease @bo::list_kref; 341 - * @never_free: The refcount should not reach zero with this operation. 342 - * 343 - * Release @count lru list references to this buffer object. 344 - */ 345 - extern void ttm_bo_list_ref_sub(struct ttm_buffer_object *bo, int count, 346 - bool never_free); 347 - 348 335 /** 349 336 * ttm_bo_add_to_lru 350 337 * ··· 354 367 * and is usually called just immediately after the bo has been reserved to 355 368 * avoid recursive reservation from lru lists. 356 369 */ 357 - extern int ttm_bo_del_from_lru(struct ttm_buffer_object *bo); 370 + extern void ttm_bo_del_from_lru(struct ttm_buffer_object *bo); 358 371 359 372 /** 360 373 * ttm_bo_move_to_lru_tail
+2 -2
include/drm/ttm/ttm_bo_driver.h
··· 878 878 { 879 879 int ret; 880 880 881 - WARN_ON(!atomic_read(&bo->kref.refcount)); 881 + WARN_ON(!kref_read(&bo->kref)); 882 882 883 883 ret = __ttm_bo_reserve(bo, interruptible, no_wait, ticket); 884 884 if (likely(ret == 0)) ··· 903 903 { 904 904 int ret = 0; 905 905 906 - WARN_ON(!atomic_read(&bo->kref.refcount)); 906 + WARN_ON(!kref_read(&bo->kref)); 907 907 908 908 if (interruptible) 909 909 ret = ww_mutex_lock_slow_interruptible(&bo->resv->lock,
+2 -2
include/linux/jump_label.h
··· 402 402 #define static_branch_enable(x) static_key_enable(&(x)->key) 403 403 #define static_branch_disable(x) static_key_disable(&(x)->key) 404 404 405 - #endif /* _LINUX_JUMP_LABEL_H */ 406 - 407 405 #endif /* __ASSEMBLY__ */ 406 + 407 + #endif /* _LINUX_JUMP_LABEL_H */
+35 -49
include/linux/kref.h
··· 15 15 #ifndef _KREF_H_ 16 16 #define _KREF_H_ 17 17 18 - #include <linux/bug.h> 19 - #include <linux/atomic.h> 20 - #include <linux/kernel.h> 21 - #include <linux/mutex.h> 18 + #include <linux/spinlock.h> 19 + #include <linux/refcount.h> 22 20 23 21 struct kref { 24 - atomic_t refcount; 22 + refcount_t refcount; 25 23 }; 24 + 25 + #define KREF_INIT(n) { .refcount = REFCOUNT_INIT(n), } 26 26 27 27 /** 28 28 * kref_init - initialize object. ··· 30 30 */ 31 31 static inline void kref_init(struct kref *kref) 32 32 { 33 - atomic_set(&kref->refcount, 1); 33 + refcount_set(&kref->refcount, 1); 34 + } 35 + 36 + static inline unsigned int kref_read(const struct kref *kref) 37 + { 38 + return refcount_read(&kref->refcount); 34 39 } 35 40 36 41 /** ··· 44 39 */ 45 40 static inline void kref_get(struct kref *kref) 46 41 { 47 - /* If refcount was 0 before incrementing then we have a race 48 - * condition when this kref is freeing by some other thread right now. 49 - * In this case one should use kref_get_unless_zero() 50 - */ 51 - WARN_ON_ONCE(atomic_inc_return(&kref->refcount) < 2); 52 - } 53 - 54 - /** 55 - * kref_sub - subtract a number of refcounts for object. 56 - * @kref: object. 57 - * @count: Number of recounts to subtract. 58 - * @release: pointer to the function that will clean up the object when the 59 - * last reference to the object is released. 60 - * This pointer is required, and it is not acceptable to pass kfree 61 - * in as this function. If the caller does pass kfree to this 62 - * function, you will be publicly mocked mercilessly by the kref 63 - * maintainer, and anyone else who happens to notice it. You have 64 - * been warned. 65 - * 66 - * Subtract @count from the refcount, and if 0, call release(). 67 - * Return 1 if the object was removed, otherwise return 0. Beware, if this 68 - * function returns 0, you still can not count on the kref from remaining in 69 - * memory. Only use the return value if you want to see if the kref is now 70 - * gone, not present. 71 - */ 72 - static inline int kref_sub(struct kref *kref, unsigned int count, 73 - void (*release)(struct kref *kref)) 74 - { 75 - WARN_ON(release == NULL); 76 - 77 - if (atomic_sub_and_test((int) count, &kref->refcount)) { 78 - release(kref); 79 - return 1; 80 - } 81 - return 0; 42 + refcount_inc(&kref->refcount); 82 43 } 83 44 84 45 /** ··· 66 95 */ 67 96 static inline int kref_put(struct kref *kref, void (*release)(struct kref *kref)) 68 97 { 69 - return kref_sub(kref, 1, release); 98 + WARN_ON(release == NULL); 99 + 100 + if (refcount_dec_and_test(&kref->refcount)) { 101 + release(kref); 102 + return 1; 103 + } 104 + return 0; 70 105 } 71 106 72 107 static inline int kref_put_mutex(struct kref *kref, ··· 80 103 struct mutex *lock) 81 104 { 82 105 WARN_ON(release == NULL); 83 - if (unlikely(!atomic_add_unless(&kref->refcount, -1, 1))) { 84 - mutex_lock(lock); 85 - if (unlikely(!atomic_dec_and_test(&kref->refcount))) { 86 - mutex_unlock(lock); 87 - return 0; 88 - } 106 + 107 + if (refcount_dec_and_mutex_lock(&kref->refcount, lock)) { 108 + release(kref); 109 + return 1; 110 + } 111 + return 0; 112 + } 113 + 114 + static inline int kref_put_lock(struct kref *kref, 115 + void (*release)(struct kref *kref), 116 + spinlock_t *lock) 117 + { 118 + WARN_ON(release == NULL); 119 + 120 + if (refcount_dec_and_lock(&kref->refcount, lock)) { 89 121 release(kref); 90 122 return 1; 91 123 } ··· 119 133 */ 120 134 static inline int __must_check kref_get_unless_zero(struct kref *kref) 121 135 { 122 - return atomic_add_unless(&kref->refcount, 1, 0); 136 + return refcount_inc_not_zero(&kref->refcount); 123 137 } 124 138 #endif /* _KREF_H_ */
+4 -1
include/linux/mutex.h
··· 20 20 #include <linux/osq_lock.h> 21 21 #include <linux/debug_locks.h> 22 22 23 + struct ww_acquire_ctx; 24 + 23 25 /* 24 26 * Simple, straightforward mutexes with strict semantics: 25 27 * ··· 67 65 68 66 static inline struct task_struct *__mutex_owner(struct mutex *lock) 69 67 { 70 - return (struct task_struct *)(atomic_long_read(&lock->owner) & ~0x03); 68 + return (struct task_struct *)(atomic_long_read(&lock->owner) & ~0x07); 71 69 } 72 70 73 71 /* ··· 77 75 struct mutex_waiter { 78 76 struct list_head list; 79 77 struct task_struct *task; 78 + struct ww_acquire_ctx *ww_ctx; 80 79 #ifdef CONFIG_DEBUG_MUTEXES 81 80 void *magic; 82 81 #endif
+4 -4
include/linux/percpu-rwsem.h
··· 4 4 #include <linux/atomic.h> 5 5 #include <linux/rwsem.h> 6 6 #include <linux/percpu.h> 7 - #include <linux/wait.h> 7 + #include <linux/rcuwait.h> 8 8 #include <linux/rcu_sync.h> 9 9 #include <linux/lockdep.h> 10 10 11 11 struct percpu_rw_semaphore { 12 12 struct rcu_sync rss; 13 13 unsigned int __percpu *read_count; 14 - struct rw_semaphore rw_sem; 15 - wait_queue_head_t writer; 14 + struct rw_semaphore rw_sem; /* slowpath */ 15 + struct rcuwait writer; /* blocked writer */ 16 16 int readers_block; 17 17 }; 18 18 ··· 22 22 .rss = __RCU_SYNC_INITIALIZER(name.rss, RCU_SCHED_SYNC), \ 23 23 .read_count = &__percpu_rwsem_rc_##name, \ 24 24 .rw_sem = __RWSEM_INITIALIZER(name.rw_sem), \ 25 - .writer = __WAIT_QUEUE_HEAD_INITIALIZER(name.writer), \ 25 + .writer = __RCUWAIT_INITIALIZER(name.writer), \ 26 26 } 27 27 28 28 extern int __percpu_down_read(struct percpu_rw_semaphore *, int);
+1
include/linux/poison.h
··· 80 80 /********** kernel/mutexes **********/ 81 81 #define MUTEX_DEBUG_INIT 0x11 82 82 #define MUTEX_DEBUG_FREE 0x22 83 + #define MUTEX_POISON_WW_CTX ((void *) 0x500 + POISON_POINTER_DELTA) 83 84 84 85 /********** lib/flex_array.c **********/ 85 86 #define FLEX_ARRAY_FREE 0x6c /* for use-after-free poisoning */
+63
include/linux/rcuwait.h
··· 1 + #ifndef _LINUX_RCUWAIT_H_ 2 + #define _LINUX_RCUWAIT_H_ 3 + 4 + #include <linux/rcupdate.h> 5 + 6 + /* 7 + * rcuwait provides a way of blocking and waking up a single 8 + * task in an rcu-safe manner; where it is forbidden to use 9 + * after exit_notify(). task_struct is not properly rcu protected, 10 + * unless dealing with rcu-aware lists, ie: find_task_by_*(). 11 + * 12 + * Alternatively we have task_rcu_dereference(), but the return 13 + * semantics have different implications which would break the 14 + * wakeup side. The only time @task is non-nil is when a user is 15 + * blocked (or checking if it needs to) on a condition, and reset 16 + * as soon as we know that the condition has succeeded and are 17 + * awoken. 18 + */ 19 + struct rcuwait { 20 + struct task_struct *task; 21 + }; 22 + 23 + #define __RCUWAIT_INITIALIZER(name) \ 24 + { .task = NULL, } 25 + 26 + static inline void rcuwait_init(struct rcuwait *w) 27 + { 28 + w->task = NULL; 29 + } 30 + 31 + extern void rcuwait_wake_up(struct rcuwait *w); 32 + 33 + /* 34 + * The caller is responsible for locking around rcuwait_wait_event(), 35 + * such that writes to @task are properly serialized. 36 + */ 37 + #define rcuwait_wait_event(w, condition) \ 38 + ({ \ 39 + /* \ 40 + * Complain if we are called after do_exit()/exit_notify(), \ 41 + * as we cannot rely on the rcu critical region for the \ 42 + * wakeup side. \ 43 + */ \ 44 + WARN_ON(current->exit_state); \ 45 + \ 46 + rcu_assign_pointer((w)->task, current); \ 47 + for (;;) { \ 48 + /* \ 49 + * Implicit barrier (A) pairs with (B) in \ 50 + * rcuwait_wake_up(). \ 51 + */ \ 52 + set_current_state(TASK_UNINTERRUPTIBLE); \ 53 + if (condition) \ 54 + break; \ 55 + \ 56 + schedule(); \ 57 + } \ 58 + \ 59 + WRITE_ONCE((w)->task, NULL); \ 60 + __set_current_state(TASK_RUNNING); \ 61 + }) 62 + 63 + #endif /* _LINUX_RCUWAIT_H_ */
+294
include/linux/refcount.h
··· 1 + #ifndef _LINUX_REFCOUNT_H 2 + #define _LINUX_REFCOUNT_H 3 + 4 + /* 5 + * Variant of atomic_t specialized for reference counts. 6 + * 7 + * The interface matches the atomic_t interface (to aid in porting) but only 8 + * provides the few functions one should use for reference counting. 9 + * 10 + * It differs in that the counter saturates at UINT_MAX and will not move once 11 + * there. This avoids wrapping the counter and causing 'spurious' 12 + * use-after-free issues. 13 + * 14 + * Memory ordering rules are slightly relaxed wrt regular atomic_t functions 15 + * and provide only what is strictly required for refcounts. 16 + * 17 + * The increments are fully relaxed; these will not provide ordering. The 18 + * rationale is that whatever is used to obtain the object we're increasing the 19 + * reference count on will provide the ordering. For locked data structures, 20 + * its the lock acquire, for RCU/lockless data structures its the dependent 21 + * load. 22 + * 23 + * Do note that inc_not_zero() provides a control dependency which will order 24 + * future stores against the inc, this ensures we'll never modify the object 25 + * if we did not in fact acquire a reference. 26 + * 27 + * The decrements will provide release order, such that all the prior loads and 28 + * stores will be issued before, it also provides a control dependency, which 29 + * will order us against the subsequent free(). 30 + * 31 + * The control dependency is against the load of the cmpxchg (ll/sc) that 32 + * succeeded. This means the stores aren't fully ordered, but this is fine 33 + * because the 1->0 transition indicates no concurrency. 34 + * 35 + * Note that the allocator is responsible for ordering things between free() 36 + * and alloc(). 37 + * 38 + */ 39 + 40 + #include <linux/atomic.h> 41 + #include <linux/bug.h> 42 + #include <linux/mutex.h> 43 + #include <linux/spinlock.h> 44 + 45 + #ifdef CONFIG_DEBUG_REFCOUNT 46 + #define REFCOUNT_WARN(cond, str) WARN_ON(cond) 47 + #define __refcount_check __must_check 48 + #else 49 + #define REFCOUNT_WARN(cond, str) (void)(cond) 50 + #define __refcount_check 51 + #endif 52 + 53 + typedef struct refcount_struct { 54 + atomic_t refs; 55 + } refcount_t; 56 + 57 + #define REFCOUNT_INIT(n) { .refs = ATOMIC_INIT(n), } 58 + 59 + static inline void refcount_set(refcount_t *r, unsigned int n) 60 + { 61 + atomic_set(&r->refs, n); 62 + } 63 + 64 + static inline unsigned int refcount_read(const refcount_t *r) 65 + { 66 + return atomic_read(&r->refs); 67 + } 68 + 69 + static inline __refcount_check 70 + bool refcount_add_not_zero(unsigned int i, refcount_t *r) 71 + { 72 + unsigned int old, new, val = atomic_read(&r->refs); 73 + 74 + for (;;) { 75 + if (!val) 76 + return false; 77 + 78 + if (unlikely(val == UINT_MAX)) 79 + return true; 80 + 81 + new = val + i; 82 + if (new < val) 83 + new = UINT_MAX; 84 + old = atomic_cmpxchg_relaxed(&r->refs, val, new); 85 + if (old == val) 86 + break; 87 + 88 + val = old; 89 + } 90 + 91 + REFCOUNT_WARN(new == UINT_MAX, "refcount_t: saturated; leaking memory.\n"); 92 + 93 + return true; 94 + } 95 + 96 + static inline void refcount_add(unsigned int i, refcount_t *r) 97 + { 98 + REFCOUNT_WARN(!refcount_add_not_zero(i, r), "refcount_t: addition on 0; use-after-free.\n"); 99 + } 100 + 101 + /* 102 + * Similar to atomic_inc_not_zero(), will saturate at UINT_MAX and WARN. 103 + * 104 + * Provides no memory ordering, it is assumed the caller has guaranteed the 105 + * object memory to be stable (RCU, etc.). It does provide a control dependency 106 + * and thereby orders future stores. See the comment on top. 107 + */ 108 + static inline __refcount_check 109 + bool refcount_inc_not_zero(refcount_t *r) 110 + { 111 + unsigned int old, new, val = atomic_read(&r->refs); 112 + 113 + for (;;) { 114 + new = val + 1; 115 + 116 + if (!val) 117 + return false; 118 + 119 + if (unlikely(!new)) 120 + return true; 121 + 122 + old = atomic_cmpxchg_relaxed(&r->refs, val, new); 123 + if (old == val) 124 + break; 125 + 126 + val = old; 127 + } 128 + 129 + REFCOUNT_WARN(new == UINT_MAX, "refcount_t: saturated; leaking memory.\n"); 130 + 131 + return true; 132 + } 133 + 134 + /* 135 + * Similar to atomic_inc(), will saturate at UINT_MAX and WARN. 136 + * 137 + * Provides no memory ordering, it is assumed the caller already has a 138 + * reference on the object, will WARN when this is not so. 139 + */ 140 + static inline void refcount_inc(refcount_t *r) 141 + { 142 + REFCOUNT_WARN(!refcount_inc_not_zero(r), "refcount_t: increment on 0; use-after-free.\n"); 143 + } 144 + 145 + /* 146 + * Similar to atomic_dec_and_test(), it will WARN on underflow and fail to 147 + * decrement when saturated at UINT_MAX. 148 + * 149 + * Provides release memory ordering, such that prior loads and stores are done 150 + * before, and provides a control dependency such that free() must come after. 151 + * See the comment on top. 152 + */ 153 + static inline __refcount_check 154 + bool refcount_sub_and_test(unsigned int i, refcount_t *r) 155 + { 156 + unsigned int old, new, val = atomic_read(&r->refs); 157 + 158 + for (;;) { 159 + if (unlikely(val == UINT_MAX)) 160 + return false; 161 + 162 + new = val - i; 163 + if (new > val) { 164 + REFCOUNT_WARN(new > val, "refcount_t: underflow; use-after-free.\n"); 165 + return false; 166 + } 167 + 168 + old = atomic_cmpxchg_release(&r->refs, val, new); 169 + if (old == val) 170 + break; 171 + 172 + val = old; 173 + } 174 + 175 + return !new; 176 + } 177 + 178 + static inline __refcount_check 179 + bool refcount_dec_and_test(refcount_t *r) 180 + { 181 + return refcount_sub_and_test(1, r); 182 + } 183 + 184 + /* 185 + * Similar to atomic_dec(), it will WARN on underflow and fail to decrement 186 + * when saturated at UINT_MAX. 187 + * 188 + * Provides release memory ordering, such that prior loads and stores are done 189 + * before. 190 + */ 191 + static inline 192 + void refcount_dec(refcount_t *r) 193 + { 194 + REFCOUNT_WARN(refcount_dec_and_test(r), "refcount_t: decrement hit 0; leaking memory.\n"); 195 + } 196 + 197 + /* 198 + * No atomic_t counterpart, it attempts a 1 -> 0 transition and returns the 199 + * success thereof. 200 + * 201 + * Like all decrement operations, it provides release memory order and provides 202 + * a control dependency. 203 + * 204 + * It can be used like a try-delete operator; this explicit case is provided 205 + * and not cmpxchg in generic, because that would allow implementing unsafe 206 + * operations. 207 + */ 208 + static inline __refcount_check 209 + bool refcount_dec_if_one(refcount_t *r) 210 + { 211 + return atomic_cmpxchg_release(&r->refs, 1, 0) == 1; 212 + } 213 + 214 + /* 215 + * No atomic_t counterpart, it decrements unless the value is 1, in which case 216 + * it will return false. 217 + * 218 + * Was often done like: atomic_add_unless(&var, -1, 1) 219 + */ 220 + static inline __refcount_check 221 + bool refcount_dec_not_one(refcount_t *r) 222 + { 223 + unsigned int old, new, val = atomic_read(&r->refs); 224 + 225 + for (;;) { 226 + if (unlikely(val == UINT_MAX)) 227 + return true; 228 + 229 + if (val == 1) 230 + return false; 231 + 232 + new = val - 1; 233 + if (new > val) { 234 + REFCOUNT_WARN(new > val, "refcount_t: underflow; use-after-free.\n"); 235 + return true; 236 + } 237 + 238 + old = atomic_cmpxchg_release(&r->refs, val, new); 239 + if (old == val) 240 + break; 241 + 242 + val = old; 243 + } 244 + 245 + return true; 246 + } 247 + 248 + /* 249 + * Similar to atomic_dec_and_mutex_lock(), it will WARN on underflow and fail 250 + * to decrement when saturated at UINT_MAX. 251 + * 252 + * Provides release memory ordering, such that prior loads and stores are done 253 + * before, and provides a control dependency such that free() must come after. 254 + * See the comment on top. 255 + */ 256 + static inline __refcount_check 257 + bool refcount_dec_and_mutex_lock(refcount_t *r, struct mutex *lock) 258 + { 259 + if (refcount_dec_not_one(r)) 260 + return false; 261 + 262 + mutex_lock(lock); 263 + if (!refcount_dec_and_test(r)) { 264 + mutex_unlock(lock); 265 + return false; 266 + } 267 + 268 + return true; 269 + } 270 + 271 + /* 272 + * Similar to atomic_dec_and_lock(), it will WARN on underflow and fail to 273 + * decrement when saturated at UINT_MAX. 274 + * 275 + * Provides release memory ordering, such that prior loads and stores are done 276 + * before, and provides a control dependency such that free() must come after. 277 + * See the comment on top. 278 + */ 279 + static inline __refcount_check 280 + bool refcount_dec_and_lock(refcount_t *r, spinlock_t *lock) 281 + { 282 + if (refcount_dec_not_one(r)) 283 + return false; 284 + 285 + spin_lock(lock); 286 + if (!refcount_dec_and_test(r)) { 287 + spin_unlock(lock); 288 + return false; 289 + } 290 + 291 + return true; 292 + } 293 + 294 + #endif /* _LINUX_REFCOUNT_H */
+9 -28
include/linux/sched.h
··· 226 226 extern char ___assert_task_state[1 - 2*!!( 227 227 sizeof(TASK_STATE_TO_CHAR_STR)-1 != ilog2(TASK_STATE_MAX)+1)]; 228 228 229 - /* Convenience macros for the sake of set_task_state */ 229 + /* Convenience macros for the sake of set_current_state */ 230 230 #define TASK_KILLABLE (TASK_WAKEKILL | TASK_UNINTERRUPTIBLE) 231 231 #define TASK_STOPPED (TASK_WAKEKILL | __TASK_STOPPED) 232 232 #define TASK_TRACED (TASK_WAKEKILL | __TASK_TRACED) ··· 253 253 254 254 #ifdef CONFIG_DEBUG_ATOMIC_SLEEP 255 255 256 - #define __set_task_state(tsk, state_value) \ 257 - do { \ 258 - (tsk)->task_state_change = _THIS_IP_; \ 259 - (tsk)->state = (state_value); \ 260 - } while (0) 261 - #define set_task_state(tsk, state_value) \ 262 - do { \ 263 - (tsk)->task_state_change = _THIS_IP_; \ 264 - smp_store_mb((tsk)->state, (state_value)); \ 265 - } while (0) 266 - 267 256 #define __set_current_state(state_value) \ 268 257 do { \ 269 258 current->task_state_change = _THIS_IP_; \ ··· 265 276 } while (0) 266 277 267 278 #else 268 - 269 - /* 270 - * @tsk had better be current, or you get to keep the pieces. 271 - * 272 - * The only reason is that computing current can be more expensive than 273 - * using a pointer that's already available. 274 - * 275 - * Therefore, see set_current_state(). 276 - */ 277 - #define __set_task_state(tsk, state_value) \ 278 - do { (tsk)->state = (state_value); } while (0) 279 - #define set_task_state(tsk, state_value) \ 280 - smp_store_mb((tsk)->state, (state_value)) 281 - 282 279 /* 283 280 * set_current_state() includes a barrier so that the write of current->state 284 281 * is correctly serialised wrt the caller's subsequent test of whether to ··· 993 1018 * 994 1019 * The DEFINE_WAKE_Q macro declares and initializes the list head. 995 1020 * wake_up_q() does NOT reinitialize the list; it's expected to be 996 - * called near the end of a function, where the fact that the queue is 997 - * not used again will be easy to see by inspection. 1021 + * called near the end of a function. Otherwise, the list can be 1022 + * re-initialized for later re-use by wake_q_init(). 998 1023 * 999 1024 * Note that this can cause spurious wakeups. schedule() callers 1000 1025 * must ensure the call is done inside a loop, confirming that the ··· 1013 1038 1014 1039 #define DEFINE_WAKE_Q(name) \ 1015 1040 struct wake_q_head name = { WAKE_Q_TAIL, &name.first } 1041 + 1042 + static inline void wake_q_init(struct wake_q_head *head) 1043 + { 1044 + head->first = WAKE_Q_TAIL; 1045 + head->lastp = &head->first; 1046 + } 1016 1047 1017 1048 extern void wake_q_add(struct wake_q_head *head, 1018 1049 struct task_struct *task);
-8
include/linux/spinlock.h
··· 180 180 #ifdef CONFIG_DEBUG_LOCK_ALLOC 181 181 # define raw_spin_lock_nested(lock, subclass) \ 182 182 _raw_spin_lock_nested(lock, subclass) 183 - # define raw_spin_lock_bh_nested(lock, subclass) \ 184 - _raw_spin_lock_bh_nested(lock, subclass) 185 183 186 184 # define raw_spin_lock_nest_lock(lock, nest_lock) \ 187 185 do { \ ··· 195 197 # define raw_spin_lock_nested(lock, subclass) \ 196 198 _raw_spin_lock(((void)(subclass), (lock))) 197 199 # define raw_spin_lock_nest_lock(lock, nest_lock) _raw_spin_lock(lock) 198 - # define raw_spin_lock_bh_nested(lock, subclass) _raw_spin_lock_bh(lock) 199 200 #endif 200 201 201 202 #if defined(CONFIG_SMP) || defined(CONFIG_DEBUG_SPINLOCK) ··· 312 315 #define spin_lock_nested(lock, subclass) \ 313 316 do { \ 314 317 raw_spin_lock_nested(spinlock_check(lock), subclass); \ 315 - } while (0) 316 - 317 - #define spin_lock_bh_nested(lock, subclass) \ 318 - do { \ 319 - raw_spin_lock_bh_nested(spinlock_check(lock), subclass);\ 320 318 } while (0) 321 319 322 320 #define spin_lock_nest_lock(lock, nest_lock) \
-2
include/linux/spinlock_api_smp.h
··· 22 22 void __lockfunc _raw_spin_lock(raw_spinlock_t *lock) __acquires(lock); 23 23 void __lockfunc _raw_spin_lock_nested(raw_spinlock_t *lock, int subclass) 24 24 __acquires(lock); 25 - void __lockfunc _raw_spin_lock_bh_nested(raw_spinlock_t *lock, int subclass) 26 - __acquires(lock); 27 25 void __lockfunc 28 26 _raw_spin_lock_nest_lock(raw_spinlock_t *lock, struct lockdep_map *map) 29 27 __acquires(lock);
-1
include/linux/spinlock_api_up.h
··· 57 57 58 58 #define _raw_spin_lock(lock) __LOCK(lock) 59 59 #define _raw_spin_lock_nested(lock, subclass) __LOCK(lock) 60 - #define _raw_spin_lock_bh_nested(lock, subclass) __LOCK(lock) 61 60 #define _raw_read_lock(lock) __LOCK(lock) 62 61 #define _raw_write_lock(lock) __LOCK(lock) 63 62 #define _raw_spin_lock_bh(lock) __LOCK_BH(lock)
+1 -1
include/linux/sunrpc/cache.h
··· 198 198 199 199 static inline void cache_put(struct cache_head *h, struct cache_detail *cd) 200 200 { 201 - if (atomic_read(&h->ref.refcount) <= 2 && 201 + if (kref_read(&h->ref) <= 2 && 202 202 h->expiry_time < cd->nextcheck) 203 203 cd->nextcheck = h->expiry_time; 204 204 kref_put(&h->ref, cd->cache_put);
+7 -25
include/linux/ww_mutex.h
··· 51 51 }; 52 52 53 53 #ifdef CONFIG_DEBUG_LOCK_ALLOC 54 - # define __WW_CLASS_MUTEX_INITIALIZER(lockname, ww_class) \ 55 - , .ww_class = &ww_class 54 + # define __WW_CLASS_MUTEX_INITIALIZER(lockname, class) \ 55 + , .ww_class = class 56 56 #else 57 - # define __WW_CLASS_MUTEX_INITIALIZER(lockname, ww_class) 57 + # define __WW_CLASS_MUTEX_INITIALIZER(lockname, class) 58 58 #endif 59 59 60 60 #define __WW_CLASS_INITIALIZER(ww_class) \ ··· 63 63 , .mutex_name = #ww_class "_mutex" } 64 64 65 65 #define __WW_MUTEX_INITIALIZER(lockname, class) \ 66 - { .base = { \__MUTEX_INITIALIZER(lockname) } \ 66 + { .base = __MUTEX_INITIALIZER(lockname.base) \ 67 67 __WW_CLASS_MUTEX_INITIALIZER(lockname, class) } 68 68 69 69 #define DEFINE_WW_CLASS(classname) \ ··· 186 186 #endif 187 187 } 188 188 189 - extern int __must_check __ww_mutex_lock(struct ww_mutex *lock, 190 - struct ww_acquire_ctx *ctx); 191 - extern int __must_check __ww_mutex_lock_interruptible(struct ww_mutex *lock, 192 - struct ww_acquire_ctx *ctx); 193 - 194 189 /** 195 190 * ww_mutex_lock - acquire the w/w mutex 196 191 * @lock: the mutex to be acquired ··· 215 220 * 216 221 * A mutex acquired with this function must be released with ww_mutex_unlock. 217 222 */ 218 - static inline int ww_mutex_lock(struct ww_mutex *lock, struct ww_acquire_ctx *ctx) 219 - { 220 - if (ctx) 221 - return __ww_mutex_lock(lock, ctx); 222 - 223 - mutex_lock(&lock->base); 224 - return 0; 225 - } 223 + extern int /* __must_check */ ww_mutex_lock(struct ww_mutex *lock, struct ww_acquire_ctx *ctx); 226 224 227 225 /** 228 226 * ww_mutex_lock_interruptible - acquire the w/w mutex, interruptible ··· 247 259 * 248 260 * A mutex acquired with this function must be released with ww_mutex_unlock. 249 261 */ 250 - static inline int __must_check ww_mutex_lock_interruptible(struct ww_mutex *lock, 251 - struct ww_acquire_ctx *ctx) 252 - { 253 - if (ctx) 254 - return __ww_mutex_lock_interruptible(lock, ctx); 255 - else 256 - return mutex_lock_interruptible(&lock->base); 257 - } 262 + extern int __must_check ww_mutex_lock_interruptible(struct ww_mutex *lock, 263 + struct ww_acquire_ctx *ctx); 258 264 259 265 /** 260 266 * ww_mutex_lock_slow - slowpath acquiring of the w/w mutex
+2 -2
include/net/bluetooth/hci_core.h
··· 987 987 static inline void hci_dev_put(struct hci_dev *d) 988 988 { 989 989 BT_DBG("%s orig refcnt %d", d->name, 990 - atomic_read(&d->dev.kobj.kref.refcount)); 990 + kref_read(&d->dev.kobj.kref)); 991 991 992 992 put_device(&d->dev); 993 993 } ··· 995 995 static inline struct hci_dev *hci_dev_hold(struct hci_dev *d) 996 996 { 997 997 BT_DBG("%s orig refcnt %d", d->name, 998 - atomic_read(&d->dev.kobj.kref.refcount)); 998 + kref_read(&d->dev.kobj.kref)); 999 999 1000 1000 get_device(&d->dev); 1001 1001 return d;
+1 -3
init/version.c
··· 23 23 #endif 24 24 25 25 struct uts_namespace init_uts_ns = { 26 - .kref = { 27 - .refcount = ATOMIC_INIT(2), 28 - }, 26 + .kref = KREF_INIT(2), 29 27 .name = { 30 28 .sysname = UTS_SYSNAME, 31 29 .nodename = UTS_NODENAME,
+41 -11
kernel/exit.c
··· 55 55 #include <linux/shm.h> 56 56 #include <linux/kcov.h> 57 57 #include <linux/random.h> 58 + #include <linux/rcuwait.h> 58 59 59 60 #include <linux/uaccess.h> 60 61 #include <asm/unistd.h> ··· 283 282 return task; 284 283 } 285 284 285 + void rcuwait_wake_up(struct rcuwait *w) 286 + { 287 + struct task_struct *task; 288 + 289 + rcu_read_lock(); 290 + 291 + /* 292 + * Order condition vs @task, such that everything prior to the load 293 + * of @task is visible. This is the condition as to why the user called 294 + * rcuwait_trywake() in the first place. Pairs with set_current_state() 295 + * barrier (A) in rcuwait_wait_event(). 296 + * 297 + * WAIT WAKE 298 + * [S] tsk = current [S] cond = true 299 + * MB (A) MB (B) 300 + * [L] cond [L] tsk 301 + */ 302 + smp_rmb(); /* (B) */ 303 + 304 + /* 305 + * Avoid using task_rcu_dereference() magic as long as we are careful, 306 + * see comment in rcuwait_wait_event() regarding ->exit_state. 307 + */ 308 + task = rcu_dereference(w->task); 309 + if (task) 310 + wake_up_process(task); 311 + rcu_read_unlock(); 312 + } 313 + 286 314 struct task_struct *try_get_task_struct(struct task_struct **ptask) 287 315 { 288 316 struct task_struct *task; ··· 498 468 * Turn us into a lazy TLB process if we 499 469 * aren't already.. 500 470 */ 501 - static void exit_mm(struct task_struct *tsk) 471 + static void exit_mm(void) 502 472 { 503 - struct mm_struct *mm = tsk->mm; 473 + struct mm_struct *mm = current->mm; 504 474 struct core_state *core_state; 505 475 506 - mm_release(tsk, mm); 476 + mm_release(current, mm); 507 477 if (!mm) 508 478 return; 509 479 sync_mm_rss(mm); ··· 521 491 522 492 up_read(&mm->mmap_sem); 523 493 524 - self.task = tsk; 494 + self.task = current; 525 495 self.next = xchg(&core_state->dumper.next, &self); 526 496 /* 527 497 * Implies mb(), the result of xchg() must be visible ··· 531 501 complete(&core_state->startup); 532 502 533 503 for (;;) { 534 - set_task_state(tsk, TASK_UNINTERRUPTIBLE); 504 + set_current_state(TASK_UNINTERRUPTIBLE); 535 505 if (!self.task) /* see coredump_finish() */ 536 506 break; 537 507 freezable_schedule(); 538 508 } 539 - __set_task_state(tsk, TASK_RUNNING); 509 + __set_current_state(TASK_RUNNING); 540 510 down_read(&mm->mmap_sem); 541 511 } 542 512 atomic_inc(&mm->mm_count); 543 - BUG_ON(mm != tsk->active_mm); 513 + BUG_ON(mm != current->active_mm); 544 514 /* more a memory barrier than a real lock */ 545 - task_lock(tsk); 546 - tsk->mm = NULL; 515 + task_lock(current); 516 + current->mm = NULL; 547 517 up_read(&mm->mmap_sem); 548 518 enter_lazy_tlb(mm, current); 549 - task_unlock(tsk); 519 + task_unlock(current); 550 520 mm_update_next_owner(mm); 551 521 mmput(mm); 552 522 if (test_thread_flag(TIF_MEMDIE)) ··· 853 823 tsk->exit_code = code; 854 824 taskstats_exit(tsk, group_dead); 855 825 856 - exit_mm(tsk); 826 + exit_mm(); 857 827 858 828 if (group_dead) 859 829 acct_process();
+4 -2
kernel/fork.c
··· 432 432 int i; 433 433 #ifndef CONFIG_ARCH_TASK_STRUCT_ALLOCATOR 434 434 #ifndef ARCH_MIN_TASKALIGN 435 - #define ARCH_MIN_TASKALIGN L1_CACHE_BYTES 435 + #define ARCH_MIN_TASKALIGN 0 436 436 #endif 437 + int align = max_t(int, L1_CACHE_BYTES, ARCH_MIN_TASKALIGN); 438 + 437 439 /* create a slab on which task_structs can be allocated */ 438 440 task_struct_cachep = kmem_cache_create("task_struct", 439 - arch_task_struct_size, ARCH_MIN_TASKALIGN, 441 + arch_task_struct_size, align, 440 442 SLAB_PANIC|SLAB_NOTRACK|SLAB_ACCOUNT, NULL); 441 443 #endif 442 444
+1
kernel/locking/Makefile
··· 28 28 obj-$(CONFIG_RWSEM_XCHGADD_ALGORITHM) += rwsem-xadd.o 29 29 obj-$(CONFIG_QUEUED_RWLOCKS) += qrwlock.o 30 30 obj-$(CONFIG_LOCK_TORTURE_TEST) += locktorture.o 31 + obj-$(CONFIG_WW_MUTEX_SELFTEST) += test-ww_mutex.o
+1 -1
kernel/locking/lockdep.c
··· 2203 2203 * Important for check_no_collision(). 2204 2204 */ 2205 2205 if (unlikely(nr_chain_hlocks > MAX_LOCKDEP_CHAIN_HLOCKS)) { 2206 - if (debug_locks_off_graph_unlock()) 2206 + if (!debug_locks_off_graph_unlock()) 2207 2207 return 0; 2208 2208 2209 2209 print_lockdep_off("BUG: MAX_LOCKDEP_CHAIN_HLOCKS too low!");
+73
kernel/locking/locktorture.c
··· 372 372 .name = "mutex_lock" 373 373 }; 374 374 375 + #include <linux/ww_mutex.h> 376 + static DEFINE_WW_CLASS(torture_ww_class); 377 + static DEFINE_WW_MUTEX(torture_ww_mutex_0, &torture_ww_class); 378 + static DEFINE_WW_MUTEX(torture_ww_mutex_1, &torture_ww_class); 379 + static DEFINE_WW_MUTEX(torture_ww_mutex_2, &torture_ww_class); 380 + 381 + static int torture_ww_mutex_lock(void) 382 + __acquires(torture_ww_mutex_0) 383 + __acquires(torture_ww_mutex_1) 384 + __acquires(torture_ww_mutex_2) 385 + { 386 + LIST_HEAD(list); 387 + struct reorder_lock { 388 + struct list_head link; 389 + struct ww_mutex *lock; 390 + } locks[3], *ll, *ln; 391 + struct ww_acquire_ctx ctx; 392 + 393 + locks[0].lock = &torture_ww_mutex_0; 394 + list_add(&locks[0].link, &list); 395 + 396 + locks[1].lock = &torture_ww_mutex_1; 397 + list_add(&locks[1].link, &list); 398 + 399 + locks[2].lock = &torture_ww_mutex_2; 400 + list_add(&locks[2].link, &list); 401 + 402 + ww_acquire_init(&ctx, &torture_ww_class); 403 + 404 + list_for_each_entry(ll, &list, link) { 405 + int err; 406 + 407 + err = ww_mutex_lock(ll->lock, &ctx); 408 + if (!err) 409 + continue; 410 + 411 + ln = ll; 412 + list_for_each_entry_continue_reverse(ln, &list, link) 413 + ww_mutex_unlock(ln->lock); 414 + 415 + if (err != -EDEADLK) 416 + return err; 417 + 418 + ww_mutex_lock_slow(ll->lock, &ctx); 419 + list_move(&ll->link, &list); 420 + } 421 + 422 + ww_acquire_fini(&ctx); 423 + return 0; 424 + } 425 + 426 + static void torture_ww_mutex_unlock(void) 427 + __releases(torture_ww_mutex_0) 428 + __releases(torture_ww_mutex_1) 429 + __releases(torture_ww_mutex_2) 430 + { 431 + ww_mutex_unlock(&torture_ww_mutex_0); 432 + ww_mutex_unlock(&torture_ww_mutex_1); 433 + ww_mutex_unlock(&torture_ww_mutex_2); 434 + } 435 + 436 + static struct lock_torture_ops ww_mutex_lock_ops = { 437 + .writelock = torture_ww_mutex_lock, 438 + .write_delay = torture_mutex_delay, 439 + .task_boost = torture_boost_dummy, 440 + .writeunlock = torture_ww_mutex_unlock, 441 + .readlock = NULL, 442 + .read_delay = NULL, 443 + .readunlock = NULL, 444 + .name = "ww_mutex_lock" 445 + }; 446 + 375 447 #ifdef CONFIG_RT_MUTEXES 376 448 static DEFINE_RT_MUTEX(torture_rtmutex); 377 449 ··· 869 797 &spin_lock_ops, &spin_lock_irq_ops, 870 798 &rw_lock_ops, &rw_lock_irq_ops, 871 799 &mutex_lock_ops, 800 + &ww_mutex_lock_ops, 872 801 #ifdef CONFIG_RT_MUTEXES 873 802 &rtmutex_lock_ops, 874 803 #endif
-17
kernel/locking/mutex-debug.h
··· 26 26 extern void debug_mutex_unlock(struct mutex *lock); 27 27 extern void debug_mutex_init(struct mutex *lock, const char *name, 28 28 struct lock_class_key *key); 29 - 30 - #define spin_lock_mutex(lock, flags) \ 31 - do { \ 32 - struct mutex *l = container_of(lock, struct mutex, wait_lock); \ 33 - \ 34 - DEBUG_LOCKS_WARN_ON(in_interrupt()); \ 35 - local_irq_save(flags); \ 36 - arch_spin_lock(&(lock)->rlock.raw_lock);\ 37 - DEBUG_LOCKS_WARN_ON(l->magic != l); \ 38 - } while (0) 39 - 40 - #define spin_unlock_mutex(lock, flags) \ 41 - do { \ 42 - arch_spin_unlock(&(lock)->rlock.raw_lock); \ 43 - local_irq_restore(flags); \ 44 - preempt_check_resched(); \ 45 - } while (0)
+337 -189
kernel/locking/mutex.c
··· 50 50 /* 51 51 * @owner: contains: 'struct task_struct *' to the current lock owner, 52 52 * NULL means not owned. Since task_struct pointers are aligned at 53 - * ARCH_MIN_TASKALIGN (which is at least sizeof(void *)), we have low 54 - * bits to store extra state. 53 + * at least L1_CACHE_BYTES, we have low bits to store extra state. 55 54 * 56 55 * Bit0 indicates a non-empty waiter list; unlock must issue a wakeup. 57 56 * Bit1 indicates unlock needs to hand the lock to the top-waiter 57 + * Bit2 indicates handoff has been done and we're waiting for pickup. 58 58 */ 59 59 #define MUTEX_FLAG_WAITERS 0x01 60 60 #define MUTEX_FLAG_HANDOFF 0x02 61 + #define MUTEX_FLAG_PICKUP 0x04 61 62 62 - #define MUTEX_FLAGS 0x03 63 + #define MUTEX_FLAGS 0x07 63 64 64 65 static inline struct task_struct *__owner_task(unsigned long owner) 65 66 { ··· 73 72 } 74 73 75 74 /* 76 - * Actual trylock that will work on any unlocked state. 77 - * 78 - * When setting the owner field, we must preserve the low flag bits. 79 - * 80 - * Be careful with @handoff, only set that in a wait-loop (where you set 81 - * HANDOFF) to avoid recursive lock attempts. 75 + * Trylock variant that retuns the owning task on failure. 82 76 */ 83 - static inline bool __mutex_trylock(struct mutex *lock, const bool handoff) 77 + static inline struct task_struct *__mutex_trylock_or_owner(struct mutex *lock) 84 78 { 85 79 unsigned long owner, curr = (unsigned long)current; 86 80 87 81 owner = atomic_long_read(&lock->owner); 88 82 for (;;) { /* must loop, can race against a flag */ 89 83 unsigned long old, flags = __owner_flags(owner); 84 + unsigned long task = owner & ~MUTEX_FLAGS; 90 85 91 - if (__owner_task(owner)) { 92 - if (handoff && unlikely(__owner_task(owner) == current)) { 93 - /* 94 - * Provide ACQUIRE semantics for the lock-handoff. 95 - * 96 - * We cannot easily use load-acquire here, since 97 - * the actual load is a failed cmpxchg, which 98 - * doesn't imply any barriers. 99 - * 100 - * Also, this is a fairly unlikely scenario, and 101 - * this contains the cost. 102 - */ 103 - smp_mb(); /* ACQUIRE */ 104 - return true; 105 - } 86 + if (task) { 87 + if (likely(task != curr)) 88 + break; 106 89 107 - return false; 90 + if (likely(!(flags & MUTEX_FLAG_PICKUP))) 91 + break; 92 + 93 + flags &= ~MUTEX_FLAG_PICKUP; 94 + } else { 95 + #ifdef CONFIG_DEBUG_MUTEXES 96 + DEBUG_LOCKS_WARN_ON(flags & MUTEX_FLAG_PICKUP); 97 + #endif 108 98 } 109 99 110 100 /* ··· 103 111 * past the point where we acquire it. This would be possible 104 112 * if we (accidentally) set the bit on an unlocked mutex. 105 113 */ 106 - if (handoff) 107 - flags &= ~MUTEX_FLAG_HANDOFF; 114 + flags &= ~MUTEX_FLAG_HANDOFF; 108 115 109 116 old = atomic_long_cmpxchg_acquire(&lock->owner, owner, curr | flags); 110 117 if (old == owner) 111 - return true; 118 + return NULL; 112 119 113 120 owner = old; 114 121 } 122 + 123 + return __owner_task(owner); 124 + } 125 + 126 + /* 127 + * Actual trylock that will work on any unlocked state. 128 + */ 129 + static inline bool __mutex_trylock(struct mutex *lock) 130 + { 131 + return !__mutex_trylock_or_owner(lock); 115 132 } 116 133 117 134 #ifndef CONFIG_DEBUG_LOCK_ALLOC ··· 172 171 173 172 /* 174 173 * Give up ownership to a specific task, when @task = NULL, this is equivalent 175 - * to a regular unlock. Clears HANDOFF, preserves WAITERS. Provides RELEASE 176 - * semantics like a regular unlock, the __mutex_trylock() provides matching 177 - * ACQUIRE semantics for the handoff. 174 + * to a regular unlock. Sets PICKUP on a handoff, clears HANDOF, preserves 175 + * WAITERS. Provides RELEASE semantics like a regular unlock, the 176 + * __mutex_trylock() provides a matching ACQUIRE semantics for the handoff. 178 177 */ 179 178 static void __mutex_handoff(struct mutex *lock, struct task_struct *task) 180 179 { ··· 185 184 186 185 #ifdef CONFIG_DEBUG_MUTEXES 187 186 DEBUG_LOCKS_WARN_ON(__owner_task(owner) != current); 187 + DEBUG_LOCKS_WARN_ON(owner & MUTEX_FLAG_PICKUP); 188 188 #endif 189 189 190 190 new = (owner & MUTEX_FLAG_WAITERS); 191 191 new |= (unsigned long)task; 192 + if (task) 193 + new |= MUTEX_FLAG_PICKUP; 192 194 193 195 old = atomic_long_cmpxchg_release(&lock->owner, owner, new); 194 196 if (old == owner) ··· 241 237 EXPORT_SYMBOL(mutex_lock); 242 238 #endif 243 239 244 - static __always_inline void ww_mutex_lock_acquired(struct ww_mutex *ww, 245 - struct ww_acquire_ctx *ww_ctx) 240 + static __always_inline void 241 + ww_mutex_lock_acquired(struct ww_mutex *ww, struct ww_acquire_ctx *ww_ctx) 246 242 { 247 243 #ifdef CONFIG_DEBUG_MUTEXES 248 244 /* ··· 281 277 ww_ctx->acquired++; 282 278 } 283 279 280 + static inline bool __sched 281 + __ww_ctx_stamp_after(struct ww_acquire_ctx *a, struct ww_acquire_ctx *b) 282 + { 283 + return a->stamp - b->stamp <= LONG_MAX && 284 + (a->stamp != b->stamp || a > b); 285 + } 286 + 287 + /* 288 + * Wake up any waiters that may have to back off when the lock is held by the 289 + * given context. 290 + * 291 + * Due to the invariants on the wait list, this can only affect the first 292 + * waiter with a context. 293 + * 294 + * The current task must not be on the wait list. 295 + */ 296 + static void __sched 297 + __ww_mutex_wakeup_for_backoff(struct mutex *lock, struct ww_acquire_ctx *ww_ctx) 298 + { 299 + struct mutex_waiter *cur; 300 + 301 + lockdep_assert_held(&lock->wait_lock); 302 + 303 + list_for_each_entry(cur, &lock->wait_list, list) { 304 + if (!cur->ww_ctx) 305 + continue; 306 + 307 + if (cur->ww_ctx->acquired > 0 && 308 + __ww_ctx_stamp_after(cur->ww_ctx, ww_ctx)) { 309 + debug_mutex_wake_waiter(lock, cur); 310 + wake_up_process(cur->task); 311 + } 312 + 313 + break; 314 + } 315 + } 316 + 284 317 /* 285 318 * After acquiring lock with fastpath or when we lost out in contested 286 319 * slowpath, set ctx and wake up any waiters so they can recheck. 287 320 */ 288 321 static __always_inline void 289 - ww_mutex_set_context_fastpath(struct ww_mutex *lock, 290 - struct ww_acquire_ctx *ctx) 322 + ww_mutex_set_context_fastpath(struct ww_mutex *lock, struct ww_acquire_ctx *ctx) 291 323 { 292 - unsigned long flags; 293 - struct mutex_waiter *cur; 294 - 295 324 ww_mutex_lock_acquired(lock, ctx); 296 325 297 326 lock->ctx = ctx; ··· 348 311 * Uh oh, we raced in fastpath, wake up everyone in this case, 349 312 * so they can see the new lock->ctx. 350 313 */ 351 - spin_lock_mutex(&lock->base.wait_lock, flags); 352 - list_for_each_entry(cur, &lock->base.wait_list, list) { 353 - debug_mutex_wake_waiter(&lock->base, cur); 354 - wake_up_process(cur->task); 355 - } 356 - spin_unlock_mutex(&lock->base.wait_lock, flags); 314 + spin_lock(&lock->base.wait_lock); 315 + __ww_mutex_wakeup_for_backoff(&lock->base, ctx); 316 + spin_unlock(&lock->base.wait_lock); 357 317 } 358 318 359 319 /* 360 - * After acquiring lock in the slowpath set ctx and wake up any 361 - * waiters so they can recheck. 320 + * After acquiring lock in the slowpath set ctx. 321 + * 322 + * Unlike for the fast path, the caller ensures that waiters are woken up where 323 + * necessary. 362 324 * 363 325 * Callers must hold the mutex wait_lock. 364 326 */ 365 327 static __always_inline void 366 - ww_mutex_set_context_slowpath(struct ww_mutex *lock, 367 - struct ww_acquire_ctx *ctx) 328 + ww_mutex_set_context_slowpath(struct ww_mutex *lock, struct ww_acquire_ctx *ctx) 368 329 { 369 - struct mutex_waiter *cur; 370 - 371 330 ww_mutex_lock_acquired(lock, ctx); 372 331 lock->ctx = ctx; 373 - 374 - /* 375 - * Give any possible sleeping processes the chance to wake up, 376 - * so they can recheck if they have to back off. 377 - */ 378 - list_for_each_entry(cur, &lock->base.wait_list, list) { 379 - debug_mutex_wake_waiter(&lock->base, cur); 380 - wake_up_process(cur->task); 381 - } 382 332 } 383 333 384 334 #ifdef CONFIG_MUTEX_SPIN_ON_OWNER 335 + 336 + static inline 337 + bool ww_mutex_spin_on_owner(struct mutex *lock, struct ww_acquire_ctx *ww_ctx, 338 + struct mutex_waiter *waiter) 339 + { 340 + struct ww_mutex *ww; 341 + 342 + ww = container_of(lock, struct ww_mutex, base); 343 + 344 + /* 345 + * If ww->ctx is set the contents are undefined, only 346 + * by acquiring wait_lock there is a guarantee that 347 + * they are not invalid when reading. 348 + * 349 + * As such, when deadlock detection needs to be 350 + * performed the optimistic spinning cannot be done. 351 + * 352 + * Check this in every inner iteration because we may 353 + * be racing against another thread's ww_mutex_lock. 354 + */ 355 + if (ww_ctx->acquired > 0 && READ_ONCE(ww->ctx)) 356 + return false; 357 + 358 + /* 359 + * If we aren't on the wait list yet, cancel the spin 360 + * if there are waiters. We want to avoid stealing the 361 + * lock from a waiter with an earlier stamp, since the 362 + * other thread may already own a lock that we also 363 + * need. 364 + */ 365 + if (!waiter && (atomic_long_read(&lock->owner) & MUTEX_FLAG_WAITERS)) 366 + return false; 367 + 368 + /* 369 + * Similarly, stop spinning if we are no longer the 370 + * first waiter. 371 + */ 372 + if (waiter && !__mutex_waiter_is_first(lock, waiter)) 373 + return false; 374 + 375 + return true; 376 + } 377 + 385 378 /* 386 - * Look out! "owner" is an entirely speculative pointer 387 - * access and not reliable. 379 + * Look out! "owner" is an entirely speculative pointer access and not 380 + * reliable. 381 + * 382 + * "noinline" so that this function shows up on perf profiles. 388 383 */ 389 384 static noinline 390 - bool mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner) 385 + bool mutex_spin_on_owner(struct mutex *lock, struct task_struct *owner, 386 + struct ww_acquire_ctx *ww_ctx, struct mutex_waiter *waiter) 391 387 { 392 388 bool ret = true; 393 389 ··· 439 369 */ 440 370 if (!owner->on_cpu || need_resched() || 441 371 vcpu_is_preempted(task_cpu(owner))) { 372 + ret = false; 373 + break; 374 + } 375 + 376 + if (ww_ctx && !ww_mutex_spin_on_owner(lock, ww_ctx, waiter)) { 442 377 ret = false; 443 378 break; 444 379 } ··· 506 431 * with the spinner at the head of the OSQ, if present, until the owner is 507 432 * changed to itself. 508 433 */ 509 - static bool mutex_optimistic_spin(struct mutex *lock, 510 - struct ww_acquire_ctx *ww_ctx, 511 - const bool use_ww_ctx, const bool waiter) 434 + static __always_inline bool 435 + mutex_optimistic_spin(struct mutex *lock, struct ww_acquire_ctx *ww_ctx, 436 + const bool use_ww_ctx, struct mutex_waiter *waiter) 512 437 { 513 - struct task_struct *task = current; 514 - 515 438 if (!waiter) { 516 439 /* 517 440 * The purpose of the mutex_can_spin_on_owner() function is ··· 533 460 for (;;) { 534 461 struct task_struct *owner; 535 462 536 - if (use_ww_ctx && ww_ctx->acquired > 0) { 537 - struct ww_mutex *ww; 538 - 539 - ww = container_of(lock, struct ww_mutex, base); 540 - /* 541 - * If ww->ctx is set the contents are undefined, only 542 - * by acquiring wait_lock there is a guarantee that 543 - * they are not invalid when reading. 544 - * 545 - * As such, when deadlock detection needs to be 546 - * performed the optimistic spinning cannot be done. 547 - */ 548 - if (READ_ONCE(ww->ctx)) 549 - goto fail_unlock; 550 - } 463 + /* Try to acquire the mutex... */ 464 + owner = __mutex_trylock_or_owner(lock); 465 + if (!owner) 466 + break; 551 467 552 468 /* 553 - * If there's an owner, wait for it to either 469 + * There's an owner, wait for it to either 554 470 * release the lock or go to sleep. 555 471 */ 556 - owner = __mutex_owner(lock); 557 - if (owner) { 558 - if (waiter && owner == task) { 559 - smp_mb(); /* ACQUIRE */ 560 - break; 561 - } 562 - 563 - if (!mutex_spin_on_owner(lock, owner)) 564 - goto fail_unlock; 565 - } 566 - 567 - /* Try to acquire the mutex if it is unlocked. */ 568 - if (__mutex_trylock(lock, waiter)) 569 - break; 472 + if (!mutex_spin_on_owner(lock, owner, ww_ctx, waiter)) 473 + goto fail_unlock; 570 474 571 475 /* 572 476 * The cpu_relax() call is a compiler barrier which forces ··· 582 532 return false; 583 533 } 584 534 #else 585 - static bool mutex_optimistic_spin(struct mutex *lock, 586 - struct ww_acquire_ctx *ww_ctx, 587 - const bool use_ww_ctx, const bool waiter) 535 + static __always_inline bool 536 + mutex_optimistic_spin(struct mutex *lock, struct ww_acquire_ctx *ww_ctx, 537 + const bool use_ww_ctx, struct mutex_waiter *waiter) 588 538 { 589 539 return false; 590 540 } ··· 644 594 EXPORT_SYMBOL(ww_mutex_unlock); 645 595 646 596 static inline int __sched 647 - __ww_mutex_lock_check_stamp(struct mutex *lock, struct ww_acquire_ctx *ctx) 597 + __ww_mutex_lock_check_stamp(struct mutex *lock, struct mutex_waiter *waiter, 598 + struct ww_acquire_ctx *ctx) 648 599 { 649 600 struct ww_mutex *ww = container_of(lock, struct ww_mutex, base); 650 601 struct ww_acquire_ctx *hold_ctx = READ_ONCE(ww->ctx); 602 + struct mutex_waiter *cur; 651 603 652 - if (!hold_ctx) 653 - return 0; 604 + if (hold_ctx && __ww_ctx_stamp_after(ctx, hold_ctx)) 605 + goto deadlock; 654 606 655 - if (ctx->stamp - hold_ctx->stamp <= LONG_MAX && 656 - (ctx->stamp != hold_ctx->stamp || ctx > hold_ctx)) { 657 - #ifdef CONFIG_DEBUG_MUTEXES 658 - DEBUG_LOCKS_WARN_ON(ctx->contending_lock); 659 - ctx->contending_lock = ww; 660 - #endif 661 - return -EDEADLK; 607 + /* 608 + * If there is a waiter in front of us that has a context, then its 609 + * stamp is earlier than ours and we must back off. 610 + */ 611 + cur = waiter; 612 + list_for_each_entry_continue_reverse(cur, &lock->wait_list, list) { 613 + if (cur->ww_ctx) 614 + goto deadlock; 662 615 } 663 616 617 + return 0; 618 + 619 + deadlock: 620 + #ifdef CONFIG_DEBUG_MUTEXES 621 + DEBUG_LOCKS_WARN_ON(ctx->contending_lock); 622 + ctx->contending_lock = ww; 623 + #endif 624 + return -EDEADLK; 625 + } 626 + 627 + static inline int __sched 628 + __ww_mutex_add_waiter(struct mutex_waiter *waiter, 629 + struct mutex *lock, 630 + struct ww_acquire_ctx *ww_ctx) 631 + { 632 + struct mutex_waiter *cur; 633 + struct list_head *pos; 634 + 635 + if (!ww_ctx) { 636 + list_add_tail(&waiter->list, &lock->wait_list); 637 + return 0; 638 + } 639 + 640 + /* 641 + * Add the waiter before the first waiter with a higher stamp. 642 + * Waiters without a context are skipped to avoid starving 643 + * them. 644 + */ 645 + pos = &lock->wait_list; 646 + list_for_each_entry_reverse(cur, &lock->wait_list, list) { 647 + if (!cur->ww_ctx) 648 + continue; 649 + 650 + if (__ww_ctx_stamp_after(ww_ctx, cur->ww_ctx)) { 651 + /* Back off immediately if necessary. */ 652 + if (ww_ctx->acquired > 0) { 653 + #ifdef CONFIG_DEBUG_MUTEXES 654 + struct ww_mutex *ww; 655 + 656 + ww = container_of(lock, struct ww_mutex, base); 657 + DEBUG_LOCKS_WARN_ON(ww_ctx->contending_lock); 658 + ww_ctx->contending_lock = ww; 659 + #endif 660 + return -EDEADLK; 661 + } 662 + 663 + break; 664 + } 665 + 666 + pos = &cur->list; 667 + 668 + /* 669 + * Wake up the waiter so that it gets a chance to back 670 + * off. 671 + */ 672 + if (cur->ww_ctx->acquired > 0) { 673 + debug_mutex_wake_waiter(lock, cur); 674 + wake_up_process(cur->task); 675 + } 676 + } 677 + 678 + list_add_tail(&waiter->list, pos); 664 679 return 0; 665 680 } 666 681 ··· 737 622 struct lockdep_map *nest_lock, unsigned long ip, 738 623 struct ww_acquire_ctx *ww_ctx, const bool use_ww_ctx) 739 624 { 740 - struct task_struct *task = current; 741 625 struct mutex_waiter waiter; 742 - unsigned long flags; 743 626 bool first = false; 744 627 struct ww_mutex *ww; 745 628 int ret; 746 629 747 - if (use_ww_ctx) { 748 - ww = container_of(lock, struct ww_mutex, base); 630 + might_sleep(); 631 + 632 + ww = container_of(lock, struct ww_mutex, base); 633 + if (use_ww_ctx && ww_ctx) { 749 634 if (unlikely(ww_ctx == READ_ONCE(ww->ctx))) 750 635 return -EALREADY; 751 636 } ··· 753 638 preempt_disable(); 754 639 mutex_acquire_nest(&lock->dep_map, subclass, 0, nest_lock, ip); 755 640 756 - if (__mutex_trylock(lock, false) || 757 - mutex_optimistic_spin(lock, ww_ctx, use_ww_ctx, false)) { 641 + if (__mutex_trylock(lock) || 642 + mutex_optimistic_spin(lock, ww_ctx, use_ww_ctx, NULL)) { 758 643 /* got the lock, yay! */ 759 644 lock_acquired(&lock->dep_map, ip); 760 - if (use_ww_ctx) 645 + if (use_ww_ctx && ww_ctx) 761 646 ww_mutex_set_context_fastpath(ww, ww_ctx); 762 647 preempt_enable(); 763 648 return 0; 764 649 } 765 650 766 - spin_lock_mutex(&lock->wait_lock, flags); 651 + spin_lock(&lock->wait_lock); 767 652 /* 768 653 * After waiting to acquire the wait_lock, try again. 769 654 */ 770 - if (__mutex_trylock(lock, false)) 655 + if (__mutex_trylock(lock)) { 656 + if (use_ww_ctx && ww_ctx) 657 + __ww_mutex_wakeup_for_backoff(lock, ww_ctx); 658 + 771 659 goto skip_wait; 660 + } 772 661 773 662 debug_mutex_lock_common(lock, &waiter); 774 - debug_mutex_add_waiter(lock, &waiter, task); 663 + debug_mutex_add_waiter(lock, &waiter, current); 775 664 776 - /* add waiting tasks to the end of the waitqueue (FIFO): */ 777 - list_add_tail(&waiter.list, &lock->wait_list); 778 - waiter.task = task; 665 + lock_contended(&lock->dep_map, ip); 666 + 667 + if (!use_ww_ctx) { 668 + /* add waiting tasks to the end of the waitqueue (FIFO): */ 669 + list_add_tail(&waiter.list, &lock->wait_list); 670 + 671 + #ifdef CONFIG_DEBUG_MUTEXES 672 + waiter.ww_ctx = MUTEX_POISON_WW_CTX; 673 + #endif 674 + } else { 675 + /* Add in stamp order, waking up waiters that must back off. */ 676 + ret = __ww_mutex_add_waiter(&waiter, lock, ww_ctx); 677 + if (ret) 678 + goto err_early_backoff; 679 + 680 + waiter.ww_ctx = ww_ctx; 681 + } 682 + 683 + waiter.task = current; 779 684 780 685 if (__mutex_waiter_is_first(lock, &waiter)) 781 686 __mutex_set_flag(lock, MUTEX_FLAG_WAITERS); 782 687 783 - lock_contended(&lock->dep_map, ip); 784 - 785 - set_task_state(task, state); 688 + set_current_state(state); 786 689 for (;;) { 787 690 /* 788 691 * Once we hold wait_lock, we're serialized against ··· 808 675 * before testing the error conditions to make sure we pick up 809 676 * the handoff. 810 677 */ 811 - if (__mutex_trylock(lock, first)) 678 + if (__mutex_trylock(lock)) 812 679 goto acquired; 813 680 814 681 /* ··· 816 683 * wait_lock. This ensures the lock cancellation is ordered 817 684 * against mutex_unlock() and wake-ups do not go missing. 818 685 */ 819 - if (unlikely(signal_pending_state(state, task))) { 686 + if (unlikely(signal_pending_state(state, current))) { 820 687 ret = -EINTR; 821 688 goto err; 822 689 } 823 690 824 - if (use_ww_ctx && ww_ctx->acquired > 0) { 825 - ret = __ww_mutex_lock_check_stamp(lock, ww_ctx); 691 + if (use_ww_ctx && ww_ctx && ww_ctx->acquired > 0) { 692 + ret = __ww_mutex_lock_check_stamp(lock, &waiter, ww_ctx); 826 693 if (ret) 827 694 goto err; 828 695 } 829 696 830 - spin_unlock_mutex(&lock->wait_lock, flags); 697 + spin_unlock(&lock->wait_lock); 831 698 schedule_preempt_disabled(); 832 699 833 - if (!first && __mutex_waiter_is_first(lock, &waiter)) { 834 - first = true; 835 - __mutex_set_flag(lock, MUTEX_FLAG_HANDOFF); 700 + /* 701 + * ww_mutex needs to always recheck its position since its waiter 702 + * list is not FIFO ordered. 703 + */ 704 + if ((use_ww_ctx && ww_ctx) || !first) { 705 + first = __mutex_waiter_is_first(lock, &waiter); 706 + if (first) 707 + __mutex_set_flag(lock, MUTEX_FLAG_HANDOFF); 836 708 } 837 709 838 - set_task_state(task, state); 710 + set_current_state(state); 839 711 /* 840 712 * Here we order against unlock; we must either see it change 841 713 * state back to RUNNING and fall through the next schedule(), 842 714 * or we must see its unlock and acquire. 843 715 */ 844 - if ((first && mutex_optimistic_spin(lock, ww_ctx, use_ww_ctx, true)) || 845 - __mutex_trylock(lock, first)) 716 + if (__mutex_trylock(lock) || 717 + (first && mutex_optimistic_spin(lock, ww_ctx, use_ww_ctx, &waiter))) 846 718 break; 847 719 848 - spin_lock_mutex(&lock->wait_lock, flags); 720 + spin_lock(&lock->wait_lock); 849 721 } 850 - spin_lock_mutex(&lock->wait_lock, flags); 722 + spin_lock(&lock->wait_lock); 851 723 acquired: 852 - __set_task_state(task, TASK_RUNNING); 724 + __set_current_state(TASK_RUNNING); 853 725 854 - mutex_remove_waiter(lock, &waiter, task); 726 + mutex_remove_waiter(lock, &waiter, current); 855 727 if (likely(list_empty(&lock->wait_list))) 856 728 __mutex_clear_flag(lock, MUTEX_FLAGS); 857 729 ··· 866 728 /* got the lock - cleanup and rejoice! */ 867 729 lock_acquired(&lock->dep_map, ip); 868 730 869 - if (use_ww_ctx) 731 + if (use_ww_ctx && ww_ctx) 870 732 ww_mutex_set_context_slowpath(ww, ww_ctx); 871 733 872 - spin_unlock_mutex(&lock->wait_lock, flags); 734 + spin_unlock(&lock->wait_lock); 873 735 preempt_enable(); 874 736 return 0; 875 737 876 738 err: 877 - __set_task_state(task, TASK_RUNNING); 878 - mutex_remove_waiter(lock, &waiter, task); 879 - spin_unlock_mutex(&lock->wait_lock, flags); 739 + __set_current_state(TASK_RUNNING); 740 + mutex_remove_waiter(lock, &waiter, current); 741 + err_early_backoff: 742 + spin_unlock(&lock->wait_lock); 880 743 debug_mutex_free_waiter(&waiter); 881 744 mutex_release(&lock->dep_map, 1, ip); 882 745 preempt_enable(); 883 746 return ret; 884 747 } 885 748 749 + static int __sched 750 + __mutex_lock(struct mutex *lock, long state, unsigned int subclass, 751 + struct lockdep_map *nest_lock, unsigned long ip) 752 + { 753 + return __mutex_lock_common(lock, state, subclass, nest_lock, ip, NULL, false); 754 + } 755 + 756 + static int __sched 757 + __ww_mutex_lock(struct mutex *lock, long state, unsigned int subclass, 758 + struct lockdep_map *nest_lock, unsigned long ip, 759 + struct ww_acquire_ctx *ww_ctx) 760 + { 761 + return __mutex_lock_common(lock, state, subclass, nest_lock, ip, ww_ctx, true); 762 + } 763 + 886 764 #ifdef CONFIG_DEBUG_LOCK_ALLOC 887 765 void __sched 888 766 mutex_lock_nested(struct mutex *lock, unsigned int subclass) 889 767 { 890 - might_sleep(); 891 - __mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, 892 - subclass, NULL, _RET_IP_, NULL, 0); 768 + __mutex_lock(lock, TASK_UNINTERRUPTIBLE, subclass, NULL, _RET_IP_); 893 769 } 894 770 895 771 EXPORT_SYMBOL_GPL(mutex_lock_nested); ··· 911 759 void __sched 912 760 _mutex_lock_nest_lock(struct mutex *lock, struct lockdep_map *nest) 913 761 { 914 - might_sleep(); 915 - __mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, 916 - 0, nest, _RET_IP_, NULL, 0); 762 + __mutex_lock(lock, TASK_UNINTERRUPTIBLE, 0, nest, _RET_IP_); 917 763 } 918 764 EXPORT_SYMBOL_GPL(_mutex_lock_nest_lock); 919 765 920 766 int __sched 921 767 mutex_lock_killable_nested(struct mutex *lock, unsigned int subclass) 922 768 { 923 - might_sleep(); 924 - return __mutex_lock_common(lock, TASK_KILLABLE, 925 - subclass, NULL, _RET_IP_, NULL, 0); 769 + return __mutex_lock(lock, TASK_KILLABLE, subclass, NULL, _RET_IP_); 926 770 } 927 771 EXPORT_SYMBOL_GPL(mutex_lock_killable_nested); 928 772 929 773 int __sched 930 774 mutex_lock_interruptible_nested(struct mutex *lock, unsigned int subclass) 931 775 { 932 - might_sleep(); 933 - return __mutex_lock_common(lock, TASK_INTERRUPTIBLE, 934 - subclass, NULL, _RET_IP_, NULL, 0); 776 + return __mutex_lock(lock, TASK_INTERRUPTIBLE, subclass, NULL, _RET_IP_); 935 777 } 936 778 EXPORT_SYMBOL_GPL(mutex_lock_interruptible_nested); 937 779 ··· 970 824 } 971 825 972 826 int __sched 973 - __ww_mutex_lock(struct ww_mutex *lock, struct ww_acquire_ctx *ctx) 827 + ww_mutex_lock(struct ww_mutex *lock, struct ww_acquire_ctx *ctx) 974 828 { 975 829 int ret; 976 830 977 831 might_sleep(); 978 - ret = __mutex_lock_common(&lock->base, TASK_UNINTERRUPTIBLE, 979 - 0, &ctx->dep_map, _RET_IP_, ctx, 1); 980 - if (!ret && ctx->acquired > 1) 832 + ret = __ww_mutex_lock(&lock->base, TASK_UNINTERRUPTIBLE, 833 + 0, ctx ? &ctx->dep_map : NULL, _RET_IP_, 834 + ctx); 835 + if (!ret && ctx && ctx->acquired > 1) 981 836 return ww_mutex_deadlock_injection(lock, ctx); 982 837 983 838 return ret; 984 839 } 985 - EXPORT_SYMBOL_GPL(__ww_mutex_lock); 840 + EXPORT_SYMBOL_GPL(ww_mutex_lock); 986 841 987 842 int __sched 988 - __ww_mutex_lock_interruptible(struct ww_mutex *lock, struct ww_acquire_ctx *ctx) 843 + ww_mutex_lock_interruptible(struct ww_mutex *lock, struct ww_acquire_ctx *ctx) 989 844 { 990 845 int ret; 991 846 992 847 might_sleep(); 993 - ret = __mutex_lock_common(&lock->base, TASK_INTERRUPTIBLE, 994 - 0, &ctx->dep_map, _RET_IP_, ctx, 1); 848 + ret = __ww_mutex_lock(&lock->base, TASK_INTERRUPTIBLE, 849 + 0, ctx ? &ctx->dep_map : NULL, _RET_IP_, 850 + ctx); 995 851 996 - if (!ret && ctx->acquired > 1) 852 + if (!ret && ctx && ctx->acquired > 1) 997 853 return ww_mutex_deadlock_injection(lock, ctx); 998 854 999 855 return ret; 1000 856 } 1001 - EXPORT_SYMBOL_GPL(__ww_mutex_lock_interruptible); 857 + EXPORT_SYMBOL_GPL(ww_mutex_lock_interruptible); 1002 858 1003 859 #endif 1004 860 ··· 1010 862 static noinline void __sched __mutex_unlock_slowpath(struct mutex *lock, unsigned long ip) 1011 863 { 1012 864 struct task_struct *next = NULL; 1013 - unsigned long owner, flags; 1014 865 DEFINE_WAKE_Q(wake_q); 866 + unsigned long owner; 1015 867 1016 868 mutex_release(&lock->dep_map, 1, ip); 1017 869 ··· 1028 880 1029 881 #ifdef CONFIG_DEBUG_MUTEXES 1030 882 DEBUG_LOCKS_WARN_ON(__owner_task(owner) != current); 883 + DEBUG_LOCKS_WARN_ON(owner & MUTEX_FLAG_PICKUP); 1031 884 #endif 1032 885 1033 886 if (owner & MUTEX_FLAG_HANDOFF) ··· 1046 897 owner = old; 1047 898 } 1048 899 1049 - spin_lock_mutex(&lock->wait_lock, flags); 900 + spin_lock(&lock->wait_lock); 1050 901 debug_mutex_unlock(lock); 1051 902 if (!list_empty(&lock->wait_list)) { 1052 903 /* get the first entry from the wait-list: */ ··· 1063 914 if (owner & MUTEX_FLAG_HANDOFF) 1064 915 __mutex_handoff(lock, next); 1065 916 1066 - spin_unlock_mutex(&lock->wait_lock, flags); 917 + spin_unlock(&lock->wait_lock); 1067 918 1068 919 wake_up_q(&wake_q); 1069 920 } ··· 1126 977 static noinline void __sched 1127 978 __mutex_lock_slowpath(struct mutex *lock) 1128 979 { 1129 - __mutex_lock_common(lock, TASK_UNINTERRUPTIBLE, 0, 1130 - NULL, _RET_IP_, NULL, 0); 980 + __mutex_lock(lock, TASK_UNINTERRUPTIBLE, 0, NULL, _RET_IP_); 1131 981 } 1132 982 1133 983 static noinline int __sched 1134 984 __mutex_lock_killable_slowpath(struct mutex *lock) 1135 985 { 1136 - return __mutex_lock_common(lock, TASK_KILLABLE, 0, 1137 - NULL, _RET_IP_, NULL, 0); 986 + return __mutex_lock(lock, TASK_KILLABLE, 0, NULL, _RET_IP_); 1138 987 } 1139 988 1140 989 static noinline int __sched 1141 990 __mutex_lock_interruptible_slowpath(struct mutex *lock) 1142 991 { 1143 - return __mutex_lock_common(lock, TASK_INTERRUPTIBLE, 0, 1144 - NULL, _RET_IP_, NULL, 0); 992 + return __mutex_lock(lock, TASK_INTERRUPTIBLE, 0, NULL, _RET_IP_); 1145 993 } 1146 994 1147 995 static noinline int __sched 1148 996 __ww_mutex_lock_slowpath(struct ww_mutex *lock, struct ww_acquire_ctx *ctx) 1149 997 { 1150 - return __mutex_lock_common(&lock->base, TASK_UNINTERRUPTIBLE, 0, 1151 - NULL, _RET_IP_, ctx, 1); 998 + return __ww_mutex_lock(&lock->base, TASK_UNINTERRUPTIBLE, 0, NULL, 999 + _RET_IP_, ctx); 1152 1000 } 1153 1001 1154 1002 static noinline int __sched 1155 1003 __ww_mutex_lock_interruptible_slowpath(struct ww_mutex *lock, 1156 1004 struct ww_acquire_ctx *ctx) 1157 1005 { 1158 - return __mutex_lock_common(&lock->base, TASK_INTERRUPTIBLE, 0, 1159 - NULL, _RET_IP_, ctx, 1); 1006 + return __ww_mutex_lock(&lock->base, TASK_INTERRUPTIBLE, 0, NULL, 1007 + _RET_IP_, ctx); 1160 1008 } 1161 1009 1162 1010 #endif ··· 1174 1028 */ 1175 1029 int __sched mutex_trylock(struct mutex *lock) 1176 1030 { 1177 - bool locked = __mutex_trylock(lock, false); 1031 + bool locked = __mutex_trylock(lock); 1178 1032 1179 1033 if (locked) 1180 1034 mutex_acquire(&lock->dep_map, 0, 1, _RET_IP_); ··· 1185 1039 1186 1040 #ifndef CONFIG_DEBUG_LOCK_ALLOC 1187 1041 int __sched 1188 - __ww_mutex_lock(struct ww_mutex *lock, struct ww_acquire_ctx *ctx) 1042 + ww_mutex_lock(struct ww_mutex *lock, struct ww_acquire_ctx *ctx) 1189 1043 { 1190 1044 might_sleep(); 1191 1045 1192 1046 if (__mutex_trylock_fast(&lock->base)) { 1193 - ww_mutex_set_context_fastpath(lock, ctx); 1047 + if (ctx) 1048 + ww_mutex_set_context_fastpath(lock, ctx); 1194 1049 return 0; 1195 1050 } 1196 1051 1197 1052 return __ww_mutex_lock_slowpath(lock, ctx); 1198 1053 } 1199 - EXPORT_SYMBOL(__ww_mutex_lock); 1054 + EXPORT_SYMBOL(ww_mutex_lock); 1200 1055 1201 1056 int __sched 1202 - __ww_mutex_lock_interruptible(struct ww_mutex *lock, struct ww_acquire_ctx *ctx) 1057 + ww_mutex_lock_interruptible(struct ww_mutex *lock, struct ww_acquire_ctx *ctx) 1203 1058 { 1204 1059 might_sleep(); 1205 1060 1206 1061 if (__mutex_trylock_fast(&lock->base)) { 1207 - ww_mutex_set_context_fastpath(lock, ctx); 1062 + if (ctx) 1063 + ww_mutex_set_context_fastpath(lock, ctx); 1208 1064 return 0; 1209 1065 } 1210 1066 1211 1067 return __ww_mutex_lock_interruptible_slowpath(lock, ctx); 1212 1068 } 1213 - EXPORT_SYMBOL(__ww_mutex_lock_interruptible); 1069 + EXPORT_SYMBOL(ww_mutex_lock_interruptible); 1214 1070 1215 1071 #endif 1216 1072
-4
kernel/locking/mutex.h
··· 9 9 * !CONFIG_DEBUG_MUTEXES case. Most of them are NOPs: 10 10 */ 11 11 12 - #define spin_lock_mutex(lock, flags) \ 13 - do { spin_lock(lock); (void)(flags); } while (0) 14 - #define spin_unlock_mutex(lock, flags) \ 15 - do { spin_unlock(lock); (void)(flags); } while (0) 16 12 #define mutex_remove_waiter(lock, waiter, task) \ 17 13 __list_del((waiter)->list.prev, (waiter)->list.next) 18 14
+3 -4
kernel/locking/percpu-rwsem.c
··· 1 1 #include <linux/atomic.h> 2 2 #include <linux/rwsem.h> 3 3 #include <linux/percpu.h> 4 - #include <linux/wait.h> 5 4 #include <linux/lockdep.h> 6 5 #include <linux/percpu-rwsem.h> 7 6 #include <linux/rcupdate.h> ··· 17 18 /* ->rw_sem represents the whole percpu_rw_semaphore for lockdep */ 18 19 rcu_sync_init(&sem->rss, RCU_SCHED_SYNC); 19 20 __init_rwsem(&sem->rw_sem, name, rwsem_key); 20 - init_waitqueue_head(&sem->writer); 21 + rcuwait_init(&sem->writer); 21 22 sem->readers_block = 0; 22 23 return 0; 23 24 } ··· 102 103 __this_cpu_dec(*sem->read_count); 103 104 104 105 /* Prod writer to recheck readers_active */ 105 - wake_up(&sem->writer); 106 + rcuwait_wake_up(&sem->writer); 106 107 } 107 108 EXPORT_SYMBOL_GPL(__percpu_up_read); 108 109 ··· 159 160 */ 160 161 161 162 /* Wait for all now active readers to complete. */ 162 - wait_event(sem->writer, readers_active_check(sem)); 163 + rcuwait_wait_event(&sem->writer, readers_active_check(sem)); 163 164 } 164 165 EXPORT_SYMBOL_GPL(percpu_down_write); 165 166
+1 -1
kernel/locking/qspinlock_paravirt.h
··· 263 263 if ((loop & PV_PREV_CHECK_MASK) != 0) 264 264 return false; 265 265 266 - return READ_ONCE(prev->state) != vcpu_running; 266 + return READ_ONCE(prev->state) != vcpu_running || vcpu_is_preempted(prev->cpu); 267 267 } 268 268 269 269 /*
+1 -1
kernel/locking/rtmutex.c
··· 1179 1179 * TASK_INTERRUPTIBLE checks for signals and 1180 1180 * timeout. Ignored otherwise. 1181 1181 */ 1182 - if (unlikely(state == TASK_INTERRUPTIBLE)) { 1182 + if (likely(state == TASK_INTERRUPTIBLE)) { 1183 1183 /* Signal pending? */ 1184 1184 if (signal_pending(current)) 1185 1185 ret = -EINTR;
+7 -11
kernel/locking/rwsem-spinlock.c
··· 128 128 void __sched __down_read(struct rw_semaphore *sem) 129 129 { 130 130 struct rwsem_waiter waiter; 131 - struct task_struct *tsk; 132 131 unsigned long flags; 133 132 134 133 raw_spin_lock_irqsave(&sem->wait_lock, flags); ··· 139 140 goto out; 140 141 } 141 142 142 - tsk = current; 143 - set_task_state(tsk, TASK_UNINTERRUPTIBLE); 143 + set_current_state(TASK_UNINTERRUPTIBLE); 144 144 145 145 /* set up my own style of waitqueue */ 146 - waiter.task = tsk; 146 + waiter.task = current; 147 147 waiter.type = RWSEM_WAITING_FOR_READ; 148 - get_task_struct(tsk); 148 + get_task_struct(current); 149 149 150 150 list_add_tail(&waiter.list, &sem->wait_list); 151 151 ··· 156 158 if (!waiter.task) 157 159 break; 158 160 schedule(); 159 - set_task_state(tsk, TASK_UNINTERRUPTIBLE); 161 + set_current_state(TASK_UNINTERRUPTIBLE); 160 162 } 161 163 162 - __set_task_state(tsk, TASK_RUNNING); 164 + __set_current_state(TASK_RUNNING); 163 165 out: 164 166 ; 165 167 } ··· 192 194 int __sched __down_write_common(struct rw_semaphore *sem, int state) 193 195 { 194 196 struct rwsem_waiter waiter; 195 - struct task_struct *tsk; 196 197 unsigned long flags; 197 198 int ret = 0; 198 199 199 200 raw_spin_lock_irqsave(&sem->wait_lock, flags); 200 201 201 202 /* set up my own style of waitqueue */ 202 - tsk = current; 203 - waiter.task = tsk; 203 + waiter.task = current; 204 204 waiter.type = RWSEM_WAITING_FOR_WRITE; 205 205 list_add_tail(&waiter.list, &sem->wait_list); 206 206 ··· 216 220 ret = -EINTR; 217 221 goto out; 218 222 } 219 - set_task_state(tsk, state); 223 + set_current_state(state); 220 224 raw_spin_unlock_irqrestore(&sem->wait_lock, flags); 221 225 schedule(); 222 226 raw_spin_lock_irqsave(&sem->wait_lock, flags);
+8 -6
kernel/locking/rwsem-xadd.c
··· 224 224 { 225 225 long count, adjustment = -RWSEM_ACTIVE_READ_BIAS; 226 226 struct rwsem_waiter waiter; 227 - struct task_struct *tsk = current; 228 227 DEFINE_WAKE_Q(wake_q); 229 228 230 - waiter.task = tsk; 229 + waiter.task = current; 231 230 waiter.type = RWSEM_WAITING_FOR_READ; 232 231 233 232 raw_spin_lock_irq(&sem->wait_lock); ··· 253 254 254 255 /* wait to be given the lock */ 255 256 while (true) { 256 - set_task_state(tsk, TASK_UNINTERRUPTIBLE); 257 + set_current_state(TASK_UNINTERRUPTIBLE); 257 258 if (!waiter.task) 258 259 break; 259 260 schedule(); 260 261 } 261 262 262 - __set_task_state(tsk, TASK_RUNNING); 263 + __set_current_state(TASK_RUNNING); 263 264 return sem; 264 265 } 265 266 EXPORT_SYMBOL(rwsem_down_read_failed); ··· 502 503 * wake any read locks that were queued ahead of us. 503 504 */ 504 505 if (count > RWSEM_WAITING_BIAS) { 505 - DEFINE_WAKE_Q(wake_q); 506 - 507 506 __rwsem_mark_wake(sem, RWSEM_WAKE_READERS, &wake_q); 508 507 /* 509 508 * The wakeup is normally called _after_ the wait_lock ··· 511 514 * for attempting rwsem_try_write_lock(). 512 515 */ 513 516 wake_up_q(&wake_q); 517 + 518 + /* 519 + * Reinitialize wake_q after use. 520 + */ 521 + wake_q_init(&wake_q); 514 522 } 515 523 516 524 } else
+3 -4
kernel/locking/semaphore.c
··· 204 204 static inline int __sched __down_common(struct semaphore *sem, long state, 205 205 long timeout) 206 206 { 207 - struct task_struct *task = current; 208 207 struct semaphore_waiter waiter; 209 208 210 209 list_add_tail(&waiter.list, &sem->wait_list); 211 - waiter.task = task; 210 + waiter.task = current; 212 211 waiter.up = false; 213 212 214 213 for (;;) { 215 - if (signal_pending_state(state, task)) 214 + if (signal_pending_state(state, current)) 216 215 goto interrupted; 217 216 if (unlikely(timeout <= 0)) 218 217 goto timed_out; 219 - __set_task_state(task, state); 218 + __set_current_state(state); 220 219 raw_spin_unlock_irq(&sem->lock); 221 220 timeout = schedule_timeout(timeout); 222 221 raw_spin_lock_irq(&sem->lock);
-8
kernel/locking/spinlock.c
··· 363 363 } 364 364 EXPORT_SYMBOL(_raw_spin_lock_nested); 365 365 366 - void __lockfunc _raw_spin_lock_bh_nested(raw_spinlock_t *lock, int subclass) 367 - { 368 - __local_bh_disable_ip(_RET_IP_, SOFTIRQ_LOCK_OFFSET); 369 - spin_acquire(&lock->dep_map, subclass, 0, _RET_IP_); 370 - LOCK_CONTENDED(lock, do_raw_spin_trylock, do_raw_spin_lock); 371 - } 372 - EXPORT_SYMBOL(_raw_spin_lock_bh_nested); 373 - 374 366 unsigned long __lockfunc _raw_spin_lock_irqsave_nested(raw_spinlock_t *lock, 375 367 int subclass) 376 368 {
+5 -81
kernel/locking/spinlock_debug.c
··· 103 103 lock->owner_cpu = -1; 104 104 } 105 105 106 - static void __spin_lock_debug(raw_spinlock_t *lock) 107 - { 108 - u64 i; 109 - u64 loops = loops_per_jiffy * HZ; 110 - 111 - for (i = 0; i < loops; i++) { 112 - if (arch_spin_trylock(&lock->raw_lock)) 113 - return; 114 - __delay(1); 115 - } 116 - /* lockup suspected: */ 117 - spin_dump(lock, "lockup suspected"); 118 - #ifdef CONFIG_SMP 119 - trigger_all_cpu_backtrace(); 120 - #endif 121 - 122 - /* 123 - * The trylock above was causing a livelock. Give the lower level arch 124 - * specific lock code a chance to acquire the lock. We have already 125 - * printed a warning/backtrace at this point. The non-debug arch 126 - * specific code might actually succeed in acquiring the lock. If it is 127 - * not successful, the end-result is the same - there is no forward 128 - * progress. 129 - */ 130 - arch_spin_lock(&lock->raw_lock); 131 - } 132 - 106 + /* 107 + * We are now relying on the NMI watchdog to detect lockup instead of doing 108 + * the detection here with an unfair lock which can cause problem of its own. 109 + */ 133 110 void do_raw_spin_lock(raw_spinlock_t *lock) 134 111 { 135 112 debug_spin_lock_before(lock); 136 - if (unlikely(!arch_spin_trylock(&lock->raw_lock))) 137 - __spin_lock_debug(lock); 113 + arch_spin_lock(&lock->raw_lock); 138 114 debug_spin_lock_after(lock); 139 115 } 140 116 ··· 147 171 } 148 172 149 173 #define RWLOCK_BUG_ON(cond, lock, msg) if (unlikely(cond)) rwlock_bug(lock, msg) 150 - 151 - #if 0 /* __write_lock_debug() can lock up - maybe this can too? */ 152 - static void __read_lock_debug(rwlock_t *lock) 153 - { 154 - u64 i; 155 - u64 loops = loops_per_jiffy * HZ; 156 - int print_once = 1; 157 - 158 - for (;;) { 159 - for (i = 0; i < loops; i++) { 160 - if (arch_read_trylock(&lock->raw_lock)) 161 - return; 162 - __delay(1); 163 - } 164 - /* lockup suspected: */ 165 - if (print_once) { 166 - print_once = 0; 167 - printk(KERN_EMERG "BUG: read-lock lockup on CPU#%d, " 168 - "%s/%d, %p\n", 169 - raw_smp_processor_id(), current->comm, 170 - current->pid, lock); 171 - dump_stack(); 172 - } 173 - } 174 - } 175 - #endif 176 174 177 175 void do_raw_read_lock(rwlock_t *lock) 178 176 { ··· 196 246 lock->owner = SPINLOCK_OWNER_INIT; 197 247 lock->owner_cpu = -1; 198 248 } 199 - 200 - #if 0 /* This can cause lockups */ 201 - static void __write_lock_debug(rwlock_t *lock) 202 - { 203 - u64 i; 204 - u64 loops = loops_per_jiffy * HZ; 205 - int print_once = 1; 206 - 207 - for (;;) { 208 - for (i = 0; i < loops; i++) { 209 - if (arch_write_trylock(&lock->raw_lock)) 210 - return; 211 - __delay(1); 212 - } 213 - /* lockup suspected: */ 214 - if (print_once) { 215 - print_once = 0; 216 - printk(KERN_EMERG "BUG: write-lock lockup on CPU#%d, " 217 - "%s/%d, %p\n", 218 - raw_smp_processor_id(), current->comm, 219 - current->pid, lock); 220 - dump_stack(); 221 - } 222 - } 223 - } 224 - #endif 225 249 226 250 void do_raw_write_lock(rwlock_t *lock) 227 251 {
+646
kernel/locking/test-ww_mutex.c
··· 1 + /* 2 + * Module-based API test facility for ww_mutexes 3 + * 4 + * This program is free software; you can redistribute it and/or modify 5 + * it under the terms of the GNU General Public License as published by 6 + * the Free Software Foundation; either version 2 of the License, or 7 + * (at your option) any later version. 8 + * 9 + * This program is distributed in the hope that it will be useful, 10 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 + * GNU General Public License for more details. 13 + * 14 + * You should have received a copy of the GNU General Public License 15 + * along with this program; if not, you can access it online at 16 + * http://www.gnu.org/licenses/gpl-2.0.html. 17 + */ 18 + 19 + #include <linux/kernel.h> 20 + 21 + #include <linux/completion.h> 22 + #include <linux/delay.h> 23 + #include <linux/kthread.h> 24 + #include <linux/module.h> 25 + #include <linux/random.h> 26 + #include <linux/slab.h> 27 + #include <linux/ww_mutex.h> 28 + 29 + static DEFINE_WW_CLASS(ww_class); 30 + struct workqueue_struct *wq; 31 + 32 + struct test_mutex { 33 + struct work_struct work; 34 + struct ww_mutex mutex; 35 + struct completion ready, go, done; 36 + unsigned int flags; 37 + }; 38 + 39 + #define TEST_MTX_SPIN BIT(0) 40 + #define TEST_MTX_TRY BIT(1) 41 + #define TEST_MTX_CTX BIT(2) 42 + #define __TEST_MTX_LAST BIT(3) 43 + 44 + static void test_mutex_work(struct work_struct *work) 45 + { 46 + struct test_mutex *mtx = container_of(work, typeof(*mtx), work); 47 + 48 + complete(&mtx->ready); 49 + wait_for_completion(&mtx->go); 50 + 51 + if (mtx->flags & TEST_MTX_TRY) { 52 + while (!ww_mutex_trylock(&mtx->mutex)) 53 + cpu_relax(); 54 + } else { 55 + ww_mutex_lock(&mtx->mutex, NULL); 56 + } 57 + complete(&mtx->done); 58 + ww_mutex_unlock(&mtx->mutex); 59 + } 60 + 61 + static int __test_mutex(unsigned int flags) 62 + { 63 + #define TIMEOUT (HZ / 16) 64 + struct test_mutex mtx; 65 + struct ww_acquire_ctx ctx; 66 + int ret; 67 + 68 + ww_mutex_init(&mtx.mutex, &ww_class); 69 + ww_acquire_init(&ctx, &ww_class); 70 + 71 + INIT_WORK_ONSTACK(&mtx.work, test_mutex_work); 72 + init_completion(&mtx.ready); 73 + init_completion(&mtx.go); 74 + init_completion(&mtx.done); 75 + mtx.flags = flags; 76 + 77 + schedule_work(&mtx.work); 78 + 79 + wait_for_completion(&mtx.ready); 80 + ww_mutex_lock(&mtx.mutex, (flags & TEST_MTX_CTX) ? &ctx : NULL); 81 + complete(&mtx.go); 82 + if (flags & TEST_MTX_SPIN) { 83 + unsigned long timeout = jiffies + TIMEOUT; 84 + 85 + ret = 0; 86 + do { 87 + if (completion_done(&mtx.done)) { 88 + ret = -EINVAL; 89 + break; 90 + } 91 + cpu_relax(); 92 + } while (time_before(jiffies, timeout)); 93 + } else { 94 + ret = wait_for_completion_timeout(&mtx.done, TIMEOUT); 95 + } 96 + ww_mutex_unlock(&mtx.mutex); 97 + ww_acquire_fini(&ctx); 98 + 99 + if (ret) { 100 + pr_err("%s(flags=%x): mutual exclusion failure\n", 101 + __func__, flags); 102 + ret = -EINVAL; 103 + } 104 + 105 + flush_work(&mtx.work); 106 + destroy_work_on_stack(&mtx.work); 107 + return ret; 108 + #undef TIMEOUT 109 + } 110 + 111 + static int test_mutex(void) 112 + { 113 + int ret; 114 + int i; 115 + 116 + for (i = 0; i < __TEST_MTX_LAST; i++) { 117 + ret = __test_mutex(i); 118 + if (ret) 119 + return ret; 120 + } 121 + 122 + return 0; 123 + } 124 + 125 + static int test_aa(void) 126 + { 127 + struct ww_mutex mutex; 128 + struct ww_acquire_ctx ctx; 129 + int ret; 130 + 131 + ww_mutex_init(&mutex, &ww_class); 132 + ww_acquire_init(&ctx, &ww_class); 133 + 134 + ww_mutex_lock(&mutex, &ctx); 135 + 136 + if (ww_mutex_trylock(&mutex)) { 137 + pr_err("%s: trylocked itself!\n", __func__); 138 + ww_mutex_unlock(&mutex); 139 + ret = -EINVAL; 140 + goto out; 141 + } 142 + 143 + ret = ww_mutex_lock(&mutex, &ctx); 144 + if (ret != -EALREADY) { 145 + pr_err("%s: missed deadlock for recursing, ret=%d\n", 146 + __func__, ret); 147 + if (!ret) 148 + ww_mutex_unlock(&mutex); 149 + ret = -EINVAL; 150 + goto out; 151 + } 152 + 153 + ret = 0; 154 + out: 155 + ww_mutex_unlock(&mutex); 156 + ww_acquire_fini(&ctx); 157 + return ret; 158 + } 159 + 160 + struct test_abba { 161 + struct work_struct work; 162 + struct ww_mutex a_mutex; 163 + struct ww_mutex b_mutex; 164 + struct completion a_ready; 165 + struct completion b_ready; 166 + bool resolve; 167 + int result; 168 + }; 169 + 170 + static void test_abba_work(struct work_struct *work) 171 + { 172 + struct test_abba *abba = container_of(work, typeof(*abba), work); 173 + struct ww_acquire_ctx ctx; 174 + int err; 175 + 176 + ww_acquire_init(&ctx, &ww_class); 177 + ww_mutex_lock(&abba->b_mutex, &ctx); 178 + 179 + complete(&abba->b_ready); 180 + wait_for_completion(&abba->a_ready); 181 + 182 + err = ww_mutex_lock(&abba->a_mutex, &ctx); 183 + if (abba->resolve && err == -EDEADLK) { 184 + ww_mutex_unlock(&abba->b_mutex); 185 + ww_mutex_lock_slow(&abba->a_mutex, &ctx); 186 + err = ww_mutex_lock(&abba->b_mutex, &ctx); 187 + } 188 + 189 + if (!err) 190 + ww_mutex_unlock(&abba->a_mutex); 191 + ww_mutex_unlock(&abba->b_mutex); 192 + ww_acquire_fini(&ctx); 193 + 194 + abba->result = err; 195 + } 196 + 197 + static int test_abba(bool resolve) 198 + { 199 + struct test_abba abba; 200 + struct ww_acquire_ctx ctx; 201 + int err, ret; 202 + 203 + ww_mutex_init(&abba.a_mutex, &ww_class); 204 + ww_mutex_init(&abba.b_mutex, &ww_class); 205 + INIT_WORK_ONSTACK(&abba.work, test_abba_work); 206 + init_completion(&abba.a_ready); 207 + init_completion(&abba.b_ready); 208 + abba.resolve = resolve; 209 + 210 + schedule_work(&abba.work); 211 + 212 + ww_acquire_init(&ctx, &ww_class); 213 + ww_mutex_lock(&abba.a_mutex, &ctx); 214 + 215 + complete(&abba.a_ready); 216 + wait_for_completion(&abba.b_ready); 217 + 218 + err = ww_mutex_lock(&abba.b_mutex, &ctx); 219 + if (resolve && err == -EDEADLK) { 220 + ww_mutex_unlock(&abba.a_mutex); 221 + ww_mutex_lock_slow(&abba.b_mutex, &ctx); 222 + err = ww_mutex_lock(&abba.a_mutex, &ctx); 223 + } 224 + 225 + if (!err) 226 + ww_mutex_unlock(&abba.b_mutex); 227 + ww_mutex_unlock(&abba.a_mutex); 228 + ww_acquire_fini(&ctx); 229 + 230 + flush_work(&abba.work); 231 + destroy_work_on_stack(&abba.work); 232 + 233 + ret = 0; 234 + if (resolve) { 235 + if (err || abba.result) { 236 + pr_err("%s: failed to resolve ABBA deadlock, A err=%d, B err=%d\n", 237 + __func__, err, abba.result); 238 + ret = -EINVAL; 239 + } 240 + } else { 241 + if (err != -EDEADLK && abba.result != -EDEADLK) { 242 + pr_err("%s: missed ABBA deadlock, A err=%d, B err=%d\n", 243 + __func__, err, abba.result); 244 + ret = -EINVAL; 245 + } 246 + } 247 + return ret; 248 + } 249 + 250 + struct test_cycle { 251 + struct work_struct work; 252 + struct ww_mutex a_mutex; 253 + struct ww_mutex *b_mutex; 254 + struct completion *a_signal; 255 + struct completion b_signal; 256 + int result; 257 + }; 258 + 259 + static void test_cycle_work(struct work_struct *work) 260 + { 261 + struct test_cycle *cycle = container_of(work, typeof(*cycle), work); 262 + struct ww_acquire_ctx ctx; 263 + int err; 264 + 265 + ww_acquire_init(&ctx, &ww_class); 266 + ww_mutex_lock(&cycle->a_mutex, &ctx); 267 + 268 + complete(cycle->a_signal); 269 + wait_for_completion(&cycle->b_signal); 270 + 271 + err = ww_mutex_lock(cycle->b_mutex, &ctx); 272 + if (err == -EDEADLK) { 273 + ww_mutex_unlock(&cycle->a_mutex); 274 + ww_mutex_lock_slow(cycle->b_mutex, &ctx); 275 + err = ww_mutex_lock(&cycle->a_mutex, &ctx); 276 + } 277 + 278 + if (!err) 279 + ww_mutex_unlock(cycle->b_mutex); 280 + ww_mutex_unlock(&cycle->a_mutex); 281 + ww_acquire_fini(&ctx); 282 + 283 + cycle->result = err; 284 + } 285 + 286 + static int __test_cycle(unsigned int nthreads) 287 + { 288 + struct test_cycle *cycles; 289 + unsigned int n, last = nthreads - 1; 290 + int ret; 291 + 292 + cycles = kmalloc_array(nthreads, sizeof(*cycles), GFP_KERNEL); 293 + if (!cycles) 294 + return -ENOMEM; 295 + 296 + for (n = 0; n < nthreads; n++) { 297 + struct test_cycle *cycle = &cycles[n]; 298 + 299 + ww_mutex_init(&cycle->a_mutex, &ww_class); 300 + if (n == last) 301 + cycle->b_mutex = &cycles[0].a_mutex; 302 + else 303 + cycle->b_mutex = &cycles[n + 1].a_mutex; 304 + 305 + if (n == 0) 306 + cycle->a_signal = &cycles[last].b_signal; 307 + else 308 + cycle->a_signal = &cycles[n - 1].b_signal; 309 + init_completion(&cycle->b_signal); 310 + 311 + INIT_WORK(&cycle->work, test_cycle_work); 312 + cycle->result = 0; 313 + } 314 + 315 + for (n = 0; n < nthreads; n++) 316 + queue_work(wq, &cycles[n].work); 317 + 318 + flush_workqueue(wq); 319 + 320 + ret = 0; 321 + for (n = 0; n < nthreads; n++) { 322 + struct test_cycle *cycle = &cycles[n]; 323 + 324 + if (!cycle->result) 325 + continue; 326 + 327 + pr_err("cylic deadlock not resolved, ret[%d/%d] = %d\n", 328 + n, nthreads, cycle->result); 329 + ret = -EINVAL; 330 + break; 331 + } 332 + 333 + for (n = 0; n < nthreads; n++) 334 + ww_mutex_destroy(&cycles[n].a_mutex); 335 + kfree(cycles); 336 + return ret; 337 + } 338 + 339 + static int test_cycle(unsigned int ncpus) 340 + { 341 + unsigned int n; 342 + int ret; 343 + 344 + for (n = 2; n <= ncpus + 1; n++) { 345 + ret = __test_cycle(n); 346 + if (ret) 347 + return ret; 348 + } 349 + 350 + return 0; 351 + } 352 + 353 + struct stress { 354 + struct work_struct work; 355 + struct ww_mutex *locks; 356 + int nlocks; 357 + int nloops; 358 + }; 359 + 360 + static int *get_random_order(int count) 361 + { 362 + int *order; 363 + int n, r, tmp; 364 + 365 + order = kmalloc_array(count, sizeof(*order), GFP_TEMPORARY); 366 + if (!order) 367 + return order; 368 + 369 + for (n = 0; n < count; n++) 370 + order[n] = n; 371 + 372 + for (n = count - 1; n > 1; n--) { 373 + r = get_random_int() % (n + 1); 374 + if (r != n) { 375 + tmp = order[n]; 376 + order[n] = order[r]; 377 + order[r] = tmp; 378 + } 379 + } 380 + 381 + return order; 382 + } 383 + 384 + static void dummy_load(struct stress *stress) 385 + { 386 + usleep_range(1000, 2000); 387 + } 388 + 389 + static void stress_inorder_work(struct work_struct *work) 390 + { 391 + struct stress *stress = container_of(work, typeof(*stress), work); 392 + const int nlocks = stress->nlocks; 393 + struct ww_mutex *locks = stress->locks; 394 + struct ww_acquire_ctx ctx; 395 + int *order; 396 + 397 + order = get_random_order(nlocks); 398 + if (!order) 399 + return; 400 + 401 + ww_acquire_init(&ctx, &ww_class); 402 + 403 + do { 404 + int contended = -1; 405 + int n, err; 406 + 407 + retry: 408 + err = 0; 409 + for (n = 0; n < nlocks; n++) { 410 + if (n == contended) 411 + continue; 412 + 413 + err = ww_mutex_lock(&locks[order[n]], &ctx); 414 + if (err < 0) 415 + break; 416 + } 417 + if (!err) 418 + dummy_load(stress); 419 + 420 + if (contended > n) 421 + ww_mutex_unlock(&locks[order[contended]]); 422 + contended = n; 423 + while (n--) 424 + ww_mutex_unlock(&locks[order[n]]); 425 + 426 + if (err == -EDEADLK) { 427 + ww_mutex_lock_slow(&locks[order[contended]], &ctx); 428 + goto retry; 429 + } 430 + 431 + if (err) { 432 + pr_err_once("stress (%s) failed with %d\n", 433 + __func__, err); 434 + break; 435 + } 436 + } while (--stress->nloops); 437 + 438 + ww_acquire_fini(&ctx); 439 + 440 + kfree(order); 441 + kfree(stress); 442 + } 443 + 444 + struct reorder_lock { 445 + struct list_head link; 446 + struct ww_mutex *lock; 447 + }; 448 + 449 + static void stress_reorder_work(struct work_struct *work) 450 + { 451 + struct stress *stress = container_of(work, typeof(*stress), work); 452 + LIST_HEAD(locks); 453 + struct ww_acquire_ctx ctx; 454 + struct reorder_lock *ll, *ln; 455 + int *order; 456 + int n, err; 457 + 458 + order = get_random_order(stress->nlocks); 459 + if (!order) 460 + return; 461 + 462 + for (n = 0; n < stress->nlocks; n++) { 463 + ll = kmalloc(sizeof(*ll), GFP_KERNEL); 464 + if (!ll) 465 + goto out; 466 + 467 + ll->lock = &stress->locks[order[n]]; 468 + list_add(&ll->link, &locks); 469 + } 470 + kfree(order); 471 + order = NULL; 472 + 473 + ww_acquire_init(&ctx, &ww_class); 474 + 475 + do { 476 + list_for_each_entry(ll, &locks, link) { 477 + err = ww_mutex_lock(ll->lock, &ctx); 478 + if (!err) 479 + continue; 480 + 481 + ln = ll; 482 + list_for_each_entry_continue_reverse(ln, &locks, link) 483 + ww_mutex_unlock(ln->lock); 484 + 485 + if (err != -EDEADLK) { 486 + pr_err_once("stress (%s) failed with %d\n", 487 + __func__, err); 488 + break; 489 + } 490 + 491 + ww_mutex_lock_slow(ll->lock, &ctx); 492 + list_move(&ll->link, &locks); /* restarts iteration */ 493 + } 494 + 495 + dummy_load(stress); 496 + list_for_each_entry(ll, &locks, link) 497 + ww_mutex_unlock(ll->lock); 498 + } while (--stress->nloops); 499 + 500 + ww_acquire_fini(&ctx); 501 + 502 + out: 503 + list_for_each_entry_safe(ll, ln, &locks, link) 504 + kfree(ll); 505 + kfree(order); 506 + kfree(stress); 507 + } 508 + 509 + static void stress_one_work(struct work_struct *work) 510 + { 511 + struct stress *stress = container_of(work, typeof(*stress), work); 512 + const int nlocks = stress->nlocks; 513 + struct ww_mutex *lock = stress->locks + (get_random_int() % nlocks); 514 + int err; 515 + 516 + do { 517 + err = ww_mutex_lock(lock, NULL); 518 + if (!err) { 519 + dummy_load(stress); 520 + ww_mutex_unlock(lock); 521 + } else { 522 + pr_err_once("stress (%s) failed with %d\n", 523 + __func__, err); 524 + break; 525 + } 526 + } while (--stress->nloops); 527 + 528 + kfree(stress); 529 + } 530 + 531 + #define STRESS_INORDER BIT(0) 532 + #define STRESS_REORDER BIT(1) 533 + #define STRESS_ONE BIT(2) 534 + #define STRESS_ALL (STRESS_INORDER | STRESS_REORDER | STRESS_ONE) 535 + 536 + static int stress(int nlocks, int nthreads, int nloops, unsigned int flags) 537 + { 538 + struct ww_mutex *locks; 539 + int n; 540 + 541 + locks = kmalloc_array(nlocks, sizeof(*locks), GFP_KERNEL); 542 + if (!locks) 543 + return -ENOMEM; 544 + 545 + for (n = 0; n < nlocks; n++) 546 + ww_mutex_init(&locks[n], &ww_class); 547 + 548 + for (n = 0; nthreads; n++) { 549 + struct stress *stress; 550 + void (*fn)(struct work_struct *work); 551 + 552 + fn = NULL; 553 + switch (n & 3) { 554 + case 0: 555 + if (flags & STRESS_INORDER) 556 + fn = stress_inorder_work; 557 + break; 558 + case 1: 559 + if (flags & STRESS_REORDER) 560 + fn = stress_reorder_work; 561 + break; 562 + case 2: 563 + if (flags & STRESS_ONE) 564 + fn = stress_one_work; 565 + break; 566 + } 567 + 568 + if (!fn) 569 + continue; 570 + 571 + stress = kmalloc(sizeof(*stress), GFP_KERNEL); 572 + if (!stress) 573 + break; 574 + 575 + INIT_WORK(&stress->work, fn); 576 + stress->locks = locks; 577 + stress->nlocks = nlocks; 578 + stress->nloops = nloops; 579 + 580 + queue_work(wq, &stress->work); 581 + nthreads--; 582 + } 583 + 584 + flush_workqueue(wq); 585 + 586 + for (n = 0; n < nlocks; n++) 587 + ww_mutex_destroy(&locks[n]); 588 + kfree(locks); 589 + 590 + return 0; 591 + } 592 + 593 + static int __init test_ww_mutex_init(void) 594 + { 595 + int ncpus = num_online_cpus(); 596 + int ret; 597 + 598 + wq = alloc_workqueue("test-ww_mutex", WQ_UNBOUND, 0); 599 + if (!wq) 600 + return -ENOMEM; 601 + 602 + ret = test_mutex(); 603 + if (ret) 604 + return ret; 605 + 606 + ret = test_aa(); 607 + if (ret) 608 + return ret; 609 + 610 + ret = test_abba(false); 611 + if (ret) 612 + return ret; 613 + 614 + ret = test_abba(true); 615 + if (ret) 616 + return ret; 617 + 618 + ret = test_cycle(ncpus); 619 + if (ret) 620 + return ret; 621 + 622 + ret = stress(16, 2*ncpus, 1<<10, STRESS_INORDER); 623 + if (ret) 624 + return ret; 625 + 626 + ret = stress(16, 2*ncpus, 1<<10, STRESS_REORDER); 627 + if (ret) 628 + return ret; 629 + 630 + ret = stress(4096, hweight32(STRESS_ALL)*ncpus, 1<<12, STRESS_ALL); 631 + if (ret) 632 + return ret; 633 + 634 + return 0; 635 + } 636 + 637 + static void __exit test_ww_mutex_exit(void) 638 + { 639 + destroy_workqueue(wq); 640 + } 641 + 642 + module_init(test_ww_mutex_init); 643 + module_exit(test_ww_mutex_exit); 644 + 645 + MODULE_LICENSE("GPL"); 646 + MODULE_AUTHOR("Intel Corporation");
+1 -3
kernel/pid.c
··· 68 68 * the scheme scales to up to 4 million PIDs, runtime. 69 69 */ 70 70 struct pid_namespace init_pid_ns = { 71 - .kref = { 72 - .refcount = ATOMIC_INIT(2), 73 - }, 71 + .kref = KREF_INIT(2), 74 72 .pidmap = { 75 73 [ 0 ... PIDMAP_ENTRIES-1] = { ATOMIC_INIT(BITS_PER_PAGE), NULL } 76 74 },
+25
lib/Kconfig.debug
··· 716 716 717 717 source "lib/Kconfig.kasan" 718 718 719 + config DEBUG_REFCOUNT 720 + bool "Verbose refcount checks" 721 + help 722 + Say Y here if you want reference counters (refcount_t and kref) to 723 + generate WARNs on dubious usage. Without this refcount_t will still 724 + be a saturating counter and avoid Use-After-Free by turning it into 725 + a resource leak Denial-Of-Service. 726 + 727 + Use of this option will increase kernel text size but will alert the 728 + admin of potential abuse. 729 + 730 + If in doubt, say "N". 731 + 719 732 endmenu # "Memory Debugging" 720 733 721 734 config ARCH_HAS_KCOV ··· 1177 1164 Say Y here if you want kernel locking-primitive torture tests 1178 1165 to be built into the kernel. 1179 1166 Say M if you want these torture tests to build as a module. 1167 + Say N if you are unsure. 1168 + 1169 + config WW_MUTEX_SELFTEST 1170 + tristate "Wait/wound mutex selftests" 1171 + help 1172 + This option provides a kernel module that runs tests on the 1173 + on the struct ww_mutex locking API. 1174 + 1175 + It is recommended to enable DEBUG_WW_MUTEX_SLOWPATH in conjunction 1176 + with this test harness. 1177 + 1178 + Say M if you want these self tests to build as a module. 1180 1179 Say N if you are unsure. 1181 1180 1182 1181 endmenu # lock debugging
+1 -1
net/bluetooth/6lowpan.c
··· 920 920 BT_DBG("dev %p removing %speer %p", dev, 921 921 last ? "last " : "1 ", peer); 922 922 BT_DBG("chan %p orig refcnt %d", chan, 923 - atomic_read(&chan->kref.refcount)); 923 + kref_read(&chan->kref)); 924 924 925 925 l2cap_chan_put(chan); 926 926 break;
+2 -2
net/bluetooth/a2mp.c
··· 810 810 /* AMP Manager functions */ 811 811 struct amp_mgr *amp_mgr_get(struct amp_mgr *mgr) 812 812 { 813 - BT_DBG("mgr %p orig refcnt %d", mgr, atomic_read(&mgr->kref.refcount)); 813 + BT_DBG("mgr %p orig refcnt %d", mgr, kref_read(&mgr->kref)); 814 814 815 815 kref_get(&mgr->kref); 816 816 ··· 833 833 834 834 int amp_mgr_put(struct amp_mgr *mgr) 835 835 { 836 - BT_DBG("mgr %p orig refcnt %d", mgr, atomic_read(&mgr->kref.refcount)); 836 + BT_DBG("mgr %p orig refcnt %d", mgr, kref_read(&mgr->kref)); 837 837 838 838 return kref_put(&mgr->kref, &amp_mgr_destroy); 839 839 }
+2 -2
net/bluetooth/amp.c
··· 24 24 void amp_ctrl_get(struct amp_ctrl *ctrl) 25 25 { 26 26 BT_DBG("ctrl %p orig refcnt %d", ctrl, 27 - atomic_read(&ctrl->kref.refcount)); 27 + kref_read(&ctrl->kref)); 28 28 29 29 kref_get(&ctrl->kref); 30 30 } ··· 42 42 int amp_ctrl_put(struct amp_ctrl *ctrl) 43 43 { 44 44 BT_DBG("ctrl %p orig refcnt %d", ctrl, 45 - atomic_read(&ctrl->kref.refcount)); 45 + kref_read(&ctrl->kref)); 46 46 47 47 return kref_put(&ctrl->kref, &amp_ctrl_destroy); 48 48 }
+2 -2
net/bluetooth/l2cap_core.c
··· 481 481 482 482 void l2cap_chan_hold(struct l2cap_chan *c) 483 483 { 484 - BT_DBG("chan %p orig refcnt %d", c, atomic_read(&c->kref.refcount)); 484 + BT_DBG("chan %p orig refcnt %d", c, kref_read(&c->kref)); 485 485 486 486 kref_get(&c->kref); 487 487 } 488 488 489 489 void l2cap_chan_put(struct l2cap_chan *c) 490 490 { 491 - BT_DBG("chan %p orig refcnt %d", c, atomic_read(&c->kref.refcount)); 491 + BT_DBG("chan %p orig refcnt %d", c, kref_read(&c->kref)); 492 492 493 493 kref_put(&c->kref, l2cap_chan_destroy); 494 494 }
+2 -2
net/ceph/messenger.c
··· 3425 3425 struct ceph_msg *ceph_msg_get(struct ceph_msg *msg) 3426 3426 { 3427 3427 dout("%s %p (was %d)\n", __func__, msg, 3428 - atomic_read(&msg->kref.refcount)); 3428 + kref_read(&msg->kref)); 3429 3429 kref_get(&msg->kref); 3430 3430 return msg; 3431 3431 } ··· 3434 3434 void ceph_msg_put(struct ceph_msg *msg) 3435 3435 { 3436 3436 dout("%s %p (was %d)\n", __func__, msg, 3437 - atomic_read(&msg->kref.refcount)); 3437 + kref_read(&msg->kref)); 3438 3438 kref_put(&msg->kref, ceph_msg_release); 3439 3439 } 3440 3440 EXPORT_SYMBOL(ceph_msg_put);
+5 -5
net/ceph/osd_client.c
··· 438 438 void ceph_osdc_get_request(struct ceph_osd_request *req) 439 439 { 440 440 dout("%s %p (was %d)\n", __func__, req, 441 - atomic_read(&req->r_kref.refcount)); 441 + kref_read(&req->r_kref)); 442 442 kref_get(&req->r_kref); 443 443 } 444 444 EXPORT_SYMBOL(ceph_osdc_get_request); ··· 447 447 { 448 448 if (req) { 449 449 dout("%s %p (was %d)\n", __func__, req, 450 - atomic_read(&req->r_kref.refcount)); 450 + kref_read(&req->r_kref)); 451 451 kref_put(&req->r_kref, ceph_osdc_release_request); 452 452 } 453 453 } ··· 487 487 struct ceph_msg *reply_msg = req->r_reply; 488 488 489 489 dout("%s req %p\n", __func__, req); 490 - WARN_ON(atomic_read(&req->r_kref.refcount) != 1); 490 + WARN_ON(kref_read(&req->r_kref) != 1); 491 491 request_release_checks(req); 492 492 493 - WARN_ON(atomic_read(&request_msg->kref.refcount) != 1); 494 - WARN_ON(atomic_read(&reply_msg->kref.refcount) != 1); 493 + WARN_ON(kref_read(&request_msg->kref) != 1); 494 + WARN_ON(kref_read(&reply_msg->kref) != 1); 495 495 target_destroy(&req->r_t); 496 496 497 497 request_init(req);
+1 -1
net/sunrpc/cache.c
··· 1358 1358 ifdebug(CACHE) 1359 1359 seq_printf(m, "# expiry=%ld refcnt=%d flags=%lx\n", 1360 1360 convert_to_wallclock(cp->expiry_time), 1361 - atomic_read(&cp->ref.refcount), cp->flags); 1361 + kref_read(&cp->ref), cp->flags); 1362 1362 cache_get(cp); 1363 1363 if (cache_check(cd, cp, NULL)) 1364 1364 /* cache_check does a cache_put on failure */
+3 -3
net/sunrpc/svc_xprt.c
··· 490 490 svc_xprt_get(xprt); 491 491 492 492 dprintk("svc: transport %p dequeued, inuse=%d\n", 493 - xprt, atomic_read(&xprt->xpt_ref.refcount)); 493 + xprt, kref_read(&xprt->xpt_ref)); 494 494 } 495 495 spin_unlock_bh(&pool->sp_lock); 496 496 out: ··· 822 822 /* XPT_DATA|XPT_DEFERRED case: */ 823 823 dprintk("svc: server %p, pool %u, transport %p, inuse=%d\n", 824 824 rqstp, rqstp->rq_pool->sp_id, xprt, 825 - atomic_read(&xprt->xpt_ref.refcount)); 825 + kref_read(&xprt->xpt_ref)); 826 826 rqstp->rq_deferred = svc_deferred_dequeue(xprt); 827 827 if (rqstp->rq_deferred) 828 828 len = svc_deferred_recv(rqstp); ··· 980 980 * through, close it. */ 981 981 if (!test_and_set_bit(XPT_OLD, &xprt->xpt_flags)) 982 982 continue; 983 - if (atomic_read(&xprt->xpt_ref.refcount) > 1 || 983 + if (kref_read(&xprt->xpt_ref) > 1 || 984 984 test_bit(XPT_BUSY, &xprt->xpt_flags)) 985 985 continue; 986 986 list_del_init(le);
+10 -5
net/sunrpc/svcauth.c
··· 126 126 static struct hlist_head auth_domain_table[DN_HASHMAX]; 127 127 static DEFINE_SPINLOCK(auth_domain_lock); 128 128 129 + static void auth_domain_release(struct kref *kref) 130 + { 131 + struct auth_domain *dom = container_of(kref, struct auth_domain, ref); 132 + 133 + hlist_del(&dom->hash); 134 + dom->flavour->domain_release(dom); 135 + spin_unlock(&auth_domain_lock); 136 + } 137 + 129 138 void auth_domain_put(struct auth_domain *dom) 130 139 { 131 - if (atomic_dec_and_lock(&dom->ref.refcount, &auth_domain_lock)) { 132 - hlist_del(&dom->hash); 133 - dom->flavour->domain_release(dom); 134 - spin_unlock(&auth_domain_lock); 135 - } 140 + kref_put_lock(&dom->ref, auth_domain_release, &auth_domain_lock); 136 141 } 137 142 EXPORT_SYMBOL_GPL(auth_domain_put); 138 143
+2 -2
net/sunrpc/xprtrdma/svc_rdma_transport.c
··· 1201 1201 ib_drain_qp(rdma->sc_qp); 1202 1202 1203 1203 /* We should only be called from kref_put */ 1204 - if (atomic_read(&xprt->xpt_ref.refcount) != 0) 1204 + if (kref_read(&xprt->xpt_ref) != 0) 1205 1205 pr_err("svcrdma: sc_xprt still in use? (%d)\n", 1206 - atomic_read(&xprt->xpt_ref.refcount)); 1206 + kref_read(&xprt->xpt_ref)); 1207 1207 1208 1208 /* 1209 1209 * Destroy queued, but not processed read completions. Note
-6
security/apparmor/include/apparmor.h
··· 78 78 return __aa_kvmalloc(size, __GFP_ZERO); 79 79 } 80 80 81 - /* returns 0 if kref not incremented */ 82 - static inline int kref_get_not0(struct kref *kref) 83 - { 84 - return atomic_inc_not_zero(&kref->refcount); 85 - } 86 - 87 81 /** 88 82 * aa_strneq - compare null terminated @str to a non null terminated substring 89 83 * @str: a null terminated string
+2 -2
security/apparmor/include/policy.h
··· 287 287 */ 288 288 static inline struct aa_profile *aa_get_profile_not0(struct aa_profile *p) 289 289 { 290 - if (p && kref_get_not0(&p->count)) 290 + if (p && kref_get_unless_zero(&p->count)) 291 291 return p; 292 292 293 293 return NULL; ··· 307 307 rcu_read_lock(); 308 308 do { 309 309 c = rcu_dereference(*p); 310 - } while (c && !kref_get_not0(&c->count)); 310 + } while (c && !kref_get_unless_zero(&c->count)); 311 311 rcu_read_unlock(); 312 312 313 313 return c;
+10
tools/testing/selftests/locking/ww_mutex.sh
··· 1 + #!/bin/sh 2 + # Runs API tests for struct ww_mutex (Wait/Wound mutexes) 3 + 4 + if /sbin/modprobe -q test-ww_mutex; then 5 + /sbin/modprobe -q -r test-ww_mutex 6 + echo "locking/ww_mutex: ok" 7 + else 8 + echo "locking/ww_mutex: [FAIL]" 9 + exit 1 10 + fi
+1
tools/testing/selftests/rcutorture/configs/lock/CFLIST
··· 4 4 LOCK04 5 5 LOCK05 6 6 LOCK06 7 + LOCK07
+6
tools/testing/selftests/rcutorture/configs/lock/LOCK07
··· 1 + CONFIG_SMP=y 2 + CONFIG_NR_CPUS=4 3 + CONFIG_HOTPLUG_CPU=y 4 + CONFIG_PREEMPT_NONE=n 5 + CONFIG_PREEMPT_VOLUNTARY=n 6 + CONFIG_PREEMPT=y
+1
tools/testing/selftests/rcutorture/configs/lock/LOCK07.boot
··· 1 + locktorture.torture_type=ww_mutex_lock