[RFC PATCH kernel 09/17] dma/swiotlb: Force shared DMA for allocatios from SWIOTLB
From: Alexey Kardashevskiy
Date: Wed Sep 16 2026 - 08:33:01 EST
SWIOTLB allocations are always decrypted but the DMA layer is unaware
of those and will miss to adjust the DMA handle.
Force __DMA_ATTR_ALLOC_CC_SHARED if SWIOTLB is used for memory allocations.
This will be exploited by AMD SEV guest vTOM feature where DMA handles
of shared memory have some high bit set (not to be confused with the
Cbit).
Signed-off-by: Alexey Kardashevskiy <aik@xxxxxxx>
---
kernel/dma/direct.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c
index da665ca22d5c..dacf513d45fd 100644
--- a/kernel/dma/direct.c
+++ b/kernel/dma/direct.c
@@ -273,13 +273,14 @@ void *dma_direct_alloc(struct device *dev, size_t size,
}
if (is_swiotlb_for_alloc(dev)) {
- page = dma_direct_alloc_swiotlb(dev, size, attrs);
+ page = dma_direct_alloc_swiotlb(dev, size, attrs | __DMA_ATTR_ALLOC_CC_SHARED);
if (page) {
/*
* swiotlb allocations comes from pool already marked
* decrypted
*/
mark_mem_decrypt = false;
+ attrs |= __DMA_ATTR_ALLOC_CC_SHARED;
goto setup_page;
}
return NULL;
--
2.55.0