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