Skip to contentSkip to conversation

KVM: fix kvm_mmu_memory_cache allocation warning

PATCH Applied Arnd Bergmann 3 participants 3 messages Feb 12, 2024 – Feb 23, 2024 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 KVM: fix kvm_mmu_memory_cache allocation warning

From: Arnd Bergmann <[email protected]>

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")
---
 virt/kvm/kvm_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
virt/kvm/kvm_main.c +1 -1
index 8f03b56dafbd..4c48f61cae35 100644
@@ -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;
 
Signature · 1 line
2.39.2
Reviewed-by on v1 1/1
#1 lore raw
Quoted 25 lines · Arnd Bergmann

From: Arnd Bergmann <[email protected]>

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")
---
 virt/kvm/kvm_main.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
virt/kvm/kvm_main.c +0 -0
index 8f03b56dafbd..4c48f61cae35 100644

virt/kvm/kvm_main.c int __kvm_mmu_topup_memory_cache(struct kvm_mmu_memory_cache *mc, int capacity, · line 427

Quoted 8 lines
virt/kvm/kvm_main.c +1 -1
@@ -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.

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
reviewer Applied
#2 lore raw
In reply to Arnd Bergmann
Quoted 9 lines · Arnd Bergmann

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