public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Alexander Graf <agraf-l3A5Bk7waGM@public.gmane.org>
To: kvm-ppc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: kvm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	hollis-yUx37fBWTUITNcAmw9vGhQ@public.gmane.org
Subject: [PATCH 2/3] Improve DEC handling
Date: Mon, 21 Dec 2009 20:21:24 +0100	[thread overview]
Message-ID: <1261423285-12715-3-git-send-email-agraf@suse.de> (raw)
In-Reply-To: <1261423285-12715-1-git-send-email-agraf-l3A5Bk7waGM@public.gmane.org>

We treated the DEC interrupt like an edge based one. This is not true for
Book3s. The DEC keeps firing until mtdec is issued again and thus clears
the interrupt line.

So let's implement this logic in KVM too. This patch moves the line clearing
from the firing of the interrupt to the mtdec emulation.

This makes PPC64 guests work without AGGRESSIVE_DEC defined.

Signed-off-by: Alexander Graf <agraf-l3A5Bk7waGM@public.gmane.org>

---

V1 -> V2:

  - make DEC clearing code on mtdec book3s specific
  - rename stop -> dequeue
---
 arch/powerpc/include/asm/kvm_ppc.h |    1 +
 arch/powerpc/kvm/book3s.c          |   16 +++++++++++++++-
 arch/powerpc/kvm/booke.c           |    5 +++++
 arch/powerpc/kvm/emulate.c         |    3 +++
 4 files changed, 24 insertions(+), 1 deletions(-)

diff --git a/arch/powerpc/include/asm/kvm_ppc.h b/arch/powerpc/include/asm/kvm_ppc.h
index 269ee46..abfd0c4 100644
--- a/arch/powerpc/include/asm/kvm_ppc.h
+++ b/arch/powerpc/include/asm/kvm_ppc.h
@@ -82,6 +82,7 @@ extern void kvmppc_core_deliver_interrupts(struct kvm_vcpu *vcpu);
 extern int kvmppc_core_pending_dec(struct kvm_vcpu *vcpu);
 extern void kvmppc_core_queue_program(struct kvm_vcpu *vcpu);
 extern void kvmppc_core_queue_dec(struct kvm_vcpu *vcpu);
+extern void kvmppc_core_dequeue_dec(struct kvm_vcpu *vcpu);
 extern void kvmppc_core_queue_external(struct kvm_vcpu *vcpu,
                                        struct kvm_interrupt *irq);
 
diff --git a/arch/powerpc/kvm/book3s.c b/arch/powerpc/kvm/book3s.c
index 241795b..fd3ad6c 100644
--- a/arch/powerpc/kvm/book3s.c
+++ b/arch/powerpc/kvm/book3s.c
@@ -151,6 +151,13 @@ static int kvmppc_book3s_vec2irqprio(unsigned int vec)
 	return prio;
 }
 
+static void kvmppc_book3s_dequeue_irqprio(struct kvm_vcpu *vcpu,
+					  unsigned int vec)
+{
+	clear_bit(kvmppc_book3s_vec2irqprio(vec),
+		  &vcpu->arch.pending_exceptions);
+}
+
 void kvmppc_book3s_queue_irqprio(struct kvm_vcpu *vcpu, unsigned int vec)
 {
 	vcpu->stat.queue_intr++;
@@ -178,6 +185,11 @@ int kvmppc_core_pending_dec(struct kvm_vcpu *vcpu)
 	return test_bit(BOOK3S_INTERRUPT_DECREMENTER >> 7, &vcpu->arch.pending_exceptions);
 }
 
