Skip to content

Commit 10b22b5

Browse files
committed
Merge tag 'dma-mapping-6.1-2022-10-10' of git://git.infradead.org/users/hch/dma-mapping
Pull dma-mapping updates from Christoph Hellwig: - fix a regression in the ARM dma-direct conversion (Christoph Hellwig) - use memcpy_{from,to}_page (Fabio M. De Francesco) - cleanup the swiotlb MAINTAINERS entry (Lukas Bulwahn) - make SG table pool allocation less fragile (Masahiro Yamada) - don't panic on swiotlb initialization failure (Robin Murphy) * tag 'dma-mapping-6.1-2022-10-10' of git://git.infradead.org/users/hch/dma-mapping: ARM/dma-mapping: remove the dma_coherent member of struct dev_archdata ARM/dma-mappіng: don't override ->dma_coherent when set from a bus notifier lib/sg_pool: change module_init(sg_pool_init) to subsys_initcall MAINTAINERS: merge SWIOTLB SUBSYSTEM into DMA MAPPING HELPERS swiotlb: don't panic! swiotlb: replace kmap_atomic() with memcpy_{from,to}_page()
2 parents f23cdfc + c9cb013 commit 10b22b5

File tree

5 files changed

+38
-46
lines changed

5 files changed

+38
-46
lines changed

MAINTAINERS

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6171,6 +6171,7 @@ F: include/asm-generic/dma-mapping.h
61716171
F: include/linux/dma-direct.h
61726172
F: include/linux/dma-mapping.h
61736173
F: include/linux/dma-map-ops.h
6174+
F: include/linux/swiotlb.h
61746175
F: kernel/dma/
61756176

61766177
DMA MAPPING BENCHMARK
@@ -19749,16 +19750,6 @@ S: Maintained
1974919750
F: Documentation/admin-guide/svga.rst
1975019751
F: arch/x86/boot/video*
1975119752

19752-
SWIOTLB SUBSYSTEM
19753-
M: Christoph Hellwig <[email protected]>
19754-
19755-
S: Supported
19756-
W: http://git.infradead.org/users/hch/dma-mapping.git
19757-
T: git git://git.infradead.org/users/hch/dma-mapping.git
19758-
F: arch/*/kernel/pci-swiotlb.c
19759-
F: include/linux/swiotlb.h
19760-
F: kernel/dma/swiotlb.c
19761-
1976219753
SWITCHDEV
1976319754
M: Jiri Pirko <[email protected]>
1976419755
M: Ivan Vecera <[email protected]>
@@ -22475,8 +22466,10 @@ M: Stefano Stabellini <[email protected]>
2247522466
L: [email protected] (moderated for non-subscribers)
2247622467
2247722468
S: Supported
22478-
F: arch/x86/xen/*swiotlb*
22479-
F: drivers/xen/*swiotlb*
22469+
F: arch/*/include/asm/xen/swiotlb-xen.h
22470+
F: drivers/xen/swiotlb-xen.c
22471+
F: include/xen/arm/swiotlb-xen.h
22472+
F: include/xen/swiotlb-xen.h
2248022473

2248122474
XFS FILESYSTEM
2248222475
C: irc://irc.oftc.net/xfs

arch/arm/include/asm/device.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ struct dev_archdata {
99
#ifdef CONFIG_ARM_DMA_USE_IOMMU
1010
struct dma_iommu_mapping *mapping;
1111
#endif
12-
unsigned int dma_coherent:1;
1312
unsigned int dma_ops_setup:1;
1413
};
1514

