public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: fix kvm_mmu_memory_cache allocation warning
@ 2024-02-12 11:24 Arnd Bergmann
  2024-02-12 11:51 ` Marc Zyngier
  2024-02-23  1:35 ` Sean Christopherson
  0 siblings, 2 replies; 3+ messages in thread
From: Arnd Bergmann @ 2024-02-12 11:24 UTC (permalink / raw)
  To: Paolo Bonzini, Marc Zyngier, David Matlack
  Cc: Arnd Bergmann, Sean Christopherson, Fuad Tabba, Shaoqin Huang,
	Chao Peng, kvm, linux-kernel

From: Arnd Bergmann <arnd@arndb.de>

gcc-14 notices that the arguments to kvmalloc_array() are mixed up:

arch/x86/kvm/../../../virt/kvm/kvm_main.c: In function '__kvm_mmu_topup_memory_cache':
arch/x86/kvm/../../../virt/kvm/kvm_main.c:424:53: error: 'kvmalloc_array' sizes specified with 'sizeof' in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
  424 |                 mc->objects = kvmalloc_array(sizeof(void *), capacity, gfp);
      |                                                     ^~~~
arch/x86/kvm/../../../virt/kvm/kvm_main.c:424:53: note: earlier argument should specify number of elements, later size of each element

The code still works correctly, but the incorrect order prevents the compiler
from properly tracking the object sizes.

Fixes: 837f66c71207 ("KVM: Allow for different capacities in kvm_mmu_memory_cache structs")
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 virt/kvm/kvm_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 8f03b56dafbd..4c48f61cae35 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -421,7 +421,7 @@ int __kvm_mmu_topup_memory_cache(struct kvm_mmu_memory_cache *mc, int capacity,
 		if (WARN_ON_ONCE(!capacity))
 			return -EIO;
 
-		mc->objects = kvmalloc_array(sizeof(void *), capacity, gfp);
+		mc->objects = kvmalloc_array(capacity, sizeof(void *), gfp);
 		if (!mc->objects)
 			return -ENOMEM;
 
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] KVM: fix kvm_mmu_memory_cache allocation warning
  2024-02-12 11:24 [PATCH] KVM: fix kvm_mmu_memory_cache allocation warning Arnd Bergmann
@ 2024-02-12 11:51 ` Marc Zyngier
  2024-02-23  1:35 ` Sean Christopherson
  1 sibling, 0 replies; 3+ messages in thread
From: Marc Zyngier @ 2024-02-12 11:51 UTC (permalink / raw)
  To: Arnd Bergmann
  Cc: Paolo Bonzini, David Matlack, Arnd Bergmann, Sean Christopherson,
	Fuad Tabba, Shaoqin Huang, Chao Peng, kvm, linux-kernel

On Mon, 12 Feb 2024 11:24:10 +0000,
Arnd Bergmann <arnd@kernel.org> wrote:
> 
> From: Arnd Bergmann <arnd@arndb.de>
> 
> gcc-14 notices that the arguments to kvmalloc_array() are mixed up:
> 
> arch/x86/kvm/../../../virt/kvm/kvm_main.c: In function '__kvm_mmu_topup_memory_cache':
> arch/x86/kvm/../../../virt/kvm/kvm_main.c:424:53: error: 'kvmalloc_array' sizes specified with 'sizeof' in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
>   424 |                 mc->objects = kvmalloc_array(sizeof(void *), capacity, gfp);
>       |                                                     ^~~~
> arch/x86/kvm/../../../virt/kvm/kvm_main.c:424:53: note: earlier argument should specify number of elements, later size of each element
> 
> The code still works correctly, but the incorrect order prevents the compiler
> from properly tracking the object sizes.
> 
> Fixes: 837f66c71207 ("KVM: Allow for different capacities in kvm_mmu_memory_cache structs")
> Signed-off-by: Arnd Bergmann <arnd@arndb.de>
> ---
>  virt/kvm/kvm_main.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index 8f03b56dafbd..4c48f61cae35 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -421,7 +421,7 @@ int __kvm_mmu_topup_memory_cache(struct kvm_mmu_memory_cache *mc, int capacity,
>  		if (WARN_ON_ONCE(!capacity))
>  			return -EIO;
>  
> -		mc->objects = kvmalloc_array(sizeof(void *), capacity, gfp);
> +		mc->objects = kvmalloc_array(capacity, sizeof(void *), gfp);
>  		if (!mc->objects)
>  			return -ENOMEM;
>  

Huh, well spotted GCC. And thanks Arnd for the fix.

Reviewed-by: Marc Zyngier <maz@kernel.org>

	M.

-- 
Without deviation from the norm, progress is not possible.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] KVM: fix kvm_mmu_memory_cache allocation warning
  2024-02-12 11:24 [PATCH] KVM: fix kvm_mmu_memory_cache allocation warning Arnd Bergmann
  2024-02-12 11:51 ` Marc Zyngier
@ 2024-02-23  1:35 ` Sean Christopherson
  1 sibling, 0 replies; 3+ messages in thread
From: Sean Christopherson @ 2024-02-23  1:35 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini, Marc Zyngier, David Matlack,
	Arnd Bergmann
  Cc: Arnd Bergmann, Fuad Tabba, Shaoqin Huang, Chao Peng, kvm,
	linux-kernel

On Mon, 12 Feb 2024 12:24:10 +0100, Arnd Bergmann wrote:
> gcc-14 notices that the arguments to kvmalloc_array() are mixed up:
> 
> arch/x86/kvm/../../../virt/kvm/kvm_main.c: In function '__kvm_mmu_topup_memory_cache':
> arch/x86/kvm/../../../virt/kvm/kvm_main.c:424:53: error: 'kvmalloc_array' sizes specified with 'sizeof' in the earlier argument and not in the later argument [-Werror=calloc-transposed-args]
>   424 |                 mc->objects = kvmalloc_array(sizeof(void *), capacity, gfp);
>       |                                                     ^~~~
> arch/x86/kvm/../../../virt/kvm/kvm_main.c:424:53: note: earlier argument should specify number of elements, later size of each element
> 
> [...]

Applied to kvm-x86 generic, so that this doesn't languish with everyone looking
at each other.

[1/1] KVM: fix kvm_mmu_memory_cache allocation warning
      https://github.com/kvm-x86/linux/commit/ea3689d9df50

--
https://github.com/kvm-x86/linux/tree/next

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-02-23  1:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-12 11:24 [PATCH] KVM: fix kvm_mmu_memory_cache allocation warning Arnd Bergmann
2024-02-12 11:51 ` Marc Zyngier
2024-02-23  1:35 ` Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox