All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/9] some more vmx real mode emulation fixes and cleanups
@ 2013-01-21 13:36 Gleb Natapov
  2013-01-21 13:36 ` [PATCH 1/9] KVM: VMX: remove special CPL cache access during transition to real mode Gleb Natapov
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: Gleb Natapov @ 2013-01-21 13:36 UTC (permalink / raw)
  To: kvm; +Cc: mtosatti


Gleb Natapov (9):
  KVM: VMX: remove special CPL cache access during transition to real
    mode.
  KVM: VMX: reset CPL only on CS register write.
  KVM: VMX: if unrestricted guest is enabled vcpu state is always
    valid.
  KVM: VMX: remove hack that disables emulation on vcpu reset/init
  KVM: VMX: skip vmx->rmode.vm86_active check on cr0 write if
    unrestricted guest is enabled
  KVM: VMX: don't clobber segment AR of unusable segments.
  KVM: VMX: rename fix_pmode_dataseg to fix_pmode_seg.
  KVM: x86: fix use of uninitialized memory as segment descriptor in
    emulator.
  KVM: VMX: set vmx->emulation_required only when needed.

 arch/x86/kvm/vmx.c |   70 +++++++++++++++++++++++++---------------------------
 arch/x86/kvm/x86.c |    4 ++-
 2 files changed, 37 insertions(+), 37 deletions(-)

-- 
1.7.10.4


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH 1/9] KVM: VMX: remove special CPL cache access during transition to real mode.
  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
  2013-01-21 13:36 ` [PATCH 2/9] KVM: VMX: reset CPL only on CS register write Gleb Natapov
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Gleb Natapov @ 2013-01-21 13:36 UTC (permalink / raw)
  To: kvm; +Cc: mtosatti

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


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 2/9] KVM: VMX: reset CPL only on CS register write.
  2013-01-21 13:36 [PATCH 0/9] some more vmx real mode emulation fixes and cleanups Gleb Natapov
  2013-01-21 13:36 ` [PATCH 1/9] KVM: VMX: remove special CPL cache access during transition to real mode Gleb Natapov
@ 2013-01-21 13:36 ` Gleb Natapov
  2013-01-21 13:36 ` [PATCH 3/9] KVM: VMX: if unrestricted guest is enabled vcpu state is always valid Gleb Natapov
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Gleb Natapov @ 2013-01-21 13:36 UTC (permalink / raw)
  To: kvm; +Cc: mtosatti


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

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 9d2ec88..edfbe94 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -3269,7 +3269,8 @@ static void vmx_set_segment(struct kvm_vcpu *vcpu,
 	const struct kvm_vmx_segment_field *sf = &kvm_vmx_segment_fields[seg];
 
 	vmx_segment_cache_clear(vmx);
-	__clear_bit(VCPU_EXREG_CPL, (ulong *)&vcpu->arch.regs_avail);
+	if (seg == VCPU_SREG_CS)
+		__clear_bit(VCPU_EXREG_CPL, (ulong *)&vcpu->arch.regs_avail);
 
 	if (vmx->rmode.vm86_active && seg != VCPU_SREG_LDTR) {
 		vmx->rmode.segs[seg] = *var;
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 3/9] KVM: VMX: if unrestricted guest is enabled vcpu state is always valid.
  2013-01-21 13:36 [PATCH 0/9] some more vmx real mode emulation fixes and cleanups Gleb Natapov
  2013-01-21 13:36 ` [PATCH 1/9] KVM: VMX: remove special CPL cache access during transition to real mode Gleb Natapov
  2013-01-21 13:36 ` [PATCH 2/9] KVM: VMX: reset CPL only on CS register write Gleb Natapov
@ 2013-01-21 13:36 ` Gleb Natapov
  2013-01-21 13:36 ` [PATCH 4/9] KVM: VMX: remove hack that disables emulation on vcpu reset/init Gleb Natapov
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Gleb Natapov @ 2013-01-21 13:36 UTC (permalink / raw)
  To: kvm; +Cc: mtosatti


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

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index edfbe94..f942b20 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -3488,6 +3488,9 @@ static bool cs_ss_rpl_check(struct kvm_vcpu *vcpu)
  */
 static bool guest_state_valid(struct kvm_vcpu *vcpu)
 {
+	if (enable_unrestricted_guest)
+		return true;
+
 	/* real mode guest state checks */
 	if (!is_protmode(vcpu)) {
 		if (!rmode_segment_valid(vcpu, VCPU_SREG_CS))
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 4/9] KVM: VMX: remove hack that disables emulation on vcpu reset/init
  2013-01-21 13:36 [PATCH 0/9] some more vmx real mode emulation fixes and cleanups Gleb Natapov
                   ` (2 preceding siblings ...)
  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 ` 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
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Gleb Natapov @ 2013-01-21 13:36 UTC (permalink / raw)
  To: kvm; +Cc: mtosatti

There is no reason for it. If state is suitable for vmentry it
will be detected during guest entry and no emulation will happen.

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

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index f942b20..20409bd 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -4035,9 +4035,6 @@ static int vmx_vcpu_reset(struct kvm_vcpu *vcpu)
 
 	ret = 0;
 
-	/* HACK: Don't enable emulation on guest boot/reset */
-	vmx->emulation_required = 0;
-
 	return ret;
 }
 
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 5/9] KVM: VMX: skip vmx->rmode.vm86_active check on cr0 write if unrestricted guest is enabled
  2013-01-21 13:36 [PATCH 0/9] some more vmx real mode emulation fixes and cleanups Gleb Natapov
                   ` (3 preceding siblings ...)
  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 ` Gleb Natapov
  2013-01-21 13:36 ` [PATCH 6/9] KVM: VMX: don't clobber segment AR of unusable segments Gleb Natapov
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Gleb Natapov @ 2013-01-21 13:36 UTC (permalink / raw)
  To: kvm; +Cc: mtosatti

vmx->rmode.vm86_active is never true is unrestricted guest is enabled.
Make it more explicit that neither enter_pmode() nor enter_rmode() is
called in this case.

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

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 20409bd..319e840 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -2877,9 +2877,6 @@ static void enter_rmode(struct kvm_vcpu *vcpu)
 	unsigned long flags;
 	struct vcpu_vmx *vmx = to_vmx(vcpu);
 
-	if (enable_unrestricted_guest)
-		return;
-
 	vmx_get_segment(vcpu, &vmx->rmode.segs[VCPU_SREG_TR], VCPU_SREG_TR);
 	vmx_get_segment(vcpu, &vmx->rmode.segs[VCPU_SREG_ES], VCPU_SREG_ES);
 	vmx_get_segment(vcpu, &vmx->rmode.segs[VCPU_SREG_DS], VCPU_SREG_DS);
@@ -3086,14 +3083,15 @@ static void vmx_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
 	if (enable_unrestricted_guest)
 		hw_cr0 = (cr0 & ~KVM_GUEST_CR0_MASK_UNRESTRICTED_GUEST)
 			| KVM_VM_CR0_ALWAYS_ON_UNRESTRICTED_GUEST;
-	else
+	else {
 		hw_cr0 = (cr0 & ~KVM_GUEST_CR0_MASK) | KVM_VM_CR0_ALWAYS_ON;
 
-	if (vmx->rmode.vm86_active && (cr0 & X86_CR0_PE))
-		enter_pmode(vcpu);
+		if (vmx->rmode.vm86_active && (cr0 & X86_CR0_PE))
+			enter_pmode(vcpu);
 
-	if (!vmx->rmode.vm86_active && !(cr0 & X86_CR0_PE))
-		enter_rmode(vcpu);
+		if (!vmx->rmode.vm86_active && !(cr0 & X86_CR0_PE))
+			enter_rmode(vcpu);
+	}
 
 #ifdef CONFIG_X86_64
 	if (vcpu->arch.efer & EFER_LME) {
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 6/9] KVM: VMX: don't clobber segment AR of unusable segments.
  2013-01-21 13:36 [PATCH 0/9] some more vmx real mode emulation fixes and cleanups Gleb Natapov
                   ` (4 preceding siblings ...)
  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 ` Gleb Natapov
  2013-01-21 13:36 ` [PATCH 7/9] KVM: VMX: rename fix_pmode_dataseg to fix_pmode_seg Gleb Natapov
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Gleb Natapov @ 2013-01-21 13:36 UTC (permalink / raw)
  To: kvm; +Cc: mtosatti

Usability is returned in unusable field, so not need to clobber entire
AR. Callers have to know how to deal with unusable segments already
since if emulate_invalid_guest_state=true AR is not zeroed.

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

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 319e840..77212d1 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -3196,8 +3196,6 @@ static void vmx_get_segment(struct kvm_vcpu *vcpu,
 	var->limit = vmx_read_guest_seg_limit(vmx, seg);
 	var->selector = vmx_read_guest_seg_selector(vmx, seg);
 	ar = vmx_read_guest_seg_ar(vmx, seg);
-	if ((ar & AR_UNUSABLE_MASK) && !emulate_invalid_guest_state)
-		ar = 0;
 	var->type = ar & 15;
 	var->s = (ar >> 4) & 1;
 	var->dpl = (ar >> 5) & 3;
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 7/9] KVM: VMX: rename fix_pmode_dataseg to fix_pmode_seg.
  2013-01-21 13:36 [PATCH 0/9] some more vmx real mode emulation fixes and cleanups Gleb Natapov
                   ` (5 preceding siblings ...)
  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 ` Gleb Natapov
  2013-01-21 13:36 ` [PATCH 8/9] KVM: x86: fix use of uninitialized memory as segment descriptor in emulator Gleb Natapov
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Gleb Natapov @ 2013-01-21 13:36 UTC (permalink / raw)
  To: kvm; +Cc: mtosatti

