Xen can use the native splraise(9) functions. There is no need for a slower C version.diff -r1.37 -r1.38 src/sys/arch/amd64/amd64/spl.S
(cherry)
--- src/sys/arch/amd64/amd64/spl.S 2018/12/25 06:50:11 1.37
+++ src/sys/arch/amd64/amd64/spl.S 2018/12/26 11:12:57 1.38
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: spl.S,v 1.37 2018/12/25 06:50:11 cherry Exp $ */ | 1 | /* $NetBSD: spl.S,v 1.38 2018/12/26 11:12:57 cherry Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 2003 Wasabi Systems, Inc. | 4 | * Copyright (c) 2003 Wasabi Systems, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * Written by Frank van der Linden for Wasabi Systems, Inc. | 7 | * Written by Frank van der Linden for Wasabi Systems, Inc. | |
8 | * | 8 | * | |
9 | * Redistribution and use in source and binary forms, with or without | 9 | * Redistribution and use in source and binary forms, with or without | |
10 | * modification, are permitted provided that the following conditions | 10 | * modification, are permitted provided that the following conditions | |
11 | * are met: | 11 | * are met: | |
12 | * 1. Redistributions of source code must retain the above copyright | 12 | * 1. Redistributions of source code must retain the above copyright | |
13 | * notice, this list of conditions and the following disclaimer. | 13 | * notice, this list of conditions and the following disclaimer. | |
14 | * 2. Redistributions in binary form must reproduce the above copyright | 14 | * 2. Redistributions in binary form must reproduce the above copyright | |
@@ -68,26 +68,37 @@ | @@ -68,26 +68,37 @@ | |||
68 | #include "opt_kasan.h" | 68 | #include "opt_kasan.h" | |
69 | 69 | |||
70 | #define ALIGN_TEXT .align 16,0x90 | 70 | #define ALIGN_TEXT .align 16,0x90 | |
71 | 71 | |||
72 | #include <machine/asm.h> | 72 | #include <machine/asm.h> | |
73 | #include <machine/trap.h> | 73 | #include <machine/trap.h> | |
74 | #include <machine/segments.h> | 74 | #include <machine/segments.h> | |
75 | #include <machine/frameasm.h> | 75 | #include <machine/frameasm.h> | |
76 | 76 | |||
77 | #include "assym.h" | 77 | #include "assym.h" | |
78 | 78 | |||
79 | .text | 79 | .text | |
80 | 80 | |||
81 | /* | |||
82 | * int splraise(int s); | |||
83 | */ | |||
84 | ENTRY(splraise) | |||
85 | movl CPUVAR(ILEVEL),%eax | |||
86 | cmpl %edi,%eax | |||
87 | cmoval %eax,%edi | |||
88 | movl %edi,CPUVAR(ILEVEL) | |||
89 | ret | |||
90 | END(splraise) | |||
91 | ||||
81 | #ifndef XEN | 92 | #ifndef XEN | |
82 | /* | 93 | /* | |
83 | * Xsoftintr() | 94 | * Xsoftintr() | |
84 | * | 95 | * | |
85 | * Switch to the LWP assigned to handle interrupts from the given | 96 | * Switch to the LWP assigned to handle interrupts from the given | |
86 | * source. We borrow the VM context from the interrupted LWP. | 97 | * source. We borrow the VM context from the interrupted LWP. | |
87 | * | 98 | * | |
88 | * On entry: | 99 | * On entry: | |
89 | * | 100 | * | |
90 | * %rax intrsource | 101 | * %rax intrsource | |
91 | * %r13 address to return to | 102 | * %r13 address to return to | |
92 | */ | 103 | */ | |
93 | IDTVEC(softintr) | 104 | IDTVEC(softintr) | |
@@ -192,37 +203,26 @@ IDTVEC(resume_preempt) | @@ -192,37 +203,26 @@ IDTVEC(resume_preempt) | |||
192 | testq $SEL_RPL,TF_CS(%rsp) | 203 | testq $SEL_RPL,TF_CS(%rsp) | |
193 | jnz 1f | 204 | jnz 1f | |
194 | movq TF_RIP(%rsp),%rdi | 205 | movq TF_RIP(%rsp),%rdi | |
195 | call _C_LABEL(kpreempt) /* from kernel */ | 206 | call _C_LABEL(kpreempt) /* from kernel */ | |
196 | cli | 207 | cli | |
197 | jmp *%r13 /* back to Xdoreti */ | 208 | jmp *%r13 /* back to Xdoreti */ | |
198 | 1: | 209 | 1: | |
199 | call _C_LABEL(preempt) /* from user */ | 210 | call _C_LABEL(preempt) /* from user */ | |
200 | cli | 211 | cli | |
201 | jmp *%r13 /* back to Xdoreti */ | 212 | jmp *%r13 /* back to Xdoreti */ | |
202 | IDTVEC_END(resume_preempt) | 213 | IDTVEC_END(resume_preempt) | |
203 | 214 | |||
204 | /* | 215 | /* | |
205 | * int splraise(int s); | |||
206 | */ | |||
207 | ENTRY(splraise) | |||
208 | movl CPUVAR(ILEVEL),%eax | |||
209 | cmpl %edi,%eax | |||
210 | cmoval %eax,%edi | |||
211 | movl %edi,CPUVAR(ILEVEL) | |||
212 | ret | |||
213 | END(splraise) | |||
214 | ||||
215 | /* | |||
216 | * void spllower(int s); | 216 | * void spllower(int s); | |
217 | * | 217 | * | |
218 | * Must be the same size as cx8_spllower(). This must use | 218 | * Must be the same size as cx8_spllower(). This must use | |
219 | * pushf/cli/popf as it is used early in boot where interrupts | 219 | * pushf/cli/popf as it is used early in boot where interrupts | |
220 | * are disabled via eflags/IE. | 220 | * are disabled via eflags/IE. | |
221 | */ | 221 | */ | |
222 | ENTRY(spllower) | 222 | ENTRY(spllower) | |
223 | cmpl CPUVAR(ILEVEL),%edi | 223 | cmpl CPUVAR(ILEVEL),%edi | |
224 | jae 1f | 224 | jae 1f | |
225 | movl CPUVAR(IUNMASK)(,%rdi,4),%edx | 225 | movl CPUVAR(IUNMASK)(,%rdi,4),%edx | |
226 | pushf | 226 | pushf | |
227 | cli | 227 | cli | |
228 | testl CPUVAR(IPENDING),%edx | 228 | testl CPUVAR(IPENDING),%edx |
--- src/sys/arch/i386/i386/spl.S 2018/12/25 09:00:26 1.45
+++ src/sys/arch/i386/i386/spl.S 2018/12/26 11:12:57 1.46
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: spl.S,v 1.45 2018/12/25 09:00:26 cherry Exp $ */ | 1 | /* $NetBSD: spl.S,v 1.46 2018/12/26 11:12:57 cherry Exp $ */ | |
2 | 2 | |||
3 | /* | 3 | /* | |
4 | * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 1998, 2007, 2008 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Charles M. Hannum and Andrew Doran. | 8 | * by Charles M. Hannum and Andrew Doran. | |
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. | |
@@ -20,64 +20,65 @@ | @@ -20,64 +20,65 @@ | |||
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | 29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #include <machine/asm.h> | 32 | #include <machine/asm.h> | |
33 | __KERNEL_RCSID(0, "$NetBSD: spl.S,v 1.45 2018/12/25 09:00:26 cherry Exp $"); | 33 | __KERNEL_RCSID(0, "$NetBSD: spl.S,v 1.46 2018/12/26 11:12:57 cherry Exp $"); | |
34 | 34 | |||
35 | #include "opt_ddb.h" | 35 | #include "opt_ddb.h" | |
36 | #include "opt_spldebug.h" | 36 | #include "opt_spldebug.h" | |
37 | #include "opt_xen.h" | 37 | #include "opt_xen.h" | |
38 | 38 | |||
39 | #include <machine/trap.h> | 39 | #include <machine/trap.h> | |
40 | #include <machine/segments.h> | 40 | #include <machine/segments.h> | |
41 | #include <machine/frameasm.h> | 41 | #include <machine/frameasm.h> | |
42 | 42 | |||
43 | #include "assym.h" | 43 | #include "assym.h" | |
44 | 44 | |||
45 | .text | 45 | .text | |
46 | 46 | |||
47 | #ifndef XEN | |||
48 | /* | 47 | /* | |
49 | * int splraise(int s); | 48 | * int splraise(int s); | |
50 | */ | 49 | */ | |
51 | ENTRY(splraise) | 50 | ENTRY(splraise) | |
52 | movl 4(%esp),%edx | 51 | movl 4(%esp),%edx | |
53 | movl CPUVAR(ILEVEL),%eax | 52 | movl CPUVAR(ILEVEL),%eax | |
54 | cmpl %edx,%eax | 53 | cmpl %edx,%eax | |
55 | ja 1f | 54 | ja 1f | |
56 | movl %edx,CPUVAR(ILEVEL) | 55 | movl %edx,CPUVAR(ILEVEL) | |
57 | 1: | 56 | 1: | |
58 | #ifdef SPLDEBUG | 57 | #ifdef SPLDEBUG | |
59 | pushl %ebp | 58 | pushl %ebp | |
60 | movl %esp,%ebp | 59 | movl %esp,%ebp | |
61 | pushl %eax | 60 | pushl %eax | |
62 | pushl %edx | 61 | pushl %edx | |
63 | call _C_LABEL(spldebug_raise) | 62 | call _C_LABEL(spldebug_raise) | |
64 | addl $4,%esp | 63 | addl $4,%esp | |
65 | popl %eax | 64 | popl %eax | |
66 | popl %ebp | 65 | popl %ebp | |
67 | #endif /* SPLDEBUG */ | 66 | #endif /* SPLDEBUG */ | |
68 | ret | 67 | ret | |
69 | END(splraise) | 68 | END(splraise) | |
70 | 69 | |||
70 | #ifndef XEN | |||
71 | ||||
71 | /* | 72 | /* | |
72 | * void spllower(int s); | 73 | * void spllower(int s); | |
73 | * | 74 | * | |
74 | * spllower() for i486 and Pentium. Must be the same size as | 75 | * spllower() for i486 and Pentium. Must be the same size as | |
75 | * cx8_spllower(). This must use pushf/cli/popf as it is used | 76 | * cx8_spllower(). This must use pushf/cli/popf as it is used | |
76 | * early in boot where interrupts are disabled via eflags/IE. | 77 | * early in boot where interrupts are disabled via eflags/IE. | |
77 | */ | 78 | */ | |
78 | ENTRY(spllower) | 79 | ENTRY(spllower) | |
79 | #ifdef SPLDEBUG | 80 | #ifdef SPLDEBUG | |
80 | movl 4(%esp),%ecx | 81 | movl 4(%esp),%ecx | |
81 | pushl %ebp | 82 | pushl %ebp | |
82 | movl %esp,%ebp | 83 | movl %esp,%ebp | |
83 | pushl %ecx | 84 | pushl %ecx |
--- src/sys/arch/xen/x86/xen_intr.c 2018/12/25 09:00:26 1.12
+++ src/sys/arch/xen/x86/xen_intr.c 2018/12/26 11:12:57 1.13
@@ -1,14 +1,14 @@ | @@ -1,14 +1,14 @@ | |||
1 | /* $NetBSD: xen_intr.c,v 1.12 2018/12/25 09:00:26 cherry Exp $ */ | 1 | /* $NetBSD: xen_intr.c,v 1.13 2018/12/26 11:12:57 cherry Exp $ */ | |
2 | 2 | |||
3 | /*- | 3 | /*- | |
4 | * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc. | 4 | * Copyright (c) 1998, 2001 The NetBSD Foundation, Inc. | |
5 | * All rights reserved. | 5 | * All rights reserved. | |
6 | * | 6 | * | |
7 | * This code is derived from software contributed to The NetBSD Foundation | 7 | * This code is derived from software contributed to The NetBSD Foundation | |
8 | * by Charles M. Hannum, and by Jason R. Thorpe. | 8 | * by Charles M. Hannum, and by Jason R. Thorpe. | |
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. | |
@@ -20,27 +20,27 @@ | @@ -20,27 +20,27 @@ | |||
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
29 | * POSSIBILITY OF SUCH DAMAGE. | 29 | * POSSIBILITY OF SUCH DAMAGE. | |
30 | */ | 30 | */ | |
31 | 31 | |||
32 | #include <sys/cdefs.h> | 32 | #include <sys/cdefs.h> | |
33 | __KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v 1.12 2018/12/25 09:00:26 cherry Exp $"); | 33 | __KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v 1.13 2018/12/26 11:12:57 cherry Exp $"); | |
34 | 34 | |||
35 | #include <sys/param.h> | 35 | #include <sys/param.h> | |
36 | #include <sys/kernel.h> | 36 | #include <sys/kernel.h> | |
37 | #include <sys/kmem.h> | 37 | #include <sys/kmem.h> | |
38 | 38 | |||
39 | #include <sys/cpu.h> | 39 | #include <sys/cpu.h> | |
40 | 40 | |||
41 | #include <xen/evtchn.h> | 41 | #include <xen/evtchn.h> | |
42 | 42 | |||
43 | #include <uvm/uvm.h> | 43 | #include <uvm/uvm.h> | |
44 | 44 | |||
45 | #include <machine/cpu.h> | 45 | #include <machine/cpu.h> | |
46 | #include <machine/intr.h> | 46 | #include <machine/intr.h> | |
@@ -62,42 +62,26 @@ __KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v | @@ -62,42 +62,26 @@ __KERNEL_RCSID(0, "$NetBSD: xen_intr.c,v | |||
62 | #include <machine/i82489var.h> | 62 | #include <machine/i82489var.h> | |
63 | #endif | 63 | #endif | |
64 | 64 | |||
65 | #if NPCI > 0 | 65 | #if NPCI > 0 | |
66 | #include <dev/pci/ppbreg.h> | 66 | #include <dev/pci/ppbreg.h> | |
67 | #endif | 67 | #endif | |
68 | 68 | |||
69 | void xen_disable_intr(void); | 69 | void xen_disable_intr(void); | |
70 | void xen_enable_intr(void); | 70 | void xen_enable_intr(void); | |
71 | u_long xen_read_psl(void); | 71 | u_long xen_read_psl(void); | |
72 | void xen_write_psl(u_long); | 72 | void xen_write_psl(u_long); | |
73 | 73 | |||
74 | /* | 74 | /* | |
75 | * Add a mask to cpl, and return the old value of cpl. | |||
76 | */ | |||
77 | int | |||
78 | splraise(int nlevel) | |||
79 | { | |||
80 | int olevel; | |||
81 | struct cpu_info *ci = curcpu(); | |||
82 | ||||
83 | olevel = ci->ci_ilevel; | |||
84 | if (nlevel > olevel) | |||
85 | ci->ci_ilevel = nlevel; | |||
86 | __insn_barrier(); | |||
87 | return (olevel); | |||
88 | } | |||
89 | ||||
90 | /* | |||
91 | * Restore a value to cpl (unmasking interrupts). If any unmasked | 75 | * Restore a value to cpl (unmasking interrupts). If any unmasked | |
92 | * interrupts are pending, call Xspllower() to process them. | 76 | * interrupts are pending, call Xspllower() to process them. | |
93 | */ | 77 | */ | |
94 | void | 78 | void | |
95 | spllower(int nlevel) | 79 | spllower(int nlevel) | |
96 | { | 80 | { | |
97 | struct cpu_info *ci = curcpu(); | 81 | struct cpu_info *ci = curcpu(); | |
98 | uint32_t xmask; | 82 | uint32_t xmask; | |
99 | u_long psl; | 83 | u_long psl; | |
100 | 84 | |||
101 | if (ci->ci_ilevel <= nlevel) | 85 | if (ci->ci_ilevel <= nlevel) | |
102 | return; | 86 | return; | |
103 | 87 |