x86: centralize setting SWIOTLB_FORCE when guest memory encryption is enabled
authorChristoph Hellwig <hch@lst.de>
Tue, 29 Mar 2022 15:25:54 +0000 (17:25 +0200)
committerChristoph Hellwig <hch@lst.de>
Mon, 18 Apr 2022 05:21:10 +0000 (07:21 +0200)
Move enabling SWIOTLB_FORCE for guest memory encryption into common code.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Tested-by: Boris Ostrovsky <boris.ostrovsky@oracle.com>
arch/x86/kernel/cpu/mshyperv.c
arch/x86/kernel/pci-dma.c
arch/x86/mm/mem_encrypt_amd.c

index 4b67094215bba18ae76d3e9407b43124e291b645..5b8f2c357160116335a93a1dd30947602a642a1e 100644 (file)
@@ -337,14 +337,6 @@ static void __init ms_hyperv_init_platform(void)
                        swiotlb_unencrypted_base = ms_hyperv.shared_gpa_boundary;
 #endif
                }
-
-#ifdef CONFIG_SWIOTLB
-               /*
-                * Enable swiotlb force mode in Isolation VM to
-                * use swiotlb bounce buffer for dma transaction.
-                */
-               swiotlb_force = SWIOTLB_FORCE;
-#endif
                /* Isolation VMs are unenlightened SEV-based VMs, thus this check: */
                if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) {
                        if (hv_get_isolation_type() != HV_ISOLATION_TYPE_NONE)
index df96926421be0c73065c66a19b51dd6dea22bb5c..04140e20ef1a361ece75c1be7836f0f183f08bd2 100644 (file)
@@ -53,6 +53,14 @@ static void __init pci_swiotlb_detect(void)
        if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
                x86_swiotlb_enable = true;
 
+       /*
+        * Guest with guest memory encryption currently perform all DMA through
+        * 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))
+               swiotlb_force = SWIOTLB_FORCE;
+
        if (swiotlb_force == SWIOTLB_FORCE)
                x86_swiotlb_enable = true;
 }
index 6169053c28541c96e50f5bd7e2276b564571b527..d732d727d3dee49e4817b23b5488b6e8863e5aef 100644 (file)
@@ -432,9 +432,6 @@ void __init sme_early_init(void)
        for (i = 0; i < ARRAY_SIZE(protection_map); i++)
                protection_map[i] = pgprot_encrypted(protection_map[i]);
 
-       if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
-               swiotlb_force = SWIOTLB_FORCE;
-
        x86_platform.guest.enc_status_change_prepare = amd_enc_status_change_prepare;
        x86_platform.guest.enc_status_change_finish  = amd_enc_status_change_finish;
        x86_platform.guest.enc_tlb_flush_required    = amd_enc_tlb_flush_required;