swiotlb: reduce the swiotlb buffer size on allocation failure
authorAlexey Kardashevskiy <aik@amd.com>
Mon, 31 Oct 2022 08:13:27 +0000 (19:13 +1100)
committerChristoph Hellwig <hch@lst.de>
Tue, 1 Nov 2022 11:06:12 +0000 (12:06 +0100)
commit8d58aa484920c4f9be4834a7aeb446cdced21a37
treed54fdd6ea0c3fae8362cc37a0ce4f3805f2fec75
parent30a0b95b1335e12efef89dd78518ed3e4a71a763
swiotlb: reduce the swiotlb buffer size on allocation failure

At the moment the AMD encrypted platform reserves 6% of RAM for SWIOTLB
or 1GB, whichever is less. However it is possible that there is no block
big enough in the low memory which make SWIOTLB allocation fail and
the kernel continues without DMA. In such case a VM hangs on DMA.

This moves alloc+remap to a helper and calls it from a loop where
the size is halved on each iteration.

This updates default_nslabs on successful allocation which looks like
an oversight as not doing so should have broken callers of
swiotlb_size_or_default().

Signed-off-by: Alexey Kardashevskiy <aik@amd.com>
Reviewed-by: Pankaj Gupta <pankaj.gupta@amd.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
kernel/dma/swiotlb.c