Commit 500e1af2 authored by Linus Torvalds's avatar Linus Torvalds

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

Pull locking fixes from Ingo Molnar:

 - Change the new refcount_t warnings from WARN() to WARN_ONCE()

 - two ww_mutex fixes

 - plus a new lockdep self-consistency check for a bug that triggered in
   practice

* 'locking-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
  locking/ww_mutex: Adjust the lock number for stress test
  locking/lockdep: Add nest_lock integrity test
  locking/ww_mutex: Replace cpu_relax() with cond_resched() for tests
  locking/refcounts: Change WARN() to WARN_ONCE()
parents 26db8f99 857811a3
...@@ -3262,10 +3262,17 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass, ...@@ -3262,10 +3262,17 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
if (depth) { if (depth) {
hlock = curr->held_locks + depth - 1; hlock = curr->held_locks + depth - 1;
if (hlock->class_idx == class_idx && nest_lock) { if (hlock->class_idx == class_idx && nest_lock) {
if (hlock->references) if (hlock->references) {
/*
* Check: unsigned int references:12, overflow.
*/
if (DEBUG_LOCKS_WARN_ON(hlock->references == (1 << 12)-1))
return 0;
hlock->references++; hlock->references++;
else } else {
hlock->references = 2; hlock->references = 2;
}
return 1; return 1;
} }
......
...@@ -50,7 +50,7 @@ static void test_mutex_work(struct work_struct *work) ...@@ -50,7 +50,7 @@ static void test_mutex_work(struct work_struct *work)
if (mtx->flags & TEST_MTX_TRY) { if (mtx->flags & TEST_MTX_TRY) {
while (!ww_mutex_trylock(&mtx->mutex)) while (!ww_mutex_trylock(&mtx->mutex))
cpu_relax(); cond_resched();
} else { } else {
ww_mutex_lock(&mtx->mutex, NULL); ww_mutex_lock(&mtx->mutex, NULL);
} }
...@@ -88,7 +88,7 @@ static int __test_mutex(unsigned int flags) ...@@ -88,7 +88,7 @@ static int __test_mutex(unsigned int flags)
ret = -EINVAL; ret = -EINVAL;
break; break;
} }
cpu_relax(); cond_resched();
} while (time_before(jiffies, timeout)); } while (time_before(jiffies, timeout));
} else { } else {
ret = wait_for_completion_timeout(&mtx.done, TIMEOUT); ret = wait_for_completion_timeout(&mtx.done, TIMEOUT);
...@@ -627,7 +627,7 @@ static int __init test_ww_mutex_init(void) ...@@ -627,7 +627,7 @@ static int __init test_ww_mutex_init(void)
if (ret) if (ret)
return ret; return ret;
ret = stress(4096, hweight32(STRESS_ALL)*ncpus, 1<<12, STRESS_ALL); ret = stress(4095, hweight32(STRESS_ALL)*ncpus, 1<<12, STRESS_ALL);
if (ret) if (ret)
return ret; return ret;
......
...@@ -58,7 +58,7 @@ bool refcount_add_not_zero(unsigned int i, refcount_t *r) ...@@ -58,7 +58,7 @@ bool refcount_add_not_zero(unsigned int i, refcount_t *r)
val = old; val = old;
} }
WARN(new == UINT_MAX, "refcount_t: saturated; leaking memory.\n"); WARN_ONCE(new == UINT_MAX, "refcount_t: saturated; leaking memory.\n");
return true; return true;
} }
...@@ -66,7 +66,7 @@ EXPORT_SYMBOL_GPL(refcount_add_not_zero); ...@@ -66,7 +66,7 @@ EXPORT_SYMBOL_GPL(refcount_add_not_zero);
void refcount_add(unsigned int i, refcount_t *r) void refcount_add(unsigned int i, refcount_t *r)
{ {
WARN(!refcount_add_not_zero(i, r), "refcount_t: addition on 0; use-after-free.\n"); WARN_ONCE(!refcount_add_not_zero(i, r), "refcount_t: addition on 0; use-after-free.\n");
} }
EXPORT_SYMBOL_GPL(refcount_add); EXPORT_SYMBOL_GPL(refcount_add);
...@@ -97,7 +97,7 @@ bool refcount_inc_not_zero(refcount_t *r) ...@@ -97,7 +97,7 @@ bool refcount_inc_not_zero(refcount_t *r)
val = old; val = old;
} }
WARN(new == UINT_MAX, "refcount_t: saturated; leaking memory.\n"); WARN_ONCE(new == UINT_MAX, "refcount_t: saturated; leaking memory.\n");
return true; return true;
} }
...@@ -111,7 +111,7 @@ EXPORT_SYMBOL_GPL(refcount_inc_not_zero); ...@@ -111,7 +111,7 @@ EXPORT_SYMBOL_GPL(refcount_inc_not_zero);
*/ */
void refcount_inc(refcount_t *r) void refcount_inc(refcount_t *r)
{ {
WARN(!refcount_inc_not_zero(r), "refcount_t: increment on 0; use-after-free.\n"); WARN_ONCE(!refcount_inc_not_zero(r), "refcount_t: increment on 0; use-after-free.\n");
} }
EXPORT_SYMBOL_GPL(refcount_inc); EXPORT_SYMBOL_GPL(refcount_inc);
...@@ -125,7 +125,7 @@ bool refcount_sub_and_test(unsigned int i, refcount_t *r) ...@@ -125,7 +125,7 @@ bool refcount_sub_and_test(unsigned int i, refcount_t *r)
new = val - i; new = val - i;
if (new > val) { if (new > val) {
WARN(new > val, "refcount_t: underflow; use-after-free.\n"); WARN_ONCE(new > val, "refcount_t: underflow; use-after-free.\n");
return false; return false;
} }
...@@ -164,7 +164,7 @@ EXPORT_SYMBOL_GPL(refcount_dec_and_test); ...@@ -164,7 +164,7 @@ EXPORT_SYMBOL_GPL(refcount_dec_and_test);
void refcount_dec(refcount_t *r) void refcount_dec(refcount_t *r)
{ {
WARN(refcount_dec_and_test(r), "refcount_t: decrement hit 0; leaking memory.\n"); WARN_ONCE(refcount_dec_and_test(r), "refcount_t: decrement hit 0; leaking memory.\n");
} }
EXPORT_SYMBOL_GPL(refcount_dec); EXPORT_SYMBOL_GPL(refcount_dec);
...@@ -204,7 +204,7 @@ bool refcount_dec_not_one(refcount_t *r) ...@@ -204,7 +204,7 @@ bool refcount_dec_not_one(refcount_t *r)
new = val - 1; new = val - 1;
if (new > val) { if (new > val) {
WARN(new > val, "refcount_t: underflow; use-after-free.\n"); WARN_ONCE(new > val, "refcount_t: underflow; use-after-free.\n");
return true; return true;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment