Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
x86/mm: Move force_dma_unencrypted() to common code
force_dma_unencrypted() has to return true for TDX guest. Move it out of AMD SME code. Introduce new config option X86_MEM_ENCRYPT_COMMON that has to be selected by all x86 memory encryption features. This is preparation for TDX changes in DMA code. Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Signed-off-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com>
- Loading branch information
Showing
5 changed files
with
49 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // SPDX-License-Identifier: GPL-2.0-only | ||
| /* | ||
| * AMD Memory Encryption Support | ||
| * | ||
| * Copyright (C) 2016 Advanced Micro Devices, Inc. | ||
| * | ||
| * Author: Tom Lendacky <thomas.lendacky@amd.com> | ||
| */ | ||
|
|
||
| #include <linux/mm.h> | ||
| #include <linux/mem_encrypt.h> | ||
| #include <linux/dma-mapping.h> | ||
|
|
||
| /* Override for DMA direct allocation check - ARCH_HAS_FORCE_DMA_UNENCRYPTED */ | ||
| bool force_dma_unencrypted(struct device *dev) | ||
| { | ||
| /* | ||
| * For SEV, all DMA must be to unencrypted/shared addresses. | ||
| */ | ||
| if (sev_active()) | ||
| return true; | ||
|
|
||
| /* | ||
| * For SME, all DMA must be to unencrypted addresses if the | ||
| * device does not support DMA to addresses that include the | ||
| * encryption mask. | ||
| */ | ||
| if (sme_active()) { | ||
| u64 dma_enc_mask = DMA_BIT_MASK(__ffs64(sme_me_mask)); | ||
| u64 dma_dev_mask = min_not_zero(dev->coherent_dma_mask, | ||
| dev->bus_dma_limit); | ||
|
|
||
| if (dma_dev_mask <= dma_enc_mask) | ||
| return true; | ||
| } | ||
|
|
||
| return false; | ||
| } |