Skip to content

Commit 62708b2

Browse files
Petr TesarikChristoph Hellwig
authored andcommitted
swiotlb: add a flag whether SWIOTLB is allowed to grow
Add a config option (CONFIG_SWIOTLB_DYNAMIC) to enable or disable dynamic allocation of additional bounce buffers. If this option is set, mark the default SWIOTLB as able to grow and restricted DMA pools as unable. However, if the address of the default memory pool is explicitly queried, make the default SWIOTLB also unable to grow. This is currently used to set up PCI BAR movable regions on some Octeon MIPS boards which may not be able to use a SWIOTLB pool elsewhere in physical memory. See octeon_pci_setup() for more details. If a remap function is specified, it must be also called on any dynamically allocated pools, but there are some issues: - The remap function may block, so it should not be called from an atomic context. - There is no corresponding unremap() function if the memory pool is freed. - The only in-tree implementation (xen_swiotlb_fixup) requires that the number of slots in the memory pool is a multiple of SWIOTLB_SEGSIZE. Keep it simple for now and disable growing the SWIOTLB if a remap function was specified. Signed-off-by: Petr Tesarik <petr.tesarik.ext@huawei.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
1 parent 158dbe9 commit 62708b2

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

include/linux/swiotlb.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ struct io_tlb_pool {
100100
* @debugfs: The dentry to debugfs.
101101
* @force_bounce: %true if swiotlb bouncing is forced
102102
* @for_alloc: %true if the pool is used for memory allocation
103+
* @can_grow: %true if more pools can be allocated dynamically.
103104
* @total_used: The total number of slots in the pool that are currently used
104105
* across all areas. Used only for calculating used_hiwater in
105106
* debugfs.
@@ -112,6 +113,9 @@ struct io_tlb_mem {
112113
struct dentry *debugfs;
113114
bool force_bounce;
114115
bool for_alloc;
116+
#ifdef CONFIG_SWIOTLB_DYNAMIC
117+
bool can_grow;
118+
#endif
115119
#ifdef CONFIG_DEBUG_FS
116120
atomic_long_t total_used;
117121
atomic_long_t used_hiwater;

kernel/dma/Kconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,19 @@ config SWIOTLB
9090
bool
9191
select NEED_DMA_MAP_STATE
9292

93+
config SWIOTLB_DYNAMIC
94+
bool "Dynamic allocation of DMA bounce buffers"
95+
default n
96+
depends on SWIOTLB
97+
help
98+
This enables dynamic resizing of the software IO TLB. The kernel
99+
starts with one memory pool at boot and it will allocate additional
100+
pools as needed. To reduce run-time kernel memory requirements, you
101+
may have to specify a smaller size of the initial pool using
102+
"swiotlb=" on the kernel command line.
103+
104+
If unsure, say N.
105+
93106
config DMA_BOUNCE_UNALIGNED_KMALLOC
94107
bool
95108
depends on SWIOTLB

kernel/dma/swiotlb.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,11 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
330330
io_tlb_default_mem.force_bounce =
331331
swiotlb_force_bounce || (flags & SWIOTLB_FORCE);
332332

333+
#ifdef CONFIG_SWIOTLB_DYNAMIC
334+
if (!remap)
335+
io_tlb_default_mem.can_grow = true;
336+
#endif
337+
333338
if (!default_nareas)
334339
swiotlb_adjust_nareas(num_possible_cpus());
335340

@@ -400,6 +405,11 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,
400405

401406
io_tlb_default_mem.force_bounce = swiotlb_force_bounce;
402407

408+
#ifdef CONFIG_SWIOTLB_DYNAMIC
409+
if (!remap)
410+
io_tlb_default_mem.can_grow = true;
411+
#endif
412+
403413
if (!default_nareas)
404414
swiotlb_adjust_nareas(num_possible_cpus());
405415

@@ -1073,6 +1083,9 @@ bool is_swiotlb_active(struct device *dev)
10731083
*/
10741084
phys_addr_t default_swiotlb_base(void)
10751085
{
1086+
#ifdef CONFIG_SWIOTLB_DYNAMIC
1087+
io_tlb_default_mem.can_grow = false;
1088+
#endif
10761089
return io_tlb_default_mem.defpool.start;
10771090
}
10781091

0 commit comments

Comments
 (0)