Skip to contentSkip to conversation

Book3S MMU Notifiers, subarch unification, lazy ee

PATCH New Alexander Graf 1 participant 11 messages Aug 13, 2012

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover Book3S MMU Notifiers, subarch unification, lazy ee

This patch set does 3 things in one:

* Add (very dumb) MMU notifiers for Book3S PR mode
* Unify BookE and Book3S entry/exit paths a bit more
* Deal properly with lazy EE for Book3S (and BookE-64)

Enjoy!

Alex

Alexander Graf (10):
KVM: PPC: BookE: No duplicate request != 0 check
KVM: PPC: Use same kvmppc_prepare_to_enter code for booke and
book3s_pr
KVM: PPC: Book3s: PR: Add (dumb) MMU Notifier support
KVM: PPC: BookE: Drop redundant vcpu->mode set
KVM: PPC: Book3S: PR: Only do resched check once per exit
KVM: PPC: Exit guest context while handling exit
KVM: PPC: Book3S: PR: Indicate we're out of guest mode
KVM: PPC: Consistentify vcpu exit path
KVM: PPC: Book3S: PR: Rework irq disabling
KVM: PPC: Move kvm_guest_enter call into generic code

 arch/powerpc/include/asm/kvm_host.h   |    3 +-
 arch/powerpc/include/asm/kvm_ppc.h    |   13 +++++
 arch/powerpc/kvm/Kconfig              |    1 +
 arch/powerpc/kvm/book3s_32_mmu_host.c |    1 +
 arch/powerpc/kvm/book3s_64_mmu_host.c |    1 +
 arch/powerpc/kvm/book3s_mmu_hpte.c    |    5 --
 arch/powerpc/kvm/book3s_pr.c          |   95 ++++++++++++++++++++++----------
 arch/powerpc/kvm/book3s_rmhandlers.S  |   15 +++---
 arch/powerpc/kvm/booke.c              |   82 +++++-----------------------
 arch/powerpc/kvm/powerpc.c            |   74 +++++++++++++++++++++++++
 10 files changed, 178 insertions(+), 112 deletions(-)
#1 lore raw

PATCH 1/10 KVM: PPC: BookE: No duplicate request != 0 check

We only call kvmppc_check_requests() when vcpu->requests != 0, so drop the redundant check in the function itself

---
 arch/powerpc/kvm/booke.c |   12 +++++-------
 1 files changed, 5 insertions(+), 7 deletions(-)
