summaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests/kvm/lib/guest_modes.c
diff options
context:
space:
mode:
authorMarc Zyngier <maz@kernel.org>2021-12-27 12:48:05 +0000
committerMarc Zyngier <maz@kernel.org>2021-12-28 11:04:20 +0000
commit357c628e1248dd53f5c43a768246a83478a7f489 (patch)
treed4308c23be6ededc349d56647862b7a36cf1b8bb /tools/testing/selftests/kvm/lib/guest_modes.c
parentcb7c4f364abd09abd1865fa049ef492fb43e6bf3 (diff)
downloadlinux-stable-357c628e1248dd53f5c43a768246a83478a7f489.tar.gz
linux-stable-357c628e1248dd53f5c43a768246a83478a7f489.tar.bz2
linux-stable-357c628e1248dd53f5c43a768246a83478a7f489.zip
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 <maz@kernel.org> Reviewed-by: Andrew Jones <drjones@redhat.com> Link: https://lore.kernel.org/r/20211227124809.1335409-3-maz@kernel.org
Diffstat (limited to 'tools/testing/selftests/kvm/lib/guest_modes.c')
-rw-r--r--tools/testing/selftests/kvm/lib/guest_modes.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/tools/testing/selftests/kvm/lib/guest_modes.c b/tools/testing/selftests/kvm/lib/guest_modes.c
index c330f414ef96..5e3fdbd992fd 100644
--- a/tools/testing/selftests/kvm/lib/guest_modes.c
+++ b/tools/testing/selftests/kvm/lib/guest_modes.c
@@ -4,22 +4,46 @@
*/
#include "guest_modes.h"
+#ifdef __aarch64__
+enum vm_guest_mode vm_mode_default;
+#endif
+
struct guest_mode guest_modes[NUM_VM_MODES];
void guest_modes_append_default(void)
{
+#ifndef __aarch64__
guest_mode_append(VM_MODE_DEFAULT, true, true);
-
-#ifdef __aarch64__
- guest_mode_append(VM_MODE_P40V48_64K, true, true);
+#else
{
unsigned int limit = kvm_check_cap(KVM_CAP_ARM_VM_IPA_SIZE);
+ int i;
+
+ vm_mode_default = NUM_VM_MODES;
+
if (limit >= 52)
guest_mode_append(VM_MODE_P52V48_64K, true, true);
if (limit >= 48) {
guest_mode_append(VM_MODE_P48V48_4K, true, true);
guest_mode_append(VM_MODE_P48V48_64K, true, true);
}
+ if (limit >= 40) {
+ guest_mode_append(VM_MODE_P40V48_4K, true, true);
+ guest_mode_append(VM_MODE_P40V48_64K, true, true);
+ vm_mode_default = VM_MODE_P40V48_4K;
+ }
+
+ /*
+ * Pick the first supported IPA size if the default
+ * isn't available.
+ */
+ for (i = 0; vm_mode_default == NUM_VM_MODES && i < NUM_VM_MODES; i++) {
+ if (guest_modes[i].supported && guest_modes[i].enabled)
+ vm_mode_default = i;
+ }
+
+ TEST_ASSERT(vm_mode_default != NUM_VM_MODES,
+ "No supported mode!");
}
#endif
#ifdef __s390x__