KVM: x86: nSVM: mark vmcb01 as dirty when restoring SMM saved state
authorMaxim Levitsky <mlevitsk@redhat.com>
Mon, 7 Feb 2022 15:54:20 +0000 (17:54 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 8 Feb 2022 18:30:47 +0000 (13:30 -0500)
commite8efa4ff00374d2e6f47f6e4628ca3b541c001af
tree5fac2f4bc40add0dd9857cc73a684cd5f8953956
parente1779c2714c3023e4629825762bcbc43a3b943df
KVM: x86: nSVM: mark vmcb01 as dirty when restoring SMM saved state

While usually, restoring the smm state makes the KVM enter
the nested guest thus a different vmcb (vmcb02 vs vmcb01),
KVM should still mark it as dirty, since hardware
can in theory cache multiple vmcbs.

Failure to do so, combined with lack of setting the
nested_run_pending (which is fixed in the next patch),
might make KVM re-enter vmcb01, which was just exited from,
with completely different set of guest state registers
(SMM vs non SMM) and without proper dirty bits set,
which results in the CPU reusing stale IDTR pointer
which leads to a guest shutdown on any interrupt.

On the real hardware this usually doesn't happen,
but when running nested, L0's KVM does check and
honour few dirty bits, causing this issue to happen.

This patch fixes boot of hyperv and SMM enabled
windows VM running nested on KVM.

Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
Cc: stable@vger.kernel.org
Message-Id: <20220207155447.840194-4-mlevitsk@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/svm/svm.c