Skip to content

Commit ebb4949

Browse files
committed
Merge tag 'iommu-updates-v4.11' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu
Pull IOMMU UPDATES from Joerg Roedel: - KVM PCIe/MSI passthrough support on ARM/ARM64 - introduction of a core representation for individual hardware iommus - support for IOMMU privileged mappings as supported by some ARM IOMMUS - 16-bit SID support for ARM-SMMUv2 - stream table optimization for ARM-SMMUv3 - various fixes and other small improvements * tag 'iommu-updates-v4.11' of git://git.kernel.org/pub/scm/linux/kernel/git/joro/iommu: (61 commits) vfio/type1: Fix error return code in vfio_iommu_type1_attach_group() iommu: Remove iommu_register_instance interface iommu/exynos: Make use of iommu_device_register interface iommu/mediatek: Make use of iommu_device_register interface iommu/msm: Make use of iommu_device_register interface iommu/arm-smmu: Make use of the iommu_register interface iommu: Add iommu_device_set_fwnode() interface iommu: Make iommu_device_link/unlink take a struct iommu_device iommu: Add sysfs bindings for struct iommu_device iommu: Introduce new 'struct iommu_device' iommu: Rename struct iommu_device iommu: Rename iommu_get_instance() iommu: Fix static checker warning in iommu_insert_device_resv_regions iommu: Avoid unnecessary assignment of dev->iommu_fwspec iommu/mediatek: Remove bogus 'select' statements iommu/dma: Remove bogus dma_supported() implementation iommu/ipmmu-vmsa: Restrict IOMMU Domain Geometry to 32-bit address space iommu/vt-d: Don't over-free page table directories iommu/vt-d: Tylersburg isoch identity map check is done too late. iommu/vt-d: Fix some macros that are incorrectly specified in intel-iommu ...
2 parents 937b5b5 + 8d2932d commit ebb4949

37 files changed

+1189
-390
lines changed

Documentation/ABI/testing/sysfs-kernel-iommu_groups

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,15 @@ Description: /sys/kernel/iommu_groups/ contains a number of sub-
1212
file if the IOMMU driver has chosen to register a more
1313
common name for the group.
1414
Users:
15+
16+
What: /sys/kernel/iommu_groups/reserved_regions
17+
Date: January 2017
18+
KernelVersion: v4.11
19+
Contact: Eric Auger <eric.auger@redhat.com>
20+
Description: /sys/kernel/iommu_groups/reserved_regions list IOVA
21+
regions that are reserved. Not necessarily all
22+
reserved regions are listed. This is typically used to
23+
output direct-mapped, MSI, non mappable regions. Each
24+
region is described on a single line: the 1st field is
25+
the base IOVA, the second is the end IOVA and the third
26+
field describes the type of the region.

Documentation/DMA-attributes.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,13 @@ So, this provides a way for drivers to avoid those error messages on calls
143143
where allocation failures are not a problem, and shouldn't bother the logs.
144144

145145
NOTE: At the moment DMA_ATTR_NO_WARN is only implemented on PowerPC.
146+
147+
DMA_ATTR_PRIVILEGED
148+
------------------------------
149+
150+
Some advanced peripherals such as remote processors and GPUs perform
151+
accesses to DMA buffers in both privileged "supervisor" and unprivileged
152+
"user" modes. This attribute is used to indicate to the DMA-mapping
153+
subsystem that the buffer is fully accessible at the elevated privilege
154+
level (and ideally inaccessible or at least read-only at the
155+
lesser-privileged levels).

arch/arm/mm/dma-mapping.c

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,25 @@ core_initcall(dma_debug_do_init);
11711171

11721172
#ifdef CONFIG_ARM_DMA_USE_IOMMU
11731173

1174+
static int __dma_info_to_prot(enum dma_data_direction dir, unsigned long attrs)
1175+
{
1176+
int prot = 0;
1177+
1178+
if (attrs & DMA_ATTR_PRIVILEGED)
1179+
prot |= IOMMU_PRIV;
1180+
1181+
switch (dir) {
1182+
case DMA_BIDIRECTIONAL:
1183+
return prot | IOMMU_READ | IOMMU_WRITE;
1184+
case DMA_TO_DEVICE:
1185+
return prot | IOMMU_READ;
1186+
case DMA_FROM_DEVICE:
1187+
return prot | IOMMU_WRITE;
1188+
default:
1189+
return prot;
1190+
}
1191+
}
1192+
11741193
/* IOMMU */
11751194

11761195
static int extend_iommu_mapping(struct dma_iommu_mapping *mapping);
@@ -1394,7 +1413,8 @@ __iommu_alloc_remap(struct page **pages, size_t size, gfp_t gfp, pgprot_t prot,
13941413
* Create a mapping in device IO address space for specified pages
13951414
*/
13961415
static dma_addr_t
1397-
__iommu_create_mapping(struct device *dev, struct page **pages, size_t size)
1416+
__iommu_create_mapping(struct device *dev, struct page **pages, size_t size,
1417+
unsigned long attrs)
13981418
{
13991419
struct dma_iommu_mapping *mapping = to_dma_iommu_mapping(dev);
14001420
unsigned int count = PAGE_ALIGN(size) >> PAGE_SHIFT;
@@ -1419,7 +1439,7 @@ __iommu_create_mapping(struct device *dev, struct page **pages, size_t size)
14191439

14201440
len = (j - i) << PAGE_SHIFT;
14211441
ret = iommu_map(mapping->domain, iova, phys, len,
1422-
IOMMU_READ|IOMMU_WRITE);
1442+
__dma_info_to_prot(DMA_BIDIRECTIONAL, attrs));
14231443
if (ret < 0)
14241444
goto fail;
14251445
iova += len;
@@ -1476,7 +1496,8 @@ static struct page **__iommu_get_pages(void *cpu_addr, unsigned long attrs)
14761496
}
14771497

