aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/locking-selftest.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/locking-selftest.c b/lib/locking-selftest.c
index 996226224bcf..37faefdbb678 100644
--- a/lib/locking-selftest.c
+++ b/lib/locking-selftest.c
@@ -1162,6 +1162,67 @@ static void ww_test_fail_acquire(void)
1162#endif 1162#endif
1163} 1163}
1164 1164
1165static void ww_test_normal(void)
1166{
1167 int ret;
1168
1169 WWAI(&t);
1170
1171 /*
1172 * None of the ww_mutex codepaths should be taken in the 'normal'
1173 * mutex calls. The easiest way to verify this is by using the
1174 * normal mutex calls, and making sure o.ctx is unmodified.
1175 */
1176
1177 /* mutex_lock (and indirectly, mutex_lock_nested) */
1178 o.ctx = (void *)~0UL;
1179 mutex_lock(&o.base);
1180 mutex_unlock(&o.base);
1181 WARN_ON(o.ctx != (void *)~0UL);
1182
1183 /* mutex_lock_interruptible (and *_nested) */
1184 o.ctx = (void *)~0UL;
1185 ret = mutex_lock_interruptible(&o.base);
1186 if (!ret)
1187 mutex_unlock(&o.base);
1188 else
1189 WARN_ON(1);
1190 WARN_ON(o.ctx != (void *)~0UL);
1191
1192 /* mutex_lock_killable (and *_nested) */
1193 o.ctx = (void *)~0UL;
1194 ret = mutex_lock_killable(&o.base);
1195 if (!ret)
1196 mutex_unlock(&o.base);
1197 else
1198 WARN_ON(1);
1199 WARN_ON(o.ctx != (void *)~0UL);
1200
1201 /* trylock, succeeding */
1202 o.ctx = (void *)~0UL;
1203 ret = mutex_trylock(&o.base);
1204 WARN_ON(!ret);
1205 if (ret)
1206 mutex_unlock(&o.base);
1207 else
1208 WARN_ON(1);
1209 WARN_ON(o.ctx != (void *)~0UL);
1210
1211 /* trylock, failing */
1212 o.ctx = (void *)~0UL;
1213 mutex_lock(&o.base);
1214 ret = mutex_trylock(&o.base);
1215 WARN_ON(ret);
1216 mutex_unlock(&o.base);
1217 WARN_ON(o.ctx != (void *)~0UL);
1218
1219 /* nest_lock */
1220 o.ctx = (void *)~0UL;
1221 mutex_lock_nest_lock(&o.base, &t);
1222 mutex_unlock(&o.base);
1223 WARN_ON(o.ctx != (void *)~0UL);
1224}
1225
1165static void ww_test_two_contexts(void) 1226static void ww_test_two_contexts(void)
1166{ 1227{
1167 WWAI(&t); 1228 WWAI(&t);
@@ -1415,6 +1476,7 @@ static void ww_tests(void)
1415 1476
1416 print_testname("ww api failures"); 1477 print_testname("ww api failures");
1417 dotest(ww_test_fail_acquire, SUCCESS, LOCKTYPE_WW); 1478 dotest(ww_test_fail_acquire, SUCCESS, LOCKTYPE_WW);
1479 dotest(ww_test_normal, SUCCESS, LOCKTYPE_WW);
1418 dotest(ww_test_unneeded_slow, FAILURE, LOCKTYPE_WW); 1480 dotest(ww_test_unneeded_slow, FAILURE, LOCKTYPE_WW);
1419 printk("\n"); 1481 printk("\n");
1420 1482