Skip to content

Commit f3cbfd0

Browse files
Stefano Stabellinigregkh
authored andcommitted
swiotlb: fix "x86: Don't panic if can not alloc buffer for swiotlb"
commit e9696d2 upstream. kernel/dma/swiotlb.c:swiotlb_init gets called first and tries to allocate a buffer for the swiotlb. It does so by calling memblock_alloc_low(PAGE_ALIGN(bytes), PAGE_SIZE); If the allocation must fail, no_iotlb_memory is set. Later during initialization swiotlb-xen comes in (drivers/xen/swiotlb-xen.c:xen_swiotlb_init) and given that io_tlb_start is != 0, it thinks the memory is ready to use when actually it is not. When the swiotlb is actually needed, swiotlb_tbl_map_single gets called and since no_iotlb_memory is set the kernel panics. Instead, if swiotlb-xen.c:xen_swiotlb_init knew the swiotlb hadn't been initialized, it would do the initialization itself, which might still succeed. Fix the panic by setting io_tlb_start to 0 on swiotlb initialization failure, and also by setting no_iotlb_memory to false on swiotlb initialization success. Fixes: ac2cbab ("x86: Don't panic if can not alloc buffer for swiotlb") Reported-by: Elliott Mitchell <ehem+xen@m5p.com> Tested-by: Elliott Mitchell <ehem+xen@m5p.com> Signed-off-by: Stefano Stabellini <stefano.stabellini@xilinx.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Cc: stable@vger.kernel.org Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 877d58e commit f3cbfd0

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎kernel/dma/swiotlb.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
231231
io_tlb_orig_addr[i] = INVALID_PHYS_ADDR;
232232
}
233233
io_tlb_index = 0;
234+
no_iotlb_memory = false;
234235

235236
if (verbose)
236237
swiotlb_print_info();
@@ -262,9 +263,11 @@ swiotlb_init(int verbose)
262263
if (vstart && !swiotlb_init_with_tbl(vstart, io_tlb_nslabs, verbose))
263264
return;
264265

265-
if (io_tlb_start)
266+
if (io_tlb_start) {
266267
memblock_free_early(io_tlb_start,
267268
PAGE_ALIGN(io_tlb_nslabs << IO_TLB_SHIFT));
269+
io_tlb_start = 0;
270+
}
268271
pr_warn("Cannot allocate buffer");
269272
no_iotlb_memory = true;
270273
}
@@ -362,6 +365,7 @@ swiotlb_late_init_with_tbl(char *tlb, unsigned long nslabs)
362365
io_tlb_orig_addr[i] = INVALID_PHYS_ADDR;
363366
}
364367
io_tlb_index = 0;
368+
no_iotlb_memory = false;
365369

366370
swiotlb_print_info();
367371

0 commit comments

Comments
 (0)