Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1554352 > unrolled thread
| Started by | Eric Auger <eric.auger@redhat.com> |
|---|---|
| First post | 2017-01-09 14:50 +0100 |
| Last post | 2017-01-10 17:00 +0100 |
| Articles | 8 — 4 participants |
Back to article view | Back to linux.kernel
[PATCH v7 00/19] KVM PCIe/MSI passthrough on ARM/ARM64 and IOVA reserved regions Eric Auger <eric.auger@redhat.com> - 2017-01-09 14:50 +0100
[PATCH v7 09/19] iommu/vt-d: Implement reserved region get/put callbacks Eric Auger <eric.auger@redhat.com> - 2017-01-09 15:00 +0100
[PATCH v7 06/19] iommu: Only map direct mapped regions Eric Auger <eric.auger@redhat.com> - 2017-01-09 15:00 +0100
[PATCH v7 02/19] iommu/dma: Allow MSI-only cookies Eric Auger <eric.auger@redhat.com> - 2017-01-09 15:00 +0100
[PATCH v7 05/19] iommu: iommu_alloc_resv_region Eric Auger <eric.auger@redhat.com> - 2017-01-09 15:00 +0100
Re: [PATCH v7 00/19] KVM PCIe/MSI passthrough on ARM/ARM64 and IOVA reserved regions Joerg Roedel <joro@8bytes.org> - 2017-01-10 15:20 +0100
Re: [PATCH v7 00/19] KVM PCIe/MSI passthrough on ARM/ARM64 and IOVA reserved regions Will Deacon <will.deacon@arm.com> - 2017-01-10 15:20 +0100
Re: [PATCH v7 00/19] KVM PCIe/MSI passthrough on ARM/ARM64 and IOVA reserved regions Auger Eric <eric.auger@redhat.com> - 2017-01-10 17:00 +0100
| From | Eric Auger <eric.auger@redhat.com> |
|---|---|
| Date | 2017-01-09 14:50 +0100 |
| Subject | [PATCH v7 00/19] KVM PCIe/MSI passthrough on ARM/ARM64 and IOVA reserved regions |
| Message-ID | <sXIuJ-4Rr-3@gated-at.bofh.it> |
Following LPC discussions, we now report reserved regions through the iommu-group sysfs reserved_regions attribute file. Reserved regions are populated through the IOMMU get_resv_region callback (former get_dm_regions), now implemented by amd-iommu, intel-iommu and arm-smmu: - the intel-iommu reports the [0xfee00000 - 0xfeefffff] MSI window as a reserved region and RMRR regions as direct-mapped regions. - the amd-iommu reports device direct mapped regions, the MSI region and HT regions. - the arm-smmu reports the MSI window (arbitrarily located at 0x8000000 and 1MB large). Unsafe interrupt assignment is tested by enumerating all MSI irq domains and checking MSI remapping is supported in the above hierarchy. This check is done in case we detect the iommu translates MSI (an IOMMU_RESV_MSI window exists). Otherwise the IRQ remapping capability is checked at IOMMU level. Obviously this is a defensive IRQ safety assessment: Assuming there are several MSI controllers in the system and at least one does not implement IRQ remapping, the assignment will be considered as unsafe (even if this controller is not acessible from the assigned devices). The two first patches stem from Robin's branch: http://linux-arm.org/git?p=linux-rm.git;a=shortlog;h=refs/heads/iommu/misc They are likely to be pulled separately. Best Regards Eric Git: complete series available at https://github.com/eauger/linux/tree/v4.10-rc3-reserved-v7 History: PATCHv6 -> PATCHv7: - "iommu/dma: Implement PCI allocation optimisation" was added to apply "iommu/dma: Allow MSI-only cookies" - report Intel RMRR as direct-mapped regions - report the type in the iommu group sysfs reserved_regions file - do not merge regions of different types when building the list of reserved regions - intgerate Robin's "iommu/dma: Allow MSI-only cookies" last version - update Documentation/ABI/testing/sysfs-kernel-iommu_groups - rename IOMMU_RESV_NOMAP into IOMMU_RESV_RESERVED PATCHv5 -> PATCHv6 - Introduce IRQ_DOMAIN_FLAG_MSI as suggested by Marc - irq_domain_is_msi, irq_domain_is_msi_remap, irq_domain_hierarchical_is_msi_remap, - set IRQ_DOMAIN_FLAG_MSI in msi_create_irq_domain - fix compil issue on i386 - rework test at VFIO level RFCv4 -> PATCHv5 - fix IRQ security assessment by looking at irq domain parents - check DOMAIN_BUS_FSL_MC_MSI irq domains - AMD MSI and HT regions are exposed in iommu group sysfs RFCv3 -> RFCv4: - arm-smmu driver does not register PCI host bridge windows as reserved regions anymore - Implement reserved region get/put callbacks also in arm-smmuv3 - take the iommu_group lock on iommu_get_group_resv_regions - add a type field in iommu_resv_region instead of using prot - init the region list_head in iommu_alloc_resv_region, also add type parameter - iommu_insert_resv_region manage overlaps and sort reserved windows - address IRQ safety assessment by enumerating all the MSI irq domains and checking the MSI_REMAP flag - update Documentation/ABI/testing/sysfs-kernel-iommu_groups RFC v2 -> v3: - switch to an iommu-group sysfs API - use new dummy allocator provided by Robin - dummy allocator initialized by vfio-iommu-type1 after enumerating the reserved regions - at the moment ARM MSI base address/size is left unchanged compared to v2 - we currently report reserved regions and not usable IOVA regions as requested by Alex RFC v1 -> v2: - fix intel_add_reserved_regions - add mutex lock/unlock in vfio_iommu_type1 Eric Auger (17): iommu: Rename iommu_dm_regions into iommu_resv_regions iommu: Add a new type field in iommu_resv_region iommu: iommu_alloc_resv_region iommu: Only map direct mapped regions iommu: iommu_get_group_resv_regions iommu: Implement reserved_regions iommu-group sysfs file iommu/vt-d: Implement reserved region get/put callbacks iommu/amd: Declare MSI and HT regions as reserved IOVA regions iommu/arm-smmu: Implement reserved region get/put callbacks iommu/arm-smmu-v3: Implement reserved region get/put callbacks irqdomain: Add irq domain MSI and MSI_REMAP flags genirq/msi: Set IRQ_DOMAIN_FLAG_MSI on MSI domain creation irqdomain: irq_domain_check_msi_remap irqchip/gicv3-its: Sets IRQ_DOMAIN_FLAG_MSI_REMAP vfio/type1: Allow transparent MSI IOVA allocation vfio/type1: Check MSI remapping at irq domain level iommu/arm-smmu: Do not advertise IOMMU_CAP_INTR_REMAP anymore Robin Murphy (2): iommu/dma: Implement PCI allocation optimisation iommu/dma: Allow MSI-only cookies .../ABI/testing/sysfs-kernel-iommu_groups | 12 ++ drivers/iommu/amd_iommu.c | 54 ++++--- drivers/iommu/arm-smmu-v3.c | 30 +++- drivers/iommu/arm-smmu.c | 30 +++- drivers/iommu/dma-iommu.c | 138 ++++++++++++---- drivers/iommu/intel-iommu.c | 92 ++++++++--- drivers/iommu/iommu.c | 179 +++++++++++++++++++-- drivers/irqchip/irq-gic-v3-its.c | 1 + drivers/vfio/vfio_iommu_type1.c | 37 ++++- include/linux/dma-iommu.h | 6 + include/linux/iommu.h | 46 ++++-- include/linux/irqdomain.h | 36 +++++ kernel/irq/irqdomain.c | 39 +++++ kernel/irq/msi.c | 4 +- 14 files changed, 606 insertions(+), 98 deletions(-) -- 1.9.1
[toc] | [next] | [standalone]
| From | Eric Auger <eric.auger@redhat.com> |
|---|---|
| Date | 2017-01-09 15:00 +0100 |
| Subject | [PATCH v7 09/19] iommu/vt-d: Implement reserved region get/put callbacks |
| Message-ID | <sXIEp-4UO-7@gated-at.bofh.it> |
| In reply to | #1554352 |
This patch registers the [FEE0_0000h - FEF0_000h] 1MB MSI
range as a reserved region and RMRR regions as direct regions.
This will allow to report those reserved regions in the
iommu-group sysfs.
Signed-off-by: Eric Auger <eric.auger@redhat.com>
---
v6 -> v7:
- report RMRR regions as direct regions
- Due to the usage of rcu_read_lock, the rmrr reserved region
allocation is done on rmrr allocation.
- use IOMMU_RESV_RESERVED
RFCv2 -> RFCv3:
- use get/put_resv_region callbacks.
RFC v1 -> RFC v2:
- fix intel_iommu_add_reserved_regions name
- use IOAPIC_RANGE_START and IOAPIC_RANGE_END defines
- return if the MSI region is already registered;
---
drivers/iommu/intel-iommu.c | 92 ++++++++++++++++++++++++++++++++++++---------
1 file changed, 74 insertions(+), 18 deletions(-)
diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c
index 8a18525..bce59a5 100644
--- a/drivers/iommu/intel-iommu.c
+++ b/drivers/iommu/intel-iommu.c
@@ -440,6 +440,7 @@ struct dmar_rmrr_unit {
u64 end_address; /* reserved end address */
struct dmar_dev_scope *devices; /* target devices */
int devices_cnt; /* target device count */
+ struct iommu_resv_region *resv; /* reserved region handle */
};
struct dmar_atsr_unit {
@@ -4246,27 +4247,40 @@ static inline void init_iommu_pm_ops(void) {}
int __init dmar_parse_one_rmrr(struct acpi_dmar_header *header, void *arg)
{
struct acpi_dmar_reserved_memory *rmrr;
+ int prot = DMA_PTE_READ|DMA_PTE_WRITE;
struct dmar_rmrr_unit *rmrru;
+ size_t length;
rmrru = kzalloc(sizeof(*rmrru), GFP_KERNEL);
if (!rmrru)
- return -ENOMEM;
+ goto out;
rmrru->hdr = header;
rmrr = (struct acpi_dmar_reserved_memory *)header;
rmrru->base_address = rmrr->base_address;
rmrru->end_address = rmrr->end_address;
+
+ length = rmrr->end_address - rmrr->base_address + 1;
+ rmrru->resv = iommu_alloc_resv_region(rmrr->base_address, length, prot,
+ IOMMU_RESV_DIRECT);
+ if (!rmrru->resv)
+ goto free_rmrru;
+
rmrru->devices = dmar_alloc_dev_scope((void *)(rmrr + 1),
((void *)rmrr) + rmrr->header.length,
&rmrru->devices_cnt);
- if (rmrru->devices_cnt && rmrru->devices == NULL) {
- kfree(rmrru);
- return -ENOMEM;
- }
+ if (rmrru->devices_cnt && rmrru->devices == NULL)
+ goto free_all;
list_add(&rmrru->list, &dmar_rmrr_units);
return 0;
+free_all:
+ kfree(rmrru->resv);
+free_rmrru:
+ kfree(rmrru);
+out:
+ return -ENOMEM;
}
static struct dmar_atsr_unit *dmar_find_atsr(struct acpi_dmar_atsr *atsr)
@@ -4480,6 +4494,7 @@ static void intel_iommu_free_dmars(void)
list_for_each_entry_safe(rmrru, rmrr_n, &dmar_rmrr_units, list) {
list_del(&rmrru->list);
dmar_free_dev_scope(&rmrru->devices, &rmrru->devices_cnt);
+ kfree(rmrru->resv);
kfree(rmrru);
}
@@ -5203,6 +5218,45 @@ static void intel_iommu_remove_device(struct device *dev)
iommu_device_unlink(iommu->iommu_dev, dev);
}
+static void intel_iommu_get_resv_regions(struct device *device,
+ struct list_head *head)
+{
+ struct iommu_resv_region *reg;
+ struct dmar_rmrr_unit *rmrr;
+ struct device *i_dev;
+ int i;
+
+ rcu_read_lock();
+ for_each_rmrr_units(rmrr) {
+ for_each_active_dev_scope(rmrr->devices, rmrr->devices_cnt,
+ i, i_dev) {
+ if (i_dev != device)
+ continue;
+
+ list_add_tail(&rmrr->resv->list, head);
+ }
+ }
+ rcu_read_unlock();
+
+ reg = iommu_alloc_resv_region(IOAPIC_RANGE_START,
+ IOAPIC_RANGE_END - IOAPIC_RANGE_START + 1,
+ 0, IOMMU_RESV_RESERVED);
+ if (!reg)
+ return;
+ list_add_tail(®->list, head);
+}
+
+static void intel_iommu_put_resv_regions(struct device *dev,
+ struct list_head *head)
+{
+ struct iommu_resv_region *entry, *next;
+
+ list_for_each_entry_safe(entry, next, head, list) {
+ if (entry->type == IOMMU_RESV_RESERVED)
+ kfree(entry);
+ }
+}
+
#ifdef CONFIG_INTEL_IOMMU_SVM
#define MAX_NR_PASID_BITS (20)
static inline unsigned long intel_iommu_get_pts(struct intel_iommu *iommu)
@@ -5333,19 +5387,21 @@ struct intel_iommu *intel_svm_device_to_iommu(struct device *dev)
#endif /* CONFIG_INTEL_IOMMU_SVM */
static const struct iommu_ops intel_iommu_ops = {
- .capable = intel_iommu_capable,
- .domain_alloc = intel_iommu_domain_alloc,
- .domain_free = intel_iommu_domain_free,
- .attach_dev = intel_iommu_attach_device,
- .detach_dev = intel_iommu_detach_device,
- .map = intel_iommu_map,
- .unmap = intel_iommu_unmap,
- .map_sg = default_iommu_map_sg,
- .iova_to_phys = intel_iommu_iova_to_phys,
- .add_device = intel_iommu_add_device,
- .remove_device = intel_iommu_remove_device,
- .device_group = pci_device_group,
- .pgsize_bitmap = INTEL_IOMMU_PGSIZES,
+ .capable = intel_iommu_capable,
+ .domain_alloc = intel_iommu_domain_alloc,
+ .domain_free = intel_iommu_domain_free,
+ .attach_dev = intel_iommu_attach_device,
+ .detach_dev = intel_iommu_detach_device,
+ .map = intel_iommu_map,
+ .unmap = intel_iommu_unmap,
+ .map_sg = default_iommu_map_sg,
+ .iova_to_phys = intel_iommu_iova_to_phys,
+ .add_device = intel_iommu_add_device,
+ .remove_device = intel_iommu_remove_device,
+ .get_resv_regions = intel_iommu_get_resv_regions,
+ .put_resv_regions = intel_iommu_put_resv_regions,
+ .device_group = pci_device_group,
+ .pgsize_bitmap = INTEL_IOMMU_PGSIZES,
};
static void quirk_iommu_g4x_gfx(struct pci_dev *dev)
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Eric Auger <eric.auger@redhat.com> |
|---|---|
| Date | 2017-01-09 15:00 +0100 |
| Subject | [PATCH v7 06/19] iommu: Only map direct mapped regions |
| Message-ID | <sXIEq-4UO-19@gated-at.bofh.it> |
| In reply to | #1554352 |
As we introduced new reserved region types which do not require
mapping, let's make sure we only map direct mapped regions.
Signed-off-by: Eric Auger <eric.auger@redhat.com>
---
v3 -> v4:
- use region's type and reword commit message and title
---
drivers/iommu/iommu.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 927878d..41c1906 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -343,6 +343,9 @@ static int iommu_group_create_direct_mappings(struct iommu_group *group,
start = ALIGN(entry->start, pg_size);
end = ALIGN(entry->start + entry->length, pg_size);
+ if (entry->type != IOMMU_RESV_DIRECT)
+ continue;
+
for (addr = start; addr < end; addr += pg_size) {
phys_addr_t phys_addr;
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Eric Auger <eric.auger@redhat.com> |
|---|---|
| Date | 2017-01-09 15:00 +0100 |
| Subject | [PATCH v7 02/19] iommu/dma: Allow MSI-only cookies |
| Message-ID | <sXIEq-4UO-27@gated-at.bofh.it> |
| In reply to | #1554352 |
From: Robin Murphy <robin.murphy@arm.com>
IOMMU domain users such as VFIO face a similar problem to DMA API ops
with regard to mapping MSI messages in systems where the MSI write is
subject to IOMMU translation. With the relevant infrastructure now in
place for managed DMA domains, it's actually really simple for other
users to piggyback off that and reap the benefits without giving up
their own IOVA management, and without having to reinvent their own
wheel in the MSI layer.
Allow such users to opt into automatic MSI remapping by dedicating a
region of their IOVA space to a managed cookie, and extend the mapping
routine to implement a trivial linear allocator in such cases, to avoid
the needless overhead of a full-blown IOVA domain.
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
---
drivers/iommu/dma-iommu.c | 119 +++++++++++++++++++++++++++++++++++++---------
include/linux/dma-iommu.h | 6 +++
2 files changed, 102 insertions(+), 23 deletions(-)
diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c
index a59ca47..008ad88 100644
--- a/drivers/iommu/dma-iommu.c
+++ b/drivers/iommu/dma-iommu.c
@@ -37,15 +37,50 @@ struct iommu_dma_msi_page {
phys_addr_t phys;
};
+enum iommu_dma_cookie_type {
+ IOMMU_DMA_IOVA_COOKIE,
+ IOMMU_DMA_MSI_COOKIE,
+};
+
struct iommu_dma_cookie {
- struct iova_domain iovad;
- struct list_head msi_page_list;
- spinlock_t msi_lock;
+ enum iommu_dma_cookie_type type;
+ union {
+ /* Full allocator for IOMMU_DMA_IOVA_COOKIE */
+ struct iova_domain iovad;
+ /* Trivial linear page allocator for IOMMU_DMA_MSI_COOKIE */
+ dma_addr_t msi_iova;
+ };
+ struct list_head msi_page_list;
+ spinlock_t msi_lock;
};
+static inline size_t cookie_msi_granule(struct iommu_dma_cookie *cookie)
+{
+ if (cookie->type == IOMMU_DMA_IOVA_COOKIE)
+ return cookie->iovad.granule;
+ return PAGE_SIZE;
+}
+
static inline struct iova_domain *cookie_iovad(struct iommu_domain *domain)
{
- return &((struct iommu_dma_cookie *)domain->iova_cookie)->iovad;
+ struct iommu_dma_cookie *cookie = domain->iova_cookie;
+
+ if (cookie->type == IOMMU_DMA_IOVA_COOKIE)
+ return &cookie->iovad;
+ return NULL;
+}
+
+static struct iommu_dma_cookie *cookie_alloc(enum iommu_dma_cookie_type type)
+{
+ struct iommu_dma_cookie *cookie;
+
+ cookie = kzalloc(sizeof(*cookie), GFP_KERNEL);
+ if (cookie) {
+ spin_lock_init(&cookie->msi_lock);
+ INIT_LIST_HEAD(&cookie->msi_page_list);
+ cookie->type = type;
+ }
+ return cookie;
}
int iommu_dma_init(void)
@@ -62,25 +97,53 @@ int iommu_dma_init(void)
*/
int iommu_get_dma_cookie(struct iommu_domain *domain)
{
+ if (domain->iova_cookie)
+ return -EEXIST;
+
+ domain->iova_cookie = cookie_alloc(IOMMU_DMA_IOVA_COOKIE);
+ if (!domain->iova_cookie)
+ return -ENOMEM;
+
+ return 0;
+}
+EXPORT_SYMBOL(iommu_get_dma_cookie);
+
+/**
+ * iommu_get_msi_cookie - Acquire just MSI remapping resources
+ * @domain: IOMMU domain to prepare
+ * @base: Start address of IOVA region for MSI mappings
+ *
+ * Users who manage their own IOVA allocation and do not want DMA API support,
+ * but would still like to take advantage of automatic MSI remapping, can use
+ * this to initialise their own domain appropriately. Users should reserve a
+ * contiguous IOVA region, starting at @base, large enough to accommodate the
+ * number of PAGE_SIZE mappings necessary to cover every MSI doorbell address
+ * used by the devices attached to @domain.
+ */
+int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base)
+{
struct iommu_dma_cookie *cookie;
+ if (domain->type != IOMMU_DOMAIN_UNMANAGED)
+ return -EINVAL;
+
if (domain->iova_cookie)
return -EEXIST;
- cookie = kzalloc(sizeof(*cookie), GFP_KERNEL);
+ cookie = cookie_alloc(IOMMU_DMA_MSI_COOKIE);
if (!cookie)
return -ENOMEM;
- spin_lock_init(&cookie->msi_lock);
- INIT_LIST_HEAD(&cookie->msi_page_list);
+ cookie->msi_iova = base;
domain->iova_cookie = cookie;
return 0;
}
-EXPORT_SYMBOL(iommu_get_dma_cookie);
+EXPORT_SYMBOL(iommu_get_msi_cookie);
/**
* iommu_put_dma_cookie - Release a domain's DMA mapping resources
- * @domain: IOMMU domain previously prepared by iommu_get_dma_cookie()
+ * @domain: IOMMU domain previously prepared by iommu_get_dma_cookie() or
+ * iommu_get_msi_cookie()
*
* IOMMU drivers should normally call this from their domain_free callback.
*/
@@ -92,7 +155,7 @@ void iommu_put_dma_cookie(struct iommu_domain *domain)
if (!cookie)
return;
- if (cookie->iovad.granule)
+ if (cookie->type == IOMMU_DMA_IOVA_COOKIE && cookie->iovad.granule)
put_iova_domain(&cookie->iovad);
list_for_each_entry_safe(msi, tmp, &cookie->msi_page_list, list) {
@@ -137,11 +200,12 @@ static void iova_reserve_pci_windows(struct pci_dev *dev,
int iommu_dma_init_domain(struct iommu_domain *domain, dma_addr_t base,
u64 size, struct device *dev)
{
- struct iova_domain *iovad = cookie_iovad(domain);
+ struct iommu_dma_cookie *cookie = domain->iova_cookie;
+ struct iova_domain *iovad = &cookie->iovad;
unsigned long order, base_pfn, end_pfn;
- if (!iovad)
- return -ENODEV;
+ if (!cookie || cookie->type != IOMMU_DMA_IOVA_COOKIE)
+ return -EINVAL;
/* Use the smallest supported page size for IOVA granularity */
order = __ffs(domain->pgsize_bitmap);
@@ -671,11 +735,12 @@ static struct iommu_dma_msi_page *iommu_dma_get_msi_page(struct device *dev,
{
struct iommu_dma_cookie *cookie = domain->iova_cookie;
struct iommu_dma_msi_page *msi_page;
- struct iova_domain *iovad = &cookie->iovad;
+ struct iova_domain *iovad = cookie_iovad(domain);
struct iova *iova;
int prot = IOMMU_WRITE | IOMMU_NOEXEC | IOMMU_MMIO;
+ size_t size = cookie_msi_granule(cookie);
- msi_addr &= ~(phys_addr_t)iova_mask(iovad);
+ msi_addr &= ~(phys_addr_t)(size - 1);
list_for_each_entry(msi_page, &cookie->msi_page_list, list)
if (msi_page->phys == msi_addr)
return msi_page;
@@ -684,13 +749,18 @@ static struct iommu_dma_msi_page *iommu_dma_get_msi_page(struct device *dev,
if (!msi_page)
return NULL;
- iova = __alloc_iova(domain, iovad->granule, dma_get_mask(dev), dev);
- if (!iova)
- goto out_free_page;
-
msi_page->phys = msi_addr;
- msi_page->iova = iova_dma_addr(iovad, iova);
- if (iommu_map(domain, msi_page->iova, msi_addr, iovad->granule, prot))
+ if (iovad) {
+ iova = __alloc_iova(domain, size, dma_get_mask(dev), dev);
+ if (!iova)
+ goto out_free_page;
+ msi_page->iova = iova_dma_addr(iovad, iova);
+ } else {
+ msi_page->iova = cookie->msi_iova;
+ cookie->msi_iova += size;
+ }
+
+ if (iommu_map(domain, msi_page->iova, msi_addr, size, prot))
goto out_free_iova;
INIT_LIST_HEAD(&msi_page->list);
@@ -698,7 +768,10 @@ static struct iommu_dma_msi_page *iommu_dma_get_msi_page(struct device *dev,
return msi_page;
out_free_iova:
- __free_iova(iovad, iova);
+ if (iovad)
+ __free_iova(iovad, iova);
+ else
+ cookie->msi_iova -= size;
out_free_page:
kfree(msi_page);
return NULL;
@@ -739,7 +812,7 @@ void iommu_dma_map_msi_msg(int irq, struct msi_msg *msg)
msg->data = ~0U;
} else {
msg->address_hi = upper_32_bits(msi_page->iova);
- msg->address_lo &= iova_mask(&cookie->iovad);
+ msg->address_lo &= cookie_msi_granule(cookie) - 1;
msg->address_lo += lower_32_bits(msi_page->iova);
}
}
diff --git a/include/linux/dma-iommu.h b/include/linux/dma-iommu.h
index 7f7e9a7..28df844 100644
--- a/include/linux/dma-iommu.h
+++ b/include/linux/dma-iommu.h
@@ -27,6 +27,7 @@
/* Domain management interface for IOMMU drivers */
int iommu_get_dma_cookie(struct iommu_domain *domain);
+int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base);
void iommu_put_dma_cookie(struct iommu_domain *domain);
/* Setup call for arch DMA mapping code */
@@ -86,6 +87,11 @@ static inline int iommu_get_dma_cookie(struct iommu_domain *domain)
return -ENODEV;
}
+static inline int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base)
+{
+ return -ENODEV;
+}
+
static inline void iommu_put_dma_cookie(struct iommu_domain *domain)
{
}
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Eric Auger <eric.auger@redhat.com> |
|---|---|
| Date | 2017-01-09 15:00 +0100 |
| Subject | [PATCH v7 05/19] iommu: iommu_alloc_resv_region |
| Message-ID | <sXIEq-4UO-29@gated-at.bofh.it> |
| In reply to | #1554352 |
Introduce a new helper serving the purpose to allocate a reserved
region. This will be used in iommu driver implementing reserved
region callbacks.
Signed-off-by: Eric Auger <eric.auger@redhat.com>
---
v3 -> v4:
- add INIT_LIST_HEAD(®ion->list)
- use int for prot param and add int type param
- remove implementation outside of CONFIG_IOMMU_API
---
drivers/iommu/iommu.c | 18 ++++++++++++++++++
include/linux/iommu.h | 2 ++
2 files changed, 20 insertions(+)
diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
index 1cee5c3..927878d 100644
--- a/drivers/iommu/iommu.c
+++ b/drivers/iommu/iommu.c
@@ -1575,6 +1575,24 @@ void iommu_put_resv_regions(struct device *dev, struct list_head *list)
ops->put_resv_regions(dev, list);
}
+struct iommu_resv_region *iommu_alloc_resv_region(phys_addr_t start,
+ size_t length,
+ int prot, int type)
+{
+ struct iommu_resv_region *region;
+
+ region = kzalloc(sizeof(*region), GFP_KERNEL);
+ if (!region)
+ return NULL;
+
+ INIT_LIST_HEAD(®ion->list);
+ region->start = start;
+ region->length = length;
+ region->prot = prot;
+ region->type = type;
+ return region;
+}
+
/* Request that a device is direct mapped by the IOMMU */
int iommu_request_dm_for_dev(struct device *dev)
{
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 233a6bf..f6bb55d3 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -244,6 +244,8 @@ extern void iommu_set_fault_handler(struct iommu_domain *domain,
extern void iommu_get_resv_regions(struct device *dev, struct list_head *list);
extern void iommu_put_resv_regions(struct device *dev, struct list_head *list);
extern int iommu_request_dm_for_dev(struct device *dev);
+extern struct iommu_resv_region *
+iommu_alloc_resv_region(phys_addr_t start, size_t length, int prot, int type);
extern int iommu_attach_group(struct iommu_domain *domain,
struct iommu_group *group);
--
1.9.1
[toc] | [prev] | [next] | [standalone]
| From | Joerg Roedel <joro@8bytes.org> |
|---|---|
| Date | 2017-01-10 15:20 +0100 |
| Subject | Re: [PATCH v7 00/19] KVM PCIe/MSI passthrough on ARM/ARM64 and IOVA reserved regions |
| Message-ID | <sY5rj-2pg-5@gated-at.bofh.it> |
| In reply to | #1554352 |
On Mon, Jan 09, 2017 at 01:45:51PM +0000, Eric Auger wrote: > Eric Auger (17): > iommu: Rename iommu_dm_regions into iommu_resv_regions > iommu: Add a new type field in iommu_resv_region > iommu: iommu_alloc_resv_region > iommu: Only map direct mapped regions > iommu: iommu_get_group_resv_regions > iommu: Implement reserved_regions iommu-group sysfs file > iommu/vt-d: Implement reserved region get/put callbacks > iommu/amd: Declare MSI and HT regions as reserved IOVA regions > iommu/arm-smmu: Implement reserved region get/put callbacks > iommu/arm-smmu-v3: Implement reserved region get/put callbacks IOMMU patches look good, what is the plan to merge this? I'd like to take the IOMMU patches and can provide a branch for someone else to base the rest on. Joerg
[toc] | [prev] | [next] | [standalone]
| From | Will Deacon <will.deacon@arm.com> |
|---|---|
| Date | 2017-01-10 15:20 +0100 |
| Subject | Re: [PATCH v7 00/19] KVM PCIe/MSI passthrough on ARM/ARM64 and IOVA reserved regions |
| Message-ID | <sY5rj-2pg-25@gated-at.bofh.it> |
| In reply to | #1555431 |
On Tue, Jan 10, 2017 at 03:09:24PM +0100, Joerg Roedel wrote: > On Mon, Jan 09, 2017 at 01:45:51PM +0000, Eric Auger wrote: > > Eric Auger (17): > > iommu: Rename iommu_dm_regions into iommu_resv_regions > > iommu: Add a new type field in iommu_resv_region > > iommu: iommu_alloc_resv_region > > iommu: Only map direct mapped regions > > iommu: iommu_get_group_resv_regions > > iommu: Implement reserved_regions iommu-group sysfs file > > iommu/vt-d: Implement reserved region get/put callbacks > > iommu/amd: Declare MSI and HT regions as reserved IOVA regions > > iommu/arm-smmu: Implement reserved region get/put callbacks > > iommu/arm-smmu-v3: Implement reserved region get/put callbacks > > IOMMU patches look good, what is the plan to merge this? I'd like to > take the IOMMU patches and can provide a branch for someone else to base > the rest on. I'm perfectly happy with this going through you. In fact, I suspect you could take the whole series once Marc is happy with the few remaining irq domain niggles (which are really minor at this point). That just leaves the VFIO bits -- Alex, are you happy with those now? If not, we can hold off on the last three patches for the time being. Will
[toc] | [prev] | [next] | [standalone]
| From | Auger Eric <eric.auger@redhat.com> |
|---|---|
| Date | 2017-01-10 17:00 +0100 |
| Subject | Re: [PATCH v7 00/19] KVM PCIe/MSI passthrough on ARM/ARM64 and IOVA reserved regions |
| Message-ID | <sY70b-3cI-11@gated-at.bofh.it> |
| In reply to | #1555431 |
Hi all, On 10/01/2017 15:09, Joerg Roedel wrote: > On Mon, Jan 09, 2017 at 01:45:51PM +0000, Eric Auger wrote: >> Eric Auger (17): >> iommu: Rename iommu_dm_regions into iommu_resv_regions >> iommu: Add a new type field in iommu_resv_region >> iommu: iommu_alloc_resv_region >> iommu: Only map direct mapped regions >> iommu: iommu_get_group_resv_regions >> iommu: Implement reserved_regions iommu-group sysfs file >> iommu/vt-d: Implement reserved region get/put callbacks >> iommu/amd: Declare MSI and HT regions as reserved IOVA regions >> iommu/arm-smmu: Implement reserved region get/put callbacks >> iommu/arm-smmu-v3: Implement reserved region get/put callbacks > > IOMMU patches look good, what is the plan to merge this? I'd like to > take the IOMMU patches and can provide a branch for someone else to base > the rest on. I will respin asap taking into account Marc's nits, Robin's update. Also I would like to do one change in [PATCH v7 08/19] iommu: Implement reserved_regions iommu-group sysfs file I will send a separate email. Thanks Eric > > > Joerg > -- > To unsubscribe from this list: send the line "unsubscribe kvm" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html >
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web