Skip to contentSkip to conversation

KVM: VMX: Fix repeatly allocate of apic access page

PATCH In review Sheng Yang 2 participants 2 messages Nov 6, 2007 1 message not in the archive KVM

lore
Share & tools
lore

Sheng Yang

author
#0 lore raw

PATCH 1/1 KVM: VMX: Fix repeatly allocate of apic access page

From 05164d73994a88ae130a086b592cd127c15a617f Mon Sep 17 00:00:00 2001
From: Sheng Yang <[email protected]>
Date: Tue, 6 Nov 2007 11:37:44 +0800
Subject: [PATCH] KVM: VMX: Fix repeatly allocate of apic access page

For SMP guest, alloc_apic_access_page() would be called more than once. So only the last one works, causing SMP guest can't benifit from FlexPriority.

This patch fixed this issue.

---
 drivers/kvm/vmx.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)
drivers/kvm/vmx.c +10 -4
index 42e7fad..6670e2b 100644
@@ -1463,18 +1463,24 @@ static void seg_setup(int seg)
 static int alloc_apic_access_page(struct kvm *kvm)
 {
 	struct kvm_userspace_memory_region kvm_userspace_mem;
-	int r;
+	int r = 0;
 
-	r = -EFAULT;
+	mutex_lock(&kvm->lock);
+	if (kvm->apic_access_page)
+		goto out;
+	mutex_unlock(&kvm->lock);
 	kvm_userspace_mem.slot = APIC_ACCESS_PAGE_PRIVATE_MEMSLOT;
 	kvm_userspace_mem.flags = 0;
 	kvm_userspace_mem.guest_phys_addr = 0xfee00000ULL;
 	kvm_userspace_mem.memory_size = PAGE_SIZE;
 	r = kvm_set_memory_region(kvm, &kvm_userspace_mem, 0);
 	if (r)
-		return r;
+		goto out;
+	mutex_lock(&kvm->lock);
 	kvm->apic_access_page = gfn_to_page(kvm, 0xfee00);
-	return 0;
+out:
+	mutex_unlock(&kvm->lock);
+	return r;
 }
 
 /*
Signature · 1 line
1.5.2

From 05164d73994a88ae130a086b592cd127c15a617f Mon Sep 17 00:00:00 2001
From: Sheng Yang <[email protected]>
Date: Tue, 6 Nov 2007 11:37:44 +0800
Subject: [PATCH] KVM: VMX: Fix repeatly allocate of apic access page

For SMP guest, alloc_apic_access_page() would be called more than once. So only the last one works, causing SMP guest can't benifit from FlexPriority.

This patch fixed this issue.

---
 drivers/kvm/vmx.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)
drivers/kvm/vmx.c +10 -4
index 42e7fad..6670e2b 100644
@@ -1463,18 +1463,24 @@ static void seg_setup(int seg)
 static int alloc_apic_access_page(struct kvm *kvm)
 {
 	struct kvm_userspace_memory_region kvm_userspace_mem;
-	int r;
+	int r = 0;
 
-	r = -EFAULT;
+	mutex_lock(&kvm->lock);
+	if (kvm->apic_access_page)
+		goto out;
+	mutex_unlock(&kvm->lock);
 	kvm_userspace_mem.slot = APIC_ACCESS_PAGE_PRIVATE_MEMSLOT;
 	kvm_userspace_mem.flags = 0;
 	kvm_userspace_mem.guest_phys_addr = 0xfee00000ULL;
 	kvm_userspace_mem.memory_size = PAGE_SIZE;
 	r = kvm_set_memory_region(kvm, &kvm_userspace_mem, 0);
 	if (r)
-		return r;
+		goto out;
+	mutex_lock(&kvm->lock);
 	kvm->apic_access_page = gfn_to_page(kvm, 0xfee00);
-	return 0;
+out:
+	mutex_unlock(&kvm->lock);
+	return r;
 }
 
 /*
Signature · 1 line
1.5.2

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/

_______________________________________________
kvm-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel

A message that is not in the archive (sent off-list or not yet received): 200711061100.35700.sheng.yang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org

#2 lore raw
Quoted 22 lines · Sheng Yang

From 05164d73994a88ae130a086b592cd127c15a617f Mon Sep 17 00:00:00 2001
From: Sheng Yang <[email protected]>
Date: Tue, 6 Nov 2007 11:37:44 +0800
Subject: [PATCH] KVM: VMX: Fix repeatly allocate of apic access page

For SMP guest, alloc_apic_access_page() would be called more than once. So only the last one works, causing SMP guest can't benifit from FlexPriority.

This patch fixed this issue.

---
 drivers/kvm/vmx.c |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)
drivers/kvm/vmx.c +0 -0
index 42e7fad..6670e2b 100644
@@ -1463,18 +1463,24 @@ static void seg_setup(int seg)
 static int alloc_apic_access_page(struct kvm *kvm)
 {

drivers/kvm/vmx.c static void seg_setup(int seg) · line 1472

Quoted 10 lines
drivers/kvm/vmx.c +5 -2
 	struct kvm_userspace_memory_region kvm_userspace_mem;
-	int r;
+	int r = 0;
 
-	r = -EFAULT;
+	mutex_lock(&kvm->lock);
+	if (kvm->apic_access_page)
+		goto out;
+	mutex_unlock(&kvm->lock);
 

Still racy. I two threads create a vcpu at the same time, they can both reach this point simultaneously.

I suggest having a __kvm_set_memory_region() that does not take kvm->lock, and call that instead, so the whole thing can be done within a single lock.

Quoted 17 lines
drivers/kvm/vmx.c +5 -2
 	kvm_userspace_mem.slot = APIC_ACCESS_PAGE_PRIVATE_MEMSLOT;
 	kvm_userspace_mem.flags = 0;
 	kvm_userspace_mem.guest_phys_addr = 0xfee00000ULL;
 	kvm_userspace_mem.memory_size = PAGE_SIZE;
 	r = kvm_set_memory_region(kvm, &kvm_userspace_mem, 0);
 	if (r)
-		return r;
+		goto out;
+	mutex_lock(&kvm->lock);
 	kvm->apic_access_page = gfn_to_page(kvm, 0xfee00);
-	return 0;
+out:
+	mutex_unlock(&kvm->lock);
+	return r;
 }
 
Signature · 8 lines
error compiling committee.c: too many arguments to function


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/