Skip to content

Commit a3e2309

Browse files
author
Christoph Hellwig
committed
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 <[email protected]> Reviewed-by: Konrad Rzeszutek Wilk <[email protected]> Tested-by: Boris Ostrovsky <[email protected]>
1 parent 78013ea commit a3e2309

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

arch/x86/kernel/cpu/mshyperv.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,14 +337,6 @@ static void __init ms_hyperv_init_platform(void)
337337
swiotlb_unencrypted_base = ms_hyperv.shared_gpa_boundary;
338338
#endif
339339
}
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
348340
/* Isolation VMs are unenlightened SEV-based VMs, thus this check: */
349341
if (IS_ENABLED(CONFIG_AMD_MEM_ENCRYPT)) {
350342
if (hv_get_isolation_type() != HV_ISOLATION_TYPE_NONE)

arch/x86/kernel/pci-dma.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ static void __init pci_swiotlb_detect(void)
5353
if (cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT))
5454
x86_swiotlb_enable = true;
5555

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+
5664
if (swiotlb_force == SWIOTLB_FORCE)
5765
x86_swiotlb_enable = true;
5866
}

arch/x86/mm/mem_encrypt_amd.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,9 +432,6 @@ void __init sme_early_init(void)
432432
for (i = 0; i < ARRAY_SIZE(protection_map); i++)
433433
protection_map[i] = pgprot_encrypted(protection_map[i]);
434434

435-
if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
436-
swiotlb_force = SWIOTLB_FORCE;
437-
438435
x86_platform.guest.enc_status_change_prepare = amd_enc_status_change_prepare;
439436
x86_platform.guest.enc_status_change_finish = amd_enc_status_change_finish;
440437
x86_platform.guest.enc_tlb_flush_required = amd_enc_tlb_flush_required;

0 commit comments

Comments
 (0)