Module Name: src Committed By: maxv Date: Sat Oct 21 06:55:54 UTC 2017
Modified Files: src/sys/arch/amd64/acpi: acpi_wakeup_low.S src/sys/arch/amd64/amd64: locore.S machdep.c src/sys/arch/x86/x86: sys_machdep.c Log Message: Improve our segregs model. Pass 3/3. Treat %gs the same way we treat %ds/%es/%fs: restore it in INTRFASTEXIT on 32bit LWPs. On Xen however, its behavior does not change, because we need to do an hypercall before INTR_RESTORE_GPRS, and that's too complicated for now. As a side effect, this change fixes a bug in the ACPI wakeup code; %fs/%gs were not restored on 32bit LWPs, and chances are they would segfault shortly afterwards. Support for USER_LDT on amd64 is almost complete now. To generate a diff of this commit: cvs rdiff -u -r1.7 -r1.8 src/sys/arch/amd64/acpi/acpi_wakeup_low.S cvs rdiff -u -r1.136 -r1.137 src/sys/arch/amd64/amd64/locore.S cvs rdiff -u -r1.271 -r1.272 src/sys/arch/amd64/amd64/machdep.c cvs rdiff -u -r1.41 -r1.42 src/sys/arch/x86/x86/sys_machdep.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/amd64/acpi/acpi_wakeup_low.S diff -u src/sys/arch/amd64/acpi/acpi_wakeup_low.S:1.7 src/sys/arch/amd64/acpi/acpi_wakeup_low.S:1.8 --- src/sys/arch/amd64/acpi/acpi_wakeup_low.S:1.7 Thu Oct 19 18:36:31 2017 +++ src/sys/arch/amd64/acpi/acpi_wakeup_low.S Sat Oct 21 06:55:54 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: acpi_wakeup_low.S,v 1.7 2017/10/19 18:36:31 maxv Exp $ */ +/* $NetBSD: acpi_wakeup_low.S,v 1.8 2017/10/21 06:55:54 maxv Exp $ */ /*- * Copyright (c) 2007 Joerg Sonnenberger <jo...@netbsd.org> @@ -47,9 +47,9 @@ acpi_md_sleep_exit: movw %ax,%ss /* - * FS and GS are driven by MSRs, so use NULL for them. - * XXX XXX XXX That's not the case if we're returning to a 32bit - * LWP! + * FS and GS are driven by MSRs, so use NULL for them. If we're + * returning to a 32bit LWP, %fs/%gs will be restored in + * INTRFASTEXIT. */ xorw %ax,%ax movw %ax,%fs Index: src/sys/arch/amd64/amd64/locore.S diff -u src/sys/arch/amd64/amd64/locore.S:1.136 src/sys/arch/amd64/amd64/locore.S:1.137 --- src/sys/arch/amd64/amd64/locore.S:1.136 Thu Oct 19 20:27:12 2017 +++ src/sys/arch/amd64/amd64/locore.S Sat Oct 21 06:55:54 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: locore.S,v 1.136 2017/10/19 20:27:12 maxv Exp $ */ +/* $NetBSD: locore.S,v 1.137 2017/10/21 06:55:54 maxv Exp $ */ /* * Copyright-o-rama! @@ -1196,7 +1196,7 @@ lwp_32bit: movq PCB_GS(%r14),%rax movq %rax,(GUGS_SEL*8)(%rcx) - /* Set default 32bit values in %ds, %es and %fs. %gs is special. */ + /* Set default 32bit values in %ds, %es, %fs and %gs. */ movq L_MD_REGS(%r12),%rbx movq $GSEL(GUDATA32_SEL, SEL_UPL),%rax movw %ax,%ds @@ -1204,7 +1204,7 @@ lwp_32bit: movw %ax,%fs CLI(ax) SWAPGS - movw TF_GS(%rbx),%gs + movw %ax,%gs SWAPGS STI(ax) #else @@ -1486,6 +1486,9 @@ ENTRY(intrfastexit) movw TF_DS(%rsp),%ds movw TF_FS(%rsp),%fs SWAPGS +#ifndef XEN + movw TF_GS(%rsp),%gs +#endif jmp .Lkexit .Luexit64: Index: src/sys/arch/amd64/amd64/machdep.c diff -u src/sys/arch/amd64/amd64/machdep.c:1.271 src/sys/arch/amd64/amd64/machdep.c:1.272 --- src/sys/arch/amd64/amd64/machdep.c:1.271 Thu Oct 19 19:05:53 2017 +++ src/sys/arch/amd64/amd64/machdep.c Sat Oct 21 06:55:54 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.271 2017/10/19 19:05:53 maxv Exp $ */ +/* $NetBSD: machdep.c,v 1.272 2017/10/21 06:55:54 maxv Exp $ */ /* * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011 @@ -110,7 +110,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.271 2017/10/19 19:05:53 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.272 2017/10/21 06:55:54 maxv Exp $"); /* #define XENDEBUG_LOW */ @@ -2138,7 +2138,11 @@ cpu_fsgs_reload(struct lwp *l, int fssel kpreempt_disable(); update_descriptor(&curcpu()->ci_gdt[GUFS_SEL], &pcb->pcb_fs); update_descriptor(&curcpu()->ci_gdt[GUGS_SEL], &pcb->pcb_gs); + +#ifdef XEN setusergs(gssel); +#endif + tf->tf_fs = fssel; tf->tf_gs = gssel; kpreempt_enable(); Index: src/sys/arch/x86/x86/sys_machdep.c diff -u src/sys/arch/x86/x86/sys_machdep.c:1.41 src/sys/arch/x86/x86/sys_machdep.c:1.42 --- src/sys/arch/x86/x86/sys_machdep.c:1.41 Thu Oct 19 19:05:53 2017 +++ src/sys/arch/x86/x86/sys_machdep.c Sat Oct 21 06:55:54 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_machdep.c,v 1.41 2017/10/19 19:05:53 maxv Exp $ */ +/* $NetBSD: sys_machdep.c,v 1.42 2017/10/21 06:55:54 maxv Exp $ */ /* * Copyright (c) 1998, 2007, 2009, 2017 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: sys_machdep.c,v 1.41 2017/10/19 19:05:53 maxv Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sys_machdep.c,v 1.42 2017/10/21 06:55:54 maxv Exp $"); #include "opt_mtrr.h" #include "opt_pmc.h" @@ -608,7 +608,7 @@ x86_set_sdbase32(void *arg, char which, sizeof(struct segment_descriptor)); if (l == curlwp) { update_descriptor(&curcpu()->ci_gdt[GUGS_SEL], &usd); -#ifdef __x86_64__ +#if defined(__x86_64__) && defined(XEN) setusergs(GSEL(GUGS_SEL, SEL_UPL)); #endif }