Skip to content

Commit af7ddd8

Browse files
committed
Merge tag 'dma-mapping-4.21' of git://git.infradead.org/users/hch/dma-mapping
Pull DMA mapping updates from Christoph Hellwig: "A huge update this time, but a lot of that is just consolidating or removing code: - provide a common DMA_MAPPING_ERROR definition and avoid indirect calls for dma_map_* error checking - use direct calls for the DMA direct mapping case, avoiding huge retpoline overhead for high performance workloads - merge the swiotlb dma_map_ops into dma-direct - provide a generic remapping DMA consistent allocator for architectures that have devices that perform DMA that is not cache coherent. Based on the existing arm64 implementation and also used for csky now. - improve the dma-debug infrastructure, including dynamic allocation of entries (Robin Murphy) - default to providing chaining scatterlist everywhere, with opt-outs for the few architectures (alpha, parisc, most arm32 variants) that can't cope with it - misc sparc32 dma-related cleanups - remove the dma_mark_clean arch hook used by swiotlb on ia64 and replace it with the generic noncoherent infrastructure - fix the return type of dma_set_max_seg_size (Niklas Söderlund) - move the dummy dma ops for not DMA capable devices from arm64 to common code (Robin Murphy) - ensure dma_alloc_coherent returns zeroed memory to avoid kernel data leaks through userspace. We already did this for most common architectures, but this ensures we do it everywhere. dma_zalloc_coherent has been deprecated and can hopefully be removed after -rc1 with a coccinelle script" * tag 'dma-mapping-4.21' of git://git.infradead.org/users/hch/dma-mapping: (73 commits) dma-mapping: fix inverted logic in dma_supported dma-mapping: deprecate dma_zalloc_coherent dma-mapping: zero memory returned from dma_alloc_* sparc/iommu: fix ->map_sg return value sparc/io-unit: fix ->map_sg return value arm64: default to the direct mapping in get_arch_dma_ops PCI: Remove unused attr variable in pci_dma_configure ia64: only select ARCH_HAS_DMA_COHERENT_TO_PFN if swiotlb is enabled dma-mapping: bypass indirect calls for dma-direct vmd: use the proper dma_* APIs instead of direct methods calls dma-direct: merge swiotlb_dma_ops into the dma_direct code dma-direct: use dma_direct_map_page to implement dma_direct_map_sg dma-direct: improve addressability error reporting swiotlb: remove dma_mark_clean swiotlb: remove SWIOTLB_MAP_ERROR ACPI / scan: Refactor _CCA enforcement dma-mapping: factor out dummy DMA ops dma-mapping: always build the direct mapping code dma-mapping: move dma_cache_sync out of line dma-mapping: move various slow path functions out of line ...
2 parents fe2b0cd + 8b1cce9 commit af7ddd8

112 files changed

Lines changed: 1408 additions & 2340 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Documentation/DMA-API.txt‎

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,6 @@ specify the ``GFP_`` flags (see kmalloc()) for the allocation (the
5858
implementation may choose to ignore flags that affect the location of
5959
the returned memory, like GFP_DMA).
6060

61-
::
62-
63-
void *
64-
dma_zalloc_coherent(struct device *dev, size_t size,
65-
dma_addr_t *dma_handle, gfp_t flag)
66-
67-
Wraps dma_alloc_coherent() and also zeroes the returned memory if the
68-
allocation attempt succeeded.
69-
7061
::
7162

7263
void
@@ -717,12 +708,15 @@ dma-api/num_errors The number in this file shows how many
717708
dma-api/min_free_entries This read-only file can be read to get the
718709
minimum number of free dma_debug_entries the
719710
allocator has ever seen. If this value goes
720-
down to zero the code will disable itself
721-
because it is not longer reliable.
711+
down to zero the code will attempt to increase
712+
nr_total_entries to compensate.
722713

723714
dma-api/num_free_entries The current number of free dma_debug_entries
724715
in the allocator.
725716

717+
dma-api/nr_total_entries The total number of dma_debug_entries in the
718+
allocator, both free and used.
719+
726720
dma-api/driver-filter You can write a name of a driver into this file
727721
to limit the debug output to requests from that
728722
particular driver. Write an empty string to
@@ -742,10 +736,15 @@ driver filter at boot time. The debug code will only print errors for that
742736
driver afterwards. This filter can be disabled or changed later using debugfs.
743737

