mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Igor Mammedov <imammedo@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: himbeere@meine-oma.de, mimi.vx@gmail.com, bsd@makefile.in,
	mtosatti@redhat.com, kvm@vger.kernel.org,
	Paolo Bonzini <pbonzini@redhat.com>
Subject: Re: [PATCH v2] kvm: avoid page allocation failure in kvm_set_memory_region()
Date: Tue, 31 Mar 2015 11:24:31 +0200	[thread overview]
Message-ID: <20150331112432.3250707c@igors-macbook-pro.local> (raw)
In-Reply-To: <1426854097-22210-1-git-send-email-imammedo@redhat.com>

On Fri, 20 Mar 2015 12:21:37 +0000
Igor Mammedov <imammedo@redhat.com> wrote:

> KVM guest can fail to startup with following trace on host:
> 
> qemu-system-x86: page allocation failure: order:4, mode:0x40d0
> Call Trace:
>   dump_stack+0x47/0x67
>   warn_alloc_failed+0xee/0x150
>   __alloc_pages_direct_compact+0x14a/0x150
>   __alloc_pages_nodemask+0x776/0xb80
>   alloc_kmem_pages+0x3a/0x110
>   kmalloc_order+0x13/0x50
>   kmemdup+0x1b/0x40
>   __kvm_set_memory_region+0x24a/0x9f0 [kvm]
>   kvm_set_ioapic+0x130/0x130 [kvm]
>   kvm_set_memory_region+0x21/0x40 [kvm]
>   kvm_vm_ioctl+0x43f/0x750 [kvm]
> 
> Failure happens when attempting to allocate pages for
> 'struct kvm_memslots', however it doesn't have to be
> present in physically contiguous (kmalloc-ed) address
> space, change allocation to kvm_kvzalloc() so that
> it will be vmalloc-ed when its size is more then a page.
> 
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
ping


> ---
> v2:
>  - alloc initial memslots with vmalloc
>  - use kvfree in every place where memslots are freed
> 
> TODO:
>  - work on follow up patches to allocate space for
>    actual amount of memory_slots instead of possible maximum.
> ---
>  virt/kvm/kvm_main.c | 14 +++++++-------
>  1 file changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index a2214d9..cc6a25d 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -471,7 +471,7 @@ static struct kvm *kvm_create_vm(unsigned long
> type) BUILD_BUG_ON(KVM_MEM_SLOTS_NUM > SHRT_MAX);
>  
>  	r = -ENOMEM;
> -	kvm->memslots = kzalloc(sizeof(struct kvm_memslots),
> GFP_KERNEL);
> +	kvm->memslots = kvm_kvzalloc(sizeof(struct kvm_memslots));
>  	if (!kvm->memslots)
>  		goto out_err_no_srcu;
>  
> @@ -522,7 +522,7 @@ out_err_no_srcu:
>  out_err_no_disable:
>  	for (i = 0; i < KVM_NR_BUSES; i++)
>  		kfree(kvm->buses[i]);
> -	kfree(kvm->memslots);
> +	kvfree(kvm->memslots);
>  	kvm_arch_free_vm(kvm);
>  	return ERR_PTR(r);
>  }
> @@ -578,7 +578,7 @@ static void kvm_free_physmem(struct kvm *kvm)
>  	kvm_for_each_memslot(memslot, slots)
>  		kvm_free_physmem_slot(kvm, memslot, NULL);
>  
> -	kfree(kvm->memslots);
> +	kvfree(kvm->memslots);
>  }
>  
>  static void kvm_destroy_devices(struct kvm *kvm)
> @@ -871,10 +871,10 @@ int __kvm_set_memory_region(struct kvm *kvm,
>  			goto out_free;
>  	}
>  
> -	slots = kmemdup(kvm->memslots, sizeof(struct kvm_memslots),
> -			GFP_KERNEL);
> +	slots = kvm_kvzalloc(sizeof(struct kvm_memslots));
>  	if (!slots)
>  		goto out_free;
> +	memcpy(slots, kvm->memslots, sizeof(struct kvm_memslots));
>  
>  	if ((change == KVM_MR_DELETE) || (change == KVM_MR_MOVE)) {
>  		slot = id_to_memslot(slots, mem->slot);
> @@ -917,7 +917,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
>  	kvm_arch_commit_memory_region(kvm, mem, &old, change);
>  
>  	kvm_free_physmem_slot(kvm, &old, &new);
> -	kfree(old_memslots);
> +	kvfree(old_memslots);
>  
>  	/*
>  	 * IOMMU mapping:  New slots need to be mapped.  Old slots
> need to be @@ -936,7 +936,7 @@ int __kvm_set_memory_region(struct kvm
> *kvm, return 0;
>  
>  out_slots:
> -	kfree(slots);
> +	kvfree(slots);
>  out_free:
>  	kvm_free_physmem_slot(kvm, &new, &old);
>  out:


      reply	other threads:[~2015-03-31  9:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-20 12:21 Igor Mammedov
2015-03-31  9:24 ` Igor Mammedov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150331112432.3250707c@igors-macbook-pro.local \
    --to=imammedo@redhat.com \
    --cc=bsd@makefile.in \
    --cc=himbeere@meine-oma.de \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mimi.vx@gmail.com \
    --cc=mtosatti@redhat.com \
    --cc=pbonzini@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®