Messages in this thread | | | Date | Wed, 26 Jan 2022 17:05:30 +0100 | Subject | Re: [PATCH] KVM: nVMX: WARN on any attempt to allocate shadow VMCS for vmcs02 | From | Paolo Bonzini <> |
| |
On 1/26/22 16:56, Vitaly Kuznetsov wrote: >> - WARN_ON(loaded_vmcs == &vmx->vmcs01 && loaded_vmcs->shadow_vmcs); >> + if (WARN_ON(loaded_vmcs != &vmx->vmcs01 || loaded_vmcs->shadow_vmcs)) >> + return loaded_vmcs->shadow_vmcs; > Stupid question: why do we want to care about 'loaded_vmcs' at all, > i.e. why can't we hardcode 'vmx->vmcs01' in alloc_shadow_vmcs()? The > only caller is enter_vmx_operation() and AFAIU 'loaded_vmcs' will always > be pointing to 'vmx->vmcs01' (as enter_vmx_operation() allocates > &vmx->nested.vmcs02 so 'loaded_vmcs' can't point there!). >
Well, that's why the WARN never happens. The idea is that if shadow VMCS _virtualization_ (not emulation, i.e. running L2 VMREAD/VMWRITE without even a vmexit to L0) was supported, then you would need a non-NULL shadow_vmcs in vmx->vmcs02.
Regarding the patch, the old WARN was messy but it was also trying to avoid a NULL pointer dereference in the caller.
What about:
if (WARN_ON(loaded_vmcs->shadow_vmcs)) return loaded_vmcs->shadow_vmcs;
/* Go ahead anyway. */ WARN_ON(loaded_vmcs != &vmx->vmcs01);
?
Paolo
| |