aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAvi Kivity <avi@qumranet.com>2007-02-19 07:37:47 -0500
committerAvi Kivity <avi@qumranet.com>2007-03-04 04:12:41 -0500
commit270fd9b96f5fcb7df15d3ca6166545d4aa0f3ee9 (patch)
tree06dcbab8d87b120ddf80ed4e184743fe542b4da8
parent02e235bc8eebf8a6fef10d46479b3c18f3e9c4f2 (diff)
KVM: Wire up hypercall handlers to a central arch-independent location
Signed-off-by: Avi Kivity <avi@qumranet.com>
-rw-r--r--drivers/kvm/kvm.h2
-rw-r--r--drivers/kvm/kvm_main.c36
-rw-r--r--drivers/kvm/svm.c10
-rw-r--r--drivers/kvm/vmx.c10
4 files changed, 40 insertions, 18 deletions
diff --git a/drivers/kvm/kvm.h b/drivers/kvm/kvm.h
index fd7746a2bc3e..41cc27de4d66 100644
--- a/drivers/kvm/kvm.h
+++ b/drivers/kvm/kvm.h
@@ -482,6 +482,8 @@ void kvm_mmu_post_write(struct kvm_vcpu *vcpu, gpa_t gpa, int bytes);
482int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva); 482int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva);
483void kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu); 483void kvm_mmu_free_some_pages(struct kvm_vcpu *vcpu);
484 484
485int kvm_hypercall(struct kvm_vcpu *vcpu, struct kvm_run *run);
486
485static inline int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t gva, 487static inline int kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gva_t gva,
486 u32 error_code) 488 u32 error_code)
487{ 489{
diff --git a/drivers/kvm/kvm_main.c b/drivers/kvm/kvm_main.c
index 757a41f1db84..2be9738dfd78 100644
--- a/drivers/kvm/kvm_main.c
+++ b/drivers/kvm/kvm_main.c
@@ -1138,6 +1138,42 @@ int emulate_instruction(struct kvm_vcpu *vcpu,
1138} 1138}
1139EXPORT_SYMBOL_GPL(emulate_instruction); 1139EXPORT_SYMBOL_GPL(emulate_instruction);
1140 1140
1141int kvm_hypercall(struct kvm_vcpu *vcpu, struct kvm_run *run)
1142{
1143 unsigned long nr, a0, a1, a2, a3, a4, a5, ret;
1144
1145 kvm_arch_ops->decache_regs(vcpu);
1146 ret = -KVM_EINVAL;
1147#ifdef CONFIG_X86_64
1148 if (is_long_mode(vcpu)) {
1149 nr = vcpu->regs[VCPU_REGS_RAX];
1150 a0 = vcpu->regs[VCPU_REGS_RDI];
1151 a1 = vcpu->regs[VCPU_REGS_RSI];
1152 a2 = vcpu->regs[VCPU_REGS_RDX];
1153 a3 = vcpu->regs[VCPU_REGS_RCX];
1154 a4 = vcpu->regs[VCPU_REGS_R8];
1155 a5 = vcpu->regs[VCPU_REGS_R9];
1156 } else
1157#endif
1158 {
1159 nr = vcpu->regs[VCPU_REGS_RBX] & -1u;
1160 a0 = vcpu->regs[VCPU_REGS_RAX] & -1u;
1161 a1 = vcpu->regs[VCPU_REGS_RCX] & -1u;
1162 a2 = vcpu->regs[VCPU_REGS_RDX] & -1u;
1163 a3 = vcpu->regs[VCPU_REGS_RSI] & -1u;
1164 a4 = vcpu->regs[VCPU_REGS_RDI] & -1u;
1165 a5 = vcpu->regs[VCPU_REGS_RBP] & -1u;
1166 }
1167 switch (nr) {
1168 default:
1169 ;
1170 }
1171 vcpu->regs[VCPU_REGS_RAX] = ret;
1172 kvm_arch_ops->cache_regs(vcpu);
1173 return 1;
1174}
1175EXPORT_SYMBOL_GPL(kvm_hypercall);
1176
1141static u64 mk_cr_64(u64 curr_cr, u32 new_val) 1177static u64 mk_cr_64(u64 curr_cr, u32 new_val)
1142{ 1178{
1143 return (curr_cr & ~((1ULL << 32) - 1)) | new_val; 1179 return (curr_cr & ~((1ULL << 32) - 1)) | new_val;
diff --git a/drivers/kvm/svm.c b/drivers/kvm/svm.c
index aaa6742089e5..711ea42370a8 100644
--- a/drivers/kvm/svm.c
+++ b/drivers/kvm/svm.c
@@ -1078,16 +1078,8 @@ static int halt_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1078 1078
1079static int vmmcall_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) 1079static int vmmcall_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1080{ 1080{
1081 printk(KERN_DEBUG "got vmmcall at RIP %08llx\n",
1082 vcpu->svm->vmcb->save.rip);
1083 printk(KERN_DEBUG "vmmcall params: %08llx, %08lx, %08lx, %08lx\n",
1084 vcpu->svm->vmcb->save.rax,
1085 vcpu->regs[VCPU_REGS_RCX],
1086 vcpu->regs[VCPU_REGS_RDX],
1087 vcpu->regs[VCPU_REGS_RBP]);
1088 vcpu->svm->vmcb->save.rax = 0;
1089 vcpu->svm->vmcb->save.rip += 3; 1081 vcpu->svm->vmcb->save.rip += 3;
1090 return 1; 1082 return kvm_hypercall(vcpu, kvm_run);
1091} 1083}
1092 1084
1093static int invalid_op_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) 1085static int invalid_op_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
diff --git a/drivers/kvm/vmx.c b/drivers/kvm/vmx.c
index ca79e594ea6e..ff956a6302ec 100644
--- a/drivers/kvm/vmx.c
+++ b/drivers/kvm/vmx.c
@@ -1659,16 +1659,8 @@ static int handle_halt(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1659 1659
1660static int handle_vmcall(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run) 1660static int handle_vmcall(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
1661{ 1661{
1662 kvm_run->exit_reason = KVM_EXIT_DEBUG;
1663 printk(KERN_DEBUG "got vmcall at RIP %08lx\n", vmcs_readl(GUEST_RIP));
1664 printk(KERN_DEBUG "vmcall params: %08lx, %08lx, %08lx, %08lx\n",
1665 vcpu->regs[VCPU_REGS_RAX],
1666 vcpu->regs[VCPU_REGS_RCX],
1667 vcpu->regs[VCPU_REGS_RDX],
1668 vcpu->regs[VCPU_REGS_RBP]);
1669 vcpu->regs[VCPU_REGS_RAX] = 0;
1670 vmcs_writel(GUEST_RIP, vmcs_readl(GUEST_RIP)+3); 1662 vmcs_writel(GUEST_RIP, vmcs_readl(GUEST_RIP)+3);
1671 return 1; 1663 return kvm_hypercall(vcpu, kvm_run);
1672} 1664}
1673 1665
1674/* 1666/*