All of lore.kernel.org
 help / color / mirror / Atom feed
From: c.dall@virtualopensystems.com (Christoffer Dall)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v4 12/13] ARM: KVM: vgic: reduce the number of vcpu kick
Date: Sat, 10 Nov 2012 16:45:39 +0100	[thread overview]
Message-ID: <20121110154539.3061.82553.stgit@chazy-air> (raw)
In-Reply-To: <20121110154358.3061.16338.stgit@chazy-air>

From: Marc Zyngier <marc.zyngier@arm.com>

If we have level interrupts already programmed to fire on a vcpu,
there is no reason to kick it after injecting a new interrupt,
as we're guaranteed that we'll exit when the level interrupt will
be EOId (VGIC_LR_EOI is set).

The exit will force a reload of the VGIC, injecting the new interrupts.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <c.dall@virtualopensystems.com>
---
 arch/arm/include/asm/kvm_vgic.h |   10 ++++++++++
 arch/arm/kvm/arm.c              |   10 +++++++++-
 arch/arm/kvm/vgic.c             |   10 ++++++++--
 3 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/arch/arm/include/asm/kvm_vgic.h b/arch/arm/include/asm/kvm_vgic.h
index a8e7a93..7d2662c 100644
--- a/arch/arm/include/asm/kvm_vgic.h
+++ b/arch/arm/include/asm/kvm_vgic.h
@@ -215,6 +215,9 @@ struct vgic_cpu {
 	u32		vgic_elrsr[2];	/* Saved only */
 	u32		vgic_apr;
 	u32		vgic_lr[64];	/* A15 has only 4... */
+
+	/* Number of level-triggered interrupt in progress */
+	atomic_t	irq_active_count;
 #endif
 };
 
@@ -254,6 +257,8 @@ bool vgic_handle_mmio(struct kvm_vcpu *vcpu, struct kvm_run *run,
 
 #define irqchip_in_kernel(k)	(!!((k)->arch.vgic.vctrl_base))
 #define vgic_initialized(k)	((k)->arch.vgic.ready)
+#define vgic_active_irq(v)	(atomic_read(&(v)->arch.vgic_cpu.irq_active_count) == 0)
+
 #else
 static inline int kvm_vgic_hyp_init(void)
 {
@@ -305,6 +310,11 @@ static inline bool vgic_initialized(struct kvm *kvm)
 {
 	return true;
 }
+
+static inline int vgic_active_irq(struct kvm_vcpu *vcpu)
+{
+	return 0;
+}
 #endif
 
 #endif
diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index a633d9d..1716f12 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -94,7 +94,15 @@ int kvm_arch_hardware_enable(void *garbage)
 
 int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu)
 {
-	return kvm_vcpu_exiting_guest_mode(vcpu) == IN_GUEST_MODE;
+	if (kvm_vcpu_exiting_guest_mode(vcpu) == IN_GUEST_MODE) {
+		if (vgic_active_irq(vcpu) &&
+		    cmpxchg(&vcpu->mode, EXITING_GUEST_MODE, IN_GUEST_MODE) == EXITING_GUEST_MODE)
+			return 0;
+
+		return 1;
+	}
+
+	return 0;
 }
 
 void kvm_arch_hardware_disable(void *garbage)
diff --git a/arch/arm/kvm/vgic.c b/arch/arm/kvm/vgic.c
index 415ddb8..146de1d 100644
--- a/arch/arm/kvm/vgic.c
+++ b/arch/arm/kvm/vgic.c
@@ -705,8 +705,10 @@ static bool vgic_queue_irq(struct kvm_vcpu *vcpu, u8 sgi_source_id, int irq)
 		kvm_debug("LR%d piggyback for IRQ%d %x\n", lr, irq, vgic_cpu->vgic_lr[lr]);
 		BUG_ON(!test_bit(lr, vgic_cpu->lr_used));
 		vgic_cpu->vgic_lr[lr] |= VGIC_LR_PENDING_BIT;
-		if (is_level)
+		if (is_level) {
 			vgic_cpu->vgic_lr[lr] |= VGIC_LR_EOI;
+			atomic_inc(&vgic_cpu->irq_active_count);
+		}
 		return true;
 	}
 
@@ -718,8 +720,10 @@ static bool vgic_queue_irq(struct kvm_vcpu *vcpu, u8 sgi_source_id, int irq)
 
 	kvm_debug("LR%d allocated for IRQ%d %x\n", lr, irq, sgi_source_id);
 	vgic_cpu->vgic_lr[lr] = MK_LR_PEND(sgi_source_id, irq);
-	if (is_level)
+	if (is_level) {
 		vgic_cpu->vgic_lr[lr] |= VGIC_LR_EOI;
+		atomic_inc(&vgic_cpu->irq_active_count);
+	}
 
 	vgic_cpu->vgic_irq_lr_map[irq] = lr;
 	clear_bit(lr, (unsigned long *)vgic_cpu->vgic_elrsr);
