Skip to content

Commit 726e2d0

Browse files
committed
Merge tag 'dma-mapping-6.12-2024-09-19' of git://git.infradead.org/users/hch/dma-mapping
Pull dma-mapping updates from Christoph Hellwig: - support DMA zones for arm64 systems where memory starts at > 4GB (Baruch Siach, Catalin Marinas) - support direct calls into dma-iommu and thus obsolete dma_map_ops for many common configurations (Leon Romanovsky) - add DMA-API tracing (Sean Anderson) - remove the not very useful return value from various dma_set_* APIs (Christoph Hellwig) - misc cleanups and minor optimizations (Chen Y, Yosry Ahmed, Christoph Hellwig) * tag 'dma-mapping-6.12-2024-09-19' of git://git.infradead.org/users/hch/dma-mapping: dma-mapping: reflow dma_supported dma-mapping: reliably inform about DMA support for IOMMU dma-mapping: add tracing for dma-mapping API calls dma-mapping: use IOMMU DMA calls for common alloc/free page calls dma-direct: optimize page freeing when it is not addressable dma-mapping: clearly mark DMA ops as an architecture feature vdpa_sim: don't select DMA_OPS arm64: mm: keep low RAM dma zone dma-mapping: don't return errors from dma_set_max_seg_size dma-mapping: don't return errors from dma_set_seg_boundary dma-mapping: don't return errors from dma_set_min_align_mask scsi: check that busses support the DMA API before setting dma parameters arm64: mm: fix DMA zone when dma-ranges is missing dma-mapping: direct calls for dma-iommu dma-mapping: call ->unmap_page and ->unmap_sg unconditionally arm64: support DMA zone above 4GB dma-mapping: replace zone_dma_bits by zone_dma_limit dma-mapping: use bit masking to check VM_DMA_COHERENT
2 parents de848da + a5fb217 commit 726e2d0

File tree

49 files changed

+782
-226
lines changed

Some content is hidden

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

49 files changed

+782
-226
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11841,6 +11841,7 @@ T: git git://git.kernel.org/pub/scm/linux/kernel/git/iommu/linux.git
1184111841
F: drivers/iommu/dma-iommu.c
1184211842
F: drivers/iommu/dma-iommu.h
1184311843
F: drivers/iommu/iova.c
11844+
F: include/linux/iommu-dma.h
1184411845
F: include/linux/iova.h
1184511846

1184611847
IOMMU SUBSYSTEM

arch/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ config CPU_MITIGATIONS
1717
def_bool y
1818
endif
1919

20+
#
21+
# Selected by architectures that need custom DMA operations for e.g. legacy
22+
# IOMMUs not handled by dma-iommu. Drivers must never select this symbol.
23+
#
24+
config ARCH_HAS_DMA_OPS
25+
depends on HAS_DMA
26+
select DMA_OPS_HELPERS
27+
bool
28+
2029
menu "General architecture-dependent options"
2130

2231
config ARCH_HAS_SUBPAGE_FAULTS

arch/alpha/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ config ALPHA
44
default y
55
select ARCH_32BIT_USTAT_F_TINODE
66
select ARCH_HAS_CURRENT_STACK_POINTER
7+
select ARCH_HAS_DMA_OPS if PCI
78
select ARCH_MIGHT_HAVE_PC_PARPORT
89
select ARCH_MIGHT_HAVE_PC_SERIO
910
select ARCH_NO_PREEMPT
1011
select ARCH_NO_SG_CHAIN
1112
select ARCH_USE_CMPXCHG_LOCKREF
12-
select DMA_OPS if PCI
1313
select FORCE_PCI
1414
select PCI_DOMAINS if PCI
1515
select PCI_SYSCALL if PCI

arch/arm/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ config ARM
1010
select ARCH_HAS_CURRENT_STACK_POINTER
1111
select ARCH_HAS_DEBUG_VIRTUAL if MMU
1212
select ARCH_HAS_DMA_ALLOC if MMU
13+
select ARCH_HAS_DMA_OPS
1314
select ARCH_HAS_DMA_WRITE_COMBINE if !ARM_DMA_MEM_BUFFERABLE
1415
select ARCH_HAS_ELF_RANDOMIZE
1516
select ARCH_HAS_FORTIFY_SOURCE
@@ -54,7 +55,6 @@ config ARM
5455
select DCACHE_WORD_ACCESS if HAVE_EFFICIENT_UNALIGNED_ACCESS
5556
select DMA_DECLARE_COHERENT
5657
select DMA_GLOBAL_POOL if !MMU
57-
select DMA_OPS
5858
select DMA_NONCOHERENT_MMAP if MMU
5959
select EDAC_SUPPORT
6060
select EDAC_ATOMIC_SCRUB