744738
When the code disables itself at runtime this is most likely because it ran
745-
out of dma_debug_entries. These entries are preallocated at boot. The number
746-
of preallocated entries is defined per architecture. If it is too low for you
747-
boot with 'dma_debug_entries=<your_desired_number>' to overwrite the
748-
architectural default.
739+
out of dma_debug_entries and was unable to allocate more on-demand. 65536
740+
entries are preallocated at boot - if this is too low for you boot with
741+
'dma_debug_entries=<your_desired_number>' to overwrite the default. Note
742+
that the code allocates entries in batches, so the exact number of
743+
preallocated entries may be greater than the actual number requested. The
744+
code will print to the kernel log each time it has dynamically allocated
745+
as many entries as were initially preallocated. This is to indicate that a
746+
larger preallocation size may be appropriate, or if it happens continually
747+
that a driver may be leaking mappings.
749748

750749
::
751750

‎Documentation/features/io/sg-chain/arch-support.txt‎

Lines changed: 0 additions & 33 deletions
This file was deleted.

‎Documentation/x86/x86_64/boot-options.txt‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ IOMMU (input/output memory management unit)
209209
mapping with memory protection, etc.
210210
Kernel boot message: "PCI-DMA: Using Calgary IOMMU"
211211

212-
iommu=[<size>][,noagp][,off][,force][,noforce][,leak[=<nr_of_leak_pages>]
212+
iommu=[<size>][,noagp][,off][,force][,noforce]
213213
[,memaper[=<order>]][,merge][,fullflush][,nomerge]
214214
[,noaperture][,calgary]
215215

@@ -228,9 +228,6 @@ IOMMU (input/output memory management unit)
228228
allowed Overwrite iommu off workarounds for specific chipsets.
229229
fullflush Flush IOMMU on each allocation (default).
230230
nofullflush Don't use IOMMU fullflush.
231-
leak Turn on simple iommu leak tracing (only when
232-
CONFIG_IOMMU_LEAK is on). Default number of leak pages
233-
is 20.
234231
memaper[=<order>] Allocate an own aperture over RAM with size 32MB<<order.
235232
(default: order=1, i.e. 64MB)
236233
merge Do scatter-gather (SG) merging. Implies "force"

‎arch/alpha/Kconfig‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ config ALPHA
55
select ARCH_MIGHT_HAVE_PC_PARPORT
66
select ARCH_MIGHT_HAVE_PC_SERIO
77
select ARCH_NO_PREEMPT
8+
select ARCH_NO_SG_CHAIN
89
select ARCH_USE_CMPXCHG_LOCKREF
910
select HAVE_AOUT
1011
select HAVE_IDE
@@ -202,7 +203,6 @@ config ALPHA_EIGER
202203
config ALPHA_JENSEN
203204
bool "Jensen"
204205
depends on BROKEN
205-
select DMA_DIRECT_OPS
206206
help
207207
DEC PC 150 AXP (aka Jensen): This is a very old Digital system - one
208208
of the first-generation Alpha systems. A number of these systems

‎arch/alpha/include/asm/dma-mapping.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extern const struct dma_map_ops alpha_pci_ops;
77
static inline const struct dma_map_ops *get_arch_dma_ops(struct bus_type *bus)
88
{
99
#ifdef CONFIG_ALPHA_JENSEN
10-
return &dma_direct_ops;
10+
return NULL;
1111
#else
1212
return &alpha_pci_ops;
1313
#endif

‎arch/alpha/kernel/pci_iommu.c‎

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ pci_map_single_1(struct pci_dev *pdev, void *cpu_addr, size_t size,
291291
use direct_map above, it now must be considered an error. */
292292
if (! alpha_mv.mv_pci_tbi) {
293293
printk_once(KERN_WARNING "pci_map_single: no HW sg\n");
294-
return 0;
294+
return DMA_MAPPING_ERROR;
295295
}
296296

297297
arena = hose->sg_pci;
@@ -307,7 +307,7 @@ pci_map_single_1(struct pci_dev *pdev, void *cpu_addr, size_t size,
307307
if (dma_ofs < 0) {
308308
printk(KERN_WARNING "pci_map_single failed: "
309309
"could not allocate dma page tables\n");
310-
return 0;
310+
return DMA_MAPPING_ERROR;
311311
}
312312

313313
paddr &= PAGE_MASK;
@@ -443,7 +443,7 @@ static void *alpha_pci_alloc_coherent(struct device *dev, size_t size,
443443
gfp &= ~GFP_DMA;
444444

445445
try_again:
446-
cpu_addr = (void *)__get_free_pages(gfp, order);
446+
cpu_addr = (void *)__get_free_pages(gfp | __GFP_ZERO, order);
447447
if (! cpu_addr) {
448448
printk(KERN_INFO "pci_alloc_consistent: "
449449
"get_free_pages failed from %pf\n",
@@ -455,7 +455,7 @@ static void *alpha_pci_alloc_coherent(struct device *dev, size_t size,
455455
memset(cpu_addr, 0, size);
456456

457457
*dma_addrp = pci_map_single_1(pdev, cpu_addr, size, 0);
458-
if (*dma_addrp == 0) {
458+
if (*dma_addrp == DMA_MAPPING_ERROR) {
459459
free_pages((unsigned long)cpu_addr, order);
460460
if (alpha_mv.mv_pci_tbi || (gfp & GFP_DMA))
461461
return NULL;
@@ -671,7 +671,7 @@ static int alpha_pci_map_sg(struct device *dev, struct scatterlist *sg,
671671
sg->dma_address
672672
= pci_map_single_1(pdev, SG_ENT_VIRT_ADDRESS(sg),
673673
sg->length, dac_allowed);
674-
return sg->dma_address != 0;
674+
return sg->dma_address != DMA_MAPPING_ERROR;
675675
}
676676

677677
start = sg;
@@ -935,19 +935,13 @@ iommu_unbind(struct pci_iommu_arena *arena, long pg_start, long pg_count)
935935
return 0;
936936
}
937937

938-
static int alpha_pci_mapping_error(struct device *dev, dma_addr_t dma_addr)
939-
{
940-
return dma_addr == 0;
941-
}
942-
943938
const struct dma_map_ops alpha_pci_ops = {
944939
.alloc = alpha_pci_alloc_coherent,
945940
.free = alpha_pci_free_coherent,
946941
.map_page = alpha_pci_map_page,
947942
.unmap_page = alpha_pci_unmap_page,
948943
.map_sg = alpha_pci_map_sg,
949944
.unmap_sg = alpha_pci_unmap_sg,
950-
.mapping_error = alpha_pci_mapping_error,
951945
.dma_supported = alpha_pci_supported,
952946
};
953947
EXPORT_SYMBOL(alpha_pci_ops);

‎arch/arc/Kconfig‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,10 @@ config ARC
1313
select ARCH_HAS_PTE_SPECIAL
1414
select ARCH_HAS_SYNC_DMA_FOR_CPU
1515
select ARCH_HAS_SYNC_DMA_FOR_DEVICE
16-
select ARCH_HAS_SG_CHAIN
1716
select ARCH_SUPPORTS_ATOMIC_RMW if ARC_HAS_LLSC
1817
select BUILDTIME_EXTABLE_SORT
1918
select CLONE_BACKWARDS
2019
select COMMON_CLK
21-
select DMA_DIRECT_OPS
2220
select GENERIC_ATOMIC64 if !ISA_ARCV2 || !(ARC_HAS_LL64 && ARC_HAS_LLSC)
2321
select GENERIC_CLOCKEVENTS
2422
select GENERIC_FIND_FIRST_BIT

‎arch/arc/mm/cache.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,7 @@ void __init arc_cache_init_master(void)
12941294
/*
12951295
* In case of IOC (say IOC+SLC case), pointers above could still be set
12961296
* but end up not being relevant as the first function in chain is not
1297-
* called at all for @dma_direct_ops
1297+
* called at all for devices using coherent DMA.
12981298
* arch_sync_dma_for_cpu() -> dma_cache_*() -> __dma_cache_*()
12991299
*/
13001300
}

‎arch/arc/mm/dma.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void *arch_dma_alloc(struct device *dev, size_t size, dma_addr_t *dma_handle,
3333
*/
3434
BUG_ON(gfp & __GFP_HIGHMEM);
3535

36-
page = alloc_pages(gfp, order);
36+
page = alloc_pages(gfp | __GFP_ZERO, order);
3737
if (!page)
3838
return NULL;
3939

‎arch/arm/Kconfig‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ config ARM
1919
select ARCH_HAVE_CUSTOM_GPIO_H
2020
select ARCH_HAS_GCOV_PROFILE_ALL
2121
select ARCH_MIGHT_HAVE_PC_PARPORT
22+
select ARCH_NO_SG_CHAIN if !ARM_HAS_SG_CHAIN
2223
select ARCH_OPTIONAL_KERNEL_RWX if ARCH_HAS_STRICT_KERNEL_RWX
2324
select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT if CPU_V7
2425
select ARCH_SUPPORTS_ATOMIC_RMW
@@ -29,7 +30,7 @@ config ARM
2930
select CLONE_BACKWARDS
3031
select CPU_PM if (SUSPEND || CPU_IDLE)
3132
select DCACHE_WORD_ACCESS if HAVE_EFFICIENT_UNALIGNED_ACCESS
32-
select DMA_DIRECT_OPS if !MMU
33+
select DMA_REMAP if MMU
3334
select EDAC_SUPPORT
3435
select EDAC_ATOMIC_SCRUB
3536
select GENERIC_ALLOCATOR
@@ -118,7 +119,6 @@ config ARM
118119
<http://www.arm.linux.org.uk/>.
119120

120121
config ARM_HAS_SG_CHAIN
121-
select ARCH_HAS_SG_CHAIN
122122
bool
123123

124124
config ARM_DMA_USE_IOMMU

0 commit comments

Comments
 (0)