KVM: Updates
cover KVM: Updates
Various minor fixes to support more guest OSes, fix a bug in exporting MSRs to userspace, and version the API.
Signature · 8 lines
error compiling committee.c: too many arguments to function ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
PATCH 1/5 KVM: Use more traditional error handling in kvm_mmu_init()
drivers/kvm/mmu.c +12 -6
@@ -647,14 +647,20 @@ int kvm_mmu_init(struct kvm_vcpu *vcpu)ASSERT (!VALID_PAGE (vcpu->mmu.root_hpa));ASSERT (list_empty (&vcpu->free_pages)); -if ((r =alloc_mmu_pages (vcpu))) -return r; + r =alloc_mmu_pages (vcpu); +if (r) + goto out; + + r =init_kvm_mmu (vcpu); +if (r) + goto out_free_pages; -if ((r =init_kvm_mmu (vcpu))) { -free_mmu_pages (vcpu); -return r; - }return 0 ; + +out_free_pages: +free_mmu_pages (vcpu); +out: +return r; }void kvm_mmu_destroy (struct kvm_vcpu *vcpu)
PATCH 2/5 KVM: Do not export unsupported msrs to userspace
In reply to Avi KivityFrom: Michael Riepe <[email protected]>
Some msrs, such as MSR_STAR, are not available on all processors. Exporting them causes qemu to try to fetch them, which will fail.
So, check all msrs for validity at module load time.
drivers/kvm/kvm_main.c +24 -3
@@ -1417,6 +1417,9 @@ static int kvm_dev_ioctl_set_sregs(struc/* * List of msr numbers which we expose to userspace through KVM_GET_MSRS * and KVM_SET_MSRS, and KVM_GET_MSR_INDEX_LIST. +* +* This list is modified at module load time to reflect the +* capabilities of the host cpu. */ static u32 msrs_to_save[] = {MSR_IA32_SYSENTER_CS ,MSR_IA32_SYSENTER_ESP ,MSR_IA32_SYSENTER_EIP ,
@@ -1427,6 +1430,22 @@ static u32 msrs_to_save[] = { MSR_IA32_TIME_STAMP_COUNTER, }; +static unsigned num_msrs_to_save =0 ; + +static __init void kvm_init_msr_list (void ) +{ +u32 dummy[2 ]; +unsigned i, j; + +for (i = j =0 ; i <ARRAY_SIZE (msrs_to_save); i++) { +if (rdmsr_safe (msrs_to_save[i], &dummy[0 ], &dummy[1 ]) <0 ) +continue ; +if (j < i) + msrs_to_save[j] = msrs_to_save[i]; + j++; + } + num_msrs_to_save = j; +}/* * Adapt set_msr() to msr_io()'s calling convention
@@ -1735,15 +1754,15 @@ static long kvm_dev_ioctl(struct file *fif (copy_from_user (&msr_list, user_msr_list,sizeof msr_list)) goto out; n = msr_list.nmsrs; - msr_list.nmsrs =ARRAY_SIZE (msrs_to_save); + msr_list.nmsrs = num_msrs_to_save;if (copy_to_user (user_msr_list, &msr_list,sizeof msr_list)) goto out; r = -E2BIG ; -if (n <ARRAY_SIZE (msrs_to_save)) +if (n < num_msrs_to_save) goto out; r = -EFAULT ;if (copy_to_user (user_msr_list->indices, &msrs_to_save, -sizeof msrs_to_save)) + num_msrs_to_save *sizeof (u32))) goto out; r =0 ; }
@@ -1894,6 +1913,8 @@ static __init int kvm_init(void)kvm_init_debug (); +kvm_init_msr_list (); +if ((bad_page =alloc_page (GFP_KERNEL )) ==NULL ) { r = -ENOMEM ; goto out;
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
PATCH 3/5 KVM: Force real-mode cs limit to 64K
In reply to Avi KivityFrom: Michael Riepe <[email protected]>
this allows opensolaris to boot on kvm/intel.
drivers/kvm/vmx.c +1 -0
@@ -726,6 +726,7 @@ static void enter_rmode(struct kvm_vcpuvmcs_write32 (GUEST_SS_AR_BYTES ,0xf3 );vmcs_write32 (GUEST_CS_AR_BYTES ,0xf3 ); +vmcs_write32 (GUEST_CS_LIMIT ,0xffff );vmcs_write16 (GUEST_CS_SELECTOR ,vmcs_readl (GUEST_CS_BASE ) >>4 );fix_rmode_seg (VCPU_SREG_ES , &vcpu->rmode.es);
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
PATCH 4/5 KVM: Handle p5 mce msrs
In reply to Avi KivityFrom: Michael Riepe <[email protected]>
This allows plan9 to get a little further booting.
drivers/kvm/svm.c +2 -0
@@ -1073,6 +1073,8 @@ static int emulate_on_interception(strucstatic int svm_get_msr (struct kvm_vcpu *vcpu,unsigned ecx,u64 *data) {switch (ecx) { +case MSR_IA32_P5_MC_ADDR : +case MSR_IA32_P5_MC_TYPE :case MSR_IA32_MC0_CTL :case MSR_IA32_MCG_STATUS :case MSR_IA32_MCG_CAP :
drivers/kvm/vmx.c +2 -0
@@ -359,6 +359,8 @@ static int vmx_get_msr(struct kvm_vcpu *case MSR_IA32_SYSENTER_ESP : data =vmcs_read32 (GUEST_SYSENTER_ESP );break ; +case MSR_IA32_P5_MC_ADDR : +case MSR_IA32_P5_MC_TYPE :case MSR_IA32_MC0_CTL :case MSR_IA32_MCG_STATUS :case MSR_IA32_MCG_CAP :
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
PATCH 5/5 KVM: API versioning
In reply to Avi KivityAdd compile-time and run-time API versioning.
drivers/kvm/kvm_main.c +3 -0
@@ -1603,6 +1603,9 @@ static long kvm_dev_ioctl(struct file *fint r = -EINVAL ;switch (ioctl) { +case KVM_GET_API_VERSION : + r =KVM_API_VERSION ; +break ;case KVM_CREATE_VCPU : { r =kvm_dev_ioctl_create_vcpu (kvm, arg);if (r)
include/linux/kvm.h +3 -0
@@ -11,6 +11,8 @@#include <asm/types.h> #include <linux/ioctl.h> +#define KVM_API_VERSION 1 +/* * Architectural interrupt line count, and the size of the bitmap needed * to hold them.
@@ -209,6 +211,7 @@ struct kvm_dirty_log {#define KVMIO 0xAE +#define KVM_GET_API_VERSION _IO(KVMIO, 1)#define KVM_RUN _IOWR(KVMIO, 2, struct kvm_run)#define KVM_GET_REGS _IOWR(KVMIO, 3, struct kvm_regs)#define KVM_SET_REGS _IOW(KVMIO, 4, struct kvm_regs)
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
PATCH 1/1 kvm: fix GFP_KERNEL alloc in atomic section bug
In reply to Avi KivitySubject: [patch] kvm: fix GFP_KERNEL alloc in atomic section bug
From: Ingo Molnar <[email protected]>
KVM does kmalloc() in an atomic section while having preemption disabled via vcpu_load(). Fix this by moving the ->*_msr setup from the vcpu_setup method to the vcpu_create method.
(This is also a small speedup for setting up a vcpu, which can in theory be more frequent than the vcpu_create method).
--- drivers/kvm/vmx.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-)
drivers/kvm/vmx.c +21 -11
@@ -1094,14 +1094,6 @@ static int vmx_vcpu_setup(struct kvm_vcprdmsrl (MSR_IA32_SYSENTER_EIP , a);vmcs_writel (HOST_IA32_SYSENTER_EIP , a);/* 22.2.3 */ - ret = -ENOMEM ; - vcpu->guest_msrs =kmalloc (PAGE_SIZE ,GFP_KERNEL ); -if (!vcpu->guest_msrs) - goto out; - vcpu->host_msrs =kmalloc (PAGE_SIZE ,GFP_KERNEL ); -if (!vcpu->host_msrs) - goto out_free_guest_msrs; -for (i =0 ; i <NR_VMX_MSR ; ++i) {u32 index = vmx_msr_index[i];u32 data_low, data_high;
@@ -1155,8 +1147,6 @@ static int vmx_vcpu_setup(struct kvm_vcpreturn 0 ; -out_free_guest_msrs: -kfree (vcpu->guest_msrs); out:return ret; }
@@ -1906,13 +1896,33 @@ static int vmx_create_vcpu(struct kvm_vc {struct vmcs *vmcs; + vcpu->guest_msrs =kmalloc (PAGE_SIZE ,GFP_KERNEL ); +if (!vcpu->guest_msrs) +return -ENOMEM ; + + vcpu->host_msrs =kmalloc (PAGE_SIZE ,GFP_KERNEL ); +if (!vcpu->host_msrs) + goto out_free_guest_msrs; + vmcs =alloc_vmcs ();if (!vmcs) -return -ENOMEM ; + goto out_free_msrs; +vmcs_clear (vmcs); vcpu->vmcs = vmcs; vcpu->launched =0 ; +return 0 ; + +out_free_msrs: +kfree (vcpu->host_msrs); + vcpu->host_msrs =NULL ; + +out_free_guest_msrs: +kfree (vcpu->guest_msrs); + vcpu->guest_msrs =NULL ; + +return -ENOMEM ; }static struct kvm_arch_ops vmx_arch_ops = {
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
Avi Kivity
AppliedRe: [patch] kvm: fix GFP_KERNEL alloc in atomic section bug
Quoted 9 lines · Ingo Molnar
Subject: [patch] kvm: fix
GFP_KERNELalloc in atomic section bug
From: Ingo Molnar <[email protected]>KVM does
kmalloc()in an atomic section while having preemption disabled viavcpu_load(). Fix this by moving the ->*_msr setup from thevcpu_setupmethod to thevcpu_createmethod.(This is also a small speedup for setting up a vcpu, which can in theory be more frequent than the
vcpu_createmethod).Signed-off-by Ingo Molnar <[email protected]>
Applied, thanks.
Signature · 1 line
error compiling committee.c: too many arguments to function