Received: by 2002:ac0:a679:0:0:0:0:0 with SMTP id p54csp1052940imp; Thu, 21 Feb 2019 17:31:12 -0800 (PST) X-Google-Smtp-Source: AHgI3IY77qog3aETRfOFnRuo7zJYPey3K4YLSN7KPJmaOBdEOHyRGI9QNCndQtBc1sOBUINVpeLg X-Received: by 2002:a63:fa10:: with SMTP id y16mr1434970pgh.88.1550799072775; Thu, 21 Feb 2019 17:31:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550799072; cv=none; d=google.com; s=arc-20160816; b=davY9qIh5CSEd6QtcDK3erEqu7izgQbC10tSrvv3SuHqUdm82aCEd6ZY+Z/3Wmn7/T mJIeHo3+r1hH31Ov8g1PkAm2NLE11ywOwNcE+fpJGzz7R0mXEQ/Mh7nj9oU3jzgNOA4P NagnjGlD7GtuC1XL8ZRalUNtk+F8DAotD0bAnfqgBRWzPLR1OuZ/0gxLWVuUpfwo9wQR X6GxkHpc8GrEpd5NubKchbGYSu6Uoy7X+7jYc2Y0vLmBqaAJLJfn4kSGVjRc0A7lfpNs 3d7YT/HvSKyqNAGjGcFvd2QsnUjXUzJWQw3TlS/2nq+5VO8iGg3XLLk9WjkYg4qdZk/h n06Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=eYNgiypBtmSuT7wK/mMCjLNfmV6y5uKvUksPp0Zz7lU=; b=n/jJ9kiwaelhqjunfsSmLPRQNsGwPxClQQRmPC4/5pLgJhYpo+yFUROMuseMyN1fRa SqTx/Xx32fYHMvbtoS5B+Ze+c5vGaeTuQ1/jV0al5orc8Ck7X/uPNR9aTXEbN5F3vjZ6 d7d/D/iqOe/cHDr7AOIlviYTDOqxE6NNAMCV4y6ZCZ7blosd4j52392K+17uf0d1NXFA hV7HeDXevTybI7cb2/sfoNn3uYwgIpyL7JEM+DRJ6BA7Lthx4yyDuy4Er+LvqR78Stha N2FQ849XhaEdwID2ik4c1QZtbPArG3381fhRTwnScmCRjEeTkZ2CowIyXwjI67U3eGaa /ErA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j132si80626pfc.84.2019.02.21.17.30.56; Thu, 21 Feb 2019 17:31:12 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726668AbfBVBaP (ORCPT + 99 others); Thu, 21 Feb 2019 20:30:15 -0500 Received: from mga14.intel.com ([192.55.52.115]:8835 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725869AbfBVBaO (ORCPT ); Thu, 21 Feb 2019 20:30:14 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Feb 2019 17:30:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.58,397,1544515200"; d="scan'208";a="124292397" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.181]) by fmsmga007.fm.intel.com with ESMTP; 21 Feb 2019 17:30:10 -0800 Date: Thu, 21 Feb 2019 17:30:10 -0800 From: Sean Christopherson To: Joao Martins Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Ankur Arora , Boris Ostrovsky , Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org Subject: Re: [PATCH RFC 01/39] KVM: x86: fix Xen hypercall page msr handling Message-ID: <20190222013008.GG7224@linux.intel.com> References: <20190220201609.28290-1-joao.m.martins@oracle.com> <20190220201609.28290-2-joao.m.martins@oracle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190220201609.28290-2-joao.m.martins@oracle.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 20, 2019 at 08:15:31PM +0000, Joao Martins wrote: > Xen usually places its MSR at 0x4000000 or 0x4000200 depending on > whether it is running in viridian mode or not. Note that this is not > ABI guaranteed, so it is possible for Xen to advertise the MSR some > place else. > > Given the way xen_hvm_config() is handled, if the former address is > selected, this will conflict with HyperV's MSR > (HV_X64_MSR_GUEST_OS_ID) which uses the same address. Unconditionally servicing Hyper-V and KVM MSRs seems wrong, i.e. KVM should only expose MSRs specific to a hypervisor if userspace has configured CPUID to advertise support for said hypervisor. If we do the same thing for Xen, then the common MSR code looks like: if (kvm_advertise_kvm()) { if () return ...; } else if (kvm_advertise_hyperv()) { if () return ...; } else if (kvm_advertise_xen()) { if () return ...; } Obviously assumes KVM only advertises itself as one hypervisor, and so the ordering is arbitrary. > Given that the MSR location is arbitrary, move the xen_hvm_config() > handling to the top of kvm_set_msr_common() before falling through. > Signed-off-by: Joao Martins > --- > arch/x86/kvm/x86.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 65e4559eef2f..47360a4b0d42 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -2429,6 +2429,9 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) > u32 msr = msr_info->index; > u64 data = msr_info->data; > > + if (msr && (msr == vcpu->kvm->arch.xen_hvm_config.msr)) > + return xen_hvm_config(vcpu, data); > + > switch (msr) { > case MSR_AMD64_NB_CFG: > case MSR_IA32_UCODE_WRITE: > @@ -2644,8 +2647,6 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) > vcpu->arch.msr_misc_features_enables = data; > break; > default: > - if (msr && (msr == vcpu->kvm->arch.xen_hvm_config.msr)) > - return xen_hvm_config(vcpu, data); > if (kvm_pmu_is_valid_msr(vcpu, msr)) > return kvm_pmu_set_msr(vcpu, msr_info); > if (!ignore_msrs) { > -- > 2.11.0 >