Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp688813ybl; Wed, 4 Dec 2019 09:16:20 -0800 (PST) X-Google-Smtp-Source: APXvYqzstVmqZFdzapcsQYfGyXyQtYqFNmLy0myyciie/NPKDAl8BWfrBEV039Oy4BFT3uoNpOUh X-Received: by 2002:a9d:67c1:: with SMTP id c1mr3251786otn.20.1575479780197; Wed, 04 Dec 2019 09:16:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575479780; cv=none; d=google.com; s=arc-20160816; b=iBRNBgy6tphfALrpA4MYhyZ2ZoD272dfyuBXWiU0XjswBwHPXNCGrPiJCqXzISpvya FiedNuh3ujiTj4uDQ44A5/PPjstxUWSBHL3lV8a7/VQVKC0y//AZNuY002zURZX55QcR KjysB7sAQuKJQRhVtJFsANOcyIeGQHUdoNd6yQ9EXV6gyhmqDmvvDEHov8+x/wIIhNX4 qaFB5eiBy59CFamMMEzh3GT7hlDmWE12/iV+/bD1qoOVCELtwv67rORbq+df1fRrl5we hzhA5HwVDHpBnMnr3QNqJ8tzTyBLope9zK0IhOVivNqkyoC3lv2bbVw59GFaarHYbIQR 8QHw== 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=l2FyUN91fG0ci09IInqwf71UH9S2R/TOlGNMYaLrULw=; b=ThbXdFuvkMYFivQnczX0RT3ezdnnqAaz0dZUXsk+3R5G5S1HV5q/V80tWeHjmxyIlm fmU9XG0B9iNjo8UPEhHkkW1XSnzb+LeJUuaDFw8jhCr3zdTFgX0HRsxGGWovp0HlP6CA PU0G6WishFtT8IubYn+aN6gat9QdBpKlKP4+xLy+Kgo77L+U8bMeBKloqXF2vGnpnD8u jTvQ5Fs6PCLPLedccZRPGj/o1j6BdVwEKULt5tsjFgURWon0rvCVbgsSn72mbXUEmqAs fl+ytKewOkhx09281vF3cEYjdkYzTuv3OVt8h+BTJbmNA98IshgH+sDC6QEewoc2+8VY UR6A== 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 q127si3675579oic.99.2019.12.04.09.16.06; Wed, 04 Dec 2019 09:16:20 -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 S1728328AbfLDPsH (ORCPT + 99 others); Wed, 4 Dec 2019 10:48:07 -0500 Received: from mga12.intel.com ([192.55.52.136]:58121 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727878AbfLDPsH (ORCPT ); Wed, 4 Dec 2019 10:48:07 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 04 Dec 2019 07:48:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,277,1571727600"; d="scan'208";a="262988929" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.41]) by FMSMGA003.fm.intel.com with ESMTP; 04 Dec 2019 07:48:06 -0800 Date: Wed, 4 Dec 2019 07:48:06 -0800 From: Sean Christopherson To: Paolo Bonzini Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, thomas.lendacky@amd.com, stable@vger.kernel.org Subject: Re: [PATCH v2] KVM: x86: use CPUID to locate host page table reserved bits Message-ID: <20191204154806.GC6323@linux.intel.com> References: <1575474037-7903-1-git-send-email-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1575474037-7903-1-git-send-email-pbonzini@redhat.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, Dec 04, 2019 at 04:40:37PM +0100, Paolo Bonzini wrote: > The comment in kvm_get_shadow_phys_bits refers to MKTME, but the same is actually > true of SME and SEV. Just use CPUID[0x8000_0008].EAX[7:0] unconditionally if > available, it is simplest and works even if memory is not encrypted. > > Cc: stable@vger.kernel.org > Reported-by: Tom Lendacky > Signed-off-by: Paolo Bonzini > --- > arch/x86/kvm/mmu/mmu.c | 20 ++++++++++++-------- > 1 file changed, 12 insertions(+), 8 deletions(-) > > diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c > index 6f92b40d798c..1e4ee4f8de5f 100644 > --- a/arch/x86/kvm/mmu/mmu.c > +++ b/arch/x86/kvm/mmu/mmu.c > @@ -538,16 +538,20 @@ void kvm_mmu_set_mask_ptes(u64 user_mask, u64 accessed_mask, > static u8 kvm_get_shadow_phys_bits(void) > { > /* > - * boot_cpu_data.x86_phys_bits is reduced when MKTME is detected > - * in CPU detection code, but MKTME treats those reduced bits as > - * 'keyID' thus they are not reserved bits. Therefore for MKTME > - * we should still return physical address bits reported by CPUID. > + * boot_cpu_data.x86_phys_bits is reduced when MKTME or SME are detected > + * in CPU detection code, but the processor treats those reduced bits as > + * 'keyID' thus they are not reserved bits. Therefore KVM needs to look at > + * the physical address bits reported by CPUID. > */ > - if (!boot_cpu_has(X86_FEATURE_TME) || > - WARN_ON_ONCE(boot_cpu_data.extended_cpuid_level < 0x80000008)) > - return boot_cpu_data.x86_phys_bits; > + if (likely(boot_cpu_data.extended_cpuid_level >= 0x80000008)) > + return cpuid_eax(0x80000008) & 0xff; > > - return cpuid_eax(0x80000008) & 0xff; > + /* > + * Quite weird to have VMX or SVM but not MAXPHYADDR; probably a VM with > + * custom CPUID. Proceed with whatever the kernel found since these features > + * aren't virtualizable (SME/SEV also require CPUIDs higher than 0x80000008). No love for MKTME? :-D Reviewed-by: Sean Christopherson > + */ > + return boot_cpu_data.x86_phys_bits; > } > > static void kvm_mmu_reset_all_pte_masks(void) > -- > 1.8.3.1 >