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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 23 Jul 2023 11:49:19 +0000 (13:49 +0200)
commitfc3db7fbdf58a2a091764889f15f6e37978aa2de
tree0a87cc408665c63ef1f8e5a5763e45365e8897c5
parent24b24863a0128152db3fb3aa33dc11b18a9b6792
swiotlb: reduce the swiotlb buffer size on allocation failure

[ Upstream commit 8d58aa484920c4f9be4834a7aeb446cdced21a37 ]

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>
Stable-dep-of: 8ac04063354a ("swiotlb: reduce the number of areas to match actual memory pool size")
Signed-off-by: Sasha Levin <sashal@kernel.org>
kernel/dma/swiotlb.c