From: Laurent Vivier <Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
To: kvm-devel <kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org>
Subject: [PATCH]Try to make some code simplications allowed by the mutex use
Date: Thu, 30 Aug 2007 14:56:21 +0200 [thread overview]
Message-ID: <46D6BE75.6000605@bull.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 369 bytes --]
Try to make some code simplifications allowed by the use of a mutex instead of a
spinlock. As we can keep the lock longer, we don't have to release it and then
have to check if the environment has not been modified before re-taking it. We
can remove kvm->busy and kvm->memory_config_version.
Signed-off-by: Laurent Vivier <Laurent.Vivier-6ktuUTfB/bM@public.gmane.org>
[-- Attachment #2: mutex-cleanup --]
[-- Type: text/plain, Size: 3463 bytes --]
Index: kvm/drivers/kvm/kvm.h
===================================================================
--- kvm.orig/drivers/kvm/kvm.h 2007-08-30 13:40:10.000000000 +0200
+++ kvm/drivers/kvm/kvm.h 2007-08-30 13:40:13.000000000 +0200
@@ -407,8 +407,6 @@ struct kvm {
int n_free_mmu_pages;
struct hlist_head mmu_page_hash[KVM_NUM_MMU_PAGES];
struct kvm_vcpu *vcpus[KVM_MAX_VCPUS];
- int memory_config_version;
- int busy;
unsigned long rmap_overflow;
struct list_head vm_list;
struct file *filp;
Index: kvm/drivers/kvm/kvm_main.c
===================================================================
--- kvm.orig/drivers/kvm/kvm_main.c 2007-08-30 13:40:10.000000000 +0200
+++ kvm/drivers/kvm/kvm_main.c 2007-08-30 13:40:35.000000000 +0200
@@ -615,7 +615,6 @@ static int kvm_vm_ioctl_set_memory_regio
unsigned long i;
struct kvm_memory_slot *memslot;
struct kvm_memory_slot old, new;
- int memory_config_version;
r = -EINVAL;
/* General sanity checks */
@@ -635,10 +634,8 @@ static int kvm_vm_ioctl_set_memory_regio
if (!npages)
mem->flags &= ~KVM_MEM_LOG_DIRTY_PAGES;
-raced:
mutex_lock(&kvm->lock);
- memory_config_version = kvm->memory_config_version;
new = old = *memslot;
new.base_gfn = base_gfn;
@@ -661,11 +658,6 @@ raced:
(base_gfn >= s->base_gfn + s->npages)))
goto out_unlock;
}
- /*
- * Do memory allocations outside lock. memory_config_version will
- * detect any races.
- */
- mutex_unlock(&kvm->lock);
/* Deallocate if slot is being removed */
if (!npages)
@@ -682,14 +674,14 @@ raced:
new.phys_mem = vmalloc(npages * sizeof(struct page *));
if (!new.phys_mem)
- goto out_free;
+ goto out_unlock;
memset(new.phys_mem, 0, npages * sizeof(struct page *));
for (i = 0; i < npages; ++i) {
new.phys_mem[i] = alloc_page(GFP_HIGHUSER
| __GFP_ZERO);
if (!new.phys_mem[i])
- goto out_free;
+ goto out_unlock;
set_page_private(new.phys_mem[i],0);
}
}
@@ -700,27 +692,14 @@ raced:
new.dirty_bitmap = vmalloc(dirty_bytes);
if (!new.dirty_bitmap)
- goto out_free;
+ goto out_unlock;
memset(new.dirty_bitmap, 0, dirty_bytes);
}
- mutex_lock(&kvm->lock);
-
- if (memory_config_version != kvm->memory_config_version) {
- mutex_unlock(&kvm->lock);
- kvm_free_physmem_slot(&new, &old);
- goto raced;
- }
-
- r = -EAGAIN;
- if (kvm->busy)
- goto out_unlock;
-
if (mem->slot >= kvm->nmemslots)
kvm->nmemslots = mem->slot + 1;
*memslot = new;
- ++kvm->memory_config_version;
kvm_mmu_slot_remove_write_access(kvm, mem->slot);
kvm_flush_remote_tlbs(kvm);
@@ -732,7 +711,6 @@ raced:
out_unlock:
mutex_unlock(&kvm->lock);
-out_free:
kvm_free_physmem_slot(&new, &old);
out:
return r;
@@ -751,12 +729,6 @@ static int kvm_vm_ioctl_get_dirty_log(st
mutex_lock(&kvm->lock);
- /*
- * Prevent changes to guest memory configuration even while the lock
- * is not taken.
- */
- ++kvm->busy;
- mutex_unlock(&kvm->lock);
r = -EINVAL;
if (log->slot >= KVM_MEMORY_SLOTS)
goto out;
@@ -777,18 +749,14 @@ static int kvm_vm_ioctl_get_dirty_log(st
/* If nothing is dirty, don't bother messing with page tables. */
if (any) {
- mutex_lock(&kvm->lock);
kvm_mmu_slot_remove_write_access(kvm, log->slot);
kvm_flush_remote_tlbs(kvm);
memset(memslot->dirty_bitmap, 0, n);
- mutex_unlock(&kvm->lock);
}
r = 0;
out:
- mutex_lock(&kvm->lock);
- --kvm->busy;
mutex_unlock(&kvm->lock);
return r;
}
[-- Attachment #3: Type: text/plain, Size: 315 bytes --]
-------------------------------------------------------------------------
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/
[-- Attachment #4: Type: text/plain, Size: 186 bytes --]
_______________________________________________
kvm-devel mailing list
kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/kvm-devel
next reply other threads:[~2007-08-30 12:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-30 12:56 Laurent Vivier [this message]
[not found] ` <46D6BE75.6000605-6ktuUTfB/bM@public.gmane.org>
2007-09-09 11:36 ` [PATCH]Try to make some code simplications allowed by the mutex use Avi Kivity
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=46D6BE75.6000605@bull.net \
--to=laurent.vivier-6ktuutfb/bm@public.gmane.org \
--cc=kvm-devel-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.