arch/arm64/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ config ARM64
2424
select ARCH_HAS_CURRENT_STACK_POINTER
2525
select ARCH_HAS_DEBUG_VIRTUAL
2626
select ARCH_HAS_DEBUG_VM_PGTABLE
27+
select ARCH_HAS_DMA_OPS if XEN
2728
select ARCH_HAS_DMA_PREP_COHERENT
2829
select ARCH_HAS_ACPI_TABLE_UPGRADE if ACPI
2930
select ARCH_HAS_FAST_MULTIPLIER

arch/arm64/mm/init.c

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -114,36 +114,33 @@ static void __init arch_reserve_crashkernel(void)
114114
low_size, high);
115115
}
116116

117-
/*
118-
* Return the maximum physical address for a zone accessible by the given bits
119-
* limit. If DRAM starts above 32-bit, expand the zone to the maximum
120-
* available memory, otherwise cap it at 32-bit.
121-
*/
122-
static phys_addr_t __init max_zone_phys(unsigned int zone_bits)
117+
static phys_addr_t __init max_zone_phys(phys_addr_t zone_limit)
123118
{
124-
phys_addr_t zone_mask = DMA_BIT_MASK(zone_bits);
125-
phys_addr_t phys_start = memblock_start_of_DRAM();
126-
127-
if (phys_start > U32_MAX)
128-
zone_mask = PHYS_ADDR_MAX;
129-
else if (phys_start > zone_mask)
130-
zone_mask = U32_MAX;
119+
/**
120+
* Information we get from firmware (e.g. DT dma-ranges) describe DMA
121+
* bus constraints. Devices using DMA might have their own limitations.
122+
* Some of them rely on DMA zone in low 32-bit memory. Keep low RAM
123+
* DMA zone on platforms that have RAM there.
124+
*/
125+
if (memblock_start_of_DRAM() < U32_MAX)
126+
zone_limit = min(zone_limit, U32_MAX);
131127

132-
return min(zone_mask, memblock_end_of_DRAM() - 1) + 1;
128+
return min(zone_limit, memblock_end_of_DRAM() - 1) + 1;
133129
}
134130

