Re: [PATCH v3 12/18] KVM: arm64: Prevent host PC adjustments for protected vCPUs
From: Fuad Tabba
Date: Mon Sep 14 2026 - 12:56:07 EST
Hi Marc,
On Mon, 14 Sept 2026 at 14:42, Marc Zyngier <maz@xxxxxxxxxx> wrote:
[...]
> nit: it is really odd to see this 'pkvm' prefix in generic code. The
> point of it is not only to abstract the pvkm complexity away, but also
> to have a wrapper that may be of use in other situations.
>
> Don't respin the series just for this though, I may end-up changing
> this when applying it.
Agree, if I respin I'll rename it.
[...]
> > + hyp_vcpu = pkvm_get_loaded_hyp_vcpu();
> > + if (!hyp_vcpu || hyp_vcpu->host_vcpu != vcpu)
>
> Under which circumstances do we get hyp_vcpu->host_vcpu != vcpu?
When EL2 calls __kvm_adjust_pc() on the hyp vCPU itself:
__kvm_vcpu_run() at guest entry and inject_sync64() in nvhe/sys_regs.c
both pass &hyp_vcpu->vcpu. There the vCPU passed is the one to adjust,
so it's returned as is.
> > + if (pkvm_hyp_vcpu_is_protected(hyp_vcpu))
> > + return NULL;
>
> Is it always the case that a protected vcpu cannot see its PC adjusted
> at all? How is PC updated after an exit for MMIO? I feel there is an
> interaction with the above, but I'm not 100% certain...
The host can't adjust it directly, EL2 applies the host's request at
the next entry. For MMIO, handle_pvm_exit_dabt() sets mmio_needed on
the hyp vCPU from EL2's own syndrome, the host completes the access
and kvm_handle_mmio_return() sets INCREMENT_PC on the host copy, and
handle_pvm_entry_dabt() increments the hyp vCPU's PC at the next entry
if EL2 had an MMIO pending, through the &hyp_vcpu->vcpu case above.
The NULL return clears nothing, so the request stays on the host copy
for that entry. It's reached from the epilogue of
kvm_arch_vcpu_ioctl_run(), e.g. an MMIO completed on an immediate_exit
run, and consuming it on the host copy there would clear INCREMENT_PC
before EL2 sees it, so the guest would re-execute the access.
"Drop" in the commit message and the adjust_pc.h comment reads as
losing the request. I'll reword if I respin.
Cheers,
/fuad