提交 22b1d57b 编写于 作者: S Sean Christopherson 提交者: Paolo Bonzini

KVM: x86/mmu: Enforce max_level on HugeTLB mappings

Limit KVM's mapping level for HugeTLB based on its calculated max_level.
The max_level check prior to invoking host_mapping_level() only filters
out the case where KVM cannot create a 2mb mapping, it doesn't handle
the scenario where KVM can create a 2mb but not 1gb mapping, and the
host is using a 1gb HugeTLB mapping.

Fixes: 2f57b705 ("KVM: x86/mmu: Persist gfn_lpage_is_disallowed() to max_level")
Signed-off-by: NSean Christopherson <sean.j.christopherson@intel.com>
Signed-off-by: NPaolo Bonzini <pbonzini@redhat.com>
上级 dc9ce71e
...@@ -1330,7 +1330,7 @@ gfn_to_memslot_dirty_bitmap(struct kvm_vcpu *vcpu, gfn_t gfn, ...@@ -1330,7 +1330,7 @@ gfn_to_memslot_dirty_bitmap(struct kvm_vcpu *vcpu, gfn_t gfn,
static int mapping_level(struct kvm_vcpu *vcpu, gfn_t large_gfn, static int mapping_level(struct kvm_vcpu *vcpu, gfn_t large_gfn,
int *max_levelp) int *max_levelp)
{ {
int max_level = *max_levelp; int host_level, max_level = *max_levelp;
struct kvm_memory_slot *slot; struct kvm_memory_slot *slot;
if (unlikely(max_level == PT_PAGE_TABLE_LEVEL)) if (unlikely(max_level == PT_PAGE_TABLE_LEVEL))
...@@ -1362,7 +1362,8 @@ static int mapping_level(struct kvm_vcpu *vcpu, gfn_t large_gfn, ...@@ -1362,7 +1362,8 @@ static int mapping_level(struct kvm_vcpu *vcpu, gfn_t large_gfn,
* So, do not propagate host_mapping_level() to max_level as KVM can * So, do not propagate host_mapping_level() to max_level as KVM can
* still promote the guest mapping to a huge page in the THP case. * still promote the guest mapping to a huge page in the THP case.
*/ */
return host_mapping_level(vcpu->kvm, large_gfn); host_level = host_mapping_level(vcpu->kvm, large_gfn);
return min(host_level, max_level);
} }
/* /*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册