+void kvmppc_core_dequeue_dec(struct kvm_vcpu *vcpu)
+{
+	kvmppc_book3s_dequeue_irqprio(vcpu, BOOK3S_INTERRUPT_DECREMENTER);
+}
+
 void kvmppc_core_queue_external(struct kvm_vcpu *vcpu,
                                 struct kvm_interrupt *irq)
 {
@@ -275,7 +287,9 @@ void kvmppc_core_deliver_interrupts(struct kvm_vcpu *vcpu)
 #endif
 	priority = __ffs(*pending);
 	while (priority <= (sizeof(unsigned int) * 8)) {
-		if (kvmppc_book3s_irqprio_deliver(vcpu, priority)) {
+		if (kvmppc_book3s_irqprio_deliver(vcpu, priority) &&
+		    (priority != BOOK3S_IRQPRIO_DECREMENTER)) {
+			/* DEC interrupts get cleared by mtdec */
 			clear_bit(priority, &vcpu->arch.pending_exceptions);
 			break;
 		}
diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c
index 06f5a9e..d8b6342 100644
--- a/arch/powerpc/kvm/booke.c
+++ b/arch/powerpc/kvm/booke.c
@@ -97,6 +97,11 @@ int kvmppc_core_pending_dec(struct kvm_vcpu *vcpu)
 	return test_bit(BOOKE_IRQPRIO_DECREMENTER, &vcpu->arch.pending_exceptions);
 }
 
+void kvmppc_core_dequeue_dec(struct kvm_vcpu *vcpu)
+{
+	clear_bit(BOOKE_IRQPRIO_DECREMENTER, &vcpu->arch.pending_exceptions);
+}
+
 void kvmppc_core_queue_external(struct kvm_vcpu *vcpu,
                                 struct kvm_interrupt *irq)
 {
diff --git a/arch/powerpc/kvm/emulate.c b/arch/powerpc/kvm/emulate.c
index 4a9ac66..303457b 100644
--- a/arch/powerpc/kvm/emulate.c
+++ b/arch/powerpc/kvm/emulate.c
@@ -83,6 +83,9 @@ void kvmppc_emulate_dec(struct kvm_vcpu *vcpu)
 
 	pr_debug("mtDEC: %x\n", vcpu->arch.dec);
 #ifdef CONFIG_PPC64
+	/* mtdec lowers the interrupt line when positive. */
+	kvmppc_core_dequeue_dec(vcpu);
+
 	/* POWER4+ triggers a dec interrupt if the value is < 0 */
 	if (vcpu->arch.dec & 0x80000000) {
 		hrtimer_try_to_cancel(&vcpu->arch.dec_timer);
-- 
1.6.0.2

  parent reply	other threads:[~2009-12-21 19:21 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-21 19:21 [PATCH 0/3] Improve Decrementor Implementation v2 Alexander Graf
2009-12-21 23:21 ` Hollis Blanchard
     [not found] ` <1261423285-12715-1-git-send-email-agraf-l3A5Bk7waGM@public.gmane.org>
2009-12-21 19:21   ` [PATCH 1/3] Move vector to irqprio resolving to separate function Alexander Graf
2009-12-21 19:21   ` Alexander Graf [this message]
2009-12-21 19:21   ` [PATCH 3/3] Remove AGGRESSIVE_DEC Alexander Graf
2009-12-22 10:04   ` [PATCH 0/3] Improve Decrementor Implementation v2 Avi Kivity
  -- strict thread matches above, loose matches on Subject: below --
2009-12-21 14:22 [PATCH 0/3] Improve Decrementor Implementation Alexander Graf
2009-12-21 14:22 ` [PATCH 2/3] Improve DEC handling Alexander Graf
     [not found] ` <1261405373-8008-3-git-send-email-agraf@suse.de>
     [not found]   ` <1261405373-8008-3-git-send-email-agraf-l3A5Bk7waGM@public.gmane.org>
2009-12-21 18:13     ` Hollis Blanchard
     [not found]       ` <fb412d760912211013w265d3d30i99498ab136a15e00-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-12-21 18:17         ` Hollis Blanchard
     [not found]           ` <fb412d760912211017i3f47fce2oc3b67c9c5c645b6-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2009-12-21 18:20             ` Alexander Graf
     [not found]               ` <4B2FBC74.3080705-l3A5Bk7waGM@public.gmane.org>
2009-12-21 19:04                 ` Hollis Blanchard
2009-12-21 18:19         ` 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=1261423285-12715-3-git-send-email-agraf@suse.de \
    --to=agraf-l3a5bk7wagm@public.gmane.org \
    --cc=hollis-yUx37fBWTUITNcAmw9vGhQ@public.gmane.org \
    --cc=kvm-ppc-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=kvm-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    /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