linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: c.dall@virtualopensystems.com (Christoffer Dall)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 15/15] KVM: ARM: Guest wait-for-interrupts (WFI) support
Date: Sat, 15 Sep 2012 11:36:05 -0400	[thread overview]
Message-ID: <20120915153605.21241.75455.stgit@ubuntu> (raw)
In-Reply-To: <20120915153359.21241.86002.stgit@ubuntu>

From: Christoffer Dall <cdall@cs.columbia.edu>

When the guest executes a WFI instruction the operation is trapped to
KVM, which emulates the instruction in software. There is no correlation
between a guest executing a WFI instruction and actually putting the
hardware into a low-power mode, since a KVM guest is essentially a
process and the WFI instruction can be seen as 'sleep' call from this
process. Therefore, we block the vcpu when the guest excecutes a wfi
instruction and the IRQ or FIQ lines are not raised.

When an interrupt comes in through KVM_IRQ_LINE (see previous patch) we
signal the VCPU thread and unflag the VCPU to no longer wait for
interrupts.

Signed-off-by: Christoffer Dall <c.dall@virtualopensystems.com>
---
 arch/arm/kvm/arm.c     |   10 ++++++++--
 arch/arm/kvm/emulate.c |   13 ++++++++++++-
 arch/arm/kvm/trace.h   |   16 ++++++++++++++++
 3 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
index 06a3368..64fbec7 100644
--- a/arch/arm/kvm/arm.c
+++ b/arch/arm/kvm/arm.c
@@ -318,9 +318,16 @@ int kvm_arch_vcpu_ioctl_set_mpstate(struct kvm_vcpu *vcpu,
 	return -EINVAL;
 }
 
+/**
+ * kvm_arch_vcpu_runnable - determine if the vcpu can be scheduled
+ * @v:		The VCPU pointer
+ *
+ * If the guest CPU is not waiting for interrupts or an interrupt line is
+ * asserted, the CPU is by definition runnable.
+ */
 int kvm_arch_vcpu_runnable(struct kvm_vcpu *v)
 {
-	return 0;
+	return !!v->arch.irq_lines;
 }
 
 int kvm_arch_vcpu_in_guest_mode(struct kvm_vcpu *v)
@@ -586,7 +593,6 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *run)
 		 * Check conditions before entering the guest
 		 */
 		cond_resched();
-
 		update_vttbr(vcpu->kvm);
 
 		local_irq_disable();
diff --git a/arch/arm/kvm/emulate.c b/arch/arm/kvm/emulate.c
index 2670679..fc0fcd3 100644
--- a/arch/arm/kvm/emulate.c
+++ b/arch/arm/kvm/emulate.c
@@ -154,9 +154,20 @@ static int kvm_instr_index(u32 instr, u32 table[][2], int table_entries)
 	return INSTR_NONE;
 }
 
+/**
+ * kvm_handle_wfi - handle a wait-for-interrupts instruction executed by a guest
+ * @vcpu:	the vcpu pointer
+ * @run:	the kvm_run structure pointer
+ *
+ * Simply sets the wait_for_interrupts flag on the vcpu structure, which will
+ * halt execution of world-switches and schedule other host processes until
+ * there is an incoming IRQ or FIQ to the VM.
+ */
 int kvm_handle_wfi(struct kvm_vcpu *vcpu, struct kvm_run *run)
 {
-	return 0;
+	trace_kvm_wfi(vcpu->arch.regs.pc);
+	kvm_vcpu_block(vcpu);
+	return 1;
 }
 
 
diff --git a/arch/arm/kvm/trace.h b/arch/arm/kvm/trace.h
index 7199b58..b371138 100644
--- a/arch/arm/kvm/trace.h
+++ b/arch/arm/kvm/trace.h
@@ -143,6 +143,22 @@ TRACE_EVENT(kvm_emulate_cp15_imp,
 			__entry->CRm, __entry->Op2)
 );
 
