Skip to content

Commit 2726bf3

Browse files
ffainellikonradwilk
authored andcommitted
swiotlb: Make SWIOTLB_NO_FORCE perform no allocation
When SWIOTLB_NO_FORCE is used, there should really be no allocations of default_nslabs to occur since we are not going to use those slabs. If a platform was somehow setting swiotlb_no_force and a later call to swiotlb_init() was to be made we would still be proceeding with allocating the default SWIOTLB size (64MB), whereas if swiotlb=noforce was set on the kernel command line we would have only allocated 2KB. This would be inconsistent and the point of initializing default_nslabs to 1, was intended to allocate the minimum amount of memory possible, so simply remove that minimal allocation period. Signed-off-by: Florian Fainelli <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Konrad Rzeszutek Wilk <[email protected]>
1 parent fcf0448 commit 2726bf3

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

kernel/dma/swiotlb.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,10 @@ setup_io_tlb_npages(char *str)
8383
}
8484
if (*str == ',')
8585
++str;
86-
if (!strcmp(str, "force")) {
86+
if (!strcmp(str, "force"))
8787
swiotlb_force = SWIOTLB_FORCE;
88-
} else if (!strcmp(str, "noforce")) {
88+
else if (!strcmp(str, "noforce"))
8989
swiotlb_force = SWIOTLB_NO_FORCE;
90-
default_nslabs = 1;
91-
}
9290

9391
return 0;
9492
}
@@ -174,6 +172,9 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
174172
struct io_tlb_mem *mem;
175173
size_t alloc_size;
176174

175+
if (swiotlb_force == SWIOTLB_NO_FORCE)
176+
return 0;
177+
177178
/* protect against double initialization */
178179
if (WARN_ON_ONCE(io_tlb_default_mem))
179180
return -ENOMEM;
@@ -211,6 +212,9 @@ swiotlb_init(int verbose)
211212
size_t bytes = PAGE_ALIGN(default_nslabs << IO_TLB_SHIFT);
212213
void *tlb;
213214

215+
if (swiotlb_force == SWIOTLB_NO_FORCE)
216+
return;
217+
214218
/* Get IO TLB memory from the low pages */
215219
tlb = memblock_alloc_low(bytes, PAGE_SIZE);
216220
if (!tlb)
@@ -240,6 +244,9 @@ swiotlb_late_init_with_default_size(size_t default_size)
240244
unsigned int order;
241245
int rc = 0;
242246

247+
if (swiotlb_force == SWIOTLB_NO_FORCE)
248+
return 0;
249+
243250
/*
244251
* Get IO TLB memory from the low pages
245252
*/
@@ -276,6 +283,9 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
276283
unsigned long bytes = nslabs << IO_TLB_SHIFT, i;
277284
struct io_tlb_mem *mem;
278285

286+
if (swiotlb_force == SWIOTLB_NO_FORCE)
287+
return 0;
288+
279289
/* protect against double initialization */
280290
if (WARN_ON_ONCE(io_tlb_default_mem))
281291
return -ENOMEM;

0 commit comments

Comments
 (0)