Skip to content

Commit 8a8544b

Browse files
kaihuanghansendc
authored andcommitted
x86/tdx: Remove 'struct tdx_hypercall_args'
Now 'struct tdx_hypercall_args' is basically 'struct tdx_module_args' minus RCX. Although from __tdx_hypercall()'s perspective RCX isn't used as shared register thus not part of input/output registers, it's not worth to have a separate structure just due to one register. Remove the 'struct tdx_hypercall_args' and use 'struct tdx_module_args' instead in __tdx_hypercall() related code. This also saves the memory copy between the two structures within __tdx_hypercall(). Suggested-by: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Kai Huang <kai.huang@intel.com> Signed-off-by: Dave Hansen <dave.hansen@linux.intel.com> Reviewed-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com> Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://lore.kernel.org/all/798dad5ce24e9d745cf0e16825b75ccc433ad065.1692096753.git.kai.huang%40intel.com
1 parent 90f5ecd commit 8a8544b

File tree

5 files changed

+23
-67
lines changed

5 files changed

+23
-67
lines changed

arch/x86/boot/compressed/tdx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void __tdx_hypercall_failed(void)
1818

1919
static inline unsigned int tdx_io_in(int size, u16 port)
2020
{
21-
struct tdx_hypercall_args args = {
21+
struct tdx_module_args args = {
2222
.r10 = TDX_HYPERCALL_STANDARD,
2323
.r11 = hcall_func(EXIT_REASON_IO_INSTRUCTION),
2424
.r12 = size,
@@ -34,7 +34,7 @@ static inline unsigned int tdx_io_in(int size, u16 port)
3434

3535
static inline void tdx_io_out(int size, u16 port, u32 value)
3636
{
37-
struct tdx_hypercall_args args = {
37+
struct tdx_module_args args = {
3838
.r10 = TDX_HYPERCALL_STANDARD,
3939
.r11 = hcall_func(EXIT_REASON_IO_INSTRUCTION),
4040
.r12 = size,

arch/x86/coco/tdx/tdx-shared.c

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -70,45 +70,22 @@ bool tdx_accept_memory(phys_addr_t start, phys_addr_t end)
7070
return true;
7171
}
7272

73-
noinstr u64 __tdx_hypercall(struct tdx_hypercall_args *args)
73+
noinstr u64 __tdx_hypercall(struct tdx_module_args *args)
7474
{
75-
struct tdx_module_args margs = {
76-
.rcx = TDVMCALL_EXPOSE_REGS_MASK,
77-
.rdx = args->rdx,
78-
.r8 = args->r8,
79-
.r9 = args->r9,
80-
.r10 = args->r10,
81-
.r11 = args->r11,
82-
.r12 = args->r12,
83-
.r13 = args->r13,
84-
.r14 = args->r14,
85-
.r15 = args->r15,
86-
.rbx = args->rbx,
87-
.rdi = args->rdi,
88-
.rsi = args->rsi,
89-
};
75+
/*
76+
* For TDVMCALL explicitly set RCX to the bitmap of shared registers.
77+
* The caller isn't expected to set @args->rcx anyway.
78+
*/
79+
args->rcx = TDVMCALL_EXPOSE_REGS_MASK;
9080

9181
/*
9282
* Failure of __tdcall_saved_ret() indicates a failure of the TDVMCALL
9383
* mechanism itself and that something has gone horribly wrong with
9484
* the TDX module. __tdx_hypercall_failed() never returns.
9585
*/
96-
if (__tdcall_saved_ret(TDG_VP_VMCALL, &margs))
86+
if (__tdcall_saved_ret(TDG_VP_VMCALL, args))
9787
__tdx_hypercall_failed();
9888

99-
args->r8 = margs.r8;
100-
args->r9 = margs.r9;
101-
args->r10 = margs.r10;
102-
args->r11 = margs.r11;
103-
args->r12 = margs.r12;
104-
args->r13 = margs.r13;
105-
args->r14 = margs.r14;
106-
args->r15 = margs.r15;
107-
args->rdi = margs.rdi;
108-
args->rsi = margs.rsi;
109-
args->rbx = margs.rbx;
110-
args->rdx = margs.rdx;
111-
11289
/* TDVMCALL leaf return code is in R10 */
11390
return args->r10;
11491
}

arch/x86/coco/tdx/tdx.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ noinstr void __noreturn __tdx_hypercall_failed(void)
4848
long tdx_kvm_hypercall(unsigned int nr, unsigned long p1, unsigned long p2,
4949
unsigned long p3, unsigned long p4)
5050
{
51-
struct tdx_hypercall_args args = {
51+
struct tdx_module_args args = {
5252
.r10 = nr,
5353
.r11 = p1,
5454
.r12 = p2,
@@ -108,7 +108,7 @@ EXPORT_SYMBOL_GPL(tdx_mcall_get_report0);
108108

109109
static void __noreturn tdx_panic(const char *msg)
110110
{
111-
struct tdx_hypercall_args args = {
111+
struct tdx_module_args args = {
112112
.r10 = TDX_HYPERCALL_STANDARD,
113113
.r11 = TDVMCALL_REPORT_FATAL_ERROR,
114114
.r12 = 0, /* Error code: 0 is Panic */
@@ -230,7 +230,7 @@ static int ve_instr_len(struct ve_info *ve)
230230

231231
static u64 __cpuidle __halt(const bool irq_disabled)
232232
{
233-
struct tdx_hypercall_args args = {
233+
struct tdx_module_args args = {
234234
.r10 = TDX_HYPERCALL_STANDARD,
235235
.r11 = hcall_func(EXIT_REASON_HLT),
236236
.r12 = irq_disabled,
@@ -274,7 +274,7 @@ void __cpuidle tdx_safe_halt(void)
274274

275275
static int read_msr(struct pt_regs *regs, struct ve_info *ve)
276276
{
277-
struct tdx_hypercall_args args = {
277+
struct tdx_module_args args = {
278278
.r10 = TDX_HYPERCALL_STANDARD,
279279
.r11 = hcall_func(EXIT_REASON_MSR_READ),
280280
.r12 = regs->cx,
@@ -295,7 +295,7 @@ static int read_msr(struct pt_regs *regs, struct ve_info *ve)
295295

296296
static int write_msr(struct pt_regs *regs, struct ve_info *ve)
297297
{
298-
struct tdx_hypercall_args args = {
298+
struct tdx_module_args args = {
299299
.r10 = TDX_HYPERCALL_STANDARD,
300300
.r11 = hcall_func(EXIT_REASON_MSR_WRITE),
301301
.r12 = regs->cx,
@@ -315,7 +315,7 @@ static int write_msr(struct pt_regs *regs, struct ve_info *ve)
315315

316316
static int handle_cpuid(struct pt_regs *regs, struct ve_info *ve)
317317
{
318-
struct tdx_hypercall_args args = {
318+
struct tdx_module_args args = {
319319
.r10 = TDX_HYPERCALL_STANDARD,
320320
.r11 = hcall_func(EXIT_REASON_CPUID),
321321
.r12 = regs->ax,
@@ -357,7 +357,7 @@ static int handle_cpuid(struct pt_regs *regs, struct ve_info *ve)
357357

358358
static bool mmio_read(int size, unsigned long addr, unsigned long *val)
359359
{
360-
struct tdx_hypercall_args args = {
360+
struct tdx_module_args args = {
361361
.r10 = TDX_HYPERCALL_STANDARD,
362362
.r11 = hcall_func(EXIT_REASON_EPT_VIOLATION),
363363
.r12 = size,
@@ -486,7 +486,7 @@ static int handle_mmio(struct pt_regs *regs, struct ve_info *ve)
486486

487487
static bool handle_in(struct pt_regs *regs, int size, int port)
488488
{
489-
struct tdx_hypercall_args args = {
489+
struct tdx_module_args args = {
490490
.r10 = TDX_HYPERCALL_STANDARD,
491491
.r11 = hcall_func(EXIT_REASON_IO_INSTRUCTION),
492492
.r12 = size,
@@ -723,7 +723,7 @@ static bool tdx_map_gpa(phys_addr_t start, phys_addr_t end, bool enc)
723723
}
724724

725725
while (retry_count < max_retries_per_page) {
726-
struct tdx_hypercall_args args = {
726+
struct tdx_module_args args = {
727727
.r10 = TDX_HYPERCALL_STANDARD,
728728
.r11 = TDVMCALL_MAP_GPA,
729729
.r12 = start,

arch/x86/hyperv/ivm.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ static inline void hv_ghcb_msr_read(u64 msr, u64 *value) {}
384384
#ifdef CONFIG_INTEL_TDX_GUEST
385385
static void hv_tdx_msr_write(u64 msr, u64 val)
386386
{
387-
struct tdx_hypercall_args args = {
387+
struct tdx_module_args args = {
388388
.r10 = TDX_HYPERCALL_STANDARD,
389389
.r11 = EXIT_REASON_MSR_WRITE,
390390
.r12 = msr,
@@ -398,7 +398,7 @@ static void hv_tdx_msr_write(u64 msr, u64 val)
398398

399399
static void hv_tdx_msr_read(u64 msr, u64 *val)
400400
{
401-
struct tdx_hypercall_args args = {
401+
struct tdx_module_args args = {
402402
.r10 = TDX_HYPERCALL_STANDARD,
403403
.r11 = EXIT_REASON_MSR_READ,
404404
.r12 = msr,
@@ -414,7 +414,7 @@ static void hv_tdx_msr_read(u64 msr, u64 *val)
414414

415415
u64 hv_tdx_hypercall(u64 control, u64 param1, u64 param2)
416416
{
417-
struct tdx_hypercall_args args = { };
417+
struct tdx_module_args args = { };
418418

419419
args.r10 = control;
420420
args.rdx = param1;

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

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -85,37 +85,16 @@ u64 __tdcall(u64 fn, struct tdx_module_args *args);
8585
u64 __tdcall_ret(u64 fn, struct tdx_module_args *args);
8686
u64 __tdcall_saved_ret(u64 fn, struct tdx_module_args *args);
8787

88-
/*
89-
* Used in __tdx_hypercall() to pass down and get back registers' values of
90-
* the TDCALL instruction when requesting services from the VMM.
91-
*
92-
* This is a software only structure and not part of the TDX module/VMM ABI.
93-
*/
94-
struct tdx_hypercall_args {
95-
u64 r8;
96-
u64 r9;
97-
u64 r10;
98-
u64 r11;
99-
u64 r12;
100-
u64 r13;
101-
u64 r14;
102-
u64 r15;
103-
u64 rdi;
104-
u64 rsi;
105-
u64 rbx;
106-
u64 rdx;
107-
};
108-
10988
/* Used to request services from the VMM */
110-
u64 __tdx_hypercall(struct tdx_hypercall_args *args);
89+
u64 __tdx_hypercall(struct tdx_module_args *args);
11190

11291
/*
11392
* Wrapper for standard use of __tdx_hypercall with no output aside from
11493
* return code.
11594
*/
11695
static inline u64 _tdx_hypercall(u64 fn, u64 r12, u64 r13, u64 r14, u64 r15)
11796
{
118-
struct tdx_hypercall_args args = {
97+
struct tdx_module_args args = {
11998
.r10 = TDX_HYPERCALL_STANDARD,
12099
.r11 = fn,
121100
.r12 = r12,

0 commit comments

Comments
 (0)