1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 2c94fbe1dSSteven Rostedt /* 3c94fbe1dSSteven Rostedt * Because linux/module.h has tracepoints in the header, and ftrace.h 4de477254SPaul Gortmaker * used to include this file, define_trace.h includes linux/module.h 5c94fbe1dSSteven Rostedt * But we do not want the module.h to override the TRACE_SYSTEM macro 6c94fbe1dSSteven Rostedt * variable that define_trace.h is processing, so we only set it 7c94fbe1dSSteven Rostedt * when module events are being processed, which would happen when 8c94fbe1dSSteven Rostedt * CREATE_TRACE_POINTS is defined. 9c94fbe1dSSteven Rostedt */ 10c94fbe1dSSteven Rostedt #ifdef CREATE_TRACE_POINTS 117ead8b83SLi Zefan #undef TRACE_SYSTEM 127ead8b83SLi Zefan #define TRACE_SYSTEM module 13c94fbe1dSSteven Rostedt #endif 147ead8b83SLi Zefan 157ead8b83SLi Zefan #if !defined(_TRACE_MODULE_H) || defined(TRACE_HEADER_MULTI_READ) 167ead8b83SLi Zefan #define _TRACE_MODULE_H 177ead8b83SLi Zefan 187ead8b83SLi Zefan #include <linux/tracepoint.h> 197ead8b83SLi Zefan 207ead8b83SLi Zefan #ifdef CONFIG_MODULES 217ead8b83SLi Zefan 227ead8b83SLi Zefan struct module; 237ead8b83SLi Zefan 247ead8b83SLi Zefan #define show_module_flags(flags) __print_flags(flags, "", \ 257ead8b83SLi Zefan { (1UL << TAINT_PROPRIETARY_MODULE), "P" }, \ 2666cc69e3SMathieu Desnoyers { (1UL << TAINT_OOT_MODULE), "O" }, \ 277ead8b83SLi Zefan { (1UL << TAINT_FORCED_MODULE), "F" }, \ 2866cc69e3SMathieu Desnoyers { (1UL << TAINT_CRAP), "C" }, \ 29132e9a68SMathieu Desnoyers { (1UL << TAINT_UNSIGNED_MODULE), "E" }) 307ead8b83SLi Zefan 317ead8b83SLi Zefan TRACE_EVENT(module_load, 327ead8b83SLi Zefan 337ead8b83SLi Zefan TP_PROTO(struct module *mod), 347ead8b83SLi Zefan 357ead8b83SLi Zefan TP_ARGS(mod), 367ead8b83SLi Zefan 377ead8b83SLi Zefan TP_STRUCT__entry( 387ead8b83SLi Zefan __field( unsigned int, taints ) 397ead8b83SLi Zefan __string( name, mod->name ) 407ead8b83SLi Zefan ), 417ead8b83SLi Zefan 427ead8b83SLi Zefan TP_fast_assign( 437ead8b83SLi Zefan __entry->taints = mod->taints; 447ead8b83SLi Zefan __assign_str(name, mod->name); 457ead8b83SLi Zefan ), 467ead8b83SLi Zefan 477ead8b83SLi Zefan TP_printk("%s %s", __get_str(name), show_module_flags(__entry->taints)) 487ead8b83SLi Zefan ); 497ead8b83SLi Zefan 507ead8b83SLi Zefan TRACE_EVENT(module_free, 517ead8b83SLi Zefan 527ead8b83SLi Zefan TP_PROTO(struct module *mod), 537ead8b83SLi Zefan 547ead8b83SLi Zefan TP_ARGS(mod), 557ead8b83SLi Zefan 567ead8b83SLi Zefan TP_STRUCT__entry( 577ead8b83SLi Zefan __string( name, mod->name ) 587ead8b83SLi Zefan ), 597ead8b83SLi Zefan 607ead8b83SLi Zefan TP_fast_assign( 617ead8b83SLi Zefan __assign_str(name, mod->name); 627ead8b83SLi Zefan ), 637ead8b83SLi Zefan 647ead8b83SLi Zefan TP_printk("%s", __get_str(name)) 657ead8b83SLi Zefan ); 667ead8b83SLi Zefan 67eb0c5377SSteven Rostedt #ifdef CONFIG_MODULE_UNLOAD 68eb0c5377SSteven Rostedt /* trace_module_get/put are only used if CONFIG_MODULE_UNLOAD is defined */ 69eb0c5377SSteven Rostedt 70925684d6SLi Zefan DECLARE_EVENT_CLASS(module_refcnt, 717ead8b83SLi Zefan 72ae832d1eSLi Zefan TP_PROTO(struct module *mod, unsigned long ip), 737ead8b83SLi Zefan 74ae832d1eSLi Zefan TP_ARGS(mod, ip), 757ead8b83SLi Zefan 767ead8b83SLi Zefan TP_STRUCT__entry( 777ead8b83SLi Zefan __field( unsigned long, ip ) 787ead8b83SLi Zefan __field( int, refcnt ) 797ead8b83SLi Zefan __string( name, mod->name ) 807ead8b83SLi Zefan ), 817ead8b83SLi Zefan 827ead8b83SLi Zefan TP_fast_assign( 837ead8b83SLi Zefan __entry->ip = ip; 842f35c41fSMasami Hiramatsu __entry->refcnt = atomic_read(&mod->refcnt); 857ead8b83SLi Zefan __assign_str(name, mod->name); 867ead8b83SLi Zefan ), 877ead8b83SLi Zefan 88bbedb179SScott Wood TP_printk("%s call_site=%ps refcnt=%d", 897ead8b83SLi Zefan __get_str(name), (void *)__entry->ip, __entry->refcnt) 907ead8b83SLi Zefan ); 917ead8b83SLi Zefan 92925684d6SLi Zefan DEFINE_EVENT(module_refcnt, module_get, 937ead8b83SLi Zefan 94ae832d1eSLi Zefan TP_PROTO(struct module *mod, unsigned long ip), 957ead8b83SLi Zefan 96ae832d1eSLi Zefan TP_ARGS(mod, ip) 97925684d6SLi Zefan ); 987ead8b83SLi Zefan 99925684d6SLi Zefan DEFINE_EVENT(module_refcnt, module_put, 1007ead8b83SLi Zefan 101ae832d1eSLi Zefan TP_PROTO(struct module *mod, unsigned long ip), 1027ead8b83SLi Zefan 103ae832d1eSLi Zefan TP_ARGS(mod, ip) 1047ead8b83SLi Zefan ); 105eb0c5377SSteven Rostedt #endif /* CONFIG_MODULE_UNLOAD */ 1067ead8b83SLi Zefan 1077ead8b83SLi Zefan TRACE_EVENT(module_request, 1087ead8b83SLi Zefan 1097ead8b83SLi Zefan TP_PROTO(char *name, bool wait, unsigned long ip), 1107ead8b83SLi Zefan 1117ead8b83SLi Zefan TP_ARGS(name, wait, ip), 1127ead8b83SLi Zefan 1137ead8b83SLi Zefan TP_STRUCT__entry( 1147ead8b83SLi Zefan __field( unsigned long, ip ) 115b5e3008eSDavid Sharp __field( bool, wait ) 1167ead8b83SLi Zefan __string( name, name ) 1177ead8b83SLi Zefan ), 1187ead8b83SLi Zefan 1197ead8b83SLi Zefan TP_fast_assign( 1207ead8b83SLi Zefan __entry->ip = ip; 121b5e3008eSDavid Sharp __entry->wait = wait; 1227ead8b83SLi Zefan __assign_str(name, name); 1237ead8b83SLi Zefan ), 1247ead8b83SLi Zefan 125bbedb179SScott Wood TP_printk("%s wait=%d call_site=%ps", 1267ead8b83SLi Zefan __get_str(name), (int)__entry->wait, (void *)__entry->ip) 1277ead8b83SLi Zefan ); 1287ead8b83SLi Zefan 1297ead8b83SLi Zefan #endif /* CONFIG_MODULES */ 1307ead8b83SLi Zefan 1317ead8b83SLi Zefan #endif /* _TRACE_MODULE_H */ 1327ead8b83SLi Zefan 1337ead8b83SLi Zefan /* This part must be outside protection */ 1347ead8b83SLi Zefan #include <trace/define_trace.h> 135