The function deals with code segment too.

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

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 77212d1..9bc68c7 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -2759,7 +2759,7 @@ static __exit void hardware_unsetup(void)
 	free_kvm_area();
 }
 
-static void fix_pmode_dataseg(struct kvm_vcpu *vcpu, int seg,
+static void fix_pmode_seg(struct kvm_vcpu *vcpu, int seg,
 		struct kvm_segment *save)
 {
 	if (!emulate_invalid_guest_state) {
@@ -2811,12 +2811,12 @@ static void enter_pmode(struct kvm_vcpu *vcpu)
 
 	update_exception_bitmap(vcpu);
 
-	fix_pmode_dataseg(vcpu, VCPU_SREG_CS, &vmx->rmode.segs[VCPU_SREG_CS]);
-	fix_pmode_dataseg(vcpu, VCPU_SREG_SS, &vmx->rmode.segs[VCPU_SREG_SS]);
-	fix_pmode_dataseg(vcpu, VCPU_SREG_ES, &vmx->rmode.segs[VCPU_SREG_ES]);
-	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]);
+	fix_pmode_seg(vcpu, VCPU_SREG_CS, &vmx->rmode.segs[VCPU_SREG_CS]);
+	fix_pmode_seg(vcpu, VCPU_SREG_SS, &vmx->rmode.segs[VCPU_SREG_SS]);
+	fix_pmode_seg(vcpu, VCPU_SREG_ES, &vmx->rmode.segs[VCPU_SREG_ES]);
+	fix_pmode_seg(vcpu, VCPU_SREG_DS, &vmx->rmode.segs[VCPU_SREG_DS]);
+	fix_pmode_seg(vcpu, VCPU_SREG_FS, &vmx->rmode.segs[VCPU_SREG_FS]);
+	fix_pmode_seg(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);
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 8/9] KVM: x86: fix use of uninitialized memory as segment descriptor in emulator.
  2013-01-21 13:36 [PATCH 0/9] some more vmx real mode emulation fixes and cleanups Gleb Natapov
                   ` (6 preceding siblings ...)
  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 ` Gleb Natapov
  2013-01-21 13:36 ` [PATCH 9/9] KVM: VMX: set vmx->emulation_required only when needed Gleb Natapov
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Gleb Natapov @ 2013-01-21 13:36 UTC (permalink / raw)
  To: kvm; +Cc: mtosatti

If VMX reports segment as unusable, zero descriptor passed by the emulator
before returning. Such descriptor will be considered not present by the
emulator.

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

diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 5483228..d8a0e94 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -4489,8 +4489,10 @@ static bool emulator_get_segment(struct x86_emulate_ctxt *ctxt, u16 *selector,
 	kvm_get_segment(emul_to_vcpu(ctxt), &var, seg);
 	*selector = var.selector;
 
-	if (var.unusable)
+	if (var.unusable) {
+		memset(desc, 0, sizeof(*desc));
 		return false;
+	}
 
 	if (var.g)
 		var.limit >>= 12;
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* [PATCH 9/9] KVM: VMX: set vmx->emulation_required only when needed.
  2013-01-21 13:36 [PATCH 0/9] some more vmx real mode emulation fixes and cleanups Gleb Natapov
                   ` (7 preceding siblings ...)
  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 ` 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
  10 siblings, 0 replies; 12+ messages in thread
From: Gleb Natapov @ 2013-01-21 13:36 UTC (permalink / raw)
  To: kvm; +Cc: mtosatti

If emulate_invalid_guest_state=false vmx->emulation_required is never
actually used, but it ends up to be always set to true since
handle_invalid_guest_state(), the only place it is reset back to
false, is never called. This, besides been not very clean, makes vmexit
and vmentry path to check emulate_invalid_guest_state needlessly.

The patch fixes that by keeping emulation_required coherent with
emulate_invalid_guest_state setting.

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

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index 9bc68c7..02eeba8 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -2759,6 +2759,11 @@ static __exit void hardware_unsetup(void)
 	free_kvm_area();
 }
 
+static bool emulation_required(struct kvm_vcpu *vcpu)
+{
+	return emulate_invalid_guest_state && !guest_state_valid(vcpu);
+}
+
 static void fix_pmode_seg(struct kvm_vcpu *vcpu, int seg,
 		struct kvm_segment *save)
 {
@@ -2794,7 +2799,6 @@ static void enter_pmode(struct kvm_vcpu *vcpu)
 	vmx_get_segment(vcpu, &vmx->rmode.segs[VCPU_SREG_SS], VCPU_SREG_SS);
 	vmx_get_segment(vcpu, &vmx->rmode.segs[VCPU_SREG_CS], VCPU_SREG_CS);
 
-	vmx->emulation_required = 1;
 	vmx->rmode.vm86_active = 0;
 
 	vmx_segment_cache_clear(vmx);
@@ -2885,7 +2889,6 @@ static void enter_rmode(struct kvm_vcpu *vcpu)
 	vmx_get_segment(vcpu, &vmx->rmode.segs[VCPU_SREG_SS], VCPU_SREG_SS);
 	vmx_get_segment(vcpu, &vmx->rmode.segs[VCPU_SREG_CS], VCPU_SREG_CS);
 
-	vmx->emulation_required = 1;
 	vmx->rmode.vm86_active = 1;
 
 	/*
@@ -3111,6 +3114,9 @@ static void vmx_set_cr0(struct kvm_vcpu *vcpu, unsigned long cr0)
 	vmcs_writel(CR0_READ_SHADOW, cr0);
 	vmcs_writel(GUEST_CR0, hw_cr0);
 	vcpu->arch.cr0 = cr0;
+
+	/* depends on vcpu->arch.cr0 to be set to a new value */
+	vmx->emulation_required = emulation_required(vcpu);
 }
 
 static u64 construct_eptp(unsigned long root_hpa)
@@ -3298,8 +3304,7 @@ static void vmx_set_segment(struct kvm_vcpu *vcpu,
 	vmcs_write32(sf->ar_bytes, vmx_segment_access_rights(var));
 
 out:
-	if (!vmx->emulation_required)
-		vmx->emulation_required = !guest_state_valid(vcpu);
+	vmx->emulation_required |= emulation_required(vcpu);
 }
 
 static void vmx_get_cs_db_l_bits(struct kvm_vcpu *vcpu, int *db, int *l)
@@ -5027,7 +5032,7 @@ static int handle_invalid_guest_state(struct kvm_vcpu *vcpu)
 			schedule();
 	}
 
-	vmx->emulation_required = !guest_state_valid(vcpu);
+	vmx->emulation_required = emulation_required(vcpu);
 out:
 	return ret;
 }
@@ -5970,7 +5975,7 @@ static int vmx_handle_exit(struct kvm_vcpu *vcpu)
 	u32 vectoring_info = vmx->idt_vectoring_info;
 
 	/* If guest state is invalid, start emulating */
-	if (vmx->emulation_required && emulate_invalid_guest_state)
+	if (vmx->emulation_required)
 		return handle_invalid_guest_state(vcpu);
 
 	/*
@@ -6253,7 +6258,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
 
 	/* Don't enter VMX if guest state is invalid, let the exit handler
 	   start emulation until we arrive back to a valid state */
-	if (vmx->emulation_required && emulate_invalid_guest_state)
+	if (vmx->emulation_required)
 		return;
 
 	if (test_bit(VCPU_REGS_RSP, (unsigned long *)&vcpu->arch.regs_dirty))
-- 
1.7.10.4


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH 0/9] some more vmx real mode emulation fixes and cleanups
  2013-01-21 13:36 [PATCH 0/9] some more vmx real mode emulation fixes and cleanups Gleb Natapov
                   ` (8 preceding siblings ...)
  2013-01-21 13:36 ` [PATCH 9/9] KVM: VMX: set vmx->emulation_required only when needed Gleb Natapov
@ 2013-01-24  0:39 ` Marcelo Tosatti
  2013-01-24 23:45 ` Marcelo Tosatti
  10 siblings, 0 replies; 12+ messages in thread
From: Marcelo Tosatti @ 2013-01-24  0:39 UTC (permalink / raw)
  To: Gleb Natapov; +Cc: kvm

On Mon, Jan 21, 2013 at 03:36:40PM +0200, Gleb Natapov wrote:
> 
> Gleb Natapov (9):
>   KVM: VMX: remove special CPL cache access during transition to real
>     mode.
>   KVM: VMX: reset CPL only on CS register write.
>   KVM: VMX: if unrestricted guest is enabled vcpu state is always
>     valid.
>   KVM: VMX: remove hack that disables emulation on vcpu reset/init
>   KVM: VMX: skip vmx->rmode.vm86_active check on cr0 write if
>     unrestricted guest is enabled
>   KVM: VMX: don't clobber segment AR of unusable segments.
>   KVM: VMX: rename fix_pmode_dataseg to fix_pmode_seg.
>   KVM: x86: fix use of uninitialized memory as segment descriptor in
>     emulator.
>   KVM: VMX: set vmx->emulation_required only when needed.
> 
>  arch/x86/kvm/vmx.c |   70 +++++++++++++++++++++++++---------------------------
>  arch/x86/kvm/x86.c |    4 ++-
>  2 files changed, 37 insertions(+), 37 deletions(-)
> 
> -- 
> 1.7.10.4

Reviewed-by: Marcelo Tosatti <mtosatti@redhat.com>


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH 0/9] some more vmx real mode emulation fixes and cleanups
  2013-01-21 13:36 [PATCH 0/9] some more vmx real mode emulation fixes and cleanups Gleb Natapov
                   ` (9 preceding siblings ...)
  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
  10 siblings, 0 replies; 12+ messages in thread
