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