arch/arm/mm/dma-mapping.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1769,8 +1769,14 @@ static void arm_teardown_iommu_dma_ops(struct device *dev) { }
17691769
void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size,
17701770
const struct iommu_ops *iommu, bool coherent)
17711771
{
1772-
dev->archdata.dma_coherent = coherent;
1773-
dev->dma_coherent = coherent;
1772+
/*
1773+
* Due to legacy code that sets the ->dma_coherent flag from a bus
1774+
* notifier we can't just assign coherent to the ->dma_coherent flag
1775+
* here, but instead have to make sure we only set but never clear it
1776+
* for now.
1777+
*/
1778+
if (coherent)
1779+
dev->dma_coherent = true;
17741780

17751781
/*
17761782
* Don't override the dma_ops if they have already been set. Ideally

kernel/dma/swiotlb.c

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -346,22 +346,27 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
346346
memblock_free(tlb, PAGE_ALIGN(bytes));
347347

348348
nslabs = ALIGN(nslabs >> 1, IO_TLB_SEGSIZE);
349-
if (nslabs < IO_TLB_MIN_SLABS)
350-
panic("%s: Failed to remap %zu bytes\n",
351-
__func__, bytes);
352-
goto retry;
349+
if (nslabs >= IO_TLB_MIN_SLABS)
350+
goto retry;
351+
352+
pr_warn("%s: Failed to remap %zu bytes\n", __func__, bytes);
353+
return;
353354
}
354355

355356
alloc_size = PAGE_ALIGN(array_size(sizeof(*mem->slots), nslabs));
356357
mem->slots = memblock_alloc(alloc_size, PAGE_SIZE);
357-
if (!mem->slots)
358-
panic("%s: Failed to allocate %zu bytes align=0x%lx\n",
359-
__func__, alloc_size, PAGE_SIZE);
358+
if (!mem->slots) {
359+
pr_warn("%s: Failed to allocate %zu bytes align=0x%lx\n",
360+
__func__, alloc_size, PAGE_SIZE);
361+
return;
362+
}
360363

361364
mem->areas = memblock_alloc(array_size(sizeof(struct io_tlb_area),
362365
default_nareas), SMP_CACHE_BYTES);
363-
if (!mem->areas)
364-
panic("%s: Failed to allocate mem->areas.\n", __func__);
366+
if (!mem->areas) {
367+
pr_warn("%s: Failed to allocate mem->areas.\n", __func__);
368+
return;
369+
}
365370

366371
swiotlb_init_io_tlb_mem(mem, __pa(tlb), nslabs, flags, false,
367372
default_nareas);
@@ -545,22 +550,20 @@ static void swiotlb_bounce(struct device *dev, phys_addr_t tlb_addr, size_t size
545550
}
546551

547552
if (PageHighMem(pfn_to_page(pfn))) {
548-
/* The buffer does not have a mapping. Map it in and copy */
549553
unsigned int offset = orig_addr & ~PAGE_MASK;
550-
char *buffer;
554+
struct page *page;
551555
unsigned int sz = 0;
552556
unsigned long flags;
553557

554558
while (size) {
555559
sz = min_t(size_t, PAGE_SIZE - offset, size);
556560

557561
local_irq_save(flags);
558-
buffer = kmap_atomic(pfn_to_page(pfn));
562+
page = pfn_to_page(pfn);
559563
if (dir == DMA_TO_DEVICE)
560-
memcpy(vaddr, buffer + offset, sz);
564+
memcpy_from_page(vaddr, page, offset, sz);
561565
else
562-
memcpy(buffer + offset, vaddr, sz);
563-
kunmap_atomic(buffer);
566+
memcpy_to_page(page, offset, vaddr, sz);
564567
local_irq_restore(flags);
565568

566569
size -= sz;
@@ -731,8 +734,11 @@ phys_addr_t swiotlb_tbl_map_single(struct device *dev, phys_addr_t orig_addr,
731734
int index;
732735
phys_addr_t tlb_addr;
733736

734-
if (!mem || !mem->nslabs)
735-
panic("Can not allocate SWIOTLB buffer earlier and can't now provide you with the DMA bounce buffer");
737+
if (!mem || !mem->nslabs) {
738+
dev_warn_ratelimited(dev,
739+
"Can not allocate SWIOTLB buffer earlier and can't now provide you with the DMA bounce buffer");
740+
return (phys_addr_t)DMA_MAPPING_ERROR;
741+
}
736742

737743
if (cc_platform_has(CC_ATTR_MEM_ENCRYPT))
738744
pr_warn_once("Memory encryption is active and system is using DMA bounce buffers\n");

lib/sg_pool.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: GPL-2.0-only
2-
#include <linux/module.h>
2+
#include <linux/init.h>
33
#include <linux/scatterlist.h>
44
#include <linux/mempool.h>
55
#include <linux/slab.h>
@@ -177,16 +177,4 @@ static __init int sg_pool_init(void)
177177
return -ENOMEM;
178178
}
179179

180-
static __exit void sg_pool_exit(void)
181-
{
182-
int i;
183-
184-
for (i = 0; i < SG_MEMPOOL_NR; i++) {
185-
struct sg_pool *sgp = sg_pools + i;
186-
mempool_destroy(sgp->pool);
187-
kmem_cache_destroy(sgp->slab);
188-
}
189-
}
190-
191-
module_init(sg_pool_init);
192-
module_exit(sg_pool_exit);
180+
subsys_initcall(sg_pool_init);

0 commit comments

Comments
 (0)