lkml.org 
[lkml]   [2019]   [Jul]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v4 8/9] KVM: MMU: Enable Lazy mode SPPT setup
Date
If SPP subpages are set while the physical page are not
available in EPT leaf entry, the mapping is first stored
in SPP access bitmap buffer. SPPT setup is deferred to
access to the protected page, in EPT page fault handler,
the SPPT enries are set up.

Signed-off-by: Yang Weijiang <weijiang.yang@intel.com>
---
arch/x86/kvm/mmu.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)

diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index 419878301375..f017fe6cd67b 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -4304,6 +4304,26 @@ check_hugepage_cache_consistency(struct kvm_vcpu *vcpu, gfn_t gfn, int level)
return kvm_mtrr_check_gfn_range_consistency(vcpu, gfn, page_num);
}

+static int kvm_enable_spp_protection(struct kvm *kvm, u64 gfn)
+{
+ struct kvm_subpage spp_info = {0};
+ struct kvm_memory_slot *slot;
+
+ slot = gfn_to_memslot(kvm, gfn);
+ if (!slot)
+ return -EFAULT;
+
+ spp_info.base_gfn = gfn;
+ spp_info.npages = 1;
+
+ if (kvm_mmu_get_subpages(kvm, &spp_info, true) < 0)
+ return -EFAULT;
+
+ if (spp_info.access_map[0] != FULL_SPP_ACCESS)
+ kvm_mmu_set_subpages(kvm, &spp_info, true);
+
+ return 0;
+}
static int tdp_page_fault(struct kvm_vcpu *vcpu, gva_t gpa, u32 error_code,
bool prefault)
{
@@ -4355,6 +4375,10 @@ static int tdp_page_fault(struct kvm_vcpu *vcpu, gva_t gpa, u32 error_code,
if (likely(!force_pt_level))
transparent_hugepage_adjust(vcpu, &gfn, &pfn, &level);
r = __direct_map(vcpu, write, map_writable, level, gfn, pfn, prefault);
+
+ if (vcpu->kvm->arch.spp_active && level == PT_PAGE_TABLE_LEVEL)
+ kvm_enable_spp_protection(vcpu->kvm, gfn);
+
spin_unlock(&vcpu->kvm->mmu_lock);

return r;
--
2.17.2
\
 
 \ /
  Last update: 2019-07-17 15:37    [W:0.056 / U:0.452 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site