Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 68424
b: refs/heads/master
c: 0d8d2bd
h: refs/heads/master
v: v3
  • Loading branch information
Laurent Vivier authored and Avi Kivity committed Oct 13, 2007
1 parent ce0e965 commit c6f196e
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 38 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 1747fb71fd7c9389696e91f354d2f841b5c85790
refs/heads/master: 0d8d2bd4f20c8a2a254b4fe3bc114f12214a6d73
2 changes: 0 additions & 2 deletions trunk/drivers/kvm/kvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,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;
Expand Down
38 changes: 3 additions & 35 deletions trunk/drivers/kvm/kvm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,6 @@ static int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,
unsigned long i;
struct kvm_memory_slot *memslot;
struct kvm_memory_slot old, new;
int memory_config_version;

r = -EINVAL;
/* General sanity checks */
Expand All @@ -699,10 +698,8 @@ static int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,
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;
Expand All @@ -725,11 +722,6 @@ static int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,
(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)
Expand All @@ -746,14 +738,14 @@ static int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,
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);
}
}
Expand All @@ -764,27 +756,14 @@ static int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,

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);
Expand All @@ -796,7 +775,6 @@ static int kvm_vm_ioctl_set_memory_region(struct kvm *kvm,

out_unlock:
mutex_unlock(&kvm->lock);
out_free:
kvm_free_physmem_slot(&new, &old);
out:
return r;
Expand All @@ -815,12 +793,6 @@ static int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,

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;
Expand All @@ -841,18 +813,14 @@ static int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,

/* 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;
}
Expand Down

0 comments on commit c6f196e

Please sign in to comment.