Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8eb7d334 authored by Avi Kivity's avatar Avi Kivity
Browse files

KVM: Fold kvm_run::exit_type into kvm_run::exit_reason



Currently, userspace is told about the nature of the last exit from the
guest using two fields, exit_type and exit_reason, where exit_type has
just two enumerations (and no need for more).  So fold exit_type into
exit_reason, reducing the complexity of determining what really happened.

Signed-off-by: default avatarAvi Kivity <avi@qumranet.com>
parent b4e63f56
Loading
Loading
Loading
Loading
+1 −2
Original line number Original line Diff line number Diff line
@@ -1608,8 +1608,7 @@ static int kvm_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)


	vcpu->mmio_needed = 0;
	vcpu->mmio_needed = 0;


	if (kvm_run->exit_type == KVM_EXIT_TYPE_VM_EXIT
	if (kvm_run->exit_reason == KVM_EXIT_HYPERCALL) {
	    && kvm_run->exit_reason == KVM_EXIT_HYPERCALL) {
		kvm_arch_ops->cache_regs(vcpu);
		kvm_arch_ops->cache_regs(vcpu);
		vcpu->regs[VCPU_REGS_RAX] = kvm_run->hypercall.ret;
		vcpu->regs[VCPU_REGS_RAX] = kvm_run->hypercall.ret;
		kvm_arch_ops->decache_regs(vcpu);
		kvm_arch_ops->decache_regs(vcpu);
+3 −4
Original line number Original line Diff line number Diff line
@@ -1298,8 +1298,6 @@ static int handle_exit(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
{
{
	u32 exit_code = vcpu->svm->vmcb->control.exit_code;
	u32 exit_code = vcpu->svm->vmcb->control.exit_code;


	kvm_run->exit_type = KVM_EXIT_TYPE_VM_EXIT;

	if (is_external_interrupt(vcpu->svm->vmcb->control.exit_int_info) &&
	if (is_external_interrupt(vcpu->svm->vmcb->control.exit_int_info) &&
	    exit_code != SVM_EXIT_EXCP_BASE + PF_VECTOR)
	    exit_code != SVM_EXIT_EXCP_BASE + PF_VECTOR)
		printk(KERN_ERR "%s: unexpected exit_ini_info 0x%x "
		printk(KERN_ERR "%s: unexpected exit_ini_info 0x%x "
@@ -1609,8 +1607,9 @@ static int svm_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
	vcpu->svm->next_rip = 0;
	vcpu->svm->next_rip = 0;


	if (vcpu->svm->vmcb->control.exit_code == SVM_EXIT_ERR) {
	if (vcpu->svm->vmcb->control.exit_code == SVM_EXIT_ERR) {
		kvm_run->exit_type = KVM_EXIT_TYPE_FAIL_ENTRY;
		kvm_run->exit_reason = KVM_EXIT_FAIL_ENTRY;
		kvm_run->exit_reason = vcpu->svm->vmcb->control.exit_code;
		kvm_run->fail_entry.hardware_entry_failure_reason
			= vcpu->svm->vmcb->control.exit_code;
		post_kvm_run_save(vcpu, kvm_run);
		post_kvm_run_save(vcpu, kvm_run);
		return 0;
		return 0;
	}
	}
+3 −4
Original line number Original line Diff line number Diff line
@@ -1922,10 +1922,10 @@ static int vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)


	asm ("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));
	asm ("mov %0, %%ds; mov %0, %%es" : : "r"(__USER_DS));


	kvm_run->exit_type = 0;
	if (fail) {
	if (fail) {
		kvm_run->exit_type = KVM_EXIT_TYPE_FAIL_ENTRY;
		kvm_run->exit_reason = KVM_EXIT_FAIL_ENTRY;
		kvm_run->exit_reason = vmcs_read32(VM_INSTRUCTION_ERROR);
		kvm_run->fail_entry.hardware_entry_failure_reason
			= vmcs_read32(VM_INSTRUCTION_ERROR);
		r = 0;
		r = 0;
	} else {
	} else {
		/*
		/*
@@ -1935,7 +1935,6 @@ static int vmx_vcpu_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run)
			profile_hit(KVM_PROFILING, (void *)vmcs_readl(GUEST_RIP));
			profile_hit(KVM_PROFILING, (void *)vmcs_readl(GUEST_RIP));


		vcpu->launched = 1;
		vcpu->launched = 1;
		kvm_run->exit_type = KVM_EXIT_TYPE_VM_EXIT;
		r = kvm_handle_exit(kvm_run, vcpu);
		r = kvm_handle_exit(kvm_run, vcpu);
		if (r > 0) {
		if (r > 0) {
			/* Give scheduler a change to reschedule. */
			/* Give scheduler a change to reschedule. */
+8 −7
Original line number Original line Diff line number Diff line
@@ -11,7 +11,7 @@
#include <asm/types.h>
#include <asm/types.h>
#include <linux/ioctl.h>
#include <linux/ioctl.h>


#define KVM_API_VERSION 7
#define KVM_API_VERSION 8


/*
/*
 * Architectural interrupt line count, and the size of the bitmap needed
 * Architectural interrupt line count, and the size of the bitmap needed
@@ -34,9 +34,6 @@ struct kvm_memory_region {
#define KVM_MEM_LOG_DIRTY_PAGES  1UL
#define KVM_MEM_LOG_DIRTY_PAGES  1UL




#define KVM_EXIT_TYPE_FAIL_ENTRY 1
#define KVM_EXIT_TYPE_VM_EXIT    2

enum kvm_exit_reason {
enum kvm_exit_reason {
	KVM_EXIT_UNKNOWN          = 0,
	KVM_EXIT_UNKNOWN          = 0,
	KVM_EXIT_EXCEPTION        = 1,
	KVM_EXIT_EXCEPTION        = 1,
@@ -47,6 +44,7 @@ enum kvm_exit_reason {
	KVM_EXIT_MMIO             = 6,
	KVM_EXIT_MMIO             = 6,
	KVM_EXIT_IRQ_WINDOW_OPEN  = 7,
	KVM_EXIT_IRQ_WINDOW_OPEN  = 7,
	KVM_EXIT_SHUTDOWN         = 8,
	KVM_EXIT_SHUTDOWN         = 8,
	KVM_EXIT_FAIL_ENTRY       = 9,
};
};


/* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */
/* for KVM_RUN, returned by mmap(vcpu_fd, offset=0) */
@@ -57,12 +55,11 @@ struct kvm_run {
	__u8 padding1[3];
	__u8 padding1[3];


	/* out */
	/* out */
	__u32 exit_type;
	__u32 exit_reason;
	__u32 exit_reason;
	__u32 instruction_length;
	__u32 instruction_length;
	__u8 ready_for_interrupt_injection;
	__u8 ready_for_interrupt_injection;
	__u8 if_flag;
	__u8 if_flag;
	__u16 padding2;
	__u8 padding2[6];


	/* in (pre_kvm_run), out (post_kvm_run) */
	/* in (pre_kvm_run), out (post_kvm_run) */
	__u64 cr8;
	__u64 cr8;
@@ -71,8 +68,12 @@ struct kvm_run {
	union {
	union {
		/* KVM_EXIT_UNKNOWN */
		/* KVM_EXIT_UNKNOWN */
		struct {
		struct {
			__u32 hardware_exit_reason;
			__u64 hardware_exit_reason;
		} hw;
		} hw;
		/* KVM_EXIT_FAIL_ENTRY */
		struct {
			__u64 hardware_entry_failure_reason;
		} fail_entry;
		/* KVM_EXIT_EXCEPTION */
		/* KVM_EXIT_EXCEPTION */
		struct {
		struct {
			__u32 exception;
			__u32 exception;