public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/5] KVM: Updates
@ 2006-12-21  9:45 Avi Kivity
  2006-12-21  9:46 ` [PATCH 1/5] KVM: Use more traditional error handling in kvm_mmu_init() Avi Kivity
       [not found] ` <458A57A4.9000807-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
  0 siblings, 2 replies; 8+ messages in thread
From: Avi Kivity @ 2006-12-21  9:45 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f; +Cc: Andrew Morton, linux-kernel

Various minor fixes to support more guest OSes, fix a bug in exporting 
MSRs to userspace, and version the API.

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/5] KVM: Use more traditional error handling in kvm_mmu_init()
  2006-12-21  9:45 [PATCH 0/5] KVM: Updates Avi Kivity
@ 2006-12-21  9:46 ` Avi Kivity
       [not found] ` <458A57A4.9000807-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
  1 sibling, 0 replies; 8+ messages in thread
From: Avi Kivity @ 2006-12-21  9:46 UTC (permalink / raw)
  To: kvm-devel; +Cc: linux-kernel, akpm, mingo

Signed-off-by: Avi Kivity <avi@qumranet.com>

Index: linux-2.6/drivers/kvm/mmu.c
===================================================================
--- linux-2.6.orig/drivers/kvm/mmu.c
+++ linux-2.6/drivers/kvm/mmu.c
@@ -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)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 2/5] KVM: Do not export unsupported msrs to userspace
       [not found] ` <458A57A4.9000807-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
@ 2006-12-21  9:47   ` Avi Kivity
  2006-12-21  9:48   ` [PATCH 3/5] KVM: Force real-mode cs limit to 64K Avi Kivity
                     ` (3 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Avi Kivity @ 2006-12-21  9:47 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: akpm-3NddpPZAyC0, linux-kernel-u79uwXL29TY76Z2rM5mHXA

From: Michael Riepe <michael-0QoEqw4nQxo@public.gmane.org>

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.

Signed-off-by: Michael Riepe <michael-0QoEqw4nQxo@public.gmane.org>
Signed-off-by: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>

Index: linux-2.6/drivers/kvm/kvm_main.c
===================================================================
--- linux-2.6.orig/drivers/kvm/kvm_main.c
+++ linux-2.6/drivers/kvm/kvm_main.c
@@ -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 *f
 		if (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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 3/5] KVM: Force real-mode cs limit to 64K
       [not found] ` <458A57A4.9000807-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
  2006-12-21  9:47   ` [PATCH 2/5] KVM: Do not export unsupported msrs to userspace Avi Kivity
@ 2006-12-21  9:48   ` Avi Kivity
  2006-12-21  9:49   ` [PATCH 4/5] KVM: Handle p5 mce msrs Avi Kivity
                     ` (2 subsequent siblings)
  4 siblings, 0 replies; 8+ messages in thread
From: Avi Kivity @ 2006-12-21  9:48 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: akpm-3NddpPZAyC0, linux-kernel-u79uwXL29TY76Z2rM5mHXA

From: Michael Riepe <michael-0QoEqw4nQxo@public.gmane.org>

this allows opensolaris to boot on kvm/intel.

Signed-off-by: Michael Riepe <michael-0QoEqw4nQxo@public.gmane.org>
Signed-off-by: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>

Index: linux-2.6/drivers/kvm/vmx.c
===================================================================
--- linux-2.6.orig/drivers/kvm/vmx.c
+++ linux-2.6/drivers/kvm/vmx.c
@@ -726,6 +726,7 @@ static void enter_rmode(struct kvm_vcpu 
 	vmcs_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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 4/5] KVM: Handle p5 mce msrs
       [not found] ` <458A57A4.9000807-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
  2006-12-21  9:47   ` [PATCH 2/5] KVM: Do not export unsupported msrs to userspace Avi Kivity
  2006-12-21  9:48   ` [PATCH 3/5] KVM: Force real-mode cs limit to 64K Avi Kivity
@ 2006-12-21  9:49   ` Avi Kivity
  2006-12-21  9:50   ` [PATCH 5/5] KVM: API versioning Avi Kivity
  2006-12-28 12:32   ` [patch] kvm: fix GFP_KERNEL alloc in atomic section bug Ingo Molnar
  4 siblings, 0 replies; 8+ messages in thread
From: Avi Kivity @ 2006-12-21  9:49 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: akpm-3NddpPZAyC0, linux-kernel-u79uwXL29TY76Z2rM5mHXA

From: Michael Riepe <michael-0QoEqw4nQxo@public.gmane.org>

This allows plan9 to get a little further booting.

Signed-off-by: Michael Riepe <michael-0QoEqw4nQxo@public.gmane.org>
Signed-off-by: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>

Index: linux-2.6/drivers/kvm/svm.c
===================================================================
--- linux-2.6.orig/drivers/kvm/svm.c
+++ linux-2.6/drivers/kvm/svm.c
@@ -1073,6 +1073,8 @@ static int emulate_on_interception(struc
 static 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:
Index: linux-2.6/drivers/kvm/vmx.c
===================================================================
--- linux-2.6.orig/drivers/kvm/vmx.c
+++ linux-2.6/drivers/kvm/vmx.c
@@ -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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 5/5] KVM: API versioning
       [not found] ` <458A57A4.9000807-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
                     ` (2 preceding siblings ...)
  2006-12-21  9:49   ` [PATCH 4/5] KVM: Handle p5 mce msrs Avi Kivity
@ 2006-12-21  9:50   ` Avi Kivity
  2006-12-28 12:32   ` [patch] kvm: fix GFP_KERNEL alloc in atomic section bug Ingo Molnar
  4 siblings, 0 replies; 8+ messages in thread
From: Avi Kivity @ 2006-12-21  9:50 UTC (permalink / raw)
  To: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f
  Cc: akpm-3NddpPZAyC0, linux-kernel-u79uwXL29TY76Z2rM5mHXA

Add compile-time and run-time API versioning.

Signed-off-by: Avi Kivity <avi-atKUWr5tajBWk0Htik3J/w@public.gmane.org>

Index: linux-2.6/drivers/kvm/kvm_main.c
===================================================================
--- linux-2.6.orig/drivers/kvm/kvm_main.c
+++ linux-2.6/drivers/kvm/kvm_main.c
@@ -1603,6 +1603,9 @@ static long kvm_dev_ioctl(struct file *f
 	int 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)
Index: linux-2.6/include/linux/kvm.h
===================================================================
--- linux-2.6.orig/include/linux/kvm.h
+++ linux-2.6/include/linux/kvm.h
@@ -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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [patch] kvm: fix GFP_KERNEL alloc in atomic section bug
       [not found] ` <458A57A4.9000807-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
                     ` (3 preceding siblings ...)
  2006-12-21  9:50   ` [PATCH 5/5] KVM: API versioning Avi Kivity
@ 2006-12-28 12:32   ` Ingo Molnar
  2006-12-28 12:44     ` Avi Kivity
  4 siblings, 1 reply; 8+ messages in thread
From: Ingo Molnar @ 2006-12-28 12:32 UTC (permalink / raw)
  To: Avi Kivity
  Cc: kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f, Andrew Morton,
	Linus Torvalds, linux-kernel

Subject: [patch] kvm: fix GFP_KERNEL alloc in atomic section bug
From: Ingo Molnar <mingo-X9Un+BFzKDI@public.gmane.org>

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).

Signed-off-by: Ingo Molnar <mingo-X9Un+BFzKDI@public.gmane.org>
---
 drivers/kvm/vmx.c |   32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)

Index: linux/drivers/kvm/vmx.c
===================================================================
--- linux.orig/drivers/kvm/vmx.c
+++ linux/drivers/kvm/vmx.c
@@ -1094,14 +1094,6 @@ static int vmx_vcpu_setup(struct kvm_vcp
 	rdmsrl(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_vcp
 
 	return 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [patch] kvm: fix GFP_KERNEL alloc in atomic section bug
  2006-12-28 12:32   ` [patch] kvm: fix GFP_KERNEL alloc in atomic section bug Ingo Molnar
@ 2006-12-28 12:44     ` Avi Kivity
  0 siblings, 0 replies; 8+ messages in thread
From: Avi Kivity @ 2006-12-28 12:44 UTC (permalink / raw)
  To: Ingo Molnar; +Cc: kvm-devel, linux-kernel, Andrew Morton, Linus Torvalds

Ingo Molnar wrote:
> Subject: [patch] kvm: fix GFP_KERNEL alloc in atomic section bug
> From: Ingo Molnar <mingo@elte.hu>
>
> 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).
>
> Signed-off-by: Ingo Molnar <mingo@elte.hu>
>   

Applied, thanks.


-- 
error compiling committee.c: too many arguments to function

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2006-12-28 12:44 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-21  9:45 [PATCH 0/5] KVM: Updates Avi Kivity
2006-12-21  9:46 ` [PATCH 1/5] KVM: Use more traditional error handling in kvm_mmu_init() Avi Kivity
     [not found] ` <458A57A4.9000807-atKUWr5tajBWk0Htik3J/w@public.gmane.org>
2006-12-21  9:47   ` [PATCH 2/5] KVM: Do not export unsupported msrs to userspace Avi Kivity
2006-12-21  9:48   ` [PATCH 3/5] KVM: Force real-mode cs limit to 64K Avi Kivity
2006-12-21  9:49   ` [PATCH 4/5] KVM: Handle p5 mce msrs Avi Kivity
2006-12-21  9:50   ` [PATCH 5/5] KVM: API versioning Avi Kivity
2006-12-28 12:32   ` [patch] kvm: fix GFP_KERNEL alloc in atomic section bug Ingo Molnar
2006-12-28 12:44     ` Avi Kivity

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox