linux/arch/x86/kvm/mmu
Sean Christopherson 63f5a1909f KVM: x86: Alert userspace that KVM_SET_CPUID{,2} after KVM_RUN is broken
Warn userspace that KVM_SET_CPUID{,2} after KVM_RUN "may" cause guest
instability.  Initialize last_vmentry_cpu to -1 and use it to detect if
the vCPU has been run at least once when its CPUID model is changed.

KVM does not correctly handle changes to paging related settings in the
guest's vCPU model after KVM_RUN, e.g. MAXPHYADDR, GBPAGES, etc...  KVM
could theoretically zap all shadow pages, but actually making that happen
is a mess due to lock inversion (vcpu->mutex is held).  And even then,
updating paging settings on the fly would only work if all vCPUs are
stopped, updated in concert with identical settings, then restarted.

To support running vCPUs with different vCPU models (that affect paging),
KVM would need to track all relevant information in kvm_mmu_page_role.
Note, that's the _page_ role, not the full mmu_role.  Updating mmu_role
isn't sufficient as a vCPU can reuse a shadow page translation that was
created by a vCPU with different settings and thus completely skip the
reserved bit checks (that are tied to CPUID).

Tracking CPUID state in kvm_mmu_page_role is _extremely_ undesirable as
it would require doubling gfn_track from a u16 to a u32, i.e. would
increase KVM's memory footprint by 2 bytes for every 4kb of guest memory.
E.g. MAXPHYADDR (6 bits), GBPAGES, AMD vs. INTEL = 1 bit, and SEV C-BIT
would all need to be tracked.

In practice, there is no remotely sane use case for changing any paging
related CPUID entries on the fly, so just sweep it under the rug (after
yelling at userspace).

Signed-off-by: Sean Christopherson <seanjc@google.com>
Message-Id: <20210622175739.3610207-8-seanjc@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-06-24 18:00:36 -04:00
..
mmu_audit.c KVM: x86/mmu: Use '0' as the one and only value for an invalid PAE root 2021-03-15 04:44:07 -04:00
mmu_internal.h KVM: x86: Support write protecting only large pages 2021-06-17 13:09:25 -04:00
mmu.c KVM: x86: Alert userspace that KVM_SET_CPUID{,2} after KVM_RUN is broken 2021-06-24 18:00:36 -04:00
mmutrace.h kvm: x86/mmu: Add TDP MMU SPTE changed trace point 2020-11-19 10:57:16 -05:00
page_track.c KVM: x86: Support write protecting only large pages 2021-06-17 13:09:25 -04:00
paging_tmpl.h KVM: x86/mmu: Use MMU's role to detect CR4.SMEP value in nested NPT walk 2021-06-24 18:00:35 -04:00
spte.c KVM: x86/mmu: Remove broken WARN that fires on 32-bit KVM w/ nested EPT 2021-06-24 18:00:35 -04:00
spte.h KVM: x86/mmu: Use low available bits for removed SPTEs 2021-03-15 04:43:54 -04:00
tdp_iter.c KVM: x86/mmu: Store the address space ID in the TDP iterator 2021-03-16 14:16:34 -04:00
tdp_iter.h KVM: x86/mmu: Store the address space ID in the TDP iterator 2021-03-16 14:16:34 -04:00
tdp_mmu.c KVM: x86/mmu: Remove redundant root_hpa checks 2021-06-18 06:45:47 -04:00
tdp_mmu.h KVM: x86/mmu: Don't WARN on a NULL shadow page in TDP MMU check 2021-06-24 11:47:56 -04:00