Skip to content

Commit 5081e8f

Browse files
kirylhansendc
authored andcommitted
x86/tdx: Introduce wrappers to read and write TD metadata
The TDG_VM_WR TDCALL is used to ask the TDX module to change some TD-specific VM configuration. There is currently only one user in the kernel of this TDCALL leaf. More will be added shortly. Refactor to make way for more users of TDG_VM_WR who will need to modify other TD configuration values. Add a wrapper for the TDG_VM_RD TDCALL that requests TD-specific metadata from the TDX module. There are currently no users for TDG_VM_RD. Mark it as __maybe_unused until the first user appears. This is preparation for enumeration and enabling optional TD features. Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Reviewed-by: Kai Huang <kai.huang@intel.com> Reviewed-by: Kuppuswamy Sathyanarayanan <sathyanarayanan.kuppuswamy@linux.intel.com> Link: https://lore.kernel.org/all/20241104103803.195705-2-kirill.shutemov%40linux.intel.com
1 parent 59b723c commit 5081e8f

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

arch/x86/coco/tdx/tdx.c

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,32 @@ static inline void tdcall(u64 fn, struct tdx_module_args *args)
7878
panic("TDCALL %lld failed (Buggy TDX module!)\n", fn);
7979
}
8080

81+
/* Read TD-scoped metadata */
82+
static inline u64 __maybe_unused tdg_vm_rd(u64 field, u64 *value)
83+
{
84+
struct tdx_module_args args = {
85+
.rdx = field,
86+
};
87+
u64 ret;
88+
89+
ret = __tdcall_ret(TDG_VM_RD, &args);
90+
*value = args.r8;
91+
92+
return ret;
93+
}
94+
95+
/* Write TD-scoped metadata */
96+
static inline u64 tdg_vm_wr(u64 field, u64 value, u64 mask)
97+
{
98+
struct tdx_module_args args = {
99+
.rdx = field,
100+
.r8 = value,
101+
.r9 = mask,
102+
};
103+
104+
return __tdcall(TDG_VM_WR, &args);
105+
}
106+
81107
/**
82108
* tdx_mcall_get_report0() - Wrapper to get TDREPORT0 (a.k.a. TDREPORT
83109
* subtype 0) using TDG.MR.REPORT TDCALL.
@@ -929,10 +955,6 @@ static void tdx_kexec_finish(void)
929955

930956
void __init tdx_early_init(void)
931957
{
932-
struct tdx_module_args args = {
933-
.rdx = TDCS_NOTIFY_ENABLES,
934-
.r9 = -1ULL,
935-
};
936958
u64 cc_mask;
937959
u32 eax, sig[3];
938960

@@ -951,7 +973,7 @@ void __init tdx_early_init(void)
951973
cc_set_mask(cc_mask);
952974

953975
/* Kernel does not use NOTIFY_ENABLES and does not need random #VEs */
954-
tdcall(TDG_VM_WR, &args);
976+
tdg_vm_wr(TDCS_NOTIFY_ENABLES, 0, -1ULL);
955977

956978
/*
957979
* All bits above GPA width are reserved and kernel treats shared bit

arch/x86/include/asm/shared/tdx.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define TDG_VP_VEINFO_GET 3
1717
#define TDG_MR_REPORT 4
1818
#define TDG_MEM_PAGE_ACCEPT 6
19+
#define TDG_VM_RD 7
1920
#define TDG_VM_WR 8
2021

2122
/* TDCS fields. To be used by TDG.VM.WR and TDG.VM.RD module calls */

0 commit comments

Comments
 (0)