All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hao Zhang <hao_zhang_kdev@163.com>
To: sashiko-reviews@lists.linux.dev
Cc: Hao Zhang <hao_zhang_kdev@163.com>, kvm@vger.kernel.org
Subject: Re: [PATCH v5 3/6] KVM: x86: ioapic: Preserve irr_delivered for duplicate edge interrupts
Date: Thu, 13 Aug 2026 15:52:17 +0800	[thread overview]
Message-ID: <an13sYh4gCyGbMZc@192.168.1.215> (raw)
In-Reply-To: <20260812085229.4EA541F000E9@smtp.kernel.org>

On Wed, Aug 12, 2026, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
> 
> Pre-existing issues:
> - [High] KVM's IOAPIC fails to latch edge-triggered interrupts if they pulse while the pin is masked, and fails to deliver latched edge-triggered interrupts upon unmasking.
> --
> 
> --- Patch [3]: [PATCH v5 3/6] KVM: x86: ioapic: Preserve irr_delivered for duplicate edge interrupts ---
> commit 691f4f74cce4e2c3436bc9f3cdf594c985c284e3
> Author: Hao Zhang <zhanghao1@kylinos.cn>
> 
> KVM: x86: ioapic: Preserve irr_delivered for duplicate edge interrupts
> 
> For edge-triggered interrupts, ioapic_set_irq() clears irr_delivered before
> checking whether the new edge is a duplicate. This patch moves the state
> update after the duplicate-edge check to prevent duplicate edges from making
> a delivered interrupt appear pending during VM migration.
> 
> > diff --git a/arch/x86/kvm/ioapic.c b/arch/x86/kvm/ioapic.c
> > index 24a7cc3b8b7ef..676effd674f9e 100644
> > --- a/arch/x86/kvm/ioapic.c
> > +++ b/arch/x86/kvm/ioapic.c
> > @@ -230,11 +230,11 @@ static int ioapic_set_irq(struct kvm_ioapic *ioapic, unsigned int irq,
> 
> [Severity: High]
> This isn't a bug introduced by this patch, but while reviewing
> ioapic_set_irq(), does KVM fail to latch edge-triggered interrupts if they
> pulse while the pin is masked?
>
> Earlier in ioapic_set_irq(), the IRR bit is cleared unconditionally when the
> pin goes low:
> 
> 	if (!irq_level) {
> 		ioapic->irr &= ~mask;
> 		ret = 1;
> 		goto out;
> 	}
> 
> This appears to destroy the latch state for edge-triggered interrupts that
> were not yet delivered.
> 
> Furthermore, looking at ioapic_write_indirect(), when unmasking, pending
> interrupt injection is restricted only to level-triggered interrupts:
> 
> 		if (e->fields.trig_mode == IOAPIC_LEVEL_TRIG &&
> 		    ioapic->irr & (1 << index) && !e->fields.mask && !e->fields.remote_irr) {
> 
> Could this sequence cause latched edge-triggered interrupts to be silently
> ignored and lost if a guest temporarily masks IOAPIC pins during interrupt
> handling?
>

Sashiko seems to assume that an edge-triggered interrupt which is signaled
while the IOAPIC RTE is masked must remain latched and then be delivered when
the RTE is unmasked.

However, the Intel 82093AA I/O Advanced Programmable Interrupt Controller datasheet
(https://pdos.csail.mit.edu/6.828/2018/readings/ia32/ioapic.pdf) states that 
edge-sensitive interrupts signaled on a masked interrupt pin are ignored, 
i.e. they are not delivered or held pending.

KVM's userspace ABI (https://www.kernel.org/doc/html/v6.12/virt/kvm/api.html#kvm-irq-line) 
also represents an edge interrupt as a pulse, by asserting the line and then deasserting 
it. If that complete pulse occurs while the RTE is masked, there is no pending edge that 
needs to be delivered on unmask.

This is also separate from this patch. The patch only preserves irr_delivered
for a duplicate edge interrupt that is coalesced after a previous edge has
already been delivered, so that KVM_GET_IRQCHIP does not expose the delivered
edge interrupt as pending.

> >  	old_irr = ioapic->irr;
> >  	ioapic->irr |= mask;
> >  	if (edge) {
> > -		ioapic->irr_delivered &= ~mask;
> >  		if (old_irr == ioapic->irr) {
> >  			ret = 0;
> >  			goto out;
> >  		}
> > +		ioapic->irr_delivered &= ~mask;
> >  	}
> >  
> >  	ret = ioapic_service(ioapic, irq, line_status);
> 
> -- 
> Sashiko AI review · https://sashiko.dev/#/patchset/anwugm-oU0v1VM-t@192.168.1.215?part=3


  reply	other threads:[~2026-08-13  7:52 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-12  8:27 [PATCH v5 0/6] KVM: x86: Fix IOAPIC remote_irr and irr_delivered handling Hao Zhang
2026-08-12  8:32 ` [PATCH v5 1/6] KVM: x86: ioapic: Update remote_irr only after successful delivery Hao Zhang
2026-08-12  8:34 ` [PATCH v5 2/6] KVM: selftests: Verify failed IOAPIC delivery preserves state Hao Zhang
2026-08-12  8:35 ` [PATCH v5 3/6] KVM: x86: ioapic: Preserve irr_delivered for duplicate edge interrupts Hao Zhang
2026-08-12  8:52   ` sashiko-bot
2026-08-13  7:52     ` Hao Zhang [this message]
2026-08-13 10:10       ` Huang, Kai
2026-08-12  8:37 ` [PATCH v5 4/6] KVM: selftests: Verify duplicate edge preserves IOAPIC state Hao Zhang
2026-08-12  8:39 ` [PATCH v5 5/6] KVM: x86: ioapic: Clear irr_delivered on level-triggered RTE Hao Zhang
2026-08-12 22:41   ` Huang, Kai
2026-08-12  8:41 ` [PATCH v5 6/6] KVM: selftests: Verify edge-to-level clears IOAPIC state Hao Zhang

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=an13sYh4gCyGbMZc@192.168.1.215 \
    --to=hao_zhang_kdev@163.com \
    --cc=kvm@vger.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.