public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Gleb Natapov <gleb@redhat.com>
To: kvm@vger.kernel.org
Cc: mtosatti@redhat.com
Subject: [PATCH 1/9] KVM: VMX: remove special CPL cache access during transition to real mode.
Date: Mon, 21 Jan 2013 15:36:41 +0200	[thread overview]
Message-ID: <1358775409-27555-2-git-send-email-gleb@redhat.com> (raw)
In-Reply-To: <1358775409-27555-1-git-send-email-gleb@redhat.com>

Since vmx_get_cpl() always returns 0 when VCPU is in real mode it is no
longer needed. Also reset CPL cache to zero during transaction to
protected mode since transaction may happen while CS.selectors & 3 != 0,
but in reality CPL is 0.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
---
 arch/x86/kvm/vmx.c |   12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index dd2a85c..9d2ec88 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -2817,6 +2817,10 @@ static void enter_pmode(struct kvm_vcpu *vcpu)
 	fix_pmode_dataseg(vcpu, VCPU_SREG_DS, &vmx->rmode.segs[VCPU_SREG_DS]);
 	fix_pmode_dataseg(vcpu, VCPU_SREG_FS, &vmx->rmode.segs[VCPU_SREG_FS]);
 	fix_pmode_dataseg(vcpu, VCPU_SREG_GS, &vmx->rmode.segs[VCPU_SREG_GS]);
+
+	/* CPL is always 0 when CPU enters protected mode */
+	__set_bit(VCPU_EXREG_CPL, (ulong *)&vcpu->arch.regs_avail);
+	vmx->cpl = 0;
 }
 
 static gva_t rmode_tss_base(struct kvm *kvm)
@@ -3229,14 +3233,6 @@ static int vmx_get_cpl(struct kvm_vcpu *vcpu)
 	    && (kvm_get_rflags(vcpu) & X86_EFLAGS_VM)) /* if virtual 8086 */
 		return 3;
 
-	/*
-	 * 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);
 		vmx->cpl = vmx_read_guest_seg_selector(vmx, VCPU_SREG_CS) & 3;
-- 
1.7.10.4


  reply	other threads:[~2013-01-21 13:36 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-21 13:36 [PATCH 0/9] some more vmx real mode emulation fixes and cleanups Gleb Natapov
2013-01-21 13:36 ` Gleb Natapov [this message]
2013-01-21 13:36 ` [PATCH 2/9] KVM: VMX: reset CPL only on CS register write Gleb Natapov
2013-01-21 13:36 ` [PATCH 3/9] KVM: VMX: if unrestricted guest is enabled vcpu state is always valid Gleb Natapov
2013-01-21 13:36 ` [PATCH 4/9] KVM: VMX: remove hack that disables emulation on vcpu reset/init Gleb Natapov
2013-01-21 13:36 ` [PATCH 5/9] KVM: VMX: skip vmx->rmode.vm86_active check on cr0 write if unrestricted guest is enabled Gleb Natapov
2013-01-21 13:36 ` [PATCH 6/9] KVM: VMX: don't clobber segment AR of unusable segments Gleb Natapov
2013-01-21 13:36 ` [PATCH 7/9] KVM: VMX: rename fix_pmode_dataseg to fix_pmode_seg Gleb Natapov
2013-01-21 13:36 ` [PATCH 8/9] KVM: x86: fix use of uninitialized memory as segment descriptor in emulator Gleb Natapov
2013-01-21 13:36 ` [PATCH 9/9] KVM: VMX: set vmx->emulation_required only when needed Gleb Natapov
2013-01-24  0:39 ` [PATCH 0/9] some more vmx real mode emulation fixes and cleanups Marcelo Tosatti
2013-01-24 23:45 ` Marcelo Tosatti

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=1358775409-27555-2-git-send-email-gleb@redhat.com \
    --to=gleb@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox