Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This program is free software; you can redistribute it and/or modify |
| 3 | * it under the terms of the GNU General Public License, version 2, as |
| 4 | * published by the Free Software Foundation. |
| 5 | * |
| 6 | * This program is distributed in the hope that it will be useful, |
| 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 8 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 9 | * GNU General Public License for more details. |
| 10 | * |
| 11 | * Copyright 2011 Paul Mackerras, IBM Corp. <paulus@au1.ibm.com> |
| 12 | * |
| 13 | * Derived from book3s_rmhandlers.S and other files, which are: |
| 14 | * |
| 15 | * Copyright SUSE Linux Products GmbH 2009 |
| 16 | * |
| 17 | * Authors: Alexander Graf <agraf@suse.de> |
| 18 | */ |
| 19 | |
| 20 | #include <asm/ppc_asm.h> |
| 21 | #include <asm/kvm_asm.h> |
| 22 | #include <asm/reg.h> |
Paul Mackerras | 177339d | 2011-07-23 17:41:11 +1000 | [diff] [blame] | 23 | #include <asm/mmu.h> |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 24 | #include <asm/page.h> |
Paul Mackerras | 177339d | 2011-07-23 17:41:11 +1000 | [diff] [blame] | 25 | #include <asm/ptrace.h> |
| 26 | #include <asm/hvcall.h> |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 27 | #include <asm/asm-offsets.h> |
| 28 | #include <asm/exception-64s.h> |
Paul Mackerras | f0888f7 | 2012-02-03 00:54:17 +0000 | [diff] [blame] | 29 | #include <asm/kvm_book3s_asm.h> |
Aneesh Kumar K.V | f64e808 | 2016-03-01 12:59:20 +0530 | [diff] [blame] | 30 | #include <asm/book3s/64/mmu-hash.h> |
Michael Neuling | e4e3812 | 2014-03-25 10:47:02 +1100 | [diff] [blame] | 31 | #include <asm/tm.h> |
Mahesh Salgaonkar | fd7bacb | 2016-05-15 09:44:26 +0530 | [diff] [blame] | 32 | #include <asm/opal.h> |
Benjamin Herrenschmidt | 5af5099 | 2017-04-05 17:54:56 +1000 | [diff] [blame] | 33 | #include <asm/xive-regs.h> |
Michael Neuling | e4e3812 | 2014-03-25 10:47:02 +1100 | [diff] [blame] | 34 | |
Paul Mackerras | 2f27246 | 2017-05-22 16:25:14 +1000 | [diff] [blame] | 35 | /* Sign-extend HDEC if not on POWER9 */ |
| 36 | #define EXTEND_HDEC(reg) \ |
| 37 | BEGIN_FTR_SECTION; \ |
| 38 | extsw reg, reg; \ |
| 39 | END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_300) |
| 40 | |
Michael Neuling | e4e3812 | 2014-03-25 10:47:02 +1100 | [diff] [blame] | 41 | #define VCPU_GPRS_TM(reg) (((reg) * ULONG_SIZE) + VCPU_GPR_TM) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 42 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 43 | /* Values in HSTATE_NAPPING(r13) */ |
| 44 | #define NAPPING_CEDE 1 |
| 45 | #define NAPPING_NOVCPU 2 |
| 46 | |
Paul Mackerras | 7ceaa6d | 2017-06-16 11:53:19 +1000 | [diff] [blame] | 47 | /* Stack frame offsets for kvmppc_hv_entry */ |
Paul Mackerras | 769377f | 2017-02-15 14:30:17 +1100 | [diff] [blame] | 48 | #define SFS 160 |
Paul Mackerras | 7ceaa6d | 2017-06-16 11:53:19 +1000 | [diff] [blame] | 49 | #define STACK_SLOT_TRAP (SFS-4) |
| 50 | #define STACK_SLOT_TID (SFS-16) |
| 51 | #define STACK_SLOT_PSSCR (SFS-24) |
| 52 | #define STACK_SLOT_PID (SFS-32) |
| 53 | #define STACK_SLOT_IAMR (SFS-40) |
| 54 | #define STACK_SLOT_CIABR (SFS-48) |
| 55 | #define STACK_SLOT_DAWR (SFS-56) |
| 56 | #define STACK_SLOT_DAWRX (SFS-64) |
Paul Mackerras | 769377f | 2017-02-15 14:30:17 +1100 | [diff] [blame] | 57 | #define STACK_SLOT_HFSCR (SFS-72) |
Paul Mackerras | 7ceaa6d | 2017-06-16 11:53:19 +1000 | [diff] [blame] | 58 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 59 | /* |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 60 | * Call kvmppc_hv_entry in real mode. |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 61 | * Must be called with interrupts hard-disabled. |
| 62 | * |
| 63 | * Input Registers: |
| 64 | * |
| 65 | * LR = return address to continue at after eventually re-enabling MMU |
| 66 | */ |
Anton Blanchard | 6ed179b | 2014-06-12 18:16:53 +1000 | [diff] [blame] | 67 | _GLOBAL_TOC(kvmppc_hv_entry_trampoline) |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 68 | mflr r0 |
| 69 | std r0, PPC_LR_STKOFF(r1) |
| 70 | stdu r1, -112(r1) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 71 | mfmsr r10 |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 72 | LOAD_REG_ADDR(r5, kvmppc_call_hv_entry) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 73 | li r0,MSR_RI |
| 74 | andc r0,r10,r0 |
| 75 | li r6,MSR_IR | MSR_DR |
| 76 | andc r6,r10,r6 |
| 77 | mtmsrd r0,1 /* clear RI in MSR */ |
| 78 | mtsrr0 r5 |
| 79 | mtsrr1 r6 |
| 80 | RFI |
| 81 | |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 82 | kvmppc_call_hv_entry: |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 83 | ld r4, HSTATE_KVM_VCPU(r13) |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 84 | bl kvmppc_hv_entry |
| 85 | |
| 86 | /* Back from guest - restore host state and return to caller */ |
| 87 | |
Michael Neuling | eee7ff9 | 2014-01-08 21:25:19 +1100 | [diff] [blame] | 88 | BEGIN_FTR_SECTION |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 89 | /* Restore host DABR and DABRX */ |
| 90 | ld r5,HSTATE_DABR(r13) |
| 91 | li r6,7 |
| 92 | mtspr SPRN_DABR,r5 |
| 93 | mtspr SPRN_DABRX,r6 |
Michael Neuling | eee7ff9 | 2014-01-08 21:25:19 +1100 | [diff] [blame] | 94 | END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S) |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 95 | |
| 96 | /* Restore SPRG3 */ |
Scott Wood | 9d378df | 2014-03-10 17:29:38 -0500 | [diff] [blame] | 97 | ld r3,PACA_SPRG_VDSO(r13) |
| 98 | mtspr SPRN_SPRG_VDSO_WRITE,r3 |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 99 | |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 100 | /* Reload the host's PMU registers */ |
| 101 | ld r3, PACALPPACAPTR(r13) /* is the host using the PMU? */ |
| 102 | lbz r4, LPPACA_PMCINUSE(r3) |
| 103 | cmpwi r4, 0 |
| 104 | beq 23f /* skip if not */ |
Paul Mackerras | 9bc01a9 | 2014-05-26 19:48:40 +1000 | [diff] [blame] | 105 | BEGIN_FTR_SECTION |
Michael Ellerman | 9a4fc4e | 2014-07-10 19:34:31 +1000 | [diff] [blame] | 106 | ld r3, HSTATE_MMCR0(r13) |
Paul Mackerras | 9bc01a9 | 2014-05-26 19:48:40 +1000 | [diff] [blame] | 107 | andi. r4, r3, MMCR0_PMAO_SYNC | MMCR0_PMAO |
| 108 | cmpwi r4, MMCR0_PMAO |
| 109 | beql kvmppc_fix_pmao |
| 110 | END_FTR_SECTION_IFSET(CPU_FTR_PMAO_BUG) |
Michael Ellerman | 9a4fc4e | 2014-07-10 19:34:31 +1000 | [diff] [blame] | 111 | lwz r3, HSTATE_PMC1(r13) |
| 112 | lwz r4, HSTATE_PMC2(r13) |
| 113 | lwz r5, HSTATE_PMC3(r13) |
| 114 | lwz r6, HSTATE_PMC4(r13) |
| 115 | lwz r8, HSTATE_PMC5(r13) |
| 116 | lwz r9, HSTATE_PMC6(r13) |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 117 | mtspr SPRN_PMC1, r3 |
| 118 | mtspr SPRN_PMC2, r4 |
| 119 | mtspr SPRN_PMC3, r5 |
| 120 | mtspr SPRN_PMC4, r6 |
| 121 | mtspr SPRN_PMC5, r8 |
| 122 | mtspr SPRN_PMC6, r9 |
Michael Ellerman | 9a4fc4e | 2014-07-10 19:34:31 +1000 | [diff] [blame] | 123 | ld r3, HSTATE_MMCR0(r13) |
| 124 | ld r4, HSTATE_MMCR1(r13) |
| 125 | ld r5, HSTATE_MMCRA(r13) |
| 126 | ld r6, HSTATE_SIAR(r13) |
| 127 | ld r7, HSTATE_SDAR(r13) |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 128 | mtspr SPRN_MMCR1, r4 |
| 129 | mtspr SPRN_MMCRA, r5 |
Paul Mackerras | 72cde5a | 2014-03-25 10:47:08 +1100 | [diff] [blame] | 130 | mtspr SPRN_SIAR, r6 |
| 131 | mtspr SPRN_SDAR, r7 |
| 132 | BEGIN_FTR_SECTION |
Michael Ellerman | 9a4fc4e | 2014-07-10 19:34:31 +1000 | [diff] [blame] | 133 | ld r8, HSTATE_MMCR2(r13) |
| 134 | ld r9, HSTATE_SIER(r13) |
Paul Mackerras | 72cde5a | 2014-03-25 10:47:08 +1100 | [diff] [blame] | 135 | mtspr SPRN_MMCR2, r8 |
| 136 | mtspr SPRN_SIER, r9 |
| 137 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 138 | mtspr SPRN_MMCR0, r3 |
| 139 | isync |
| 140 | 23: |
| 141 | |
| 142 | /* |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 143 | * Reload DEC. HDEC interrupts were disabled when |
| 144 | * we reloaded the host's LPCR value. |
| 145 | */ |
| 146 | ld r3, HSTATE_DECEXP(r13) |
| 147 | mftb r4 |
| 148 | subf r4, r4, r3 |
| 149 | mtspr SPRN_DEC, r4 |
| 150 | |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 151 | /* hwthread_req may have got set by cede or no vcpu, so clear it */ |
| 152 | li r0, 0 |
| 153 | stb r0, HSTATE_HWTHREAD_REQ(r13) |
| 154 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 155 | /* |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 156 | * For external and machine check interrupts, we need |
| 157 | * to call the Linux handler to process the interrupt. |
| 158 | * We do that by jumping to absolute address 0x500 for |
| 159 | * external interrupts, or the machine_check_fwnmi label |
| 160 | * for machine checks (since firmware might have patched |
| 161 | * the vector area at 0x200). The [h]rfid at the end of the |
| 162 | * handler will return to the book3s_hv_interrupts.S code. |
| 163 | * For other interrupts we do the rfid to get back |
| 164 | * to the book3s_hv_interrupts.S code here. |
| 165 | */ |
| 166 | ld r8, 112+PPC_LR_STKOFF(r1) |
| 167 | addi r1, r1, 112 |
| 168 | ld r7, HSTATE_HOST_MSR(r13) |
| 169 | |
Paul Mackerras | 53af3ba | 2017-01-30 21:21:51 +1100 | [diff] [blame] | 170 | /* |
| 171 | * If we came back from the guest via a relocation-on interrupt, |
| 172 | * we will be in virtual mode at this point, which makes it a |
| 173 | * little easier to get back to the caller. |
| 174 | */ |
| 175 | mfmsr r0 |
| 176 | andi. r0, r0, MSR_IR /* in real mode? */ |
| 177 | bne .Lvirt_return |
| 178 | |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 179 | cmpwi cr1, r12, BOOK3S_INTERRUPT_MACHINE_CHECK |
| 180 | cmpwi r12, BOOK3S_INTERRUPT_EXTERNAL |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 181 | beq 11f |
Gautham R. Shenoy | 70aa396 | 2015-10-15 11:29:58 +0530 | [diff] [blame] | 182 | cmpwi r12, BOOK3S_INTERRUPT_H_DOORBELL |
| 183 | beq 15f /* Invoke the H_DOORBELL handler */ |
Mahesh Salgaonkar | 0869b6f | 2014-07-29 18:40:01 +0530 | [diff] [blame] | 184 | cmpwi cr2, r12, BOOK3S_INTERRUPT_HMI |
| 185 | beq cr2, 14f /* HMI check */ |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 186 | |
| 187 | /* RFI into the highmem handler, or branch to interrupt handler */ |
| 188 | mfmsr r6 |
| 189 | li r0, MSR_RI |
| 190 | andc r6, r6, r0 |
| 191 | mtmsrd r6, 1 /* Clear RI in MSR */ |
| 192 | mtsrr0 r8 |
| 193 | mtsrr1 r7 |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 194 | beq cr1, 13f /* machine check */ |
| 195 | RFI |
| 196 | |
| 197 | /* On POWER7, we have external interrupts set to use HSRR0/1 */ |
| 198 | 11: mtspr SPRN_HSRR0, r8 |
| 199 | mtspr SPRN_HSRR1, r7 |
| 200 | ba 0x500 |
| 201 | |
| 202 | 13: b machine_check_fwnmi |
| 203 | |
Mahesh Salgaonkar | 0869b6f | 2014-07-29 18:40:01 +0530 | [diff] [blame] | 204 | 14: mtspr SPRN_HSRR0, r8 |
| 205 | mtspr SPRN_HSRR1, r7 |
| 206 | b hmi_exception_after_realmode |
| 207 | |
Gautham R. Shenoy | 70aa396 | 2015-10-15 11:29:58 +0530 | [diff] [blame] | 208 | 15: mtspr SPRN_HSRR0, r8 |
| 209 | mtspr SPRN_HSRR1, r7 |
| 210 | ba 0xe80 |
| 211 | |
Paul Mackerras | 53af3ba | 2017-01-30 21:21:51 +1100 | [diff] [blame] | 212 | /* Virtual-mode return - can't get here for HMI or machine check */ |
| 213 | .Lvirt_return: |
| 214 | cmpwi r12, BOOK3S_INTERRUPT_EXTERNAL |
| 215 | beq 16f |
| 216 | cmpwi r12, BOOK3S_INTERRUPT_H_DOORBELL |
| 217 | beq 17f |
| 218 | andi. r0, r7, MSR_EE /* were interrupts hard-enabled? */ |
| 219 | beq 18f |
| 220 | mtmsrd r7, 1 /* if so then re-enable them */ |
| 221 | 18: mtlr r8 |
| 222 | blr |
| 223 | |
| 224 | 16: mtspr SPRN_HSRR0, r8 /* jump to reloc-on external vector */ |
| 225 | mtspr SPRN_HSRR1, r7 |
| 226 | b exc_virt_0x4500_hardware_interrupt |
| 227 | |
| 228 | 17: mtspr SPRN_HSRR0, r8 |
| 229 | mtspr SPRN_HSRR1, r7 |
| 230 | b exc_virt_0x4e80_h_doorbell |
| 231 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 232 | kvmppc_primary_no_guest: |
| 233 | /* We handle this much like a ceded vcpu */ |
Paul Mackerras | fd6d53b | 2015-03-28 14:21:08 +1100 | [diff] [blame] | 234 | /* put the HDEC into the DEC, since HDEC interrupts don't wake us */ |
Paul Mackerras | 2f27246 | 2017-05-22 16:25:14 +1000 | [diff] [blame] | 235 | /* HDEC may be larger than DEC for arch >= v3.00, but since the */ |
| 236 | /* HDEC value came from DEC in the first place, it will fit */ |
Paul Mackerras | fd6d53b | 2015-03-28 14:21:08 +1100 | [diff] [blame] | 237 | mfspr r3, SPRN_HDEC |
| 238 | mtspr SPRN_DEC, r3 |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 239 | /* |
| 240 | * Make sure the primary has finished the MMU switch. |
| 241 | * We should never get here on a secondary thread, but |
| 242 | * check it for robustness' sake. |
| 243 | */ |
| 244 | ld r5, HSTATE_KVM_VCORE(r13) |
| 245 | 65: lbz r0, VCORE_IN_GUEST(r5) |
| 246 | cmpwi r0, 0 |
| 247 | beq 65b |
| 248 | /* Set LPCR. */ |
| 249 | ld r8,VCORE_LPCR(r5) |
| 250 | mtspr SPRN_LPCR,r8 |
| 251 | isync |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 252 | /* set our bit in napping_threads */ |
| 253 | ld r5, HSTATE_KVM_VCORE(r13) |
| 254 | lbz r7, HSTATE_PTID(r13) |
| 255 | li r0, 1 |
| 256 | sld r0, r0, r7 |
| 257 | addi r6, r5, VCORE_NAPPING_THREADS |
| 258 | 1: lwarx r3, 0, r6 |
| 259 | or r3, r3, r0 |
| 260 | stwcx. r3, 0, r6 |
| 261 | bne 1b |
Paul Mackerras | 7d6c40d | 2015-03-28 14:21:09 +1100 | [diff] [blame] | 262 | /* order napping_threads update vs testing entry_exit_map */ |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 263 | isync |
| 264 | li r12, 0 |
| 265 | lwz r7, VCORE_ENTRY_EXIT(r5) |
| 266 | cmpwi r7, 0x100 |
| 267 | bge kvm_novcpu_exit /* another thread already exiting */ |
| 268 | li r3, NAPPING_NOVCPU |
| 269 | stb r3, HSTATE_NAPPING(r13) |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 270 | |
Paul Mackerras | ccc0777 | 2015-03-28 14:21:07 +1100 | [diff] [blame] | 271 | li r3, 0 /* Don't wake on privileged (OS) doorbell */ |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 272 | b kvm_do_nap |
| 273 | |
Suresh Warrier | 37f55d3 | 2016-08-19 15:35:46 +1000 | [diff] [blame] | 274 | /* |
| 275 | * kvm_novcpu_wakeup |
| 276 | * Entered from kvm_start_guest if kvm_hstate.napping is set |
| 277 | * to NAPPING_NOVCPU |
| 278 | * r2 = kernel TOC |
| 279 | * r13 = paca |
| 280 | */ |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 281 | kvm_novcpu_wakeup: |
| 282 | ld r1, HSTATE_HOST_R1(r13) |
| 283 | ld r5, HSTATE_KVM_VCORE(r13) |
| 284 | li r0, 0 |
| 285 | stb r0, HSTATE_NAPPING(r13) |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 286 | |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 287 | /* check the wake reason */ |
| 288 | bl kvmppc_check_wake_reason |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 289 | |
Suresh Warrier | 37f55d3 | 2016-08-19 15:35:46 +1000 | [diff] [blame] | 290 | /* |
| 291 | * Restore volatile registers since we could have called |
| 292 | * a C routine in kvmppc_check_wake_reason. |
| 293 | * r5 = VCORE |
| 294 | */ |
| 295 | ld r5, HSTATE_KVM_VCORE(r13) |
| 296 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 297 | /* see if any other thread is already exiting */ |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 298 | lwz r0, VCORE_ENTRY_EXIT(r5) |
| 299 | cmpwi r0, 0x100 |
| 300 | bge kvm_novcpu_exit |
| 301 | |
| 302 | /* clear our bit in napping_threads */ |
| 303 | lbz r7, HSTATE_PTID(r13) |
| 304 | li r0, 1 |
| 305 | sld r0, r0, r7 |
| 306 | addi r6, r5, VCORE_NAPPING_THREADS |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 307 | 4: lwarx r7, 0, r6 |
| 308 | andc r7, r7, r0 |
| 309 | stwcx. r7, 0, r6 |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 310 | bne 4b |
| 311 | |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 312 | /* See if the wake reason means we need to exit */ |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 313 | cmpdi r3, 0 |
| 314 | bge kvm_novcpu_exit |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 315 | |
Paul Mackerras | fd6d53b | 2015-03-28 14:21:08 +1100 | [diff] [blame] | 316 | /* See if our timeslice has expired (HDEC is negative) */ |
| 317 | mfspr r0, SPRN_HDEC |
Paul Mackerras | 2f27246 | 2017-05-22 16:25:14 +1000 | [diff] [blame] | 318 | EXTEND_HDEC(r0) |
Paul Mackerras | fd6d53b | 2015-03-28 14:21:08 +1100 | [diff] [blame] | 319 | li r12, BOOK3S_INTERRUPT_HV_DECREMENTER |
Paul Mackerras | 2f27246 | 2017-05-22 16:25:14 +1000 | [diff] [blame] | 320 | cmpdi r0, 0 |
Paul Mackerras | fd6d53b | 2015-03-28 14:21:08 +1100 | [diff] [blame] | 321 | blt kvm_novcpu_exit |
| 322 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 323 | /* Got an IPI but other vcpus aren't yet exiting, must be a latecomer */ |
| 324 | ld r4, HSTATE_KVM_VCPU(r13) |
| 325 | cmpdi r4, 0 |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 326 | beq kvmppc_primary_no_guest |
| 327 | |
| 328 | #ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING |
| 329 | addi r3, r4, VCPU_TB_RMENTRY |
| 330 | bl kvmhv_start_timing |
| 331 | #endif |
| 332 | b kvmppc_got_guest |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 333 | |
| 334 | kvm_novcpu_exit: |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 335 | #ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING |
| 336 | ld r4, HSTATE_KVM_VCPU(r13) |
| 337 | cmpdi r4, 0 |
| 338 | beq 13f |
| 339 | addi r3, r4, VCPU_TB_RMEXIT |
| 340 | bl kvmhv_accumulate_time |
| 341 | #endif |
Paul Mackerras | eddb60f | 2015-03-28 14:21:11 +1100 | [diff] [blame] | 342 | 13: mr r3, r12 |
Paul Mackerras | 7ceaa6d | 2017-06-16 11:53:19 +1000 | [diff] [blame] | 343 | stw r12, STACK_SLOT_TRAP(r1) |
Paul Mackerras | eddb60f | 2015-03-28 14:21:11 +1100 | [diff] [blame] | 344 | bl kvmhv_commence_exit |
| 345 | nop |
Paul Mackerras | 7ceaa6d | 2017-06-16 11:53:19 +1000 | [diff] [blame] | 346 | lwz r12, STACK_SLOT_TRAP(r1) |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 347 | b kvmhv_switch_to_host |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 348 | |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 349 | /* |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 350 | * We come in here when wakened from nap mode. |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 351 | * Relocation is off and most register values are lost. |
| 352 | * r13 points to the PACA. |
| 353 | */ |
| 354 | .globl kvm_start_guest |
| 355 | kvm_start_guest: |
Preeti U Murthy | fd17dc7 | 2014-04-11 16:01:58 +0530 | [diff] [blame] | 356 | |
| 357 | /* Set runlatch bit the minute you wake up from nap */ |
Paul Mackerras | 1f09c3e | 2015-03-28 14:21:04 +1100 | [diff] [blame] | 358 | mfspr r0, SPRN_CTRLF |
| 359 | ori r0, r0, 1 |
| 360 | mtspr SPRN_CTRLT, r0 |
Preeti U Murthy | fd17dc7 | 2014-04-11 16:01:58 +0530 | [diff] [blame] | 361 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 362 | ld r2,PACATOC(r13) |
| 363 | |
Paul Mackerras | f0888f7 | 2012-02-03 00:54:17 +0000 | [diff] [blame] | 364 | li r0,KVM_HWTHREAD_IN_KVM |
| 365 | stb r0,HSTATE_HWTHREAD_STATE(r13) |
| 366 | |
| 367 | /* NV GPR values from power7_idle() will no longer be valid */ |
| 368 | li r0,1 |
| 369 | stb r0,PACA_NAPSTATELOST(r13) |
| 370 | |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 371 | /* were we napping due to cede? */ |
| 372 | lbz r0,HSTATE_NAPPING(r13) |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 373 | cmpwi r0,NAPPING_CEDE |
| 374 | beq kvm_end_cede |
| 375 | cmpwi r0,NAPPING_NOVCPU |
| 376 | beq kvm_novcpu_wakeup |
| 377 | |
| 378 | ld r1,PACAEMERGSP(r13) |
| 379 | subi r1,r1,STACK_FRAME_OVERHEAD |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 380 | |
| 381 | /* |
| 382 | * We weren't napping due to cede, so this must be a secondary |
| 383 | * thread being woken up to run a guest, or being woken up due |
| 384 | * to a stray IPI. (Or due to some machine check or hypervisor |
| 385 | * maintenance interrupt while the core is in KVM.) |
| 386 | */ |
Paul Mackerras | f0888f7 | 2012-02-03 00:54:17 +0000 | [diff] [blame] | 387 | |
| 388 | /* Check the wake reason in SRR1 to see why we got here */ |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 389 | bl kvmppc_check_wake_reason |
Suresh Warrier | 37f55d3 | 2016-08-19 15:35:46 +1000 | [diff] [blame] | 390 | /* |
| 391 | * kvmppc_check_wake_reason could invoke a C routine, but we |
| 392 | * have no volatile registers to restore when we return. |
| 393 | */ |
| 394 | |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 395 | cmpdi r3, 0 |
| 396 | bge kvm_no_guest |
Paul Mackerras | f0888f7 | 2012-02-03 00:54:17 +0000 | [diff] [blame] | 397 | |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 398 | /* get vcore pointer, NULL if we have nothing to run */ |
| 399 | ld r5,HSTATE_KVM_VCORE(r13) |
| 400 | cmpdi r5,0 |
| 401 | /* if we have no vcore to run, go back to sleep */ |
Paul Mackerras | 7b444c6 | 2012-10-15 01:16:14 +0000 | [diff] [blame] | 402 | beq kvm_no_guest |
Paul Mackerras | f0888f7 | 2012-02-03 00:54:17 +0000 | [diff] [blame] | 403 | |
Paul Mackerras | 56548fc | 2014-12-03 14:48:40 +1100 | [diff] [blame] | 404 | kvm_secondary_got_guest: |
| 405 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 406 | /* Set HSTATE_DSCR(r13) to something sensible */ |
Anshuman Khandual | 1db3652 | 2015-05-21 12:13:03 +0530 | [diff] [blame] | 407 | ld r6, PACA_DSCR_DEFAULT(r13) |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 408 | std r6, HSTATE_DSCR(r13) |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 409 | |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 410 | /* On thread 0 of a subcore, set HDEC to max */ |
| 411 | lbz r4, HSTATE_PTID(r13) |
| 412 | cmpwi r4, 0 |
| 413 | bne 63f |
Paul Mackerras | 2f27246 | 2017-05-22 16:25:14 +1000 | [diff] [blame] | 414 | LOAD_REG_ADDR(r6, decrementer_max) |
| 415 | ld r6, 0(r6) |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 416 | mtspr SPRN_HDEC, r6 |
| 417 | /* and set per-LPAR registers, if doing dynamic micro-threading */ |
| 418 | ld r6, HSTATE_SPLIT_MODE(r13) |
| 419 | cmpdi r6, 0 |
| 420 | beq 63f |
| 421 | ld r0, KVM_SPLIT_RPR(r6) |
| 422 | mtspr SPRN_RPR, r0 |
| 423 | ld r0, KVM_SPLIT_PMMAR(r6) |
| 424 | mtspr SPRN_PMMAR, r0 |
| 425 | ld r0, KVM_SPLIT_LDBAR(r6) |
| 426 | mtspr SPRN_LDBAR, r0 |
| 427 | isync |
| 428 | 63: |
| 429 | /* Order load of vcpu after load of vcore */ |
Paul Mackerras | 5d5b99c | 2015-03-28 14:21:06 +1100 | [diff] [blame] | 430 | lwsync |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 431 | ld r4, HSTATE_KVM_VCPU(r13) |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 432 | bl kvmppc_hv_entry |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 433 | |
| 434 | /* Back from the guest, go back to nap */ |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 435 | /* Clear our vcpu and vcore pointers so we don't come back in early */ |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 436 | li r0, 0 |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 437 | std r0, HSTATE_KVM_VCPU(r13) |
Paul Mackerras | f019b7a | 2013-11-16 17:46:03 +1100 | [diff] [blame] | 438 | /* |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 439 | * Once we clear HSTATE_KVM_VCORE(r13), the code in |
Paul Mackerras | 5d5b99c | 2015-03-28 14:21:06 +1100 | [diff] [blame] | 440 | * kvmppc_run_core() is going to assume that all our vcpu |
| 441 | * state is visible in memory. This lwsync makes sure |
| 442 | * that that is true. |
Paul Mackerras | f019b7a | 2013-11-16 17:46:03 +1100 | [diff] [blame] | 443 | */ |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 444 | lwsync |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 445 | std r0, HSTATE_KVM_VCORE(r13) |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 446 | |
Mahesh Salgaonkar | fd7bacb | 2016-05-15 09:44:26 +0530 | [diff] [blame] | 447 | /* |
| 448 | * All secondaries exiting guest will fall through this path. |
| 449 | * Before proceeding, just check for HMI interrupt and |
| 450 | * invoke opal hmi handler. By now we are sure that the |
| 451 | * primary thread on this core/subcore has already made partition |
| 452 | * switch/TB resync and we are good to call opal hmi handler. |
| 453 | */ |
| 454 | cmpwi r12, BOOK3S_INTERRUPT_HMI |
| 455 | bne kvm_no_guest |
| 456 | |
| 457 | li r3,0 /* NULL argument */ |
| 458 | bl hmi_exception_realmode |
Paul Mackerras | 56548fc | 2014-12-03 14:48:40 +1100 | [diff] [blame] | 459 | /* |
| 460 | * At this point we have finished executing in the guest. |
| 461 | * We need to wait for hwthread_req to become zero, since |
| 462 | * we may not turn on the MMU while hwthread_req is non-zero. |
| 463 | * While waiting we also need to check if we get given a vcpu to run. |
| 464 | */ |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 465 | kvm_no_guest: |
Paul Mackerras | 56548fc | 2014-12-03 14:48:40 +1100 | [diff] [blame] | 466 | lbz r3, HSTATE_HWTHREAD_REQ(r13) |
| 467 | cmpwi r3, 0 |
| 468 | bne 53f |
| 469 | HMT_MEDIUM |
| 470 | li r0, KVM_HWTHREAD_IN_KERNEL |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 471 | stb r0, HSTATE_HWTHREAD_STATE(r13) |
Paul Mackerras | 56548fc | 2014-12-03 14:48:40 +1100 | [diff] [blame] | 472 | /* need to recheck hwthread_req after a barrier, to avoid race */ |
| 473 | sync |
| 474 | lbz r3, HSTATE_HWTHREAD_REQ(r13) |
| 475 | cmpwi r3, 0 |
| 476 | bne 54f |
| 477 | /* |
Shreyas B. Prabhu | 5fa6b6b | 2016-07-08 11:50:46 +0530 | [diff] [blame] | 478 | * We jump to pnv_wakeup_loss, which will return to the caller |
Paul Mackerras | 56548fc | 2014-12-03 14:48:40 +1100 | [diff] [blame] | 479 | * of power7_nap in the powernv cpu offline loop. The value we |
| 480 | * put in r3 becomes the return value for power7_nap. |
| 481 | */ |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 482 | li r3, LPCR_PECE0 |
| 483 | mfspr r4, SPRN_LPCR |
| 484 | rlwimi r4, r3, 0, LPCR_PECE0 | LPCR_PECE1 |
| 485 | mtspr SPRN_LPCR, r4 |
Paul Mackerras | 56548fc | 2014-12-03 14:48:40 +1100 | [diff] [blame] | 486 | li r3, 0 |
Shreyas B. Prabhu | 5fa6b6b | 2016-07-08 11:50:46 +0530 | [diff] [blame] | 487 | b pnv_wakeup_loss |
Paul Mackerras | 56548fc | 2014-12-03 14:48:40 +1100 | [diff] [blame] | 488 | |
| 489 | 53: HMT_LOW |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 490 | ld r5, HSTATE_KVM_VCORE(r13) |
| 491 | cmpdi r5, 0 |
| 492 | bne 60f |
| 493 | ld r3, HSTATE_SPLIT_MODE(r13) |
| 494 | cmpdi r3, 0 |
| 495 | beq kvm_no_guest |
| 496 | lbz r0, KVM_SPLIT_DO_NAP(r3) |
| 497 | cmpwi r0, 0 |
Paul Mackerras | 56548fc | 2014-12-03 14:48:40 +1100 | [diff] [blame] | 498 | beq kvm_no_guest |
| 499 | HMT_MEDIUM |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 500 | b kvm_unsplit_nap |
| 501 | 60: HMT_MEDIUM |
Paul Mackerras | 56548fc | 2014-12-03 14:48:40 +1100 | [diff] [blame] | 502 | b kvm_secondary_got_guest |
| 503 | |
| 504 | 54: li r0, KVM_HWTHREAD_IN_KVM |
| 505 | stb r0, HSTATE_HWTHREAD_STATE(r13) |
| 506 | b kvm_no_guest |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 507 | |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 508 | /* |
| 509 | * Here the primary thread is trying to return the core to |
| 510 | * whole-core mode, so we need to nap. |
| 511 | */ |
| 512 | kvm_unsplit_nap: |
Gautham R. Shenoy | 7f23532 | 2015-09-02 21:48:58 +0530 | [diff] [blame] | 513 | /* |
Mahesh Salgaonkar | fd7bacb | 2016-05-15 09:44:26 +0530 | [diff] [blame] | 514 | * When secondaries are napping in kvm_unsplit_nap() with |
| 515 | * hwthread_req = 1, HMI goes ignored even though subcores are |
| 516 | * already exited the guest. Hence HMI keeps waking up secondaries |
| 517 | * from nap in a loop and secondaries always go back to nap since |
| 518 | * no vcore is assigned to them. This makes impossible for primary |
| 519 | * thread to get hold of secondary threads resulting into a soft |
| 520 | * lockup in KVM path. |
| 521 | * |
| 522 | * Let us check if HMI is pending and handle it before we go to nap. |
| 523 | */ |
| 524 | cmpwi r12, BOOK3S_INTERRUPT_HMI |
| 525 | bne 55f |
| 526 | li r3, 0 /* NULL argument */ |
| 527 | bl hmi_exception_realmode |
| 528 | 55: |
| 529 | /* |
Gautham R. Shenoy | 7f23532 | 2015-09-02 21:48:58 +0530 | [diff] [blame] | 530 | * Ensure that secondary doesn't nap when it has |
| 531 | * its vcore pointer set. |
| 532 | */ |
| 533 | sync /* matches smp_mb() before setting split_info.do_nap */ |
| 534 | ld r0, HSTATE_KVM_VCORE(r13) |
| 535 | cmpdi r0, 0 |
| 536 | bne kvm_no_guest |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 537 | /* clear any pending message */ |
| 538 | BEGIN_FTR_SECTION |
| 539 | lis r6, (PPC_DBELL_SERVER << (63-36))@h |
| 540 | PPC_MSGCLR(6) |
| 541 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) |
| 542 | /* Set kvm_split_mode.napped[tid] = 1 */ |
| 543 | ld r3, HSTATE_SPLIT_MODE(r13) |
| 544 | li r0, 1 |
| 545 | lhz r4, PACAPACAINDEX(r13) |
| 546 | clrldi r4, r4, 61 /* micro-threading => P8 => 8 threads/core */ |
| 547 | addi r4, r4, KVM_SPLIT_NAPPED |
| 548 | stbx r0, r3, r4 |
| 549 | /* Check the do_nap flag again after setting napped[] */ |
| 550 | sync |
| 551 | lbz r0, KVM_SPLIT_DO_NAP(r3) |
| 552 | cmpwi r0, 0 |
| 553 | beq 57f |
| 554 | li r3, (LPCR_PECEDH | LPCR_PECE0) >> 4 |
Paul Mackerras | bf53c88 | 2016-11-18 14:34:07 +1100 | [diff] [blame] | 555 | mfspr r5, SPRN_LPCR |
| 556 | rlwimi r5, r3, 4, (LPCR_PECEDP | LPCR_PECEDH | LPCR_PECE0 | LPCR_PECE1) |
| 557 | b kvm_nap_sequence |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 558 | |
| 559 | 57: li r0, 0 |
| 560 | stbx r0, r3, r4 |
| 561 | b kvm_no_guest |
| 562 | |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 563 | /****************************************************************************** |
| 564 | * * |
| 565 | * Entry code * |
| 566 | * * |
| 567 | *****************************************************************************/ |
| 568 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 569 | .global kvmppc_hv_entry |
| 570 | kvmppc_hv_entry: |
| 571 | |
| 572 | /* Required state: |
| 573 | * |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 574 | * R4 = vcpu pointer (or NULL) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 575 | * MSR = ~IR|DR |
| 576 | * R13 = PACA |
| 577 | * R1 = host R1 |
Michael Neuling | 06a29e4 | 2014-08-19 14:59:30 +1000 | [diff] [blame] | 578 | * R2 = TOC |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 579 | * all other volatile GPRS = free |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 580 | * Does not preserve non-volatile GPRs or CR fields |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 581 | */ |
| 582 | mflr r0 |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 583 | std r0, PPC_LR_STKOFF(r1) |
Paul Mackerras | 7ceaa6d | 2017-06-16 11:53:19 +1000 | [diff] [blame] | 584 | stdu r1, -SFS(r1) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 585 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 586 | /* Save R1 in the PACA */ |
| 587 | std r1, HSTATE_HOST_R1(r13) |
| 588 | |
Paul Mackerras | 44a3add | 2013-10-04 21:45:04 +1000 | [diff] [blame] | 589 | li r6, KVM_GUEST_MODE_HOST_HV |
| 590 | stb r6, HSTATE_IN_GUEST(r13) |
| 591 | |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 592 | #ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING |
| 593 | /* Store initial timestamp */ |
| 594 | cmpdi r4, 0 |
| 595 | beq 1f |
| 596 | addi r3, r4, VCPU_TB_RMENTRY |
| 597 | bl kvmhv_start_timing |
| 598 | 1: |
| 599 | #endif |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 600 | |
| 601 | /* Use cr7 as an indication of radix mode */ |
| 602 | ld r5, HSTATE_KVM_VCORE(r13) |
| 603 | ld r9, VCORE_KVM(r5) /* pointer to struct kvm */ |
| 604 | lbz r0, KVM_RADIX(r9) |
| 605 | cmpwi cr7, r0, 0 |
| 606 | |
| 607 | /* Clear out SLB if hash */ |
| 608 | bne cr7, 2f |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 609 | li r6,0 |
| 610 | slbmte r6,r6 |
| 611 | slbia |
| 612 | ptesync |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 613 | 2: |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 614 | /* |
Paul Mackerras | c17b98c | 2014-12-03 13:30:38 +1100 | [diff] [blame] | 615 | * POWER7/POWER8 host -> guest partition switch code. |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 616 | * We don't have to lock against concurrent tlbies, |
| 617 | * but we do have to coordinate across hardware threads. |
| 618 | */ |
Paul Mackerras | 7d6c40d | 2015-03-28 14:21:09 +1100 | [diff] [blame] | 619 | /* Set bit in entry map iff exit map is zero. */ |
Paul Mackerras | 7d6c40d | 2015-03-28 14:21:09 +1100 | [diff] [blame] | 620 | li r7, 1 |
| 621 | lbz r6, HSTATE_PTID(r13) |
| 622 | sld r7, r7, r6 |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 623 | addi r8, r5, VCORE_ENTRY_EXIT |
| 624 | 21: lwarx r3, 0, r8 |
Paul Mackerras | 7d6c40d | 2015-03-28 14:21:09 +1100 | [diff] [blame] | 625 | cmpwi r3, 0x100 /* any threads starting to exit? */ |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 626 | bge secondary_too_late /* if so we're too late to the party */ |
Paul Mackerras | 7d6c40d | 2015-03-28 14:21:09 +1100 | [diff] [blame] | 627 | or r3, r3, r7 |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 628 | stwcx. r3, 0, r8 |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 629 | bne 21b |
| 630 | |
| 631 | /* Primary thread switches to guest partition. */ |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 632 | cmpwi r6,0 |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 633 | bne 10f |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 634 | lwz r7,KVM_LPID(r9) |
Paul Mackerras | 7a84084 | 2016-11-16 22:25:20 +1100 | [diff] [blame] | 635 | BEGIN_FTR_SECTION |
| 636 | ld r6,KVM_SDR1(r9) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 637 | li r0,LPID_RSVD /* switch to reserved LPID */ |
| 638 | mtspr SPRN_LPID,r0 |
| 639 | ptesync |
| 640 | mtspr SPRN_SDR1,r6 /* switch to partition page table */ |
Paul Mackerras | 7a84084 | 2016-11-16 22:25:20 +1100 | [diff] [blame] | 641 | END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_300) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 642 | mtspr SPRN_LPID,r7 |
| 643 | isync |
Paul Mackerras | 1b400ba | 2012-11-21 23:28:08 +0000 | [diff] [blame] | 644 | |
| 645 | /* See if we need to flush the TLB */ |
| 646 | lhz r6,PACAPACAINDEX(r13) /* test_bit(cpu, need_tlb_flush) */ |
Paul Mackerras | a29ebea | 2017-01-30 21:21:50 +1100 | [diff] [blame] | 647 | BEGIN_FTR_SECTION |
| 648 | /* |
| 649 | * On POWER9, individual threads can come in here, but the |
| 650 | * TLB is shared between the 4 threads in a core, hence |
| 651 | * invalidating on one thread invalidates for all. |
| 652 | * Thus we make all 4 threads use the same bit here. |
| 653 | */ |
| 654 | clrrdi r6,r6,2 |
| 655 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300) |
Paul Mackerras | 1b400ba | 2012-11-21 23:28:08 +0000 | [diff] [blame] | 656 | clrldi r7,r6,64-6 /* extract bit number (6 bits) */ |
| 657 | srdi r6,r6,6 /* doubleword number */ |
| 658 | sldi r6,r6,3 /* address offset */ |
| 659 | add r6,r6,r9 |
| 660 | addi r6,r6,KVM_NEED_FLUSH /* dword in kvm->arch.need_tlb_flush */ |
Paul Mackerras | a29ebea | 2017-01-30 21:21:50 +1100 | [diff] [blame] | 661 | li r8,1 |
| 662 | sld r8,r8,r7 |
Paul Mackerras | 1b400ba | 2012-11-21 23:28:08 +0000 | [diff] [blame] | 663 | ld r7,0(r6) |
Paul Mackerras | a29ebea | 2017-01-30 21:21:50 +1100 | [diff] [blame] | 664 | and. r7,r7,r8 |
Paul Mackerras | 1b400ba | 2012-11-21 23:28:08 +0000 | [diff] [blame] | 665 | beq 22f |
Paul Mackerras | ca25205 | 2014-01-08 21:25:22 +1100 | [diff] [blame] | 666 | /* Flush the TLB of any entries for this LPID */ |
Paul Mackerras | a29ebea | 2017-01-30 21:21:50 +1100 | [diff] [blame] | 667 | lwz r0,KVM_TLB_SETS(r9) |
| 668 | mtctr r0 |
Paul Mackerras | 1b400ba | 2012-11-21 23:28:08 +0000 | [diff] [blame] | 669 | li r7,0x800 /* IS field = 0b10 */ |
| 670 | ptesync |
Paul Mackerras | a29ebea | 2017-01-30 21:21:50 +1100 | [diff] [blame] | 671 | li r0,0 /* RS for P9 version of tlbiel */ |
| 672 | bne cr7, 29f |
| 673 | 28: tlbiel r7 /* On P9, rs=0, RIC=0, PRS=0, R=0 */ |
Paul Mackerras | 1b400ba | 2012-11-21 23:28:08 +0000 | [diff] [blame] | 674 | addi r7,r7,0x1000 |
| 675 | bdnz 28b |
Paul Mackerras | a29ebea | 2017-01-30 21:21:50 +1100 | [diff] [blame] | 676 | b 30f |
| 677 | 29: PPC_TLBIEL(7,0,2,1,1) /* for radix, RIC=2, PRS=1, R=1 */ |
| 678 | addi r7,r7,0x1000 |
| 679 | bdnz 29b |
| 680 | 30: ptesync |
| 681 | 23: ldarx r7,0,r6 /* clear the bit after TLB flushed */ |
| 682 | andc r7,r7,r8 |
| 683 | stdcx. r7,0,r6 |
| 684 | bne 23b |
Paul Mackerras | 1b400ba | 2012-11-21 23:28:08 +0000 | [diff] [blame] | 685 | |
Paul Mackerras | 93b0f4d | 2013-09-06 13:17:46 +1000 | [diff] [blame] | 686 | /* Add timebase offset onto timebase */ |
| 687 | 22: ld r8,VCORE_TB_OFFSET(r5) |
| 688 | cmpdi r8,0 |
| 689 | beq 37f |
| 690 | mftb r6 /* current host timebase */ |
| 691 | add r8,r8,r6 |
| 692 | mtspr SPRN_TBU40,r8 /* update upper 40 bits */ |
| 693 | mftb r7 /* check if lower 24 bits overflowed */ |
| 694 | clrldi r6,r6,40 |
| 695 | clrldi r7,r7,40 |
| 696 | cmpld r7,r6 |
| 697 | bge 37f |
| 698 | addis r8,r8,0x100 /* if so, increment upper 40 bits */ |
| 699 | mtspr SPRN_TBU40,r8 |
| 700 | |
Paul Mackerras | 388cc6e | 2013-09-21 14:35:02 +1000 | [diff] [blame] | 701 | /* Load guest PCR value to select appropriate compat mode */ |
| 702 | 37: ld r7, VCORE_PCR(r5) |
| 703 | cmpdi r7, 0 |
| 704 | beq 38f |
| 705 | mtspr SPRN_PCR, r7 |
| 706 | 38: |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 707 | |
| 708 | BEGIN_FTR_SECTION |
Paul Mackerras | 88b02cf9 | 2016-09-15 13:42:52 +1000 | [diff] [blame] | 709 | /* DPDES and VTB are shared between threads */ |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 710 | ld r8, VCORE_DPDES(r5) |
Paul Mackerras | 88b02cf9 | 2016-09-15 13:42:52 +1000 | [diff] [blame] | 711 | ld r7, VCORE_VTB(r5) |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 712 | mtspr SPRN_DPDES, r8 |
Paul Mackerras | 88b02cf9 | 2016-09-15 13:42:52 +1000 | [diff] [blame] | 713 | mtspr SPRN_VTB, r7 |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 714 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) |
| 715 | |
Mahesh Salgaonkar | fd7bacb | 2016-05-15 09:44:26 +0530 | [diff] [blame] | 716 | /* Mark the subcore state as inside guest */ |
| 717 | bl kvmppc_subcore_enter_guest |
| 718 | nop |
| 719 | ld r5, HSTATE_KVM_VCORE(r13) |
| 720 | ld r4, HSTATE_KVM_VCPU(r13) |
Paul Mackerras | 388cc6e | 2013-09-21 14:35:02 +1000 | [diff] [blame] | 721 | li r0,1 |
Paul Mackerras | 371fefd | 2011-06-29 00:23:08 +0000 | [diff] [blame] | 722 | stb r0,VCORE_IN_GUEST(r5) /* signal secondaries to continue */ |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 723 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 724 | /* Do we have a guest vcpu to run? */ |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 725 | 10: cmpdi r4, 0 |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 726 | beq kvmppc_primary_no_guest |
| 727 | kvmppc_got_guest: |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 728 | |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 729 | /* Load up guest SLB entries (N.B. slb_max will be 0 for radix) */ |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 730 | lwz r5,VCPU_SLB_MAX(r4) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 731 | cmpwi r5,0 |
| 732 | beq 9f |
| 733 | mtctr r5 |
| 734 | addi r6,r4,VCPU_SLB |
| 735 | 1: ld r8,VCPU_SLB_E(r6) |
| 736 | ld r9,VCPU_SLB_V(r6) |
| 737 | slbmte r9,r8 |
| 738 | addi r6,r6,VCPU_SLB_SIZE |
| 739 | bdnz 1b |
| 740 | 9: |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 741 | /* Increment yield count if they have a VPA */ |
| 742 | ld r3, VCPU_VPA(r4) |
| 743 | cmpdi r3, 0 |
| 744 | beq 25f |
Alexander Graf | 0865a58 | 2014-06-11 10:36:17 +0200 | [diff] [blame] | 745 | li r6, LPPACA_YIELDCOUNT |
| 746 | LWZX_BE r5, r3, r6 |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 747 | addi r5, r5, 1 |
Alexander Graf | 0865a58 | 2014-06-11 10:36:17 +0200 | [diff] [blame] | 748 | STWX_BE r5, r3, r6 |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 749 | li r6, 1 |
| 750 | stb r6, VCPU_VPA_DIRTY(r4) |
| 751 | 25: |
| 752 | |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 753 | /* Save purr/spurr */ |
| 754 | mfspr r5,SPRN_PURR |
| 755 | mfspr r6,SPRN_SPURR |
| 756 | std r5,HSTATE_PURR(r13) |
| 757 | std r6,HSTATE_SPURR(r13) |
| 758 | ld r7,VCPU_PURR(r4) |
| 759 | ld r8,VCPU_SPURR(r4) |
| 760 | mtspr SPRN_PURR,r7 |
| 761 | mtspr SPRN_SPURR,r8 |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 762 | |
Paul Mackerras | e9cf1e0 | 2016-11-18 13:11:42 +1100 | [diff] [blame] | 763 | /* Save host values of some registers */ |
| 764 | BEGIN_FTR_SECTION |
| 765 | mfspr r5, SPRN_TIDR |
| 766 | mfspr r6, SPRN_PSSCR |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 767 | mfspr r7, SPRN_PID |
Paul Mackerras | 4c3bb4c | 2017-06-15 15:43:17 +1000 | [diff] [blame] | 768 | mfspr r8, SPRN_IAMR |
Paul Mackerras | e9cf1e0 | 2016-11-18 13:11:42 +1100 | [diff] [blame] | 769 | std r5, STACK_SLOT_TID(r1) |
| 770 | std r6, STACK_SLOT_PSSCR(r1) |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 771 | std r7, STACK_SLOT_PID(r1) |
Paul Mackerras | 4c3bb4c | 2017-06-15 15:43:17 +1000 | [diff] [blame] | 772 | std r8, STACK_SLOT_IAMR(r1) |
Paul Mackerras | 769377f | 2017-02-15 14:30:17 +1100 | [diff] [blame] | 773 | mfspr r5, SPRN_HFSCR |
| 774 | std r5, STACK_SLOT_HFSCR(r1) |
Paul Mackerras | e9cf1e0 | 2016-11-18 13:11:42 +1100 | [diff] [blame] | 775 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300) |
Paul Mackerras | 7ceaa6d | 2017-06-16 11:53:19 +1000 | [diff] [blame] | 776 | BEGIN_FTR_SECTION |
| 777 | mfspr r5, SPRN_CIABR |
| 778 | mfspr r6, SPRN_DAWR |
| 779 | mfspr r7, SPRN_DAWRX |
| 780 | std r5, STACK_SLOT_CIABR(r1) |
| 781 | std r6, STACK_SLOT_DAWR(r1) |
| 782 | std r7, STACK_SLOT_DAWRX(r1) |
| 783 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) |
Paul Mackerras | e9cf1e0 | 2016-11-18 13:11:42 +1100 | [diff] [blame] | 784 | |
Michael Neuling | eee7ff9 | 2014-01-08 21:25:19 +1100 | [diff] [blame] | 785 | BEGIN_FTR_SECTION |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 786 | /* Set partition DABR */ |
| 787 | /* Do this before re-enabling PMU to avoid P7 DABR corruption bug */ |
Paul Mackerras | 8563bf5 | 2014-01-08 21:25:29 +1100 | [diff] [blame] | 788 | lwz r5,VCPU_DABRX(r4) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 789 | ld r6,VCPU_DABR(r4) |
| 790 | mtspr SPRN_DABRX,r5 |
| 791 | mtspr SPRN_DABR,r6 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 792 | isync |
Michael Neuling | eee7ff9 | 2014-01-08 21:25:19 +1100 | [diff] [blame] | 793 | END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 794 | |
Michael Neuling | e4e3812 | 2014-03-25 10:47:02 +1100 | [diff] [blame] | 795 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM |
| 796 | BEGIN_FTR_SECTION |
Paul Mackerras | f024ee0 | 2016-06-22 14:21:59 +1000 | [diff] [blame] | 797 | bl kvmppc_restore_tm |
| 798 | END_FTR_SECTION_IFSET(CPU_FTR_TM) |
Michael Neuling | e4e3812 | 2014-03-25 10:47:02 +1100 | [diff] [blame] | 799 | #endif |
| 800 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 801 | /* Load guest PMU registers */ |
| 802 | /* R4 is live here (vcpu pointer) */ |
| 803 | li r3, 1 |
| 804 | sldi r3, r3, 31 /* MMCR0_FC (freeze counters) bit */ |
| 805 | mtspr SPRN_MMCR0, r3 /* freeze all counters, disable ints */ |
| 806 | isync |
Paul Mackerras | 9bc01a9 | 2014-05-26 19:48:40 +1000 | [diff] [blame] | 807 | BEGIN_FTR_SECTION |
| 808 | ld r3, VCPU_MMCR(r4) |
| 809 | andi. r5, r3, MMCR0_PMAO_SYNC | MMCR0_PMAO |
| 810 | cmpwi r5, MMCR0_PMAO |
| 811 | beql kvmppc_fix_pmao |
| 812 | END_FTR_SECTION_IFSET(CPU_FTR_PMAO_BUG) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 813 | lwz r3, VCPU_PMC(r4) /* always load up guest PMU registers */ |
| 814 | lwz r5, VCPU_PMC + 4(r4) /* to prevent information leak */ |
| 815 | lwz r6, VCPU_PMC + 8(r4) |
| 816 | lwz r7, VCPU_PMC + 12(r4) |
| 817 | lwz r8, VCPU_PMC + 16(r4) |
| 818 | lwz r9, VCPU_PMC + 20(r4) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 819 | mtspr SPRN_PMC1, r3 |
| 820 | mtspr SPRN_PMC2, r5 |
| 821 | mtspr SPRN_PMC3, r6 |
| 822 | mtspr SPRN_PMC4, r7 |
| 823 | mtspr SPRN_PMC5, r8 |
| 824 | mtspr SPRN_PMC6, r9 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 825 | ld r3, VCPU_MMCR(r4) |
| 826 | ld r5, VCPU_MMCR + 8(r4) |
| 827 | ld r6, VCPU_MMCR + 16(r4) |
| 828 | ld r7, VCPU_SIAR(r4) |
| 829 | ld r8, VCPU_SDAR(r4) |
| 830 | mtspr SPRN_MMCR1, r5 |
| 831 | mtspr SPRN_MMCRA, r6 |
| 832 | mtspr SPRN_SIAR, r7 |
| 833 | mtspr SPRN_SDAR, r8 |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 834 | BEGIN_FTR_SECTION |
| 835 | ld r5, VCPU_MMCR + 24(r4) |
| 836 | ld r6, VCPU_SIER(r4) |
Paul Mackerras | 83677f5 | 2016-11-16 22:33:27 +1100 | [diff] [blame] | 837 | mtspr SPRN_MMCR2, r5 |
| 838 | mtspr SPRN_SIER, r6 |
| 839 | BEGIN_FTR_SECTION_NESTED(96) |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 840 | lwz r7, VCPU_PMC + 24(r4) |
| 841 | lwz r8, VCPU_PMC + 28(r4) |
| 842 | ld r9, VCPU_MMCR + 32(r4) |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 843 | mtspr SPRN_SPMC1, r7 |
| 844 | mtspr SPRN_SPMC2, r8 |
| 845 | mtspr SPRN_MMCRS, r9 |
Paul Mackerras | 83677f5 | 2016-11-16 22:33:27 +1100 | [diff] [blame] | 846 | END_FTR_SECTION_NESTED(CPU_FTR_ARCH_300, 0, 96) |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 847 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 848 | mtspr SPRN_MMCR0, r3 |
| 849 | isync |
| 850 | |
| 851 | /* Load up FP, VMX and VSX registers */ |
| 852 | bl kvmppc_load_fp |
| 853 | |
| 854 | ld r14, VCPU_GPR(R14)(r4) |
| 855 | ld r15, VCPU_GPR(R15)(r4) |
| 856 | ld r16, VCPU_GPR(R16)(r4) |
| 857 | ld r17, VCPU_GPR(R17)(r4) |
| 858 | ld r18, VCPU_GPR(R18)(r4) |
| 859 | ld r19, VCPU_GPR(R19)(r4) |
| 860 | ld r20, VCPU_GPR(R20)(r4) |
| 861 | ld r21, VCPU_GPR(R21)(r4) |
| 862 | ld r22, VCPU_GPR(R22)(r4) |
| 863 | ld r23, VCPU_GPR(R23)(r4) |
| 864 | ld r24, VCPU_GPR(R24)(r4) |
| 865 | ld r25, VCPU_GPR(R25)(r4) |
| 866 | ld r26, VCPU_GPR(R26)(r4) |
| 867 | ld r27, VCPU_GPR(R27)(r4) |
| 868 | ld r28, VCPU_GPR(R28)(r4) |
| 869 | ld r29, VCPU_GPR(R29)(r4) |
| 870 | ld r30, VCPU_GPR(R30)(r4) |
| 871 | ld r31, VCPU_GPR(R31)(r4) |
| 872 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 873 | /* Switch DSCR to guest value */ |
| 874 | ld r5, VCPU_DSCR(r4) |
| 875 | mtspr SPRN_DSCR, r5 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 876 | |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 877 | BEGIN_FTR_SECTION |
Paul Mackerras | c17b98c | 2014-12-03 13:30:38 +1100 | [diff] [blame] | 878 | /* Skip next section on POWER7 */ |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 879 | b 8f |
| 880 | END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S) |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 881 | /* Load up POWER8-specific registers */ |
| 882 | ld r5, VCPU_IAMR(r4) |
| 883 | lwz r6, VCPU_PSPB(r4) |
| 884 | ld r7, VCPU_FSCR(r4) |
| 885 | mtspr SPRN_IAMR, r5 |
| 886 | mtspr SPRN_PSPB, r6 |
| 887 | mtspr SPRN_FSCR, r7 |
| 888 | ld r5, VCPU_DAWR(r4) |
| 889 | ld r6, VCPU_DAWRX(r4) |
| 890 | ld r7, VCPU_CIABR(r4) |
| 891 | ld r8, VCPU_TAR(r4) |
| 892 | mtspr SPRN_DAWR, r5 |
| 893 | mtspr SPRN_DAWRX, r6 |
| 894 | mtspr SPRN_CIABR, r7 |
| 895 | mtspr SPRN_TAR, r8 |
| 896 | ld r5, VCPU_IC(r4) |
Michael Neuling | 7b49041 | 2014-01-08 21:25:32 +1100 | [diff] [blame] | 897 | ld r8, VCPU_EBBHR(r4) |
Paul Mackerras | 88b02cf9 | 2016-09-15 13:42:52 +1000 | [diff] [blame] | 898 | mtspr SPRN_IC, r5 |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 899 | mtspr SPRN_EBBHR, r8 |
| 900 | ld r5, VCPU_EBBRR(r4) |
| 901 | ld r6, VCPU_BESCR(r4) |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 902 | lwz r7, VCPU_GUEST_PID(r4) |
| 903 | ld r8, VCPU_WORT(r4) |
Paul Mackerras | 83677f5 | 2016-11-16 22:33:27 +1100 | [diff] [blame] | 904 | mtspr SPRN_EBBRR, r5 |
| 905 | mtspr SPRN_BESCR, r6 |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 906 | mtspr SPRN_PID, r7 |
| 907 | mtspr SPRN_WORT, r8 |
Paul Mackerras | 83677f5 | 2016-11-16 22:33:27 +1100 | [diff] [blame] | 908 | BEGIN_FTR_SECTION |
Paul Mackerras | f11f6f7 | 2017-01-30 21:21:52 +1100 | [diff] [blame] | 909 | PPC_INVALIDATE_ERAT |
| 910 | END_FTR_SECTION_IFSET(CPU_FTR_POWER9_DD1) |
| 911 | BEGIN_FTR_SECTION |
Paul Mackerras | e9cf1e0 | 2016-11-18 13:11:42 +1100 | [diff] [blame] | 912 | /* POWER8-only registers */ |
Paul Mackerras | 83677f5 | 2016-11-16 22:33:27 +1100 | [diff] [blame] | 913 | ld r5, VCPU_TCSCR(r4) |
| 914 | ld r6, VCPU_ACOP(r4) |
| 915 | ld r7, VCPU_CSIGR(r4) |
| 916 | ld r8, VCPU_TACR(r4) |
| 917 | mtspr SPRN_TCSCR, r5 |
| 918 | mtspr SPRN_ACOP, r6 |
| 919 | mtspr SPRN_CSIGR, r7 |
| 920 | mtspr SPRN_TACR, r8 |
Paul Mackerras | e9cf1e0 | 2016-11-18 13:11:42 +1100 | [diff] [blame] | 921 | FTR_SECTION_ELSE |
| 922 | /* POWER9-only registers */ |
| 923 | ld r5, VCPU_TID(r4) |
| 924 | ld r6, VCPU_PSSCR(r4) |
| 925 | oris r6, r6, PSSCR_EC@h /* This makes stop trap to HV */ |
Paul Mackerras | 769377f | 2017-02-15 14:30:17 +1100 | [diff] [blame] | 926 | ld r7, VCPU_HFSCR(r4) |
Paul Mackerras | e9cf1e0 | 2016-11-18 13:11:42 +1100 | [diff] [blame] | 927 | mtspr SPRN_TIDR, r5 |
| 928 | mtspr SPRN_PSSCR, r6 |
Paul Mackerras | 769377f | 2017-02-15 14:30:17 +1100 | [diff] [blame] | 929 | mtspr SPRN_HFSCR, r7 |
Paul Mackerras | e9cf1e0 | 2016-11-18 13:11:42 +1100 | [diff] [blame] | 930 | ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_300) |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 931 | 8: |
| 932 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 933 | /* |
| 934 | * Set the decrementer to the guest decrementer. |
| 935 | */ |
| 936 | ld r8,VCPU_DEC_EXPIRES(r4) |
Paul Mackerras | c5fb80d | 2014-03-25 10:47:07 +1100 | [diff] [blame] | 937 | /* r8 is a host timebase value here, convert to guest TB */ |
| 938 | ld r5,HSTATE_KVM_VCORE(r13) |
| 939 | ld r6,VCORE_TB_OFFSET(r5) |
| 940 | add r8,r8,r6 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 941 | mftb r7 |
| 942 | subf r3,r7,r8 |
| 943 | mtspr SPRN_DEC,r3 |
Paul Mackerras | 1bc3fe8 | 2017-05-22 16:55:16 +1000 | [diff] [blame] | 944 | std r3,VCPU_DEC(r4) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 945 | |
| 946 | ld r5, VCPU_SPRG0(r4) |
| 947 | ld r6, VCPU_SPRG1(r4) |
| 948 | ld r7, VCPU_SPRG2(r4) |
| 949 | ld r8, VCPU_SPRG3(r4) |
| 950 | mtspr SPRN_SPRG0, r5 |
| 951 | mtspr SPRN_SPRG1, r6 |
| 952 | mtspr SPRN_SPRG2, r7 |
| 953 | mtspr SPRN_SPRG3, r8 |
| 954 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 955 | /* Load up DAR and DSISR */ |
| 956 | ld r5, VCPU_DAR(r4) |
| 957 | lwz r6, VCPU_DSISR(r4) |
| 958 | mtspr SPRN_DAR, r5 |
| 959 | mtspr SPRN_DSISR, r6 |
| 960 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 961 | /* Restore AMR and UAMOR, set AMOR to all 1s */ |
| 962 | ld r5,VCPU_AMR(r4) |
| 963 | ld r6,VCPU_UAMOR(r4) |
| 964 | li r7,-1 |
| 965 | mtspr SPRN_AMR,r5 |
| 966 | mtspr SPRN_UAMOR,r6 |
| 967 | mtspr SPRN_AMOR,r7 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 968 | |
| 969 | /* Restore state of CTRL run bit; assume 1 on entry */ |
| 970 | lwz r5,VCPU_CTRL(r4) |
| 971 | andi. r5,r5,1 |
| 972 | bne 4f |
| 973 | mfspr r6,SPRN_CTRLF |
| 974 | clrrdi r6,r6,1 |
| 975 | mtspr SPRN_CTRLT,r6 |
| 976 | 4: |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 977 | /* Secondary threads wait for primary to have done partition switch */ |
| 978 | ld r5, HSTATE_KVM_VCORE(r13) |
| 979 | lbz r6, HSTATE_PTID(r13) |
| 980 | cmpwi r6, 0 |
| 981 | beq 21f |
| 982 | lbz r0, VCORE_IN_GUEST(r5) |
| 983 | cmpwi r0, 0 |
| 984 | bne 21f |
| 985 | HMT_LOW |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 986 | 20: lwz r3, VCORE_ENTRY_EXIT(r5) |
| 987 | cmpwi r3, 0x100 |
| 988 | bge no_switch_exit |
| 989 | lbz r0, VCORE_IN_GUEST(r5) |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 990 | cmpwi r0, 0 |
| 991 | beq 20b |
| 992 | HMT_MEDIUM |
| 993 | 21: |
| 994 | /* Set LPCR. */ |
| 995 | ld r8,VCORE_LPCR(r5) |
| 996 | mtspr SPRN_LPCR,r8 |
| 997 | isync |
| 998 | |
| 999 | /* Check if HDEC expires soon */ |
| 1000 | mfspr r3, SPRN_HDEC |
Paul Mackerras | 2f27246 | 2017-05-22 16:25:14 +1000 | [diff] [blame] | 1001 | EXTEND_HDEC(r3) |
| 1002 | cmpdi r3, 512 /* 1 microsecond */ |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 1003 | blt hdec_soon |
| 1004 | |
Benjamin Herrenschmidt | 5af5099 | 2017-04-05 17:54:56 +1000 | [diff] [blame] | 1005 | #ifdef CONFIG_KVM_XICS |
| 1006 | /* We are entering the guest on that thread, push VCPU to XIVE */ |
| 1007 | ld r10, HSTATE_XIVE_TIMA_PHYS(r13) |
| 1008 | cmpldi cr0, r10, r0 |
| 1009 | beq no_xive |
| 1010 | ld r11, VCPU_XIVE_SAVED_STATE(r4) |
| 1011 | li r9, TM_QW1_OS |
| 1012 | stdcix r11,r9,r10 |
| 1013 | eieio |
| 1014 | lwz r11, VCPU_XIVE_CAM_WORD(r4) |
| 1015 | li r9, TM_QW1_OS + TM_WORD2 |
| 1016 | stwcix r11,r9,r10 |
| 1017 | li r9, 1 |
| 1018 | stw r9, VCPU_XIVE_PUSHED(r4) |
| 1019 | no_xive: |
| 1020 | #endif /* CONFIG_KVM_XICS */ |
| 1021 | |
Suresh Warrier | 37f55d3 | 2016-08-19 15:35:46 +1000 | [diff] [blame] | 1022 | deliver_guest_interrupt: |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1023 | ld r6, VCPU_CTR(r4) |
Sam bobroff | c63517c | 2015-05-27 09:56:57 +1000 | [diff] [blame] | 1024 | ld r7, VCPU_XER(r4) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1025 | |
| 1026 | mtctr r6 |
| 1027 | mtxer r7 |
| 1028 | |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 1029 | kvmppc_cede_reentry: /* r4 = vcpu, r13 = paca */ |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 1030 | ld r10, VCPU_PC(r4) |
| 1031 | ld r11, VCPU_MSR(r4) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1032 | ld r6, VCPU_SRR0(r4) |
| 1033 | ld r7, VCPU_SRR1(r4) |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 1034 | mtspr SPRN_SRR0, r6 |
| 1035 | mtspr SPRN_SRR1, r7 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1036 | |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 1037 | /* r11 = vcpu->arch.msr & ~MSR_HV */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1038 | rldicl r11, r11, 63 - MSR_HV_LG, 1 |
| 1039 | rotldi r11, r11, 1 + MSR_HV_LG |
| 1040 | ori r11, r11, MSR_ME |
| 1041 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1042 | /* Check if we can deliver an external or decrementer interrupt now */ |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 1043 | ld r0, VCPU_PENDING_EXC(r4) |
| 1044 | rldicl r0, r0, 64 - BOOK3S_IRQPRIO_EXTERNAL_LEVEL, 63 |
| 1045 | cmpdi cr1, r0, 0 |
| 1046 | andi. r8, r11, MSR_EE |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 1047 | mfspr r8, SPRN_LPCR |
| 1048 | /* Insert EXTERNAL_LEVEL bit into LPCR at the MER bit position */ |
| 1049 | rldimi r8, r0, LPCR_MER_SH, 63 - LPCR_MER_SH |
| 1050 | mtspr SPRN_LPCR, r8 |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1051 | isync |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1052 | beq 5f |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 1053 | li r0, BOOK3S_INTERRUPT_EXTERNAL |
| 1054 | bne cr1, 12f |
| 1055 | mfspr r0, SPRN_DEC |
Paul Mackerras | 1bc3fe8 | 2017-05-22 16:55:16 +1000 | [diff] [blame] | 1056 | BEGIN_FTR_SECTION |
| 1057 | /* On POWER9 check whether the guest has large decrementer enabled */ |
| 1058 | andis. r8, r8, LPCR_LD@h |
| 1059 | bne 15f |
| 1060 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300) |
| 1061 | extsw r0, r0 |
| 1062 | 15: cmpdi r0, 0 |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 1063 | li r0, BOOK3S_INTERRUPT_DECREMENTER |
| 1064 | bge 5f |
| 1065 | |
| 1066 | 12: mtspr SPRN_SRR0, r10 |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1067 | mr r10,r0 |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 1068 | mtspr SPRN_SRR1, r11 |
Michael Neuling | e4e3812 | 2014-03-25 10:47:02 +1100 | [diff] [blame] | 1069 | mr r9, r4 |
| 1070 | bl kvmppc_msr_interrupt |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 1071 | 5: |
Paul Mackerras | 5790069 | 2017-05-16 16:41:20 +1000 | [diff] [blame^] | 1072 | BEGIN_FTR_SECTION |
| 1073 | b fast_guest_return |
| 1074 | END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_300) |
| 1075 | /* On POWER9, check for pending doorbell requests */ |
| 1076 | lbz r0, VCPU_DBELL_REQ(r4) |
| 1077 | cmpwi r0, 0 |
| 1078 | beq fast_guest_return |
| 1079 | ld r5, HSTATE_KVM_VCORE(r13) |
| 1080 | /* Set DPDES register so the CPU will take a doorbell interrupt */ |
| 1081 | li r0, 1 |
| 1082 | mtspr SPRN_DPDES, r0 |
| 1083 | std r0, VCORE_DPDES(r5) |
| 1084 | /* Make sure other cpus see vcore->dpdes set before dbell req clear */ |
| 1085 | lwsync |
| 1086 | /* Clear the pending doorbell request */ |
| 1087 | li r0, 0 |
| 1088 | stb r0, VCPU_DBELL_REQ(r4) |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 1089 | |
Liu Ping Fan | 27025a6 | 2013-11-19 14:12:48 +0800 | [diff] [blame] | 1090 | /* |
| 1091 | * Required state: |
| 1092 | * R4 = vcpu |
| 1093 | * R10: value for HSRR0 |
| 1094 | * R11: value for HSRR1 |
| 1095 | * R13 = PACA |
| 1096 | */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1097 | fast_guest_return: |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 1098 | li r0,0 |
| 1099 | stb r0,VCPU_CEDED(r4) /* cancel cede */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1100 | mtspr SPRN_HSRR0,r10 |
| 1101 | mtspr SPRN_HSRR1,r11 |
| 1102 | |
| 1103 | /* Activate guest mode, so faults get handled by KVM */ |
Paul Mackerras | 44a3add | 2013-10-04 21:45:04 +1000 | [diff] [blame] | 1104 | li r9, KVM_GUEST_MODE_GUEST_HV |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1105 | stb r9, HSTATE_IN_GUEST(r13) |
| 1106 | |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 1107 | #ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING |
| 1108 | /* Accumulate timing */ |
| 1109 | addi r3, r4, VCPU_TB_GUEST |
| 1110 | bl kvmhv_accumulate_time |
| 1111 | #endif |
| 1112 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1113 | /* Enter guest */ |
| 1114 | |
Paul Mackerras | 0acb911 | 2013-02-04 18:10:51 +0000 | [diff] [blame] | 1115 | BEGIN_FTR_SECTION |
| 1116 | ld r5, VCPU_CFAR(r4) |
| 1117 | mtspr SPRN_CFAR, r5 |
| 1118 | END_FTR_SECTION_IFSET(CPU_FTR_CFAR) |
Paul Mackerras | 4b8473c | 2013-09-20 14:52:39 +1000 | [diff] [blame] | 1119 | BEGIN_FTR_SECTION |
| 1120 | ld r0, VCPU_PPR(r4) |
| 1121 | END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) |
Paul Mackerras | 0acb911 | 2013-02-04 18:10:51 +0000 | [diff] [blame] | 1122 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1123 | ld r5, VCPU_LR(r4) |
| 1124 | lwz r6, VCPU_CR(r4) |
| 1125 | mtlr r5 |
| 1126 | mtcr r6 |
| 1127 | |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 1128 | ld r1, VCPU_GPR(R1)(r4) |
| 1129 | ld r2, VCPU_GPR(R2)(r4) |
| 1130 | ld r3, VCPU_GPR(R3)(r4) |
| 1131 | ld r5, VCPU_GPR(R5)(r4) |
| 1132 | ld r6, VCPU_GPR(R6)(r4) |
| 1133 | ld r7, VCPU_GPR(R7)(r4) |
| 1134 | ld r8, VCPU_GPR(R8)(r4) |
| 1135 | ld r9, VCPU_GPR(R9)(r4) |
| 1136 | ld r10, VCPU_GPR(R10)(r4) |
| 1137 | ld r11, VCPU_GPR(R11)(r4) |
| 1138 | ld r12, VCPU_GPR(R12)(r4) |
| 1139 | ld r13, VCPU_GPR(R13)(r4) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1140 | |
Paul Mackerras | 4b8473c | 2013-09-20 14:52:39 +1000 | [diff] [blame] | 1141 | BEGIN_FTR_SECTION |
| 1142 | mtspr SPRN_PPR, r0 |
| 1143 | END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) |
| 1144 | ld r0, VCPU_GPR(R0)(r4) |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 1145 | ld r4, VCPU_GPR(R4)(r4) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1146 | |
| 1147 | hrfid |
| 1148 | b . |
| 1149 | |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 1150 | secondary_too_late: |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 1151 | li r12, 0 |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 1152 | cmpdi r4, 0 |
| 1153 | beq 11f |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 1154 | stw r12, VCPU_TRAP(r4) |
| 1155 | #ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 1156 | addi r3, r4, VCPU_TB_RMEXIT |
| 1157 | bl kvmhv_accumulate_time |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 1158 | #endif |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 1159 | 11: b kvmhv_switch_to_host |
| 1160 | |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 1161 | no_switch_exit: |
| 1162 | HMT_MEDIUM |
| 1163 | li r12, 0 |
| 1164 | b 12f |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 1165 | hdec_soon: |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 1166 | li r12, BOOK3S_INTERRUPT_HV_DECREMENTER |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 1167 | 12: stw r12, VCPU_TRAP(r4) |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 1168 | mr r9, r4 |
| 1169 | #ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 1170 | addi r3, r4, VCPU_TB_RMEXIT |
| 1171 | bl kvmhv_accumulate_time |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 1172 | #endif |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 1173 | b guest_exit_cont |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 1174 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1175 | /****************************************************************************** |
| 1176 | * * |
| 1177 | * Exit code * |
| 1178 | * * |
| 1179 | *****************************************************************************/ |
| 1180 | |
| 1181 | /* |
| 1182 | * We come here from the first-level interrupt handlers. |
| 1183 | */ |
Aneesh Kumar K.V | dd96b2c | 2013-10-07 22:17:55 +0530 | [diff] [blame] | 1184 | .globl kvmppc_interrupt_hv |
| 1185 | kvmppc_interrupt_hv: |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1186 | /* |
| 1187 | * Register contents: |
Nicholas Piggin | d3918e7 | 2016-12-22 04:29:25 +1000 | [diff] [blame] | 1188 | * R12 = (guest CR << 32) | interrupt vector |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1189 | * R13 = PACA |
Nicholas Piggin | d3918e7 | 2016-12-22 04:29:25 +1000 | [diff] [blame] | 1190 | * guest R12 saved in shadow VCPU SCRATCH0 |
Nicholas Piggin | a97a65d | 2017-01-27 14:00:34 +1000 | [diff] [blame] | 1191 | * guest CTR saved in shadow VCPU SCRATCH1 if RELOCATABLE |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1192 | * guest R13 saved in SPRN_SCRATCH0 |
| 1193 | */ |
Nicholas Piggin | a97a65d | 2017-01-27 14:00:34 +1000 | [diff] [blame] | 1194 | std r9, HSTATE_SCRATCH2(r13) |
Paul Mackerras | 44a3add | 2013-10-04 21:45:04 +1000 | [diff] [blame] | 1195 | lbz r9, HSTATE_IN_GUEST(r13) |
| 1196 | cmpwi r9, KVM_GUEST_MODE_HOST_HV |
| 1197 | beq kvmppc_bad_host_intr |
Aneesh Kumar K.V | dd96b2c | 2013-10-07 22:17:55 +0530 | [diff] [blame] | 1198 | #ifdef CONFIG_KVM_BOOK3S_PR_POSSIBLE |
| 1199 | cmpwi r9, KVM_GUEST_MODE_GUEST |
Nicholas Piggin | a97a65d | 2017-01-27 14:00:34 +1000 | [diff] [blame] | 1200 | ld r9, HSTATE_SCRATCH2(r13) |
Aneesh Kumar K.V | dd96b2c | 2013-10-07 22:17:55 +0530 | [diff] [blame] | 1201 | beq kvmppc_interrupt_pr |
| 1202 | #endif |
Paul Mackerras | 44a3add | 2013-10-04 21:45:04 +1000 | [diff] [blame] | 1203 | /* We're now back in the host but in guest MMU context */ |
| 1204 | li r9, KVM_GUEST_MODE_HOST_HV |
| 1205 | stb r9, HSTATE_IN_GUEST(r13) |
| 1206 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1207 | ld r9, HSTATE_KVM_VCPU(r13) |
| 1208 | |
| 1209 | /* Save registers */ |
| 1210 | |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 1211 | std r0, VCPU_GPR(R0)(r9) |
| 1212 | std r1, VCPU_GPR(R1)(r9) |
| 1213 | std r2, VCPU_GPR(R2)(r9) |
| 1214 | std r3, VCPU_GPR(R3)(r9) |
| 1215 | std r4, VCPU_GPR(R4)(r9) |
| 1216 | std r5, VCPU_GPR(R5)(r9) |
| 1217 | std r6, VCPU_GPR(R6)(r9) |
| 1218 | std r7, VCPU_GPR(R7)(r9) |
| 1219 | std r8, VCPU_GPR(R8)(r9) |
Nicholas Piggin | a97a65d | 2017-01-27 14:00:34 +1000 | [diff] [blame] | 1220 | ld r0, HSTATE_SCRATCH2(r13) |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 1221 | std r0, VCPU_GPR(R9)(r9) |
| 1222 | std r10, VCPU_GPR(R10)(r9) |
| 1223 | std r11, VCPU_GPR(R11)(r9) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1224 | ld r3, HSTATE_SCRATCH0(r13) |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 1225 | std r3, VCPU_GPR(R12)(r9) |
Nicholas Piggin | d3918e7 | 2016-12-22 04:29:25 +1000 | [diff] [blame] | 1226 | /* CR is in the high half of r12 */ |
| 1227 | srdi r4, r12, 32 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1228 | stw r4, VCPU_CR(r9) |
Paul Mackerras | 0acb911 | 2013-02-04 18:10:51 +0000 | [diff] [blame] | 1229 | BEGIN_FTR_SECTION |
| 1230 | ld r3, HSTATE_CFAR(r13) |
| 1231 | std r3, VCPU_CFAR(r9) |
| 1232 | END_FTR_SECTION_IFSET(CPU_FTR_CFAR) |
Paul Mackerras | 4b8473c | 2013-09-20 14:52:39 +1000 | [diff] [blame] | 1233 | BEGIN_FTR_SECTION |
| 1234 | ld r4, HSTATE_PPR(r13) |
| 1235 | std r4, VCPU_PPR(r9) |
| 1236 | END_FTR_SECTION_IFSET(CPU_FTR_HAS_PPR) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1237 | |
| 1238 | /* Restore R1/R2 so we can handle faults */ |
| 1239 | ld r1, HSTATE_HOST_R1(r13) |
| 1240 | ld r2, PACATOC(r13) |
| 1241 | |
| 1242 | mfspr r10, SPRN_SRR0 |
| 1243 | mfspr r11, SPRN_SRR1 |
| 1244 | std r10, VCPU_SRR0(r9) |
| 1245 | std r11, VCPU_SRR1(r9) |
Nicholas Piggin | d3918e7 | 2016-12-22 04:29:25 +1000 | [diff] [blame] | 1246 | /* trap is in the low half of r12, clear CR from the high half */ |
| 1247 | clrldi r12, r12, 32 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1248 | andi. r0, r12, 2 /* need to read HSRR0/1? */ |
| 1249 | beq 1f |
| 1250 | mfspr r10, SPRN_HSRR0 |
| 1251 | mfspr r11, SPRN_HSRR1 |
| 1252 | clrrdi r12, r12, 2 |
| 1253 | 1: std r10, VCPU_PC(r9) |
| 1254 | std r11, VCPU_MSR(r9) |
| 1255 | |
| 1256 | GET_SCRATCH0(r3) |
| 1257 | mflr r4 |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 1258 | std r3, VCPU_GPR(R13)(r9) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1259 | std r4, VCPU_LR(r9) |
| 1260 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1261 | stw r12,VCPU_TRAP(r9) |
| 1262 | |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 1263 | #ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING |
| 1264 | addi r3, r9, VCPU_TB_RMINTR |
| 1265 | mr r4, r9 |
| 1266 | bl kvmhv_accumulate_time |
| 1267 | ld r5, VCPU_GPR(R5)(r9) |
| 1268 | ld r6, VCPU_GPR(R6)(r9) |
| 1269 | ld r7, VCPU_GPR(R7)(r9) |
| 1270 | ld r8, VCPU_GPR(R8)(r9) |
| 1271 | #endif |
| 1272 | |
Paul Mackerras | 4a157d6 | 2014-12-03 13:30:39 +1100 | [diff] [blame] | 1273 | /* Save HEIR (HV emulation assist reg) in emul_inst |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1274 | if this is an HEI (HV emulation interrupt, e40) */ |
| 1275 | li r3,KVM_INST_FETCH_FAILED |
Paul Mackerras | 2bf2760 | 2015-03-20 20:39:40 +1100 | [diff] [blame] | 1276 | stw r3,VCPU_LAST_INST(r9) |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1277 | cmpwi r12,BOOK3S_INTERRUPT_H_EMUL_ASSIST |
| 1278 | bne 11f |
| 1279 | mfspr r3,SPRN_HEIR |
Paul Mackerras | 4a157d6 | 2014-12-03 13:30:39 +1100 | [diff] [blame] | 1280 | 11: stw r3,VCPU_HEIR(r9) |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1281 | |
| 1282 | /* these are volatile across C function calls */ |
Nicholas Piggin | a97a65d | 2017-01-27 14:00:34 +1000 | [diff] [blame] | 1283 | #ifdef CONFIG_RELOCATABLE |
| 1284 | ld r3, HSTATE_SCRATCH1(r13) |
| 1285 | mtctr r3 |
| 1286 | #else |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1287 | mfctr r3 |
Nicholas Piggin | a97a65d | 2017-01-27 14:00:34 +1000 | [diff] [blame] | 1288 | #endif |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1289 | mfxer r4 |
| 1290 | std r3, VCPU_CTR(r9) |
Sam bobroff | c63517c | 2015-05-27 09:56:57 +1000 | [diff] [blame] | 1291 | std r4, VCPU_XER(r9) |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1292 | |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1293 | /* If this is a page table miss then see if it's theirs or ours */ |
| 1294 | cmpwi r12, BOOK3S_INTERRUPT_H_DATA_STORAGE |
| 1295 | beq kvmppc_hdsi |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 1296 | cmpwi r12, BOOK3S_INTERRUPT_H_INST_STORAGE |
| 1297 | beq kvmppc_hisi |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1298 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1299 | /* See if this is a leftover HDEC interrupt */ |
| 1300 | cmpwi r12,BOOK3S_INTERRUPT_HV_DECREMENTER |
| 1301 | bne 2f |
| 1302 | mfspr r3,SPRN_HDEC |
| 1303 | cmpwi r3,0 |
Paul Mackerras | 1f09c3e | 2015-03-28 14:21:04 +1100 | [diff] [blame] | 1304 | mr r4,r9 |
| 1305 | bge fast_guest_return |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1306 | 2: |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1307 | /* See if this is an hcall we can handle in real mode */ |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1308 | cmpwi r12,BOOK3S_INTERRUPT_SYSCALL |
| 1309 | beq hcall_try_real_mode |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1310 | |
Paul Mackerras | 66feed6 | 2015-03-28 14:21:12 +1100 | [diff] [blame] | 1311 | /* Hypervisor doorbell - exit only if host IPI flag set */ |
| 1312 | cmpwi r12, BOOK3S_INTERRUPT_H_DOORBELL |
| 1313 | bne 3f |
| 1314 | lbz r0, HSTATE_HOST_IPI(r13) |
Gautham R. Shenoy | 06554d9 | 2015-08-07 17:41:20 +0530 | [diff] [blame] | 1315 | cmpwi r0, 0 |
Paul Mackerras | 66feed6 | 2015-03-28 14:21:12 +1100 | [diff] [blame] | 1316 | beq 4f |
| 1317 | b guest_exit_cont |
| 1318 | 3: |
Paul Mackerras | 769377f | 2017-02-15 14:30:17 +1100 | [diff] [blame] | 1319 | /* If it's a hypervisor facility unavailable interrupt, save HFSCR */ |
| 1320 | cmpwi r12, BOOK3S_INTERRUPT_H_FAC_UNAVAIL |
| 1321 | bne 14f |
| 1322 | mfspr r3, SPRN_HFSCR |
| 1323 | std r3, VCPU_HFSCR(r9) |
| 1324 | b guest_exit_cont |
| 1325 | 14: |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 1326 | /* External interrupt ? */ |
| 1327 | cmpwi r12, BOOK3S_INTERRUPT_EXTERNAL |
Paul Mackerras | 1f09c3e | 2015-03-28 14:21:04 +1100 | [diff] [blame] | 1328 | bne+ guest_exit_cont |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 1329 | |
| 1330 | /* External interrupt, first check for host_ipi. If this is |
| 1331 | * set, we know the host wants us out so let's do it now |
| 1332 | */ |
Paul Mackerras | c934243 | 2013-09-06 13:24:13 +1000 | [diff] [blame] | 1333 | bl kvmppc_read_intr |
Suresh Warrier | 37f55d3 | 2016-08-19 15:35:46 +1000 | [diff] [blame] | 1334 | |
| 1335 | /* |
| 1336 | * Restore the active volatile registers after returning from |
| 1337 | * a C function. |
| 1338 | */ |
| 1339 | ld r9, HSTATE_KVM_VCPU(r13) |
| 1340 | li r12, BOOK3S_INTERRUPT_EXTERNAL |
| 1341 | |
| 1342 | /* |
| 1343 | * kvmppc_read_intr return codes: |
| 1344 | * |
| 1345 | * Exit to host (r3 > 0) |
| 1346 | * 1 An interrupt is pending that needs to be handled by the host |
| 1347 | * Exit guest and return to host by branching to guest_exit_cont |
| 1348 | * |
Suresh Warrier | f7af520 | 2016-08-19 15:35:52 +1000 | [diff] [blame] | 1349 | * 2 Passthrough that needs completion in the host |
| 1350 | * Exit guest and return to host by branching to guest_exit_cont |
| 1351 | * However, we also set r12 to BOOK3S_INTERRUPT_HV_RM_HARD |
| 1352 | * to indicate to the host to complete handling the interrupt |
| 1353 | * |
Suresh Warrier | 37f55d3 | 2016-08-19 15:35:46 +1000 | [diff] [blame] | 1354 | * Before returning to guest, we check if any CPU is heading out |
| 1355 | * to the host and if so, we head out also. If no CPUs are heading |
| 1356 | * check return values <= 0. |
| 1357 | * |
| 1358 | * Return to guest (r3 <= 0) |
| 1359 | * 0 No external interrupt is pending |
| 1360 | * -1 A guest wakeup IPI (which has now been cleared) |
| 1361 | * In either case, we return to guest to deliver any pending |
| 1362 | * guest interrupts. |
Suresh Warrier | e3c13e5 | 2016-08-19 15:35:51 +1000 | [diff] [blame] | 1363 | * |
| 1364 | * -2 A PCI passthrough external interrupt was handled |
| 1365 | * (interrupt was delivered directly to guest) |
| 1366 | * Return to guest to deliver any pending guest interrupts. |
Suresh Warrier | 37f55d3 | 2016-08-19 15:35:46 +1000 | [diff] [blame] | 1367 | */ |
| 1368 | |
Suresh Warrier | f7af520 | 2016-08-19 15:35:52 +1000 | [diff] [blame] | 1369 | cmpdi r3, 1 |
| 1370 | ble 1f |
| 1371 | |
| 1372 | /* Return code = 2 */ |
| 1373 | li r12, BOOK3S_INTERRUPT_HV_RM_HARD |
| 1374 | stw r12, VCPU_TRAP(r9) |
| 1375 | b guest_exit_cont |
| 1376 | |
| 1377 | 1: /* Return code <= 1 */ |
Paul Mackerras | c934243 | 2013-09-06 13:24:13 +1000 | [diff] [blame] | 1378 | cmpdi r3, 0 |
Paul Mackerras | 1f09c3e | 2015-03-28 14:21:04 +1100 | [diff] [blame] | 1379 | bgt guest_exit_cont |
Benjamin Herrenschmidt | 54695c3 | 2013-04-17 20:30:50 +0000 | [diff] [blame] | 1380 | |
Suresh Warrier | 37f55d3 | 2016-08-19 15:35:46 +1000 | [diff] [blame] | 1381 | /* Return code <= 0 */ |
Paul Mackerras | 66feed6 | 2015-03-28 14:21:12 +1100 | [diff] [blame] | 1382 | 4: ld r5, HSTATE_KVM_VCORE(r13) |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 1383 | lwz r0, VCORE_ENTRY_EXIT(r5) |
| 1384 | cmpwi r0, 0x100 |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 1385 | mr r4, r9 |
Paul Mackerras | 1f09c3e | 2015-03-28 14:21:04 +1100 | [diff] [blame] | 1386 | blt deliver_guest_interrupt |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1387 | |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1388 | guest_exit_cont: /* r9 = vcpu, r12 = trap, r13 = paca */ |
Benjamin Herrenschmidt | 5af5099 | 2017-04-05 17:54:56 +1000 | [diff] [blame] | 1389 | #ifdef CONFIG_KVM_XICS |
| 1390 | /* We are exiting, pull the VP from the XIVE */ |
| 1391 | lwz r0, VCPU_XIVE_PUSHED(r9) |
| 1392 | cmpwi cr0, r0, 0 |
| 1393 | beq 1f |
| 1394 | li r7, TM_SPC_PULL_OS_CTX |
| 1395 | li r6, TM_QW1_OS |
| 1396 | mfmsr r0 |
| 1397 | andi. r0, r0, MSR_IR /* in real mode? */ |
| 1398 | beq 2f |
| 1399 | ld r10, HSTATE_XIVE_TIMA_VIRT(r13) |
| 1400 | cmpldi cr0, r10, 0 |
| 1401 | beq 1f |
| 1402 | /* First load to pull the context, we ignore the value */ |
| 1403 | lwzx r11, r7, r10 |
| 1404 | eieio |
| 1405 | /* Second load to recover the context state (Words 0 and 1) */ |
| 1406 | ldx r11, r6, r10 |
| 1407 | b 3f |
| 1408 | 2: ld r10, HSTATE_XIVE_TIMA_PHYS(r13) |
| 1409 | cmpldi cr0, r10, 0 |
| 1410 | beq 1f |
| 1411 | /* First load to pull the context, we ignore the value */ |
| 1412 | lwzcix r11, r7, r10 |
| 1413 | eieio |
| 1414 | /* Second load to recover the context state (Words 0 and 1) */ |
| 1415 | ldcix r11, r6, r10 |
| 1416 | 3: std r11, VCPU_XIVE_SAVED_STATE(r9) |
| 1417 | /* Fixup some of the state for the next load */ |
| 1418 | li r10, 0 |
| 1419 | li r0, 0xff |
| 1420 | stw r10, VCPU_XIVE_PUSHED(r9) |
| 1421 | stb r10, (VCPU_XIVE_SAVED_STATE+3)(r9) |
| 1422 | stb r0, (VCPU_XIVE_SAVED_STATE+4)(r9) |
| 1423 | 1: |
| 1424 | #endif /* CONFIG_KVM_XICS */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1425 | /* Save more register state */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1426 | mfdar r6 |
| 1427 | mfdsisr r7 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1428 | std r6, VCPU_DAR(r9) |
| 1429 | stw r7, VCPU_DSISR(r9) |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1430 | /* don't overwrite fault_dar/fault_dsisr if HDSI */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1431 | cmpwi r12,BOOK3S_INTERRUPT_H_DATA_STORAGE |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 1432 | beq mc_cont |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1433 | std r6, VCPU_FAULT_DAR(r9) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1434 | stw r7, VCPU_FAULT_DSISR(r9) |
| 1435 | |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1436 | /* See if it is a machine check */ |
| 1437 | cmpwi r12, BOOK3S_INTERRUPT_MACHINE_CHECK |
| 1438 | beq machine_check_realmode |
| 1439 | mc_cont: |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 1440 | #ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING |
| 1441 | addi r3, r9, VCPU_TB_RMEXIT |
| 1442 | mr r4, r9 |
| 1443 | bl kvmhv_accumulate_time |
| 1444 | #endif |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1445 | |
Gautham R. Shenoy | 7e022e7 | 2015-05-21 13:57:04 +0530 | [diff] [blame] | 1446 | mr r3, r12 |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 1447 | /* Increment exit count, poke other threads to exit */ |
| 1448 | bl kvmhv_commence_exit |
Paul Mackerras | eddb60f | 2015-03-28 14:21:11 +1100 | [diff] [blame] | 1449 | nop |
| 1450 | ld r9, HSTATE_KVM_VCPU(r13) |
| 1451 | lwz r12, VCPU_TRAP(r9) |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 1452 | |
Paul Mackerras | ec25716 | 2015-06-24 21:18:03 +1000 | [diff] [blame] | 1453 | /* Stop others sending VCPU interrupts to this physical CPU */ |
| 1454 | li r0, -1 |
| 1455 | stw r0, VCPU_CPU(r9) |
| 1456 | stw r0, VCPU_THREAD_CPU(r9) |
| 1457 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1458 | /* Save guest CTRL register, set runlatch to 1 */ |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 1459 | mfspr r6,SPRN_CTRLF |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1460 | stw r6,VCPU_CTRL(r9) |
| 1461 | andi. r0,r6,1 |
| 1462 | bne 4f |
| 1463 | ori r6,r6,1 |
| 1464 | mtspr SPRN_CTRLT,r6 |
| 1465 | 4: |
| 1466 | /* Read the guest SLB and save it away */ |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 1467 | ld r5, VCPU_KVM(r9) |
| 1468 | lbz r0, KVM_RADIX(r5) |
| 1469 | cmpwi r0, 0 |
| 1470 | li r5, 0 |
| 1471 | bne 3f /* for radix, save 0 entries */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1472 | lwz r0,VCPU_SLB_NR(r9) /* number of entries in SLB */ |
| 1473 | mtctr r0 |
| 1474 | li r6,0 |
| 1475 | addi r7,r9,VCPU_SLB |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1476 | 1: slbmfee r8,r6 |
| 1477 | andis. r0,r8,SLB_ESID_V@h |
| 1478 | beq 2f |
| 1479 | add r8,r8,r6 /* put index in */ |
| 1480 | slbmfev r3,r6 |
| 1481 | std r8,VCPU_SLB_E(r7) |
| 1482 | std r3,VCPU_SLB_V(r7) |
| 1483 | addi r7,r7,VCPU_SLB_SIZE |
| 1484 | addi r5,r5,1 |
| 1485 | 2: addi r6,r6,1 |
| 1486 | bdnz 1b |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 1487 | 3: stw r5,VCPU_SLB_MAX(r9) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1488 | |
| 1489 | /* |
| 1490 | * Save the guest PURR/SPURR |
| 1491 | */ |
| 1492 | mfspr r5,SPRN_PURR |
| 1493 | mfspr r6,SPRN_SPURR |
| 1494 | ld r7,VCPU_PURR(r9) |
| 1495 | ld r8,VCPU_SPURR(r9) |
| 1496 | std r5,VCPU_PURR(r9) |
| 1497 | std r6,VCPU_SPURR(r9) |
| 1498 | subf r5,r7,r5 |
| 1499 | subf r6,r8,r6 |
| 1500 | |
| 1501 | /* |
| 1502 | * Restore host PURR/SPURR and add guest times |
| 1503 | * so that the time in the guest gets accounted. |
| 1504 | */ |
| 1505 | ld r3,HSTATE_PURR(r13) |
| 1506 | ld r4,HSTATE_SPURR(r13) |
| 1507 | add r3,r3,r5 |
| 1508 | add r4,r4,r6 |
| 1509 | mtspr SPRN_PURR,r3 |
| 1510 | mtspr SPRN_SPURR,r4 |
| 1511 | |
Paul Mackerras | 93b0f4d | 2013-09-06 13:17:46 +1000 | [diff] [blame] | 1512 | /* Save DEC */ |
Paul Mackerras | 1bc3fe8 | 2017-05-22 16:55:16 +1000 | [diff] [blame] | 1513 | ld r3, HSTATE_KVM_VCORE(r13) |
Paul Mackerras | 93b0f4d | 2013-09-06 13:17:46 +1000 | [diff] [blame] | 1514 | mfspr r5,SPRN_DEC |
| 1515 | mftb r6 |
Paul Mackerras | 1bc3fe8 | 2017-05-22 16:55:16 +1000 | [diff] [blame] | 1516 | /* On P9, if the guest has large decr enabled, don't sign extend */ |
| 1517 | BEGIN_FTR_SECTION |
| 1518 | ld r4, VCORE_LPCR(r3) |
| 1519 | andis. r4, r4, LPCR_LD@h |
| 1520 | bne 16f |
| 1521 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300) |
Paul Mackerras | 93b0f4d | 2013-09-06 13:17:46 +1000 | [diff] [blame] | 1522 | extsw r5,r5 |
Paul Mackerras | 1bc3fe8 | 2017-05-22 16:55:16 +1000 | [diff] [blame] | 1523 | 16: add r5,r5,r6 |
Paul Mackerras | c5fb80d | 2014-03-25 10:47:07 +1100 | [diff] [blame] | 1524 | /* r5 is a guest timebase value here, convert to host TB */ |
Paul Mackerras | c5fb80d | 2014-03-25 10:47:07 +1100 | [diff] [blame] | 1525 | ld r4,VCORE_TB_OFFSET(r3) |
| 1526 | subf r5,r4,r5 |
Paul Mackerras | 93b0f4d | 2013-09-06 13:17:46 +1000 | [diff] [blame] | 1527 | std r5,VCPU_DEC_EXPIRES(r9) |
| 1528 | |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1529 | BEGIN_FTR_SECTION |
| 1530 | b 8f |
| 1531 | END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S) |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1532 | /* Save POWER8-specific registers */ |
| 1533 | mfspr r5, SPRN_IAMR |
| 1534 | mfspr r6, SPRN_PSPB |
| 1535 | mfspr r7, SPRN_FSCR |
| 1536 | std r5, VCPU_IAMR(r9) |
| 1537 | stw r6, VCPU_PSPB(r9) |
| 1538 | std r7, VCPU_FSCR(r9) |
| 1539 | mfspr r5, SPRN_IC |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1540 | mfspr r7, SPRN_TAR |
| 1541 | std r5, VCPU_IC(r9) |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1542 | std r7, VCPU_TAR(r9) |
Michael Neuling | 7b49041 | 2014-01-08 21:25:32 +1100 | [diff] [blame] | 1543 | mfspr r8, SPRN_EBBHR |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1544 | std r8, VCPU_EBBHR(r9) |
| 1545 | mfspr r5, SPRN_EBBRR |
| 1546 | mfspr r6, SPRN_BESCR |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1547 | mfspr r7, SPRN_PID |
| 1548 | mfspr r8, SPRN_WORT |
Paul Mackerras | 83677f5 | 2016-11-16 22:33:27 +1100 | [diff] [blame] | 1549 | std r5, VCPU_EBBRR(r9) |
| 1550 | std r6, VCPU_BESCR(r9) |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1551 | stw r7, VCPU_GUEST_PID(r9) |
| 1552 | std r8, VCPU_WORT(r9) |
Paul Mackerras | 83677f5 | 2016-11-16 22:33:27 +1100 | [diff] [blame] | 1553 | BEGIN_FTR_SECTION |
| 1554 | mfspr r5, SPRN_TCSCR |
| 1555 | mfspr r6, SPRN_ACOP |
| 1556 | mfspr r7, SPRN_CSIGR |
| 1557 | mfspr r8, SPRN_TACR |
| 1558 | std r5, VCPU_TCSCR(r9) |
| 1559 | std r6, VCPU_ACOP(r9) |
| 1560 | std r7, VCPU_CSIGR(r9) |
| 1561 | std r8, VCPU_TACR(r9) |
Paul Mackerras | e9cf1e0 | 2016-11-18 13:11:42 +1100 | [diff] [blame] | 1562 | FTR_SECTION_ELSE |
| 1563 | mfspr r5, SPRN_TIDR |
| 1564 | mfspr r6, SPRN_PSSCR |
| 1565 | std r5, VCPU_TID(r9) |
| 1566 | rldicl r6, r6, 4, 50 /* r6 &= PSSCR_GUEST_VIS */ |
| 1567 | rotldi r6, r6, 60 |
| 1568 | std r6, VCPU_PSSCR(r9) |
Paul Mackerras | 769377f | 2017-02-15 14:30:17 +1100 | [diff] [blame] | 1569 | /* Restore host HFSCR value */ |
| 1570 | ld r7, STACK_SLOT_HFSCR(r1) |
| 1571 | mtspr SPRN_HFSCR, r7 |
Paul Mackerras | e9cf1e0 | 2016-11-18 13:11:42 +1100 | [diff] [blame] | 1572 | ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_300) |
Paul Mackerras | ccec445 | 2016-03-05 19:34:39 +1100 | [diff] [blame] | 1573 | /* |
| 1574 | * Restore various registers to 0, where non-zero values |
| 1575 | * set by the guest could disrupt the host. |
| 1576 | */ |
| 1577 | li r0, 0 |
Paul Mackerras | 4c3bb4c | 2017-06-15 15:43:17 +1000 | [diff] [blame] | 1578 | mtspr SPRN_PSPB, r0 |
Paul Mackerras | ccec445 | 2016-03-05 19:34:39 +1100 | [diff] [blame] | 1579 | mtspr SPRN_WORT, r0 |
Paul Mackerras | 83677f5 | 2016-11-16 22:33:27 +1100 | [diff] [blame] | 1580 | BEGIN_FTR_SECTION |
Paul Mackerras | 4c3bb4c | 2017-06-15 15:43:17 +1000 | [diff] [blame] | 1581 | mtspr SPRN_IAMR, r0 |
Paul Mackerras | 83677f5 | 2016-11-16 22:33:27 +1100 | [diff] [blame] | 1582 | mtspr SPRN_TCSCR, r0 |
Paul Mackerras | ccec445 | 2016-03-05 19:34:39 +1100 | [diff] [blame] | 1583 | /* Set MMCRS to 1<<31 to freeze and disable the SPMC counters */ |
| 1584 | li r0, 1 |
| 1585 | sldi r0, r0, 31 |
| 1586 | mtspr SPRN_MMCRS, r0 |
Paul Mackerras | 83677f5 | 2016-11-16 22:33:27 +1100 | [diff] [blame] | 1587 | END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_300) |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1588 | 8: |
| 1589 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1590 | /* Save and reset AMR and UAMOR before turning on the MMU */ |
| 1591 | mfspr r5,SPRN_AMR |
| 1592 | mfspr r6,SPRN_UAMOR |
| 1593 | std r5,VCPU_AMR(r9) |
| 1594 | std r6,VCPU_UAMOR(r9) |
| 1595 | li r6,0 |
| 1596 | mtspr SPRN_AMR,r6 |
Paul Mackerras | 4c3bb4c | 2017-06-15 15:43:17 +1000 | [diff] [blame] | 1597 | mtspr SPRN_UAMOR, r6 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1598 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1599 | /* Switch DSCR back to host value */ |
| 1600 | mfspr r8, SPRN_DSCR |
| 1601 | ld r7, HSTATE_DSCR(r13) |
Paul Mackerras | cfc8602 | 2013-09-21 09:53:28 +1000 | [diff] [blame] | 1602 | std r8, VCPU_DSCR(r9) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1603 | mtspr SPRN_DSCR, r7 |
| 1604 | |
| 1605 | /* Save non-volatile GPRs */ |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 1606 | std r14, VCPU_GPR(R14)(r9) |
| 1607 | std r15, VCPU_GPR(R15)(r9) |
| 1608 | std r16, VCPU_GPR(R16)(r9) |
| 1609 | std r17, VCPU_GPR(R17)(r9) |
| 1610 | std r18, VCPU_GPR(R18)(r9) |
| 1611 | std r19, VCPU_GPR(R19)(r9) |
| 1612 | std r20, VCPU_GPR(R20)(r9) |
| 1613 | std r21, VCPU_GPR(R21)(r9) |
| 1614 | std r22, VCPU_GPR(R22)(r9) |
| 1615 | std r23, VCPU_GPR(R23)(r9) |
| 1616 | std r24, VCPU_GPR(R24)(r9) |
| 1617 | std r25, VCPU_GPR(R25)(r9) |
| 1618 | std r26, VCPU_GPR(R26)(r9) |
| 1619 | std r27, VCPU_GPR(R27)(r9) |
| 1620 | std r28, VCPU_GPR(R28)(r9) |
| 1621 | std r29, VCPU_GPR(R29)(r9) |
| 1622 | std r30, VCPU_GPR(R30)(r9) |
| 1623 | std r31, VCPU_GPR(R31)(r9) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1624 | |
| 1625 | /* Save SPRGs */ |
| 1626 | mfspr r3, SPRN_SPRG0 |
| 1627 | mfspr r4, SPRN_SPRG1 |
| 1628 | mfspr r5, SPRN_SPRG2 |
| 1629 | mfspr r6, SPRN_SPRG3 |
| 1630 | std r3, VCPU_SPRG0(r9) |
| 1631 | std r4, VCPU_SPRG1(r9) |
| 1632 | std r5, VCPU_SPRG2(r9) |
| 1633 | std r6, VCPU_SPRG3(r9) |
| 1634 | |
Paul Mackerras | 8943633 | 2012-03-02 01:38:23 +0000 | [diff] [blame] | 1635 | /* save FP state */ |
| 1636 | mr r3, r9 |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 1637 | bl kvmppc_save_fp |
Paul Mackerras | 8943633 | 2012-03-02 01:38:23 +0000 | [diff] [blame] | 1638 | |
Paul Mackerras | 0a8ecce | 2014-04-14 08:56:26 +1000 | [diff] [blame] | 1639 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM |
| 1640 | BEGIN_FTR_SECTION |
Paul Mackerras | f024ee0 | 2016-06-22 14:21:59 +1000 | [diff] [blame] | 1641 | bl kvmppc_save_tm |
| 1642 | END_FTR_SECTION_IFSET(CPU_FTR_TM) |
Paul Mackerras | 0a8ecce | 2014-04-14 08:56:26 +1000 | [diff] [blame] | 1643 | #endif |
| 1644 | |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1645 | /* Increment yield count if they have a VPA */ |
| 1646 | ld r8, VCPU_VPA(r9) /* do they have a VPA? */ |
| 1647 | cmpdi r8, 0 |
| 1648 | beq 25f |
Alexander Graf | 0865a58 | 2014-06-11 10:36:17 +0200 | [diff] [blame] | 1649 | li r4, LPPACA_YIELDCOUNT |
| 1650 | LWZX_BE r3, r8, r4 |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1651 | addi r3, r3, 1 |
Alexander Graf | 0865a58 | 2014-06-11 10:36:17 +0200 | [diff] [blame] | 1652 | STWX_BE r3, r8, r4 |
Paul Mackerras | c35635e | 2013-04-18 19:51:04 +0000 | [diff] [blame] | 1653 | li r3, 1 |
| 1654 | stb r3, VCPU_VPA_DIRTY(r9) |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1655 | 25: |
| 1656 | /* Save PMU registers if requested */ |
| 1657 | /* r8 and cr0.eq are live here */ |
Paul Mackerras | 9bc01a9 | 2014-05-26 19:48:40 +1000 | [diff] [blame] | 1658 | BEGIN_FTR_SECTION |
| 1659 | /* |
| 1660 | * POWER8 seems to have a hardware bug where setting |
| 1661 | * MMCR0[PMAE] along with MMCR0[PMC1CE] and/or MMCR0[PMCjCE] |
| 1662 | * when some counters are already negative doesn't seem |
| 1663 | * to cause a performance monitor alert (and hence interrupt). |
| 1664 | * The effect of this is that when saving the PMU state, |
| 1665 | * if there is no PMU alert pending when we read MMCR0 |
| 1666 | * before freezing the counters, but one becomes pending |
| 1667 | * before we read the counters, we lose it. |
| 1668 | * To work around this, we need a way to freeze the counters |
| 1669 | * before reading MMCR0. Normally, freezing the counters |
| 1670 | * is done by writing MMCR0 (to set MMCR0[FC]) which |
| 1671 | * unavoidably writes MMCR0[PMA0] as well. On POWER8, |
| 1672 | * we can also freeze the counters using MMCR2, by writing |
| 1673 | * 1s to all the counter freeze condition bits (there are |
| 1674 | * 9 bits each for 6 counters). |
| 1675 | */ |
| 1676 | li r3, -1 /* set all freeze bits */ |
| 1677 | clrrdi r3, r3, 10 |
| 1678 | mfspr r10, SPRN_MMCR2 |
| 1679 | mtspr SPRN_MMCR2, r3 |
| 1680 | isync |
| 1681 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1682 | li r3, 1 |
| 1683 | sldi r3, r3, 31 /* MMCR0_FC (freeze counters) bit */ |
| 1684 | mfspr r4, SPRN_MMCR0 /* save MMCR0 */ |
| 1685 | mtspr SPRN_MMCR0, r3 /* freeze all counters, disable ints */ |
Paul Mackerras | 8943633 | 2012-03-02 01:38:23 +0000 | [diff] [blame] | 1686 | mfspr r6, SPRN_MMCRA |
Paul Mackerras | c17b98c | 2014-12-03 13:30:38 +1100 | [diff] [blame] | 1687 | /* Clear MMCRA in order to disable SDAR updates */ |
Paul Mackerras | 8943633 | 2012-03-02 01:38:23 +0000 | [diff] [blame] | 1688 | li r7, 0 |
| 1689 | mtspr SPRN_MMCRA, r7 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1690 | isync |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 1691 | beq 21f /* if no VPA, save PMU stuff anyway */ |
| 1692 | lbz r7, LPPACA_PMCINUSE(r8) |
| 1693 | cmpwi r7, 0 /* did they ask for PMU stuff to be saved? */ |
| 1694 | bne 21f |
| 1695 | std r3, VCPU_MMCR(r9) /* if not, set saved MMCR0 to FC */ |
| 1696 | b 22f |
| 1697 | 21: mfspr r5, SPRN_MMCR1 |
Paul Mackerras | 1494178 | 2013-09-06 13:11:18 +1000 | [diff] [blame] | 1698 | mfspr r7, SPRN_SIAR |
| 1699 | mfspr r8, SPRN_SDAR |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1700 | std r4, VCPU_MMCR(r9) |
| 1701 | std r5, VCPU_MMCR + 8(r9) |
| 1702 | std r6, VCPU_MMCR + 16(r9) |
Paul Mackerras | 9bc01a9 | 2014-05-26 19:48:40 +1000 | [diff] [blame] | 1703 | BEGIN_FTR_SECTION |
| 1704 | std r10, VCPU_MMCR + 24(r9) |
| 1705 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) |
Paul Mackerras | 1494178 | 2013-09-06 13:11:18 +1000 | [diff] [blame] | 1706 | std r7, VCPU_SIAR(r9) |
| 1707 | std r8, VCPU_SDAR(r9) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1708 | mfspr r3, SPRN_PMC1 |
| 1709 | mfspr r4, SPRN_PMC2 |
| 1710 | mfspr r5, SPRN_PMC3 |
| 1711 | mfspr r6, SPRN_PMC4 |
| 1712 | mfspr r7, SPRN_PMC5 |
| 1713 | mfspr r8, SPRN_PMC6 |
| 1714 | stw r3, VCPU_PMC(r9) |
| 1715 | stw r4, VCPU_PMC + 4(r9) |
| 1716 | stw r5, VCPU_PMC + 8(r9) |
| 1717 | stw r6, VCPU_PMC + 12(r9) |
| 1718 | stw r7, VCPU_PMC + 16(r9) |
| 1719 | stw r8, VCPU_PMC + 20(r9) |
Paul Mackerras | 9e368f2 | 2011-06-29 00:40:08 +0000 | [diff] [blame] | 1720 | BEGIN_FTR_SECTION |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1721 | mfspr r5, SPRN_SIER |
Paul Mackerras | 83677f5 | 2016-11-16 22:33:27 +1100 | [diff] [blame] | 1722 | std r5, VCPU_SIER(r9) |
| 1723 | BEGIN_FTR_SECTION_NESTED(96) |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1724 | mfspr r6, SPRN_SPMC1 |
| 1725 | mfspr r7, SPRN_SPMC2 |
| 1726 | mfspr r8, SPRN_MMCRS |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1727 | stw r6, VCPU_PMC + 24(r9) |
| 1728 | stw r7, VCPU_PMC + 28(r9) |
| 1729 | std r8, VCPU_MMCR + 32(r9) |
| 1730 | lis r4, 0x8000 |
| 1731 | mtspr SPRN_MMCRS, r4 |
Paul Mackerras | 83677f5 | 2016-11-16 22:33:27 +1100 | [diff] [blame] | 1732 | END_FTR_SECTION_NESTED(CPU_FTR_ARCH_300, 0, 96) |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1733 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1734 | 22: |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1735 | /* Clear out SLB */ |
| 1736 | li r5,0 |
| 1737 | slbmte r5,r5 |
| 1738 | slbia |
| 1739 | ptesync |
| 1740 | |
Paul Mackerras | e9cf1e0 | 2016-11-18 13:11:42 +1100 | [diff] [blame] | 1741 | /* Restore host values of some registers */ |
| 1742 | BEGIN_FTR_SECTION |
Paul Mackerras | 7ceaa6d | 2017-06-16 11:53:19 +1000 | [diff] [blame] | 1743 | ld r5, STACK_SLOT_CIABR(r1) |
| 1744 | ld r6, STACK_SLOT_DAWR(r1) |
| 1745 | ld r7, STACK_SLOT_DAWRX(r1) |
| 1746 | mtspr SPRN_CIABR, r5 |
| 1747 | mtspr SPRN_DAWR, r6 |
| 1748 | mtspr SPRN_DAWRX, r7 |
| 1749 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) |
| 1750 | BEGIN_FTR_SECTION |
Paul Mackerras | e9cf1e0 | 2016-11-18 13:11:42 +1100 | [diff] [blame] | 1751 | ld r5, STACK_SLOT_TID(r1) |
| 1752 | ld r6, STACK_SLOT_PSSCR(r1) |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 1753 | ld r7, STACK_SLOT_PID(r1) |
Paul Mackerras | 4c3bb4c | 2017-06-15 15:43:17 +1000 | [diff] [blame] | 1754 | ld r8, STACK_SLOT_IAMR(r1) |
Paul Mackerras | e9cf1e0 | 2016-11-18 13:11:42 +1100 | [diff] [blame] | 1755 | mtspr SPRN_TIDR, r5 |
| 1756 | mtspr SPRN_PSSCR, r6 |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 1757 | mtspr SPRN_PID, r7 |
Paul Mackerras | 4c3bb4c | 2017-06-15 15:43:17 +1000 | [diff] [blame] | 1758 | mtspr SPRN_IAMR, r8 |
Paul Mackerras | e9cf1e0 | 2016-11-18 13:11:42 +1100 | [diff] [blame] | 1759 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300) |
Paul Mackerras | f11f6f7 | 2017-01-30 21:21:52 +1100 | [diff] [blame] | 1760 | BEGIN_FTR_SECTION |
| 1761 | PPC_INVALIDATE_ERAT |
| 1762 | END_FTR_SECTION_IFSET(CPU_FTR_POWER9_DD1) |
Paul Mackerras | e9cf1e0 | 2016-11-18 13:11:42 +1100 | [diff] [blame] | 1763 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1764 | /* |
Paul Mackerras | c17b98c | 2014-12-03 13:30:38 +1100 | [diff] [blame] | 1765 | * POWER7/POWER8 guest -> host partition switch code. |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1766 | * We don't have to lock against tlbies but we do |
| 1767 | * have to coordinate the hardware threads. |
| 1768 | */ |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 1769 | kvmhv_switch_to_host: |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1770 | /* Secondary threads wait for primary to do partition switch */ |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 1771 | ld r5,HSTATE_KVM_VCORE(r13) |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 1772 | ld r4,VCORE_KVM(r5) /* pointer to struct kvm */ |
| 1773 | lbz r3,HSTATE_PTID(r13) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1774 | cmpwi r3,0 |
| 1775 | beq 15f |
| 1776 | HMT_LOW |
| 1777 | 13: lbz r3,VCORE_IN_GUEST(r5) |
| 1778 | cmpwi r3,0 |
| 1779 | bne 13b |
| 1780 | HMT_MEDIUM |
| 1781 | b 16f |
| 1782 | |
| 1783 | /* Primary thread waits for all the secondaries to exit guest */ |
| 1784 | 15: lwz r3,VCORE_ENTRY_EXIT(r5) |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 1785 | rlwinm r0,r3,32-8,0xff |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1786 | clrldi r3,r3,56 |
| 1787 | cmpw r3,r0 |
| 1788 | bne 15b |
| 1789 | isync |
| 1790 | |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 1791 | /* Did we actually switch to the guest at all? */ |
| 1792 | lbz r6, VCORE_IN_GUEST(r5) |
| 1793 | cmpwi r6, 0 |
| 1794 | beq 19f |
| 1795 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1796 | /* Primary thread switches back to host partition */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1797 | lwz r7,KVM_HOST_LPID(r4) |
Paul Mackerras | 7a84084 | 2016-11-16 22:25:20 +1100 | [diff] [blame] | 1798 | BEGIN_FTR_SECTION |
| 1799 | ld r6,KVM_HOST_SDR1(r4) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1800 | li r8,LPID_RSVD /* switch to reserved LPID */ |
| 1801 | mtspr SPRN_LPID,r8 |
| 1802 | ptesync |
Paul Mackerras | 7a84084 | 2016-11-16 22:25:20 +1100 | [diff] [blame] | 1803 | mtspr SPRN_SDR1,r6 /* switch to host page table */ |
| 1804 | END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_300) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1805 | mtspr SPRN_LPID,r7 |
| 1806 | isync |
| 1807 | |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1808 | BEGIN_FTR_SECTION |
Paul Mackerras | 88b02cf9 | 2016-09-15 13:42:52 +1000 | [diff] [blame] | 1809 | /* DPDES and VTB are shared between threads */ |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1810 | mfspr r7, SPRN_DPDES |
Paul Mackerras | 88b02cf9 | 2016-09-15 13:42:52 +1000 | [diff] [blame] | 1811 | mfspr r8, SPRN_VTB |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1812 | std r7, VCORE_DPDES(r5) |
Paul Mackerras | 88b02cf9 | 2016-09-15 13:42:52 +1000 | [diff] [blame] | 1813 | std r8, VCORE_VTB(r5) |
Michael Neuling | b005255e | 2014-01-08 21:25:21 +1100 | [diff] [blame] | 1814 | /* clear DPDES so we don't get guest doorbells in the host */ |
| 1815 | li r8, 0 |
| 1816 | mtspr SPRN_DPDES, r8 |
| 1817 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) |
| 1818 | |
Mahesh Salgaonkar | fd7bacb | 2016-05-15 09:44:26 +0530 | [diff] [blame] | 1819 | /* If HMI, call kvmppc_realmode_hmi_handler() */ |
| 1820 | cmpwi r12, BOOK3S_INTERRUPT_HMI |
| 1821 | bne 27f |
| 1822 | bl kvmppc_realmode_hmi_handler |
| 1823 | nop |
| 1824 | li r12, BOOK3S_INTERRUPT_HMI |
| 1825 | /* |
| 1826 | * At this point kvmppc_realmode_hmi_handler would have resync-ed |
| 1827 | * the TB. Hence it is not required to subtract guest timebase |
| 1828 | * offset from timebase. So, skip it. |
| 1829 | * |
| 1830 | * Also, do not call kvmppc_subcore_exit_guest() because it has |
| 1831 | * been invoked as part of kvmppc_realmode_hmi_handler(). |
| 1832 | */ |
| 1833 | b 30f |
| 1834 | |
| 1835 | 27: |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1836 | /* Subtract timebase offset from timebase */ |
| 1837 | ld r8,VCORE_TB_OFFSET(r5) |
| 1838 | cmpdi r8,0 |
| 1839 | beq 17f |
Paul Mackerras | c5fb80d | 2014-03-25 10:47:07 +1100 | [diff] [blame] | 1840 | mftb r6 /* current guest timebase */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1841 | subf r8,r8,r6 |
| 1842 | mtspr SPRN_TBU40,r8 /* update upper 40 bits */ |
| 1843 | mftb r7 /* check if lower 24 bits overflowed */ |
| 1844 | clrldi r6,r6,40 |
| 1845 | clrldi r7,r7,40 |
| 1846 | cmpld r7,r6 |
| 1847 | bge 17f |
| 1848 | addis r8,r8,0x100 /* if so, increment upper 40 bits */ |
| 1849 | mtspr SPRN_TBU40,r8 |
| 1850 | |
Mahesh Salgaonkar | fd7bacb | 2016-05-15 09:44:26 +0530 | [diff] [blame] | 1851 | 17: bl kvmppc_subcore_exit_guest |
| 1852 | nop |
| 1853 | 30: ld r5,HSTATE_KVM_VCORE(r13) |
| 1854 | ld r4,VCORE_KVM(r5) /* pointer to struct kvm */ |
| 1855 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1856 | /* Reset PCR */ |
Mahesh Salgaonkar | fd7bacb | 2016-05-15 09:44:26 +0530 | [diff] [blame] | 1857 | ld r0, VCORE_PCR(r5) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1858 | cmpdi r0, 0 |
| 1859 | beq 18f |
| 1860 | li r0, 0 |
| 1861 | mtspr SPRN_PCR, r0 |
| 1862 | 18: |
| 1863 | /* Signal secondary CPUs to continue */ |
| 1864 | stb r0,VCORE_IN_GUEST(r5) |
Paul Mackerras | b4deba5 | 2015-07-02 20:38:16 +1000 | [diff] [blame] | 1865 | 19: lis r8,0x7fff /* MAX_INT@h */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1866 | mtspr SPRN_HDEC,r8 |
| 1867 | |
| 1868 | 16: ld r8,KVM_HOST_LPCR(r4) |
| 1869 | mtspr SPRN_LPCR,r8 |
| 1870 | isync |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1871 | |
| 1872 | /* load host SLB entries */ |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 1873 | BEGIN_MMU_FTR_SECTION |
| 1874 | b 0f |
| 1875 | END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_RADIX) |
Paul Mackerras | c17b98c | 2014-12-03 13:30:38 +1100 | [diff] [blame] | 1876 | ld r8,PACA_SLBSHADOWPTR(r13) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1877 | |
| 1878 | .rept SLB_NUM_BOLTED |
Alexander Graf | 0865a58 | 2014-06-11 10:36:17 +0200 | [diff] [blame] | 1879 | li r3, SLBSHADOW_SAVEAREA |
| 1880 | LDX_BE r5, r8, r3 |
| 1881 | addi r3, r3, 8 |
| 1882 | LDX_BE r6, r8, r3 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1883 | andis. r7,r5,SLB_ESID_V@h |
| 1884 | beq 1f |
| 1885 | slbmte r6,r5 |
| 1886 | 1: addi r8,r8,16 |
| 1887 | .endr |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 1888 | 0: |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 1889 | #ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING |
| 1890 | /* Finish timing, if we have a vcpu */ |
| 1891 | ld r4, HSTATE_KVM_VCPU(r13) |
| 1892 | cmpdi r4, 0 |
| 1893 | li r3, 0 |
| 1894 | beq 2f |
| 1895 | bl kvmhv_accumulate_time |
| 1896 | 2: |
| 1897 | #endif |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1898 | /* Unset guest mode */ |
| 1899 | li r0, KVM_GUEST_MODE_NONE |
| 1900 | stb r0, HSTATE_IN_GUEST(r13) |
| 1901 | |
Paul Mackerras | 7ceaa6d | 2017-06-16 11:53:19 +1000 | [diff] [blame] | 1902 | ld r0, SFS+PPC_LR_STKOFF(r1) |
| 1903 | addi r1, r1, SFS |
Paul Mackerras | 218309b | 2013-09-06 13:23:44 +1000 | [diff] [blame] | 1904 | mtlr r0 |
| 1905 | blr |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1906 | |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1907 | /* |
| 1908 | * Check whether an HDSI is an HPTE not found fault or something else. |
| 1909 | * If it is an HPTE not found fault that is due to the guest accessing |
| 1910 | * a page that they have mapped but which we have paged out, then |
| 1911 | * we continue on with the guest exit path. In all other cases, |
| 1912 | * reflect the HDSI to the guest as a DSI. |
| 1913 | */ |
| 1914 | kvmppc_hdsi: |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 1915 | ld r3, VCPU_KVM(r9) |
| 1916 | lbz r0, KVM_RADIX(r3) |
| 1917 | cmpwi r0, 0 |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1918 | mfspr r4, SPRN_HDAR |
| 1919 | mfspr r6, SPRN_HDSISR |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 1920 | bne .Lradix_hdsi /* on radix, just save DAR/DSISR/ASDR */ |
Paul Mackerras | 4cf302b | 2011-12-12 12:38:51 +0000 | [diff] [blame] | 1921 | /* HPTE not found fault or protection fault? */ |
| 1922 | andis. r0, r6, (DSISR_NOHPTE | DSISR_PROTFAULT)@h |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1923 | beq 1f /* if not, send it to the guest */ |
Paul Mackerras | 4e5acdc | 2017-02-28 11:05:47 +1100 | [diff] [blame] | 1924 | andi. r0, r11, MSR_DR /* data relocation enabled? */ |
| 1925 | beq 3f |
Paul Mackerras | ef8c640 | 2017-01-30 21:21:43 +1100 | [diff] [blame] | 1926 | BEGIN_FTR_SECTION |
| 1927 | mfspr r5, SPRN_ASDR /* on POWER9, use ASDR to get VSID */ |
| 1928 | b 4f |
| 1929 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300) |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1930 | clrrdi r0, r4, 28 |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 1931 | PPC_SLBFEE_DOT(R5, R0) /* if so, look up SLB */ |
Paul Mackerras | cf29b21 | 2015-10-27 16:10:20 +1100 | [diff] [blame] | 1932 | li r0, BOOK3S_INTERRUPT_DATA_SEGMENT |
| 1933 | bne 7f /* if no SLB entry found */ |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1934 | 4: std r4, VCPU_FAULT_DAR(r9) |
| 1935 | stw r6, VCPU_FAULT_DSISR(r9) |
| 1936 | |
| 1937 | /* Search the hash table. */ |
| 1938 | mr r3, r9 /* vcpu pointer */ |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 1939 | li r7, 1 /* data fault */ |
Anton Blanchard | b1576fe | 2014-02-04 16:04:35 +1100 | [diff] [blame] | 1940 | bl kvmppc_hpte_hv_fault |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1941 | ld r9, HSTATE_KVM_VCPU(r13) |
| 1942 | ld r10, VCPU_PC(r9) |
| 1943 | ld r11, VCPU_MSR(r9) |
| 1944 | li r12, BOOK3S_INTERRUPT_H_DATA_STORAGE |
| 1945 | cmpdi r3, 0 /* retry the instruction */ |
| 1946 | beq 6f |
| 1947 | cmpdi r3, -1 /* handle in kernel mode */ |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1948 | beq guest_exit_cont |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1949 | cmpdi r3, -2 /* MMIO emulation; need instr word */ |
| 1950 | beq 2f |
| 1951 | |
Paul Mackerras | cf29b21 | 2015-10-27 16:10:20 +1100 | [diff] [blame] | 1952 | /* Synthesize a DSI (or DSegI) for the guest */ |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1953 | ld r4, VCPU_FAULT_DAR(r9) |
| 1954 | mr r6, r3 |
Paul Mackerras | cf29b21 | 2015-10-27 16:10:20 +1100 | [diff] [blame] | 1955 | 1: li r0, BOOK3S_INTERRUPT_DATA_STORAGE |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1956 | mtspr SPRN_DSISR, r6 |
Paul Mackerras | cf29b21 | 2015-10-27 16:10:20 +1100 | [diff] [blame] | 1957 | 7: mtspr SPRN_DAR, r4 |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1958 | mtspr SPRN_SRR0, r10 |
| 1959 | mtspr SPRN_SRR1, r11 |
Paul Mackerras | cf29b21 | 2015-10-27 16:10:20 +1100 | [diff] [blame] | 1960 | mr r10, r0 |
Michael Neuling | e4e3812 | 2014-03-25 10:47:02 +1100 | [diff] [blame] | 1961 | bl kvmppc_msr_interrupt |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1962 | fast_interrupt_c_return: |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1963 | 6: ld r7, VCPU_CTR(r9) |
Sam bobroff | c63517c | 2015-05-27 09:56:57 +1000 | [diff] [blame] | 1964 | ld r8, VCPU_XER(r9) |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1965 | mtctr r7 |
| 1966 | mtxer r8 |
| 1967 | mr r4, r9 |
| 1968 | b fast_guest_return |
| 1969 | |
| 1970 | 3: ld r5, VCPU_KVM(r9) /* not relocated, use VRMA */ |
| 1971 | ld r5, KVM_VRMA_SLB_V(r5) |
| 1972 | b 4b |
| 1973 | |
| 1974 | /* If this is for emulated MMIO, load the instruction word */ |
| 1975 | 2: li r8, KVM_INST_FETCH_FAILED /* In case lwz faults */ |
| 1976 | |
| 1977 | /* Set guest mode to 'jump over instruction' so if lwz faults |
| 1978 | * we'll just continue at the next IP. */ |
| 1979 | li r0, KVM_GUEST_MODE_SKIP |
| 1980 | stb r0, HSTATE_IN_GUEST(r13) |
| 1981 | |
| 1982 | /* Do the access with MSR:DR enabled */ |
| 1983 | mfmsr r3 |
| 1984 | ori r4, r3, MSR_DR /* Enable paging for data */ |
| 1985 | mtmsrd r4 |
| 1986 | lwz r8, 0(r10) |
| 1987 | mtmsrd r3 |
| 1988 | |
| 1989 | /* Store the result */ |
| 1990 | stw r8, VCPU_LAST_INST(r9) |
| 1991 | |
| 1992 | /* Unset guest mode. */ |
Paul Mackerras | 44a3add | 2013-10-04 21:45:04 +1000 | [diff] [blame] | 1993 | li r0, KVM_GUEST_MODE_HOST_HV |
Paul Mackerras | 697d389 | 2011-12-12 12:36:37 +0000 | [diff] [blame] | 1994 | stb r0, HSTATE_IN_GUEST(r13) |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 1995 | b guest_exit_cont |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 1996 | |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 1997 | .Lradix_hdsi: |
| 1998 | std r4, VCPU_FAULT_DAR(r9) |
| 1999 | stw r6, VCPU_FAULT_DSISR(r9) |
| 2000 | .Lradix_hisi: |
| 2001 | mfspr r5, SPRN_ASDR |
| 2002 | std r5, VCPU_FAULT_GPA(r9) |
| 2003 | b guest_exit_cont |
| 2004 | |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 2005 | /* |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 2006 | * Similarly for an HISI, reflect it to the guest as an ISI unless |
| 2007 | * it is an HPTE not found fault for a page that we have paged out. |
| 2008 | */ |
| 2009 | kvmppc_hisi: |
Paul Mackerras | f4c51f8 | 2017-01-30 21:21:45 +1100 | [diff] [blame] | 2010 | ld r3, VCPU_KVM(r9) |
| 2011 | lbz r0, KVM_RADIX(r3) |
| 2012 | cmpwi r0, 0 |
| 2013 | bne .Lradix_hisi /* for radix, just save ASDR */ |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 2014 | andis. r0, r11, SRR1_ISI_NOPT@h |
| 2015 | beq 1f |
Paul Mackerras | 4e5acdc | 2017-02-28 11:05:47 +1100 | [diff] [blame] | 2016 | andi. r0, r11, MSR_IR /* instruction relocation enabled? */ |
| 2017 | beq 3f |
Paul Mackerras | ef8c640 | 2017-01-30 21:21:43 +1100 | [diff] [blame] | 2018 | BEGIN_FTR_SECTION |
| 2019 | mfspr r5, SPRN_ASDR /* on POWER9, use ASDR to get VSID */ |
| 2020 | b 4f |
| 2021 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300) |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 2022 | clrrdi r0, r10, 28 |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 2023 | PPC_SLBFEE_DOT(R5, R0) /* if so, look up SLB */ |
Paul Mackerras | cf29b21 | 2015-10-27 16:10:20 +1100 | [diff] [blame] | 2024 | li r0, BOOK3S_INTERRUPT_INST_SEGMENT |
| 2025 | bne 7f /* if no SLB entry found */ |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 2026 | 4: |
| 2027 | /* Search the hash table. */ |
| 2028 | mr r3, r9 /* vcpu pointer */ |
| 2029 | mr r4, r10 |
| 2030 | mr r6, r11 |
| 2031 | li r7, 0 /* instruction fault */ |
Anton Blanchard | b1576fe | 2014-02-04 16:04:35 +1100 | [diff] [blame] | 2032 | bl kvmppc_hpte_hv_fault |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 2033 | ld r9, HSTATE_KVM_VCPU(r13) |
| 2034 | ld r10, VCPU_PC(r9) |
| 2035 | ld r11, VCPU_MSR(r9) |
| 2036 | li r12, BOOK3S_INTERRUPT_H_INST_STORAGE |
| 2037 | cmpdi r3, 0 /* retry the instruction */ |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 2038 | beq fast_interrupt_c_return |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 2039 | cmpdi r3, -1 /* handle in kernel mode */ |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 2040 | beq guest_exit_cont |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 2041 | |
Paul Mackerras | cf29b21 | 2015-10-27 16:10:20 +1100 | [diff] [blame] | 2042 | /* Synthesize an ISI (or ISegI) for the guest */ |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 2043 | mr r11, r3 |
Paul Mackerras | cf29b21 | 2015-10-27 16:10:20 +1100 | [diff] [blame] | 2044 | 1: li r0, BOOK3S_INTERRUPT_INST_STORAGE |
| 2045 | 7: mtspr SPRN_SRR0, r10 |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 2046 | mtspr SPRN_SRR1, r11 |
Paul Mackerras | cf29b21 | 2015-10-27 16:10:20 +1100 | [diff] [blame] | 2047 | mr r10, r0 |
Michael Neuling | e4e3812 | 2014-03-25 10:47:02 +1100 | [diff] [blame] | 2048 | bl kvmppc_msr_interrupt |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 2049 | b fast_interrupt_c_return |
Paul Mackerras | 342d3db | 2011-12-12 12:38:05 +0000 | [diff] [blame] | 2050 | |
| 2051 | 3: ld r6, VCPU_KVM(r9) /* not relocated, use VRMA */ |
| 2052 | ld r5, KVM_VRMA_SLB_V(r6) |
| 2053 | b 4b |
| 2054 | |
| 2055 | /* |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 2056 | * Try to handle an hcall in real mode. |
| 2057 | * Returns to the guest if we handle it, or continues on up to |
| 2058 | * the kernel if we can't (i.e. if we don't have a handler for |
| 2059 | * it, or if the handler returns H_TOO_HARD). |
Paul Mackerras | 1f09c3e | 2015-03-28 14:21:04 +1100 | [diff] [blame] | 2060 | * |
| 2061 | * r5 - r8 contain hcall args, |
| 2062 | * r9 = vcpu, r10 = pc, r11 = msr, r12 = trap, r13 = paca |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 2063 | */ |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 2064 | hcall_try_real_mode: |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 2065 | ld r3,VCPU_GPR(R3)(r9) |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 2066 | andi. r0,r11,MSR_PR |
Liu Ping Fan | 27025a6 | 2013-11-19 14:12:48 +0800 | [diff] [blame] | 2067 | /* sc 1 from userspace - reflect to guest syscall */ |
| 2068 | bne sc_1_fast_return |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 2069 | clrrdi r3,r3,2 |
| 2070 | cmpldi r3,hcall_real_table_end - hcall_real_table |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 2071 | bge guest_exit_cont |
Paul Mackerras | 699a0ea | 2014-06-02 11:02:59 +1000 | [diff] [blame] | 2072 | /* See if this hcall is enabled for in-kernel handling */ |
| 2073 | ld r4, VCPU_KVM(r9) |
| 2074 | srdi r0, r3, 8 /* r0 = (r3 / 4) >> 6 */ |
| 2075 | sldi r0, r0, 3 /* index into kvm->arch.enabled_hcalls[] */ |
| 2076 | add r4, r4, r0 |
| 2077 | ld r0, KVM_ENABLED_HCALLS(r4) |
| 2078 | rlwinm r4, r3, 32-2, 0x3f /* r4 = (r3 / 4) & 0x3f */ |
| 2079 | srd r0, r0, r4 |
| 2080 | andi. r0, r0, 1 |
| 2081 | beq guest_exit_cont |
| 2082 | /* Get pointer to handler, if any, and call it */ |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 2083 | LOAD_REG_ADDR(r4, hcall_real_table) |
Paul Mackerras | 4baa1d8 | 2013-07-08 20:09:53 +1000 | [diff] [blame] | 2084 | lwax r3,r3,r4 |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 2085 | cmpwi r3,0 |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 2086 | beq guest_exit_cont |
Anton Blanchard | 05a308c | 2014-06-12 18:16:10 +1000 | [diff] [blame] | 2087 | add r12,r3,r4 |
| 2088 | mtctr r12 |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 2089 | mr r3,r9 /* get vcpu pointer */ |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 2090 | ld r4,VCPU_GPR(R4)(r9) |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 2091 | bctrl |
| 2092 | cmpdi r3,H_TOO_HARD |
| 2093 | beq hcall_real_fallback |
| 2094 | ld r4,HSTATE_KVM_VCPU(r13) |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 2095 | std r3,VCPU_GPR(R3)(r4) |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 2096 | ld r10,VCPU_PC(r4) |
| 2097 | ld r11,VCPU_MSR(r4) |
| 2098 | b fast_guest_return |
| 2099 | |
Liu Ping Fan | 27025a6 | 2013-11-19 14:12:48 +0800 | [diff] [blame] | 2100 | sc_1_fast_return: |
| 2101 | mtspr SPRN_SRR0,r10 |
| 2102 | mtspr SPRN_SRR1,r11 |
| 2103 | li r10, BOOK3S_INTERRUPT_SYSCALL |
Michael Neuling | e4e3812 | 2014-03-25 10:47:02 +1100 | [diff] [blame] | 2104 | bl kvmppc_msr_interrupt |
Liu Ping Fan | 27025a6 | 2013-11-19 14:12:48 +0800 | [diff] [blame] | 2105 | mr r4,r9 |
| 2106 | b fast_guest_return |
| 2107 | |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 2108 | /* We've attempted a real mode hcall, but it's punted it back |
| 2109 | * to userspace. We need to restore some clobbered volatiles |
| 2110 | * before resuming the pass-it-to-qemu path */ |
| 2111 | hcall_real_fallback: |
| 2112 | li r12,BOOK3S_INTERRUPT_SYSCALL |
| 2113 | ld r9, HSTATE_KVM_VCPU(r13) |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 2114 | |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 2115 | b guest_exit_cont |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 2116 | |
| 2117 | .globl hcall_real_table |
| 2118 | hcall_real_table: |
| 2119 | .long 0 /* 0 - unused */ |
Anton Blanchard | c1fb019 | 2014-02-04 16:07:01 +1100 | [diff] [blame] | 2120 | .long DOTSYM(kvmppc_h_remove) - hcall_real_table |
| 2121 | .long DOTSYM(kvmppc_h_enter) - hcall_real_table |
| 2122 | .long DOTSYM(kvmppc_h_read) - hcall_real_table |
Paul Mackerras | cdeee51 | 2015-06-24 21:18:07 +1000 | [diff] [blame] | 2123 | .long DOTSYM(kvmppc_h_clear_mod) - hcall_real_table |
| 2124 | .long DOTSYM(kvmppc_h_clear_ref) - hcall_real_table |
Anton Blanchard | c1fb019 | 2014-02-04 16:07:01 +1100 | [diff] [blame] | 2125 | .long DOTSYM(kvmppc_h_protect) - hcall_real_table |
| 2126 | .long DOTSYM(kvmppc_h_get_tce) - hcall_real_table |
Alexey Kardashevskiy | 31217db | 2016-03-18 13:50:42 +1100 | [diff] [blame] | 2127 | .long DOTSYM(kvmppc_rm_h_put_tce) - hcall_real_table |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 2128 | .long 0 /* 0x24 - H_SET_SPRG0 */ |
Anton Blanchard | c1fb019 | 2014-02-04 16:07:01 +1100 | [diff] [blame] | 2129 | .long DOTSYM(kvmppc_h_set_dabr) - hcall_real_table |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 2130 | .long 0 /* 0x2c */ |
| 2131 | .long 0 /* 0x30 */ |
| 2132 | .long 0 /* 0x34 */ |
| 2133 | .long 0 /* 0x38 */ |
| 2134 | .long 0 /* 0x3c */ |
| 2135 | .long 0 /* 0x40 */ |
| 2136 | .long 0 /* 0x44 */ |
| 2137 | .long 0 /* 0x48 */ |
| 2138 | .long 0 /* 0x4c */ |
| 2139 | .long 0 /* 0x50 */ |
| 2140 | .long 0 /* 0x54 */ |
| 2141 | .long 0 /* 0x58 */ |
| 2142 | .long 0 /* 0x5c */ |
| 2143 | .long 0 /* 0x60 */ |
Benjamin Herrenschmidt | e7d26f2 | 2013-04-17 20:31:15 +0000 | [diff] [blame] | 2144 | #ifdef CONFIG_KVM_XICS |
Anton Blanchard | c1fb019 | 2014-02-04 16:07:01 +1100 | [diff] [blame] | 2145 | .long DOTSYM(kvmppc_rm_h_eoi) - hcall_real_table |
| 2146 | .long DOTSYM(kvmppc_rm_h_cppr) - hcall_real_table |
| 2147 | .long DOTSYM(kvmppc_rm_h_ipi) - hcall_real_table |
Benjamin Herrenschmidt | 5af5099 | 2017-04-05 17:54:56 +1000 | [diff] [blame] | 2148 | .long DOTSYM(kvmppc_rm_h_ipoll) - hcall_real_table |
Anton Blanchard | c1fb019 | 2014-02-04 16:07:01 +1100 | [diff] [blame] | 2149 | .long DOTSYM(kvmppc_rm_h_xirr) - hcall_real_table |
Benjamin Herrenschmidt | e7d26f2 | 2013-04-17 20:31:15 +0000 | [diff] [blame] | 2150 | #else |
| 2151 | .long 0 /* 0x64 - H_EOI */ |
| 2152 | .long 0 /* 0x68 - H_CPPR */ |
| 2153 | .long 0 /* 0x6c - H_IPI */ |
| 2154 | .long 0 /* 0x70 - H_IPOLL */ |
| 2155 | .long 0 /* 0x74 - H_XIRR */ |
| 2156 | #endif |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 2157 | .long 0 /* 0x78 */ |
| 2158 | .long 0 /* 0x7c */ |
| 2159 | .long 0 /* 0x80 */ |
| 2160 | .long 0 /* 0x84 */ |
| 2161 | .long 0 /* 0x88 */ |
| 2162 | .long 0 /* 0x8c */ |
| 2163 | .long 0 /* 0x90 */ |
| 2164 | .long 0 /* 0x94 */ |
| 2165 | .long 0 /* 0x98 */ |
| 2166 | .long 0 /* 0x9c */ |
| 2167 | .long 0 /* 0xa0 */ |
| 2168 | .long 0 /* 0xa4 */ |
| 2169 | .long 0 /* 0xa8 */ |
| 2170 | .long 0 /* 0xac */ |
| 2171 | .long 0 /* 0xb0 */ |
| 2172 | .long 0 /* 0xb4 */ |
| 2173 | .long 0 /* 0xb8 */ |
| 2174 | .long 0 /* 0xbc */ |
| 2175 | .long 0 /* 0xc0 */ |
| 2176 | .long 0 /* 0xc4 */ |
| 2177 | .long 0 /* 0xc8 */ |
| 2178 | .long 0 /* 0xcc */ |
| 2179 | .long 0 /* 0xd0 */ |
| 2180 | .long 0 /* 0xd4 */ |
| 2181 | .long 0 /* 0xd8 */ |
| 2182 | .long 0 /* 0xdc */ |
Anton Blanchard | c1fb019 | 2014-02-04 16:07:01 +1100 | [diff] [blame] | 2183 | .long DOTSYM(kvmppc_h_cede) - hcall_real_table |
Sam Bobroff | 90fd09f | 2014-12-03 13:30:40 +1100 | [diff] [blame] | 2184 | .long DOTSYM(kvmppc_rm_h_confer) - hcall_real_table |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 2185 | .long 0 /* 0xe8 */ |
| 2186 | .long 0 /* 0xec */ |
| 2187 | .long 0 /* 0xf0 */ |
| 2188 | .long 0 /* 0xf4 */ |
| 2189 | .long 0 /* 0xf8 */ |
| 2190 | .long 0 /* 0xfc */ |
| 2191 | .long 0 /* 0x100 */ |
| 2192 | .long 0 /* 0x104 */ |
| 2193 | .long 0 /* 0x108 */ |
| 2194 | .long 0 /* 0x10c */ |
| 2195 | .long 0 /* 0x110 */ |
| 2196 | .long 0 /* 0x114 */ |
| 2197 | .long 0 /* 0x118 */ |
| 2198 | .long 0 /* 0x11c */ |
| 2199 | .long 0 /* 0x120 */ |
Anton Blanchard | c1fb019 | 2014-02-04 16:07:01 +1100 | [diff] [blame] | 2200 | .long DOTSYM(kvmppc_h_bulk_remove) - hcall_real_table |
Paul Mackerras | 8563bf5 | 2014-01-08 21:25:29 +1100 | [diff] [blame] | 2201 | .long 0 /* 0x128 */ |
| 2202 | .long 0 /* 0x12c */ |
| 2203 | .long 0 /* 0x130 */ |
Anton Blanchard | c1fb019 | 2014-02-04 16:07:01 +1100 | [diff] [blame] | 2204 | .long DOTSYM(kvmppc_h_set_xdabr) - hcall_real_table |
Alexey Kardashevskiy | 31217db | 2016-03-18 13:50:42 +1100 | [diff] [blame] | 2205 | .long DOTSYM(kvmppc_rm_h_stuff_tce) - hcall_real_table |
Alexey Kardashevskiy | d3695aa | 2016-02-15 12:55:09 +1100 | [diff] [blame] | 2206 | .long DOTSYM(kvmppc_rm_h_put_tce_indirect) - hcall_real_table |
Michael Ellerman | e928e9c | 2015-03-20 20:39:41 +1100 | [diff] [blame] | 2207 | .long 0 /* 0x140 */ |
| 2208 | .long 0 /* 0x144 */ |
| 2209 | .long 0 /* 0x148 */ |
| 2210 | .long 0 /* 0x14c */ |
| 2211 | .long 0 /* 0x150 */ |
| 2212 | .long 0 /* 0x154 */ |
| 2213 | .long 0 /* 0x158 */ |
| 2214 | .long 0 /* 0x15c */ |
| 2215 | .long 0 /* 0x160 */ |
| 2216 | .long 0 /* 0x164 */ |
| 2217 | .long 0 /* 0x168 */ |
| 2218 | .long 0 /* 0x16c */ |
| 2219 | .long 0 /* 0x170 */ |
| 2220 | .long 0 /* 0x174 */ |
| 2221 | .long 0 /* 0x178 */ |
| 2222 | .long 0 /* 0x17c */ |
| 2223 | .long 0 /* 0x180 */ |
| 2224 | .long 0 /* 0x184 */ |
| 2225 | .long 0 /* 0x188 */ |
| 2226 | .long 0 /* 0x18c */ |
| 2227 | .long 0 /* 0x190 */ |
| 2228 | .long 0 /* 0x194 */ |
| 2229 | .long 0 /* 0x198 */ |
| 2230 | .long 0 /* 0x19c */ |
| 2231 | .long 0 /* 0x1a0 */ |
| 2232 | .long 0 /* 0x1a4 */ |
| 2233 | .long 0 /* 0x1a8 */ |
| 2234 | .long 0 /* 0x1ac */ |
| 2235 | .long 0 /* 0x1b0 */ |
| 2236 | .long 0 /* 0x1b4 */ |
| 2237 | .long 0 /* 0x1b8 */ |
| 2238 | .long 0 /* 0x1bc */ |
| 2239 | .long 0 /* 0x1c0 */ |
| 2240 | .long 0 /* 0x1c4 */ |
| 2241 | .long 0 /* 0x1c8 */ |
| 2242 | .long 0 /* 0x1cc */ |
| 2243 | .long 0 /* 0x1d0 */ |
| 2244 | .long 0 /* 0x1d4 */ |
| 2245 | .long 0 /* 0x1d8 */ |
| 2246 | .long 0 /* 0x1dc */ |
| 2247 | .long 0 /* 0x1e0 */ |
| 2248 | .long 0 /* 0x1e4 */ |
| 2249 | .long 0 /* 0x1e8 */ |
| 2250 | .long 0 /* 0x1ec */ |
| 2251 | .long 0 /* 0x1f0 */ |
| 2252 | .long 0 /* 0x1f4 */ |
| 2253 | .long 0 /* 0x1f8 */ |
| 2254 | .long 0 /* 0x1fc */ |
| 2255 | .long 0 /* 0x200 */ |
| 2256 | .long 0 /* 0x204 */ |
| 2257 | .long 0 /* 0x208 */ |
| 2258 | .long 0 /* 0x20c */ |
| 2259 | .long 0 /* 0x210 */ |
| 2260 | .long 0 /* 0x214 */ |
| 2261 | .long 0 /* 0x218 */ |
| 2262 | .long 0 /* 0x21c */ |
| 2263 | .long 0 /* 0x220 */ |
| 2264 | .long 0 /* 0x224 */ |
| 2265 | .long 0 /* 0x228 */ |
| 2266 | .long 0 /* 0x22c */ |
| 2267 | .long 0 /* 0x230 */ |
| 2268 | .long 0 /* 0x234 */ |
| 2269 | .long 0 /* 0x238 */ |
| 2270 | .long 0 /* 0x23c */ |
| 2271 | .long 0 /* 0x240 */ |
| 2272 | .long 0 /* 0x244 */ |
| 2273 | .long 0 /* 0x248 */ |
| 2274 | .long 0 /* 0x24c */ |
| 2275 | .long 0 /* 0x250 */ |
| 2276 | .long 0 /* 0x254 */ |
| 2277 | .long 0 /* 0x258 */ |
| 2278 | .long 0 /* 0x25c */ |
| 2279 | .long 0 /* 0x260 */ |
| 2280 | .long 0 /* 0x264 */ |
| 2281 | .long 0 /* 0x268 */ |
| 2282 | .long 0 /* 0x26c */ |
| 2283 | .long 0 /* 0x270 */ |
| 2284 | .long 0 /* 0x274 */ |
| 2285 | .long 0 /* 0x278 */ |
| 2286 | .long 0 /* 0x27c */ |
| 2287 | .long 0 /* 0x280 */ |
| 2288 | .long 0 /* 0x284 */ |
| 2289 | .long 0 /* 0x288 */ |
| 2290 | .long 0 /* 0x28c */ |
| 2291 | .long 0 /* 0x290 */ |
| 2292 | .long 0 /* 0x294 */ |
| 2293 | .long 0 /* 0x298 */ |
| 2294 | .long 0 /* 0x29c */ |
| 2295 | .long 0 /* 0x2a0 */ |
| 2296 | .long 0 /* 0x2a4 */ |
| 2297 | .long 0 /* 0x2a8 */ |
| 2298 | .long 0 /* 0x2ac */ |
| 2299 | .long 0 /* 0x2b0 */ |
| 2300 | .long 0 /* 0x2b4 */ |
| 2301 | .long 0 /* 0x2b8 */ |
| 2302 | .long 0 /* 0x2bc */ |
| 2303 | .long 0 /* 0x2c0 */ |
| 2304 | .long 0 /* 0x2c4 */ |
| 2305 | .long 0 /* 0x2c8 */ |
| 2306 | .long 0 /* 0x2cc */ |
| 2307 | .long 0 /* 0x2d0 */ |
| 2308 | .long 0 /* 0x2d4 */ |
| 2309 | .long 0 /* 0x2d8 */ |
| 2310 | .long 0 /* 0x2dc */ |
| 2311 | .long 0 /* 0x2e0 */ |
| 2312 | .long 0 /* 0x2e4 */ |
| 2313 | .long 0 /* 0x2e8 */ |
| 2314 | .long 0 /* 0x2ec */ |
| 2315 | .long 0 /* 0x2f0 */ |
| 2316 | .long 0 /* 0x2f4 */ |
| 2317 | .long 0 /* 0x2f8 */ |
Benjamin Herrenschmidt | 5af5099 | 2017-04-05 17:54:56 +1000 | [diff] [blame] | 2318 | #ifdef CONFIG_KVM_XICS |
| 2319 | .long DOTSYM(kvmppc_rm_h_xirr_x) - hcall_real_table |
| 2320 | #else |
| 2321 | .long 0 /* 0x2fc - H_XIRR_X*/ |
| 2322 | #endif |
Michael Ellerman | e928e9c | 2015-03-20 20:39:41 +1100 | [diff] [blame] | 2323 | .long DOTSYM(kvmppc_h_random) - hcall_real_table |
Paul Mackerras | ae2113a | 2014-06-02 11:03:00 +1000 | [diff] [blame] | 2324 | .globl hcall_real_table_end |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 2325 | hcall_real_table_end: |
| 2326 | |
Paul Mackerras | 8563bf5 | 2014-01-08 21:25:29 +1100 | [diff] [blame] | 2327 | _GLOBAL(kvmppc_h_set_xdabr) |
| 2328 | andi. r0, r5, DABRX_USER | DABRX_KERNEL |
| 2329 | beq 6f |
| 2330 | li r0, DABRX_USER | DABRX_KERNEL | DABRX_BTI |
| 2331 | andc. r0, r5, r0 |
| 2332 | beq 3f |
| 2333 | 6: li r3, H_PARAMETER |
| 2334 | blr |
| 2335 | |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 2336 | _GLOBAL(kvmppc_h_set_dabr) |
Paul Mackerras | 8563bf5 | 2014-01-08 21:25:29 +1100 | [diff] [blame] | 2337 | li r5, DABRX_USER | DABRX_KERNEL |
| 2338 | 3: |
Michael Neuling | eee7ff9 | 2014-01-08 21:25:19 +1100 | [diff] [blame] | 2339 | BEGIN_FTR_SECTION |
| 2340 | b 2f |
| 2341 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 2342 | std r4,VCPU_DABR(r3) |
Paul Mackerras | 8563bf5 | 2014-01-08 21:25:29 +1100 | [diff] [blame] | 2343 | stw r5, VCPU_DABRX(r3) |
| 2344 | mtspr SPRN_DABRX, r5 |
Paul Mackerras | 8943633 | 2012-03-02 01:38:23 +0000 | [diff] [blame] | 2345 | /* Work around P7 bug where DABR can get corrupted on mtspr */ |
| 2346 | 1: mtspr SPRN_DABR,r4 |
| 2347 | mfspr r5, SPRN_DABR |
| 2348 | cmpd r4, r5 |
| 2349 | bne 1b |
| 2350 | isync |
Paul Mackerras | a8606e2 | 2011-06-29 00:22:05 +0000 | [diff] [blame] | 2351 | li r3,0 |
| 2352 | blr |
| 2353 | |
Paul Mackerras | 8563bf5 | 2014-01-08 21:25:29 +1100 | [diff] [blame] | 2354 | /* Emulate H_SET_DABR/X on P8 for the sake of compat mode guests */ |
| 2355 | 2: rlwimi r5, r4, 5, DAWRX_DR | DAWRX_DW |
Thomas Huth | 760a736 | 2015-11-20 09:11:45 +0100 | [diff] [blame] | 2356 | rlwimi r5, r4, 2, DAWRX_WT |
Paul Mackerras | 8563bf5 | 2014-01-08 21:25:29 +1100 | [diff] [blame] | 2357 | clrrdi r4, r4, 3 |
| 2358 | std r4, VCPU_DAWR(r3) |
| 2359 | std r5, VCPU_DAWRX(r3) |
| 2360 | mtspr SPRN_DAWR, r4 |
| 2361 | mtspr SPRN_DAWRX, r5 |
| 2362 | li r3, 0 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2363 | blr |
| 2364 | |
Paul Mackerras | 1f09c3e | 2015-03-28 14:21:04 +1100 | [diff] [blame] | 2365 | _GLOBAL(kvmppc_h_cede) /* r3 = vcpu pointer, r11 = msr, r13 = paca */ |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2366 | ori r11,r11,MSR_EE |
| 2367 | std r11,VCPU_MSR(r3) |
| 2368 | li r0,1 |
| 2369 | stb r0,VCPU_CEDED(r3) |
| 2370 | sync /* order setting ceded vs. testing prodded */ |
| 2371 | lbz r5,VCPU_PRODDED(r3) |
| 2372 | cmpwi r5,0 |
Paul Mackerras | 04f995a | 2012-08-06 00:03:28 +0000 | [diff] [blame] | 2373 | bne kvm_cede_prodded |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 2374 | li r12,0 /* set trap to 0 to say hcall is handled */ |
| 2375 | stw r12,VCPU_TRAP(r3) |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2376 | li r0,H_SUCCESS |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 2377 | std r0,VCPU_GPR(R3)(r3) |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2378 | |
| 2379 | /* |
| 2380 | * Set our bit in the bitmask of napping threads unless all the |
| 2381 | * other threads are already napping, in which case we send this |
| 2382 | * up to the host. |
| 2383 | */ |
| 2384 | ld r5,HSTATE_KVM_VCORE(r13) |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 2385 | lbz r6,HSTATE_PTID(r13) |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2386 | lwz r8,VCORE_ENTRY_EXIT(r5) |
| 2387 | clrldi r8,r8,56 |
| 2388 | li r0,1 |
| 2389 | sld r0,r0,r6 |
| 2390 | addi r6,r5,VCORE_NAPPING_THREADS |
| 2391 | 31: lwarx r4,0,r6 |
| 2392 | or r4,r4,r0 |
Paul Mackerras | 7d6c40d | 2015-03-28 14:21:09 +1100 | [diff] [blame] | 2393 | cmpw r4,r8 |
| 2394 | beq kvm_cede_exit |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2395 | stwcx. r4,0,r6 |
| 2396 | bne 31b |
Paul Mackerras | 7d6c40d | 2015-03-28 14:21:09 +1100 | [diff] [blame] | 2397 | /* order napping_threads update vs testing entry_exit_map */ |
Paul Mackerras | f019b7a | 2013-11-16 17:46:03 +1100 | [diff] [blame] | 2398 | isync |
Paul Mackerras | e0b7ec0 | 2014-01-08 21:25:20 +1100 | [diff] [blame] | 2399 | li r0,NAPPING_CEDE |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2400 | stb r0,HSTATE_NAPPING(r13) |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2401 | lwz r7,VCORE_ENTRY_EXIT(r5) |
| 2402 | cmpwi r7,0x100 |
| 2403 | bge 33f /* another thread already exiting */ |
| 2404 | |
| 2405 | /* |
| 2406 | * Although not specifically required by the architecture, POWER7 |
| 2407 | * preserves the following registers in nap mode, even if an SMT mode |
| 2408 | * switch occurs: SLB entries, PURR, SPURR, AMOR, UAMOR, AMR, SPRG0-3, |
| 2409 | * DAR, DSISR, DABR, DABRX, DSCR, PMCx, MMCRx, SIAR, SDAR. |
| 2410 | */ |
| 2411 | /* Save non-volatile GPRs */ |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 2412 | std r14, VCPU_GPR(R14)(r3) |
| 2413 | std r15, VCPU_GPR(R15)(r3) |
| 2414 | std r16, VCPU_GPR(R16)(r3) |
| 2415 | std r17, VCPU_GPR(R17)(r3) |
| 2416 | std r18, VCPU_GPR(R18)(r3) |
| 2417 | std r19, VCPU_GPR(R19)(r3) |
| 2418 | std r20, VCPU_GPR(R20)(r3) |
| 2419 | std r21, VCPU_GPR(R21)(r3) |
| 2420 | std r22, VCPU_GPR(R22)(r3) |
| 2421 | std r23, VCPU_GPR(R23)(r3) |
| 2422 | std r24, VCPU_GPR(R24)(r3) |
| 2423 | std r25, VCPU_GPR(R25)(r3) |
| 2424 | std r26, VCPU_GPR(R26)(r3) |
| 2425 | std r27, VCPU_GPR(R27)(r3) |
| 2426 | std r28, VCPU_GPR(R28)(r3) |
| 2427 | std r29, VCPU_GPR(R29)(r3) |
| 2428 | std r30, VCPU_GPR(R30)(r3) |
| 2429 | std r31, VCPU_GPR(R31)(r3) |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2430 | |
| 2431 | /* save FP state */ |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2432 | bl kvmppc_save_fp |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2433 | |
Paul Mackerras | 93d1739 | 2016-06-22 15:52:55 +1000 | [diff] [blame] | 2434 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM |
| 2435 | BEGIN_FTR_SECTION |
| 2436 | ld r9, HSTATE_KVM_VCPU(r13) |
| 2437 | bl kvmppc_save_tm |
| 2438 | END_FTR_SECTION_IFSET(CPU_FTR_TM) |
| 2439 | #endif |
| 2440 | |
Paul Mackerras | fd6d53b | 2015-03-28 14:21:08 +1100 | [diff] [blame] | 2441 | /* |
| 2442 | * Set DEC to the smaller of DEC and HDEC, so that we wake |
| 2443 | * no later than the end of our timeslice (HDEC interrupts |
| 2444 | * don't wake us from nap). |
| 2445 | */ |
| 2446 | mfspr r3, SPRN_DEC |
| 2447 | mfspr r4, SPRN_HDEC |
| 2448 | mftb r5 |
Paul Mackerras | 1bc3fe8 | 2017-05-22 16:55:16 +1000 | [diff] [blame] | 2449 | BEGIN_FTR_SECTION |
| 2450 | /* On P9 check whether the guest has large decrementer mode enabled */ |
| 2451 | ld r6, HSTATE_KVM_VCORE(r13) |
| 2452 | ld r6, VCORE_LPCR(r6) |
| 2453 | andis. r6, r6, LPCR_LD@h |
| 2454 | bne 68f |
| 2455 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300) |
Paul Mackerras | 2f27246 | 2017-05-22 16:25:14 +1000 | [diff] [blame] | 2456 | extsw r3, r3 |
Paul Mackerras | 1bc3fe8 | 2017-05-22 16:55:16 +1000 | [diff] [blame] | 2457 | 68: EXTEND_HDEC(r4) |
Paul Mackerras | 2f27246 | 2017-05-22 16:25:14 +1000 | [diff] [blame] | 2458 | cmpd r3, r4 |
Paul Mackerras | fd6d53b | 2015-03-28 14:21:08 +1100 | [diff] [blame] | 2459 | ble 67f |
| 2460 | mtspr SPRN_DEC, r4 |
| 2461 | 67: |
| 2462 | /* save expiry time of guest decrementer */ |
Paul Mackerras | fd6d53b | 2015-03-28 14:21:08 +1100 | [diff] [blame] | 2463 | add r3, r3, r5 |
| 2464 | ld r4, HSTATE_KVM_VCPU(r13) |
| 2465 | ld r5, HSTATE_KVM_VCORE(r13) |
| 2466 | ld r6, VCORE_TB_OFFSET(r5) |
| 2467 | subf r3, r6, r3 /* convert to host TB value */ |
| 2468 | std r3, VCPU_DEC_EXPIRES(r4) |
| 2469 | |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 2470 | #ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING |
| 2471 | ld r4, HSTATE_KVM_VCPU(r13) |
| 2472 | addi r3, r4, VCPU_TB_CEDE |
| 2473 | bl kvmhv_accumulate_time |
| 2474 | #endif |
| 2475 | |
Paul Mackerras | ccc0777 | 2015-03-28 14:21:07 +1100 | [diff] [blame] | 2476 | lis r3, LPCR_PECEDP@h /* Do wake on privileged doorbell */ |
| 2477 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2478 | /* |
Paul Mackerras | aa31e84 | 2014-01-08 21:25:26 +1100 | [diff] [blame] | 2479 | * Take a nap until a decrementer or external or doobell interrupt |
Paul Mackerras | ccc0777 | 2015-03-28 14:21:07 +1100 | [diff] [blame] | 2480 | * occurs, with PECE1 and PECE0 set in LPCR. |
Paul Mackerras | 66feed6 | 2015-03-28 14:21:12 +1100 | [diff] [blame] | 2481 | * On POWER8, set PECEDH, and if we are ceding, also set PECEDP. |
Paul Mackerras | ccc0777 | 2015-03-28 14:21:07 +1100 | [diff] [blame] | 2482 | * Also clear the runlatch bit before napping. |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2483 | */ |
Paul Mackerras | 56548fc | 2014-12-03 14:48:40 +1100 | [diff] [blame] | 2484 | kvm_do_nap: |
Paul Mackerras | 1f09c3e | 2015-03-28 14:21:04 +1100 | [diff] [blame] | 2485 | mfspr r0, SPRN_CTRLF |
| 2486 | clrrdi r0, r0, 1 |
| 2487 | mtspr SPRN_CTRLT, r0 |
Preeti U Murthy | 582b910 | 2014-04-11 16:02:08 +0530 | [diff] [blame] | 2488 | |
Paul Mackerras | f0888f7 | 2012-02-03 00:54:17 +0000 | [diff] [blame] | 2489 | li r0,1 |
| 2490 | stb r0,HSTATE_HWTHREAD_REQ(r13) |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2491 | mfspr r5,SPRN_LPCR |
| 2492 | ori r5,r5,LPCR_PECE0 | LPCR_PECE1 |
Paul Mackerras | aa31e84 | 2014-01-08 21:25:26 +1100 | [diff] [blame] | 2493 | BEGIN_FTR_SECTION |
Paul Mackerras | 66feed6 | 2015-03-28 14:21:12 +1100 | [diff] [blame] | 2494 | ori r5, r5, LPCR_PECEDH |
Paul Mackerras | ccc0777 | 2015-03-28 14:21:07 +1100 | [diff] [blame] | 2495 | rlwimi r5, r3, 0, LPCR_PECEDP |
Paul Mackerras | aa31e84 | 2014-01-08 21:25:26 +1100 | [diff] [blame] | 2496 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) |
Paul Mackerras | bf53c88 | 2016-11-18 14:34:07 +1100 | [diff] [blame] | 2497 | |
| 2498 | kvm_nap_sequence: /* desired LPCR value in r5 */ |
| 2499 | BEGIN_FTR_SECTION |
| 2500 | /* |
| 2501 | * PSSCR bits: exit criterion = 1 (wakeup based on LPCR at sreset) |
| 2502 | * enable state loss = 1 (allow SMT mode switch) |
| 2503 | * requested level = 0 (just stop dispatching) |
| 2504 | */ |
| 2505 | lis r3, (PSSCR_EC | PSSCR_ESL)@h |
| 2506 | mtspr SPRN_PSSCR, r3 |
| 2507 | /* Set LPCR_PECE_HVEE bit to enable wakeup by HV interrupts */ |
| 2508 | li r4, LPCR_PECE_HVEE@higher |
| 2509 | sldi r4, r4, 32 |
| 2510 | or r5, r5, r4 |
| 2511 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300) |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2512 | mtspr SPRN_LPCR,r5 |
| 2513 | isync |
| 2514 | li r0, 0 |
| 2515 | std r0, HSTATE_SCRATCH0(r13) |
| 2516 | ptesync |
| 2517 | ld r0, HSTATE_SCRATCH0(r13) |
| 2518 | 1: cmpd r0, r0 |
| 2519 | bne 1b |
Paul Mackerras | bf53c88 | 2016-11-18 14:34:07 +1100 | [diff] [blame] | 2520 | BEGIN_FTR_SECTION |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2521 | nap |
Paul Mackerras | bf53c88 | 2016-11-18 14:34:07 +1100 | [diff] [blame] | 2522 | FTR_SECTION_ELSE |
| 2523 | PPC_STOP |
| 2524 | ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_300) |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2525 | b . |
| 2526 | |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 2527 | 33: mr r4, r3 |
| 2528 | li r3, 0 |
| 2529 | li r12, 0 |
| 2530 | b 34f |
| 2531 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2532 | kvm_end_cede: |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 2533 | /* get vcpu pointer */ |
| 2534 | ld r4, HSTATE_KVM_VCPU(r13) |
| 2535 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2536 | /* Woken by external or decrementer interrupt */ |
| 2537 | ld r1, HSTATE_HOST_R1(r13) |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2538 | |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 2539 | #ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING |
| 2540 | addi r3, r4, VCPU_TB_RMINTR |
| 2541 | bl kvmhv_accumulate_time |
| 2542 | #endif |
| 2543 | |
Paul Mackerras | 93d1739 | 2016-06-22 15:52:55 +1000 | [diff] [blame] | 2544 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM |
| 2545 | BEGIN_FTR_SECTION |
| 2546 | bl kvmppc_restore_tm |
| 2547 | END_FTR_SECTION_IFSET(CPU_FTR_TM) |
| 2548 | #endif |
| 2549 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2550 | /* load up FP state */ |
| 2551 | bl kvmppc_load_fp |
| 2552 | |
Paul Mackerras | fd6d53b | 2015-03-28 14:21:08 +1100 | [diff] [blame] | 2553 | /* Restore guest decrementer */ |
| 2554 | ld r3, VCPU_DEC_EXPIRES(r4) |
| 2555 | ld r5, HSTATE_KVM_VCORE(r13) |
| 2556 | ld r6, VCORE_TB_OFFSET(r5) |
| 2557 | add r3, r3, r6 /* convert host TB to guest TB value */ |
| 2558 | mftb r7 |
| 2559 | subf r3, r7, r3 |
| 2560 | mtspr SPRN_DEC, r3 |
| 2561 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2562 | /* Load NV GPRS */ |
Michael Neuling | c75df6f | 2012-06-25 13:33:10 +0000 | [diff] [blame] | 2563 | ld r14, VCPU_GPR(R14)(r4) |
| 2564 | ld r15, VCPU_GPR(R15)(r4) |
| 2565 | ld r16, VCPU_GPR(R16)(r4) |
| 2566 | ld r17, VCPU_GPR(R17)(r4) |
| 2567 | ld r18, VCPU_GPR(R18)(r4) |
| 2568 | ld r19, VCPU_GPR(R19)(r4) |
| 2569 | ld r20, VCPU_GPR(R20)(r4) |
| 2570 | ld r21, VCPU_GPR(R21)(r4) |
| 2571 | ld r22, VCPU_GPR(R22)(r4) |
| 2572 | ld r23, VCPU_GPR(R23)(r4) |
| 2573 | ld r24, VCPU_GPR(R24)(r4) |
| 2574 | ld r25, VCPU_GPR(R25)(r4) |
| 2575 | ld r26, VCPU_GPR(R26)(r4) |
| 2576 | ld r27, VCPU_GPR(R27)(r4) |
| 2577 | ld r28, VCPU_GPR(R28)(r4) |
| 2578 | ld r29, VCPU_GPR(R29)(r4) |
| 2579 | ld r30, VCPU_GPR(R30)(r4) |
| 2580 | ld r31, VCPU_GPR(R31)(r4) |
Suresh Warrier | 37f55d3 | 2016-08-19 15:35:46 +1000 | [diff] [blame] | 2581 | |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 2582 | /* Check the wake reason in SRR1 to see why we got here */ |
| 2583 | bl kvmppc_check_wake_reason |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2584 | |
Suresh Warrier | 37f55d3 | 2016-08-19 15:35:46 +1000 | [diff] [blame] | 2585 | /* |
| 2586 | * Restore volatile registers since we could have called a |
| 2587 | * C routine in kvmppc_check_wake_reason |
| 2588 | * r4 = VCPU |
| 2589 | * r3 tells us whether we need to return to host or not |
| 2590 | * WARNING: it gets checked further down: |
| 2591 | * should not modify r3 until this check is done. |
| 2592 | */ |
| 2593 | ld r4, HSTATE_KVM_VCPU(r13) |
| 2594 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2595 | /* clear our bit in vcore->napping_threads */ |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 2596 | 34: ld r5,HSTATE_KVM_VCORE(r13) |
| 2597 | lbz r7,HSTATE_PTID(r13) |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2598 | li r0,1 |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 2599 | sld r0,r0,r7 |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2600 | addi r6,r5,VCORE_NAPPING_THREADS |
| 2601 | 32: lwarx r7,0,r6 |
| 2602 | andc r7,r7,r0 |
| 2603 | stwcx. r7,0,r6 |
| 2604 | bne 32b |
| 2605 | li r0,0 |
| 2606 | stb r0,HSTATE_NAPPING(r13) |
| 2607 | |
Suresh Warrier | 37f55d3 | 2016-08-19 15:35:46 +1000 | [diff] [blame] | 2608 | /* See if the wake reason saved in r3 means we need to exit */ |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 2609 | stw r12, VCPU_TRAP(r4) |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 2610 | mr r9, r4 |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 2611 | cmpdi r3, 0 |
| 2612 | bgt guest_exit_cont |
Paul Mackerras | 4619ac8 | 2013-04-17 20:31:41 +0000 | [diff] [blame] | 2613 | |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2614 | /* see if any other thread is already exiting */ |
| 2615 | lwz r0,VCORE_ENTRY_EXIT(r5) |
| 2616 | cmpwi r0,0x100 |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 2617 | bge guest_exit_cont |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2618 | |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 2619 | b kvmppc_cede_reentry /* if not go back to guest */ |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2620 | |
| 2621 | /* cede when already previously prodded case */ |
Paul Mackerras | 04f995a | 2012-08-06 00:03:28 +0000 | [diff] [blame] | 2622 | kvm_cede_prodded: |
| 2623 | li r0,0 |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2624 | stb r0,VCPU_PRODDED(r3) |
| 2625 | sync /* order testing prodded vs. clearing ceded */ |
| 2626 | stb r0,VCPU_CEDED(r3) |
| 2627 | li r3,H_SUCCESS |
| 2628 | blr |
| 2629 | |
| 2630 | /* we've ceded but we want to give control to the host */ |
Paul Mackerras | 04f995a | 2012-08-06 00:03:28 +0000 | [diff] [blame] | 2631 | kvm_cede_exit: |
Paul Mackerras | 6af27c8 | 2015-03-28 14:21:10 +1100 | [diff] [blame] | 2632 | ld r9, HSTATE_KVM_VCPU(r13) |
| 2633 | b guest_exit_cont |
Paul Mackerras | 19ccb76 | 2011-07-23 17:42:46 +1000 | [diff] [blame] | 2634 | |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 2635 | /* Try to handle a machine check in real mode */ |
| 2636 | machine_check_realmode: |
| 2637 | mr r3, r9 /* get vcpu pointer */ |
Anton Blanchard | b1576fe | 2014-02-04 16:04:35 +1100 | [diff] [blame] | 2638 | bl kvmppc_realmode_machine_check |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 2639 | nop |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 2640 | ld r9, HSTATE_KVM_VCPU(r13) |
| 2641 | li r12, BOOK3S_INTERRUPT_MACHINE_CHECK |
Mahesh Salgaonkar | 74845bc | 2014-06-11 14:18:21 +0530 | [diff] [blame] | 2642 | /* |
| 2643 | * Deliver unhandled/fatal (e.g. UE) MCE errors to guest through |
| 2644 | * machine check interrupt (set HSRR0 to 0x200). And for handled |
| 2645 | * errors (no-fatal), just go back to guest execution with current |
| 2646 | * HSRR0 instead of exiting guest. This new approach will inject |
| 2647 | * machine check to guest for fatal error causing guest to crash. |
| 2648 | * |
| 2649 | * The old code used to return to host for unhandled errors which |
| 2650 | * was causing guest to hang with soft lockups inside guest and |
| 2651 | * makes it difficult to recover guest instance. |
Mahesh Salgaonkar | 966d713 | 2015-03-23 22:24:45 +0530 | [diff] [blame] | 2652 | * |
| 2653 | * if we receive machine check with MSR(RI=0) then deliver it to |
| 2654 | * guest as machine check causing guest to crash. |
Mahesh Salgaonkar | 74845bc | 2014-06-11 14:18:21 +0530 | [diff] [blame] | 2655 | */ |
Mahesh Salgaonkar | 74845bc | 2014-06-11 14:18:21 +0530 | [diff] [blame] | 2656 | ld r11, VCPU_MSR(r9) |
Paul Mackerras | 1c9e3d5 | 2015-11-12 16:43:48 +1100 | [diff] [blame] | 2657 | rldicl. r0, r11, 64-MSR_HV_LG, 63 /* check if it happened in HV mode */ |
| 2658 | bne mc_cont /* if so, exit to host */ |
Mahesh Salgaonkar | 966d713 | 2015-03-23 22:24:45 +0530 | [diff] [blame] | 2659 | andi. r10, r11, MSR_RI /* check for unrecoverable exception */ |
| 2660 | beq 1f /* Deliver a machine check to guest */ |
| 2661 | ld r10, VCPU_PC(r9) |
| 2662 | cmpdi r3, 0 /* Did we handle MCE ? */ |
Mahesh Salgaonkar | 74845bc | 2014-06-11 14:18:21 +0530 | [diff] [blame] | 2663 | bne 2f /* Continue guest execution. */ |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 2664 | /* If not, deliver a machine check. SRR0/1 are already set */ |
Mahesh Salgaonkar | 966d713 | 2015-03-23 22:24:45 +0530 | [diff] [blame] | 2665 | 1: li r10, BOOK3S_INTERRUPT_MACHINE_CHECK |
Michael Neuling | e4e3812 | 2014-03-25 10:47:02 +1100 | [diff] [blame] | 2666 | bl kvmppc_msr_interrupt |
Mahesh Salgaonkar | 74845bc | 2014-06-11 14:18:21 +0530 | [diff] [blame] | 2667 | 2: b fast_interrupt_c_return |
Paul Mackerras | b4072df | 2012-11-23 22:37:50 +0000 | [diff] [blame] | 2668 | |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2669 | /* |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 2670 | * Check the reason we woke from nap, and take appropriate action. |
Paul Mackerras | 1f09c3e | 2015-03-28 14:21:04 +1100 | [diff] [blame] | 2671 | * Returns (in r3): |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 2672 | * 0 if nothing needs to be done |
| 2673 | * 1 if something happened that needs to be handled by the host |
Paul Mackerras | 66feed6 | 2015-03-28 14:21:12 +1100 | [diff] [blame] | 2674 | * -1 if there was a guest wakeup (IPI or msgsnd) |
Suresh Warrier | e3c13e5 | 2016-08-19 15:35:51 +1000 | [diff] [blame] | 2675 | * -2 if we handled a PCI passthrough interrupt (returned by |
| 2676 | * kvmppc_read_intr only) |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 2677 | * |
| 2678 | * Also sets r12 to the interrupt vector for any interrupt that needs |
| 2679 | * to be handled now by the host (0x500 for external interrupt), or zero. |
Suresh Warrier | 37f55d3 | 2016-08-19 15:35:46 +1000 | [diff] [blame] | 2680 | * Modifies all volatile registers (since it may call a C function). |
| 2681 | * This routine calls kvmppc_read_intr, a C function, if an external |
| 2682 | * interrupt is pending. |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 2683 | */ |
| 2684 | kvmppc_check_wake_reason: |
| 2685 | mfspr r6, SPRN_SRR1 |
Paul Mackerras | aa31e84 | 2014-01-08 21:25:26 +1100 | [diff] [blame] | 2686 | BEGIN_FTR_SECTION |
| 2687 | rlwinm r6, r6, 45-31, 0xf /* extract wake reason field (P8) */ |
| 2688 | FTR_SECTION_ELSE |
| 2689 | rlwinm r6, r6, 45-31, 0xe /* P7 wake reason field is 3 bits */ |
| 2690 | ALT_FTR_SECTION_END_IFSET(CPU_FTR_ARCH_207S) |
| 2691 | cmpwi r6, 8 /* was it an external interrupt? */ |
Suresh Warrier | 37f55d3 | 2016-08-19 15:35:46 +1000 | [diff] [blame] | 2692 | beq 7f /* if so, see what it was */ |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 2693 | li r3, 0 |
| 2694 | li r12, 0 |
| 2695 | cmpwi r6, 6 /* was it the decrementer? */ |
| 2696 | beq 0f |
Paul Mackerras | aa31e84 | 2014-01-08 21:25:26 +1100 | [diff] [blame] | 2697 | BEGIN_FTR_SECTION |
| 2698 | cmpwi r6, 5 /* privileged doorbell? */ |
| 2699 | beq 0f |
Paul Mackerras | 5d00f66 | 2014-01-08 21:25:28 +1100 | [diff] [blame] | 2700 | cmpwi r6, 3 /* hypervisor doorbell? */ |
| 2701 | beq 3f |
Paul Mackerras | aa31e84 | 2014-01-08 21:25:26 +1100 | [diff] [blame] | 2702 | END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S) |
Mahesh Salgaonkar | fd7bacb | 2016-05-15 09:44:26 +0530 | [diff] [blame] | 2703 | cmpwi r6, 0xa /* Hypervisor maintenance ? */ |
| 2704 | beq 4f |
Paul Mackerras | e3bbbbf | 2014-01-08 21:25:25 +1100 | [diff] [blame] | 2705 | li r3, 1 /* anything else, return 1 */ |
| 2706 | 0: blr |
| 2707 | |
Paul Mackerras | 5d00f66 | 2014-01-08 21:25:28 +1100 | [diff] [blame] | 2708 | /* hypervisor doorbell */ |
| 2709 | 3: li r12, BOOK3S_INTERRUPT_H_DOORBELL |
Gautham R. Shenoy | 70aa396 | 2015-10-15 11:29:58 +0530 | [diff] [blame] | 2710 | |
| 2711 | /* |
| 2712 | * Clear the doorbell as we will invoke the handler |
| 2713 | * explicitly in the guest exit path. |
| 2714 | */ |
| 2715 | lis r6, (PPC_DBELL_SERVER << (63-36))@h |
| 2716 | PPC_MSGCLR(6) |
Paul Mackerras | 66feed6 | 2015-03-28 14:21:12 +1100 | [diff] [blame] | 2717 | /* see if it's a host IPI */ |
Paul Mackerras | 5d00f66 | 2014-01-08 21:25:28 +1100 | [diff] [blame] | 2718 | li r3, 1 |
Paul Mackerras | 66feed6 | 2015-03-28 14:21:12 +1100 | [diff] [blame] | 2719 | lbz r0, HSTATE_HOST_IPI(r13) |
| 2720 | cmpwi r0, 0 |
| 2721 | bnelr |
Gautham R. Shenoy | 70aa396 | 2015-10-15 11:29:58 +0530 | [diff] [blame] | 2722 | /* if not, return -1 */ |
Paul Mackerras | 66feed6 | 2015-03-28 14:21:12 +1100 | [diff] [blame] | 2723 | li r3, -1 |
Paul Mackerras | 5d00f66 | 2014-01-08 21:25:28 +1100 | [diff] [blame] | 2724 | blr |
| 2725 | |
Mahesh Salgaonkar | fd7bacb | 2016-05-15 09:44:26 +0530 | [diff] [blame] | 2726 | /* Woken up due to Hypervisor maintenance interrupt */ |
| 2727 | 4: li r12, BOOK3S_INTERRUPT_HMI |
| 2728 | li r3, 1 |
| 2729 | blr |
| 2730 | |
Suresh Warrier | 37f55d3 | 2016-08-19 15:35:46 +1000 | [diff] [blame] | 2731 | /* external interrupt - create a stack frame so we can call C */ |
| 2732 | 7: mflr r0 |
| 2733 | std r0, PPC_LR_STKOFF(r1) |
| 2734 | stdu r1, -PPC_MIN_STKFRM(r1) |
| 2735 | bl kvmppc_read_intr |
| 2736 | nop |
| 2737 | li r12, BOOK3S_INTERRUPT_EXTERNAL |
Suresh Warrier | f7af520 | 2016-08-19 15:35:52 +1000 | [diff] [blame] | 2738 | cmpdi r3, 1 |
| 2739 | ble 1f |
| 2740 | |
| 2741 | /* |
| 2742 | * Return code of 2 means PCI passthrough interrupt, but |
| 2743 | * we need to return back to host to complete handling the |
| 2744 | * interrupt. Trap reason is expected in r12 by guest |
| 2745 | * exit code. |
| 2746 | */ |
| 2747 | li r12, BOOK3S_INTERRUPT_HV_RM_HARD |
| 2748 | 1: |
Suresh Warrier | 37f55d3 | 2016-08-19 15:35:46 +1000 | [diff] [blame] | 2749 | ld r0, PPC_MIN_STKFRM+PPC_LR_STKOFF(r1) |
| 2750 | addi r1, r1, PPC_MIN_STKFRM |
| 2751 | mtlr r0 |
| 2752 | blr |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2753 | |
| 2754 | /* |
| 2755 | * Save away FP, VMX and VSX registers. |
| 2756 | * r3 = vcpu pointer |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2757 | * N.B. r30 and r31 are volatile across this function, |
| 2758 | * thus it is not callable from C. |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2759 | */ |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2760 | kvmppc_save_fp: |
| 2761 | mflr r30 |
| 2762 | mr r31,r3 |
Paul Mackerras | 8943633 | 2012-03-02 01:38:23 +0000 | [diff] [blame] | 2763 | mfmsr r5 |
| 2764 | ori r8,r5,MSR_FP |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2765 | #ifdef CONFIG_ALTIVEC |
| 2766 | BEGIN_FTR_SECTION |
| 2767 | oris r8,r8,MSR_VEC@h |
| 2768 | END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) |
| 2769 | #endif |
| 2770 | #ifdef CONFIG_VSX |
| 2771 | BEGIN_FTR_SECTION |
| 2772 | oris r8,r8,MSR_VSX@h |
| 2773 | END_FTR_SECTION_IFSET(CPU_FTR_VSX) |
| 2774 | #endif |
| 2775 | mtmsrd r8 |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2776 | addi r3,r3,VCPU_FPRS |
Alexander Graf | 9bf163f | 2014-06-16 14:41:15 +0200 | [diff] [blame] | 2777 | bl store_fp_state |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2778 | #ifdef CONFIG_ALTIVEC |
| 2779 | BEGIN_FTR_SECTION |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2780 | addi r3,r31,VCPU_VRS |
Alexander Graf | 9bf163f | 2014-06-16 14:41:15 +0200 | [diff] [blame] | 2781 | bl store_vr_state |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2782 | END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) |
| 2783 | #endif |
| 2784 | mfspr r6,SPRN_VRSAVE |
Paul Mackerras | e724f08 | 2014-03-13 20:02:48 +1100 | [diff] [blame] | 2785 | stw r6,VCPU_VRSAVE(r31) |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2786 | mtlr r30 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2787 | blr |
| 2788 | |
| 2789 | /* |
| 2790 | * Load up FP, VMX and VSX registers |
| 2791 | * r4 = vcpu pointer |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2792 | * N.B. r30 and r31 are volatile across this function, |
| 2793 | * thus it is not callable from C. |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2794 | */ |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2795 | kvmppc_load_fp: |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2796 | mflr r30 |
| 2797 | mr r31,r4 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2798 | mfmsr r9 |
| 2799 | ori r8,r9,MSR_FP |
| 2800 | #ifdef CONFIG_ALTIVEC |
| 2801 | BEGIN_FTR_SECTION |
| 2802 | oris r8,r8,MSR_VEC@h |
| 2803 | END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) |
| 2804 | #endif |
| 2805 | #ifdef CONFIG_VSX |
| 2806 | BEGIN_FTR_SECTION |
| 2807 | oris r8,r8,MSR_VSX@h |
| 2808 | END_FTR_SECTION_IFSET(CPU_FTR_VSX) |
| 2809 | #endif |
| 2810 | mtmsrd r8 |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2811 | addi r3,r4,VCPU_FPRS |
Alexander Graf | 9bf163f | 2014-06-16 14:41:15 +0200 | [diff] [blame] | 2812 | bl load_fp_state |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2813 | #ifdef CONFIG_ALTIVEC |
| 2814 | BEGIN_FTR_SECTION |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2815 | addi r3,r31,VCPU_VRS |
Alexander Graf | 9bf163f | 2014-06-16 14:41:15 +0200 | [diff] [blame] | 2816 | bl load_vr_state |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2817 | END_FTR_SECTION_IFSET(CPU_FTR_ALTIVEC) |
| 2818 | #endif |
Paul Mackerras | e724f08 | 2014-03-13 20:02:48 +1100 | [diff] [blame] | 2819 | lwz r7,VCPU_VRSAVE(r31) |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2820 | mtspr SPRN_VRSAVE,r7 |
Paul Mackerras | 595e4f7 | 2013-10-15 20:43:04 +1100 | [diff] [blame] | 2821 | mtlr r30 |
| 2822 | mr r4,r31 |
Paul Mackerras | de56a94 | 2011-06-29 00:21:34 +0000 | [diff] [blame] | 2823 | blr |
Paul Mackerras | 44a3add | 2013-10-04 21:45:04 +1000 | [diff] [blame] | 2824 | |
Paul Mackerras | f024ee0 | 2016-06-22 14:21:59 +1000 | [diff] [blame] | 2825 | #ifdef CONFIG_PPC_TRANSACTIONAL_MEM |
| 2826 | /* |
| 2827 | * Save transactional state and TM-related registers. |
| 2828 | * Called with r9 pointing to the vcpu struct. |
| 2829 | * This can modify all checkpointed registers, but |
| 2830 | * restores r1, r2 and r9 (vcpu pointer) before exit. |
| 2831 | */ |
| 2832 | kvmppc_save_tm: |
| 2833 | mflr r0 |
| 2834 | std r0, PPC_LR_STKOFF(r1) |
| 2835 | |
| 2836 | /* Turn on TM. */ |
| 2837 | mfmsr r8 |
| 2838 | li r0, 1 |
| 2839 | rldimi r8, r0, MSR_TM_LG, 63-MSR_TM_LG |
| 2840 | mtmsrd r8 |
| 2841 | |
| 2842 | ld r5, VCPU_MSR(r9) |
| 2843 | rldicl. r5, r5, 64 - MSR_TS_S_LG, 62 |
| 2844 | beq 1f /* TM not active in guest. */ |
| 2845 | |
| 2846 | std r1, HSTATE_HOST_R1(r13) |
| 2847 | li r3, TM_CAUSE_KVM_RESCHED |
| 2848 | |
| 2849 | /* Clear the MSR RI since r1, r13 are all going to be foobar. */ |
| 2850 | li r5, 0 |
| 2851 | mtmsrd r5, 1 |
| 2852 | |
| 2853 | /* All GPRs are volatile at this point. */ |
| 2854 | TRECLAIM(R3) |
| 2855 | |
| 2856 | /* Temporarily store r13 and r9 so we have some regs to play with */ |
| 2857 | SET_SCRATCH0(r13) |
| 2858 | GET_PACA(r13) |
| 2859 | std r9, PACATMSCRATCH(r13) |
| 2860 | ld r9, HSTATE_KVM_VCPU(r13) |
| 2861 | |
| 2862 | /* Get a few more GPRs free. */ |
| 2863 | std r29, VCPU_GPRS_TM(29)(r9) |
| 2864 | std r30, VCPU_GPRS_TM(30)(r9) |
| 2865 | std r31, VCPU_GPRS_TM(31)(r9) |
| 2866 | |
| 2867 | /* Save away PPR and DSCR soon so don't run with user values. */ |
| 2868 | mfspr r31, SPRN_PPR |
| 2869 | HMT_MEDIUM |
| 2870 | mfspr r30, SPRN_DSCR |
| 2871 | ld r29, HSTATE_DSCR(r13) |
| 2872 | mtspr SPRN_DSCR, r29 |
| 2873 | |
| 2874 | /* Save all but r9, r13 & r29-r31 */ |
| 2875 | reg = 0 |
| 2876 | .rept 29 |
| 2877 | .if (reg != 9) && (reg != 13) |
| 2878 | std reg, VCPU_GPRS_TM(reg)(r9) |
| 2879 | .endif |
| 2880 | reg = reg + 1 |
| 2881 | .endr |
| 2882 | /* ... now save r13 */ |
| 2883 | GET_SCRATCH0(r4) |
| 2884 | std r4, VCPU_GPRS_TM(13)(r9) |
| 2885 | /* ... and save r9 */ |
| 2886 | ld r4, PACATMSCRATCH(r13) |
| 2887 | std r4, VCPU_GPRS_TM(9)(r9) |
| 2888 | |
| 2889 | /* Reload stack pointer and TOC. */ |
| 2890 | ld r1, HSTATE_HOST_R1(r13) |
| 2891 | ld r2, PACATOC(r13) |
| 2892 | |
| 2893 | /* Set MSR RI now we have r1 and r13 back. */ |
| 2894 | li r5, MSR_RI |
| 2895 | mtmsrd r5, 1 |
| 2896 | |
| 2897 | /* Save away checkpinted SPRs. */ |
| 2898 | std r31, VCPU_PPR_TM(r9) |
| 2899 | std r30, VCPU_DSCR_TM(r9) |
| 2900 | mflr r5 |
| 2901 | mfcr r6 |
| 2902 | mfctr r7 |
| 2903 | mfspr r8, SPRN_AMR |
| 2904 | mfspr r10, SPRN_TAR |
Paul Mackerras | 0d808df | 2016-11-07 15:09:58 +1100 | [diff] [blame] | 2905 | mfxer r11 |
Paul Mackerras | f024ee0 | 2016-06-22 14:21:59 +1000 | [diff] [blame] | 2906 | std r5, VCPU_LR_TM(r9) |
| 2907 | stw r6, VCPU_CR_TM(r9) |
| 2908 | std r7, VCPU_CTR_TM(r9) |
| 2909 | std r8, VCPU_AMR_TM(r9) |
| 2910 | std r10, VCPU_TAR_TM(r9) |
Paul Mackerras | 0d808df | 2016-11-07 15:09:58 +1100 | [diff] [blame] | 2911 | std r11, VCPU_XER_TM(r9) |
Paul Mackerras | f024ee0 | 2016-06-22 14:21:59 +1000 | [diff] [blame] | 2912 | |
| 2913 | /* Restore r12 as trap number. */ |
| 2914 | lwz r12, VCPU_TRAP(r9) |
| 2915 | |
| 2916 | /* Save FP/VSX. */ |
| 2917 | addi r3, r9, VCPU_FPRS_TM |
| 2918 | bl store_fp_state |
| 2919 | addi r3, r9, VCPU_VRS_TM |
| 2920 | bl store_vr_state |
| 2921 | mfspr r6, SPRN_VRSAVE |
| 2922 | stw r6, VCPU_VRSAVE_TM(r9) |
| 2923 | 1: |
| 2924 | /* |
| 2925 | * We need to save these SPRs after the treclaim so that the software |
| 2926 | * error code is recorded correctly in the TEXASR. Also the user may |
| 2927 | * change these outside of a transaction, so they must always be |
| 2928 | * context switched. |
| 2929 | */ |
| 2930 | mfspr r5, SPRN_TFHAR |
| 2931 | mfspr r6, SPRN_TFIAR |
| 2932 | mfspr r7, SPRN_TEXASR |
| 2933 | std r5, VCPU_TFHAR(r9) |
| 2934 | std r6, VCPU_TFIAR(r9) |
| 2935 | std r7, VCPU_TEXASR(r9) |
| 2936 | |
| 2937 | ld r0, PPC_LR_STKOFF(r1) |
| 2938 | mtlr r0 |
| 2939 | blr |
| 2940 | |
| 2941 | /* |
| 2942 | * Restore transactional state and TM-related registers. |
| 2943 | * Called with r4 pointing to the vcpu struct. |
| 2944 | * This potentially modifies all checkpointed registers. |
| 2945 | * It restores r1, r2, r4 from the PACA. |
| 2946 | */ |
| 2947 | kvmppc_restore_tm: |
| 2948 | mflr r0 |
| 2949 | std r0, PPC_LR_STKOFF(r1) |
| 2950 | |
| 2951 | /* Turn on TM/FP/VSX/VMX so we can restore them. */ |
| 2952 | mfmsr r5 |
| 2953 | li r6, MSR_TM >> 32 |
| 2954 | sldi r6, r6, 32 |
| 2955 | or r5, r5, r6 |
| 2956 | ori r5, r5, MSR_FP |
| 2957 | oris r5, r5, (MSR_VEC | MSR_VSX)@h |
| 2958 | mtmsrd r5 |
| 2959 | |
| 2960 | /* |
| 2961 | * The user may change these outside of a transaction, so they must |
| 2962 | * always be context switched. |
| 2963 | */ |
| 2964 | ld r5, VCPU_TFHAR(r4) |
| 2965 | ld r6, VCPU_TFIAR(r4) |
| 2966 | ld r7, VCPU_TEXASR(r4) |
| 2967 | mtspr SPRN_TFHAR, r5 |
| 2968 | mtspr SPRN_TFIAR, r6 |
| 2969 | mtspr SPRN_TEXASR, r7 |
| 2970 | |
| 2971 | ld r5, VCPU_MSR(r4) |
| 2972 | rldicl. r5, r5, 64 - MSR_TS_S_LG, 62 |
| 2973 | beqlr /* TM not active in guest */ |
| 2974 | std r1, HSTATE_HOST_R1(r13) |
| 2975 | |
| 2976 | /* Make sure the failure summary is set, otherwise we'll program check |
| 2977 | * when we trechkpt. It's possible that this might have been not set |
| 2978 | * on a kvmppc_set_one_reg() call but we shouldn't let this crash the |
| 2979 | * host. |
| 2980 | */ |
| 2981 | oris r7, r7, (TEXASR_FS)@h |
| 2982 | mtspr SPRN_TEXASR, r7 |
| 2983 | |
| 2984 | /* |
| 2985 | * We need to load up the checkpointed state for the guest. |
| 2986 | * We need to do this early as it will blow away any GPRs, VSRs and |
| 2987 | * some SPRs. |
| 2988 | */ |
| 2989 | |
| 2990 | mr r31, r4 |
| 2991 | addi r3, r31, VCPU_FPRS_TM |
| 2992 | bl load_fp_state |
| 2993 | addi r3, r31, VCPU_VRS_TM |
| 2994 | bl load_vr_state |
| 2995 | mr r4, r31 |
| 2996 | lwz r7, VCPU_VRSAVE_TM(r4) |
| 2997 | mtspr SPRN_VRSAVE, r7 |
| 2998 | |
| 2999 | ld r5, VCPU_LR_TM(r4) |
| 3000 | lwz r6, VCPU_CR_TM(r4) |
| 3001 | ld r7, VCPU_CTR_TM(r4) |
| 3002 | ld r8, VCPU_AMR_TM(r4) |
| 3003 | ld r9, VCPU_TAR_TM(r4) |
Paul Mackerras | 0d808df | 2016-11-07 15:09:58 +1100 | [diff] [blame] | 3004 | ld r10, VCPU_XER_TM(r4) |
Paul Mackerras | f024ee0 | 2016-06-22 14:21:59 +1000 | [diff] [blame] | 3005 | mtlr r5 |
| 3006 | mtcr r6 |
| 3007 | mtctr r7 |
| 3008 | mtspr SPRN_AMR, r8 |
| 3009 | mtspr SPRN_TAR, r9 |
Paul Mackerras | 0d808df | 2016-11-07 15:09:58 +1100 | [diff] [blame] | 3010 | mtxer r10 |
Paul Mackerras | f024ee0 | 2016-06-22 14:21:59 +1000 | [diff] [blame] | 3011 | |
| 3012 | /* |
| 3013 | * Load up PPR and DSCR values but don't put them in the actual SPRs |
| 3014 | * till the last moment to avoid running with userspace PPR and DSCR for |
| 3015 | * too long. |
| 3016 | */ |
| 3017 | ld r29, VCPU_DSCR_TM(r4) |
| 3018 | ld r30, VCPU_PPR_TM(r4) |
| 3019 | |
| 3020 | std r2, PACATMSCRATCH(r13) /* Save TOC */ |
| 3021 | |
| 3022 | /* Clear the MSR RI since r1, r13 are all going to be foobar. */ |
| 3023 | li r5, 0 |
| 3024 | mtmsrd r5, 1 |
| 3025 | |
| 3026 | /* Load GPRs r0-r28 */ |
| 3027 | reg = 0 |
| 3028 | .rept 29 |
| 3029 | ld reg, VCPU_GPRS_TM(reg)(r31) |
| 3030 | reg = reg + 1 |
| 3031 | .endr |
| 3032 | |
| 3033 | mtspr SPRN_DSCR, r29 |
| 3034 | mtspr SPRN_PPR, r30 |
| 3035 | |
| 3036 | /* Load final GPRs */ |
| 3037 | ld 29, VCPU_GPRS_TM(29)(r31) |
| 3038 | ld 30, VCPU_GPRS_TM(30)(r31) |
| 3039 | ld 31, VCPU_GPRS_TM(31)(r31) |
| 3040 | |
| 3041 | /* TM checkpointed state is now setup. All GPRs are now volatile. */ |
| 3042 | TRECHKPT |
| 3043 | |
| 3044 | /* Now let's get back the state we need. */ |
| 3045 | HMT_MEDIUM |
| 3046 | GET_PACA(r13) |
| 3047 | ld r29, HSTATE_DSCR(r13) |
| 3048 | mtspr SPRN_DSCR, r29 |
| 3049 | ld r4, HSTATE_KVM_VCPU(r13) |
| 3050 | ld r1, HSTATE_HOST_R1(r13) |
| 3051 | ld r2, PACATMSCRATCH(r13) |
| 3052 | |
| 3053 | /* Set the MSR RI since we have our registers back. */ |
| 3054 | li r5, MSR_RI |
| 3055 | mtmsrd r5, 1 |
| 3056 | |
| 3057 | ld r0, PPC_LR_STKOFF(r1) |
| 3058 | mtlr r0 |
| 3059 | blr |
| 3060 | #endif |
| 3061 | |
Paul Mackerras | 44a3add | 2013-10-04 21:45:04 +1000 | [diff] [blame] | 3062 | /* |
| 3063 | * We come here if we get any exception or interrupt while we are |
| 3064 | * executing host real mode code while in guest MMU context. |
| 3065 | * For now just spin, but we should do something better. |
| 3066 | */ |
| 3067 | kvmppc_bad_host_intr: |
| 3068 | b . |
Michael Neuling | e4e3812 | 2014-03-25 10:47:02 +1100 | [diff] [blame] | 3069 | |
| 3070 | /* |
| 3071 | * This mimics the MSR transition on IRQ delivery. The new guest MSR is taken |
| 3072 | * from VCPU_INTR_MSR and is modified based on the required TM state changes. |
| 3073 | * r11 has the guest MSR value (in/out) |
| 3074 | * r9 has a vcpu pointer (in) |
| 3075 | * r0 is used as a scratch register |
| 3076 | */ |
| 3077 | kvmppc_msr_interrupt: |
| 3078 | rldicl r0, r11, 64 - MSR_TS_S_LG, 62 |
| 3079 | cmpwi r0, 2 /* Check if we are in transactional state.. */ |
| 3080 | ld r11, VCPU_INTR_MSR(r9) |
| 3081 | bne 1f |
| 3082 | /* ... if transactional, change to suspended */ |
| 3083 | li r0, 1 |
| 3084 | 1: rldimi r11, r0, MSR_TS_S_LG, 63 - MSR_TS_T_LG |
| 3085 | blr |
Paul Mackerras | 9bc01a9 | 2014-05-26 19:48:40 +1000 | [diff] [blame] | 3086 | |
| 3087 | /* |
| 3088 | * This works around a hardware bug on POWER8E processors, where |
| 3089 | * writing a 1 to the MMCR0[PMAO] bit doesn't generate a |
| 3090 | * performance monitor interrupt. Instead, when we need to have |
| 3091 | * an interrupt pending, we have to arrange for a counter to overflow. |
| 3092 | */ |
| 3093 | kvmppc_fix_pmao: |
| 3094 | li r3, 0 |
| 3095 | mtspr SPRN_MMCR2, r3 |
| 3096 | lis r3, (MMCR0_PMXE | MMCR0_FCECE)@h |
| 3097 | ori r3, r3, MMCR0_PMCjCE | MMCR0_C56RUN |
| 3098 | mtspr SPRN_MMCR0, r3 |
| 3099 | lis r3, 0x7fff |
| 3100 | ori r3, r3, 0xffff |
| 3101 | mtspr SPRN_PMC6, r3 |
| 3102 | isync |
| 3103 | blr |
Paul Mackerras | b6c295d | 2015-03-28 14:21:02 +1100 | [diff] [blame] | 3104 | |
| 3105 | #ifdef CONFIG_KVM_BOOK3S_HV_EXIT_TIMING |
| 3106 | /* |
| 3107 | * Start timing an activity |
| 3108 | * r3 = pointer to time accumulation struct, r4 = vcpu |
| 3109 | */ |
| 3110 | kvmhv_start_timing: |
| 3111 | ld r5, HSTATE_KVM_VCORE(r13) |
| 3112 | lbz r6, VCORE_IN_GUEST(r5) |
| 3113 | cmpwi r6, 0 |
| 3114 | beq 5f /* if in guest, need to */ |
| 3115 | ld r6, VCORE_TB_OFFSET(r5) /* subtract timebase offset */ |
| 3116 | 5: mftb r5 |
| 3117 | subf r5, r6, r5 |
| 3118 | std r3, VCPU_CUR_ACTIVITY(r4) |
| 3119 | std r5, VCPU_ACTIVITY_START(r4) |
| 3120 | blr |
| 3121 | |
| 3122 | /* |
| 3123 | * Accumulate time to one activity and start another. |
| 3124 | * r3 = pointer to new time accumulation struct, r4 = vcpu |
| 3125 | */ |
| 3126 | kvmhv_accumulate_time: |
| 3127 | ld r5, HSTATE_KVM_VCORE(r13) |
| 3128 | lbz r8, VCORE_IN_GUEST(r5) |
| 3129 | cmpwi r8, 0 |
| 3130 | beq 4f /* if in guest, need to */ |
| 3131 | ld r8, VCORE_TB_OFFSET(r5) /* subtract timebase offset */ |
| 3132 | 4: ld r5, VCPU_CUR_ACTIVITY(r4) |
| 3133 | ld r6, VCPU_ACTIVITY_START(r4) |
| 3134 | std r3, VCPU_CUR_ACTIVITY(r4) |
| 3135 | mftb r7 |
| 3136 | subf r7, r8, r7 |
| 3137 | std r7, VCPU_ACTIVITY_START(r4) |
| 3138 | cmpdi r5, 0 |
| 3139 | beqlr |
| 3140 | subf r3, r6, r7 |
| 3141 | ld r8, TAS_SEQCOUNT(r5) |
| 3142 | cmpdi r8, 0 |
| 3143 | addi r8, r8, 1 |
| 3144 | std r8, TAS_SEQCOUNT(r5) |
| 3145 | lwsync |
| 3146 | ld r7, TAS_TOTAL(r5) |
| 3147 | add r7, r7, r3 |
| 3148 | std r7, TAS_TOTAL(r5) |
| 3149 | ld r6, TAS_MIN(r5) |
| 3150 | ld r7, TAS_MAX(r5) |
| 3151 | beq 3f |
| 3152 | cmpd r3, r6 |
| 3153 | bge 1f |
| 3154 | 3: std r3, TAS_MIN(r5) |
| 3155 | 1: cmpd r3, r7 |
| 3156 | ble 2f |
| 3157 | std r3, TAS_MAX(r5) |
| 3158 | 2: lwsync |
| 3159 | addi r8, r8, 1 |
| 3160 | std r8, TAS_SEQCOUNT(r5) |
| 3161 | blr |
| 3162 | #endif |