arch/powerpc/kvm/booke.c +5 -7
index 00bcc57..683cbd6 100644
@@ -457,16 +457,14 @@ int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)
 
 static void kvmppc_check_requests(struct kvm_vcpu *vcpu)
 {
-	if (vcpu->requests) {
-		trace_kvm_check_requests(vcpu);
+	trace_kvm_check_requests(vcpu);
 
-		if (kvm_check_request(KVM_REQ_PENDING_TIMER, vcpu))
-			update_timer_ints(vcpu);
+	if (kvm_check_request(KVM_REQ_PENDING_TIMER, vcpu))
+		update_timer_ints(vcpu);
 #if defined(CONFIG_KVM_E500V2) || defined(CONFIG_KVM_E500MC)
-		if (kvm_check_request(KVM_REQ_TLB_FLUSH, vcpu))
-			kvmppc_core_flush_tlb(vcpu);
+	if (kvm_check_request(KVM_REQ_TLB_FLUSH, vcpu))
+		kvmppc_core_flush_tlb(vcpu);
 #endif
-	}
 }
 
 /*
Signature · 1 line
1.6.0.2
#2 lore raw

PATCH 2/10 KVM: PPC: Use same kvmppc_prepare_to_enter code for booke and book3s_pr

In reply to Alexander Graf

We need to do the same things when preparing to enter a guest for booke and book3s_pr cores. Fold the generic code into a generic function that both call.

---
 arch/powerpc/include/asm/kvm_ppc.h |    3 ++
 arch/powerpc/kvm/book3s_pr.c       |   22 ++++----------
 arch/powerpc/kvm/booke.c           |   58 +-----------------------------------
 arch/powerpc/kvm/powerpc.c         |   57 +++++++++++++++++++++++++++++++++++
 4 files changed, 67 insertions(+), 73 deletions(-)
arch/powerpc/include/asm/kvm_ppc.h +3 -0
index 88de314..59b7c87 100644
@@ -112,6 +112,7 @@ extern int kvmppc_core_emulate_mtspr(struct kvm_vcpu *vcpu, int sprn,
 				     ulong val);
 extern int kvmppc_core_emulate_mfspr(struct kvm_vcpu *vcpu, int sprn,
 				     ulong *val);
+extern void kvmppc_core_check_requests(struct kvm_vcpu *vcpu);
 
 extern int kvmppc_booke_init(void);
 extern void kvmppc_booke_exit(void);
@@ -150,6 +151,8 @@ extern int kvm_vm_ioctl_get_smmu_info(struct kvm *kvm,
 extern int kvmppc_bookehv_init(void);
 extern void kvmppc_bookehv_exit(void);
 
+extern int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu);
+
 /*
  * Cuts out inst bits with ordering according to spec.
  * That means the leftmost bit is zero. All given bits are included.
arch/powerpc/kvm/book3s_pr.c +6 -16
index 0fe4cd4..87744e0 100644
@@ -88,6 +88,10 @@ void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu)
 	kvmppc_giveup_ext(vcpu, MSR_VSX);
 }
 
+void kvmppc_core_check_requests(struct kvm_vcpu *vcpu)
+{
+}
+
 static void kvmppc_recalc_shadow_msr(struct kvm_vcpu *vcpu)
 {
 	ulong smsr = vcpu->arch.shared->msr;
@@ -817,19 +821,9 @@ program_interrupt:
 		 * again due to a host external interrupt.
 		 */
 		__hard_irq_disable();
-		if (signal_pending(current)) {
-			__hard_irq_enable();
-#ifdef EXIT_DEBUG
-			printk(KERN_EMERG "KVM: Going back to host\n");
-#endif
-			vcpu->stat.signal_exits++;
+		if (kvmppc_prepare_to_enter(vcpu)) {
 			run->exit_reason = KVM_EXIT_INTR;
 			r = -EINTR;
-		} else {
-			/* In case an interrupt came in that was triggered
-			 * from userspace (like DEC), we need to check what
-			 * to inject now! */
-			kvmppc_core_prepare_to_enter(vcpu);
 		}
 	}
 
@@ -1031,8 +1025,6 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 		goto out;
 	}
 
-	kvmppc_core_prepare_to_enter(vcpu);
-
 	/*
 	 * Interrupts could be timers for the guest which we have to inject
 	 * again, so let's postpone them until we're in the guest and if we
@@ -1040,9 +1032,7 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 	 * a host external interrupt.
 	 */
 	__hard_irq_disable();
