Module Name: src Committed By: bouyer Date: Sun May 17 18:24:24 UTC 2009
Modified Files: src/sys/arch/i386/i386: gdt.c src/sys/arch/i386/include: segments.h src/sys/arch/x86/x86: sys_machdep.c Log Message: on Xen the GDT has to be updated though HYPERVISOR_update_descriptor(). Export i386/i386/gdt.c:update_descriptor() and use it in x86_set_sdbase(), as a direct write to the GDT will cause a kernel trap. Fix PR port-xen/41401. To generate a diff of this commit: cvs rdiff -u -r1.47 -r1.48 src/sys/arch/i386/i386/gdt.c cvs rdiff -u -r1.52 -r1.53 src/sys/arch/i386/include/segments.h cvs rdiff -u -r1.18 -r1.19 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/i386/i386/gdt.c diff -u src/sys/arch/i386/i386/gdt.c:1.47 src/sys/arch/i386/i386/gdt.c:1.48 --- src/sys/arch/i386/i386/gdt.c:1.47 Sat Mar 21 14:41:29 2009 +++ src/sys/arch/i386/i386/gdt.c Sun May 17 18:24:23 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: gdt.c,v 1.47 2009/03/21 14:41:29 ad Exp $ */ +/* $NetBSD: gdt.c,v 1.48 2009/05/17 18:24:23 bouyer Exp $ */ /*- * Copyright (c) 1996, 1997, 2009 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.47 2009/03/21 14:41:29 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: gdt.c,v 1.48 2009/05/17 18:24:23 bouyer Exp $"); #include "opt_multiprocessor.h" #include "opt_xen.h" @@ -66,7 +66,7 @@ int gdt_get_slot1(int); void gdt_put_slot1(int, int); -static void +void update_descriptor(union descriptor *table, union descriptor *entry) { #ifndef XEN Index: src/sys/arch/i386/include/segments.h diff -u src/sys/arch/i386/include/segments.h:1.52 src/sys/arch/i386/include/segments.h:1.53 --- src/sys/arch/i386/include/segments.h:1.52 Sat Mar 21 22:17:13 2009 +++ src/sys/arch/i386/include/segments.h Sun May 17 18:24:23 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: segments.h,v 1.52 2009/03/21 22:17:13 ad Exp $ */ +/* $NetBSD: segments.h,v 1.53 2009/05/17 18:24:23 bouyer Exp $ */ /*- * Copyright (c) 1990 The Regents of the University of California. @@ -197,6 +197,7 @@ void setgdt(int, const void *, size_t, int, int, int, int); void unsetgate(struct gate_descriptor *); void cpu_init_idt(void); +void update_descriptor(union descriptor *, union descriptor *); #if !defined(XEN) void idt_init(void); Index: src/sys/arch/x86/x86/sys_machdep.c diff -u src/sys/arch/x86/x86/sys_machdep.c:1.18 src/sys/arch/x86/x86/sys_machdep.c:1.19 --- src/sys/arch/x86/x86/sys_machdep.c:1.18 Sun Mar 29 09:24:52 2009 +++ src/sys/arch/x86/x86/sys_machdep.c Sun May 17 18:24:24 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: sys_machdep.c,v 1.18 2009/03/29 09:24:52 ad Exp $ */ +/* $NetBSD: sys_machdep.c,v 1.19 2009/05/17 18:24:24 bouyer Exp $ */ /*- * Copyright (c) 1998, 2007, 2009 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: sys_machdep.c,v 1.18 2009/03/29 09:24:52 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sys_machdep.c,v 1.19 2009/05/17 18:24:24 bouyer Exp $"); #include "opt_mtrr.h" #include "opt_perfctrs.h" @@ -591,7 +591,7 @@ x86_set_sdbase(void *arg, char which, lwp_t *l, bool direct) { #ifdef i386 - struct segment_descriptor sd; + union descriptor usd; struct pcb *pcb; vaddr_t base; int error; @@ -604,28 +604,30 @@ return error; } - sd.sd_lobase = base & 0xffffff; - sd.sd_hibase = (base >> 24) & 0xff; - sd.sd_lolimit = 0xffff; - sd.sd_hilimit = 0xf; - sd.sd_type = SDT_MEMRWA; - sd.sd_dpl = SEL_UPL; - sd.sd_p = 1; - sd.sd_xx = 0; - sd.sd_def32 = 1; - sd.sd_gran = 1; + usd.sd.sd_lobase = base & 0xffffff; + usd.sd.sd_hibase = (base >> 24) & 0xff; + usd.sd.sd_lolimit = 0xffff; + usd.sd.sd_hilimit = 0xf; + usd.sd.sd_type = SDT_MEMRWA; + usd.sd.sd_dpl = SEL_UPL; + usd.sd.sd_p = 1; + usd.sd.sd_xx = 0; + usd.sd.sd_def32 = 1; + usd.sd.sd_gran = 1; kpreempt_disable(); pcb = &l->l_addr->u_pcb; if (which == 'f') { - memcpy(&pcb->pcb_fsd, &sd, sizeof(sd)); + memcpy(&pcb->pcb_fsd, &usd.sd, + sizeof(struct segment_descriptor)); if (l == curlwp) { - memcpy(&curcpu()->ci_gdt[GUFS_SEL], &sd, sizeof(sd)); + update_descriptor(&curcpu()->ci_gdt[GUFS_SEL], &usd); } } else /* which == 'g' */ { - memcpy(&pcb->pcb_gsd, &sd, sizeof(sd)); + memcpy(&pcb->pcb_gsd, &usd.sd, + sizeof(struct segment_descriptor)); if (l == curlwp) { - memcpy(&curcpu()->ci_gdt[GUGS_SEL], &sd, sizeof(sd)); + update_descriptor(&curcpu()->ci_gdt[GUGS_SEL], &usd); } } kpreempt_enable();