Skip to contentSkip to conversation

powerpc: Call restore_sprs() before _switch()

PATCH Applied Anton Blanchard 2 participants 2 messages Dec 10, 2015 – Dec 14, 2015 PowerPC

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 powerpc: Call restore_sprs() before _switch()

commit 152d523e6307 ("powerpc: Create context switch helpers save_sprs() and restore_sprs()") moved the restore of SPRs after the call to _switch().

There is an issue with this approach - new tasks do not return through _switch(), they are set up by copy_thread() to directly return through ret_from_fork() or ret_from_kernel_thread(). This means restore_sprs() is not getting called for new tasks.

Fix this by moving restore_sprs() before _switch().

Fixes 152d523e6307 ("powerpc: Create context switch helpers save_sprs() and restore_sprs()")

fold

---
 arch/powerpc/kernel/process.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)
arch/powerpc/kernel/process.c +9 -6
index 58194c3..6f5c392 100644
@@ -964,14 +964,17 @@ struct task_struct *__switch_to(struct task_struct *prev,
 
 	tm_recheckpoint_new_task(new);
 
-	last = _switch(old_thread, new_thread);
-
-	/* Need to recalculate these after calling _switch() */
-	old_thread = &last->thread;
-	new_thread = &current->thread;
-
+	/*
+	 * Call restore_sprs() before calling _switch(). If we move it after
+	 * _switch() then we miss out on calling it for new tasks. The reason
+	 * for this is we manually create a stack frame for new tasks that
+	 * directly returns through ret_from_fork() or
+	 * ret_from_kernel_thread(). See copy_thread() for details.
+	 */
 	restore_sprs(old_thread, new_thread);
 
+	last = _switch(old_thread, new_thread);
+
 #ifdef CONFIG_PPC_BOOK3S_64
 	if (current_thread_info()->local_flags & _TLF_LAZY_MMU) {
 		current_thread_info()->local_flags &= ~_TLF_LAZY_MMU;
Signature · 1 line
2.5.0
reviewer Applied
#1 lore raw
Quoted 8 lines · Anton Blanchard

commit 152d523e6307 ("powerpc: Create context switch helpers save_sprs() and restore_sprs()") moved the restore of SPRs after the call to _switch().

There is an issue with this approach - new tasks do not return through _switch(), they are set up by copy_thread() to directly return through ret_from_fork() or ret_from_kernel_thread(). This means restore_sprs() is not getting called for new tasks.

Quoted 4 lines

Fix this by moving restore_sprs() before _switch().

Fixes 152d523e6307 ("powerpc: Create context switch helpers save_sprs() and restore_sprs()")

Applied to powerpc next, thanks.

https://git.kernel.org/powerpc/c/20dbe67062062c2a790832f0

cheers