14781498
static void *__iommu_alloc_simple(struct device *dev, size_t size, gfp_t gfp,
1479-
dma_addr_t *handle, int coherent_flag)
1499+
dma_addr_t *handle, int coherent_flag,
1500+
unsigned long attrs)
14801501
{
14811502
struct page *page;
14821503
void *addr;
@@ -1488,7 +1509,7 @@ static void *__iommu_alloc_simple(struct device *dev, size_t size, gfp_t gfp,
14881509
if (!addr)
14891510
return NULL;
14901511

1491-
*handle = __iommu_create_mapping(dev, &page, size);
1512+
*handle = __iommu_create_mapping(dev, &page, size, attrs);
14921513
if (*handle == DMA_ERROR_CODE)
14931514
goto err_mapping;
14941515

@@ -1522,7 +1543,7 @@ static void *__arm_iommu_alloc_attrs(struct device *dev, size_t size,
15221543

15231544
if (coherent_flag == COHERENT || !gfpflags_allow_blocking(gfp))
15241545
return __iommu_alloc_simple(dev, size, gfp, handle,
1525-
coherent_flag);
1546+
coherent_flag, attrs);
15261547

15271548
/*
15281549
* Following is a work-around (a.k.a. hack) to prevent pages
@@ -1537,7 +1558,7 @@ static void *__arm_iommu_alloc_attrs(struct device *dev, size_t size,
15371558
if (!pages)
15381559
return NULL;
15391560

1540-
*handle = __iommu_create_mapping(dev, pages, size);
1561+
*handle = __iommu_create_mapping(dev, pages, size, attrs);
15411562
if (*handle == DMA_ERROR_CODE)
15421563
goto err_buffer;
15431564

@@ -1672,27 +1693,6 @@ static int arm_iommu_get_sgtable(struct device *dev, struct sg_table *sgt,
16721693
GFP_KERNEL);
16731694
}
16741695

1675-
static int __dma_direction_to_prot(enum dma_data_direction dir)
1676-
{
1677-
int prot;
1678-
1679-
switch (dir) {
1680-
case DMA_BIDIRECTIONAL:
1681-
prot = IOMMU_READ | IOMMU_WRITE;
1682-
break;
1683-
case DMA_TO_DEVICE:
1684-
prot = IOMMU_READ;
1685-
break;
1686-
case DMA_FROM_DEVICE:
1687-
prot = IOMMU_WRITE;
1688-
break;
1689-
default:
1690-
prot = 0;
1691-
}
1692-
1693-
return prot;
1694-
}
1695-
16961696
/*
16971697
* Map a part of the scatter-gather list into contiguous io address space
16981698
*/
@@ -1722,7 +1722,7 @@ static int __map_sg_chunk(struct device *dev, struct scatterlist *sg,
17221722
if (!is_coherent && (attrs & DMA_ATTR_SKIP_CPU_SYNC) == 0)
17231723
__dma_page_cpu_to_dev(sg_page(s), s->offset, s->length, dir);
17241724

1725-
prot = __dma_direction_to_prot(dir);
1725+
prot = __dma_info_to_prot(dir, attrs);
17261726

17271727
ret = iommu_map(mapping->domain, iova, phys, len, prot);
17281728
if (ret < 0)
@@ -1930,7 +1930,7 @@ static dma_addr_t arm_coherent_iommu_map_page(struct device *dev, struct page *p
19301930
if (dma_addr == DMA_ERROR_CODE)
19311931
return dma_addr;
19321932

1933-
prot = __dma_direction_to_prot(dir);
1933+
prot = __dma_info_to_prot(dir, attrs);
19341934

19351935
ret = iommu_map(mapping->domain, dma_addr, page_to_phys(page), len, prot);
19361936
if (ret < 0)
@@ -2036,7 +2036,7 @@ static dma_addr_t arm_iommu_map_resource(struct device *dev,
20362036
if (dma_addr == DMA_ERROR_CODE)
20372037
return dma_addr;
20382038

2039-
prot = __dma_direction_to_prot(dir) | IOMMU_MMIO;
2039+
prot = __dma_info_to_prot(dir, attrs) | IOMMU_MMIO;
20402040

20412041
ret = iommu_map(mapping->domain, dma_addr, addr, len, prot);
20422042
if (ret < 0)

arch/arm64/mm/dma-mapping.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ static void *__iommu_alloc_attrs(struct device *dev, size_t size,
558558
unsigned long attrs)
559559
{
560560
bool coherent = is_device_dma_coherent(dev);
561-
int ioprot = dma_direction_to_prot(DMA_BIDIRECTIONAL, coherent);
561+
int ioprot = dma_info_to_prot(DMA_BIDIRECTIONAL, coherent, attrs);
562562
size_t iosize = size;
563563
void *addr;
564564

@@ -712,7 +712,7 @@ static dma_addr_t __iommu_map_page(struct device *dev, struct page *page,
712712
unsigned long attrs)
713713
{
714714
bool coherent = is_device_dma_coherent(dev);
715-
int prot = dma_direction_to_prot(dir, coherent);
715+
int prot = dma_info_to_prot(dir, coherent, attrs);
716716
dma_addr_t dev_addr = iommu_dma_map_page(dev, page, offset, size, prot);
717717

718718
if (!iommu_dma_mapping_error(dev, dev_addr) &&
@@ -770,7 +770,7 @@ static int __iommu_map_sg_attrs(struct device *dev, struct scatterlist *sgl,
770770
__iommu_sync_sg_for_device(dev, sgl, nelems, dir);
771771

772772
return iommu_dma_map_sg(dev, sgl, nelems,
773-
dma_direction_to_prot(dir, coherent));
773+
dma_info_to_prot(dir, coherent, attrs));
774774
}
775775

776776
static void __iommu_unmap_sg_attrs(struct device *dev,
@@ -799,7 +799,6 @@ static struct dma_map_ops iommu_dma_ops = {
799799
.sync_sg_for_device = __iommu_sync_sg_for_device,
800800
.map_resource = iommu_dma_map_resource,
801801
.unmap_resource = iommu_dma_unmap_resource,
802-
.dma_supported = iommu_dma_supported,
803802
.mapping_error = iommu_dma_mapping_error,
804803
};
805804

drivers/acpi/arm64/iort.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ static const struct iommu_ops *iort_iommu_xlate(struct device *dev,
536536
if (!iort_fwnode)
537537
return NULL;
538538

539-
ops = iommu_get_instance(iort_fwnode);
539+
ops = iommu_ops_from_fwnode(iort_fwnode);
540540
if (!ops)
541541
return NULL;
542542

drivers/dma/pl330.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1859,9 +1859,10 @@ static int dmac_alloc_resources(struct pl330_dmac *pl330)
18591859
* Alloc MicroCode buffer for 'chans' Channel threads.
18601860
* A channel's buffer offset is (Channel_Id * MCODE_BUFF_PERCHAN)
18611861
*/
1862-
pl330->mcode_cpu = dma_alloc_coherent(pl330->ddma.dev,
1862+
pl330->mcode_cpu = dma_alloc_attrs(pl330->ddma.dev,
18631863
chans * pl330->mcbufsz,
1864-
&pl330->mcode_bus, GFP_KERNEL);
1864+
&pl330->mcode_bus, GFP_KERNEL,
1865+
DMA_ATTR_PRIVILEGED);
18651866
if (!pl330->mcode_cpu) {
18661867
dev_err(pl330->ddma.dev, "%s:%d Can't allocate memory!\n",
18671868
__func__, __LINE__);

drivers/iommu/Kconfig

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,6 @@ config MTK_IOMMU_V1
352352
select IOMMU_API
353353
select MEMORY
354354
select MTK_SMI
355-
select COMMON_CLK_MT2701_MMSYS
356-
select COMMON_CLK_MT2701_IMGSYS
357-
select COMMON_CLK_MT2701_VDECSYS
358355
help
359356
Support for the M4U on certain Mediatek SoCs. M4U generation 1 HW is
360357
Multimedia Memory Managememt Unit. This option enables remapping of

0 commit comments

Comments
 (0)