Skip to contentSkip to conversation

KVM - Add missing kvm_run initializations

PATCH Applied Jeff Dike 2 participants 4 messages Jul 16, 2007 – Jul 18, 2007 KVM

lore
Share & tools
lore

Jeff Dike

author
#0 lore raw

PATCH 1/3 KVM - Add missing kvm_run initializations

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.

--

 drivers/kvm/kvm_main.c |    3 +++
 drivers/kvm/svm.c      |    3 +++
 drivers/kvm/vmx.c      |    4 +++-
 3 files changed, 9 insertions(+), 1 deletion(-)
drivers/kvm/kvm_main.c +3 -0
Index: 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;
drivers/kvm/svm.c +3 -0
Index: 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;
 }
drivers/kvm/vmx.c +3 -1
Index: 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;

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

#1 lore raw
Quoted 27 lines · Jeff Dike

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.

--

 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
===================================================================

drivers/kvm/kvm_main.c int kvm_hypercall(struct kvm_vcpu *vcpu, · line 1376

Quoted 7 lines
drivers/kvm/kvm_main.c +1 -0
@@ -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)

drivers/kvm/kvm_main.c static int kvm_vcpu_ioctl_run(struct kvm · line 1936

Quoted 11 lines
drivers/kvm/kvm_main.c +2 -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;

I believe that emulate_instruction will set run->mmio if it returns EMULATE_DO_MMIO.

drivers/kvm/svm.c static int pf_interception(struct kvm_vc · line 934

Quoted 11 lines

Index: kvm/drivers/kvm/svm.c
===================================================================

drivers/kvm/svm.c +1 -0
@@ -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.

Signature · 8 lines
error compiling committee.c: too many arguments to function


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
author
#2 lore raw
Quoted 2 lines · Avi Kivity

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.

--

 drivers/kvm/kvm_main.c |    2 +-
 drivers/kvm/svm.c      |    1 -
 drivers/kvm/vmx.c      |    1 -
 3 files changed, 1 insertion(+), 3 deletions(-)
drivers/kvm/kvm_main.c +1 -1
Index: 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;
 		}
drivers/kvm/svm.c +0 -1
Index: 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__);
drivers/kvm/vmx.c +0 -1
Index: 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__);
Signature · 1 line
Work email - jdike at linux dot intel dot com
Applied
#3 lore raw
Quoted 11 lines · Jeff Dike
Quoted 3 lines · Avi Kivity

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.

Signature · 8 lines
Do not meddle in the internals of kernels, for they are subtle and quick to panic.


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/