Skip to content

Commit 357c628

Browse files
author
Marc Zyngier
committed
KVM: selftests: arm64: Introduce a variable default IPA size
Contrary to popular belief, there is no such thing as a default IPA size on arm64. Anything goes, and implementations are the usual Wild West. The selftest infrastructure default to 40bit IPA, which obviously doesn't work for some systems out there. Turn VM_MODE_DEFAULT from a constant into a variable, and let guest_modes_append_default() populate it, depending on what the HW can do. In order to preserve the current behaviour, we still pick 40bits IPA as the default if it is available, and the largest supported IPA space otherwise. Signed-off-by: Marc Zyngier <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent cb7c4f3 commit 357c628

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

tools/testing/selftests/kvm/include/kvm_util.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ enum vm_guest_mode {
5353

5454
#if defined(__aarch64__)
5555

56-
#define VM_MODE_DEFAULT VM_MODE_P40V48_4K
56+
extern enum vm_guest_mode vm_mode_default;
57+
58+
#define VM_MODE_DEFAULT vm_mode_default
5759
#define MIN_PAGE_SHIFT 12U
5860
#define ptes_per_page(page_size) ((page_size) / 8)
5961

tools/testing/selftests/kvm/lib/guest_modes.c

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,46 @@
44
*/
55
#include "guest_modes.h"
66

7+
#ifdef __aarch64__
8+
enum vm_guest_mode vm_mode_default;
9+
#endif
10+
711
struct guest_mode guest_modes[NUM_VM_MODES];
812

913
void guest_modes_append_default(void)
1014
{
15+
#ifndef __aarch64__
1116
guest_mode_append(VM_MODE_DEFAULT, true, true);
12-
13-
#ifdef __aarch64__
14-
guest_mode_append(VM_MODE_P40V48_64K, true, true);
17+
#else
1518
{
1619
unsigned int limit = kvm_check_cap(KVM_CAP_ARM_VM_IPA_SIZE);
20+
int i;
21+
22+
vm_mode_default = NUM_VM_MODES;
23+
1724
if (limit >= 52)
1825
guest_mode_append(VM_MODE_P52V48_64K, true, true);
1926
if (limit >= 48) {
2027
guest_mode_append(VM_MODE_P48V48_4K, true, true);
2128
guest_mode_append(VM_MODE_P48V48_64K, true, true);
2229
}
30+
if (limit >= 40) {
31+
guest_mode_append(VM_MODE_P40V48_4K, true, true);
32+
guest_mode_append(VM_MODE_P40V48_64K, true, true);
33+
vm_mode_default = VM_MODE_P40V48_4K;
34+
}
35+
36+
/*
37+
* Pick the first supported IPA size if the default
38+
* isn't available.
39+
*/
40+
for (i = 0; vm_mode_default == NUM_VM_MODES && i < NUM_VM_MODES; i++) {
41+
if (guest_modes[i].supported && guest_modes[i].enabled)
42+
vm_mode_default = i;
43+
}
44+
45+
TEST_ASSERT(vm_mode_default != NUM_VM_MODES,
46+
"No supported mode!");
2347
}
2448
#endif
2549
#ifdef __s390x__

0 commit comments

Comments
 (0)