* [PATCH 1/2] PCI/MSI: Allow opt-in teardown of per-device MSI domains
2026-12-04 16:41 [PATCH 0/2] PCI/MSI: Allow opt-in domain teardown for pSeries RTAS Narayana Murty N
@ 2026-12-04 16:41 ` Narayana Murty N
2026-12-04 17:01 ` sashiko-bot
2026-12-04 16:41 ` [PATCH 2/2] powerpc/pseries/msi: Release RTAS MSI state on vector disable Narayana Murty N
2026-12-04 17:11 ` [PATCH 0/2] PCI/MSI: Allow opt-in domain teardown for pSeries RTAS sashiko-bot
2 siblings, 1 reply; 5+ messages in thread
From: Narayana Murty N @ 2026-12-04 16:41 UTC (permalink / raw)
To: Madhavan Srinivasan, Bjorn Helgaas, Thomas Gleixner
Cc: Michael Ellerman, Nicholas Piggin, Christophe Leroy,
Ritesh Harjani, Shrikanth Hegde, Radu Rendec, sbhat, harshpb,
gautam, Nam Cao, Nilay Shroff, Vivian Wang, Shawn Lin,
Rafael J . Wysocki, Jonathan Cameron, Lorenzo Pieralisi,
Farhan Ali, Haoxiang Li, Yuanhe Shu, Vidya Sagar, Hans Zhang,
Miles Krause, Randy Dunlap, linuxppc-dev, linux-pci, linux-kernel
PCI per-device MSI domains normally remain in place after all MSI or
MSI-X vectors have been disabled. This is appropriate for providers
that can reuse the domain across subsequent allocations, but not for
providers whose msi_ops->msi_prepare() and msi_ops->msi_teardown()
callbacks manage firmware resources that must be refreshed across vector
lifecycles.
Add MSI_FLAG_PCI_MSI_TEARDOWN_DOMAIN to let an MSI parent provider
request removal of its PCI per-device MSI domain when the vectors
are disabled. Perform this teardown after pci_disable_msi() or
pci_disable_msix() has freed the IRQs. Also tear down the domain on
a terminal MSI/MSI-X enable failure after domain creation.
Do not remove the domain during internal allocation error cleanup: the
MSI and MSI-X enable paths may retry with fewer vectors and must retain
the domain until the allocation succeeds or fails terminally.
Provide locked variants for domain removal and flag inspection so these
operations can run under the existing msi_descs_lock without recursively
acquiring it. Providers that do not set the new flag retain their
current device-domain lifetime.
Signed-off-by: Narayana Murty N <nnmlinux@linux.ibm.com>
---
drivers/pci/msi/api.c | 2 ++
drivers/pci/msi/irqdomain.c | 7 ++++++
drivers/pci/msi/msi.c | 36 ++++++++++++++++++++++---------
drivers/pci/msi/msi.h | 1 +
include/linux/msi.h | 4 ++++
kernel/irq/msi.c | 43 ++++++++++++++++++++++++++++++++++---
6 files changed, 80 insertions(+), 13 deletions(-)
diff --git a/drivers/pci/msi/api.c b/drivers/pci/msi/api.c
index c18559b6272c..b042c92e1114 100644
--- a/drivers/pci/msi/api.c
+++ b/drivers/pci/msi/api.c
@@ -56,6 +56,7 @@ void pci_disable_msi(struct pci_dev *dev)
guard(msi_descs_lock)(&dev->dev);
pci_msi_shutdown(dev);
pci_free_msi_irqs(dev);
+ pci_msi_teardown_device_domain(dev);
}
EXPORT_SYMBOL(pci_disable_msi);
@@ -198,6 +199,7 @@ void pci_disable_msix(struct pci_dev *dev)
guard(msi_descs_lock)(&dev->dev);
pci_msix_shutdown(dev);
pci_free_msi_irqs(dev);
+ pci_msi_teardown_device_domain(dev);
}
EXPORT_SYMBOL(pci_disable_msix);
diff --git a/drivers/pci/msi/irqdomain.c b/drivers/pci/msi/irqdomain.c
index 6e65f0f44112..9cebee81f970 100644
--- a/drivers/pci/msi/irqdomain.c
+++ b/drivers/pci/msi/irqdomain.c
@@ -19,6 +19,13 @@ int pci_msi_setup_msi_irqs(struct pci_dev *dev, int nvec, int type)
return pci_msi_legacy_setup_msi_irqs(dev, nvec, type);
}
+void pci_msi_teardown_device_domain(struct pci_dev *dev)
+{
+ if (msi_device_domain_has_flag_locked(&dev->dev, MSI_DEFAULT_DOMAIN,
+ MSI_FLAG_PCI_MSI_TEARDOWN_DOMAIN))
+ msi_remove_device_irq_domain_locked(&dev->dev, MSI_DEFAULT_DOMAIN);
+}
+
void pci_msi_teardown_msi_irqs(struct pci_dev *dev)
{
struct irq_domain *domain;
diff --git a/drivers/pci/msi/msi.c b/drivers/pci/msi/msi.c
index 8a0133a6a286..0e0a977d0a20 100644
--- a/drivers/pci/msi/msi.c
+++ b/drivers/pci/msi/msi.c
@@ -465,8 +465,10 @@ int __pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec,
for (;;) {
if (affd) {
nvec = irq_calc_affinity_vectors(minvec, nvec, affd);
- if (nvec < minvec)
- return -ENOSPC;
+ if (nvec < minvec) {
+ rc = -ENOSPC;
+ break;
+ }
}
rc = msi_capability_init(dev, nvec, affd);
@@ -474,12 +476,18 @@ int __pci_enable_msi_range(struct pci_dev *dev, int minvec, int maxvec,
return nvec;
if (rc < 0)
- return rc;
- if (rc < minvec)
- return -ENOSPC;
+ break;
+ if (rc < minvec) {
+ rc = -ENOSPC;
+ break;
+ }
nvec = rc;
}
+
+ scoped_guard (msi_descs_lock, &dev->dev)
+ pci_msi_teardown_device_domain(dev);
+ return rc;
}
/**
@@ -851,8 +859,10 @@ int __pci_enable_msix_range(struct pci_dev *dev, struct msix_entry *entries, int
for (;;) {
if (affd) {
nvec = irq_calc_affinity_vectors(minvec, nvec, affd);
- if (nvec < minvec)
- return -ENOSPC;
+ if (nvec < minvec) {
+ rc = -ENOSPC;
+ break;
+ }
}
rc = msix_capability_init(dev, entries, nvec, affd);
@@ -860,12 +870,18 @@ int __pci_enable_msix_range(struct pci_dev *dev, struct msix_entry *entries, int
return nvec;
if (rc < 0)
- return rc;
- if (rc < minvec)
- return -ENOSPC;
+ break;
+ if (rc < minvec) {
+ rc = -ENOSPC;
+ break;
+ }
nvec = rc;
}
+
+ scoped_guard (msi_descs_lock, &dev->dev)
+ pci_msi_teardown_device_domain(dev);
+ return rc;
}
void __pci_restore_msix_state(struct pci_dev *dev)
diff --git a/drivers/pci/msi/msi.h b/drivers/pci/msi/msi.h
index f987cf897264..e7bd49123eae 100644
--- a/drivers/pci/msi/msi.h
+++ b/drivers/pci/msi/msi.h
@@ -117,6 +117,7 @@ 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, unsigned int hwsize);
bool pci_setup_msix_device_domain(struct pci_dev *pdev, unsigned int hwsize);
+void pci_msi_teardown_device_domain(struct pci_dev *dev);
/* Legacy (!IRQDOMAIN) fallbacks */
diff --git a/include/linux/msi.h b/include/linux/msi.h
index a4613de11960..74440df6dd0a 100644
--- a/include/linux/msi.h
+++ b/include/linux/msi.h
@@ -567,6 +567,8 @@ enum {
MSI_FLAG_PCI_MSI_MASK_PARENT = (1 << 9),
/* Support for parent startup/shutdown */
MSI_FLAG_PCI_MSI_STARTUP_PARENT = (1 << 10),
+ /* Remove the PCI device MSI domain on vector disable */
+ MSI_FLAG_PCI_MSI_TEARDOWN_DOMAIN = (1 << 11),
/* Mask for the generic functionality */
MSI_GENERIC_FLAGS_MASK = GENMASK(15, 0),
@@ -645,10 +647,12 @@ 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_locked(struct device *dev, unsigned int domid);
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);
+bool msi_device_domain_has_flag_locked(struct device *dev, unsigned int domid, u32 flag);
int msi_domain_alloc_irqs_range_locked(struct device *dev, unsigned int domid,
unsigned int first, unsigned int last);
diff --git a/kernel/irq/msi.c b/kernel/irq/msi.c
index b22d74496af1..ad10f2195741 100644
--- a/kernel/irq/msi.c
+++ b/kernel/irq/msi.c
@@ -1106,17 +1106,19 @@ bool msi_create_device_irq_domain(struct device *dev, unsigned int domid,
}
/**
- * msi_remove_device_irq_domain - Free a device MSI interrupt domain
+ * msi_remove_device_irq_domain_locked - Free a device MSI interrupt domain
* @dev: Pointer to the device
* @domid: Domain id
+ *
+ * Must be invoked from within a msi_lock_descs() / msi_unlock_descs() pair.
*/
-void msi_remove_device_irq_domain(struct device *dev, unsigned int domid)
+void msi_remove_device_irq_domain_locked(struct device *dev, unsigned int domid)
{
struct fwnode_handle *fwnode = NULL;
struct msi_domain_info *info;
struct irq_domain *domain;
- guard(msi_descs_lock)(dev);
+ lockdep_assert_held(&dev->msi.data->mutex);
domain = msi_get_device_domain(dev, domid);
if (!domain || !irq_domain_is_msi_device(domain))
return;
@@ -1133,6 +1135,17 @@ void msi_remove_device_irq_domain(struct device *dev, unsigned int domid)
kfree(container_of(info, struct msi_domain_template, info));
}
+/**
+ * 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)
+{
+ guard(msi_descs_lock)(dev);
+ msi_remove_device_irq_domain_locked(dev, domid);
+}
+
/**
* msi_match_device_irq_domain - Match a device irq domain against a bus token
* @dev: Pointer to the device
@@ -1156,6 +1169,30 @@ bool msi_match_device_irq_domain(struct device *dev, unsigned int domid,
return false;
}
+/**
+ * msi_device_domain_has_flag_locked - Check if a device MSI domain has a specific flag set
+ * @dev: Pointer to the device
+ * @domid: Domain id
+ * @flag: Flag to check
+ *
+ * Must be invoked from within a msi_lock_descs() / msi_unlock_descs() pair.
+ *
+ * Return: True if device domain exists and flag is set.
+ */
+bool msi_device_domain_has_flag_locked(struct device *dev, unsigned int domid, u32 flag)
+{
+ struct msi_domain_info *info;
+ struct irq_domain *domain;
+
+ lockdep_assert_held(&dev->msi.data->mutex);
+ domain = msi_get_device_domain(dev, domid);
+ if (domain && irq_domain_is_msi_device(domain)) {
+ info = domain->host_data;
+ return !!(info->flags & flag);
+ }
+ return false;
+}
+
static int msi_domain_prepare_irqs(struct irq_domain *domain, struct device *dev,
int nvec, msi_alloc_info_t *arg)
{
--
2.54.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH 2/2] powerpc/pseries/msi: Release RTAS MSI state on vector disable
2026-12-04 16:41 [PATCH 0/2] PCI/MSI: Allow opt-in domain teardown for pSeries RTAS Narayana Murty N
2026-12-04 16:41 ` [PATCH 1/2] PCI/MSI: Allow opt-in teardown of per-device MSI domains Narayana Murty N
@ 2026-12-04 16:41 ` Narayana Murty N
2026-12-04 17:11 ` [PATCH 0/2] PCI/MSI: Allow opt-in domain teardown for pSeries RTAS sashiko-bot
2 siblings, 0 replies; 5+ messages in thread
From: Narayana Murty N @ 2026-12-04 16:41 UTC (permalink / raw)
To: Madhavan Srinivasan, Bjorn Helgaas, Thomas Gleixner
Cc: Michael Ellerman, Nicholas Piggin, Christophe Leroy,
Ritesh Harjani, Shrikanth Hegde, Radu Rendec, sbhat, harshpb,
gautam, Nam Cao, Nilay Shroff, Vivian Wang, Shawn Lin,
Rafael J . Wysocki, Jonathan Cameron, Lorenzo Pieralisi,
Farhan Ali, Haoxiang Li, Yuanhe Shu, Vidya Sagar, Hans Zhang,
Miles Krause, Randy Dunlap, linuxppc-dev, linux-pci, linux-kernel
Before commit daaa574aba6f ("powerpc/pseries/msi: Switch to
msi_create_parent_irq_domain()"), pSeries released its RTAS MSI
configuration from the legacy msi_post_free() callback when the MSI
or MSI-X vectors were freed.
The conversion to hierarchical MSI domains moved that release into
msi_ops->msi_teardown(), which runs when the per-device MSI domain is
destroyed. The PCI/MSI core normally retains that domain across a
complete vector disable, so freeing the vectors no longer necessarily
calls rtas_disable_msi(). A later allocation can reuse the existing
domain and skip msi_ops->msi_prepare(), leaving the RTAS configuration
unchanged even when the device has been reset or reconfigured between
allocations.
Set MSI_FLAG_PCI_MSI_TEARDOWN_DOMAIN for pSeries. This causes the
device MSI domain to be destroyed after normal vector disable or a
terminal enable failure. Domain teardown releases the RTAS
configuration, and the next allocation creates a fresh domain and runs
RTAS preparation again. Internal retries with fewer vectors continue to
reuse the prepared domain.
Fixes: daaa574aba6f ("powerpc/pseries/msi: Switch to msi_create_parent_irq_domain()")
Signed-off-by: Narayana Murty N <nnmlinux@linux.ibm.com>
---
arch/powerpc/platforms/pseries/msi.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/arch/powerpc/platforms/pseries/msi.c b/arch/powerpc/platforms/pseries/msi.c
index 8285b9a29fbf..6d5b1799c5b7 100644
--- a/arch/powerpc/platforms/pseries/msi.c
+++ b/arch/powerpc/platforms/pseries/msi.c
@@ -517,7 +517,8 @@ static bool pseries_init_dev_msi_info(struct device *dev, struct irq_domain *dom
#define PSERIES_PCI_MSI_FLAGS_REQUIRED (MSI_FLAG_USE_DEF_DOM_OPS | \
MSI_FLAG_USE_DEF_CHIP_OPS | \
- MSI_FLAG_PCI_MSI_MASK_PARENT)
+ MSI_FLAG_PCI_MSI_MASK_PARENT | \
+ MSI_FLAG_PCI_MSI_TEARDOWN_DOMAIN)
#define PSERIES_PCI_MSI_FLAGS_SUPPORTED (MSI_GENERIC_FLAGS_MASK | \
MSI_FLAG_PCI_MSIX | \
MSI_FLAG_MSIX_CONTIGUOUS | \
--
2.54.0
^ permalink raw reply related [flat|nested] 5+ messages in thread