All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation
@ 2022-11-21 14:37 Thomas Gleixner
  2022-11-21 14:37 ` [patch V2 01/33] genirq/msi: Rearrange MSI domain flags Thomas Gleixner
                   ` (32 more replies)
  0 siblings, 33 replies; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:37 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe

This is V2 of the third part of the effort to provide support for per device
MSI interrupt domains.

Version 1 of this part can be found here:

  https://lore.kernel.org/all/20221111133158.196269823@linutronix.de

This is based on the second part which is available here:

  https://lore.kernel.org/all/20221121083210.309161925@linutronix.de

and from git:

  git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git devmsi-v2-part2

This third part is available from git too:

  git://git.kernel.org/pub/scm/linux/kernel/git/tglx/devel.git devmsi-v2-part3

This part provides the actual per device domain implementation and related
functionality:

  1) Provide infrastructure to create and remove per device MSI domains

  2) Implement per device MSI domains in the PCI/MSI code and make
     them conditional on the availability of a suitable parent MSI
     domain. This allows to convert the existing domains one by one
     and keeps both the legacy and the current "global" PCI/MSI domain
     model working.

  3) Convert the related x86 MSI domains over (vector and remapping).

  4) Provide core infrastructure for dynamic allocations

  5) Provide PCI/MSI-X interfaces for device drivers to do post
     MSI-X enable allocation/free

  6) Enable dynamic allocation support on the x86 MSI parent domains

  7) Provide infrastructure to create PCI/IMS domains

  8) Enable IMS support on the x86 MSI parent domains

  9) Provide a driver for IDXD which demonstrates how IMS domains
     look like.

Changes vs. v1:

  - Clarified argument names for the init callback (Jason)

  - Split the domain and instance data and named them accordingly

  - Fixed the recursive allocation issue and the missing index offset
    (Reinette)

  - Updated changelogs and comments (Bjorn, Jason)

  - Fixed the kernel robot fallout from randconfig builds

  - Picked up Reviewed/Acked-by tags where appropriate

Thanks,

	tglx
---
 arch/x86/include/asm/irq_remapping.h       |    4 
 arch/x86/include/asm/msi.h                 |    6 
 arch/x86/include/asm/pci.h                 |    1 
 arch/x86/kernel/apic/msi.c                 |  208 +++++++++------
 drivers/iommu/amd/amd_iommu_types.h        |    1 
 drivers/iommu/amd/iommu.c                  |   23 +
 drivers/iommu/intel/iommu.h                |    1 
 drivers/iommu/intel/irq_remapping.c        |   31 +-
 drivers/irqchip/Kconfig                    |    7 
 drivers/irqchip/Makefile                   |    1 
 drivers/irqchip/irq-pci-intel-idxd.c       |  143 ++++++++++
 drivers/pci/msi/api.c                      |  117 ++++++++
 drivers/pci/msi/irqdomain.c                |  278 ++++++++++++++++++--
 drivers/pci/msi/msi.c                      |  192 ++++++++------
 drivers/pci/msi/msi.h                      |    4 
 include/linux/irqchip/irq-pci-intel-idxd.h |   22 +
 include/linux/irqdomain.h                  |    9 
 include/linux/irqdomain_defs.h             |    5 
 include/linux/msi.h                        |  149 +++++++++-
 include/linux/msi_api.h                    |   38 ++
 include/linux/pci.h                        |   14 +
 kernel/irq/msi.c                           |  394 +++++++++++++++++++++++++++--
 22 files changed, 1395 insertions(+), 253 deletions(-)

^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 01/33] genirq/msi: Rearrange MSI domain flags
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
@ 2022-11-21 14:37 ` Thomas Gleixner
  2022-11-21 14:37 ` [patch V2 02/33] genirq/msi: Provide struct msi_parent_ops Thomas Gleixner
                   ` (31 subsequent siblings)
  32 siblings, 0 replies; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:37 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe,
	Jason Gunthorpe

These flags got added as necessary and have no obvious structure. For
feature support checks and masking it's convenient to have two blocks of
flags:

   1) Flags to control the internal behaviour like allocating/freeing
      MSI descriptors. Those flags do not need any support from the
      underlying MSI parent domain. They are mostly under the control
      of the outermost domain which implements the actual MSI support.

   2) Flags to expose features, e.g. PCI multi-MSI or requirements
      which can depend on a underlying domain.

No functional change.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
---
 include/linux/msi.h |   49 ++++++++++++++++++++++++++++++++++---------------
 1 file changed, 34 insertions(+), 15 deletions(-)

--- a/include/linux/msi.h
+++ b/include/linux/msi.h
@@ -24,6 +24,8 @@
 #include <linux/xarray.h>
 #include <linux/mutex.h>
 #include <linux/list.h>
+#include <linux/bits.h>
+
 #include <asm/msi.h>
 
 /* Dummy shadow structures if an architecture does not define them */
@@ -432,7 +434,16 @@ struct msi_domain_info {
 	void				*data;
 };
 
-/* Flags for msi_domain_info */
+/*
+ * Flags for msi_domain_info
+ *
+ * Bit 0-15:	Generic MSI functionality which is not subject to restriction
+ *		by parent domains
+ *
+ * Bit 16-31:	Functionality which depends on the underlying parent domain and
+ *		can be masked out by msi_parent_ops::init_dev_msi_info() when
+ *		a device MSI domain is initialized.
+ */
 enum {
 	/*
 	 * Init non implemented ops callbacks with default MSI domain
@@ -444,33 +455,41 @@ enum {
 	 * callbacks.
 	 */
 	MSI_FLAG_USE_DEF_CHIP_OPS	= (1 << 1),
-	/* Support multiple PCI MSI interrupts */
-	MSI_FLAG_MULTI_PCI_MSI		= (1 << 2),
-	/* Support PCI MSIX interrupts */
-	MSI_FLAG_PCI_MSIX		= (1 << 3),
 	/* Needs early activate, required for PCI */
-	MSI_FLAG_ACTIVATE_EARLY		= (1 << 4),
+	MSI_FLAG_ACTIVATE_EARLY		= (1 << 2),
 	/*
 	 * Must reactivate when irq is started even when
 	 * MSI_FLAG_ACTIVATE_EARLY has been set.
 	 */
-	MSI_FLAG_MUST_REACTIVATE	= (1 << 5),
-	/* Is level-triggered capable, using two messages */
-	MSI_FLAG_LEVEL_CAPABLE		= (1 << 6),
+	MSI_FLAG_MUST_REACTIVATE	= (1 << 3),
 	/* Populate sysfs on alloc() and destroy it on free() */
-	MSI_FLAG_DEV_SYSFS		= (1 << 7),
-	/* MSI-X entries must be contiguous */
-	MSI_FLAG_MSIX_CONTIGUOUS	= (1 << 8),
+	MSI_FLAG_DEV_SYSFS		= (1 << 4),
 	/* Allocate simple MSI descriptors */
-	MSI_FLAG_ALLOC_SIMPLE_MSI_DESCS	= (1 << 9),
+	MSI_FLAG_ALLOC_SIMPLE_MSI_DESCS	= (1 << 5),
 	/* Free MSI descriptors */
-	MSI_FLAG_FREE_MSI_DESCS		= (1 << 10),
+	MSI_FLAG_FREE_MSI_DESCS		= (1 << 6),
 	/*
 	 * Quirk to handle MSI implementations which do not provide
 	 * masking. Currently known to affect x86, but has to be partially
 	 * handled in the core MSI code.
 	 */
-	MSI_FLAG_NOMASK_QUIRK		= (1 << 11),
+	MSI_FLAG_NOMASK_QUIRK		= (1 << 7),
+
+	/* Mask for the generic functionality */
+	MSI_GENERIC_FLAGS_MASK		= GENMASK(15, 0),
+
+	/* Mask for the domain specific functionality */
+	MSI_DOMAIN_FLAGS_MASK		= GENMASK(31, 16),
+
+	/* Support multiple PCI MSI interrupts */
+	MSI_FLAG_MULTI_PCI_MSI		= (1 << 16),
+	/* Support PCI MSIX interrupts */
+	MSI_FLAG_PCI_MSIX		= (1 << 17),
+	/* Is level-triggered capable, using two messages */
+	MSI_FLAG_LEVEL_CAPABLE		= (1 << 18),
+	/* MSI-X entries must be contiguous */
+	MSI_FLAG_MSIX_CONTIGUOUS	= (1 << 19),
+
 };
 
 int msi_domain_set_affinity(struct irq_data *data, const struct cpumask *mask,


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 02/33] genirq/msi: Provide struct msi_parent_ops
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
  2022-11-21 14:37 ` [patch V2 01/33] genirq/msi: Rearrange MSI domain flags Thomas Gleixner
@ 2022-11-21 14:37 ` Thomas Gleixner
  2022-11-23  7:57   ` Tian, Kevin
  2022-11-21 14:37 ` [patch V2 03/33] genirq/msi: Provide data structs for per device domains Thomas Gleixner
                   ` (30 subsequent siblings)
  32 siblings, 1 reply; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:37 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe

MSI parent domains must have some control over the MSI domains which are
built on top. On domain creation they need to fill in e.g. architecture
specific chip callbacks or msi domain ops to make the outermost domain
parent agnostic which is obviously required for architecture independence
etc.

The structure contains:

    1) A bitfield which exposes the supported functional features. This
       allows to check for features and is also used in the initialization
       callback to mask out unsupported features when the actual domain
       implementation requests a broader range, e.g. on x86 PCI multi-MSI
       is only supported by remapping domains but not by the underlying
       vector domain. The PCI/MSI code can then always request multi-MSI
       support, but the resulting feature set after creation might not
       have it set.

    2) An optional string prefix which is put in front of domain and chip
       names during creation of the MSI domain. That allows to keep the
       naming schemes e.g. on x86 where PCI-MSI domains have a IR- prefix
       when interrupt remapping is enabled.

    3) An initialization callback to sanity check the domain info of
       the to be created MSI domain, to restrict features and to
       apply changes in MSI ops and interrupt chip callbacks to
       accomodate to the particular MSI parent implementation and/or
       the underlying hierarchy.

Add a conveniance function to delegate the initialization from the
MSI parent domain to an underlying domain in the hierarchy.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
V2: Renamed arguments and updated comments (Jason)
---
 include/linux/irqdomain.h |    5 +++++
 include/linux/msi.h       |   21 +++++++++++++++++++++
 kernel/irq/msi.c          |   41 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 67 insertions(+)

--- a/include/linux/irqdomain.h
+++ b/include/linux/irqdomain.h
@@ -46,6 +46,7 @@ struct irq_desc;
 struct cpumask;
 struct seq_file;
 struct irq_affinity_desc;
+struct msi_parent_ops;
 
 #define IRQ_DOMAIN_IRQ_SPEC_PARAMS 16
 
@@ -134,6 +135,7 @@ struct irq_domain_chip_generic;
  * @pm_dev:	Pointer to a device that can be utilized for power management
  *		purposes related to the irq domain.
  * @parent:	Pointer to parent irq_domain to support hierarchy irq_domains
+ * @msi_parent_ops: Pointer to MSI parent domain methods for per device domain init
  *
  * Revmap data, used internally by the irq domain code:
  * @revmap_size:	Size of the linear map table @revmap[]
@@ -157,6 +159,9 @@ struct irq_domain {
 #ifdef	CONFIG_IRQ_DOMAIN_HIERARCHY
 	struct irq_domain		*parent;
 #endif
+#ifdef CONFIG_GENERIC_MSI_IRQ
+	const struct msi_parent_ops	*msi_parent_ops;
+#endif
 
 	/* reverse map data. The linear map gets appended to the irq_domain */
 	irq_hw_number_t			hwirq_max;
--- a/include/linux/msi.h
+++ b/include/linux/msi.h
@@ -492,6 +492,27 @@ enum {
 
 };
 
+/**
+ * struct msi_parent_ops - MSI parent domain callbacks and configuration info
+ *
+ * @supported_flags:	Required: The supported MSI flags of the parent domain
+ * @prefix:		Optional: Prefix for the domain and chip name
+ * @init_dev_msi_info:	Required: Callback for MSI parent domains to setup parent
+ *			domain specific domain flags, domain ops and interrupt chip
+ *			callbacks when a per device domain is created.
+ */
+struct msi_parent_ops {
+	u32		supported_flags;
+	const char	*prefix;
+	bool		(*init_dev_msi_info)(struct device *dev, struct irq_domain *domain,
+					     struct irq_domain *msi_parent_domain,
+					     struct msi_domain_info *msi_child_info);
+};
+
+bool msi_parent_init_dev_msi_info(struct device *dev, struct irq_domain *domain,
+				  struct irq_domain *msi_parent_domain,
+				  struct msi_domain_info *msi_child_info);
+
 int msi_domain_set_affinity(struct irq_data *data, const struct cpumask *mask,
 			    bool force);
 
--- a/kernel/irq/msi.c
+++ b/kernel/irq/msi.c
@@ -826,6 +826,47 @@ struct irq_domain *msi_create_irq_domain
 	return domain;
 }
 
+/**
+ * msi_parent_init_dev_msi_info - Delegate initialization of device MSI info down
+ *				  in the domain hierarchy
+ * @dev:		The device for which the domain should be created
+ * @domain:		The domain in the hierarchy this op is being called on
+ * @msi_parent_domain:	The IRQ_DOMAIN_FLAG_MSI_PARENT domain for the child to
+ *			be created
+ * @msi_child_info:	The MSI domain info of the IRQ_DOMAIN_FLAG_MSI_DEVICE
+ *			domain to be created
+ *
+ * Return: true on success, false otherwise
+ *
+ * This is the most complex problem of per device MSI domains and the
+ * underlying interrupt domain hierarchy:
+ *
+ * The device domain to be initialized requests the broadest feature set
+ * possible and the underlying domain hierarchy puts restrictions on it.
+ *
+ * That's trivial for a simple parent->child relationship, but it gets
+ * interesting with an intermediate domain: root->parent->child.  The
+ * intermediate 'parent' can expand the capabilities which the 'root'
+ * domain is providing. So that creates a classic hen and egg problem:
+ * Which entity is doing the restrictions/expansions?
+ *
+ * One solution is to let the root domain handle the initialization that's
+ * why there is the @domain and the @msi_parent_domain pointer.
+ */
+bool msi_parent_init_dev_msi_info(struct device *dev, struct irq_domain *domain,
+				  struct irq_domain *msi_parent_domain,
+				  struct msi_domain_info *msi_child_info)
+{
+	struct irq_domain *parent = domain->parent;
+
+	if (WARN_ON_ONCE(!parent || !parent->msi_parent_ops ||
+			 !parent->msi_parent_ops->init_dev_msi_info))
+		return false;
+
+	return parent->msi_parent_ops->init_dev_msi_info(dev, parent, msi_parent_domain,
+							 msi_child_info);
+}
+
 int msi_domain_prepare_irqs(struct irq_domain *domain, struct device *dev,
 			    int nvec, msi_alloc_info_t *arg)
 {


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 03/33] genirq/msi: Provide data structs for per device domains
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
  2022-11-21 14:37 ` [patch V2 01/33] genirq/msi: Rearrange MSI domain flags Thomas Gleixner
  2022-11-21 14:37 ` [patch V2 02/33] genirq/msi: Provide struct msi_parent_ops Thomas Gleixner
@ 2022-11-21 14:37 ` Thomas Gleixner
  2022-11-23  7:57   ` Tian, Kevin
  2022-11-21 14:37 ` [patch V2 04/33] genirq/msi: Add size info to struct msi_domain_info Thomas Gleixner
                   ` (29 subsequent siblings)
  32 siblings, 1 reply; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:37 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe

Provide struct msi_domain_template which contains a bundle of struct
irq_chip, struct msi_domain_ops and struct msi_domain_info and a name
field.

This template is used by MSI device domain implementations to provide the
domain specific functionality, feature bits etc.

When a MSI domain is created the template is duplicated in the core code
so that it can be modified per instance. That means templates can be
marked const at the MSI device domain code.

The template is a bundle to avoid several allocations and duplications
of the involved structures.

The name field is used to construct the final domain and chip name via:

    $PREFIX-$NAME-$DEVNAME

where prefix is the optional prefix of the MSI parent domain, $NAME is the
provided name in template::chip and the device name so that the domain
is properly identified. On x86 this results for PCI/MSI in:

   PCI-MSI-0000:3d:00.1 or IR-PCI-MSIX-0000:3d:00.1

depending on the domain type and the availability of remapping.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 include/linux/msi.h |   16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

--- a/include/linux/msi.h
+++ b/include/linux/msi.h
@@ -24,6 +24,7 @@
 #include <linux/xarray.h>
 #include <linux/mutex.h>
 #include <linux/list.h>
+#include <linux/irq.h>
 #include <linux/bits.h>
 
 #include <asm/msi.h>
