diff options
author | Avi Kivity <avi@qumranet.com> | 2007-04-22 08:28:19 -0400 |
---|---|---|
committer | Avi Kivity <avi@qumranet.com> | 2007-05-03 03:52:31 -0400 |
commit | 4c690a1e8667a84b61a6114a4ad293681f32cb11 (patch) | |
tree | ed5ffaedc83068a7cf791530a2f54483107f3d21 /drivers/kvm/kvm_main.c | |
parent | 1165f5fec18c077bdba88e7125fd41f8e3617cb4 (diff) |
KVM: Allow passing 64-bit values to the emulated read/write API
This simplifies the API somewhat (by eliminating the special-case
cmpxchg8b on i386).
Signed-off-by: Avi Kivity <avi@qumranet.com>
Diffstat (limited to 'drivers/kvm/kvm_main.c')
-rw-r--r-- | drivers/kvm/kvm_main.c | 45 |
1 files changed, 9 insertions, 36 deletions
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c index 911c8175cc08..67554034d001 100644 --- a/drivers/kvm/kvm_main.c +++ b/drivers/kvm/kvm_main.c | |||
@@ -970,7 +970,7 @@ void mark_page_dirty(struct kvm *kvm, gfn_t gfn) | |||
970 | } | 970 | } |
971 | 971 | ||
972 | static int emulator_read_std(unsigned long addr, | 972 | static int emulator_read_std(unsigned long addr, |
973 | unsigned long *val, | 973 | void *val, |
974 | unsigned int bytes, | 974 | unsigned int bytes, |
975 | struct x86_emulate_ctxt *ctxt) | 975 | struct x86_emulate_ctxt *ctxt) |
976 | { | 976 | { |
@@ -1006,7 +1006,7 @@ static int emulator_read_std(unsigned long addr, | |||
1006 | } | 1006 | } |
1007 | 1007 | ||
1008 | static int emulator_write_std(unsigned long addr, | 1008 | static int emulator_write_std(unsigned long addr, |
1009 | unsigned long val, | 1009 | const void *val, |
1010 | unsigned int bytes, | 1010 | unsigned int bytes, |
1011 | struct x86_emulate_ctxt *ctxt) | 1011 | struct x86_emulate_ctxt *ctxt) |
1012 | { | 1012 | { |
@@ -1016,7 +1016,7 @@ static int emulator_write_std(unsigned long addr, | |||
1016 | } | 1016 | } |
1017 | 1017 | ||
1018 | static int emulator_read_emulated(unsigned long addr, | 1018 | static int emulator_read_emulated(unsigned long addr, |
1019 | unsigned long *val, | 1019 | void *val, |
1020 | unsigned int bytes, | 1020 | unsigned int bytes, |
1021 | struct x86_emulate_ctxt *ctxt) | 1021 | struct x86_emulate_ctxt *ctxt) |
1022 | { | 1022 | { |
@@ -1044,7 +1044,7 @@ static int emulator_read_emulated(unsigned long addr, | |||
1044 | } | 1044 | } |
1045 | 1045 | ||
1046 | static int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa, | 1046 | static int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa, |
1047 | unsigned long val, int bytes) | 1047 | const void *val, int bytes) |
1048 | { | 1048 | { |
1049 | struct page *page; | 1049 | struct page *page; |
1050 | void *virt; | 1050 | void *virt; |
@@ -1057,14 +1057,14 @@ static int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa, | |||
1057 | kvm_mmu_pre_write(vcpu, gpa, bytes); | 1057 | kvm_mmu_pre_write(vcpu, gpa, bytes); |
1058 | mark_page_dirty(vcpu->kvm, gpa >> PAGE_SHIFT); | 1058 | mark_page_dirty(vcpu->kvm, gpa >> PAGE_SHIFT); |
1059 | virt = kmap_atomic(page, KM_USER0); | 1059 | virt = kmap_atomic(page, KM_USER0); |
1060 | memcpy(virt + offset_in_page(gpa), &val, bytes); | 1060 | memcpy(virt + offset_in_page(gpa), val, bytes); |
1061 | kunmap_atomic(virt, KM_USER0); | 1061 | kunmap_atomic(virt, KM_USER0); |
1062 | kvm_mmu_post_write(vcpu, gpa, bytes); | 1062 | kvm_mmu_post_write(vcpu, gpa, bytes); |
1063 | return 1; | 1063 | return 1; |
1064 | } | 1064 | } |
1065 | 1065 | ||
1066 | static int emulator_write_emulated(unsigned long addr, | 1066 | static int emulator_write_emulated(unsigned long addr, |
1067 | unsigned long val, | 1067 | const void *val, |
1068 | unsigned int bytes, | 1068 | unsigned int bytes, |
1069 | struct x86_emulate_ctxt *ctxt) | 1069 | struct x86_emulate_ctxt *ctxt) |
1070 | { | 1070 | { |
@@ -1083,14 +1083,14 @@ static int emulator_write_emulated(unsigned long addr, | |||
1083 | vcpu->mmio_phys_addr = gpa; | 1083 | vcpu->mmio_phys_addr = gpa; |
1084 | vcpu->mmio_size = bytes; | 1084 | vcpu->mmio_size = bytes; |
1085 | vcpu->mmio_is_write = 1; | 1085 | vcpu->mmio_is_write = 1; |
1086 | memcpy(vcpu->mmio_data, &val, bytes); | 1086 | memcpy(vcpu->mmio_data, val, bytes); |
1087 | 1087 | ||
1088 | return X86EMUL_CONTINUE; | 1088 | return X86EMUL_CONTINUE; |
1089 | } | 1089 | } |
1090 | 1090 | ||
1091 | static int emulator_cmpxchg_emulated(unsigned long addr, | 1091 | static int emulator_cmpxchg_emulated(unsigned long addr, |
1092 | unsigned long old, | 1092 | const void *old, |
1093 | unsigned long new, | 1093 | const void *new, |
1094 | unsigned int bytes, | 1094 | unsigned int bytes, |
1095 | struct x86_emulate_ctxt *ctxt) | 1095 | struct x86_emulate_ctxt *ctxt) |
1096 | { | 1096 | { |
@@ -1103,30 +1103,6 @@ static int emulator_cmpxchg_emulated(unsigned long addr, | |||
1103 | return emulator_write_emulated(addr, new, bytes, ctxt); | 1103 | return emulator_write_emulated(addr, new, bytes, ctxt); |
1104 | } | 1104 | } |
1105 | 1105 | ||
1106 | #ifdef CONFIG_X86_32 | ||
1107 | |||
1108 | static int emulator_cmpxchg8b_emulated(unsigned long addr, | ||
1109 | unsigned long old_lo, | ||
1110 | unsigned long old_hi, | ||
1111 | unsigned long new_lo, | ||
1112 | unsigned long new_hi, | ||
1113 | struct x86_emulate_ctxt *ctxt) | ||
1114 | { | ||
1115 | static int reported; | ||
1116 | int r; | ||
1117 | |||
1118 | if (!reported) { | ||
1119 | reported = 1; | ||
1120 | printk(KERN_WARNING "kvm: emulating exchange8b as write\n"); | ||
1121 | } | ||
1122 | r = emulator_write_emulated(addr, new_lo, 4, ctxt); | ||
1123 | if (r != X86EMUL_CONTINUE) | ||
1124 | return r; | ||
1125 | return emulator_write_emulated(addr+4, new_hi, 4, ctxt); | ||
1126 | } | ||
1127 | |||
1128 | #endif | ||
1129 | |||
1130 | static unsigned long get_segment_base(struct kvm_vcpu *vcpu, int seg) | 1106 | static unsigned long get_segment_base(struct kvm_vcpu *vcpu, int seg) |
1131 | { | 1107 | { |
1132 | return kvm_arch_ops->get_segment_base(vcpu, seg); | 1108 | return kvm_arch_ops->get_segment_base(vcpu, seg); |
@@ -1201,9 +1177,6 @@ struct x86_emulate_ops emulate_ops = { | |||
1201 | .read_emulated = emulator_read_emulated, | 1177 | .read_emulated = emulator_read_emulated, |
1202 | .write_emulated = emulator_write_emulated, | 1178 | .write_emulated = emulator_write_emulated, |
1203 | .cmpxchg_emulated = emulator_cmpxchg_emulated, | 1179 | .cmpxchg_emulated = emulator_cmpxchg_emulated, |
1204 | #ifdef CONFIG_X86_32 | ||
1205 | .cmpxchg8b_emulated = emulator_cmpxchg8b_emulated, | ||
1206 | #endif | ||
1207 | }; | 1180 | }; |
1208 | 1181 | ||
1209 | int emulate_instruction(struct kvm_vcpu *vcpu, | 1182 | int emulate_instruction(struct kvm_vcpu *vcpu, |