livepatch-callbacks-busymod.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2017 Joe Lawrence <joe.lawrence@redhat.com>
  4. */
  5. /*
  6. * livepatch-callbacks-busymod.c - (un)patching callbacks demo support module
  7. *
  8. *
  9. * Purpose
  10. * -------
  11. *
  12. * Simple module to demonstrate livepatch (un)patching callbacks.
  13. *
  14. *
  15. * Usage
  16. * -----
  17. *
  18. * This module is not intended to be standalone. See the "Usage"
  19. * section of livepatch-callbacks-mod.c.
  20. */
  21. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  22. #include <linux/module.h>
  23. #include <linux/kernel.h>
  24. #include <linux/workqueue.h>
  25. #include <linux/delay.h>
  26. static int sleep_secs;
  27. module_param(sleep_secs, int, 0644);
  28. MODULE_PARM_DESC(sleep_secs, "sleep_secs (default=0)");
  29. static void busymod_work_func(struct work_struct *work);
  30. static DECLARE_DELAYED_WORK(work, busymod_work_func);
  31. static void busymod_work_func(struct work_struct *work)
  32. {
  33. pr_info("%s, sleeping %d seconds ...\n", __func__, sleep_secs);
  34. msleep(sleep_secs * 1000);
  35. pr_info("%s exit\n", __func__);
  36. }
  37. static int livepatch_callbacks_mod_init(void)
  38. {
  39. pr_info("%s\n", __func__);
  40. schedule_delayed_work(&work,
  41. msecs_to_jiffies(1000 * 0));
  42. return 0;
  43. }
  44. static void livepatch_callbacks_mod_exit(void)
  45. {
  46. cancel_delayed_work_sync(&work);
  47. pr_info("%s\n", __func__);
  48. }
  49. module_init(livepatch_callbacks_mod_init);
  50. module_exit(livepatch_callbacks_mod_exit);
  51. MODULE_LICENSE("GPL");