Messages in this thread | | | Date | Thu, 22 Apr 2021 18:35:46 -0700 | From | Andi Kleen <> | Subject | Re: [PATCH v2 1/1] x86/tdx: Add __tdcall() and __tdvmcall() helper functions |
| |
On Thu, Apr 22, 2021 at 06:21:07PM -0700, Dave Hansen wrote: > 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
It's possible, but you would need to mark a lot more registers clobbered (the x86-64 ABI allows to clobber many registers)
I don't think the stack would be messed up, but there might be problems with writing the correct unwind information (which tends to be tricky)
Usually it's better to avoid it.
-Andi
> 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.
| |