@@ -74,7 +75,6 @@ struct msi_msg {
 
 extern int pci_msi_ignore_mask;
 /* Helper functions */
-struct irq_data;
 struct msi_desc;
 struct pci_dev;
 struct platform_msi_priv_data;
@@ -434,6 +434,20 @@ struct msi_domain_info {
 	void				*data;
 };
 
+/**
+ * struct msi_domain_template - Template for MSI device domains
+ * @name:	Storage for the resulting name. Filled in by the core.
+ * @chip:	Interrupt chip for this domain
+ * @ops:	MSI domain ops
+ * @info:	MSI domain info data
+ */
+struct msi_domain_template {
+	char			name[48];
+	struct irq_chip		chip;
+	struct msi_domain_ops	ops;
+	struct msi_domain_info	info;
+};
+
 /*
  * Flags for msi_domain_info
  *


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 04/33] genirq/msi: Add size info to struct msi_domain_info
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
                   ` (2 preceding siblings ...)
  2022-11-21 14:37 ` [patch V2 03/33] genirq/msi: Provide data structs for per device domains Thomas Gleixner
@ 2022-11-21 14:37 ` Thomas Gleixner
  2022-11-21 14:37 ` [patch V2 05/33] genirq/msi: Split msi_create_irq_domain() Thomas Gleixner
                   ` (28 subsequent siblings)
  32 siblings, 0 replies; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:37 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe

To allow proper range checking especially for dynamic allocations add a
size field to struct msi_domain_info. If the field is 0 then the size is
unknown or unlimited (up to MSI_MAX_INDEX) to provide backwards
compability.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 include/linux/msi.h |    2 ++
 1 file changed, 2 insertions(+)

--- a/include/linux/msi.h
+++ b/include/linux/msi.h
@@ -414,6 +414,7 @@ struct msi_domain_ops {
  * struct msi_domain_info - MSI interrupt domain data
  * @flags:		Flags to decribe features and capabilities
  * @bus_token:		The domain bus token
+ * @hwsize:		The hardware table size (0 if unknown/unlimited)
  * @ops:		The callback data structure
  * @chip:		Optional: associated interrupt chip
  * @chip_data:		Optional: associated interrupt chip data
@@ -425,6 +426,7 @@ struct msi_domain_ops {
 struct msi_domain_info {
 	u32				flags;
 	enum irq_domain_bus_token	bus_token;
+	unsigned int			hwsize;
 	struct msi_domain_ops		*ops;
 	struct irq_chip			*chip;
 	void				*chip_data;


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 05/33] genirq/msi: Split msi_create_irq_domain()
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
                   ` (3 preceding siblings ...)
  2022-11-21 14:37 ` [patch V2 04/33] genirq/msi: Add size info to struct msi_domain_info Thomas Gleixner
@ 2022-11-21 14:37 ` Thomas Gleixner
  2022-11-21 14:37 ` [patch V2 06/33] genirq/irqdomain: Add irq_domain::dev for per device MSI domains Thomas Gleixner
                   ` (27 subsequent siblings)
  32 siblings, 0 replies; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:37 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe

Split the functionality of msi_create_irq_domain() so it can
be reused for creating per device irq domains.

No functional change.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 kernel/irq/msi.c |   32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)

--- a/kernel/irq/msi.c
+++ b/kernel/irq/msi.c
@@ -796,17 +796,10 @@ static void msi_domain_update_chip_ops(s
 		chip->irq_set_affinity = msi_domain_set_affinity;
 }
 
-/**
- * msi_create_irq_domain - Create an MSI interrupt domain
- * @fwnode:	Optional fwnode of the interrupt controller
- * @info:	MSI domain info
- * @parent:	Parent irq domain
- *
- * Return: pointer to the created &struct irq_domain or %NULL on failure
- */
-struct irq_domain *msi_create_irq_domain(struct fwnode_handle *fwnode,
-					 struct msi_domain_info *info,
-					 struct irq_domain *parent)
+static struct irq_domain *__msi_create_irq_domain(struct fwnode_handle *fwnode,
+						  struct msi_domain_info *info,
+						  unsigned int flags,
+						  struct irq_domain *parent)
 {
 	struct irq_domain *domain;
 
@@ -814,7 +807,7 @@ struct irq_domain *msi_create_irq_domain
 	if (info->flags & MSI_FLAG_USE_DEF_CHIP_OPS)
 		msi_domain_update_chip_ops(info);
 
-	domain = irq_domain_create_hierarchy(parent, IRQ_DOMAIN_FLAG_MSI, 0,
+	domain = irq_domain_create_hierarchy(parent, flags | IRQ_DOMAIN_FLAG_MSI, 0,
 					     fwnode, &msi_domain_ops, info);
 
 	if (domain) {
@@ -827,6 +820,21 @@ struct irq_domain *msi_create_irq_domain
 }
 
 /**
+ * msi_create_irq_domain - Create an MSI interrupt domain
+ * @fwnode:	Optional fwnode of the interrupt controller
+ * @info:	MSI domain info
+ * @parent:	Parent irq domain
+ *
+ * Return: pointer to the created &struct irq_domain or %NULL on failure
+ */
+struct irq_domain *msi_create_irq_domain(struct fwnode_handle *fwnode,
+					 struct msi_domain_info *info,
+					 struct irq_domain *parent)
+{
+	return __msi_create_irq_domain(fwnode, info, 0, parent);
+}
+
+/**
  * msi_parent_init_dev_msi_info - Delegate initialization of device MSI info down
  *				  in the domain hierarchy
  * @dev:		The device for which the domain should be created


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 06/33] genirq/irqdomain: Add irq_domain::dev for per device MSI domains
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
                   ` (4 preceding siblings ...)
  2022-11-21 14:37 ` [patch V2 05/33] genirq/msi: Split msi_create_irq_domain() Thomas Gleixner
@ 2022-11-21 14:37 ` Thomas Gleixner
  2022-11-21 14:37 ` [patch V2 07/33] genirq/msi: Provide msi_create/free_device_irq_domain() Thomas Gleixner
                   ` (26 subsequent siblings)
  32 siblings, 0 replies; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:37 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe

Per device domains require the device pointer of the device which
instantiated the domain for some purposes. Add the pointer to struct
irq_domain. It will be used in the next step which provides the
infrastructure to create per device MSI domains.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 include/linux/irqdomain.h |    4 ++++
 1 file changed, 4 insertions(+)

--- a/include/linux/irqdomain.h
+++ b/include/linux/irqdomain.h
@@ -132,6 +132,9 @@ struct irq_domain_chip_generic;
  * @gc:		Pointer to a list of generic chips. There is a helper function for
  *		setting up one or more generic chips for interrupt controllers
  *		drivers using the generic chip library which uses this pointer.
+ * @dev:	Pointer to the device which instantiated the irqdomain
+ *		With per device irq domains this is not necessarily the same
+ *		as @pm_dev.
  * @pm_dev:	Pointer to a device that can be utilized for power management
  *		purposes related to the irq domain.
  * @parent:	Pointer to parent irq_domain to support hierarchy irq_domains
@@ -155,6 +158,7 @@ struct irq_domain {
 	struct fwnode_handle		*fwnode;
 	enum irq_domain_bus_token	bus_token;
 	struct irq_domain_chip_generic	*gc;
+	struct device			*dev;
 	struct device			*pm_dev;
 #ifdef	CONFIG_IRQ_DOMAIN_HIERARCHY
 	struct irq_domain		*parent;


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 07/33] genirq/msi: Provide msi_create/free_device_irq_domain()
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
                   ` (5 preceding siblings ...)
  2022-11-21 14:37 ` [patch V2 06/33] genirq/irqdomain: Add irq_domain::dev for per device MSI domains Thomas Gleixner
@ 2022-11-21 14:37 ` Thomas Gleixner
  2022-11-23  8:02   ` Tian, Kevin
  2022-11-21 14:37 ` [patch V2 08/33] genirq/msi: Provide msi_match_device_domain() Thomas Gleixner
                   ` (25 subsequent siblings)
  32 siblings, 1 reply; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:37 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe

Now that all prerequsites are in place, provide the actual interfaces for
creating and removing per device interrupt domains.

MSI device interrupt domains are created from the provided
msi_domain_template which is duplicated so that it can be modified for the
particular device.

The name of the domain and the name of the interrupt chip are composed by
"$(PREFIX)$(CHIPNAME)-$(DEVNAME)"

  $PREFIX:   The optional prefix provided by the underlying MSI parent domain
             via msi_parent_ops::prefix.
  $CHIPNAME: The name of the irq_chip in the template
  $DEVNAME:  The name of the device

The domain is further initialized through a MSI parent domain callback which
fills in the required functionality for the parent domain or domains further
down the hierarchy. This initialization can fail, e.g. when the requested
feature or MSI domain type cannot be supported.

The domain pointer is stored in the pointer array inside of msi_device_data
which is attached to the domain.

The domain can be removed via the API or left for disposal via devres when
the device is torn down. The API removal is useful e.g. for PCI to have
seperate domains for MSI and MSI-X, which are mutually exclusive and always
occupy the default domain id slot.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 include/linux/msi.h |    6 ++
 kernel/irq/msi.c    |  146 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 152 insertions(+)

--- a/include/linux/msi.h
+++ b/include/linux/msi.h
@@ -536,6 +536,12 @@ struct irq_domain *msi_create_irq_domain
 					 struct msi_domain_info *info,
 					 struct irq_domain *parent);
 
+bool msi_create_device_irq_domain(struct device *dev, unsigned int domid,
+				  const struct msi_domain_template *template,
+				  unsigned int hwsize, void *domain_data,
+				  void *chip_data);
+void msi_remove_device_irq_domain(struct device *dev, unsigned int domid);
+
 int msi_domain_alloc_irqs_range_locked(struct device *dev, unsigned int domid,
 				       unsigned int first, unsigned int last);
 int msi_domain_alloc_irqs_range(struct device *dev, unsigned int domid,
--- a/kernel/irq/msi.c
+++ b/kernel/irq/msi.c
@@ -53,6 +53,14 @@ static inline void msi_setup_default_irq
 		md->__irqdomains[MSI_DEFAULT_DOMAIN] = dev->msi.domain;
 }
 
+static inline void msi_remove_device_irqdomains(struct device *dev, struct msi_device_data *md)
+{
+	int domid;
+
+	for (domid = 0; domid < MSI_MAX_DEVICE_IRQDOMAINS; domid++)
+		msi_remove_device_irq_domain(dev, domid);
+}
+
 static int msi_get_domain_base_index(struct device *dev, unsigned int domid)
 {
 	lockdep_assert_held(&dev->msi.data->mutex);
@@ -279,6 +287,7 @@ static void msi_device_data_release(stru
 {
 	struct msi_device_data *md = res;
 
+	msi_remove_device_irqdomains(dev, md);
 	WARN_ON_ONCE(!xa_empty(&md->__store));
 	xa_destroy(&md->__store);
 	dev->msi.data = NULL;
@@ -875,6 +884,143 @@ bool msi_parent_init_dev_msi_info(struct
 							 msi_child_info);
 }
 
+/**
+ * msi_create_device_irq_domain - Create a device MSI interrupt domain
+ * @dev:		Pointer to the device
+ * @domid:		Domain id
+ * @template:		MSI domain info bundle used as template
+ * @hwsize:		Maximum number of MSI table entries (0 if unknown or unlimited)
+ * @domain_data:	Optional pointer to domain specific data which is set in
+ *			msi_domain_info::data
+ * @chip_data:		Optional pointer to chip specific data which is set in
+ *			msi_domain_info::chip_data
+ *
+ * Return: True on success, false otherwise
+ *
+ * There is no firmware node required for this interface because the per
+ * device domains are software constructs which are actually closer to the
+ * hardware reality than any firmware can describe them.
+ *
+ * The domain name and the irq chip name for a MSI device domain are
+ * composed by: "$(PREFIX)$(CHIPNAME)-$(DEVNAME)"
+ *
+ * $PREFIX:   Optional prefix provided by the underlying MSI parent domain
+ *	      via msi_parent_ops::prefix. If that pointer is NULL the prefix
+ *	      is empty.
+ * $CHIPNAME: The name of the irq_chip in @template
+ * $DEVNAME:  The name of the device
+ *
+ * This results in understandable chip names and hardware interrupt numbers
+ * in e.g. /proc/interrupts
+ *
+ * PCI-MSI-0000:00:1c.0     0-edge  Parent domain has no prefix
+ * IR-PCI-MSI-0000:00:1c.4  0-edge  Same with interrupt remapping prefix 'IR-'
+ *
+ * IR-PCI-MSIX-0000:3d:00.0 0-edge  Hardware interrupt numbers reflect
+ * IR-PCI-MSIX-0000:3d:00.0 1-edge  the real MSI-X index on that device
+ * IR-PCI-MSIX-0000:3d:00.0 2-edge
+ *
+ * On IMS domains the hardware interrupt number is either a table entry
+ * index or a purely software managed index but it is guaranteed to be
+ * unique.
+ *
+ * The domain pointer is stored in @dev::msi::data::__irqdomains[]. All
+ * subsequent operations on the domain depend on the domain id.
+ *
+ * The domain is automatically freed when the device is removed via devres
+ * in the context of @dev::msi::data freeing, but it can also be
+ * independently removed via @msi_remove_device_irq_domain().
+ */
+bool msi_create_device_irq_domain(struct device *dev, unsigned int domid,
+				  const struct msi_domain_template *template,
+				  unsigned int hwsize, void *domain_data,
+				  void *chip_data)
+{
+	struct irq_domain *domain, *parent = dev->msi.domain;
+	const struct msi_parent_ops *pops;
+	struct msi_domain_template *bundle;
+	struct fwnode_handle *fwnode;
+
+	if (!irq_domain_is_msi_parent(parent))
+		return false;
+
+	if (domid >= MSI_MAX_DEVICE_IRQDOMAINS)
+		return false;
+
+	bundle = kmemdup(template, sizeof(*bundle), GFP_KERNEL);
+	if (!bundle)
+		return false;
+
+	bundle->info.hwsize = hwsize ? hwsize : MSI_MAX_INDEX;
+	bundle->info.chip = &bundle->chip;
+	bundle->info.ops = &bundle->ops;
+	bundle->info.data = domain_data;
+	bundle->info.chip_data = chip_data;
+
+	pops = parent->msi_parent_ops;
+	snprintf(bundle->name, sizeof(bundle->name), "%s%s-%s",
+		 pops->prefix ? : "", bundle->chip.name, dev_name(dev));
+	bundle->chip.name = bundle->name;
+
+	fwnode = irq_domain_alloc_named_fwnode(bundle->name);
+	if (!fwnode)
+		goto free_bundle;
+
+	if (msi_setup_device_data(dev))
+		goto free_fwnode;
+
+	msi_lock_descs(dev);
+
+	if (WARN_ON_ONCE(msi_get_device_domain(dev, domid)))
+		goto fail;
+
+	if (!pops->init_dev_msi_info(dev, parent, parent, &bundle->info))
+		goto fail;
+
+	domain = __msi_create_irq_domain(fwnode, &bundle->info, IRQ_DOMAIN_FLAG_MSI_DEVICE, parent);
+	if (!domain)
+		goto fail;
+
+	domain->dev = dev;
+	dev->msi.data->__irqdomains[domid] = domain;
+	msi_unlock_descs(dev);
+	return true;
+
+fail:
+	msi_unlock_descs(dev);
+free_fwnode:
+	kfree(fwnode);
+free_bundle:
+	kfree(bundle);
+	return false;
+}
+
+/**
+ * msi_remove_device_irq_domain - Free a device MSI interrupt domain
+ * @dev:	Pointer to the device
+ * @domid:	Domain id
+ */
+void msi_remove_device_irq_domain(struct device *dev, unsigned int domid)
+{
+	struct msi_domain_info *info;
+	struct irq_domain *domain;
+
+	msi_lock_descs(dev);
+
+	domain = msi_get_device_domain(dev, domid);
+
+	if (!domain || !irq_domain_is_msi_device(domain))
+		goto unlock;
+
+	dev->msi.data->__irqdomains[domid] = NULL;
+	info = domain->host_data;
+	irq_domain_remove(domain);
+	kfree(container_of(info, struct msi_domain_template, info));
+
+unlock:
+	msi_unlock_descs(dev);
+}
+
 int msi_domain_prepare_irqs(struct irq_domain *domain, struct device *dev,
 			    int nvec, msi_alloc_info_t *arg)
 {


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 08/33] genirq/msi: Provide msi_match_device_domain()
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
                   ` (6 preceding siblings ...)
  2022-11-21 14:37 ` [patch V2 07/33] genirq/msi: Provide msi_create/free_device_irq_domain() Thomas Gleixner
@ 2022-11-21 14:37 ` Thomas Gleixner
  2022-11-21 14:37 ` [patch V2 09/33] genirq/msi: Add range checking to msi_insert_desc() Thomas Gleixner
                   ` (24 subsequent siblings)
  32 siblings, 0 replies; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:37 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe

Provide an interface to match a per device domain bus token. This allows to
query which type of domain is installed for a particular domain id. Will be
used for PCI to avoid frequent create/remove cycles for the MSI resp. MSI-X
domains.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 include/linux/msi.h |    3 +++
 kernel/irq/msi.c    |   25 +++++++++++++++++++++++++
 2 files changed, 28 insertions(+)

--- a/include/linux/msi.h
+++ b/include/linux/msi.h
@@ -542,6 +542,9 @@ bool msi_create_device_irq_domain(struct
 				  void *chip_data);
 void msi_remove_device_irq_domain(struct device *dev, unsigned int domid);
 
+bool msi_match_device_irq_domain(struct device *dev, unsigned int domid,
+				 enum irq_domain_bus_token bus_token);
+
 int msi_domain_alloc_irqs_range_locked(struct device *dev, unsigned int domid,
 				       unsigned int first, unsigned int last);
 int msi_domain_alloc_irqs_range(struct device *dev, unsigned int domid,
--- a/kernel/irq/msi.c
+++ b/kernel/irq/msi.c
@@ -1021,6 +1021,31 @@ void msi_remove_device_irq_domain(struct
 	msi_unlock_descs(dev);
 }
 
+/**
+ * msi_match_device_irq_domain - Match a device irq domain against a bus token
+ * @dev:	Pointer to the device
+ * @domid:	Domain id
+ * @bus_token:	Bus token to match against the domain bus token
+ *
+ * Return: True if device domain exists and bus tokens match.
+ */
+bool msi_match_device_irq_domain(struct device *dev, unsigned int domid,
+				 enum irq_domain_bus_token bus_token)
+{
+	struct msi_domain_info *info;
+	struct irq_domain *domain;
+	bool ret = false;
+
+	msi_lock_descs(dev);
+	domain = msi_get_device_domain(dev, domid);
+	if (domain && irq_domain_is_msi_device(domain)) {
+		info = domain->host_data;
+		ret = info->bus_token == bus_token;
+	}
+	msi_unlock_descs(dev);
+	return ret;
+}
+
 int msi_domain_prepare_irqs(struct irq_domain *domain, struct device *dev,
 			    int nvec, msi_alloc_info_t *arg)
 {


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 09/33] genirq/msi: Add range checking to msi_insert_desc()
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
                   ` (7 preceding siblings ...)
  2022-11-21 14:37 ` [patch V2 08/33] genirq/msi: Provide msi_match_device_domain() Thomas Gleixner
@ 2022-11-21 14:37 ` Thomas Gleixner
  2022-11-21 14:37 ` [patch V2 10/33] PCI/MSI: Split __pci_write_msi_msg() Thomas Gleixner
                   ` (23 subsequent siblings)
  32 siblings, 0 replies; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:37 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe

Per device domains provide the domain size to the core code. This allows
range checking on insertion of MSI descriptors and also paves the way for
dynamic index allocations which are required e.g. for IMS. This avoids
external mechanisms like bitmaps on the device side and just utilizes
the core internal MSI descriptor store for it.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 kernel/irq/msi.c |   40 +++++++++++++++++++++++++++++++++++-----
 1 file changed, 35 insertions(+), 5 deletions(-)

--- a/kernel/irq/msi.c
+++ b/kernel/irq/msi.c
@@ -74,6 +74,7 @@ static int msi_get_domain_base_index(str
 	return domid * MSI_XA_DOMAIN_SIZE;
 }
 
+static unsigned int msi_domain_get_hwsize(struct device *dev, unsigned int domid);
 
 /**
  * msi_alloc_desc - Allocate an initialized msi_desc
@@ -116,6 +117,7 @@ static int msi_insert_desc(struct device
 			   unsigned int domid, unsigned int index)
 {
 	struct msi_device_data *md = dev->msi.data;
+	unsigned int hwsize;
 	int baseidx, ret;
 
 	baseidx = msi_get_domain_base_index(dev, domid);
@@ -124,6 +126,12 @@ static int msi_insert_desc(struct device
 		goto fail;
 	}
 
+	hwsize = msi_domain_get_hwsize(dev, domid);
+	if (index >= hwsize) {
+		ret = -ERANGE;
+		goto fail;
+	}
+
 	desc->msi_index = index;
 	index += baseidx;
 	ret = xa_insert(&md->__store, index, desc, GFP_KERNEL);
@@ -179,9 +187,11 @@ static bool msi_desc_match(struct msi_de
 
 static bool msi_ctrl_range_valid(struct device *dev, struct msi_ctrl *ctrl)
 {
+	unsigned int hwsize = msi_domain_get_hwsize(dev, ctrl->domid);
+
 	if (WARN_ON_ONCE(ctrl->first > ctrl->last ||
-			 ctrl->first > MSI_MAX_INDEX ||
-			 ctrl->last > MSI_MAX_INDEX))
+			 ctrl->first >= hwsize ||
+			 ctrl->last >= hwsize))
 		return false;
 	return true;
 }
@@ -446,7 +456,7 @@ unsigned int msi_domain_get_virq(struct
 	if (!dev->msi.data)
 		return 0;
 
-	if (WARN_ON_ONCE(index > MSI_MAX_INDEX))
+	if (WARN_ON_ONCE(index >= msi_domain_get_hwsize(dev, domid)))
 		return 0;
 
 	/* This check is only valid for the PCI default MSI domain */
@@ -614,6 +624,25 @@ static struct irq_domain *msi_get_device
 	return domain;
 }
 
+static unsigned int msi_domain_get_hwsize(struct device *dev, unsigned int domid)
+{
+	struct msi_domain_info *info;
+	struct irq_domain *domain;
+
+	/*
+	 * Retrieve the MSI domain for range checking. If there is no
+	 * domain or the domain is not a per device domain, then assume
+	 * full MSI range and pray that the calling subsystem knows what it
+	 * is doing.
+	 */
+	domain = msi_get_device_domain(dev, domid);
+	if (domain && irq_domain_is_msi_device(domain)) {
+		info = domain->host_data;
+		return info->hwsize;
+	}
+	return MSI_MAX_INDEX + 1;
+}
+
 static inline void irq_chip_write_msi_msg(struct irq_data *data,
 					  struct msi_msg *msg)
 {
@@ -1390,7 +1419,7 @@ int msi_domain_alloc_irqs_all_locked(str
 	struct msi_ctrl ctrl = {
 		.domid	= domid,
 		.first	= 0,
-		.last	= MSI_MAX_INDEX,
+		.last	= msi_domain_get_hwsize(dev, domid) - 1,
 		.nirqs	= nirqs,
 	};
 
@@ -1506,7 +1535,8 @@ void msi_domain_free_irqs_range(struct d
  */
 void msi_domain_free_irqs_all_locked(struct device *dev, unsigned int domid)
 {
-	msi_domain_free_irqs_range_locked(dev, domid, 0, MSI_MAX_INDEX);
+	msi_domain_free_irqs_range_locked(dev, domid, 0,
+					  msi_domain_get_hwsize(dev, domid) - 1);
 }
 
 /**


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 10/33] PCI/MSI: Split __pci_write_msi_msg()
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
                   ` (8 preceding siblings ...)
  2022-11-21 14:37 ` [patch V2 09/33] genirq/msi: Add range checking to msi_insert_desc() Thomas Gleixner
@ 2022-11-21 14:37 ` Thomas Gleixner
  2022-11-21 14:37 ` [patch V2 11/33] genirq/msi: Provide BUS_DEVICE_PCI_MSI[X] Thomas Gleixner
                   ` (22 subsequent siblings)
  32 siblings, 0 replies; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:37 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe,
	Ahmed S. Darwish

The upcoming per device MSI domains will create different domains for MSI
and MSI-X. Split the write message function into MSI and MSI-X helpers so
they can be used by those new domain functions seperately.

Signed-off-by: Ahmed S. Darwish <darwi@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
---
 drivers/pci/msi/msi.c |  104 +++++++++++++++++++++++++-------------------------
 1 file changed, 54 insertions(+), 50 deletions(-)

--- a/drivers/pci/msi/msi.c
+++ b/drivers/pci/msi/msi.c
@@ -180,6 +180,58 @@ void __pci_read_msi_msg(struct msi_desc
 	}
 }
 
+static inline void pci_write_msg_msi(struct pci_dev *dev, struct msi_desc *desc,
+				     struct msi_msg *msg)
+{
+	int pos = dev->msi_cap;
+	u16 msgctl;
+
+	pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &msgctl);
+	msgctl &= ~PCI_MSI_FLAGS_QSIZE;
+	msgctl |= desc->pci.msi_attrib.multiple << 4;
+	pci_write_config_word(dev, pos + PCI_MSI_FLAGS, msgctl);
+
+	pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_LO, msg->address_lo);
+	if (desc->pci.msi_attrib.is_64) {
+		pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_HI,  msg->address_hi);
+		pci_write_config_word(dev, pos + PCI_MSI_DATA_64, msg->data);
+	} else {
+		pci_write_config_word(dev, pos + PCI_MSI_DATA_32, msg->data);
+	}
+	/* Ensure that the writes are visible in the device */
+	pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &msgctl);
+}
+
+static inline void pci_write_msg_msix(struct msi_desc *desc, struct msi_msg *msg)
+{
+	void __iomem *base = pci_msix_desc_addr(desc);
+	u32 ctrl = desc->pci.msix_ctrl;
+	bool unmasked = !(ctrl & PCI_MSIX_ENTRY_CTRL_MASKBIT);
+
+	if (desc->pci.msi_attrib.is_virtual)
+		return;
+	/*
+	 * The specification mandates that the entry is masked
+	 * when the message is modified:
+	 *
+	 * "If software changes the Address or Data value of an
+	 * entry while the entry is unmasked, the result is
+	 * undefined."
+	 */
+	if (unmasked)
+		pci_msix_write_vector_ctrl(desc, ctrl | PCI_MSIX_ENTRY_CTRL_MASKBIT);
+
+	writel(msg->address_lo, base + PCI_MSIX_ENTRY_LOWER_ADDR);
+	writel(msg->address_hi, base + PCI_MSIX_ENTRY_UPPER_ADDR);
+	writel(msg->data, base + PCI_MSIX_ENTRY_DATA);
+
+	if (unmasked)
+		pci_msix_write_vector_ctrl(desc, ctrl);
+
+	/* Ensure that the writes are visible in the device */
+	readl(base + PCI_MSIX_ENTRY_DATA);
+}
+
 void __pci_write_msi_msg(struct msi_desc *entry, struct msi_msg *msg)
 {
 	struct pci_dev *dev = msi_desc_to_pci_dev(entry);
@@ -187,63 +239,15 @@ void __pci_write_msi_msg(struct msi_desc
 	if (dev->current_state != PCI_D0 || pci_dev_is_disconnected(dev)) {
 		/* Don't touch the hardware now */
 	} else if (entry->pci.msi_attrib.is_msix) {
-		void __iomem *base = pci_msix_desc_addr(entry);
-		u32 ctrl = entry->pci.msix_ctrl;
-		bool unmasked = !(ctrl & PCI_MSIX_ENTRY_CTRL_MASKBIT);
-
-		if (entry->pci.msi_attrib.is_virtual)
-			goto skip;
-
-		/*
-		 * The specification mandates that the entry is masked
-		 * when the message is modified:
-		 *
-		 * "If software changes the Address or Data value of an
-		 * entry while the entry is unmasked, the result is
-		 * undefined."
-		 */
-		if (unmasked)
-			pci_msix_write_vector_ctrl(entry, ctrl | PCI_MSIX_ENTRY_CTRL_MASKBIT);
-
-		writel(msg->address_lo, base + PCI_MSIX_ENTRY_LOWER_ADDR);
-		writel(msg->address_hi, base + PCI_MSIX_ENTRY_UPPER_ADDR);
-		writel(msg->data, base + PCI_MSIX_ENTRY_DATA);
-
-		if (unmasked)
-			pci_msix_write_vector_ctrl(entry, ctrl);
-
-		/* Ensure that the writes are visible in the device */
-		readl(base + PCI_MSIX_ENTRY_DATA);
+		pci_write_msg_msix(entry, msg);
 	} else {
-		int pos = dev->msi_cap;
-		u16 msgctl;
-
-		pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &msgctl);
-		msgctl &= ~PCI_MSI_FLAGS_QSIZE;
-		msgctl |= entry->pci.msi_attrib.multiple << 4;
-		pci_write_config_word(dev, pos + PCI_MSI_FLAGS, msgctl);
-
-		pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_LO,
-				       msg->address_lo);
-		if (entry->pci.msi_attrib.is_64) {
-			pci_write_config_dword(dev, pos + PCI_MSI_ADDRESS_HI,
-					       msg->address_hi);
-			pci_write_config_word(dev, pos + PCI_MSI_DATA_64,
-					      msg->data);
-		} else {
-			pci_write_config_word(dev, pos + PCI_MSI_DATA_32,
-					      msg->data);
-		}
-		/* Ensure that the writes are visible in the device */
-		pci_read_config_word(dev, pos + PCI_MSI_FLAGS, &msgctl);
+		pci_write_msg_msi(dev, entry, msg);
 	}
 
-skip:
 	entry->msg = *msg;
 
 	if (entry->write_msi_msg)
 		entry->write_msi_msg(entry, entry->write_msi_msg_data);
-
 }
 
 void pci_write_msi_msg(unsigned int irq, struct msi_msg *msg)


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 11/33] genirq/msi: Provide BUS_DEVICE_PCI_MSI[X]
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
                   ` (9 preceding siblings ...)
  2022-11-21 14:37 ` [patch V2 10/33] PCI/MSI: Split __pci_write_msi_msg() Thomas Gleixner
@ 2022-11-21 14:37 ` Thomas Gleixner
  2022-11-21 14:38 ` [patch V2 12/33] PCI/MSI: Add support for per device MSI[X] domains Thomas Gleixner
                   ` (21 subsequent siblings)
  32 siblings, 0 replies; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:37 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe

Provide new bus tokens for the upcoming per device PCI/MSI and PCI/MSIX
interrupt domains.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 include/linux/irqdomain_defs.h |    2 ++
 kernel/irq/msi.c               |    4 ++++
 2 files changed, 6 insertions(+)

--- a/include/linux/irqdomain_defs.h
+++ b/include/linux/irqdomain_defs.h
@@ -21,6 +21,8 @@ enum irq_domain_bus_token {
 	DOMAIN_BUS_TI_SCI_INTA_MSI,
 	DOMAIN_BUS_WAKEUP,
 	DOMAIN_BUS_VMD_MSI,
+	DOMAIN_BUS_PCI_DEVICE_MSI,
+	DOMAIN_BUS_PCI_DEVICE_MSIX,
 };
 
 #endif /* _LINUX_IRQDOMAIN_DEFS_H */
--- a/kernel/irq/msi.c
+++ b/kernel/irq/msi.c
@@ -1147,6 +1147,8 @@ static bool msi_check_reservation_mode(s
 
 	switch(domain->bus_token) {
 	case DOMAIN_BUS_PCI_MSI:
+	case DOMAIN_BUS_PCI_DEVICE_MSI:
+	case DOMAIN_BUS_PCI_DEVICE_MSIX:
 	case DOMAIN_BUS_VMD_MSI:
 		break;
 	default:
@@ -1172,6 +1174,8 @@ static int msi_handle_pci_fail(struct ir
 {
 	switch(domain->bus_token) {
 	case DOMAIN_BUS_PCI_MSI:
+	case DOMAIN_BUS_PCI_DEVICE_MSI:
+	case DOMAIN_BUS_PCI_DEVICE_MSIX:
 	case DOMAIN_BUS_VMD_MSI:
 		if (IS_ENABLED(CONFIG_PCI_MSI))
 			break;


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 12/33] PCI/MSI: Add support for per device MSI[X] domains
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
                   ` (10 preceding siblings ...)
  2022-11-21 14:37 ` [patch V2 11/33] genirq/msi: Provide BUS_DEVICE_PCI_MSI[X] Thomas Gleixner
@ 2022-11-21 14:38 ` Thomas Gleixner
  2022-11-23  8:08   ` Tian, Kevin
  2022-11-21 14:38 ` [patch V2 13/33] x86/apic/vector: Provide MSI parent domain Thomas Gleixner
                   ` (20 subsequent siblings)
  32 siblings, 1 reply; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:38 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe,
	Ahmed S. Darwish

Provide a template and the necessary callbacks to create PCI/MSI and
PCI/MSI-X domains.

The domains are created when MSI or MSI-X is enabled. The domain's lifetime
is either the device lifetime or in case that e.g. MSI-X was tried first
and failed, then the MSI-X domain is removed and a MSI domain is created as
both are mutually exclusive and reside in the default domain ID slot of the
per device domain pointer array.

Also expand pci_msi_domain_supports() to handle feature checks correctly
even in the case that the per device domain was not yet created by checking
the features supported by the MSI parent.

Add the necessary setup calls into the MSI and MSI-X enable code path.
These setup calls are backwards compatible. They return success when there
is no parent domain found, which means the existing global domains or the
legacy allocation path keep just working.

Co-developed-by: Ahmed S. Darwish <darwi@linutronix.de>
Signed-off-by: Ahmed S. Darwish <darwi@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
---
 drivers/pci/msi/irqdomain.c |  188 +++++++++++++++++++++++++++++++++++++++++++-
 drivers/pci/msi/msi.c       |   16 +++
 drivers/pci/msi/msi.h       |    2 
 3 files changed, 201 insertions(+), 5 deletions(-)

--- a/drivers/pci/msi/irqdomain.c
+++ b/drivers/pci/msi/irqdomain.c
@@ -139,6 +139,170 @@ struct irq_domain *pci_msi_create_irq_do
 }
 EXPORT_SYMBOL_GPL(pci_msi_create_irq_domain);
 
+/*
+ * Per device MSI[-X] domain functionality
+ */
+static void pci_device_domain_set_desc(msi_alloc_info_t *arg, struct msi_desc *desc)
+{
+	arg->desc = desc;
+	arg->hwirq = desc->msi_index;
+}
+
+static void pci_mask_msi(struct irq_data *data)
+{
+	struct msi_desc *desc = irq_data_get_msi_desc(data);
+
+	pci_msi_mask(desc, BIT(data->irq - desc->irq));
+}
+
+static void pci_unmask_msi(struct irq_data *data)
+{
+	struct msi_desc *desc = irq_data_get_msi_desc(data);
+
+	pci_msi_unmask(desc, BIT(data->irq - desc->irq));
+}
+
+#ifdef CONFIG_GENERIC_IRQ_RESERVATION_MODE
+# define MSI_REACTIVATE		MSI_FLAG_MUST_REACTIVATE
+#else
+# define MSI_REACTIVATE		0
+#endif
+
+#define MSI_COMMON_FLAGS	(MSI_FLAG_FREE_MSI_DESCS |	\
+				 MSI_FLAG_ACTIVATE_EARLY |	\
+				 MSI_FLAG_DEV_SYSFS |		\
+				 MSI_REACTIVATE)
+
+static struct msi_domain_template pci_msi_template = {
+	.chip = {
+		.name			= "PCI-MSI",
+		.irq_mask		= pci_mask_msi,
+		.irq_unmask		= pci_unmask_msi,
+		.irq_write_msi_msg	= pci_msi_domain_write_msg,
+		.flags			= IRQCHIP_ONESHOT_SAFE,
+	},
+
+	.ops = {
+		.set_desc		= pci_device_domain_set_desc,
+	},
+
+	.info = {
+		.flags			= MSI_COMMON_FLAGS | MSI_FLAG_MULTI_PCI_MSI,
+		.bus_token		= DOMAIN_BUS_PCI_DEVICE_MSI,
+	},
+};
+
+static void pci_mask_msix(struct irq_data *data)
+{
+	pci_msix_mask(irq_data_get_msi_desc(data));
+}
+
+static void pci_unmask_msix(struct irq_data *data)
+{
+	pci_msix_unmask(irq_data_get_msi_desc(data));
+}
+
+static struct msi_domain_template pci_msix_template = {
+	.chip = {
+		.name			= "PCI-MSIX",
+		.irq_mask		= pci_mask_msix,
+		.irq_unmask		= pci_unmask_msix,
+		.irq_write_msi_msg	= pci_msi_domain_write_msg,
+		.flags			= IRQCHIP_ONESHOT_SAFE,
+	},
+
+	.ops = {
+		.set_desc		= pci_device_domain_set_desc,
+	},
+
+	.info = {
+		.flags			= MSI_COMMON_FLAGS | MSI_FLAG_PCI_MSIX,
+		.bus_token		= DOMAIN_BUS_PCI_DEVICE_MSIX,
+	},
+};
+
+static bool pci_match_device_domain(struct pci_dev *pdev, enum irq_domain_bus_token bus_token)
+{
+	return msi_match_device_irq_domain(&pdev->dev, MSI_DEFAULT_DOMAIN, bus_token);
+}
+
+static bool pci_create_device_domain(struct pci_dev *pdev, struct msi_domain_template *tmpl,
+				     unsigned int hwsize)
+{
+	struct irq_domain *domain = dev_get_msi_domain(&pdev->dev);
+
+	if (!domain || !irq_domain_is_msi_parent(domain))
+		return true;
+
+	return msi_create_device_irq_domain(&pdev->dev, MSI_DEFAULT_DOMAIN, tmpl,
+					    hwsize, NULL, NULL);
+}
+
+/**
+ * pci_setup_msi_device_domain - Setup a device MSI interrupt domain
+ * @pdev:	The PCI device to create the domain on
+ *
+ * Return:
+ *  True when:
+ *	- The device does not have a MSI parent irq domain associated,
+ *	  which keeps the legacy architecture specific and the global
+ *	  PCI/MSI domain models working
+ *	- The MSI domain exists already
+ *	- The MSI domain was successfully allocated
+ *  False when:
+ *	- MSI-X is enabled
+ *	- The domain creation fails.
+ *
+ * The created MSI domain is preserved until:
+ *	- The device is removed
+ *	- MSI is disabled and a MSI-X domain is created
+ */
+bool pci_setup_msi_device_domain(struct pci_dev *pdev)
+{
+	if (WARN_ON_ONCE(pdev->msix_enabled))
+		return false;
+
+	if (pci_match_device_domain(pdev, DOMAIN_BUS_PCI_DEVICE_MSI))
+		return true;
+	if (pci_match_device_domain(pdev, DOMAIN_BUS_PCI_DEVICE_MSIX))
+		msi_remove_device_irq_domain(&pdev->dev, MSI_DEFAULT_DOMAIN);
+
+	return pci_create_device_domain(pdev, &pci_msi_template, 1);
+}
+
+/**
+ * pci_setup_msix_device_domain - Setup a device MSI-X interrupt domain
+ * @pdev:	The PCI device to create the domain on
+ * @hwsize:	The size of the MSI-X vector table
+ *
+ * Return:
+ *  True when:
+ *	- The device does not have a MSI parent irq domain associated,
+ *	  which keeps the legacy architecture specific and the global
+ *	  PCI/MSI domain models working
+ *	- The MSI-X domain exists already
+ *	- The MSI-X domain was successfully allocated
+ *  False when:
+ *	- MSI is enabled
+ *	- The domain creation fails.
+ *
+ * The created MSI-X domain is preserved until:
+ *	- The device is removed
+ *	- MSI-X is disabled and a MSI domain is created
+ */
+bool pci_setup_msix_device_domain(struct pci_dev *pdev, unsigned int hwsize)
+{
+	if (WARN_ON_ONCE(pdev->msix_enabled))
+		return false;
+
+	if (pci_match_device_domain(pdev, DOMAIN_BUS_PCI_DEVICE_MSIX))
+		return true;
+	if (pci_match_device_domain(pdev, DOMAIN_BUS_PCI_DEVICE_MSI))
+		msi_remove_device_irq_domain(&pdev->dev, MSI_DEFAULT_DOMAIN);
+
+	return pci_create_device_domain(pdev, &pci_msix_template, hwsize);
+}
+
 /**
  * pci_msi_domain_supports - Check for support of a particular feature flag
  * @pdev:		The PCI device to operate on
@@ -152,13 +316,33 @@ bool pci_msi_domain_supports(struct pci_
 {
 	struct msi_domain_info *info;
 	struct irq_domain *domain;
+	unsigned int supported;
 
 	domain = dev_get_msi_domain(&pdev->dev);
 
 	if (!domain || !irq_domain_is_hierarchy(domain))
 		return mode == ALLOW_LEGACY;
-	info = domain->host_data;
-	return (info->flags & feature_mask) == feature_mask;
+
+	if (!irq_domain_is_msi_parent(domain)) {
+		/*
+		 * For "global" PCI/MSI interrupt domains the associated
+		 * msi_domain_info::flags is the authoritive source of
+		 * information.
+		 */
+		info = domain->host_data;
+		supported = info->flags;
+	} else {
+		/*
+		 * For MSI parent domains the supported feature set
+		 * is avaliable in the parent ops. This makes checks
+		 * possible before actually instantiating the
+		 * per device domain because the parent is never
+		 * expanding the PCI/MSI functionality.
+		 */
+		supported = domain->msi_parent_ops->supported_flags;
+	}
+
+	return (supported & feature_mask) == feature_mask;
 }
 
 /*
--- a/drivers/pci/msi/msi.c
+++ b/drivers/pci/msi/msi.c
@@ -436,6 +436,9 @@ int __pci_enable_msi_range(struct pci_de
 	if (rc)
 		return rc;
 
+	if (!pci_setup_msi_device_domain(dev))
+		return -ENODEV;
+
 	for (;;) {
 		if (affd) {
 			nvec = irq_calc_affinity_vectors(minvec, nvec, affd);
@@ -787,9 +790,13 @@ int __pci_enable_msix_range(struct pci_d
 	if (!pci_msix_validate_entries(dev, entries, nvec, hwsize))
 		return -EINVAL;
 
-	/* PCI_IRQ_VIRTUAL is a horrible hack! */
-	if (nvec > hwsize && !(flags & PCI_IRQ_VIRTUAL))
-		nvec = hwsize;
+	if (hwsize < nvec) {
+		/* Keep the IRQ virtual hackery working */
+		if (flags & PCI_IRQ_VIRTUAL)
+			hwsize = nvec;
+		else
+			nvec = hwsize;
+	}
 
 	if (nvec < minvec)
 		return -ENOSPC;
@@ -798,6 +805,9 @@ int __pci_enable_msix_range(struct pci_d
 	if (rc)
 		return rc;
 
+	if (!pci_setup_msix_device_domain(dev, hwsize))
+		return -ENODEV;
+
 	for (;;) {
 		if (affd) {
 			nvec = irq_calc_affinity_vectors(minvec, nvec, affd);
--- a/drivers/pci/msi/msi.h
+++ b/drivers/pci/msi/msi.h
@@ -105,6 +105,8 @@ enum support_mode {
 };
 
 bool pci_msi_domain_supports(struct pci_dev *dev, unsigned int feature_mask, enum support_mode mode);
+bool pci_setup_msi_device_domain(struct pci_dev *pdev);
+bool pci_setup_msix_device_domain(struct pci_dev *pdev, unsigned int hwsize);
 
 /* Legacy (!IRQDOMAIN) fallbacks */
 


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 13/33] x86/apic/vector: Provide MSI parent domain
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
                   ` (11 preceding siblings ...)
  2022-11-21 14:38 ` [patch V2 12/33] PCI/MSI: Add support for per device MSI[X] domains Thomas Gleixner
@ 2022-11-21 14:38 ` Thomas Gleixner
  2022-11-23  8:16   ` Tian, Kevin
  2022-11-21 14:38 ` [patch V2 14/33] PCI/MSI: Remove unused pci_dev_has_special_msi_domain() Thomas Gleixner
                   ` (19 subsequent siblings)
  32 siblings, 1 reply; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:38 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe

Enable MSI parent domain support in the x86 vector domain and fixup the
checks in the iommu implementations to check whether device::msi::domain is
the default MSI parent domain. That keeps the existing logic to protect
e.g. devices behind VMD working.

The interrupt remap PCI/MSI code still works because the underlying vector
domain still provides the same functionality.

None of the other x86 PCI/MSI, e.g. XEN and HyperV, implementations are
affected either. They still work the same way both at the low level and the
PCI/MSI implementations they provide.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
V2: Fix kernel doc (robot)
---
 arch/x86/include/asm/msi.h          |    6 +
 arch/x86/include/asm/pci.h          |    1 
 arch/x86/kernel/apic/msi.c          |  176 ++++++++++++++++++++++++++----------
 drivers/iommu/amd/iommu.c           |    2 
 drivers/iommu/intel/irq_remapping.c |    2 
 5 files changed, 138 insertions(+), 49 deletions(-)

--- a/arch/x86/include/asm/msi.h
+++ b/arch/x86/include/asm/msi.h
@@ -62,4 +62,10 @@ typedef struct x86_msi_addr_hi {
 struct msi_msg;
 u32 x86_msi_msg_get_destid(struct msi_msg *msg, bool extid);
 
+#define X86_VECTOR_MSI_FLAGS_SUPPORTED					\
+	(MSI_GENERIC_FLAGS_MASK | MSI_FLAG_PCI_MSIX)
+
+#define X86_VECTOR_MSI_FLAGS_REQUIRED					\
+	(MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS)
+
 #endif /* _ASM_X86_MSI_H */
--- a/arch/x86/include/asm/pci.h
+++ b/arch/x86/include/asm/pci.h
@@ -92,6 +92,7 @@ void pcibios_scan_root(int bus);
 struct irq_routing_table *pcibios_get_irq_routing_table(void);
 int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq);
 
+bool pci_dev_has_default_msi_parent_domain(struct pci_dev *dev);
 
 #define HAVE_PCI_MMAP
 #define arch_can_pci_mmap_wc()	pat_enabled()
--- a/arch/x86/kernel/apic/msi.c
+++ b/arch/x86/kernel/apic/msi.c
@@ -142,67 +142,131 @@ msi_set_affinity(struct irq_data *irqd,
 	return ret;
 }
 
-/*
- * IRQ Chip for MSI PCI/PCI-X/PCI-Express Devices,
- * which implement the MSI or MSI-X Capability Structure.
+/**
+ * pci_dev_has_default_msi_parent_domain - Check whether the device has the default
+ *					   MSI parent domain associated
+ * @dev:	Pointer to the PCI device
  */
-static struct irq_chip pci_msi_controller = {
-	.name			= "PCI-MSI",
-	.irq_unmask		= pci_msi_unmask_irq,
-	.irq_mask		= pci_msi_mask_irq,
-	.irq_ack		= irq_chip_ack_parent,
-	.irq_retrigger		= irq_chip_retrigger_hierarchy,
-	.irq_set_affinity	= msi_set_affinity,
-	.flags			= IRQCHIP_SKIP_SET_WAKE |
-				  IRQCHIP_AFFINITY_PRE_STARTUP,
-};
+bool pci_dev_has_default_msi_parent_domain(struct pci_dev *dev)
+{
+	struct irq_domain *domain = dev_get_msi_domain(&dev->dev);
 
-int pci_msi_prepare(struct irq_domain *domain, struct device *dev, int nvec,
-		    msi_alloc_info_t *arg)
+	if (!domain)
+		domain = dev_get_msi_domain(&dev->bus->dev);
+	if (!domain)
+		return false;
+
+	return domain == x86_vector_domain;
+}
+
+/**
+ * x86_msi_prepare - Setup of msi_alloc_info_t for allocations
+ * @domain:	The domain for which this setup happens
+ * @dev:	The device for which interrupts are allocated
+ * @nvec:	The number of vectors to allocate
+ * @alloc:	The allocation info structure to initialize
+ *
+ * This function is to be used for all types of MSI domains above the x86
+ * vector domain and any intermediates. It is always invoked from the
+ * top level interrupt domain. The domain specific allocation
+ * functionality is determined via the @domain's bus token which allows to
+ * map the X86 specific allocation type.
+ */
+static int x86_msi_prepare(struct irq_domain *domain, struct device *dev,
+			   int nvec, msi_alloc_info_t *alloc)
 {
-	init_irq_alloc_info(arg, NULL);
-	if (to_pci_dev(dev)->msix_enabled)
-		arg->type = X86_IRQ_ALLOC_TYPE_PCI_MSIX;
-	else
-		arg->type = X86_IRQ_ALLOC_TYPE_PCI_MSI;
+	struct msi_domain_info *info = domain->host_data;
 
-	return 0;
+	init_irq_alloc_info(alloc, NULL);
+
+	switch (info->bus_token) {
+	case DOMAIN_BUS_PCI_DEVICE_MSI:
+		alloc->type = X86_IRQ_ALLOC_TYPE_PCI_MSI;
+		return 0;
+	case DOMAIN_BUS_PCI_DEVICE_MSIX:
+		alloc->type = X86_IRQ_ALLOC_TYPE_PCI_MSIX;
+		return 0;
+	default:
+		return -EINVAL;
+	}
 }
-EXPORT_SYMBOL_GPL(pci_msi_prepare);
 
-static struct msi_domain_ops pci_msi_domain_ops = {
-	.msi_prepare	= pci_msi_prepare,
-};
+/**
+ * x86_init_dev_msi_info - Domain info setup for MSI domains
+ * @dev:		The device for which the domain should be created
+ * @domain:		The (root) domain providing this callback
+ * @real_parent:	The real parent domain of the to initialize domain
+ * @info:		The domain info for the to initialize domain
+ *
+ * This function is to be used for all types of MSI domains above the x86
+ * vector domain and any intermediates. The domain specific functionality
+ * is determined via the @real_parent.
+ */
+static bool x86_init_dev_msi_info(struct device *dev, struct irq_domain *domain,
+				  struct irq_domain *real_parent, struct msi_domain_info *info)
+{
+	const struct msi_parent_ops *pops = real_parent->msi_parent_ops;
+
+	/* MSI parent domain specific settings */
+	switch (real_parent->bus_token) {
+	case DOMAIN_BUS_ANY:
+		/* Only the vector domain can have the ANY token */
+		if (WARN_ON_ONCE(domain != real_parent))
+			return false;
+		info->chip->irq_set_affinity = msi_set_affinity;
+		/* See msi_set_affinity() for the gory details */
+		info->flags |= MSI_FLAG_NOMASK_QUIRK;
+		break;
+	default:
+		WARN_ON_ONCE(1);
+		return false;
+	}
+
+	/* Is the target supported? */
+	switch(info->bus_token) {
+	case DOMAIN_BUS_PCI_DEVICE_MSI:
+	case DOMAIN_BUS_PCI_DEVICE_MSIX:
+		break;
+	default:
+		WARN_ON_ONCE(1);
+		return false;
+	}
+
+	/*
+	 * Mask out the domain specific MSI feature flags which are not
+	 * supported by the real parent.
+	 */
+	info->flags			&= pops->supported_flags;
+	/* Enforce the required flags */
+	info->flags			|= X86_VECTOR_MSI_FLAGS_REQUIRED;
+
+	/* This is always invoked from the top level MSI domain! */
+	info->ops->msi_prepare		= x86_msi_prepare;
+
+	info->chip->irq_ack		= irq_chip_ack_parent;
+	info->chip->irq_retrigger	= irq_chip_retrigger_hierarchy;
+	info->chip->flags		|= IRQCHIP_SKIP_SET_WAKE |
+					   IRQCHIP_AFFINITY_PRE_STARTUP;
 
-static struct msi_domain_info pci_msi_domain_info = {
-	.flags		= MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS |
-			  MSI_FLAG_PCI_MSIX | MSI_FLAG_NOMASK_QUIRK,
-
-	.ops		= &pci_msi_domain_ops,
-	.chip		= &pci_msi_controller,
-	.handler	= handle_edge_irq,
-	.handler_name	= "edge",
+	info->handler			= handle_edge_irq;
+	info->handler_name		= "edge";
+
+	return true;
+}
+
+static const struct msi_parent_ops x86_vector_msi_parent_ops = {
+	.supported_flags	= X86_VECTOR_MSI_FLAGS_SUPPORTED,
+	.init_dev_msi_info	= x86_init_dev_msi_info,
 };
 
 struct irq_domain * __init native_create_pci_msi_domain(void)
 {
-	struct fwnode_handle *fn;
-	struct irq_domain *d;
-
 	if (disable_apic)
 		return NULL;
 
-	fn = irq_domain_alloc_named_fwnode("PCI-MSI");
-	if (!fn)
-		return NULL;
-
-	d = pci_msi_create_irq_domain(fn, &pci_msi_domain_info,
-				      x86_vector_domain);
-	if (!d) {
-		irq_domain_free_fwnode(fn);
-		pr_warn("Failed to initialize PCI-MSI irqdomain.\n");
-	}
-	return d;
+	x86_vector_domain->flags |= IRQ_DOMAIN_FLAG_MSI_PARENT;
+	x86_vector_domain->msi_parent_ops = &x86_vector_msi_parent_ops;
+	return x86_vector_domain;
 }
 
 void __init x86_create_pci_msi_domain(void)
@@ -210,7 +274,25 @@ void __init x86_create_pci_msi_domain(vo
 	x86_pci_msi_default_domain = x86_init.irqs.create_pci_msi_domain();
 }
 
+/* Keep around for hyperV and the remap code below */
+int pci_msi_prepare(struct irq_domain *domain, struct device *dev, int nvec,
+		    msi_alloc_info_t *arg)
+{
+	init_irq_alloc_info(arg, NULL);
+
+	if (to_pci_dev(dev)->msix_enabled)
+		arg->type = X86_IRQ_ALLOC_TYPE_PCI_MSIX;
+	else
+		arg->type = X86_IRQ_ALLOC_TYPE_PCI_MSI;
+	return 0;
+}
+EXPORT_SYMBOL_GPL(pci_msi_prepare);
+
 #ifdef CONFIG_IRQ_REMAP
+static struct msi_domain_ops pci_msi_domain_ops = {
+	.msi_prepare	= pci_msi_prepare,
+};
+
 static struct irq_chip pci_msi_ir_controller = {
 	.name			= "IR-PCI-MSI",
 	.irq_unmask		= pci_msi_unmask_irq,
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -812,7 +812,7 @@ static void
 amd_iommu_set_pci_msi_domain(struct device *dev, struct amd_iommu *iommu)
 {
 	if (!irq_remapping_enabled || !dev_is_pci(dev) ||
-	    pci_dev_has_special_msi_domain(to_pci_dev(dev)))
+	    !pci_dev_has_default_msi_parent_domain(to_pci_dev(dev)))
 		return;
 
 	dev_set_msi_domain(dev, iommu->msi_domain);
--- a/drivers/iommu/intel/irq_remapping.c
+++ b/drivers/iommu/intel/irq_remapping.c
@@ -1107,7 +1107,7 @@ static int reenable_irq_remapping(int ei
  */
 void intel_irq_remap_add_device(struct dmar_pci_notify_info *info)
 {
-	if (!irq_remapping_enabled || pci_dev_has_special_msi_domain(info->dev))
+	if (!irq_remapping_enabled || !pci_dev_has_default_msi_parent_domain(info->dev))
 		return;
 
 	dev_set_msi_domain(&info->dev->dev, map_dev_to_ir(info->dev));


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 14/33] PCI/MSI: Remove unused pci_dev_has_special_msi_domain()
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
                   ` (12 preceding siblings ...)
  2022-11-21 14:38 ` [patch V2 13/33] x86/apic/vector: Provide MSI parent domain Thomas Gleixner
@ 2022-11-21 14:38 ` Thomas Gleixner
  2022-11-21 14:38 ` [patch V2 15/33] iommu/vt-d: Switch to MSI parent domains Thomas Gleixner
                   ` (18 subsequent siblings)
  32 siblings, 0 replies; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:38 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe

The check for special MSI domains like VMD which prevents the interrupt
remapping code to overwrite device::msi::domain is not longer required and
has been replaced by an x86 specific version which is aware of MSI parent
domains.

Remove it.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
---
 drivers/pci/msi/irqdomain.c |   21 ---------------------
 include/linux/msi.h         |    1 -
 2 files changed, 22 deletions(-)

--- a/drivers/pci/msi/irqdomain.c
+++ b/drivers/pci/msi/irqdomain.c
@@ -414,24 +414,3 @@ struct irq_domain *pci_msi_get_device_do
 					     DOMAIN_BUS_PCI_MSI);
 	return dom;
 }
