KVM: x86: use direct accessors for RIP and RSP
authorPaolo Bonzini <pbonzini@redhat.com>
Tue, 30 Apr 2019 20:07:26 +0000 (22:07 +0200)
committerPaolo Bonzini <pbonzini@redhat.com>
Tue, 30 Apr 2019 20:07:26 +0000 (22:07 +0200)
Use specific inline functions for RIP and RSP instead of
going through kvm_register_read and kvm_register_write,
which are quite a mouthful.  kvm_rsp_read and kvm_rsp_write
did not exist, so add them.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
arch/x86/kvm/kvm_cache_regs.h
arch/x86/kvm/svm.c
arch/x86/kvm/vmx/nested.c
arch/x86/kvm/x86.c

index d179b7d7860df8121e286665bb9a8bff862ddd08..1cc6c47dc77e4856c59323be2904214cfbd967f9 100644 (file)
@@ -65,6 +65,16 @@ static inline void kvm_rip_write(struct kvm_vcpu *vcpu, unsigned long val)
        kvm_register_write(vcpu, VCPU_REGS_RIP, val);
 }
 
+static inline unsigned long kvm_rsp_read(struct kvm_vcpu *vcpu)
+{
+       return kvm_register_read(vcpu, VCPU_REGS_RSP);
+}
+
+static inline void kvm_rsp_write(struct kvm_vcpu *vcpu, unsigned long val)
+{
+       kvm_register_write(vcpu, VCPU_REGS_RSP, val);
+}
+
 static inline u64 kvm_pdptr_read(struct kvm_vcpu *vcpu, int index)
 {
        might_sleep();  /* on svm */
index 38aef34397992aaaaf1db127ae1cb0c69d3bca2d..893686cb00447ed48b04d9deb262fb0e24bd01f9 100644 (file)
@@ -3389,8 +3389,8 @@ static int nested_svm_vmexit(struct vcpu_svm *svm)
                (void)kvm_set_cr3(&svm->vcpu, hsave->save.cr3);
        }
        kvm_rax_write(&svm->vcpu, hsave->save.rax);
-       kvm_register_write(&svm->vcpu, VCPU_REGS_RSP, hsave->save.rsp);
-       kvm_register_write(&svm->vcpu, VCPU_REGS_RIP, hsave->save.rip);
+       kvm_rsp_write(&svm->vcpu, hsave->save.rsp);
+       kvm_rip_write(&svm->vcpu, hsave->save.rip);
        svm->vmcb->save.dr7 = 0;
        svm->vmcb->save.cpl = 0;
        svm->vmcb->control.exit_int_info = 0;
@@ -3497,8 +3497,8 @@ static void enter_svm_guest_mode(struct vcpu_svm *svm, u64 vmcb_gpa,
 
        svm->vmcb->save.cr2 = svm->vcpu.arch.cr2 = nested_vmcb->save.cr2;
        kvm_rax_write(&svm->vcpu, nested_vmcb->save.rax);
-       kvm_register_write(&svm->vcpu, VCPU_REGS_RSP, nested_vmcb->save.rsp);
-       kvm_register_write(&svm->vcpu, VCPU_REGS_RIP, nested_vmcb->save.rip);
+       kvm_rsp_write(&svm->vcpu, nested_vmcb->save.rsp);
+       kvm_rip_write(&svm->vcpu, nested_vmcb->save.rip);
 
        /* In case we don't even reach vcpu_run, the fields are not updated */
        svm->vmcb->save.rax = nested_vmcb->save.rax;
index d97dbea150bab6feb7b650ee991e65e1d62ab65c..04b40a98f60bdc2595102500aeec6095fb2ff587 100644 (file)
@@ -2372,8 +2372,8 @@ static int prepare_vmcs02(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12,
        if (!enable_ept)
                vcpu->arch.walk_mmu->inject_page_fault = vmx_inject_page_fault_nested;
 
-       kvm_register_write(vcpu, VCPU_REGS_RSP, vmcs12->guest_rsp);
-       kvm_register_write(vcpu, VCPU_REGS_RIP, vmcs12->guest_rip);
+       kvm_rsp_write(vcpu, vmcs12->guest_rsp);
+       kvm_rip_write(vcpu, vmcs12->guest_rip);
        return 0;
 }
 
@@ -3401,8 +3401,8 @@ static void sync_vmcs12(struct kvm_vcpu *vcpu, struct vmcs12 *vmcs12)
        vmcs12->guest_cr0 = vmcs12_guest_cr0(vcpu, vmcs12);
        vmcs12->guest_cr4 = vmcs12_guest_cr4(vcpu, vmcs12);
 
-       vmcs12->guest_rsp = kvm_register_read(vcpu, VCPU_REGS_RSP);
-       vmcs12->guest_rip = kvm_register_read(vcpu, VCPU_REGS_RIP);
+       vmcs12->guest_rsp = kvm_rsp_read(vcpu);
+       vmcs12->guest_rip = kvm_rip_read(vcpu);
        vmcs12->guest_rflags = vmcs_readl(GUEST_RFLAGS);
 
        vmcs12->guest_es_selector = vmcs_read16(GUEST_ES_SELECTOR);
@@ -3585,8 +3585,8 @@ static void load_vmcs12_host_state(struct kvm_vcpu *vcpu,
                vcpu->arch.efer &= ~(EFER_LMA | EFER_LME);
        vmx_set_efer(vcpu, vcpu->arch.efer);
 
-       kvm_register_write(vcpu, VCPU_REGS_RSP, vmcs12->host_rsp);
-       kvm_register_write(vcpu, VCPU_REGS_RIP, vmcs12->host_rip);
+       kvm_rsp_write(vcpu, vmcs12->host_rsp);
+       kvm_rip_write(vcpu, vmcs12->host_rip);
        vmx_set_rflags(vcpu, X86_EFLAGS_FIXED);
        vmx_set_interrupt_shadow(vcpu, 0);
 
index b352a7c137cd0dfdda1c26d15a1e0634a3ec16f3..dc621f73e96b3b0aad91a1ec0948cd22af13bfd5 100644 (file)
@@ -8290,7 +8290,7 @@ static void __get_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
        regs->rdx = kvm_rdx_read(vcpu);
        regs->rsi = kvm_rsi_read(vcpu);
        regs->rdi = kvm_rdi_read(vcpu);
-       regs->rsp = kvm_register_read(vcpu, VCPU_REGS_RSP);
+       regs->rsp = kvm_rsp_read(vcpu);
        regs->rbp = kvm_rbp_read(vcpu);
 #ifdef CONFIG_X86_64
        regs->r8 = kvm_r8_read(vcpu);
@@ -8326,7 +8326,7 @@ static void __set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
        kvm_rdx_write(vcpu, regs->rdx);
        kvm_rsi_write(vcpu, regs->rsi);
        kvm_rdi_write(vcpu, regs->rdi);
-       kvm_register_write(vcpu, VCPU_REGS_RSP, regs->rsp);
+       kvm_rsp_write(vcpu, regs->rsp);
        kvm_rbp_write(vcpu, regs->rbp);
 #ifdef CONFIG_X86_64
        kvm_r8_write(vcpu, regs->r8);