Skip to content

Commit

Permalink
locking/ww_mutex: Add kselftests for ww_mutex AA deadlock detection
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Maarten Lankhorst <dev@mblankhorst.nl>
Cc: Nicolai Hähnle <nhaehnle@gmail.com>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/20161201114711.28697-5-chris@chris-wilson.co.uk
Signed-off-by: Ingo Molnar <mingo@kernel.org>
  • Loading branch information
Chris Wilson authored and Ingo Molnar committed Jan 14, 2017
1 parent f2a5fec commit c22fb38
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions kernel/locking/test-ww_mutex.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,41 @@ static int test_mutex(void)
return 0;
}

static int test_aa(void)
{
struct ww_mutex mutex;
struct ww_acquire_ctx ctx;
int ret;

ww_mutex_init(&mutex, &ww_class);
ww_acquire_init(&ctx, &ww_class);

ww_mutex_lock(&mutex, &ctx);

if (ww_mutex_trylock(&mutex)) {
pr_err("%s: trylocked itself!\n", __func__);
ww_mutex_unlock(&mutex);
ret = -EINVAL;
goto out;
}

ret = ww_mutex_lock(&mutex, &ctx);
if (ret != -EALREADY) {
pr_err("%s: missed deadlock for recursing, ret=%d\n",
__func__, ret);
if (!ret)
ww_mutex_unlock(&mutex);
ret = -EINVAL;
goto out;
}

ret = 0;
out:
ww_mutex_unlock(&mutex);
ww_acquire_fini(&ctx);
return ret;
}

static int __init test_ww_mutex_init(void)
{
int ret;
Expand All @@ -126,6 +161,10 @@ static int __init test_ww_mutex_init(void)
if (ret)
return ret;

ret = test_aa();
if (ret)
return ret;

return 0;
}

Expand Down

0 comments on commit c22fb38

Please sign in to comment.