-
-/**
- * pci_dev_has_special_msi_domain - Check whether the device is handled by
- *				    a non-standard PCI-MSI domain
- * @pdev:	The PCI device to check.
- *
- * Returns: True if the device irqdomain or the bus irqdomain is
- * non-standard PCI/MSI.
- */
-bool pci_dev_has_special_msi_domain(struct pci_dev *pdev)
-{
-	struct irq_domain *dom = dev_get_msi_domain(&pdev->dev);
-
-	if (!dom)
-		dom = dev_get_msi_domain(&pdev->bus->dev);
-
-	if (!dom)
-		return true;
-
-	return dom->bus_token != DOMAIN_BUS_PCI_MSI;
-}
--- a/include/linux/msi.h
+++ b/include/linux/msi.h
@@ -606,7 +606,6 @@ struct irq_domain *pci_msi_create_irq_do
 					     struct irq_domain *parent);
 u32 pci_msi_domain_get_msi_rid(struct irq_domain *domain, struct pci_dev *pdev);
 struct irq_domain *pci_msi_get_device_domain(struct pci_dev *pdev);
-bool pci_dev_has_special_msi_domain(struct pci_dev *pdev);
 #else /* CONFIG_PCI_MSI */
 static inline struct irq_domain *pci_msi_get_device_domain(struct pci_dev *pdev)
 {


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 15/33] iommu/vt-d: Switch to MSI parent domains
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
                   ` (13 preceding siblings ...)
  2022-11-21 14:38 ` [patch V2 14/33] PCI/MSI: Remove unused pci_dev_has_special_msi_domain() Thomas Gleixner
@ 2022-11-21 14:38 ` Thomas Gleixner
  2022-11-21 14:38 ` [patch V2 16/33] iommu/amd: Switch to MSI base domains Thomas Gleixner
                   ` (17 subsequent siblings)
  32 siblings, 0 replies; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:38 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe

Remove the global PCI/MSI irqdomain implementation and provide the required
MSI parent ops so the PCI/MSI code can detect the new parent and setup per
device domains.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 arch/x86/kernel/apic/msi.c          |    2 ++
 drivers/iommu/intel/iommu.h         |    1 -
 drivers/iommu/intel/irq_remapping.c |   27 ++++++++++++---------------
 include/linux/irqdomain_defs.h      |    1 +
 4 files changed, 15 insertions(+), 16 deletions(-)

--- a/arch/x86/kernel/apic/msi.c
+++ b/arch/x86/kernel/apic/msi.c
@@ -217,6 +217,8 @@ static bool x86_init_dev_msi_info(struct
 		/* See msi_set_affinity() for the gory details */
 		info->flags |= MSI_FLAG_NOMASK_QUIRK;
 		break;
+	case DOMAIN_BUS_DMAR:
+		break;
 	default:
 		WARN_ON_ONCE(1);
 		return false;
--- a/drivers/iommu/intel/iommu.h
+++ b/drivers/iommu/intel/iommu.h
@@ -600,7 +600,6 @@ struct intel_iommu {
 #ifdef CONFIG_IRQ_REMAP
 	struct ir_table *ir_table;	/* Interrupt remapping info */
 	struct irq_domain *ir_domain;
-	struct irq_domain *ir_msi_domain;
 #endif
 	struct iommu_device iommu;  /* IOMMU core code handle */
 	int		node;
--- a/drivers/iommu/intel/irq_remapping.c
+++ b/drivers/iommu/intel/irq_remapping.c
@@ -82,6 +82,7 @@ static const struct irq_domain_ops intel
 
 static void iommu_disable_irq_remapping(struct intel_iommu *iommu);
 static int __init parse_ioapics_under_ir(void);
+static const struct msi_parent_ops dmar_msi_parent_ops;
 
 static bool ir_pre_enabled(struct intel_iommu *iommu)
 {
@@ -230,7 +231,7 @@ static struct irq_domain *map_dev_to_ir(
 {
 	struct dmar_drhd_unit *drhd = dmar_find_matched_drhd_unit(dev);
 
-	return drhd ? drhd->iommu->ir_msi_domain : NULL;
+	return drhd ? drhd->iommu->ir_domain : NULL;
 }
 
 static int clear_entries(struct irq_2_iommu *irq_iommu)
@@ -573,10 +574,10 @@ static int intel_setup_irq_remapping(str
 		pr_err("IR%d: failed to allocate irqdomain\n", iommu->seq_id);
 		goto out_free_fwnode;
 	}
-	iommu->ir_msi_domain =
-		arch_create_remap_msi_irq_domain(iommu->ir_domain,
-						 "INTEL-IR-MSI",
-						 iommu->seq_id);
+
+	irq_domain_update_bus_token(iommu->ir_domain,  DOMAIN_BUS_DMAR);
+	iommu->ir_domain->flags |= IRQ_DOMAIN_FLAG_MSI_PARENT;
+	iommu->ir_domain->msi_parent_ops = &dmar_msi_parent_ops;
 
 	ir_table->base = page_address(pages);
 	ir_table->bitmap = bitmap;
@@ -620,9 +621,6 @@ static int intel_setup_irq_remapping(str
 	return 0;
 
 out_free_ir_domain:
-	if (iommu->ir_msi_domain)
-		irq_domain_remove(iommu->ir_msi_domain);
-	iommu->ir_msi_domain = NULL;
 	irq_domain_remove(iommu->ir_domain);
 	iommu->ir_domain = NULL;
 out_free_fwnode:
@@ -644,13 +642,6 @@ static void intel_teardown_irq_remapping
 	struct fwnode_handle *fn;
 
 	if (iommu && iommu->ir_table) {
-		if (iommu->ir_msi_domain) {
-			fn = iommu->ir_msi_domain->fwnode;
-
-			irq_domain_remove(iommu->ir_msi_domain);
-			irq_domain_free_fwnode(fn);
-			iommu->ir_msi_domain = NULL;
-		}
 		if (iommu->ir_domain) {
 			fn = iommu->ir_domain->fwnode;
 
@@ -1437,6 +1428,12 @@ static const struct irq_domain_ops intel
 	.deactivate = intel_irq_remapping_deactivate,
 };
 
+static const struct msi_parent_ops dmar_msi_parent_ops = {
+	.supported_flags	= X86_VECTOR_MSI_FLAGS_SUPPORTED | MSI_FLAG_MULTI_PCI_MSI,
+	.prefix			= "IR-",
+	.init_dev_msi_info	= msi_parent_init_dev_msi_info,
+};
+
 /*
  * Support of Interrupt Remapping Unit Hotplug
  */
--- a/include/linux/irqdomain_defs.h
+++ b/include/linux/irqdomain_defs.h
@@ -23,6 +23,7 @@ enum irq_domain_bus_token {
 	DOMAIN_BUS_VMD_MSI,
 	DOMAIN_BUS_PCI_DEVICE_MSI,
 	DOMAIN_BUS_PCI_DEVICE_MSIX,
+	DOMAIN_BUS_DMAR,
 };
 
 #endif /* _LINUX_IRQDOMAIN_DEFS_H */


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 16/33] iommu/amd: Switch to MSI base domains
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
                   ` (14 preceding siblings ...)
  2022-11-21 14:38 ` [patch V2 15/33] iommu/vt-d: Switch to MSI parent domains Thomas Gleixner
@ 2022-11-21 14:38 ` Thomas Gleixner
  2022-11-21 14:38 ` [patch V2 17/33] x86/apic/msi: Remove arch_create_remap_msi_irq_domain() Thomas Gleixner
                   ` (16 subsequent siblings)
  32 siblings, 0 replies; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:38 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe

Remove the global PCI/MSI irqdomain implementation and provide the required
MSI parent ops so the PCI/MSI code can detect the new parent and setup per
device domains.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 arch/x86/kernel/apic/msi.c          |    1 +
 drivers/iommu/amd/amd_iommu_types.h |    1 -
 drivers/iommu/amd/iommu.c           |   19 +++++++++++++------
 include/linux/irqdomain_defs.h      |    1 +
 4 files changed, 15 insertions(+), 7 deletions(-)

