1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 240cbf09fSAndy Shevchenko /* 340cbf09fSAndy Shevchenko * NOTE: 440cbf09fSAndy Shevchenko * 540cbf09fSAndy Shevchenko * This header has combined a lot of unrelated to each other stuff. 640cbf09fSAndy Shevchenko * The process of splitting its content is in progress while keeping 740cbf09fSAndy Shevchenko * backward compatibility. That's why it's highly recommended NOT to 840cbf09fSAndy Shevchenko * include this header inside another header file, especially under 940cbf09fSAndy Shevchenko * generic or architectural include/ directory. 1040cbf09fSAndy Shevchenko */ 111da177e4SLinus Torvalds #ifndef _LINUX_KERNEL_H 121da177e4SLinus Torvalds #define _LINUX_KERNEL_H 131da177e4SLinus Torvalds 14c0891ac1SAlexey Dobriyan #include <linux/stdarg.h> 1508c5188eSAndy Shevchenko #include <linux/align.h> 163cd39bc3SAlejandro Colomar #include <linux/array_size.h> 1754d50897SMasahiro Yamada #include <linux/limits.h> 181da177e4SLinus Torvalds #include <linux/linkage.h> 191da177e4SLinus Torvalds #include <linux/stddef.h> 201da177e4SLinus Torvalds #include <linux/types.h> 211da177e4SLinus Torvalds #include <linux/compiler.h> 22d2a8ebbfSAndy Shevchenko #include <linux/container_of.h> 231da177e4SLinus Torvalds #include <linux/bitops.h> 24890a3ee3SAndy Shevchenko #include <linux/hex.h> 254c527293SAndy Shevchenko #include <linux/kstrtox.h> 26f0d1b0b3SDavid Howells #include <linux/log2.h> 27aa6159abSAndy Shevchenko #include <linux/math.h> 28b296a6d5SAndy Shevchenko #include <linux/minmax.h> 29e0deaff4SAndrew Morton #include <linux/typecheck.h> 30f39650deSAndy Shevchenko #include <linux/panic.h> 31968ab183SLinus Torvalds #include <linux/printk.h> 32c7acec71SIan Abbott #include <linux/build_bug.h> 3339ced19bSAndy Shevchenko #include <linux/sprintf.h> 34b965f1ddSPeter Zijlstra (Intel) #include <linux/static_call_types.h> 35e52340deSStephen Rothwell #include <linux/instruction_pointer.h> 36*adeb0436SAndy Shevchenko #include <linux/wordpart.h> 37*adeb0436SAndy Shevchenko 381da177e4SLinus Torvalds #include <asm/byteorder.h> 39aa6159abSAndy Shevchenko 40607ca46eSDavid Howells #include <uapi/linux/kernel.h> 411da177e4SLinus Torvalds 421da177e4SLinus Torvalds #define STACK_MAGIC 0xdeadbeef 431da177e4SLinus Torvalds 44d3849953SChristoph Hellwig /* generic data direction definitions */ 45d3849953SChristoph Hellwig #define READ 0 46d3849953SChristoph Hellwig #define WRITE 1 47d3849953SChristoph Hellwig 480ab1438bSMasahiro Yamada #define PTR_IF(cond, ptr) ((cond) ? (ptr) : NULL) 490ab1438bSMasahiro Yamada 503ed605bcSGustavo Padovan #define u64_to_user_ptr(x) ( \ 513ed605bcSGustavo Padovan { \ 52a0fe2c64SJann Horn typecheck(u64, (x)); \ 53a0fe2c64SJann Horn (void __user *)(uintptr_t)(x); \ 543ed605bcSGustavo Padovan } \ 553ed605bcSGustavo Padovan ) 563ed605bcSGustavo Padovan 571da177e4SLinus Torvalds struct completion; 58df2e71fbS[email protected] struct user; 591da177e4SLinus Torvalds 60a8b76910SValentin Schneider #ifdef CONFIG_PREEMPT_VOLUNTARY_BUILD 61b965f1ddSPeter Zijlstra (Intel) 62b965f1ddSPeter Zijlstra (Intel) extern int __cond_resched(void); 63b965f1ddSPeter Zijlstra (Intel) # define might_resched() __cond_resched() 64b965f1ddSPeter Zijlstra (Intel) 6599cf983cSMark Rutland #elif defined(CONFIG_PREEMPT_DYNAMIC) && defined(CONFIG_HAVE_PREEMPT_DYNAMIC_CALL) 66b965f1ddSPeter Zijlstra (Intel) 67b965f1ddSPeter Zijlstra (Intel) extern int __cond_resched(void); 68b965f1ddSPeter Zijlstra (Intel) 69b965f1ddSPeter Zijlstra (Intel) DECLARE_STATIC_CALL(might_resched, __cond_resched); 70b965f1ddSPeter Zijlstra (Intel) 71b965f1ddSPeter Zijlstra (Intel) static __always_inline void might_resched(void) 72b965f1ddSPeter Zijlstra (Intel) { 73ef72661eSPeter Zijlstra static_call_mod(might_resched)(); 74b965f1ddSPeter Zijlstra (Intel) } 75b965f1ddSPeter Zijlstra (Intel) 7699cf983cSMark Rutland #elif defined(CONFIG_PREEMPT_DYNAMIC) && defined(CONFIG_HAVE_PREEMPT_DYNAMIC_KEY) 7799cf983cSMark Rutland 7899cf983cSMark Rutland extern int dynamic_might_resched(void); 7999cf983cSMark Rutland # define might_resched() dynamic_might_resched() 8099cf983cSMark Rutland 81070cb065SUwe Kleine-König #else 82b965f1ddSPeter Zijlstra (Intel) 83070cb065SUwe Kleine-König # define might_resched() do { } while (0) 84b965f1ddSPeter Zijlstra (Intel) 85b965f1ddSPeter Zijlstra (Intel) #endif /* CONFIG_PREEMPT_* */ 86070cb065SUwe Kleine-König 87d902db1eSFrederic Weisbecker #ifdef CONFIG_DEBUG_ATOMIC_SLEEP 8850e081b9SThomas Gleixner extern void __might_resched(const char *file, int line, unsigned int offsets); 8942a38756SThomas Gleixner extern void __might_sleep(const char *file, int line); 90568f1967SPeter Zijlstra extern void __cant_sleep(const char *file, int line, int preempt_offset); 9174d862b6SThomas Gleixner extern void __cant_migrate(const char *file, int line); 92568f1967SPeter Zijlstra 931da177e4SLinus Torvalds /** 941da177e4SLinus Torvalds * might_sleep - annotation for functions that can sleep 951da177e4SLinus Torvalds * 961da177e4SLinus Torvalds * this macro will print a stack trace if it is executed in an atomic 97312364f3SDaniel Vetter * context (spinlock, irq-handler, ...). Additional sections where blocking is 98312364f3SDaniel Vetter * not allowed can be annotated with non_block_start() and non_block_end() 99312364f3SDaniel Vetter * pairs. 1001da177e4SLinus Torvalds * 1011da177e4SLinus Torvalds * This is a useful debugging help to be able to catch problems early and not 102e20ec991SJim Cromie * be bitten later when the calling function happens to sleep when it is not 1031da177e4SLinus Torvalds * supposed to. 1041da177e4SLinus Torvalds */ 105f8cbd99bSIngo Molnar # define might_sleep() \ 10642a38756SThomas Gleixner do { __might_sleep(__FILE__, __LINE__); might_resched(); } while (0) 107568f1967SPeter Zijlstra /** 108568f1967SPeter Zijlstra * cant_sleep - annotation for functions that cannot sleep 109568f1967SPeter Zijlstra * 110568f1967SPeter Zijlstra * this macro will print a stack trace if it is executed with preemption enabled 111568f1967SPeter Zijlstra */ 112568f1967SPeter Zijlstra # define cant_sleep() \ 113568f1967SPeter Zijlstra do { __cant_sleep(__FILE__, __LINE__, 0); } while (0) 11400845eb9SLinus Torvalds # define sched_annotate_sleep() (current->task_state_change = 0) 11574d862b6SThomas Gleixner 11674d862b6SThomas Gleixner /** 11774d862b6SThomas Gleixner * cant_migrate - annotation for functions that cannot migrate 11874d862b6SThomas Gleixner * 11974d862b6SThomas Gleixner * Will print a stack trace if executed in code which is migratable 12074d862b6SThomas Gleixner */ 12174d862b6SThomas Gleixner # define cant_migrate() \ 12274d862b6SThomas Gleixner do { \ 12374d862b6SThomas Gleixner if (IS_ENABLED(CONFIG_SMP)) \ 12474d862b6SThomas Gleixner __cant_migrate(__FILE__, __LINE__); \ 12574d862b6SThomas Gleixner } while (0) 12674d862b6SThomas Gleixner 127312364f3SDaniel Vetter /** 128312364f3SDaniel Vetter * non_block_start - annotate the start of section where sleeping is prohibited 129312364f3SDaniel Vetter * 130312364f3SDaniel Vetter * This is on behalf of the oom reaper, specifically when it is calling the mmu 131312364f3SDaniel Vetter * notifiers. The problem is that if the notifier were to block on, for example, 132312364f3SDaniel Vetter * mutex_lock() and if the process which holds that mutex were to perform a 133312364f3SDaniel Vetter * sleeping memory allocation, the oom reaper is now blocked on completion of 134312364f3SDaniel Vetter * that memory allocation. Other blocking calls like wait_event() pose similar 135312364f3SDaniel Vetter * issues. 136312364f3SDaniel Vetter */ 137312364f3SDaniel Vetter # define non_block_start() (current->non_block_count++) 138312364f3SDaniel Vetter /** 139312364f3SDaniel Vetter * non_block_end - annotate the end of section where sleeping is prohibited 140312364f3SDaniel Vetter * 141312364f3SDaniel Vetter * Closes a section opened by non_block_start(). 142312364f3SDaniel Vetter */ 143312364f3SDaniel Vetter # define non_block_end() WARN_ON(current->non_block_count-- == 0) 144f8cbd99bSIngo Molnar #else 145874f670eSThomas Gleixner static inline void __might_resched(const char *file, int line, 14650e081b9SThomas Gleixner unsigned int offsets) { } 14742a38756SThomas Gleixner static inline void __might_sleep(const char *file, int line) { } 148f8cbd99bSIngo Molnar # define might_sleep() do { might_resched(); } while (0) 149568f1967SPeter Zijlstra # define cant_sleep() do { } while (0) 15074d862b6SThomas Gleixner # define cant_migrate() do { } while (0) 1511029a2b5SPeter Zijlstra # define sched_annotate_sleep() do { } while (0) 152312364f3SDaniel Vetter # define non_block_start() do { } while (0) 153312364f3SDaniel Vetter # define non_block_end() do { } while (0) 154f8cbd99bSIngo Molnar #endif 155f8cbd99bSIngo Molnar 156368a5fa1SHua Zhong #define might_sleep_if(cond) do { if (cond) might_sleep(); } while (0) 157f8cbd99bSIngo Molnar 158386e7906SAxel Lin #if defined(CONFIG_MMU) && \ 159386e7906SAxel Lin (defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_DEBUG_ATOMIC_SLEEP)) 1609ec23531SDavid Hildenbrand #define might_fault() __might_fault(__FILE__, __LINE__) 1619ec23531SDavid Hildenbrand void __might_fault(const char *file, int line); 1623ee1afa3SNick Piggin #else 163662bbcb2SMichael S. Tsirkin static inline void might_fault(void) { } 1643ee1afa3SNick Piggin #endif 1653ee1afa3SNick Piggin 1669af6528eSPeter Zijlstra void do_exit(long error_code) __noreturn; 16733ee3b2eSAlexey Dobriyan 1681da177e4SLinus Torvalds extern int get_option(char **str, int *pint); 1691da177e4SLinus Torvalds extern char *get_options(const char *str, int nints, int *ints); 170d974ae37SJeremy Fitzhardinge extern unsigned long long memparse(const char *ptr, char **retptr); 1716ccc72b8SDave Young extern bool parse_option_str(const char *str, const char *option); 172f51b17c8SBaoquan He extern char *next_arg(char *args, char **param, char **val); 1731da177e4SLinus Torvalds 1745e376613STrent Piepho extern int core_kernel_text(unsigned long addr); 1751da177e4SLinus Torvalds extern int __kernel_text_address(unsigned long addr); 1761da177e4SLinus Torvalds extern int kernel_text_address(unsigned long addr); 177ab7476cfSArjan van de Ven extern int func_ptr_is_kernel_text(void *ptr); 178ab7476cfSArjan van de Ven 1791da177e4SLinus Torvalds extern void bust_spinlocks(int yes); 1805375b708SHATAYAMA Daisuke 181b920de1bSDavid Howells extern int root_mountflags; 1821da177e4SLinus Torvalds 1832ce802f6STejun Heo extern bool early_boot_irqs_disabled; 1842ce802f6STejun Heo 18569a78ff2SThomas Gleixner /* 18669a78ff2SThomas Gleixner * Values used for system_state. Ordering of the states must not be changed 18769a78ff2SThomas Gleixner * as code checks for <, <=, >, >= STATE. 18869a78ff2SThomas Gleixner */ 1891da177e4SLinus Torvalds extern enum system_states { 1901da177e4SLinus Torvalds SYSTEM_BOOTING, 19169a78ff2SThomas Gleixner SYSTEM_SCHEDULING, 192d2635f20SChristophe Leroy SYSTEM_FREEING_INITMEM, 1931da177e4SLinus Torvalds SYSTEM_RUNNING, 1941da177e4SLinus Torvalds SYSTEM_HALT, 1951da177e4SLinus Torvalds SYSTEM_POWER_OFF, 1961da177e4SLinus Torvalds SYSTEM_RESTART, 197c1a957d1SThomas Gleixner SYSTEM_SUSPEND, 1981da177e4SLinus Torvalds } system_state; 1991da177e4SLinus Torvalds 2008a64f336SJoe Perches /* 201526211bcSIngo Molnar * General tracing related utility functions - trace_printk(), 2022002c258SSteven Rostedt * tracing_on/tracing_off and tracing_start()/tracing_stop 2032002c258SSteven Rostedt * 2042002c258SSteven Rostedt * Use tracing_on/tracing_off when you want to quickly turn on or off 2052002c258SSteven Rostedt * tracing. It simply enables or disables the recording of the trace events. 2062455f0e1SRoss Zwisler * This also corresponds to the user space /sys/kernel/tracing/tracing_on 2072002c258SSteven Rostedt * file, which gives a means for the kernel and userspace to interact. 2082002c258SSteven Rostedt * Place a tracing_off() in the kernel where you want tracing to end. 2092002c258SSteven Rostedt * From user space, examine the trace, and then echo 1 > tracing_on 2102002c258SSteven Rostedt * to continue tracing. 2112002c258SSteven Rostedt * 2122002c258SSteven Rostedt * tracing_stop/tracing_start has slightly more overhead. It is used 2132002c258SSteven Rostedt * by things like suspend to ram where disabling the recording of the 2142002c258SSteven Rostedt * trace is not enough, but tracing must actually stop because things 2152002c258SSteven Rostedt * like calling smp_processor_id() may crash the system. 2162002c258SSteven Rostedt * 2172002c258SSteven Rostedt * Most likely, you want to use tracing_on/tracing_off. 218526211bcSIngo Molnar */ 219cecbca96SFrederic Weisbecker 220cecbca96SFrederic Weisbecker enum ftrace_dump_mode { 221cecbca96SFrederic Weisbecker DUMP_NONE, 222cecbca96SFrederic Weisbecker DUMP_ALL, 223cecbca96SFrederic Weisbecker DUMP_ORIG, 224cecbca96SFrederic Weisbecker }; 225cecbca96SFrederic Weisbecker 226526211bcSIngo Molnar #ifdef CONFIG_TRACING 22793d68e52SSteven Rostedt void tracing_on(void); 22893d68e52SSteven Rostedt void tracing_off(void); 22993d68e52SSteven Rostedt int tracing_is_on(void); 230ad909e21SSteven Rostedt (Red Hat) void tracing_snapshot(void); 231ad909e21SSteven Rostedt (Red Hat) void tracing_snapshot_alloc(void); 23293d68e52SSteven Rostedt 233526211bcSIngo Molnar extern void tracing_start(void); 234526211bcSIngo Molnar extern void tracing_stop(void); 235526211bcSIngo Molnar 236b9075fa9SJoe Perches static inline __printf(1, 2) 237b9075fa9SJoe Perches void ____trace_printk_check_format(const char *fmt, ...) 238769b0441SFrederic Weisbecker { 239769b0441SFrederic Weisbecker } 240769b0441SFrederic Weisbecker #define __trace_printk_check_format(fmt, args...) \ 241769b0441SFrederic Weisbecker do { \ 242769b0441SFrederic Weisbecker if (0) \ 243769b0441SFrederic Weisbecker ____trace_printk_check_format(fmt, ##args); \ 244769b0441SFrederic Weisbecker } while (0) 245769b0441SFrederic Weisbecker 246526211bcSIngo Molnar /** 247526211bcSIngo Molnar * trace_printk - printf formatting in the ftrace buffer 248526211bcSIngo Molnar * @fmt: the printf format for printing 249526211bcSIngo Molnar * 250e8c97af0SRandy Dunlap * Note: __trace_printk is an internal function for trace_printk() and 251e8c97af0SRandy Dunlap * the @ip is passed in via the trace_printk() macro. 252526211bcSIngo Molnar * 253526211bcSIngo Molnar * This function allows a kernel developer to debug fast path sections 254526211bcSIngo Molnar * that printk is not appropriate for. By scattering in various 255526211bcSIngo Molnar * printk like tracing in the code, a developer can quickly see 256526211bcSIngo Molnar * where problems are occurring. 257526211bcSIngo Molnar * 258526211bcSIngo Molnar * This is intended as a debugging tool for the developer only. 259526211bcSIngo Molnar * Please refrain from leaving trace_printks scattered around in 26009ae7234SSteven Rostedt (Red Hat) * your code. (Extra memory is used for special buffers that are 261e8c97af0SRandy Dunlap * allocated when trace_printk() is used.) 2629d3c752cSSteven Rostedt (Red Hat) * 2638730662dSWei Wang * A little optimization trick is done here. If there's only one 2649d3c752cSSteven Rostedt (Red Hat) * argument, there's no need to scan the string for printf formats. 2659d3c752cSSteven Rostedt (Red Hat) * The trace_puts() will suffice. But how can we take advantage of 2669d3c752cSSteven Rostedt (Red Hat) * using trace_puts() when trace_printk() has only one argument? 2679d3c752cSSteven Rostedt (Red Hat) * By stringifying the args and checking the size we can tell 2689d3c752cSSteven Rostedt (Red Hat) * whether or not there are args. __stringify((__VA_ARGS__)) will 2699d3c752cSSteven Rostedt (Red Hat) * turn into "()\0" with a size of 3 when there are no args, anything 2709d3c752cSSteven Rostedt (Red Hat) * else will be bigger. All we need to do is define a string to this, 2719d3c752cSSteven Rostedt (Red Hat) * and then take its size and compare to 3. If it's bigger, use 2729d3c752cSSteven Rostedt (Red Hat) * do_trace_printk() otherwise, optimize it to trace_puts(). Then just 2739d3c752cSSteven Rostedt (Red Hat) * let gcc optimize the rest. 274526211bcSIngo Molnar */ 275769b0441SFrederic Weisbecker 2769d3c752cSSteven Rostedt (Red Hat) #define trace_printk(fmt, ...) \ 2779d3c752cSSteven Rostedt (Red Hat) do { \ 2789d3c752cSSteven Rostedt (Red Hat) char _______STR[] = __stringify((__VA_ARGS__)); \ 2799d3c752cSSteven Rostedt (Red Hat) if (sizeof(_______STR) > 3) \ 2809d3c752cSSteven Rostedt (Red Hat) do_trace_printk(fmt, ##__VA_ARGS__); \ 2819d3c752cSSteven Rostedt (Red Hat) else \ 2829d3c752cSSteven Rostedt (Red Hat) trace_puts(fmt); \ 2839d3c752cSSteven Rostedt (Red Hat) } while (0) 2849d3c752cSSteven Rostedt (Red Hat) 2859d3c752cSSteven Rostedt (Red Hat) #define do_trace_printk(fmt, args...) \ 286769b0441SFrederic Weisbecker do { \ 2873debb0a9SSteven Rostedt (Red Hat) static const char *trace_printk_fmt __used \ 28833def849SJoe Perches __section("__trace_printk_fmt") = \ 28948ead020SFrederic Weisbecker __builtin_constant_p(fmt) ? fmt : NULL; \ 29048ead020SFrederic Weisbecker \ 29107d777feSSteven Rostedt __trace_printk_check_format(fmt, ##args); \ 29207d777feSSteven Rostedt \ 29307d777feSSteven Rostedt if (__builtin_constant_p(fmt)) \ 29448ead020SFrederic Weisbecker __trace_bprintk(_THIS_IP_, trace_printk_fmt, ##args); \ 29507d777feSSteven Rostedt else \ 29648ead020SFrederic Weisbecker __trace_printk(_THIS_IP_, fmt, ##args); \ 297769b0441SFrederic Weisbecker } while (0) 298769b0441SFrederic Weisbecker 299b9075fa9SJoe Perches extern __printf(2, 3) 300b9075fa9SJoe Perches int __trace_bprintk(unsigned long ip, const char *fmt, ...); 30148ead020SFrederic Weisbecker 302b9075fa9SJoe Perches extern __printf(2, 3) 303b9075fa9SJoe Perches int __trace_printk(unsigned long ip, const char *fmt, ...); 304769b0441SFrederic Weisbecker 30509ae7234SSteven Rostedt (Red Hat) /** 30609ae7234SSteven Rostedt (Red Hat) * trace_puts - write a string into the ftrace buffer 30709ae7234SSteven Rostedt (Red Hat) * @str: the string to record 30809ae7234SSteven Rostedt (Red Hat) * 30909ae7234SSteven Rostedt (Red Hat) * Note: __trace_bputs is an internal function for trace_puts and 31009ae7234SSteven Rostedt (Red Hat) * the @ip is passed in via the trace_puts macro. 31109ae7234SSteven Rostedt (Red Hat) * 31209ae7234SSteven Rostedt (Red Hat) * This is similar to trace_printk() but is made for those really fast 313e8c97af0SRandy Dunlap * paths that a developer wants the least amount of "Heisenbug" effects, 31409ae7234SSteven Rostedt (Red Hat) * where the processing of the print format is still too much. 31509ae7234SSteven Rostedt (Red Hat) * 31609ae7234SSteven Rostedt (Red Hat) * This function allows a kernel developer to debug fast path sections 31709ae7234SSteven Rostedt (Red Hat) * that printk is not appropriate for. By scattering in various 31809ae7234SSteven Rostedt (Red Hat) * printk like tracing in the code, a developer can quickly see 31909ae7234SSteven Rostedt (Red Hat) * where problems are occurring. 32009ae7234SSteven Rostedt (Red Hat) * 32109ae7234SSteven Rostedt (Red Hat) * This is intended as a debugging tool for the developer only. 32209ae7234SSteven Rostedt (Red Hat) * Please refrain from leaving trace_puts scattered around in 32309ae7234SSteven Rostedt (Red Hat) * your code. (Extra memory is used for special buffers that are 324e8c97af0SRandy Dunlap * allocated when trace_puts() is used.) 32509ae7234SSteven Rostedt (Red Hat) * 32609ae7234SSteven Rostedt (Red Hat) * Returns: 0 if nothing was written, positive # if string was. 32709ae7234SSteven Rostedt (Red Hat) * (1 when __trace_bputs is used, strlen(str) when __trace_puts is used) 32809ae7234SSteven Rostedt (Red Hat) */ 32909ae7234SSteven Rostedt (Red Hat) 33009ae7234SSteven Rostedt (Red Hat) #define trace_puts(str) ({ \ 3313debb0a9SSteven Rostedt (Red Hat) static const char *trace_printk_fmt __used \ 33233def849SJoe Perches __section("__trace_printk_fmt") = \ 33309ae7234SSteven Rostedt (Red Hat) __builtin_constant_p(str) ? str : NULL; \ 33409ae7234SSteven Rostedt (Red Hat) \ 33509ae7234SSteven Rostedt (Red Hat) if (__builtin_constant_p(str)) \ 33609ae7234SSteven Rostedt (Red Hat) __trace_bputs(_THIS_IP_, trace_printk_fmt); \ 33709ae7234SSteven Rostedt (Red Hat) else \ 33809ae7234SSteven Rostedt (Red Hat) __trace_puts(_THIS_IP_, str, strlen(str)); \ 33909ae7234SSteven Rostedt (Red Hat) }) 340bcf312cfSSteven Rostedt extern int __trace_bputs(unsigned long ip, const char *str); 341bcf312cfSSteven Rostedt extern int __trace_puts(unsigned long ip, const char *str, int size); 34209ae7234SSteven Rostedt (Red Hat) 343c142be8eSSteven Rostedt (Red Hat) extern void trace_dump_stack(int skip); 34403889384SSteven Rostedt 34548ead020SFrederic Weisbecker /* 34648ead020SFrederic Weisbecker * The double __builtin_constant_p is because gcc will give us an error 34748ead020SFrederic Weisbecker * if we try to allocate the static variable to fmt if it is not a 34848ead020SFrederic Weisbecker * constant. Even with the outer if statement. 34948ead020SFrederic Weisbecker */ 350769b0441SFrederic Weisbecker #define ftrace_vprintk(fmt, vargs) \ 351769b0441SFrederic Weisbecker do { \ 35248ead020SFrederic Weisbecker if (__builtin_constant_p(fmt)) { \ 3533debb0a9SSteven Rostedt (Red Hat) static const char *trace_printk_fmt __used \ 35433def849SJoe Perches __section("__trace_printk_fmt") = \ 35548ead020SFrederic Weisbecker __builtin_constant_p(fmt) ? fmt : NULL; \ 3567bffc23eSIngo Molnar \ 35748ead020SFrederic Weisbecker __ftrace_vbprintk(_THIS_IP_, trace_printk_fmt, vargs); \ 35848ead020SFrederic Weisbecker } else \ 35948ead020SFrederic Weisbecker __ftrace_vprintk(_THIS_IP_, fmt, vargs); \ 360769b0441SFrederic Weisbecker } while (0) 361769b0441SFrederic Weisbecker 3628db14860SNicolas Iooss extern __printf(2, 0) int 36348ead020SFrederic Weisbecker __ftrace_vbprintk(unsigned long ip, const char *fmt, va_list ap); 36448ead020SFrederic Weisbecker 3658db14860SNicolas Iooss extern __printf(2, 0) int 366526211bcSIngo Molnar __ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap); 367769b0441SFrederic Weisbecker 368cecbca96SFrederic Weisbecker extern void ftrace_dump(enum ftrace_dump_mode oops_dump_mode); 369526211bcSIngo Molnar #else 370526211bcSIngo Molnar static inline void tracing_start(void) { } 371526211bcSIngo Molnar static inline void tracing_stop(void) { } 372e67bc51eSDhaval Giani static inline void trace_dump_stack(int skip) { } 37393d68e52SSteven Rostedt 37493d68e52SSteven Rostedt static inline void tracing_on(void) { } 37593d68e52SSteven Rostedt static inline void tracing_off(void) { } 37693d68e52SSteven Rostedt static inline int tracing_is_on(void) { return 0; } 377ad909e21SSteven Rostedt (Red Hat) static inline void tracing_snapshot(void) { } 378ad909e21SSteven Rostedt (Red Hat) static inline void tracing_snapshot_alloc(void) { } 37993d68e52SSteven Rostedt 38060efc15aSMichal Hocko static inline __printf(1, 2) 38160efc15aSMichal Hocko int trace_printk(const char *fmt, ...) 382526211bcSIngo Molnar { 383526211bcSIngo Molnar return 0; 384526211bcSIngo Molnar } 3858db14860SNicolas Iooss static __printf(1, 0) inline int 386526211bcSIngo Molnar ftrace_vprintk(const char *fmt, va_list ap) 387526211bcSIngo Molnar { 388526211bcSIngo Molnar return 0; 389526211bcSIngo Molnar } 390cecbca96SFrederic Weisbecker static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { } 391769b0441SFrederic Weisbecker #endif /* CONFIG_TRACING */ 392526211bcSIngo Molnar 393b9d4f426SArnaud Lacombe /* Rebuild everything on CONFIG_FTRACE_MCOUNT_RECORD */ 394b9d4f426SArnaud Lacombe #ifdef CONFIG_FTRACE_MCOUNT_RECORD 395b9d4f426SArnaud Lacombe # define REBUILD_DUE_TO_FTRACE_MCOUNT_RECORD 396b9d4f426SArnaud Lacombe #endif 3979d00f92fSWANG Cong 39858f86cc8SRusty Russell /* Permissions on a sysfs file: you didn't miss the 0 prefix did you? */ 39958f86cc8SRusty Russell #define VERIFY_OCTAL_PERMISSIONS(perms) \ 40058f86cc8SRusty Russell (BUILD_BUG_ON_ZERO((perms) < 0) + \ 40158f86cc8SRusty Russell BUILD_BUG_ON_ZERO((perms) > 0777) + \ 40228b8d0c8SGobinda Charan Maji /* USER_READABLE >= GROUP_READABLE >= OTHER_READABLE */ \ 40328b8d0c8SGobinda Charan Maji BUILD_BUG_ON_ZERO((((perms) >> 6) & 4) < (((perms) >> 3) & 4)) + \ 40428b8d0c8SGobinda Charan Maji BUILD_BUG_ON_ZERO((((perms) >> 3) & 4) < ((perms) & 4)) + \ 40528b8d0c8SGobinda Charan Maji /* USER_WRITABLE >= GROUP_WRITABLE */ \ 40628b8d0c8SGobinda Charan Maji BUILD_BUG_ON_ZERO((((perms) >> 6) & 2) < (((perms) >> 3) & 2)) + \ 40728b8d0c8SGobinda Charan Maji /* OTHER_WRITABLE? Generally considered a bad idea. */ \ 40837549e94SRusty Russell BUILD_BUG_ON_ZERO((perms) & 2) + \ 40958f86cc8SRusty Russell (perms)) 4101da177e4SLinus Torvalds #endif 411