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 <willdeacon@google.com>
Change-Id: I84bdc43eded79f1f5e5a489dbc0874604491e5c8
This commit is contained in:
Will Deacon
2023-04-26 15:38:32 +01:00
parent bad74575a1
commit e8cf4c06e1

View File

@@ -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;