-
-	/* No need to go into the guest when all we do is going out */
-	if (signal_pending(current)) {
+	if (kvmppc_prepare_to_enter(vcpu)) {
 		__hard_irq_enable();
 		kvm_run->exit_reason = KVM_EXIT_INTR;
 		ret = -EINTR;
arch/powerpc/kvm/booke.c +1 -57

71 lines not on this page · raw message

arch/powerpc/kvm/powerpc.c +57 -0

63 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#3 lore raw

PATCH 3/10 KVM: PPC: Book3s: PR: Add (dumb) MMU Notifier support

In reply to Alexander Graf

Now that we have very simple MMU Notifier support for e500 in place, also add the same simple support to book3s. It gets us one step closer to actual fast support.

---
 arch/powerpc/include/asm/kvm_host.h   |    3 +-
 arch/powerpc/kvm/Kconfig              |    1 +
 arch/powerpc/kvm/book3s_32_mmu_host.c |    1 +
 arch/powerpc/kvm/book3s_64_mmu_host.c |    1 +
 arch/powerpc/kvm/book3s_mmu_hpte.c    |    5 ---
 arch/powerpc/kvm/book3s_pr.c          |   47 +++++++++++++++++++++++++++++++++
 6 files changed, 51 insertions(+), 7 deletions(-)
arch/powerpc/include/asm/kvm_host.h +1 -2
index f5c289b..667813b 100644
@@ -46,8 +46,7 @@
 #define KVM_COALESCED_MMIO_PAGE_OFFSET 1
 #endif
 
-#if defined(CONFIG_KVM_BOOK3S_64_HV) || defined(CONFIG_KVM_E500V2) || \
-    defined(CONFIG_KVM_E500MC)
+#if !defined(CONFIG_KVM_440)
 #include <linux/mmu_notifier.h>
 
 #define KVM_ARCH_WANT_MMU_NOTIFIER
arch/powerpc/kvm/Kconfig +1 -0
index 40cad8c..71f0cd9 100644
@@ -36,6 +36,7 @@ config KVM_BOOK3S_64_HANDLER
 config KVM_BOOK3S_PR
 	bool
 	select KVM_MMIO
+	select MMU_NOTIFIER
 
 config KVM_BOOK3S_32
 	tristate "KVM support for PowerPC book3s_32 processors"
arch/powerpc/kvm/book3s_32_mmu_host.c +1 -0
index 837f13e..9fac010 100644
@@ -254,6 +254,7 @@ next_pteg:
 
 	kvmppc_mmu_hpte_cache_map(vcpu, pte);
 
+	kvm_release_pfn_clean(hpaddr >> PAGE_SHIFT);
 out:
 	return r;
 }
arch/powerpc/kvm/book3s_64_mmu_host.c +1 -0
index 0688b6b..6b2c80e 100644
@@ -168,6 +168,7 @@ map_again:
 
 		kvmppc_mmu_hpte_cache_map(vcpu, pte);
 	}
+	kvm_release_pfn_clean(hpaddr >> PAGE_SHIFT);
 
 out:
 	return r;
arch/powerpc/kvm/book3s_mmu_hpte.c +0 -5
index 41cb001..2c86b0d 100644
@@ -114,11 +114,6 @@ static void invalidate_pte(struct kvm_vcpu *vcpu, struct hpte_cache *pte)
 	hlist_del_init_rcu(&pte->list_vpte);
 	hlist_del_init_rcu(&pte->list_vpte_long);
 
-	if (pte->pte.may_write)
-		kvm_release_pfn_dirty(pte->pfn);
-	else
-		kvm_release_pfn_clean(pte->pfn);
-
 	spin_unlock(&vcpu3s->mmu_lock);
 
 	vcpu3s->hpte_cache_count--;
arch/powerpc/kvm/book3s_pr.c +47 -0

55 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#4 lore raw

PATCH 4/10 KVM: PPC: BookE: Drop redundant vcpu->mode set

In reply to Alexander Graf

We only need to set vcpu->mode to outside once.

---
 arch/powerpc/kvm/booke.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
arch/powerpc/kvm/booke.c +0 -2
index 4652e0b..492c343 100644
@@ -528,8 +528,6 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 #endif
 
 	kvm_guest_exit();
-	vcpu->mode = OUTSIDE_GUEST_MODE;
-	smp_wmb();
 
 out:
 	vcpu->mode = OUTSIDE_GUEST_MODE;
Signature · 1 line
1.6.0.2
#5 lore raw

PATCH 5/10 KVM: PPC: Book3S: PR: Only do resched check once per exit

In reply to Alexander Graf

Now that we use our generic exit helper, we can safely drop our previous kvm_resched that we used to trigger at the beginning of the exit handler function.

---
 arch/powerpc/kvm/book3s_pr.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/powerpc/kvm/book3s_pr.c +1 -1
