[PATCH v6 09/11] KVM: arm64: Select protected VM behaviour by VM flavour

Steven Price steven.price at arm.com
Fri Dec 4 03:57:16 PST 2026


Use the VM flavour when choosing the stage-2 fault lock, fault memory
cache, pre-fault policy and ptdump visibility. This prepares these paths
for Realm VMs, whose stage-2 tables are managed outside the host.

Move the VM flavour helper outside the nVHE guard so the shared
fault-lock helpers can use it.

Signed-off-by: Steven Price <steven.price at arm.com>

---
Changes since v5:
- New patch: select the fault lock, cache, pre-fault policy and
  stage-2 debugfs visibility by VM flavour.
---
 arch/arm64/include/asm/kvm_host.h | 4 ++--
 arch/arm64/include/asm/kvm_mmu.h  | 4 ++--
 arch/arm64/kvm/mmu.c              | 4 ++--
 arch/arm64/kvm/ptdump.c           | 4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index 55673d08e3eb..505c0c5b7dbb 100644
--- a/arch/arm64/include/asm/kvm_host.h
+++ b/arch/arm64/include/asm/kvm_host.h
@@ -1601,12 +1601,12 @@ struct kvm *kvm_arch_alloc_vm(void);
 #define kvm_vm_is_protected(kvm)	((kvm)->arch.vm_flavor >= __VM_PROTECTED)
 #define vcpu_is_protected(vcpu)		kvm_vm_is_protected((vcpu)->kvm)
 
-#define kvm_vm_hyp_is_distrusting(kvm)	((kvm)->arch.vm_flavor >= __VM_DISTRUSTING_HYP)
-
 #endif	/* __KVM_NVHE_HYPERVISOR__ */
 
 #define kvm_vm_is_realm(kvm)		((kvm)->arch.vm_flavor == VM_REALM)
 
+#define kvm_vm_hyp_is_distrusting(kvm)	((kvm)->arch.vm_flavor >= __VM_DISTRUSTING_HYP)
+
 #define kvm_arch_has_private_mem(kvm) kvm_vm_is_realm(kvm)
 
 #define kvm_has_mte(kvm)					\
diff --git a/arch/arm64/include/asm/kvm_mmu.h b/arch/arm64/include/asm/kvm_mmu.h
index 32392abf2e21..a70f8bd4b2b9 100644
--- a/arch/arm64/include/asm/kvm_mmu.h
+++ b/arch/arm64/include/asm/kvm_mmu.h
@@ -371,7 +371,7 @@ static inline bool kvm_is_nested_s2_mmu(struct kvm *kvm, struct kvm_s2_mmu *mmu)
 
 static inline void kvm_fault_lock(struct kvm *kvm)
 {
-	if (is_protected_kvm_enabled())
+	if (kvm_vm_hyp_is_distrusting(kvm))
 		write_lock(&kvm->mmu_lock);
 	else
 		read_lock(&kvm->mmu_lock);
@@ -379,7 +379,7 @@ static inline void kvm_fault_lock(struct kvm *kvm)
 
 static inline void kvm_fault_unlock(struct kvm *kvm)
 {
-	if (is_protected_kvm_enabled())
+	if (kvm_vm_hyp_is_distrusting(kvm))
 		write_unlock(&kvm->mmu_lock);
 	else
 		read_unlock(&kvm->mmu_lock);
diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c
index ce7cea447f58..a1ae89ce3707 100644
--- a/arch/arm64/kvm/mmu.c
+++ b/arch/arm64/kvm/mmu.c
@@ -2317,7 +2317,7 @@ static int user_mem_abort(const struct kvm_s2_fault_desc *s2fd,
 	 */
 	memcache = get_mmu_memcache(s2fd->vcpu);
 	if (!perm_fault || memslot_is_logging(s2fd->memslot) ||
-	    is_protected_kvm_enabled()) {
+	    kvm_vm_hyp_is_distrusting(s2fd->vcpu->kvm)) {
 		ret = topup_mmu_memcache(s2fd->mmu, memcache);
 		if (ret)
 			return ret;
@@ -3136,7 +3136,7 @@ pre_fault_bytes_consumed(gpa_t gpa, unsigned long granule_size,
 
 int kvm_arch_pre_fault_allowed(struct kvm_vcpu *vcpu)
 {
-	if (is_protected_kvm_enabled())
+	if (kvm_vm_hyp_is_distrusting(vcpu->kvm))
 		return -EOPNOTSUPP;
 	if (!kvm_vcpu_initialized(vcpu))
 		return -ENOEXEC;
diff --git a/arch/arm64/kvm/ptdump.c b/arch/arm64/kvm/ptdump.c
index 9f0aebacea5b..ec3acbefa1be 100644
--- a/arch/arm64/kvm/ptdump.c
+++ b/arch/arm64/kvm/ptdump.c
@@ -321,8 +321,8 @@ void kvm_nested_s2_ptdump_create_debugfs(struct kvm_s2_mmu *mmu, int idx)
 
 void kvm_s2_ptdump_create_debugfs(struct kvm *kvm)
 {
-	/* pKVM handles the page-tables in the hypervisor */
-	if (is_protected_kvm_enabled())
+	/* Protected VMs have stage-2 tables outside the host's access. */
+	if (kvm_vm_hyp_is_distrusting(kvm))
 		return;
 
 	debugfs_create_file("stage2_page_tables", 0400, kvm->debugfs_dentry,
-- 
2.43.0




More information about the linux-arm-kernel mailing list