KVM: use __vcalloc for very large allocations
commit 37b2a6510a48ca361ced679f92682b7b7d7d0330 upstream. Allocations whose size is related to the memslot size can be arbitrarily large. Do not use kvzalloc/kvcalloc, as those are limited to "not crazy" sizes that fit in 32 bits. Cc: stable@vger.kernel.org Fixes: 7661809d493b ("mm: don't allow oversized kvmalloc() calls") Reviewed-by: David Hildenbrand <david@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Alexander Ofitserov <oficerovas@altlinux.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
b1eb196cae
commit
e4cf6b17e6
4 changed files with 6 additions and 6 deletions
|
@ -250,7 +250,7 @@ int kvmppc_uvmem_slot_init(struct kvm *kvm, const struct kvm_memory_slot *slot)
|
|||
p = kzalloc(sizeof(*p), GFP_KERNEL);
|
||||
if (!p)
|
||||
return -ENOMEM;
|
||||
p->pfns = vzalloc(array_size(slot->npages, sizeof(*p->pfns)));
|
||||
p->pfns = vcalloc(slot->npages, sizeof(*p->pfns));
|
||||
if (!p->pfns) {
|
||||
kfree(p);
|
||||
return -ENOMEM;
|
||||
|
|
|
@ -35,7 +35,7 @@ int kvm_page_track_create_memslot(struct kvm_memory_slot *slot,
|
|||
|
||||
for (i = 0; i < KVM_PAGE_TRACK_MAX; i++) {
|
||||
slot->arch.gfn_track[i] =
|
||||
kvcalloc(npages, sizeof(*slot->arch.gfn_track[i]),
|
||||
__vcalloc(npages, sizeof(*slot->arch.gfn_track[i]),
|
||||
GFP_KERNEL_ACCOUNT);
|
||||
if (!slot->arch.gfn_track[i])
|
||||
goto track_free;
|
||||
|
|
|
@ -10826,14 +10826,14 @@ static int kvm_alloc_memslot_metadata(struct kvm_memory_slot *slot,
|
|||
slot->base_gfn, level) + 1;
|
||||
|
||||
slot->arch.rmap[i] =
|
||||
kvcalloc(lpages, sizeof(*slot->arch.rmap[i]),
|
||||
__vcalloc(lpages, sizeof(*slot->arch.rmap[i]),
|
||||
GFP_KERNEL_ACCOUNT);
|
||||
if (!slot->arch.rmap[i])
|
||||
goto out_free;
|
||||
if (i == 0)
|
||||
continue;
|
||||
|
||||
linfo = kvcalloc(lpages, sizeof(*linfo), GFP_KERNEL_ACCOUNT);
|
||||
linfo = __vcalloc(lpages, sizeof(*linfo), GFP_KERNEL_ACCOUNT);
|
||||
if (!linfo)
|
||||
goto out_free;
|
||||
|
||||
|
|
|
@ -1008,9 +1008,9 @@ static int kvm_vm_release(struct inode *inode, struct file *filp)
|
|||
*/
|
||||
static int kvm_alloc_dirty_bitmap(struct kvm_memory_slot *memslot)
|
||||
{
|
||||
unsigned long dirty_bytes = 2 * kvm_dirty_bitmap_bytes(memslot);
|
||||
unsigned long dirty_bytes = kvm_dirty_bitmap_bytes(memslot);
|
||||
|
||||
memslot->dirty_bitmap = kvzalloc(dirty_bytes, GFP_KERNEL_ACCOUNT);
|
||||
memslot->dirty_bitmap = __vcalloc(2, dirty_bytes, GFP_KERNEL_ACCOUNT);
|
||||
if (!memslot->dirty_bitmap)
|
||||
return -ENOMEM;
|
||||
|
||||
|
|
Loading…
Reference in a new issue