path: root/virt/kvm/kvm_main.c
diff options
authorSean Christopherson <sean.j.christopherson@intel.com>2020-01-08 12:24:36 -0800
committerPaolo Bonzini <pbonzini@redhat.com>2020-01-27 20:00:01 +0100
commit005ba37cb89bcc0cf63c2029a41f8db165aeb615 (patch)
tree0d0b3d133dfd012cfe53f548397308a7089da89c /virt/kvm/kvm_main.c
parentKVM: x86/mmu: Enforce max_level on HugeTLB mappings (diff)
mm: thp: KVM: Explicitly check for THP when populating secondary MMU
Add a helper, is_transparent_hugepage(), to explicitly check whether a compound page is a THP and use it when populating KVM's secondary MMU. The explicit check fixes a bug where a remapped compound page, e.g. for an XDP Rx socket, is mapped into a KVM guest and is mistaken for a THP, which results in KVM incorrectly creating a huge page in its secondary MMU. Fixes: 936a5fe6e6148 ("thp: kvm mmu transparent hugepage support") Reported-by: syzbot+c9d1fb51ac9d0d10c39d@syzkaller.appspotmail.com Cc: Andrea Arcangeli <aarcange@redhat.com> Cc: stable@vger.kernel.org Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'virt/kvm/kvm_main.c')
1 files changed, 10 insertions, 0 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index ffec9f427b55..64e9e9d65ed4 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -191,6 +191,16 @@ bool kvm_is_reserved_pfn(kvm_pfn_t pfn)
return true;
+bool kvm_is_transparent_hugepage(kvm_pfn_t pfn)
+ struct page *page = pfn_to_page(pfn);
+ if (!PageTransCompoundMap(page))
+ return false;
+ return is_transparent_hugepage(compound_head(page));
* Switches to specified vcpu, until a matching vcpu_put()