diff options
author | Paul Mackerras <paulus@samba.org> | 2011-06-28 20:20:58 -0400 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2011-07-12 06:16:53 -0400 |
commit | 3c42bf8a717cb636e0ed2ed77194669e2ac3ed56 (patch) | |
tree | 4f543088e6a64ce7f1a771c1618668ff27752ecc /arch/powerpc/kvm | |
parent | 923c53caea446d246949c94703be83e68f251af7 (diff) |
KVM: PPC: Split host-state fields out of kvmppc_book3s_shadow_vcpu
There are several fields in struct kvmppc_book3s_shadow_vcpu that
temporarily store bits of host state while a guest is running,
rather than anything relating to the particular guest or vcpu.
This splits them out into a new kvmppc_host_state structure and
modifies the definitions in asm-offsets.c to suit.
On 32-bit, we have a kvmppc_host_state structure inside the
kvmppc_book3s_shadow_vcpu since the assembly code needs to be able
to get to them both with one pointer. On 64-bit they are separate
fields in the PACA. This means that on 64-bit we don't need to
copy the kvmppc_host_state in and out on vcpu load/unload, and
in future will mean that the book3s_hv code doesn't need a
shadow_vcpu struct in the PACA at all. That does mean that we
have to be careful not to rely on any values persisting in the
hstate field of the paca across any point where we could block
or get preempted.
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Alexander Graf <agraf@suse.de>
Diffstat (limited to 'arch/powerpc/kvm')
-rw-r--r-- | arch/powerpc/kvm/book3s_interrupts.S | 19 | ||||
-rw-r--r-- | arch/powerpc/kvm/book3s_rmhandlers.S | 18 | ||||
-rw-r--r-- | arch/powerpc/kvm/book3s_segment.S | 76 |
3 files changed, 54 insertions, 59 deletions
diff --git a/arch/powerpc/kvm/book3s_interrupts.S b/arch/powerpc/kvm/book3s_interrupts.S index 8c5e0e160107..c54b0e30cf3f 100644 --- a/arch/powerpc/kvm/book3s_interrupts.S +++ b/arch/powerpc/kvm/book3s_interrupts.S | |||
@@ -29,8 +29,7 @@ | |||
29 | #define ULONG_SIZE 8 | 29 | #define ULONG_SIZE 8 |
30 | #define FUNC(name) GLUE(.,name) | 30 | #define FUNC(name) GLUE(.,name) |
31 | 31 | ||
32 | #define GET_SHADOW_VCPU(reg) \ | 32 | #define GET_SHADOW_VCPU_R13 |
33 | addi reg, r13, PACA_KVM_SVCPU | ||
34 | 33 | ||
35 | #define DISABLE_INTERRUPTS \ | 34 | #define DISABLE_INTERRUPTS \ |
36 | mfmsr r0; \ | 35 | mfmsr r0; \ |
@@ -43,8 +42,8 @@ | |||
43 | #define ULONG_SIZE 4 | 42 | #define ULONG_SIZE 4 |
44 | #define FUNC(name) name | 43 | #define FUNC(name) name |
45 | 44 | ||
46 | #define GET_SHADOW_VCPU(reg) \ | 45 | #define GET_SHADOW_VCPU_R13 \ |
47 | lwz reg, (THREAD + THREAD_KVM_SVCPU)(r2) | 46 | lwz r13, (THREAD + THREAD_KVM_SVCPU)(r2) |
48 | 47 | ||
49 | #define DISABLE_INTERRUPTS \ | 48 | #define DISABLE_INTERRUPTS \ |
50 | mfmsr r0; \ | 49 | mfmsr r0; \ |
@@ -107,17 +106,11 @@ kvm_start_entry: | |||
107 | /* Load non-volatile guest state from the vcpu */ | 106 | /* Load non-volatile guest state from the vcpu */ |
108 | VCPU_LOAD_NVGPRS(r4) | 107 | VCPU_LOAD_NVGPRS(r4) |
109 | 108 | ||
110 | GET_SHADOW_VCPU(r5) | 109 | kvm_start_lightweight: |
111 | |||
112 | /* Save R1/R2 in the PACA */ | ||
113 | PPC_STL r1, SVCPU_HOST_R1(r5) | ||
114 | PPC_STL r2, SVCPU_HOST_R2(r5) | ||
115 | 110 | ||
116 | /* XXX swap in/out on load? */ | 111 | GET_SHADOW_VCPU_R13 |
117 | PPC_LL r3, VCPU_HIGHMEM_HANDLER(r4) | 112 | PPC_LL r3, VCPU_HIGHMEM_HANDLER(r4) |
118 | PPC_STL r3, SVCPU_VMHANDLER(r5) | 113 | PPC_STL r3, HSTATE_VMHANDLER(r13) |
119 | |||
120 | kvm_start_lightweight: | ||
121 | 114 | ||
122 | PPC_LL r10, VCPU_SHADOW_MSR(r4) /* r10 = vcpu->arch.shadow_msr */ | 115 | PPC_LL r10, VCPU_SHADOW_MSR(r4) /* r10 = vcpu->arch.shadow_msr */ |
123 | 116 | ||
diff --git a/arch/powerpc/kvm/book3s_rmhandlers.S b/arch/powerpc/kvm/book3s_rmhandlers.S index dd03689fc609..c1f877c4a884 100644 --- a/arch/powerpc/kvm/book3s_rmhandlers.S +++ b/arch/powerpc/kvm/book3s_rmhandlers.S | |||
@@ -36,7 +36,6 @@ | |||
36 | #if defined(CONFIG_PPC_BOOK3S_64) | 36 | #if defined(CONFIG_PPC_BOOK3S_64) |
37 | 37 | ||
38 | #define LOAD_SHADOW_VCPU(reg) GET_PACA(reg) | 38 | #define LOAD_SHADOW_VCPU(reg) GET_PACA(reg) |
39 | #define SHADOW_VCPU_OFF PACA_KVM_SVCPU | ||
40 | #define MSR_NOIRQ MSR_KERNEL & ~(MSR_IR | MSR_DR) | 39 | #define MSR_NOIRQ MSR_KERNEL & ~(MSR_IR | MSR_DR) |
41 | #define FUNC(name) GLUE(.,name) | 40 | #define FUNC(name) GLUE(.,name) |
42 | 41 | ||
@@ -66,7 +65,6 @@ kvmppc_skip_Hinterrupt: | |||
66 | 65 | ||
67 | #elif defined(CONFIG_PPC_BOOK3S_32) | 66 | #elif defined(CONFIG_PPC_BOOK3S_32) |
68 | 67 | ||
69 | #define SHADOW_VCPU_OFF 0 | ||
70 | #define MSR_NOIRQ MSR_KERNEL | 68 | #define MSR_NOIRQ MSR_KERNEL |
71 | #define FUNC(name) name | 69 | #define FUNC(name) name |
72 | 70 | ||
@@ -96,14 +94,14 @@ kvmppc_trampoline_\intno: | |||
96 | b kvmppc_resume_\intno /* Get back original handler */ | 94 | b kvmppc_resume_\intno /* Get back original handler */ |
97 | 95 | ||
98 | 1: tophys(r13, r13) | 96 | 1: tophys(r13, r13) |
99 | stw r12, (SHADOW_VCPU_OFF + SVCPU_SCRATCH1)(r13) | 97 | stw r12, HSTATE_SCRATCH1(r13) |
100 | mfspr r12, SPRN_SPRG_SCRATCH1 | 98 | mfspr r12, SPRN_SPRG_SCRATCH1 |
101 | stw r12, (SHADOW_VCPU_OFF + SVCPU_SCRATCH0)(r13) | 99 | stw r12, HSTATE_SCRATCH0(r13) |
102 | lbz r12, (SHADOW_VCPU_OFF + SVCPU_IN_GUEST)(r13) | 100 | lbz r12, HSTATE_IN_GUEST(r13) |
103 | cmpwi r12, KVM_GUEST_MODE_NONE | 101 | cmpwi r12, KVM_GUEST_MODE_NONE |
104 | bne ..kvmppc_handler_hasmagic_\intno | 102 | bne ..kvmppc_handler_hasmagic_\intno |
105 | /* No KVM guest? Then jump back to the Linux handler! */ | 103 | /* No KVM guest? Then jump back to the Linux handler! */ |
106 | lwz r12, (SHADOW_VCPU_OFF + SVCPU_SCRATCH1)(r13) | 104 | lwz r12, HSTATE_SCRATCH1(r13) |
107 | b 2b | 105 | b 2b |
108 | 106 | ||
109 | /* Now we know we're handling a KVM guest */ | 107 | /* Now we know we're handling a KVM guest */ |
@@ -146,8 +144,8 @@ INTERRUPT_TRAMPOLINE BOOK3S_INTERRUPT_ALTIVEC | |||
146 | * | 144 | * |
147 | * R12 = free | 145 | * R12 = free |
148 | * R13 = Shadow VCPU (PACA) | 146 | * R13 = Shadow VCPU (PACA) |
149 | * SVCPU.SCRATCH0 = guest R12 | 147 | * HSTATE.SCRATCH0 = guest R12 |
150 | * SVCPU.SCRATCH1 = guest CR | 148 | * HSTATE.SCRATCH1 = guest CR |
151 | * SPRG_SCRATCH0 = guest R13 | 149 | * SPRG_SCRATCH0 = guest R13 |
152 | * | 150 | * |
153 | */ | 151 | */ |
@@ -159,9 +157,9 @@ kvmppc_handler_skip_ins: | |||
159 | mtsrr0 r12 | 157 | mtsrr0 r12 |
160 | 158 | ||
161 | /* Clean up all state */ | 159 | /* Clean up all state */ |
162 | lwz r12, (SHADOW_VCPU_OFF + SVCPU_SCRATCH1)(r13) | 160 | lwz r12, HSTATE_SCRATCH1(r13) |
163 | mtcr r12 | 161 | mtcr r12 |
164 | PPC_LL r12, (SHADOW_VCPU_OFF + SVCPU_SCRATCH0)(r13) | 162 | PPC_LL r12, HSTATE_SCRATCH0(r13) |
165 | GET_SCRATCH0(r13) | 163 | GET_SCRATCH0(r13) |
166 | 164 | ||
167 | /* And get back into the code */ | 165 | /* And get back into the code */ |
diff --git a/arch/powerpc/kvm/book3s_segment.S b/arch/powerpc/kvm/book3s_segment.S index 4a623eb28a53..1cc25e8c0cf1 100644 --- a/arch/powerpc/kvm/book3s_segment.S +++ b/arch/powerpc/kvm/book3s_segment.S | |||
@@ -22,7 +22,7 @@ | |||
22 | #if defined(CONFIG_PPC_BOOK3S_64) | 22 | #if defined(CONFIG_PPC_BOOK3S_64) |
23 | 23 | ||
24 | #define GET_SHADOW_VCPU(reg) \ | 24 | #define GET_SHADOW_VCPU(reg) \ |
25 | addi reg, r13, PACA_KVM_SVCPU | 25 | mr reg, r13 |
26 | 26 | ||
27 | #elif defined(CONFIG_PPC_BOOK3S_32) | 27 | #elif defined(CONFIG_PPC_BOOK3S_32) |
28 | 28 | ||
@@ -71,6 +71,10 @@ kvmppc_handler_trampoline_enter: | |||
71 | /* r3 = shadow vcpu */ | 71 | /* r3 = shadow vcpu */ |
72 | GET_SHADOW_VCPU(r3) | 72 | GET_SHADOW_VCPU(r3) |
73 | 73 | ||
74 | /* Save R1/R2 in the PACA (64-bit) or shadow_vcpu (32-bit) */ | ||
75 | PPC_STL r1, HSTATE_HOST_R1(r3) | ||
76 | PPC_STL r2, HSTATE_HOST_R2(r3) | ||
77 | |||
74 | /* Move SRR0 and SRR1 into the respective regs */ | 78 | /* Move SRR0 and SRR1 into the respective regs */ |
75 | PPC_LL r9, SVCPU_PC(r3) | 79 | PPC_LL r9, SVCPU_PC(r3) |
76 | mtsrr0 r9 | 80 | mtsrr0 r9 |
@@ -78,7 +82,7 @@ kvmppc_handler_trampoline_enter: | |||
78 | 82 | ||
79 | /* Activate guest mode, so faults get handled by KVM */ | 83 | /* Activate guest mode, so faults get handled by KVM */ |
80 | li r11, KVM_GUEST_MODE_GUEST | 84 | li r11, KVM_GUEST_MODE_GUEST |
81 | stb r11, SVCPU_IN_GUEST(r3) | 85 | stb r11, HSTATE_IN_GUEST(r3) |
82 | 86 | ||
83 | /* Switch to guest segment. This is subarch specific. */ | 87 | /* Switch to guest segment. This is subarch specific. */ |
84 | LOAD_GUEST_SEGMENTS | 88 | LOAD_GUEST_SEGMENTS |
@@ -132,30 +136,30 @@ kvmppc_interrupt: | |||
132 | * | 136 | * |
133 | * SPRG_SCRATCH0 = guest R13 | 137 | * SPRG_SCRATCH0 = guest R13 |
134 | * R12 = exit handler id | 138 | * R12 = exit handler id |
135 | * R13 = shadow vcpu - SHADOW_VCPU_OFF [=PACA on PPC64] | 139 | * R13 = shadow vcpu (32-bit) or PACA (64-bit) |
136 | * SVCPU.SCRATCH0 = guest R12 | 140 | * HSTATE.SCRATCH0 = guest R12 |
137 | * SVCPU.SCRATCH1 = guest CR | 141 | * HSTATE.SCRATCH1 = guest CR |
138 | * | 142 | * |
139 | */ | 143 | */ |
140 | 144 | ||
141 | /* Save registers */ | 145 | /* Save registers */ |
142 | 146 | ||
143 | PPC_STL r0, (SHADOW_VCPU_OFF + SVCPU_R0)(r13) | 147 | PPC_STL r0, SVCPU_R0(r13) |
144 | PPC_STL r1, (SHADOW_VCPU_OFF + SVCPU_R1)(r13) | 148 | PPC_STL r1, SVCPU_R1(r13) |
145 | PPC_STL r2, (SHADOW_VCPU_OFF + SVCPU_R2)(r13) | 149 | PPC_STL r2, SVCPU_R2(r13) |
146 | PPC_STL r3, (SHADOW_VCPU_OFF + SVCPU_R3)(r13) | 150 | PPC_STL r3, SVCPU_R3(r13) |
147 | PPC_STL r4, (SHADOW_VCPU_OFF + SVCPU_R4)(r13) | 151 | PPC_STL r4, SVCPU_R4(r13) |
148 | PPC_STL r5, (SHADOW_VCPU_OFF + SVCPU_R5)(r13) | 152 | PPC_STL r5, SVCPU_R5(r13) |
149 | PPC_STL r6, (SHADOW_VCPU_OFF + SVCPU_R6)(r13) | 153 | PPC_STL r6, SVCPU_R6(r13) |
150 | PPC_STL r7, (SHADOW_VCPU_OFF + SVCPU_R7)(r13) | 154 | PPC_STL r7, SVCPU_R7(r13) |
151 | PPC_STL r8, (SHADOW_VCPU_OFF + SVCPU_R8)(r13) | 155 | PPC_STL r8, SVCPU_R8(r13) |
152 | PPC_STL r9, (SHADOW_VCPU_OFF + SVCPU_R9)(r13) | 156 | PPC_STL r9, SVCPU_R9(r13) |
153 | PPC_STL r10, (SHADOW_VCPU_OFF + SVCPU_R10)(r13) | 157 | PPC_STL r10, SVCPU_R10(r13) |
154 | PPC_STL r11, (SHADOW_VCPU_OFF + SVCPU_R11)(r13) | 158 | PPC_STL r11, SVCPU_R11(r13) |
155 | 159 | ||
156 | /* Restore R1/R2 so we can handle faults */ | 160 | /* Restore R1/R2 so we can handle faults */ |
157 | PPC_LL r1, (SHADOW_VCPU_OFF + SVCPU_HOST_R1)(r13) | 161 | PPC_LL r1, HSTATE_HOST_R1(r13) |
158 | PPC_LL r2, (SHADOW_VCPU_OFF + SVCPU_HOST_R2)(r13) | 162 | PPC_LL r2, HSTATE_HOST_R2(r13) |
159 | 163 | ||
160 | /* Save guest PC and MSR */ | 164 | /* Save guest PC and MSR */ |
161 | #ifdef CONFIG_PPC64 | 165 | #ifdef CONFIG_PPC64 |
@@ -171,17 +175,17 @@ END_FTR_SECTION_IFSET(CPU_FTR_HVMODE_206) | |||
171 | 1: mfsrr0 r3 | 175 | 1: mfsrr0 r3 |
172 | mfsrr1 r4 | 176 | mfsrr1 r4 |
173 | 2: | 177 | 2: |
174 | PPC_STL r3, (SHADOW_VCPU_OFF + SVCPU_PC)(r13) | 178 | PPC_STL r3, SVCPU_PC(r13) |
175 | PPC_STL r4, (SHADOW_VCPU_OFF + SVCPU_SHADOW_SRR1)(r13) | 179 | PPC_STL r4, SVCPU_SHADOW_SRR1(r13) |
176 | 180 | ||
177 | /* Get scratch'ed off registers */ | 181 | /* Get scratch'ed off registers */ |
178 | GET_SCRATCH0(r9) | 182 | GET_SCRATCH0(r9) |
179 | PPC_LL r8, (SHADOW_VCPU_OFF + SVCPU_SCRATCH0)(r13) | 183 | PPC_LL r8, HSTATE_SCRATCH0(r13) |
180 | lwz r7, (SHADOW_VCPU_OFF + SVCPU_SCRATCH1)(r13) | 184 | lwz r7, HSTATE_SCRATCH1(r13) |
181 | 185 | ||
182 | PPC_STL r9, (SHADOW_VCPU_OFF + SVCPU_R13)(r13) | 186 | PPC_STL r9, SVCPU_R13(r13) |
183 | PPC_STL r8, (SHADOW_VCPU_OFF + SVCPU_R12)(r13) | 187 | PPC_STL r8, SVCPU_R12(r13) |
184 | stw r7, (SHADOW_VCPU_OFF + SVCPU_CR)(r13) | 188 | stw r7, SVCPU_CR(r13) |
185 | 189 | ||
186 | /* Save more register state */ | 190 | /* Save more register state */ |
187 | 191 | ||
@@ -191,11 +195,11 @@ END_FTR_SECTION_IFSET(CPU_FTR_HVMODE_206) | |||
191 | mfctr r8 | 195 | mfctr r8 |
192 | mflr r9 | 196 | mflr r9 |
193 | 197 | ||
194 | stw r5, (SHADOW_VCPU_OFF + SVCPU_XER)(r13) | 198 | stw r5, SVCPU_XER(r13) |
195 | PPC_STL r6, (SHADOW_VCPU_OFF + SVCPU_FAULT_DAR)(r13) | 199 | PPC_STL r6, SVCPU_FAULT_DAR(r13) |
196 | stw r7, (SHADOW_VCPU_OFF + SVCPU_FAULT_DSISR)(r13) | 200 | stw r7, SVCPU_FAULT_DSISR(r13) |
197 | PPC_STL r8, (SHADOW_VCPU_OFF + SVCPU_CTR)(r13) | 201 | PPC_STL r8, SVCPU_CTR(r13) |
198 | PPC_STL r9, (SHADOW_VCPU_OFF + SVCPU_LR)(r13) | 202 | PPC_STL r9, SVCPU_LR(r13) |
199 | 203 | ||
200 | /* | 204 | /* |
201 | * In order for us to easily get the last instruction, | 205 | * In order for us to easily get the last instruction, |
@@ -225,7 +229,7 @@ ld_last_inst: | |||
225 | /* Set guest mode to 'jump over instruction' so if lwz faults | 229 | /* Set guest mode to 'jump over instruction' so if lwz faults |
226 | * we'll just continue at the next IP. */ | 230 | * we'll just continue at the next IP. */ |
227 | li r9, KVM_GUEST_MODE_SKIP | 231 | li r9, KVM_GUEST_MODE_SKIP |
228 | stb r9, (SHADOW_VCPU_OFF + SVCPU_IN_GUEST)(r13) | 232 | stb r9, HSTATE_IN_GUEST(r13) |
229 | 233 | ||
230 | /* 1) enable paging for data */ | 234 | /* 1) enable paging for data */ |
231 | mfmsr r9 | 235 | mfmsr r9 |
@@ -239,13 +243,13 @@ ld_last_inst: | |||
239 | sync | 243 | sync |
240 | 244 | ||
241 | #endif | 245 | #endif |
242 | stw r0, (SHADOW_VCPU_OFF + SVCPU_LAST_INST)(r13) | 246 | stw r0, SVCPU_LAST_INST(r13) |
243 | 247 | ||
244 | no_ld_last_inst: | 248 | no_ld_last_inst: |
245 | 249 | ||
246 | /* Unset guest mode */ | 250 | /* Unset guest mode */ |
247 | li r9, KVM_GUEST_MODE_NONE | 251 | li r9, KVM_GUEST_MODE_NONE |
248 | stb r9, (SHADOW_VCPU_OFF + SVCPU_IN_GUEST)(r13) | 252 | stb r9, HSTATE_IN_GUEST(r13) |
249 | 253 | ||
250 | /* Switch back to host MMU */ | 254 | /* Switch back to host MMU */ |
251 | LOAD_HOST_SEGMENTS | 255 | LOAD_HOST_SEGMENTS |
@@ -255,7 +259,7 @@ no_ld_last_inst: | |||
255 | * R1 = host R1 | 259 | * R1 = host R1 |
256 | * R2 = host R2 | 260 | * R2 = host R2 |
257 | * R12 = exit handler id | 261 | * R12 = exit handler id |
258 | * R13 = shadow vcpu - SHADOW_VCPU_OFF [=PACA on PPC64] | 262 | * R13 = shadow vcpu (32-bit) or PACA (64-bit) |
259 | * SVCPU.* = guest * | 263 | * SVCPU.* = guest * |
260 | * | 264 | * |
261 | */ | 265 | */ |
@@ -265,7 +269,7 @@ no_ld_last_inst: | |||
265 | ori r7, r7, MSR_IR|MSR_DR|MSR_RI|MSR_ME /* Enable paging */ | 269 | ori r7, r7, MSR_IR|MSR_DR|MSR_RI|MSR_ME /* Enable paging */ |
266 | mtsrr1 r7 | 270 | mtsrr1 r7 |
267 | /* Load highmem handler address */ | 271 | /* Load highmem handler address */ |
268 | PPC_LL r8, (SHADOW_VCPU_OFF + SVCPU_VMHANDLER)(r13) | 272 | PPC_LL r8, HSTATE_VMHANDLER(r13) |
269 | mtsrr0 r8 | 273 | mtsrr0 r8 |
270 | 274 | ||
271 | RFI | 275 | RFI |