Re: [PATCH v17 011/116] KVM: TDX: Add C wrapper functions for SEAMCALLs to the TDX module

From: Huang, Kai
Date: Tue Dec 19 2023 - 05:39:39 EST


On Tue, 2023-11-07 at 06:55 -0800, isaku.yamahata@xxxxxxxxx wrote:
> +static inline u64 tdx_seamcall(u64 op, u64 rcx, u64 rdx, u64 r8, u64 r9,
> +        struct tdx_module_args *out)
> +{
> + u64 ret;
> +
> + if (out) {
> + *out = (struct tdx_module_args) {
> + .rcx = rcx,
> + .rdx = rdx,
> + .r8 = r8,
> + .r9 = r9,
> + };
> + ret = __seamcall_ret(op, out);
> + } else {
> + struct tdx_module_args args = {
> + .rcx = rcx,
> + .rdx = rdx,
> + .r8 = r8,
> + .r9 = r9,
> + };
> + ret = __seamcall(op, &args);
> + }
> + if (unlikely(ret == TDX_SEAMCALL_UD)) {
> + /*
> + * SEAMCALLs fail with TDX_SEAMCALL_UD returned when VMX is off.
> + * This can happen when the host gets rebooted or live
> + * updated. In this case, the instruction execution is ignored
> + * as KVM is shut down, so the error code is suppressed. Other
> + * than this, the error is unexpected and the execution can't
> + * continue as the TDX features reply on VMX to be on.
> + */
> + kvm_spurious_fault();
> + return 0;
> + }
> + return ret;
> +}

Why is tdx_seamcall() still taking individual registers as input? This is not
extendable for supporting SEAMCALLs taking more input registers such as live
migration SEAMCALLs.

It's OK to take individual inputs for the SEAMCALL leaf wrappers like ...

> +
> +static inline u64 tdh_mng_addcx(hpa_t tdr, hpa_t addr)
> +{
> + clflush_cache_range(__va(addr), PAGE_SIZE);
> + return tdx_seamcall(TDH_MNG_ADDCX, addr, tdr, 0, 0, NULL);
> +}

... this, but the tdx_seamcall() should just take 'struct tdx_module_args' as
argument.