From: Marc Zyngier <maz@kernel.org>
To: Lorenzo Pieralisi <lpieralisi@kernel.org>
Cc: linux-pci@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org,
"Toan Le" <toan@os.amperecomputing.com>,
"Krzysztof Wilczyński" <kwilczynski@kernel.org>,
"Manivannan Sadhasivam" <mani@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Bjorn Helgaas" <bhelgaas@google.com>,
"Thomas Gleixner" <tglx@linutronix.de>
Subject: Re: [PATCH v2 09/13] PCI: xgene-msi: Sanitise MSI allocation and affinity setting
Date: Fri, 11 Jul 2025 11:50:37 +0100 [thread overview]
Message-ID: <86ecun9f2a.wl-maz@kernel.org> (raw)
In-Reply-To: <aHDfhVRa1lhu7qPg@lpieralisi>
On Fri, 11 Jul 2025 10:55:17 +0100,
Lorenzo Pieralisi <lpieralisi@kernel.org> wrote:
>
> On Tue, Jul 08, 2025 at 06:34:00PM +0100, Marc Zyngier wrote:
> > static void xgene_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
> > {
> > struct xgene_msi *msi = irq_data_get_irq_chip_data(data);
> > - u32 reg_set = hwirq_to_reg_set(data->hwirq);
> > - u32 group = hwirq_to_group(data->hwirq);
> > - u64 target_addr = msi->msi_addr + (((8 * group) + reg_set) << 16);
> > + u64 target_addr;
> > + u32 frame, msir;
> > + int cpu;
> >
> > - msg->address_hi = upper_32_bits(target_addr);
> > - msg->address_lo = lower_32_bits(target_addr);
> > - msg->data = hwirq_to_msi_data(data->hwirq);
> > -}
> > + cpu = cpumask_first(irq_data_get_effective_affinity_mask(data));
> > + msir = FIELD_GET(GENMASK(6, 4), data->hwirq);
>
> We could use MSInRx_HWIRQ_MASK, I can update it.
Yes, I appear to have missed that one. It'd be good if you could fix
it up.
> More importantly, what code would set data->hwirq[6:4] (and
> data->hwirq[7:7] below) ?
That's obviously driven by the hwirq allocation, which is guaranteed
to happen in the 0:255 range.
[...]
> > @@ -173,23 +167,20 @@ static int xgene_irq_domain_alloc(struct irq_domain *domain, unsigned int virq,
> > unsigned int nr_irqs, void *args)
> > {
> > struct xgene_msi *msi = domain->host_data;
> > - int msi_irq;
> > + irq_hw_number_t hwirq;
> >
> > mutex_lock(&msi->bitmap_lock);
> >
> > - msi_irq = bitmap_find_next_zero_area(msi->bitmap, NR_MSI_VEC, 0,
> > - num_possible_cpus(), 0);
> > - if (msi_irq < NR_MSI_VEC)
> > - bitmap_set(msi->bitmap, msi_irq, num_possible_cpus());
> > - else
> > - msi_irq = -ENOSPC;
> > + hwirq = find_first_zero_bit(msi->bitmap, NR_MSI_VEC);
> > + if (hwirq < NR_MSI_VEC)
> > + set_bit(hwirq, msi->bitmap);
> >
> > mutex_unlock(&msi->bitmap_lock);
> >
> > - if (msi_irq < 0)
> > - return msi_irq;
> > + if (hwirq >= NR_MSI_VEC)
> > + return -ENOSPC;
> >
> > - irq_domain_set_info(domain, virq, msi_irq,
> > + irq_domain_set_info(domain, virq, hwirq,
> > &xgene_msi_bottom_irq_chip, domain->host_data,
> > handle_simple_irq, NULL, NULL);
>
> This is something I don't get. We alloc an MSI, set a bit in the bitmap
> and the hwirq to that value, when we handle the IRQ below in
>
> xgene_msi_isr()
>
> hwirq = compute_hwirq(msi_grp, msir_idx, intr_idx);
> ret = generic_handle_domain_irq(xgene_msi->inner_domain, hwirq);
>
> imagining that we changed the affinity for the IRQ so that the computed
> HWIRQ does not have zeros in bits[7:4], how would the domain HWIRQ
> matching work ?
No. The whole point of this series is that hwirq is now *constant*, no
matter what the affinity says.
> Actually, how would an IRQ fire causing the hwirq[7:4] bits to be != 0
> in the first place ?
hwirq[7:4] is a function of what IRQ fired (giving you a register
frame), and what register was accessed. That 's what allows you to
*rebuild* hwirq as the HW doesn't give it you on a plate (only the
bottom 4 bits are more or less given as a bitmap).
> Forgive me if I am missing something obvious, the *current* MSI handling
> is very hard to grok, it is certain I misunderstood it entirely.
Ignore the current code, it does things that are completely forbidden
by law in any civilised country (although I find it difficult to name
a single civilised country these days).
Thanks,
M.
--
Without deviation from the norm, progress is not possible.
next prev parent reply other threads:[~2025-07-11 12:44 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-08 17:33 [PATCH v2 00/13] PCI: xgene: Fix and simplify the MSI driver Marc Zyngier
2025-07-08 17:33 ` [PATCH v2 01/13] genirq: Teach handle_simple_irq() to resend an in-progress interrupt Marc Zyngier
2025-07-08 17:33 ` [PATCH v2 02/13] PCI: xgene: Defer probing if the MSI widget driver hasn't probed yet Marc Zyngier
2025-07-08 17:33 ` [PATCH v2 03/13] PCI: xgene: Drop useless conditional compilation Marc Zyngier
2025-07-08 17:33 ` [PATCH v2 04/13] PCI: xgene: Drop XGENE_PCIE_IP_VER_UNKN Marc Zyngier
2025-07-08 17:33 ` [PATCH v2 05/13] PCI: xgene-msi: Make per-CPU interrupt setup robust Marc Zyngier
2025-07-08 17:33 ` [PATCH v2 06/13] PCI: xgene-msi: Drop superfluous fields from xgene_msi structure Marc Zyngier
2025-07-17 11:24 ` Markus Elfring
2025-07-08 17:33 ` [PATCH v2 07/13] PCI: xgene-msi: Use device-managed memory allocations Marc Zyngier
2025-07-08 17:33 ` [PATCH v2 08/13] PCI: xgene-msi: Get rid of intermediate tracking structure Marc Zyngier
2025-07-08 17:34 ` [PATCH v2 09/13] PCI: xgene-msi: Sanitise MSI allocation and affinity setting Marc Zyngier
2025-07-11 9:55 ` Lorenzo Pieralisi
2025-07-11 10:11 ` Lorenzo Pieralisi
2025-07-11 10:51 ` Marc Zyngier
2025-07-11 10:50 ` Marc Zyngier [this message]
2025-07-08 17:34 ` [PATCH v2 10/13] PCI: xgene-msi: Resend an MSI racing with itself on a different CPU Marc Zyngier
2025-07-08 17:34 ` [PATCH v2 11/13] PCI: xgene-msi: Probe as a standard platform driver Marc Zyngier
2025-07-17 11:45 ` Markus Elfring
2025-07-17 13:18 ` Lorenzo Pieralisi
2025-07-08 17:34 ` [PATCH v2 12/13] PCI: xgene-msi: Restructure handler setup/teardown Marc Zyngier
2025-07-08 17:34 ` [PATCH v2 13/13] cpu/hotplug: Remove unused cpuhp_state CPUHP_PCI_XGENE_DEAD Marc Zyngier
2025-07-11 13:15 ` Lorenzo Pieralisi
2025-07-17 9:52 ` [PATCH v2 00/13] PCI: xgene: Fix and simplify the MSI driver Lorenzo Pieralisi
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=86ecun9f2a.wl-maz@kernel.org \
--to=maz@kernel.org \
--cc=bhelgaas@google.com \
--cc=kwilczynski@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=mani@kernel.org \
--cc=robh@kernel.org \
--cc=tglx@linutronix.de \
--cc=toan@os.amperecomputing.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;
as well as URLs for NNTP newsgroup(s).