Re: [PATCH 20/30] KVM: arm64: Introduce hypercall to force reclaim of a protected page

Quentin Perret
2026-01-06T15:44:14Z

> +static int host_stage2_decode_gfn_meta(kvm_pte_t pte, struct pkvm_hyp_vm **vm,
> + u64 *gfn)
> +{
> + pkvm_handle_t handle;
> + u64 meta;
> +
> + if (kvm_pte_valid(pte))
> + return -EINVAL;

Nit:

I can't think of any cases where we'd end up returning -EINVAL here that
isn't indicative of a major problem (e.g taking a stage-2 perm fault we
don't expect) given that we've extensively checked the state of the page
already. Upgrade to WARN()? It's fatal, but the system is unlikely to
make much more progress if we return cleanly anyways, so we might as
well make it obvious where things went wrong.

> + if (FIELD_GET(KVM_INVALID_PTE_OWNER_MASK, pte) != PKVM_ID_GUEST)
> + return -EPERM;
> +
> + meta = FIELD_GET(KVM_INVALID_PTE_EXTRA_MASK, pte);
> + handle = FIELD_GET(KVM_HOST_INVALID_PTE_GUEST_HANDLE_MASK, meta);
> + *vm = get_vm_by_handle(handle);
> + if (!*vm) {
> + /* We probably raced with teardown; try again */
> + return -EAGAIN;
> + }
> +
> + *gfn = FIELD_GET(KVM_HOST_INVALID_PTE_GUEST_GFN_MASK, meta);
> + return 0;
> +}