From mboxrd@z Thu Jan 1 00:00:00 1970 From: Marcelo Tosatti Subject: Re: [PATCH] KVM: unbreak userspace that does not sets tss address Date: Fri, 11 Mar 2011 14:30:32 -0300 Message-ID: <20110311173032.GA11111@amt.cnet> References: <20110307151936.GA10151@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: kvm@vger.kernel.org, avi@redhat.com To: Gleb Natapov Return-path: Received: from mx1.redhat.com ([209.132.183.28]:25399 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751465Ab1CKR65 (ORCPT ); Fri, 11 Mar 2011 12:58:57 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p2BHwvwm015883 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 11 Mar 2011 12:58:57 -0500 Content-Disposition: inline In-Reply-To: <20110307151936.GA10151@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: On Mon, Mar 07, 2011 at 05:19:36PM +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 > diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c > index e2b8c6b..280b6ea 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,16 @@ 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"); > + vmx_set_tss_addr(vcpu->kvm, 0xfeffd000); > + } > + > 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)); Should leave/enter srcu section before/after set_memory_region. Actually, for older userspace, isnt the base_gfn + slot[0].npages - 3 address (rmode_tss_base) used? That is, initializing the TSS page at that address at vcpu_reset time should be enough?