From 0ee8dcb87e403397e575674d0e79272b06dea12e Mon Sep 17 00:00:00 2001 From: Xiao Guangrong Date: Wed, 9 Mar 2011 15:41:59 +0800 Subject: KVM: cleanup memslot_id function We can get memslot id from memslot->id directly Signed-off-by: Xiao Guangrong Signed-off-by: Avi Kivity --- virt/kvm/kvm_main.c | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'virt/kvm') diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 6330653480e..58146457bf9 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -996,23 +996,6 @@ out: return size; } -int memslot_id(struct kvm *kvm, gfn_t gfn) -{ - int i; - struct kvm_memslots *slots = kvm_memslots(kvm); - struct kvm_memory_slot *memslot = NULL; - - for (i = 0; i < slots->nmemslots; ++i) { - memslot = &slots->memslots[i]; - - if (gfn >= memslot->base_gfn - && gfn < memslot->base_gfn + memslot->npages) - break; - } - - return memslot - slots->memslots; -} - static unsigned long gfn_to_hva_many(struct kvm_memory_slot *slot, gfn_t gfn, gfn_t *nr_pages) { -- cgit v1.2.3-18-g5258 From a38f84ca8c6991925cb8bb6371ade8df9d3cc1e6 Mon Sep 17 00:00:00 2001 From: Liu Yuan Date: Thu, 21 Apr 2011 14:53:57 +0800 Subject: KVM: ioapic: Fix an error field reference Function ioapic_debug() in the ioapic_deliver() misnames one filed by reference. This patch correct it. Signed-off-by: Liu Yuan Signed-off-by: Avi Kivity --- virt/kvm/ioapic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'virt/kvm') diff --git a/virt/kvm/ioapic.c b/virt/kvm/ioapic.c index 0b9df8303dc..8df1ca104a7 100644 --- a/virt/kvm/ioapic.c +++ b/virt/kvm/ioapic.c @@ -167,7 +167,7 @@ static int ioapic_deliver(struct kvm_ioapic *ioapic, int irq) ioapic_debug("dest=%x dest_mode=%x delivery_mode=%x " "vector=%x trig_mode=%x\n", - entry->fields.dest, entry->fields.dest_mode, + entry->fields.dest_id, entry->fields.dest_mode, entry->fields.delivery_mode, entry->fields.vector, entry->fields.trig_mode); -- cgit v1.2.3-18-g5258 From fa3d315a4ce2c0891cdde262562e710d95fba19e Mon Sep 17 00:00:00 2001 From: Takuya Yoshikawa Date: Sat, 7 May 2011 16:35:38 +0900 Subject: KVM: Validate userspace_addr of memslot when registered This way, we can avoid checking the user space address many times when we read the guest memory. Although we can do the same for write if we check which slots are writable, we do not care write now: reading the guest memory happens more often than writing. [avi: change VERIFY_READ to VERIFY_WRITE] Signed-off-by: Takuya Yoshikawa Signed-off-by: Avi Kivity --- virt/kvm/kvm_main.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'virt/kvm') diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 58146457bf9..ed3c4e7c100 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -648,7 +648,10 @@ int __kvm_set_memory_region(struct kvm *kvm, goto out; if (mem->guest_phys_addr & (PAGE_SIZE - 1)) goto out; - if (user_alloc && (mem->userspace_addr & (PAGE_SIZE - 1))) + /* We can read the guest memory with __xxx_user() later on. */ + if (user_alloc && + ((mem->userspace_addr & (PAGE_SIZE - 1)) || + !access_ok(VERIFY_WRITE, mem->userspace_addr, mem->memory_size))) goto out; if (mem->slot >= KVM_MEMORY_SLOTS + KVM_PRIVATE_MEM_SLOTS) goto out; @@ -1283,7 +1286,7 @@ int kvm_read_guest_page(struct kvm *kvm, gfn_t gfn, void *data, int offset, addr = gfn_to_hva(kvm, gfn); if (kvm_is_error_hva(addr)) return -EFAULT; - r = copy_from_user(data, (void __user *)addr + offset, len); + r = __copy_from_user(data, (void __user *)addr + offset, len); if (r) return -EFAULT; return 0; -- cgit v1.2.3-18-g5258 From 85722cda308c0ad7390dc910139b2ce58c11b9c4 Mon Sep 17 00:00:00 2001 From: OGAWA Hirofumi Date: Wed, 11 May 2011 09:28:28 +0900 Subject: KVM: Fix kvm mmu_notifier initialization order Like the following, mmu_notifier can be called after registering immediately. So, kvm have to initialize kvm->mmu_lock before it. BUG: spinlock bad magic on CPU#0, kswapd0/342 lock: ffff8800af8c4000, .magic: 00000000, .owner: /-1, .owner_cpu: 0 Pid: 342, comm: kswapd0 Not tainted 2.6.39-rc5+ #1 Call Trace: [] spin_bug+0x9c/0xa3 [] do_raw_spin_lock+0x29/0x13c [] ? flush_tlb_others_ipi+0xaf/0xfd [] _raw_spin_lock+0x9/0xb [] kvm_mmu_notifier_clear_flush_young+0x2c/0x66 [kvm] [] __mmu_notifier_clear_flush_young+0x2b/0x57 [] page_referenced_one+0x88/0xea [] page_referenced+0x1fc/0x256 [] shrink_page_list+0x187/0x53a [] shrink_inactive_list+0x1e0/0x33d [] ? determine_dirtyable_memory+0x15/0x27 [] ? call_function_single_interrupt+0xe/0x20 [] shrink_zone+0x322/0x3de [] ? zone_watermark_ok_safe+0xe2/0xf1 [] kswapd+0x516/0x818 [] ? shrink_zone+0x3de/0x3de [] kthread+0x7d/0x85 [] kernel_thread_helper+0x4/0x10 [] ? __init_kthread_worker+0x37/0x37 [] ? gs_change+0xb/0xb Signed-off-by: OGAWA Hirofumi Signed-off-by: Avi Kivity --- virt/kvm/kvm_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'virt/kvm') diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index ed3c4e7c100..22cdb960660 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -467,6 +467,7 @@ static struct kvm *kvm_create_vm(void) if (!kvm->buses[i]) goto out_err; } + spin_lock_init(&kvm->mmu_lock); r = kvm_init_mmu_notifier(kvm); if (r) @@ -474,7 +475,6 @@ static struct kvm *kvm_create_vm(void) kvm->mm = current->mm; atomic_inc(&kvm->mm->mm_count); - spin_lock_init(&kvm->mmu_lock); kvm_eventfd_init(kvm); mutex_init(&kvm->lock); mutex_init(&kvm->irq_lock); -- cgit v1.2.3-18-g5258