All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Marcelo Tosatti <mtosatti@redhat.com>
Cc: kvm@vger.kernel.org
Subject: [PATCH v3 01/26] KVM: VMX: Return correct CPL during transition to protected mode
Date: Wed, 27 Jun 2012 18:24:49 +0300	[thread overview]
Message-ID: <1340810714-19399-2-git-send-email-avi@redhat.com> (raw)
In-Reply-To: <1340810714-19399-1-git-send-email-avi@redhat.com>

In protected mode, the CPL is defined as the lower two bits of CS, as set by
the last far jump.  But during the transition to protected mode, there is no
last far jump, so we need to return zero (the inherited real mode CPL).

Fix by reading CPL from the cache during the transition.  This isn't 100%
correct since we don't set the CPL cache on a far jump, but since protected
mode transition will always jump to a segment with RPL=0, it will always
work.

Signed-off-by: Avi Kivity <avi@redhat.com>
---
 arch/x86/kvm/vmx.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index eeeb4a2..8f2ddd9 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -3175,11 +3175,22 @@ static int __vmx_get_cpl(struct kvm_vcpu *vcpu)
 
 static int vmx_get_cpl(struct kvm_vcpu *vcpu)
 {
+	struct vcpu_vmx *vmx = to_vmx(vcpu);
+
+	/*
+	 * If we enter real mode with cs.sel & 3 != 0, the normal CPL calculations
+	 * fail; use the cache instead.
+	 */
+	if (unlikely(vmx->emulation_required && emulate_invalid_guest_state)) {
+		return vmx->cpl;
+	}
+
 	if (!test_bit(VCPU_EXREG_CPL, (ulong *)&vcpu->arch.regs_avail)) {
 		__set_bit(VCPU_EXREG_CPL, (ulong *)&vcpu->arch.regs_avail);
-		to_vmx(vcpu)->cpl = __vmx_get_cpl(vcpu);
+		vmx->cpl = __vmx_get_cpl(vcpu);
 	}
-	return to_vmx(vcpu)->cpl;
+
+	return vmx->cpl;
 }
 
 
-- 
1.7.11


  reply	other threads:[~2012-06-27 15:25 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-27 15:24 [PATCH v3 00/26] Big big real mode improvements Avi Kivity
2012-06-27 15:24 ` Avi Kivity [this message]
2012-06-27 15:24 ` [PATCH v3 02/26] KVM: Split cpuid register access from computation Avi Kivity
2012-07-03 17:34   ` Marcelo Tosatti
2012-07-04  8:17     ` Avi Kivity
2012-07-04  8:24       ` [PATCH v3.1 02/26] KVM: Split cpuid register access from computatio Avi Kivity
2012-06-27 15:24 ` [PATCH v3 03/26] KVM: x86 emulator: change ->get_cpuid() accessor to use the x86 semantics Avi Kivity
2012-06-27 15:24 ` [PATCH v3 04/26] KVM: x86 emulator: emulate cpuid Avi Kivity
2012-06-27 15:24 ` [PATCH v3 05/26] KVM: x86 emulator: allow loading null SS in long mode Avi Kivity
2012-06-27 15:24 ` [PATCH v3 06/26] KVM: x86 emulator: fix LIDT/LGDT " Avi Kivity
2012-06-27 15:24 ` [PATCH v3 07/26] KVM: VMX: Relax check on unusable segment Avi Kivity
2012-06-27 15:24 ` [PATCH v3 08/26] KVM: VMX: Limit iterations with emulator_invalid_guest_state Avi Kivity
2012-06-27 15:24 ` [PATCH v3 09/26] KVM: x86 emulator: emulate LEAVE Avi Kivity
2012-06-27 15:24 ` [PATCH v3 10/26] KVM: x86 emulator: initialize memop Avi Kivity
2012-06-27 15:24 ` [PATCH v3 11/26] KVM: Fix SS default ESP/EBP based addressing Avi Kivity
2012-06-27 15:25 ` [PATCH v3 12/26] KVM: x86 emulator: emulate SGDT/SIDT Avi Kivity
2012-06-27 15:25 ` [PATCH v3 13/26] KVM: VMX: Fix interrupt exit condition during emulation Avi Kivity
2012-06-27 15:25 ` [PATCH v3 14/26] KVM: VMX: Continue emulating after batch exhausted Avi Kivity
2012-06-27 15:25 ` [PATCH v3 15/26] KVM: x86 emulator: emulate LAHF Avi Kivity
2012-06-27 15:25 ` [PATCH v3 16/26] KVM: x86 emulator: fix byte-sized MOVZX/MOVSX Avi Kivity
2012-06-27 15:25 ` [PATCH v3 17/26] KVM: x86 emulator: split push logic from push opcode emulation Avi Kivity
2012-06-27 15:25 ` [PATCH v3 18/26] KVM: x86 emulator: implement ENTER Avi Kivity
2012-06-27 15:25 ` [PATCH v3 19/26] KVM: VMX: Stop invalid guest state emulation on pending event Avi Kivity
2012-06-27 15:25 ` [PATCH v3 20/26] KVM: VMX: Improve error reporting during invalid guest state emulation Avi Kivity
2012-06-27 15:25 ` [PATCH v3 21/26] KVM: x86 emulator: emulate BSWAP Avi Kivity
2012-06-27 15:25 ` [PATCH v3 22/26] KVM: x86 emulator: emulate LLDT Avi Kivity
2012-06-27 15:25 ` [PATCH v3 23/26] KVM: x86 emulator: make read_segment_descriptor() return the address Avi Kivity
2012-06-27 15:25 ` [PATCH v3 24/26] KVM: x86 emulator: make loading TR set the busy bit Avi Kivity
2012-06-27 15:25 ` [PATCH v3 25/26] KVM: x86 emulator: implement LTR Avi Kivity
2012-06-27 15:25 ` [PATCH v3 26/26] KVM: VMX: Emulate invalid guest state by default 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=1340810714-19399-2-git-send-email-avi@redhat.com \
    --to=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.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 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.