-
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.
x86/tdx: Add unaccepted memory support
Hookup TDX-specific code to accept memory. Accepting the memory is done with ACCEPT_PAGE module call on every page in the range. MAP_GPA hypercall is not required as the unaccepted memory is considered private already. Extract the part of tdx_enc_status_changed() that does memory acceptance in a new helper. Move the helper tdx-shared.c. It is going to be used by both main kernel and decompressor. [ bp: Fix the INTEL_TDX_GUEST=y, KVM_GUEST=n build. ] Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de> Link: https://lore.kernel.org/r/20230606142637.5171-10-kirill.shutemov@linux.intel.com
- Loading branch information
Kirill A. Shutemov
authored and
Borislav Petkov (AMD)
committed
Jun 6, 2023
1 parent
c2b353a
commit 75d090f
Showing
12 changed files
with
162 additions
and
70 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
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 |
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,71 @@ | ||
#include <asm/tdx.h> | ||
#include <asm/pgtable.h> | ||
|
||
static unsigned long try_accept_one(phys_addr_t start, unsigned long len, | ||
enum pg_level pg_level) | ||
{ | ||
unsigned long accept_size = page_level_size(pg_level); | ||
u64 tdcall_rcx; | ||
u8 page_size; | ||
|
||
if (!IS_ALIGNED(start, accept_size)) | ||
return 0; | ||
|
||
if (len < accept_size) | ||
return 0; | ||
|
||
/* | ||
* Pass the page physical address to the TDX module to accept the | ||
* pending, private page. | ||
* | ||
* Bits 2:0 of RCX encode page size: 0 - 4K, 1 - 2M, 2 - 1G. | ||
*/ | ||
switch (pg_level) { | ||
case PG_LEVEL_4K: | ||
page_size = 0; | ||
break; | ||
case PG_LEVEL_2M: | ||
page_size = 1; | ||
break; | ||
case PG_LEVEL_1G: | ||
page_size = 2; | ||
break; | ||
default: | ||
return 0; | ||
} | ||
|
||
tdcall_rcx = start | page_size; | ||
if (__tdx_module_call(TDX_ACCEPT_PAGE, tdcall_rcx, 0, 0, 0, NULL)) | ||
return 0; | ||
|
||
return accept_size; | ||
} | ||
|
||
bool tdx_accept_memory(phys_addr_t start, phys_addr_t end) | ||
{ | ||
/* | ||
* For shared->private conversion, accept the page using | ||
* TDX_ACCEPT_PAGE TDX module call. | ||
*/ | ||
while (start < end) { | ||
unsigned long len = end - start; | ||
unsigned long accept_size; | ||
|
||
/* | ||
* Try larger accepts first. It gives chance to VMM to keep | ||
* 1G/2M Secure EPT entries where possible and speeds up | ||
* process by cutting number of hypercalls (if successful). | ||
*/ | ||
|
||
accept_size = try_accept_one(start, len, PG_LEVEL_1G); | ||
if (!accept_size) | ||
accept_size = try_accept_one(start, len, PG_LEVEL_2M); | ||
if (!accept_size) | ||
accept_size = try_accept_one(start, len, PG_LEVEL_4K); | ||
if (!accept_size) | ||
return false; | ||
start += accept_size; | ||
} | ||
|
||
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,24 @@ | ||
#ifndef _ASM_X86_UNACCEPTED_MEMORY_H | ||
#define _ASM_X86_UNACCEPTED_MEMORY_H | ||
|
||
#include <linux/efi.h> | ||
#include <asm/tdx.h> | ||
|
||
static inline void arch_accept_memory(phys_addr_t start, phys_addr_t end) | ||
{ | ||
/* Platform-specific memory-acceptance call goes here */ | ||
if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) { | ||
if (!tdx_accept_memory(start, end)) | ||
panic("TDX: Failed to accept memory\n"); | ||
} else { | ||
panic("Cannot accept memory: unknown platform\n"); | ||
} | ||
} | ||
|
||
static inline struct efi_unaccepted_memory *efi_get_unaccepted_table(void) | ||
{ | ||
if (efi.unaccepted == EFI_INVALID_TABLE_ADDR) | ||
return NULL; | ||
return __va(efi.unaccepted); | ||
} | ||
#endif |