135131
static void __init zone_sizes_init(void)
136132
{
137133
unsigned long max_zone_pfns[MAX_NR_ZONES] = {0};
138-
unsigned int __maybe_unused acpi_zone_dma_bits;
139-
unsigned int __maybe_unused dt_zone_dma_bits;
140-
phys_addr_t __maybe_unused dma32_phys_limit = max_zone_phys(32);
134+
phys_addr_t __maybe_unused acpi_zone_dma_limit;
135+
phys_addr_t __maybe_unused dt_zone_dma_limit;
136+
phys_addr_t __maybe_unused dma32_phys_limit =
137+
max_zone_phys(DMA_BIT_MASK(32));
141138

142139
#ifdef CONFIG_ZONE_DMA
143-
acpi_zone_dma_bits = fls64(acpi_iort_dma_get_max_cpu_address());
144-
dt_zone_dma_bits = fls64(of_dma_get_max_cpu_address(NULL));
145-
zone_dma_bits = min3(32U, dt_zone_dma_bits, acpi_zone_dma_bits);
146-
arm64_dma_phys_limit = max_zone_phys(zone_dma_bits);
140+
acpi_zone_dma_limit = acpi_iort_dma_get_max_cpu_address();
141+
dt_zone_dma_limit = of_dma_get_max_cpu_address(NULL);
142+
zone_dma_limit = min(dt_zone_dma_limit, acpi_zone_dma_limit);
143+
arm64_dma_phys_limit = max_zone_phys(zone_dma_limit);
147144
max_zone_pfns[ZONE_DMA] = PFN_DOWN(arm64_dma_phys_limit);
148145
#endif
149146
#ifdef CONFIG_ZONE_DMA32

arch/mips/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ config MIPS
88
select ARCH_HAS_CPU_FINALIZE_INIT
99
select ARCH_HAS_CURRENT_STACK_POINTER if !CC_IS_CLANG || CLANG_VERSION >= 140000
1010
select ARCH_HAS_DEBUG_VIRTUAL if !64BIT
11+
select ARCH_HAS_DMA_OPS if MACH_JAZZ
1112
select ARCH_HAS_FORTIFY_SOURCE
1213
select ARCH_HAS_KCOV
1314
select ARCH_HAS_NON_OVERLAPPING_ADDRESS_SPACE if !EVA
@@ -393,7 +394,6 @@ config MACH_JAZZ
393394
select ARC_PROMLIB
394395
select ARCH_MIGHT_HAVE_PC_PARPORT
395396
select ARCH_MIGHT_HAVE_PC_SERIO
396-
select DMA_OPS
397397
select FW_ARC
398398
select FW_ARC32
399399
select ARCH_MAY_HAVE_PC_FDC

arch/parisc/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ config PARISC
1010
select ARCH_WANT_FRAME_POINTERS
1111
select ARCH_HAS_CPU_CACHE_ALIASING
1212
select ARCH_HAS_DMA_ALLOC if PA11
13+
select ARCH_HAS_DMA_OPS
1314
select ARCH_HAS_ELF_RANDOMIZE
1415
select ARCH_HAS_STRICT_KERNEL_RWX
1516
select ARCH_HAS_STRICT_MODULE_RWX
@@ -23,7 +24,6 @@ config PARISC
2324
select ARCH_HAS_CACHE_LINE_SIZE
2425
select ARCH_HAS_DEBUG_VM_PGTABLE
2526
select HAVE_RELIABLE_STACKTRACE
26-
select DMA_OPS
2727
select RTC_CLASS
2828
select RTC_DRV_GENERIC
2929
select INIT_ALL_POSSIBLE

arch/powerpc/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ config PPC
133133
select ARCH_HAS_DEBUG_WX if STRICT_KERNEL_RWX
134134
select ARCH_HAS_DEVMEM_IS_ALLOWED
135135
select ARCH_HAS_DMA_MAP_DIRECT if PPC_PSERIES
136+
select ARCH_HAS_DMA_OPS if PPC64
136137
select ARCH_HAS_FORTIFY_SOURCE
137138
select ARCH_HAS_GCOV_PROFILE_ALL
138139
select ARCH_HAS_KCOV
@@ -185,7 +186,6 @@ config PPC
185186
select CPUMASK_OFFSTACK if NR_CPUS >= 8192
186187
select DCACHE_WORD_ACCESS if PPC64 && CPU_LITTLE_ENDIAN
187188
select DMA_OPS_BYPASS if PPC64
188-
select DMA_OPS if PPC64
189189
select DYNAMIC_FTRACE if FUNCTION_TRACER
190190
select EDAC_ATOMIC_SCRUB
191191
select EDAC_SUPPORT

arch/powerpc/mm/mem.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ static int __init mark_nonram_nosave(void)
216216
* everything else. GFP_DMA32 page allocations automatically fall back to
217217
* ZONE_DMA.
218218
*
219-
* By using 31-bit unconditionally, we can exploit zone_dma_bits to inform the
219+
* By using 31-bit unconditionally, we can exploit zone_dma_limit to inform the
220220
* generic DMA mapping code. 32-bit only devices (if not handled by an IOMMU
221221
* anyway) will take a first dip into ZONE_NORMAL and get otherwise served by
222222
* ZONE_DMA.
@@ -230,6 +230,7 @@ void __init paging_init(void)
230230
{
231231
unsigned long long total_ram = memblock_phys_mem_size();
232232
phys_addr_t top_of_ram = memblock_end_of_DRAM();
233+
int zone_dma_bits;
233234

234235
#ifdef CONFIG_HIGHMEM
235236
unsigned long v = __fix_to_virt(FIX_KMAP_END);
@@ -256,6 +257,8 @@ void __init paging_init(void)
256257
else
257258
zone_dma_bits = 31;
258259

260+
zone_dma_limit = DMA_BIT_MASK(zone_dma_bits);
261+
259262
#ifdef CONFIG_ZONE_DMA
260263
max_zone_pfns[ZONE_DMA] = min(max_low_pfn,
261264
1UL << (zone_dma_bits - PAGE_SHIFT));

0 commit comments

Comments
 (0)