From: Andrew Jones <drjones@redhat.com>
To: kvmarm@lists.cs.columbia.edu
Cc: marc.zyngier@arm.com, cdall@linaro.org
Subject: [PATCH 4/5] KVM: arm/arm64: improve kvm_arch_vcpu_runnable
Date: Fri, 29 Sep 2017 13:30:40 +0200 [thread overview]
Message-ID: <20170929113041.24371-5-drjones@redhat.com> (raw)
In-Reply-To: <20170929113041.24371-1-drjones@redhat.com>
Conceptually, kvm_arch_vcpu_runnable() should be "not waiting,
or waiting for interrupts and interrupts are pending",
!waiting-uninterruptable &&
(!waiting-for-interrupts || interrupts-pending)
but the implementation was only
!waiting-uninterruptable && interrupts-pending
Thanks to the context of the two callers there wasn't an issue,
however, to future-proof the function, this patch implements the
conceptual condition by applying mp_state to track waiting-
uninterruptable vs. waiting-for-interrupts.
Signed-off-by: Andrew Jones <drjones@redhat.com>
---
Documentation/virtual/kvm/api.txt | 10 ++++++----
virt/kvm/arm/arm.c | 13 +++++++++----
2 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt
index e63a35fafef0..7c0bb1ae10a2 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -1071,7 +1071,7 @@ Possible values are:
- KVM_MP_STATE_INIT_RECEIVED: the vcpu has received an INIT signal, and is
now ready for a SIPI [x86]
- KVM_MP_STATE_HALTED: the vcpu has executed a HLT instruction and
- is waiting for an interrupt [x86]
+ is waiting for an interrupt [x86,arm/arm64]
- KVM_MP_STATE_SIPI_RECEIVED: the vcpu has just received a SIPI (vector
accessible via KVM_GET_VCPU_EVENTS) [x86]
- KVM_MP_STATE_STOPPED: the vcpu is stopped [s390,arm/arm64]
@@ -1087,8 +1087,9 @@ these architectures.
For arm/arm64:
-The only states that are valid are KVM_MP_STATE_STOPPED and
-KVM_MP_STATE_RUNNABLE which reflect if the vcpu is paused or not.
+The only states that are valid are KVM_MP_STATE_STOPPED, KVM_MP_STATE_HALTED,
+and KVM_MP_STATE_RUNNABLE which reflect if the vcpu is powered-off, waiting
+for interrupts, or powered-on and not waiting for interrupts.
4.39 KVM_SET_MP_STATE
@@ -1108,7 +1109,8 @@ these architectures.
For arm/arm64:
The only states that are valid are KVM_MP_STATE_STOPPED and
-KVM_MP_STATE_RUNNABLE which reflect if the vcpu should be paused or not.
+KVM_MP_STATE_RUNNABLE which reflect if the vcpu should be
+powered-off or not.
4.40 KVM_SET_IDENTITY_MAP_ADDR
diff --git a/virt/kvm/arm/arm.c b/virt/kvm/arm/arm.c
index 220a3dbda76c..5bc9b0d2fd0f 100644
--- a/virt/kvm/arm/arm.c
+++ b/virt/kvm/arm/arm.c
@@ -414,13 +414,16 @@ static bool vcpu_should_sleep(struct kvm_vcpu *vcpu)
* kvm_arch_vcpu_runnable - determine if the vcpu can be scheduled
* @vcpu: The VCPU pointer
*
- * If the guest CPU is not waiting for interrupts or an interrupt line is
- * asserted, the CPU is by definition runnable.
+ * If the VCPU is not waiting at all (including sleeping, which is waiting
+ * uninterruptably), or it's waiting for interrupts but interrupts are
+ * pending, then it is by definition runnable.
*/
int kvm_arch_vcpu_runnable(struct kvm_vcpu *vcpu)
{
- return (!!vcpu->arch.irq_lines || kvm_vgic_vcpu_pending_irq(vcpu))
- && !vcpu_should_sleep(vcpu);
+ return !vcpu_should_sleep(vcpu) &&
+ (vcpu->arch.mp_state != KVM_MP_STATE_HALTED ||
+ (!!vcpu->arch.irq_lines ||
+ kvm_vgic_vcpu_pending_irq(vcpu)));
}
bool kvm_arch_vcpu_in_kernel(struct kvm_vcpu *vcpu)
@@ -582,7 +585,9 @@ void kvm_arm_emulate_wfe(struct kvm_vcpu *vcpu)
void kvm_arm_emulate_wfi(struct kvm_vcpu *vcpu)
{
vcpu->stat.wfi_exit_stat++;
+ vcpu->arch.mp_state = KVM_MP_STATE_HALTED;
kvm_vcpu_block(vcpu);
+ vcpu->arch.mp_state = KVM_MP_STATE_RUNNABLE;
kvm_clear_request(KVM_REQ_UNHALT, vcpu);
}
--
2.13.5
next prev parent reply other threads:[~2017-09-29 11:30 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-29 11:30 [PATCH 0/5] kvm_arch_vcpu_runnable related improvements Andrew Jones
2017-09-29 11:30 ` [PATCH 1/5] KVM: arm/arm64: tidy 'should sleep' conditions Andrew Jones
2017-10-05 8:13 ` Marc Zyngier
2017-09-29 11:30 ` [PATCH 2/5] KVM: arm/arm64: replace power_off with mp_state=STOPPED Andrew Jones
2017-10-05 8:32 ` Marc Zyngier
2017-10-10 13:26 ` Andrew Jones
2017-10-14 19:12 ` Christoffer Dall
2017-10-18 12:04 ` Andrew Jones
2017-09-29 11:30 ` [PATCH 3/5] KVM: arm/arm64: factor out common wfe/wfi emulation code Andrew Jones
2017-10-05 8:36 ` Marc Zyngier
2017-10-14 19:13 ` Christoffer Dall
2017-10-18 12:06 ` Andrew Jones
2017-09-29 11:30 ` Andrew Jones [this message]
2017-10-05 9:19 ` [PATCH 4/5] KVM: arm/arm64: improve kvm_arch_vcpu_runnable Marc Zyngier
2017-10-14 19:13 ` Christoffer Dall
2017-10-18 12:09 ` Andrew Jones
2017-09-29 11:30 ` [PATCH 5/5] KVM: arm/arm64: kvm_arch_vcpu_runnable: don't miss injected irqs Andrew Jones
2017-10-05 9:37 ` Marc Zyngier
2017-10-10 13:28 ` Andrew Jones
2017-10-14 19:13 ` Christoffer Dall
2017-10-18 12:13 ` Andrew Jones
2017-10-18 13:18 ` Christoffer Dall
2017-10-18 13:55 ` Andrew Jones
2017-10-18 14:14 ` Christoffer Dall
2017-10-02 8:31 ` [PATCH 6/5] KVM: arm/arm64: make kvm_vgic_vcpu_pending_irq static Andrew Jones
2017-10-05 9:37 ` Marc Zyngier
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=20170929113041.24371-5-drjones@redhat.com \
--to=drjones@redhat.com \
--cc=cdall@linaro.org \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=marc.zyngier@arm.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