From: Marcelo Tosatti @ 2013-01-24 23:45 UTC (permalink / raw)
  To: Gleb Natapov; +Cc: kvm

On Mon, Jan 21, 2013 at 03:36:40PM +0200, Gleb Natapov wrote:
> 
> Gleb Natapov (9):
>   KVM: VMX: remove special CPL cache access during transition to real
>     mode.
>   KVM: VMX: reset CPL only on CS register write.
>   KVM: VMX: if unrestricted guest is enabled vcpu state is always
>     valid.
>   KVM: VMX: remove hack that disables emulation on vcpu reset/init
>   KVM: VMX: skip vmx->rmode.vm86_active check on cr0 write if
>     unrestricted guest is enabled
>   KVM: VMX: don't clobber segment AR of unusable segments.
>   KVM: VMX: rename fix_pmode_dataseg to fix_pmode_seg.
>   KVM: x86: fix use of uninitialized memory as segment descriptor in
>     emulator.
>   KVM: VMX: set vmx->emulation_required only when needed.
> 
>  arch/x86/kvm/vmx.c |   70 +++++++++++++++++++++++++---------------------------
>  arch/x86/kvm/x86.c |    4 ++-
>  2 files changed, 37 insertions(+), 37 deletions(-)

Applied, thanks.


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2013-01-25  0:21 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-21 13:36 [PATCH 0/9] some more vmx real mode emulation fixes and cleanups Gleb Natapov
2013-01-21 13:36 ` [PATCH 1/9] KVM: VMX: remove special CPL cache access during transition to real mode Gleb Natapov
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

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.