livepatch_external.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * External livepatch interfaces for patch creation tooling
  4. */
  5. #ifndef _LINUX_LIVEPATCH_EXTERNAL_H_
  6. #define _LINUX_LIVEPATCH_EXTERNAL_H_
  7. #include <linux/types.h>
  8. #define KLP_RELOC_SEC_PREFIX ".klp.rela."
  9. #define KLP_SYM_PREFIX ".klp.sym."
  10. #define __KLP_PRE_PATCH_PREFIX __klp_pre_patch_callback_
  11. #define __KLP_POST_PATCH_PREFIX __klp_post_patch_callback_
  12. #define __KLP_PRE_UNPATCH_PREFIX __klp_pre_unpatch_callback_
  13. #define __KLP_POST_UNPATCH_PREFIX __klp_post_unpatch_callback_
  14. #define KLP_PRE_PATCH_PREFIX __stringify(__KLP_PRE_PATCH_PREFIX)
  15. #define KLP_POST_PATCH_PREFIX __stringify(__KLP_POST_PATCH_PREFIX)
  16. #define KLP_PRE_UNPATCH_PREFIX __stringify(__KLP_PRE_UNPATCH_PREFIX)
  17. #define KLP_POST_UNPATCH_PREFIX __stringify(__KLP_POST_UNPATCH_PREFIX)
  18. struct klp_object;
  19. typedef int (*klp_pre_patch_t)(struct klp_object *obj);
  20. typedef void (*klp_post_patch_t)(struct klp_object *obj);
  21. typedef void (*klp_pre_unpatch_t)(struct klp_object *obj);
  22. typedef void (*klp_post_unpatch_t)(struct klp_object *obj);
  23. /**
  24. * struct klp_callbacks - pre/post live-(un)patch callback structure
  25. * @pre_patch: executed before code patching
  26. * @post_patch: executed after code patching
  27. * @pre_unpatch: executed before code unpatching
  28. * @post_unpatch: executed after code unpatching
  29. * @post_unpatch_enabled: flag indicating if post-unpatch callback
  30. * should run
  31. *
  32. * All callbacks are optional. Only the pre-patch callback, if provided,
  33. * will be unconditionally executed. If the parent klp_object fails to
  34. * patch for any reason, including a non-zero error status returned from
  35. * the pre-patch callback, no further callbacks will be executed.
  36. */
  37. struct klp_callbacks {
  38. klp_pre_patch_t pre_patch;
  39. klp_post_patch_t post_patch;
  40. klp_pre_unpatch_t pre_unpatch;
  41. klp_post_unpatch_t post_unpatch;
  42. bool post_unpatch_enabled;
  43. };
  44. /*
  45. * 'struct klp_{func,object}_ext' are compact "external" representations of
  46. * 'struct klp_{func,object}'. They are used by objtool for livepatch
  47. * generation. The structs are then read by the livepatch module and converted
  48. * to the real structs before calling klp_enable_patch().
  49. *
  50. * TODO make these the official API for klp_enable_patch(). That should
  51. * simplify livepatch's interface as well as its data structure lifetime
  52. * management.
  53. */
  54. struct klp_func_ext {
  55. const char *old_name;
  56. void *new_func;
  57. unsigned long sympos;
  58. };
  59. struct klp_object_ext {
  60. const char *name;
  61. struct klp_func_ext *funcs;
  62. struct klp_callbacks callbacks;
  63. unsigned int nr_funcs;
  64. };
  65. #endif /* _LINUX_LIVEPATCH_EXTERNAL_H_ */