]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
rqspinlock: Add locktorture support
authorKumar Kartikeya Dwivedi <memxor@gmail.com>
Sun, 16 Mar 2025 04:05:34 +0000 (21:05 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 19 Mar 2025 15:03:05 +0000 (08:03 -0700)
Introduce locktorture support for rqspinlock using the newly added
macros as the first in-kernel user and consumer. Guard the code with
CONFIG_BPF_SYSCALL ifdef since rqspinlock is not available otherwise.

Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Link: https://lore.kernel.org/r/20250316040541.108729-19-memxor@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/locking/locktorture.c

index cc33470f4de97bffa12074bcd5498f641bc48ad5..ce0362f0a8719a5e6d4f81665a756508572edb7a 100644 (file)
@@ -362,6 +362,60 @@ static struct lock_torture_ops raw_spin_lock_irq_ops = {
        .name           = "raw_spin_lock_irq"
 };
 
+#ifdef CONFIG_BPF_SYSCALL
+
+#include <asm/rqspinlock.h>
+static rqspinlock_t rqspinlock;
+
+static int torture_raw_res_spin_write_lock(int tid __maybe_unused)
+{
+       raw_res_spin_lock(&rqspinlock);
+       return 0;
+}
+
+static void torture_raw_res_spin_write_unlock(int tid __maybe_unused)
+{
+       raw_res_spin_unlock(&rqspinlock);
+}
+
+static struct lock_torture_ops raw_res_spin_lock_ops = {
+       .writelock      = torture_raw_res_spin_write_lock,
+       .write_delay    = torture_spin_lock_write_delay,
+       .task_boost     = torture_rt_boost,
+       .writeunlock    = torture_raw_res_spin_write_unlock,
+       .readlock       = NULL,
+       .read_delay     = NULL,
+       .readunlock     = NULL,
+       .name           = "raw_res_spin_lock"
+};
+
+static int torture_raw_res_spin_write_lock_irq(int tid __maybe_unused)
+{
+       unsigned long flags;
+
+       raw_res_spin_lock_irqsave(&rqspinlock, flags);
+       cxt.cur_ops->flags = flags;
+       return 0;
+}
+
+static void torture_raw_res_spin_write_unlock_irq(int tid __maybe_unused)
+{
+       raw_res_spin_unlock_irqrestore(&rqspinlock, cxt.cur_ops->flags);
+}
+
+static struct lock_torture_ops raw_res_spin_lock_irq_ops = {
+       .writelock      = torture_raw_res_spin_write_lock_irq,
+       .write_delay    = torture_spin_lock_write_delay,
+       .task_boost     = torture_rt_boost,
+       .writeunlock    = torture_raw_res_spin_write_unlock_irq,
+       .readlock       = NULL,
+       .read_delay     = NULL,
+       .readunlock     = NULL,
+       .name           = "raw_res_spin_lock_irq"
+};
+
+#endif
+
 static DEFINE_RWLOCK(torture_rwlock);
 
 static int torture_rwlock_write_lock(int tid __maybe_unused)
@@ -1168,6 +1222,9 @@ static int __init lock_torture_init(void)
                &lock_busted_ops,
                &spin_lock_ops, &spin_lock_irq_ops,
                &raw_spin_lock_ops, &raw_spin_lock_irq_ops,
+#ifdef CONFIG_BPF_SYSCALL
+               &raw_res_spin_lock_ops, &raw_res_spin_lock_irq_ops,
+#endif
                &rw_lock_ops, &rw_lock_irq_ops,
                &mutex_lock_ops,
                &ww_mutex_lock_ops,