~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/include/linux/entry-common.h

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /include/linux/entry-common.h (Version linux-6.12-rc7) and /include/linux/entry-common.h (Version linux-5.14.21)


  1 /* SPDX-License-Identifier: GPL-2.0 */              1 /* SPDX-License-Identifier: GPL-2.0 */
  2 #ifndef __LINUX_ENTRYCOMMON_H                       2 #ifndef __LINUX_ENTRYCOMMON_H
  3 #define __LINUX_ENTRYCOMMON_H                       3 #define __LINUX_ENTRYCOMMON_H
  4                                                     4 
  5 #include <linux/static_call_types.h>                5 #include <linux/static_call_types.h>
  6 #include <linux/ptrace.h>                      !!   6 #include <linux/tracehook.h>
  7 #include <linux/syscalls.h>                         7 #include <linux/syscalls.h>
  8 #include <linux/seccomp.h>                          8 #include <linux/seccomp.h>
  9 #include <linux/sched.h>                            9 #include <linux/sched.h>
 10 #include <linux/context_tracking.h>            << 
 11 #include <linux/livepatch.h>                   << 
 12 #include <linux/resume_user_mode.h>            << 
 13 #include <linux/tick.h>                        << 
 14 #include <linux/kmsan.h>                       << 
 15                                                    10 
 16 #include <asm/entry-common.h>                      11 #include <asm/entry-common.h>
 17                                                    12 
 18 /*                                                 13 /*
 19  * Define dummy _TIF work flags if not defined     14  * Define dummy _TIF work flags if not defined by the architecture or for
 20  * disabled functionality.                         15  * disabled functionality.
 21  */                                                16  */
 22 #ifndef _TIF_PATCH_PENDING                         17 #ifndef _TIF_PATCH_PENDING
 23 # define _TIF_PATCH_PENDING             (0)        18 # define _TIF_PATCH_PENDING             (0)
 24 #endif                                             19 #endif
 25                                                    20 
 26 #ifndef _TIF_UPROBE                                21 #ifndef _TIF_UPROBE
 27 # define _TIF_UPROBE                    (0)        22 # define _TIF_UPROBE                    (0)
 28 #endif                                             23 #endif
 29                                                    24 
 30 /*                                                 25 /*
 31  * SYSCALL_WORK flags handled in syscall_enter     26  * SYSCALL_WORK flags handled in syscall_enter_from_user_mode()
 32  */                                                27  */
 33 #ifndef ARCH_SYSCALL_WORK_ENTER                    28 #ifndef ARCH_SYSCALL_WORK_ENTER
 34 # define ARCH_SYSCALL_WORK_ENTER        (0)        29 # define ARCH_SYSCALL_WORK_ENTER        (0)
 35 #endif                                             30 #endif
 36                                                    31 
 37 /*                                                 32 /*
 38  * SYSCALL_WORK flags handled in syscall_exit_     33  * SYSCALL_WORK flags handled in syscall_exit_to_user_mode()
 39  */                                                34  */
 40 #ifndef ARCH_SYSCALL_WORK_EXIT                     35 #ifndef ARCH_SYSCALL_WORK_EXIT
 41 # define ARCH_SYSCALL_WORK_EXIT         (0)        36 # define ARCH_SYSCALL_WORK_EXIT         (0)
 42 #endif                                             37 #endif
 43                                                    38 
 44 #define SYSCALL_WORK_ENTER      (SYSCALL_WORK_     39 #define SYSCALL_WORK_ENTER      (SYSCALL_WORK_SECCOMP |                 \
 45                                  SYSCALL_WORK_     40                                  SYSCALL_WORK_SYSCALL_TRACEPOINT |      \
 46                                  SYSCALL_WORK_     41                                  SYSCALL_WORK_SYSCALL_TRACE |           \
 47                                  SYSCALL_WORK_     42                                  SYSCALL_WORK_SYSCALL_EMU |             \
 48                                  SYSCALL_WORK_     43                                  SYSCALL_WORK_SYSCALL_AUDIT |           \
 49                                  SYSCALL_WORK_     44                                  SYSCALL_WORK_SYSCALL_USER_DISPATCH |   \
 50                                  ARCH_SYSCALL_     45                                  ARCH_SYSCALL_WORK_ENTER)
 51 #define SYSCALL_WORK_EXIT       (SYSCALL_WORK_     46 #define SYSCALL_WORK_EXIT       (SYSCALL_WORK_SYSCALL_TRACEPOINT |      \
 52                                  SYSCALL_WORK_     47                                  SYSCALL_WORK_SYSCALL_TRACE |           \
 53                                  SYSCALL_WORK_     48                                  SYSCALL_WORK_SYSCALL_AUDIT |           \
 54                                  SYSCALL_WORK_     49                                  SYSCALL_WORK_SYSCALL_USER_DISPATCH |   \
 55                                  SYSCALL_WORK_     50                                  SYSCALL_WORK_SYSCALL_EXIT_TRAP |       \
 56                                  ARCH_SYSCALL_     51                                  ARCH_SYSCALL_WORK_EXIT)
 57                                                    52 
 58 /*                                                 53 /*
 59  * TIF flags handled in exit_to_user_mode_loop     54  * TIF flags handled in exit_to_user_mode_loop()
 60  */                                                55  */
 61 #ifndef ARCH_EXIT_TO_USER_MODE_WORK                56 #ifndef ARCH_EXIT_TO_USER_MODE_WORK
 62 # define ARCH_EXIT_TO_USER_MODE_WORK               57 # define ARCH_EXIT_TO_USER_MODE_WORK            (0)
 63 #endif                                             58 #endif
 64                                                    59 
 65 #define EXIT_TO_USER_MODE_WORK                     60 #define EXIT_TO_USER_MODE_WORK                                          \
 66         (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME      61         (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_UPROBE |           \
 67          _TIF_NEED_RESCHED | _TIF_PATCH_PENDIN     62          _TIF_NEED_RESCHED | _TIF_PATCH_PENDING | _TIF_NOTIFY_SIGNAL |  \
 68          ARCH_EXIT_TO_USER_MODE_WORK)              63          ARCH_EXIT_TO_USER_MODE_WORK)
 69                                                    64 
 70 /**                                                65 /**
 71  * arch_enter_from_user_mode - Architecture sp !!  66  * arch_check_user_regs - Architecture specific sanity check for user mode regs
 72  * @regs:       Pointer to currents pt_regs        67  * @regs:       Pointer to currents pt_regs
 73  *                                                 68  *
 74  * Defaults to an empty implementation. Can be     69  * Defaults to an empty implementation. Can be replaced by architecture
 75  * specific code.                                  70  * specific code.
 76  *                                                 71  *
 77  * Invoked from syscall_enter_from_user_mode()     72  * Invoked from syscall_enter_from_user_mode() in the non-instrumentable
 78  * section. Use __always_inline so the compile     73  * section. Use __always_inline so the compiler cannot push it out of line
 79  * and make it instrumentable.                     74  * and make it instrumentable.
 80  */                                                75  */
 81 static __always_inline void arch_enter_from_us !!  76 static __always_inline void arch_check_user_regs(struct pt_regs *regs);
 82                                                    77 
 83 #ifndef arch_enter_from_user_mode              !!  78 #ifndef arch_check_user_regs
 84 static __always_inline void arch_enter_from_us !!  79 static __always_inline void arch_check_user_regs(struct pt_regs *regs) {}
                                                   >>  80 #endif
                                                   >>  81 
                                                   >>  82 /**
                                                   >>  83  * arch_syscall_enter_tracehook - Wrapper around tracehook_report_syscall_entry()
                                                   >>  84  * @regs:       Pointer to currents pt_regs
                                                   >>  85  *
                                                   >>  86  * Returns: 0 on success or an error code to skip the syscall.
                                                   >>  87  *
                                                   >>  88  * Defaults to tracehook_report_syscall_entry(). Can be replaced by
                                                   >>  89  * architecture specific code.
                                                   >>  90  *
                                                   >>  91  * Invoked from syscall_enter_from_user_mode()
                                                   >>  92  */
                                                   >>  93 static inline __must_check int arch_syscall_enter_tracehook(struct pt_regs *regs);
                                                   >>  94 
                                                   >>  95 #ifndef arch_syscall_enter_tracehook
                                                   >>  96 static inline __must_check int arch_syscall_enter_tracehook(struct pt_regs *regs)
                                                   >>  97 {
                                                   >>  98         return tracehook_report_syscall_entry(regs);
                                                   >>  99 }
 85 #endif                                            100 #endif
 86                                                   101 
 87 /**                                               102 /**
 88  * enter_from_user_mode - Establish state when    103  * enter_from_user_mode - Establish state when coming from user mode
 89  *                                                104  *
 90  * Syscall/interrupt entry disables interrupts    105  * Syscall/interrupt entry disables interrupts, but user mode is traced as
 91  * interrupts enabled. Also with NO_HZ_FULL RC    106  * interrupts enabled. Also with NO_HZ_FULL RCU might be idle.
 92  *                                                107  *
 93  * 1) Tell lockdep that interrupts are disable    108  * 1) Tell lockdep that interrupts are disabled
 94  * 2) Invoke context tracking if enabled to re    109  * 2) Invoke context tracking if enabled to reactivate RCU
 95  * 3) Trace interrupts off state                  110  * 3) Trace interrupts off state
 96  *                                                111  *
 97  * Invoked from architecture specific syscall     112  * Invoked from architecture specific syscall entry code with interrupts
 98  * disabled. The calling code has to be non-in    113  * disabled. The calling code has to be non-instrumentable. When the
 99  * function returns all state is correct and i    114  * function returns all state is correct and interrupts are still
100  * disabled. The subsequent functions can be i    115  * disabled. The subsequent functions can be instrumented.
101  *                                                116  *
102  * This is invoked when there is architecture     117  * This is invoked when there is architecture specific functionality to be
103  * done between establishing state and enablin    118  * done between establishing state and enabling interrupts. The caller must
104  * enable interrupts before invoking syscall_e    119  * enable interrupts before invoking syscall_enter_from_user_mode_work().
105  */                                               120  */
106 static __always_inline void enter_from_user_mo !! 121 void enter_from_user_mode(struct pt_regs *regs);
107 {                                              << 
108         arch_enter_from_user_mode(regs);       << 
109         lockdep_hardirqs_off(CALLER_ADDR0);    << 
110                                                << 
111         CT_WARN_ON(__ct_state() != CT_STATE_US << 
112         user_exit_irqoff();                    << 
113                                                << 
114         instrumentation_begin();               << 
115         kmsan_unpoison_entry_regs(regs);       << 
116         trace_hardirqs_off_finish();           << 
117         instrumentation_end();                 << 
118 }                                              << 
119                                                   122 
120 /**                                               123 /**
121  * syscall_enter_from_user_mode_prepare - Esta    124  * syscall_enter_from_user_mode_prepare - Establish state and enable interrupts
122  * @regs:       Pointer to currents pt_regs       125  * @regs:       Pointer to currents pt_regs
123  *                                                126  *
124  * Invoked from architecture specific syscall     127  * Invoked from architecture specific syscall entry code with interrupts
125  * disabled. The calling code has to be non-in    128  * disabled. The calling code has to be non-instrumentable. When the
126  * function returns all state is correct, inte    129  * function returns all state is correct, interrupts are enabled and the
127  * subsequent functions can be instrumented.      130  * subsequent functions can be instrumented.
128  *                                                131  *
129  * This handles lockdep, RCU (context tracking    132  * This handles lockdep, RCU (context tracking) and tracing state, i.e.
130  * the functionality provided by enter_from_us    133  * the functionality provided by enter_from_user_mode().
131  *                                                134  *
132  * This is invoked when there is extra archite    135  * This is invoked when there is extra architecture specific functionality
133  * to be done between establishing state and h    136  * to be done between establishing state and handling user mode entry work.
134  */                                               137  */
135 void syscall_enter_from_user_mode_prepare(stru    138 void syscall_enter_from_user_mode_prepare(struct pt_regs *regs);
136                                                   139 
137 long syscall_trace_enter(struct pt_regs *regs, << 
138                          unsigned long work);  << 
139                                                << 
140 /**                                               140 /**
141  * syscall_enter_from_user_mode_work - Check a    141  * syscall_enter_from_user_mode_work - Check and handle work before invoking
142  *                                     a sysca    142  *                                     a syscall
143  * @regs:       Pointer to currents pt_regs       143  * @regs:       Pointer to currents pt_regs
144  * @syscall:    The syscall number                144  * @syscall:    The syscall number
145  *                                                145  *
146  * Invoked from architecture specific syscall     146  * Invoked from architecture specific syscall entry code with interrupts
147  * enabled after invoking syscall_enter_from_u    147  * enabled after invoking syscall_enter_from_user_mode_prepare() and extra
148  * architecture specific work.                    148  * architecture specific work.
149  *                                                149  *
150  * Returns: The original or a modified syscall    150  * Returns: The original or a modified syscall number
151  *                                                151  *
152  * If the returned syscall number is -1 then t    152  * If the returned syscall number is -1 then the syscall should be
153  * skipped. In this case the caller may invoke    153  * skipped. In this case the caller may invoke syscall_set_error() or
154  * syscall_set_return_value() first.  If neith    154  * syscall_set_return_value() first.  If neither of those are called and -1
155  * is returned, then the syscall will fail wit    155  * is returned, then the syscall will fail with ENOSYS.
156  *                                                156  *
157  * It handles the following work items:           157  * It handles the following work items:
158  *                                                158  *
159  *  1) syscall_work flag dependent invocations    159  *  1) syscall_work flag dependent invocations of
160  *     ptrace_report_syscall_entry(), __secure !! 160  *     arch_syscall_enter_tracehook(), __secure_computing(), trace_sys_enter()
161  *  2) Invocation of audit_syscall_entry()        161  *  2) Invocation of audit_syscall_entry()
162  */                                               162  */
163 static __always_inline long syscall_enter_from !! 163 long syscall_enter_from_user_mode_work(struct pt_regs *regs, long syscall);
164 {                                              << 
165         unsigned long work = READ_ONCE(current << 
166                                                << 
167         if (work & SYSCALL_WORK_ENTER)         << 
168                 syscall = syscall_trace_enter( << 
169                                                << 
170         return syscall;                        << 
171 }                                              << 
172                                                   164 
173 /**                                               165 /**
174  * syscall_enter_from_user_mode - Establish st    166  * syscall_enter_from_user_mode - Establish state and check and handle work
175  *                                before invok    167  *                                before invoking a syscall
176  * @regs:       Pointer to currents pt_regs       168  * @regs:       Pointer to currents pt_regs
177  * @syscall:    The syscall number                169  * @syscall:    The syscall number
178  *                                                170  *
179  * Invoked from architecture specific syscall     171  * Invoked from architecture specific syscall entry code with interrupts
180  * disabled. The calling code has to be non-in    172  * disabled. The calling code has to be non-instrumentable. When the
181  * function returns all state is correct, inte    173  * function returns all state is correct, interrupts are enabled and the
182  * subsequent functions can be instrumented.      174  * subsequent functions can be instrumented.
183  *                                                175  *
184  * This is combination of syscall_enter_from_u    176  * This is combination of syscall_enter_from_user_mode_prepare() and
185  * syscall_enter_from_user_mode_work().           177  * syscall_enter_from_user_mode_work().
186  *                                                178  *
187  * Returns: The original or a modified syscall    179  * Returns: The original or a modified syscall number. See
188  * syscall_enter_from_user_mode_work() for fur    180  * syscall_enter_from_user_mode_work() for further explanation.
189  */                                               181  */
190 static __always_inline long syscall_enter_from !! 182 long syscall_enter_from_user_mode(struct pt_regs *regs, long syscall);
191 {                                              << 
192         long ret;                              << 
193                                                << 
194         enter_from_user_mode(regs);            << 
195                                                << 
196         instrumentation_begin();               << 
197         local_irq_enable();                    << 
198         ret = syscall_enter_from_user_mode_wor << 
199         instrumentation_end();                 << 
200                                                << 
201         return ret;                            << 
202 }                                              << 
203                                                   183 
204 /**                                               184 /**
205  * local_irq_enable_exit_to_user - Exit to use    185  * local_irq_enable_exit_to_user - Exit to user variant of local_irq_enable()
206  * @ti_work:    Cached TIF flags gathered with    186  * @ti_work:    Cached TIF flags gathered with interrupts disabled
207  *                                                187  *
208  * Defaults to local_irq_enable(). Can be supp    188  * Defaults to local_irq_enable(). Can be supplied by architecture specific
209  * code.                                          189  * code.
210  */                                               190  */
211 static inline void local_irq_enable_exit_to_us    191 static inline void local_irq_enable_exit_to_user(unsigned long ti_work);
212                                                   192 
213 #ifndef local_irq_enable_exit_to_user             193 #ifndef local_irq_enable_exit_to_user
214 static inline void local_irq_enable_exit_to_us    194 static inline void local_irq_enable_exit_to_user(unsigned long ti_work)
215 {                                                 195 {
216         local_irq_enable();                       196         local_irq_enable();
217 }                                                 197 }
218 #endif                                            198 #endif
219                                                   199 
220 /**                                               200 /**
221  * local_irq_disable_exit_to_user - Exit to us    201  * local_irq_disable_exit_to_user - Exit to user variant of local_irq_disable()
222  *                                                202  *
223  * Defaults to local_irq_disable(). Can be sup    203  * Defaults to local_irq_disable(). Can be supplied by architecture specific
224  * code.                                          204  * code.
225  */                                               205  */
226 static inline void local_irq_disable_exit_to_u    206 static inline void local_irq_disable_exit_to_user(void);
227                                                   207 
228 #ifndef local_irq_disable_exit_to_user            208 #ifndef local_irq_disable_exit_to_user
229 static inline void local_irq_disable_exit_to_u    209 static inline void local_irq_disable_exit_to_user(void)
230 {                                                 210 {
231         local_irq_disable();                      211         local_irq_disable();
232 }                                                 212 }
233 #endif                                            213 #endif
234                                                   214 
235 /**                                               215 /**
236  * arch_exit_to_user_mode_work - Architecture     216  * arch_exit_to_user_mode_work - Architecture specific TIF work for exit
237  *                               to user mode.    217  *                               to user mode.
238  * @regs:       Pointer to currents pt_regs       218  * @regs:       Pointer to currents pt_regs
239  * @ti_work:    Cached TIF flags gathered with    219  * @ti_work:    Cached TIF flags gathered with interrupts disabled
240  *                                                220  *
241  * Invoked from exit_to_user_mode_loop() with     221  * Invoked from exit_to_user_mode_loop() with interrupt enabled
242  *                                                222  *
243  * Defaults to NOOP. Can be supplied by archit    223  * Defaults to NOOP. Can be supplied by architecture specific code.
244  */                                               224  */
245 static inline void arch_exit_to_user_mode_work    225 static inline void arch_exit_to_user_mode_work(struct pt_regs *regs,
246                                                   226                                                unsigned long ti_work);
247                                                   227 
248 #ifndef arch_exit_to_user_mode_work               228 #ifndef arch_exit_to_user_mode_work
249 static inline void arch_exit_to_user_mode_work    229 static inline void arch_exit_to_user_mode_work(struct pt_regs *regs,
250                                                   230                                                unsigned long ti_work)
251 {                                                 231 {
252 }                                                 232 }
253 #endif                                            233 #endif
254                                                   234 
255 /**                                               235 /**
256  * arch_exit_to_user_mode_prepare - Architectu    236  * arch_exit_to_user_mode_prepare - Architecture specific preparation for
257  *                                  exit to us    237  *                                  exit to user mode.
258  * @regs:       Pointer to currents pt_regs       238  * @regs:       Pointer to currents pt_regs
259  * @ti_work:    Cached TIF flags gathered with    239  * @ti_work:    Cached TIF flags gathered with interrupts disabled
260  *                                                240  *
261  * Invoked from exit_to_user_mode_prepare() wi    241  * Invoked from exit_to_user_mode_prepare() with interrupt disabled as the last
262  * function before return. Defaults to NOOP.      242  * function before return. Defaults to NOOP.
263  */                                               243  */
264 static inline void arch_exit_to_user_mode_prep    244 static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs,
265                                                   245                                                   unsigned long ti_work);
266                                                   246 
267 #ifndef arch_exit_to_user_mode_prepare            247 #ifndef arch_exit_to_user_mode_prepare
268 static inline void arch_exit_to_user_mode_prep    248 static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs,
269                                                   249                                                   unsigned long ti_work)
270 {                                                 250 {
271 }                                                 251 }
272 #endif                                            252 #endif
273                                                   253 
274 /**                                               254 /**
275  * arch_exit_to_user_mode - Architecture speci    255  * arch_exit_to_user_mode - Architecture specific final work before
276  *                          exit to user mode.    256  *                          exit to user mode.
277  *                                                257  *
278  * Invoked from exit_to_user_mode() with inter    258  * Invoked from exit_to_user_mode() with interrupt disabled as the last
279  * function before return. Defaults to NOOP.      259  * function before return. Defaults to NOOP.
280  *                                                260  *
281  * This needs to be __always_inline because it    261  * This needs to be __always_inline because it is non-instrumentable code
282  * invoked after context tracking switched to     262  * invoked after context tracking switched to user mode.
283  *                                                263  *
284  * An architecture implementation must not do     264  * An architecture implementation must not do anything complex, no locking
285  * etc. The main purpose is for speculation mi    265  * etc. The main purpose is for speculation mitigations.
286  */                                               266  */
287 static __always_inline void arch_exit_to_user_    267 static __always_inline void arch_exit_to_user_mode(void);
288                                                   268 
289 #ifndef arch_exit_to_user_mode                    269 #ifndef arch_exit_to_user_mode
290 static __always_inline void arch_exit_to_user_    270 static __always_inline void arch_exit_to_user_mode(void) { }
291 #endif                                            271 #endif
292                                                   272 
293 /**                                               273 /**
294  * arch_do_signal_or_restart -  Architecture s    274  * arch_do_signal_or_restart -  Architecture specific signal delivery function
295  * @regs:       Pointer to currents pt_regs       275  * @regs:       Pointer to currents pt_regs
                                                   >> 276  * @has_signal: actual signal to handle
296  *                                                277  *
297  * Invoked from exit_to_user_mode_loop().         278  * Invoked from exit_to_user_mode_loop().
298  */                                               279  */
299 void arch_do_signal_or_restart(struct pt_regs  !! 280 void arch_do_signal_or_restart(struct pt_regs *regs, bool has_signal);
300                                                   281 
301 /**                                               282 /**
302  * exit_to_user_mode_loop - do any pending wor !! 283  * arch_syscall_exit_tracehook - Wrapper around tracehook_report_syscall_exit()
303  */                                            !! 284  * @regs:       Pointer to currents pt_regs
304 unsigned long exit_to_user_mode_loop(struct pt !! 285  * @step:       Indicator for single step
305                                      unsigned  !! 286  *
306                                                !! 287  * Defaults to tracehook_report_syscall_exit(). Can be replaced by
307 /**                                            !! 288  * architecture specific code.
308  * exit_to_user_mode_prepare - call exit_to_us << 
309  * @regs:       Pointer to pt_regs on entry st << 
310  *                                                289  *
311  * 1) check that interrupts are disabled       !! 290  * Invoked from syscall_exit_to_user_mode()
312  * 2) call tick_nohz_user_enter_prepare()      << 
313  * 3) call exit_to_user_mode_loop() if any fla << 
314  *    EXIT_TO_USER_MODE_WORK are set           << 
315  * 4) check that interrupts are still disabled << 
316  */                                               291  */
317 static __always_inline void exit_to_user_mode_ !! 292 static inline void arch_syscall_exit_tracehook(struct pt_regs *regs, bool step);
318 {                                              << 
319         unsigned long ti_work;                 << 
320                                                << 
321         lockdep_assert_irqs_disabled();        << 
322                                                << 
323         /* Flush pending rcuog wakeup before t << 
324         tick_nohz_user_enter_prepare();        << 
325                                                << 
326         ti_work = read_thread_flags();         << 
327         if (unlikely(ti_work & EXIT_TO_USER_MO << 
328                 ti_work = exit_to_user_mode_lo << 
329                                                << 
330         arch_exit_to_user_mode_prepare(regs, t << 
331                                                   293 
332         /* Ensure that kernel state is sane fo !! 294 #ifndef arch_syscall_exit_tracehook
333         kmap_assert_nomap();                   !! 295 static inline void arch_syscall_exit_tracehook(struct pt_regs *regs, bool step)
334         lockdep_assert_irqs_disabled();        !! 296 {
335         lockdep_sys_exit();                    !! 297         tracehook_report_syscall_exit(regs, step);
336 }                                                 298 }
                                                   >> 299 #endif
337                                                   300 
338 /**                                               301 /**
339  * exit_to_user_mode - Fixup state when exitin    302  * exit_to_user_mode - Fixup state when exiting to user mode
340  *                                                303  *
341  * Syscall/interrupt exit enables interrupts,     304  * Syscall/interrupt exit enables interrupts, but the kernel state is
342  * interrupts disabled when this is invoked. A    305  * interrupts disabled when this is invoked. Also tell RCU about it.
343  *                                                306  *
344  * 1) Trace interrupts on state                   307  * 1) Trace interrupts on state
345  * 2) Invoke context tracking if enabled to ad    308  * 2) Invoke context tracking if enabled to adjust RCU state
346  * 3) Invoke architecture specific last minute    309  * 3) Invoke architecture specific last minute exit code, e.g. speculation
347  *    mitigations, etc.: arch_exit_to_user_mod    310  *    mitigations, etc.: arch_exit_to_user_mode()
348  * 4) Tell lockdep that interrupts are enabled    311  * 4) Tell lockdep that interrupts are enabled
349  *                                                312  *
350  * Invoked from architecture specific code whe    313  * Invoked from architecture specific code when syscall_exit_to_user_mode()
351  * is not suitable as the last step before ret    314  * is not suitable as the last step before returning to userspace. Must be
352  * invoked with interrupts disabled and the ca    315  * invoked with interrupts disabled and the caller must be
353  * non-instrumentable.                            316  * non-instrumentable.
354  * The caller has to invoke syscall_exit_to_us    317  * The caller has to invoke syscall_exit_to_user_mode_work() before this.
355  */                                               318  */
356 static __always_inline void exit_to_user_mode( !! 319 void exit_to_user_mode(void);
357 {                                              << 
358         instrumentation_begin();               << 
359         trace_hardirqs_on_prepare();           << 
360         lockdep_hardirqs_on_prepare();         << 
361         instrumentation_end();                 << 
362                                                << 
363         user_enter_irqoff();                   << 
364         arch_exit_to_user_mode();              << 
365         lockdep_hardirqs_on(CALLER_ADDR0);     << 
366 }                                              << 
367                                                   320 
368 /**                                               321 /**
369  * syscall_exit_to_user_mode_work - Handle wor    322  * syscall_exit_to_user_mode_work - Handle work before returning to user mode
370  * @regs:       Pointer to currents pt_regs       323  * @regs:       Pointer to currents pt_regs
371  *                                                324  *
372  * Same as step 1 and 2 of syscall_exit_to_use    325  * Same as step 1 and 2 of syscall_exit_to_user_mode() but without calling
373  * exit_to_user_mode() to perform the final tr    326  * exit_to_user_mode() to perform the final transition to user mode.
374  *                                                327  *
375  * Calling convention is the same as for sysca    328  * Calling convention is the same as for syscall_exit_to_user_mode() and it
376  * returns with all work handled and interrupt    329  * returns with all work handled and interrupts disabled. The caller must
377  * invoke exit_to_user_mode() before actually     330  * invoke exit_to_user_mode() before actually switching to user mode to
378  * make the final state transitions. Interrupt    331  * make the final state transitions. Interrupts must stay disabled between
379  * return from this function and the invocatio    332  * return from this function and the invocation of exit_to_user_mode().
380  */                                               333  */
381 void syscall_exit_to_user_mode_work(struct pt_    334 void syscall_exit_to_user_mode_work(struct pt_regs *regs);
382                                                   335 
383 /**                                               336 /**
384  * syscall_exit_to_user_mode - Handle work bef    337  * syscall_exit_to_user_mode - Handle work before returning to user mode
385  * @regs:       Pointer to currents pt_regs       338  * @regs:       Pointer to currents pt_regs
386  *                                                339  *
387  * Invoked with interrupts enabled and fully v    340  * Invoked with interrupts enabled and fully valid regs. Returns with all
388  * work handled, interrupts disabled such that    341  * work handled, interrupts disabled such that the caller can immediately
389  * switch to user mode. Called from architectu    342  * switch to user mode. Called from architecture specific syscall and ret
390  * from fork code.                                343  * from fork code.
391  *                                                344  *
392  * The call order is:                             345  * The call order is:
393  *  1) One-time syscall exit work:                346  *  1) One-time syscall exit work:
394  *      - rseq syscall exit                       347  *      - rseq syscall exit
395  *      - audit                                   348  *      - audit
396  *      - syscall tracing                         349  *      - syscall tracing
397  *      - ptrace (single stepping)             !! 350  *      - tracehook (single stepping)
398  *                                                351  *
399  *  2) Preparatory work                           352  *  2) Preparatory work
400  *      - Exit to user mode loop (common TIF h    353  *      - Exit to user mode loop (common TIF handling). Invokes
401  *        arch_exit_to_user_mode_work() for ar    354  *        arch_exit_to_user_mode_work() for architecture specific TIF work
402  *      - Architecture specific one time work     355  *      - Architecture specific one time work arch_exit_to_user_mode_prepare()
403  *      - Address limit and lockdep checks        356  *      - Address limit and lockdep checks
404  *                                                357  *
405  *  3) Final transition (lockdep, tracing, con    358  *  3) Final transition (lockdep, tracing, context tracking, RCU), i.e. the
406  *     functionality in exit_to_user_mode().      359  *     functionality in exit_to_user_mode().
407  *                                                360  *
408  * This is a combination of syscall_exit_to_us    361  * This is a combination of syscall_exit_to_user_mode_work() (1,2) and
409  * exit_to_user_mode(). This function is prefe    362  * exit_to_user_mode(). This function is preferred unless there is a
410  * compelling architectural reason to use the     363  * compelling architectural reason to use the separate functions.
411  */                                               364  */
412 void syscall_exit_to_user_mode(struct pt_regs     365 void syscall_exit_to_user_mode(struct pt_regs *regs);
413                                                   366 
414 /**                                               367 /**
415  * irqentry_enter_from_user_mode - Establish s    368  * irqentry_enter_from_user_mode - Establish state before invoking the irq handler
416  * @regs:       Pointer to currents pt_regs       369  * @regs:       Pointer to currents pt_regs
417  *                                                370  *
418  * Invoked from architecture specific entry co    371  * Invoked from architecture specific entry code with interrupts disabled.
419  * Can only be called when the interrupt entry    372  * Can only be called when the interrupt entry came from user mode. The
420  * calling code must be non-instrumentable.  W    373  * calling code must be non-instrumentable.  When the function returns all
421  * state is correct and the subsequent functio    374  * state is correct and the subsequent functions can be instrumented.
422  *                                                375  *
423  * The function establishes state (lockdep, RC    376  * The function establishes state (lockdep, RCU (context tracking), tracing)
424  */                                               377  */
425 void irqentry_enter_from_user_mode(struct pt_r    378 void irqentry_enter_from_user_mode(struct pt_regs *regs);
426                                                   379 
427 /**                                               380 /**
428  * irqentry_exit_to_user_mode - Interrupt exit    381  * irqentry_exit_to_user_mode - Interrupt exit work
429  * @regs:       Pointer to current's pt_regs      382  * @regs:       Pointer to current's pt_regs
430  *                                                383  *
431  * Invoked with interrupts disabled and fully     384  * Invoked with interrupts disabled and fully valid regs. Returns with all
432  * work handled, interrupts disabled such that    385  * work handled, interrupts disabled such that the caller can immediately
433  * switch to user mode. Called from architectu    386  * switch to user mode. Called from architecture specific interrupt
434  * handling code.                                 387  * handling code.
435  *                                                388  *
436  * The call order is #2 and #3 as described in    389  * The call order is #2 and #3 as described in syscall_exit_to_user_mode().
437  * Interrupt exit is not invoking #1 which is     390  * Interrupt exit is not invoking #1 which is the syscall specific one time
438  * work.                                          391  * work.
439  */                                               392  */
440 void irqentry_exit_to_user_mode(struct pt_regs    393 void irqentry_exit_to_user_mode(struct pt_regs *regs);
441                                                   394 
442 #ifndef irqentry_state                            395 #ifndef irqentry_state
443 /**                                               396 /**
444  * struct irqentry_state - Opaque object for e    397  * struct irqentry_state - Opaque object for exception state storage
445  * @exit_rcu: Used exclusively in the irqentry    398  * @exit_rcu: Used exclusively in the irqentry_*() calls; signals whether the
446  *            exit path has to invoke ct_irq_e !! 399  *            exit path has to invoke rcu_irq_exit().
447  * @lockdep: Used exclusively in the irqentry_    400  * @lockdep: Used exclusively in the irqentry_nmi_*() calls; ensures that
448  *           lockdep state is restored correct    401  *           lockdep state is restored correctly on exit from nmi.
449  *                                                402  *
450  * This opaque object is filled in by the irqe    403  * This opaque object is filled in by the irqentry_*_enter() functions and
451  * must be passed back into the corresponding     404  * must be passed back into the corresponding irqentry_*_exit() functions
452  * when the exception is complete.                405  * when the exception is complete.
453  *                                                406  *
454  * Callers of irqentry_*_[enter|exit]() must c    407  * Callers of irqentry_*_[enter|exit]() must consider this structure opaque
455  * and all members private.  Descriptions of t    408  * and all members private.  Descriptions of the members are provided to aid in
456  * the maintenance of the irqentry_*() functio    409  * the maintenance of the irqentry_*() functions.
457  */                                               410  */
458 typedef struct irqentry_state {                   411 typedef struct irqentry_state {
459         union {                                   412         union {
460                 bool    exit_rcu;                 413                 bool    exit_rcu;
461                 bool    lockdep;                  414                 bool    lockdep;
462         };                                        415         };
463 } irqentry_state_t;                               416 } irqentry_state_t;
464 #endif                                            417 #endif
465                                                   418 
466 /**                                               419 /**
467  * irqentry_enter - Handle state tracking on o    420  * irqentry_enter - Handle state tracking on ordinary interrupt entries
468  * @regs:       Pointer to pt_regs of interrup    421  * @regs:       Pointer to pt_regs of interrupted context
469  *                                                422  *
470  * Invokes:                                       423  * Invokes:
471  *  - lockdep irqflag state tracking as low le    424  *  - lockdep irqflag state tracking as low level ASM entry disabled
472  *    interrupts.                                 425  *    interrupts.
473  *                                                426  *
474  *  - Context tracking if the exception hit us    427  *  - Context tracking if the exception hit user mode.
475  *                                                428  *
476  *  - The hardirq tracer to keep the state con    429  *  - The hardirq tracer to keep the state consistent as low level ASM
477  *    entry disabled interrupts.                  430  *    entry disabled interrupts.
478  *                                                431  *
479  * As a precondition, this requires that the e    432  * As a precondition, this requires that the entry came from user mode,
480  * idle, or a kernel context in which RCU is w    433  * idle, or a kernel context in which RCU is watching.
481  *                                                434  *
482  * For kernel mode entries RCU handling is don    435  * For kernel mode entries RCU handling is done conditional. If RCU is
483  * watching then the only RCU requirement is t    436  * watching then the only RCU requirement is to check whether the tick has
484  * to be restarted. If RCU is not watching the !! 437  * to be restarted. If RCU is not watching then rcu_irq_enter() has to be
485  * invoked on entry and ct_irq_exit() on exit. !! 438  * invoked on entry and rcu_irq_exit() on exit.
486  *                                                439  *
487  * Avoiding the ct_irq_enter/exit() calls is a !! 440  * Avoiding the rcu_irq_enter/exit() calls is an optimization but also
488  * solves the problem of kernel mode pagefault    441  * solves the problem of kernel mode pagefaults which can schedule, which
489  * is not possible after invoking ct_irq_enter !! 442  * is not possible after invoking rcu_irq_enter() without undoing it.
490  *                                                443  *
491  * For user mode entries irqentry_enter_from_u    444  * For user mode entries irqentry_enter_from_user_mode() is invoked to
492  * establish the proper context for NOHZ_FULL.    445  * establish the proper context for NOHZ_FULL. Otherwise scheduling on exit
493  * would not be possible.                         446  * would not be possible.
494  *                                                447  *
495  * Returns: An opaque object that must be pass    448  * Returns: An opaque object that must be passed to idtentry_exit()
496  */                                               449  */
497 irqentry_state_t noinstr irqentry_enter(struct    450 irqentry_state_t noinstr irqentry_enter(struct pt_regs *regs);
498                                                   451 
499 /**                                               452 /**
500  * irqentry_exit_cond_resched - Conditionally     453  * irqentry_exit_cond_resched - Conditionally reschedule on return from interrupt
501  *                                                454  *
502  * Conditional reschedule with additional sani    455  * Conditional reschedule with additional sanity checks.
503  */                                               456  */
504 void raw_irqentry_exit_cond_resched(void);     !! 457 void irqentry_exit_cond_resched(void);
505 #ifdef CONFIG_PREEMPT_DYNAMIC                     458 #ifdef CONFIG_PREEMPT_DYNAMIC
506 #if defined(CONFIG_HAVE_PREEMPT_DYNAMIC_CALL)  !! 459 DECLARE_STATIC_CALL(irqentry_exit_cond_resched, irqentry_exit_cond_resched);
507 #define irqentry_exit_cond_resched_dynamic_ena !! 460 #endif
508 #define irqentry_exit_cond_resched_dynamic_dis << 
509 DECLARE_STATIC_CALL(irqentry_exit_cond_resched << 
510 #define irqentry_exit_cond_resched()    static << 
511 #elif defined(CONFIG_HAVE_PREEMPT_DYNAMIC_KEY) << 
512 DECLARE_STATIC_KEY_TRUE(sk_dynamic_irqentry_ex << 
513 void dynamic_irqentry_exit_cond_resched(void); << 
514 #define irqentry_exit_cond_resched()    dynami << 
515 #endif                                         << 
516 #else /* CONFIG_PREEMPT_DYNAMIC */             << 
517 #define irqentry_exit_cond_resched()    raw_ir << 
518 #endif /* CONFIG_PREEMPT_DYNAMIC */            << 
519                                                   461 
520 /**                                               462 /**
521  * irqentry_exit - Handle return from exceptio    463  * irqentry_exit - Handle return from exception that used irqentry_enter()
522  * @regs:       Pointer to pt_regs (exception     464  * @regs:       Pointer to pt_regs (exception entry regs)
523  * @state:      Return value from matching cal    465  * @state:      Return value from matching call to irqentry_enter()
524  *                                                466  *
525  * Depending on the return target (kernel/user    467  * Depending on the return target (kernel/user) this runs the necessary
526  * preemption and work checks if possible and     468  * preemption and work checks if possible and required and returns to
527  * the caller with interrupts disabled and no     469  * the caller with interrupts disabled and no further work pending.
528  *                                                470  *
529  * This is the last action before returning to    471  * This is the last action before returning to the low level ASM code which
530  * just needs to return to the appropriate con    472  * just needs to return to the appropriate context.
531  *                                                473  *
532  * Counterpart to irqentry_enter().               474  * Counterpart to irqentry_enter().
533  */                                               475  */
534 void noinstr irqentry_exit(struct pt_regs *reg    476 void noinstr irqentry_exit(struct pt_regs *regs, irqentry_state_t state);
535                                                   477 
536 /**                                               478 /**
537  * irqentry_nmi_enter - Handle NMI entry          479  * irqentry_nmi_enter - Handle NMI entry
538  * @regs:       Pointer to currents pt_regs       480  * @regs:       Pointer to currents pt_regs
539  *                                                481  *
540  * Similar to irqentry_enter() but taking care    482  * Similar to irqentry_enter() but taking care of the NMI constraints.
541  */                                               483  */
542 irqentry_state_t noinstr irqentry_nmi_enter(st    484 irqentry_state_t noinstr irqentry_nmi_enter(struct pt_regs *regs);
543                                                   485 
544 /**                                               486 /**
545  * irqentry_nmi_exit - Handle return from NMI     487  * irqentry_nmi_exit - Handle return from NMI handling
546  * @regs:       Pointer to pt_regs (NMI entry     488  * @regs:       Pointer to pt_regs (NMI entry regs)
547  * @irq_state:  Return value from matching cal    489  * @irq_state:  Return value from matching call to irqentry_nmi_enter()
548  *                                                490  *
549  * Last action before returning to the low lev    491  * Last action before returning to the low level assembly code.
550  *                                                492  *
551  * Counterpart to irqentry_nmi_enter().           493  * Counterpart to irqentry_nmi_enter().
552  */                                               494  */
553 void noinstr irqentry_nmi_exit(struct pt_regs     495 void noinstr irqentry_nmi_exit(struct pt_regs *regs, irqentry_state_t irq_state);
554                                                   496 
555 #endif                                            497 #endif
556                                                   498 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php