* [PATCH] KVM: use kvcalloc for array allocations
@ 2022-03-08 16:33 Paolo Bonzini
2022-03-08 17:43 ` Oliver Upton
0 siblings, 1 reply; 3+ messages in thread
From: Paolo Bonzini @ 2022-03-08 16:33 UTC (permalink / raw)
To: linux-kernel, kvm
Instead of using array_size, use a function that takes care of the
multiplication. While at it, switch to kvcalloc since this allocation
should not be very large.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
arch/x86/kvm/cpuid.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index afcdd4e693e5..419eb8e14f79 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -1248,8 +1248,7 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
if (sanity_check_entries(entries, cpuid->nent, type))
return -EINVAL;
- array.entries = vzalloc(array_size(sizeof(struct kvm_cpuid_entry2),
- cpuid->nent));
+ array.entries = kvcalloc(sizeof(struct kvm_cpuid_entry2), cpuid->nent, GFP_KERNEL);
if (!array.entries)
return -ENOMEM;
@@ -1267,7 +1266,7 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
r = -EFAULT;
out_free:
- vfree(array.entries);
+ kvfree(array.entries);
return r;
}
--
2.31.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] KVM: use kvcalloc for array allocations
2022-03-08 16:33 [PATCH] KVM: use kvcalloc for array allocations Paolo Bonzini
@ 2022-03-08 17:43 ` Oliver Upton
0 siblings, 0 replies; 3+ messages in thread
From: Oliver Upton @ 2022-03-08 17:43 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: linux-kernel, kvm
On Tue, Mar 08, 2022 at 11:33:18AM -0500, Paolo Bonzini wrote:
> Instead of using array_size, use a function that takes care of the
> multiplication. While at it, switch to kvcalloc since this allocation
> should not be very large.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> arch/x86/kvm/cpuid.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
> index afcdd4e693e5..419eb8e14f79 100644
> --- a/arch/x86/kvm/cpuid.c
> +++ b/arch/x86/kvm/cpuid.c
> @@ -1248,8 +1248,7 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
> if (sanity_check_entries(entries, cpuid->nent, type))
> return -EINVAL;
>
> - array.entries = vzalloc(array_size(sizeof(struct kvm_cpuid_entry2),
> - cpuid->nent));
> + array.entries = kvcalloc(sizeof(struct kvm_cpuid_entry2), cpuid->nent, GFP_KERNEL);
Even though this allocation is short-lived, should we use
GFP_KERNEL_ACCOUNT instead?
Otherwise:
Reviewed-by: Oliver Upton <oupton@google.com>
Thanks!
> if (!array.entries)
> return -ENOMEM;
>
> @@ -1267,7 +1266,7 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
> r = -EFAULT;
>
> out_free:
> - vfree(array.entries);
> + kvfree(array.entries);
> return r;
> }
>
> --
> 2.31.1
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] KVM: use kvcalloc for array allocations
@ 2022-03-30 2:55 Zhiguang Ni
0 siblings, 0 replies; 3+ messages in thread
From: Zhiguang Ni @ 2022-03-30 2:55 UTC (permalink / raw)
To: pbonzini, seanjc, vkuznets, wanpengli, jmattson, joro, tglx,
mingo, bp, dave.hansen, hpa
Cc: x86, kvm, linux-kernel, Zhiguang Ni
From: Paolo Bonzini <pbonzini@redhat.com>
Instead of using array_size, use a function that takes care of the
multiplication. While at it, switch to kvcalloc since this allocation
should not be very large.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Zhiguang Ni <zhiguangni01@gmail.com>
---
arch/x86/kvm/cpuid.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index 32007f902bba..58b0b4e0263c 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -1290,8 +1290,7 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
if (sanity_check_entries(entries, cpuid->nent, type))
return -EINVAL;
- array.entries = vzalloc(array_size(sizeof(struct kvm_cpuid_entry2),
- cpuid->nent));
+ array.entries = kvcalloc(sizeof(struct kvm_cpuid_entry2), cpuid->nent, GFP_KERNEL);
if (!array.entries)
return -ENOMEM;
@@ -1309,7 +1308,7 @@ int kvm_dev_ioctl_get_cpuid(struct kvm_cpuid2 *cpuid,
r = -EFAULT;
out_free:
- vfree(array.entries);
+ kvfree(array.entries);
return r;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-03-30 2:56 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-08 16:33 [PATCH] KVM: use kvcalloc for array allocations Paolo Bonzini
2022-03-08 17:43 ` Oliver Upton
2022-03-30 2:55 Zhiguang Ni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).