drm/atomic-helper: document drm_atomic_helper_check() restrictions
[drm/drm-misc.git] / tools / testing / selftests / livepatch / test_modules / test_klp_callbacks_busy.c
blob133929e0ce8ff0a0ffcece81544f5c2c940c97fd
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2018 Joe Lawrence <joe.lawrence@redhat.com>
4 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
6 #include <linux/module.h>
7 #include <linux/kernel.h>
8 #include <linux/sched.h>
9 #include <linux/workqueue.h>
10 #include <linux/delay.h>
12 /* load/run-time control from sysfs writer */
13 static bool block_transition;
14 module_param(block_transition, bool, 0644);
15 MODULE_PARM_DESC(block_transition, "block_transition (default=false)");
17 static void busymod_work_func(struct work_struct *work);
18 static DECLARE_WORK(work, busymod_work_func);
19 static DECLARE_COMPLETION(busymod_work_started);
21 static void busymod_work_func(struct work_struct *work)
23 pr_info("%s enter\n", __func__);
24 complete(&busymod_work_started);
26 while (READ_ONCE(block_transition)) {
28 * Busy-wait until the sysfs writer has acknowledged a
29 * blocked transition and clears the flag.
31 msleep(20);
34 pr_info("%s exit\n", __func__);
37 static int test_klp_callbacks_busy_init(void)
39 pr_info("%s\n", __func__);
40 schedule_work(&work);
43 * To synchronize kernel messages, hold the init function from
44 * exiting until the work function's entry message has printed.
46 wait_for_completion(&busymod_work_started);
48 if (!block_transition) {
50 * Serialize output: print all messages from the work
51 * function before returning from init().
53 flush_work(&work);
56 return 0;
59 static void test_klp_callbacks_busy_exit(void)
61 WRITE_ONCE(block_transition, false);
62 flush_work(&work);
63 pr_info("%s\n", __func__);
66 module_init(test_klp_callbacks_busy_init);
67 module_exit(test_klp_callbacks_busy_exit);
68 MODULE_LICENSE("GPL");
69 MODULE_AUTHOR("Joe Lawrence <joe.lawrence@redhat.com>");
70 MODULE_DESCRIPTION("Livepatch test: busy target module");