From: sashiko-bot@kernel.org
To: "Fuad Tabba" <tabba@google.com>
Cc: kvmarm@lists.linux.dev, "Oliver Upton" <oupton@kernel.org>,
"Marc Zyngier" <maz@kernel.org>
Subject: Re: [PATCH v2 8/8] KVM: arm64: Implement lazy vCPU state sync for non-protected guests
Date: Fri, 19 Jun 2026 07:28:26 +0000 [thread overview]
Message-ID: <20260619072826.A4AB91F00A3D@smtp.kernel.org> (raw)
In-Reply-To: <20260619070719.812227-9-tabba@google.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Dropped register updates for non-protected guests due to missing PKVM_HOST_STATE_DIRTY flag.
- [High] Missing HCR_EL2 sync on guest exit causes an infinite loop of virtual SError injections.
--
commit b6999f3ffe5ca70d542b029d1a2d4a9e5e9d8276
Author: Fuad Tabba <tabba@google.com>
KVM: arm64: Implement lazy vCPU state sync for non-protected guests
This commit defers copying a non-protected guest's register context between
the host and hypervisor. It introduces a PKVM_HOST_STATE_DIRTY flag to only
sync the state when modified by the host.
> diff --git a/arch/arm64/kvm/handle_exit.c b/arch/arm64/kvm/handle_exit.c
> --- a/arch/arm64/kvm/handle_exit.c
> +++ b/arch/arm64/kvm/handle_exit.c
[ ... ]
> @@ -489,6 +503,22 @@ int handle_exit(struct kvm_vcpu *vcpu, int exception_index)
> /* For exit types that need handling before we can be preempted */
> void handle_exit_early(struct kvm_vcpu *vcpu, int exception_index)
> {
> + bool inject_serror = ARM_SERROR_PENDING(exception_index) ||
> + ARM_EXCEPTION_CODE(exception_index) == ARM_EXCEPTION_EL1_SERROR;
> +
> + /*
> + * An SError injected below writes the host ctxt; for a non-protected
> + * guest, sync from the hyp vCPU and keep it dirty so it isn't dropped.
> + */
> + if (is_protected_kvm_enabled()) {
> + vcpu_clear_flag(vcpu, PKVM_HOST_STATE_DIRTY);
[Severity: High]
Does unconditionally clearing this flag on every exit drop register updates
for non-trap exits?
For non-trap exits like ARM_EXCEPTION_IRQ or ARM_EXCEPTION_IL,
handle_trap_exceptions() will not be called to set the flag again.
If an asynchronous request like KVM_REQ_VCPU_RESET (triggered by PSCI CPU_ON)
modifies the host vcpu->arch.ctxt in the kvm_arch_vcpu_ioctl_run() loop, or
if an undefined exception is injected via handle_exit(), flush_hyp_vcpu()
will skip copying these updates because the dirty flag is clear.
Could this cause the guest to resume execution from its old pc with stale
state?
> diff --git a/arch/arm64/kvm/hyp/nvhe/hyp-main.c b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
> --- a/arch/arm64/kvm/hyp/nvhe/hyp-main.c
> +++ b/arch/arm64/kvm/hyp/nvhe/hyp-main.c
[ ... ]
> @@ -203,9 +255,13 @@ static void sync_hyp_vcpu(struct pkvm_hyp_vcpu *hyp_vcpu)
> fpsimd_sve_sync(&hyp_vcpu->vcpu);
> sync_debug_state(hyp_vcpu);
>
> - host_vcpu->arch.ctxt = hyp_vcpu->vcpu.arch.ctxt;
> -
> - host_vcpu->arch.hcr_el2 = hyp_vcpu->vcpu.arch.hcr_el2;
[Severity: High]
Does removing the hcr_el2 sync cause an infinite loop of virtual SError
injections?
To inject a virtual SError, the host sets HCR_VSE in host_vcpu->arch.hcr_el2.
When the guest takes the SError, the hardware clears the VSE bit, which is
captured in hyp_vcpu->vcpu.arch.hcr_el2 on exit.
Since this patch removes the copy-back of hcr_el2 to the host for both
protected and non-protected guests, the host's HCR_VSE bit remains set
permanently.
Will this cause flush_hyp_vcpu() to endlessly re-inject the SError on every
subsequent entry?
> + if (pkvm_hyp_vcpu_is_protected(hyp_vcpu)) {
> + host_vcpu->arch.ctxt = hyp_vcpu->vcpu.arch.ctxt;
> + } else {
> + /* Keep PC (tracepoint) and PSTATE (vcpu_mode_is_bad_32bit) current. */
> + host_vcpu->arch.ctxt.regs.pc = hyp_vcpu->vcpu.arch.ctxt.regs.pc;
> + host_vcpu->arch.ctxt.regs.pstate = hyp_vcpu->vcpu.arch.ctxt.regs.pstate;
> + }
>
> host_vcpu->arch.fault = hyp_vcpu->vcpu.arch.fault;
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260619070719.812227-1-tabba@google.com?part=8
next prev parent reply other threads:[~2026-06-19 7:28 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-19 7:07 [PATCH v2 0/8] KVM: arm64: Rework pKVM vCPU state synchronisation Fuad Tabba
2026-06-19 7:07 ` [PATCH v2 1/8] KVM: arm64: Extract MPIDR computation into a shared header Fuad Tabba
2026-06-19 13:24 ` Vincent Donnefort
2026-06-19 7:07 ` [PATCH v2 2/8] KVM: arm64: Make vcpu_{read,write}_sys_reg available to HYP code Fuad Tabba
2026-06-19 13:26 ` Vincent Donnefort
2026-06-19 7:07 ` [PATCH v2 3/8] KVM: arm64: Factor out reusable vCPU reset helpers Fuad Tabba
2026-06-19 13:29 ` Vincent Donnefort
2026-06-19 7:07 ` [PATCH v2 4/8] KVM: arm64: Move PSCI helper functions to a shared header Fuad Tabba
2026-06-19 13:30 ` Vincent Donnefort
2026-06-19 7:07 ` [PATCH v2 5/8] KVM: arm64: Add host and hypervisor vCPU lookup primitives Fuad Tabba
2026-06-19 13:31 ` Vincent Donnefort
2026-06-19 7:07 ` [PATCH v2 6/8] KVM: arm64: Minimise EL2's exposure of host VGIC state during world switch Fuad Tabba
2026-06-19 7:25 ` sashiko-bot
2026-06-19 7:38 ` Fuad Tabba
2026-06-19 7:07 ` [PATCH v2 7/8] KVM: arm64: Add primitives to flush/sync the VGIC state at EL2 Fuad Tabba
2026-06-19 7:21 ` sashiko-bot
2026-06-19 7:41 ` Marc Zyngier
2026-06-19 7:45 ` Fuad Tabba
2026-06-19 7:07 ` [PATCH v2 8/8] KVM: arm64: Implement lazy vCPU state sync for non-protected guests Fuad Tabba
2026-06-19 7:28 ` sashiko-bot [this message]
2026-06-19 7:54 ` Fuad Tabba
2026-06-19 13:12 ` Vincent Donnefort
2026-06-19 16:41 ` Fuad Tabba
2026-06-22 8:49 ` Vincent Donnefort
2026-06-22 10:14 ` Fuad Tabba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260619072826.A4AB91F00A3D@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=maz@kernel.org \
--cc=oupton@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tabba@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox