xref: /linux/include/linux/entry-common.h (revision a5497bab5f72dce38a259a53fd3ac1239a7ecf40)
1142781e1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0 */
2142781e1SThomas Gleixner #ifndef __LINUX_ENTRYCOMMON_H
3142781e1SThomas Gleixner #define __LINUX_ENTRYCOMMON_H
4142781e1SThomas Gleixner 
5142781e1SThomas Gleixner #include <linux/tracehook.h>
6142781e1SThomas Gleixner #include <linux/syscalls.h>
7142781e1SThomas Gleixner #include <linux/seccomp.h>
8142781e1SThomas Gleixner #include <linux/sched.h>
9142781e1SThomas Gleixner 
10142781e1SThomas Gleixner #include <asm/entry-common.h>
11142781e1SThomas Gleixner 
12142781e1SThomas Gleixner /*
13142781e1SThomas Gleixner  * Define dummy _TIF work flags if not defined by the architecture or for
14142781e1SThomas Gleixner  * disabled functionality.
15142781e1SThomas Gleixner  */
16142781e1SThomas Gleixner #ifndef _TIF_SYSCALL_EMU
17142781e1SThomas Gleixner # define _TIF_SYSCALL_EMU		(0)
18142781e1SThomas Gleixner #endif
19142781e1SThomas Gleixner 
20142781e1SThomas Gleixner #ifndef _TIF_SYSCALL_TRACEPOINT
21142781e1SThomas Gleixner # define _TIF_SYSCALL_TRACEPOINT	(0)
22142781e1SThomas Gleixner #endif
23142781e1SThomas Gleixner 
24142781e1SThomas Gleixner #ifndef _TIF_SECCOMP
25142781e1SThomas Gleixner # define _TIF_SECCOMP			(0)
26142781e1SThomas Gleixner #endif
27142781e1SThomas Gleixner 
28142781e1SThomas Gleixner #ifndef _TIF_SYSCALL_AUDIT
29142781e1SThomas Gleixner # define _TIF_SYSCALL_AUDIT		(0)
30142781e1SThomas Gleixner #endif
31142781e1SThomas Gleixner 
32a9f3a74aSThomas Gleixner #ifndef _TIF_PATCH_PENDING
33a9f3a74aSThomas Gleixner # define _TIF_PATCH_PENDING		(0)
34a9f3a74aSThomas Gleixner #endif
35a9f3a74aSThomas Gleixner 
36a9f3a74aSThomas Gleixner #ifndef _TIF_UPROBE
37a9f3a74aSThomas Gleixner # define _TIF_UPROBE			(0)
38a9f3a74aSThomas Gleixner #endif
39a9f3a74aSThomas Gleixner 
40142781e1SThomas Gleixner /*
41142781e1SThomas Gleixner  * TIF flags handled in syscall_enter_from_usermode()
42142781e1SThomas Gleixner  */
43142781e1SThomas Gleixner #ifndef ARCH_SYSCALL_ENTER_WORK
44142781e1SThomas Gleixner # define ARCH_SYSCALL_ENTER_WORK	(0)
45142781e1SThomas Gleixner #endif
46142781e1SThomas Gleixner 
47142781e1SThomas Gleixner #define SYSCALL_ENTER_WORK						\
48142781e1SThomas Gleixner 	(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SECCOMP |	\
49142781e1SThomas Gleixner 	 _TIF_SYSCALL_TRACEPOINT | _TIF_SYSCALL_EMU |			\
50142781e1SThomas Gleixner 	 ARCH_SYSCALL_ENTER_WORK)
51142781e1SThomas Gleixner 
52a9f3a74aSThomas Gleixner /*
53a9f3a74aSThomas Gleixner  * TIF flags handled in syscall_exit_to_user_mode()
54a9f3a74aSThomas Gleixner  */
55a9f3a74aSThomas Gleixner #ifndef ARCH_SYSCALL_EXIT_WORK
56a9f3a74aSThomas Gleixner # define ARCH_SYSCALL_EXIT_WORK		(0)
57a9f3a74aSThomas Gleixner #endif
58a9f3a74aSThomas Gleixner 
59a9f3a74aSThomas Gleixner #define SYSCALL_EXIT_WORK						\
60a9f3a74aSThomas Gleixner 	(_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT |			\
61a9f3a74aSThomas Gleixner 	 _TIF_SYSCALL_TRACEPOINT | ARCH_SYSCALL_EXIT_WORK)
62a9f3a74aSThomas Gleixner 
63a9f3a74aSThomas Gleixner /*
64a9f3a74aSThomas Gleixner  * TIF flags handled in exit_to_user_mode_loop()
65a9f3a74aSThomas Gleixner  */
66a9f3a74aSThomas Gleixner #ifndef ARCH_EXIT_TO_USER_MODE_WORK
67a9f3a74aSThomas Gleixner # define ARCH_EXIT_TO_USER_MODE_WORK		(0)
68a9f3a74aSThomas Gleixner #endif
69a9f3a74aSThomas Gleixner 
70a9f3a74aSThomas Gleixner #define EXIT_TO_USER_MODE_WORK						\
71a9f3a74aSThomas Gleixner 	(_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_UPROBE |		\
72a9f3a74aSThomas Gleixner 	 _TIF_NEED_RESCHED | _TIF_PATCH_PENDING |			\
73a9f3a74aSThomas Gleixner 	 ARCH_EXIT_TO_USER_MODE_WORK)
74a9f3a74aSThomas Gleixner 
75142781e1SThomas Gleixner /**
76142781e1SThomas Gleixner  * arch_check_user_regs - Architecture specific sanity check for user mode regs
77142781e1SThomas Gleixner  * @regs:	Pointer to currents pt_regs
78142781e1SThomas Gleixner  *
79142781e1SThomas Gleixner  * Defaults to an empty implementation. Can be replaced by architecture
80142781e1SThomas Gleixner  * specific code.
81142781e1SThomas Gleixner  *
82142781e1SThomas Gleixner  * Invoked from syscall_enter_from_user_mode() in the non-instrumentable
83142781e1SThomas Gleixner  * section. Use __always_inline so the compiler cannot push it out of line
84142781e1SThomas Gleixner  * and make it instrumentable.
85142781e1SThomas Gleixner  */
86142781e1SThomas Gleixner static __always_inline void arch_check_user_regs(struct pt_regs *regs);
87142781e1SThomas Gleixner 
88142781e1SThomas Gleixner #ifndef arch_check_user_regs
89142781e1SThomas Gleixner static __always_inline void arch_check_user_regs(struct pt_regs *regs) {}
90142781e1SThomas Gleixner #endif
91142781e1SThomas Gleixner 
92142781e1SThomas Gleixner /**
93142781e1SThomas Gleixner  * arch_syscall_enter_tracehook - Wrapper around tracehook_report_syscall_entry()
94142781e1SThomas Gleixner  * @regs:	Pointer to currents pt_regs
95142781e1SThomas Gleixner  *
96142781e1SThomas Gleixner  * Returns: 0 on success or an error code to skip the syscall.
97142781e1SThomas Gleixner  *
98142781e1SThomas Gleixner  * Defaults to tracehook_report_syscall_entry(). Can be replaced by
99142781e1SThomas Gleixner  * architecture specific code.
100142781e1SThomas Gleixner  *
101142781e1SThomas Gleixner  * Invoked from syscall_enter_from_user_mode()
102142781e1SThomas Gleixner  */
103142781e1SThomas Gleixner static inline __must_check int arch_syscall_enter_tracehook(struct pt_regs *regs);
104142781e1SThomas Gleixner 
105142781e1SThomas Gleixner #ifndef arch_syscall_enter_tracehook
106142781e1SThomas Gleixner static inline __must_check int arch_syscall_enter_tracehook(struct pt_regs *regs)
107142781e1SThomas Gleixner {
108142781e1SThomas Gleixner 	return tracehook_report_syscall_entry(regs);
109142781e1SThomas Gleixner }
110142781e1SThomas Gleixner #endif
111142781e1SThomas Gleixner 
112142781e1SThomas Gleixner /**
113142781e1SThomas Gleixner  * syscall_enter_from_user_mode - Check and handle work before invoking
114142781e1SThomas Gleixner  *				 a syscall
115142781e1SThomas Gleixner  * @regs:	Pointer to currents pt_regs
116142781e1SThomas Gleixner  * @syscall:	The syscall number
117142781e1SThomas Gleixner  *
118142781e1SThomas Gleixner  * Invoked from architecture specific syscall entry code with interrupts
119142781e1SThomas Gleixner  * disabled. The calling code has to be non-instrumentable. When the
120142781e1SThomas Gleixner  * function returns all state is correct and the subsequent functions can be
121142781e1SThomas Gleixner  * instrumented.
122142781e1SThomas Gleixner  *
123142781e1SThomas Gleixner  * Returns: The original or a modified syscall number
124142781e1SThomas Gleixner  *
125142781e1SThomas Gleixner  * If the returned syscall number is -1 then the syscall should be
126142781e1SThomas Gleixner  * skipped. In this case the caller may invoke syscall_set_error() or
127142781e1SThomas Gleixner  * syscall_set_return_value() first.  If neither of those are called and -1
128142781e1SThomas Gleixner  * is returned, then the syscall will fail with ENOSYS.
129142781e1SThomas Gleixner  *
130142781e1SThomas Gleixner  * The following functionality is handled here:
131142781e1SThomas Gleixner  *
132142781e1SThomas Gleixner  *  1) Establish state (lockdep, RCU (context tracking), tracing)
133142781e1SThomas Gleixner  *  2) TIF flag dependent invocations of arch_syscall_enter_tracehook(),
134142781e1SThomas Gleixner  *     __secure_computing(), trace_sys_enter()
135142781e1SThomas Gleixner  *  3) Invocation of audit_syscall_entry()
136142781e1SThomas Gleixner  */
137142781e1SThomas Gleixner long syscall_enter_from_user_mode(struct pt_regs *regs, long syscall);
138142781e1SThomas Gleixner 
139142781e1SThomas Gleixner /**
140a9f3a74aSThomas Gleixner  * local_irq_enable_exit_to_user - Exit to user variant of local_irq_enable()
141a9f3a74aSThomas Gleixner  * @ti_work:	Cached TIF flags gathered with interrupts disabled
142a9f3a74aSThomas Gleixner  *
143a9f3a74aSThomas Gleixner  * Defaults to local_irq_enable(). Can be supplied by architecture specific
144a9f3a74aSThomas Gleixner  * code.
145a9f3a74aSThomas Gleixner  */
146a9f3a74aSThomas Gleixner static inline void local_irq_enable_exit_to_user(unsigned long ti_work);
147a9f3a74aSThomas Gleixner 
148a9f3a74aSThomas Gleixner #ifndef local_irq_enable_exit_to_user
149a9f3a74aSThomas Gleixner static inline void local_irq_enable_exit_to_user(unsigned long ti_work)
150a9f3a74aSThomas Gleixner {
151a9f3a74aSThomas Gleixner 	local_irq_enable();
152a9f3a74aSThomas Gleixner }
153a9f3a74aSThomas Gleixner #endif
154a9f3a74aSThomas Gleixner 
155a9f3a74aSThomas Gleixner /**
156a9f3a74aSThomas Gleixner  * local_irq_disable_exit_to_user - Exit to user variant of local_irq_disable()
157a9f3a74aSThomas Gleixner  *
158a9f3a74aSThomas Gleixner  * Defaults to local_irq_disable(). Can be supplied by architecture specific
159a9f3a74aSThomas Gleixner  * code.
160a9f3a74aSThomas Gleixner  */
161a9f3a74aSThomas Gleixner static inline void local_irq_disable_exit_to_user(void);
162a9f3a74aSThomas Gleixner 
163a9f3a74aSThomas Gleixner #ifndef local_irq_disable_exit_to_user
164a9f3a74aSThomas Gleixner static inline void local_irq_disable_exit_to_user(void)
165a9f3a74aSThomas Gleixner {
166a9f3a74aSThomas Gleixner 	local_irq_disable();
167a9f3a74aSThomas Gleixner }
168a9f3a74aSThomas Gleixner #endif
169a9f3a74aSThomas Gleixner 
170a9f3a74aSThomas Gleixner /**
171a9f3a74aSThomas Gleixner  * arch_exit_to_user_mode_work - Architecture specific TIF work for exit
172a9f3a74aSThomas Gleixner  *				 to user mode.
173a9f3a74aSThomas Gleixner  * @regs:	Pointer to currents pt_regs
174a9f3a74aSThomas Gleixner  * @ti_work:	Cached TIF flags gathered with interrupts disabled
175a9f3a74aSThomas Gleixner  *
176a9f3a74aSThomas Gleixner  * Invoked from exit_to_user_mode_loop() with interrupt enabled
177a9f3a74aSThomas Gleixner  *
178a9f3a74aSThomas Gleixner  * Defaults to NOOP. Can be supplied by architecture specific code.
179a9f3a74aSThomas Gleixner  */
180a9f3a74aSThomas Gleixner static inline void arch_exit_to_user_mode_work(struct pt_regs *regs,
181a9f3a74aSThomas Gleixner 					       unsigned long ti_work);
182a9f3a74aSThomas Gleixner 
183a9f3a74aSThomas Gleixner #ifndef arch_exit_to_user_mode_work
184a9f3a74aSThomas Gleixner static inline void arch_exit_to_user_mode_work(struct pt_regs *regs,
185a9f3a74aSThomas Gleixner 					       unsigned long ti_work)
186a9f3a74aSThomas Gleixner {
187a9f3a74aSThomas Gleixner }
188a9f3a74aSThomas Gleixner #endif
189a9f3a74aSThomas Gleixner 
190a9f3a74aSThomas Gleixner /**
191a9f3a74aSThomas Gleixner  * arch_exit_to_user_mode_prepare - Architecture specific preparation for
192a9f3a74aSThomas Gleixner  *				    exit to user mode.
193a9f3a74aSThomas Gleixner  * @regs:	Pointer to currents pt_regs
194a9f3a74aSThomas Gleixner  * @ti_work:	Cached TIF flags gathered with interrupts disabled
195a9f3a74aSThomas Gleixner  *
196a9f3a74aSThomas Gleixner  * Invoked from exit_to_user_mode_prepare() with interrupt disabled as the last
197a9f3a74aSThomas Gleixner  * function before return. Defaults to NOOP.
198a9f3a74aSThomas Gleixner  */
199a9f3a74aSThomas Gleixner static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs,
200a9f3a74aSThomas Gleixner 						  unsigned long ti_work);
201a9f3a74aSThomas Gleixner 
202a9f3a74aSThomas Gleixner #ifndef arch_exit_to_user_mode_prepare
203a9f3a74aSThomas Gleixner static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs,
204a9f3a74aSThomas Gleixner 						  unsigned long ti_work)
205a9f3a74aSThomas Gleixner {
206a9f3a74aSThomas Gleixner }
207a9f3a74aSThomas Gleixner #endif
208a9f3a74aSThomas Gleixner 
209a9f3a74aSThomas Gleixner /**
210a9f3a74aSThomas Gleixner  * arch_exit_to_user_mode - Architecture specific final work before
211a9f3a74aSThomas Gleixner  *			    exit to user mode.
212a9f3a74aSThomas Gleixner  *
213a9f3a74aSThomas Gleixner  * Invoked from exit_to_user_mode() with interrupt disabled as the last
214a9f3a74aSThomas Gleixner  * function before return. Defaults to NOOP.
215a9f3a74aSThomas Gleixner  *
216a9f3a74aSThomas Gleixner  * This needs to be __always_inline because it is non-instrumentable code
217a9f3a74aSThomas Gleixner  * invoked after context tracking switched to user mode.
218a9f3a74aSThomas Gleixner  *
219a9f3a74aSThomas Gleixner  * An architecture implementation must not do anything complex, no locking
220a9f3a74aSThomas Gleixner  * etc. The main purpose is for speculation mitigations.
221a9f3a74aSThomas Gleixner  */
222a9f3a74aSThomas Gleixner static __always_inline void arch_exit_to_user_mode(void);
223a9f3a74aSThomas Gleixner 
224a9f3a74aSThomas Gleixner #ifndef arch_exit_to_user_mode
225a9f3a74aSThomas Gleixner static __always_inline void arch_exit_to_user_mode(void) { }
226a9f3a74aSThomas Gleixner #endif
227a9f3a74aSThomas Gleixner 
228a9f3a74aSThomas Gleixner /**
229a9f3a74aSThomas Gleixner  * arch_do_signal -  Architecture specific signal delivery function
230a9f3a74aSThomas Gleixner  * @regs:	Pointer to currents pt_regs
231a9f3a74aSThomas Gleixner  *
232a9f3a74aSThomas Gleixner  * Invoked from exit_to_user_mode_loop().
233a9f3a74aSThomas Gleixner  */
234a9f3a74aSThomas Gleixner void arch_do_signal(struct pt_regs *regs);
235a9f3a74aSThomas Gleixner 
236a9f3a74aSThomas Gleixner /**
237a9f3a74aSThomas Gleixner  * arch_syscall_exit_tracehook - Wrapper around tracehook_report_syscall_exit()
238a9f3a74aSThomas Gleixner  * @regs:	Pointer to currents pt_regs
239a9f3a74aSThomas Gleixner  * @step:	Indicator for single step
240a9f3a74aSThomas Gleixner  *
241a9f3a74aSThomas Gleixner  * Defaults to tracehook_report_syscall_exit(). Can be replaced by
242a9f3a74aSThomas Gleixner  * architecture specific code.
243a9f3a74aSThomas Gleixner  *
244a9f3a74aSThomas Gleixner  * Invoked from syscall_exit_to_user_mode()
245a9f3a74aSThomas Gleixner  */
246a9f3a74aSThomas Gleixner static inline void arch_syscall_exit_tracehook(struct pt_regs *regs, bool step);
247a9f3a74aSThomas Gleixner 
248a9f3a74aSThomas Gleixner #ifndef arch_syscall_exit_tracehook
249a9f3a74aSThomas Gleixner static inline void arch_syscall_exit_tracehook(struct pt_regs *regs, bool step)
250a9f3a74aSThomas Gleixner {
251a9f3a74aSThomas Gleixner 	tracehook_report_syscall_exit(regs, step);
252a9f3a74aSThomas Gleixner }
253a9f3a74aSThomas Gleixner #endif
254a9f3a74aSThomas Gleixner 
255a9f3a74aSThomas Gleixner /**
256a9f3a74aSThomas Gleixner  * syscall_exit_to_user_mode - Handle work before returning to user mode
257a9f3a74aSThomas Gleixner  * @regs:	Pointer to currents pt_regs
258a9f3a74aSThomas Gleixner  *
259a9f3a74aSThomas Gleixner  * Invoked with interrupts enabled and fully valid regs. Returns with all
260a9f3a74aSThomas Gleixner  * work handled, interrupts disabled such that the caller can immediately
261a9f3a74aSThomas Gleixner  * switch to user mode. Called from architecture specific syscall and ret
262a9f3a74aSThomas Gleixner  * from fork code.
263a9f3a74aSThomas Gleixner  *
264a9f3a74aSThomas Gleixner  * The call order is:
265a9f3a74aSThomas Gleixner  *  1) One-time syscall exit work:
266a9f3a74aSThomas Gleixner  *	- rseq syscall exit
267a9f3a74aSThomas Gleixner  *      - audit
268a9f3a74aSThomas Gleixner  *	- syscall tracing
269a9f3a74aSThomas Gleixner  *	- tracehook (single stepping)
270a9f3a74aSThomas Gleixner  *
271a9f3a74aSThomas Gleixner  *  2) Preparatory work
272a9f3a74aSThomas Gleixner  *	- Exit to user mode loop (common TIF handling). Invokes
273a9f3a74aSThomas Gleixner  *	  arch_exit_to_user_mode_work() for architecture specific TIF work
274a9f3a74aSThomas Gleixner  *	- Architecture specific one time work arch_exit_to_user_mode_prepare()
275a9f3a74aSThomas Gleixner  *	- Address limit and lockdep checks
276a9f3a74aSThomas Gleixner  *
277a9f3a74aSThomas Gleixner  *  3) Final transition (lockdep, tracing, context tracking, RCU). Invokes
278a9f3a74aSThomas Gleixner  *     arch_exit_to_user_mode() to handle e.g. speculation mitigations
279a9f3a74aSThomas Gleixner  */
280a9f3a74aSThomas Gleixner void syscall_exit_to_user_mode(struct pt_regs *regs);
281a9f3a74aSThomas Gleixner 
282a9f3a74aSThomas Gleixner /**
283142781e1SThomas Gleixner  * irqentry_enter_from_user_mode - Establish state before invoking the irq handler
284142781e1SThomas Gleixner  * @regs:	Pointer to currents pt_regs
285142781e1SThomas Gleixner  *
286142781e1SThomas Gleixner  * Invoked from architecture specific entry code with interrupts disabled.
287142781e1SThomas Gleixner  * Can only be called when the interrupt entry came from user mode. The
288142781e1SThomas Gleixner  * calling code must be non-instrumentable.  When the function returns all
289142781e1SThomas Gleixner  * state is correct and the subsequent functions can be instrumented.
290142781e1SThomas Gleixner  *
291142781e1SThomas Gleixner  * The function establishes state (lockdep, RCU (context tracking), tracing)
292142781e1SThomas Gleixner  */
293142781e1SThomas Gleixner void irqentry_enter_from_user_mode(struct pt_regs *regs);
294142781e1SThomas Gleixner 
295a9f3a74aSThomas Gleixner /**
296a9f3a74aSThomas Gleixner  * irqentry_exit_to_user_mode - Interrupt exit work
297a9f3a74aSThomas Gleixner  * @regs:	Pointer to current's pt_regs
298a9f3a74aSThomas Gleixner  *
299a9f3a74aSThomas Gleixner  * Invoked with interrupts disbled and fully valid regs. Returns with all
300a9f3a74aSThomas Gleixner  * work handled, interrupts disabled such that the caller can immediately
301a9f3a74aSThomas Gleixner  * switch to user mode. Called from architecture specific interrupt
302a9f3a74aSThomas Gleixner  * handling code.
303a9f3a74aSThomas Gleixner  *
304a9f3a74aSThomas Gleixner  * The call order is #2 and #3 as described in syscall_exit_to_user_mode().
305a9f3a74aSThomas Gleixner  * Interrupt exit is not invoking #1 which is the syscall specific one time
306a9f3a74aSThomas Gleixner  * work.
307a9f3a74aSThomas Gleixner  */
308a9f3a74aSThomas Gleixner void irqentry_exit_to_user_mode(struct pt_regs *regs);
309a9f3a74aSThomas Gleixner 
310*a5497babSThomas Gleixner #ifndef irqentry_state
311*a5497babSThomas Gleixner typedef struct irqentry_state {
312*a5497babSThomas Gleixner 	bool	exit_rcu;
313*a5497babSThomas Gleixner } irqentry_state_t;
314*a5497babSThomas Gleixner #endif
315*a5497babSThomas Gleixner 
316*a5497babSThomas Gleixner /**
317*a5497babSThomas Gleixner  * irqentry_enter - Handle state tracking on ordinary interrupt entries
318*a5497babSThomas Gleixner  * @regs:	Pointer to pt_regs of interrupted context
319*a5497babSThomas Gleixner  *
320*a5497babSThomas Gleixner  * Invokes:
321*a5497babSThomas Gleixner  *  - lockdep irqflag state tracking as low level ASM entry disabled
322*a5497babSThomas Gleixner  *    interrupts.
323*a5497babSThomas Gleixner  *
324*a5497babSThomas Gleixner  *  - Context tracking if the exception hit user mode.
325*a5497babSThomas Gleixner  *
326*a5497babSThomas Gleixner  *  - The hardirq tracer to keep the state consistent as low level ASM
327*a5497babSThomas Gleixner  *    entry disabled interrupts.
328*a5497babSThomas Gleixner  *
329*a5497babSThomas Gleixner  * As a precondition, this requires that the entry came from user mode,
330*a5497babSThomas Gleixner  * idle, or a kernel context in which RCU is watching.
331*a5497babSThomas Gleixner  *
332*a5497babSThomas Gleixner  * For kernel mode entries RCU handling is done conditional. If RCU is
333*a5497babSThomas Gleixner  * watching then the only RCU requirement is to check whether the tick has
334*a5497babSThomas Gleixner  * to be restarted. If RCU is not watching then rcu_irq_enter() has to be
335*a5497babSThomas Gleixner  * invoked on entry and rcu_irq_exit() on exit.
336*a5497babSThomas Gleixner  *
337*a5497babSThomas Gleixner  * Avoiding the rcu_irq_enter/exit() calls is an optimization but also
338*a5497babSThomas Gleixner  * solves the problem of kernel mode pagefaults which can schedule, which
339*a5497babSThomas Gleixner  * is not possible after invoking rcu_irq_enter() without undoing it.
340*a5497babSThomas Gleixner  *
341*a5497babSThomas Gleixner  * For user mode entries irqentry_enter_from_user_mode() is invoked to
342*a5497babSThomas Gleixner  * establish the proper context for NOHZ_FULL. Otherwise scheduling on exit
343*a5497babSThomas Gleixner  * would not be possible.
344*a5497babSThomas Gleixner  *
345*a5497babSThomas Gleixner  * Returns: An opaque object that must be passed to idtentry_exit()
346*a5497babSThomas Gleixner  */
347*a5497babSThomas Gleixner irqentry_state_t noinstr irqentry_enter(struct pt_regs *regs);
348*a5497babSThomas Gleixner 
349*a5497babSThomas Gleixner /**
350*a5497babSThomas Gleixner  * irqentry_exit_cond_resched - Conditionally reschedule on return from interrupt
351*a5497babSThomas Gleixner  *
352*a5497babSThomas Gleixner  * Conditional reschedule with additional sanity checks.
353*a5497babSThomas Gleixner  */
354*a5497babSThomas Gleixner void irqentry_exit_cond_resched(void);
355*a5497babSThomas Gleixner 
356*a5497babSThomas Gleixner /**
357*a5497babSThomas Gleixner  * irqentry_exit - Handle return from exception that used irqentry_enter()
358*a5497babSThomas Gleixner  * @regs:	Pointer to pt_regs (exception entry regs)
359*a5497babSThomas Gleixner  * @state:	Return value from matching call to irqentry_enter()
360*a5497babSThomas Gleixner  *
361*a5497babSThomas Gleixner  * Depending on the return target (kernel/user) this runs the necessary
362*a5497babSThomas Gleixner  * preemption and work checks if possible and reguired and returns to
363*a5497babSThomas Gleixner  * the caller with interrupts disabled and no further work pending.
364*a5497babSThomas Gleixner  *
365*a5497babSThomas Gleixner  * This is the last action before returning to the low level ASM code which
366*a5497babSThomas Gleixner  * just needs to return to the appropriate context.
367*a5497babSThomas Gleixner  *
368*a5497babSThomas Gleixner  * Counterpart to irqentry_enter().
369*a5497babSThomas Gleixner  */
370*a5497babSThomas Gleixner void noinstr irqentry_exit(struct pt_regs *regs, irqentry_state_t state);
371*a5497babSThomas Gleixner 
372142781e1SThomas Gleixner #endif
373