index ac675ad..d39cfdc 100644
@@ -604,7 +604,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
 
 	trace_kvm_exit(exit_nr, vcpu);
 	preempt_enable();
-	kvm_resched(vcpu);
+
 	switch (exit_nr) {
 	case BOOK3S_INTERRUPT_INST_STORAGE:
 	{
Signature · 1 line
1.6.0.2
#6 lore raw

PATCH 6/10 KVM: PPC: Exit guest context while handling exit

In reply to Alexander Graf

The x86 implementation of KVM accounts for host time while processing guest exits. Do the same for us.

---
 arch/powerpc/kvm/book3s_pr.c |    2 ++
 arch/powerpc/kvm/booke.c     |    3 +++
 2 files changed, 5 insertions(+), 0 deletions(-)
arch/powerpc/kvm/book3s_pr.c +2 -0
index d39cfdc..ed9ac3f 100644
@@ -603,6 +603,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
 	__hard_irq_enable();
 
 	trace_kvm_exit(exit_nr, vcpu);
+	kvm_guest_exit();
 	preempt_enable();
 
 	switch (exit_nr) {
@@ -874,6 +875,7 @@ program_interrupt:
 		}
 	}
 
+	kvm_guest_enter();
 	trace_kvm_book3s_reenter(r, vcpu);
 
 	return r;
arch/powerpc/kvm/booke.c +3 -0
index 492c343..887c7cc 100644
@@ -650,6 +650,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
 	local_irq_enable();
 
 	trace_kvm_exit(exit_nr, vcpu);
+	kvm_guest_exit();
 
 	run->exit_reason = KVM_EXIT_UNKNOWN;
 	run->ready_for_interrupt_injection = 1;
@@ -952,6 +953,8 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
 		}
 	}
 
+	kvm_guest_enter();
+
 	return r;
 }
 
Signature · 1 line
1.6.0.2
#7 lore raw

PATCH 7/10 KVM: PPC: Book3S: PR: Indicate we're out of guest mode

In reply to Alexander Graf

When going out of guest mode, indicate that we are in vcpu->mode. That way requests from other CPUs don't needlessly need to kick us to process them, because it'll just happen next time we enter the guest.

---
 arch/powerpc/kvm/book3s_pr.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
arch/powerpc/kvm/book3s_pr.c +1 -0
index ed9ac3f..10a1c5c 100644
@@ -1154,6 +1154,7 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 #endif
 
 out:
+	vcpu->mode = OUTSIDE_GUEST_MODE;
 	preempt_enable();
 	return ret;
 }
Signature · 1 line
1.6.0.2
#8 lore raw

PATCH 8/10 KVM: PPC: Consistentify vcpu exit path

In reply to Alexander Graf

When getting out of __vcpu_run, let's be consistent about the state we return in. We want to always

* have IRQs enabled
* have called kvm_guest_exit before

---
 arch/powerpc/kvm/book3s_pr.c |    8 ++++++--
 arch/powerpc/kvm/booke.c     |   13 ++++++++-----
 2 files changed, 14 insertions(+), 7 deletions(-)
arch/powerpc/kvm/book3s_pr.c +6 -2
index 10a1c5c..3e6ad89 100644
@@ -870,12 +870,15 @@ program_interrupt:
 		 */
 		__hard_irq_disable();
 		if (kvmppc_prepare_to_enter(vcpu)) {
+			/* local_irq_enable(); */
 			run->exit_reason = KVM_EXIT_INTR;
 			r = -EINTR;
+		} else {
+			/* Going back to guest */
+			kvm_guest_enter();
 		}
 	}
 
-	kvm_guest_enter();
 	trace_kvm_book3s_reenter(r, vcpu);
 
 	return r;
@@ -1125,7 +1128,8 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 
 	ret = __kvmppc_vcpu_run(kvm_run, vcpu);
 
-	kvm_guest_exit();
+	/* No need for kvm_guest_exit. It's done in handle_exit.
+	   We also get here with interrupts enabled. */
 
 	current->thread.regs->msr = ext_msr;
 
