Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch Improve our segregs model. Pass 3/3.
details: https://anonhg.NetBSD.org/src/rev/c6269f5d5588
branches: trunk
changeset: 356926:c6269f5d5588
user: maxv <maxv%NetBSD.org@localhost>
date: Sat Oct 21 06:55:54 2017 +0000
description:
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.
diffstat:
sys/arch/amd64/acpi/acpi_wakeup_low.S | 8 ++++----
sys/arch/amd64/amd64/locore.S | 9 ++++++---
sys/arch/amd64/amd64/machdep.c | 8 ++++++--
sys/arch/x86/x86/sys_machdep.c | 6 +++---
4 files changed, 19 insertions(+), 12 deletions(-)
diffs (116 lines):
diff -r bfd2cb13e85f -r c6269f5d5588 sys/arch/amd64/acpi/acpi_wakeup_low.S
--- a/sys/arch/amd64/acpi/acpi_wakeup_low.S Sat Oct 21 05:30:48 2017 +0000
+++ b/sys/arch/amd64/acpi/acpi_wakeup_low.S Sat Oct 21 06:55:54 2017 +0000
@@ -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 <joerg%netbsd.org@localhost>
@@ -47,9 +47,9 @@
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
diff -r bfd2cb13e85f -r c6269f5d5588 sys/arch/amd64/amd64/locore.S
--- a/sys/arch/amd64/amd64/locore.S Sat Oct 21 05:30:48 2017 +0000
+++ b/sys/arch/amd64/amd64/locore.S Sat Oct 21 06:55:54 2017 +0000
@@ -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 @@
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 @@
movw %ax,%fs
CLI(ax)
SWAPGS
- movw TF_GS(%rbx),%gs
+ movw %ax,%gs
SWAPGS
STI(ax)
#else
@@ -1486,6 +1486,9 @@
movw TF_DS(%rsp),%ds
movw TF_FS(%rsp),%fs
SWAPGS
+#ifndef XEN
+ movw TF_GS(%rsp),%gs
+#endif
jmp .Lkexit
.Luexit64:
diff -r bfd2cb13e85f -r c6269f5d5588 sys/arch/amd64/amd64/machdep.c
--- a/sys/arch/amd64/amd64/machdep.c Sat Oct 21 05:30:48 2017 +0000
+++ b/sys/arch/amd64/amd64/machdep.c Sat Oct 21 06:55:54 2017 +0000
@@ -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 @@
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();
diff -r bfd2cb13e85f -r c6269f5d5588 sys/arch/x86/x86/sys_machdep.c
--- a/sys/arch/x86/x86/sys_machdep.c Sat Oct 21 05:30:48 2017 +0000
+++ b/sys/arch/x86/x86/sys_machdep.c Sat Oct 21 06:55:54 2017 +0000
@@ -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 @@
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
}
Home |
Main Index |
Thread Index |
Old Index