Skip to content

Commit e164710

Browse files
ruanjinjie-engThomas Gleixner
authored andcommitted
entry: Rework syscall_exit_to_user_mode_work() for architecture reuse
syscall_exit_to_user_mode_work() invokes local_irq_disable_exit_to_user() and syscall_exit_to_user_mode_prepare() after handling pending syscall exit work. The conversion of ARM64 to the generic entry code requires this to be split up, so move the invocations of local_irq_disable_exit_to_user() and syscall_exit_to_user_mode_prepare() into the only caller. No functional change intended. [ tglx: Massaged changelog and comments ] Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com> Signed-off-by: Thomas Gleixner <tglx@kernel.org> Reviewed-by: Kevin Brodsky <kevin.brodsky@arm.com> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Link: https://patch.msgid.link/20260128031934.3906955-10-ruanjinjie@huawei.com
1 parent 03150a9 commit e164710

1 file changed

Lines changed: 11 additions & 14 deletions

File tree

include/linux/entry-common.h

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,12 @@ static __always_inline long syscall_enter_from_user_mode(struct pt_regs *regs, l
122122
void syscall_exit_work(struct pt_regs *regs, unsigned long work);
123123

124124
/**
125-
* syscall_exit_to_user_mode_work - Handle work before returning to user mode
125+
* syscall_exit_to_user_mode_work - Handle one time work before returning to user mode
126126
* @regs: Pointer to currents pt_regs
127127
*
128-
* Same as step 1 and 2 of syscall_exit_to_user_mode() but without calling
129-
* exit_to_user_mode() to perform the final transition to user mode.
128+
* Step 1 of syscall_exit_to_user_mode() with the same calling convention.
130129
*
131-
* Calling convention is the same as for syscall_exit_to_user_mode() and it
132-
* returns with all work handled and interrupts disabled. The caller must
133-
* invoke exit_to_user_mode() before actually switching to user mode to
134-
* make the final state transitions. Interrupts must stay disabled between
135-
* return from this function and the invocation of exit_to_user_mode().
130+
* The caller must invoke steps 2-3 of syscall_exit_to_user_mode() afterwards.
136131
*/
137132
static __always_inline void syscall_exit_to_user_mode_work(struct pt_regs *regs)
138133
{
@@ -155,15 +150,13 @@ static __always_inline void syscall_exit_to_user_mode_work(struct pt_regs *regs)
155150
*/
156151
if (unlikely(work & SYSCALL_WORK_EXIT))
157152
syscall_exit_work(regs, work);
158-
local_irq_disable_exit_to_user();
159-
syscall_exit_to_user_mode_prepare(regs);
160153
}
161154

162155
/**
163156
* syscall_exit_to_user_mode - Handle work before returning to user mode
164157
* @regs: Pointer to currents pt_regs
165158
*
166-
* Invoked with interrupts enabled and fully valid regs. Returns with all
159+
* Invoked with interrupts enabled and fully valid @regs. Returns with all
167160
* work handled, interrupts disabled such that the caller can immediately
168161
* switch to user mode. Called from architecture specific syscall and ret
169162
* from fork code.
@@ -176,6 +169,7 @@ static __always_inline void syscall_exit_to_user_mode_work(struct pt_regs *regs)
176169
* - ptrace (single stepping)
177170
*
178171
* 2) Preparatory work
172+
* - Disable interrupts
179173
* - Exit to user mode loop (common TIF handling). Invokes
180174
* arch_exit_to_user_mode_work() for architecture specific TIF work
181175
* - Architecture specific one time work arch_exit_to_user_mode_prepare()
@@ -184,14 +178,17 @@ static __always_inline void syscall_exit_to_user_mode_work(struct pt_regs *regs)
184178
* 3) Final transition (lockdep, tracing, context tracking, RCU), i.e. the
185179
* functionality in exit_to_user_mode().
186180
*
187-
* This is a combination of syscall_exit_to_user_mode_work() (1,2) and
188-
* exit_to_user_mode(). This function is preferred unless there is a
189-
* compelling architectural reason to use the separate functions.
181+
* This is a combination of syscall_exit_to_user_mode_work() (1), disabling
182+
* interrupts followed by syscall_exit_to_user_mode_prepare() (2) and
183+
* exit_to_user_mode() (3). This function is preferred unless there is a
184+
* compelling architectural reason to invoke the functions separately.
190185
*/
191186
static __always_inline void syscall_exit_to_user_mode(struct pt_regs *regs)
192187
{
193188
instrumentation_begin();
194189
syscall_exit_to_user_mode_work(regs);
190+
local_irq_disable_exit_to_user();
191+
syscall_exit_to_user_mode_prepare(regs);
195192
instrumentation_end();
196193
exit_to_user_mode();
197194
}

0 commit comments

Comments
 (0)