diff mbox

[1/4,v2] Introduce a common kvm requests handler

Message ID 1344496676-32426-1-git-send-email-Bharat.Bhushan@freescale.com (mailing list archive)
State New, archived
Headers show

Commit Message

Bharat Bhushan Aug. 9, 2012, 7:17 a.m. UTC
Added a common requests handler which is called before returning to guest.
This returns non zero value when some request demands exit to userspace.

Signed-off-by: Bharat Bhushan <bharat.bhushan@freescale.com>
---
v2:
 - checkpatch error removed

 arch/powerpc/kvm/booke.c |   46 ++++++++++++++++++++++++++++++++++------------
 1 files changed, 34 insertions(+), 12 deletions(-)
diff mbox

Patch

diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index d25a097..0e51102 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -412,18 +412,30 @@  static void update_timer_ints(struct kvm_vcpu *vcpu)
 		kvmppc_core_dequeue_dec(vcpu);
 }
 
+/*
+ * This function handle all requests when returning to guest. This return
+ * non zero value when some request demands exit to userspace.
+ */
+static int kvmppc_handle_requests(struct kvm_vcpu *vcpu)
+{
+	int ret = 0;
+
+	if (!vcpu->requests)
+		return 0;
+
+	if (kvm_check_request(KVM_REQ_PENDING_TIMER, vcpu)) {
+		smp_mb();
+		update_timer_ints(vcpu);
+	}
+
+	return ret;
+}
+
 static void kvmppc_core_check_exceptions(struct kvm_vcpu *vcpu)
 {
 	unsigned long *pending = &vcpu->arch.pending_exceptions;
 	unsigned int priority;
 
-	if (vcpu->requests) {
-		if (kvm_check_request(KVM_REQ_PENDING_TIMER, vcpu)) {
-			smp_mb();
-			update_timer_ints(vcpu);
-		}
-	}
-
 	priority = __ffs(*pending);
 	while (priority < BOOKE_IRQPRIO_MAX) {
 		if (kvmppc_booke_irqprio_deliver(vcpu, priority))
@@ -479,10 +491,15 @@  static int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu)
 		}
 
 		if (signal_pending(current)) {
+			vcpu->run->exit_reason = KVM_EXIT_INTR;
 			r = 1;
 			break;
 		}
 
+		r = kvmppc_handle_requests(vcpu);
+		if (r)
+			break;
+
 		if (kvmppc_core_prepare_to_enter(vcpu)) {
 			/* interrupts got enabled in between, so we
 			   are back at square 1 */
@@ -511,8 +528,10 @@  int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 
 	local_irq_disable();
 	if (kvmppc_prepare_to_enter(vcpu)) {
-		kvm_run->exit_reason = KVM_EXIT_INTR;
-		ret = -EINTR;
+		if (kvm_run->exit_reason == KVM_EXIT_INTR)
+			ret = -EINTR;
+		else
+			ret = 0;
 		goto out;
 	}
 
@@ -972,9 +991,12 @@  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)) {
-			run->exit_reason = KVM_EXIT_INTR;
-			r = (-EINTR << 2) | RESUME_HOST | (r & RESUME_FLAG_NV);
-			kvmppc_account_exit(vcpu, SIGNAL_EXITS);
+			if (run->exit_reason == KVM_EXIT_INTR) {
+				r = (-EINTR << 2) | RESUME_HOST |
+				     (r & RESUME_FLAG_NV);
+				kvmppc_account_exit(vcpu, SIGNAL_EXITS);
+			} else
+				r = RESUME_HOST | (r & RESUME_FLAG_NV);
 		}
 	}