Skip to content

Commit 7ceaa6d

Browse files
committed
KVM: PPC: Book3S HV: Save/restore host values of debug registers
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. Fixes: b005255 ("KVM: PPC: Book3S HV: Context-switch new POWER8 SPRs", 2014-01-08) Cc: [email protected] # v3.14+ Signed-off-by: Paul Mackerras <[email protected]>
1 parent 46a704f commit 7ceaa6d

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

arch/powerpc/kvm/book3s_hv_rmhandlers.S

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ END_FTR_SECTION_IFCLR(CPU_FTR_ARCH_300)
4444
#define NAPPING_CEDE 1
4545
#define NAPPING_NOVCPU 2
4646

47+
/* Stack frame offsets for kvmppc_hv_entry */
48+
#define SFS 144
49+
#define STACK_SLOT_TRAP (SFS-4)
50+
#define STACK_SLOT_TID (SFS-16)
51+
#define STACK_SLOT_PSSCR (SFS-24)
52+
#define STACK_SLOT_PID (SFS-32)
53+
#define STACK_SLOT_IAMR (SFS-40)
54+
#define STACK_SLOT_CIABR (SFS-48)
55+
#define STACK_SLOT_DAWR (SFS-56)
56+
#define STACK_SLOT_DAWRX (SFS-64)
57+
4758
/*
4859
* Call kvmppc_hv_entry in real mode.
4960
* Must be called with interrupts hard-disabled.
@@ -328,10 +339,10 @@ kvm_novcpu_exit:
328339
bl kvmhv_accumulate_time
329340
#endif
330341
13: mr r3, r12
331-
stw r12, 112-4(r1)
342+
stw r12, STACK_SLOT_TRAP(r1)
332343
bl kvmhv_commence_exit
333344
nop
334-
lwz r12, 112-4(r1)
345+
lwz r12, STACK_SLOT_TRAP(r1)
335346
b kvmhv_switch_to_host
336347

337348
/*
@@ -554,12 +565,6 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
554565
* *
555566
*****************************************************************************/
556567

557-
/* Stack frame offsets */
558-
#define STACK_SLOT_TID (112-16)
559-
#define STACK_SLOT_PSSCR (112-24)
560-
#define STACK_SLOT_PID (112-32)
561-
#define STACK_SLOT_IAMR (112-40)
562-
563568
.global kvmppc_hv_entry
564569
kvmppc_hv_entry:
565570

@@ -575,7 +580,7 @@ kvmppc_hv_entry:
575580
*/
576581
mflr r0
577582
std r0, PPC_LR_STKOFF(r1)
578-
stdu r1, -112(r1)
583+
stdu r1, -SFS(r1)
579584

580585
/* Save R1 in the PACA */
581586
std r1, HSTATE_HOST_R1(r13)
@@ -765,6 +770,14 @@ BEGIN_FTR_SECTION
765770
std r7, STACK_SLOT_PID(r1)
766771
std r8, STACK_SLOT_IAMR(r1)
767772
END_FTR_SECTION_IFSET(CPU_FTR_ARCH_300)
773+
BEGIN_FTR_SECTION
774+
mfspr r5, SPRN_CIABR
775+
mfspr r6, SPRN_DAWR
776+
mfspr r7, SPRN_DAWRX
777+
std r5, STACK_SLOT_CIABR(r1)
778+
std r6, STACK_SLOT_DAWR(r1)
779+
std r7, STACK_SLOT_DAWRX(r1)
780+
END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
768781

769782
BEGIN_FTR_SECTION
770783
/* Set partition DABR */
@@ -1518,8 +1531,6 @@ ALT_FTR_SECTION_END_IFCLR(CPU_FTR_ARCH_300)
15181531
* set by the guest could disrupt the host.
15191532
*/
15201533
li r0, 0
1521-
mtspr SPRN_CIABR, r0
1522-
mtspr SPRN_DAWRX, r0
15231534
mtspr SPRN_PSPB, r0
15241535
mtspr SPRN_WORT, r0
15251536
BEGIN_FTR_SECTION
@@ -1684,6 +1695,14 @@ END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
16841695
ptesync
16851696

16861697
/* Restore host values of some registers */
1698+
BEGIN_FTR_SECTION
1699+
ld r5, STACK_SLOT_CIABR(r1)
1700+
ld r6, STACK_SLOT_DAWR(r1)
1701+
ld r7, STACK_SLOT_DAWRX(r1)
1702+
mtspr SPRN_CIABR, r5
1703+
mtspr SPRN_DAWR, r6
1704+
mtspr SPRN_DAWRX, r7
1705+
END_FTR_SECTION_IFSET(CPU_FTR_ARCH_207S)
16871706
BEGIN_FTR_SECTION
16881707
ld r5, STACK_SLOT_TID(r1)
16891708
ld r6, STACK_SLOT_PSSCR(r1)
@@ -1836,8 +1855,8 @@ END_MMU_FTR_SECTION_IFSET(MMU_FTR_TYPE_RADIX)
18361855
li r0, KVM_GUEST_MODE_NONE
18371856
stb r0, HSTATE_IN_GUEST(r13)
18381857

1839-
ld r0, 112+PPC_LR_STKOFF(r1)
1840-
addi r1, r1, 112
1858+
ld r0, SFS+PPC_LR_STKOFF(r1)
1859+
addi r1, r1, SFS
18411860
mtlr r0
18421861
blr
18431862

0 commit comments

Comments
 (0)