Skip to content

Commit ff40b57

Browse files
kirylbp3tk0v
authored andcommitted
x86/tdx: Make _tdx_hypercall() and __tdx_module_call() available in boot stub
Memory acceptance requires a hypercall and one or multiple module calls. Make helpers for the calls available in boot stub. It has to accept memory where kernel image and initrd are placed. Signed-off-by: Kirill A. Shutemov <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Reviewed-by: Dave Hansen <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent c211c19 commit ff40b57

File tree

3 files changed

+51
-51
lines changed

3 files changed

+51
-51
lines changed

arch/x86/coco/tdx/tdx.c

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,6 @@
1414
#include <asm/insn-eval.h>
1515
#include <asm/pgtable.h>
1616

17-
/* TDX module Call Leaf IDs */
18-
#define TDX_GET_INFO 1
19-
#define TDX_GET_VEINFO 3
20-
#define TDX_GET_REPORT 4
21-
#define TDX_ACCEPT_PAGE 6
22-
#define TDX_WR 8
23-
24-
/* TDCS fields. To be used by TDG.VM.WR and TDG.VM.RD module calls */
25-
#define TDCS_NOTIFY_ENABLES 0x9100000000000010
26-
27-
/* TDX hypercall Leaf IDs */
28-
#define TDVMCALL_MAP_GPA 0x10001
29-
#define TDVMCALL_REPORT_FATAL_ERROR 0x10003
30-
3117
/* MMIO direction */
3218
#define EPT_READ 0
3319
#define EPT_WRITE 1
@@ -51,24 +37,6 @@
5137

5238
#define TDREPORT_SUBTYPE_0 0
5339

54-
/*
55-
* Wrapper for standard use of __tdx_hypercall with no output aside from
56-
* return code.
57-
*/
58-
static inline u64 _tdx_hypercall(u64 fn, u64 r12, u64 r13, u64 r14, u64 r15)
59-
{
60-
struct tdx_hypercall_args args = {
61-
.r10 = TDX_HYPERCALL_STANDARD,
62-
.r11 = fn,
63-
.r12 = r12,
64-
.r13 = r13,
65-
.r14 = r14,
66-
.r15 = r15,
67-
};
68-
69-
return __tdx_hypercall(&args);
70-
}
71-
7240
/* Called from __tdx_hypercall() for unrecoverable failure */
7341
noinstr void __tdx_hypercall_failed(void)
7442
{

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

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,20 @@
1010
#define TDX_CPUID_LEAF_ID 0x21
1111
#define TDX_IDENT "IntelTDX "
1212

13+
/* TDX module Call Leaf IDs */
14+
#define TDX_GET_INFO 1
15+
#define TDX_GET_VEINFO 3
16+
#define TDX_GET_REPORT 4
17+
#define TDX_ACCEPT_PAGE 6
18+
#define TDX_WR 8
19+
20+
/* TDCS fields. To be used by TDG.VM.WR and TDG.VM.RD module calls */
21+
#define TDCS_NOTIFY_ENABLES 0x9100000000000010
22+
23+
/* TDX hypercall Leaf IDs */
24+
#define TDVMCALL_MAP_GPA 0x10001
25+
#define TDVMCALL_REPORT_FATAL_ERROR 0x10003
26+
1327
#ifndef __ASSEMBLY__
1428

1529
/*
@@ -37,8 +51,45 @@ struct tdx_hypercall_args {
3751
u64 __tdx_hypercall(struct tdx_hypercall_args *args);
3852
u64 __tdx_hypercall_ret(struct tdx_hypercall_args *args);
3953

54+
/*
55+
* Wrapper for standard use of __tdx_hypercall with no output aside from
56+
* return code.
57+
*/
58+
static inline u64 _tdx_hypercall(u64 fn, u64 r12, u64 r13, u64 r14, u64 r15)
59+
{
60+
struct tdx_hypercall_args args = {
61+
.r10 = TDX_HYPERCALL_STANDARD,
62+
.r11 = fn,
63+
.r12 = r12,
64+
.r13 = r13,
65+
.r14 = r14,
66+
.r15 = r15,
67+
};
68+
69+
return __tdx_hypercall(&args);
70+
}
71+
72+
4073
/* Called from __tdx_hypercall() for unrecoverable failure */
4174
void __tdx_hypercall_failed(void);
4275

76+
/*
77+
* Used in __tdx_module_call() to gather the output registers' values of the
78+
* TDCALL instruction when requesting services from the TDX module. This is a
79+
* software only structure and not part of the TDX module/VMM ABI
80+
*/
81+
struct tdx_module_output {
82+
u64 rcx;
83+
u64 rdx;
84+
u64 r8;
85+
u64 r9;
86+
u64 r10;
87+
u64 r11;
88+
};
89+
90+
/* Used to communicate with the TDX module */
91+
u64 __tdx_module_call(u64 fn, u64 rcx, u64 rdx, u64 r8, u64 r9,
92+
struct tdx_module_output *out);
93+
4394
#endif /* !__ASSEMBLY__ */
4495
#endif /* _ASM_X86_SHARED_TDX_H */

arch/x86/include/asm/tdx.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,6 @@
2020

2121
#ifndef __ASSEMBLY__
2222

23-
/*
24-
* Used to gather the output registers values of the TDCALL and SEAMCALL
25-
* instructions when requesting services from the TDX module.
26-
*
27-
* This is a software only structure and not part of the TDX module/VMM ABI.
28-
*/
29-
struct tdx_module_output {
30-
u64 rcx;
31-
u64 rdx;
32-
u64 r8;
33-
u64 r9;
34-
u64 r10;
35-
u64 r11;
36-
};
37-
3823
/*
3924
* Used by the #VE exception handler to gather the #VE exception
4025
* info from the TDX module. This is a software only structure
@@ -55,10 +40,6 @@ struct ve_info {
5540

5641
void __init tdx_early_init(void);
5742

58-
/* Used to communicate with the TDX module */
59-
u64 __tdx_module_call(u64 fn, u64 rcx, u64 rdx, u64 r8, u64 r9,
60-
struct tdx_module_output *out);
61-
6243
void tdx_get_ve_info(struct ve_info *ve);
6344

6445
bool tdx_handle_virt_exception(struct pt_regs *regs, struct ve_info *ve);

0 commit comments

Comments
 (0)