linux/lib/test_lockup.c

// SPDX-License-Identifier: GPL-2.0
/*
 * Test module to generate lockups
 */
#define pr_fmt(fmt)

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/sched.h>
#include <linux/sched/signal.h>
#include <linux/sched/clock.h>
#include <linux/cpu.h>
#include <linux/nmi.h>
#include <linux/mm.h>
#include <linux/uaccess.h>
#include <linux/file.h>

static unsigned int time_secs;
module_param(time_secs, uint, 0600);
MODULE_PARM_DESC();

static unsigned int time_nsecs;
module_param(time_nsecs, uint, 0600);
MODULE_PARM_DESC();

static unsigned int cooldown_secs;
module_param(cooldown_secs, uint, 0600);
MODULE_PARM_DESC();

static unsigned int cooldown_nsecs;
module_param(cooldown_nsecs, uint, 0600);
MODULE_PARM_DESC();

static unsigned int iterations =;
module_param(iterations, uint, 0600);
MODULE_PARM_DESC();

static bool all_cpus;
module_param(all_cpus, bool, 0400);
MODULE_PARM_DESC();

static int wait_state;
static char *state =;
module_param(state, charp, 0400);
MODULE_PARM_DESC();

static bool use_hrtimer;
module_param(use_hrtimer, bool, 0400);
MODULE_PARM_DESC();

static bool iowait;
module_param(iowait, bool, 0400);
MODULE_PARM_DESC();

static bool lock_read;
module_param(lock_read, bool, 0400);
MODULE_PARM_DESC();

static bool lock_single;
module_param(lock_single, bool, 0400);
MODULE_PARM_DESC();

static bool reacquire_locks;
module_param(reacquire_locks, bool, 0400);
MODULE_PARM_DESC();

static bool touch_softlockup;
module_param(touch_softlockup, bool, 0600);
MODULE_PARM_DESC();

static bool touch_hardlockup;
module_param(touch_hardlockup, bool, 0600);
MODULE_PARM_DESC();

static bool call_cond_resched;
module_param(call_cond_resched, bool, 0600);
MODULE_PARM_DESC();

static bool measure_lock_wait;
module_param(measure_lock_wait, bool, 0400);
MODULE_PARM_DESC();

static unsigned long lock_wait_threshold =;
module_param(lock_wait_threshold, ulong, 0400);
MODULE_PARM_DESC();

static bool test_disable_irq;
module_param_named(disable_irq, test_disable_irq, bool, 0400);
MODULE_PARM_DESC();

static bool disable_softirq;
module_param(disable_softirq, bool, 0400);
MODULE_PARM_DESC();

static bool disable_preempt;
module_param(disable_preempt, bool, 0400);
MODULE_PARM_DESC();

static bool lock_rcu;
module_param(lock_rcu, bool, 0400);
MODULE_PARM_DESC();

static bool lock_mmap_sem;
module_param(lock_mmap_sem, bool, 0400);
MODULE_PARM_DESC();

static unsigned long lock_rwsem_ptr;
module_param_unsafe(lock_rwsem_ptr, ulong, 0400);
MODULE_PARM_DESC();

static unsigned long lock_mutex_ptr;
module_param_unsafe(lock_mutex_ptr, ulong, 0400);
MODULE_PARM_DESC();

static unsigned long lock_spinlock_ptr;
module_param_unsafe(lock_spinlock_ptr, ulong, 0400);
MODULE_PARM_DESC();

static unsigned long lock_rwlock_ptr;
module_param_unsafe(lock_rwlock_ptr, ulong, 0400);
MODULE_PARM_DESC();

static unsigned int alloc_pages_nr;
module_param_unsafe(alloc_pages_nr, uint, 0600);
MODULE_PARM_DESC();

static unsigned int alloc_pages_order;
module_param(alloc_pages_order, uint, 0400);
MODULE_PARM_DESC();

static gfp_t alloc_pages_gfp =;
module_param_unsafe(alloc_pages_gfp, uint, 0400);
MODULE_PARM_DESC();

static bool alloc_pages_atomic;
module_param(alloc_pages_atomic, bool, 0400);
MODULE_PARM_DESC();

static bool reallocate_pages;
module_param(reallocate_pages, bool, 0400);
MODULE_PARM_DESC();

struct file *test_file;
static struct inode *test_inode;
static char test_file_path[256];
module_param_string();
MODULE_PARM_DESC();

static bool test_lock_inode;
module_param_named(lock_inode, test_lock_inode, bool, 0400);
MODULE_PARM_DESC();

static bool test_lock_mapping;
module_param_named(lock_mapping, test_lock_mapping, bool, 0400);
MODULE_PARM_DESC();

static bool test_lock_sb_umount;
module_param_named(lock_sb_umount, test_lock_sb_umount, bool, 0400);
MODULE_PARM_DESC();

static atomic_t alloc_pages_failed =;

static atomic64_t max_lock_wait =;

static struct task_struct *main_task;
static int master_cpu;

static void test_lock(bool master, bool verbose)
{}

static void test_unlock(bool master, bool verbose)
{}

static void test_alloc_pages(struct list_head *pages)
{}

static void test_free_pages(struct list_head *pages)
{}

static void test_wait(unsigned int secs, unsigned int nsecs)
{}

static void test_lockup(bool master)
{}

static DEFINE_PER_CPU(struct work_struct, test_works);

static void test_work_fn(struct work_struct *work)
{}

static bool test_kernel_ptr(unsigned long addr, int size)
{}

static bool __maybe_unused test_magic(unsigned long addr, int offset,
				      unsigned int expected)
{}

static int __init test_lockup_init(void)
{}
module_init(test_lockup_init);

MODULE_LICENSE();
MODULE_AUTHOR();
MODULE_DESCRIPTION();