diff options
| -rw-r--r-- | virt/kvm/kvm_main.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index f5283438ee05..050974c051b5 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c | |||
| @@ -687,11 +687,23 @@ static void update_memslots(struct kvm_memslots *slots, | |||
| 687 | slots->id_to_index[mslots[i].id] = i; | 687 | slots->id_to_index[mslots[i].id] = i; |
| 688 | i++; | 688 | i++; |
| 689 | } | 689 | } |
| 690 | while (i > 0 && | 690 | |
| 691 | new->base_gfn > mslots[i - 1].base_gfn) { | 691 | /* |
| 692 | mslots[i] = mslots[i - 1]; | 692 | * The ">=" is needed when creating a slot with base_gfn == 0, |
| 693 | slots->id_to_index[mslots[i].id] = i; | 693 | * so that it moves before all those with base_gfn == npages == 0. |
| 694 | i--; | 694 | * |
| 695 | * On the other hand, if new->npages is zero, the above loop has | ||
| 696 | * already left i pointing to the beginning of the empty part of | ||
| 697 | * mslots, and the ">=" would move the hole backwards in this | ||
| 698 | * case---which is wrong. So skip the loop when deleting a slot. | ||
| 699 | */ | ||
| 700 | if (new->npages) { | ||
| 701 | while (i > 0 && | ||
| 702 | new->base_gfn >= mslots[i - 1].base_gfn) { | ||
| 703 | mslots[i] = mslots[i - 1]; | ||
| 704 | slots->id_to_index[mslots[i].id] = i; | ||
| 705 | i--; | ||
| 706 | } | ||
| 695 | } | 707 | } |
| 696 | 708 | ||
| 697 | mslots[i] = *new; | 709 | mslots[i] = *new; |
