KVM: s390: fix cmma migration for multiple memory slots

When multiple memory slots are present the cmma migration code
does not allocate enough memory for the bitmap. The memory slots
are sorted in reverse order, so we must use gfn and size of
slot[0] instead of the last one.

Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.vnet.ibm.com>
Cc: stable@vger.kernel.org # 4.13+
Fixes: 190df4a212a7 (KVM: s390: CMMA tracking, ESSA emulation, migration mode)
Reviewed-by: Cornelia Huck <cohuck@redhat.com>

+5 -4
+5 -4
arch/s390/kvm/kvm-s390.c
··· 792 793 if (kvm->arch.use_cmma) { 794 /* 795 - * Get the last slot. They should be sorted by base_gfn, so the 796 - * last slot is also the one at the end of the address space. 797 - * We have verified above that at least one slot is present. 798 */ 799 - ms = slots->memslots + slots->used_slots - 1; 800 /* round up so we only use full longs */ 801 ram_pages = roundup(ms->base_gfn + ms->npages, BITS_PER_LONG); 802 /* allocate enough bytes to store all the bits */
··· 792 793 if (kvm->arch.use_cmma) { 794 /* 795 + * Get the first slot. They are reverse sorted by base_gfn, so 796 + * the first slot is also the one at the end of the address 797 + * space. We have verified above that at least one slot is 798 + * present. 799 */ 800 + ms = slots->memslots; 801 /* round up so we only use full longs */ 802 ram_pages = roundup(ms->base_gfn + ms->npages, BITS_PER_LONG); 803 /* allocate enough bytes to store all the bits */