Re: [PATCHv2.1 05/29] x86/tdx: Add HLT support for TDX guests

Thomas Gleixner
2022-02-02T17:17:13Z

On Wed, Feb 02 2022 at 15:48, Kirill A. Shutemov wrote:

> On Tue, Feb 01, 2022 at 10:21:58PM +0100, Thomas Gleixner wrote:
>> On Sun, Jan 30 2022 at 01:30, Kirill A. Shutemov wrote:
>> This really can be simplified:
>>
>> cmpl $EXIT_REASON_SAFE_HLT, %r11d
>> jne .Lnohalt
>> movl $EXIT_REASON_HLT, %r11d
>> sti
>> .Lnohalt:
>> tdcall
>>
>> and the below becomes:
>>
>> static bool tdx_halt(void)
>> {
>> return !!__tdx_hypercall(EXIT_REASON_HLT, !!irqs_disabled(), 0, 0, 0, NULL);
>> }
>>
>> void __cpuidle tdx_safe_halt(void)
>> {
>> if (__tdx_hypercall(EXIT_REASON_SAFE_HLT, 0, 0, 0, 0, NULL)
>> WARN_ONCE(1, "HLT instruction emulation failed\n");
>> }
>>
>> Hmm?
>
> EXIT_REASON_* are architectural, see SDM vol 3D, appendix C. There's no
> EXIT_REASON_SAFE_HLT.
>
> Do you want to define a synthetic one? Like
>
> #define EXIT_REASON_SAFE_HLT 0x10000
> ?

That was my idea, yes.

> Looks dubious to me, I donno. I worry about possible conflicts with the
> spec in the future.

The spec should have a reserved space for such things :)

But you might think about having a in/out struct similar to the module
call or just an array of u64.

and the signature would become:

__tdx_hypercall(u64 op, u64 flags, struct inout *args)
__tdx_hypercall(u64 op, u64 flags, u64 *args)

and have flag bits:

HCALL_ISSUE_STI
HCALL_HAS_OUTPUT

Hmm?

Thanks,

tglx