From 6f6f0a51cb73aa25b3c5777796ec4e23e8d64dd3 Mon Sep 17 00:00:00 2001 From: Maxim Levitsky Date: Sat, 13 Feb 2021 18:04:04 +0200 Subject: [PATCH 01/16] KVM: x86: mmu: add strict mmu mode Signed-off-by: Maxim Levitsky --- arch/x86/kvm/mmu/mmu.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 112b221e1e6a9d..a1130daa5a9356 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -91,6 +91,10 @@ __MODULE_PARM_TYPE(nx_huge_pages_recovery_period_ms, "uint"); static bool __read_mostly force_flush_and_sync_on_reuse; module_param_named(flush_on_reuse, force_flush_and_sync_on_reuse, bool, 0644); + +bool strict_mmu; +module_param(strict_mmu, bool, 0644); + /* * When setting this variable to true it enables Two-Dimensional-Paging * where the hardware walks 2 page tables: @@ -2716,7 +2720,7 @@ static int mmu_set_spte(struct kvm_vcpu *vcpu, struct kvm_memory_slot *slot, } wrprot = make_spte(vcpu, sp, slot, pte_access, gfn, pfn, *sptep, prefetch, - true, host_writable, &spte); + !strict_mmu, host_writable, &spte); if (*sptep == spte) { ret = RET_PF_SPURIOUS; @@ -5125,6 +5129,9 @@ static u64 mmu_pte_write_fetch_gpte(struct kvm_vcpu *vcpu, gpa_t *gpa, */ static bool detect_write_flooding(struct kvm_mmu_page *sp) { + /* In strict mmu case we don't unsync pages ever */ + if (strict_mmu) + return true; /* * Skip write-flooding detected for the sp whose level is 1, because * it can become unsync, then the guest page is not write-protected. -- 2.26.3