arch/powerpc/kvm/booke.c +8 -5
index 887c7cc..aae535f 100644
@@ -481,6 +481,7 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 
 	local_irq_disable();
 	if (kvmppc_prepare_to_enter(vcpu)) {
+		local_irq_enable();
 		kvm_run->exit_reason = KVM_EXIT_INTR;
 		ret = -EINTR;
 		goto out;
@@ -512,6 +513,9 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 
 	ret = __kvmppc_vcpu_run(kvm_run, vcpu);
 
+	/* No need for kvm_guest_exit. It's done in handle_exit.
+	   We also get here with interrupts enabled. */
+
 #ifdef CONFIG_PPC_FPU
 	kvmppc_save_guest_fp(vcpu);
 
@@ -527,12 +531,9 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 	current->thread.fpexc_mode = fpexc_mode;
 #endif
 
-	kvm_guest_exit();
-
 out:
 	vcpu->mode = OUTSIDE_GUEST_MODE;
 	smp_wmb();
-	local_irq_enable();
 	return ret;
 }
 
@@ -947,14 +948,16 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
 	if (!(r & RESUME_HOST)) {
 		local_irq_disable();
 		if (kvmppc_prepare_to_enter(vcpu)) {
+			local_irq_enable();
 			run->exit_reason = KVM_EXIT_INTR;
 			r = (-EINTR << 2) | RESUME_HOST | (r & RESUME_FLAG_NV);
 			kvmppc_account_exit(vcpu, SIGNAL_EXITS);
+		} else {
+			/* Going back to guest */
+			kvm_guest_enter();
 		}
 	}
 
-	kvm_guest_enter();
-
 	return r;
 }
 
Signature · 1 line
1.6.0.2
#9 lore raw

PATCH 9/10 KVM: PPC: Book3S: PR: Rework irq disabling

In reply to Alexander Graf

Today, we disable preemption while inside guest context, because we need to expose to the world that we are not in a preemptible context. However, during that time we already have interrupts disabled, which would indicate that we are in a non-preemptible context.

The reason the checks for irqs_disabled() fail for us though is that we manually control hard IRQs and ignore all the lazy EE framework. Let's stop doing that. Instead, let's always use lazy EE to indicate when we want to disable IRQs, but do a special final switch that gets us into EE disabled, but soft enabled state. That way when we get back out of guest state, we are immediately ready to process interrupts.

This simplifies the code drastically and reduces the time that we appear as preempt disabled.

---
 arch/powerpc/include/asm/kvm_ppc.h   |   10 ++++++++++
 arch/powerpc/kvm/book3s_pr.c         |   21 +++++++--------------
 arch/powerpc/kvm/book3s_rmhandlers.S |   15 ++++++++-------
 arch/powerpc/kvm/booke.c             |    2 ++
 arch/powerpc/kvm/powerpc.c           |   14 ++++++++++++++
 5 files changed, 41 insertions(+), 21 deletions(-)
arch/powerpc/include/asm/kvm_ppc.h +10 -0
index 59b7c87..5459364 100644
@@ -234,5 +234,15 @@ static inline void kvmppc_mmu_flush_icache(pfn_t pfn)
 	}
 }
 
+/* Please call after prepare_to_enter. This function puts the lazy ee state
+   back to normal mode, without actually enabling interrupts. */
+static inline void kvmppc_lazy_ee_enable(void)
+{
+#ifdef CONFIG_PPC64
+	/* Only need to enable IRQs by hard enabling them after this */
+	local_paca->irq_happened = 0;
+	local_paca->soft_enabled = 1;
+#endif
+}
 
 #endif /* __POWERPC_KVM_PPC_H__ */
