]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
KVM: x86: Ensure vendor's exit handler runs before fastpath userspace exits
authorSean Christopherson <seanjc@google.com>
Thu, 23 Apr 2026 16:26:27 +0000 (09:26 -0700)
committerSean Christopherson <seanjc@google.com>
Wed, 13 May 2026 16:53:55 +0000 (09:53 -0700)
commit0ffedf43910e44b76c2c1db4e9fbf12b268190c1
tree996432dfe2bbb92db780b7f11872d1d75df7d466
parentb7fbe9a1bf9ee6c967ef77d366ca58c35fcf1887
KVM: x86: Ensure vendor's exit handler runs before fastpath userspace exits

Move the handling of fastpath userspace exits into vendor code to ensure
KVM runs vendor specific operations that need to run before userspace gains
control of the vCPU.  E.g. for VMX (and soon to be for SVM as well), KVM
needs to flush the PML buffer prior to exiting to userspace, otherwise any
memory written by the final KVM_RUN might never be flagged as dirty.

Note, waiting to snapshot CR0 and CR3 until svm_handle_exit() is flawed in
general, as that risks consuming stale state in a fastpath handler.  That
will be addressed in a future change.

Fixes: f7f39c50edb9 ("KVM: x86: Exit to userspace if fastpath triggers one on instruction skip")
Cc: stable@vger.kernel.org
Cc: Nikunj A. Dadhania <nikunj@amd.com>
Reviewed-by: Nikunj A. Dadhania <nikunj@amd.com>
Reviewed-by: Kai Huang <kai.huang@intel.com>
Link: https://patch.msgid.link/20260423162628.490962-2-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
arch/x86/kvm/svm/svm.c
arch/x86/kvm/vmx/vmx.c
arch/x86/kvm/x86.c