]> git.baikalelectronics.ru Git - kernel.git/commit
KVM: x86: clamp host mapping level to max_level in kvm_mmu_max_mapping_level
authorPaolo Bonzini <pbonzini@redhat.com>
Fri, 6 Aug 2021 11:05:58 +0000 (07:05 -0400)
committerPaolo Bonzini <pbonzini@redhat.com>
Fri, 20 Aug 2021 20:06:41 +0000 (16:06 -0400)
commit1df61c859a541169d63f9d4259592abd58b2c519
treeae9d397e6f5841ac05b194d6aa005c9627776f63
parent4204c070d8729e8f671d05d362aff7af654b2008
KVM: x86: clamp host mapping level to max_level in kvm_mmu_max_mapping_level

This change started as a way to make kvm_mmu_hugepage_adjust a bit simpler,
but it does fix two bugs as well.

One bug is in zapping collapsible PTEs.  If a large page size is
disallowed but not all of them, kvm_mmu_max_mapping_level will return the
host mapping level and the small PTEs will be zapped up to that level.
However, if e.g. 1GB are prohibited, we can still zap 4KB mapping and
preserve the 2MB ones. This can happen for example when NX huge pages
are in use.

The second would happen when userspace backs guest memory
with a 1gb hugepage but only assign a subset of the page to
the guest.  1gb pages would be disallowed by the memslot, but
not 2mb.  kvm_mmu_max_mapping_level() would fall through to the
host_pfn_mapping_level() logic, see the 1gb hugepage, and map the whole
thing into the guest.

Fixes: f67db543bc57 ("KVM: x86/mmu: Persist gfn_lpage_is_disallowed() to max_level")
Cc: stable@vger.kernel.org
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/mmu/mmu.c