From e8cf4c06e141d1d676c8fcc3e8e48724242634ef Mon Sep 17 00:00:00 2001 From: Will Deacon Date: Wed, 26 Apr 2023 15:38:32 +0100 Subject: [PATCH] ANDROID: KVM: arm64: Move addr_is_allowed_memory() check into host callback Since host stage-2 mappings are created lazily, we cannot rely on the pte in order to recover the target physical address when checking a host-initiated memory transition. Instead, move the addr_is_allowed_memory() check into the host callback function where it is passed the physical address directly from the walker. Bug: 279739439 Signed-off-by: Will Deacon Change-Id: I84bdc43eded79f1f5e5a489dbc0874604491e5c8 --- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c index ddd14eb489bc..5337bfaf8529 100644 --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c @@ -948,9 +948,6 @@ static int __check_page_state_visitor(u64 addr, u64 end, u32 level, struct check_walk_data *d = arg; kvm_pte_t pte = *ptep; - if (kvm_pte_valid(pte) && !addr_is_allowed_memory(kvm_pte_to_phys(pte))) - return -EINVAL; - return d->get_page_state(pte, addr) == d->desired ? 0 : -EPERM; } @@ -975,6 +972,9 @@ static enum pkvm_page_state host_get_page_state(kvm_pte_t pte, u64 addr) if (is_memory && hyp_phys_to_page(addr)->flags & MODULE_OWNED_PAGE) return PKVM_MODULE_DONT_TOUCH; + if (!addr_is_allowed_memory(addr)) + return PKVM_NOPAGE; + if (!kvm_pte_valid(pte) && pte) return PKVM_NOPAGE;