summaryrefslogtreecommitdiff
path: root/arch/x86/kvm/svm/svm.c
diff options
context:
space:
mode:
authorSean Christopherson <seanjc@google.com>2021-02-04 16:57:45 -0800
committerPaolo Bonzini <pbonzini@redhat.com>2021-03-15 04:43:17 -0400
commit2ac636a6ea4dae8260639e8df5c457c0c74cafa9 (patch)
tree1ccca8311e328dbdde9eb00a1294925ff7a87dab /arch/x86/kvm/svm/svm.c
parent3a87c7e0d176ff73c9ef5d58d89ad65f3be31d1b (diff)
downloadlwn-2ac636a6ea4dae8260639e8df5c457c0c74cafa9.tar.gz
lwn-2ac636a6ea4dae8260639e8df5c457c0c74cafa9.zip
KVM: nSVM: Add VMLOAD/VMSAVE helper to deduplicate code
Add another helper layer for VMLOAD+VMSAVE, the code is identical except for the one line that determines which VMCB is the source and which is the destination. No functional change intended. Signed-off-by: Sean Christopherson <seanjc@google.com> Message-Id: <20210205005750.3841462-5-seanjc@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'arch/x86/kvm/svm/svm.c')
-rw-r--r--arch/x86/kvm/svm/svm.c37
1 files changed, 12 insertions, 25 deletions
diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 352cf794ed7d..8e62b9988f10 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -2118,7 +2118,7 @@ static int vmmcall_interception(struct kvm_vcpu *vcpu)
return kvm_emulate_hypercall(vcpu);
}
-static int vmload_interception(struct kvm_vcpu *vcpu)
+static int vmload_vmsave_interception(struct kvm_vcpu *vcpu, bool vmload)
{
struct vcpu_svm *svm = to_svm(vcpu);
struct vmcb *vmcb12;
@@ -2139,37 +2139,24 @@ static int vmload_interception(struct kvm_vcpu *vcpu)
ret = kvm_skip_emulated_instruction(vcpu);
- nested_svm_vmloadsave(vmcb12, svm->vmcb);
+ if (vmload)
+ nested_svm_vmloadsave(vmcb12, svm->vmcb);
+ else
+ nested_svm_vmloadsave(svm->vmcb, vmcb12);
+
kvm_vcpu_unmap(vcpu, &map, true);
return ret;
}
-static int vmsave_interception(struct kvm_vcpu *vcpu)
+static int vmload_interception(struct kvm_vcpu *vcpu)
{
- struct vcpu_svm *svm = to_svm(vcpu);
- struct vmcb *vmcb12;
- struct kvm_host_map map;
- int ret;
-
- if (nested_svm_check_permissions(vcpu))
- return 1;
-
- ret = kvm_vcpu_map(vcpu, gpa_to_gfn(svm->vmcb->save.rax), &map);
- if (ret) {
- if (ret == -EINVAL)
- kvm_inject_gp(vcpu, 0);
- return 1;
- }
-
- vmcb12 = map.hva;
-
- ret = kvm_skip_emulated_instruction(vcpu);
-
- nested_svm_vmloadsave(svm->vmcb, vmcb12);
- kvm_vcpu_unmap(vcpu, &map, true);
+ return vmload_vmsave_interception(vcpu, true);
+}
- return ret;
+static int vmsave_interception(struct kvm_vcpu *vcpu)
+{
+ return vmload_vmsave_interception(vcpu, false);
}
static int vmrun_interception(struct kvm_vcpu *vcpu)