Re: [kvm PATCH 1/1] kvm: Make VM ioctl do a vzalloc instead of a kzalloc

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 04/19/2018 08:29 PM, Marc Orr wrote:
> The kvm struct is (currently) tens of kilo-bytes, which turns out to be a
> large amount of memory to allocate contiguously via kzalloc. Thus, this
> patch changes the kzalloc to a vzalloc, so that the memory allocation is
> less likely to fail in resource-constrained environments.
> 
> Signed-off-by: Marc Orr <marcorr@xxxxxxxxxx>
> ---
>  include/linux/kvm_host.h | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> index 6930c63126c7..cf7b6a3a4197 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -19,6 +19,7 @@
>  #include <linux/preempt.h>
>  #include <linux/msi.h>
>  #include <linux/slab.h>
> +#include <linux/vmalloc.h>
>  #include <linux/rcupdate.h>
>  #include <linux/ratelimit.h>
>  #include <linux/err.h>
> @@ -810,12 +811,12 @@ int kvm_arch_vcpu_should_kick(struct kvm_vcpu *vcpu);
>  #ifndef __KVM_HAVE_ARCH_VM_ALLOC
>  static inline struct kvm *kvm_arch_alloc_vm(void)
>  {
> -	return kzalloc(sizeof(struct kvm), GFP_KERNEL);
> +	return vzalloc(sizeof(struct kvm));
>  }
> 
>  static inline void kvm_arch_free_vm(struct kvm *kvm)
>  {
> -	kfree(kvm);
> +	vfree(kvm);
>  }
>  #endif
> 

I dont think this is necessarily safe. This contains kvm_arch and you
would need to verify that no architecture has data in struct kvm_arch 
that must be allocated with kmalloc. Fo example on s390 kernel virtual
== kernel real for kmalloc so some driver might rely on that.
FWIW, it looks like the s390 struct kvm_arch is fine, but this requires 
more review I guess.

Another thing: 

In s390 this is 14760 bytes and on x86 it seems to be 12440 on my system.
This should never fail, no?




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux