summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYosry Ahmed <yosry@kernel.org>2026-05-28 02:46:57 +0300
committerSean Christopherson <seanjc@google.com>2026-05-28 04:45:48 +0300
commit0a35c2a051f34890f39befb5dc4f1cf41ec12b2a (patch)
treebb7464cc02831b7c654ac00e752245e966b4f2e2
parent42ff88db18a5a42f619eab1d862e04e6505e8ee6 (diff)
downloadlinux-0a35c2a051f34890f39befb5dc4f1cf41ec12b2a.tar.xz
KVM: nSVM: Unify RIP and PMU handling calls when emulating VMRUN
The code paths for advancing RIP and retiring the instruction for RIP are very similar whether or not caching vmcb12 succeeds. The only difference is handling mapping failures (i.e. EFAULT). Pull the mapping failure handling out and unify the calls to svm_skip_emulated_instruction() and kvm_pmu_instruction_retired(), but return immediately after if copying and caching vmcb12 failed. A nice side effect of this is that the FIXME comment is now above the only code path calling svm_skip_emulated_instruction(). Signed-off-by: Yosry Ahmed <yosry@kernel.org> Link: https://patch.msgid.link/20260527234711.4175166-4-yosry@kernel.org Signed-off-by: Sean Christopherson <seanjc@google.com>
-rw-r--r--arch/x86/kvm/svm/nested.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
index 6e26c8e1b771..2ef31efd4c9d 100644
--- a/arch/x86/kvm/svm/nested.c
+++ b/arch/x86/kvm/svm/nested.c
@@ -1136,20 +1136,13 @@ int nested_svm_vmrun(struct kvm_vcpu *vcpu)
}
ret = nested_svm_copy_vmcb12_to_cache(vcpu, vmcb12_gpa);
- if (ret) {
- if (ret == -EFAULT)
- return kvm_handle_memory_failure(vcpu, X86EMUL_IO_NEEDED, NULL);
-
- /* Advance RIP past VMRUN as part of the nested #VMEXIT. */
- if (!svm_skip_emulated_instruction(vcpu))
- return 0;
-
- kvm_pmu_instruction_retired(vcpu);
- return 1;
- }
+ if (ret == -EFAULT)
+ return kvm_handle_memory_failure(vcpu, X86EMUL_IO_NEEDED, NULL);
/*
- * At this point, VMRUN is guaranteed to not fault; advance RIP.
+ * At this point, VMRUN is guaranteed to not fault; advance RIP. If
+ * caching vmcb12 failed for other reasons, return immediately afterward
+ * as a nested #VMEXIT was already set up.
*
* FIXME: If TF is set on VMRUN should inject a #DB (or handle guest
* debugging) right after #VMEXIT, right now it's just ignored.
@@ -1159,6 +1152,9 @@ int nested_svm_vmrun(struct kvm_vcpu *vcpu)
kvm_pmu_instruction_retired(vcpu);
+ if (ret)
+ return 1;
+
/*
* Since vmcb01 is not in use, we can use it to store some of the L1
* state.