Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

KVM: PPC: Book3S HV: Add missing code for transaction reclaim on guest exit

Testing by Michael Neuling revealed that commit e4e38121507a ("KVM:
PPC: Book3S HV: Add transactional memory support") is missing the code
that saves away the checkpointed state of the guest when switching to
the host. This adds that code, which was in earlier versions of the
patch but went missing somehow.

Reported-by: Michael Neuling <mikey@neuling.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>
Signed-off-by: Alexander Graf <agraf@suse.de>

authored by

Paul Mackerras and committed by
Alexander Graf
0a8eccef 1ad9f238

+104
+104
arch/powerpc/kvm/book3s_hv_rmhandlers.S
··· 1312 1312 mr r3, r9 1313 1313 bl kvmppc_save_fp 1314 1314 1315 + #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 1316 + BEGIN_FTR_SECTION 1317 + b 2f 1318 + END_FTR_SECTION_IFCLR(CPU_FTR_TM) 1319 + /* Turn on TM. */ 1320 + mfmsr r8 1321 + li r0, 1 1322 + rldimi r8, r0, MSR_TM_LG, 63-MSR_TM_LG 1323 + mtmsrd r8 1324 + 1325 + ld r5, VCPU_MSR(r9) 1326 + rldicl. r5, r5, 64 - MSR_TS_S_LG, 62 1327 + beq 1f /* TM not active in guest. */ 1328 + 1329 + li r3, TM_CAUSE_KVM_RESCHED 1330 + 1331 + /* Clear the MSR RI since r1, r13 are all going to be foobar. */ 1332 + li r5, 0 1333 + mtmsrd r5, 1 1334 + 1335 + /* All GPRs are volatile at this point. */ 1336 + TRECLAIM(R3) 1337 + 1338 + /* Temporarily store r13 and r9 so we have some regs to play with */ 1339 + SET_SCRATCH0(r13) 1340 + GET_PACA(r13) 1341 + std r9, PACATMSCRATCH(r13) 1342 + ld r9, HSTATE_KVM_VCPU(r13) 1343 + 1344 + /* Get a few more GPRs free. */ 1345 + std r29, VCPU_GPRS_TM(29)(r9) 1346 + std r30, VCPU_GPRS_TM(30)(r9) 1347 + std r31, VCPU_GPRS_TM(31)(r9) 1348 + 1349 + /* Save away PPR and DSCR soon so don't run with user values. */ 1350 + mfspr r31, SPRN_PPR 1351 + HMT_MEDIUM 1352 + mfspr r30, SPRN_DSCR 1353 + ld r29, HSTATE_DSCR(r13) 1354 + mtspr SPRN_DSCR, r29 1355 + 1356 + /* Save all but r9, r13 & r29-r31 */ 1357 + reg = 0 1358 + .rept 29 1359 + .if (reg != 9) && (reg != 13) 1360 + std reg, VCPU_GPRS_TM(reg)(r9) 1361 + .endif 1362 + reg = reg + 1 1363 + .endr 1364 + /* ... now save r13 */ 1365 + GET_SCRATCH0(r4) 1366 + std r4, VCPU_GPRS_TM(13)(r9) 1367 + /* ... and save r9 */ 1368 + ld r4, PACATMSCRATCH(r13) 1369 + std r4, VCPU_GPRS_TM(9)(r9) 1370 + 1371 + /* Reload stack pointer and TOC. */ 1372 + ld r1, HSTATE_HOST_R1(r13) 1373 + ld r2, PACATOC(r13) 1374 + 1375 + /* Set MSR RI now we have r1 and r13 back. */ 1376 + li r5, MSR_RI 1377 + mtmsrd r5, 1 1378 + 1379 + /* Save away checkpinted SPRs. */ 1380 + std r31, VCPU_PPR_TM(r9) 1381 + std r30, VCPU_DSCR_TM(r9) 1382 + mflr r5 1383 + mfcr r6 1384 + mfctr r7 1385 + mfspr r8, SPRN_AMR 1386 + mfspr r10, SPRN_TAR 1387 + std r5, VCPU_LR_TM(r9) 1388 + stw r6, VCPU_CR_TM(r9) 1389 + std r7, VCPU_CTR_TM(r9) 1390 + std r8, VCPU_AMR_TM(r9) 1391 + std r10, VCPU_TAR_TM(r9) 1392 + 1393 + /* Restore r12 as trap number. */ 1394 + lwz r12, VCPU_TRAP(r9) 1395 + 1396 + /* Save FP/VSX. */ 1397 + addi r3, r9, VCPU_FPRS_TM 1398 + bl .store_fp_state 1399 + addi r3, r9, VCPU_VRS_TM 1400 + bl .store_vr_state 1401 + mfspr r6, SPRN_VRSAVE 1402 + stw r6, VCPU_VRSAVE_TM(r9) 1403 + 1: 1404 + /* 1405 + * We need to save these SPRs after the treclaim so that the software 1406 + * error code is recorded correctly in the TEXASR. Also the user may 1407 + * change these outside of a transaction, so they must always be 1408 + * context switched. 1409 + */ 1410 + mfspr r5, SPRN_TFHAR 1411 + mfspr r6, SPRN_TFIAR 1412 + mfspr r7, SPRN_TEXASR 1413 + std r5, VCPU_TFHAR(r9) 1414 + std r6, VCPU_TFIAR(r9) 1415 + std r7, VCPU_TEXASR(r9) 1416 + 2: 1417 + #endif 1418 + 1315 1419 /* Increment yield count if they have a VPA */ 1316 1420 ld r8, VCPU_VPA(r9) /* do they have a VPA? */ 1317 1421 cmpdi r8, 0