linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Graf <agraf@suse.de>
To: kvm-ppc@vger.kernel.org
Cc: Scott Wood <scottwood@freescale.com>,
	linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org
Subject: [PATCH 24/38] KVM: PPC: booke: rework rescheduling checks
Date: Wed, 29 Feb 2012 01:09:52 +0100	[thread overview]
Message-ID: <1330474206-14794-25-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1330474206-14794-1-git-send-email-agraf@suse.de>

Instead of checking whether we should reschedule only when we exited
due to an interrupt, let's always check before entering the guest back
again. This gets the target more in line with the other archs.

Also while at it, generalize the whole thing so that eventually we could
have a single kvmppc_prepare_to_enter function for all ppc targets that
does signal and reschedule checking for us.

Signed-off-by: Alexander Graf <agraf@suse.de>

---

v2 -> v3:

  - check for signals earlier
---
 arch/powerpc/include/asm/kvm_ppc.h |    2 +-
 arch/powerpc/kvm/book3s.c          |    4 +-
 arch/powerpc/kvm/booke.c           |   72 +++++++++++++++++++++++++-----------
 3 files changed, 54 insertions(+), 24 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_ppc.h b/arch/powerpc/include/asm/kvm_ppc.h
index e709975..7f0a3da 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -95,7 +95,7 @@ extern int kvmppc_core_vcpu_translate(struct kvm_vcpu *vcpu,
 extern void kvmppc_core_vcpu_load(struct kvm_vcpu *vcpu, int cpu);
 extern void kvmppc_core_vcpu_put(struct kvm_vcpu *vcpu);
 
-extern void kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu);
+extern int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu);
 extern int kvmppc_core_pending_dec(struct kvm_vcpu *vcpu);
 extern void kvmppc_core_queue_program(struct kvm_vcpu *vcpu, ulong flags);
 extern void kvmppc_core_queue_dec(struct kvm_vcpu *vcpu);
diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index 7d54f4e..c8ead7b 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -258,7 +258,7 @@ static bool clear_irqprio(struct kvm_vcpu *vcpu, unsigned int priority)
 	return true;
 }
 
-void kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)
+int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)
 {
 	unsigned long *pending = &vcpu->arch.pending_exceptions;
 	unsigned long old_pending = vcpu->arch.pending_exceptions;
@@ -283,6 +283,8 @@ void kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)
 
 	/* Tell the guest about our interrupt status */
 	kvmppc_update_int_pending(vcpu, *pending, old_pending);
+
+	return 0;
 }
 
 pfn_t kvmppc_gfn_to_pfn(struct kvm_vcpu *vcpu, gfn_t gfn)
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 9979be1..3da0e42 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -439,8 +439,9 @@ static void kvmppc_core_check_exceptions(struct kvm_vcpu *vcpu)
 }
 
 /* Check pending exceptions and deliver one, if possible. */
-void kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)
+int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)
 {
+	int r = 0;
 	WARN_ON_ONCE(!irqs_disabled());
 
 	kvmppc_core_check_exceptions(vcpu);
@@ -451,8 +452,46 @@ void kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)
 		local_irq_disable();
 
 		kvmppc_set_exit_type(vcpu, EMULATED_MTMSRWE_EXITS);
-		kvmppc_core_check_exceptions(vcpu);
+		r = 1;
 	};
+
+	return r;
+}
+
+/*
+ * Common checks before entering the guest world.  Call with interrupts
+ * disabled.
+ *
+ * returns !0 if a signal is pending and check_signal is true
+ */
+static int kvmppc_prepare_to_enter(struct kvm_vcpu *vcpu, bool check_signal)
+{
+	int r = 0;
+
+	WARN_ON_ONCE(!irqs_disabled());
+	while (true) {
+		if (need_resched()) {
+			local_irq_enable();
+			cond_resched();
+			local_irq_disable();
+			continue;
+		}
+
+		if (check_signal && signal_pending(current)) {
+			r = 1;
+			break;
+		}
+
+		if (kvmppc_core_prepare_to_enter(vcpu)) {
+			/* interrupts got enabled in between, so we
+			   are back at square 1 */
+			continue;
+		}
+
+		break;
+	}
+
+	return r;
 }
 
 int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
@@ -470,10 +509,7 @@ int kvmppc_vcpu_run(struct kvm_run *kvm_run, struct kvm_vcpu *vcpu)
 	}
 
 	local_irq_disable();
