Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * lib/locking-selftest.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Testsuite for various locking APIs: spinlocks, rwlocks,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * mutexes and rw-semaphores.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  * It is checking both false positives and false negatives.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  * Started by Ingo Molnar:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  *  Copyright (C) 2006 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/rwsem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/ww_mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/lockdep.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/kallsyms.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <linux/debug_locks.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <linux/irqflags.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/rtmutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28)  * Change this to 1 if you want to see the failure printouts:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) static unsigned int debug_locks_verbose;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) unsigned int force_read_lock_recursive;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) static DEFINE_WD_CLASS(ww_lockdep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) static int __init setup_debug_locks_verbose(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) 	get_option(&str, &debug_locks_verbose);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) 	return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) __setup("debug_locks_verbose=", setup_debug_locks_verbose);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #define FAILURE		0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #define SUCCESS		1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) #define LOCKTYPE_SPIN	0x1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #define LOCKTYPE_RWLOCK	0x2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) #define LOCKTYPE_MUTEX	0x4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #define LOCKTYPE_RWSEM	0x8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) #define LOCKTYPE_WW	0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) #define LOCKTYPE_RTMUTEX 0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) static struct ww_acquire_ctx t, t2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) static struct ww_mutex o, o2, o3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58)  * Normal standalone locks, for the circular and irq-context
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59)  * dependency tests:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) static DEFINE_RAW_SPINLOCK(lock_A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) static DEFINE_RAW_SPINLOCK(lock_B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) static DEFINE_RAW_SPINLOCK(lock_C);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) static DEFINE_RAW_SPINLOCK(lock_D);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) static DEFINE_RWLOCK(rwlock_A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) static DEFINE_RWLOCK(rwlock_B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) static DEFINE_RWLOCK(rwlock_C);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) static DEFINE_RWLOCK(rwlock_D);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) static DEFINE_MUTEX(mutex_A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) static DEFINE_MUTEX(mutex_B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) static DEFINE_MUTEX(mutex_C);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) static DEFINE_MUTEX(mutex_D);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) static DECLARE_RWSEM(rwsem_A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) static DECLARE_RWSEM(rwsem_B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) static DECLARE_RWSEM(rwsem_C);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) static DECLARE_RWSEM(rwsem_D);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) #ifdef CONFIG_RT_MUTEXES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) static DEFINE_RT_MUTEX(rtmutex_A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) static DEFINE_RT_MUTEX(rtmutex_B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) static DEFINE_RT_MUTEX(rtmutex_C);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) static DEFINE_RT_MUTEX(rtmutex_D);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91)  * Locks that we initialize dynamically as well so that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92)  * e.g. X1 and X2 becomes two instances of the same class,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93)  * but X* and Y* are different classes. We do this so that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94)  * we do not trigger a real lockup:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) static DEFINE_RAW_SPINLOCK(lock_X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) static DEFINE_RAW_SPINLOCK(lock_X2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) static DEFINE_RAW_SPINLOCK(lock_Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) static DEFINE_RAW_SPINLOCK(lock_Y2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) static DEFINE_RAW_SPINLOCK(lock_Z1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) static DEFINE_RAW_SPINLOCK(lock_Z2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) static DEFINE_RWLOCK(rwlock_X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) static DEFINE_RWLOCK(rwlock_X2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) static DEFINE_RWLOCK(rwlock_Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) static DEFINE_RWLOCK(rwlock_Y2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) static DEFINE_RWLOCK(rwlock_Z1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) static DEFINE_RWLOCK(rwlock_Z2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) static DEFINE_MUTEX(mutex_X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) static DEFINE_MUTEX(mutex_X2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) static DEFINE_MUTEX(mutex_Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) static DEFINE_MUTEX(mutex_Y2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) static DEFINE_MUTEX(mutex_Z1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) static DEFINE_MUTEX(mutex_Z2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) static DECLARE_RWSEM(rwsem_X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) static DECLARE_RWSEM(rwsem_X2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) static DECLARE_RWSEM(rwsem_Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) static DECLARE_RWSEM(rwsem_Y2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) static DECLARE_RWSEM(rwsem_Z1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) static DECLARE_RWSEM(rwsem_Z2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) #ifdef CONFIG_RT_MUTEXES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) static DEFINE_RT_MUTEX(rtmutex_X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) static DEFINE_RT_MUTEX(rtmutex_X2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) static DEFINE_RT_MUTEX(rtmutex_Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) static DEFINE_RT_MUTEX(rtmutex_Y2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) static DEFINE_RT_MUTEX(rtmutex_Z1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) static DEFINE_RT_MUTEX(rtmutex_Z2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136)  * non-inlined runtime initializers, to let separate locks share
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137)  * the same lock-class:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) #define INIT_CLASS_FUNC(class) 				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) static noinline void					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) init_class_##class(raw_spinlock_t *lock, rwlock_t *rwlock, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 	struct mutex *mutex, struct rw_semaphore *rwsem)\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) {							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	raw_spin_lock_init(lock);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 	rwlock_init(rwlock);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	mutex_init(mutex);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 	init_rwsem(rwsem);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) INIT_CLASS_FUNC(X)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) INIT_CLASS_FUNC(Y)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) INIT_CLASS_FUNC(Z)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) static void init_shared_classes(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) #ifdef CONFIG_RT_MUTEXES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	static struct lock_class_key rt_X, rt_Y, rt_Z;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	__rt_mutex_init(&rtmutex_X1, __func__, &rt_X);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	__rt_mutex_init(&rtmutex_X2, __func__, &rt_X);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 	__rt_mutex_init(&rtmutex_Y1, __func__, &rt_Y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 	__rt_mutex_init(&rtmutex_Y2, __func__, &rt_Y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 	__rt_mutex_init(&rtmutex_Z1, __func__, &rt_Z);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 	__rt_mutex_init(&rtmutex_Z2, __func__, &rt_Z);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	init_class_X(&lock_X1, &rwlock_X1, &mutex_X1, &rwsem_X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 	init_class_X(&lock_X2, &rwlock_X2, &mutex_X2, &rwsem_X2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 	init_class_Y(&lock_Y1, &rwlock_Y1, &mutex_Y1, &rwsem_Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 	init_class_Y(&lock_Y2, &rwlock_Y2, &mutex_Y2, &rwsem_Y2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 	init_class_Z(&lock_Z1, &rwlock_Z1, &mutex_Z1, &rwsem_Z1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 	init_class_Z(&lock_Z2, &rwlock_Z2, &mutex_Z2, &rwsem_Z2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178)  * For spinlocks and rwlocks we also do hardirq-safe / softirq-safe tests.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179)  * The following functions use a lock from a simulated hardirq/softirq
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180)  * context, causing the locks to be marked as hardirq-safe/softirq-safe:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) #define HARDIRQ_DISABLE		local_irq_disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) #define HARDIRQ_ENABLE		local_irq_enable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) #define HARDIRQ_ENTER()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	local_irq_disable();			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	__irq_enter();				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	lockdep_hardirq_threaded();		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 	WARN_ON(!in_irq());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) #define HARDIRQ_EXIT()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	__irq_exit();				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	local_irq_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) #define SOFTIRQ_DISABLE		local_bh_disable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) #define SOFTIRQ_ENABLE		local_bh_enable
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) #define SOFTIRQ_ENTER()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 		local_bh_disable();		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 		local_irq_disable();		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 		lockdep_softirq_enter();	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 		WARN_ON(!in_softirq());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) #define SOFTIRQ_EXIT()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 		lockdep_softirq_exit();		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 		local_irq_enable();		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 		local_bh_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211)  * Shortcuts for lock/unlock API variants, to keep
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212)  * the testcases compact:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) #define L(x)			raw_spin_lock(&lock_##x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) #define U(x)			raw_spin_unlock(&lock_##x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) #define LU(x)			L(x); U(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) #define SI(x)			raw_spin_lock_init(&lock_##x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) #define WL(x)			write_lock(&rwlock_##x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) #define WU(x)			write_unlock(&rwlock_##x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) #define WLU(x)			WL(x); WU(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) #define RL(x)			read_lock(&rwlock_##x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) #define RU(x)			read_unlock(&rwlock_##x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) #define RLU(x)			RL(x); RU(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) #define RWI(x)			rwlock_init(&rwlock_##x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) #define ML(x)			mutex_lock(&mutex_##x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) #define MU(x)			mutex_unlock(&mutex_##x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) #define MI(x)			mutex_init(&mutex_##x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) #define RTL(x)			rt_mutex_lock(&rtmutex_##x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) #define RTU(x)			rt_mutex_unlock(&rtmutex_##x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) #define RTI(x)			rt_mutex_init(&rtmutex_##x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) #define WSL(x)			down_write(&rwsem_##x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) #define WSU(x)			up_write(&rwsem_##x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) #define RSL(x)			down_read(&rwsem_##x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) #define RSU(x)			up_read(&rwsem_##x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) #define RWSI(x)			init_rwsem(&rwsem_##x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) #ifndef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) #define WWAI(x)			ww_acquire_init(x, &ww_lockdep)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) #define WWAI(x)			do { ww_acquire_init(x, &ww_lockdep); (x)->deadlock_inject_countdown = ~0U; } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) #define WWAD(x)			ww_acquire_done(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) #define WWAF(x)			ww_acquire_fini(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) #define WWL(x, c)		ww_mutex_lock(x, c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) #define WWT(x)			ww_mutex_trylock(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) #define WWL1(x)			ww_mutex_lock(x, NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) #define WWU(x)			ww_mutex_unlock(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) #define LOCK_UNLOCK_2(x,y)	LOCK(x); LOCK(y); UNLOCK(y); UNLOCK(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260)  * Generate different permutations of the same testcase, using
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261)  * the same basic lock-dependency/state events:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) #define GENERATE_TESTCASE(name)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) static void name(void) { E(); }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) #define GENERATE_PERMUTATIONS_2_EVENTS(name)	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) static void name##_12(void) { E1(); E2(); }	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) static void name##_21(void) { E2(); E1(); }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) #define GENERATE_PERMUTATIONS_3_EVENTS(name)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) static void name##_123(void) { E1(); E2(); E3(); }	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) static void name##_132(void) { E1(); E3(); E2(); }	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) static void name##_213(void) { E2(); E1(); E3(); }	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) static void name##_231(void) { E2(); E3(); E1(); }	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) static void name##_312(void) { E3(); E1(); E2(); }	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) static void name##_321(void) { E3(); E2(); E1(); }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283)  * AA deadlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) #define E()					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 	LOCK(X1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	LOCK(X2); /* this one should fail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292)  * 6 testcases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) #include "locking-selftest-spin.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) GENERATE_TESTCASE(AA_spin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) #include "locking-selftest-wlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) GENERATE_TESTCASE(AA_wlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) #include "locking-selftest-rlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) GENERATE_TESTCASE(AA_rlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) #include "locking-selftest-mutex.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) GENERATE_TESTCASE(AA_mutex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) #include "locking-selftest-wsem.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) GENERATE_TESTCASE(AA_wsem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) #include "locking-selftest-rsem.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) GENERATE_TESTCASE(AA_rsem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) #ifdef CONFIG_RT_MUTEXES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) #include "locking-selftest-rtmutex.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) GENERATE_TESTCASE(AA_rtmutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) #undef E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315)  * Special-case for read-locking, they are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316)  * allowed to recurse on the same lock class:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) static void rlock_AA1(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	RL(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 	RL(X1); // this one should NOT fail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) static void rlock_AA1B(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	RL(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	RL(X2); // this one should NOT fail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) static void rsem_AA1(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 	RSL(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 	RSL(X1); // this one should fail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) static void rsem_AA1B(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	RSL(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	RSL(X2); // this one should fail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342)  * The mixing of read and write locks is not allowed:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) static void rlock_AA2(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	RL(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 	WL(X2); // this one should fail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) static void rsem_AA2(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	RSL(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	WSL(X2); // this one should fail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) static void rlock_AA3(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 	WL(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 	RL(X2); // this one should fail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) static void rsem_AA3(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	WSL(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	RSL(X2); // this one should fail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369)  * read_lock(A)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370)  * spin_lock(B)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371)  *		spin_lock(B)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372)  *		write_lock(A)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) static void rlock_ABBA1(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	RL(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	L(Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	U(Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	RU(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 	L(Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	WL(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	WU(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 	U(Y1); // should fail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) static void rwsem_ABBA1(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 	RSL(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 	ML(Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	MU(Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	RSU(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 	ML(Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 	WSL(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	WSU(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	MU(Y1); // should fail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401)  * read_lock(A)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402)  * spin_lock(B)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403)  *		spin_lock(B)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404)  *		write_lock(A)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406)  * This test case is aimed at poking whether the chain cache prevents us from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407)  * detecting a read-lock/lock-write deadlock: if the chain cache doesn't differ
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408)  * read/write locks, the following case may happen
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410)  * 	{ read_lock(A)->lock(B) dependency exists }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412)  * 	P0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413)  * 	lock(B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414)  * 	read_lock(A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416)  *	{ Not a deadlock, B -> A is added in the chain cache }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418)  *	P1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419)  *	lock(B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420)  *	write_lock(A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422)  *	{ B->A found in chain cache, not reported as a deadlock }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) static void rlock_chaincache_ABBA1(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) 	RL(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	L(Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 	U(Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	RU(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	L(Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	RL(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	RU(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	U(Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	L(Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	WL(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 	WU(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	U(Y1); // should fail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444)  * read_lock(A)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445)  * spin_lock(B)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446)  *		spin_lock(B)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447)  *		read_lock(A)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) static void rlock_ABBA2(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 	RL(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	L(Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 	U(Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	RU(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	L(Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	RL(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 	RU(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 	U(Y1); // should NOT fail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) static void rwsem_ABBA2(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	RSL(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 	ML(Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 	MU(Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	RSU(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	ML(Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	RSL(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 	RSU(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	MU(Y1); // should fail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477)  * write_lock(A)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478)  * spin_lock(B)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479)  *		spin_lock(B)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480)  *		write_lock(A)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) static void rlock_ABBA3(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 	WL(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 	L(Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 	U(Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 	WU(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	L(Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	WL(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	WU(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	U(Y1); // should fail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) static void rwsem_ABBA3(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 	WSL(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	ML(Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 	MU(Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	WSU(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	ML(Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	WSL(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	WSU(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	MU(Y1); // should fail
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509)  * ABBA deadlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) #define E()					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 	LOCK_UNLOCK_2(A, B);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 	LOCK_UNLOCK_2(B, A); /* fail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518)  * 6 testcases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) #include "locking-selftest-spin.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) GENERATE_TESTCASE(ABBA_spin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) #include "locking-selftest-wlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) GENERATE_TESTCASE(ABBA_wlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) #include "locking-selftest-rlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) GENERATE_TESTCASE(ABBA_rlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) #include "locking-selftest-mutex.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) GENERATE_TESTCASE(ABBA_mutex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) #include "locking-selftest-wsem.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) GENERATE_TESTCASE(ABBA_wsem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) #include "locking-selftest-rsem.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) GENERATE_TESTCASE(ABBA_rsem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) #ifdef CONFIG_RT_MUTEXES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) #include "locking-selftest-rtmutex.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) GENERATE_TESTCASE(ABBA_rtmutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) #undef E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541)  * AB BC CA deadlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) #define E()					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	LOCK_UNLOCK_2(A, B);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	LOCK_UNLOCK_2(B, C);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	LOCK_UNLOCK_2(C, A); /* fail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551)  * 6 testcases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) #include "locking-selftest-spin.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) GENERATE_TESTCASE(ABBCCA_spin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) #include "locking-selftest-wlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) GENERATE_TESTCASE(ABBCCA_wlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) #include "locking-selftest-rlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) GENERATE_TESTCASE(ABBCCA_rlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) #include "locking-selftest-mutex.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) GENERATE_TESTCASE(ABBCCA_mutex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) #include "locking-selftest-wsem.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) GENERATE_TESTCASE(ABBCCA_wsem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) #include "locking-selftest-rsem.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) GENERATE_TESTCASE(ABBCCA_rsem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) #ifdef CONFIG_RT_MUTEXES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) #include "locking-selftest-rtmutex.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) GENERATE_TESTCASE(ABBCCA_rtmutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) #undef E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574)  * AB CA BC deadlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) #define E()					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	LOCK_UNLOCK_2(A, B);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	LOCK_UNLOCK_2(C, A);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	LOCK_UNLOCK_2(B, C); /* fail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584)  * 6 testcases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) #include "locking-selftest-spin.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) GENERATE_TESTCASE(ABCABC_spin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) #include "locking-selftest-wlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) GENERATE_TESTCASE(ABCABC_wlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) #include "locking-selftest-rlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) GENERATE_TESTCASE(ABCABC_rlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) #include "locking-selftest-mutex.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) GENERATE_TESTCASE(ABCABC_mutex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) #include "locking-selftest-wsem.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) GENERATE_TESTCASE(ABCABC_wsem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) #include "locking-selftest-rsem.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) GENERATE_TESTCASE(ABCABC_rsem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) #ifdef CONFIG_RT_MUTEXES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) #include "locking-selftest-rtmutex.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) GENERATE_TESTCASE(ABCABC_rtmutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) #undef E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607)  * AB BC CD DA deadlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) #define E()					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	LOCK_UNLOCK_2(A, B);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	LOCK_UNLOCK_2(B, C);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	LOCK_UNLOCK_2(C, D);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	LOCK_UNLOCK_2(D, A); /* fail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618)  * 6 testcases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) #include "locking-selftest-spin.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) GENERATE_TESTCASE(ABBCCDDA_spin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) #include "locking-selftest-wlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) GENERATE_TESTCASE(ABBCCDDA_wlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) #include "locking-selftest-rlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) GENERATE_TESTCASE(ABBCCDDA_rlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) #include "locking-selftest-mutex.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) GENERATE_TESTCASE(ABBCCDDA_mutex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) #include "locking-selftest-wsem.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) GENERATE_TESTCASE(ABBCCDDA_wsem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) #include "locking-selftest-rsem.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) GENERATE_TESTCASE(ABBCCDDA_rsem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) #ifdef CONFIG_RT_MUTEXES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) #include "locking-selftest-rtmutex.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) GENERATE_TESTCASE(ABBCCDDA_rtmutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) #undef E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641)  * AB CD BD DA deadlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) #define E()					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 	LOCK_UNLOCK_2(A, B);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 	LOCK_UNLOCK_2(C, D);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	LOCK_UNLOCK_2(B, D);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 	LOCK_UNLOCK_2(D, A); /* fail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651)  * 6 testcases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) #include "locking-selftest-spin.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) GENERATE_TESTCASE(ABCDBDDA_spin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) #include "locking-selftest-wlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) GENERATE_TESTCASE(ABCDBDDA_wlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) #include "locking-selftest-rlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) GENERATE_TESTCASE(ABCDBDDA_rlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) #include "locking-selftest-mutex.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) GENERATE_TESTCASE(ABCDBDDA_mutex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) #include "locking-selftest-wsem.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) GENERATE_TESTCASE(ABCDBDDA_wsem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) #include "locking-selftest-rsem.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) GENERATE_TESTCASE(ABCDBDDA_rsem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) #ifdef CONFIG_RT_MUTEXES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) #include "locking-selftest-rtmutex.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) GENERATE_TESTCASE(ABCDBDDA_rtmutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) #undef E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674)  * AB CD BC DA deadlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) #define E()					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 	LOCK_UNLOCK_2(A, B);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	LOCK_UNLOCK_2(C, D);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	LOCK_UNLOCK_2(B, C);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 	LOCK_UNLOCK_2(D, A); /* fail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684)  * 6 testcases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) #include "locking-selftest-spin.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) GENERATE_TESTCASE(ABCDBCDA_spin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) #include "locking-selftest-wlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) GENERATE_TESTCASE(ABCDBCDA_wlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) #include "locking-selftest-rlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) GENERATE_TESTCASE(ABCDBCDA_rlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) #include "locking-selftest-mutex.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) GENERATE_TESTCASE(ABCDBCDA_mutex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) #include "locking-selftest-wsem.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) GENERATE_TESTCASE(ABCDBCDA_wsem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) #include "locking-selftest-rsem.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) GENERATE_TESTCASE(ABCDBCDA_rsem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) #ifdef CONFIG_RT_MUTEXES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) #include "locking-selftest-rtmutex.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) GENERATE_TESTCASE(ABCDBCDA_rtmutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) #undef E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707)  * Double unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) #define E()					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	LOCK(A);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 	UNLOCK(A);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	UNLOCK(A); /* fail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716)  * 6 testcases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) #include "locking-selftest-spin.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) GENERATE_TESTCASE(double_unlock_spin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) #include "locking-selftest-wlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) GENERATE_TESTCASE(double_unlock_wlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) #include "locking-selftest-rlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) GENERATE_TESTCASE(double_unlock_rlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) #include "locking-selftest-mutex.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) GENERATE_TESTCASE(double_unlock_mutex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) #include "locking-selftest-wsem.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) GENERATE_TESTCASE(double_unlock_wsem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) #include "locking-selftest-rsem.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) GENERATE_TESTCASE(double_unlock_rsem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) #ifdef CONFIG_RT_MUTEXES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) #include "locking-selftest-rtmutex.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) GENERATE_TESTCASE(double_unlock_rtmutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) #undef E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739)  * initializing a held lock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) #define E()					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	LOCK(A);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	INIT(A); /* fail */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747)  * 6 testcases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) #include "locking-selftest-spin.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) GENERATE_TESTCASE(init_held_spin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) #include "locking-selftest-wlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) GENERATE_TESTCASE(init_held_wlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) #include "locking-selftest-rlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) GENERATE_TESTCASE(init_held_rlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) #include "locking-selftest-mutex.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) GENERATE_TESTCASE(init_held_mutex)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) #include "locking-selftest-wsem.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) GENERATE_TESTCASE(init_held_wsem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) #include "locking-selftest-rsem.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) GENERATE_TESTCASE(init_held_rsem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) #ifdef CONFIG_RT_MUTEXES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) #include "locking-selftest-rtmutex.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) GENERATE_TESTCASE(init_held_rtmutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) #undef E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770)  * locking an irq-safe lock with irqs enabled:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) #define E1()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	IRQ_ENTER();			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 	LOCK(A);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 	UNLOCK(A);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 	IRQ_EXIT();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) #define E2()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	LOCK(A);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	UNLOCK(A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785)  * Generate 24 testcases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) #include "locking-selftest-spin-hardirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) GENERATE_PERMUTATIONS_2_EVENTS(irqsafe1_hard_spin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) #include "locking-selftest-rlock-hardirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) GENERATE_PERMUTATIONS_2_EVENTS(irqsafe1_hard_rlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) #include "locking-selftest-wlock-hardirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) GENERATE_PERMUTATIONS_2_EVENTS(irqsafe1_hard_wlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) #include "locking-selftest-spin-softirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) GENERATE_PERMUTATIONS_2_EVENTS(irqsafe1_soft_spin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) #include "locking-selftest-rlock-softirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) GENERATE_PERMUTATIONS_2_EVENTS(irqsafe1_soft_rlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) #include "locking-selftest-wlock-softirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) GENERATE_PERMUTATIONS_2_EVENTS(irqsafe1_soft_wlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) #undef E1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) #undef E2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809)  * Enabling hardirqs with a softirq-safe lock held:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) #define E1()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	SOFTIRQ_ENTER();		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	LOCK(A);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 	UNLOCK(A);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	SOFTIRQ_EXIT();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) #define E2()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	HARDIRQ_DISABLE();		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	LOCK(A);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	HARDIRQ_ENABLE();		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	UNLOCK(A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826)  * Generate 12 testcases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) #include "locking-selftest-spin.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2A_spin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) #include "locking-selftest-wlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2A_wlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) #include "locking-selftest-rlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2A_rlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) #undef E1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) #undef E2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841)  * Enabling irqs with an irq-safe lock held:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) #define E1()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 	IRQ_ENTER();			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	LOCK(A);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	UNLOCK(A);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	IRQ_EXIT();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) #define E2()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	IRQ_DISABLE();			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 	LOCK(A);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 	IRQ_ENABLE();			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 	UNLOCK(A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858)  * Generate 24 testcases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) #include "locking-selftest-spin-hardirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2B_hard_spin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) #include "locking-selftest-rlock-hardirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2B_hard_rlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) #include "locking-selftest-wlock-hardirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2B_hard_wlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) #include "locking-selftest-spin-softirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2B_soft_spin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) #include "locking-selftest-rlock-softirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2B_soft_rlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) #include "locking-selftest-wlock-softirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) GENERATE_PERMUTATIONS_2_EVENTS(irqsafe2B_soft_wlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) #undef E1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) #undef E2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882)  * Acquiring a irq-unsafe lock while holding an irq-safe-lock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) #define E1()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 	LOCK(A);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	LOCK(B);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	UNLOCK(B);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	UNLOCK(A);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) #define E2()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	LOCK(B);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	UNLOCK(B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) #define E3()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	IRQ_ENTER();			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	LOCK(A);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 	UNLOCK(A);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	IRQ_EXIT();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904)  * Generate 36 testcases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) #include "locking-selftest-spin-hardirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) GENERATE_PERMUTATIONS_3_EVENTS(irqsafe3_hard_spin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) #include "locking-selftest-rlock-hardirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) GENERATE_PERMUTATIONS_3_EVENTS(irqsafe3_hard_rlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) #include "locking-selftest-wlock-hardirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) GENERATE_PERMUTATIONS_3_EVENTS(irqsafe3_hard_wlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) #include "locking-selftest-spin-softirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) GENERATE_PERMUTATIONS_3_EVENTS(irqsafe3_soft_spin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) #include "locking-selftest-rlock-softirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) GENERATE_PERMUTATIONS_3_EVENTS(irqsafe3_soft_rlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) #include "locking-selftest-wlock-softirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) GENERATE_PERMUTATIONS_3_EVENTS(irqsafe3_soft_wlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) #undef E1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) #undef E2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) #undef E3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929)  * If a lock turns into softirq-safe, but earlier it took
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930)  * a softirq-unsafe lock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) #define E1()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	IRQ_DISABLE();			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) 	LOCK(A);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 	LOCK(B);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	UNLOCK(B);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	UNLOCK(A);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	IRQ_ENABLE();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) #define E2()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	LOCK(B);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	UNLOCK(B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) #define E3()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	IRQ_ENTER();			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	LOCK(A);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	UNLOCK(A);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	IRQ_EXIT();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952)  * Generate 36 testcases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) #include "locking-selftest-spin-hardirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) GENERATE_PERMUTATIONS_3_EVENTS(irqsafe4_hard_spin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) #include "locking-selftest-rlock-hardirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) GENERATE_PERMUTATIONS_3_EVENTS(irqsafe4_hard_rlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) #include "locking-selftest-wlock-hardirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) GENERATE_PERMUTATIONS_3_EVENTS(irqsafe4_hard_wlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) #include "locking-selftest-spin-softirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) GENERATE_PERMUTATIONS_3_EVENTS(irqsafe4_soft_spin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) #include "locking-selftest-rlock-softirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) GENERATE_PERMUTATIONS_3_EVENTS(irqsafe4_soft_rlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) #include "locking-selftest-wlock-softirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) GENERATE_PERMUTATIONS_3_EVENTS(irqsafe4_soft_wlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) #undef E1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) #undef E2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) #undef E3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977)  * read-lock / write-lock irq inversion.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979)  * Deadlock scenario:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981)  * CPU#1 is at #1, i.e. it has write-locked A, but has not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982)  * taken B yet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984)  * CPU#2 is at #2, i.e. it has locked B.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986)  * Hardirq hits CPU#2 at point #2 and is trying to read-lock A.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988)  * The deadlock occurs because CPU#1 will spin on B, and CPU#2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989)  * will spin on A.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) #define E1()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	IRQ_DISABLE();			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	WL(A);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	LOCK(B);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	UNLOCK(B);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	WU(A);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	IRQ_ENABLE();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) #define E2()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	LOCK(B);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	UNLOCK(B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) #define E3()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	IRQ_ENTER();			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	RL(A);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	RU(A);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	IRQ_EXIT();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014)  * Generate 36 testcases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) #include "locking-selftest-spin-hardirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) GENERATE_PERMUTATIONS_3_EVENTS(irq_inversion_hard_spin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) #include "locking-selftest-rlock-hardirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) GENERATE_PERMUTATIONS_3_EVENTS(irq_inversion_hard_rlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) #include "locking-selftest-wlock-hardirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) GENERATE_PERMUTATIONS_3_EVENTS(irq_inversion_hard_wlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) #include "locking-selftest-spin-softirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) GENERATE_PERMUTATIONS_3_EVENTS(irq_inversion_soft_spin)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) #include "locking-selftest-rlock-softirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) GENERATE_PERMUTATIONS_3_EVENTS(irq_inversion_soft_rlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) #include "locking-selftest-wlock-softirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) GENERATE_PERMUTATIONS_3_EVENTS(irq_inversion_soft_wlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) #undef E1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) #undef E2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) #undef E3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039)  * write-read / write-read / write-read deadlock even if read is recursive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) #define E1()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 	WL(X1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	RL(Y1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	RU(Y1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	WU(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) #define E2()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	WL(Y1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 	RL(Z1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	RU(Z1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	WU(Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) #define E3()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 	WL(Z1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 	RL(X1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	RU(X1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	WU(Z1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) #include "locking-selftest-rlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) GENERATE_PERMUTATIONS_3_EVENTS(W1R2_W2R3_W3R1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) #undef E1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) #undef E2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) #undef E3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071)  * write-write / read-read / write-read deadlock even if read is recursive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) #define E1()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	WL(X1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	WL(Y1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 	WU(Y1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 	WU(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) #define E2()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	RL(Y1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	RL(Z1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	RU(Z1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	RU(Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) #define E3()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	WL(Z1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	RL(X1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	RU(X1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 	WU(Z1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) #include "locking-selftest-rlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) GENERATE_PERMUTATIONS_3_EVENTS(W1W2_R2R3_W3R1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) #undef E1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) #undef E2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) #undef E3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103)  * write-write / read-read / read-write is not deadlock when read is recursive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) #define E1()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	WL(X1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	WL(Y1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	WU(Y1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	WU(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) #define E2()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	RL(Y1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	RL(Z1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 	RU(Z1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	RU(Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) #define E3()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	RL(Z1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	WL(X1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 	WU(X1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	RU(Z1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) #include "locking-selftest-rlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) GENERATE_PERMUTATIONS_3_EVENTS(W1R2_R2R3_W3W1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) #undef E1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) #undef E2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) #undef E3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135)  * write-read / read-read / write-write is not deadlock when read is recursive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) #define E1()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	WL(X1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 	RL(Y1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 	RU(Y1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 	WU(X1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) #define E2()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	RL(Y1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 	RL(Z1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	RU(Z1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 	RU(Y1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) #define E3()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) 	WL(Z1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	WL(X1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 	WU(X1);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 	WU(Z1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) #include "locking-selftest-rlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) GENERATE_PERMUTATIONS_3_EVENTS(W1W2_R2R3_R3W1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) #undef E1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) #undef E2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) #undef E3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166)  * read-lock / write-lock recursion that is actually safe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) #define E1()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 	IRQ_DISABLE();			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 	WL(A);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 	WU(A);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 	IRQ_ENABLE();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) #define E2()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	RL(A);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 	RU(A);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) #define E3()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 	IRQ_ENTER();			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	LOCK(A);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 	L(B);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 	U(B);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 	UNLOCK(A);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	IRQ_EXIT();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191)  * Generate 24 testcases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) #include "locking-selftest-hardirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) #include "locking-selftest-rlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion_hard_rlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) #include "locking-selftest-wlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion_hard_wlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) #include "locking-selftest-softirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) #include "locking-selftest-rlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion_soft_rlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) #include "locking-selftest-wlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion_soft_wlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) #undef E1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) #undef E2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) #undef E3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212)  * read-lock / write-lock recursion that is unsafe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) #define E1()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 	IRQ_DISABLE();			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 	L(B);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 	LOCK(A);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 	UNLOCK(A);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 	U(B);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 	IRQ_ENABLE();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) #define E2()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 	RL(A);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 	RU(A);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) #define E3()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 	IRQ_ENTER();			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 	L(B);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 	U(B);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 	IRQ_EXIT();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237)  * Generate 24 testcases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) #include "locking-selftest-hardirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) #include "locking-selftest-rlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion2_hard_rlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) #include "locking-selftest-wlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion2_hard_wlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) #include "locking-selftest-softirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) #include "locking-selftest-rlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion2_soft_rlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) #include "locking-selftest-wlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion2_soft_wlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) #undef E1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) #undef E2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) #undef E3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257)  * read-lock / write-lock recursion that is unsafe.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259)  * A is a ENABLED_*_READ lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260)  * B is a USED_IN_*_READ lock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262)  * read_lock(A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263)  *			write_lock(B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264)  * <interrupt>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265)  * read_lock(B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266)  * 			write_lock(A); // if this one is read_lock(), no deadlock
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) #define E1()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 	IRQ_DISABLE();			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 	WL(B);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 	LOCK(A);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 	UNLOCK(A);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 	WU(B);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 	IRQ_ENABLE();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) #define E2()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 	RL(A);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 	RU(A);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) #define E3()				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 	IRQ_ENTER();			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 	RL(B);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 	RU(B);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 	IRQ_EXIT();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291)  * Generate 24 testcases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) #include "locking-selftest-hardirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) #include "locking-selftest-rlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion3_hard_rlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) #include "locking-selftest-wlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion3_hard_wlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) #include "locking-selftest-softirq.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) #include "locking-selftest-rlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion3_soft_rlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) #include "locking-selftest-wlock.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) GENERATE_PERMUTATIONS_3_EVENTS(irq_read_recursion3_soft_wlock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) #ifdef CONFIG_DEBUG_LOCK_ALLOC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) # define I_SPINLOCK(x)	lockdep_reset_lock(&lock_##x.dep_map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) # define I_RWLOCK(x)	lockdep_reset_lock(&rwlock_##x.dep_map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) # define I_MUTEX(x)	lockdep_reset_lock(&mutex_##x.dep_map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) # define I_RWSEM(x)	lockdep_reset_lock(&rwsem_##x.dep_map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) # define I_WW(x)	lockdep_reset_lock(&x.dep_map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) #ifdef CONFIG_RT_MUTEXES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) # define I_RTMUTEX(x)	lockdep_reset_lock(&rtmutex_##x.dep_map)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) # define I_SPINLOCK(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) # define I_RWLOCK(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) # define I_MUTEX(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) # define I_RWSEM(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) # define I_WW(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) #ifndef I_RTMUTEX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) # define I_RTMUTEX(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) #ifdef CONFIG_RT_MUTEXES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) #define I2_RTMUTEX(x)	rt_mutex_init(&rtmutex_##x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) #define I2_RTMUTEX(x)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) #define I1(x)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 	do {					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 		I_SPINLOCK(x);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 		I_RWLOCK(x);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 		I_MUTEX(x);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 		I_RWSEM(x);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 		I_RTMUTEX(x);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) #define I2(x)					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 	do {					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 		raw_spin_lock_init(&lock_##x);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 		rwlock_init(&rwlock_##x);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 		mutex_init(&mutex_##x);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 		init_rwsem(&rwsem_##x);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 		I2_RTMUTEX(x);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 	} while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) static void reset_locks(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 	local_irq_disable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 	lockdep_free_key_range(&ww_lockdep.acquire_key, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 	lockdep_free_key_range(&ww_lockdep.mutex_key, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 	I1(A); I1(B); I1(C); I1(D);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 	I1(X1); I1(X2); I1(Y1); I1(Y2); I1(Z1); I1(Z2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 	I_WW(t); I_WW(t2); I_WW(o.base); I_WW(o2.base); I_WW(o3.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 	lockdep_reset();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 	I2(A); I2(B); I2(C); I2(D);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 	init_shared_classes();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 	ww_mutex_init(&o, &ww_lockdep); ww_mutex_init(&o2, &ww_lockdep); ww_mutex_init(&o3, &ww_lockdep);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 	memset(&t, 0, sizeof(t)); memset(&t2, 0, sizeof(t2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 	memset(&ww_lockdep.acquire_key, 0, sizeof(ww_lockdep.acquire_key));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 	memset(&ww_lockdep.mutex_key, 0, sizeof(ww_lockdep.mutex_key));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 	local_irq_enable();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) #undef I
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) static int testcase_total;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) static int testcase_successes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) static int expected_testcase_failures;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) static int unexpected_testcase_failures;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) static void dotest(void (*testcase_fn)(void), int expected, int lockclass_mask)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 	unsigned long saved_preempt_count = preempt_count();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 	WARN_ON(irqs_disabled());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 	testcase_fn();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 	 * Filter out expected failures:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) #ifndef CONFIG_PROVE_LOCKING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 	if (expected == FAILURE && debug_locks) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 		expected_testcase_failures++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 		pr_cont("failed|");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 	if (debug_locks != expected) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 		unexpected_testcase_failures++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 		pr_cont("FAILED|");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 		testcase_successes++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 		pr_cont("  ok  |");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 	testcase_total++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 	if (debug_locks_verbose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 		pr_cont(" lockclass mask: %x, debug_locks: %d, expected: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 			lockclass_mask, debug_locks, expected);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 	 * Some tests (e.g. double-unlock) might corrupt the preemption
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 	 * count, so restore it:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 	preempt_count_set(saved_preempt_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) #ifdef CONFIG_TRACE_IRQFLAGS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 	if (softirq_count())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 		current->softirqs_enabled = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 		current->softirqs_enabled = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 	reset_locks();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) #ifdef CONFIG_RT_MUTEXES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) #define dotest_rt(fn, e, m)	dotest((fn), (e), (m))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) #define dotest_rt(fn, e, m)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) static inline void print_testname(const char *testname)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 	printk("%33s:", testname);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) #define DO_TESTCASE_1(desc, name, nr)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 	print_testname(desc"/"#nr);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 	dotest(name##_##nr, SUCCESS, LOCKTYPE_RWLOCK);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) #define DO_TESTCASE_1B(desc, name, nr)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 	print_testname(desc"/"#nr);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 	dotest(name##_##nr, FAILURE, LOCKTYPE_RWLOCK);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) #define DO_TESTCASE_1RR(desc, name, nr)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 	print_testname(desc"/"#nr);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 	pr_cont("             |");				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 	dotest(name##_##nr, SUCCESS, LOCKTYPE_RWLOCK);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) #define DO_TESTCASE_1RRB(desc, name, nr)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 	print_testname(desc"/"#nr);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 	pr_cont("             |");				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 	dotest(name##_##nr, FAILURE, LOCKTYPE_RWLOCK);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) #define DO_TESTCASE_3(desc, name, nr)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 	print_testname(desc"/"#nr);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 	dotest(name##_spin_##nr, FAILURE, LOCKTYPE_SPIN);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 	dotest(name##_wlock_##nr, FAILURE, LOCKTYPE_RWLOCK);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 	dotest(name##_rlock_##nr, SUCCESS, LOCKTYPE_RWLOCK);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) #define DO_TESTCASE_3RW(desc, name, nr)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 	print_testname(desc"/"#nr);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) 	dotest(name##_spin_##nr, FAILURE, LOCKTYPE_SPIN|LOCKTYPE_RWLOCK);\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 	dotest(name##_wlock_##nr, FAILURE, LOCKTYPE_RWLOCK);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 	dotest(name##_rlock_##nr, SUCCESS, LOCKTYPE_RWLOCK);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) #define DO_TESTCASE_2RW(desc, name, nr)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 	print_testname(desc"/"#nr);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 	pr_cont("      |");					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 	dotest(name##_wlock_##nr, FAILURE, LOCKTYPE_RWLOCK);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 	dotest(name##_rlock_##nr, SUCCESS, LOCKTYPE_RWLOCK);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) #define DO_TESTCASE_2x2RW(desc, name, nr)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 	DO_TESTCASE_2RW("hard-"desc, name##_hard, nr)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 	DO_TESTCASE_2RW("soft-"desc, name##_soft, nr)		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) #define DO_TESTCASE_6x2x2RW(desc, name)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 	DO_TESTCASE_2x2RW(desc, name, 123);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 	DO_TESTCASE_2x2RW(desc, name, 132);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 	DO_TESTCASE_2x2RW(desc, name, 213);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 	DO_TESTCASE_2x2RW(desc, name, 231);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 	DO_TESTCASE_2x2RW(desc, name, 312);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 	DO_TESTCASE_2x2RW(desc, name, 321);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) #define DO_TESTCASE_6(desc, name)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 	print_testname(desc);					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 	dotest(name##_spin, FAILURE, LOCKTYPE_SPIN);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 	dotest(name##_wlock, FAILURE, LOCKTYPE_RWLOCK);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 	dotest(name##_rlock, FAILURE, LOCKTYPE_RWLOCK);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 	dotest(name##_mutex, FAILURE, LOCKTYPE_MUTEX);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 	dotest(name##_wsem, FAILURE, LOCKTYPE_RWSEM);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 	dotest(name##_rsem, FAILURE, LOCKTYPE_RWSEM);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 	dotest_rt(name##_rtmutex, FAILURE, LOCKTYPE_RTMUTEX);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) #define DO_TESTCASE_6_SUCCESS(desc, name)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 	print_testname(desc);					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 	dotest(name##_spin, SUCCESS, LOCKTYPE_SPIN);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 	dotest(name##_wlock, SUCCESS, LOCKTYPE_RWLOCK);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 	dotest(name##_rlock, SUCCESS, LOCKTYPE_RWLOCK);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 	dotest(name##_mutex, SUCCESS, LOCKTYPE_MUTEX);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 	dotest(name##_wsem, SUCCESS, LOCKTYPE_RWSEM);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 	dotest(name##_rsem, SUCCESS, LOCKTYPE_RWSEM);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 	dotest_rt(name##_rtmutex, SUCCESS, LOCKTYPE_RTMUTEX);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513)  * 'read' variant: rlocks must not trigger.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) #define DO_TESTCASE_6R(desc, name)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 	print_testname(desc);					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 	dotest(name##_spin, FAILURE, LOCKTYPE_SPIN);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 	dotest(name##_wlock, FAILURE, LOCKTYPE_RWLOCK);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 	dotest(name##_rlock, SUCCESS, LOCKTYPE_RWLOCK);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 	dotest(name##_mutex, FAILURE, LOCKTYPE_MUTEX);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 	dotest(name##_wsem, FAILURE, LOCKTYPE_RWSEM);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 	dotest(name##_rsem, FAILURE, LOCKTYPE_RWSEM);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 	dotest_rt(name##_rtmutex, FAILURE, LOCKTYPE_RTMUTEX);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) #define DO_TESTCASE_2I(desc, name, nr)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 	DO_TESTCASE_1("hard-"desc, name##_hard, nr);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 	DO_TESTCASE_1("soft-"desc, name##_soft, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) #define DO_TESTCASE_2IB(desc, name, nr)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 	DO_TESTCASE_1B("hard-"desc, name##_hard, nr);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 	DO_TESTCASE_1B("soft-"desc, name##_soft, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) #define DO_TESTCASE_6I(desc, name, nr)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) 	DO_TESTCASE_3("hard-"desc, name##_hard, nr);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 	DO_TESTCASE_3("soft-"desc, name##_soft, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) #define DO_TESTCASE_6IRW(desc, name, nr)			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 	DO_TESTCASE_3RW("hard-"desc, name##_hard, nr);		\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 	DO_TESTCASE_3RW("soft-"desc, name##_soft, nr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) #define DO_TESTCASE_2x3(desc, name)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 	DO_TESTCASE_3(desc, name, 12);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 	DO_TESTCASE_3(desc, name, 21);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) #define DO_TESTCASE_2x6(desc, name)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 	DO_TESTCASE_6I(desc, name, 12);				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 	DO_TESTCASE_6I(desc, name, 21);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) #define DO_TESTCASE_6x2(desc, name)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 	DO_TESTCASE_2I(desc, name, 123);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 	DO_TESTCASE_2I(desc, name, 132);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 	DO_TESTCASE_2I(desc, name, 213);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) 	DO_TESTCASE_2I(desc, name, 231);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 	DO_TESTCASE_2I(desc, name, 312);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 	DO_TESTCASE_2I(desc, name, 321);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) #define DO_TESTCASE_6x2B(desc, name)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 	DO_TESTCASE_2IB(desc, name, 123);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 	DO_TESTCASE_2IB(desc, name, 132);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 	DO_TESTCASE_2IB(desc, name, 213);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 	DO_TESTCASE_2IB(desc, name, 231);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 	DO_TESTCASE_2IB(desc, name, 312);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 	DO_TESTCASE_2IB(desc, name, 321);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) #define DO_TESTCASE_6x1RR(desc, name)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 	DO_TESTCASE_1RR(desc, name, 123);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 	DO_TESTCASE_1RR(desc, name, 132);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 	DO_TESTCASE_1RR(desc, name, 213);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 	DO_TESTCASE_1RR(desc, name, 231);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 	DO_TESTCASE_1RR(desc, name, 312);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 	DO_TESTCASE_1RR(desc, name, 321);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) #define DO_TESTCASE_6x1RRB(desc, name)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 	DO_TESTCASE_1RRB(desc, name, 123);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 	DO_TESTCASE_1RRB(desc, name, 132);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 	DO_TESTCASE_1RRB(desc, name, 213);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 	DO_TESTCASE_1RRB(desc, name, 231);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 	DO_TESTCASE_1RRB(desc, name, 312);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 	DO_TESTCASE_1RRB(desc, name, 321);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) #define DO_TESTCASE_6x6(desc, name)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 	DO_TESTCASE_6I(desc, name, 123);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 	DO_TESTCASE_6I(desc, name, 132);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 	DO_TESTCASE_6I(desc, name, 213);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 	DO_TESTCASE_6I(desc, name, 231);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 	DO_TESTCASE_6I(desc, name, 312);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 	DO_TESTCASE_6I(desc, name, 321);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) #define DO_TESTCASE_6x6RW(desc, name)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 	DO_TESTCASE_6IRW(desc, name, 123);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 	DO_TESTCASE_6IRW(desc, name, 132);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 	DO_TESTCASE_6IRW(desc, name, 213);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 	DO_TESTCASE_6IRW(desc, name, 231);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 	DO_TESTCASE_6IRW(desc, name, 312);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) 	DO_TESTCASE_6IRW(desc, name, 321);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) static void ww_test_fail_acquire(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 	WWAI(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 	t.stamp++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 	ret = WWL(&o, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 	if (WARN_ON(!o.ctx) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 	    WARN_ON(ret))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 	/* No lockdep test, pure API */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 	ret = WWL(&o, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) 	WARN_ON(ret != -EALREADY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 	ret = WWT(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 	WARN_ON(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 	t2 = t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 	t2.stamp++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 	ret = WWL(&o, &t2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 	WARN_ON(ret != -EDEADLK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 	WWU(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 	if (WWT(&o))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 		WWU(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) #ifdef CONFIG_DEBUG_LOCK_ALLOC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 		DEBUG_LOCKS_WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) static void ww_test_normal(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 	WWAI(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 	 * None of the ww_mutex codepaths should be taken in the 'normal'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 	 * mutex calls. The easiest way to verify this is by using the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 	 * normal mutex calls, and making sure o.ctx is unmodified.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 	/* mutex_lock (and indirectly, mutex_lock_nested) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 	o.ctx = (void *)~0UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 	mutex_lock(&o.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 	mutex_unlock(&o.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 	WARN_ON(o.ctx != (void *)~0UL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) 	/* mutex_lock_interruptible (and *_nested) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 	o.ctx = (void *)~0UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) 	ret = mutex_lock_interruptible(&o.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 		mutex_unlock(&o.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 		WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 	WARN_ON(o.ctx != (void *)~0UL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 	/* mutex_lock_killable (and *_nested) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 	o.ctx = (void *)~0UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 	ret = mutex_lock_killable(&o.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 		mutex_unlock(&o.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 		WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 	WARN_ON(o.ctx != (void *)~0UL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 	/* trylock, succeeding */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 	o.ctx = (void *)~0UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 	ret = mutex_trylock(&o.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 	WARN_ON(!ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 		mutex_unlock(&o.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) 		WARN_ON(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 	WARN_ON(o.ctx != (void *)~0UL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 	/* trylock, failing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 	o.ctx = (void *)~0UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 	mutex_lock(&o.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 	ret = mutex_trylock(&o.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 	WARN_ON(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 	mutex_unlock(&o.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 	WARN_ON(o.ctx != (void *)~0UL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 	/* nest_lock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 	o.ctx = (void *)~0UL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 	mutex_lock_nest_lock(&o.base, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 	mutex_unlock(&o.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 	WARN_ON(o.ctx != (void *)~0UL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) static void ww_test_two_contexts(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 	WWAI(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 	WWAI(&t2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) static void ww_test_diff_class(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 	WWAI(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) #ifdef CONFIG_DEBUG_MUTEXES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) 	t.ww_class = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 	WWL(&o, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) static void ww_test_context_done_twice(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) 	WWAI(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) 	WWAD(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) 	WWAD(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 	WWAF(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) static void ww_test_context_unlock_twice(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 	WWAI(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 	WWAD(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 	WWAF(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 	WWAF(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) static void ww_test_context_fini_early(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 	WWAI(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 	WWL(&o, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 	WWAD(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 	WWAF(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) static void ww_test_context_lock_after_done(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 	WWAI(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 	WWAD(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 	WWL(&o, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) static void ww_test_object_unlock_twice(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 	WWL1(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 	WWU(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 	WWU(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) static void ww_test_object_lock_unbalanced(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 	WWAI(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 	WWL(&o, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 	t.acquired = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 	WWU(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 	WWAF(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) static void ww_test_object_lock_stale_context(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) 	WWAI(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 	o.ctx = &t2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) 	WWL(&o, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) static void ww_test_edeadlk_normal(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 	mutex_lock(&o2.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 	o2.ctx = &t2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 	mutex_release(&o2.base.dep_map, _THIS_IP_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) 	WWAI(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 	t2 = t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 	t2.stamp--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 	ret = WWL(&o, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) 	WARN_ON(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 	ret = WWL(&o2, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) 	WARN_ON(ret != -EDEADLK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) 	o2.ctx = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 	mutex_acquire(&o2.base.dep_map, 0, 1, _THIS_IP_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) 	mutex_unlock(&o2.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) 	WWU(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) 	WWL(&o2, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) static void ww_test_edeadlk_normal_slow(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) 	mutex_lock(&o2.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) 	mutex_release(&o2.base.dep_map, _THIS_IP_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) 	o2.ctx = &t2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 	WWAI(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 	t2 = t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 	t2.stamp--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 	ret = WWL(&o, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) 	WARN_ON(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) 	ret = WWL(&o2, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 	WARN_ON(ret != -EDEADLK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 	o2.ctx = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 	mutex_acquire(&o2.base.dep_map, 0, 1, _THIS_IP_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) 	mutex_unlock(&o2.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 	WWU(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) 	ww_mutex_lock_slow(&o2, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) static void ww_test_edeadlk_no_unlock(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) 	mutex_lock(&o2.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 	o2.ctx = &t2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) 	mutex_release(&o2.base.dep_map, _THIS_IP_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) 	WWAI(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) 	t2 = t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 	t2.stamp--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 	ret = WWL(&o, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) 	WARN_ON(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) 	ret = WWL(&o2, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) 	WARN_ON(ret != -EDEADLK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 	o2.ctx = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) 	mutex_acquire(&o2.base.dep_map, 0, 1, _THIS_IP_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) 	mutex_unlock(&o2.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) 	WWL(&o2, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1837) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1838) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1839) static void ww_test_edeadlk_no_unlock_slow(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1840) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1841) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1842) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1843) 	mutex_lock(&o2.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1844) 	mutex_release(&o2.base.dep_map, _THIS_IP_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1845) 	o2.ctx = &t2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1847) 	WWAI(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1848) 	t2 = t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1849) 	t2.stamp--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1851) 	ret = WWL(&o, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1852) 	WARN_ON(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1853) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1854) 	ret = WWL(&o2, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1855) 	WARN_ON(ret != -EDEADLK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1856) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1857) 	o2.ctx = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1858) 	mutex_acquire(&o2.base.dep_map, 0, 1, _THIS_IP_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1859) 	mutex_unlock(&o2.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1860) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1861) 	ww_mutex_lock_slow(&o2, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1862) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1863) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1864) static void ww_test_edeadlk_acquire_more(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1865) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1866) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1868) 	mutex_lock(&o2.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1869) 	mutex_release(&o2.base.dep_map, _THIS_IP_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1870) 	o2.ctx = &t2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1871) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1872) 	WWAI(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1873) 	t2 = t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1874) 	t2.stamp--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1875) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1876) 	ret = WWL(&o, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1877) 	WARN_ON(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1879) 	ret = WWL(&o2, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1880) 	WARN_ON(ret != -EDEADLK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1881) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1882) 	ret = WWL(&o3, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1883) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1884) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1885) static void ww_test_edeadlk_acquire_more_slow(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1886) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1887) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1888) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1889) 	mutex_lock(&o2.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1890) 	mutex_release(&o2.base.dep_map, _THIS_IP_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1891) 	o2.ctx = &t2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1892) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1893) 	WWAI(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1894) 	t2 = t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1895) 	t2.stamp--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1897) 	ret = WWL(&o, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1898) 	WARN_ON(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1899) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1900) 	ret = WWL(&o2, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1901) 	WARN_ON(ret != -EDEADLK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1902) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1903) 	ww_mutex_lock_slow(&o3, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1904) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1905) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1906) static void ww_test_edeadlk_acquire_more_edeadlk(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1907) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1908) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1909) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1910) 	mutex_lock(&o2.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1911) 	mutex_release(&o2.base.dep_map, _THIS_IP_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1912) 	o2.ctx = &t2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1913) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1914) 	mutex_lock(&o3.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1915) 	mutex_release(&o3.base.dep_map, _THIS_IP_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1916) 	o3.ctx = &t2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1917) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1918) 	WWAI(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1919) 	t2 = t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1920) 	t2.stamp--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1921) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1922) 	ret = WWL(&o, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1923) 	WARN_ON(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1924) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1925) 	ret = WWL(&o2, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1926) 	WARN_ON(ret != -EDEADLK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1927) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1928) 	ret = WWL(&o3, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1929) 	WARN_ON(ret != -EDEADLK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1931) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1932) static void ww_test_edeadlk_acquire_more_edeadlk_slow(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1933) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1934) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1935) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1936) 	mutex_lock(&o2.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1937) 	mutex_release(&o2.base.dep_map, _THIS_IP_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1938) 	o2.ctx = &t2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1939) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1940) 	mutex_lock(&o3.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1941) 	mutex_release(&o3.base.dep_map, _THIS_IP_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1942) 	o3.ctx = &t2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1943) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1944) 	WWAI(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1945) 	t2 = t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1946) 	t2.stamp--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1947) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1948) 	ret = WWL(&o, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1949) 	WARN_ON(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1950) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1951) 	ret = WWL(&o2, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1952) 	WARN_ON(ret != -EDEADLK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1953) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1954) 	ww_mutex_lock_slow(&o3, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1955) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1956) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1957) static void ww_test_edeadlk_acquire_wrong(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1958) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1959) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1960) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1961) 	mutex_lock(&o2.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1962) 	mutex_release(&o2.base.dep_map, _THIS_IP_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1963) 	o2.ctx = &t2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1965) 	WWAI(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1966) 	t2 = t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1967) 	t2.stamp--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1968) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1969) 	ret = WWL(&o, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1970) 	WARN_ON(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1971) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1972) 	ret = WWL(&o2, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1973) 	WARN_ON(ret != -EDEADLK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1974) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1975) 		WWU(&o2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1976) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1977) 	WWU(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1979) 	ret = WWL(&o3, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1980) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1981) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1982) static void ww_test_edeadlk_acquire_wrong_slow(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1983) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1984) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1985) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1986) 	mutex_lock(&o2.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1987) 	mutex_release(&o2.base.dep_map, _THIS_IP_);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1988) 	o2.ctx = &t2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1989) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1990) 	WWAI(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1991) 	t2 = t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1992) 	t2.stamp--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1994) 	ret = WWL(&o, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1995) 	WARN_ON(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1996) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1997) 	ret = WWL(&o2, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1998) 	WARN_ON(ret != -EDEADLK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1999) 	if (!ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2000) 		WWU(&o2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2001) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2002) 	WWU(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2004) 	ww_mutex_lock_slow(&o3, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2005) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2006) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2007) static void ww_test_spin_nest_unlocked(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2008) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2009) 	raw_spin_lock_nest_lock(&lock_A, &o.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2010) 	U(A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2011) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2012) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2013) static void ww_test_unneeded_slow(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2014) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2015) 	WWAI(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2016) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2017) 	ww_mutex_lock_slow(&o, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2018) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2019) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2020) static void ww_test_context_block(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2021) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2022) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2023) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2024) 	WWAI(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2025) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2026) 	ret = WWL(&o, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2027) 	WARN_ON(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2028) 	WWL1(&o2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2029) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2030) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2031) static void ww_test_context_try(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2032) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2033) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2034) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2035) 	WWAI(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2037) 	ret = WWL(&o, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2038) 	WARN_ON(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2039) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2040) 	ret = WWT(&o2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2041) 	WARN_ON(!ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2042) 	WWU(&o2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2043) 	WWU(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2044) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2045) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2046) static void ww_test_context_context(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2047) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2048) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2049) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2050) 	WWAI(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2051) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2052) 	ret = WWL(&o, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2053) 	WARN_ON(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2054) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2055) 	ret = WWL(&o2, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2056) 	WARN_ON(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2057) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2058) 	WWU(&o2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2059) 	WWU(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2060) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2061) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2062) static void ww_test_try_block(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2063) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2064) 	bool ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2065) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2066) 	ret = WWT(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2067) 	WARN_ON(!ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2069) 	WWL1(&o2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2070) 	WWU(&o2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2071) 	WWU(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2072) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2073) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2074) static void ww_test_try_try(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2075) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2076) 	bool ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2077) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2078) 	ret = WWT(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2079) 	WARN_ON(!ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2080) 	ret = WWT(&o2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2081) 	WARN_ON(!ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2082) 	WWU(&o2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2083) 	WWU(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2084) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2085) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2086) static void ww_test_try_context(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2087) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2088) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2089) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2090) 	ret = WWT(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2091) 	WARN_ON(!ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2092) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2093) 	WWAI(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2094) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2095) 	ret = WWL(&o2, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2096) 	WARN_ON(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2097) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2098) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2099) static void ww_test_block_block(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2101) 	WWL1(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2102) 	WWL1(&o2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2103) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2105) static void ww_test_block_try(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2107) 	bool ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2109) 	WWL1(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2110) 	ret = WWT(&o2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2111) 	WARN_ON(!ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2114) static void ww_test_block_context(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2116) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2118) 	WWL1(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2119) 	WWAI(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2121) 	ret = WWL(&o2, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2122) 	WARN_ON(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2125) static void ww_test_spin_block(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2127) 	L(A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2128) 	U(A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2130) 	WWL1(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2131) 	L(A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2132) 	U(A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2133) 	WWU(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2135) 	L(A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2136) 	WWL1(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2137) 	WWU(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2138) 	U(A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2139) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2140) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2141) static void ww_test_spin_try(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2142) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2143) 	bool ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2145) 	L(A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2146) 	U(A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2148) 	ret = WWT(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2149) 	WARN_ON(!ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2150) 	L(A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2151) 	U(A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2152) 	WWU(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2154) 	L(A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2155) 	ret = WWT(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2156) 	WARN_ON(!ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2157) 	WWU(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2158) 	U(A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2161) static void ww_test_spin_context(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2163) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2165) 	L(A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2166) 	U(A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2168) 	WWAI(&t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2170) 	ret = WWL(&o, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2171) 	WARN_ON(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2172) 	L(A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2173) 	U(A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2174) 	WWU(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2176) 	L(A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2177) 	ret = WWL(&o, &t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2178) 	WARN_ON(ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2179) 	WWU(&o);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2180) 	U(A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2183) static void ww_tests(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2184) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2185) 	printk("  --------------------------------------------------------------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2186) 	printk("  | Wound/wait tests |\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2187) 	printk("  ---------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2189) 	print_testname("ww api failures");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2190) 	dotest(ww_test_fail_acquire, SUCCESS, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2191) 	dotest(ww_test_normal, SUCCESS, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2192) 	dotest(ww_test_unneeded_slow, FAILURE, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2193) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2195) 	print_testname("ww contexts mixing");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2196) 	dotest(ww_test_two_contexts, FAILURE, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2197) 	dotest(ww_test_diff_class, FAILURE, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2198) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2199) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2200) 	print_testname("finishing ww context");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2201) 	dotest(ww_test_context_done_twice, FAILURE, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2202) 	dotest(ww_test_context_unlock_twice, FAILURE, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2203) 	dotest(ww_test_context_fini_early, FAILURE, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2204) 	dotest(ww_test_context_lock_after_done, FAILURE, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2205) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2207) 	print_testname("locking mismatches");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2208) 	dotest(ww_test_object_unlock_twice, FAILURE, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2209) 	dotest(ww_test_object_lock_unbalanced, FAILURE, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2210) 	dotest(ww_test_object_lock_stale_context, FAILURE, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2211) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2213) 	print_testname("EDEADLK handling");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2214) 	dotest(ww_test_edeadlk_normal, SUCCESS, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2215) 	dotest(ww_test_edeadlk_normal_slow, SUCCESS, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2216) 	dotest(ww_test_edeadlk_no_unlock, FAILURE, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2217) 	dotest(ww_test_edeadlk_no_unlock_slow, FAILURE, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2218) 	dotest(ww_test_edeadlk_acquire_more, FAILURE, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2219) 	dotest(ww_test_edeadlk_acquire_more_slow, FAILURE, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2220) 	dotest(ww_test_edeadlk_acquire_more_edeadlk, FAILURE, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2221) 	dotest(ww_test_edeadlk_acquire_more_edeadlk_slow, FAILURE, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2222) 	dotest(ww_test_edeadlk_acquire_wrong, FAILURE, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2223) 	dotest(ww_test_edeadlk_acquire_wrong_slow, FAILURE, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2224) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2226) 	print_testname("spinlock nest unlocked");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2227) 	dotest(ww_test_spin_nest_unlocked, FAILURE, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2228) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2229) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2230) 	printk("  -----------------------------------------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2231) 	printk("                                 |block | try  |context|\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2232) 	printk("  -----------------------------------------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2233) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2234) 	print_testname("context");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2235) 	dotest(ww_test_context_block, FAILURE, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2236) 	dotest(ww_test_context_try, SUCCESS, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2237) 	dotest(ww_test_context_context, SUCCESS, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2238) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2240) 	print_testname("try");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2241) 	dotest(ww_test_try_block, FAILURE, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2242) 	dotest(ww_test_try_try, SUCCESS, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2243) 	dotest(ww_test_try_context, FAILURE, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2244) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2246) 	print_testname("block");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2247) 	dotest(ww_test_block_block, FAILURE, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2248) 	dotest(ww_test_block_try, SUCCESS, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2249) 	dotest(ww_test_block_context, FAILURE, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2250) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2252) 	print_testname("spinlock");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2253) 	dotest(ww_test_spin_block, FAILURE, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2254) 	dotest(ww_test_spin_try, SUCCESS, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2255) 	dotest(ww_test_spin_context, FAILURE, LOCKTYPE_WW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2256) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2257) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2260) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2261)  * <in hardirq handler>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2262)  * read_lock(&A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2263)  *			<hardirq disable>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2264)  *			spin_lock(&B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2265)  * spin_lock(&B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2266)  *			read_lock(&A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2267)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2268)  * is a deadlock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2269)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2270) static void queued_read_lock_hardirq_RE_Er(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2272) 	HARDIRQ_ENTER();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2273) 	read_lock(&rwlock_A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2274) 	LOCK(B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2275) 	UNLOCK(B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2276) 	read_unlock(&rwlock_A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2277) 	HARDIRQ_EXIT();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2279) 	HARDIRQ_DISABLE();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2280) 	LOCK(B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2281) 	read_lock(&rwlock_A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2282) 	read_unlock(&rwlock_A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2283) 	UNLOCK(B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2284) 	HARDIRQ_ENABLE();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2287) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2288)  * <in hardirq handler>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2289)  * spin_lock(&B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2290)  *			<hardirq disable>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2291)  *			read_lock(&A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2292)  * read_lock(&A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2293)  *			spin_lock(&B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2294)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2295)  * is not a deadlock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2296)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2297) static void queued_read_lock_hardirq_ER_rE(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2299) 	HARDIRQ_ENTER();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2300) 	LOCK(B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2301) 	read_lock(&rwlock_A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2302) 	read_unlock(&rwlock_A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2303) 	UNLOCK(B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2304) 	HARDIRQ_EXIT();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2306) 	HARDIRQ_DISABLE();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2307) 	read_lock(&rwlock_A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2308) 	LOCK(B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2309) 	UNLOCK(B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2310) 	read_unlock(&rwlock_A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2311) 	HARDIRQ_ENABLE();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2312) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2314) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2315)  * <hardirq disable>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2316)  * spin_lock(&B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2317)  *			read_lock(&A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2318)  *			<in hardirq handler>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2319)  *			spin_lock(&B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2320)  * read_lock(&A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2321)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2322)  * is a deadlock. Because the two read_lock()s are both non-recursive readers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2323)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2324) static void queued_read_lock_hardirq_inversion(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2327) 	HARDIRQ_ENTER();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2328) 	LOCK(B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2329) 	UNLOCK(B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2330) 	HARDIRQ_EXIT();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2331) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2332) 	HARDIRQ_DISABLE();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2333) 	LOCK(B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2334) 	read_lock(&rwlock_A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2335) 	read_unlock(&rwlock_A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2336) 	UNLOCK(B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2337) 	HARDIRQ_ENABLE();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2339) 	read_lock(&rwlock_A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2340) 	read_unlock(&rwlock_A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2343) static void queued_read_lock_tests(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2345) 	printk("  --------------------------------------------------------------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2346) 	printk("  | queued read lock tests |\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2347) 	printk("  ---------------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2348) 	print_testname("hardirq read-lock/lock-read");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2349) 	dotest(queued_read_lock_hardirq_RE_Er, FAILURE, LOCKTYPE_RWLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2350) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2352) 	print_testname("hardirq lock-read/read-lock");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2353) 	dotest(queued_read_lock_hardirq_ER_rE, SUCCESS, LOCKTYPE_RWLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2354) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2356) 	print_testname("hardirq inversion");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2357) 	dotest(queued_read_lock_hardirq_inversion, FAILURE, LOCKTYPE_RWLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2358) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2360) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2361) void locking_selftest(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2362) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2363) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2364) 	 * Got a locking failure before the selftest ran?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2365) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2366) 	if (!debug_locks) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2367) 		printk("----------------------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2368) 		printk("| Locking API testsuite disabled |\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2369) 		printk("----------------------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2370) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2371) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2373) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2374) 	 * treats read_lock() as recursive read locks for testing purpose
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2375) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2376) 	force_read_lock_recursive = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2377) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2378) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2379) 	 * Run the testsuite:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2380) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2381) 	printk("------------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2382) 	printk("| Locking API testsuite:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2383) 	printk("----------------------------------------------------------------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2384) 	printk("                                 | spin |wlock |rlock |mutex | wsem | rsem |\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2385) 	printk("  --------------------------------------------------------------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2387) 	init_shared_classes();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2388) 	debug_locks_silent = !debug_locks_verbose;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2389) 	lockdep_set_selftest_task(current);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2391) 	DO_TESTCASE_6R("A-A deadlock", AA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2392) 	DO_TESTCASE_6R("A-B-B-A deadlock", ABBA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2393) 	DO_TESTCASE_6R("A-B-B-C-C-A deadlock", ABBCCA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2394) 	DO_TESTCASE_6R("A-B-C-A-B-C deadlock", ABCABC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2395) 	DO_TESTCASE_6R("A-B-B-C-C-D-D-A deadlock", ABBCCDDA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2396) 	DO_TESTCASE_6R("A-B-C-D-B-D-D-A deadlock", ABCDBDDA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2397) 	DO_TESTCASE_6R("A-B-C-D-B-C-D-A deadlock", ABCDBCDA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2398) 	DO_TESTCASE_6("double unlock", double_unlock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2399) 	DO_TESTCASE_6("initialize held", init_held);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2401) 	printk("  --------------------------------------------------------------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2402) 	print_testname("recursive read-lock");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2403) 	pr_cont("             |");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2404) 	dotest(rlock_AA1, SUCCESS, LOCKTYPE_RWLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2405) 	pr_cont("             |");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2406) 	dotest(rsem_AA1, FAILURE, LOCKTYPE_RWSEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2407) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2409) 	print_testname("recursive read-lock #2");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2410) 	pr_cont("             |");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2411) 	dotest(rlock_AA1B, SUCCESS, LOCKTYPE_RWLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2412) 	pr_cont("             |");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2413) 	dotest(rsem_AA1B, FAILURE, LOCKTYPE_RWSEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2414) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2415) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2416) 	print_testname("mixed read-write-lock");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2417) 	pr_cont("             |");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2418) 	dotest(rlock_AA2, FAILURE, LOCKTYPE_RWLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2419) 	pr_cont("             |");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2420) 	dotest(rsem_AA2, FAILURE, LOCKTYPE_RWSEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2421) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2422) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2423) 	print_testname("mixed write-read-lock");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2424) 	pr_cont("             |");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2425) 	dotest(rlock_AA3, FAILURE, LOCKTYPE_RWLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2426) 	pr_cont("             |");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2427) 	dotest(rsem_AA3, FAILURE, LOCKTYPE_RWSEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2428) 	pr_cont("\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2429) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2430) 	print_testname("mixed read-lock/lock-write ABBA");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2431) 	pr_cont("             |");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2432) 	dotest(rlock_ABBA1, FAILURE, LOCKTYPE_RWLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2433) 	pr_cont("             |");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2434) 	dotest(rwsem_ABBA1, FAILURE, LOCKTYPE_RWSEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2436) 	print_testname("mixed read-lock/lock-read ABBA");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2437) 	pr_cont("             |");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2438) 	dotest(rlock_ABBA2, SUCCESS, LOCKTYPE_RWLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2439) 	pr_cont("             |");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2440) 	dotest(rwsem_ABBA2, FAILURE, LOCKTYPE_RWSEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2442) 	print_testname("mixed write-lock/lock-write ABBA");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2443) 	pr_cont("             |");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2444) 	dotest(rlock_ABBA3, FAILURE, LOCKTYPE_RWLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2445) 	pr_cont("             |");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2446) 	dotest(rwsem_ABBA3, FAILURE, LOCKTYPE_RWSEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2447) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2448) 	print_testname("chain cached mixed R-L/L-W ABBA");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2449) 	pr_cont("             |");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2450) 	dotest(rlock_chaincache_ABBA1, FAILURE, LOCKTYPE_RWLOCK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2452) 	DO_TESTCASE_6x1RRB("rlock W1R2/W2R3/W3R1", W1R2_W2R3_W3R1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2453) 	DO_TESTCASE_6x1RRB("rlock W1W2/R2R3/W3R1", W1W2_R2R3_W3R1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2454) 	DO_TESTCASE_6x1RR("rlock W1W2/R2R3/R3W1", W1W2_R2R3_R3W1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2455) 	DO_TESTCASE_6x1RR("rlock W1R2/R2R3/W3W1", W1R2_R2R3_W3W1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2456) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2457) 	printk("  --------------------------------------------------------------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2459) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2460) 	 * irq-context testcases:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2461) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2462) 	DO_TESTCASE_2x6("irqs-on + irq-safe-A", irqsafe1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2463) 	DO_TESTCASE_2x3("sirq-safe-A => hirqs-on", irqsafe2A);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2464) 	DO_TESTCASE_2x6("safe-A + irqs-on", irqsafe2B);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2465) 	DO_TESTCASE_6x6("safe-A + unsafe-B #1", irqsafe3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2466) 	DO_TESTCASE_6x6("safe-A + unsafe-B #2", irqsafe4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2467) 	DO_TESTCASE_6x6RW("irq lock-inversion", irq_inversion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2468) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2469) 	DO_TESTCASE_6x2x2RW("irq read-recursion", irq_read_recursion);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2470) 	DO_TESTCASE_6x2x2RW("irq read-recursion #2", irq_read_recursion2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2471) 	DO_TESTCASE_6x2x2RW("irq read-recursion #3", irq_read_recursion3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2472) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2473) 	ww_tests();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2475) 	force_read_lock_recursive = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2476) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2477) 	 * queued_read_lock() specific test cases can be put here
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2478) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2479) 	if (IS_ENABLED(CONFIG_QUEUED_RWLOCKS))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2480) 		queued_read_lock_tests();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2482) 	if (unexpected_testcase_failures) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2483) 		printk("-----------------------------------------------------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2484) 		debug_locks = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2485) 		printk("BUG: %3d unexpected failures (out of %3d) - debugging disabled! |\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2486) 			unexpected_testcase_failures, testcase_total);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2487) 		printk("-----------------------------------------------------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2488) 	} else if (expected_testcase_failures && testcase_successes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2489) 		printk("--------------------------------------------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2490) 		printk("%3d out of %3d testcases failed, as expected. |\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2491) 			expected_testcase_failures, testcase_total);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2492) 		printk("----------------------------------------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2493) 		debug_locks = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2494) 	} else if (expected_testcase_failures && !testcase_successes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2495) 		printk("--------------------------------------------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2496) 		printk("All %3d testcases failed, as expected. |\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2497) 			expected_testcase_failures);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2498) 		printk("----------------------------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2499) 		debug_locks = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2500) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2501) 		printk("-------------------------------------------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2502) 		printk("Good, all %3d testcases passed! |\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2503) 			testcase_successes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2504) 		printk("---------------------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2505) 		debug_locks = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2506) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2507) 	lockdep_set_selftest_task(NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2508) 	debug_locks_silent = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2509) }