From: Thomas Gleixner <tglx@kernel.org>
To: "Gregory CLEMENT" <gregory.clement@bootlin.com>,
"Vladimir Kondratiev" <vladimir.kondratiev@mobileye.com>,
"Benoît Monin" <benoit.monin@bootlin.com>,
"Théo Lebrun" <theo.lebrun@bootlin.com>,
"Radu Rendec" <radu@rendec.net>, "Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Thomas Bogendoerfer" <tsbogend@alpha.franken.de>
Cc: Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org,
devicetree@vger.kernel.org,
Gregory CLEMENT <gregory.clement@bootlin.com>
Subject: Re: [PATCH v5 2/5] irqchip: irq-eyeq5-msi: add EyeQ5 PCIe MSI controller driver
Date: Tue, 01 Dec 2026 19:04:40 +0100 [thread overview]
Message-ID: <87jylsq3lz.ffs@fw13> (raw)
In-Reply-To: <20261125-eyeq5_msi-v5-2-72346cd10736@bootlin.com>
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
next prev parent reply other threads:[~2026-12-01 18:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 19:27 [PATCH v5 0/5] irqchip: add EyeQ5 PCIe MSI controller Gregory CLEMENT
2026-11-25 19:27 ` [PATCH v5 1/5] dt-bindings: interrupt-controller: add Mobileye " Gregory CLEMENT
2026-11-25 19:27 ` [PATCH v5 2/5] irqchip: irq-eyeq5-msi: add EyeQ5 PCIe MSI controller driver Gregory CLEMENT
2026-12-01 18:04 ` Thomas Gleixner [this message]
2026-11-25 19:27 ` [PATCH v5 3/5] MIPS: eyeq: select the EyeQ5 MSI controller Gregory CLEMENT
2026-11-25 19:27 ` [PATCH v5 4/5] MIPS: dts: eyeq5: add MSI controllers Gregory CLEMENT
2026-11-25 19:27 ` [PATCH v5 5/5] MAINTAINERS: add EyeQ5 MSI controller entry Gregory CLEMENT
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=87jylsq3lz.ffs@fw13 \
--to=tglx@kernel.org \
--cc=benoit.monin@bootlin.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=gregory.clement@bootlin.com \
--cc=krzk+dt@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=radu@rendec.net \
--cc=robh@kernel.org \
--cc=theo.lebrun@bootlin.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=tsbogend@alpha.franken.de \
--cc=vladimir.kondratiev@mobileye.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