18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Because linux/module.h has tracepoints in the header, and ftrace.h 48c2ecf20Sopenharmony_ci * used to include this file, define_trace.h includes linux/module.h 58c2ecf20Sopenharmony_ci * But we do not want the module.h to override the TRACE_SYSTEM macro 68c2ecf20Sopenharmony_ci * variable that define_trace.h is processing, so we only set it 78c2ecf20Sopenharmony_ci * when module events are being processed, which would happen when 88c2ecf20Sopenharmony_ci * CREATE_TRACE_POINTS is defined. 98c2ecf20Sopenharmony_ci */ 108c2ecf20Sopenharmony_ci#ifdef CREATE_TRACE_POINTS 118c2ecf20Sopenharmony_ci#undef TRACE_SYSTEM 128c2ecf20Sopenharmony_ci#define TRACE_SYSTEM module 138c2ecf20Sopenharmony_ci#endif 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci#if !defined(_TRACE_MODULE_H) || defined(TRACE_HEADER_MULTI_READ) 168c2ecf20Sopenharmony_ci#define _TRACE_MODULE_H 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_ci#include <linux/tracepoint.h> 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_ci#ifdef CONFIG_MODULES 218c2ecf20Sopenharmony_ci 228c2ecf20Sopenharmony_cistruct module; 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci#define show_module_flags(flags) __print_flags(flags, "", \ 258c2ecf20Sopenharmony_ci { (1UL << TAINT_PROPRIETARY_MODULE), "P" }, \ 268c2ecf20Sopenharmony_ci { (1UL << TAINT_OOT_MODULE), "O" }, \ 278c2ecf20Sopenharmony_ci { (1UL << TAINT_FORCED_MODULE), "F" }, \ 288c2ecf20Sopenharmony_ci { (1UL << TAINT_CRAP), "C" }, \ 298c2ecf20Sopenharmony_ci { (1UL << TAINT_UNSIGNED_MODULE), "E" }) 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ciTRACE_EVENT(module_load, 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci TP_PROTO(struct module *mod), 348c2ecf20Sopenharmony_ci 358c2ecf20Sopenharmony_ci TP_ARGS(mod), 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci TP_STRUCT__entry( 388c2ecf20Sopenharmony_ci __field( unsigned int, taints ) 398c2ecf20Sopenharmony_ci __string( name, mod->name ) 408c2ecf20Sopenharmony_ci ), 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci TP_fast_assign( 438c2ecf20Sopenharmony_ci __entry->taints = mod->taints; 448c2ecf20Sopenharmony_ci __assign_str(name, mod->name); 458c2ecf20Sopenharmony_ci ), 468c2ecf20Sopenharmony_ci 478c2ecf20Sopenharmony_ci TP_printk("%s %s", __get_str(name), show_module_flags(__entry->taints)) 488c2ecf20Sopenharmony_ci); 498c2ecf20Sopenharmony_ci 508c2ecf20Sopenharmony_ciTRACE_EVENT(module_free, 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci TP_PROTO(struct module *mod), 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci TP_ARGS(mod), 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci TP_STRUCT__entry( 578c2ecf20Sopenharmony_ci __string( name, mod->name ) 588c2ecf20Sopenharmony_ci ), 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci TP_fast_assign( 618c2ecf20Sopenharmony_ci __assign_str(name, mod->name); 628c2ecf20Sopenharmony_ci ), 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci TP_printk("%s", __get_str(name)) 658c2ecf20Sopenharmony_ci); 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci#ifdef CONFIG_MODULE_UNLOAD 688c2ecf20Sopenharmony_ci/* trace_module_get/put are only used if CONFIG_MODULE_UNLOAD is defined */ 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ciDECLARE_EVENT_CLASS(module_refcnt, 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_ci TP_PROTO(struct module *mod, unsigned long ip), 738c2ecf20Sopenharmony_ci 748c2ecf20Sopenharmony_ci TP_ARGS(mod, ip), 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci TP_STRUCT__entry( 778c2ecf20Sopenharmony_ci __field( unsigned long, ip ) 788c2ecf20Sopenharmony_ci __field( int, refcnt ) 798c2ecf20Sopenharmony_ci __string( name, mod->name ) 808c2ecf20Sopenharmony_ci ), 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci TP_fast_assign( 838c2ecf20Sopenharmony_ci __entry->ip = ip; 848c2ecf20Sopenharmony_ci __entry->refcnt = atomic_read(&mod->refcnt); 858c2ecf20Sopenharmony_ci __assign_str(name, mod->name); 868c2ecf20Sopenharmony_ci ), 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci TP_printk("%s call_site=%ps refcnt=%d", 898c2ecf20Sopenharmony_ci __get_str(name), (void *)__entry->ip, __entry->refcnt) 908c2ecf20Sopenharmony_ci); 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ciDEFINE_EVENT(module_refcnt, module_get, 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci TP_PROTO(struct module *mod, unsigned long ip), 958c2ecf20Sopenharmony_ci 968c2ecf20Sopenharmony_ci TP_ARGS(mod, ip) 978c2ecf20Sopenharmony_ci); 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ciDEFINE_EVENT(module_refcnt, module_put, 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci TP_PROTO(struct module *mod, unsigned long ip), 1028c2ecf20Sopenharmony_ci 1038c2ecf20Sopenharmony_ci TP_ARGS(mod, ip) 1048c2ecf20Sopenharmony_ci); 1058c2ecf20Sopenharmony_ci#endif /* CONFIG_MODULE_UNLOAD */ 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ciTRACE_EVENT(module_request, 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_ci TP_PROTO(char *name, bool wait, unsigned long ip), 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_ci TP_ARGS(name, wait, ip), 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_ci TP_STRUCT__entry( 1148c2ecf20Sopenharmony_ci __field( unsigned long, ip ) 1158c2ecf20Sopenharmony_ci __field( bool, wait ) 1168c2ecf20Sopenharmony_ci __string( name, name ) 1178c2ecf20Sopenharmony_ci ), 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ci TP_fast_assign( 1208c2ecf20Sopenharmony_ci __entry->ip = ip; 1218c2ecf20Sopenharmony_ci __entry->wait = wait; 1228c2ecf20Sopenharmony_ci __assign_str(name, name); 1238c2ecf20Sopenharmony_ci ), 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_ci TP_printk("%s wait=%d call_site=%ps", 1268c2ecf20Sopenharmony_ci __get_str(name), (int)__entry->wait, (void *)__entry->ip) 1278c2ecf20Sopenharmony_ci); 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci#endif /* CONFIG_MODULES */ 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci#endif /* _TRACE_MODULE_H */ 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci/* This part must be outside protection */ 1348c2ecf20Sopenharmony_ci#include <trace/define_trace.h> 135