Commit 8a8544bd authored by Kai Huang's avatar Kai Huang Committed by Dave Hansen

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: default avatarPeter Zijlstra <peterz@infradead.org>
Signed-off-by: default avatarKai Huang <kai.huang@intel.com>
Signed-off-by: default avatarDave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: default avatarKirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/all/798dad5ce24e9d745cf0e16825b75ccc433ad065.1692096753.git.kai.huang%40intel.com
parent 90f5ecd3
...@@ -18,7 +18,7 @@ void __tdx_hypercall_failed(void) ...@@ -18,7 +18,7 @@ void __tdx_hypercall_failed(void)
static inline unsigned int tdx_io_in(int size, u16 port) static inline unsigned int tdx_io_in(int size, u16 port)
{ {
struct tdx_hypercall_args args = { struct tdx_module_args args = {
.r10 = TDX_HYPERCALL_STANDARD, .r10 = TDX_HYPERCALL_STANDARD,
.r11 = hcall_func(EXIT_REASON_IO_INSTRUCTION), .r11 = hcall_func(EXIT_REASON_IO_INSTRUCTION),
.r12 = size, .r12 = size,
...@@ -34,7 +34,7 @@ static inline unsigned int tdx_io_in(int size, u16 port) ...@@ -34,7 +34,7 @@ static inline unsigned int tdx_io_in(int size, u16 port)
static inline void tdx_io_out(int size, u16 port, u32 value) static inline void tdx_io_out(int size, u16 port, u32 value)
{ {
struct tdx_hypercall_args args = { struct tdx_module_args args = {
.r10 = TDX_HYPERCALL_STANDARD, .r10 = TDX_HYPERCALL_STANDARD,
.r11 = hcall_func(EXIT_REASON_IO_INSTRUCTION), .r11 = hcall_func(EXIT_REASON_IO_INSTRUCTION),
.r12 = size, .r12 = size,
......
...@@ -70,45 +70,22 @@ bool tdx_accept_memory(phys_addr_t start, phys_addr_t end) ...@@ -70,45 +70,22 @@ bool tdx_accept_memory(phys_addr_t start, phys_addr_t end)
return true; return true;
} }
noinstr u64 __tdx_hypercall(struct tdx_hypercall_args *args) noinstr u64 __tdx_hypercall(struct tdx_module_args *args)
{ {
struct tdx_module_args margs = { /*
.rcx = TDVMCALL_EXPOSE_REGS_MASK, * For TDVMCALL explicitly set RCX to the bitmap of shared registers.
.rdx = args->rdx, * The caller isn't expected to set @args->rcx anyway.
.r8 = args->r8, */
.r9 = args->r9, args->rcx = TDVMCALL_EXPOSE_REGS_MASK;
.r10 = args->r10,
.r11 = args->r11,
.r12 = args->r12,
.r13 = args->r13,
.r14 = args->r14,
.r15 = args->r15,
.rbx = args->rbx,
.rdi = args->rdi,
.rsi = args->rsi,
};
/* /*
* Failure of __tdcall_saved_ret() indicates a failure of the TDVMCALL * Failure of __tdcall_saved_ret() indicates a failure of the TDVMCALL
* mechanism itself and that something has gone horribly wrong with * mechanism itself and that something has gone horribly wrong with
* the TDX module. __tdx_hypercall_failed() never returns. * the TDX module. __tdx_hypercall_failed() never returns.
*/ */
if (__tdcall_saved_ret(TDG_VP_VMCALL, &margs)) if (__tdcall_saved_ret(TDG_VP_VMCALL, args))
__tdx_hypercall_failed(); __tdx_hypercall_failed();
args->r8 = margs.r8;
args->r9 = margs.r9;
args->r10 = margs.r10;
args->r11 = margs.r11;
args->r12 = margs.r12;
args->r13 = margs.r13;
args->r14 = margs.r14;
args->r15 = margs.r15;
args->rdi = margs.rdi;
args->rsi = margs.rsi;
args->rbx = margs.rbx;
args->rdx = margs.rdx;
/* TDVMCALL leaf return code is in R10 */ /* TDVMCALL leaf return code is in R10 */
return args->r10; return args->r10;
} }
...@@ -48,7 +48,7 @@ noinstr void __noreturn __tdx_hypercall_failed(void) ...@@ -48,7 +48,7 @@ noinstr void __noreturn __tdx_hypercall_failed(void)
long tdx_kvm_hypercall(unsigned int nr, unsigned long p1, unsigned long p2, long tdx_kvm_hypercall(unsigned int nr, unsigned long p1, unsigned long p2,
unsigned long p3, unsigned long p4) unsigned long p3, unsigned long p4)
{ {
struct tdx_hypercall_args args = { struct tdx_module_args args = {
.r10 = nr, .r10 = nr,
.r11 = p1, .r11 = p1,
.r12 = p2, .r12 = p2,
...@@ -108,7 +108,7 @@ EXPORT_SYMBOL_GPL(tdx_mcall_get_report0); ...@@ -108,7 +108,7 @@ EXPORT_SYMBOL_GPL(tdx_mcall_get_report0);
static void __noreturn tdx_panic(const char *msg) static void __noreturn tdx_panic(const char *msg)
{ {
struct tdx_hypercall_args args = { struct tdx_module_args args = {
.r10 = TDX_HYPERCALL_STANDARD, .r10 = TDX_HYPERCALL_STANDARD,
.r11 = TDVMCALL_REPORT_FATAL_ERROR, .r11 = TDVMCALL_REPORT_FATAL_ERROR,
.r12 = 0, /* Error code: 0 is Panic */ .r12 = 0, /* Error code: 0 is Panic */
...@@ -230,7 +230,7 @@ static int ve_instr_len(struct ve_info *ve) ...@@ -230,7 +230,7 @@ static int ve_instr_len(struct ve_info *ve)
static u64 __cpuidle __halt(const bool irq_disabled) static u64 __cpuidle __halt(const bool irq_disabled)
{ {
struct tdx_hypercall_args args = { struct tdx_module_args args = {
.r10 = TDX_HYPERCALL_STANDARD, .r10 = TDX_HYPERCALL_STANDARD,
.r11 = hcall_func(EXIT_REASON_HLT), .r11 = hcall_func(EXIT_REASON_HLT),
.r12 = irq_disabled, .r12 = irq_disabled,
...@@ -274,7 +274,7 @@ void __cpuidle tdx_safe_halt(void) ...@@ -274,7 +274,7 @@ void __cpuidle tdx_safe_halt(void)
static int read_msr(struct pt_regs *regs, struct ve_info *ve) static int read_msr(struct pt_regs *regs, struct ve_info *ve)
{ {
struct tdx_hypercall_args args = { struct tdx_module_args args = {
.r10 = TDX_HYPERCALL_STANDARD, .r10 = TDX_HYPERCALL_STANDARD,
.r11 = hcall_func(EXIT_REASON_MSR_READ), .r11 = hcall_func(EXIT_REASON_MSR_READ),
.r12 = regs->cx, .r12 = regs->cx,
...@@ -295,7 +295,7 @@ static int read_msr(struct pt_regs *regs, struct ve_info *ve) ...@@ -295,7 +295,7 @@ static int read_msr(struct pt_regs *regs, struct ve_info *ve)
static int write_msr(struct pt_regs *regs, struct ve_info *ve) static int write_msr(struct pt_regs *regs, struct ve_info *ve)
{ {
struct tdx_hypercall_args args = { struct tdx_module_args args = {
.r10 = TDX_HYPERCALL_STANDARD, .r10 = TDX_HYPERCALL_STANDARD,
.r11 = hcall_func(EXIT_REASON_MSR_WRITE), .r11 = hcall_func(EXIT_REASON_MSR_WRITE),
.r12 = regs->cx, .r12 = regs->cx,
...@@ -315,7 +315,7 @@ static int write_msr(struct pt_regs *regs, struct ve_info *ve) ...@@ -315,7 +315,7 @@ static int write_msr(struct pt_regs *regs, struct ve_info *ve)
static int handle_cpuid(struct pt_regs *regs, struct ve_info *ve) static int handle_cpuid(struct pt_regs *regs, struct ve_info *ve)
{ {
struct tdx_hypercall_args args = { struct tdx_module_args args = {
.r10 = TDX_HYPERCALL_STANDARD, .r10 = TDX_HYPERCALL_STANDARD,
.r11 = hcall_func(EXIT_REASON_CPUID), .r11 = hcall_func(EXIT_REASON_CPUID),
.r12 = regs->ax, .r12 = regs->ax,
...@@ -357,7 +357,7 @@ static int handle_cpuid(struct pt_regs *regs, struct ve_info *ve) ...@@ -357,7 +357,7 @@ static int handle_cpuid(struct pt_regs *regs, struct ve_info *ve)
static bool mmio_read(int size, unsigned long addr, unsigned long *val) static bool mmio_read(int size, unsigned long addr, unsigned long *val)
{ {
struct tdx_hypercall_args args = { struct tdx_module_args args = {
.r10 = TDX_HYPERCALL_STANDARD, .r10 = TDX_HYPERCALL_STANDARD,
.r11 = hcall_func(EXIT_REASON_EPT_VIOLATION), .r11 = hcall_func(EXIT_REASON_EPT_VIOLATION),
.r12 = size, .r12 = size,
...@@ -486,7 +486,7 @@ static int handle_mmio(struct pt_regs *regs, struct ve_info *ve) ...@@ -486,7 +486,7 @@ static int handle_mmio(struct pt_regs *regs, struct ve_info *ve)
static bool handle_in(struct pt_regs *regs, int size, int port) static bool handle_in(struct pt_regs *regs, int size, int port)
{ {
struct tdx_hypercall_args args = { struct tdx_module_args args = {
.r10 = TDX_HYPERCALL_STANDARD, .r10 = TDX_HYPERCALL_STANDARD,
.r11 = hcall_func(EXIT_REASON_IO_INSTRUCTION), .r11 = hcall_func(EXIT_REASON_IO_INSTRUCTION),
.r12 = size, .r12 = size,
...@@ -723,7 +723,7 @@ static bool tdx_map_gpa(phys_addr_t start, phys_addr_t end, bool enc) ...@@ -723,7 +723,7 @@ static bool tdx_map_gpa(phys_addr_t start, phys_addr_t end, bool enc)
} }
while (retry_count < max_retries_per_page) { while (retry_count < max_retries_per_page) {
struct tdx_hypercall_args args = { struct tdx_module_args args = {
.r10 = TDX_HYPERCALL_STANDARD, .r10 = TDX_HYPERCALL_STANDARD,
.r11 = TDVMCALL_MAP_GPA, .r11 = TDVMCALL_MAP_GPA,
.r12 = start, .r12 = start,
......
...@@ -384,7 +384,7 @@ static inline void hv_ghcb_msr_read(u64 msr, u64 *value) {} ...@@ -384,7 +384,7 @@ static inline void hv_ghcb_msr_read(u64 msr, u64 *value) {}
#ifdef CONFIG_INTEL_TDX_GUEST #ifdef CONFIG_INTEL_TDX_GUEST
static void hv_tdx_msr_write(u64 msr, u64 val) static void hv_tdx_msr_write(u64 msr, u64 val)
{ {
struct tdx_hypercall_args args = { struct tdx_module_args args = {
.r10 = TDX_HYPERCALL_STANDARD, .r10 = TDX_HYPERCALL_STANDARD,
.r11 = EXIT_REASON_MSR_WRITE, .r11 = EXIT_REASON_MSR_WRITE,
.r12 = msr, .r12 = msr,
...@@ -398,7 +398,7 @@ static void hv_tdx_msr_write(u64 msr, u64 val) ...@@ -398,7 +398,7 @@ static void hv_tdx_msr_write(u64 msr, u64 val)
static void hv_tdx_msr_read(u64 msr, u64 *val) static void hv_tdx_msr_read(u64 msr, u64 *val)
{ {
struct tdx_hypercall_args args = { struct tdx_module_args args = {
.r10 = TDX_HYPERCALL_STANDARD, .r10 = TDX_HYPERCALL_STANDARD,
.r11 = EXIT_REASON_MSR_READ, .r11 = EXIT_REASON_MSR_READ,
.r12 = msr, .r12 = msr,
...@@ -414,7 +414,7 @@ static void hv_tdx_msr_read(u64 msr, u64 *val) ...@@ -414,7 +414,7 @@ static void hv_tdx_msr_read(u64 msr, u64 *val)
u64 hv_tdx_hypercall(u64 control, u64 param1, u64 param2) u64 hv_tdx_hypercall(u64 control, u64 param1, u64 param2)
{ {
struct tdx_hypercall_args args = { }; struct tdx_module_args args = { };
args.r10 = control; args.r10 = control;
args.rdx = param1; args.rdx = param1;
......
...@@ -85,29 +85,8 @@ u64 __tdcall(u64 fn, struct tdx_module_args *args); ...@@ -85,29 +85,8 @@ u64 __tdcall(u64 fn, struct tdx_module_args *args);
u64 __tdcall_ret(u64 fn, struct tdx_module_args *args); u64 __tdcall_ret(u64 fn, struct tdx_module_args *args);
u64 __tdcall_saved_ret(u64 fn, struct tdx_module_args *args); u64 __tdcall_saved_ret(u64 fn, struct tdx_module_args *args);
/*
* Used in __tdx_hypercall() to pass down and get back registers' values of
* the TDCALL instruction when requesting services from the VMM.
*
* This is a software only structure and not part of the TDX module/VMM ABI.
*/
struct tdx_hypercall_args {
u64 r8;
u64 r9;
u64 r10;
u64 r11;
u64 r12;
u64 r13;
u64 r14;
u64 r15;
u64 rdi;
u64 rsi;
u64 rbx;
u64 rdx;
};
/* Used to request services from the VMM */ /* Used to request services from the VMM */
u64 __tdx_hypercall(struct tdx_hypercall_args *args); u64 __tdx_hypercall(struct tdx_module_args *args);
/* /*
* Wrapper for standard use of __tdx_hypercall with no output aside from * Wrapper for standard use of __tdx_hypercall with no output aside from
...@@ -115,7 +94,7 @@ u64 __tdx_hypercall(struct tdx_hypercall_args *args); ...@@ -115,7 +94,7 @@ u64 __tdx_hypercall(struct tdx_hypercall_args *args);
*/ */
static inline u64 _tdx_hypercall(u64 fn, u64 r12, u64 r13, u64 r14, u64 r15) static inline u64 _tdx_hypercall(u64 fn, u64 r12, u64 r13, u64 r14, u64 r15)
{ {
struct tdx_hypercall_args args = { struct tdx_module_args args = {
.r10 = TDX_HYPERCALL_STANDARD, .r10 = TDX_HYPERCALL_STANDARD,
.r11 = fn, .r11 = fn,
.r12 = r12, .r12 = r12,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment