Re: [PATCH v2] KVM: x86: nSVM/nVMX: Fix handling triple fault on RSM instruction
From: Wilczynski, Michal
Date: Tue Jan 30 2024 - 15:08:01 EST
On 1/25/2024 1:57 AM, Yunhong Jiang wrote:
> On Tue, Jan 23, 2024 at 02:15:55AM +0200, Michal Wilczynski wrote:
>> To resolve this, introduce a new emulator flag indicating the need for
>> HW VM-Enter to complete emulating RSM. Based on this flag, a decision can
>> be made in vendor-specific triple fault handlers about whether
>> nested_pending_run needs to be cleared.
> Would it be ok to move the followed emulator_leave_smm() code into
> vmx_leave_smm, before setting nested_run_pending bit? It avoids changing
> the generic emulator code.
>
> #ifdef CONFIG_X86_64
> if (guest_cpuid_has(vcpu, X86_FEATURE_LM))
> return rsm_load_state_64(ctxt, &smram.smram64);
> else
> #endif
> return rsm_load_state_32(ctxt, &smram.smram32);
>
> --jyh
>
Moving rsm_load_state_* to the vendor structs would be architecturally
incorrect as vendor callbacks should only do vendor specific stuff, and
recovering state from SMRAM is VMX/SVM independent, and should be kept
that way.
nested_pending_run is unfortunately buried in vendor-specific structs so
it's zeroeing has to be done in vendor specific callbacks.
The way I structured this fix is hopefully in line with the discussion
under v1 of this patch, where Sean gave some background on the code and
proposed ways to fix.
Thanks for your input !
Michał