forked from microsoft/WSL2-Linux-Kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge tag 'x86_cc_for_v6.5' of git://git.kernel.org/pub/scm/linux/ker…
…nel/git/tip/tip Pull x86 confidential computing update from Borislav Petkov: - Add support for unaccepted memory as specified in the UEFI spec v2.9. The gist of it all is that Intel TDX and AMD SEV-SNP confidential computing guests define the notion of accepting memory before using it and thus preventing a whole set of attacks against such guests like memory replay and the like. There are a couple of strategies of how memory should be accepted - the current implementation does an on-demand way of accepting. * tag 'x86_cc_for_v6.5' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: virt: sevguest: Add CONFIG_CRYPTO dependency x86/efi: Safely enable unaccepted memory in UEFI x86/sev: Add SNP-specific unaccepted memory support x86/sev: Use large PSC requests if applicable x86/sev: Allow for use of the early boot GHCB for PSC requests x86/sev: Put PSC struct on the stack in prep for unaccepted memory support x86/sev: Fix calculation of end address based on number of pages x86/tdx: Add unaccepted memory support x86/tdx: Refactor try_accept_one() x86/tdx: Make _tdx_hypercall() and __tdx_module_call() available in boot stub efi/unaccepted: Avoid load_unaligned_zeropad() stepping into unaccepted memory efi: Add unaccepted memory support x86/boot/compressed: Handle unaccepted memory efi/libstub: Implement support for unaccepted memory efi/x86: Get full memory map in allocate_e820() mm: Add support for unaccepted memory
- Loading branch information
Showing
44 changed files
with
1,448 additions
and
307 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
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,86 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only | ||
|
||
#include "error.h" | ||
#include "misc.h" | ||
#include "tdx.h" | ||
#include "sev.h" | ||
#include <asm/shared/tdx.h> | ||
|
||
/* | ||
* accept_memory() and process_unaccepted_memory() called from EFI stub which | ||
* runs before decompresser and its early_tdx_detect(). | ||
* | ||
* Enumerate TDX directly from the early users. | ||
*/ | ||
static bool early_is_tdx_guest(void) | ||
{ | ||
static bool once; | ||
static bool is_tdx; | ||
|
||
if (!IS_ENABLED(CONFIG_INTEL_TDX_GUEST)) | ||
return false; | ||
|
||
if (!once) { | ||
u32 eax, sig[3]; | ||
|
||
cpuid_count(TDX_CPUID_LEAF_ID, 0, &eax, | ||
&sig[0], &sig[2], &sig[1]); | ||
is_tdx = !memcmp(TDX_IDENT, sig, sizeof(sig)); | ||
once = true; | ||
} | ||
|
||
return is_tdx; | ||
} | ||
|
||
void arch_accept_memory(phys_addr_t start, phys_addr_t end) | ||
{ | ||
/* Platform-specific memory-acceptance call goes here */ | ||
if (early_is_tdx_guest()) { | ||
if (!tdx_accept_memory(start, end)) | ||
panic("TDX: Failed to accept memory\n"); | ||
} else if (sev_snp_enabled()) { | ||
snp_accept_memory(start, end); | ||
} else { | ||
error("Cannot accept memory: unknown platform\n"); | ||
} | ||
} | ||
|
||
bool init_unaccepted_memory(void) | ||
{ | ||
guid_t guid = LINUX_EFI_UNACCEPTED_MEM_TABLE_GUID; | ||
struct efi_unaccepted_memory *table; | ||
unsigned long cfg_table_pa; | ||
unsigned int cfg_table_len; | ||
enum efi_type et; | ||
int ret; | ||
|
||
et = efi_get_type(boot_params); | ||
if (et == EFI_TYPE_NONE) | ||
return false; | ||
|
||
ret = efi_get_conf_table(boot_params, &cfg_table_pa, &cfg_table_len); | ||
if (ret) { | ||
warn("EFI config table not found."); | ||
return false; | ||
} | ||
|
||
table = (void *)efi_find_vendor_table(boot_params, cfg_table_pa, | ||
cfg_table_len, guid); | ||
if (!table) | ||
return false; | ||
|
||
if (table->version != 1) | ||
error("Unknown version of unaccepted memory table\n"); | ||
|
||
/* | ||
* In many cases unaccepted_table is already set by EFI stub, but it | ||
* has to be initialized again to cover cases when the table is not | ||
* allocated by EFI stub or EFI stub copied the kernel image with | ||
* efi_relocate_kernel() before the variable is set. | ||
* | ||
* It must be initialized before the first usage of accept_memory(). | ||
*/ | ||
unaccepted_table = table; | ||
|
||
return true; | ||
} |
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,23 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
/* | ||
* AMD SEV header for early boot related functions. | ||
* | ||
* Author: Tom Lendacky <thomas.lendacky@amd.com> | ||
*/ | ||
|
||
#ifndef BOOT_COMPRESSED_SEV_H | ||
#define BOOT_COMPRESSED_SEV_H | ||
|
||
#ifdef CONFIG_AMD_MEM_ENCRYPT | ||
|
||
bool sev_snp_enabled(void); | ||
void snp_accept_memory(phys_addr_t start, phys_addr_t end); | ||
|
||
#else | ||
|
||
static inline bool sev_snp_enabled(void) { return false; } | ||
static inline void snp_accept_memory(phys_addr_t start, phys_addr_t end) { } | ||
|
||
#endif | ||
|
||
#endif |
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,2 @@ | ||
#include "error.h" | ||
#include "../../coco/tdx/tdx-shared.c" |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# SPDX-License-Identifier: GPL-2.0 | ||
|
||
obj-y += tdx.o tdcall.o | ||
obj-y += tdx.o tdx-shared.o tdcall.o |
Oops, something went wrong.