aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Hansen <dave.hansen@linux.intel.com>2018-10-12 19:21:18 -0400
committerThomas Gleixner <tglx@linutronix.de>2018-10-14 05:11:22 -0400
commit16561f27f94e6193ee8f5b9b74801e1668c86efc (patch)
tree044d2cfaa1e2fe08feb08946233af179b05b2643
parentb59167ac7bafd804c91e49ad53c6d33a7394d4c8 (diff)
x86/entry: Add some paranoid entry/exit CR3 handling comments
Andi Kleen was just asking me about the NMI CR3 handling and why we restore it unconditionally. I was *sure* we had documented it well. We did not. Add some documentation. We have common entry code where the CR3 value is stashed, but three places in two big code paths where we restore it. I put bulk of the comments in this common path and then refer to it from the other spots. Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: luto@kernel.org Cc: bp@alien8.de Cc: "H. Peter Anvin" <hpa@zytor.come Cc: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Link: https://lkml.kernel.org/r/20181012232118.3EAAE77B@viggo.jf.intel.com
-rw-r--r--arch/x86/entry/entry_64.S15
1 files changed, 15 insertions, 0 deletions
diff --git a/arch/x86/entry/entry_64.S b/arch/x86/entry/entry_64.S
index 957dfb693ecc..1d9b4a300c8c 100644
--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -1187,6 +1187,18 @@ ENTRY(paranoid_entry)
1187 xorl %ebx, %ebx 1187 xorl %ebx, %ebx
1188 1188
11891: 11891:
1190 /*
1191 * Always stash CR3 in %r14. This value will be restored,
1192 * verbatim, at exit. Needed if kernel is interrupted
1193 * after switching to the user CR3 value but before
1194 * returning to userspace.
1195 *
1196 * This is also why CS (stashed in the "iret frame" by the
1197 * hardware at entry) can not be used: this may be a return
1198 * to kernel code, but with a user CR3 value. The %ebx flag
1199 * for SWAPGS is also unusable for CR3 because there is a
1200 * window with a user GS and a kernel CR3.
1201 */
1190 SAVE_AND_SWITCH_TO_KERNEL_CR3 scratch_reg=%rax save_reg=%r14 1202 SAVE_AND_SWITCH_TO_KERNEL_CR3 scratch_reg=%rax save_reg=%r14
1191 1203
1192 ret 1204 ret
@@ -1211,11 +1223,13 @@ ENTRY(paranoid_exit)
1211 testl %ebx, %ebx /* swapgs needed? */ 1223 testl %ebx, %ebx /* swapgs needed? */
1212 jnz .Lparanoid_exit_no_swapgs 1224 jnz .Lparanoid_exit_no_swapgs
1213 TRACE_IRQS_IRETQ 1225 TRACE_IRQS_IRETQ
1226 /* Always restore stashed CR3 value (see paranoid_entry) */
1214 RESTORE_CR3 scratch_reg=%rbx save_reg=%r14 1227 RESTORE_CR3 scratch_reg=%rbx save_reg=%r14
1215 SWAPGS_UNSAFE_STACK 1228 SWAPGS_UNSAFE_STACK
1216 jmp .Lparanoid_exit_restore 1229 jmp .Lparanoid_exit_restore
1217.Lparanoid_exit_no_swapgs: 1230.Lparanoid_exit_no_swapgs:
1218 TRACE_IRQS_IRETQ_DEBUG 1231 TRACE_IRQS_IRETQ_DEBUG
1232 /* Always restore stashed CR3 value (see paranoid_entry) */
1219 RESTORE_CR3 scratch_reg=%rbx save_reg=%r14 1233 RESTORE_CR3 scratch_reg=%rbx save_reg=%r14
1220.Lparanoid_exit_restore: 1234.Lparanoid_exit_restore:
1221 jmp restore_regs_and_return_to_kernel 1235 jmp restore_regs_and_return_to_kernel
@@ -1626,6 +1640,7 @@ end_repeat_nmi:
1626 movq $-1, %rsi 1640 movq $-1, %rsi
1627 call do_nmi 1641 call do_nmi
1628 1642
1643 /* Always restore stashed CR3 value (see paranoid_entry) */
1629 RESTORE_CR3 scratch_reg=%r15 save_reg=%r14 1644 RESTORE_CR3 scratch_reg=%r15 save_reg=%r14
1630 1645
1631 testl %ebx, %ebx /* swapgs needed? */ 1646 testl %ebx, %ebx /* swapgs needed? */