[v2] locktorture: Add raw_spinlock* torture tests for PREEMPT_RT kernels
Commit Message
In PREEMPT_RT kernels, both spin_lock() and spin_lock_irq() are converted
to sleepable rt_spin_lock(). This means that the interrupt related suffix
for spin_lock/unlock(_irq, irqsave/irqrestore) do not affect the CPU's
interrupt state. This commit therefore adds raw spin-lock torture tests.
This in turn permits pure spin locks to be tested in PREEMPT_RT kernels.
Suggested-by: Paul E. McKenney <paulmck@kernel.org>
Suggested-by: Davidlohr Bueso <dave@stgolabs.net>
Signed-off-by: Zqiang <qiang1.zhang@intel.com>
---
kernel/locking/locktorture.c | 56 +++++++++++++++++++++++++++++++++++-
1 file changed, 55 insertions(+), 1 deletion(-)
Comments
On Fri, 24 Feb 2023, Zqiang wrote:
>In PREEMPT_RT kernels, both spin_lock() and spin_lock_irq() are converted
>to sleepable rt_spin_lock(). This means that the interrupt related suffix
>for spin_lock/unlock(_irq, irqsave/irqrestore) do not affect the CPU's
>interrupt state. This commit therefore adds raw spin-lock torture tests.
>This in turn permits pure spin locks to be tested in PREEMPT_RT kernels.
>
>Suggested-by: Paul E. McKenney <paulmck@kernel.org>
>Suggested-by: Davidlohr Bueso <dave@stgolabs.net>
>Signed-off-by: Zqiang <qiang1.zhang@intel.com>
Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
On Thu, Feb 23, 2023 at 07:12:32PM -0800, Davidlohr Bueso wrote:
> On Fri, 24 Feb 2023, Zqiang wrote:
>
> > In PREEMPT_RT kernels, both spin_lock() and spin_lock_irq() are converted
> > to sleepable rt_spin_lock(). This means that the interrupt related suffix
> > for spin_lock/unlock(_irq, irqsave/irqrestore) do not affect the CPU's
> > interrupt state. This commit therefore adds raw spin-lock torture tests.
> > This in turn permits pure spin locks to be tested in PREEMPT_RT kernels.
> >
> > Suggested-by: Paul E. McKenney <paulmck@kernel.org>
> > Suggested-by: Davidlohr Bueso <dave@stgolabs.net>
> > Signed-off-by: Zqiang <qiang1.zhang@intel.com>
>
> Reviewed-by: Davidlohr Bueso <dave@stgolabs.net>
Queued replacing the previous version, thank you both!
Thanx, Paul
@@ -55,7 +55,7 @@ torture_param(int, nested_locks, 0, "Number of nested locks (max = 8)");
/* Going much higher trips "BUG: MAX_LOCKDEP_CHAIN_HLOCKS too low!" errors */
#define MAX_NESTED_LOCKS 8
-static char *torture_type = "spin_lock";
+static char *torture_type = IS_ENABLED(CONFIG_PREEMPT_RT) ? "raw_spin_lock" : "spin_lock";
module_param(torture_type, charp, 0444);
MODULE_PARM_DESC(torture_type,
"Type of lock to torture (spin_lock, spin_lock_irq, mutex_lock, ...)");
@@ -257,6 +257,59 @@ static struct lock_torture_ops spin_lock_irq_ops = {
.name = "spin_lock_irq"
};
+static DEFINE_RAW_SPINLOCK(torture_raw_spinlock);
+
+static int torture_raw_spin_lock_write_lock(int tid __maybe_unused)
+__acquires(torture_raw_spinlock)
+{
+ raw_spin_lock(&torture_raw_spinlock);
+ return 0;
+}
+
+static void torture_raw_spin_lock_write_unlock(int tid __maybe_unused)
+__releases(torture_raw_spinlock)
+{
+ raw_spin_unlock(&torture_raw_spinlock);
+}
+
+static struct lock_torture_ops raw_spin_lock_ops = {
+ .writelock = torture_raw_spin_lock_write_lock,
+ .write_delay = torture_spin_lock_write_delay,
+ .task_boost = torture_rt_boost,
+ .writeunlock = torture_raw_spin_lock_write_unlock,
+ .readlock = NULL,
+ .read_delay = NULL,
+ .readunlock = NULL,
+ .name = "raw_spin_lock"
+};
+
+static int torture_raw_spin_lock_write_lock_irq(int tid __maybe_unused)
+__acquires(torture_raw_spinlock)
+{
+ unsigned long flags;
+
+ raw_spin_lock_irqsave(&torture_raw_spinlock, flags);
+ cxt.cur_ops->flags = flags;
+ return 0;
+}
+
+static void torture_raw_spin_lock_write_unlock_irq(int tid __maybe_unused)
+__releases(torture_raw_spinlock)
+{
+ raw_spin_unlock_irqrestore(&torture_raw_spinlock, cxt.cur_ops->flags);
+}
+
+static struct lock_torture_ops raw_spin_lock_irq_ops = {
+ .writelock = torture_raw_spin_lock_write_lock_irq,
+ .write_delay = torture_spin_lock_write_delay,
+ .task_boost = torture_rt_boost,
+ .writeunlock = torture_raw_spin_lock_write_unlock_irq,
+ .readlock = NULL,
+ .read_delay = NULL,
+ .readunlock = NULL,
+ .name = "raw_spin_lock_irq"
+};
+
static DEFINE_RWLOCK(torture_rwlock);
static int torture_rwlock_write_lock(int tid __maybe_unused)
@@ -1017,6 +1070,7 @@ static int __init lock_torture_init(void)
static struct lock_torture_ops *torture_ops[] = {
&lock_busted_ops,
&spin_lock_ops, &spin_lock_irq_ops,
+ &raw_spin_lock_ops, &raw_spin_lock_irq_ops,
&rw_lock_ops, &rw_lock_irq_ops,
&mutex_lock_ops,
&ww_mutex_lock_ops,