Skip to content

Commit c3abbf1

Browse files
kirylbp3tk0v
authored andcommitted
x86/tdx: Account shared memory
The kernel will convert all shared memory back to private during kexec. The direct mapping page tables will provide information on which memory is shared. It is extremely important to convert all shared memory. If a page is missed, it will cause the second kernel to crash when it accesses it. Keep track of the number of shared pages. This will allow for cross-checking against the shared information in the direct mapping and reporting if the shared bit is lost. Memory conversion is slow and does not happen often. Global atomic is not going to be a bottleneck. Signed-off-by: Kirill A. Shutemov <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Kai Huang <[email protected]> Tested-by: Tao Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 9d1dcdf commit c3abbf1

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

arch/x86/coco/tdx/tdx.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838

3939
#define TDREPORT_SUBTYPE_0 0
4040

41+
static atomic_long_t nr_shared;
42+
4143
/* Called from __tdx_hypercall() for unrecoverable failure */
4244
noinstr void __noreturn __tdx_hypercall_failed(void)
4345
{
@@ -821,6 +823,11 @@ static int tdx_enc_status_change_finish(unsigned long vaddr, int numpages,
821823
if (!enc && !tdx_enc_status_changed(vaddr, numpages, enc))
822824
return -EIO;
823825

826+
if (enc)
827+
atomic_long_sub(numpages, &nr_shared);
828+
else
829+
atomic_long_add(numpages, &nr_shared);
830+
824831
return 0;
825832
}
826833

0 commit comments

Comments
 (0)