--- a/arch/x86/kernel/apic/msi.c
+++ b/arch/x86/kernel/apic/msi.c
@@ -218,6 +218,7 @@ static bool x86_init_dev_msi_info(struct
 		info->flags |= MSI_FLAG_NOMASK_QUIRK;
 		break;
 	case DOMAIN_BUS_DMAR:
+	case DOMAIN_BUS_AMDVI:
 		break;
 	default:
 		WARN_ON_ONCE(1);
--- a/drivers/iommu/amd/amd_iommu_types.h
+++ b/drivers/iommu/amd/amd_iommu_types.h
@@ -734,7 +734,6 @@ struct amd_iommu {
 	u8 max_counters;
 #ifdef CONFIG_IRQ_REMAP
 	struct irq_domain *ir_domain;
-	struct irq_domain *msi_domain;
 
 	struct amd_irte_ops *irte_ops;
 #endif
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -815,7 +815,7 @@ amd_iommu_set_pci_msi_domain(struct devi
 	    !pci_dev_has_default_msi_parent_domain(to_pci_dev(dev)))
 		return;
 
-	dev_set_msi_domain(dev, iommu->msi_domain);
+	dev_set_msi_domain(dev, iommu->ir_domain);
 }
 
 #else /* CONFIG_IRQ_REMAP */
@@ -3648,6 +3648,12 @@ static struct irq_chip amd_ir_chip = {
 	.irq_compose_msi_msg	= ir_compose_msi_msg,
 };
 
+static const struct msi_parent_ops amdvi_msi_parent_ops = {
+	.supported_flags	= X86_VECTOR_MSI_FLAGS_SUPPORTED | MSI_FLAG_MULTI_PCI_MSI,
+	.prefix			= "IR-",
+	.init_dev_msi_info	= msi_parent_init_dev_msi_info,
+};
+
 int amd_iommu_create_irq_domain(struct amd_iommu *iommu)
 {
 	struct fwnode_handle *fn;
@@ -3655,16 +3661,17 @@ int amd_iommu_create_irq_domain(struct a
 	fn = irq_domain_alloc_named_id_fwnode("AMD-IR", iommu->index);
 	if (!fn)
 		return -ENOMEM;
-	iommu->ir_domain = irq_domain_create_tree(fn, &amd_ir_domain_ops, iommu);
+	iommu->ir_domain = irq_domain_create_hierarchy(arch_get_ir_parent_domain(), 0, 0,
+						       fn, &amd_ir_domain_ops, iommu);
 	if (!iommu->ir_domain) {
 		irq_domain_free_fwnode(fn);
 		return -ENOMEM;
 	}
 
-	iommu->ir_domain->parent = arch_get_ir_parent_domain();
-	iommu->msi_domain = arch_create_remap_msi_irq_domain(iommu->ir_domain,
-							     "AMD-IR-MSI",
-							     iommu->index);
+	irq_domain_update_bus_token(iommu->ir_domain,  DOMAIN_BUS_AMDVI);
+	iommu->ir_domain->flags |= IRQ_DOMAIN_FLAG_MSI_PARENT;
+	iommu->ir_domain->msi_parent_ops = &amdvi_msi_parent_ops;
+
 	return 0;
 }
 
--- a/include/linux/irqdomain_defs.h
+++ b/include/linux/irqdomain_defs.h
@@ -24,6 +24,7 @@ enum irq_domain_bus_token {
 	DOMAIN_BUS_PCI_DEVICE_MSI,
 	DOMAIN_BUS_PCI_DEVICE_MSIX,
 	DOMAIN_BUS_DMAR,
+	DOMAIN_BUS_AMDVI,
 };
 
 #endif /* _LINUX_IRQDOMAIN_DEFS_H */


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 17/33] x86/apic/msi: Remove arch_create_remap_msi_irq_domain()
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
                   ` (15 preceding siblings ...)
  2022-11-21 14:38 ` [patch V2 16/33] iommu/amd: Switch to MSI base domains Thomas Gleixner
@ 2022-11-21 14:38 ` Thomas Gleixner
  2022-11-21 14:38 ` [patch V2 18/33] genirq/msi: Provide struct msi_map Thomas Gleixner
                   ` (15 subsequent siblings)
  32 siblings, 0 replies; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:38 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe

and related code which is not longer required now that the interrupt remap
code has been converted to MSI parent domains.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 arch/x86/include/asm/irq_remapping.h |    4 ---
 arch/x86/kernel/apic/msi.c           |   42 -----------------------------------
 2 files changed, 1 insertion(+), 45 deletions(-)

--- a/arch/x86/include/asm/irq_remapping.h
+++ b/arch/x86/include/asm/irq_remapping.h
@@ -44,10 +44,6 @@ extern int irq_remapping_reenable(int);
 extern int irq_remap_enable_fault_handling(void);
 extern void panic_if_irq_remap(const char *msg);
 
-/* Create PCI MSI/MSIx irqdomain, use @parent as the parent irqdomain. */
-extern struct irq_domain *
-arch_create_remap_msi_irq_domain(struct irq_domain *par, const char *n, int id);
-
 /* Get parent irqdomain for interrupt remapping irqdomain */
 static inline struct irq_domain *arch_get_ir_parent_domain(void)
 {
--- a/arch/x86/kernel/apic/msi.c
+++ b/arch/x86/kernel/apic/msi.c
@@ -277,7 +277,7 @@ void __init x86_create_pci_msi_domain(vo
 	x86_pci_msi_default_domain = x86_init.irqs.create_pci_msi_domain();
 }
 
-/* Keep around for hyperV and the remap code below */
+/* Keep around for hyperV */
 int pci_msi_prepare(struct irq_domain *domain, struct device *dev, int nvec,
 		    msi_alloc_info_t *arg)
 {
@@ -291,46 +291,6 @@ int pci_msi_prepare(struct irq_domain *d
 }
 EXPORT_SYMBOL_GPL(pci_msi_prepare);
 
-#ifdef CONFIG_IRQ_REMAP
-static struct msi_domain_ops pci_msi_domain_ops = {
-	.msi_prepare	= pci_msi_prepare,
-};
-
-static struct irq_chip pci_msi_ir_controller = {
-	.name			= "IR-PCI-MSI",
-	.irq_unmask		= pci_msi_unmask_irq,
-	.irq_mask		= pci_msi_mask_irq,
-	.irq_ack		= irq_chip_ack_parent,
-	.irq_retrigger		= irq_chip_retrigger_hierarchy,
-	.flags			= IRQCHIP_SKIP_SET_WAKE |
-				  IRQCHIP_AFFINITY_PRE_STARTUP,
-};
-
-static struct msi_domain_info pci_msi_ir_domain_info = {
-	.flags		= MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS |
-			  MSI_FLAG_MULTI_PCI_MSI | MSI_FLAG_PCI_MSIX,
-	.ops		= &pci_msi_domain_ops,
-	.chip		= &pci_msi_ir_controller,
-	.handler	= handle_edge_irq,
-	.handler_name	= "edge",
-};
-
-struct irq_domain *arch_create_remap_msi_irq_domain(struct irq_domain *parent,
-						    const char *name, int id)
-{
-	struct fwnode_handle *fn;
-	struct irq_domain *d;
-
-	fn = irq_domain_alloc_named_id_fwnode(name, id);
-	if (!fn)
-		return NULL;
-	d = pci_msi_create_irq_domain(fn, &pci_msi_ir_domain_info, parent);
-	if (!d)
-		irq_domain_free_fwnode(fn);
-	return d;
-}
-#endif
-
 #ifdef CONFIG_DMAR_TABLE
 /*
  * The Intel IOMMU (ab)uses the high bits of the MSI address to contain the


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 18/33] genirq/msi: Provide struct msi_map
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
                   ` (16 preceding siblings ...)
  2022-11-21 14:38 ` [patch V2 17/33] x86/apic/msi: Remove arch_create_remap_msi_irq_domain() Thomas Gleixner
@ 2022-11-21 14:38 ` Thomas Gleixner
  2022-11-21 14:38 ` [patch V2 19/33] genirq/msi: Provide msi_desc::msi_data Thomas Gleixner
                   ` (14 subsequent siblings)
  32 siblings, 0 replies; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:38 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe

A simple struct to hold a MSI index / Linux interrupt number pair. It will
be returned from the dynamic vector allocation function and handed back to
the corresponding free() function.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 include/linux/msi_api.h |   13 +++++++++++++
 1 file changed, 13 insertions(+)

--- a/include/linux/msi_api.h
+++ b/include/linux/msi_api.h
@@ -18,6 +18,19 @@ enum msi_domain_ids {
 	MSI_MAX_DEVICE_IRQDOMAINS,
 };
 
+/**
+ * msi_map - Mapping between MSI index and Linux interrupt number
+ * @index:	The MSI index, e.g. slot in the MSI-X table or
+ *		a software managed index if >= 0. If negative
+ *		the allocation function failed and it contains
+ *		the error code.
+ * @virq:	The associated Linux interrupt number
+ */
+struct msi_map {
+	int	index;
+	int	virq;
+};
+
 unsigned int msi_domain_get_virq(struct device *dev, unsigned int domid, unsigned int index);
 
 /**


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 19/33] genirq/msi: Provide msi_desc::msi_data
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
                   ` (17 preceding siblings ...)
  2022-11-21 14:38 ` [patch V2 18/33] genirq/msi: Provide struct msi_map Thomas Gleixner
@ 2022-11-21 14:38 ` Thomas Gleixner
  2022-11-23  8:27   ` Tian, Kevin
  2022-11-21 14:38 ` [patch V2 20/33] genirq/msi: Provide msi_domain_ops::prepare_desc() Thomas Gleixner
                   ` (13 subsequent siblings)
  32 siblings, 1 reply; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:38 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe

The upcoming support for PCI/IMS requires to store some information related
to the message handling in the MSI descriptor, e.g. PASID or a pointer to a
queue.

Provide a generic storage struct which maps over the existing PCI specific
storage which means the size of struct msi_desc is not getting bigger.

It contains a iomem pointer for device memory based IMS and a union of a
u64 and a void pointer which allows the device specific IMS implementations
to store the necessary information.

The iomem pointer is set up by the domain allocation functions.

The data union msi_dev_cookie is going to be handed in when allocating an
interrupt on an IMS domain so the irq chip callbacks of the IMS domain have
the necessary per vector information available. It also comes in handy when
cleaning up the platform MSI code for wire to MSI bridges which need to
hand down the type information to the underlying interrupt domain.

For the core code the cookie is opaque and meaningless. It just stores it
during an allocation through the upcoming interfaces for IMS and wire to
MSI brigdes.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 include/linux/msi.h     |   38 +++++++++++++++++++++++++++++++++++++-
 include/linux/msi_api.h |   17 +++++++++++++++++
 2 files changed, 54 insertions(+), 1 deletion(-)

--- a/include/linux/msi.h
+++ b/include/linux/msi.h
@@ -125,6 +125,38 @@ struct pci_msi_desc {
 	};
 };
 
+/**
+ * union msi_domain_cookie - Opaque MSI domain specific data
+ * @value:	u64 value store
+ * @ptr:	Pointer to domain specific data
+ * @iobase:	Domain specific IOmem pointer
+ *
+ * The content of this data is implementation defined and used by the MSI
+ * domain to store domain specific information which is requried for
+ * interrupt chip callbacks.
+ */
+union msi_domain_cookie {
+	u64	value;
+	void	*ptr;
+	void	__iomem *iobase;
+};
+
+/**
+ * struct msi_desc_data - Generic MSI descriptor data
+ * @dcookie:	Cookie for MSI domain specific data which is required
+ *		for irq_chip callbacks
+ * @icookie:	Cookie for the MSI interrupt instance provided by
+ *		the usage site to the allocation function
+ *
+ * The content of this data is implementation defined, e.g. PCI/IMS
+ * implementations define the meaning of the data. The MSI core ignores
+ * this data completely.
+ */
+struct msi_desc_data {
+	union msi_domain_cookie		dcookie;
+	union msi_instance_cookie	icookie;
+};
+
 #define MSI_MAX_INDEX		((unsigned int)USHRT_MAX)
 
 /**
@@ -142,6 +174,7 @@ struct pci_msi_desc {
  *
  * @msi_index:	Index of the msi descriptor
  * @pci:	PCI specific msi descriptor data
+ * @data:	Generic MSI descriptor data
  */
 struct msi_desc {
 	/* Shared device/bus type independent data */
@@ -161,7 +194,10 @@ struct msi_desc {
 	void *write_msi_msg_data;
 
 	u16				msi_index;
-	struct pci_msi_desc		pci;
+	union {
+		struct pci_msi_desc	pci;
+		struct msi_desc_data	data;
+	};
 };
 
 /*
--- a/include/linux/msi_api.h
+++ b/include/linux/msi_api.h
@@ -19,6 +19,23 @@ enum msi_domain_ids {
 };
 
 /**
+ * union msi_instance_cookie - MSI instance cookie
+ * @value:	u64 value store
+ * @ptr:	Pointer to usage site specific data
+ *
+ * This cookie is handed to the IMS allocation function and stored in the
+ * MSI descriptor for the interrupt chip callbacks.
+ *
+ * The content of this cookie is MSI domain implementation defined.  For
+ * PCI/IMS implementations this could be a PASID or a pointer to queue
+ * memory.
+ */
+union msi_instance_cookie {
+	u64	value;
+	void	*ptr;
+};
+
+/**
  * msi_map - Mapping between MSI index and Linux interrupt number
  * @index:	The MSI index, e.g. slot in the MSI-X table or
  *		a software managed index if >= 0. If negative


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 20/33] genirq/msi: Provide msi_domain_ops::prepare_desc()
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
                   ` (18 preceding siblings ...)
  2022-11-21 14:38 ` [patch V2 19/33] genirq/msi: Provide msi_desc::msi_data Thomas Gleixner
@ 2022-11-21 14:38 ` Thomas Gleixner
  2022-11-21 14:38 ` [patch V2 21/33] genirq/msi: Provide msi_domain_alloc_irq_at() Thomas Gleixner
                   ` (12 subsequent siblings)
  32 siblings, 0 replies; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:38 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe

The existing MSI domain ops msi_prepare() and set_desc() turned out to be
unsuitable for implementing IMS support.

msi_prepare() does not operate on the MSI descriptors. set_desc() lacks
an irq_domain pointer and has a completely different purpose.

Introduce a prepare_desc() op which allows IMS implementations to amend an
MSI descriptor which was allocated by the core code, e.g. by adjusting the
iomem base or adding some data based on the allocated index. This is way
better than requiring that all IMS domain implementations preallocate the
MSI descriptor and then allocate the interrupt.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 include/linux/msi.h |    6 +++++-
 kernel/irq/msi.c    |    3 +++
 2 files changed, 8 insertions(+), 1 deletion(-)

--- a/include/linux/msi.h
+++ b/include/linux/msi.h
@@ -402,6 +402,8 @@ struct msi_domain_info;
  * @msi_init:		Domain specific init function for MSI interrupts
  * @msi_free:		Domain specific function to free a MSI interrupts
  * @msi_prepare:	Prepare the allocation of the interrupts in the domain
+ * @prepare_desc:	Optional function to prepare the allocated MSI descriptor
+ *			in the domain
  * @set_desc:		Set the msi descriptor for an interrupt
  * @domain_alloc_irqs:	Optional function to override the default allocation
  *			function.
@@ -413,7 +415,7 @@ struct msi_domain_info;
  * @get_hwirq, @msi_init and @msi_free are callbacks used by the underlying
  * irqdomain.
  *
- * @msi_check, @msi_prepare and @set_desc are callbacks used by the
+ * @msi_check, @msi_prepare, @prepare_desc and @set_desc are callbacks used by the
  * msi_domain_alloc/free_irqs*() variants.
  *
  * @domain_alloc_irqs, @domain_free_irqs can be used to override the
@@ -436,6 +438,8 @@ struct msi_domain_ops {
 	int		(*msi_prepare)(struct irq_domain *domain,
 				       struct device *dev, int nvec,
 				       msi_alloc_info_t *arg);
+	void		(*prepare_desc)(struct irq_domain *domain, msi_alloc_info_t *arg,
+					struct msi_desc *desc);
 	void		(*set_desc)(msi_alloc_info_t *arg,
 				    struct msi_desc *desc);
 	int		(*domain_alloc_irqs)(struct irq_domain *domain,
--- a/kernel/irq/msi.c
+++ b/kernel/irq/msi.c
@@ -1285,6 +1285,9 @@ static int __msi_domain_alloc_irqs(struc
 		if (WARN_ON_ONCE(allocated >= ctrl->nirqs))
 			return -EINVAL;
 
+		if (ops->prepare_desc)
+			ops->prepare_desc(domain, &arg, desc);
+
 		ops->set_desc(&arg, desc);
 
 		virq = __irq_domain_alloc_irqs(domain, -1, desc->nvec_used,


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 21/33] genirq/msi: Provide msi_domain_alloc_irq_at()
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
                   ` (19 preceding siblings ...)
  2022-11-21 14:38 ` [patch V2 20/33] genirq/msi: Provide msi_domain_ops::prepare_desc() Thomas Gleixner
@ 2022-11-21 14:38 ` Thomas Gleixner
  2022-11-24  2:54   ` Tian, Kevin
  2022-11-21 14:38 ` [patch V2 22/33] genirq/msi: Provide MSI_FLAG_MSIX_ALLOC_DYN Thomas Gleixner
                   ` (11 subsequent siblings)
  32 siblings, 1 reply; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:38 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe

For supporting post MSI-X enable allocations and for the upcoming PCI/IMS
support a seperate interface is required which allows not only the
allocation of a specific index, but also the allocation of any, i.e. the
next free index. The latter is especially required for IMS because IMS
completely does away with index to functionality mappings which are
often found in MSI/MSI-X implementation.

But even with MSI-X there are devices where only the first few indices have
a fixed functionality and the rest is freely assignable by software,
e.g. to queues.

msi_domain_alloc_irq_at() is also different from the range based interfaces
as it always enforces that the MSI descriptor is allocated by the core code
and not preallocated by the caller like the PCI/MSI[-X] enable code path
does.

msi_domain_alloc_irq_at() can be invoked with the index argument set to
MSI_ANY_INDEX which makes the core code pick the next free index. The irq
domain can provide a prepare_desc() operation callback in its
msi_domain_ops to do domain specific post allocation initialization before
the actual Linux interrupt and the associated interrupt descriptor and
hierarchy alloccations are conducted.

The function also takes an optional @cookie argument which is of type union
msi_dev_cookie. This cookie is not used by the core code and is stored in
the allocated msi_desc::data::cookie. The meaning of the cookie is
completely implementation defined. In case of IMS this might be a PASID or
a pointer to a device queue, but for the MSI core it's opaque and not used
in any way.

The function returns a struct msi_map which on success contains the
allocated index number and the Linux interrupt number so the caller can
spare the index to Linux interrupt number lookup.

On failure map::index contains the error code and map::virq is 0.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
V2: Fix the recursive allocation issue and the index calculation (Reinette)
---
 include/linux/msi.h     |    4 +
 include/linux/msi_api.h |    7 ++
 kernel/irq/msi.c        |  113 +++++++++++++++++++++++++++++++++++++++++++-----
 3 files changed, 113 insertions(+), 11 deletions(-)

--- a/include/linux/msi.h
+++ b/include/linux/msi.h
@@ -80,6 +80,7 @@ struct pci_dev;
 struct platform_msi_priv_data;
 struct device_attribute;
 struct irq_domain;
+struct irq_affinity_desc;
 
 void __get_cached_msi_msg(struct msi_desc *entry, struct msi_msg *msg);
 #ifdef CONFIG_GENERIC_MSI_IRQ
@@ -591,6 +592,9 @@ int msi_domain_alloc_irqs_range(struct d
 				unsigned int first, unsigned int last);
 int msi_domain_alloc_irqs_all_locked(struct device *dev, unsigned int domid, int nirqs);
 
+struct msi_map msi_domain_alloc_irq_at(struct device *dev, unsigned int domid, unsigned int index,
+				       const struct irq_affinity_desc *affdesc,
+				       union msi_instance_cookie *cookie);
 
 void msi_domain_free_irqs_range_locked(struct device *dev, unsigned int domid,
 				       unsigned int first, unsigned int last);
--- a/include/linux/msi_api.h
+++ b/include/linux/msi_api.h
@@ -48,6 +48,13 @@ struct msi_map {
 	int	virq;
 };
 
+/*
+ * Constant to be used for dynamic allocations when the allocation
+ * is any free MSI index (entry in the MSI-X table or a software
+ * managed index.
+ */
+#define MSI_ANY_INDEX		UINT_MAX
+
 unsigned int msi_domain_get_virq(struct device *dev, unsigned int domid, unsigned int index);
 
 /**
--- a/kernel/irq/msi.c
+++ b/kernel/irq/msi.c
@@ -40,6 +40,7 @@ static inline int msi_sysfs_create_group
 /* Invalid XA index which is outside of any searchable range */
 #define MSI_XA_MAX_INDEX	(ULONG_MAX - 1)
 #define MSI_XA_DOMAIN_SIZE	(MSI_MAX_INDEX + 1)
+#define MSI_ANY_INDEX		UINT_MAX
 
 static inline void msi_setup_default_irqdomain(struct device *dev, struct msi_device_data *md)
 {
@@ -127,18 +128,34 @@ static int msi_insert_desc(struct device
 	}
 
 	hwsize = msi_domain_get_hwsize(dev, domid);
-	if (index >= hwsize) {
-		ret = -ERANGE;
-		goto fail;
-	}
 
-	desc->msi_index = index;
-	index += baseidx;
-	ret = xa_insert(&md->__store, index, desc, GFP_KERNEL);
-	if (ret)
-		goto fail;
-	return 0;
+	if (index == MSI_ANY_INDEX) {
+		struct xa_limit limit;
+		unsigned int index;
+
+		limit.min = baseidx;
+		limit.max = baseidx + hwsize - 1;
+
+		/* Let the xarray allocate a free index within the limits */
+		ret = xa_alloc(&md->__store, &index, desc, limit, GFP_KERNEL);
+		if (ret)
+			goto fail;
 
+		desc->msi_index = index - baseidx;
+		return 0;
+	} else {
+		if (index >= hwsize) {
+			ret = -ERANGE;
+			goto fail;
+		}
+
+		desc->msi_index = index;
+		index += baseidx;
+		ret = xa_insert(&md->__store, index, desc, GFP_KERNEL);
+		if (ret)
+			goto fail;
+		return 0;
+	}
 fail:
 	msi_free_desc(desc);
 	return ret;
@@ -333,7 +350,7 @@ int msi_setup_device_data(struct device
 
 	msi_setup_default_irqdomain(dev, md);
 
-	xa_init(&md->__store);
+	xa_init_flags(&md->__store, XA_FLAGS_ALLOC);
 	mutex_init(&md->mutex);
 	md->__iter_idx = MSI_XA_MAX_INDEX;
 	dev->msi.data = md;
@@ -1433,6 +1450,80 @@ int msi_domain_alloc_irqs_all_locked(str
 	return msi_domain_alloc_locked(dev, &ctrl);
 }
 
+/**
+ * msi_domain_alloc_irq_at - Allocate an interrupt from a MSI interrupt domain at
+ *			     a given index - or at the next free index
+ *
+ * @dev:	Pointer to device struct of the device for which the interrupts
+ *		are allocated
+ * @domid:	Id of the interrupt domain to operate on
+ * @index:	Index for allocation. If @index == %MSI_ANY_INDEX the allocation
+ *		uses the next free index.
+ * @affdesc:	Optional pointer to an interrupt affinity descriptor structure
+ * @icookie:	Optional pointer to a domain specific per instance cookie. If
+ *		non-NULL the content of the cookie is stored in msi_desc::data.
+ *		Must be NULL for MSI-X allocations
+ *
+ * This requires a MSI interrupt domain which lets the core code manage the
+ * MSI descriptors.
+ *
+ * Return: struct msi_map
+ *
+ *	On success msi_map::index contains the allocated index number and
+ *	msi_map::virq the corresponding Linux interrupt number
+ *
+ *	On failure msi_map::index contains the error code and msi_map::virq
+ *	is %0.
+ */
+struct msi_map msi_domain_alloc_irq_at(struct device *dev, unsigned int domid, unsigned int index,
+				       const struct irq_affinity_desc *affdesc,
+				       union msi_instance_cookie *icookie)
+{
+	struct msi_ctrl ctrl = { .domid	= domid, .nirqs = 1, };
+	struct msi_domain_info *info;
+	struct irq_domain *domain;
+	struct msi_map map = { };
+	struct msi_desc *desc;
+	int ret;
+
+	msi_lock_descs(dev);
+	domain = msi_get_device_domain(dev, domid);
+	if (!domain) {
+		map.index = -ENODEV;
+		goto unlock;
+	}
+
+	desc = msi_alloc_desc(dev, 1, affdesc);
+	if (!desc) {
+		map.index = -ENOMEM;
+		goto unlock;
+	}
+
+	if (icookie)
+		desc->data.icookie = *icookie;
+
+	ret = msi_insert_desc(dev, desc, domid, index);
+	if (ret) {
+		map.index = ret;
+		goto unlock;
+	}
+
+	ctrl.first = ctrl.last = desc->msi_index;
+	info = domain->host_data;
+
+	ret = __msi_domain_alloc_irqs(dev, domain, &ctrl);
+	if (ret) {
+		map.index = ret;
+		msi_domain_free_locked(dev, &ctrl);
+	} else {
+		map.index = desc->msi_index;
+		map.virq = desc->irq;
+	}
+unlock:
+	msi_unlock_descs(dev);
+	return map;
+}
+
 static void __msi_domain_free_irqs(struct device *dev, struct irq_domain *domain,
 				   struct msi_ctrl *ctrl)
 {


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 22/33] genirq/msi: Provide MSI_FLAG_MSIX_ALLOC_DYN
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
                   ` (20 preceding siblings ...)
  2022-11-21 14:38 ` [patch V2 21/33] genirq/msi: Provide msi_domain_alloc_irq_at() Thomas Gleixner
@ 2022-11-21 14:38 ` Thomas Gleixner
  2022-11-21 14:38 ` [patch V2 23/33] PCI/MSI: Split MSI-X descriptor setup Thomas Gleixner
                   ` (10 subsequent siblings)
  32 siblings, 0 replies; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:38 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe,
	Jason Gunthorpe

Provide a new MSI feature flag in preparation for dynamic MSIX allocation
after the initial MSI-X enable has been done.

This needs to be an explicit MSI interrupt domain feature because quite
some implementations (both interrupt domains and legacy allocation mode)
have clear expectations that the allocation code is only invoked when MSI-X
is about to be enabled. They either talk to hypervisors or do some other
work and are not prepared to be invoked on an already MSI-X enabled device.

This is also explicit MSI-X only because rewriting the size of the MSI
entries is only possible when disabling MSI which in turn might cause lost
interrupts on the device.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
---
 include/linux/msi.h |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

--- a/include/linux/msi.h
+++ b/include/linux/msi.h
@@ -546,7 +546,8 @@ enum {
 	MSI_FLAG_LEVEL_CAPABLE		= (1 << 18),
 	/* MSI-X entries must be contiguous */
 	MSI_FLAG_MSIX_CONTIGUOUS	= (1 << 19),
-
+	/* PCI/MSI-X vectors can be dynamically allocated/freed post MSI-X enable */
+	MSI_FLAG_PCI_MSIX_ALLOC_DYN	= (1 << 20),
 };
 
 /**


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 23/33] PCI/MSI: Split MSI-X descriptor setup
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
                   ` (21 preceding siblings ...)
  2022-11-21 14:38 ` [patch V2 22/33] genirq/msi: Provide MSI_FLAG_MSIX_ALLOC_DYN Thomas Gleixner
@ 2022-11-21 14:38 ` Thomas Gleixner
  2022-11-21 14:38 ` [patch V2 24/33] PCI/MSI: Provide prepare_desc() MSI domain op Thomas Gleixner
                   ` (9 subsequent siblings)
  32 siblings, 0 replies; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:38 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe

The upcoming mechanism to allocate MSI-X vectors after enabling MSI-X needs
to share some of the MSI-X descriptor setup.

The regular descriptor setup on enable has the following code flow:

    1) Allocate descriptor
    2) Setup descriptor with PCI specific data
    3) Insert descriptor
    4) Allocate interrupts which in turn scans the inserted
       descriptors

This cannot be easily changed because the PCI/MSI code needs to handle the
legacy architecture specific allocation model and the irq domain model
where quite some domains have the assumption that the above flow is how it
works.

Ideally the code flow should look like this:

   1) Invoke allocation at the MSI core
   2) MSI core allocates descriptor
   3) MSI core calls back into the irq domain which fills in
      the domain specific parts

This could be done for underlying parent MSI domains which support
post-enable allocation/free but that would create significantly different
code pathes for MSI/MSI-X enable.

Though for dynamic allocation which wants to share the allocation code with
the upcoming PCI/IMS support it's the right thing to do.

Split the MSI-X descriptor setup into the preallocation part which just sets
the index and fills in the horrible hack of virtual IRQs and the real PCI
specific MSI-X setup part which solely depends on the index in the
descriptor. This allows to provide a common dynamic allocation interface at
the MSI core level for both PCI/MSI-X and PCI/IMS.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
---
 drivers/pci/msi/msi.c |   72 +++++++++++++++++++++++++++++++-------------------
 drivers/pci/msi/msi.h |    2 +
 2 files changed, 47 insertions(+), 27 deletions(-)

--- a/drivers/pci/msi/msi.c
+++ b/drivers/pci/msi/msi.c
@@ -569,34 +569,56 @@ static void __iomem *msix_map_region(str
 	return ioremap(phys_addr, nr_entries * PCI_MSIX_ENTRY_SIZE);
 }
 