arch/powerpc/kvm/book3s_pr.c +7 -14
index 3e6ad89..203f3b2 100644
@@ -52,8 +52,6 @@ static int kvmppc_handle_ext(struct kvm_vcpu *vcpu, unsigned int exit_nr,
 #define MSR_USER32 MSR_USER
 #define MSR_USER64 MSR_USER
 #define HW_PAGE_SIZE PAGE_SIZE
-#define __hard_irq_disable local_irq_disable
-#define __hard_irq_enable local_irq_enable
 #endif
 
 void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
@@ -599,12 +597,10 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
 	run->exit_reason = KVM_EXIT_UNKNOWN;
 	run->ready_for_interrupt_injection = 1;
 
-	/* We get here with MSR.EE=0, so enable it to be a nice citizen */
-	__hard_irq_enable();
+	/* We get here with MSR.EE=1 */
 
 	trace_kvm_exit(exit_nr, vcpu);
 	kvm_guest_exit();
-	preempt_enable();
 
 	switch (exit_nr) {
 	case BOOK3S_INTERRUPT_INST_STORAGE:
@@ -856,7 +852,6 @@ program_interrupt:
 	}
 	}
 
-	preempt_disable();
 	if (!(r & RESUME_HOST)) {
 		/* To avoid clobbering exit_reason, only check for signals if
 		 * we aren't already exiting to userspace for some other
@@ -868,14 +863,15 @@ program_interrupt:
 		 * and if we really did time things so badly, then we just exit
 		 * again due to a host external interrupt.
 		 */
-		__hard_irq_disable();
+		local_irq_disable();
 		if (kvmppc_prepare_to_enter(vcpu)) {
-			/* local_irq_enable(); */
+			local_irq_enable();
 			run->exit_reason = KVM_EXIT_INTR;
 			r = -EINTR;
 		} else {
 			/* Going back to guest */
 			kvm_guest_enter();
+			kvmppc_lazy_ee_enable();
 		}
 	}
 
@@ -1068,8 +1064,6 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 #endif
 	ulong ext_msr;
 
-	preempt_disable();
-
 	/* Check if we can run the vcpu at all */
 	if (!vcpu->arch.sane) {
 		kvm_run->exit_reason = KVM_EXIT_INTERNAL_ERROR;
@@ -1083,9 +1077,9 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 	 * really did time things so badly, then we just exit again due to
 	 * a host external interrupt.
 	 */
-	__hard_irq_disable();
+	local_irq_disable();
 	if (kvmppc_prepare_to_enter(vcpu)) {
-		__hard_irq_enable();
+		local_irq_enable();
 		kvm_run->exit_reason = KVM_EXIT_INTR;
 		ret = -EINTR;
 		goto out;
@@ -1124,7 +1118,7 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 	if (vcpu->arch.shared->msr & MSR_FP)
 		kvmppc_handle_ext(vcpu, BOOK3S_INTERRUPT_FP_UNAVAIL, MSR_FP);
 
-	kvm_guest_enter();
+	kvmppc_lazy_ee_enable();
 
 	ret = __kvmppc_vcpu_run(kvm_run, vcpu);
 
@@ -1159,7 +1153,6 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 
 out:
 	vcpu->mode = OUTSIDE_GUEST_MODE;
-	preempt_enable();
 	return ret;
 }
 
arch/powerpc/kvm/book3s_rmhandlers.S +8 -7
index 9ecf6e3..b2f8258 100644
@@ -170,20 +170,21 @@ kvmppc_handler_skip_ins:
  * Call kvmppc_handler_trampoline_enter in real mode
  *
  * On entry, r4 contains the guest shadow MSR
+ * MSR.EE has to be 0 when calling this function
  */
 _GLOBAL(kvmppc_entry_trampoline)
 	mfmsr	r5
 	LOAD_REG_ADDR(r7, kvmppc_handler_trampoline_enter)
 	toreal(r7)
 
-	li	r9, MSR_RI
-	ori	r9, r9, MSR_EE
-	andc	r9, r5, r9	/* Clear EE and RI in MSR value */
 	li	r6, MSR_IR | MSR_DR
-	ori	r6, r6, MSR_EE
-	andc	r6, r5, r6	/* Clear EE, DR and IR in MSR value */
-	MTMSR_EERI(r9)		/* Clear EE and RI in MSR */
-	mtsrr0	r7		/* before we set srr0/1 */
+	andc	r6, r5, r6	/* Clear DR and IR in MSR value */
+	/*
+	 * Set EE in HOST_MSR so that it's enabled when we get into our
+	 * C exit handler function
+	 */
+	ori	r5, r5, MSR_EE
+	mtsrr0	r7
 	mtsrr1	r6
 	RFI
 
arch/powerpc/kvm/booke.c +2 -0
index aae535f..2bd190c 100644
@@ -486,6 +486,7 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 		ret = -EINTR;
 		goto out;
 	}
