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