[PATCH 3/5] Switch shadow/host debug registers on guest enter/exit path

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



So that we don't give any chance for host to trigger the debug event.
Also the debug ability in guest can be implemented based on this.

Signed-off-by: Liu Yu <yu.liu@xxxxxxxxxxxxx>
---
 arch/powerpc/kernel/asm-offsets.c   |    3 ++
 arch/powerpc/kvm/booke_interrupts.S |   58 +++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+), 0 deletions(-)

diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c
index 561b646..643ee15 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -379,6 +379,9 @@ int main(void)
 	DEFINE(VCPU_LAST_INST, offsetof(struct kvm_vcpu, arch.last_inst));
 	DEFINE(VCPU_FAULT_DEAR, offsetof(struct kvm_vcpu, arch.fault_dear));
 	DEFINE(VCPU_FAULT_ESR, offsetof(struct kvm_vcpu, arch.fault_esr));
+	DEFINE(VCPU_SHADOW_DBG, offsetof(struct kvm_vcpu, arch.shadow_dbg_reg));
+	DEFINE(VCPU_HOST_DBG, offsetof(struct kvm_vcpu, arch.host_dbg_reg));
+	DEFINE(VCPU_GUEST_DEBUG, offsetof(struct kvm_vcpu, guest_debug));
 #endif
 #ifdef CONFIG_44x
 	DEFINE(PGD_T_LOG2, PGD_T_LOG2);
diff --git a/arch/powerpc/kvm/booke_interrupts.S b/arch/powerpc/kvm/booke_interrupts.S
index d0c6f84..52592fe 100644
--- a/arch/powerpc/kvm/booke_interrupts.S
+++ b/arch/powerpc/kvm/booke_interrupts.S
@@ -168,6 +168,26 @@ _GLOBAL(kvmppc_resume_host)
 	stw	r9, VCPU_FAULT_ESR(r4)
 ..skip_esr:
 
+	lwz	r6, VCPU_GUEST_DEBUG(r4)
+	or.	r6, r6, r6
+	beq	..skip_host_debug
+	addi	r7, r4, VCPU_HOST_DBG - 4
+	lwzu	r9, 4(r7)
+	mtspr	SPRN_DBCR0, r9
+	lwzu	r9, 4(r7)
+	mtspr	SPRN_IAC1, r9
+	lwzu	r9, 4(r7)
+	mtspr	SPRN_IAC2, r9
+	lwzu	r9, 4(r7)
+	mtspr	SPRN_IAC3, r9
+	lwzu	r9, 4(r7)
+	mtspr	SPRN_IAC4, r9
+	lwzu	r9, 4(r7)
+	mtspr	SPRN_DAC1, r9
+	lwzu	r9, 4(r7)
+	mtspr	SPRN_DAC2, r9
+..skip_host_debug:
+
 	/* Save remaining volatile guest register state to vcpu. */
 	stw	r0, VCPU_GPR(r0)(r4)
 	stw	r1, VCPU_GPR(r1)(r4)
@@ -392,6 +412,44 @@ lightweight_exit:
 	lwz	r3, VCPU_SPRG7(r4)
 	mtspr	SPRN_SPRG7, r3
 
+	lwz	r6, VCPU_GUEST_DEBUG(r4)
+	or.	r6, r6, r6
+	beq	..skip_guest_debug
+	mfmsr	r7
+	rlwinm	r7, r7, 0, ~MSR_DE
+	mtmsr	r7
+	addi	r7, r4, VCPU_HOST_DBG - 4
+	mfspr	r8, SPRN_DBCR0
+	stwu	r8, 4(r7)
+	mfspr	r8, SPRN_IAC1
+	stwu	r8, 4(r7)
+	mfspr	r8, SPRN_IAC2
+	stwu	r8, 4(r7)
+	mfspr	r8, SPRN_IAC3
+	stwu	r8, 4(r7)
+	mfspr	r8, SPRN_IAC4
+	stwu	r8, 4(r7)
+	mfspr	r8, SPRN_DAC1
+	stwu	r8, 4(r7)
+	mfspr	r8, SPRN_DAC2
+	stwu	r8, 4(r7)
+	addi	r7, r4, VCPU_SHADOW_DBG - 4
+	lwzu	r8, 4(r7)
+	mtspr	SPRN_DBCR0, r8
+	lwzu	r8, 4(r7)
+	mtspr	SPRN_IAC1, r8
+	lwzu	r8, 4(r7)
+	mtspr	SPRN_IAC2, r8
+	lwzu	r8, 4(r7)
+	mtspr	SPRN_IAC3, r8
+	lwzu	r8, 4(r7)
+	mtspr	SPRN_IAC4, r8
+	lwzu	r8, 4(r7)
+	mtspr	SPRN_DAC1, r8
+	lwzu	r8, 4(r7)
+	mtspr	SPRN_DAC2, r8
+..skip_guest_debug:
+
 #ifdef CONFIG_KVM_EXIT_TIMING
 	/* save enter time */
 1:
-- 
1.5.4

--
To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [KVM Development]     [KVM ARM]     [KVM ia64]     [Linux Virtualization]     [Linux USB Devel]     [Linux Video]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux