* [PATCH 1/2] iommu/amd: Avoid get_irq_table() from atomic context
@ 2018-01-21 9:28 Scott Wood
[not found] ` <20180121092854.28290-1-swood-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
0 siblings, 1 reply; 4+ messages in thread
From: Scott Wood @ 2018-01-21 9:28 UTC (permalink / raw)
To: Joerg Roedel
Cc: Luis Claudio R. Goncalves, Clark Williams,
iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Myron Stowe,
Scott Wood
get_irq_table() acquires amd_iommu_devtable_lock which is not a raw lock,
and thus cannot be acquired from atomic context on PREEMPT_RT. Many
calls to modify_irte*() come from atomic context due to the IRQ
desc->lock, as does amd_iommu_update_ga() due to the preemption disabling
in vcpu_load/put().
The only difference between calling get_irq_table() and reading from
irq_lookup_table[] directly, other than the lock acquisition and
amd_iommu_rlookup_table[] check, is if the table entry is unpopulated,
which should never happen when looking up a devid that came from an
irq_2_irte struct, as get_irq_table() would have already been called on
that devid during irq_remapping_alloc().
The lock acquisition is not needed in these cases because entries in
irq_lookup_table[] never change once non-NULL -- nor would the
amd_iommu_devtable_lock usage in get_irq_table() provide meaningful
protection if they did, since it's released before using the looked up
table in the get_irq_table() caller.
The amd_iommu_rlookup_table[] check is not needed because
irq_lookup_table[devid] should never be non-NULL if
amd_iommu_rlookup_table[devid] is NULL.
Signed-off-by: Scott Wood <swood-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
---
drivers/iommu/amd_iommu.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index dc4b73833419..8ead1b296d09 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -3732,7 +3732,7 @@ static int modify_irte_ga(u16 devid, int index, struct irte_ga *irte,
if (iommu == NULL)
return -EINVAL;
- table = get_irq_table(devid, false);
+ table = irq_lookup_table[devid];
if (!table)
return -ENOMEM;
@@ -3765,7 +3765,7 @@ static int modify_irte(u16 devid, int index, union irte *irte)
if (iommu == NULL)
return -EINVAL;
- table = get_irq_table(devid, false);
+ table = irq_lookup_table[devid];
if (!table)
return -ENOMEM;
@@ -3789,7 +3789,7 @@ static void free_irte(u16 devid, int index)
if (iommu == NULL)
return;
- table = get_irq_table(devid, false);
+ table = irq_lookup_table[devid];
if (!table)
return;
@@ -4392,7 +4392,7 @@ int amd_iommu_update_ga(int cpu, bool is_run, void *data)
if (!iommu)
return -ENODEV;
- irt = get_irq_table(devid, false);
+ irt = irq_lookup_table[devid];
if (!irt)
return -ENODEV;
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread[parent not found: <20180121092854.28290-1-swood-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>]
* [PATCH 2/2] amd/iommu: Use raw locks on atomic context paths [not found] ` <20180121092854.28290-1-swood-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> @ 2018-01-21 9:28 ` Scott Wood [not found] ` <20180121092854.28290-2-swood-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> 2018-02-13 13:13 ` [PATCH 1/2] iommu/amd: Avoid get_irq_table() from atomic context Joerg Roedel 1 sibling, 1 reply; 4+ messages in thread From: Scott Wood @ 2018-01-21 9:28 UTC (permalink / raw) To: Joerg Roedel Cc: Luis Claudio R. Goncalves, Clark Williams, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Myron Stowe, Scott Wood Several functions in this driver are called from atomic context, and thus raw locks must be used in order to be safe on PREEMPT_RT. This includes paths that must wait for command completion, which is a potential PREEMPT_RT latency concern but not easily avoidable. Signed-off-by: Scott Wood <swood-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> --- drivers/iommu/amd_iommu.c | 30 +++++++++++++++--------------- drivers/iommu/amd_iommu_init.c | 2 +- drivers/iommu/amd_iommu_types.h | 4 ++-- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index 8ead1b296d09..213f5a796ae5 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -1055,9 +1055,9 @@ static int iommu_queue_command_sync(struct amd_iommu *iommu, unsigned long flags; int ret; - spin_lock_irqsave(&iommu->lock, flags); + raw_spin_lock_irqsave(&iommu->lock, flags); ret = __iommu_queue_command_sync(iommu, cmd, sync); - spin_unlock_irqrestore(&iommu->lock, flags); + raw_spin_unlock_irqrestore(&iommu->lock, flags); return ret; } @@ -1083,7 +1083,7 @@ static int iommu_completion_wait(struct amd_iommu *iommu) build_completion_wait(&cmd, (u64)&iommu->cmd_sem); - spin_lock_irqsave(&iommu->lock, flags); + raw_spin_lock_irqsave(&iommu->lock, flags); iommu->cmd_sem = 0; @@ -1094,7 +1094,7 @@ static int iommu_completion_wait(struct amd_iommu *iommu) ret = wait_on_sem(&iommu->cmd_sem); out_unlock: - spin_unlock_irqrestore(&iommu->lock, flags); + raw_spin_unlock_irqrestore(&iommu->lock, flags); return ret; } @@ -3626,7 +3626,7 @@ static struct irq_remap_table *get_irq_table(u16 devid, bool ioapic) goto out_unlock; /* Initialize table spin-lock */ - spin_lock_init(&table->lock); + raw_spin_lock_init(&table->lock); if (ioapic) /* Keep the first 32 indexes free for IOAPIC interrupts */ @@ -3688,7 +3688,7 @@ static int alloc_irq_index(u16 devid, int count, bool align) if (align) alignment = roundup_pow_of_two(count); - spin_lock_irqsave(&table->lock, flags); + raw_spin_lock_irqsave(&table->lock, flags); /* Scan table for free entries */ for (index = ALIGN(table->min_index, alignment), c = 0; @@ -3715,7 +3715,7 @@ static int alloc_irq_index(u16 devid, int count, bool align) index = -ENOSPC; out: - spin_unlock_irqrestore(&table->lock, flags); + raw_spin_unlock_irqrestore(&table->lock, flags); return index; } @@ -3736,7 +3736,7 @@ static int modify_irte_ga(u16 devid, int index, struct irte_ga *irte, if (!table) return -ENOMEM; - spin_lock_irqsave(&table->lock, flags); + raw_spin_lock_irqsave(&table->lock, flags); entry = (struct irte_ga *)table->table; entry = &entry[index]; @@ -3747,7 +3747,7 @@ static int modify_irte_ga(u16 devid, int index, struct irte_ga *irte, if (data) data->ref = entry; - spin_unlock_irqrestore(&table->lock, flags); + raw_spin_unlock_irqrestore(&table->lock, flags); iommu_flush_irt(iommu, devid); iommu_completion_wait(iommu); @@ -3769,9 +3769,9 @@ static int modify_irte(u16 devid, int index, union irte *irte) if (!table) return -ENOMEM; - spin_lock_irqsave(&table->lock, flags); + raw_spin_lock_irqsave(&table->lock, flags); table->table[index] = irte->val; - spin_unlock_irqrestore(&table->lock, flags); + raw_spin_unlock_irqrestore(&table->lock, flags); iommu_flush_irt(iommu, devid); iommu_completion_wait(iommu); @@ -3793,9 +3793,9 @@ static void free_irte(u16 devid, int index) if (!table) return; - spin_lock_irqsave(&table->lock, flags); + raw_spin_lock_irqsave(&table->lock, flags); iommu->irte_ops->clear_allocated(table, index); - spin_unlock_irqrestore(&table->lock, flags); + raw_spin_unlock_irqrestore(&table->lock, flags); iommu_flush_irt(iommu, devid); iommu_completion_wait(iommu); @@ -4396,7 +4396,7 @@ int amd_iommu_update_ga(int cpu, bool is_run, void *data) if (!irt) return -ENODEV; - spin_lock_irqsave(&irt->lock, flags); + raw_spin_lock_irqsave(&irt->lock, flags); if (ref->lo.fields_vapic.guest_mode) { if (cpu >= 0) @@ -4405,7 +4405,7 @@ int amd_iommu_update_ga(int cpu, bool is_run, void *data) barrier(); } - spin_unlock_irqrestore(&irt->lock, flags); + raw_spin_unlock_irqrestore(&irt->lock, flags); iommu_flush_irt(iommu, devid); iommu_completion_wait(iommu); diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c index 6fe2d0346073..e3cd81b32a33 100644 --- a/drivers/iommu/amd_iommu_init.c +++ b/drivers/iommu/amd_iommu_init.c @@ -1474,7 +1474,7 @@ static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h) { int ret; - spin_lock_init(&iommu->lock); + raw_spin_lock_init(&iommu->lock); /* Add IOMMU to internal data structures */ list_add_tail(&iommu->list, &amd_iommu_list); diff --git a/drivers/iommu/amd_iommu_types.h b/drivers/iommu/amd_iommu_types.h index 6a877ebd058b..da886b0095aa 100644 --- a/drivers/iommu/amd_iommu_types.h +++ b/drivers/iommu/amd_iommu_types.h @@ -408,7 +408,7 @@ #define IRQ_TABLE_ALIGNMENT 128 struct irq_remap_table { - spinlock_t lock; + raw_spinlock_t lock; unsigned min_index; u32 *table; }; @@ -490,7 +490,7 @@ struct amd_iommu { int index; /* locks the accesses to the hardware */ - spinlock_t lock; + raw_spinlock_t lock; /* Pointer to PCI device of this IOMMU */ struct pci_dev *dev; -- 1.8.3.1 ^ permalink raw reply related [flat|nested] 4+ messages in thread
[parent not found: <20180121092854.28290-2-swood-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>]
* Re: [PATCH 2/2] amd/iommu: Use raw locks on atomic context paths [not found] ` <20180121092854.28290-2-swood-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> @ 2018-02-13 13:18 ` Joerg Roedel 0 siblings, 0 replies; 4+ messages in thread From: Joerg Roedel @ 2018-02-13 13:18 UTC (permalink / raw) To: Scott Wood Cc: Luis Claudio R. Goncalves, Clark Williams, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Myron Stowe On Sun, Jan 21, 2018 at 03:28:54AM -0600, Scott Wood wrote: > Several functions in this driver are called from atomic context, > and thus raw locks must be used in order to be safe on PREEMPT_RT. > > This includes paths that must wait for command completion, which is > a potential PREEMPT_RT latency concern but not easily avoidable. > > Signed-off-by: Scott Wood <swood-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> > --- > drivers/iommu/amd_iommu.c | 30 +++++++++++++++--------------- > drivers/iommu/amd_iommu_init.c | 2 +- > drivers/iommu/amd_iommu_types.h | 4 ++-- > 3 files changed, 18 insertions(+), 18 deletions(-) Applied, thanks. ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] iommu/amd: Avoid get_irq_table() from atomic context [not found] ` <20180121092854.28290-1-swood-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> 2018-01-21 9:28 ` [PATCH 2/2] amd/iommu: Use raw locks on atomic context paths Scott Wood @ 2018-02-13 13:13 ` Joerg Roedel 1 sibling, 0 replies; 4+ messages in thread From: Joerg Roedel @ 2018-02-13 13:13 UTC (permalink / raw) To: Scott Wood Cc: Luis Claudio R. Goncalves, Clark Williams, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Myron Stowe Hi Scott, On Sun, Jan 21, 2018 at 03:28:53AM -0600, Scott Wood wrote: > The amd_iommu_rlookup_table[] check is not needed because > irq_lookup_table[devid] should never be non-NULL if > amd_iommu_rlookup_table[devid] is NULL. Your reasoning is correct, but I'd like the patch make the code more robust when accessing the irq_lookup_table directly. Can you change rename get_irq_table() into something like alloc_irq_table() and build a new get_irq_table() around the irq_lookup_table access that throws a WARN_ON when the pointer is NULL? Joerg ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-02-13 13:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-01-21 9:28 [PATCH 1/2] iommu/amd: Avoid get_irq_table() from atomic context Scott Wood
[not found] ` <20180121092854.28290-1-swood-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2018-01-21 9:28 ` [PATCH 2/2] amd/iommu: Use raw locks on atomic context paths Scott Wood
[not found] ` <20180121092854.28290-2-swood-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2018-02-13 13:18 ` Joerg Roedel
2018-02-13 13:13 ` [PATCH 1/2] iommu/amd: Avoid get_irq_table() from atomic context Joerg Roedel
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).