aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86
diff options
context:
space:
mode:
authorXiao Guangrong <xiaoguangrong@cn.fujitsu.com>2011-07-11 15:22:46 -0400
committerAvi Kivity <avi@redhat.com>2011-07-24 04:50:25 -0400
commitaf7cc7d1ee422a612f6785e347a893d44cc892ea (patch)
tree8897ab6ef96d67a0a42cbd30aed66a50356cd3d4 /arch/x86
parentffb61bb3bca33ff8e68d11d7cb6b27ac0f74a2c0 (diff)
KVM: x86: introduce vcpu_mmio_gva_to_gpa to cleanup the code
Introduce vcpu_mmio_gva_to_gpa to translate the gva to gpa, we can use it to cleanup the code between read emulation and write emulation Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com> Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/x86')
-rw-r--r--arch/x86/kvm/x86.c42
1 files changed, 31 insertions, 11 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index c96cdc092484..a1dbd0443545 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -4010,6 +4010,27 @@ out:
4010} 4010}
4011EXPORT_SYMBOL_GPL(kvm_write_guest_virt_system); 4011EXPORT_SYMBOL_GPL(kvm_write_guest_virt_system);
4012 4012
4013static int vcpu_mmio_gva_to_gpa(struct kvm_vcpu *vcpu, unsigned long gva,
4014 gpa_t *gpa, struct x86_exception *exception,
4015 bool write)
4016{
4017 u32 access = (kvm_x86_ops->get_cpl(vcpu) == 3) ? PFERR_USER_MASK : 0;
4018
4019 if (write)
4020 access |= PFERR_WRITE_MASK;
4021
4022 *gpa = vcpu->arch.walk_mmu->gva_to_gpa(vcpu, gva, access, exception);
4023
4024 if (*gpa == UNMAPPED_GVA)
4025 return -1;
4026
4027 /* For APIC access vmexit */
4028 if ((*gpa & PAGE_MASK) == APIC_DEFAULT_PHYS_BASE)
4029 return 1;
4030
4031 return 0;
4032}
4033
4013static int emulator_read_emulated(struct x86_emulate_ctxt *ctxt, 4034static int emulator_read_emulated(struct x86_emulate_ctxt *ctxt,
4014 unsigned long addr, 4035 unsigned long addr,
4015 void *val, 4036 void *val,
@@ -4017,8 +4038,8 @@ static int emulator_read_emulated(struct x86_emulate_ctxt *ctxt,
4017 struct x86_exception *exception) 4038 struct x86_exception *exception)
4018{ 4039{
4019 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt); 4040 struct kvm_vcpu *vcpu = emul_to_vcpu(ctxt);
4020 gpa_t gpa; 4041 gpa_t gpa;
4021 int handled; 4042 int handled, ret;
4022 4043
4023 if (vcpu->mmio_read_completed) { 4044 if (vcpu->mmio_read_completed) {
4024 memcpy(val, vcpu->mmio_data, bytes); 4045 memcpy(val, vcpu->mmio_data, bytes);
@@ -4028,13 +4049,12 @@ static int emulator_read_emulated(struct x86_emulate_ctxt *ctxt,
4028 return X86EMUL_CONTINUE; 4049 return X86EMUL_CONTINUE;
4029 } 4050 }
4030 4051
4031 gpa = kvm_mmu_gva_to_gpa_read(vcpu, addr, exception); 4052 ret = vcpu_mmio_gva_to_gpa(vcpu, addr, &gpa, exception, false);
4032 4053
4033 if (gpa == UNMAPPED_GVA) 4054 if (ret < 0)
4034 return X86EMUL_PROPAGATE_FAULT; 4055 return X86EMUL_PROPAGATE_FAULT;
4035 4056
4036 /* For APIC access vmexit */ 4057 if (ret)
4037 if ((gpa & PAGE_MASK) == APIC_DEFAULT_PHYS_BASE)
4038 goto mmio; 4058 goto mmio;
4039 4059
4040 if (kvm_read_guest_virt(ctxt, addr, val, bytes, exception) 4060 if (kvm_read_guest_virt(ctxt, addr, val, bytes, exception)
@@ -4085,16 +4105,16 @@ static int emulator_write_emulated_onepage(unsigned long addr,
4085 struct x86_exception *exception, 4105 struct x86_exception *exception,
4086 struct kvm_vcpu *vcpu) 4106 struct kvm_vcpu *vcpu)
4087{ 4107{
4088 gpa_t gpa; 4108 gpa_t gpa;
4089 int handled; 4109 int handled, ret;
4090 4110
4091 gpa = kvm_mmu_gva_to_gpa_write(vcpu, addr, exception); 4111 ret = vcpu_mmio_gva_to_gpa(vcpu, addr, &gpa, exception, true);
4092 4112
4093 if (gpa == UNMAPPED_GVA) 4113 if (ret < 0)
4094 return X86EMUL_PROPAGATE_FAULT; 4114 return X86EMUL_PROPAGATE_FAULT;
4095 4115
4096 /* For APIC access vmexit */ 4116 /* For APIC access vmexit */
4097 if ((gpa & PAGE_MASK) == APIC_DEFAULT_PHYS_BASE) 4117 if (ret)
4098 goto mmio; 4118 goto mmio;
4099 4119
4100 if (emulator_write_phys(vcpu, gpa, val, bytes)) 4120 if (emulator_write_phys(vcpu, gpa, val, bytes))