All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Marc Zyngier" <maz@kernel.org>
Cc: "Oliver Upton" <oupton@kernel.org>,
	"Marc Zyngier" <maz@kernel.org>,
	kvmarm@lists.linux.dev
Subject: Re: [PATCH 3/3] KVM: arm64: vgic: Stop the VM when disabling LPIs
Date: Tue, 22 Sep 2026 22:01:25 +0000	[thread overview]
Message-ID: <20260922220125.91CC01F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260922214212.3327146-4-maz@kernel.org>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] kvm: arm64: vgic: race in vcpu->arch.pause unpause due to missing VM lock
- [High] kvm: arm64: vgic: stale LR state during vgic_flush_pending_lpis()
--

commit 81f0f5ee375a1e011fabe86a70b81c8175c5fd88
Author: Marc Zyngier <maz@kernel.org>

KVM: arm64: vgic: Stop the VM when disabling LPIs

Disabling LPIs modifies the AP list of the affected CPU, which could be
running. This commit aims to safely manipulate the state by pausing all
vCPUs so they are in a quiescent state when disabling LPIs.

> diff --git a/arch/arm64/kvm/vgic/vgic-mmio-v3.c b/arch/arm64/kvm/vgic/vgic-mmio-v3.c
> index 5913a20d83019..adefc42964732 100644
> --- a/arch/arm64/kvm/vgic/vgic-mmio-v3.c
> +++ b/arch/arm64/kvm/vgic/vgic-mmio-v3.c
> @@ -303,9 +303,19 @@ static void vgic_mmio_write_v3r_ctlr(struct kvm_vcpu *vcpu,
>  		if (ctlr != GICR_CTLR_ENABLE_LPIS)
>  			return;
>  
> +		/*
> +		 * Yes, disabling LPIs is painful, since it can be done from
> +		 * a *remote* vcpu! So let's not take any chance, and make
> +		 * sure that everybody has written their LRs back to the irq
> +		 * structures, and release any reference they would have.
> +		 *
> +		 * If it hurts, don't do it.
> +		 */
> +		kvm_arm_halt_guest(vcpu->kvm);
>  		vgic_flush_pending_lpis(vcpu);

[Severity: High]
Does the asynchronous halt ensure the target vCPU has fully synchronized its
hardware state back to software state before proceeding to flush?

kvm_arm_halt_guest() uses kvm_make_all_cpus_request(kvm, KVM_REQ_SLEEP).
If the target vCPU has exited guest mode and set vcpu->mode = OUTSIDE_GUEST_MODE
but has not yet executed kvm_vgic_sync_hwstate() to fold its LRs,
kvm_make_all_cpus_request() will skip waiting for it:

virt/kvm/kvm_main.c:kvm_request_needs_ipi() {
    ...
	if (req & KVM_REQUEST_WAIT)
		return mode != OUTSIDE_GUEST_MODE;
    ...
}

If the wait is skipped, could the flushing vCPU clear the ap_list in
vgic_flush_pending_lpis() just before the target vCPU folds its LRs? 
Would this incorrectly resurrect the deleted LPI state and cause ghost
interrupts?

>  		vgic_its_invalidate_all_caches(vcpu->kvm);
>  		atomic_set_release(&vgic_cpu->ctlr, 0);
> +		kvm_arm_resume_guest(vcpu->kvm);

[Severity: High]
Does this block need to hold a VM-wide lock?

Since vgic_mmio_write_v3r_ctlr() only synchronizes locally using an atomic
cmpxchg on the target vgic_cpu->ctlr, multiple vCPUs could concurrently
write to different VGIC redistributors to disable their LPIs.

If this happens, multiple vCPUs will concurrently call kvm_arm_halt_guest()
and race to set vcpu->arch.pause = true:

arch/arm64/kvm/arm.c:kvm_arm_halt_guest() {
    ...
	kvm_for_each_vcpu(i, vcpu, kvm)
		vcpu->arch.pause = true;
    ...
}

The first vCPU to finish flushing will call kvm_arm_resume_guest() which
unconditionally clears the pause boolean:

arch/arm64/kvm/arm.c:kvm_arm_resume_guest() {
    ...
	kvm_for_each_vcpu(i, vcpu, kvm) {
		vcpu->arch.pause = false;
		__kvm_vcpu_wake_up(vcpu);
	}
    ...
}

Could this unpause the VM prematurely while another vCPU is still tearing
down VGIC state in vgic_flush_pending_lpis(), allowing guests to run and
modify their VGIC state concurrently?

>  	} else {
>  		ctlr = atomic_cmpxchg_acquire(&vgic_cpu->ctlr, 0,
>  					      GICR_CTLR_ENABLE_LPIS);

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260922214212.3327146-1-maz@kernel.org?part=3

  reply	other threads:[~2026-09-22 22:01 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-22 21:42 [PATCH 0/3] KVM: arm64: vgic-v3: Make LPI disabling robust Marc Zyngier
2026-09-22 21:42 ` [PATCH 1/3] KVM: arm64: vgic: Allow last_lr_irq to be NULL when LRs are not overflowing Marc Zyngier
2026-09-22 21:42 ` [PATCH 2/3] KVM: arm64: vgic: Take a refcount on IRQs referenced by last_lr_irq Marc Zyngier
2026-09-22 21:42 ` [PATCH 3/3] KVM: arm64: vgic: Stop the VM when disabling LPIs Marc Zyngier
2026-09-22 22:01   ` sashiko-bot [this message]
2026-09-22 23:21     ` Marc Zyngier
2026-09-23 16:41       ` Oliver Upton
2026-09-23 17:56         ` Marc Zyngier
2026-09-23 18:21           ` Oliver Upton

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=20260922220125.91CC01F000FF@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 \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.