Skip to content

Commit 42e1b14

Browse files
committed
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() ...
2 parents 828cad8 + 95cb64c commit 42e1b14

116 files changed

Lines changed: 1864 additions & 761 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Documentation/locking/ww-mutex-design.txt‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,15 @@ Design:
309309
normal mutex locks, which are far more common. As such there is only a small
310310
increase in code size if wait/wound mutexes are not used.
311311

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+
312319
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.
317321

318322
Lockdep:
319323
Special care has been taken to warn for as many cases of api abuse

‎arch/um/drivers/random.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ static ssize_t rng_dev_read (struct file *filp, char __user *buf, size_t size,
7676
add_sigio_fd(random_fd);
7777

7878
add_wait_queue(&host_read_wait, &wait);
79-
set_task_state(current, TASK_INTERRUPTIBLE);
79+
set_current_state(TASK_INTERRUPTIBLE);
8080

8181
schedule();
8282
remove_wait_queue(&host_read_wait, &wait);

‎arch/x86/include/asm/spinlock.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
/* How long a lock should spin before we consider blocking */
2424
#define SPIN_THRESHOLD (1 << 15)
2525

26-
extern struct static_key paravirt_ticketlocks_enabled;
27-
static __always_inline bool static_key_false(struct static_key *key);
28-
2926
#include <asm/qspinlock.h>
3027

3128
/*

‎arch/x86/kernel/jump_label.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ static void bug_at(unsigned char *ip, int line)
3232
* Something went wrong. Crash the box, as something could be
3333
* corrupting the kernel.
3434
*/
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);
3736
BUG();
3837
}
3938

‎arch/x86/kernel/kvm.c‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -620,18 +620,4 @@ void __init kvm_spinlock_init(void)
620620
}
621621
}
622622

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-
637623
#endif /* CONFIG_PARAVIRT_SPINLOCKS */

‎arch/x86/kernel/paravirt-spinlocks.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,3 @@ struct pv_lock_ops pv_lock_ops = {
4242
#endif /* SMP */
4343
};
4444
EXPORT_SYMBOL(pv_lock_ops);
45-
46-
struct static_key paravirt_ticketlocks_enabled = STATIC_KEY_INIT_FALSE;
47-
EXPORT_SYMBOL(paravirt_ticketlocks_enabled);

‎arch/x86/xen/spinlock.c‎

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -141,25 +141,6 @@ void __init xen_init_spinlocks(void)
141141
pv_lock_ops.vcpu_is_preempted = PV_CALLEE_SAVE(xen_vcpu_stolen);
142142
}
143143

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-
163144
static __init int xen_parse_nopvspin(char *arg)
164145
{
165146
xen_pvspin = false;

‎drivers/block/drbd/drbd_bitmap.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ static int bm_rw(struct drbd_device *device, const unsigned int flags, unsigned
10701070
.done = 0,
10711071
.flags = flags,
10721072
.error = 0,
1073-
.kref = { ATOMIC_INIT(2) },
1073+
.kref = KREF_INIT(2),
10741074
};
10751075

10761076
if (!get_ldev_if_state(device, D_ATTACHING)) { /* put is in drbd_bm_aio_ctx_destroy() */

‎drivers/block/drbd/drbd_main.c‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2948,21 +2948,22 @@ void drbd_delete_device(struct drbd_device *device)
29482948
struct drbd_resource *resource = device->resource;
29492949
struct drbd_connection *connection;
29502950
struct drbd_peer_device *peer_device;
2951-
int refs = 3;
29522951

29532952
/* move to free_peer_device() */
29542953
for_each_peer_device(peer_device, device)
29552954
drbd_debugfs_peer_device_cleanup(peer_device);
29562955
drbd_debugfs_device_cleanup(device);
29572956
for_each_connection(connection, resource) {
29582957
idr_remove(&connection->peer_devices, device->vnr);
2959-
refs++;
2958+
kref_put(&device->kref, drbd_destroy_device);
29602959
}
29612960
idr_remove(&resource->devices, device->vnr);
2961+
kref_put(&device->kref, drbd_destroy_device);
29622962
idr_remove(&drbd_devices, device_to_minor(device));
2963+
kref_put(&device->kref, drbd_destroy_device);
29632964
del_gendisk(device->vdisk);
29642965
synchronize_rcu();
2965-
kref_sub(&device->kref, refs, drbd_destroy_device);
2966+
kref_put(&device->kref, drbd_destroy_device);
29662967
}
29672968

29682969
static int __init drbd_init(void)

‎drivers/block/drbd/drbd_req.c‎

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,6 @@ static void mod_rq_state(struct drbd_request *req, struct bio_and_error *m,
421421
struct drbd_peer_device *peer_device = first_peer_device(device);
422422
unsigned s = req->rq_state;
423423
int c_put = 0;
424-
int k_put = 0;
425424

426425
if (drbd_suspended(device) && !((s | clear) & RQ_COMPLETION_SUSP))
427426
set |= RQ_COMPLETION_SUSP;
@@ -437,6 +436,8 @@ static void mod_rq_state(struct drbd_request *req, struct bio_and_error *m,
437436

438437
/* intent: get references */
439438

439+
kref_get(&req->kref);
440+
440441
if (!(s & RQ_LOCAL_PENDING) && (set & RQ_LOCAL_PENDING))
441442
atomic_inc(&req->completion_ref);
442443

@@ -473,15 +474,12 @@ static void mod_rq_state(struct drbd_request *req, struct bio_and_error *m,
473474

474475
if (!(s & RQ_LOCAL_ABORTED) && (set & RQ_LOCAL_ABORTED)) {
475476
D_ASSERT(device, req->rq_state & RQ_LOCAL_PENDING);
476-
/* local completion may still come in later,
477-
* we need to keep the req object around. */
478-
kref_get(&req->kref);
479477
++c_put;
480478
}
481479

482480
if ((s & RQ_LOCAL_PENDING) && (clear & RQ_LOCAL_PENDING)) {
483481
if (req->rq_state & RQ_LOCAL_ABORTED)
484-
++k_put;
482+
kref_put(&req->kref, drbd_req_destroy);
485483
else
486484
++c_put;
487485
list_del_init(&req->req_pending_local);
@@ -503,7 +501,7 @@ static void mod_rq_state(struct drbd_request *req, struct bio_and_error *m,
503501
if (s & RQ_NET_SENT)
504502
atomic_sub(req->i.size >> 9, &device->ap_in_flight);
505503
if (s & RQ_EXP_BARR_ACK)
506-
++k_put;
504+
kref_put(&req->kref, drbd_req_destroy);
507505
req->net_done_jif = jiffies;
508506

509507
/* in ahead/behind mode, or just in case,
@@ -516,25 +514,16 @@ static void mod_rq_state(struct drbd_request *req, struct bio_and_error *m,
516514

517515
/* potentially complete and destroy */
518516

519-
if (k_put || c_put) {
520-
/* Completion does it's own kref_put. If we are going to
521-
* kref_sub below, we need req to be still around then. */
522-
int at_least = k_put + !!c_put;
523-
int refcount = atomic_read(&req->kref.refcount);
524-
if (refcount < at_least)
525-
drbd_err(device,
526-
"mod_rq_state: Logic BUG: %x -> %x: refcount = %d, should be >= %d\n",
527-
s, req->rq_state, refcount, at_least);
528-
}
529-
530517
/* If we made progress, retry conflicting peer requests, if any. */
531518
if (req->i.waiting)
532519
wake_up(&device->misc_wait);
533520

534-
if (c_put)
535-
k_put += drbd_req_put_completion_ref(req, m, c_put);
536-
if (k_put)
537-
kref_sub(&req->kref, k_put, drbd_req_destroy);
521+
if (c_put) {
522+
if (drbd_req_put_completion_ref(req, m, c_put))
523+
kref_put(&req->kref, drbd_req_destroy);
524+
} else {
525+
kref_put(&req->kref, drbd_req_destroy);
526+
}
538527
}
539528

540529
static void drbd_report_io_error(struct drbd_device *device, struct drbd_request *req)

0 commit comments

Comments
 (0)