diff options
author | Xiao Guangrong <xiaoguangrong.eric@gmail.com> | 2011-11-24 06:04:35 -0500 |
---|---|---|
committer | Avi Kivity <avi@redhat.com> | 2011-12-27 04:17:39 -0500 |
commit | 28a37544fb0223eb9805d2567b88f7360edec52a (patch) | |
tree | 83afb64f8448303f9486eb6c87980695611275ab /arch/x86/kvm | |
parent | be6ba0f0962a39091c52eb9167ddea201fe80716 (diff) |
KVM: introduce id_to_memslot function
Introduce id_to_memslot to get memslot by slot id
Signed-off-by: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/x86/kvm')
-rw-r--r-- | arch/x86/kvm/vmx.c | 6 | ||||
-rw-r--r-- | arch/x86/kvm/x86.c | 18 |
2 files changed, 13 insertions, 11 deletions
diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index ba24022f4575..8f19d91ec3e7 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c | |||
@@ -2711,11 +2711,13 @@ static gva_t rmode_tss_base(struct kvm *kvm) | |||
2711 | { | 2711 | { |
2712 | if (!kvm->arch.tss_addr) { | 2712 | if (!kvm->arch.tss_addr) { |
2713 | struct kvm_memslots *slots; | 2713 | struct kvm_memslots *slots; |
2714 | struct kvm_memory_slot *slot; | ||
2714 | gfn_t base_gfn; | 2715 | gfn_t base_gfn; |
2715 | 2716 | ||
2716 | slots = kvm_memslots(kvm); | 2717 | slots = kvm_memslots(kvm); |
2717 | base_gfn = slots->memslots[0].base_gfn + | 2718 | slot = id_to_memslot(slots, 0); |
2718 | kvm->memslots->memslots[0].npages - 3; | 2719 | base_gfn = slot->base_gfn + slot->npages - 3; |
2720 | |||
2719 | return base_gfn << PAGE_SHIFT; | 2721 | return base_gfn << PAGE_SHIFT; |
2720 | } | 2722 | } |
2721 | return kvm->arch.tss_addr; | 2723 | return kvm->arch.tss_addr; |
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 917a287d21c8..b6776c613e6d 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c | |||
@@ -3520,7 +3520,7 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, | |||
3520 | if (log->slot >= KVM_MEMORY_SLOTS) | 3520 | if (log->slot >= KVM_MEMORY_SLOTS) |
3521 | goto out; | 3521 | goto out; |
3522 | 3522 | ||
3523 | memslot = &kvm->memslots->memslots[log->slot]; | 3523 | memslot = id_to_memslot(kvm->memslots, log->slot); |
3524 | r = -ENOENT; | 3524 | r = -ENOENT; |
3525 | if (!memslot->dirty_bitmap) | 3525 | if (!memslot->dirty_bitmap) |
3526 | goto out; | 3526 | goto out; |
@@ -3531,27 +3531,27 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, | |||
3531 | /* If nothing is dirty, don't bother messing with page tables. */ | 3531 | /* If nothing is dirty, don't bother messing with page tables. */ |
3532 | if (nr_dirty_pages) { | 3532 | if (nr_dirty_pages) { |
3533 | struct kvm_memslots *slots, *old_slots; | 3533 | struct kvm_memslots *slots, *old_slots; |
3534 | unsigned long *dirty_bitmap; | 3534 | unsigned long *dirty_bitmap, *dirty_bitmap_head; |
3535 | 3535 | ||
3536 | dirty_bitmap = memslot->dirty_bitmap_head; | 3536 | dirty_bitmap = memslot->dirty_bitmap; |
3537 | if (memslot->dirty_bitmap == dirty_bitmap) | 3537 | dirty_bitmap_head = memslot->dirty_bitmap_head; |
3538 | dirty_bitmap += n / sizeof(long); | 3538 | if (dirty_bitmap == dirty_bitmap_head) |
3539 | memset(dirty_bitmap, 0, n); | 3539 | dirty_bitmap_head += n / sizeof(long); |
3540 | memset(dirty_bitmap_head, 0, n); | ||
3540 | 3541 | ||
3541 | r = -ENOMEM; | 3542 | r = -ENOMEM; |
3542 | slots = kzalloc(sizeof(struct kvm_memslots), GFP_KERNEL); | 3543 | slots = kzalloc(sizeof(struct kvm_memslots), GFP_KERNEL); |
3543 | if (!slots) | 3544 | if (!slots) |
3544 | goto out; | 3545 | goto out; |
3545 | memcpy(slots, kvm->memslots, sizeof(struct kvm_memslots)); | 3546 | memcpy(slots, kvm->memslots, sizeof(struct kvm_memslots)); |
3546 | memslot = &slots->memslots[log->slot]; | 3547 | memslot = id_to_memslot(slots, log->slot); |
3547 | memslot->dirty_bitmap = dirty_bitmap; | ||
3548 | memslot->nr_dirty_pages = 0; | 3548 | memslot->nr_dirty_pages = 0; |
3549 | memslot->dirty_bitmap = dirty_bitmap_head; | ||
3549 | update_memslots(slots, NULL); | 3550 | update_memslots(slots, NULL); |
3550 | 3551 | ||
3551 | old_slots = kvm->memslots; | 3552 | old_slots = kvm->memslots; |
3552 | rcu_assign_pointer(kvm->memslots, slots); | 3553 | rcu_assign_pointer(kvm->memslots, slots); |
3553 | synchronize_srcu_expedited(&kvm->srcu); | 3554 | synchronize_srcu_expedited(&kvm->srcu); |
3554 | dirty_bitmap = old_slots->memslots[log->slot].dirty_bitmap; | ||
3555 | kfree(old_slots); | 3555 | kfree(old_slots); |
3556 | 3556 | ||
3557 | write_protect_slot(kvm, memslot, dirty_bitmap, nr_dirty_pages); | 3557 | write_protect_slot(kvm, memslot, dirty_bitmap, nr_dirty_pages); |