From: Aneesh Kumar K.V (Arm) <[email protected]> Sent: Thursday, May 21, 2026 9:28 PM > > Teach dma_direct_map_phys() to select the DMA address encoding based on > DMA_ATTR_CC_SHARED. > > Use phys_to_dma_unencrypted() for decrypted mappings and > phys_to_dma_encrypted() otherwise. If a device requires unencrypted DMA > but the source physical address is still encrypted, force the mapping > through swiotlb so the DMA address and backing memory attributes remain > consistent. > > Update the arm64, x86, s390 and powerpc secure-guest setup to not use > swiotlb force option > > Tested-by: Jiri Pirko <[email protected]> > Signed-off-by: Aneesh Kumar K.V (Arm) <[email protected]> > --- > Changes from v3: > * Handle DMA_ATTR_MMIO > --- > arch/arm64/mm/init.c | 4 +-- > arch/powerpc/platforms/pseries/svm.c | 2 +- > arch/s390/mm/init.c | 2 +- > arch/x86/kernel/pci-dma.c | 4 +-- > kernel/dma/direct.c | 4 ++- > kernel/dma/direct.h | 45 +++++++++++++++------------- > 6 files changed, 31 insertions(+), 30 deletions(-) > > diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c > index c1b223e7cc8e..a087ac5b15f7 100644 > --- a/arch/arm64/mm/init.c > +++ b/arch/arm64/mm/init.c > @@ -340,10 +340,8 @@ void __init arch_mm_preinit(void) > unsigned int flags = SWIOTLB_VERBOSE; > bool swiotlb = max_pfn > PFN_DOWN(arm64_dma_phys_limit); > > - if (is_realm_world()) { > + if (is_realm_world()) > swiotlb = true; > - flags |= SWIOTLB_FORCE; > - } > > if (IS_ENABLED(CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC) && !swiotlb) > { > /* > diff --git a/arch/powerpc/platforms/pseries/svm.c > b/arch/powerpc/platforms/pseries/svm.c > index 384c9dc1899a..7a403dbd35ee 100644 > --- a/arch/powerpc/platforms/pseries/svm.c > +++ b/arch/powerpc/platforms/pseries/svm.c > @@ -29,7 +29,7 @@ static int __init init_svm(void) > * need to use the SWIOTLB buffer for DMA even if dma_capable() says > * otherwise. > */ > - ppc_swiotlb_flags |= SWIOTLB_ANY | SWIOTLB_FORCE; > + ppc_swiotlb_flags |= SWIOTLB_ANY; > > /* Share the SWIOTLB buffer with the host. */ > swiotlb_update_mem_attributes(); > diff --git a/arch/s390/mm/init.c b/arch/s390/mm/init.c > index ad3c6d92b801..581af1483c42 100644 > --- a/arch/s390/mm/init.c > +++ b/arch/s390/mm/init.c > @@ -163,7 +163,7 @@ static void __init pv_init(void) > virtio_set_mem_acc_cb(virtio_require_restricted_mem_acc); > > /* make sure bounce buffers are shared */ > - swiotlb_init(true, SWIOTLB_FORCE | SWIOTLB_VERBOSE); > + swiotlb_init(true, SWIOTLB_VERBOSE); > swiotlb_update_mem_attributes(); > } > > diff --git a/arch/x86/kernel/pci-dma.c b/arch/x86/kernel/pci-dma.c > index 6267363e0189..75cf8f6ae8cd 100644 > --- a/arch/x86/kernel/pci-dma.c > +++ b/arch/x86/kernel/pci-dma.c > @@ -59,10 +59,8 @@ static void __init pci_swiotlb_detect(void) > * bounce buffers as the hypervisor can't access arbitrary VM memory > * that is not explicitly shared with it. > */ > - if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) { > + if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) > x86_swiotlb_enable = true; > - x86_swiotlb_flags |= SWIOTLB_FORCE; > - }
With this patch removing SWIOTLB_FORCE from four places in kernel code, there are no remaining places where it is set. The test of SWIOTLB_FORCE could be removed from swiotlb_init_remap(), and its definition could be deleted from include/linux/swiotlb.h. Michael
