From: Maarten Lankhorst <maarten.lankhorst@canonical.com>
To: linux-kernel@vger.kernel.org
Cc: linux-arch@vger.kernel.org, peterz@infradead.org, x86@kernel.org,
dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org,
robclark@gmail.com, rostedt@goodmis.org, daniel@ffwll.ch,
tglx@linutronix.de, mingo@kernel.org,
linux-media@vger.kernel.org
Subject: [PATCH v5 5/7] mutex: add more tests to lib/locking-selftest.c
Date: Thu, 20 Jun 2013 13:31:30 +0200 [thread overview]
Message-ID: <20130620113130.4001.45423.stgit@patser> (raw)
In-Reply-To: <20130620112811.4001.86934.stgit@patser>
None of the ww_mutex codepaths should be taken in the 'normal'
mutex calls. The easiest way to verify this is by using the
normal mutex calls, and making sure o.ctx is unmodified.
Signed-off-by: Maarten Lankhorst <maarten.lankhorst@canonical.com>
---
lib/locking-selftest.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 62 insertions(+)
diff --git a/lib/locking-selftest.c b/lib/locking-selftest.c
index 9962262..37faefd 100644
--- a/lib/locking-selftest.c
+++ b/lib/locking-selftest.c
@@ -1162,6 +1162,67 @@ static void ww_test_fail_acquire(void)
#endif
}
+static void ww_test_normal(void)
+{
+ int ret;
+
+ WWAI(&t);
+
+ /*
+ * None of the ww_mutex codepaths should be taken in the 'normal'
+ * mutex calls. The easiest way to verify this is by using the
+ * normal mutex calls, and making sure o.ctx is unmodified.
+ */
+
+ /* mutex_lock (and indirectly, mutex_lock_nested) */
+ o.ctx = (void *)~0UL;
+ mutex_lock(&o.base);
+ mutex_unlock(&o.base);
+ WARN_ON(o.ctx != (void *)~0UL);
+
+ /* mutex_lock_interruptible (and *_nested) */
+ o.ctx = (void *)~0UL;
+ ret = mutex_lock_interruptible(&o.base);
+ if (!ret)
+ mutex_unlock(&o.base);
+ else
+ WARN_ON(1);
+ WARN_ON(o.ctx != (void *)~0UL);
+
+ /* mutex_lock_killable (and *_nested) */
+ o.ctx = (void *)~0UL;
+ ret = mutex_lock_killable(&o.base);
+ if (!ret)
+ mutex_unlock(&o.base);
+ else
+ WARN_ON(1);
+ WARN_ON(o.ctx != (void *)~0UL);
+
+ /* trylock, succeeding */
+ o.ctx = (void *)~0UL;
+ ret = mutex_trylock(&o.base);
+ WARN_ON(!ret);
+ if (ret)
+ mutex_unlock(&o.base);
+ else
+ WARN_ON(1);
+ WARN_ON(o.ctx != (void *)~0UL);
+
+ /* trylock, failing */
+ o.ctx = (void *)~0UL;
+ mutex_lock(&o.base);
+ ret = mutex_trylock(&o.base);
+ WARN_ON(ret);
+ mutex_unlock(&o.base);
+ WARN_ON(o.ctx != (void *)~0UL);
+
+ /* nest_lock */
+ o.ctx = (void *)~0UL;
+ mutex_lock_nest_lock(&o.base, &t);
+ mutex_unlock(&o.base);
+ WARN_ON(o.ctx != (void *)~0UL);
+}
+
static void ww_test_two_contexts(void)
{
WWAI(&t);
@@ -1415,6 +1476,7 @@ static void ww_tests(void)
print_testname("ww api failures");
dotest(ww_test_fail_acquire, SUCCESS, LOCKTYPE_WW);
+ dotest(ww_test_normal, SUCCESS, LOCKTYPE_WW);
dotest(ww_test_unneeded_slow, FAILURE, LOCKTYPE_WW);
printk("\n");
next prev parent reply other threads:[~2013-06-20 11:31 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-20 11:30 [PATCH v5 0/7] add mutex wait/wound/style style locks Maarten Lankhorst
2013-06-20 11:30 ` Maarten Lankhorst
2013-06-20 11:31 ` [PATCH v5 1/7] arch: make __mutex_fastpath_lock_retval return whether fastpath succeeded or not Maarten Lankhorst
2013-06-20 11:31 ` [PATCH v5 2/7] mutex: add support for wound/wait style locks, v5 Maarten Lankhorst
2013-06-20 11:31 ` Maarten Lankhorst
2013-06-20 11:55 ` Ingo Molnar
2013-06-20 12:16 ` Maarten Lankhorst
2013-06-20 12:16 ` Maarten Lankhorst
2013-06-20 12:23 ` Ingo Molnar
2013-06-20 12:23 ` Ingo Molnar
2013-06-24 8:30 ` [PATCH v6 2/7] mutex: add support for wound/wait style locks Maarten Lankhorst
2013-06-20 11:58 ` [PATCH v5 2/7] mutex: add support for wound/wait style locks, v5 Ingo Molnar
2013-06-20 11:31 ` [PATCH v5 3/7] mutex: w/w mutex slowpath debugging Maarten Lankhorst
2013-06-20 11:31 ` Maarten Lankhorst
2013-06-20 11:31 ` [PATCH v5 4/7] mutex: Add ww tests to lib/locking-selftest.c. v5 Maarten Lankhorst
2013-06-20 11:31 ` Maarten Lankhorst
2013-06-20 11:31 ` Maarten Lankhorst [this message]
2013-06-20 11:31 ` [PATCH v5 5/7] mutex: add more tests to lib/locking-selftest.c Maarten Lankhorst
2013-06-20 11:31 ` [PATCH v5 6/7] mutex: add more ww tests to test EDEADLK path handling Maarten Lankhorst
2013-06-20 11:31 ` Maarten Lankhorst
2013-06-20 11:31 ` [PATCH v5 7/7] locking-selftests: handle unexpected failures more strictly Maarten Lankhorst
2013-06-20 11:31 ` Maarten Lankhorst
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130620113130.4001.45423.stgit@patser \
--to=maarten.lankhorst@canonical.com \
--cc=daniel@ffwll.ch \
--cc=dri-devel@lists.freedesktop.org \
--cc=linaro-mm-sig@lists.linaro.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=robclark@gmail.com \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).