Pull up the following revisions(s) (requested by bouyer in ticket #80): sys/arch/xen/x86/x86_xpmap.c: revision 1.42 sys/arch/x86/include/specialreg.h: revision 1.56 sys/arch/amd64/amd64/machdep.c: revision 1.179 sys/arch/i386/i386/locore.S: revision 1.97 sys/arch/i386/i386/machdep.c: revision 1.723 via patch sys/arch/x86/include/cpu.h: revision 1.49 Fix possible FPU registers corruption on context switches. Fix type of pointers passed to some hypercalls.diff -r1.175.2.1 -r1.175.2.2 src/sys/arch/amd64/amd64/machdep.c
(sborrill)
--- src/sys/arch/amd64/amd64/machdep.c 2012/02/23 18:37:12 1.175.2.1
+++ src/sys/arch/amd64/amd64/machdep.c 2012/03/05 20:18:01 1.175.2.2
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: machdep.c,v 1.175.2.1 2012/02/23 18:37:12 riz Exp $ */ | 1 | /* $NetBSD: machdep.c,v 1.175.2.2 2012/03/05 20:18:01 sborrill Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011 | 4 | * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011 | |
5 | * The NetBSD Foundation, Inc. | 5 | * The NetBSD Foundation, Inc. | |
6 | * All rights reserved. | 6 | * All rights reserved. | |
7 | * | 7 | * | |
8 | * This code is derived from software contributed to The NetBSD Foundation | 8 | * This code is derived from software contributed to The NetBSD Foundation | |
9 | * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace | 9 | * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace | |
10 | * Simulation Facility, NASA Ames Research Center. | 10 | * Simulation Facility, NASA Ames Research Center. | |
11 | * | 11 | * | |
12 | * This code is derived from software contributed to The NetBSD Foundation | 12 | * This code is derived from software contributed to The NetBSD Foundation | |
13 | * by Coyote Point Systems, Inc. which was written under contract to Coyote | 13 | * by Coyote Point Systems, Inc. which was written under contract to Coyote | |
14 | * Point by Jed Davis and Devon O'Dell. | 14 | * Point by Jed Davis and Devon O'Dell. | |
@@ -101,27 +101,27 @@ | @@ -101,27 +101,27 @@ | |||
101 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 101 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
102 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 102 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
103 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 103 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
104 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 104 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
105 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 105 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
106 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 106 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
107 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 107 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
108 | * SUCH DAMAGE. | 108 | * SUCH DAMAGE. | |
109 | * | 109 | * | |
110 | * @(#)machdep.c 7.4 (Berkeley) 6/3/91 | 110 | * @(#)machdep.c 7.4 (Berkeley) 6/3/91 | |
111 | */ | 111 | */ | |
112 | 112 | |||
113 | #include <sys/cdefs.h> | 113 | #include <sys/cdefs.h> | |
114 | __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.175.2.1 2012/02/23 18:37:12 riz Exp $"); | 114 | __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.175.2.2 2012/03/05 20:18:01 sborrill Exp $"); | |
115 | 115 | |||
116 | /* #define XENDEBUG_LOW */ | 116 | /* #define XENDEBUG_LOW */ | |
117 | 117 | |||
118 | #include "opt_modular.h" | 118 | #include "opt_modular.h" | |
119 | #include "opt_user_ldt.h" | 119 | #include "opt_user_ldt.h" | |
120 | #include "opt_ddb.h" | 120 | #include "opt_ddb.h" | |
121 | #include "opt_kgdb.h" | 121 | #include "opt_kgdb.h" | |
122 | #include "opt_cpureset_delay.h" | 122 | #include "opt_cpureset_delay.h" | |
123 | #include "opt_mtrr.h" | 123 | #include "opt_mtrr.h" | |
124 | #include "opt_realmem.h" | 124 | #include "opt_realmem.h" | |
125 | #include "opt_xen.h" | 125 | #include "opt_xen.h" | |
126 | #ifndef XEN | 126 | #ifndef XEN | |
127 | #include "opt_physmem.h" | 127 | #include "opt_physmem.h" | |
@@ -404,43 +404,73 @@ cpu_startup(void) | @@ -404,43 +404,73 @@ cpu_startup(void) | |||
404 | cpu_init_tss(&cpu_info_primary); | 404 | cpu_init_tss(&cpu_info_primary); | |
405 | #if !defined(XEN) | 405 | #if !defined(XEN) | |
406 | ltr(cpu_info_primary.ci_tss_sel); | 406 | ltr(cpu_info_primary.ci_tss_sel); | |
407 | #endif /* !defined(XEN) */ | 407 | #endif /* !defined(XEN) */ | |
408 | 408 | |||
409 | x86_startup(); | 409 | x86_startup(); | |
410 | } | 410 | } | |
411 | 411 | |||
412 | #ifdef XEN | 412 | #ifdef XEN | |
413 | /* used in assembly */ | 413 | /* used in assembly */ | |
414 | void hypervisor_callback(void); | 414 | void hypervisor_callback(void); | |
415 | void failsafe_callback(void); | 415 | void failsafe_callback(void); | |
416 | void x86_64_switch_context(struct pcb *); | 416 | void x86_64_switch_context(struct pcb *); | |
417 | void x86_64_tls_switch(struct lwp *); | |||
417 | 418 | |||
418 | void | 419 | void | |
419 | x86_64_switch_context(struct pcb *new) | 420 | x86_64_switch_context(struct pcb *new) | |
420 | { | 421 | { | |
421 | struct cpu_info *ci; | |||
422 | ci = curcpu(); | |||
423 | HYPERVISOR_stack_switch(GSEL(GDATA_SEL, SEL_KPL), new->pcb_rsp0); | 422 | HYPERVISOR_stack_switch(GSEL(GDATA_SEL, SEL_KPL), new->pcb_rsp0); | |
424 | struct physdev_op physop; | 423 | struct physdev_op physop; | |
425 | physop.cmd = PHYSDEVOP_SET_IOPL; | 424 | physop.cmd = PHYSDEVOP_SET_IOPL; | |
426 | physop.u.set_iopl.iopl = new->pcb_iopl; | 425 | physop.u.set_iopl.iopl = new->pcb_iopl; | |
427 | HYPERVISOR_physdev_op(&physop); | 426 | HYPERVISOR_physdev_op(&physop); | |
428 | if (new->pcb_fpcpu != ci) { | 427 | } | |
428 | ||||
429 | void | |||
430 | x86_64_tls_switch(struct lwp *l) | |||
431 | { | |||
432 | struct cpu_info *ci = curcpu(); | |||
433 | struct pcb *pcb = lwp_getpcb(l); | |||
434 | struct trapframe *tf = l->l_md.md_regs; | |||
435 | ||||
436 | /* | |||
437 | * Raise the IPL to IPL_HIGH. | |||
438 | * FPU IPIs can alter the LWP's saved cr0. Dropping the priority | |||
439 | * is deferred until mi_switch(), when cpu_switchto() returns. | |||
440 | */ | |||
441 | (void)splhigh(); | |||
442 | /* | |||
443 | * If our floating point registers are on a different CPU, | |||
444 | * set CR0_TS so we'll trap rather than reuse bogus state. | |||
445 | */ | |||
446 | if (l != ci->ci_fpcurlwp) { | |||
429 | HYPERVISOR_fpu_taskswitch(1); | 447 | HYPERVISOR_fpu_taskswitch(1); | |
430 | } | 448 | } | |
431 | } | |||
432 | 449 | |||
433 | #endif | 450 | /* Update TLS segment pointers */ | |
451 | if (pcb->pcb_flags & PCB_COMPAT32) { | |||
452 | update_descriptor(&curcpu()->ci_gdt[GUFS_SEL], &pcb->pcb_fs); | |||
453 | update_descriptor(&curcpu()->ci_gdt[GUGS_SEL], &pcb->pcb_gs); | |||
454 | setfs(tf->tf_fs); | |||
455 | HYPERVISOR_set_segment_base(SEGBASE_GS_USER_SEL, tf->tf_gs); | |||
456 | } else { | |||
457 | setfs(0); | |||
458 | HYPERVISOR_set_segment_base(SEGBASE_GS_USER_SEL, 0); | |||
459 | HYPERVISOR_set_segment_base(SEGBASE_FS, pcb->pcb_fs); | |||
460 | HYPERVISOR_set_segment_base(SEGBASE_GS_USER, pcb->pcb_gs); | |||
461 | } | |||
462 | } | |||
463 | #endif /* XEN */ | |||
434 | 464 | |||
435 | /* | 465 | /* | |
436 | * Set up proc0's TSS and LDT. | 466 | * Set up proc0's TSS and LDT. | |
437 | */ | 467 | */ | |
438 | void | 468 | void | |
439 | x86_64_proc0_tss_ldt_init(void) | 469 | x86_64_proc0_tss_ldt_init(void) | |
440 | { | 470 | { | |
441 | struct lwp *l = &lwp0; | 471 | struct lwp *l = &lwp0; | |
442 | struct pcb *pcb = lwp_getpcb(l); | 472 | struct pcb *pcb = lwp_getpcb(l); | |
443 | 473 | |||
444 | pcb->pcb_flags = 0; | 474 | pcb->pcb_flags = 0; | |
445 | pcb->pcb_fs = 0; | 475 | pcb->pcb_fs = 0; | |
446 | pcb->pcb_gs = 0; | 476 | pcb->pcb_gs = 0; | |
@@ -2287,48 +2317,26 @@ cpu_fsgs_reload(struct lwp *l, int fssel | @@ -2287,48 +2317,26 @@ cpu_fsgs_reload(struct lwp *l, int fssel | |||
2287 | setusergs(gssel); | 2317 | setusergs(gssel); | |
2288 | #else | 2318 | #else | |
2289 | HYPERVISOR_set_segment_base(SEGBASE_GS_USER_SEL, gssel); | 2319 | HYPERVISOR_set_segment_base(SEGBASE_GS_USER_SEL, gssel); | |
2290 | #endif | 2320 | #endif | |
2291 | tf->tf_fs = fssel; | 2321 | tf->tf_fs = fssel; | |
2292 | tf->tf_gs = gssel; | 2322 | tf->tf_gs = gssel; | |
2293 | kpreempt_enable(); | 2323 | kpreempt_enable(); | |
2294 | } else { | 2324 | } else { | |
2295 | tf->tf_fs = fssel; | 2325 | tf->tf_fs = fssel; | |
2296 | tf->tf_gs = gssel; | 2326 | tf->tf_gs = gssel; | |
2297 | } | 2327 | } | |
2298 | } | 2328 | } | |
2299 | 2329 | |||
2300 | #ifdef XEN | |||
2301 | void x86_64_tls_switch(struct lwp *); | |||
2302 | ||||
2303 | void | |||
2304 | x86_64_tls_switch(struct lwp *l) | |||
2305 | { | |||
2306 | struct pcb *pcb = lwp_getpcb(l); | |||
2307 | struct trapframe *tf = l->l_md.md_regs; | |||
2308 | ||||
2309 | if (pcb->pcb_flags & PCB_COMPAT32) { | |||
2310 | update_descriptor(&curcpu()->ci_gdt[GUFS_SEL], &pcb->pcb_fs); | |||
2311 | update_descriptor(&curcpu()->ci_gdt[GUGS_SEL], &pcb->pcb_gs); | |||
2312 | setfs(tf->tf_fs); | |||
2313 | HYPERVISOR_set_segment_base(SEGBASE_GS_USER_SEL, tf->tf_gs); | |||
2314 | } else { | |||
2315 | setfs(0); | |||
2316 | HYPERVISOR_set_segment_base(SEGBASE_GS_USER_SEL, 0); | |||
2317 | HYPERVISOR_set_segment_base(SEGBASE_FS, pcb->pcb_fs); | |||
2318 | HYPERVISOR_set_segment_base(SEGBASE_GS_USER, pcb->pcb_gs); | |||
2319 | } | |||
2320 | } | |||
2321 | #endif | |||
2322 | 2330 | |||
2323 | #ifdef __HAVE_DIRECT_MAP | 2331 | #ifdef __HAVE_DIRECT_MAP | |
2324 | bool | 2332 | bool | |
2325 | mm_md_direct_mapped_io(void *addr, paddr_t *paddr) | 2333 | mm_md_direct_mapped_io(void *addr, paddr_t *paddr) | |
2326 | { | 2334 | { | |
2327 | vaddr_t va = (vaddr_t)addr; | 2335 | vaddr_t va = (vaddr_t)addr; | |
2328 | 2336 | |||
2329 | if (va >= PMAP_DIRECT_BASE && va < PMAP_DIRECT_END) { | 2337 | if (va >= PMAP_DIRECT_BASE && va < PMAP_DIRECT_END) { | |
2330 | *paddr = PMAP_DIRECT_UNMAP(va); | 2338 | *paddr = PMAP_DIRECT_UNMAP(va); | |
2331 | return true; | 2339 | return true; | |
2332 | } | 2340 | } | |
2333 | return false; | 2341 | return false; | |
2334 | } | 2342 | } |
--- src/sys/arch/i386/i386/locore.S 2011/03/18 15:18:16 1.95
+++ src/sys/arch/i386/i386/locore.S 2012/03/05 20:18:01 1.95.10.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: locore.S,v 1.95 2011/03/18 15:18:16 joerg Exp $ */ | 1 | /* $NetBSD: locore.S,v 1.95.10.1 2012/03/05 20:18:01 sborrill Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright-o-rama! | 4 | * Copyright-o-rama! | |
5 | */ | 5 | */ | |
6 | 6 | |||
7 | /* | 7 | /* | |
8 | * Copyright (c) 2006 Manuel Bouyer. | 8 | * Copyright (c) 2006 Manuel Bouyer. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -119,27 +119,27 @@ | @@ -119,27 +119,27 @@ | |||
119 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 119 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
120 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 120 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
121 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 121 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
122 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 122 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
123 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 123 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
124 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 124 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
125 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 125 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
126 | * SUCH DAMAGE. | 126 | * SUCH DAMAGE. | |
127 | * | 127 | * | |
128 | * @(#)locore.s 7.3 (Berkeley) 5/13/91 | 128 | * @(#)locore.s 7.3 (Berkeley) 5/13/91 | |
129 | */ | 129 | */ | |
130 | 130 | |||
131 | #include <machine/asm.h> | 131 | #include <machine/asm.h> | |
132 | __KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.95 2011/03/18 15:18:16 joerg Exp $"); | 132 | __KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.95.10.1 2012/03/05 20:18:01 sborrill Exp $"); | |
133 | 133 | |||
134 | #include "opt_compat_oldboot.h" | 134 | #include "opt_compat_oldboot.h" | |
135 | #include "opt_ddb.h" | 135 | #include "opt_ddb.h" | |
136 | #include "opt_modular.h" | 136 | #include "opt_modular.h" | |
137 | #include "opt_multiboot.h" | 137 | #include "opt_multiboot.h" | |
138 | #include "opt_realmem.h" | 138 | #include "opt_realmem.h" | |
139 | #include "opt_vm86.h" | 139 | #include "opt_vm86.h" | |
140 | #include "opt_xen.h" | 140 | #include "opt_xen.h" | |
141 | 141 | |||
142 | #include "npx.h" | 142 | #include "npx.h" | |
143 | #include "assym.h" | 143 | #include "assym.h" | |
144 | #include "lapic.h" | 144 | #include "lapic.h" | |
145 | #include "ioapic.h" | 145 | #include "ioapic.h" | |
@@ -989,83 +989,89 @@ ENTRY(cpu_switchto) | @@ -989,83 +989,89 @@ ENTRY(cpu_switchto) | |||
989 | * non-interlocked mutex release. | 989 | * non-interlocked mutex release. | |
990 | */ | 990 | */ | |
991 | movl %edi,%ecx | 991 | movl %edi,%ecx | |
992 | xchgl %ecx,CPUVAR(CURLWP) | 992 | xchgl %ecx,CPUVAR(CURLWP) | |
993 | 993 | |||
994 | /* Skip the rest if returning to a pinned LWP. */ | 994 | /* Skip the rest if returning to a pinned LWP. */ | |
995 | testl %edx,%edx | 995 | testl %edx,%edx | |
996 | jnz 4f | 996 | jnz 4f | |
997 | 997 | |||
998 | #ifdef XEN | 998 | #ifdef XEN | |
999 | pushl %edi | 999 | pushl %edi | |
1000 | call _C_LABEL(i386_switch_context) | 1000 | call _C_LABEL(i386_switch_context) | |
1001 | addl $4,%esp | 1001 | addl $4,%esp | |
1002 | #else /* XEN */ | 1002 | #else /* !XEN */ | |
1003 | /* Switch ring0 esp */ | 1003 | /* Switch ring0 esp */ | |
1004 | movl PCB_ESP0(%ebx),%eax | 1004 | movl PCB_ESP0(%ebx),%eax | |
1005 | movl %eax,CPUVAR(ESP0) | 1005 | movl %eax,CPUVAR(ESP0) | |
1006 | #endif /* !XEN */ | |||
1006 | 1007 | |||
1007 | /* Don't bother with the rest if switching to a system process. */ | 1008 | /* Don't bother with the rest if switching to a system process. */ | |
1008 | testl $LW_SYSTEM,L_FLAG(%edi) | 1009 | testl $LW_SYSTEM,L_FLAG(%edi) | |
1009 | jnz 4f | 1010 | jnz 4f | |
1010 | 1011 | |||
1012 | #ifndef XEN | |||
1011 | /* Restore thread-private %fs/%gs descriptors. */ | 1013 | /* Restore thread-private %fs/%gs descriptors. */ | |
1012 | movl CPUVAR(GDT),%ecx | 1014 | movl CPUVAR(GDT),%ecx | |
1013 | movl PCB_FSD(%ebx), %eax | 1015 | movl PCB_FSD(%ebx), %eax | |
1014 | movl PCB_FSD+4(%ebx), %edx | 1016 | movl PCB_FSD+4(%ebx), %edx | |
1015 | movl %eax, (GUFS_SEL*8)(%ecx) | 1017 | movl %eax, (GUFS_SEL*8)(%ecx) | |
1016 | movl %edx, (GUFS_SEL*8+4)(%ecx) | 1018 | movl %edx, (GUFS_SEL*8+4)(%ecx) | |
1017 | movl PCB_GSD(%ebx), %eax | 1019 | movl PCB_GSD(%ebx), %eax | |
1018 | movl PCB_GSD+4(%ebx), %edx | 1020 | movl PCB_GSD+4(%ebx), %edx | |
1019 | movl %eax, (GUGS_SEL*8)(%ecx) | 1021 | movl %eax, (GUGS_SEL*8)(%ecx) | |
1020 | movl %edx, (GUGS_SEL*8+4)(%ecx) | 1022 | movl %edx, (GUGS_SEL*8+4)(%ecx) | |
1021 | #endif /* XEN */ | 1023 | #endif /* !XEN */ | |
1022 | 1024 | |||
1023 | /* Switch I/O bitmap */ | 1025 | /* Switch I/O bitmap */ | |
1024 | movl PCB_IOMAP(%ebx),%eax | 1026 | movl PCB_IOMAP(%ebx),%eax | |
1025 | orl %eax,%eax | 1027 | orl %eax,%eax | |
1026 | jnz .Lcopy_iobitmap | 1028 | jnz .Lcopy_iobitmap | |
1027 | movl $(IOMAP_INVALOFF << 16),CPUVAR(IOBASE) | 1029 | movl $(IOMAP_INVALOFF << 16),CPUVAR(IOBASE) | |
1028 | .Liobitmap_done: | 1030 | .Liobitmap_done: | |
1029 | 1031 | |||
1030 | /* Is this process using RAS (restartable atomic sequences)? */ | 1032 | /* Is this process using RAS (restartable atomic sequences)? */ | |
1031 | movl L_PROC(%edi),%eax | 1033 | movl L_PROC(%edi),%eax | |
1032 | cmpl $0,P_RASLIST(%eax) | 1034 | cmpl $0,P_RASLIST(%eax) | |
1033 | jne 5f | 1035 | jne 5f | |
1034 | 1036 | |||
1035 | /* | 1037 | /* | |
1036 | * Restore cr0 (including FPU state). Raise the IPL to IPL_HIGH. | 1038 | * Restore cr0 (including FPU state). Raise the IPL to IPL_HIGH. | |
1037 | * FPU IPIs can alter the LWP's saved cr0. Dropping the priority | 1039 | * FPU IPIs can alter the LWP's saved cr0. Dropping the priority | |
1038 | * is deferred until mi_switch(), when cpu_switchto() returns. | 1040 | * is deferred until mi_switch(), when cpu_switchto() returns. | |
1039 | */ | 1041 | */ | |
1040 | 2: | 1042 | 2: | |
1041 | #ifndef XEN | 1043 | #ifdef XEN | |
1044 | pushl %edi | |||
1045 | call _C_LABEL(i386_tls_switch) | |||
1046 | addl $4,%esp | |||
1047 | #else /* !XEN */ | |||
1042 | movl $IPL_HIGH,CPUVAR(ILEVEL) | 1048 | movl $IPL_HIGH,CPUVAR(ILEVEL) | |
1043 | movl PCB_CR0(%ebx),%ecx /* has CR0_TS clear */ | 1049 | movl PCB_CR0(%ebx),%ecx /* has CR0_TS clear */ | |
1044 | movl %cr0,%edx | 1050 | movl %cr0,%edx | |
1045 | 1051 | |||
1046 | /* | 1052 | /* | |
1047 | * If our floating point registers are on a different CPU, | 1053 | * If our floating point registers are on a different CPU, | |
1048 | * set CR0_TS so we'll trap rather than reuse bogus state. | 1054 | * set CR0_TS so we'll trap rather than reuse bogus state. | |
1049 | */ | 1055 | */ | |
1050 | cmpl CPUVAR(FPCURLWP),%edi | 1056 | cmpl CPUVAR(FPCURLWP),%edi | |
1051 | je 3f | 1057 | je 3f | |
1052 | orl $CR0_TS,%ecx | 1058 | orl $CR0_TS,%ecx | |
1053 | 1059 | |||
1054 | /* Reloading CR0 is very expensive - avoid if possible. */ | 1060 | /* Reloading CR0 is very expensive - avoid if possible. */ | |
1055 | 3: cmpl %edx,%ecx | 1061 | 3: cmpl %edx,%ecx | |
1056 | je 4f | 1062 | je 4f | |
1057 | movl %ecx,%cr0 | 1063 | movl %ecx,%cr0 | |
1058 | #endif /* XEN */ | 1064 | #endif /* !XEN */ | |
1059 | 1065 | |||
1060 | /* Return to the new LWP, returning 'oldlwp' in %eax. */ | 1066 | /* Return to the new LWP, returning 'oldlwp' in %eax. */ | |
1061 | 4: movl %esi,%eax | 1067 | 4: movl %esi,%eax | |
1062 | popl %edi | 1068 | popl %edi | |
1063 | popl %esi | 1069 | popl %esi | |
1064 | popl %ebx | 1070 | popl %ebx | |
1065 | ret | 1071 | ret | |
1066 | 1072 | |||
1067 | /* Check for restartable atomic sequences (RAS). */ | 1073 | /* Check for restartable atomic sequences (RAS). */ | |
1068 | 5: movl L_MD_REGS(%edi),%ecx | 1074 | 5: movl L_MD_REGS(%edi),%ecx | |
1069 | pushl TF_EIP(%ecx) | 1075 | pushl TF_EIP(%ecx) | |
1070 | pushl %eax | 1076 | pushl %eax | |
1071 | call _C_LABEL(ras_lookup) | 1077 | call _C_LABEL(ras_lookup) |
--- src/sys/arch/i386/i386/machdep.c 2012/02/27 20:29:36 1.717.2.3
+++ src/sys/arch/i386/i386/machdep.c 2012/03/05 20:18:02 1.717.2.4
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: machdep.c,v 1.717.2.3 2012/02/27 20:29:36 riz Exp $ */ | 1 | /* $NetBSD: machdep.c,v 1.717.2.4 2012/03/05 20:18:02 sborrill Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009 | 4 | * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009 | |
5 | * The NetBSD Foundation, Inc. | 5 | * The NetBSD Foundation, Inc. | |
6 | * All rights reserved. | 6 | * All rights reserved. | |
7 | * | 7 | * | |
8 | * This code is derived from software contributed to The NetBSD Foundation | 8 | * This code is derived from software contributed to The NetBSD Foundation | |
9 | * by Charles M. Hannum, by Jason R. Thorpe of the Numerical Aerospace | 9 | * by Charles M. Hannum, by Jason R. Thorpe of the Numerical Aerospace | |
10 | * Simulation Facility NASA Ames Research Center, by Julio M. Merino Vidal, | 10 | * Simulation Facility NASA Ames Research Center, by Julio M. Merino Vidal, | |
11 | * and by Andrew Doran. | 11 | * and by Andrew Doran. | |
12 | * | 12 | * | |
13 | * Redistribution and use in source and binary forms, with or without | 13 | * Redistribution and use in source and binary forms, with or without | |
14 | * modification, are permitted provided that the following conditions | 14 | * modification, are permitted provided that the following conditions | |
@@ -57,27 +57,27 @@ | @@ -57,27 +57,27 @@ | |||
57 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | 57 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
58 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 58 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
59 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 59 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
60 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 60 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
61 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | 61 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
62 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | 62 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
63 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 63 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
64 | * SUCH DAMAGE. | 64 | * SUCH DAMAGE. | |
65 | * | 65 | * | |
66 | * @(#)machdep.c 7.4 (Berkeley) 6/3/91 | 66 | * @(#)machdep.c 7.4 (Berkeley) 6/3/91 | |
67 | */ | 67 | */ | |
68 | 68 | |||
69 | #include <sys/cdefs.h> | 69 | #include <sys/cdefs.h> | |
70 | __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.717.2.3 2012/02/27 20:29:36 riz Exp $"); | 70 | __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.717.2.4 2012/03/05 20:18:02 sborrill Exp $"); | |
71 | 71 | |||
72 | #include "opt_beep.h" | 72 | #include "opt_beep.h" | |
73 | #include "opt_compat_ibcs2.h" | 73 | #include "opt_compat_ibcs2.h" | |
74 | #include "opt_compat_freebsd.h" | 74 | #include "opt_compat_freebsd.h" | |
75 | #include "opt_compat_netbsd.h" | 75 | #include "opt_compat_netbsd.h" | |
76 | #include "opt_compat_svr4.h" | 76 | #include "opt_compat_svr4.h" | |
77 | #include "opt_cpureset_delay.h" | 77 | #include "opt_cpureset_delay.h" | |
78 | #include "opt_ddb.h" | 78 | #include "opt_ddb.h" | |
79 | #include "opt_ipkdb.h" | 79 | #include "opt_ipkdb.h" | |
80 | #include "opt_kgdb.h" | 80 | #include "opt_kgdb.h" | |
81 | #include "opt_mtrr.h" | 81 | #include "opt_mtrr.h" | |
82 | #include "opt_modular.h" | 82 | #include "opt_modular.h" | |
83 | #include "opt_multiboot.h" | 83 | #include "opt_multiboot.h" | |
@@ -520,61 +520,84 @@ i386_proc0_tss_ldt_init(void) | @@ -520,61 +520,84 @@ i386_proc0_tss_ldt_init(void) | |||
520 | HYPERVISOR_fpu_taskswitch(1); | 520 | HYPERVISOR_fpu_taskswitch(1); | |
521 | XENPRINTF(("lwp tss sp %p ss %04x/%04x\n", | 521 | XENPRINTF(("lwp tss sp %p ss %04x/%04x\n", | |
522 | (void *)pcb->pcb_esp0, | 522 | (void *)pcb->pcb_esp0, | |
523 | GSEL(GDATA_SEL, SEL_KPL), | 523 | GSEL(GDATA_SEL, SEL_KPL), | |
524 | IDXSEL(GSEL(GDATA_SEL, SEL_KPL)))); | 524 | IDXSEL(GSEL(GDATA_SEL, SEL_KPL)))); | |
525 | HYPERVISOR_stack_switch(GSEL(GDATA_SEL, SEL_KPL), pcb->pcb_esp0); | 525 | HYPERVISOR_stack_switch(GSEL(GDATA_SEL, SEL_KPL), pcb->pcb_esp0); | |
526 | #endif | 526 | #endif | |
527 | } | 527 | } | |
528 | 528 | |||
529 | #ifdef XEN | 529 | #ifdef XEN | |
530 | /* Shim for curcpu() until %fs is ready */ | 530 | /* Shim for curcpu() until %fs is ready */ | |
531 | extern struct cpu_info * (*xpq_cpu)(void); | 531 | extern struct cpu_info * (*xpq_cpu)(void); | |
532 | 532 | |||
533 | /* used in assembly */ | |||
534 | void i386_switch_context(lwp_t *); | |||
535 | void i386_tls_switch(lwp_t *); | |||
536 | ||||
533 | /* | 537 | /* | |
534 | * Switch context: | 538 | * Switch context: | |
535 | * - honor CR0_TS in saved CR0 and request DNA exception on FPU use | |||
536 | * - switch stack pointer for user->kernel transition | 539 | * - switch stack pointer for user->kernel transition | |
537 | */ | 540 | */ | |
538 | void | 541 | void | |
539 | i386_switch_context(lwp_t *l) | 542 | i386_switch_context(lwp_t *l) | |
540 | { | 543 | { | |
541 | struct cpu_info *ci; | 544 | struct cpu_info *ci; | |
542 | struct pcb *pcb; | 545 | struct pcb *pcb; | |
543 | struct physdev_op physop; | 546 | struct physdev_op physop; | |
544 | 547 | |||
545 | pcb = lwp_getpcb(l); | 548 | pcb = lwp_getpcb(l); | |
546 | ci = curcpu(); | 549 | ci = curcpu(); | |
547 | if (pcb->pcb_fpcpu != ci) { | |||
548 | HYPERVISOR_fpu_taskswitch(1); | |||
549 | } | |||
550 | 550 | |||
551 | HYPERVISOR_stack_switch(GSEL(GDATA_SEL, SEL_KPL), pcb->pcb_esp0); | 551 | HYPERVISOR_stack_switch(GSEL(GDATA_SEL, SEL_KPL), pcb->pcb_esp0); | |
552 | 552 | |||
553 | physop.cmd = PHYSDEVOP_SET_IOPL; | |||
554 | physop.u.set_iopl.iopl = pcb->pcb_iopl; | |||
555 | HYPERVISOR_physdev_op(&physop); | |||
556 | } | |||
557 | ||||
558 | void | |||
559 | i386_tls_switch(lwp_t *l) | |||
560 | { | |||
561 | struct cpu_info *ci = curcpu(); | |||
562 | struct pcb *pcb = lwp_getpcb(l); | |||
563 | /* | |||
564 | * Raise the IPL to IPL_HIGH. | |||
565 | * FPU IPIs can alter the LWP's saved cr0. Dropping the priority | |||
566 | * is deferred until mi_switch(), when cpu_switchto() returns. | |||
567 | */ | |||
568 | (void)splhigh(); | |||
569 | ||||
570 | /* | |||
571 | * If our floating point registers are on a different CPU, | |||
572 | * set CR0_TS so we'll trap rather than reuse bogus state. | |||
573 | */ | |||
574 | ||||
575 | if (l != ci->ci_fpcurlwp) { | |||
576 | HYPERVISOR_fpu_taskswitch(1); | |||
577 | } | |||
578 | ||||
553 | /* Update TLS segment pointers */ | 579 | /* Update TLS segment pointers */ | |
554 | update_descriptor(&ci->ci_gdt[GUFS_SEL], | 580 | update_descriptor(&ci->ci_gdt[GUFS_SEL], | |
555 | (union descriptor *) &pcb->pcb_fsd); | 581 | (union descriptor *) &pcb->pcb_fsd); | |
556 | update_descriptor(&ci->ci_gdt[GUGS_SEL], | 582 | update_descriptor(&ci->ci_gdt[GUGS_SEL], | |
557 | (union descriptor *) &pcb->pcb_gsd); | 583 | (union descriptor *) &pcb->pcb_gsd); | |
558 | 584 | |||
559 | /* setup curcpu() to use %fs now */ | 585 | /* setup curcpu() to use %fs now */ | |
560 | /* XXX: find a way to do this, just once */ | 586 | /* XXX: find a way to do this, just once */ | |
561 | if (__predict_false(xpq_cpu != x86_curcpu)) { | 587 | if (__predict_false(xpq_cpu != x86_curcpu)) { | |
562 | xpq_cpu = x86_curcpu; | 588 | xpq_cpu = x86_curcpu; | |
563 | } | 589 | } | |
564 | 590 | |||
565 | physop.cmd = PHYSDEVOP_SET_IOPL; | |||
566 | physop.u.set_iopl.iopl = pcb->pcb_iopl; | |||
567 | HYPERVISOR_physdev_op(&physop); | |||
568 | } | 591 | } | |
569 | #endif /* XEN */ | 592 | #endif /* XEN */ | |
570 | 593 | |||
571 | #ifndef XEN | 594 | #ifndef XEN | |
572 | /* | 595 | /* | |
573 | * Set up TSS and I/O bitmap. | 596 | * Set up TSS and I/O bitmap. | |
574 | */ | 597 | */ | |
575 | void | 598 | void | |
576 | cpu_init_tss(struct cpu_info *ci) | 599 | cpu_init_tss(struct cpu_info *ci) | |
577 | { | 600 | { | |
578 | struct i386tss *tss = &ci->ci_tss; | 601 | struct i386tss *tss = &ci->ci_tss; | |
579 | 602 | |||
580 | tss->tss_iobase = IOMAP_INVALOFF << 16; | 603 | tss->tss_iobase = IOMAP_INVALOFF << 16; |
--- src/sys/arch/x86/include/cpu.h 2012/02/22 18:56:47 1.47.2.1
+++ src/sys/arch/x86/include/cpu.h 2012/03/05 20:18:02 1.47.2.2
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: cpu.h,v 1.47.2.1 2012/02/22 18:56:47 riz Exp $ */ | 1 | /* $NetBSD: cpu.h,v 1.47.2.2 2012/03/05 20:18:02 sborrill Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1990 The Regents of the University of California. | 4 | * Copyright (c) 1990 The Regents of the University of California. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to Berkeley by | 7 | * This code is derived from software contributed to Berkeley by | |
8 | * William Jolitz. | 8 | * William Jolitz. | |
9 | * | 9 | * | |
10 | * Redistribution and use in source and binary forms, with or without | 10 | * Redistribution and use in source and binary forms, with or without | |
11 | * modification, are permitted provided that the following conditions | 11 | * modification, are permitted provided that the following conditions | |
12 | * are met: | 12 | * are met: | |
13 | * 1. Redistributions of source code must retain the above copyright | 13 | * 1. Redistributions of source code must retain the above copyright | |
14 | * notice, this list of conditions and the following disclaimer. | 14 | * notice, this list of conditions and the following disclaimer. | |
@@ -394,27 +394,26 @@ void cpu_probe(struct cpu_info *); | @@ -394,27 +394,26 @@ void cpu_probe(struct cpu_info *); | |||
394 | void cpu_identify(struct cpu_info *); | 394 | void cpu_identify(struct cpu_info *); | |
395 | 395 | |||
396 | /* cpu_topology.c */ | 396 | /* cpu_topology.c */ | |
397 | void x86_cpu_topology(struct cpu_info *); | 397 | void x86_cpu_topology(struct cpu_info *); | |
398 | 398 | |||
399 | /* vm_machdep.c */ | 399 | /* vm_machdep.c */ | |
400 | void cpu_proc_fork(struct proc *, struct proc *); | 400 | void cpu_proc_fork(struct proc *, struct proc *); | |
401 | 401 | |||
402 | /* locore.s */ | 402 | /* locore.s */ | |
403 | struct region_descriptor; | 403 | struct region_descriptor; | |
404 | void lgdt(struct region_descriptor *); | 404 | void lgdt(struct region_descriptor *); | |
405 | #ifdef XEN | 405 | #ifdef XEN | |
406 | void lgdt_finish(void); | 406 | void lgdt_finish(void); | |
407 | void i386_switch_context(lwp_t *); | |||
408 | #endif | 407 | #endif | |
409 | 408 | |||
410 | struct pcb; | 409 | struct pcb; | |
411 | void savectx(struct pcb *); | 410 | void savectx(struct pcb *); | |
412 | void lwp_trampoline(void); | 411 | void lwp_trampoline(void); | |
413 | void child_trampoline(void); | 412 | void child_trampoline(void); | |
414 | #ifdef XEN | 413 | #ifdef XEN | |
415 | void startrtclock(void); | 414 | void startrtclock(void); | |
416 | void xen_delay(unsigned int); | 415 | void xen_delay(unsigned int); | |
417 | void xen_initclocks(void); | 416 | void xen_initclocks(void); | |
418 | void xen_suspendclocks(struct cpu_info *); | 417 | void xen_suspendclocks(struct cpu_info *); | |
419 | void xen_resumeclocks(struct cpu_info *); | 418 | void xen_resumeclocks(struct cpu_info *); | |
420 | #else | 419 | #else |
--- src/sys/arch/x86/include/specialreg.h 2011/12/15 09:38:21 1.55
+++ src/sys/arch/x86/include/specialreg.h 2012/03/05 20:18:03 1.55.2.1
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: specialreg.h,v 1.55 2011/12/15 09:38:21 abs Exp $ */ | 1 | /* $NetBSD: specialreg.h,v 1.55.2.1 2012/03/05 20:18:03 sborrill Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1991 The Regents of the University of California. | 4 | * Copyright (c) 1991 The Regents of the University of California. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without | |
8 | * modification, are permitted provided that the following conditions | 8 | * modification, are permitted provided that the following conditions | |
9 | * are met: | 9 | * are met: | |
10 | * 1. Redistributions of source code must retain the above copyright | 10 | * 1. Redistributions of source code must retain the above copyright | |
11 | * notice, this list of conditions and the following disclaimer. | 11 | * notice, this list of conditions and the following disclaimer. | |
12 | * 2. Redistributions in binary form must reproduce the above copyright | 12 | * 2. Redistributions in binary form must reproduce the above copyright | |
13 | * notice, this list of conditions and the following disclaimer in the | 13 | * notice, this list of conditions and the following disclaimer in the | |
14 | * documentation and/or other materials provided with the distribution. | 14 | * documentation and/or other materials provided with the distribution. | |
@@ -297,27 +297,27 @@ | @@ -297,27 +297,27 @@ | |||
297 | "\34OSXSAVE\35AVX\36F16C\37B30\40RAZ" | 297 | "\34OSXSAVE\35AVX\36F16C\37B30\40RAZ" | |
298 | 298 | |||
299 | #define CPUID2FAMILY(cpuid) (((cpuid) >> 8) & 0xf) | 299 | #define CPUID2FAMILY(cpuid) (((cpuid) >> 8) & 0xf) | |
300 | #define CPUID2MODEL(cpuid) (((cpuid) >> 4) & 0xf) | 300 | #define CPUID2MODEL(cpuid) (((cpuid) >> 4) & 0xf) | |
301 | #define CPUID2STEPPING(cpuid) ((cpuid) & 0xf) | 301 | #define CPUID2STEPPING(cpuid) ((cpuid) & 0xf) | |
302 | 302 | |||
303 | /* Extended family and model are defined on amd64 processors */ | 303 | /* Extended family and model are defined on amd64 processors */ | |
304 | #define CPUID2EXTFAMILY(cpuid) (((cpuid) >> 20) & 0xff) | 304 | #define CPUID2EXTFAMILY(cpuid) (((cpuid) >> 20) & 0xff) | |
305 | #define CPUID2EXTMODEL(cpuid) (((cpuid) >> 16) & 0xf) | 305 | #define CPUID2EXTMODEL(cpuid) (((cpuid) >> 16) & 0xf) | |
306 | 306 | |||
307 | /* Blacklists of CPUID flags - used to mask certain features */ | 307 | /* Blacklists of CPUID flags - used to mask certain features */ | |
308 | #ifdef XEN | 308 | #ifdef XEN | |
309 | /* Not on Xen */ | 309 | /* Not on Xen */ | |
310 | #define CPUID_FEAT_BLACKLIST (CPUID_PGE|CPUID_PSE|CPUID_MTRR|CPUID_FXSR) | 310 | #define CPUID_FEAT_BLACKLIST (CPUID_PGE|CPUID_PSE|CPUID_MTRR) | |
311 | #else | 311 | #else | |
312 | #define CPUID_FEAT_BLACKLIST 0 | 312 | #define CPUID_FEAT_BLACKLIST 0 | |
313 | #endif /* XEN */ | 313 | #endif /* XEN */ | |
314 | 314 | |||
315 | /* | 315 | /* | |
316 | * Model-specific registers for the i386 family | 316 | * Model-specific registers for the i386 family | |
317 | */ | 317 | */ | |
318 | #define MSR_P5_MC_ADDR 0x000 /* P5 only */ | 318 | #define MSR_P5_MC_ADDR 0x000 /* P5 only */ | |
319 | #define MSR_P5_MC_TYPE 0x001 /* P5 only */ | 319 | #define MSR_P5_MC_TYPE 0x001 /* P5 only */ | |
320 | #define MSR_TSC 0x010 | 320 | #define MSR_TSC 0x010 | |
321 | #define MSR_CESR 0x011 /* P5 only (trap on P6) */ | 321 | #define MSR_CESR 0x011 /* P5 only (trap on P6) */ | |
322 | #define MSR_CTR0 0x012 /* P5 only (trap on P6) */ | 322 | #define MSR_CTR0 0x012 /* P5 only (trap on P6) */ | |
323 | #define MSR_CTR1 0x013 /* P5 only (trap on P6) */ | 323 | #define MSR_CTR1 0x013 /* P5 only (trap on P6) */ |
--- src/sys/arch/xen/x86/x86_xpmap.c 2012/02/23 21:17:25 1.38.2.2
+++ src/sys/arch/xen/x86/x86_xpmap.c 2012/03/05 20:18:03 1.38.2.3
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: x86_xpmap.c,v 1.38.2.2 2012/02/23 21:17:25 riz Exp $ */ | 1 | /* $NetBSD: x86_xpmap.c,v 1.38.2.3 2012/03/05 20:18:03 sborrill Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2006 Mathieu Ropert <mro@adviseo.fr> | 4 | * Copyright (c) 2006 Mathieu Ropert <mro@adviseo.fr> | |
5 | * | 5 | * | |
6 | * Permission to use, copy, modify, and distribute this software for any | 6 | * Permission to use, copy, modify, and distribute this software for any | |
7 | * purpose with or without fee is hereby granted, provided that the above | 7 | * purpose with or without fee is hereby granted, provided that the above | |
8 | * copyright notice and this permission notice appear in all copies. | 8 | * copyright notice and this permission notice appear in all copies. | |
9 | * | 9 | * | |
10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | 10 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | 11 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | 12 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | 13 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | 14 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
@@ -59,70 +59,64 @@ | @@ -59,70 +59,64 @@ | |||
59 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | 59 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
60 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | 60 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
61 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | 61 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
62 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | 62 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
63 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 63 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
64 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 64 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
65 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 65 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
66 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 66 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
67 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 67 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
68 | */ | 68 | */ | |
69 | 69 | |||
70 | 70 | |||
71 | #include <sys/cdefs.h> | 71 | #include <sys/cdefs.h> | |
72 | __KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.38.2.2 2012/02/23 21:17:25 riz Exp $"); | 72 | __KERNEL_RCSID(0, "$NetBSD: x86_xpmap.c,v 1.38.2.3 2012/03/05 20:18:03 sborrill Exp $"); | |
73 | 73 | |||
74 | #include "opt_xen.h" | 74 | #include "opt_xen.h" | |
75 | #include "opt_ddb.h" | 75 | #include "opt_ddb.h" | |
76 | #include "ksyms.h" | 76 | #include "ksyms.h" | |
77 | 77 | |||
78 | #include <sys/param.h> | 78 | #include <sys/param.h> | |
79 | #include <sys/systm.h> | 79 | #include <sys/systm.h> | |
80 | #include <sys/mutex.h> | 80 | #include <sys/mutex.h> | |
81 | #include <sys/cpu.h> | |||
81 | 82 | |||
82 | #include <uvm/uvm.h> | 83 | #include <uvm/uvm.h> | |
83 | 84 | |||
84 | #include <machine/pmap.h> | 85 | #include <x86/pmap.h> | |
85 | #include <machine/gdt.h> | 86 | #include <machine/gdt.h> | |
86 | #include <xen/xenfunc.h> | 87 | #include <xen/xenfunc.h> | |
87 | 88 | |||
88 | #include <dev/isa/isareg.h> | 89 | #include <dev/isa/isareg.h> | |
89 | #include <machine/isa_machdep.h> | 90 | #include <machine/isa_machdep.h> | |
90 | 91 | |||
91 | #undef XENDEBUG | 92 | #undef XENDEBUG | |
92 | /* #define XENDEBUG_SYNC */ | 93 | /* #define XENDEBUG_SYNC */ | |
93 | /* #define XENDEBUG_LOW */ | 94 | /* #define XENDEBUG_LOW */ | |
94 | 95 | |||
95 | #ifdef XENDEBUG | 96 | #ifdef XENDEBUG | |
96 | #define XENPRINTF(x) printf x | 97 | #define XENPRINTF(x) printf x | |
97 | #define XENPRINTK(x) printk x | 98 | #define XENPRINTK(x) printk x | |
98 | #define XENPRINTK2(x) /* printk x */ | 99 | #define XENPRINTK2(x) /* printk x */ | |
99 | 100 | |||
100 | static char XBUF[256]; | 101 | static char XBUF[256]; | |
101 | #else | 102 | #else | |
102 | #define XENPRINTF(x) | 103 | #define XENPRINTF(x) | |
103 | #define XENPRINTK(x) | 104 | #define XENPRINTK(x) | |
104 | #define XENPRINTK2(x) | 105 | #define XENPRINTK2(x) | |
105 | #endif | 106 | #endif | |
106 | #define PRINTF(x) printf x | 107 | #define PRINTF(x) printf x | |
107 | #define PRINTK(x) printk x | 108 | #define PRINTK(x) printk x | |
108 | 109 | |||
109 | /* on x86_64 kernel runs in ring 3 */ | |||
110 | #ifdef __x86_64__ | |||
111 | #define PG_k PG_u | |||
112 | #else | |||
113 | #define PG_k 0 | |||
114 | #endif | |||
115 | ||||
116 | volatile shared_info_t *HYPERVISOR_shared_info; | 110 | volatile shared_info_t *HYPERVISOR_shared_info; | |
117 | /* Xen requires the start_info struct to be page aligned */ | 111 | /* Xen requires the start_info struct to be page aligned */ | |
118 | union start_info_union start_info_union __aligned(PAGE_SIZE); | 112 | union start_info_union start_info_union __aligned(PAGE_SIZE); | |
119 | unsigned long *xpmap_phys_to_machine_mapping; | 113 | unsigned long *xpmap_phys_to_machine_mapping; | |
120 | kmutex_t pte_lock; | 114 | kmutex_t pte_lock; | |
121 | 115 | |||
122 | void xen_failsafe_handler(void); | 116 | void xen_failsafe_handler(void); | |
123 | 117 | |||
124 | #define HYPERVISOR_mmu_update_self(req, count, success_count) \ | 118 | #define HYPERVISOR_mmu_update_self(req, count, success_count) \ | |
125 | HYPERVISOR_mmu_update((req), (count), (success_count), DOMID_SELF) | 119 | HYPERVISOR_mmu_update((req), (count), (success_count), DOMID_SELF) | |
126 | 120 | |||
127 | void | 121 | void | |
128 | xen_failsafe_handler(void) | 122 | xen_failsafe_handler(void) | |
@@ -360,33 +354,34 @@ xpq_queue_invlpg(vaddr_t va) | @@ -360,33 +354,34 @@ xpq_queue_invlpg(vaddr_t va) | |||
360 | xpq_flush_queue(); | 354 | xpq_flush_queue(); | |
361 | 355 | |||
362 | XENPRINTK2(("xpq_queue_invlpg %#" PRIxVADDR "\n", va)); | 356 | XENPRINTK2(("xpq_queue_invlpg %#" PRIxVADDR "\n", va)); | |
363 | op.cmd = MMUEXT_INVLPG_LOCAL; | 357 | op.cmd = MMUEXT_INVLPG_LOCAL; | |
364 | op.arg1.linear_addr = (va & ~PAGE_MASK); | 358 | op.arg1.linear_addr = (va & ~PAGE_MASK); | |
365 | if (HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0) | 359 | if (HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0) | |
366 | panic("xpq_queue_invlpg"); | 360 | panic("xpq_queue_invlpg"); | |
367 | } | 361 | } | |
368 | 362 | |||
369 | void | 363 | void | |
370 | xen_mcast_invlpg(vaddr_t va, uint32_t cpumask) | 364 | xen_mcast_invlpg(vaddr_t va, uint32_t cpumask) | |
371 | { | 365 | { | |
372 | mmuext_op_t op; | 366 | mmuext_op_t op; | |
367 | u_long xcpumask = cpumask; | |||
373 | 368 | |||
374 | /* Flush pending page updates */ | 369 | /* Flush pending page updates */ | |
375 | xpq_flush_queue(); | 370 | xpq_flush_queue(); | |
376 | 371 | |||
377 | op.cmd = MMUEXT_INVLPG_MULTI; | 372 | op.cmd = MMUEXT_INVLPG_MULTI; | |
378 | op.arg1.linear_addr = va; | 373 | op.arg1.linear_addr = va; | |
379 | op.arg2.vcpumask = &cpumask; | 374 | op.arg2.vcpumask = &xcpumask; | |
380 | 375 | |||
381 | if (HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0) { | 376 | if (HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0) { | |
382 | panic("xpq_queue_invlpg_all"); | 377 | panic("xpq_queue_invlpg_all"); | |
383 | } | 378 | } | |
384 | 379 | |||
385 | return; | 380 | return; | |
386 | } | 381 | } | |
387 | 382 | |||
388 | void | 383 | void | |
389 | xen_bcast_invlpg(vaddr_t va) | 384 | xen_bcast_invlpg(vaddr_t va) | |
390 | { | 385 | { | |
391 | mmuext_op_t op; | 386 | mmuext_op_t op; | |
392 | 387 | |||
@@ -398,32 +393,33 @@ xen_bcast_invlpg(vaddr_t va) | @@ -398,32 +393,33 @@ xen_bcast_invlpg(vaddr_t va) | |||
398 | 393 | |||
399 | if (HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0) { | 394 | if (HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0) { | |
400 | panic("xpq_queue_invlpg_all"); | 395 | panic("xpq_queue_invlpg_all"); | |
401 | } | 396 | } | |
402 | 397 | |||
403 | return; | 398 | return; | |
404 | } | 399 | } | |
405 | 400 | |||
406 | /* This is a synchronous call. */ | 401 | /* This is a synchronous call. */ | |
407 | void | 402 | void | |
408 | xen_mcast_tlbflush(uint32_t cpumask) | 403 | xen_mcast_tlbflush(uint32_t cpumask) | |
409 | { | 404 | { | |
410 | mmuext_op_t op; | 405 | mmuext_op_t op; | |
406 | u_long xcpumask = cpumask; | |||
411 | 407 | |||
412 | /* Flush pending page updates */ | 408 | /* Flush pending page updates */ | |
413 | xpq_flush_queue(); | 409 | xpq_flush_queue(); | |
414 | 410 | |||
415 | op.cmd = MMUEXT_TLB_FLUSH_MULTI; | 411 | op.cmd = MMUEXT_TLB_FLUSH_MULTI; | |
416 | op.arg2.vcpumask = &cpumask; | 412 | op.arg2.vcpumask = &xcpumask; | |
417 | 413 | |||
418 | if (HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0) { | 414 | if (HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0) { | |
419 | panic("xpq_queue_invlpg_all"); | 415 | panic("xpq_queue_invlpg_all"); | |
420 | } | 416 | } | |
421 | 417 | |||
422 | return; | 418 | return; | |
423 | } | 419 | } | |
424 | 420 | |||
425 | /* This is a synchronous call. */ | 421 | /* This is a synchronous call. */ | |
426 | void | 422 | void | |
427 | xen_bcast_tlbflush(void) | 423 | xen_bcast_tlbflush(void) | |
428 | { | 424 | { | |
429 | mmuext_op_t op; | 425 | mmuext_op_t op; |