* [PATCH 1/3] KVM - Add missing kvm_run initializations
@ 2007-07-16 19:24 Jeff Dike
2007-07-17 8:12 ` Avi Kivity
0 siblings, 1 reply; 4+ messages in thread
From: Jeff Dike @ 2007-07-16 19:24 UTC (permalink / raw)
To: Avi Kivity; +Cc: LKML, KVM devel
There are a bunch of missing initializations of run->exit_reason and
associated data.
kvm_hypercall wasn't setting exit_reason at all.
When exit_reason is KVM_EXIT_MMIO, the mmio data isn't initialized. I
don't know what it should be, so I just stuck a FIXME in there.
There were some missing initializations of hardware_exit_reason with
KVM_EXIT_UNKNOWN, so I added those. One case had exit_reason = 0,
which I changed to KVM_EXIT_UNKNOWN.
I did a pass over all of the return 0 paths in the exit handler
callbacks, so this should cover everything.
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
--
drivers/kvm/kvm_main.c | 3 +++
drivers/kvm/svm.c | 3 +++
drivers/kvm/vmx.c | 4 +++-
3 files changed, 9 insertions(+), 1 deletion(-)
Index: kvm/drivers/kvm/kvm_main.c
===================================================================
--- kvm.orig/drivers/kvm/kvm_main.c
+++ kvm/drivers/kvm/kvm_main.c
@@ -1370,6 +1370,7 @@ int kvm_hypercall(struct kvm_vcpu *vcpu,
run->hypercall.ret = ret;
run->hypercall.longmode = is_long_mode(vcpu);
kvm_arch_ops->decache_regs(vcpu);
+ run->exit_reason = KVM_EXIT_HYPERCALL;
return 0;
}
vcpu->regs[VCPU_REGS_RAX] = ret;
@@ -1928,6 +1929,8 @@ static int kvm_vcpu_ioctl_run(struct kvm
if (r == EMULATE_DO_MMIO) {
/*
* Read-modify-write. Back to userspace.
+ *
+ * FIXME - kvm_run->mmio not initialized
*/
kvm_run->exit_reason = KVM_EXIT_MMIO;
r = 0;
Index: kvm/drivers/kvm/svm.c
===================================================================
--- kvm.orig/drivers/kvm/svm.c
+++ kvm/drivers/kvm/svm.c
@@ -929,6 +929,7 @@ static int pf_interception(struct kvm_vc
return 1;
case EMULATE_DO_MMIO:
++vcpu->stat.mmio_exits;
+ /* FIXME - kvm_run->mmio not initialized */
kvm_run->exit_reason = KVM_EXIT_MMIO;
return 0;
case EMULATE_FAIL:
@@ -938,6 +939,7 @@ static int pf_interception(struct kvm_vc
BUG();
}
+ kvm_run->hw.hardware_exit_reason = vcpu->svm->vmcb->control.exit_code;
kvm_run->exit_reason = KVM_EXIT_UNKNOWN;
return 0;
}
@@ -1135,6 +1137,7 @@ static int invalid_op_interception(struc
static int task_switch_interception(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
{
printk(KERN_DEBUG "%s: task swiche is unsupported\n", __FUNCTION__);
+ kvm_run->hw.hardware_exit_reason = vcpu->svm->vmcb->control.exit_code;
kvm_run->exit_reason = KVM_EXIT_UNKNOWN;
return 0;
}
Index: kvm/drivers/kvm/vmx.c
===================================================================
--- kvm.orig/drivers/kvm/vmx.c
+++ kvm/drivers/kvm/vmx.c
@@ -1610,6 +1610,7 @@ static int handle_exception(struct kvm_v
return 1;
case EMULATE_DO_MMIO:
++vcpu->stat.mmio_exits;
+ /* FIXME - kvm_run->mmio not initialized */
kvm_run->exit_reason = KVM_EXIT_MMIO;
return 0;
case EMULATE_FAIL:
@@ -1807,7 +1808,8 @@ static int handle_cr(struct kvm_vcpu *vc
default:
break;
}
- kvm_run->exit_reason = 0;
+ kvm_run->exit_reason = KVM_EXIT_UNKNOWN;
+ kvm_run->hw.hardware_exit_reason = vmcs_read32(VM_EXIT_REASON);
printk(KERN_ERR "kvm: unhandled control register: op %d cr %d\n",
(int)(exit_qualification >> 4) & 3, cr);
return 0;
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH 1/3] KVM - Add missing kvm_run initializations
2007-07-16 19:24 [PATCH 1/3] KVM - Add missing kvm_run initializations Jeff Dike
@ 2007-07-17 8:12 ` Avi Kivity
2007-07-17 16:26 ` Jeff Dike
0 siblings, 1 reply; 4+ messages in thread
From: Avi Kivity @ 2007-07-17 8:12 UTC (permalink / raw)
To: Jeff Dike; +Cc: LKML, KVM devel
Jeff Dike wrote:
> There are a bunch of missing initializations of run->exit_reason and
> associated data.
>
> kvm_hypercall wasn't setting exit_reason at all.
>
> When exit_reason is KVM_EXIT_MMIO, the mmio data isn't initialized. I
> don't know what it should be, so I just stuck a FIXME in there.
>
> There were some missing initializations of hardware_exit_reason with
> KVM_EXIT_UNKNOWN, so I added those. One case had exit_reason = 0,
> which I changed to KVM_EXIT_UNKNOWN.
>
> I did a pass over all of the return 0 paths in the exit handler
> callbacks, so this should cover everything.
>
> Signed-off-by: Jeff Dike <jdike@linux.intel.com>
> --
> drivers/kvm/kvm_main.c | 3 +++
> drivers/kvm/svm.c | 3 +++
> drivers/kvm/vmx.c | 4 +++-
> 3 files changed, 9 insertions(+), 1 deletion(-)
>
> Index: kvm/drivers/kvm/kvm_main.c
> ===================================================================
> --- kvm.orig/drivers/kvm/kvm_main.c
> +++ kvm/drivers/kvm/kvm_main.c
> @@ -1370,6 +1370,7 @@ int kvm_hypercall(struct kvm_vcpu *vcpu,
> run->hypercall.ret = ret;
> run->hypercall.longmode = is_long_mode(vcpu);
> kvm_arch_ops->decache_regs(vcpu);
> + run->exit_reason = KVM_EXIT_HYPERCALL;
> return 0;
> }
>
Aye. (And: aiiieee)
> vcpu->regs[VCPU_REGS_RAX] = ret;
> @@ -1928,6 +1929,8 @@ static int kvm_vcpu_ioctl_run(struct kvm
> if (r == EMULATE_DO_MMIO) {
> /*
> * Read-modify-write. Back to userspace.
> + *
> + * FIXME - kvm_run->mmio not initialized
> */
> kvm_run->exit_reason = KVM_EXIT_MMIO;
> r = 0;
>
I believe that emulate_instruction will set run->mmio if it returns
EMULATE_DO_MMIO.
> Index: kvm/drivers/kvm/svm.c
> ===================================================================
> --- kvm.orig/drivers/kvm/svm.c
> +++ kvm/drivers/kvm/svm.c
> @@ -929,6 +929,7 @@ static int pf_interception(struct kvm_vc
> return 1;
> case EMULATE_DO_MMIO:
> ++vcpu->stat.mmio_exits;
> + /* FIXME - kvm_run->mmio not initialized */
> kvm_run->exit_reason = KVM_EXIT_MMIO;
>
Ditto.
The rest are all good.
--
error compiling committee.c: too many arguments to function
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH 1/3] KVM - Add missing kvm_run initializations
2007-07-17 8:12 ` Avi Kivity
@ 2007-07-17 16:26 ` Jeff Dike
2007-07-18 10:39 ` Avi Kivity
0 siblings, 1 reply; 4+ messages in thread
From: Jeff Dike @ 2007-07-17 16:26 UTC (permalink / raw)
To: Avi Kivity; +Cc: LKML, KVM devel
On Tue, Jul 17, 2007 at 11:12:53AM +0300, Avi Kivity wrote:
> I believe that emulate_instruction will set run->mmio if it returns
> EMULATE_DO_MMIO.
Righto, forgot to check that. How about this patch instead?
Set exit_reason to KVM_EXIT_MMIO where run->mmio is initialized.
Signed-off-by: Jeff Dike <jdike@linux.intel.com>
--
drivers/kvm/kvm_main.c | 2 +-
drivers/kvm/svm.c | 1 -
drivers/kvm/vmx.c | 1 -
3 files changed, 1 insertion(+), 3 deletions(-)
Index: kvm/drivers/kvm/kvm_main.c
===================================================================
--- kvm.orig/drivers/kvm/kvm_main.c
+++ kvm/drivers/kvm/kvm_main.c
@@ -1294,6 +1294,7 @@ int emulate_instruction(struct kvm_vcpu
r = x86_emulate_memop(&emulate_ctxt, &emulate_ops);
if ((r || vcpu->mmio_is_write) && run) {
+ run->exit_reason = KVM_EXIT_MMIO;
run->mmio.phys_addr = vcpu->mmio_phys_addr;
memcpy(run->mmio.data, vcpu->mmio_data, 8);
run->mmio.len = vcpu->mmio_size;
@@ -1929,7 +1930,6 @@ static int kvm_vcpu_ioctl_run(struct kvm
/*
* Read-modify-write. Back to userspace.
*/
- kvm_run->exit_reason = KVM_EXIT_MMIO;
r = 0;
goto out;
}
Index: kvm/drivers/kvm/svm.c
===================================================================
--- kvm.orig/drivers/kvm/svm.c
+++ kvm/drivers/kvm/svm.c
@@ -929,7 +929,6 @@ static int pf_interception(struct kvm_vc
return 1;
case EMULATE_DO_MMIO:
++vcpu->stat.mmio_exits;
- kvm_run->exit_reason = KVM_EXIT_MMIO;
return 0;
case EMULATE_FAIL:
vcpu_printf(vcpu, "%s: emulate fail\n", __FUNCTION__);
Index: kvm/drivers/kvm/vmx.c
===================================================================
--- kvm.orig/drivers/kvm/vmx.c
+++ kvm/drivers/kvm/vmx.c
@@ -1610,7 +1610,6 @@ static int handle_exception(struct kvm_v
return 1;
case EMULATE_DO_MMIO:
++vcpu->stat.mmio_exits;
- kvm_run->exit_reason = KVM_EXIT_MMIO;
return 0;
case EMULATE_FAIL:
vcpu_printf(vcpu, "%s: emulate fail\n", __FUNCTION__);
--
Work email - jdike at linux dot intel dot com
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH 1/3] KVM - Add missing kvm_run initializations
2007-07-17 16:26 ` Jeff Dike
@ 2007-07-18 10:39 ` Avi Kivity
0 siblings, 0 replies; 4+ messages in thread
From: Avi Kivity @ 2007-07-18 10:39 UTC (permalink / raw)
To: Jeff Dike; +Cc: LKML, KVM devel
Jeff Dike wrote:
> On Tue, Jul 17, 2007 at 11:12:53AM +0300, Avi Kivity wrote:
>
>> I believe that emulate_instruction will set run->mmio if it returns
>> EMULATE_DO_MMIO.
>>
>
> Righto, forgot to check that. How about this patch instead?
>
> Set exit_reason to KVM_EXIT_MMIO where run->mmio is initialized.
>
>
Applied, thanks.
--
Do not meddle in the internals of kernels, for they are subtle and quick to panic.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-07-18 10:40 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-07-16 19:24 [PATCH 1/3] KVM - Add missing kvm_run initializations Jeff Dike
2007-07-17 8:12 ` Avi Kivity
2007-07-17 16:26 ` Jeff Dike
2007-07-18 10:39 ` Avi Kivity
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox