Skip to content

Commit fcd35f5

Browse files
paulusmackgregkh
authored andcommitted
KVM: PPC: Book3S HV: Save/restore host values of debug registers
commit 7ceaa6d upstream. At present, HV KVM on POWER8 and POWER9 machines loses any instruction or data breakpoint set in the host whenever a guest is run. Instruction breakpoints are currently only used by xmon, but ptrace and the perf_event subsystem can set data breakpoints as well as xmon. To fix this, we save the host values of the debug registers (CIABR, DAWR and DAWRX) before entering the guest and restore them on exit. To provide space to save them in the stack frame, we expand the stack frame allocated by kvmppc_hv_entry() from 112 to 144 bytes. [[email protected] - Adjusted stack offsets since we aren't saving POWER9-specific registers.] Fixes: b005255 ("KVM: PPC: Book3S HV: Context-switch new POWER8 SPRs", 2014-01-08) Signed-off-by: Paul Mackerras <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 17d3810 commit fcd35f5

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

arch/powerpc/kvm/book3s_hv_rmhandlers.S

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@
3636
#define NAPPING_CEDE 1
3737
#define NAPPING_NOVCPU 2
3838

39+
/* Stack frame offsets for kvmppc_hv_entry */
40+
#define SFS 112
41+
#define STACK_SLOT_TRAP (SFS-4)
42+
#define STACK_SLOT_CIABR (SFS-16)
43+
#define STACK_SLOT_DAWR (SFS-24)
44+
#define STACK_SLOT_DAWRX (SFS-32)
45+
3946
/*
4047
* Call kvmppc_hv_entry in real mode.
4148
* Must be called with interrupts hard-disabled.
@@ -274,10 +281,10 @@ kvm_novcpu_exit:
274281
bl kvmhv_accumulate_time
275282
#endif
276283
13: mr r3, r12
277-
stw r12, 112-4(r1)
284+
stw r12, STACK_SLOT_TRAP(r1)
278285
bl kvmhv_commence_exit
279286
nop
280-
lwz r12, 112-4(r1)
287+
lwz r12, STACK_SLOT_TRAP(r1)
281288
b kvmhv_switch_to_host
282289

283290
/*
@@ -489,7 +496,7 @@ kvmppc_hv_entry:
489496
*/
490497
mflr r0
491498
std r0, PPC_LR_STKOFF(r1)
492-
stdu r1, -112(r1)
499+
stdu r1, -SFS(r1)
493500

494501
/* Save R1 in the PACA */
495502
std r1, HSTATE_HOST_R1(r13)
@@ -643,6 +650,16 @@ kvmppc_got_guest:
643650
mtspr SPRN_PURR,r7
644651
mtspr SPRN_SPURR,r8
645652

653+
/* Save host values of some registers */
654+
BEGIN_FTR_SECTION
655+
mfspr r5, SPRN_CIABR
656+
mfspr r6, SPRN_DAWR
657+
mfspr r7, SPRN_DAWRX
658+
std r5, STACK_SLOT_CIABR(r1)
659+
std r6, STACK_SLOT_DAWR(r1)
660+
std r7, STACK_SLOT_DAWRX(r1)
661+
END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
662+
646663
BEGIN_FTR_SECTION
647664
/* Set partition DABR */
648665
/* Do this before re-enabling PMU to avoid P7 DABR corruption bug */
@@ -1266,8 +1283,6 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_207S)
12661283
*/
12671284
li r0, 0
12681285
mtspr SPRN_IAMR, r0
1269-
mtspr SPRN_CIABR, r0
1270-
mtspr SPRN_DAWRX, r0
12711286
mtspr SPRN_PSPB, r0
12721287
mtspr SPRN_TCSCR, r0
12731288
mtspr SPRN_WORT, r0
@@ -1426,6 +1441,16 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
14261441
slbia
14271442
ptesync
14281443

1444+
/* Restore host values of some registers */
1445+
BEGIN_FTR_SECTION
1446+
ld r5, STACK_SLOT_CIABR(r1)
1447+
ld r6, STACK_SLOT_DAWR(r1)
1448+
ld r7, STACK_SLOT_DAWRX(r1)
1449+
mtspr SPRN_CIABR, r5
1450+
mtspr SPRN_DAWR, r6
1451+
mtspr SPRN_DAWRX, r7
1452+
END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
1453+
14291454
/*
14301455
* POWER7/POWER8 guest -> host partition switch code.
14311456
* We don't have to lock against tlbies but we do
@@ -1535,8 +1560,8 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
15351560
li r0, KVM_GUEST_MODE_NONE
15361561
stb r0, HSTATE_IN_GUEST(r13)
15371562

1538-
ld r0, 112+PPC_LR_STKOFF(r1)
1539-
addi r1, r1, 112
1563+
ld r0, SFS+PPC_LR_STKOFF(r1)
1564+
addi r1, r1, SFS
15401565
mtlr r0
15411566
blr
15421567

0 commit comments

Comments
 (0)