public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCHv2] KVM: unbreak userspace that does not sets tss address
@ 2011-03-13 10:34 Gleb Natapov
  2011-03-16 18:30 ` Marcelo Tosatti
  0 siblings, 1 reply; 2+ messages in thread
From: Gleb Natapov @ 2011-03-13 10:34 UTC (permalink / raw)
  To: kvm; +Cc: avi, mtosatti

Commit 6440e5967bc broke old userspaces that do not set tss address
before entering vcpu. Unbreak it by setting tss address to a safe
value on the first vcpu entry. New userspaces should set tss address,
so print warning in case it doesn't.

Signed-off-by: Gleb Natapov <gleb@redhat.com>
---

v1->v2
 - Drop srcu lock during memory slots update.

diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
index d8475a2..5b4cdcb 100644
--- a/arch/x86/kvm/vmx.c
+++ b/arch/x86/kvm/vmx.c
@@ -180,6 +180,7 @@ static u64 construct_eptp(unsigned long root_hpa);
 static void kvm_cpu_vmxon(u64 addr);
 static void kvm_cpu_vmxoff(void);
 static void vmx_set_cr3(struct kvm_vcpu *vcpu, unsigned long cr3);
+static int vmx_set_tss_addr(struct kvm *kvm, unsigned int addr);
 
 static DEFINE_PER_CPU(struct vmcs *, vmxarea);
 static DEFINE_PER_CPU(struct vmcs *, current_vmcs);
@@ -1762,6 +1763,18 @@ static void enter_rmode(struct kvm_vcpu *vcpu)
 	vmx->emulation_required = 1;
 	vmx->rmode.vm86_active = 1;
 
+	/*
+	 * Very old userspace does not call KVM_SET_TSS_ADDR before entering
+	 * vcpu. Call it here with phys address pointing 16M below 4G.
+	 */
+	if (!vcpu->kvm->arch.tss_addr) {
+		printk_once(KERN_WARNING "kvm: KVM_SET_TSS_ADDR need to be "
+			     "called before entering vcpu\n");
+		srcu_read_unlock(&vcpu->kvm->srcu, vcpu->srcu_idx);
+		vmx_set_tss_addr(vcpu->kvm, 0xfeffd000);
+		vcpu->srcu_idx = srcu_read_lock(&vcpu->kvm->srcu);
+	}
+
 	vmx->rmode.tr.selector = vmcs_read16(GUEST_TR_SELECTOR);
 	vmx->rmode.tr.base = vmcs_readl(GUEST_TR_BASE);
 	vmcs_writel(GUEST_TR_BASE, rmode_tss_base(vcpu->kvm));
--
			Gleb.

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

* Re: [PATCHv2] KVM: unbreak userspace that does not sets tss address
  2011-03-13 10:34 [PATCHv2] KVM: unbreak userspace that does not sets tss address Gleb Natapov
@ 2011-03-16 18:30 ` Marcelo Tosatti
  0 siblings, 0 replies; 2+ messages in thread
From: Marcelo Tosatti @ 2011-03-16 18:30 UTC (permalink / raw)
  To: Gleb Natapov; +Cc: kvm, avi

On Sun, Mar 13, 2011 at 12:34:27PM +0200, Gleb Natapov wrote:
> Commit 6440e5967bc broke old userspaces that do not set tss address
> before entering vcpu. Unbreak it by setting tss address to a safe
> value on the first vcpu entry. New userspaces should set tss address,
> so print warning in case it doesn't.
> 
> Signed-off-by: Gleb Natapov <gleb@redhat.com>

Applied, thanks.


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

end of thread, other threads:[~2011-03-16 19:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-13 10:34 [PATCHv2] KVM: unbreak userspace that does not sets tss address Gleb Natapov
2011-03-16 18:30 ` Marcelo Tosatti

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox