Linux KVM/arm64 development list
 help / color / mirror / Atom feed
From: "Carlos López" <clopez@suse.de>
To: sashiko-reviews@lists.linux.dev
Cc: kvmarm@lists.linux.dev, Oliver Upton <oupton@kernel.org>,
	Marc Zyngier <maz@kernel.org>
Subject: Re: [PATCH v5 2/2] KVM: arm64: vgic: Mitigate potential LPI registration failure
Date: Thu, 9 Jul 2026 17:52:31 +0200	[thread overview]
Message-ID: <bdcfcedd-4914-4fab-bede-a16357e2a7b3@suse.de> (raw)
In-Reply-To: <20260709150934.626561F000E9@smtp.kernel.org>

On 7/9/26 5:09 PM, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> 
> Pre-existing issues:
> - [High] The error path in `vgic_add_lpi()` calls `xa_release()`, which acquires the `lpi_xa` lock without disabling interrupts, leading to a potential deadlock.
> --
> 
> --- Patch [2]: [PATCH v5 2/2] KVM: arm64: vgic: Mitigate potential LPI registration failure ---
> commit c5f231166837f986fca0d6f0a35dc7e8c46a61d1
> Author: Carlos López <clopez@suse.de>
> Subject: KVM: arm64: vgic: Mitigate potential LPI registration failure
> 
> This commit mitigates a potential allocation failure when inserting a new LPI 
> into the VGIC LPI xarray. It updates vgic_add_lpi() to pass GFP_NOWAIT and 
> __GFP_ACCOUNT to __xa_store(), allowing allocation to occur under the lock if 
> the reserved entry was removed concurrently.
> 
>> diff --git a/arch/arm64/kvm/vgic/vgic-its.c b/arch/arm64/kvm/vgic/vgic-its.c
>> --- a/arch/arm64/kvm/vgic/vgic-its.c
>> +++ b/arch/arm64/kvm/vgic/vgic-its.c
>> @@ -124,7 +124,8 @@ static struct vgic_irq *vgic_add_lpi(struct kvm *kvm, u32 intid,
>>  		 * holds before freeing it, as otherwise someone else could still
>>  		 * hold a pointer to the evicted struct.
>>  		 */
>> -		oldirq = __xa_store(&dist->lpi_xa, intid, irq, 0);
>> +		oldirq = __xa_store(&dist->lpi_xa, intid, irq,
>> +				    GFP_NOWAIT | __GFP_ACCOUNT);
>>  		ret = xa_err(oldirq);
>>  		if (!ret && oldirq &&
>>  		    !WARN_ON_ONCE(refcount_read(&oldirq->refcount) ||
>>  				  !oldirq->pending_release))
>>  			kfree_rcu(oldirq, rcu);
>>  	}
>>  
>>  	xa_unlock_irqrestore(&dist->lpi_xa, flags);
>>  
>>  	if (ret) {
>>  		xa_release(&dist->lpi_xa, intid);
> 
> [Severity: High]
> This is a pre-existing issue, but does calling xa_release() here introduce a
> potential lock inversion deadlock with hardirqs?

I clearly did not read Oliver's diff carefully enough, this does not
happen with those changes.

> The xa_release() function internally uses xa_cmpxchg(), which acquires the 
> lpi_xa.xa_lock using spin_lock() without disabling local interrupts.
> 
> If a hardware interrupt fires on this CPU while the lock is held (for example,
> an eventfd signal triggering irqfd_wakeup() in hardirq context for fast-path 
> MSIs), it can inject an LPI and eventually call vgic_put_irq().
> 
> Because vgic_put_irq() acquires lpi_xa.xa_lock using spin_lock_irqsave(), the 
> interrupt handler would spin forever waiting for the lock held by the preempted
> vgic_add_lpi() thread.
> 
> Since this patch makes it more likely for the error path to be hit (if the 
> GFP_NOWAIT allocation fails), should this path be updated to manually erase 
> the entry while holding the xarray lock with interrupts disabled?
> 
>>  		kfree(irq);
>>  
>>  		return ERR_PTR(ret);
> 


      reply	other threads:[~2026-07-09 15:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-09 14:42 [PATCH v5 0/2] KVM: arm64: vgic: Fix racy LPI release and re-registration handling Carlos López
2026-07-09 14:42 ` [PATCH v5 1/2] KVM: arm64: vgic: Fix race between LPI release and re-registration Carlos López
2026-07-09 14:59   ` sashiko-bot
2026-07-09 14:42 ` [PATCH v5 2/2] KVM: arm64: vgic: Mitigate potential LPI registration failure Carlos López
2026-07-09 15:09   ` sashiko-bot
2026-07-09 15:52     ` Carlos López [this message]

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=bdcfcedd-4914-4fab-bede-a16357e2a7b3@suse.de \
    --to=clopez@suse.de \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox