^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Because linux/module.h has tracepoints in the header, and ftrace.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * used to include this file, define_trace.h includes linux/module.h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * But we do not want the module.h to override the TRACE_SYSTEM macro
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * variable that define_trace.h is processing, so we only set it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * when module events are being processed, which would happen when
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * CREATE_TRACE_POINTS is defined.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #ifdef CREATE_TRACE_POINTS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #undef TRACE_SYSTEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #define TRACE_SYSTEM module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #if !defined(_TRACE_MODULE_H) || defined(TRACE_HEADER_MULTI_READ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define _TRACE_MODULE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/tracepoint.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #ifdef CONFIG_MODULES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) struct module;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define show_module_flags(flags) __print_flags(flags, "", \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) { (1UL << TAINT_PROPRIETARY_MODULE), "P" }, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) { (1UL << TAINT_OOT_MODULE), "O" }, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) { (1UL << TAINT_FORCED_MODULE), "F" }, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) { (1UL << TAINT_CRAP), "C" }, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) { (1UL << TAINT_UNSIGNED_MODULE), "E" })
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) TRACE_EVENT(module_load,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) TP_PROTO(struct module *mod),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) TP_ARGS(mod),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) TP_STRUCT__entry(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) __field( unsigned int, taints )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) __string( name, mod->name )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) TP_fast_assign(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) __entry->taints = mod->taints;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) __assign_str(name, mod->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) TP_printk("%s %s", __get_str(name), show_module_flags(__entry->taints))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) TRACE_EVENT(module_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) TP_PROTO(struct module *mod),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) TP_ARGS(mod),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) TP_STRUCT__entry(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) __string( name, mod->name )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) TP_fast_assign(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) __assign_str(name, mod->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) TP_printk("%s", __get_str(name))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #ifdef CONFIG_MODULE_UNLOAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) /* trace_module_get/put are only used if CONFIG_MODULE_UNLOAD is defined */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) DECLARE_EVENT_CLASS(module_refcnt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) TP_PROTO(struct module *mod, unsigned long ip),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) TP_ARGS(mod, ip),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) TP_STRUCT__entry(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) __field( unsigned long, ip )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) __field( int, refcnt )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) __string( name, mod->name )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) TP_fast_assign(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) __entry->ip = ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) __entry->refcnt = atomic_read(&mod->refcnt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) __assign_str(name, mod->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) TP_printk("%s call_site=%ps refcnt=%d",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) __get_str(name), (void *)__entry->ip, __entry->refcnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) DEFINE_EVENT(module_refcnt, module_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) TP_PROTO(struct module *mod, unsigned long ip),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) TP_ARGS(mod, ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) DEFINE_EVENT(module_refcnt, module_put,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) TP_PROTO(struct module *mod, unsigned long ip),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) TP_ARGS(mod, ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) #endif /* CONFIG_MODULE_UNLOAD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) TRACE_EVENT(module_request,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) TP_PROTO(char *name, bool wait, unsigned long ip),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) TP_ARGS(name, wait, ip),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) TP_STRUCT__entry(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) __field( unsigned long, ip )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) __field( bool, wait )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) __string( name, name )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) TP_fast_assign(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) __entry->ip = ip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) __entry->wait = wait;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) __assign_str(name, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) ),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) TP_printk("%s wait=%d call_site=%ps",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) __get_str(name), (int)__entry->wait, (void *)__entry->ip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) #endif /* CONFIG_MODULES */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) #endif /* _TRACE_MODULE_H */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /* This part must be outside protection */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) #include <trace/define_trace.h>