[PATCH 2/4] kvmppc/booke: switch shadow/host debug registers on guest enter/exit path

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

 



This provide a precise way to avoid confounding settings of guest and host.
Also the guest hardware emulation about debug 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 957ceb7..67e978d 100644
--- a/arch/powerpc/kernel/asm-offsets.c
+++ b/arch/powerpc/kernel/asm-offsets.c
@@ -425,6 +425,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));
 
 	/* book3s_64 */
 #ifdef CONFIG_PPC64
diff --git a/arch/powerpc/kvm/booke_interrupts.S b/arch/powerpc/kvm/booke_interrupts.S
index 380a78c..644ff1d 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_load_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_load_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_SPRG7W, r3
 
+	lwz	r6, VCPU_GUEST_DEBUG(r4)
+	or.	r6, r6, r6
+	beq	..skip_load_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_load_guest_debug:
+
 #ifdef CONFIG_KVM_EXIT_TIMING
 	/* save enter time */
 1:
-- 
1.6.4

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

[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux