From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796148284; b=mCCtJqv0txcRU9c7YjB7d2nM2adJJBojRpIZzwqzPw9oQLwj0YC+ki0FXFE+sxpUJKow woQbYk19ba4Mq6laLsHP+POd6iD5ulVZeLsL6CH6KqUmkECbod4rP5O0kZD9eBE7hUXT1 4Id8EIZdLU+CaiagjEuzHofkFH8v2cbhPjP0o94nOUK+nSLKFqItOZMMSUKeo4Y59vPeJ ntQP/zwmnzK52oBfgqFI7wnbb2BiQcXuTbpbL0cnld80T5IMJY/XWfyWxSN2iOQ/bHsDs iugveTE11/hYxvoiboy+qJJRjfMCupx1kRJimQN6X4o2kfeYnbBjs/mEEu7BO+SSIeA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796148284; h=Received:DKIM-Signature:From:To:Cc:Subject:In-Reply-To:References: Date:Message-ID:MIME-Version:Content-Type; bh=C8jQ5PxHe78VIcPe+TrTW+hgXBeBTNWnhvB0cPtwWNc=; b=HXtR4uOfugVqCPm/ZIzG7tzIPB5AON0tFHgsjAGHVIbar1u0yRONey9Z9ey1Vu+CuqU7 yFgEqOPWPd4Y5dBSO/ttLltABcQmyPae0FBoh70AjRI5dzJgUU3gp022AzLPh12l+LAbE Qnv4+WDwPrF2WmzOSVRw+qr9PJVjos+SlD+re6/ibPDnCaFNA8RU2vGjpcj1Pkj4ckDvs MJAoRVod4pRuuS2bFH6XArPEV+gCTxO9BhAYSzdtB8A3d6il4cNh2PwJVTN/ox34VYcZG sWoT5o7ddhqBHCngVWRyZ0FwPodekkpDkxr+bifAodu41j3Z0riGaacjdhefaL4ETqg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=S2TdRdQ5; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 332CC606A31A; Tue, 1 Dec 2026 18:04:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=S2TdRdQ5 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4790E1F00893; Tue, 1 Dec 2026 18:04:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796148284; bh=C8jQ5PxHe78VIcPe+TrTW+hgXBeBTNWnhvB0cPtwWNc=; h=From:To:Cc:Subject:In-Reply-To:References:Date; b=S2TdRdQ5qusszekpPGiUD2Qqh3lWBVNOqJ1sjr2D1maaIXm2NpEdV4CVwZaVTuctH gVUd5ofBT4rXhhyZ3a2ep32hVM2NesCLUthzU0nVjg9f+4dmFKskfGN+Har9V2qsiJ JTguoMdqcpxpH14DD58x+n+GQwRSHx7/SjeZz+yjfUOiBaR6KHMQabnPYSQ+pu4Ss0 dXKVmIcyL6p4704nOHviey88iz9PkjdVwAxM2HYOMn1khogdRcxcCPY+zywGjdECTX OUQdN4prCpGTf88qIr9fAXXvQJdKVYTrFSQ8RTcnlPYKEIKNWHaOB/fb+MOST3kSdD vZwnvnlLpftEQ== From: Thomas Gleixner To: Gregory CLEMENT , Vladimir Kondratiev , =?utf-8?Q?Beno=C3=AEt?= Monin , =?utf-8?Q?Th=C3=A9o?= Lebrun , Radu Rendec , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Thomas Bogendoerfer Cc: Thomas Petazzoni , linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Gregory CLEMENT Subject: Re: [PATCH v5 2/5] irqchip: irq-eyeq5-msi: add EyeQ5 PCIe MSI controller driver In-Reply-To: <20261125-eyeq5_msi-v5-2-72346cd10736@bootlin.com> References: <20261125-eyeq5_msi-v5-0-72346cd10736@bootlin.com> <20261125-eyeq5_msi-v5-2-72346cd10736@bootlin.com> Date: Tue, 01 Dec 2026 19:04:40 +0100 Message-ID: <87jylsq3lz.ffs@fw13> X-Mailing-List: linux-mips@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain 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