linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] iommu/amd: Correctly Align Multiple MSI IRQs
@ 2017-10-06 11:34 Joerg Roedel
  2017-10-06 11:34 ` [PATCH 1/2] iommu/amd: Add align parameter to alloc_irq_index() Joerg Roedel
  2017-10-06 11:34 ` [PATCH 2/2] iommu/amd: Enforce alignment for MSI IRQs Joerg Roedel
  0 siblings, 2 replies; 5+ messages in thread
From: Joerg Roedel @ 2017-10-06 11:34 UTC (permalink / raw)
  To: iommu; +Cc: Thomas Gleixner, linux-kernel, Joerg Roedel

Hi,

Thomas made me recently aware of the fact that the IRQ
remapping code in the AMD IOMMU driver does not enforce the
required alignment of IRQ indexes for multiple MSI IRQs.

This patch-set adds the correct alignment for these IRQs.

Regards,

	Joerg

Joerg Roedel (2):
  iommu/amd: Add align parameter to alloc_irq_index()
  iommu/amd: Enforce alignment for MSI IRQs

 drivers/iommu/amd_iommu.c | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

-- 
2.7.4

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

* [PATCH 1/2] iommu/amd: Add align parameter to alloc_irq_index()
  2017-10-06 11:34 [PATCH 0/2] iommu/amd: Correctly Align Multiple MSI IRQs Joerg Roedel
@ 2017-10-06 11:34 ` Joerg Roedel
  2017-10-08  8:39   ` Thomas Gleixner
  2017-10-06 11:34 ` [PATCH 2/2] iommu/amd: Enforce alignment for MSI IRQs Joerg Roedel
  1 sibling, 1 reply; 5+ messages in thread
From: Joerg Roedel @ 2017-10-06 11:34 UTC (permalink / raw)
  To: iommu; +Cc: Thomas Gleixner, linux-kernel, Joerg Roedel

From: Joerg Roedel <jroedel@suse.de>

For multi-MSI IRQ ranges the IRQ index needs to be aligned
to the power-of-two of the requested IRQ count. Extend the
alloc_irq_index() function to allow such an allocation.

Reported-by: Thomas Gleixner <tglx@linutronix.de>
Fixes: 2b324506341cb ('iommu/amd: Add routines to manage irq remapping tables')
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
 drivers/iommu/amd_iommu.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 51f8215..2d4ee25 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -3660,11 +3660,11 @@ static struct irq_remap_table *get_irq_table(u16 devid, bool ioapic)
 	return table;
 }
 
-static int alloc_irq_index(u16 devid, int count)
+static int alloc_irq_index(u16 devid, int count, bool align)
 {
 	struct irq_remap_table *table;
+	int index, c, alignment = 1;
 	unsigned long flags;
-	int index, c;
 	struct amd_iommu *iommu = amd_iommu_rlookup_table[devid];
 
 	if (!iommu)
@@ -3674,16 +3674,22 @@ static int alloc_irq_index(u16 devid, int count)
 	if (!table)
 		return -ENODEV;
 
+	if (align)
+		alignment = roundup_pow_of_two(count);
+
 	spin_lock_irqsave(&table->lock, flags);
 
 	/* Scan table for free entries */
-	for (c = 0, index = table->min_index;
+	for (index = ALIGN(table->min_index, alignment), c = 0;
 	     index < MAX_IRQS_PER_TABLE;
-	     ++index) {
-		if (!iommu->irte_ops->is_allocated(table, index))
+	     index++) {
+		if (!iommu->irte_ops->is_allocated(table, index)) {
 			c += 1;
-		else
-			c = 0;
+		} else {
+			c     = 0;
+			index = ALIGN(index, alignment);
+			continue;
+		}
 
 		if (c == count)	{
 			for (; c != 0; --c)
@@ -4096,7 +4102,7 @@ static int irq_remapping_alloc(struct irq_domain *domain, unsigned int virq,
 		else
 			ret = -ENOMEM;
 	} else {
-		index = alloc_irq_index(devid, nr_irqs);
+		index = alloc_irq_index(devid, nr_irqs, false);
 	}
 	if (index < 0) {
 		pr_warn("Failed to allocate IRTE\n");
-- 
2.7.4

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

* [PATCH 2/2] iommu/amd: Enforce alignment for MSI IRQs
  2017-10-06 11:34 [PATCH 0/2] iommu/amd: Correctly Align Multiple MSI IRQs Joerg Roedel
  2017-10-06 11:34 ` [PATCH 1/2] iommu/amd: Add align parameter to alloc_irq_index() Joerg Roedel
@ 2017-10-06 11:34 ` Joerg Roedel
  2017-10-08  8:40   ` Thomas Gleixner
  1 sibling, 1 reply; 5+ messages in thread
From: Joerg Roedel @ 2017-10-06 11:34 UTC (permalink / raw)
  To: iommu; +Cc: Thomas Gleixner, linux-kernel, Joerg Roedel

From: Joerg Roedel <jroedel@suse.de>

Make use of the new alignment capability of
alloc_irq_index() to enforce IRQ index alignment
for MSI.

Reported-by: Thomas Gleixner <tglx@linutronix.de>
Fixes: 2b324506341cb ('iommu/amd: Add routines to manage irq remapping tables')
Signed-off-by: Joerg Roedel <jroedel@suse.de>
---
 drivers/iommu/amd_iommu.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 2d4ee25..cb7c531 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -4102,7 +4102,9 @@ static int irq_remapping_alloc(struct irq_domain *domain, unsigned int virq,
 		else
 			ret = -ENOMEM;
 	} else {
-		index = alloc_irq_index(devid, nr_irqs, false);
+		bool align = (info->type == X86_IRQ_ALLOC_TYPE_MSI);
+
+		index = alloc_irq_index(devid, nr_irqs, align);
 	}
 	if (index < 0) {
 		pr_warn("Failed to allocate IRTE\n");
-- 
2.7.4

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

* Re: [PATCH 1/2] iommu/amd: Add align parameter to alloc_irq_index()
  2017-10-06 11:34 ` [PATCH 1/2] iommu/amd: Add align parameter to alloc_irq_index() Joerg Roedel
@ 2017-10-08  8:39   ` Thomas Gleixner
  0 siblings, 0 replies; 5+ messages in thread
From: Thomas Gleixner @ 2017-10-08  8:39 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: iommu, linux-kernel, Joerg Roedel

On Fri, 6 Oct 2017, Joerg Roedel wrote:

> From: Joerg Roedel <jroedel@suse.de>
> 
> For multi-MSI IRQ ranges the IRQ index needs to be aligned
> to the power-of-two of the requested IRQ count. Extend the
> alloc_irq_index() function to allow such an allocation.
> 
> Reported-by: Thomas Gleixner <tglx@linutronix.de>
> Fixes: 2b324506341cb ('iommu/amd: Add routines to manage irq remapping tables')
> Signed-off-by: Joerg Roedel <jroedel@suse.de>

Reviewed-by: Thomas Gleixner <tglx@linutronix.de>

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

* Re: [PATCH 2/2] iommu/amd: Enforce alignment for MSI IRQs
  2017-10-06 11:34 ` [PATCH 2/2] iommu/amd: Enforce alignment for MSI IRQs Joerg Roedel
@ 2017-10-08  8:40   ` Thomas Gleixner
  0 siblings, 0 replies; 5+ messages in thread
From: Thomas Gleixner @ 2017-10-08  8:40 UTC (permalink / raw)
  To: Joerg Roedel; +Cc: iommu, linux-kernel, Joerg Roedel

On Fri, 6 Oct 2017, Joerg Roedel wrote:

> From: Joerg Roedel <jroedel@suse.de>
> 
> Make use of the new alignment capability of
> alloc_irq_index() to enforce IRQ index alignment
> for MSI.
> 
> Reported-by: Thomas Gleixner <tglx@linutronix.de>
> Fixes: 2b324506341cb ('iommu/amd: Add routines to manage irq remapping tables')
> Signed-off-by: Joerg Roedel <jroedel@suse.de>

Reviewed-by: Thomas Gleixner <tglx@linutronix.de>

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

end of thread, other threads:[~2017-10-08  8:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-06 11:34 [PATCH 0/2] iommu/amd: Correctly Align Multiple MSI IRQs Joerg Roedel
2017-10-06 11:34 ` [PATCH 1/2] iommu/amd: Add align parameter to alloc_irq_index() Joerg Roedel
2017-10-08  8:39   ` Thomas Gleixner
2017-10-06 11:34 ` [PATCH 2/2] iommu/amd: Enforce alignment for MSI IRQs Joerg Roedel
2017-10-08  8:40   ` Thomas Gleixner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).