linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] kvm: x86/mmu: Use cpuid to determine max gfn
@ 2020-12-03 23:11 Rick Edgecombe
  2020-12-04  0:43 ` Sean Christopherson
  0 siblings, 1 reply; 3+ messages in thread
From: Rick Edgecombe @ 2020-12-03 23:11 UTC (permalink / raw)
  To: pbonzini, seanjc, vkuznets, wanpengli, jmattson, joro, bgardon
  Cc: kvm, linux-kernel, Rick Edgecombe

In the TDP MMU, use shadow_phys_bits to dermine the maximum possible GFN
mapped in the guest for zapping operations. boot_cpu_data.x86_phys_bits
may be reduced in the case of HW features that steal HPA bits for other
purposes. However, this doesn't necessarily reduce GPA space that can be
accessed via TDP. So zap based on a maximum gfn calculated with MAXPHYADDR
retrieved from CPUID. This is already stored in shadow_phys_bits, so use
it instead of x86_phys_bits.

Fixes: faaf05b00aec ("kvm: x86/mmu: Support zapping SPTEs in the TDP MMU")
Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
---
 arch/x86/kvm/mmu/tdp_mmu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c
index ff28a5c6abd6..84c8f06bec26 100644
--- a/arch/x86/kvm/mmu/tdp_mmu.c
+++ b/arch/x86/kvm/mmu/tdp_mmu.c
@@ -66,7 +66,7 @@ static bool zap_gfn_range(struct kvm *kvm, struct kvm_mmu_page *root,
 
 void kvm_tdp_mmu_free_root(struct kvm *kvm, struct kvm_mmu_page *root)
 {
-	gfn_t max_gfn = 1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT);
+	gfn_t max_gfn = 1ULL << (shadow_phys_bits - PAGE_SHIFT);
 
 	lockdep_assert_held(&kvm->mmu_lock);
 
@@ -456,7 +456,7 @@ bool kvm_tdp_mmu_zap_gfn_range(struct kvm *kvm, gfn_t start, gfn_t end)
 
 void kvm_tdp_mmu_zap_all(struct kvm *kvm)
 {
-	gfn_t max_gfn = 1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT);
+	gfn_t max_gfn = 1ULL << (shadow_phys_bits - PAGE_SHIFT);
 	bool flush;
 
 	flush = kvm_tdp_mmu_zap_gfn_range(kvm, 0, max_gfn);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] kvm: x86/mmu: Use cpuid to determine max gfn
  2020-12-03 23:11 [PATCH] kvm: x86/mmu: Use cpuid to determine max gfn Rick Edgecombe
@ 2020-12-04  0:43 ` Sean Christopherson
  2020-12-04  8:48   ` Paolo Bonzini
  0 siblings, 1 reply; 3+ messages in thread
From: Sean Christopherson @ 2020-12-04  0:43 UTC (permalink / raw)
  To: Rick Edgecombe
  Cc: pbonzini, vkuznets, wanpengli, jmattson, joro, bgardon, kvm,
	linux-kernel

On Thu, Dec 03, 2020, Rick Edgecombe wrote:
> In the TDP MMU, use shadow_phys_bits to dermine the maximum possible GFN
> mapped in the guest for zapping operations. boot_cpu_data.x86_phys_bits
> may be reduced in the case of HW features that steal HPA bits for other
> purposes. However, this doesn't necessarily reduce GPA space that can be
> accessed via TDP. So zap based on a maximum gfn calculated with MAXPHYADDR
> retrieved from CPUID. This is already stored in shadow_phys_bits, so use
> it instead of x86_phys_bits.
> 
> Fixes: faaf05b00aec ("kvm: x86/mmu: Support zapping SPTEs in the TDP MMU")
> Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com>

Dang, in hindsight it'd be nice if KVM_CAP_SMALLER_MAXPHYADDR allowed explicitly
setting the max MAXPHYADDR for an entire VM instead of being a simple toggle.
E.g. TDX and SEV-ES likely could also make use of "what's this VM's max GPA?".

Reviewed-by: Sean Christopherson <seanjc@google.com> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] kvm: x86/mmu: Use cpuid to determine max gfn
  2020-12-04  0:43 ` Sean Christopherson
@ 2020-12-04  8:48   ` Paolo Bonzini
  0 siblings, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2020-12-04  8:48 UTC (permalink / raw)
  To: Sean Christopherson, Rick Edgecombe
  Cc: vkuznets, wanpengli, jmattson, joro, bgardon, kvm, linux-kernel

On 04/12/20 01:43, Sean Christopherson wrote:
> On Thu, Dec 03, 2020, Rick Edgecombe wrote:
>> In the TDP MMU, use shadow_phys_bits to dermine the maximum possible GFN
>> mapped in the guest for zapping operations. boot_cpu_data.x86_phys_bits
>> may be reduced in the case of HW features that steal HPA bits for other
>> purposes. However, this doesn't necessarily reduce GPA space that can be
>> accessed via TDP. So zap based on a maximum gfn calculated with MAXPHYADDR
>> retrieved from CPUID. This is already stored in shadow_phys_bits, so use
>> it instead of x86_phys_bits.
>>
>> Fixes: faaf05b00aec ("kvm: x86/mmu: Support zapping SPTEs in the TDP MMU")
>> Signed-off-by: Rick Edgecombe <rick.p.edgecombe@intel.com>
> 
> Dang, in hindsight it'd be nice if KVM_CAP_SMALLER_MAXPHYADDR allowed explicitly
> setting the max MAXPHYADDR for an entire VM instead of being a simple toggle.
> E.g. TDX and SEV-ES likely could also make use of "what's this VM's max GPA?".
> 
> Reviewed-by: Sean Christopherson <seanjc@google.com>
> 

Queued, thanks.

Paolo


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-12-04  8:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-03 23:11 [PATCH] kvm: x86/mmu: Use cpuid to determine max gfn Rick Edgecombe
2020-12-04  0:43 ` Sean Christopherson
2020-12-04  8:48   ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).