iommu: MSI parent domain conversion
Subsystems (3)
cover iommu: MSI parent domain conversion
The initial implementation of PCI/MSI interrupt domains in the hierarchical interrupt domain model used a shortcut by providing a global PCI/MSI domain.
This works because the PCI/MSI[X] hardware is standardized and uniform, but it violates the basic design principle of hierarchical interrupt domains:
Each hardware block involved in the interrupt delivery chain should have a separate interrupt domain.
For PCI/MSI[X], the interrupt controller is per PCI device and not a global made-up entity.
Unsurprisingly, the shortcut turned out to have downsides as it does not allow dynamic allocation of interrupt vectors after initialization and it prevents supporting IMS on PCI. For further details, see:
https://lore.kernel.org/lkml/[email protected]/
The solution is implementing per device MSI domains, this means the entities which provide global PCI/MSI domain so far have to implement MSI parent domain functionality instead.
This series convert the IOMMU drivers to implement MSI parent domain.
drivers/iommu/Kconfig | 1 + drivers/iommu/amd/Kconfig | 1 + drivers/iommu/amd/iommu.c | 26 ++++++++++++++------------ drivers/iommu/intel/irq_remapping.c | 28 ++++++++++++++-------------- 4 files changed, 30 insertions(+), 26 deletions(-)
Signature · 1 line
2.39.5
PATCH 1/2 iommu/amd: Convert to msi_create_parent_irq_domain() helper
From: Marc Zyngier <[email protected]>
Now that we have a concise helper to create an MSI parent domain, switch the AMD IOMMU remapping over to that.
--- drivers/iommu/amd/Kconfig | 1 + drivers/iommu/amd/iommu.c | 26 ++++++++++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-)
drivers/iommu/amd/Kconfig +1 -0
@@ -7,6 +7,7 @@ config AMD_IOMMU select PCI_ATS select PCI_PRI select PCI_PASID + select IRQ_MSI_LIB select MMU_NOTIFIER select IOMMU_API select IOMMU_IOVA
drivers/iommu/amd/iommu.c +14 -12
@@ -25,6 +25,7 @@#include <linux/notifier.h> #include <linux/export.h> #include <linux/irq.h> +#include <linux/irqchip/irq-msi-lib.h> #include <linux/msi.h> #include <linux/irqdomain.h> #include <linux/percpu.h>
@@ -3970,29 +3971,30 @@ 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 , + .bus_select_token =DOMAIN_BUS_AMDVI , + .bus_select_mask =MATCH_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; +struct irq_domain_info info = { + .fwnode =irq_domain_alloc_named_id_fwnode ("AMD-IR" , iommu->index), + .ops = &amd_ir_domain_ops, + .domain_flags =IRQ_DOMAIN_FLAG_ISOLATED_MSI , + .host_data = iommu, + .parent =arch_get_ir_parent_domain (), + }; - fn =irq_domain_alloc_named_id_fwnode ("AMD-IR" , iommu->index); -if (!fn) +if (!info.fwnode)return -ENOMEM ; - iommu->ir_domain =irq_domain_create_hierarchy (arch_get_ir_parent_domain (),0 ,0 , - fn, &amd_ir_domain_ops, iommu); + + iommu->ir_domain =msi_create_parent_irq_domain (&info, &amdvi_msi_parent_ops);if (!iommu->ir_domain) { -irq_domain_free_fwnode (fn); +irq_domain_free_fwnode (info.fwnode);return -ENOMEM ; } - -irq_domain_update_bus_token (iommu->ir_domain,DOMAIN_BUS_AMDVI ); - iommu->ir_domain->flags |=IRQ_DOMAIN_FLAG_MSI_PARENT | -IRQ_DOMAIN_FLAG_ISOLATED_MSI ; - iommu->ir_domain->msi_parent_ops = &amdvi_msi_parent_ops; -return 0 ; }
Signature · 1 line
2.39.5
PATCH 2/2 iommu/intel: Convert to msi_create_parent_irq_domain() helper
In reply to Nam CaoFrom: Marc Zyngier <[email protected]>
Now that we have a concise helper to create an MSI parent domain, switch the Intel IOMMU remapping over to that.
--- drivers/iommu/Kconfig | 1 + drivers/iommu/intel/irq_remapping.c | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 14 deletions(-)
drivers/iommu/Kconfig +1 -0
@@ -200,6 +200,7 @@ source "drivers/iommu/riscv/Kconfig" config IRQ_REMAP bool "Support for Interrupt Remapping" depends on X86_64 && X86_IO_APIC && PCI_MSI && ACPI + select IRQ_MSI_LIB help Supports Interrupt remapping for IO-APIC and MSI devices. To use x2apic mode in the CPU's which support x2APIC enhancements or
drivers/iommu/intel/irq_remapping.c +14 -14
@@ -10,6 +10,7 @@#include <linux/hpet.h> #include <linux/pci.h> #include <linux/irq.h> +#include <linux/irqchip/irq-msi-lib.h> #include <linux/acpi.h> #include <linux/irqdomain.h> #include <linux/crash_dump.h>
@@ -518,8 +519,14 @@ static void iommu_enable_irq_remapping(struct intel_iommu *iommu)static int intel_setup_irq_remapping (struct intel_iommu *iommu) { +struct irq_domain_info info = { + .ops = &intel_ir_domain_ops, + .parent =arch_get_ir_parent_domain (), + .domain_flags =IRQ_DOMAIN_FLAG_ISOLATED_MSI , + .size =INTR_REMAP_TABLE_ENTRIES , + .host_data = iommu, + };struct ir_table *ir_table; -struct fwnode_handle *fn;unsigned long *bitmap;void *ir_table_base;
@@ -544,25 +551,16 @@ static int intel_setup_irq_remapping(struct intel_iommu *iommu) goto out_free_pages; } - fn =irq_domain_alloc_named_id_fwnode ("INTEL-IR" , iommu->seq_id); -if (!fn) + info.fwnode =irq_domain_alloc_named_id_fwnode ("INTEL-IR" , iommu->seq_id); +if (!info.fwnode) goto out_free_bitmap; - iommu->ir_domain = -irq_domain_create_hierarchy (arch_get_ir_parent_domain (), -0 ,INTR_REMAP_TABLE_ENTRIES , - fn, &intel_ir_domain_ops, - iommu); + iommu->ir_domain =msi_create_parent_irq_domain (&info, &dmar_msi_parent_ops);if (!iommu->ir_domain) {pr_err ("IR%d: failed to allocate irqdomain\n" , iommu->seq_id); goto out_free_fwnode; } -irq_domain_update_bus_token (iommu->ir_domain,DOMAIN_BUS_DMAR ); - iommu->ir_domain->flags |=IRQ_DOMAIN_FLAG_MSI_PARENT | -IRQ_DOMAIN_FLAG_ISOLATED_MSI ; - iommu->ir_domain->msi_parent_ops = &dmar_msi_parent_ops; - ir_table->base = ir_table_base; ir_table->bitmap = bitmap; iommu->ir_table = ir_table;
@@ -608,7 +606,7 @@ static int intel_setup_irq_remapping(struct intel_iommu *iommu)irq_domain_remove (iommu->ir_domain); iommu->ir_domain =NULL ; out_free_fwnode: -irq_domain_free_fwnode (fn); +irq_domain_free_fwnode (info.fwnode); out_free_bitmap:bitmap_free (bitmap); out_free_pages:
@@ -1530,6 +1528,8 @@ static const struct irq_domain_ops intel_ir_domain_ops = {static const struct msi_parent_ops dmar_msi_parent_ops = { .supported_flags =X86_VECTOR_MSI_FLAGS_SUPPORTED |MSI_FLAG_MULTI_PCI_MSI , + .bus_select_token =DOMAIN_BUS_DMAR , + .bus_select_mask =MATCH_PCI_MSI , .prefix ="IR-" , .init_dev_msi_info = msi_parent_init_dev_msi_info, };
Signature · 1 line
2.39.5