KVM: x86: Disallow hugepages when memory attributes are mixed
authorChao Peng <chao.p.peng@linux.intel.com>
Fri, 27 Oct 2023 18:22:01 +0000 (11:22 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 14 Nov 2023 13:01:04 +0000 (08:01 -0500)
commit90b4fe17981e155432c4dbc490606d0c2e9c2199
tree1d9820c1105ec89b202bf5812625a3b84fdda9b1
parentee605e31563348f44d2ff0b6b74d33df69dd535c
KVM: x86: Disallow hugepages when memory attributes are mixed

Disallow creating hugepages with mixed memory attributes, e.g. shared
versus private, as mapping a hugepage in this case would allow the guest
to access memory with the wrong attributes, e.g. overlaying private memory
with a shared hugepage.

Tracking whether or not attributes are mixed via the existing
disallow_lpage field, but use the most significant bit in 'disallow_lpage'
to indicate a hugepage has mixed attributes instead using the normal
refcounting.  Whether or not attributes are mixed is binary; either they
are or they aren't.  Attempting to squeeze that info into the refcount is
unnecessarily complex as it would require knowing the previous state of
the mixed count when updating attributes.  Using a flag means KVM just
needs to ensure the current status is reflected in the memslots.

Signed-off-by: Chao Peng <chao.p.peng@linux.intel.com>
Co-developed-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20231027182217.3615211-20-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/mmu/mmu.c
arch/x86/kvm/x86.c