Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp21952225ybl; Mon, 6 Jan 2020 14:51:32 -0800 (PST) X-Google-Smtp-Source: APXvYqy6b7oagJP73Gy/ezXqDg6jECGXFWGL+2DPpM3girj4x8uVIxrcqh2ZXt9W2DHpceKa1+Nk X-Received: by 2002:a05:6830:1e2d:: with SMTP id t13mr122032717otr.128.1578351092178; Mon, 06 Jan 2020 14:51:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1578351092; cv=none; d=google.com; s=arc-20160816; b=no+ybh0Hq4r+O+izQg9MfzbpJXf6flwzHeYLNyu2qc4Zbh5YHd6o01ROBrYdP8iL4L lDaikrxZ5+d/jYSeFB1hOBxPPgIVy9jZOKtLyELRmccqp+ayaIc/KXI1MWfAmwfiemOX uyL/lL0gyIiiISIqSsQ+RCxMxTfcnbHhDvbJcZPWzyfs3iNrDRe70+CUU/MIQoxSBSnR EX+Wvcp4oBk0dH6odNjo52BLcUkqaXGC1GKsDiuKVZVyHXzRgGfRzQ+FFk17agort3Mi /pmTbTSFwQ8RzRHqDaT9mOAkROQh8G9wh0UvJEya22SP1Oe4L05Q5axVyoPF2LCN9EGX RuGA== 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=7MV3/iQQoPQ+8sQsFJc8kbl1wKOcBsd5b84j63Mz8W0=; b=SWcg00syMGK5AW2Y2F9+Pg/X1ssdW/IuiDB0SRusuSnN506rroHiRJUtmktalXF7fJ e7OgY1ucTSp/1HBGK+hDzbpmn7L9vDwBR/ko9qt/WFJf+mgEKL+fCqNnQ5jPEtgZnOKO 5CHaZVSJkpY6grycEntyrdbBXZWuiBCYjHy2nq1yWRMocJySqIDZ/9+f0VJyNccl/BYA dymCPNcRCbVeqstl3iqxLgN4Ogx7FHg86ia68hHPNQLrmJSHxXvFr8Fvo0zpMXtBk24B ckhBvuJVY6Y6NA+wEBcgWwHPDO1GcfWP+d200irD4c6iqQWguX1VnX0VR7OVEIvcFyim AHMA== 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 t74si3352810oih.155.2020.01.06.14.51.18; Mon, 06 Jan 2020 14:51:32 -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 S1727158AbgAFWtc (ORCPT + 99 others); Mon, 6 Jan 2020 17:49:32 -0500 Received: from mga12.intel.com ([192.55.52.136]:51362 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726721AbgAFWtc (ORCPT ); Mon, 6 Jan 2020 17:49:32 -0500 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Jan 2020 14:49:32 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,403,1571727600"; d="scan'208";a="216958946" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.202]) by fmsmga007.fm.intel.com with ESMTP; 06 Jan 2020 14:49:31 -0800 Date: Mon, 6 Jan 2020 14:49:31 -0800 From: Sean Christopherson To: Tom Lendacky Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Paolo Bonzini , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Brijesh Singh Subject: Re: [PATCH v2] KVM: SVM: Override default MMIO mask if memory encryption is enabled Message-ID: <20200106224931.GB12879@linux.intel.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Fri, Dec 27, 2019 at 09:58:00AM -0600, Tom Lendacky wrote: > The KVM MMIO support uses bit 51 as the reserved bit to cause nested page > faults when a guest performs MMIO. The AMD memory encryption support uses > a CPUID function to define the encryption bit position. Given this, it is > possible that these bits can conflict. > > Use svm_hardware_setup() to override the MMIO mask if memory encryption > support is enabled. When memory encryption support is enabled the physical > address width is reduced and the first bit after the last valid reduced > physical address bit will always be reserved. Use this bit as the MMIO > mask. > > Fixes: 28a1f3ac1d0c ("kvm: x86: Set highest physical address bits in non-present/reserved SPTEs") > Suggested-by: Sean Christopherson > Signed-off-by: Tom Lendacky > --- > arch/x86/kvm/svm.c | 26 ++++++++++++++++++++++++++ > 1 file changed, 26 insertions(+) > > diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c > index 122d4ce3b1ab..2cb834b5982a 100644 > --- a/arch/x86/kvm/svm.c > +++ b/arch/x86/kvm/svm.c > @@ -1361,6 +1361,32 @@ static __init int svm_hardware_setup(void) > } > } > > + /* > + * The default MMIO mask is a single bit (excluding the present bit), > + * which could conflict with the memory encryption bit. Check for > + * memory encryption support and override the default MMIO masks if > + * it is enabled. > + */ > + if (cpuid_eax(0x80000000) >= 0x8000001f) { > + u64 msr, mask; > + > + rdmsrl(MSR_K8_SYSCFG, msr); > + if (msr & MSR_K8_SYSCFG_MEM_ENCRYPT) { > + /* > + * The physical addressing width is reduced. The first > + * bit above the new physical addressing limit will > + * always be reserved. Use this bit and the present bit > + * to generate a page fault with PFER.RSV = 1. > + */ > + mask = BIT_ULL(boot_cpu_data.x86_phys_bits); This doesn't handle the case where x86_phys_bits _isn't_ reduced by SME/SEV on a future processor, i.e. x86_phys_bits==52. After staring at things for a while, I think we can handle this issue with minimal fuss by special casing MKTME in kvm_set_mmio_spte_mask(). I'll send a patch, I have a related bug fix for kvm_set_mmio_spte_mask() that touches the same code. > + mask |= BIT_ULL(0); > + > + kvm_mmu_set_mmio_spte_mask(mask, mask, > + PT_WRITABLE_MASK | > + PT_USER_MASK); > + } > + } > + > for_each_possible_cpu(cpu) { > r = svm_cpu_init(cpu); > if (r) > -- > 2.17.1 >