+TRACE_EVENT(kvm_wfi,
+	TP_PROTO(unsigned long vcpu_pc),
+	TP_ARGS(vcpu_pc),
+
+	TP_STRUCT__entry(
+		__field(	unsigned long,	vcpu_pc		)
+	),
+
+	TP_fast_assign(
+		__entry->vcpu_pc		= vcpu_pc;
+	),
+
+	TP_printk("guest executed wfi at: 0x%08lx", __entry->vcpu_pc)
+);
+
+
 #endif /* _TRACE_KVM_H */
 
 #undef TRACE_INCLUDE_PATH

  parent reply	other threads:[~2012-09-15 15:36 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-15 15:34 [PATCH 00/15] KVM/ARM Implementation Christoffer Dall
2012-09-15 15:34 ` [PATCH 01/15] ARM: add mem_type prot_pte accessor Christoffer Dall
2012-09-18 12:23   ` Will Deacon
2012-09-18 19:18     ` Christoffer Dall
2012-09-18 21:04   ` Russell King - ARM Linux
2012-09-18 21:53     ` Christoffer Dall
2012-09-20 10:01       ` Marc Zyngier
2012-09-20 13:21         ` Christoffer Dall
2012-09-15 15:34 ` [PATCH 02/15] ARM: Add page table and page defines needed by KVM Christoffer Dall
2012-09-18 12:47   ` Will Deacon
2012-09-18 14:06     ` Catalin Marinas
2012-09-18 15:05       ` Christoffer Dall
2012-09-18 15:07         ` Catalin Marinas
2012-09-18 15:10           ` Christoffer Dall
2012-09-18 22:01     ` Christoffer Dall
2012-09-19  9:21       ` Will Deacon
2012-09-20  0:10         ` Christoffer Dall
2012-09-15 15:34 ` [PATCH 03/15] ARM: Section based HYP idmap Christoffer Dall
2012-09-18 13:00   ` Will Deacon
2012-10-01  2:19     ` Christoffer Dall
2012-09-15 15:34 ` [PATCH 04/15] ARM: idmap: only initialize HYP idmap when HYP mode is available Christoffer Dall
2012-09-18 13:03   ` Will Deacon
2012-09-20  0:11     ` Christoffer Dall
2012-09-15 15:35 ` [PATCH 05/15] ARM: Expose PMNC bitfields for KVM use Christoffer Dall
2012-09-18 13:08   ` Will Deacon
2012-09-18 22:13     ` Christoffer Dall
2012-09-19  4:09     ` [kvmarm] " Rusty Russell
2012-09-19  9:30       ` Will Deacon
2012-09-15 15:35 ` [PATCH 06/15] KVM: ARM: Initial skeleton to compile KVM support Christoffer Dall
2012-09-25 15:20   ` Will Deacon
2012-09-26  1:43     ` Christoffer Dall
2012-09-27 14:13       ` Will Deacon
2012-09-27 14:39         ` Marc Zyngier
2012-09-27 14:45         ` [kvmarm] " Peter Maydell
2012-09-27 15:20           ` Will Deacon
2012-09-30 19:21         ` Christoffer Dall
2012-10-01 13:03           ` [kvmarm] " Marc Zyngier
2012-10-04 13:02           ` Min-gyu Kim
2012-10-04 13:35             ` Christoffer Dall
2012-10-05  6:28             ` Rusty Russell
2012-10-04 13:44     ` [kvmarm] " Avi Kivity
2012-09-15 15:35 ` [PATCH 07/15] KVM: ARM: Hypervisor inititalization Christoffer Dall
2012-09-15 15:35 ` [PATCH 08/15] KVM: ARM: Memory virtualization setup Christoffer Dall
2012-09-15 15:35 ` [PATCH 09/15] KVM: ARM: Inject IRQs and FIQs from userspace Christoffer Dall
2012-09-25 15:55   ` Will Deacon
2012-09-29 15:50     ` Christoffer Dall
2012-09-30 12:48       ` Will Deacon
2012-09-30 14:34         ` Christoffer Dall
2012-09-15 15:35 ` [PATCH 10/15] KVM: ARM: World-switch implementation Christoffer Dall
2012-09-25 17:00   ` Will Deacon
2012-09-25 17:15     ` [kvmarm] " Peter Maydell
2012-09-25 17:42       ` Marc Zyngier
2012-09-30  0:33         ` Christoffer Dall
2012-09-30  9:48           ` Peter Maydell
2012-09-30 14:31             ` Christoffer Dall
2012-09-30 17:47     ` Christoffer Dall
2012-09-15 15:35 ` [PATCH 11/15] KVM: ARM: Emulation framework and CP15 emulation Christoffer Dall
2012-09-15 15:35 ` [PATCH 12/15] KVM: ARM: User space API for getting/setting co-proc registers Christoffer Dall
2012-09-15 15:35 ` [PATCH 13/15] KVM: ARM: Handle guest faults in KVM Christoffer Dall
2012-09-25 11:11   ` Min-gyu Kim
2012-09-25 12:38     ` Christoffer Dall
2012-09-27  3:11       ` Min-gyu Kim
2012-09-27  5:35         ` Christoffer Dall
2012-09-27 15:26         ` [kvmarm] " Marc Zyngier
2012-09-27 12:39       ` Catalin Marinas
2012-09-27 17:15         ` Christoffer Dall
2012-09-27 17:21           ` Catalin Marinas
2012-09-15 15:35 ` [PATCH 14/15] KVM: ARM: Handle I/O aborts Christoffer Dall
2012-09-27 15:11   ` Will Deacon
2012-09-30 21:49     ` Christoffer Dall
2012-10-01 12:53       ` Dave Martin
2012-10-01 15:12         ` Jon Medhurst (Tixy)
2012-10-01 16:07           ` Dave Martin
2012-10-05  9:00         ` Russell King - ARM Linux
2012-10-08 10:04           ` Dave Martin
2012-10-08 21:52             ` Christoffer Dall
2012-09-15 15:36 ` Christoffer Dall [this message]
2012-09-25 17:04   ` [PATCH 15/15] KVM: ARM: Guest wait-for-interrupts (WFI) support Will Deacon
2012-09-29 23:00     ` Christoffer Dall
2012-09-18 12:21 ` [PATCH 00/15] KVM/ARM Implementation Will Deacon
2012-09-18 12:32   ` Christoffer Dall
2012-09-19 12:44 ` Avi Kivity

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=20120915153605.21241.75455.stgit@ubuntu \
    --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 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).