Skip to content

Commit 4f27729

Browse files
committed
x86/xen: init %gs very early to avoid page faults with stack protector
When running as Xen pv guest %gs is initialized some time after C code is started. Depending on stack protector usage this might be too late, resulting in page faults. So setup %gs and MSR_GS_BASE in assembly code already. Cc: [email protected] Signed-off-by: Juergen Gross <[email protected]> Reviewed-by: Boris Ostrovsky <[email protected]> Tested-by: Chris Patterson <[email protected]> Signed-off-by: Juergen Gross <[email protected]>
1 parent ddb9e13 commit 4f27729

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

arch/x86/xen/xen-head.S

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
#include <asm/boot.h>
1111
#include <asm/asm.h>
12+
#include <asm/msr.h>
1213
#include <asm/page_types.h>
14+
#include <asm/percpu.h>
1315
#include <asm/unwind_hints.h>
1416

1517
#include <xen/interface/elfnote.h>
@@ -35,6 +37,20 @@ ENTRY(startup_xen)
3537
mov %_ASM_SI, xen_start_info
3638
mov $init_thread_union+THREAD_SIZE, %_ASM_SP
3739

40+
#ifdef CONFIG_X86_64
41+
/* Set up %gs.
42+
*
43+
* The base of %gs always points to the bottom of the irqstack
44+
* union. If the stack protector canary is enabled, it is
45+
* located at %gs:40. Note that, on SMP, the boot cpu uses
46+
* init data section till per cpu areas are set up.
47+
*/
48+
movl $MSR_GS_BASE,%ecx
49+
movq $INIT_PER_CPU_VAR(irq_stack_union),%rax
50+
cdq
51+
wrmsr
52+
#endif
53+
3854
jmp xen_start_kernel
3955
END(startup_xen)
4056
__FINIT

0 commit comments

Comments
 (0)