diff mbox series

[v15,02/15] irqdomain: Add IRQ_DOMAIN_FLAG_MSI_IMMUTABLE and irq_domain_is_msi_immutable()

Message ID 20250211-ep-msi-v15-2-bcacc1f2b1a9@nxp.com (mailing list archive)
State New
Headers show
Series PCI: EP: Add RC-to-EP doorbell with platform MSI controller | expand

Commit Message

Frank Li Feb. 11, 2025, 7:21 p.m. UTC
Add the flag IRQ_DOMAIN_FLAG_MSI_IMMUTABLE and the API function
irq_domain_is_msi_immutable() to check if the MSI controller retains an
immutable address/data pair during irq_set_affinity().

Ensure compatibility with MSI users like PCIe Endpoint Doorbell, which
require the address/data pair to remain unchanged after setup. Use this
function to verify if the MSI controller is immutable.

Signed-off-by: Frank Li <Frank.Li@nxp.com>
---
change from v14 to v15
- none

change from v13 to v14
- Roll back to v12 version because Marc Zyngier have concern about add
DOMAIN_BUS_DEVICE_PCI_EP_MSI.
https://lore.kernel.org/imx/861pxfq315.wl-maz@kernel.org/

Change from v11 to v12
- change to IRQ_DOMAIN_FLAG_MSI_IMMUTABLE to minimized the code change.
---
 include/linux/irqdomain.h | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Marc Zyngier March 1, 2025, 11:10 a.m. UTC | #1
On Tue, 11 Feb 2025 19:21:55 +0000,
Frank Li <Frank.Li@nxp.com> wrote:
> 
> Add the flag IRQ_DOMAIN_FLAG_MSI_IMMUTABLE and the API function
> irq_domain_is_msi_immutable() to check if the MSI controller retains an
> immutable address/data pair during irq_set_affinity().
> 
> Ensure compatibility with MSI users like PCIe Endpoint Doorbell, which
> require the address/data pair to remain unchanged after setup. Use this
> function to verify if the MSI controller is immutable.

Why is that a requirement? Why should a driver even care?

	M.
Frank Li March 3, 2025, 5:01 p.m. UTC | #2
On Sat, Mar 01, 2025 at 11:10:35AM +0000, Marc Zyngier wrote:
> On Tue, 11 Feb 2025 19:21:55 +0000,
> Frank Li <Frank.Li@nxp.com> wrote:
> >
> > Add the flag IRQ_DOMAIN_FLAG_MSI_IMMUTABLE and the API function
> > irq_domain_is_msi_immutable() to check if the MSI controller retains an
> > immutable address/data pair during irq_set_affinity().
> >
> > Ensure compatibility with MSI users like PCIe Endpoint Doorbell, which
> > require the address/data pair to remain unchanged after setup. Use this
> > function to verify if the MSI controller is immutable.
>
> Why is that a requirement? Why should a driver even care?

At v9, there were detail discussion about this
https://lore.kernel.org/all/87v7w0s9a8.ffs@tglx/

let me summary:

Host driver workflow like:

1. read address/data from shared memory (PC bar<n>)
2. write data to address to trigger doorbell.

1 and 2 is not atomic. So EP side may call set_affinity function during 1
and 2, address/data may be changed in some MSI provider, so 2 write to
previous address/data pair, which may not existed or map to other place and
cause write to unexpected place.

Frank

>
> 	M.
>
> --
> Without deviation from the norm, progress is not possible.
diff mbox series

Patch

diff --git a/include/linux/irqdomain.h b/include/linux/irqdomain.h
index e432b6a12a32f..3dbe05d8740e6 100644
--- a/include/linux/irqdomain.h
+++ b/include/linux/irqdomain.h
@@ -231,6 +231,9 @@  enum {
 	/* Irq domain must destroy generic chips when removed */
 	IRQ_DOMAIN_FLAG_DESTROY_GC	= (1 << 10),
 
+	/* Address and data pair is mutable when irq_set_affinity() */
+	IRQ_DOMAIN_FLAG_MSI_IMMUTABLE	= (1 << 11),
+
 	/*
 	 * Flags starting from IRQ_DOMAIN_FLAG_NONCORE are reserved
 	 * for implementation specific purposes and ignored by the
@@ -692,6 +695,10 @@  static inline bool irq_domain_is_msi_device(struct irq_domain *domain)
 	return domain->flags & IRQ_DOMAIN_FLAG_MSI_DEVICE;
 }
 
+static inline bool irq_domain_is_msi_immutable(struct irq_domain *domain)
+{
+	return domain->flags & IRQ_DOMAIN_FLAG_MSI_IMMUTABLE;
+}
 #else	/* CONFIG_IRQ_DOMAIN_HIERARCHY */
 static inline int irq_domain_alloc_irqs(struct irq_domain *domain,
 			unsigned int nr_irqs, int node, void *arg)