Re: [PATCH v2 1/1] x86/tdx: Add __tdcall() and __tdvmcall() helper functions

From: Dave Hansen
Date: Thu Apr 22 2021 - 21:21:13 EST


On 4/22/21 6:09 PM, Kuppuswamy, Sathyanarayanan wrote:
> But let me try to explain it here. What I meant by complication is,
> for in/out instruction, we use alternative_io() to substitute in/out
> instructions with tdg_in()/tdg_out() assembly calls. So we have to ensure
> that we don't corrupt registers or stack from the substituted instructions
>
> If you check the implementation of tdg_in()/tdg_out(), you will notice
> that we have added code to preserve the caller registers. So, if we use
> C wrapper for this use case, there is a chance that it might mess
> the caller registers or stack.
>
>     alternative_io("in" #bwl " %w2, %" #bw "0",            \
>             "call tdg_in" #bwl, X86_FEATURE_TDX_GUEST,    \
>             "=a"(value), "d"(port))

Are you saying that calling C functions from inline assembly might
corrupt the stack or registers? Are you suggesting that you simply
can't call C functions from inline assembly? Or, that you can't express
the register clobbers of a function call in inline assembly?

You might want to check around the kernel to see how other folks do it.