[RFC PATCH part-3 10/22] pkvm: x86: Initialize MMU/EPT configuration

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Initializes MMU/EPT pgtable cap for pKVM, which is used for later
MMU/EPT pgtable creation.

Signed-off-by: Shaoqin Huang <shaoqin.huang@xxxxxxxxx>
Signed-off-by: Chuanxiao Dong <chuanxiao.dong@xxxxxxxxx>
Signed-off-by: Jason Chen CJ <jason.cj.chen@xxxxxxxxx>
---
 arch/x86/kvm/vmx/pkvm/include/pkvm.h |  3 +++
 arch/x86/kvm/vmx/pkvm/pkvm_host.c    | 21 +++++++++++++++++++--
 2 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kvm/vmx/pkvm/include/pkvm.h b/arch/x86/kvm/vmx/pkvm/include/pkvm.h
index 3b75760b37a3..648b00326e23 100644
--- a/arch/x86/kvm/vmx/pkvm/include/pkvm.h
+++ b/arch/x86/kvm/vmx/pkvm/include/pkvm.h
@@ -45,6 +45,9 @@ struct pkvm_hyp {
 	struct vmx_capability vmx_cap;
 	struct vmcs_config vmcs_config;
 
+	struct pkvm_pgtable_cap mmu_cap;
+	struct pkvm_pgtable_cap ept_cap;
+
 	struct pkvm_pcpu *pcpus[CONFIG_NR_CPUS];
 
 	struct pkvm_host_vm host_vm;
diff --git a/arch/x86/kvm/vmx/pkvm/pkvm_host.c b/arch/x86/kvm/vmx/pkvm/pkvm_host.c
index ea70f3692044..06f90b41a2de 100644
--- a/arch/x86/kvm/vmx/pkvm/pkvm_host.c
+++ b/arch/x86/kvm/vmx/pkvm/pkvm_host.c
@@ -8,6 +8,8 @@
 #include <asm/trapnr.h>
 #include <asm/kvm_pkvm.h>
 
+#include <mmu.h>
+#include <mmu/spte.h>
 #include <pkvm.h>
 #include "pkvm_constants.h"
 
@@ -433,8 +435,23 @@ static __init int pkvm_host_check_and_setup_vmx_cap(struct pkvm_hyp *pkvm)
 	return ret;
 }
 
-static __init int pkvm_init_mmu(void)
+static __init int pkvm_init_mmu(struct pkvm_hyp *pkvm)
 {
+	int pgsz_mask = (1 << PG_LEVEL_2M) | (1 << PG_LEVEL_4K);
+
+	if (boot_cpu_has(X86_FEATURE_GBPAGES))
+		pgsz_mask |= 1 << PG_LEVEL_1G;
+
+	/* record mmu pgtable cap for later mmu pgtable build */
+	pkvm->mmu_cap.level = pgtable_l5_enabled() ? 5 : 4;
+	pkvm->mmu_cap.allowed_pgsz = pgsz_mask;
+	pkvm->mmu_cap.table_prot = (u64)_KERNPG_TABLE_NOENC;
+
+	/* record ept pgtable cap for later ept pgtable build */
+	pkvm->ept_cap.level = pkvm->vmx_cap.ept & VMX_EPT_PAGE_WALK_4_BIT ? 4 : 5;
+	pkvm->ept_cap.allowed_pgsz = pgsz_mask;
+	pkvm->ept_cap.table_prot = VMX_EPT_RWX_MASK;
+
 	/*
 	 * __page_base_offset stores the offset for pkvm
 	 * to translate VA to a PA.
@@ -710,7 +727,7 @@ __init int pkvm_init(void)
 	if (ret)
 		goto out;
 
-	ret = pkvm_init_mmu();
+	ret = pkvm_init_mmu(pkvm);
 	if (ret)
 		goto out;
 
-- 
2.25.1




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux