Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7307953imu; Thu, 31 Jan 2019 08:14:11 -0800 (PST) X-Google-Smtp-Source: ALg8bN5vcaPk8Nj9xJ7nKhX8TCGne0E/gIHvzM8UZXRiRnnSX61Vjf+Vbx4yM/hcL9yngNNDCBSB X-Received: by 2002:a63:557:: with SMTP id 84mr31336097pgf.411.1548951251057; Thu, 31 Jan 2019 08:14:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548951251; cv=none; d=google.com; s=arc-20160816; b=FsDLjAQAnhrVr0cIrRBnNBKVbpLMk+2q1MbEivgX+3Ar9OBdkXQAGEnQ5WZxIDrNN9 m59EF5eHAyU7bq8G+zjiWVgEz88StJjm0Nm4afzOOh6X+511Dw7CYthBFiijg4MExjRm YVhI9gc03twfdksuCsC+vN9k79VwIb8lF95GhQ8mgRTHaYgnhdF8eXnOzw5cSvh2ijls q3KhOedeCT+RzrumF3wih8T6GzyXMgwbLsLwDMJm29/eVIZ1wWGcf6j/Fei9c0+ywenG GTQ15QLmFmMthq9FjxziEZq/UCGbSYWvJDkYTj+1D67GMG8/ClLc5RloCWLffa0QES+5 N/Uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:message-id:date :subject:cc:to:from; bh=529x8eWTFMBt2weWwA++iwySxJydyG48g0YlIdC0PnE=; b=QCAVXSSAlkQYXhCqFvNzGgFlnPT9F8b+WnXVofO6RycXNz84yz+kxbjXNGlt2CRLq7 C/D8sWBdtPu7OeNsgxlYPKJ1V4dqnIT9jGmSBFkOSf7qtDueWCCDEBvn9rzLZORcwone w9rb6BsphBq26jT8+4EAwpR+TP8iNm5hhbAMQ5kvnKG03ZKjKviZ6ubu/9nzg7hsYAEM Bh8KmueM/K5ohdE0k2pfdNVPe8qsczoIp0iTaokmHacjm67c9ozUA5n77SzqAAKqthqf TjBZkUxpaSCmtsI9osB6mv9svMeWjrNt9f0NOGwRVf4rLtyUfEpcN0rRQtAPaw4VPQxe UEPQ== 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 f13si5167991plm.393.2019.01.31.08.13.54; Thu, 31 Jan 2019 08:14:11 -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 S2388175AbfAaQN3 (ORCPT + 99 others); Thu, 31 Jan 2019 11:13:29 -0500 Received: from mga12.intel.com ([192.55.52.136]:63027 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388109AbfAaQN3 (ORCPT ); Thu, 31 Jan 2019 11:13:29 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Jan 2019 08:13:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,545,1539673200"; d="scan'208";a="130485182" Received: from zhangyu-optiplex-9020.bj.intel.com ([10.238.135.159]) by orsmga002.jf.intel.com with ESMTP; 31 Jan 2019 08:13:26 -0800 From: Yu Zhang To: kvm@vger.kernel.org Cc: Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , linux-kernel@vger.kernel.org Subject: [PATCH] KVM: MMU: record maximum physical address width in kvm_mmu_extended_role Date: Fri, 1 Feb 2019 00:09:23 +0800 Message-Id: <1548950963-18414-1-git-send-email-yu.c.zhang@linux.intel.com> X-Mailer: git-send-email 1.9.1 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Previously, commit 7dcd57552008 ("x86/kvm/mmu: check if tdp/shadow MMU reconfiguration is needed") offered some optimization to avoid the unnecessary reconfiguration. Yet one scenario is broken - when cpuid changes VM's maximum physical address width, reconfiguration is needed to reset the reserved bits. Also, the TDP may need to reset its shadow_root_level when this value is changed. To fix this, a new field, maxphyaddr, is introduced in the extended role structure to keep track of the configured guest physical address width. Signed-off-by: Yu Zhang --- Cc: Paolo Bonzini Cc: "Radim Krčmář" Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: "H. Peter Anvin" Cc: linux-kernel@vger.kernel.org --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/mmu.c | 1 + 2 files changed, 2 insertions(+) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 4660ce9..be87f71 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -299,6 +299,7 @@ struct kvm_mmu_memory_cache { unsigned int cr4_smap:1; unsigned int cr4_smep:1; unsigned int cr4_la57:1; + unsigned int maxphyaddr:6; }; }; diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index ce770b4..2b74505 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -4769,6 +4769,7 @@ static union kvm_mmu_extended_role kvm_calc_mmu_role_ext(struct kvm_vcpu *vcpu) ext.cr4_pse = !!is_pse(vcpu); ext.cr4_pke = !!kvm_read_cr4_bits(vcpu, X86_CR4_PKE); ext.cr4_la57 = !!kvm_read_cr4_bits(vcpu, X86_CR4_LA57); + ext.maxphyaddr = cpuid_maxphyaddr(vcpu); ext.valid = 1; -- 1.9.1