@@ -1011,6 +1015,8 @@ static irqreturn_t vgic_maintenance_handler(int irq, void *data)
 
 			vgic_bitmap_set_irq_val(&dist->irq_active,
 						vcpu->vcpu_id, irq, 0);
+			atomic_dec(&vgic_cpu->irq_active_count);
+			smp_mb();
 			vgic_cpu->vgic_lr[lr] &= ~VGIC_LR_EOI;
 			writel_relaxed(vgic_cpu->vgic_lr[lr],
 				       dist->vctrl_base + GICH_LR0 + (lr << 2));

WARNING: multiple messages have this Message-ID (diff)
From: Christoffer Dall <c.dall@virtualopensystems.com>
To: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	kvmarm@lists.cs.columbia.edu
Cc: Marc Zyngier <marc.zyngier@arm.com>
Subject: [PATCH v4 12/13] ARM: KVM: vgic: reduce the number of vcpu kick
Date: Sat, 10 Nov 2012 16:45:39 +0100	[thread overview]
Message-ID: <20121110154539.3061.82553.stgit@chazy-air> (raw)
In-Reply-To: <20121110154358.3061.16338.stgit@chazy-air>

From: Marc Zyngier <marc.zyngier@arm.com>

If we have level interrupts already programmed to fire on a vcpu,
there is no reason to kick it after injecting a new interrupt,
as we're guaranteed that we'll exit when the level interrupt will
be EOId (VGIC_LR_EOI is set).

The exit will force a reload of the VGIC, injecting the new interrupts.

Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Signed-off-by: Christoffer Dall <c.dall@virtualopensystems.com>
---
 arch/arm/include/asm/kvm_vgic.h |   10 ++++++++++
 arch/arm/kvm/arm.c              |   10 +++++++++-
 arch/arm/kvm/vgic.c             |   10 ++++++++--
 3 files changed, 27 insertions(+), 3 deletions(-)

diff --git a/arch/arm/include/asm/kvm_vgic.h b/arch/arm/include/asm/kvm_vgic.h
index a8e7a93..7d2662c 100644
--- a/arch/arm/include/asm/kvm_vgic.h
+++ b/arch/arm/include/asm/kvm_vgic.h
@@ -215,6 +215,9 @@ struct vgic_cpu {
 	u32		vgic_elrsr[2];	/* Saved only */
 	u32		vgic_apr;
 	u32		vgic_lr[64];	/* A15 has only 4... */
+
+	/* Number of level-triggered interrupt in progress */
+	atomic_t	irq_active_count;
 #endif
 };
 
@@ -254,6 +257,8 @@ bool vgic_handle_mmio(struct kvm_vcpu *vcpu, struct kvm_run *run,
 
 #define irqchip_in_kernel(k)	(!!((k)->arch.vgic.vctrl_base))
 #define vgic_initialized(k)	((k)->arch.vgic.ready)
+#define vgic_active_irq(v)	(atomic_read(&(v)->arch.vgic_cpu.irq_active_count) == 0)
+
 #else
 static inline int kvm_vgic_hyp_init(void)
 {
@@ -305,6 +310,11 @@ static inline bool vgic_initialized(struct kvm *kvm)
 {
 	return true;
 }
+
+static inline int vgic_active_irq(struct kvm_vcpu *vcpu)
+{
+	return 0;
+}
 #endif
 
 #endif
diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index a633d9d..1716f12 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -94,7 +94,15 @@ int kvm_arch_hardware_enable(void *garbage)
 
 int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu)
 {
-	return kvm_vcpu_exiting_guest_mode(vcpu) == IN_GUEST_MODE;
+	if (kvm_vcpu_exiting_guest_mode(vcpu) == IN_GUEST_MODE) {
+		if (vgic_active_irq(vcpu) &&
+		    cmpxchg(&vcpu->mode, EXITING_GUEST_MODE, IN_GUEST_MODE) == EXITING_GUEST_MODE)
+			return 0;
+
+		return 1;
+	}
+
+	return 0;
 }
 
 void kvm_arch_hardware_disable(void *garbage)
diff --git a/arch/arm/kvm/vgic.c b/arch/arm/kvm/vgic.c
index 415ddb8..146de1d 100644
--- a/arch/arm/kvm/vgic.c
+++ b/arch/arm/kvm/vgic.c
@@ -705,8 +705,10 @@ static bool vgic_queue_irq(struct kvm_vcpu *vcpu, u8 sgi_source_id, int irq)
 		kvm_debug("LR%d piggyback for IRQ%d %x\n", lr, irq, vgic_cpu->vgic_lr[lr]);
 		BUG_ON(!test_bit(lr, vgic_cpu->lr_used));
 		vgic_cpu->vgic_lr[lr] |= VGIC_LR_PENDING_BIT;
-		if (is_level)
+		if (is_level) {
 			vgic_cpu->vgic_lr[lr] |= VGIC_LR_EOI;
+			atomic_inc(&vgic_cpu->irq_active_count);
+		}
 		return true;
 	}
 
