Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1389876
| From | Eric Auger <eric.auger@linaro.org> |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH v8 7/8] genirq/msi: map/unmap the MSI doorbells on msi_domain_alloc/free_irqs |
| Date | 2016-04-28 10:30 +0200 |
| Message-ID | <rsPuH-4Y-43@gated-at.bofh.it> (permalink) |
| References | <rsPuF-4Y-3@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
This patch handles the iommu mapping of MSI doorbells that require to
be mapped in an iommu domain. This happens on msi_domain_alloc/free_irqs
since this is called in code that can sleep (pci_enable/disable_msi):
iommu_map/unmap is not stated as atomic. On msi_domain_(de)activate and
msi_domain_set_affinity, which must be atomic, we just lookup for this
pre-allocated/mapped IOVA.
Signed-off-by: Eric Auger <eric.auger@linaro.org>
---
v7 -> v8:
- new percpu pointer type
- exit from the irq domain hierarchy parsing on first map/unmap success
- reset desc->irq to 0 on mapping failure
v7: creation
---
kernel/irq/msi.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 79 insertions(+), 8 deletions(-)
diff --git a/kernel/irq/msi.c b/kernel/irq/msi.c
index 72bf4d6..d5f95e6 100644
--- a/kernel/irq/msi.c
+++ b/kernel/irq/msi.c
@@ -14,6 +14,8 @@
#include <linux/irq.h>
#include <linux/irqdomain.h>
#include <linux/msi.h>
+#include <linux/msi-iommu.h>
+#include <linux/iommu.h>
/* Temparory solution for building, will be removed later */
#include <linux/pci.h>
@@ -322,6 +324,56 @@ int msi_domain_populate_irqs(struct irq_domain *domain, struct device *dev,
}
/**
+ * msi_handle_doorbell_mappings: in case the irq data corresponds to an
+ * MSI that requires iommu mapping, traverse the irq domain hierarchy
+ * to retrieve the doorbells to handle and iommu_map/unmap them according
+ * to @map boolean.
+ *
+ * @data: irq data handle
+ * @map: mapping if true, unmapping if false
+ */
+static int msi_handle_doorbell_mappings(struct irq_data *data, bool map)
+{
+ for (; data; data = data->parent_data) {
+ struct device *dev =
+ msi_desc_to_dev(irq_data_get_msi_desc(data));
+ struct irq_chip *chip = irq_data_get_irq_chip(data);
+ const struct irq_chip_msi_doorbell_info *dbinfo;
+ struct iommu_domain *domain;
+ phys_addr_t __percpu *db_addr;
+ dma_addr_t iova;
+ int ret = 0, i;
+
+ domain = iommu_msi_domain(dev);
+ if (!domain)
+ continue;
+
+ if (!chip->msi_doorbell_info)
+ continue;
+
+ dbinfo = chip->msi_doorbell_info(data);
+ if (!dbinfo)
+ return -EINVAL;
+
+ for (i = 0; i < dbinfo->nb_doorbells; i++) {
+ db_addr = per_cpu_ptr(dbinfo->percpu_doorbells, i);
+ if (map) {
+ ret = iommu_msi_get_doorbell_iova(domain,
+ *db_addr,
+ dbinfo->size,
+ dbinfo->prot,
+ &iova);
+ if (ret)
+ return ret;
+ } else
+ iommu_msi_put_doorbell_iova(domain, *db_addr);
+ }
+ break;
+ }
+ return 0;
+}
+
+/**
* msi_domain_alloc_irqs - Allocate interrupts from a MSI interrupt domain
* @domain: The domain to allocate from
* @dev: Pointer to device struct of the device for which the interrupts
@@ -352,17 +404,26 @@ int msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev,
virq = __irq_domain_alloc_irqs(domain, virq, desc->nvec_used,
dev_to_node(dev), &arg, false);
- if (virq < 0) {
- ret = -ENOSPC;
- if (ops->handle_error)
- ret = ops->handle_error(domain, desc, ret);
- if (ops->msi_finish)
- ops->msi_finish(&arg, ret);
- return ret;
- }
+ if (virq < 0)
+ goto error;
for (i = 0; i < desc->nvec_used; i++)
irq_set_msi_desc_off(virq, i, desc);
+
+ for (i = 0; i < desc->nvec_used; i++) {
+ ret = msi_handle_doorbell_mappings(
+ irq_get_irq_data(virq + i), true);
+ if (ret)
+ break;
+ }
+ if (ret) {
+ for (; i >= 0; i--)
+ msi_handle_doorbell_mappings(
+ irq_get_irq_data(virq + i), false);
+ irq_domain_free_irqs(virq, desc->nvec_used);
+ desc->irq = 0;
+ goto error;
+ }
}
if (ops->msi_finish)
@@ -377,6 +438,13 @@ int msi_domain_alloc_irqs(struct irq_domain *domain, struct device *dev,
}
return 0;
+error:
+ ret = -ENOSPC;
+ if (ops->handle_error)
+ ret = ops->handle_error(domain, desc, ret);
+ if (ops->msi_finish)
+ ops->msi_finish(&arg, ret);
+ return ret;
}
/**
@@ -396,6 +464,9 @@ void msi_domain_free_irqs(struct irq_domain *domain, struct device *dev)
* entry. If that's the case, don't do anything.
*/
if (desc->irq) {
+ msi_handle_doorbell_mappings(
+ irq_get_irq_data(desc->irq),
+ false);
irq_domain_free_irqs(desc->irq, desc->nvec_used);
desc->irq = 0;
}
--
1.9.1
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v8 0/8] KVM PCIe/MSI passthrough on ARM/ARM64: kernel part 2/3: msi changes Eric Auger <eric.auger@linaro.org> - 2016-04-28 10:30 +0200
[PATCH v8 4/8] genirq/msi: msi_compose wrapper Eric Auger <eric.auger@linaro.org> - 2016-04-28 10:30 +0200
[PATCH v8 5/8] genirq/irq: introduce msi_doorbell_info Eric Auger <eric.auger@linaro.org> - 2016-04-28 10:30 +0200
Re: [PATCH v8 5/8] genirq/irq: introduce msi_doorbell_info Marc Zyngier <marc.zyngier@arm.com> - 2016-05-04 15:00 +0200
[PATCH v8 1/8] genirq/msi: Add a new MSI_FLAG_IRQ_REMAPPING flag Eric Auger <eric.auger@linaro.org> - 2016-04-28 10:30 +0200
[PATCH v8 3/8] genirq/msi: export msi_get_domain_info Eric Auger <eric.auger@linaro.org> - 2016-04-28 10:30 +0200
[PATCH v8 7/8] genirq/msi: map/unmap the MSI doorbells on msi_domain_alloc/free_irqs Eric Auger <eric.auger@linaro.org> - 2016-04-28 10:30 +0200
Re: [PATCH v8 7/8] genirq/msi: map/unmap the MSI doorbells on msi_domain_alloc/free_irqs Marc Zyngier <marc.zyngier@arm.com> - 2016-05-04 15:30 +0200
Re: [PATCH v8 7/8] genirq/msi: map/unmap the MSI doorbells on msi_domain_alloc/free_irqs Eric Auger <eric.auger@linaro.org> - 2016-05-04 17:30 +0200
[PATCH v8 2/8] irqchip/gic-v3-its: ITS advertises MSI_FLAG_IRQ_REMAPPING Eric Auger <eric.auger@linaro.org> - 2016-04-28 10:30 +0200
csiph-web