x86/xen: init %gs very early to avoid page faults with stack protector

"Linux Kernel Mailing List" <[email protected]>
Newsgroups gmane.linux.kernel.commits.head
Message-ID <[email protected]>
Web:        https://git.kernel.org/torvalds/c/4f277295e54c5b7340e48efea3fc5cc21a2872b7
Commit:     4f277295e54c5b7340e48efea3fc5cc21a2872b7
Parent:     ddb9e13af3bba3f8c36ccee0eb9563a82b425c12
Refname:    refs/heads/master
Author:     Juergen Gross <[email protected]>
AuthorDate: Thu Feb 1 13:40:19 2018 +0100
Committer:  Juergen Gross <[email protected]>
CommitDate: Tue Feb 6 09:37:18 2018 +0100

    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]>
---
 arch/x86/xen/xen-head.S | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
index 497cc55a0c16..96f26e026783 100644
--- a/arch/x86/xen/xen-head.S
+++ b/arch/x86/xen/xen-head.S
@@ -9,7 +9,9 @@
 
 #include <asm/boot.h>
 #include <asm/asm.h>
+#include <asm/msr.h>
 #include <asm/page_types.h>
+#include <asm/percpu.h>
 #include <asm/unwind_hints.h>
 
 #include <xen/interface/elfnote.h>
@@ -35,6 +37,20 @@ ENTRY(startup_xen)
 	mov %_ASM_SI, xen_start_info
 	mov $init_thread_union+THREAD_SIZE, %_ASM_SP
 
+#ifdef CONFIG_X86_64
+	/* Set up %gs.
+	 *
+	 * The base of %gs always points to the bottom of the irqstack
+	 * union.  If the stack protector canary is enabled, it is
+	 * located at %gs:40.  Note that, on SMP, the boot cpu uses
+	 * init data section till per cpu areas are set up.
+	 */
+	movl	$MSR_GS_BASE,%ecx
+	movq	$INIT_PER_CPU_VAR(irq_stack_union),%rax
+	cdq
+	wrmsr
+#endif
+
 	jmp xen_start_kernel
 END(startup_xen)
 	__FINIT
--
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.