linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: bdas@redhat.com, gleb@kernel.org
Subject: [PATCH 02/25] KVM: x86: return all bits from get_interrupt_shadow
Date: Mon,  9 Jun 2014 14:58:50 +0200	[thread overview]
Message-ID: <1402318753-23362-3-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1402318753-23362-1-git-send-email-pbonzini@redhat.com>

For the next patch we will need to know the full state of the
interrupt shadow; we will then set KVM_REQ_EVENT when one bit
is cleared.

However, right now get_interrupt_shadow only returns the one
corresponding to the emulated instruction, or an unconditional
0 if the emulated instruction does not have an interrupt shadow.
This is confusing and does not allow us to check for cleared
bits as mentioned above.

Clean the callback up, and modify toggle_interruptibility to
match the comment above the call.  As a small result, the
call to set_interrupt_shadow will be skipped in the common
case where int_shadow == 0 && mask == 0.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 arch/x86/include/asm/kvm_host.h |  2 +-
 arch/x86/kvm/svm.c              |  6 +++---
 arch/x86/kvm/vmx.c              |  4 ++--
 arch/x86/kvm/x86.c              | 10 +++++-----
 4 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 63e020be3da7..0b140dc65bee 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -717,7 +717,7 @@ struct kvm_x86_ops {
 	int (*handle_exit)(struct kvm_vcpu *vcpu);
 	void (*skip_emulated_instruction)(struct kvm_vcpu *vcpu);
 	void (*set_interrupt_shadow)(struct kvm_vcpu *vcpu, int mask);
-	u32 (*get_interrupt_shadow)(struct kvm_vcpu *vcpu, int mask);
+	u32 (*get_interrupt_shadow)(struct kvm_vcpu *vcpu);
 	void (*patch_hypercall)(struct kvm_vcpu *vcpu,
 				unsigned char *hypercall_addr);
 	void (*set_irq)(struct kvm_vcpu *vcpu);
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index ec8366c5cfea..175702d51176 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -486,14 +486,14 @@ static int is_external_interrupt(u32 info)
 	return info == (SVM_EVTINJ_VALID | SVM_EVTINJ_TYPE_INTR);
 }
 
-static u32 svm_get_interrupt_shadow(struct kvm_vcpu *vcpu, int mask)
+static u32 svm_get_interrupt_shadow(struct kvm_vcpu *vcpu)
 {
 	struct vcpu_svm *svm = to_svm(vcpu);
 	u32 ret = 0;
 
 	if (svm->vmcb->control.int_state & SVM_INTERRUPT_SHADOW_MASK)
-		ret |= KVM_X86_SHADOW_INT_STI | KVM_X86_SHADOW_INT_MOV_SS;
-	return ret & mask;
+		ret = KVM_X86_SHADOW_INT_STI | KVM_X86_SHADOW_INT_MOV_SS;
+	return ret;
 }
 
 static void svm_set_interrupt_shadow(struct kvm_vcpu *vcpu, int mask)
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index a2ae11d162fe..57ed3aa0f5d3 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -1940,7 +1940,7 @@ static void vmx_set_rflags(struct kvm_vcpu *vcpu, unsigned long rflags)
 	vmcs_writel(GUEST_RFLAGS, rflags);
 }
 
-static u32 vmx_get_interrupt_shadow(struct kvm_vcpu *vcpu, int mask)
+static u32 vmx_get_interrupt_shadow(struct kvm_vcpu *vcpu)
 {
 	u32 interruptibility = vmcs_read32(GUEST_INTERRUPTIBILITY_INFO);
 	int ret = 0;
@@ -1950,7 +1950,7 @@ static u32 vmx_get_interrupt_shadow(struct kvm_vcpu *vcpu, int mask)
 	if (interruptibility & GUEST_INTR_STATE_MOV_SS)
 		ret |= KVM_X86_SHADOW_INT_MOV_SS;
 
-	return ret & mask;
+	return ret;
 }
 
 static void vmx_set_interrupt_shadow(struct kvm_vcpu *vcpu, int mask)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 451d6acea808..70faa1089b75 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2974,9 +2974,7 @@ static void kvm_vcpu_ioctl_x86_get_vcpu_events(struct kvm_vcpu *vcpu,
 		vcpu->arch.interrupt.pending && !vcpu->arch.interrupt.soft;
 	events->interrupt.nr = vcpu->arch.interrupt.nr;
 	events->interrupt.soft = 0;
-	events->interrupt.shadow =
-		kvm_x86_ops->get_interrupt_shadow(vcpu,
-			KVM_X86_SHADOW_INT_MOV_SS | KVM_X86_SHADOW_INT_STI);
+	events->interrupt.shadow = kvm_x86_ops->get_interrupt_shadow(vcpu);
 
 	events->nmi.injected = vcpu->arch.nmi_injected;
 	events->nmi.pending = vcpu->arch.nmi_pending != 0;
@@ -4857,7 +4855,7 @@ static const struct x86_emulate_ops emulate_ops = {
 
 static void toggle_interruptibility(struct kvm_vcpu *vcpu, u32 mask)
 {
-	u32 int_shadow = kvm_x86_ops->get_interrupt_shadow(vcpu, mask);
+	u32 int_shadow = kvm_x86_ops->get_interrupt_shadow(vcpu);
 	/*
 	 * an sti; sti; sequence only disable interrupts for the first
 	 * instruction. So, if the last instruction, be it emulated or
@@ -4865,7 +4863,9 @@ static void toggle_interruptibility(struct kvm_vcpu *vcpu, u32 mask)
 	 * means that the last instruction is an sti. We should not
 	 * leave the flag on in this case. The same goes for mov ss
 	 */
-	if (!(int_shadow & mask))
+	if (int_shadow & mask)
+		mask = 0;
+	if (unlikely(int_shadow || mask))
 		kvm_x86_ops->set_interrupt_shadow(vcpu, mask);
 }
 
-- 
1.8.3.1



  parent reply	other threads:[~2014-06-09 12:59 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-09 12:58 [PATCH 00/25] KVM: x86: Speed up emulation of invalid state Paolo Bonzini
2014-06-09 12:58 ` [PATCH 01/25] KVM: vmx: speed up emulation of invalid guest state Paolo Bonzini
2014-06-09 12:58 ` Paolo Bonzini [this message]
2014-06-09 12:58 ` [PATCH 03/25] KVM: x86: avoid useless set of KVM_REQ_EVENT after emulation Paolo Bonzini
2014-06-09 12:58 ` [PATCH 04/25] KVM: emulate: move around some checks Paolo Bonzini
2014-06-09 12:58 ` [PATCH 05/25] KVM: emulate: protect checks on ctxt->d by a common "if (unlikely())" Paolo Bonzini
2014-06-09 12:58 ` [PATCH 06/25] KVM: emulate: speed up emulated moves Paolo Bonzini
2014-06-09 12:58 ` [PATCH 07/25] KVM: emulate: simplify writeback Paolo Bonzini
2014-06-09 12:58 ` [PATCH 08/25] KVM: emulate: abstract handling of memory operands Paolo Bonzini
2014-06-09 12:58 ` [PATCH 09/25] KVM: export mark_page_dirty_in_slot Paolo Bonzini
2014-06-09 12:58 ` [PATCH 10/25] KVM: emulate: introduce memory_prepare callback to speed up memory access Paolo Bonzini
2014-06-09 12:58 ` [PATCH 11/25] KVM: emulate: activate memory access optimization Paolo Bonzini
2014-06-09 12:59 ` [PATCH 12/25] KVM: emulate: extend memory access optimization to stores Paolo Bonzini
2014-06-09 18:40   ` Bandan Das
2014-06-19 11:37     ` Paolo Bonzini
2014-06-09 12:59 ` [PATCH 13/25] KVM: emulate: move init_decode_cache to emulate.c Paolo Bonzini
2014-06-09 12:59 ` [PATCH 14/25] KVM: emulate: Remove ctxt->intercept and ctxt->check_perm checks Paolo Bonzini
2014-06-09 12:59 ` [PATCH 15/25] KVM: emulate: cleanup decode_modrm Paolo Bonzini
2014-06-09 12:59 ` [PATCH 16/25] KVM: emulate: clean up initializations in init_decode_cache Paolo Bonzini
2014-06-09 12:59 ` [PATCH 17/25] KVM: emulate: rework seg_override Paolo Bonzini
2014-06-09 12:59 ` [PATCH 18/25] KVM: emulate: do not initialize memopp Paolo Bonzini
2014-06-09 12:59 ` [PATCH 19/25] KVM: emulate: speed up do_insn_fetch Paolo Bonzini
2014-06-09 12:59 ` [PATCH 20/25] KVM: emulate: avoid repeated calls to do_insn_fetch_bytes Paolo Bonzini
2014-06-09 12:59 ` [PATCH 21/25] KVM: emulate: avoid per-byte copying in instruction fetches Paolo Bonzini
2014-06-09 12:59 ` [PATCH 22/25] KVM: emulate: put pointers in the fetch_cache Paolo Bonzini
2014-06-09 12:59 ` [PATCH 23/25] KVM: x86: use kvm_read_guest_page for emulator accesses Paolo Bonzini
2014-06-09 12:59 ` [PATCH 24/25] KVM: emulate: simplify BitOp handling Paolo Bonzini
2014-06-09 12:59 ` [PATCH 25/25] KVM: emulate: fix harmless typo in MMX decoding Paolo Bonzini

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=1402318753-23362-3-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=bdas@redhat.com \
    --cc=gleb@kernel.org \
    --cc=linux-kernel@vger.kernel.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).