@@ -718,8 +720,10 @@ static bool vgic_queue_irq(struct kvm_vcpu *vcpu, u8 sgi_source_id, int irq)
 
 	kvm_debug("LR%d allocated for IRQ%d %x\n", lr, irq, sgi_source_id);
 	vgic_cpu->vgic_lr[lr] = MK_LR_PEND(sgi_source_id, irq);
-	if (is_level)
+	if (is_level) {
 		vgic_cpu->vgic_lr[lr] |= VGIC_LR_EOI;
+		atomic_inc(&vgic_cpu->irq_active_count);
+	}
 
 	vgic_cpu->vgic_irq_lr_map[irq] = lr;
 	clear_bit(lr, (unsigned long *)vgic_cpu->vgic_elrsr);
@@ -1011,6 +1015,8 @@ static irqreturn_t vgic_maintenance_handler(int irq, void *data)
 
 			vgic_bitmap_set_irq_val(&dist->irq_active,
 						vcpu->vcpu_id, irq, 0);
+			atomic_dec(&vgic_cpu->irq_active_count);
+			smp_mb();
 			vgic_cpu->vgic_lr[lr] &= ~VGIC_LR_EOI;
 			writel_relaxed(vgic_cpu->vgic_lr[lr],
 				       dist->vctrl_base + GICH_LR0 + (lr << 2));


  parent reply	other threads:[~2012-11-10 15:45 UTC|newest]

