On Thu, Feb 20, 2025 at 3:00 PM Dave Hansen <dave.hansen@xxxxxxxxx> wrote: > > On 2/20/25 13:16, Vishal Annapurve wrote: > > Direct HLT instruction execution causes #VEs for TDX VMs which is routed > > to hypervisor via TDCALL. safe_halt() routines execute HLT in STI-shadow > > so IRQs need to remain disabled until the TDCALL to ensure that pending > > IRQs are correctly treated as wake events. > > This isn't quite true. There's only one paravirt safe_halt() and it > doesn't do HLT or STI. pv_native_safe_halt() -> native_safe_halt() -> "sti; hlt". > > I think it's more true to say that "safe" halts are entered with IRQs > disabled. They logically do the halt operation and then enable > interrupts before returning. > > > So "sti;hlt" sequence needs to be replaced for TDX VMs with "TDCALL; > > *_irq_enable()" to keep interrupts disabled during TDCALL execution. > But this isn't new. TDX already tried to avoid "sti;hlt". It just > screwed up the implementation. > > > Commit bfe6ed0c6727 ("x86/tdx: Add HLT support for TDX guests") > > prevented the idle routines from using "sti;hlt". But it missed the > > paravirt routine which can be reached like this as an example: > > acpi_safe_halt() => > > raw_safe_halt() => > > arch_safe_halt() => > > irq.safe_halt() => > > pv_native_safe_halt() > > This, on the other hand, *is* important. > > > Modify tdx_safe_halt() to implement the sequence "TDCALL; > > raw_local_irq_enable()" and invoke tdx_halt() from idle routine which just > > executes TDCALL without toggling interrupt state. Introduce dependency > > on CONFIG_PARAVIRT and override paravirt halt()/safe_halt() routines for > > TDX VMs. > > This changelog glosses over one of the key points: Why *MUST* TDX use > paravirt? It further confuses the reasoning by alluding to the idea that > "Direct HLT instruction execution ... is routed to hypervisor via TDCALL". > > It gives background and a solution, but it's not obvious what the > problem is or how the solution _fixes_ the problem. > > What must TDX now depend on PARAVIRT? > > Why not just route the HLT to a TDXCALL via the #VE code? > > Makes sense, I will update the commit message in the next version to clearly answer these questions and address the above comments.