xref: /linux-6.15/include/linux/kernel.h (revision 19f0423f)
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>
36adeb0436SAndy Shevchenko #include <linux/wordpart.h>
37adeb0436SAndy 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) 
might_resched(void)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
__might_resched(const char * file,int line,unsigned int offsets)145874f670eSThomas Gleixner   static inline void __might_resched(const char *file, int line,
14650e081b9SThomas Gleixner 				     unsigned int offsets) { }
__might_sleep(const char * file,int line)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
might_fault(void)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 
1685e376613STrent Piepho extern int core_kernel_text(unsigned long addr);
1691da177e4SLinus Torvalds extern int __kernel_text_address(unsigned long addr);
1701da177e4SLinus Torvalds extern int kernel_text_address(unsigned long addr);
171ab7476cfSArjan van de Ven extern int func_ptr_is_kernel_text(void *ptr);
172ab7476cfSArjan van de Ven 
1731da177e4SLinus Torvalds extern void bust_spinlocks(int yes);
1745375b708SHATAYAMA Daisuke 
175b920de1bSDavid Howells extern int root_mountflags;
1761da177e4SLinus Torvalds 
1772ce802f6STejun Heo extern bool early_boot_irqs_disabled;
1782ce802f6STejun Heo 
17969a78ff2SThomas Gleixner /*
18069a78ff2SThomas Gleixner  * Values used for system_state. Ordering of the states must not be changed
18169a78ff2SThomas Gleixner  * as code checks for <, <=, >, >= STATE.
18269a78ff2SThomas Gleixner  */
1831da177e4SLinus Torvalds extern enum system_states {
1841da177e4SLinus Torvalds 	SYSTEM_BOOTING,
18569a78ff2SThomas Gleixner 	SYSTEM_SCHEDULING,
186d2635f20SChristophe Leroy 	SYSTEM_FREEING_INITMEM,
1871da177e4SLinus Torvalds 	SYSTEM_RUNNING,
1881da177e4SLinus Torvalds 	SYSTEM_HALT,
1891da177e4SLinus Torvalds 	SYSTEM_POWER_OFF,
1901da177e4SLinus Torvalds 	SYSTEM_RESTART,
191c1a957d1SThomas Gleixner 	SYSTEM_SUSPEND,
1921da177e4SLinus Torvalds } system_state;
1931da177e4SLinus Torvalds 
1948a64f336SJoe Perches /*
195526211bcSIngo Molnar  * General tracing related utility functions - trace_printk(),
1962002c258SSteven Rostedt  * tracing_on/tracing_off and tracing_start()/tracing_stop
1972002c258SSteven Rostedt  *
1982002c258SSteven Rostedt  * Use tracing_on/tracing_off when you want to quickly turn on or off
1992002c258SSteven Rostedt  * tracing. It simply enables or disables the recording of the trace events.
2002455f0e1SRoss Zwisler  * This also corresponds to the user space /sys/kernel/tracing/tracing_on
2012002c258SSteven Rostedt  * file, which gives a means for the kernel and userspace to interact.
2022002c258SSteven Rostedt  * Place a tracing_off() in the kernel where you want tracing to end.
2032002c258SSteven Rostedt  * From user space, examine the trace, and then echo 1 > tracing_on
2042002c258SSteven Rostedt  * to continue tracing.
2052002c258SSteven Rostedt  *
2062002c258SSteven Rostedt  * tracing_stop/tracing_start has slightly more overhead. It is used
2072002c258SSteven Rostedt  * by things like suspend to ram where disabling the recording of the
2082002c258SSteven Rostedt  * trace is not enough, but tracing must actually stop because things
2092002c258SSteven Rostedt  * like calling smp_processor_id() may crash the system.
2102002c258SSteven Rostedt  *
2112002c258SSteven Rostedt  * Most likely, you want to use tracing_on/tracing_off.
212526211bcSIngo Molnar  */
213cecbca96SFrederic Weisbecker 
214cecbca96SFrederic Weisbecker enum ftrace_dump_mode {
215cecbca96SFrederic Weisbecker 	DUMP_NONE,
216cecbca96SFrederic Weisbecker 	DUMP_ALL,
217cecbca96SFrederic Weisbecker 	DUMP_ORIG,
218*19f0423fSHuang Yiwei 	DUMP_PARAM,
219cecbca96SFrederic Weisbecker };
220cecbca96SFrederic Weisbecker 
221526211bcSIngo Molnar #ifdef CONFIG_TRACING
22293d68e52SSteven Rostedt void tracing_on(void);
22393d68e52SSteven Rostedt void tracing_off(void);
22493d68e52SSteven Rostedt int tracing_is_on(void);
225ad909e21SSteven Rostedt (Red Hat) void tracing_snapshot(void);
226ad909e21SSteven Rostedt (Red Hat) void tracing_snapshot_alloc(void);
22793d68e52SSteven Rostedt 
228526211bcSIngo Molnar extern void tracing_start(void);
229526211bcSIngo Molnar extern void tracing_stop(void);
230526211bcSIngo Molnar 
231b9075fa9SJoe Perches static inline __printf(1, 2)
____trace_printk_check_format(const char * fmt,...)232b9075fa9SJoe Perches void ____trace_printk_check_format(const char *fmt, ...)
233769b0441SFrederic Weisbecker {
234769b0441SFrederic Weisbecker }
235769b0441SFrederic Weisbecker #define __trace_printk_check_format(fmt, args...)			\
236769b0441SFrederic Weisbecker do {									\
237769b0441SFrederic Weisbecker 	if (0)								\
238769b0441SFrederic Weisbecker 		____trace_printk_check_format(fmt, ##args);		\
239769b0441SFrederic Weisbecker } while (0)
240769b0441SFrederic Weisbecker 
241526211bcSIngo Molnar /**
242526211bcSIngo Molnar  * trace_printk - printf formatting in the ftrace buffer
243526211bcSIngo Molnar  * @fmt: the printf format for printing
244526211bcSIngo Molnar  *
245e8c97af0SRandy Dunlap  * Note: __trace_printk is an internal function for trace_printk() and
246e8c97af0SRandy Dunlap  *       the @ip is passed in via the trace_printk() macro.
247526211bcSIngo Molnar  *
248526211bcSIngo Molnar  * This function allows a kernel developer to debug fast path sections
249526211bcSIngo Molnar  * that printk is not appropriate for. By scattering in various
250526211bcSIngo Molnar  * printk like tracing in the code, a developer can quickly see
251526211bcSIngo Molnar  * where problems are occurring.
252526211bcSIngo Molnar  *
253526211bcSIngo Molnar  * This is intended as a debugging tool for the developer only.
254526211bcSIngo Molnar  * Please refrain from leaving trace_printks scattered around in
25509ae7234SSteven Rostedt (Red Hat)  * your code. (Extra memory is used for special buffers that are
256e8c97af0SRandy Dunlap  * allocated when trace_printk() is used.)
2579d3c752cSSteven Rostedt (Red Hat)  *
2588730662dSWei Wang  * A little optimization trick is done here. If there's only one
2599d3c752cSSteven Rostedt (Red Hat)  * argument, there's no need to scan the string for printf formats.
2609d3c752cSSteven Rostedt (Red Hat)  * The trace_puts() will suffice. But how can we take advantage of
2619d3c752cSSteven Rostedt (Red Hat)  * using trace_puts() when trace_printk() has only one argument?
2629d3c752cSSteven Rostedt (Red Hat)  * By stringifying the args and checking the size we can tell
2639d3c752cSSteven Rostedt (Red Hat)  * whether or not there are args. __stringify((__VA_ARGS__)) will
2649d3c752cSSteven Rostedt (Red Hat)  * turn into "()\0" with a size of 3 when there are no args, anything
2659d3c752cSSteven Rostedt (Red Hat)  * else will be bigger. All we need to do is define a string to this,
2669d3c752cSSteven Rostedt (Red Hat)  * and then take its size and compare to 3. If it's bigger, use
2679d3c752cSSteven Rostedt (Red Hat)  * do_trace_printk() otherwise, optimize it to trace_puts(). Then just
2689d3c752cSSteven Rostedt (Red Hat)  * let gcc optimize the rest.
269526211bcSIngo Molnar  */
270769b0441SFrederic Weisbecker 
2719d3c752cSSteven Rostedt (Red Hat) #define trace_printk(fmt, ...)				\
2729d3c752cSSteven Rostedt (Red Hat) do {							\
2739d3c752cSSteven Rostedt (Red Hat) 	char _______STR[] = __stringify((__VA_ARGS__));	\
2749d3c752cSSteven Rostedt (Red Hat) 	if (sizeof(_______STR) > 3)			\
2759d3c752cSSteven Rostedt (Red Hat) 		do_trace_printk(fmt, ##__VA_ARGS__);	\
2769d3c752cSSteven Rostedt (Red Hat) 	else						\
2779d3c752cSSteven Rostedt (Red Hat) 		trace_puts(fmt);			\
2789d3c752cSSteven Rostedt (Red Hat) } while (0)
2799d3c752cSSteven Rostedt (Red Hat) 
2809d3c752cSSteven Rostedt (Red Hat) #define do_trace_printk(fmt, args...)					\
281769b0441SFrederic Weisbecker do {									\
2823debb0a9SSteven Rostedt (Red Hat) 	static const char *trace_printk_fmt __used			\
28333def849SJoe Perches 		__section("__trace_printk_fmt") =			\
28448ead020SFrederic Weisbecker 		__builtin_constant_p(fmt) ? fmt : NULL;			\
28548ead020SFrederic Weisbecker 									\
28607d777feSSteven Rostedt 	__trace_printk_check_format(fmt, ##args);			\
28707d777feSSteven Rostedt 									\
28807d777feSSteven Rostedt 	if (__builtin_constant_p(fmt))					\
28948ead020SFrederic Weisbecker 		__trace_bprintk(_THIS_IP_, trace_printk_fmt, ##args);	\
29007d777feSSteven Rostedt 	else								\
29148ead020SFrederic Weisbecker 		__trace_printk(_THIS_IP_, fmt, ##args);			\
292769b0441SFrederic Weisbecker } while (0)
293769b0441SFrederic Weisbecker 
294b9075fa9SJoe Perches extern __printf(2, 3)
295b9075fa9SJoe Perches int __trace_bprintk(unsigned long ip, const char *fmt, ...);
29648ead020SFrederic Weisbecker 
297b9075fa9SJoe Perches extern __printf(2, 3)
298b9075fa9SJoe Perches int __trace_printk(unsigned long ip, const char *fmt, ...);
299769b0441SFrederic Weisbecker 
30009ae7234SSteven Rostedt (Red Hat) /**
30109ae7234SSteven Rostedt (Red Hat)  * trace_puts - write a string into the ftrace buffer
30209ae7234SSteven Rostedt (Red Hat)  * @str: the string to record
30309ae7234SSteven Rostedt (Red Hat)  *
30409ae7234SSteven Rostedt (Red Hat)  * Note: __trace_bputs is an internal function for trace_puts and
30509ae7234SSteven Rostedt (Red Hat)  *       the @ip is passed in via the trace_puts macro.
30609ae7234SSteven Rostedt (Red Hat)  *
30709ae7234SSteven Rostedt (Red Hat)  * This is similar to trace_printk() but is made for those really fast
308e8c97af0SRandy Dunlap  * paths that a developer wants the least amount of "Heisenbug" effects,
30909ae7234SSteven Rostedt (Red Hat)  * where the processing of the print format is still too much.
31009ae7234SSteven Rostedt (Red Hat)  *
31109ae7234SSteven Rostedt (Red Hat)  * This function allows a kernel developer to debug fast path sections
31209ae7234SSteven Rostedt (Red Hat)  * that printk is not appropriate for. By scattering in various
31309ae7234SSteven Rostedt (Red Hat)  * printk like tracing in the code, a developer can quickly see
31409ae7234SSteven Rostedt (Red Hat)  * where problems are occurring.
31509ae7234SSteven Rostedt (Red Hat)  *
31609ae7234SSteven Rostedt (Red Hat)  * This is intended as a debugging tool for the developer only.
31709ae7234SSteven Rostedt (Red Hat)  * Please refrain from leaving trace_puts scattered around in
31809ae7234SSteven Rostedt (Red Hat)  * your code. (Extra memory is used for special buffers that are
319e8c97af0SRandy Dunlap  * allocated when trace_puts() is used.)
32009ae7234SSteven Rostedt (Red Hat)  *
32109ae7234SSteven Rostedt (Red Hat)  * Returns: 0 if nothing was written, positive # if string was.
32209ae7234SSteven Rostedt (Red Hat)  *  (1 when __trace_bputs is used, strlen(str) when __trace_puts is used)
32309ae7234SSteven Rostedt (Red Hat)  */
32409ae7234SSteven Rostedt (Red Hat) 
32509ae7234SSteven Rostedt (Red Hat) #define trace_puts(str) ({						\
3263debb0a9SSteven Rostedt (Red Hat) 	static const char *trace_printk_fmt __used			\
32733def849SJoe Perches 		__section("__trace_printk_fmt") =			\
32809ae7234SSteven Rostedt (Red Hat) 		__builtin_constant_p(str) ? str : NULL;			\
32909ae7234SSteven Rostedt (Red Hat) 									\
33009ae7234SSteven Rostedt (Red Hat) 	if (__builtin_constant_p(str))					\
33109ae7234SSteven Rostedt (Red Hat) 		__trace_bputs(_THIS_IP_, trace_printk_fmt);		\
33209ae7234SSteven Rostedt (Red Hat) 	else								\
33309ae7234SSteven Rostedt (Red Hat) 		__trace_puts(_THIS_IP_, str, strlen(str));		\
33409ae7234SSteven Rostedt (Red Hat) })
335bcf312cfSSteven Rostedt extern int __trace_bputs(unsigned long ip, const char *str);
336bcf312cfSSteven Rostedt extern int __trace_puts(unsigned long ip, const char *str, int size);
33709ae7234SSteven Rostedt (Red Hat) 
338c142be8eSSteven Rostedt (Red Hat) extern void trace_dump_stack(int skip);
33903889384SSteven Rostedt 
34048ead020SFrederic Weisbecker /*
34148ead020SFrederic Weisbecker  * The double __builtin_constant_p is because gcc will give us an error
34248ead020SFrederic Weisbecker  * if we try to allocate the static variable to fmt if it is not a
34348ead020SFrederic Weisbecker  * constant. Even with the outer if statement.
34448ead020SFrederic Weisbecker  */
345769b0441SFrederic Weisbecker #define ftrace_vprintk(fmt, vargs)					\
346769b0441SFrederic Weisbecker do {									\
34748ead020SFrederic Weisbecker 	if (__builtin_constant_p(fmt)) {				\
3483debb0a9SSteven Rostedt (Red Hat) 		static const char *trace_printk_fmt __used		\
34933def849SJoe Perches 		  __section("__trace_printk_fmt") =			\
35048ead020SFrederic Weisbecker 			__builtin_constant_p(fmt) ? fmt : NULL;		\
3517bffc23eSIngo Molnar 									\
35248ead020SFrederic Weisbecker 		__ftrace_vbprintk(_THIS_IP_, trace_printk_fmt, vargs);	\
35348ead020SFrederic Weisbecker 	} else								\
35448ead020SFrederic Weisbecker 		__ftrace_vprintk(_THIS_IP_, fmt, vargs);		\
355769b0441SFrederic Weisbecker } while (0)
356769b0441SFrederic Weisbecker 
3578db14860SNicolas Iooss extern __printf(2, 0) int
35848ead020SFrederic Weisbecker __ftrace_vbprintk(unsigned long ip, const char *fmt, va_list ap);
35948ead020SFrederic Weisbecker 
3608db14860SNicolas Iooss extern __printf(2, 0) int
361526211bcSIngo Molnar __ftrace_vprintk(unsigned long ip, const char *fmt, va_list ap);
362769b0441SFrederic Weisbecker 
363cecbca96SFrederic Weisbecker extern void ftrace_dump(enum ftrace_dump_mode oops_dump_mode);
364526211bcSIngo Molnar #else
tracing_start(void)365526211bcSIngo Molnar static inline void tracing_start(void) { }
tracing_stop(void)366526211bcSIngo Molnar static inline void tracing_stop(void) { }
trace_dump_stack(int skip)367e67bc51eSDhaval Giani static inline void trace_dump_stack(int skip) { }
36893d68e52SSteven Rostedt 
tracing_on(void)36993d68e52SSteven Rostedt static inline void tracing_on(void) { }
tracing_off(void)37093d68e52SSteven Rostedt static inline void tracing_off(void) { }
tracing_is_on(void)37193d68e52SSteven Rostedt static inline int tracing_is_on(void) { return 0; }
tracing_snapshot(void)372ad909e21SSteven Rostedt (Red Hat) static inline void tracing_snapshot(void) { }
tracing_snapshot_alloc(void)373ad909e21SSteven Rostedt (Red Hat) static inline void tracing_snapshot_alloc(void) { }
37493d68e52SSteven Rostedt 
37560efc15aSMichal Hocko static inline __printf(1, 2)
trace_printk(const char * fmt,...)37660efc15aSMichal Hocko int trace_printk(const char *fmt, ...)
377526211bcSIngo Molnar {
378526211bcSIngo Molnar 	return 0;
379526211bcSIngo Molnar }
3808db14860SNicolas Iooss static __printf(1, 0) inline int
ftrace_vprintk(const char * fmt,va_list ap)381526211bcSIngo Molnar ftrace_vprintk(const char *fmt, va_list ap)
382526211bcSIngo Molnar {
383526211bcSIngo Molnar 	return 0;
384526211bcSIngo Molnar }
ftrace_dump(enum ftrace_dump_mode oops_dump_mode)385cecbca96SFrederic Weisbecker static inline void ftrace_dump(enum ftrace_dump_mode oops_dump_mode) { }
386769b0441SFrederic Weisbecker #endif /* CONFIG_TRACING */
387526211bcSIngo Molnar 
388b9d4f426SArnaud Lacombe /* Rebuild everything on CONFIG_FTRACE_MCOUNT_RECORD */
389b9d4f426SArnaud Lacombe #ifdef CONFIG_FTRACE_MCOUNT_RECORD
390b9d4f426SArnaud Lacombe # define REBUILD_DUE_TO_FTRACE_MCOUNT_RECORD
391b9d4f426SArnaud Lacombe #endif
3929d00f92fSWANG Cong 
39358f86cc8SRusty Russell /* Permissions on a sysfs file: you didn't miss the 0 prefix did you? */
39458f86cc8SRusty Russell #define VERIFY_OCTAL_PERMISSIONS(perms)						\
39558f86cc8SRusty Russell 	(BUILD_BUG_ON_ZERO((perms) < 0) +					\
39658f86cc8SRusty Russell 	 BUILD_BUG_ON_ZERO((perms) > 0777) +					\
39728b8d0c8SGobinda Charan Maji 	 /* USER_READABLE >= GROUP_READABLE >= OTHER_READABLE */		\
39828b8d0c8SGobinda Charan Maji 	 BUILD_BUG_ON_ZERO((((perms) >> 6) & 4) < (((perms) >> 3) & 4)) +	\
39928b8d0c8SGobinda Charan Maji 	 BUILD_BUG_ON_ZERO((((perms) >> 3) & 4) < ((perms) & 4)) +		\
40028b8d0c8SGobinda Charan Maji 	 /* USER_WRITABLE >= GROUP_WRITABLE */					\
40128b8d0c8SGobinda Charan Maji 	 BUILD_BUG_ON_ZERO((((perms) >> 6) & 2) < (((perms) >> 3) & 2)) +	\
40228b8d0c8SGobinda Charan Maji 	 /* OTHER_WRITABLE?  Generally considered a bad idea. */		\
40337549e94SRusty Russell 	 BUILD_BUG_ON_ZERO((perms) & 2) +					\
40458f86cc8SRusty Russell 	 (perms))
4051da177e4SLinus Torvalds #endif
406