-
-	kvmppc_core_prepare_to_enter(vcpu);
-
-	if (signal_pending(current)) {
+	if (kvmppc_prepare_to_enter(vcpu, true)) {
 		kvm_run->exit_reason = KVM_EXIT_INTR;
 		ret = -EINTR;
 		goto out;
@@ -598,25 +634,21 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
 
 	switch (exit_nr) {
 	case BOOKE_INTERRUPT_MACHINE_CHECK:
-		kvm_resched(vcpu);
 		r = RESUME_GUEST;
 		break;
 
 	case BOOKE_INTERRUPT_EXTERNAL:
 		kvmppc_account_exit(vcpu, EXT_INTR_EXITS);
-		kvm_resched(vcpu);
 		r = RESUME_GUEST;
 		break;
 
 	case BOOKE_INTERRUPT_DECREMENTER:
 		kvmppc_account_exit(vcpu, DEC_EXITS);
-		kvm_resched(vcpu);
 		r = RESUME_GUEST;
 		break;
 
 	case BOOKE_INTERRUPT_DOORBELL:
 		kvmppc_account_exit(vcpu, DBELL_EXITS);
-		kvm_resched(vcpu);
 		r = RESUME_GUEST;
 		break;
 
@@ -865,19 +897,15 @@ int kvmppc_handle_exit(struct kvm_run *run, struct kvm_vcpu *vcpu,
 		BUG();
 	}
 
+	/*
+	 * To avoid clobbering exit_reason, only check for signals if we
+	 * aren't already exiting to userspace for some other reason.
+	 */
 	local_irq_disable();
-
-	kvmppc_core_prepare_to_enter(vcpu);
-
-	if (!(r & RESUME_HOST)) {
-		/* To avoid clobbering exit_reason, only check for signals if
-		 * we aren't already exiting to userspace for some other
-		 * reason. */
-		if (signal_pending(current)) {
-			run->exit_reason = KVM_EXIT_INTR;
-			r = (-EINTR << 2) | RESUME_HOST | (r & RESUME_FLAG_NV);
-			kvmppc_account_exit(vcpu, SIGNAL_EXITS);
-		}
+	if (kvmppc_prepare_to_enter(vcpu, !(r & RESUME_HOST))) {
+		run->exit_reason = KVM_EXIT_INTR;
+		r = (-EINTR << 2) | RESUME_HOST | (r & RESUME_FLAG_NV);
+		kvmppc_account_exit(vcpu, SIGNAL_EXITS);
 	}
 
 	return r;
-- 
1.6.0.2

  parent reply	other threads:[~2012-02-29  0:10 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-29  0:09 [PATCH 00/38] KVM: PPC: e500mc support v3 Alexander Graf
2012-02-29  0:09 ` [PATCH 01/38] powerpc/booke: Set CPU_FTR_DEBUG_LVL_EXC on 32-bit Alexander Graf
2012-02-29  0:09 ` [PATCH 02/38] powerpc/e500: split CPU_FTRS_ALWAYS/CPU_FTRS_POSSIBLE Alexander Graf
2012-02-29  0:09 ` [PATCH 03/38] KVM: PPC: factor out lpid allocator from book3s_64_mmu_hv Alexander Graf
2012-02-29  0:09 ` [PATCH 04/38] KVM: PPC: booke: add booke-level vcpu load/put Alexander Graf
2012-02-29  0:09 ` [PATCH 05/38] KVM: PPC: booke: Move vm core init/destroy out of booke.c Alexander Graf
2012-02-29  0:09 ` [PATCH 06/38] KVM: PPC: e500: rename e500_tlb.h to e500.h Alexander Graf
2012-02-29  0:09 ` [PATCH 07/38] KVM: PPC: e500: merge <asm/kvm_e500.h> into arch/powerpc/kvm/e500.h Alexander Graf
2012-02-29  0:09 ` [PATCH 08/38] KVM: PPC: e500: clean up arch/powerpc/kvm/e500.h Alexander Graf
2012-02-29  0:09 ` [PATCH 09/38] KVM: PPC: e500: refactor core-specific TLB code Alexander Graf
2012-02-29  0:09 ` [PATCH 10/38] KVM: PPC: e500: Track TLB1 entries with a bitmap Alexander Graf
2012-02-29  0:09 ` [PATCH 11/38] KVM: PPC: e500: emulate tlbilx Alexander Graf
2012-02-29  0:09 ` [PATCH 12/38] powerpc/booke: Provide exception macros with interrupt name Alexander Graf
2012-03-21 18:04   ` Kumar Gala
2012-03-21 18:19     ` Scott Wood
2012-03-21 20:20       ` Kumar Gala
2012-02-29  0:09 ` [PATCH 13/38] KVM: PPC: booke: category E.HV (GS-mode) support Alexander Graf
2012-03-05  9:04   ` Bhushan Bharat-R65777
2012-03-05  9:57     ` tiejun.chen
2012-02-29  0:09 ` [PATCH 14/38] KVM: PPC: booke: standard PPC floating point support Alexander Graf
2012-02-29  0:09 ` [PATCH 15/38] KVM: PPC: e500mc support Alexander Graf
2012-02-29  0:09 ` [PATCH 16/38] KVM: PPC: e500mc: Add doorbell emulation support Alexander Graf
2012-02-29  0:09 ` [PATCH 17/38] KVM: PPC: e500mc: implicitly set MSR_GS Alexander Graf
2012-02-29  0:09 ` [PATCH 18/38] KVM: PPC: e500mc: Move r1/r2 restoration very early Alexander Graf
2012-02-29  0:09 ` [PATCH 19/38] KVM: PPC: e500mc: add load inst fixup Alexander Graf
2012-03-08 22:36   ` Marcelo Tosatti
2012-03-12 19:39   ` Alexander Graf
2012-02-29  0:09 ` [PATCH 20/38] KVM: PPC: rename CONFIG_KVM_E500 -> CONFIG_KVM_E500V2 Alexander Graf
2012-02-29  0:09 ` [PATCH 21/38] KVM: PPC: make e500v2 kvm and e500mc cpu mutually exclusive Alexander Graf
2012-02-29  0:09 ` [PATCH 22/38] KVM: PPC: booke: remove leftover debugging Alexander Graf
2012-02-29  0:09 ` [PATCH 23/38] KVM: PPC: booke: deliver program int on emulation failure Alexander Graf
2012-02-29  0:09 ` Alexander Graf [this message]
2012-02-29  0:09 ` [PATCH 25/38] KVM: PPC: booke: BOOKE_IRQPRIO_MAX is n+1 Alexander Graf
2012-02-29  0:09 ` [PATCH 26/38] KVM: PPC: bookehv: fix exit timing Alexander Graf
2012-02-29  0:09 ` [PATCH 27/38] KVM: PPC: bookehv: remove negation for CONFIG_64BIT Alexander Graf
2012-02-29  0:09 ` [PATCH 28/38] KVM: PPC: bookehv: remove SET_VCPU Alexander Graf
2012-02-29  0:09 ` [PATCH 29/38] KVM: PPC: bookehv: disable MAS register updates early Alexander Graf
2012-02-29  0:09 ` [PATCH 30/38] KVM: PPC: bookehv: add comment about shadow_msr Alexander Graf
2012-02-29  0:09 ` [PATCH 31/38] KVM: PPC: booke: Readd debug abort code for machine check Alexander Graf
2012-02-29  0:10 ` [PATCH 32/38] KVM: PPC: booke: add GS documentation for program interrupt Alexander Graf
2012-02-29  0:10 ` [PATCH 33/38] KVM: PPC: bookehv: remove unused code Alexander Graf
2012-02-29  0:10 ` [PATCH 34/38] KVM: PPC: e500: fix typo in tlb code Alexander Graf
2012-02-29  0:10 ` [PATCH 35/38] KVM: PPC: booke: Support perfmon interrupts Alexander Graf
2012-02-29  0:10 ` [PATCH 36/38] KVM: PPC: booke: expose good state on irq reinject Alexander Graf
2012-02-29  0:10 ` [PATCH 37/38] KVM: PPC: booke: Reinject performance monitor interrupts Alexander Graf
2012-02-29  0:10 ` [PATCH 38/38] KVM: PPC: Booke: only prepare to enter when we enter Alexander Graf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1330474206-14794-25-git-send-email-agraf@suse.de \
    --to=agraf@suse.de \
    --cc=kvm-ppc@vger.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=scottwood@freescale.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).