Skip to content

Commit a6884f6

Browse files
kkdwivediAlexei Starovoitov
authored andcommitted
rqspinlock: Add locktorture support
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>
1 parent e2082e3 commit a6884f6

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

kernel/locking/locktorture.c

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,60 @@ static struct lock_torture_ops raw_spin_lock_irq_ops = {
362362
.name = "raw_spin_lock_irq"
363363
};
364364

365+
#ifdef CONFIG_BPF_SYSCALL
366+
367+
#include <asm/rqspinlock.h>
368+
static rqspinlock_t rqspinlock;
369+
370+
static int torture_raw_res_spin_write_lock(int tid __maybe_unused)
371+
{
372+
raw_res_spin_lock(&rqspinlock);
373+
return 0;
374+
}
375+
376+
static void torture_raw_res_spin_write_unlock(int tid __maybe_unused)
377+
{
378+
raw_res_spin_unlock(&rqspinlock);
379+
}
380+
381+
static struct lock_torture_ops raw_res_spin_lock_ops = {
382+
.writelock = torture_raw_res_spin_write_lock,
383+
.write_delay = torture_spin_lock_write_delay,
384+
.task_boost = torture_rt_boost,
385+
.writeunlock = torture_raw_res_spin_write_unlock,
386+
.readlock = NULL,
387+
.read_delay = NULL,
388+
.readunlock = NULL,
389+
.name = "raw_res_spin_lock"
390+
};
391+
392+
static int torture_raw_res_spin_write_lock_irq(int tid __maybe_unused)
393+
{
394+
unsigned long flags;
395+
396+
raw_res_spin_lock_irqsave(&rqspinlock, flags);
397+
cxt.cur_ops->flags = flags;
398+
return 0;
399+
}
400+
401+
static void torture_raw_res_spin_write_unlock_irq(int tid __maybe_unused)
402+
{
403+
raw_res_spin_unlock_irqrestore(&rqspinlock, cxt.cur_ops->flags);
404+
}
405+
406+
static struct lock_torture_ops raw_res_spin_lock_irq_ops = {
407+
.writelock = torture_raw_res_spin_write_lock_irq,
408+
.write_delay = torture_spin_lock_write_delay,
409+
.task_boost = torture_rt_boost,
410+
.writeunlock = torture_raw_res_spin_write_unlock_irq,
411+
.readlock = NULL,
412+
.read_delay = NULL,
413+
.readunlock = NULL,
414+
.name = "raw_res_spin_lock_irq"
415+
};
416+
417+
#endif
418+
365419
static DEFINE_RWLOCK(torture_rwlock);
366420

367421
static int torture_rwlock_write_lock(int tid __maybe_unused)
@@ -1168,6 +1222,9 @@ static int __init lock_torture_init(void)
11681222
&lock_busted_ops,
11691223
&spin_lock_ops, &spin_lock_irq_ops,
11701224
&raw_spin_lock_ops, &raw_spin_lock_irq_ops,
1225+
#ifdef CONFIG_BPF_SYSCALL
1226+
&raw_res_spin_lock_ops, &raw_res_spin_lock_irq_ops,
1227+
#endif
11711228
&rw_lock_ops, &rw_lock_irq_ops,
11721229
&mutex_lock_ops,
11731230
&ww_mutex_lock_ops,

0 commit comments

Comments
 (0)