[PATCH 1/5] KVM: selftests: Fix vm_compute_max_gfn on !x86

Marc Zyngier maz at kernel.org
Thu Dec 16 04:31:31 PST 2021


Compiling the selftestts on arm64 leads to this:

gcc -Wall -Wstrict-prototypes -Wuninitialized -O2 -g -std=gnu99 -fno-stack-protector -fno-PIE -I../../../../tools/include -I../../../../tools/arch/arm64/include -I../../../../usr/include/ -Iinclude -Ilib -Iinclude/aarch64 -I..   -c lib/kvm_util.c -o /home/maz/arm-platforms/tools/testing/selftests/kvm/lib/kvm_util.o
In file included from lib/kvm_util.c:10:
include/kvm_util.h: In function ‘vm_compute_max_gfn’:
include/kvm_util.h:79:21: error: invalid use of undefined type ‘struct kvm_vm’
   79 |  return ((1ULL << vm->pa_bits) >> vm->page_shift) - 1;
      |                     ^~
include/kvm_util.h:79:37: error: invalid use of undefined type ‘struct kvm_vm’
   79 |  return ((1ULL << vm->pa_bits) >> vm->page_shift) - 1;
      |                                     ^~
[...]

This is all because struct kvm_vm is not defined yet (only declared).
Sidestep the whole issue by making vm_compute_max_gfn() a macro.

Fixes: c8cc43c1eae2 ("selftests: KVM: avoid failures due to reserved HyperTransport region")
Signed-off-by: Marc Zyngier <maz at kernel.org>
---
 tools/testing/selftests/kvm/include/kvm_util.h | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/kvm/include/kvm_util.h b/tools/testing/selftests/kvm/include/kvm_util.h
index da2b702da71a..c74241ddf8b1 100644
--- a/tools/testing/selftests/kvm/include/kvm_util.h
+++ b/tools/testing/selftests/kvm/include/kvm_util.h
@@ -74,10 +74,11 @@ enum vm_guest_mode {
 #if defined(__x86_64__)
 unsigned long vm_compute_max_gfn(struct kvm_vm *vm);
 #else
-static inline unsigned long vm_compute_max_gfn(struct kvm_vm *vm)
-{
-	return ((1ULL << vm->pa_bits) >> vm->page_shift) - 1;
-}
+#define vm_compute_max_gfn(vm)						\
+	({								\
+		struct kvm_vm *__vm = vm;				\
+		((1ULL << __vm->pa_bits) >> __vm->page_shift) - 1;	\
+	})
 #endif
 
 #define MIN_PAGE_SIZE		(1U << MIN_PAGE_SHIFT)
-- 
2.30.2




More information about the linux-arm-kernel mailing list