Skip to content

Commit 43c4755

Browse files
Quentin PerretMarc Zyngier
authored andcommitted
KVM: arm64: Unconditionally cross check hyp state
Now that the hypervisor's state is stored in the hyp_vmemmap, we no longer need an expensive page-table walk to read it. This means we can now afford to cross check the hyp-state during all memory ownership transitions where the hyp is involved unconditionally, hence avoiding problems such as [1]. [1] https://lore.kernel.org/kvmarm/20241128154406.602875-1-qperret@google.com/ Reviewed-by: Marc Zyngier <maz@kernel.org> Signed-off-by: Quentin Perret <qperret@google.com> Link: https://lore.kernel.org/r/20250416152648.2982950-8-qperret@google.com Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent 48d8488 commit 43c4755

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

arch/arm64/kvm/hyp/nvhe/mem_protect.c

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -702,11 +702,9 @@ int __pkvm_host_share_hyp(u64 pfn)
702702
ret = __host_check_page_state_range(phys, size, PKVM_PAGE_OWNED);
703703
if (ret)
704704
goto unlock;
705-
if (IS_ENABLED(CONFIG_NVHE_EL2_DEBUG)) {
706-
ret = __hyp_check_page_state_range(phys, size, PKVM_NOPAGE);
707-
if (ret)
708-
goto unlock;
709-
}
705+
ret = __hyp_check_page_state_range(phys, size, PKVM_NOPAGE);
706+
if (ret)
707+
goto unlock;
710708

711709
__hyp_set_page_state_range(phys, size, PKVM_PAGE_SHARED_BORROWED);
712710
WARN_ON(__host_set_page_state_range(phys, size, PKVM_PAGE_SHARED_OWNED));
@@ -762,11 +760,9 @@ int __pkvm_host_donate_hyp(u64 pfn, u64 nr_pages)
762760
ret = __host_check_page_state_range(phys, size, PKVM_PAGE_OWNED);
763761
if (ret)
764762
goto unlock;
765-
if (IS_ENABLED(CONFIG_NVHE_EL2_DEBUG)) {
766-
ret = __hyp_check_page_state_range(phys, size, PKVM_NOPAGE);
767-
if (ret)
768-
goto unlock;
769-
}
763+
ret = __hyp_check_page_state_range(phys, size, PKVM_NOPAGE);
764+
if (ret)
765+
goto unlock;
770766

771767
__hyp_set_page_state_range(phys, size, PKVM_PAGE_OWNED);
772768
WARN_ON(pkvm_create_mappings_locked(virt, virt + size, PAGE_HYP));
@@ -792,11 +788,9 @@ int __pkvm_hyp_donate_host(u64 pfn, u64 nr_pages)
792788
ret = __hyp_check_page_state_range(phys, size, PKVM_PAGE_OWNED);
793789
if (ret)
794790
goto unlock;
795-
if (IS_ENABLED(CONFIG_NVHE_EL2_DEBUG)) {
796-
ret = __host_check_page_state_range(phys, size, PKVM_NOPAGE);
797-
if (ret)
798-
goto unlock;
799-
}
791+
ret = __host_check_page_state_range(phys, size, PKVM_NOPAGE);
792+
if (ret)
793+
goto unlock;
800794

801795
__hyp_set_page_state_range(phys, size, PKVM_NOPAGE);
802796
WARN_ON(kvm_pgtable_hyp_unmap(&pkvm_pgtable, virt, size) != size);

0 commit comments

Comments
 (0)