livepatch-callbacks-busymod.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (C) 2017 Joe Lawrence <joe.lawrence@redhat.com>
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  16. */
  17. /*
  18. * livepatch-callbacks-busymod.c - (un)patching callbacks demo support module
  19. *
  20. *
  21. * Purpose
  22. * -------
  23. *
  24. * Simple module to demonstrate livepatch (un)patching callbacks.
  25. *
  26. *
  27. * Usage
  28. * -----
  29. *
  30. * This module is not intended to be standalone. See the "Usage"
  31. * section of livepatch-callbacks-mod.c.
  32. */
  33. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  34. #include <linux/module.h>
  35. #include <linux/kernel.h>
  36. #include <linux/workqueue.h>
  37. #include <linux/delay.h>
  38. static int sleep_secs;
  39. module_param(sleep_secs, int, 0644);
  40. MODULE_PARM_DESC(sleep_secs, "sleep_secs (default=0)");
  41. static void busymod_work_func(struct work_struct *work);
  42. static DECLARE_DELAYED_WORK(work, busymod_work_func);
  43. static void busymod_work_func(struct work_struct *work)
  44. {
  45. pr_info("%s, sleeping %d seconds ...\n", __func__, sleep_secs);
  46. msleep(sleep_secs * 1000);
  47. pr_info("%s exit\n", __func__);
  48. }
  49. static int livepatch_callbacks_mod_init(void)
  50. {
  51. pr_info("%s\n", __func__);
  52. schedule_delayed_work(&work,
  53. msecs_to_jiffies(1000 * 0));
  54. return 0;
  55. }
  56. static void livepatch_callbacks_mod_exit(void)
  57. {
  58. cancel_delayed_work_sync(&work);
  59. pr_info("%s\n", __func__);
  60. }
  61. module_init(livepatch_callbacks_mod_init);
  62. module_exit(livepatch_callbacks_mod_exit);
  63. MODULE_LICENSE("GPL");