Skip to content

Commit 639205e

Browse files
rmurphy-armChristoph Hellwig
authored andcommitted
swiotlb: don't panic!
The panics in swiotlb are relics of a bygone era, some of them inadvertently inherited from a memblock refactor, and all of them unnecessary since they are in places that may also fail gracefully anyway. Convert the panics in swiotlb_init_remap() into non-fatal warnings more consistent with the other bail-out paths there and in swiotlb_init_late() (but don't bother trying to roll anything back, since if anything does actually fail that early, the aim is merely to keep going as far as possible to get more diagnostic information out of the inevitably-dying kernel). It's not for SWIOTLB to decide that the system is terminally compromised just because there *might* turn out to be one or more 32-bit devices that might want to make streaming DMA mappings, especially since we already handle the no-buffer case later if it turns out someone did want it. Similarly though, downgrade that panic in swiotlb_tbl_map_single(), since even if we do get to that point it's an overly extreme reaction. It makes little difference to the DMA API caller whether a mapping fails because the buffer is full or because there is no buffer, and once again it's not for SWIOTLB to presume that any particular DMA mapping is so fundamental to the operation of the system that it must be terminal if it could never succeed. Even if the caller handles failure by futilely retrying forever, a single stuck thread is considerably less impactful to the user than a needless panic. Signed-off-by: Robin Murphy <robin.murphy@arm.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
1 parent 1d61261 commit 639205e

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

kernel/dma/swiotlb.c

Lines changed: 19 additions & 11 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);
@@ -729,8 +734,11 @@ phys_addr_t swiotlb_tbl_map_single(struct device *dev, phys_addr_t orig_addr,
729734
int index;
730735
phys_addr_t tlb_addr;
731736

732-
if (!mem || !mem->nslabs)
733-
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+
}
734742

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

0 commit comments

Comments
 (0)