+	kvmppc_lazy_ee_enable();
 
 	kvm_guest_enter();
 
@@ -955,6 +956,7 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
 		} else {
 			/* Going back to guest */
 			kvm_guest_enter();
+			kvmppc_lazy_ee_enable();
 		}
 	}
 
arch/powerpc/kvm/powerpc.c +14 -0
index 87648bd..ce9c7da 100644
@@ -30,6 +30,7 @@
 #include <asm/kvm_ppc.h>
 #include <asm/tlbflush.h>
 #include <asm/cputhreads.h>
+#include <asm/irqflags.h>
 #include "timing.h"
 #include "../mm/mmu_decl.h"
 
@@ -93,6 +94,19 @@ int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu)
 			break;
 		}
 
+#ifdef CONFIG_PPC64
+		/* lazy EE magic */
+		hard_irq_disable();
+		if (lazy_irq_pending()) {
+			/* Got an interrupt in between, try again */
+			local_irq_enable();
+			local_irq_disable();
+			continue;
+		}
+
+		trace_hardirqs_on();
+#endif
+
 		/* Going into guest context! Yay! */
 		vcpu->mode = IN_GUEST_MODE;
 		smp_wmb();
Signature · 1 line
1.6.0.2
#10 lore raw

PATCH 10/10 KVM: PPC: Move kvm_guest_enter call into generic code

In reply to Alexander Graf

We need to call kvm_guest_enter in booke and book3s, so move its call to generic code.

---
 arch/powerpc/kvm/book3s_pr.c |    2 --
 arch/powerpc/kvm/booke.c     |    2 --
 arch/powerpc/kvm/powerpc.c   |    3 +++
 3 files changed, 3 insertions(+), 4 deletions(-)
arch/powerpc/kvm/book3s_pr.c +0 -2
index 203f3b2..a19799d 100644
@@ -869,8 +869,6 @@ program_interrupt:
 			run->exit_reason = KVM_EXIT_INTR;
 			r = -EINTR;
 		} else {
-			/* Going back to guest */
-			kvm_guest_enter();
 			kvmppc_lazy_ee_enable();
 		}
 	}
arch/powerpc/kvm/booke.c +0 -2
index 2bd190c..5e8dc19 100644
@@ -954,8 +954,6 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
 			r = (-EINTR << 2) | RESUME_HOST | (r & RESUME_FLAG_NV);
 			kvmppc_account_exit(vcpu, SIGNAL_EXITS);
 		} else {
-			/* Going back to guest */
-			kvm_guest_enter();
 			kvmppc_lazy_ee_enable();
 		}
 	}
arch/powerpc/kvm/powerpc.c +3 -0
index ce9c7da..add7d99 100644
@@ -101,12 +101,15 @@ int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu)
 			/* Got an interrupt in between, try again */
 			local_irq_enable();
 			local_irq_disable();
+			kvm_guest_exit();
 			continue;
 		}
 
 		trace_hardirqs_on();
 #endif
 
+		kvm_guest_enter();
+
 		/* Going into guest context! Yay! */
 		vcpu->mode = IN_GUEST_MODE;
 		smp_wmb();
Signature · 1 line
1.6.0.2