Skip to contentSkip to conversation

x86/cpu: Reposition stack alignment check

PATCH In review Andrew Cooper 3 participants 4 messages Nov 25, 2016 – Nov 28, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/cpu: Reposition stack alignment check

As identified during review, using BUG_ON() before lidt will result in a triple fault, even on APs.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>

---
 xen/arch/x86/cpu/common.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
xen/arch/x86/cpu/common.c +9 -5
index 06ee401..16cf001 100644
@@ -643,11 +643,6 @@ void load_system_tables(void)
 		.limit = (IDT_ENTRIES * sizeof(idt_entry_t)) - 1,
 	};
 
-	/* Bottom-of-stack must be 16-byte aligned! */
-	BUILD_BUG_ON((sizeof(struct cpu_info) -
-		      offsetof(struct cpu_info, guest_cpu_user_regs.es)) & 0xf);
-	BUG_ON(system_state != SYS_STATE_early_boot && (stack_bottom & 0xf));
-
 	/* Main stack for interrupts/exceptions. */
 	tss->rsp0 = stack_bottom;
 	tss->bitmap = IOBMP_INVALID_OFFSET;
@@ -672,6 +667,15 @@ void load_system_tables(void)
 	asm volatile ("lidt %0"  : : "m"  (idtr) );
 	asm volatile ("ltr  %w0" : : "rm" (TSS_ENTRY << 3) );
 	asm volatile ("lldt %w0" : : "rm" (0) );
+
+	/*
+         * Bottom-of-stack must be 16-byte aligned!
+         *
+         * Defer checks until exception support is sufficiently set up.
+         */
+	BUILD_BUG_ON((sizeof(struct cpu_info) -
+		      offsetof(struct cpu_info, guest_cpu_user_regs.es)) & 0xf);
+	BUG_ON(system_state != SYS_STATE_early_boot && (stack_bottom & 0xf));
 }
 
 /*
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw
Quoted 7 lines · Andrew Cooper

As identified during review, using BUG_ON() before lidt will result in a triple fault, even on APs.

---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>

On the basis that this is a critical bug fix:

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

Reviewed-by on v1 1/1
#2 lore raw
In reply to Andrew Cooper
Quoted 3 lines
Quoted 1 line
Quoted 1 line · On 25.11.16 at 20:04, <[email protected]> wrote:

As identified during review, using BUG_ON() before lidt will result in a triple fault, even on APs.

Oh, I did commit v1 instead of v2, sorry.

Quoted 1 line

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw
In reply to Andrew Cooper

xen/arch/x86/cpu/common.c void load_system_tables(void) · line 675

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 25.11.16 at 20:04, <[email protected]> wrote:
xen/arch/x86/cpu/common.c +6 -0
@@ -672,6 +667,15 @@ void load_system_tables(void)
 	asm volatile ("lidt %0"  : : "m"  (idtr) );
 	asm volatile ("ltr  %w0" : : "rm" (TSS_ENTRY << 3) );
 	asm volatile ("lldt %w0" : : "rm" (0) );
+
+	/*
+         * Bottom-of-stack must be 16-byte aligned!
+         *
+         * Defer checks until exception support is sufficiently set up.
+         */

I've applied this right away, correcting the indentation issue here.

Jan

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel