Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86: centralize setting SWIOTLB_FORCE when guest memory encryption is enabled

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>

+8 -11
-8
arch/x86/kernel/cpu/mshyperv.c
··· 337 337 swiotlb_unencrypted_base = ms_hyperv.shared_gpa_boundary; 338 338 #endif 339 339 } 340 - 341 - #ifdef CONFIG_SWIOTLB 342 - /* 343 - * Enable swiotlb force mode in Isolation VM to 344 - * use swiotlb bounce buffer for dma transaction. 345 - */ 346 - swiotlb_force = SWIOTLB_FORCE; 347 - #endif 348 340 /* Isolation VMs are unenlightened SEV-based VMs, thus this check: */ 349 341 if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) { 350 342 if (hv_get_isolation_type() != HV_ISOLATION_TYPE_NONE)
+8
arch/x86/kernel/pci-dma.c
··· 53 53 if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT)) 54 54 x86_swiotlb_enable = true; 55 55 56 + /* 57 + * Guest with guest memory encryption currently perform all DMA through 58 + * bounce buffers as the hypervisor can't access arbitrary VM memory 59 + * that is not explicitly shared with it. 60 + */ 61 + if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) 62 + swiotlb_force = SWIOTLB_FORCE; 63 + 56 64 if (swiotlb_force == SWIOTLB_FORCE) 57 65 x86_swiotlb_enable = true; 58 66 }
-3
arch/x86/mm/mem_encrypt_amd.c
··· 432 432 for (i = 0; i < ARRAY_SIZE(protection_map); i++) 433 433 protection_map[i] = pgprot_encrypted(protection_map[i]); 434 434 435 - if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) 436 - swiotlb_force = SWIOTLB_FORCE; 437 - 438 435 x86_platform.guest.enc_status_change_prepare = amd_enc_status_change_prepare; 439 436 x86_platform.guest.enc_status_change_finish = amd_enc_status_change_finish; 440 437 x86_platform.guest.enc_tlb_flush_required = amd_enc_tlb_flush_required;