Thread overview: 116+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-10 15:44 [PATCH v4 00/13] KVM/ARM vGIC support Christoffer Dall
2012-11-10 15:44 ` Christoffer Dall
2012-11-10 15:44 ` [PATCH v4 01/13] KVM: ARM: Introduce KVM_SET_DEVICE_ADDRESS ioctl Christoffer Dall
2012-11-10 15:44   ` Christoffer Dall
2012-11-10 15:44 ` [PATCH v4 02/13] ARM: KVM: Keep track of currently running vcpus Christoffer Dall
2012-11-10 15:44   ` Christoffer Dall
2012-11-28 12:47   ` Will Deacon
2012-11-28 12:47     ` Will Deacon
2012-11-28 13:15     ` Marc Zyngier
2012-11-28 13:15       ` Marc Zyngier
2012-11-30 22:39     ` Christoffer Dall
2012-11-30 22:39       ` Christoffer Dall
2012-11-10 15:44 ` [PATCH v4 03/13] ARM: KVM: Initial VGIC infrastructure support Christoffer Dall
2012-11-10 15:44   ` Christoffer Dall
2012-11-28 12:49   ` Will Deacon
2012-11-28 12:49     ` Will Deacon
2012-11-28 13:09     ` Marc Zyngier
2012-11-28 13:09       ` Marc Zyngier
2012-11-28 14:13       ` Will Deacon
2012-11-28 14:13         ` Will Deacon
2012-12-01  2:19     ` Christoffer Dall
2012-12-01  2:19       ` Christoffer Dall
2012-11-10 15:44 ` [PATCH v4 04/13] ARM: KVM: Initial VGIC MMIO support code Christoffer Dall
2012-11-10 15:44   ` Christoffer Dall
2012-11-12  8:54   ` Dong Aisheng
2012-11-12  8:54     ` Dong Aisheng
2012-11-13 13:32     ` Christoffer Dall
2012-11-13 13:32       ` Christoffer Dall
2012-11-28 13:09   ` Will Deacon
2012-11-28 13:09     ` Will Deacon
2012-11-28 13:44     ` Marc Zyngier
2012-11-28 13:44       ` Marc Zyngier
2012-11-10 15:44 ` [PATCH v4 05/13] ARM: KVM: VGIC accept vcpu and dist base addresses from user space Christoffer Dall
2012-11-10 15:44   ` Christoffer Dall
2012-11-12  8:56   ` Dong Aisheng
2012-11-12  8:56     ` Dong Aisheng
2012-11-13 13:35     ` Christoffer Dall
2012-11-13 13:35       ` Christoffer Dall
2012-11-28 13:11   ` Will Deacon
2012-11-28 13:11     ` Will Deacon
2012-11-28 13:22     ` [kvmarm] " Marc Zyngier
2012-11-28 13:22       ` Marc Zyngier
2012-12-01  2:52     ` Christoffer Dall
2012-12-01  2:52       ` Christoffer Dall
2012-12-01 15:57       ` Christoffer Dall
2012-12-01 15:57         ` Christoffer Dall
2012-12-03 10:40       ` Will Deacon
2012-12-03 10:40         ` Will Deacon
2012-11-10 15:44 ` [PATCH v4 06/13] ARM: KVM: VGIC distributor handling Christoffer Dall
2012-11-10 15:44   ` Christoffer Dall
2012-11-12  9:29   ` Dong Aisheng
2012-11-12  9:29     ` Dong Aisheng
2012-11-13 13:38     ` Christoffer Dall
2012-11-13 13:38       ` Christoffer Dall
2012-11-28 13:21   ` Will Deacon
2012-11-28 13:21     ` Will Deacon
2012-11-28 14:35     ` Marc Zyngier
2012-11-28 14:35       ` Marc Zyngier
2012-11-10 15:45 ` [PATCH v4 07/13] ARM: KVM: VGIC virtual CPU interface management Christoffer Dall
2012-11-10 15:45   ` Christoffer Dall
2012-12-03 13:23   ` Will Deacon
2012-12-03 13:23     ` Will Deacon
2012-12-03 14:11     ` Marc Zyngier
2012-12-03 14:11       ` Marc Zyngier
2012-12-03 14:34       ` Will Deacon
2012-12-03 14:34         ` Will Deacon
2012-12-03 15:24         ` Marc Zyngier
2012-12-03 15:24           ` Marc Zyngier
2012-12-03 14:54       ` Christoffer Dall
2012-12-03 14:54         ` Christoffer Dall
2012-11-10 15:45 ` [PATCH v4 08/13] ARM: KVM: vgic: retire queued, disabled interrupts Christoffer Dall
2012-11-10 15:45   ` Christoffer Dall
2012-12-03 13:24   ` Will Deacon
2012-12-03 13:24     ` Will Deacon
2012-11-10 15:45 ` [PATCH v4 09/13] ARM: KVM: VGIC interrupt injection Christoffer Dall
2012-11-10 15:45   ` Christoffer Dall
2012-12-03 13:25   ` Will Deacon
2012-12-03 13:25     ` Will Deacon
2012-12-03 14:21     ` Marc Zyngier
2012-12-03 14:21       ` Marc Zyngier
2012-12-03 14:58       ` Christoffer Dall
2012-12-03 14:58         ` Christoffer Dall
2012-12-03 19:13       ` Christoffer Dall
2012-12-03 19:13         ` Christoffer Dall
2012-12-03 19:22         ` Marc Zyngier
2012-12-03 19:22           ` Marc Zyngier
2012-11-10 15:45 ` [PATCH v4 10/13] ARM: KVM: VGIC control interface world switch Christoffer Dall
2012-11-10 15:45   ` Christoffer Dall
2012-12-03 13:31   ` Will Deacon
2012-12-03 13:31     ` Will Deacon
2012-12-03 14:26     ` Marc Zyngier
2012-12-03 14:26       ` Marc Zyngier
2012-11-10 15:45 ` [PATCH v4 11/13] ARM: KVM: VGIC initialisation code Christoffer Dall
2012-11-10 15:45   ` Christoffer Dall
2012-12-05 10:43   ` Will Deacon
2012-12-05 10:43     ` Will Deacon
2012-11-10 15:45 ` Christoffer Dall [this message]
2012-11-10 15:45   ` [PATCH v4 12/13] ARM: KVM: vgic: reduce the number of vcpu kick Christoffer Dall
2012-12-05 10:43   ` Will Deacon
2012-12-05 10:43     ` Will Deacon
2012-12-05 10:58     ` Russell King - ARM Linux
2012-12-05 10:58       ` Russell King - ARM Linux
2012-12-05 12:17       ` Marc Zyngier
2012-12-05 12:17         ` Marc Zyngier
2012-12-05 12:29         ` Russell King - ARM Linux
2012-12-05 12:29           ` Russell King - ARM Linux
2012-12-05 13:40           ` Marc Zyngier
2012-12-05 13:40             ` Marc Zyngier
2012-12-05 15:55             ` Russell King - ARM Linux
2012-12-05 15:55               ` Russell King - ARM Linux
2012-12-05 11:16   ` Russell King - ARM Linux
2012-12-05 11:16     ` Russell King - ARM Linux
2012-11-10 15:45 ` [PATCH v4 13/13] ARM: KVM: Add VGIC configuration option Christoffer Dall
2012-11-10 15:45   ` Christoffer Dall
2012-11-10 19:52   ` Sergei Shtylyov
2012-11-10 19:52     ` Sergei Shtylyov

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=20121110154539.3061.82553.stgit@chazy-air \
    --to=c.dall@virtualopensystems.com \
    --cc=linux-arm-kernel@lists.infradead.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.