Re: [PATCH v5 2/5] irqchip: irq-eyeq5-msi: add EyeQ5 PCIe MSI controller driver

From: Thomas Gleixner

Date: Tue Dec 01 2026 - 13:04:48 EST


On Wed, Nov 25 2026 at 20:27, Gregory CLEMENT wrote:
> +/*
> + * The pending bit is write-one-to-cleared in eyeq_msi_isr() before the
> + * vector is dispatched, so there is nothing left to acknowledge here.
> + * handle_edge_irq() nevertheless requires an ack callback.
> + */
> +static void eyeq_msi_ack_irq(struct irq_data *data) { }
> +
> +static struct irq_chip eyeq_msi_irq_chip = {
> + .name = "EyeQ5-MSI",
> + .irq_mask = eyeq_msi_mask_irq,
> + .irq_unmask = eyeq_msi_unmask_irq,
> + .irq_ack = eyeq_msi_ack_irq,
> + .irq_compose_msi_msg = eyeq_msi_compose_msg,
> +#ifdef CONFIG_SMP
> + .irq_set_affinity = irq_chip_redirect_set_affinity,
> +#endif
> +};
> +
> +static void eyeq_msi_isr(struct irq_desc *desc)
> +{
> + struct irq_chip *parent_chip = irq_desc_get_chip(desc);
> + struct eyeq_msi *msi = irq_desc_get_handler_data(desc);
> + void __iomem *status_reg;
> + unsigned long pending;
> + unsigned long mask;
> + unsigned int bit;
> + unsigned int i;

Please put same types into one line and bring the variable declarations
into the scope in which they are used.

+
> + guard_chained_irq(parent_chip, desc);
> +
> + status_reg = msi->gcsr_base + GCSR_IRQSTATUS;
> +
> + for (i = 0; i < EYEQ_MSI_MAX_DRAIN; i++) {

for (int i ...) {
> + pending = FIELD_GET(GCSR_IRQSTATUS_MASK, readw(status_reg));

unsigned long mask, pending = ....

> + if (!pending)
> + break;
> +
> + /*
> + * Masked vectors must stay pending in GCSR_IRQSTATUS: unmasking
> + * them must re-assert the top-level IRQ. Only dispatch and ack
> + * the bits that are currently unmasked.
> + */
> + mask = FIELD_GET(GCSR_IRQMASK_MASK,
> + readw(msi->gcsr_base + GCSR_IRQMASK));
> + pending &= mask;

That's wishful thinking....

> + if (!pending)
> + break;
> +
> + /*
> + * Write-one-to-clear status register.
> + */
> + writew(FIELD_PREP(GCSR_IRQSTATUS_MASK, pending), status_reg);
> +
> + for_each_set_bit(bit, &pending, EYEQ_MSI_MAX_VECTORS) {
> + if (!generic_handle_demux_domain_irq(msi->msi_domain, bit))
> + pr_err_ratelimited("unmapped MSI interrupt %u\n", bit);
> + }

... because:

disable_irq()
__disable_irq_nosync()
guard(irqdesc)
irq_disable(desc, @mask = irq_settings_disable_unlazy(desc))
if (irqd_irq_disabled(irqd)) {
// Not taken
...
return;
}
A: irq_state_set_disabled();
if (chip->irq_disable)
B: chip->irq_disable();
if (mask)
C: mask();

synchronize_irq();

So with DISABLE_UNLAZY not set and no irq_disable() callback in the chip
disable_irq() will only set the state to disabled.

So if the demultiplex interrupt is raised after #A and handled (same or
other CPU) then the readout of the mask register will have the interrupt
unmasked, so it's acknowledged and the handler invoked.

The handler observes disabled state, masks the interrupt, marks it
PENDING and returns w/o invoking the device interrupt handler. Interrupt
is lost. This is guaranteed to happen and if so it will be really hard
to diagnose.

Even if you set DISABLE_UNLAZY or add an irq_disable() callback this
won't work because the demultiplex interrupt on a different CPU will
still be able to observe the unmasked state in the mask register between
#A and #B/ #C. The edge handler will behave exactly the same way as
described above and the interrupt is lost. Just the race window becomes
smaller and therefore even harder to debug.

The problem is that the demultiplex handler and the device interrupt
management are not synchronized in any way and you can't do anything
about that.

So either you enable software resend or you do the following:

1) Implement the irq_pre_redirect() callback in the chip

if (!irqd_irq_disabled(irqd) || irqd_irq_masked(irqd))
return;

guard(raw_spinlock)(&msi->lock);
// Mask in hardware
mask(THIS_BIT);
// Ensure the state is correct otherwise irq_enable() -> unmask()
// will not work...
irqd_set_masked(irqd);

This ensures that on redirect to a different CPU the interrupt is
masked and does not resurface in the demultiplexer. It will still be
handled, but the edge handler will leave when it still observes
disabled state.

2) Implement a proper ACK callback in the eyeq_msi_irq_chip which takes
the state into account:

if (irqd_irq_disabled(irqd))
return;

guard(raw_spinlock)(&msi->lock);
ack(THIS_BIT);

This prevents the ACK to be issued when the interrupt is disabled.

#1 and #2 are properly serialized with the interrupt descriptor lock
against a concurrent irq_disable().

3) Remove the bulk acknowledge from the chained handler and do

if (!generic_handle_demux_domain_irq(...)) {
guard(raw_spinlock)(&msi->lock);
__eyeq_msi_mask_irq(msi, bit);
__eyeq_msi_ack_irq(msi, bit);
}

to silence spurious unmapped interrupts.

That still leaves you with the MASK register readout racing against a
concurrent write, but that's not an issue because that just results in
one pointless edge handler invocation.

You also can spare the hardware read and cache the mask register content
in struct eyeq_msi in mask() and unmask(). You don't have to take
msi->lock in the demux handler because that'd be just a cosmetic
exercise w/o any actual serialization value. So you can do the writes in
mask/unmask() under the lock with WRITE_ONCE() and use READ_ONCE() in
the demux handler. I would do that anyway because that avoids the read
in mask/unmask() too.

Thanks,

tglx