Skip to content

Commit

Permalink
selftests: KVM: Fix non-x86 compiling
Browse files Browse the repository at this point in the history
commit 577e022 upstream.

Attempting to compile on a non-x86 architecture fails with

include/kvm_util.h: In function ‘vm_compute_max_gfn’:
include/kvm_util.h:79:21: error: dereferencing pointer to incomplete type ‘struct kvm_vm’
  return ((1ULL << vm->pa_bits) >> vm->page_shift) - 1;
                     ^~

This is because the declaration of struct kvm_vm is in
lib/kvm_util_internal.h as an effort to make it private to
the test lib code. We can still provide arch specific functions,
though, by making the generic function symbols weak. Do that to
fix the compile error.

Fixes: c8cc43c ("selftests: KVM: avoid failures due to reserved HyperTransport region")
Cc: stable@vger.kernel.org
Signed-off-by: Andrew Jones <drjones@redhat.com>
Message-Id: <20211214151842.848314-1-drjones@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
Andrew Jones authored and gregkh committed Dec 29, 2021
1 parent 49c29e1 commit a65ac9d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
10 changes: 1 addition & 9 deletions tools/testing/selftests/kvm/include/kvm_util.h
Expand Up @@ -69,15 +69,6 @@ enum vm_guest_mode {

#endif

#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;
}
#endif

#define MIN_PAGE_SIZE (1U << MIN_PAGE_SHIFT)
#define PTES_PER_MIN_PAGE ptes_per_page(MIN_PAGE_SIZE)

Expand Down Expand Up @@ -318,6 +309,7 @@ bool vm_is_unrestricted_guest(struct kvm_vm *vm);

unsigned int vm_get_page_size(struct kvm_vm *vm);
unsigned int vm_get_page_shift(struct kvm_vm *vm);
unsigned long vm_compute_max_gfn(struct kvm_vm *vm);
uint64_t vm_get_max_gfn(struct kvm_vm *vm);
int vm_get_fd(struct kvm_vm *vm);

Expand Down
5 changes: 5 additions & 0 deletions tools/testing/selftests/kvm/lib/kvm_util.c
Expand Up @@ -2282,6 +2282,11 @@ unsigned int vm_get_page_shift(struct kvm_vm *vm)
return vm->page_shift;
}

unsigned long __attribute__((weak)) vm_compute_max_gfn(struct kvm_vm *vm)
{
return ((1ULL << vm->pa_bits) >> vm->page_shift) - 1;
}

uint64_t vm_get_max_gfn(struct kvm_vm *vm)
{
return vm->max_gfn;
Expand Down

0 comments on commit a65ac9d

Please sign in to comment.