Re: [PATCH v3 12/12] x86/virt/tdx: Adjust 'struct tdx_module_args' to use x86 "register index" layout

From: Huang, Kai
Date: Sun Aug 06 2023 - 22:17:06 EST


On Sun, 2023-08-06 at 14:50 +0300, kirill.shutemov@xxxxxxxxxxxxxxx wrote:
> On Wed, Jul 26, 2023 at 11:25:14PM +1200, Kai Huang wrote:
> > For TDX guest, KVM needs to call __seamcall_saved_ret() to make the
> > TDH.VP.ENTER SEAMCALL to enter the guest, possibly taking all registers
> > in 'struct tdx_module_args' as input/output.
> >
> > KVM caches guest's GPRs in 'kvm_vcpu_arch::regs[]', which follows the
> > "register index" hardware layout of x86 GPRs. On the other hand, the
> > __seamcall_saved_ret() takes the pointer of 'struct tdx_module_args' as
> > argument, thus there's a mismatch.
> >
> > KVM could choose to copy input registers from 'vcpu::regs[]' to a
> > 'struct tdx_module_args' and use that as argument to make the SEAMCALL,
> > but such memory copy isn't desired and should be avoided if possible.
>
> I doubt the copy will be visible on any profile.
>
> I personally don't like that kvm implementation detail leaks here. It
> suppose to be generic TDX code.
>
>

Well I kinda agree with you. But it seems Peter wanted this to be done:

https://lore.kernel.org/lkml/a23ce8fd289141cea3a1b4f3dace221dca847238.camel@xxxxxxxxx/T/#m37f39493e9f2bf0a4c9ccc72aaf4938927375dc1