-static int msix_setup_msi_descs(struct pci_dev *dev, void __iomem *base,
-				struct msix_entry *entries, int nvec,
-				struct irq_affinity_desc *masks)
+/**
+ * msix_prepare_msi_desc - Prepare a half initialized MSI descriptor for operation
+ * @dev:	The PCI device for which the descriptor is prepared
+ * @desc:	The MSI descriptor for preparation
+ *
+ * This is separate from msix_setup_msi_descs() below to handle dynamic
+ * allocations for MSI-X after initial enablement.
+ *
+ * Ideally the whole MSI-X setup would work that way, but there is no way to
+ * support this for the legacy arch_setup_msi_irqs() mechanism and for the
+ * fake irq domains like the x86 XEN one. Sigh...
+ *
+ * The descriptor is zeroed and only @desc::msi_index and @desc::affinity
+ * are set. When called from msix_setup_msi_descs() then the is_virtual
+ * attribute is initialized as well.
+ *
+ * Fill in the rest.
+ */
+void msix_prepare_msi_desc(struct pci_dev *dev, struct msi_desc *desc)
+{
+	desc->nvec_used				= 1;
+	desc->pci.msi_attrib.is_msix		= 1;
+	desc->pci.msi_attrib.is_64		= 1;
+	desc->pci.msi_attrib.default_irq	= dev->irq;
+	desc->pci.mask_base			= dev->msix_base;
+	desc->pci.msi_attrib.can_mask		= !pci_msi_ignore_mask &&
+						  !desc->pci.msi_attrib.is_virtual;
+
+	if (desc->pci.msi_attrib.can_mask) {
+		void __iomem *addr = pci_msix_desc_addr(desc);
+
+		desc->pci.msix_ctrl = readl(addr + PCI_MSIX_ENTRY_VECTOR_CTRL);
+	}
+}
+
+static int msix_setup_msi_descs(struct pci_dev *dev, struct msix_entry *entries,
+				int nvec, struct irq_affinity_desc *masks)
 {
 	int ret = 0, i, vec_count = pci_msix_vec_count(dev);
 	struct irq_affinity_desc *curmsk;
 	struct msi_desc desc;
-	void __iomem *addr;
 
 	memset(&desc, 0, sizeof(desc));
 
-	desc.nvec_used			= 1;
-	desc.pci.msi_attrib.is_msix	= 1;
-	desc.pci.msi_attrib.is_64	= 1;
-	desc.pci.msi_attrib.default_irq	= dev->irq;
-	desc.pci.mask_base		= base;
-
 	for (i = 0, curmsk = masks; i < nvec; i++, curmsk++) {
 		desc.msi_index = entries ? entries[i].entry : i;
 		desc.affinity = masks ? curmsk : NULL;
 		desc.pci.msi_attrib.is_virtual = desc.msi_index >= vec_count;
-		desc.pci.msi_attrib.can_mask = !pci_msi_ignore_mask &&
-					       !desc.pci.msi_attrib.is_virtual;
 
-		if (desc.pci.msi_attrib.can_mask) {
-			addr = pci_msix_desc_addr(&desc);
-			desc.pci.msix_ctrl = readl(addr + PCI_MSIX_ENTRY_VECTOR_CTRL);
-		}
+		msix_prepare_msi_desc(dev, &desc);
 
 		ret = msi_insert_msi_desc(&dev->dev, &desc);
 		if (ret)
@@ -629,9 +651,8 @@ static void msix_mask_all(void __iomem *
 		writel(ctrl, base + PCI_MSIX_ENTRY_VECTOR_CTRL);
 }
 
-static int msix_setup_interrupts(struct pci_dev *dev, void __iomem *base,
-				 struct msix_entry *entries, int nvec,
-				 struct irq_affinity *affd)
+static int msix_setup_interrupts(struct pci_dev *dev, struct msix_entry *entries,
+				 int nvec, struct irq_affinity *affd)
 {
 	struct irq_affinity_desc *masks = NULL;
 	int ret;
@@ -640,7 +661,7 @@ static int msix_setup_interrupts(struct
 		masks = irq_create_affinity_masks(nvec, affd);
 
 	msi_lock_descs(&dev->dev);
-	ret = msix_setup_msi_descs(dev, base, entries, nvec, masks);
+	ret = msix_setup_msi_descs(dev, entries, nvec, masks);
 	if (ret)
 		goto out_free;
 
@@ -678,7 +699,6 @@ static int msix_setup_interrupts(struct
 static int msix_capability_init(struct pci_dev *dev, struct msix_entry *entries,
 				int nvec, struct irq_affinity *affd)
 {
-	void __iomem *base;
 	int ret, tsize;
 	u16 control;
 
@@ -696,15 +716,13 @@ static int msix_capability_init(struct p
 	pci_read_config_word(dev, dev->msix_cap + PCI_MSIX_FLAGS, &control);
 	/* Request & Map MSI-X table region */
 	tsize = msix_table_size(control);
-	base = msix_map_region(dev, tsize);
-	if (!base) {
+	dev->msix_base = msix_map_region(dev, tsize);
+	if (!dev->msix_base) {
 		ret = -ENOMEM;
 		goto out_disable;
 	}
 
-	dev->msix_base = base;
-
-	ret = msix_setup_interrupts(dev, base, entries, nvec, affd);
+	ret = msix_setup_interrupts(dev, entries, nvec, affd);
 	if (ret)
 		goto out_disable;
 
@@ -719,7 +737,7 @@ static int msix_capability_init(struct p
 	 * which takes the MSI-X mask bits into account even
 	 * when MSI-X is disabled, which prevents MSI delivery.
 	 */
-	msix_mask_all(base, tsize);
+	msix_mask_all(dev->msix_base, tsize);
 	pci_msix_clear_and_set_ctrl(dev, PCI_MSIX_FLAGS_MASKALL, 0);
 
 	pcibios_free_irq(dev);
--- a/drivers/pci/msi/msi.h
+++ b/drivers/pci/msi/msi.h
@@ -84,6 +84,8 @@ static inline __attribute_const__ u32 ms
 	return (1 << (1 << desc->pci.msi_attrib.multi_cap)) - 1;
 }
 
+void msix_prepare_msi_desc(struct pci_dev *dev, struct msi_desc *desc);
+
 /* Subsystem variables */
 extern int pci_msi_enable;
 


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 24/33] PCI/MSI: Provide prepare_desc() MSI domain op
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
                   ` (22 preceding siblings ...)
  2022-11-21 14:38 ` [patch V2 23/33] PCI/MSI: Split MSI-X descriptor setup Thomas Gleixner
@ 2022-11-21 14:38 ` Thomas Gleixner
  2022-11-21 14:38 ` [patch V2 25/33] PCI/MSI: Provide post-enable dynamic allocation interfaces for MSI-X Thomas Gleixner
                   ` (8 subsequent siblings)
  32 siblings, 0 replies; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:38 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe,
	Jason Gunthorpe

The setup of MSI descriptors for PCI/MSI-X interrupts depends partially on
the MSI index for which the descriptor is initialized.

Dynamic MSI-X vector allocation post MSI-X enablement allows to allocate
vectors at a given index or at any free index in the available table
range. The latter requires that the descriptor is initialized after the
MSI core has chosen an index.

Implement the prepare_desc() op in the PCI/MSI-X specific msi_domain_ops
which is invoked before the core interrupt descriptor and the associated
Linux interrupt number is allocated.

That callback is also provided for the upcoming PCI/IMS implementations so
the implementation specific interrupt domain can do their domain specific
initialization of the MSI descriptors.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
---
V2: Reworded changelog (Bjorn)
---
 drivers/pci/msi/irqdomain.c |    9 +++++++++
 1 file changed, 9 insertions(+)

--- a/drivers/pci/msi/irqdomain.c
+++ b/drivers/pci/msi/irqdomain.c
@@ -202,6 +202,14 @@ static void pci_unmask_msix(struct irq_d
 	pci_msix_unmask(irq_data_get_msi_desc(data));
 }
 
+static void pci_msix_prepare_desc(struct irq_domain *domain, msi_alloc_info_t *arg,
+				  struct msi_desc *desc)
+{
+	/* Don't fiddle with preallocated MSI descriptors */
+	if (!desc->pci.mask_base)
+		msix_prepare_msi_desc(to_pci_dev(desc->dev), desc);
+}
+
 static struct msi_domain_template pci_msix_template = {
 	.chip = {
 		.name			= "PCI-MSIX",
@@ -212,6 +220,7 @@ static struct msi_domain_template pci_ms
 	},
 
 	.ops = {
+		.prepare_desc		= pci_msix_prepare_desc,
 		.set_desc		= pci_device_domain_set_desc,
 	},
 


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 25/33] PCI/MSI: Provide post-enable dynamic allocation interfaces for MSI-X
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
                   ` (23 preceding siblings ...)
  2022-11-21 14:38 ` [patch V2 24/33] PCI/MSI: Provide prepare_desc() MSI domain op Thomas Gleixner
@ 2022-11-21 14:38 ` Thomas Gleixner
  2022-11-24  2:58   ` Tian, Kevin
  2022-11-21 14:38 ` [patch V2 26/33] x86/apic/msi: Enable MSI_FLAG_PCI_MSIX_ALLOC_DYN Thomas Gleixner
                   ` (7 subsequent siblings)
  32 siblings, 1 reply; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:38 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe

MSI-X vectors can be allocated after the initial MSI-X enablement, but this
needs explicit support of the underlying interrupt domains.

Provide a function to query the ability and functions to allocate/free
individual vectors post-enable.

The allocation can either request a specific index in the MSI-X table or
with the index argument MSI_ANY_INDEX it allocates the next free vector.

The return value is a struct msi_map which on success contains both index
and the Linux interrupt number. In case of failure index is negative and
the Linux interrupt number is 0.

The allocation function is for a single MSI-X index at a time as that's
sufficient for the most urgent use case VFIO to get rid of the 'disable
MSI-X, reallocate, enable-MSI-X' cycle which is prone to lost interrupts
and redirections to the legacy and obviously unhandled INTx.

As single index allocation is also sufficient for the use cases Jason
Gunthorpe pointed out: Allocation of a MSI-X or IMS vector for a network
queue. See Link below.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
Link: https://lore.kernel.org/all/20211126232735.547996838@linutronix.de
---
V2: Added Link to previous discussions (Bjorn)
---
 drivers/pci/msi/api.c       |   67 ++++++++++++++++++++++++++++++++++++++++++++
 drivers/pci/msi/irqdomain.c |    3 +
 include/linux/pci.h         |    6 +++
 3 files changed, 75 insertions(+), 1 deletion(-)

--- a/drivers/pci/msi/api.c
+++ b/drivers/pci/msi/api.c
@@ -113,6 +113,73 @@ int pci_enable_msix_range(struct pci_dev
 EXPORT_SYMBOL(pci_enable_msix_range);
 
 /**
+ * pci_msix_can_alloc_dyn - Query whether dynamic allocation after enabling
+ *			    MSI-X is supported
+ *
+ * @dev:	PCI device to operate on
+ *
+ * Return: True if supported, false otherwise
+ */
+bool pci_msix_can_alloc_dyn(struct pci_dev *dev)
+{
+	if (!dev->msix_cap)
+		return false;
+
+	return pci_msi_domain_supports(dev, MSI_FLAG_PCI_MSIX_ALLOC_DYN, DENY_LEGACY);
+}
+EXPORT_SYMBOL_GPL(pci_msix_can_alloc_dyn);
+
+/**
+ * pci_msix_alloc_irq_at - Allocate an MSI-X interrupt after enabling MSI-X
+ *			   at a given MSI-X vector index or any free vector index
+ *
+ * @dev:	PCI device to operate on
+ * @index:	Index to allocate. If @index == MSI_ANY_INDEX this allocates
+ *		the next free index in the MSI-X table
+ * @affdesc:	Optional pointer to an affinity descriptor structure. NULL otherwise
+ *
+ * Return: A struct msi_map
+ *
+ *	On success msi_map::index contains the allocated index (>= 0) and
+ *	msi_map::virq the allocated Linux interrupt number (> 0).
+ *
+ *	On fail msi_map::index contains the error code and msi_map::virq
+ *	is set to 0.
+ */
+struct msi_map pci_msix_alloc_irq_at(struct pci_dev *dev, unsigned int index,
+				     const struct irq_affinity_desc *affdesc)
+{
+	struct msi_map map = { .index = -ENOTSUPP };
+
+	if (!dev->msix_enabled)
+		return map;
+
+	if (!pci_msix_can_alloc_dyn(dev))
+		return map;
+
+	return msi_domain_alloc_irq_at(&dev->dev, MSI_DEFAULT_DOMAIN, index, affdesc, NULL);
+}
+EXPORT_SYMBOL_GPL(pci_msix_alloc_irq_at);
+
+/**
+ * pci_msix_free_irq - Free an interrupt on a PCI/MSIX interrupt domain
+ *		      which was allocated via pci_msix_alloc_irq_at()
+ *
+ * @dev:	The PCI device to operate on
+ * @map:	A struct msi_map describing the interrupt to free
+ *		as returned from the allocation function.
+ */
+void pci_msix_free_irq(struct pci_dev *dev, struct msi_map map)
+{
+	if (WARN_ON_ONCE(map.index < 0 || map.virq <= 0))
+		return;
+	if (WARN_ON_ONCE(!pci_msix_can_alloc_dyn(dev)))
+		return;
+	msi_domain_free_irqs_range(&dev->dev, MSI_DEFAULT_DOMAIN, map.index, map.index);
+}
+EXPORT_SYMBOL_GPL(pci_msix_free_irq);
+
+/**
  * pci_disable_msix() - Disable MSI-X interrupt mode on device
  * @dev: the PCI device to operate on
  *
--- a/drivers/pci/msi/irqdomain.c
+++ b/drivers/pci/msi/irqdomain.c
@@ -225,7 +225,8 @@ static struct msi_domain_template pci_ms
 	},
 
 	.info = {
-		.flags			= MSI_COMMON_FLAGS | MSI_FLAG_PCI_MSIX,
+		.flags			= MSI_COMMON_FLAGS | MSI_FLAG_PCI_MSIX |
+					  MSI_FLAG_PCI_MSIX_ALLOC_DYN,
 		.bus_token		= DOMAIN_BUS_PCI_DEVICE_MSIX,
 	},
 };
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -38,6 +38,7 @@
 #include <linux/interrupt.h>
 #include <linux/io.h>
 #include <linux/resource_ext.h>
+#include <linux/msi_api.h>
 #include <uapi/linux/pci.h>
 
 #include <linux/pci_ids.h>
@@ -1559,6 +1560,11 @@ int pci_alloc_irq_vectors_affinity(struc
 				   unsigned int max_vecs, unsigned int flags,
 				   struct irq_affinity *affd);
 
+bool pci_msix_can_alloc_dyn(struct pci_dev *dev);
+struct msi_map pci_msix_alloc_irq_at(struct pci_dev *dev, unsigned int index,
+				     const struct irq_affinity_desc *affdesc);
+void pci_msix_free_irq(struct pci_dev *pdev, struct msi_map map);
+
 void pci_free_irq_vectors(struct pci_dev *dev);
 int pci_irq_vector(struct pci_dev *dev, unsigned int nr);
 const struct cpumask *pci_irq_get_affinity(struct pci_dev *pdev, int vec);


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 26/33] x86/apic/msi: Enable MSI_FLAG_PCI_MSIX_ALLOC_DYN
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
                   ` (24 preceding siblings ...)
  2022-11-21 14:38 ` [patch V2 25/33] PCI/MSI: Provide post-enable dynamic allocation interfaces for MSI-X Thomas Gleixner
@ 2022-11-21 14:38 ` Thomas Gleixner
  2022-11-21 14:38 ` [patch V2 27/33] genirq/msi: Provide constants for PCI/IMS support Thomas Gleixner
                   ` (6 subsequent siblings)
  32 siblings, 0 replies; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:38 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe

x86 MSI irqdomains can handle MSI-X allocation post MSI-X enable just out
of the box - on the vector domain and on the remapping domains,

Add the feature flag to the supported feature list

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 arch/x86/include/asm/msi.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/arch/x86/include/asm/msi.h
+++ b/arch/x86/include/asm/msi.h
@@ -63,7 +63,7 @@ struct msi_msg;
 u32 x86_msi_msg_get_destid(struct msi_msg *msg, bool extid);
 
 #define X86_VECTOR_MSI_FLAGS_SUPPORTED					\
-	(MSI_GENERIC_FLAGS_MASK | MSI_FLAG_PCI_MSIX)
+	(MSI_GENERIC_FLAGS_MASK | MSI_FLAG_PCI_MSIX | MSI_FLAG_PCI_MSIX_ALLOC_DYN)
 
 #define X86_VECTOR_MSI_FLAGS_REQUIRED					\
 	(MSI_FLAG_USE_DEF_DOM_OPS | MSI_FLAG_USE_DEF_CHIP_OPS)


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 27/33] genirq/msi: Provide constants for PCI/IMS support
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
                   ` (25 preceding siblings ...)
  2022-11-21 14:38 ` [patch V2 26/33] x86/apic/msi: Enable MSI_FLAG_PCI_MSIX_ALLOC_DYN Thomas Gleixner
@ 2022-11-21 14:38 ` Thomas Gleixner
  2022-11-24  3:01   ` Tian, Kevin
  2022-11-21 14:38 ` [patch V2 28/33] PCI/MSI: Provide IMS (Interrupt Message Store) support Thomas Gleixner
                   ` (5 subsequent siblings)
  32 siblings, 1 reply; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:38 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe

Provide the necessary constants for PCI/IMS support:

  - A new bus token for MSI irqdomain identification
  - A MSI feature flag for the MSI irqdomains to signal support
  - A secondary domain id

The latter expands the device internal domain pointer storage array from 1
to 2 entries. That extra pointer is mostly unused today, but the
alternative solutions would not be free either and would introduce more
complexity all over the place. Trade the 8bytes for simplicity.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 include/linux/irqdomain_defs.h |    1 +
 include/linux/msi.h            |    2 ++
 include/linux/msi_api.h        |    1 +
 3 files changed, 4 insertions(+)

--- a/include/linux/irqdomain_defs.h
+++ b/include/linux/irqdomain_defs.h
@@ -25,6 +25,7 @@ enum irq_domain_bus_token {
 	DOMAIN_BUS_PCI_DEVICE_MSIX,
 	DOMAIN_BUS_DMAR,
 	DOMAIN_BUS_AMDVI,
+	DOMAIN_BUS_PCI_DEVICE_IMS,
 };
 
 #endif /* _LINUX_IRQDOMAIN_DEFS_H */
--- a/include/linux/msi.h
+++ b/include/linux/msi.h
@@ -529,6 +529,8 @@ enum {
 	MSI_FLAG_MSIX_CONTIGUOUS	= (1 << 19),
 	/* PCI/MSI-X vectors can be dynamically allocated/freed post MSI-X enable */
 	MSI_FLAG_PCI_MSIX_ALLOC_DYN	= (1 << 20),
+	/* Support for PCI/IMS */
+	MSI_FLAG_PCI_IMS		= (1 << 21),
 };
 
 /**
--- a/include/linux/msi_api.h
+++ b/include/linux/msi_api.h
@@ -15,6 +15,7 @@ struct device;
  */
 enum msi_domain_ids {
 	MSI_DEFAULT_DOMAIN,
+	MSI_SECONDARY_DOMAIN,
 	MSI_MAX_DEVICE_IRQDOMAINS,
 };
 


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 28/33] PCI/MSI: Provide IMS (Interrupt Message Store) support
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
                   ` (26 preceding siblings ...)
  2022-11-21 14:38 ` [patch V2 27/33] genirq/msi: Provide constants for PCI/IMS support Thomas Gleixner
@ 2022-11-21 14:38 ` Thomas Gleixner
  2022-11-24  3:10   ` Tian, Kevin
  2022-11-21 14:38 ` [patch V2 29/33] PCI/MSI: Provide pci_ims_alloc/free_irq() Thomas Gleixner
                   ` (4 subsequent siblings)
  32 siblings, 1 reply; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:38 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe

IMS (Interrupt Message Store) is a new specification which allows
implementation specific storage of MSI messages contrary to the
strict standard specified MSI and MSI-X message stores.

This requires new device specific interrupt domains to handle the
implementation defined storage which can be an array in device memory or
host/guest memory which is shared with hardware queues.

Add a function to create IMS domains for PCI devices. IMS domains are using
the new per device domain mechanism and are configured by the device driver
via a template. IMS domains are created as secondary device domains so they
work side on side with MSI[-X] on the same device.

The IMS domains have a few constraints:

  - The index space is managed by the core code.

    Device memory based IMS provides a storage array with a fixed size
    which obviously requires an index. But there is no association between
    index and functionality so the core can randomly allocate an index in
    the array.

    Queue memory based IMS does not have the concept of an index as the
    storage is somewhere in memory. In that case the index is purely
    software based to keep track of the allocations.

  - There is no requirement for consecutive index ranges

    This is currently a limitation of the MSI core and can be implemented
    if there is a justified use case by changing the internal storage from
    xarray to maple_tree. For now it's single vector allocation.

  - The interrupt chip must provide the following callbacks:

  	- irq_mask()
	- irq_unmask()
	- irq_write_msi_msg()

   - The interrupt chip must provide the following optional callbacks
     when the irq_mask(), irq_unmask() and irq_write_msi_msg() callbacks
     cannot operate directly on hardware, e.g. in the case that the
     interrupt message store is in queue memory:

     	- irq_bus_lock()
	- irq_bus_unlock()

     These callbacks are invoked from preemptible task context and are
     allowed to sleep. In this case the mandatory callbacks above just
     store the information. The irq_bus_unlock() callback is supposed to
     make the change effective before returning.

   - Interrupt affinity setting is handled by the underlying parent
     interrupt domain and communicated to the IMS domain via
     irq_write_msi_msg(). IMS domains cannot have a irq_set_affinity()
     callback. That's a reasonable restriction similar to the PCI/MSI
     device domain implementations.

The domain is automatically destroyed when the PCI device is removed.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 drivers/pci/msi/irqdomain.c |   59 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/pci.h         |    5 +++
 2 files changed, 64 insertions(+)

--- a/drivers/pci/msi/irqdomain.c
+++ b/drivers/pci/msi/irqdomain.c
@@ -355,6 +355,65 @@ bool pci_msi_domain_supports(struct pci_
 	return (supported & feature_mask) == feature_mask;
 }
 
+/**
+ * pci_create_ims_domain - Create a secondary IMS domain for a PCI device
+ * @pdev:	The PCI device to operate on
+ * @template:	The MSI info template which describes the domain
+ * @hwsize:	The size of the hardware entry table or 0 if the domain
+ *		is purely software managed
+ * @data:	Optional pointer to domain specific data to be stored
+ *		in msi_domain_info::data
+ *
+ * Return: True on success, false otherwise
+ *
+ * An IMS domain is expected to have the following constraints:
+ *	- The index space is managed by the core code
+ *
+ *	- There is no requirement for consecutive index ranges
+ *
+ *	- The interrupt chip must provide the following callbacks:
+ *		- irq_mask()
+ *		- irq_unmask()
+ *		- irq_write_msi_msg()
+ *
+ *	- The interrupt chip must provide the following optional callbacks
+ *	  when the irq_mask(), irq_unmask() and irq_write_msi_msg() callbacks
+ *	  cannot operate directly on hardware, e.g. in the case that the
+ *	  interrupt message store is in queue memory:
+ *		- irq_bus_lock()
+ *		- irq_bus_unlock()
+ *
+ *	  These callbacks are invoked from preemptible task context and are
+ *	  allowed to sleep. In this case the mandatory callbacks above just
+ *	  store the information. The irq_bus_unlock() callback is supposed
+ *	  to make the change effective before returning.
+ *
+ *	- Interrupt affinity setting is handled by the underlying parent
+ *	  interrupt domain and communicated to the IMS domain via
+ *	  irq_write_msi_msg().
+ *
+ * The domain is automatically destroyed when the PCI device is removed.
+ */
+bool pci_create_ims_domain(struct pci_dev *pdev, const struct msi_domain_template *template,
+			   unsigned int hwsize, void *data)
+{
+	struct irq_domain *domain = dev_get_msi_domain(&pdev->dev);
+
+	if (!domain || !irq_domain_is_msi_parent(domain))
+		return -ENOTSUPP;
+
+	if (template->info.bus_token != DOMAIN_BUS_PCI_DEVICE_IMS ||
+	    !(template->info.flags & MSI_FLAG_ALLOC_SIMPLE_MSI_DESCS) ||
+	    !(template->info.flags & MSI_FLAG_FREE_MSI_DESCS) ||
+	    !template->chip.irq_mask || !template->chip.irq_unmask ||
+	    !template->chip.irq_write_msi_msg || template->chip.irq_set_affinity)
+		return -EINVAL;
+
+	return msi_create_device_irq_domain(&pdev->dev, MSI_SECONDARY_DOMAIN, template,
+					    hwsize, data, NULL);
+}
+EXPORT_SYMBOL_GPL(pci_create_ims_domain);
+
 /*
  * Users of the generic MSI infrastructure expect a device to have a single ID,
  * so with DMA aliases we have to pick the least-worst compromise. Devices with
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -2487,6 +2487,11 @@ static inline bool pci_is_thunderbolt_at
 void pci_uevent_ers(struct pci_dev *pdev, enum  pci_ers_result err_type);
 #endif
 
+struct msi_domain_template;
+
+bool pci_create_ims_domain(struct pci_dev *pdev, const struct msi_domain_template *template,
+			   unsigned int hwsize, void *data);
+
 #include <linux/dma-mapping.h>
 
 #define pci_printk(level, pdev, fmt, arg...) \


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 29/33] PCI/MSI: Provide pci_ims_alloc/free_irq()
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
                   ` (27 preceding siblings ...)
  2022-11-21 14:38 ` [patch V2 28/33] PCI/MSI: Provide IMS (Interrupt Message Store) support Thomas Gleixner
@ 2022-11-21 14:38 ` Thomas Gleixner
  2022-11-24  3:11   ` Tian, Kevin
  2022-11-21 14:38 ` [patch V2 30/33] x86/apic/msi: Enable PCI/IMS Thomas Gleixner
                   ` (3 subsequent siblings)
  32 siblings, 1 reply; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:38 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe

Single vector allocation which allocates the next free index in the IMS
space. The free function releases.

All allocated vectors are released also via pci_free_vectors() which is
also releasing MSI/MSI-X vectors.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Bjorn Helgaas <bhelgaas@google.com>
---
 drivers/pci/msi/api.c |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/pci.h   |    3 +++
 2 files changed, 53 insertions(+)

--- a/drivers/pci/msi/api.c
+++ b/drivers/pci/msi/api.c
@@ -361,6 +361,56 @@ const struct cpumask *pci_irq_get_affini
 EXPORT_SYMBOL(pci_irq_get_affinity);
 
 /**
+ * pci_ims_alloc_irq - Allocate an interrupt on a PCI/IMS interrupt domain
+ * @dev:	The PCI device to operate on
+ * @icookie:	Pointer to an IMS implementation specific cookie for this
+ *		IMS instance (PASID, queue ID, pointer...).
+ *		The cookie content is copied into the MSI descriptor for the
+ *		interrupt chip callbacks or domain specific setup functions.
+ * @affdesc:	Optional pointer to an interrupt affinity descriptor
+ *
+ * There is no index for IMS allocations as IMS is an implementation
+ * specific storage and does not have any direct associations between
+ * index, which might be a pure software construct, and device
+ * functionality. This association is established by the driver either via
+ * the index - if there is a hardware table - or in case of purely software
+ * managed IMS implementation the association happens via the
+ * irq_write_msi_msg() callback of the implementation specific interrupt
+ * chip, which utilizes the provided @cookie to store the MSI message in
+ * the appropriate place.
+ *
+ * Return: A struct msi_map
+ *
+ *	On success msi_map::index contains the allocated index (>= 0) and
+ *	msi_map::virq the allocated Linux interrupt number (> 0).
+ *
+ *	On fail msi_map::index contains the error code and msi_map::virq
+ *	is set to 0.
+ */
+struct msi_map pci_ims_alloc_irq(struct pci_dev *dev, union msi_instance_cookie *icookie,
+				 const struct irq_affinity_desc *affdesc)
+{
+	return msi_domain_alloc_irq_at(&dev->dev, MSI_SECONDARY_DOMAIN, MSI_ANY_INDEX,
+				       affdesc, icookie);
+}
+EXPORT_SYMBOL_GPL(pci_ims_alloc_irq);
+
+/**
+ * pci_ims_free_irq - Allocate an interrupt on a PCI/IMS interrupt domain
+ *		      which was allocated via pci_ims_alloc_irq()
+ * @dev:	The PCI device to operate on
+ * @map:	A struct msi_map describing the interrupt to free as
+ *		returned from pci_ims_alloc_irq()
+ */
+void pci_ims_free_irq(struct pci_dev *dev, struct msi_map map)
+{
+	if (WARN_ON_ONCE(map.index < 0 || !map.virq))
+		return;
+	msi_domain_free_irqs_range(&dev->dev, MSI_SECONDARY_DOMAIN, map.index, map.index);
+}
+EXPORT_SYMBOL_GPL(pci_ims_free_irq);
+
+/**
  * pci_free_irq_vectors() - Free previously allocated IRQs for a device
  * @dev: the PCI device to operate on
  *
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -2491,6 +2491,9 @@ struct msi_domain_template;
 
 bool pci_create_ims_domain(struct pci_dev *pdev, const struct msi_domain_template *template,
 			   unsigned int hwsize, void *data);
+struct msi_map pci_ims_alloc_irq(struct pci_dev *pdev, union msi_instance_cookie *icookie,
+				 const struct irq_affinity_desc *affdesc);
+void pci_ims_free_irq(struct pci_dev *pdev, struct msi_map map);
 
 #include <linux/dma-mapping.h>
 


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 30/33] x86/apic/msi: Enable PCI/IMS
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
                   ` (28 preceding siblings ...)
  2022-11-21 14:38 ` [patch V2 29/33] PCI/MSI: Provide pci_ims_alloc/free_irq() Thomas Gleixner
@ 2022-11-21 14:38 ` Thomas Gleixner
  2022-11-21 14:38 ` [patch V2 31/33] iommu/vt-d: " Thomas Gleixner
                   ` (2 subsequent siblings)
  32 siblings, 0 replies; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:38 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe

Enable IMS in the domain init and allocation mapping code, but do not
enable it on the vector domain as discussed in various threads on LKML.

The interrupt remap domains can expand this setting like they do with
PCI multi MSI.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 arch/x86/kernel/apic/msi.c |    5 +++++
 1 file changed, 5 insertions(+)

--- a/arch/x86/kernel/apic/msi.c
+++ b/arch/x86/kernel/apic/msi.c
@@ -184,6 +184,7 @@ static int x86_msi_prepare(struct irq_do
 		alloc->type = X86_IRQ_ALLOC_TYPE_PCI_MSI;
 		return 0;
 	case DOMAIN_BUS_PCI_DEVICE_MSIX:
+	case DOMAIN_BUS_PCI_DEVICE_IMS:
 		alloc->type = X86_IRQ_ALLOC_TYPE_PCI_MSIX;
 		return 0;
 	default:
@@ -230,6 +231,10 @@ static bool x86_init_dev_msi_info(struct
 	case DOMAIN_BUS_PCI_DEVICE_MSI:
 	case DOMAIN_BUS_PCI_DEVICE_MSIX:
 		break;
+	case DOMAIN_BUS_PCI_DEVICE_IMS:
+		if (!(pops->supported_flags & MSI_FLAG_PCI_IMS))
+			return false;
+		break;
 	default:
 		WARN_ON_ONCE(1);
 		return false;


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 31/33] iommu/vt-d: Enable PCI/IMS
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
                   ` (29 preceding siblings ...)
  2022-11-21 14:38 ` [patch V2 30/33] x86/apic/msi: Enable PCI/IMS Thomas Gleixner
@ 2022-11-21 14:38 ` Thomas Gleixner
  2022-11-24  3:17   ` Tian, Kevin
  2022-11-21 14:38 ` [patch V2 32/33] iommu/amd: " Thomas Gleixner
  2022-11-21 14:38 ` [patch V2 33/33] irqchip: Add IDXD Interrupt Message Store driver Thomas Gleixner
  32 siblings, 1 reply; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:38 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe

PCI/IMS works like PCI/MSI-X in the remapping. Just add the feature flag.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 drivers/iommu/intel/irq_remapping.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

--- a/drivers/iommu/intel/irq_remapping.c
+++ b/drivers/iommu/intel/irq_remapping.c
@@ -1429,7 +1429,9 @@ static const struct irq_domain_ops intel
 };
 
 static const struct msi_parent_ops dmar_msi_parent_ops = {
-	.supported_flags	= X86_VECTOR_MSI_FLAGS_SUPPORTED | MSI_FLAG_MULTI_PCI_MSI,
+	.supported_flags	= X86_VECTOR_MSI_FLAGS_SUPPORTED |
+				  MSI_FLAG_MULTI_PCI_MSI |
+				  MSI_FLAG_PCI_IMS,
 	.prefix			= "IR-",
 	.init_dev_msi_info	= msi_parent_init_dev_msi_info,
 };


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 32/33] iommu/amd: Enable PCI/IMS
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
                   ` (30 preceding siblings ...)
  2022-11-21 14:38 ` [patch V2 31/33] iommu/vt-d: " Thomas Gleixner
@ 2022-11-21 14:38 ` Thomas Gleixner
  2022-11-21 14:38 ` [patch V2 33/33] irqchip: Add IDXD Interrupt Message Store driver Thomas Gleixner
  32 siblings, 0 replies; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:38 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe

PCI/IMS works like PCI/MSI-X in the remapping. Just add the feature flag.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 drivers/iommu/amd/iommu.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -3649,7 +3649,9 @@ static struct irq_chip amd_ir_chip = {
 };
 
 static const struct msi_parent_ops amdvi_msi_parent_ops = {
-	.supported_flags	= X86_VECTOR_MSI_FLAGS_SUPPORTED | MSI_FLAG_MULTI_PCI_MSI,
+	.supported_flags	= X86_VECTOR_MSI_FLAGS_SUPPORTED |
+				  MSI_FLAG_MULTI_PCI_MSI |
+				  MSI_FLAG_PCI_IMS,
 	.prefix			= "IR-",
 	.init_dev_msi_info	= msi_parent_init_dev_msi_info,
 };


^ permalink raw reply	[flat|nested] 72+ messages in thread

* [patch V2 33/33] irqchip: Add IDXD Interrupt Message Store driver
  2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
                   ` (31 preceding siblings ...)
  2022-11-21 14:38 ` [patch V2 32/33] iommu/amd: " Thomas Gleixner
@ 2022-11-21 14:38 ` Thomas Gleixner
  2022-11-24  3:19   ` Tian, Kevin
  32 siblings, 1 reply; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-21 14:38 UTC (permalink / raw)
  To: LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Dave Jiang, Alex Williamson, Kevin Tian,
	Dan Williams, Logan Gunthorpe, Ashok Raj, Jon Mason, Allen Hubbe

Provide a driver for the Intel IDXD IMS implementation. The implementation
uses a large message store array in device memory.

The IMS domain implementation is minimal and just provides the required
irq_chip callbacks and one domain callback which prepares the MSI
descriptor for easy usage in the irq_chip callbacks.

The necessary iobase is stored in the irqdomain and the PASID which is
required for operation is handed in via msi_instance_cookie in the
allocation function.

Not much to see here. A few lines of code and a filled in template is all
what's needed.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 drivers/irqchip/Kconfig                    |    7 +
 drivers/irqchip/Makefile                   |    1 
 drivers/irqchip/irq-pci-intel-idxd.c       |  143 +++++++++++++++++++++++++++++
 include/linux/irqchip/irq-pci-intel-idxd.h |   22 ++++
 4 files changed, 173 insertions(+)

--- a/drivers/irqchip/Kconfig
+++ b/drivers/irqchip/Kconfig
@@ -695,4 +695,11 @@ config SUNPLUS_SP7021_INTC
 	  chained controller, routing all interrupt source in P-Chip to
 	  the primary controller on C-Chip.
 
+config PCI_INTEL_IDXD_IMS
+	tristate "Intel IDXD Interrupt Message Store controller"
+	depends on PCI_MSI
+	help
+	  Support for Intel IDXD IMS Interrupt Message Store controller
+	  with IMS slot storage in a slot array in device memory
+
 endmenu
--- a/drivers/irqchip/Makefile
+++ b/drivers/irqchip/Makefile
@@ -121,3 +121,4 @@ obj-$(CONFIG_IRQ_IDT3243X)		+= irq-idt32
 obj-$(CONFIG_APPLE_AIC)			+= irq-apple-aic.o
 obj-$(CONFIG_MCHP_EIC)			+= irq-mchp-eic.o
 obj-$(CONFIG_SUNPLUS_SP7021_INTC)	+= irq-sp7021-intc.o
+obj-$(CONFIG_PCI_INTEL_IDXD_IMS)	+= irq-pci-intel-idxd.o
--- /dev/null
+++ b/drivers/irqchip/irq-pci-intel-idxd.c
@@ -0,0 +1,143 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Interrupt chip and domain for Intel IDXD with hardware array based
+ * interrupt message store (IMS).
+ */
+#include <linux/device.h>
+#include <linux/irq.h>
+#include <linux/irqdomain.h>
+#include <linux/msi.h>
+#include <linux/pci.h>
+
+#include <linux/irqchip/irq-pci-intel-idxd.h>
+
+MODULE_LICENSE("GPL");
+
+/**
+ * struct ims_slot - The hardware layout of a slot in the memory table
+ * @address_lo:	Lower 32bit address
+ * @address_hi:	Upper 32bit address
+ * @data:	Message data
+ * @ctrl:	Control word
+ */
+struct ims_slot {
+	u32	address_lo;
+	u32	address_hi;
+	u32	data;
+	u32	ctrl;
+} __packed;
+
+/* Bit to mask the interrupt in the control word */
+#define CTRL_VECTOR_MASKBIT	BIT(0)
+/* Bit to enable PASID in the control word */
+#define CTRL_PASID_ENABLE	BIT(3)
+/* Position of PASID.LSB in the control word */
+#define CTRL_PASID_SHIFT	12
+
+static inline void iowrite32_and_flush(u32 value, void __iomem *addr)
+{
+	iowrite32(value, addr);
+	ioread32(addr);
+}
+
+static void idxd_mask(struct irq_data *data)
+{
+	struct msi_desc *desc = irq_data_get_msi_desc(data);
+	struct ims_slot __iomem *slot = desc->data.dcookie.iobase;
+	u32 cval = (u32)desc->data.icookie.value;
+
+	iowrite32_and_flush(cval | CTRL_VECTOR_MASKBIT, &slot->ctrl);
+}
+
+static void idxd_unmask(struct irq_data *data)
+{
+	struct msi_desc *desc = irq_data_get_msi_desc(data);
+	struct ims_slot __iomem *slot = desc->data.dcookie.iobase;
+	u32 cval = (u32)desc->data.icookie.value;
+
+	iowrite32_and_flush(cval, &slot->ctrl);
+}
+
+static void idxd_write_msi_msg(struct irq_data *data, struct msi_msg *msg)
+{
+	struct msi_desc *desc = irq_data_get_msi_desc(data);
+	struct ims_slot __iomem *slot = desc->data.dcookie.iobase;
+
+	iowrite32(msg->address_lo, &slot->address_lo);
+	iowrite32(msg->address_hi, &slot->address_hi);
+	iowrite32_and_flush(msg->data, &slot->data);
+}
+
+static void idxd_shutdown(struct irq_data *data)
+{
+	struct msi_desc *desc = irq_data_get_msi_desc(data);
+	struct ims_slot __iomem *slot = desc->data.dcookie.iobase;
+
+	iowrite32(0, &slot->address_lo);
+	iowrite32(0, &slot->address_hi);
+	iowrite32(0, &slot->data);
+	iowrite32_and_flush(CTRL_VECTOR_MASKBIT, &slot->ctrl);
+}
+
+static void idxd_prepare_desc(struct irq_domain *domain, msi_alloc_info_t *arg,
+			      struct msi_desc *desc)
+{
+	struct msi_domain_info *info = domain->host_data;
+	struct ims_slot __iomem *slot;
+
+	/* Set up the slot address for the irq_chip callbacks */
+	slot = (__force struct ims_slot __iomem *) info->data;
+	slot += desc->msi_index;
+	desc->data.dcookie.iobase = slot;
+
+	/* Mask the interrupt for paranoia sake */
+	iowrite32_and_flush(CTRL_VECTOR_MASKBIT, &slot->ctrl);
+
+	/*
+	 * The caller provided PASID. Shift it to the proper position
+	 * and set the PASID enable bit.
+	 */
+	desc->data.icookie.value <<= CTRL_PASID_SHIFT;
+	desc->data.icookie.value |= CTRL_PASID_ENABLE;
+
+	arg->hwirq = desc->msi_index;
+}
+
+static const struct msi_domain_template idxd_ims_template = {
+	.chip = {
+		.name			= "PCI-IDXD",
+		.irq_mask		= idxd_mask,
+		.irq_unmask		= idxd_unmask,
+		.irq_write_msi_msg	= idxd_write_msi_msg,
+		.irq_shutdown		= idxd_shutdown,
+		.flags			= IRQCHIP_ONESHOT_SAFE,
+	},
+
+	.ops = {
+		.prepare_desc		= idxd_prepare_desc,
+	},
+
+	.info = {
+		.flags			= MSI_FLAG_ALLOC_SIMPLE_MSI_DESCS |
+					  MSI_FLAG_FREE_MSI_DESCS |
+					  MSI_FLAG_PCI_IMS,
+		.bus_token		= DOMAIN_BUS_PCI_DEVICE_IMS,
+	},
+};
+
+/**
+ * pci_intel_idxd_create_ims_domain - Create a IDXD IMS domain
+ * @pdev:	IDXD PCI device to operate on
+ * @slots:	Pointer to the mapped slot memory arrray
+ * @nr_slots:	The number of slots in the array
+ *
+ * Returns: True on success, false otherwise
+ *
+ * The domain is automatically destroyed when the @pdev is destroyed
+ */
+bool pci_intel_idxd_create_ims_domain(struct pci_dev *pdev, void __iomem *slots,
+				      unsigned int nr_slots)
+{
+	return pci_create_ims_domain(pdev, &idxd_ims_template, nr_slots, (__force void *)slots);
+}
+EXPORT_SYMBOL_GPL(pci_intel_idxd_create_ims_domain);
--- /dev/null
+++ b/include/linux/irqchip/irq-pci-intel-idxd.h
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* (C) Copyright 2022 Thomas Gleixner <tglx@linutronix.de> */
+
+#ifndef _LINUX_IRQCHIP_IRQ_PCI_INTEL_IDXD_H
+#define _LINUX_IRQCHIP_IRQ_PCI_INTEL_IDXD_H
+
+#include <linux/msi_api.h>
+#include <linux/bits.h>
+#include <linux/types.h>
+
+/*
+ * Conveniance macro to wrap the PASID for interrupt allocation
+ * via pci_ims_alloc_irq(pdev, INTEL_IDXD_DEV_COOKIE(pasid))
+ */
+#define INTEL_IDXD_DEV_COOKIE(pasid)	(union msi_instance_cookie) { .value = (pasid), }
+
+struct pci_dev;
+
+bool pci_intel_idxd_create_ims_domain(struct pci_dev *pdev, void __iomem *slots,
+				      unsigned int nr_slots);
+
+#endif


^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 02/33] genirq/msi: Provide struct msi_parent_ops
  2022-11-21 14:37 ` [patch V2 02/33] genirq/msi: Provide struct msi_parent_ops Thomas Gleixner
@ 2022-11-23  7:57   ` Tian, Kevin
  2022-11-23 11:28     ` Thomas Gleixner
  0 siblings, 1 reply; 72+ messages in thread
From: Tian, Kevin @ 2022-11-23  7:57 UTC (permalink / raw)
  To: Thomas Gleixner, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

> From: Thomas Gleixner <tglx@linutronix.de>
> Sent: Monday, November 21, 2022 10:38 PM
> 
> +/**
> + * msi_parent_init_dev_msi_info - Delegate initialization of device MSI info
> down
> + *				  in the domain hierarchy
> + * @dev:		The device for which the domain should be created
> + * @domain:		The domain in the hierarchy this op is being called on
> + * @msi_parent_domain:	The IRQ_DOMAIN_FLAG_MSI_PARENT
> domain for the child to
> + *			be created
> + * @msi_child_info:	The MSI domain info of the
> IRQ_DOMAIN_FLAG_MSI_DEVICE
> + *			domain to be created
> + *
> + * Return: true on success, false otherwise
> + *
> + * This is the most complex problem of per device MSI domains and the
> + * underlying interrupt domain hierarchy:
> + *
> + * The device domain to be initialized requests the broadest feature set
> + * possible and the underlying domain hierarchy puts restrictions on it.
> + *
> + * That's trivial for a simple parent->child relationship, but it gets
> + * interesting with an intermediate domain: root->parent->child.  The
> + * intermediate 'parent' can expand the capabilities which the 'root'
> + * domain is providing. So that creates a classic hen and egg problem:
> + * Which entity is doing the restrictions/expansions?
> + *
> + * One solution is to let the root domain handle the initialization that's
> + * why there is the @domain and the @msi_parent_domain pointer.
 
This is the part which I don't quite understand (sorry with limited knowledge
in this area).

In concept a hierarchical model has restrictions added up when moving
down to lower layers i.e. presumably the root domain decides the minimal
supported capabilities. In this case there is no need of a real parent pointer
as long as every domain in the stack incrementally adds its restrictions to
info->flags.

I can see why this is required for x86 given that MULTI_MSI is supported
only with IR. and we cannot make vector domain inclusively claiming
MULTI_MSI since it's completely broken when the vector domain becomes
the parent itself, in absence of IR.

Just be curious whether this intermediate-parent-deciding-restrictions
is generic instead of x86 specific, e.g. is it possible to have a 4-layers
hierarchy where the root parent wants to check both two intermediate
parents?

Thanks
Kevin

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 03/33] genirq/msi: Provide data structs for per device domains
  2022-11-21 14:37 ` [patch V2 03/33] genirq/msi: Provide data structs for per device domains Thomas Gleixner
@ 2022-11-23  7:57   ` Tian, Kevin
  2022-11-23 11:29     ` Thomas Gleixner
  0 siblings, 1 reply; 72+ messages in thread
From: Tian, Kevin @ 2022-11-23  7:57 UTC (permalink / raw)
  To: Thomas Gleixner, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

> From: Thomas Gleixner <tglx@linutronix.de>
> Sent: Monday, November 21, 2022 10:38 PM
> 
> Provide struct msi_domain_template which contains a bundle of struct
> irq_chip, struct msi_domain_ops and struct msi_domain_info and a name
> field.
> 
> This template is used by MSI device domain implementations to provide the
> domain specific functionality, feature bits etc.
> 
> When a MSI domain is created the template is duplicated in the core code
> so that it can be modified per instance. That means templates can be
> marked const at the MSI device domain code.
> 
> The template is a bundle to avoid several allocations and duplications
> of the involved structures.
> 
> The name field is used to construct the final domain and chip name via:
> 
>     $PREFIX-$NAME-$DEVNAME

$PREFIX$NAME-$DEVNAME


^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 07/33] genirq/msi: Provide msi_create/free_device_irq_domain()
  2022-11-21 14:37 ` [patch V2 07/33] genirq/msi: Provide msi_create/free_device_irq_domain() Thomas Gleixner
@ 2022-11-23  8:02   ` Tian, Kevin
  2022-11-23 11:38     ` Thomas Gleixner
  0 siblings, 1 reply; 72+ messages in thread
From: Tian, Kevin @ 2022-11-23  8:02 UTC (permalink / raw)
  To: Thomas Gleixner, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

> From: Thomas Gleixner <tglx@linutronix.de>
> Sent: Monday, November 21, 2022 10:38 PM
> 
> 
> +static inline void msi_remove_device_irqdomains(struct device *dev, struct
> msi_device_data *md)
> +{

'md' is unused

> 
> +/**
> + * msi_create_device_irq_domain - Create a device MSI interrupt domain
> + * @dev:		Pointer to the device
> + * @domid:		Domain id
> + * @template:		MSI domain info bundle used as template
> + * @hwsize:		Maximum number of MSI table entries (0 if unknown
> or unlimited)
> + * @domain_data:	Optional pointer to domain specific data which is set
> in
> + *			msi_domain_info::data
> + * @chip_data:		Optional pointer to chip specific data which is
> set in
> + *			msi_domain_info::chip_data
> + *
> + * Return: True on success, false otherwise

Can you elaborate why boolean type is selected instead of returning the
actual error codes? the outmost callers are all new functions:

	pci_setup_msi[x]_device_domain()
	pci_create_ims_domain()

I didn't find out any legacy convention forcing this way...

> +	bundle = kmemdup(template, sizeof(*bundle), GFP_KERNEL);
> +	if (!bundle)
> +		return false;
> +
> +	bundle->info.hwsize = hwsize ? hwsize : MSI_MAX_INDEX;

patch04 marks that hwsize being 0 means unknown or unlimited in the
header file.

but here info.hwsize always gets a value i.e. the meaning of 0 only exists
in this function. What about removing the trailing words about 0 in
patch04?

- + * @hwsize:		The hardware table size (0 if unknown/unlimited)
+ + * @hwsize:		The hardware table size

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 12/33] PCI/MSI: Add support for per device MSI[X] domains
  2022-11-21 14:38 ` [patch V2 12/33] PCI/MSI: Add support for per device MSI[X] domains Thomas Gleixner
@ 2022-11-23  8:08   ` Tian, Kevin
  2022-11-23 11:41     ` Thomas Gleixner
  0 siblings, 1 reply; 72+ messages in thread
From: Tian, Kevin @ 2022-11-23  8:08 UTC (permalink / raw)
  To: Thomas Gleixner, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe,
	Ahmed S. Darwish

> From: Thomas Gleixner <tglx@linutronix.de>
> Sent: Monday, November 21, 2022 10:38 PM
> 
> +
> +static void pci_mask_msi(struct irq_data *data)
> +{
> +	struct msi_desc *desc = irq_data_get_msi_desc(data);
> +
> +	pci_msi_mask(desc, BIT(data->irq - desc->irq));

pci_mask_msi() and pci_msi_mask() are confusing.

Probably pci_irq_mask_msi() given the parameter is irq_data.

> +bool pci_setup_msi_device_domain(struct pci_dev *pdev)
> +{
> +	if (WARN_ON_ONCE(pdev->msix_enabled))
> +		return false;

the check already exists in __pci_enable_msi_range()

> +bool pci_setup_msix_device_domain(struct pci_dev *pdev, unsigned int
> hwsize)
> +{
> +	if (WARN_ON_ONCE(pdev->msix_enabled))
> +		return false;

ditto.

btw according to the comment this should check pdev->msi_enabled.

> @@ -152,13 +316,33 @@ bool pci_msi_domain_supports(struct pci_
>  {
>  	struct msi_domain_info *info;
>  	struct irq_domain *domain;
> +	unsigned int supported;
> 
>  	domain = dev_get_msi_domain(&pdev->dev);
> 
>  	if (!domain || !irq_domain_is_hierarchy(domain))
>  		return mode == ALLOW_LEGACY;
> -	info = domain->host_data;
> -	return (info->flags & feature_mask) == feature_mask;
> +
> +	if (!irq_domain_is_msi_parent(domain)) {
> +		/*
> +		 * For "global" PCI/MSI interrupt domains the associated
> +		 * msi_domain_info::flags is the authoritive source of
> +		 * information.
> +		 */
> +		info = domain->host_data;
> +		supported = info->flags;
> +	} else {
> +		/*
> +		 * For MSI parent domains the supported feature set
> +		 * is avaliable in the parent ops. This makes checks
> +		 * possible before actually instantiating the
> +		 * per device domain because the parent is never
> +		 * expanding the PCI/MSI functionality.
> +		 */
> +		supported = domain->msi_parent_ops->supported_flags;

This is general PCI MSI logic. So an open related to my rely to patch02,
is it correct for PCI core to assume that the real parent imposes all the
restrictions and there is no need to further go down the hierarchy?

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 13/33] x86/apic/vector: Provide MSI parent domain
  2022-11-21 14:38 ` [patch V2 13/33] x86/apic/vector: Provide MSI parent domain Thomas Gleixner
@ 2022-11-23  8:16   ` Tian, Kevin
  2022-11-23 13:42     ` Thomas Gleixner
  0 siblings, 1 reply; 72+ messages in thread
From: Tian, Kevin @ 2022-11-23  8:16 UTC (permalink / raw)
  To: Thomas Gleixner, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

> From: Thomas Gleixner <tglx@linutronix.de>
> Sent: Monday, November 21, 2022 10:38 PM
> 
> +bool pci_dev_has_default_msi_parent_domain(struct pci_dev *dev)
> +{
> +	struct irq_domain *domain = dev_get_msi_domain(&dev->dev);
> 
> -int pci_msi_prepare(struct irq_domain *domain, struct device *dev, int nvec,
> -		    msi_alloc_info_t *arg)
> +	if (!domain)
> +		domain = dev_get_msi_domain(&dev->bus->dev);
> +	if (!domain)
> +		return false;
> +
> +	return domain == x86_vector_domain;

the function name is about parent domain but there is no check on
the parent flag. Probably just remove 'parent'?

> +/**
> + * x86_init_dev_msi_info - Domain info setup for MSI domains
> + * @dev:		The device for which the domain should be created
> + * @domain:		The (root) domain providing this callback

what is the purpose of '(root)'? it's also used by intermediate domain i.e. IR.

> +
> +	/*
> +	 * Mask out the domain specific MSI feature flags which are not
> +	 * supported by the real parent.
> +	 */
> +	info->flags			&= pops->supported_flags;
> +	/* Enforce the required flags */
> +	info->flags			|=
> X86_VECTOR_MSI_FLAGS_REQUIRED;
> +
> +	/* This is always invoked from the top level MSI domain! */
> +	info->ops->msi_prepare		= x86_msi_prepare;
> +
> +	info->chip->irq_ack		= irq_chip_ack_parent;
> +	info->chip->irq_retrigger	= irq_chip_retrigger_hierarchy;
> +	info->chip->flags		|= IRQCHIP_SKIP_SET_WAKE |
> +					   IRQCHIP_AFFINITY_PRE_STARTUP;

Above are executed twice for both IR and vector after next patch comes.
Could skip it for IR.


^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 19/33] genirq/msi: Provide msi_desc::msi_data
  2022-11-21 14:38 ` [patch V2 19/33] genirq/msi: Provide msi_desc::msi_data Thomas Gleixner
@ 2022-11-23  8:27   ` Tian, Kevin
  2022-11-23 11:41     ` Thomas Gleixner
  0 siblings, 1 reply; 72+ messages in thread
From: Tian, Kevin @ 2022-11-23  8:27 UTC (permalink / raw)
  To: Thomas Gleixner, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

> From: Thomas Gleixner <tglx@linutronix.de>
> Sent: Monday, November 21, 2022 10:38 PM
> 
> The upcoming support for PCI/IMS requires to store some information
> related
> to the message handling in the MSI descriptor, e.g. PASID or a pointer to a
> queue.
> 
> Provide a generic storage struct which maps over the existing PCI specific
> storage which means the size of struct msi_desc is not getting bigger.
> 
> It contains a iomem pointer for device memory based IMS and a union of a
> u64 and a void pointer which allows the device specific IMS implementations
> to store the necessary information.

stale comment.

> 
> The iomem pointer is set up by the domain allocation functions.
> 
> The data union msi_dev_cookie is going to be handed in when allocating an

no msi_dev_cookie now.

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 02/33] genirq/msi: Provide struct msi_parent_ops
  2022-11-23  7:57   ` Tian, Kevin
@ 2022-11-23 11:28     ` Thomas Gleixner
  2022-11-24  0:53       ` Tian, Kevin
  0 siblings, 1 reply; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-23 11:28 UTC (permalink / raw)
  To: Tian, Kevin, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

On Wed, Nov 23 2022 at 07:57, Kevin Tian wrote:
>> From: Thomas Gleixner <tglx@linutronix.de>
>> + * One solution is to let the root domain handle the initialization that's
>> + * why there is the @domain and the @msi_parent_domain pointer.
>  
> This is the part which I don't quite understand (sorry with limited knowledge
> in this area).
>
> In concept a hierarchical model has restrictions added up when moving
> down to lower layers i.e. presumably the root domain decides the minimal
> supported capabilities. In this case there is no need of a real parent pointer
> as long as every domain in the stack incrementally adds its restrictions to
> info->flags.
>
> I can see why this is required for x86 given that MULTI_MSI is supported
> only with IR. and we cannot make vector domain inclusively claiming
> MULTI_MSI since it's completely broken when the vector domain becomes
> the parent itself, in absence of IR.
>
> Just be curious whether this intermediate-parent-deciding-restrictions
> is generic instead of x86 specific, e.g. is it possible to have a 4-layers
> hierarchy where the root parent wants to check both two intermediate
> parents?

Sure. Nothing prevents you from doing so:

dom4:
    .init... = dom4_init

dom4_init()
    do_stuff()
    invoke parent init

dom3:
    .init... = parent_init

dom2:
    .init... = dom2_init

dom2_init()
    do_stuff()
    invoke parent init

....

See?

Thanks,

        tglx


^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 03/33] genirq/msi: Provide data structs for per device domains
  2022-11-23  7:57   ` Tian, Kevin
@ 2022-11-23 11:29     ` Thomas Gleixner
  0 siblings, 0 replies; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-23 11:29 UTC (permalink / raw)
  To: Tian, Kevin, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

On Wed, Nov 23 2022 at 07:57, Kevin Tian wrote:
>> From: Thomas Gleixner <tglx@linutronix.de>
>> Sent: Monday, November 21, 2022 10:38 PM
>> 
>> Provide struct msi_domain_template which contains a bundle of struct
>> irq_chip, struct msi_domain_ops and struct msi_domain_info and a name
>> field.
>> 
>> This template is used by MSI device domain implementations to provide the
>> domain specific functionality, feature bits etc.
>> 
>> When a MSI domain is created the template is duplicated in the core code
>> so that it can be modified per instance. That means templates can be
>> marked const at the MSI device domain code.
>> 
>> The template is a bundle to avoid several allocations and duplications
>> of the involved structures.
>> 
>> The name field is used to construct the final domain and chip name via:
>> 
>>     $PREFIX-$NAME-$DEVNAME
>
> $PREFIX$NAME-$DEVNAME

Indeed.

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 07/33] genirq/msi: Provide msi_create/free_device_irq_domain()
  2022-11-23  8:02   ` Tian, Kevin
@ 2022-11-23 11:38     ` Thomas Gleixner
  2022-11-23 21:01       ` Thomas Gleixner
  2022-11-24  1:07       ` Tian, Kevin
  0 siblings, 2 replies; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-23 11:38 UTC (permalink / raw)
  To: Tian, Kevin, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

On Wed, Nov 23 2022 at 08:02, Kevin Tian wrote:
>> From: Thomas Gleixner <tglx@linutronix.de>
>> Sent: Monday, November 21, 2022 10:38 PM
>> 
>> 
>> +static inline void msi_remove_device_irqdomains(struct device *dev, struct
>> msi_device_data *md)
>> +{
>
> 'md' is unused

Duh, yes.

>> + *
>> + * Return: True on success, false otherwise
>
> Can you elaborate why boolean type is selected instead of returning the
> actual error codes? the outmost callers are all new functions:
>
> 	pci_setup_msi[x]_device_domain()
> 	pci_create_ims_domain()
>
> I didn't find out any legacy convention forcing this way...

What's the value of error codes? 99% of all callsites do:

       ret = foo();
       if (ret)
          goto fail;

Nothing evaluates the error codes, unless there is real useful
information like EAGAIN or ENOSPC which can tell the caller to retry
eventually or with different parameters. But for the above, the error
code is just useless.

>> +	bundle = kmemdup(template, sizeof(*bundle), GFP_KERNEL);
>> +	if (!bundle)
>> +		return false;
>> +
>> +	bundle->info.hwsize = hwsize ? hwsize : MSI_MAX_INDEX;
>
> patch04 marks that hwsize being 0 means unknown or unlimited in the
> header file.
>
> but here info.hwsize always gets a value i.e. the meaning of 0 only exists
> in this function. What about removing the trailing words about 0 in
> patch04?
>
> - + * @hwsize:		The hardware table size (0 if unknown/unlimited)
> + + * @hwsize:		The hardware table size

Fair enough, though I rather make that:

 * @hwsize:		The hardware table size or the software defined
                        index limit




      

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 12/33] PCI/MSI: Add support for per device MSI[X] domains
  2022-11-23  8:08   ` Tian, Kevin
@ 2022-11-23 11:41     ` Thomas Gleixner
  2022-11-23 21:50       ` Thomas Gleixner
  0 siblings, 1 reply; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-23 11:41 UTC (permalink / raw)
  To: Tian, Kevin, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe,
	Ahmed S. Darwish

On Wed, Nov 23 2022 at 08:08, Kevin Tian wrote:
>> From: Thomas Gleixner <tglx@linutronix.de>
>
> pci_mask_msi() and pci_msi_mask() are confusing.
>
> Probably pci_irq_mask_msi() given the parameter is irq_data.

maybe.

>> +bool pci_setup_msi_device_domain(struct pci_dev *pdev)
>> +{
>> +	if (WARN_ON_ONCE(pdev->msix_enabled))
>> +		return false;
>
> the check already exists in __pci_enable_msi_range()
>
>> +bool pci_setup_msix_device_domain(struct pci_dev *pdev, unsigned int
>> hwsize)
>> +{
>> +	if (WARN_ON_ONCE(pdev->msix_enabled))
>> +		return false;
>
> ditto.
>
> btw according to the comment this should check pdev->msi_enabled.

Yeah, those are probably redundant.

>
>> @@ -152,13 +316,33 @@ bool pci_msi_domain_supports(struct pci_
>>  {
>>  	struct msi_domain_info *info;
>>  	struct irq_domain *domain;
>> +	unsigned int supported;
>> 
>>  	domain = dev_get_msi_domain(&pdev->dev);
>> 
>>  	if (!domain || !irq_domain_is_hierarchy(domain))
>>  		return mode == ALLOW_LEGACY;
>> -	info = domain->host_data;
>> -	return (info->flags & feature_mask) == feature_mask;
>> +
>> +	if (!irq_domain_is_msi_parent(domain)) {
>> +		/*
>> +		 * For "global" PCI/MSI interrupt domains the associated
>> +		 * msi_domain_info::flags is the authoritive source of
>> +		 * information.
>> +		 */
>> +		info = domain->host_data;
>> +		supported = info->flags;
>> +	} else {
>> +		/*
>> +		 * For MSI parent domains the supported feature set
>> +		 * is avaliable in the parent ops. This makes checks
>> +		 * possible before actually instantiating the
>> +		 * per device domain because the parent is never
>> +		 * expanding the PCI/MSI functionality.
>> +		 */
>> +		supported = domain->msi_parent_ops->supported_flags;
>
> This is general PCI MSI logic. So an open related to my rely to patch02,
> is it correct for PCI core to assume that the real parent imposes all the
> restrictions and there is no need to further go down the hierarchy?

That was my working assumption and it turned out to be correct with both
x86 and ARM.

Thanks,

        tglx

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 19/33] genirq/msi: Provide msi_desc::msi_data
  2022-11-23  8:27   ` Tian, Kevin
@ 2022-11-23 11:41     ` Thomas Gleixner
  0 siblings, 0 replies; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-23 11:41 UTC (permalink / raw)
  To: Tian, Kevin, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

On Wed, Nov 23 2022 at 08:27, Kevin Tian wrote:

>> From: Thomas Gleixner <tglx@linutronix.de>
>> Sent: Monday, November 21, 2022 10:38 PM
>> 
>> The upcoming support for PCI/IMS requires to store some information
>> related
>> to the message handling in the MSI descriptor, e.g. PASID or a pointer to a
>> queue.
>> 
>> Provide a generic storage struct which maps over the existing PCI specific
>> storage which means the size of struct msi_desc is not getting bigger.
>> 
>> It contains a iomem pointer for device memory based IMS and a union of a
>> u64 and a void pointer which allows the device specific IMS implementations
>> to store the necessary information.
>
> stale comment.
>
>> 
>> The iomem pointer is set up by the domain allocation functions.
>> 
>> The data union msi_dev_cookie is going to be handed in when allocating an
>
> no msi_dev_cookie now.

Ooops.

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 13/33] x86/apic/vector: Provide MSI parent domain
  2022-11-23  8:16   ` Tian, Kevin
@ 2022-11-23 13:42     ` Thomas Gleixner
  2022-11-24  1:10       ` Tian, Kevin
  0 siblings, 1 reply; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-23 13:42 UTC (permalink / raw)
  To: Tian, Kevin, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

On Wed, Nov 23 2022 at 08:16, Kevin Tian wrote:
>> From: Thomas Gleixner <tglx@linutronix.de>
>> Sent: Monday, November 21, 2022 10:38 PM
>> 
>> +bool pci_dev_has_default_msi_parent_domain(struct pci_dev *dev)
>> +{
>> +	struct irq_domain *domain = dev_get_msi_domain(&dev->dev);
>> 
>> -int pci_msi_prepare(struct irq_domain *domain, struct device *dev, int nvec,
>> -		    msi_alloc_info_t *arg)
>> +	if (!domain)
>> +		domain = dev_get_msi_domain(&dev->bus->dev);
>> +	if (!domain)
>> +		return false;
>> +
>> +	return domain == x86_vector_domain;
>
> the function name is about parent domain but there is no check on
> the parent flag. Probably just remove 'parent'?

No. This checks whether the device has the default MSI parent domain,
which _IS_ the vector domain.

I really don't have to check whether the vector domain has the MSI
parent flag set or not. It _IS_ set. If that gets lost later then the
result of the above function is the least of our problems.

>> +/**
>> + * x86_init_dev_msi_info - Domain info setup for MSI domains
>> + * @dev:		The device for which the domain should be created
>> + * @domain:		The (root) domain providing this callback
>
> what is the purpose of '(root)'? it's also used by intermediate domain
> i.e. IR.

It _can_ be used, yes. But the way I implemented IR MSI parents it is
not used by it.

>> +
>> +	/*
>> +	 * Mask out the domain specific MSI feature flags which are not
>> +	 * supported by the real parent.
>> +	 */
>> +	info->flags			&= pops->supported_flags;
>> +	/* Enforce the required flags */
>> +	info->flags			|=
>> X86_VECTOR_MSI_FLAGS_REQUIRED;
>> +
>> +	/* This is always invoked from the top level MSI domain! */
>> +	info->ops->msi_prepare		= x86_msi_prepare;
>> +
>> +	info->chip->irq_ack		= irq_chip_ack_parent;
>> +	info->chip->irq_retrigger	= irq_chip_retrigger_hierarchy;
>> +	info->chip->flags		|= IRQCHIP_SKIP_SET_WAKE |
>> +					   IRQCHIP_AFFINITY_PRE_STARTUP;
>
> Above are executed twice for both IR and vector after next patch comes.
> Could skip it for IR.

How so?

+static const struct msi_parent_ops dmar_msi_parent_ops = {
+	.supported_flags	= X86_VECTOR_MSI_FLAGS_SUPPORTED | MSI_FLAG_MULTI_PCI_MSI,
+	.prefix			= "IR-",
+	.init_dev_msi_info	= msi_parent_init_dev_msi_info,
+};

IR delegates the init to its parent domain, i.e. the vector domain. So
there is no double invocation.

Thanks,

        tglx

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 07/33] genirq/msi: Provide msi_create/free_device_irq_domain()
  2022-11-23 11:38     ` Thomas Gleixner
@ 2022-11-23 21:01       ` Thomas Gleixner
  2022-11-24  1:07       ` Tian, Kevin
  1 sibling, 0 replies; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-23 21:01 UTC (permalink / raw)
  To: Tian, Kevin, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

On Wed, Nov 23 2022 at 12:38, Thomas Gleixner wrote:
> On Wed, Nov 23 2022 at 08:02, Kevin Tian wrote:
>>> +	bundle->info.hwsize = hwsize ? hwsize : MSI_MAX_INDEX;
>>
>> patch04 marks that hwsize being 0 means unknown or unlimited in the
>> header file.
>>
>> but here info.hwsize always gets a value i.e. the meaning of 0 only exists
>> in this function. What about removing the trailing words about 0 in
>> patch04?
>>
>> - + * @hwsize:		The hardware table size (0 if unknown/unlimited)
>> + + * @hwsize:		The hardware table size
>
> Fair enough, though I rather make that:
>
>  * @hwsize:		The hardware table size or the software defined
>                         index limit
>

Actually 0 still needs to be valid to guarantee backward compatibility
for all existing msi_domain_info implementations.

The above is the per device domain creation function, but yes, I can lift
that initialization into the common MSI domain creation code.

Let me stare at this some more.

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 12/33] PCI/MSI: Add support for per device MSI[X] domains
  2022-11-23 11:41     ` Thomas Gleixner
@ 2022-11-23 21:50       ` Thomas Gleixner
  2022-11-24  1:08         ` Tian, Kevin
  0 siblings, 1 reply; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-23 21:50 UTC (permalink / raw)
  To: Tian, Kevin, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe,
	Ahmed S. Darwish

On Wed, Nov 23 2022 at 12:41, Thomas Gleixner wrote:
> On Wed, Nov 23 2022 at 08:08, Kevin Tian wrote:
>>> +bool pci_setup_msi_device_domain(struct pci_dev *pdev)
>>> +{
>>> +	if (WARN_ON_ONCE(pdev->msix_enabled))
>>> +		return false;
>>
>> the check already exists in __pci_enable_msi_range()
>>
>>> +bool pci_setup_msix_device_domain(struct pci_dev *pdev, unsigned int
>>> hwsize)
>>> +{
>>> +	if (WARN_ON_ONCE(pdev->msix_enabled))
>>> +		return false;
>>
>> ditto.
>>
>> btw according to the comment this should check pdev->msi_enabled.
>
> Yeah, those are probably redundant.

I fixed the MSIX check and kept them for paranoia reasons, so changes in
the calling code get caught.

>> This is general PCI MSI logic. So an open related to my rely to patch02,
>> is it correct for PCI core to assume that the real parent imposes all the
>> restrictions and there is no need to further go down the hierarchy?
>
> That was my working assumption and it turned out to be correct with both
> x86 and ARM.

As a follow up, I went through some of the other architectures,
especially the places which have extra limitations and it turns out that
the restriction comes always from the direct parent.

If that ever changes then we need a callback which lets us evaluate the
resulting capabilities through the hierarchy. That's nothing which can
be evaluated directly.

Just look at the x86 hierarchy with IR. IR allows multi PCI-MSI, but the
vector domain does not. Who is right? That's a decision which is made in
the particular hierarchy.

For now it's valid that the direct MSI parent has the proper set
available.

Thanks,

        tglx

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 02/33] genirq/msi: Provide struct msi_parent_ops
  2022-11-23 11:28     ` Thomas Gleixner
@ 2022-11-24  0:53       ` Tian, Kevin
  0 siblings, 0 replies; 72+ messages in thread
From: Tian, Kevin @ 2022-11-24  0:53 UTC (permalink / raw)
  To: Thomas Gleixner, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

> From: Thomas Gleixner <tglx@linutronix.de>
> Sent: Wednesday, November 23, 2022 7:29 PM
> 
> On Wed, Nov 23 2022 at 07:57, Kevin Tian wrote:
> >> From: Thomas Gleixner <tglx@linutronix.de>
> >> + * One solution is to let the root domain handle the initialization that's
> >> + * why there is the @domain and the @msi_parent_domain pointer.
> >
> > This is the part which I don't quite understand (sorry with limited
> knowledge
> > in this area).
> >
> > In concept a hierarchical model has restrictions added up when moving
> > down to lower layers i.e. presumably the root domain decides the minimal
> > supported capabilities. In this case there is no need of a real parent pointer
> > as long as every domain in the stack incrementally adds its restrictions to
> > info->flags.
> >
> > I can see why this is required for x86 given that MULTI_MSI is supported
> > only with IR. and we cannot make vector domain inclusively claiming
> > MULTI_MSI since it's completely broken when the vector domain becomes
> > the parent itself, in absence of IR.
> >
> > Just be curious whether this intermediate-parent-deciding-restrictions
> > is generic instead of x86 specific, e.g. is it possible to have a 4-layers
> > hierarchy where the root parent wants to check both two intermediate
> > parents?
> 
> Sure. Nothing prevents you from doing so:
> 
> dom4:
>     .init... = dom4_init
> 
> dom4_init()
>     do_stuff()
>     invoke parent init
> 
> dom3:
>     .init... = parent_init
> 
> dom2:
>     .init... = dom2_init
> 
> dom2_init()
>     do_stuff()
>     invoke parent init
> 
> ....
> 
> See?
> 

yes. with the hierarchy being arch specific those dependencies
can be easily figured out.

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 07/33] genirq/msi: Provide msi_create/free_device_irq_domain()
  2022-11-23 11:38     ` Thomas Gleixner
  2022-11-23 21:01       ` Thomas Gleixner
@ 2022-11-24  1:07       ` Tian, Kevin
  2022-11-24  8:36         ` Thomas Gleixner
  1 sibling, 1 reply; 72+ messages in thread
From: Tian, Kevin @ 2022-11-24  1:07 UTC (permalink / raw)
  To: Thomas Gleixner, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

> From: Thomas Gleixner <tglx@linutronix.de>
> Sent: Wednesday, November 23, 2022 7:38 PM
> 
> >> + *
> >> + * Return: True on success, false otherwise
> >
> > Can you elaborate why boolean type is selected instead of returning the
> > actual error codes? the outmost callers are all new functions:
> >
> > 	pci_setup_msi[x]_device_domain()
> > 	pci_create_ims_domain()
> >
> > I didn't find out any legacy convention forcing this way...
> 
> What's the value of error codes? 99% of all callsites do:
> 
>        ret = foo();
>        if (ret)
>           goto fail;
> 
> Nothing evaluates the error codes, unless there is real useful
> information like EAGAIN or ENOSPC which can tell the caller to retry
> eventually or with different parameters. But for the above, the error
> code is just useless.
> 

I looked at it from the outmost invocation:

@@ -436,6 +436,9 @@ int __pci_enable_msi_range(struct pci_de
 	if (rc)
 		return rc;
 
+	if (!pci_setup_msi_device_domain(dev))
+		return -ENODEV;
+

the current style kind of converts meaningful -EINVAL/-ENOMEM/etc.
into -ENODEV.

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 12/33] PCI/MSI: Add support for per device MSI[X] domains
  2022-11-23 21:50       ` Thomas Gleixner
@ 2022-11-24  1:08         ` Tian, Kevin
  0 siblings, 0 replies; 72+ messages in thread
From: Tian, Kevin @ 2022-11-24  1:08 UTC (permalink / raw)
  To: Thomas Gleixner, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe,
	Ahmed S. Darwish

> From: Thomas Gleixner <tglx@linutronix.de>
> Sent: Thursday, November 24, 2022 5:50 AM
> 
> >> This is general PCI MSI logic. So an open related to my rely to patch02,
> >> is it correct for PCI core to assume that the real parent imposes all the
> >> restrictions and there is no need to further go down the hierarchy?
> >
> > That was my working assumption and it turned out to be correct with both
> > x86 and ARM.
> 
> As a follow up, I went through some of the other architectures,
> especially the places which have extra limitations and it turns out that
> the restriction comes always from the direct parent.
> 
> If that ever changes then we need a callback which lets us evaluate the
> resulting capabilities through the hierarchy. That's nothing which can
> be evaluated directly.
> 
> Just look at the x86 hierarchy with IR. IR allows multi PCI-MSI, but the
> vector domain does not. Who is right? That's a decision which is made in
> the particular hierarchy.

make sense.

> 
> For now it's valid that the direct MSI parent has the proper set
> available.
> 

probably above can be marked out in the comment.

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 13/33] x86/apic/vector: Provide MSI parent domain
  2022-11-23 13:42     ` Thomas Gleixner
@ 2022-11-24  1:10       ` Tian, Kevin
  0 siblings, 0 replies; 72+ messages in thread
From: Tian, Kevin @ 2022-11-24  1:10 UTC (permalink / raw)
  To: Thomas Gleixner, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

> From: Thomas Gleixner <tglx@linutronix.de>
> Sent: Wednesday, November 23, 2022 9:42 PM
> 
> On Wed, Nov 23 2022 at 08:16, Kevin Tian wrote:
> >> From: Thomas Gleixner <tglx@linutronix.de>
> >> Sent: Monday, November 21, 2022 10:38 PM
> >> +
> >> +	/*
> >> +	 * Mask out the domain specific MSI feature flags which are not
> >> +	 * supported by the real parent.
> >> +	 */
> >> +	info->flags			&= pops->supported_flags;
> >> +	/* Enforce the required flags */
> >> +	info->flags			|=
> >> X86_VECTOR_MSI_FLAGS_REQUIRED;
> >> +
> >> +	/* This is always invoked from the top level MSI domain! */
> >> +	info->ops->msi_prepare		= x86_msi_prepare;
> >> +
> >> +	info->chip->irq_ack		= irq_chip_ack_parent;
> >> +	info->chip->irq_retrigger	= irq_chip_retrigger_hierarchy;
> >> +	info->chip->flags		|= IRQCHIP_SKIP_SET_WAKE |
> >> +					   IRQCHIP_AFFINITY_PRE_STARTUP;
> >
> > Above are executed twice for both IR and vector after next patch comes.
> > Could skip it for IR.
> 
> How so?
> 
> +static const struct msi_parent_ops dmar_msi_parent_ops = {
> +	.supported_flags	= X86_VECTOR_MSI_FLAGS_SUPPORTED |
> MSI_FLAG_MULTI_PCI_MSI,
> +	.prefix			= "IR-",
> +	.init_dev_msi_info	= msi_parent_init_dev_msi_info,
> +};
> 
> IR delegates the init to its parent domain, i.e. the vector domain. So
> there is no double invocation.
> 

oops. How come I read msi_parent_init_dev_msi_info() as
x86_init_dev_msi_info(). 😊

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 21/33] genirq/msi: Provide msi_domain_alloc_irq_at()
  2022-11-21 14:38 ` [patch V2 21/33] genirq/msi: Provide msi_domain_alloc_irq_at() Thomas Gleixner
@ 2022-11-24  2:54   ` Tian, Kevin
  0 siblings, 0 replies; 72+ messages in thread
From: Tian, Kevin @ 2022-11-24  2:54 UTC (permalink / raw)
  To: Thomas Gleixner, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

> From: Thomas Gleixner <tglx@linutronix.de>
> Sent: Monday, November 21, 2022 10:38 PM
> 
> For supporting post MSI-X enable allocations and for the upcoming PCI/IMS
> support a seperate interface is required which allows not only the

s/seperate/separate/

> 
> The function also takes an optional @cookie argument which is of type union
> msi_dev_cookie. This cookie is not used by the core code and is stored in

no msi_dev_cookie.

> 
> +/*
> + * Constant to be used for dynamic allocations when the allocation
> + * is any free MSI index (entry in the MSI-X table or a software
> + * managed index.

miss a parenthesis in the end.

> + *
> + * This requires a MSI interrupt domain which lets the core code manage
> the
> + * MSI descriptors.
> + *
> + * Return: struct msi_map
> + *
> + *	On success msi_map::index contains the allocated index number and
> + *	msi_map::virq the corresponding Linux interrupt number

msi_map::virq 'contains' the...


^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 25/33] PCI/MSI: Provide post-enable dynamic allocation interfaces for MSI-X
  2022-11-21 14:38 ` [patch V2 25/33] PCI/MSI: Provide post-enable dynamic allocation interfaces for MSI-X Thomas Gleixner
@ 2022-11-24  2:58   ` Tian, Kevin
  2022-11-24  9:08     ` Thomas Gleixner
  0 siblings, 1 reply; 72+ messages in thread
From: Tian, Kevin @ 2022-11-24  2:58 UTC (permalink / raw)
  To: Thomas Gleixner, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

> From: Thomas Gleixner <tglx@linutronix.de>
> Sent: Monday, November 21, 2022 10:38 PM
> 
> +/**
> + * pci_msix_alloc_irq_at - Allocate an MSI-X interrupt after enabling MSI-X
> + *			   at a given MSI-X vector index or any free vector
> index
> + *
> + * @dev:	PCI device to operate on
> + * @index:	Index to allocate. If @index == MSI_ANY_INDEX this allocates
> + *		the next free index in the MSI-X table

%MSI_ANY_INDEX as done in other places.

> +
> +/**
> + * pci_msix_free_irq - Free an interrupt on a PCI/MSIX interrupt domain
> + *		      which was allocated via pci_msix_alloc_irq_at()
> + *
> + * @dev:	The PCI device to operate on
> + * @map:	A struct msi_map describing the interrupt to free
> + *		as returned from the allocation function.
> + */

Can this be used on preallocated descriptors? If not any guard required
or just treat it as a driver responsibility to not misuse?

> +void pci_msix_free_irq(struct pci_dev *dev, struct msi_map map)
> +{
> +	if (WARN_ON_ONCE(map.index < 0 || map.virq <= 0))

map.virq cannot be negative.

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 27/33] genirq/msi: Provide constants for PCI/IMS support
  2022-11-21 14:38 ` [patch V2 27/33] genirq/msi: Provide constants for PCI/IMS support Thomas Gleixner
@ 2022-11-24  3:01   ` Tian, Kevin
  2022-11-24  9:10     ` Thomas Gleixner
  0 siblings, 1 reply; 72+ messages in thread
From: Tian, Kevin @ 2022-11-24  3:01 UTC (permalink / raw)
  To: Thomas Gleixner, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

> From: Thomas Gleixner <tglx@linutronix.de>
> Sent: Monday, November 21, 2022 10:38 PM
>  /**
> --- a/include/linux/msi_api.h
> +++ b/include/linux/msi_api.h
> @@ -15,6 +15,7 @@ struct device;
>   */
>  enum msi_domain_ids {
>  	MSI_DEFAULT_DOMAIN,
> +	MSI_SECONDARY_DOMAIN,
>  	MSI_MAX_DEVICE_IRQDOMAINS,

SECONDARY or be explicit IMS? Are we envisioning non-IMS usages to
occupy this slot in the future?

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 28/33] PCI/MSI: Provide IMS (Interrupt Message Store) support
  2022-11-21 14:38 ` [patch V2 28/33] PCI/MSI: Provide IMS (Interrupt Message Store) support Thomas Gleixner
@ 2022-11-24  3:10   ` Tian, Kevin
  2022-11-24  9:10     ` Thomas Gleixner
  0 siblings, 1 reply; 72+ messages in thread
From: Tian, Kevin @ 2022-11-24  3:10 UTC (permalink / raw)
  To: Thomas Gleixner, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

> From: Thomas Gleixner <tglx@linutronix.de>
> Sent: Monday, November 21, 2022 10:38 PM
> 
> The IMS domains have a few constraints:
> 
>   - The index space is managed by the core code.
> 
>     Device memory based IMS provides a storage array with a fixed size
>     which obviously requires an index. But there is no association between
>     index and functionality so the core can randomly allocate an index in
>     the array.
> 
>     Queue memory based IMS does not have the concept of an index as the
>     storage is somewhere in memory. In that case the index is purely
>     software based to keep track of the allocations.

'Queue' could be a HW queue or SW queue. Is it clearer to just use
'system memory based IMS" here?

and for a GPU it is probably just a gfx context to store IMS content, w/o
a queue concept.

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 29/33] PCI/MSI: Provide pci_ims_alloc/free_irq()
  2022-11-21 14:38 ` [patch V2 29/33] PCI/MSI: Provide pci_ims_alloc/free_irq() Thomas Gleixner
@ 2022-11-24  3:11   ` Tian, Kevin
  0 siblings, 0 replies; 72+ messages in thread
From: Tian, Kevin @ 2022-11-24  3:11 UTC (permalink / raw)
  To: Thomas Gleixner, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

> From: Thomas Gleixner <tglx@linutronix.de>
> Sent: Monday, November 21, 2022 10:38 PM
> 
> + * There is no index for IMS allocations as IMS is an implementation
> + * specific storage and does not have any direct associations between
> + * index, which might be a pure software construct, and device
> + * functionality. This association is established by the driver either via
> + * the index - if there is a hardware table - or in case of purely software
> + * managed IMS implementation the association happens via the
> + * irq_write_msi_msg() callback of the implementation specific interrupt
> + * chip, which utilizes the provided @cookie to store the MSI message in

@icookie


^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 31/33] iommu/vt-d: Enable PCI/IMS
  2022-11-21 14:38 ` [patch V2 31/33] iommu/vt-d: " Thomas Gleixner
@ 2022-11-24  3:17   ` Tian, Kevin
  2022-11-24  9:37     ` Thomas Gleixner
  0 siblings, 1 reply; 72+ messages in thread
From: Tian, Kevin @ 2022-11-24  3:17 UTC (permalink / raw)
  To: Thomas Gleixner, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

> From: Thomas Gleixner <tglx@linutronix.de>
> Sent: Monday, November 21, 2022 10:38 PM
> 
> PCI/IMS works like PCI/MSI-X in the remapping. Just add the feature flag.
> 
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> ---
>  drivers/iommu/intel/irq_remapping.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> --- a/drivers/iommu/intel/irq_remapping.c
> +++ b/drivers/iommu/intel/irq_remapping.c
> @@ -1429,7 +1429,9 @@ static const struct irq_domain_ops intel
>  };
> 
>  static const struct msi_parent_ops dmar_msi_parent_ops = {
> -	.supported_flags	= X86_VECTOR_MSI_FLAGS_SUPPORTED |
> MSI_FLAG_MULTI_PCI_MSI,
> +	.supported_flags	= X86_VECTOR_MSI_FLAGS_SUPPORTED |
> +				  MSI_FLAG_MULTI_PCI_MSI |
> +				  MSI_FLAG_PCI_IMS,
>  	.prefix			= "IR-",
>  	.init_dev_msi_info	= msi_parent_init_dev_msi_info,
>  };

vIR is already available on vIOMMU today [1].

Fortunately both intel/amd IOMMU has a way to detect whether it's a vIOMMU.

For intel it's cap_caching_mode().

For AMD it's amd_iommu_np_cache.

Then MSI_FLAG_PCI_IMS should be set only on physical IOMMU.

In the future once we have hypercall then it can be set on vIOMMU too.

[1] https://lore.kernel.org/all/BL1PR11MB5271326D39DAB692F07587768C739@BL1PR11MB5271.namprd11.prod.outlook.com/



^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 33/33] irqchip: Add IDXD Interrupt Message Store driver
  2022-11-21 14:38 ` [patch V2 33/33] irqchip: Add IDXD Interrupt Message Store driver Thomas Gleixner
@ 2022-11-24  3:19   ` Tian, Kevin
  0 siblings, 0 replies; 72+ messages in thread
From: Tian, Kevin @ 2022-11-24  3:19 UTC (permalink / raw)
  To: Thomas Gleixner, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

> From: Thomas Gleixner <tglx@linutronix.de>
> Sent: Monday, November 21, 2022 10:38 PM
> 
> +config PCI_INTEL_IDXD_IMS
> +	tristate "Intel IDXD Interrupt Message Store controller"
> +	depends on PCI_MSI
> +	help
> +	  Support for Intel IDXD IMS Interrupt Message Store controller

IMS is an abbreviation so it's better be:

"Support for Intel IDXD Interrupt Message Store (IMS) controller..."

> +/**
> + * pci_intel_idxd_create_ims_domain - Create a IDXD IMS domain
> + * @pdev:	IDXD PCI device to operate on
> + * @slots:	Pointer to the mapped slot memory arrray

s/arrray/array/


^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 07/33] genirq/msi: Provide msi_create/free_device_irq_domain()
  2022-11-24  1:07       ` Tian, Kevin
@ 2022-11-24  8:36         ` Thomas Gleixner
  2022-11-28  1:47           ` Tian, Kevin
  0 siblings, 1 reply; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-24  8:36 UTC (permalink / raw)
  To: Tian, Kevin, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

On Thu, Nov 24 2022 at 01:07, Kevin Tian wrote:
>> From: Thomas Gleixner <tglx@linutronix.de>
> I looked at it from the outmost invocation:
>
> @@ -436,6 +436,9 @@ int __pci_enable_msi_range(struct pci_de
>  	if (rc)
>  		return rc;
>  
> +	if (!pci_setup_msi_device_domain(dev))
> +		return -ENODEV;
> +
>
> the current style kind of converts meaningful -EINVAL/-ENOMEM/etc.
> into -ENODEV.

But go to the call sites of the various places in drivers which set up
MSI or MSI-X and check whether anything evaluates those error codes in a
meaningful way.

Some of them print the error code, but that does not help much because
the error code does not allow you to pin point the place which returns
that. If you just analyze the pci_alloc_irq_vectors_affinity() call then
you find at least 10 places, which can return -ENOMEM. So how is that
meaningful and helpful?

All it tells you is that some memory allocation failed. In that case the
failure of the PCI/MSI[-X] setup is the least of the problems.

Where error codes are mandatory are user space interfaces, but in the
kernel a simple fail/success like we have with many interfaces which
just return a NULL pointer on fail is sufficient.

Just because the kernel historically propagated error codes all over the
place does not make them useful or meaningful.

Thanks,

        tglx



^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 25/33] PCI/MSI: Provide post-enable dynamic allocation interfaces for MSI-X
  2022-11-24  2:58   ` Tian, Kevin
@ 2022-11-24  9:08     ` Thomas Gleixner
  2022-11-28  1:49       ` Tian, Kevin
  2023-02-21  7:32       ` [tip: irq/urgent] PCI/MSI: Clarify usage of pci_msix_free_irq() tip-bot2 for Reinette Chatre
  0 siblings, 2 replies; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-24  9:08 UTC (permalink / raw)
  To: Tian, Kevin, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

On Thu, Nov 24 2022 at 02:58, Kevin Tian wrote:
>> +
>> +/**
>> + * pci_msix_free_irq - Free an interrupt on a PCI/MSIX interrupt domain
>> + *		      which was allocated via pci_msix_alloc_irq_at()
>> + *
>> + * @dev:	The PCI device to operate on
>> + * @map:	A struct msi_map describing the interrupt to free
>> + *		as returned from the allocation function.
>> + */
>
> Can this be used on preallocated descriptors? If not any guard required
> or just treat it as a driver responsibility to not misuse?

The preallocated descriptors are only relevant during setup, but not
post setup. So yes, you can do:

pci_alloc_irq_vectors(dev, 10, 10, PCI_IRQ_MSIX);

and then

    map = { .index = 9, .virq = $IRQ };
    pci_msix_free_irq(dev, &map);

It just works.

>> +void pci_msix_free_irq(struct pci_dev *dev, struct msi_map map)
>> +{
>> +	if (WARN_ON_ONCE(map.index < 0 || map.virq <= 0))
>
> map.virq cannot be negative.

Why? Callers can make up whatever they want, no?

Thanks,

        tglx

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 27/33] genirq/msi: Provide constants for PCI/IMS support
  2022-11-24  3:01   ` Tian, Kevin
@ 2022-11-24  9:10     ` Thomas Gleixner
  2022-11-24 13:09       ` Jason Gunthorpe
  0 siblings, 1 reply; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-24  9:10 UTC (permalink / raw)
  To: Tian, Kevin, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

On Thu, Nov 24 2022 at 03:01, Kevin Tian wrote:
>> From: Thomas Gleixner <tglx@linutronix.de>
>> @@ -15,6 +15,7 @@ struct device;
>>   */
>>  enum msi_domain_ids {
>>  	MSI_DEFAULT_DOMAIN,
>> +	MSI_SECONDARY_DOMAIN,
>>  	MSI_MAX_DEVICE_IRQDOMAINS,
>
> SECONDARY or be explicit IMS? Are we envisioning non-IMS usages to
> occupy this slot in the future?

I'm not really decided on that. Whatever the name or use-case for a
secondary domain is. Not, that this is not restricted to PCI.

Thanks,

        tglx

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 28/33] PCI/MSI: Provide IMS (Interrupt Message Store) support
  2022-11-24  3:10   ` Tian, Kevin
@ 2022-11-24  9:10     ` Thomas Gleixner
  0 siblings, 0 replies; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-24  9:10 UTC (permalink / raw)
  To: Tian, Kevin, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

On Thu, Nov 24 2022 at 03:10, Kevin Tian wrote:

>> From: Thomas Gleixner <tglx@linutronix.de>
>> Sent: Monday, November 21, 2022 10:38 PM
>> 
>> The IMS domains have a few constraints:
>> 
>>   - The index space is managed by the core code.
>> 
>>     Device memory based IMS provides a storage array with a fixed size
>>     which obviously requires an index. But there is no association between
>>     index and functionality so the core can randomly allocate an index in
>>     the array.
>> 
>>     Queue memory based IMS does not have the concept of an index as the
>>     storage is somewhere in memory. In that case the index is purely
>>     software based to keep track of the allocations.
>
> 'Queue' could be a HW queue or SW queue. Is it clearer to just use
> 'system memory based IMS" here?

Yes

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 31/33] iommu/vt-d: Enable PCI/IMS
  2022-11-24  3:17   ` Tian, Kevin
@ 2022-11-24  9:37     ` Thomas Gleixner
  2022-11-24 13:14       ` Jason Gunthorpe
  0 siblings, 1 reply; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-24  9:37 UTC (permalink / raw)
  To: Tian, Kevin, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

On Thu, Nov 24 2022 at 03:17, Kevin Tian wrote:
>>  static const struct msi_parent_ops dmar_msi_parent_ops = {
>> -	.supported_flags	= X86_VECTOR_MSI_FLAGS_SUPPORTED |
>> MSI_FLAG_MULTI_PCI_MSI,
>> +	.supported_flags	= X86_VECTOR_MSI_FLAGS_SUPPORTED |
>> +				  MSI_FLAG_MULTI_PCI_MSI |
>> +				  MSI_FLAG_PCI_IMS,
>>  	.prefix			= "IR-",
>>  	.init_dev_msi_info	= msi_parent_init_dev_msi_info,
>>  };
>
> vIR is already available on vIOMMU today [1].
>
> Fortunately both intel/amd IOMMU has a way to detect whether it's a vIOMMU.
>
> For intel it's cap_caching_mode().
>
> For AMD it's amd_iommu_np_cache.
>
> Then MSI_FLAG_PCI_IMS should be set only on physical IOMMU.

Ok. Let me fix that then.

But that made me read back some more.

Jason said, that the envisioned Mellanox use case does not depend on the
IOMMU because the card itself has one which takes care of the
protections.

How are we going to resolve that dilemma?

Thanks,

        tglx

^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [patch V2 27/33] genirq/msi: Provide constants for PCI/IMS support
  2022-11-24  9:10     ` Thomas Gleixner
@ 2022-11-24 13:09       ` Jason Gunthorpe
  2022-11-24 13:28         ` Thomas Gleixner
  0 siblings, 1 reply; 72+ messages in thread
From: Jason Gunthorpe @ 2022-11-24 13:09 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Tian, Kevin, LKML, x86, Joerg Roedel, Will Deacon, linux-pci,
	Bjorn Helgaas, Lorenzo Pieralisi, Marc Zyngier,
	Greg Kroah-Hartman, Jiang, Dave, Alex Williamson, Williams,
	Dan J, Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

On Thu, Nov 24, 2022 at 10:10:05AM +0100, Thomas Gleixner wrote:
> On Thu, Nov 24 2022 at 03:01, Kevin Tian wrote:
> >> From: Thomas Gleixner <tglx@linutronix.de>
> >> @@ -15,6 +15,7 @@ struct device;
> >>   */
> >>  enum msi_domain_ids {
> >>  	MSI_DEFAULT_DOMAIN,
> >> +	MSI_SECONDARY_DOMAIN,
> >>  	MSI_MAX_DEVICE_IRQDOMAINS,
> >
> > SECONDARY or be explicit IMS? Are we envisioning non-IMS usages to
> > occupy this slot in the future?
> 
> I'm not really decided on that. Whatever the name or use-case for a
> secondary domain is. Not, that this is not restricted to PCI.

This is hierarchical right? So if a pci_device spawns an
auxiliary_device, its driver could stick a msi domain on the
MSI_DEFAULT_DOMAIN of the aux device as a child of the PCI device's
domain?

I don't know if we need per "ADI" msi domains, but it seems OK to me
to hav have two slots for now and be general about what can go in
those slots

Jason

^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [patch V2 31/33] iommu/vt-d: Enable PCI/IMS
  2022-11-24  9:37     ` Thomas Gleixner
@ 2022-11-24 13:14       ` Jason Gunthorpe
  2022-11-24 13:21         ` Thomas Gleixner
  0 siblings, 1 reply; 72+ messages in thread
From: Jason Gunthorpe @ 2022-11-24 13:14 UTC (permalink / raw)
  To: Thomas Gleixner
  Cc: Tian, Kevin, LKML, x86, Joerg Roedel, Will Deacon, linux-pci,
	Bjorn Helgaas, Lorenzo Pieralisi, Marc Zyngier,
	Greg Kroah-Hartman, Jiang, Dave, Alex Williamson, Williams,
	Dan J, Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

On Thu, Nov 24, 2022 at 10:37:53AM +0100, Thomas Gleixner wrote:
> On Thu, Nov 24 2022 at 03:17, Kevin Tian wrote:
> >>  static const struct msi_parent_ops dmar_msi_parent_ops = {
> >> -	.supported_flags	= X86_VECTOR_MSI_FLAGS_SUPPORTED |
> >> MSI_FLAG_MULTI_PCI_MSI,
> >> +	.supported_flags	= X86_VECTOR_MSI_FLAGS_SUPPORTED |
> >> +				  MSI_FLAG_MULTI_PCI_MSI |
> >> +				  MSI_FLAG_PCI_IMS,
> >>  	.prefix			= "IR-",
> >>  	.init_dev_msi_info	= msi_parent_init_dev_msi_info,
> >>  };
> >
> > vIR is already available on vIOMMU today [1].
> >
> > Fortunately both intel/amd IOMMU has a way to detect whether it's a vIOMMU.
> >
> > For intel it's cap_caching_mode().
> >
> > For AMD it's amd_iommu_np_cache.
> >
> > Then MSI_FLAG_PCI_IMS should be set only on physical IOMMU.
> 
> Ok. Let me fix that then.
> 
> But that made me read back some more.
> 
> Jason said, that the envisioned Mellanox use case does not depend on the
> IOMMU because the card itself has one which takes care of the
> protections.

Right, but that doesn't mean we need the physical iommu turned
off. Setting the mlx pci device to identity mode is usually enough to
get back to full performance.

> How are we going to resolve that dilemma?

The outcome is we don't have a strategy right now to make IMS work in
VMs. This series is all about making it work on physical machines,
that has to be a good first step.

I'm hoping the OCP work stream on SIOV will tackle how to fix the
interrupt problems. Some of the ideas I've seen could be formed into
something that would work in a VM.

Jason

^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [patch V2 31/33] iommu/vt-d: Enable PCI/IMS
  2022-11-24 13:14       ` Jason Gunthorpe
@ 2022-11-24 13:21         ` Thomas Gleixner
  2022-11-28  1:54           ` Tian, Kevin
  0 siblings, 1 reply; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-24 13:21 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Tian, Kevin, LKML, x86, Joerg Roedel, Will Deacon, linux-pci,
	Bjorn Helgaas, Lorenzo Pieralisi, Marc Zyngier,
	Greg Kroah-Hartman, Jiang, Dave, Alex Williamson, Williams,
	Dan J, Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

On Thu, Nov 24 2022 at 09:14, Jason Gunthorpe wrote:
> On Thu, Nov 24, 2022 at 10:37:53AM +0100, Thomas Gleixner wrote:
>> Jason said, that the envisioned Mellanox use case does not depend on the
>> IOMMU because the card itself has one which takes care of the
>> protections.
>
> Right, but that doesn't mean we need the physical iommu turned
> off. Setting the mlx pci device to identity mode is usually enough to
> get back to full performance.

Ok.

>> How are we going to resolve that dilemma?
>
> The outcome is we don't have a strategy right now to make IMS work in
> VMs. This series is all about making it work on physical machines,
> that has to be a good first step.
>
> I'm hoping the OCP work stream on SIOV will tackle how to fix the
> interrupt problems. Some of the ideas I've seen could be formed into
> something that would work in a VM.

Fair enough.

Let me put the limitation into effect then.

Thanks,

        tglx

^ permalink raw reply	[flat|nested] 72+ messages in thread

* Re: [patch V2 27/33] genirq/msi: Provide constants for PCI/IMS support
  2022-11-24 13:09       ` Jason Gunthorpe
@ 2022-11-24 13:28         ` Thomas Gleixner
  0 siblings, 0 replies; 72+ messages in thread
From: Thomas Gleixner @ 2022-11-24 13:28 UTC (permalink / raw)
  To: Jason Gunthorpe
  Cc: Tian, Kevin, LKML, x86, Joerg Roedel, Will Deacon, linux-pci,
	Bjorn Helgaas, Lorenzo Pieralisi, Marc Zyngier,
	Greg Kroah-Hartman, Jiang, Dave, Alex Williamson, Williams,
	Dan J, Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

On Thu, Nov 24 2022 at 09:09, Jason Gunthorpe wrote:
> On Thu, Nov 24, 2022 at 10:10:05AM +0100, Thomas Gleixner wrote:
>> On Thu, Nov 24 2022 at 03:01, Kevin Tian wrote:
>> > SECONDARY or be explicit IMS? Are we envisioning non-IMS usages to
>> > occupy this slot in the future?
>> 
>> I'm not really decided on that. Whatever the name or use-case for a
>> secondary domain is. Not, that this is not restricted to PCI.
>
> This is hierarchical right? So if a pci_device spawns an
> auxiliary_device, its driver could stick a msi domain on the
> MSI_DEFAULT_DOMAIN of the aux device as a child of the PCI device's
> domain?

A child of the PCI devices parent domain. The per device domains are
endpoint domains. They cannot serve as parent domains themself right
now.

If there is a real reason and use case which requires that, it can be
made work with trivial tweaks.

Thanks,

        tglx

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 07/33] genirq/msi: Provide msi_create/free_device_irq_domain()
  2022-11-24  8:36         ` Thomas Gleixner
@ 2022-11-28  1:47           ` Tian, Kevin
  0 siblings, 0 replies; 72+ messages in thread
From: Tian, Kevin @ 2022-11-28  1:47 UTC (permalink / raw)
  To: Thomas Gleixner, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

> From: Thomas Gleixner <tglx@linutronix.de>
> Sent: Thursday, November 24, 2022 4:36 PM
> 
> On Thu, Nov 24 2022 at 01:07, Kevin Tian wrote:
> >> From: Thomas Gleixner <tglx@linutronix.de>
> > I looked at it from the outmost invocation:
> >
> > @@ -436,6 +436,9 @@ int __pci_enable_msi_range(struct pci_de
> >  	if (rc)
> >  		return rc;
> >
> > +	if (!pci_setup_msi_device_domain(dev))
> > +		return -ENODEV;
> > +
> >
> > the current style kind of converts meaningful -EINVAL/-ENOMEM/etc.
> > into -ENODEV.
> 
> But go to the call sites of the various places in drivers which set up
> MSI or MSI-X and check whether anything evaluates those error codes in a
> meaningful way.
> 
> Some of them print the error code, but that does not help much because
> the error code does not allow you to pin point the place which returns
> that. If you just analyze the pci_alloc_irq_vectors_affinity() call then
> you find at least 10 places, which can return -ENOMEM. So how is that
> meaningful and helpful?
> 
> All it tells you is that some memory allocation failed. In that case the
> failure of the PCI/MSI[-X] setup is the least of the problems.
> 
> Where error codes are mandatory are user space interfaces, but in the
> kernel a simple fail/success like we have with many interfaces which
> just return a NULL pointer on fail is sufficient.
> 
> Just because the kernel historically propagated error codes all over the
> place does not make them useful or meaningful.
> 

Good learning. Thanks.

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 25/33] PCI/MSI: Provide post-enable dynamic allocation interfaces for MSI-X
  2022-11-24  9:08     ` Thomas Gleixner
@ 2022-11-28  1:49       ` Tian, Kevin
  2023-02-21  7:32       ` [tip: irq/urgent] PCI/MSI: Clarify usage of pci_msix_free_irq() tip-bot2 for Reinette Chatre
  1 sibling, 0 replies; 72+ messages in thread
From: Tian, Kevin @ 2022-11-28  1:49 UTC (permalink / raw)
  To: Thomas Gleixner, LKML
  Cc: x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman,
	Jason Gunthorpe, Jiang, Dave, Alex Williamson, Williams, Dan J,
	Logan Gunthorpe, Raj, Ashok, Jon Mason, Allen Hubbe

> From: Thomas Gleixner <tglx@linutronix.de>
> Sent: Thursday, November 24, 2022 5:09 PM
> >> +void pci_msix_free_irq(struct pci_dev *dev, struct msi_map map)
> >> +{
> >> +	if (WARN_ON_ONCE(map.index < 0 || map.virq <= 0))
> >
> > map.virq cannot be negative.
> 
> Why? Callers can make up whatever they want, no?
> 

obviously callers can. Read too fast...

Then following check should be fixed too:

+void pci_ims_free_irq(struct pci_dev *dev, struct msi_map map)
+{
+	if (WARN_ON_ONCE(map.index < 0 || !map.virq))
+		return;
+	msi_domain_free_irqs_range(&dev->dev, MSI_SECONDARY_DOMAIN, map.index, map.index);
+}

^ permalink raw reply	[flat|nested] 72+ messages in thread

* RE: [patch V2 31/33] iommu/vt-d: Enable PCI/IMS
  2022-11-24 13:21         ` Thomas Gleixner
@ 2022-11-28  1:54           ` Tian, Kevin
  0 siblings, 0 replies; 72+ messages in thread
From: Tian, Kevin @ 2022-11-28  1:54 UTC (permalink / raw)
  To: Thomas Gleixner, Jason Gunthorpe
  Cc: LKML, x86, Joerg Roedel, Will Deacon, linux-pci, Bjorn Helgaas,
	Lorenzo Pieralisi, Marc Zyngier, Greg Kroah-Hartman, Jiang, Dave,
	Alex Williamson, Williams, Dan J, Logan Gunthorpe, Raj, Ashok,
	Jon Mason, Allen Hubbe

> From: Thomas Gleixner <tglx@linutronix.de>
> Sent: Thursday, November 24, 2022 9:21 PM
> 
> On Thu, Nov 24 2022 at 09:14, Jason Gunthorpe wrote:
> > On Thu, Nov 24, 2022 at 10:37:53AM +0100, Thomas Gleixner wrote:
> >> Jason said, that the envisioned Mellanox use case does not depend on the
> >> IOMMU because the card itself has one which takes care of the
> >> protections.
> >
> > Right, but that doesn't mean we need the physical iommu turned
> > off. Setting the mlx pci device to identity mode is usually enough to
> > get back to full performance.
> 
> Ok.

yes. IR can be enabled orthogonal to DMA mapping mode in IOMMU.

> 
> >> How are we going to resolve that dilemma?
> >
> > The outcome is we don't have a strategy right now to make IMS work in
> > VMs. This series is all about making it work on physical machines,
> > that has to be a good first step.

yes, that is the point. As long as IMS is disabled in the guest it's already
a good first step for the moment.

> >
> > I'm hoping the OCP work stream on SIOV will tackle how to fix the
> > interrupt problems. Some of the ideas I've seen could be formed into
> > something that would work in a VM.
> 
> Fair enough.
> 
> Let me put the limitation into effect then.
> 
> Thanks,
> 
>         tglx

^ permalink raw reply	[flat|nested] 72+ messages in thread

* [tip: irq/urgent] PCI/MSI: Clarify usage of pci_msix_free_irq()
  2022-11-24  9:08     ` Thomas Gleixner
  2022-11-28  1:49       ` Tian, Kevin
@ 2023-02-21  7:32       ` tip-bot2 for Reinette Chatre
  1 sibling, 0 replies; 72+ messages in thread
From: tip-bot2 for Reinette Chatre @ 2023-02-21  7:32 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Reinette Chatre, Thomas Gleixner, Kevin Tian, x86, linux-kernel, maz

The following commit has been merged into the irq/urgent branch of tip:

Commit-ID:     e6cc6f175566dd21a3f6e384c24593b1c751dd74
Gitweb:        https://git.kernel.org/tip/e6cc6f175566dd21a3f6e384c24593b1c751dd74
Author:        Reinette Chatre <reinette.chatre@intel.com>
AuthorDate:    Tue, 14 Feb 2023 13:13:20 -08:00
Committer:     Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Tue, 21 Feb 2023 08:25:14 +01:00

PCI/MSI: Clarify usage of pci_msix_free_irq()

pci_msix_free_irq() is used to free an interrupt on a PCI/MSI-X interrupt
domain.

The API description specifies that the interrupt to be freed was allocated
via pci_msix_alloc_irq_at().  This description limits the usage of
pci_msix_free_irq() since pci_msix_free_irq() can also be used to free
MSI-X interrupts allocated with, for example, pci_alloc_irq_vectors().

Remove the text stating that the interrupt to be freed had to be allocated
with pci_msix_alloc_irq_at(). The needed struct msi_map need not be from
pci_msix_alloc_irq_at() but can be created from scratch using
pci_irq_vector() to obtain the Linux IRQ number. Highlight that
pci_msix_free_irq() cannot be used to disable MSI-X to guide users that,
for example, pci_free_irq_vectors() remains to be needed.

Signed-off-by: Reinette Chatre <reinette.chatre@intel.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Link: https://lore.kernel.org/lkml/87r0xsd8j4.ffs@tglx
Link: https://lore.kernel.org/r/4c3e7a50d6e70f408812cd7ab199c6b4b326f9de.1676408572.git.reinette.chatre@intel.com
---
 drivers/pci/msi/api.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/msi/api.c b/drivers/pci/msi/api.c
index b8009aa..be679aa 100644
--- a/drivers/pci/msi/api.c
+++ b/drivers/pci/msi/api.c
@@ -163,11 +163,11 @@ EXPORT_SYMBOL_GPL(pci_msix_alloc_irq_at);
 
 /**
  * pci_msix_free_irq - Free an interrupt on a PCI/MSIX interrupt domain
- *		      which was allocated via pci_msix_alloc_irq_at()
  *
  * @dev:	The PCI device to operate on
  * @map:	A struct msi_map describing the interrupt to free
- *		as returned from the allocation function.
+ *
+ * Undo an interrupt vector allocation. Does not disable MSI-X.
  */
 void pci_msix_free_irq(struct pci_dev *dev, struct msi_map map)
 {

^ permalink raw reply related	[flat|nested] 72+ messages in thread

end of thread, other threads:[~2023-02-21  7:32 UTC | newest]

Thread overview: 72+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-21 14:37 [patch V2 00/33] genirq, PCI/MSI: Support for per device MSI and PCI/IMS - Part 3 implementation Thomas Gleixner
2022-11-21 14:37 ` [patch V2 01/33] genirq/msi: Rearrange MSI domain flags Thomas Gleixner
2022-11-21 14:37 ` [patch V2 02/33] genirq/msi: Provide struct msi_parent_ops Thomas Gleixner
2022-11-23  7:57   ` Tian, Kevin
2022-11-23 11:28     ` Thomas Gleixner
2022-11-24  0:53       ` Tian, Kevin
2022-11-21 14:37 ` [patch V2 03/33] genirq/msi: Provide data structs for per device domains Thomas Gleixner
2022-11-23  7:57   ` Tian, Kevin
2022-11-23 11:29     ` Thomas Gleixner
2022-11-21 14:37 ` [patch V2 04/33] genirq/msi: Add size info to struct msi_domain_info Thomas Gleixner
2022-11-21 14:37 ` [patch V2 05/33] genirq/msi: Split msi_create_irq_domain() Thomas Gleixner
2022-11-21 14:37 ` [patch V2 06/33] genirq/irqdomain: Add irq_domain::dev for per device MSI domains Thomas Gleixner
2022-11-21 14:37 ` [patch V2 07/33] genirq/msi: Provide msi_create/free_device_irq_domain() Thomas Gleixner
2022-11-23  8:02   ` Tian, Kevin
2022-11-23 11:38     ` Thomas Gleixner
2022-11-23 21:01       ` Thomas Gleixner
2022-11-24  1:07       ` Tian, Kevin
2022-11-24  8:36         ` Thomas Gleixner
2022-11-28  1:47           ` Tian, Kevin
2022-11-21 14:37 ` [patch V2 08/33] genirq/msi: Provide msi_match_device_domain() Thomas Gleixner
2022-11-21 14:37 ` [patch V2 09/33] genirq/msi: Add range checking to msi_insert_desc() Thomas Gleixner
2022-11-21 14:37 ` [patch V2 10/33] PCI/MSI: Split __pci_write_msi_msg() Thomas Gleixner
2022-11-21 14:37 ` [patch V2 11/33] genirq/msi: Provide BUS_DEVICE_PCI_MSI[X] Thomas Gleixner
2022-11-21 14:38 ` [patch V2 12/33] PCI/MSI: Add support for per device MSI[X] domains Thomas Gleixner
2022-11-23  8:08   ` Tian, Kevin
2022-11-23 11:41     ` Thomas Gleixner
2022-11-23 21:50       ` Thomas Gleixner
2022-11-24  1:08         ` Tian, Kevin
2022-11-21 14:38 ` [patch V2 13/33] x86/apic/vector: Provide MSI parent domain Thomas Gleixner
2022-11-23  8:16   ` Tian, Kevin
2022-11-23 13:42     ` Thomas Gleixner
2022-11-24  1:10       ` Tian, Kevin
2022-11-21 14:38 ` [patch V2 14/33] PCI/MSI: Remove unused pci_dev_has_special_msi_domain() Thomas Gleixner
2022-11-21 14:38 ` [patch V2 15/33] iommu/vt-d: Switch to MSI parent domains Thomas Gleixner
2022-11-21 14:38 ` [patch V2 16/33] iommu/amd: Switch to MSI base domains Thomas Gleixner
2022-11-21 14:38 ` [patch V2 17/33] x86/apic/msi: Remove arch_create_remap_msi_irq_domain() Thomas Gleixner
2022-11-21 14:38 ` [patch V2 18/33] genirq/msi: Provide struct msi_map Thomas Gleixner
2022-11-21 14:38 ` [patch V2 19/33] genirq/msi: Provide msi_desc::msi_data Thomas Gleixner
2022-11-23  8:27   ` Tian, Kevin
2022-11-23 11:41     ` Thomas Gleixner
2022-11-21 14:38 ` [patch V2 20/33] genirq/msi: Provide msi_domain_ops::prepare_desc() Thomas Gleixner
2022-11-21 14:38 ` [patch V2 21/33] genirq/msi: Provide msi_domain_alloc_irq_at() Thomas Gleixner
2022-11-24  2:54   ` Tian, Kevin
2022-11-21 14:38 ` [patch V2 22/33] genirq/msi: Provide MSI_FLAG_MSIX_ALLOC_DYN Thomas Gleixner
2022-11-21 14:38 ` [patch V2 23/33] PCI/MSI: Split MSI-X descriptor setup Thomas Gleixner
2022-11-21 14:38 ` [patch V2 24/33] PCI/MSI: Provide prepare_desc() MSI domain op Thomas Gleixner
2022-11-21 14:38 ` [patch V2 25/33] PCI/MSI: Provide post-enable dynamic allocation interfaces for MSI-X Thomas Gleixner
2022-11-24  2:58   ` Tian, Kevin
2022-11-24  9:08     ` Thomas Gleixner
2022-11-28  1:49       ` Tian, Kevin
2023-02-21  7:32       ` [tip: irq/urgent] PCI/MSI: Clarify usage of pci_msix_free_irq() tip-bot2 for Reinette Chatre
2022-11-21 14:38 ` [patch V2 26/33] x86/apic/msi: Enable MSI_FLAG_PCI_MSIX_ALLOC_DYN Thomas Gleixner
2022-11-21 14:38 ` [patch V2 27/33] genirq/msi: Provide constants for PCI/IMS support Thomas Gleixner
2022-11-24  3:01   ` Tian, Kevin
2022-11-24  9:10     ` Thomas Gleixner
2022-11-24 13:09       ` Jason Gunthorpe
2022-11-24 13:28         ` Thomas Gleixner
2022-11-21 14:38 ` [patch V2 28/33] PCI/MSI: Provide IMS (Interrupt Message Store) support Thomas Gleixner
2022-11-24  3:10   ` Tian, Kevin
2022-11-24  9:10     ` Thomas Gleixner
2022-11-21 14:38 ` [patch V2 29/33] PCI/MSI: Provide pci_ims_alloc/free_irq() Thomas Gleixner
2022-11-24  3:11   ` Tian, Kevin
2022-11-21 14:38 ` [patch V2 30/33] x86/apic/msi: Enable PCI/IMS Thomas Gleixner
2022-11-21 14:38 ` [patch V2 31/33] iommu/vt-d: " Thomas Gleixner
2022-11-24  3:17   ` Tian, Kevin
2022-11-24  9:37     ` Thomas Gleixner
2022-11-24 13:14       ` Jason Gunthorpe
2022-11-24 13:21         ` Thomas Gleixner
2022-11-28  1:54           ` Tian, Kevin
2022-11-21 14:38 ` [patch V2 32/33] iommu/amd: " Thomas Gleixner
2022-11-21 14:38 ` [patch V2 33/33] irqchip: Add IDXD Interrupt Message Store driver Thomas Gleixner
2022-11-24  3:19   ` Tian, Kevin

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.