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