[PATCH 07/20] x86/tdx: Convert CPUID handling to use new TDVMCALL_4()

From: Kirill A. Shutemov
Date: Fri May 17 2024 - 10:21:47 EST


Use newly introduced TDVMCALL_4() instead of __tdx_hypercall() to handle
CPUID instruction emulation.

It cuts code bloat substantially:

Function old new delta
tdx_handle_virt_exception 1819 1747 -72

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@xxxxxxxxxxxxxxx>
---
arch/x86/coco/tdx/tdx.c | 20 ++------------------
1 file changed, 2 insertions(+), 18 deletions(-)

diff --git a/arch/x86/coco/tdx/tdx.c b/arch/x86/coco/tdx/tdx.c
index f59a2b3500db..c436cab355e0 100644
--- a/arch/x86/coco/tdx/tdx.c
+++ b/arch/x86/coco/tdx/tdx.c
@@ -414,13 +414,6 @@ static int write_msr(struct pt_regs *regs, struct ve_info *ve)

static int handle_cpuid(struct pt_regs *regs, struct ve_info *ve)
{
- struct tdx_module_args args = {
- .r10 = TDX_HYPERCALL_STANDARD,
- .r11 = hcall_func(EXIT_REASON_CPUID),
- .r12 = regs->ax,
- .r13 = regs->cx,
- };
-
/*
* Only allow VMM to control range reserved for hypervisor
* communication.
@@ -438,19 +431,10 @@ static int handle_cpuid(struct pt_regs *regs, struct ve_info *ve)
* ABI can be found in TDX Guest-Host-Communication Interface
* (GHCI), section titled "VP.VMCALL<Instruction.CPUID>".
*/
- if (__tdx_hypercall(&args))
+ if (TDVMCALL_4(EXIT_REASON_CPUID, regs->ax, regs->cx, 0, 0,
+ regs->ax, regs->bx, regs->cx, regs->dx))
return -EIO;

- /*
- * As per TDX GHCI CPUID ABI, r12-r15 registers contain contents of
- * EAX, EBX, ECX, EDX registers after the CPUID instruction execution.
- * So copy the register contents back to pt_regs.
- */
- regs->ax = args.r12;
- regs->bx = args.r13;
- regs->cx = args.r14;
- regs->dx = args.r15;
-
return ve_instr_len(ve);
}

--
2.43.0