]> git.baikalelectronics.ru Git - kernel.git/commitdiff
selftests: KVM: Rename psci_cpu_on_test to psci_test
authorOliver Upton <oupton@google.com>
Sat, 9 Apr 2022 18:45:45 +0000 (18:45 +0000)
committerMarc Zyngier <maz@kernel.org>
Tue, 3 May 2022 20:30:19 +0000 (21:30 +0100)
There are other interactions with PSCI worth testing; rename the PSCI
test to make it more generic.

No functional change intended.

Signed-off-by: Oliver Upton <oupton@google.com>
Reviewed-by: Andrew Jones <drjones@redhat.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20220409184549.1681189-10-oupton@google.com
tools/testing/selftests/kvm/.gitignore
tools/testing/selftests/kvm/Makefile
tools/testing/selftests/kvm/aarch64/psci_cpu_on_test.c [deleted file]
tools/testing/selftests/kvm/aarch64/psci_test.c [new file with mode: 0644]

index 0b0e4402bba6ae13e66cc812b64f7a128a1ca4ab..1bb575dfc42e5310dc54434b8f859afb4094c8fc 100644 (file)
@@ -2,7 +2,7 @@
 /aarch64/arch_timer
 /aarch64/debug-exceptions
 /aarch64/get-reg-list
-/aarch64/psci_cpu_on_test
+/aarch64/psci_test
 /aarch64/vcpu_width_config
 /aarch64/vgic_init
 /aarch64/vgic_irq
index 681b173aa87c17e5d467071f59d23764b2023759..c2cf4d31829621d6a2449063510005edb7522261 100644 (file)
@@ -105,7 +105,7 @@ TEST_GEN_PROGS_x86_64 += system_counter_offset_test
 TEST_GEN_PROGS_aarch64 += aarch64/arch_timer
 TEST_GEN_PROGS_aarch64 += aarch64/debug-exceptions
 TEST_GEN_PROGS_aarch64 += aarch64/get-reg-list
-TEST_GEN_PROGS_aarch64 += aarch64/psci_cpu_on_test
+TEST_GEN_PROGS_aarch64 += aarch64/psci_test
 TEST_GEN_PROGS_aarch64 += aarch64/vcpu_width_config
 TEST_GEN_PROGS_aarch64 += aarch64/vgic_init
 TEST_GEN_PROGS_aarch64 += aarch64/vgic_irq
diff --git a/tools/testing/selftests/kvm/aarch64/psci_cpu_on_test.c b/tools/testing/selftests/kvm/aarch64/psci_cpu_on_test.c
deleted file mode 100644 (file)
index 4c5f681..0000000
+++ /dev/null
@@ -1,121 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-only
-/*
- * psci_cpu_on_test - Test that the observable state of a vCPU targeted by the
- * CPU_ON PSCI call matches what the caller requested.
- *
- * Copyright (c) 2021 Google LLC.
- *
- * This is a regression test for a race between KVM servicing the PSCI call and
- * userspace reading the vCPUs registers.
- */
-
-#define _GNU_SOURCE
-
-#include <linux/psci.h>
-
-#include "kvm_util.h"
-#include "processor.h"
-#include "test_util.h"
-
-#define VCPU_ID_SOURCE 0
-#define VCPU_ID_TARGET 1
-
-#define CPU_ON_ENTRY_ADDR 0xfeedf00dul
-#define CPU_ON_CONTEXT_ID 0xdeadc0deul
-
-static uint64_t psci_cpu_on(uint64_t target_cpu, uint64_t entry_addr,
-                           uint64_t context_id)
-{
-       register uint64_t x0 asm("x0") = PSCI_0_2_FN64_CPU_ON;
-       register uint64_t x1 asm("x1") = target_cpu;
-       register uint64_t x2 asm("x2") = entry_addr;
-       register uint64_t x3 asm("x3") = context_id;
-
-       asm("hvc #0"
-           : "=r"(x0)
-           : "r"(x0), "r"(x1), "r"(x2), "r"(x3)
-           : "memory");
-
-       return x0;
-}
-
-static uint64_t psci_affinity_info(uint64_t target_affinity,
-                                  uint64_t lowest_affinity_level)
-{
-       register uint64_t x0 asm("x0") = PSCI_0_2_FN64_AFFINITY_INFO;
-       register uint64_t x1 asm("x1") = target_affinity;
-       register uint64_t x2 asm("x2") = lowest_affinity_level;
-
-       asm("hvc #0"
-           : "=r"(x0)
-           : "r"(x0), "r"(x1), "r"(x2)
-           : "memory");
-
-       return x0;
-}
-
-static void guest_main(uint64_t target_cpu)
-{
-       GUEST_ASSERT(!psci_cpu_on(target_cpu, CPU_ON_ENTRY_ADDR, CPU_ON_CONTEXT_ID));
-       uint64_t target_state;
-
-       do {
-               target_state = psci_affinity_info(target_cpu, 0);
-
-               GUEST_ASSERT((target_state == PSCI_0_2_AFFINITY_LEVEL_ON) ||
-                            (target_state == PSCI_0_2_AFFINITY_LEVEL_OFF));
-       } while (target_state != PSCI_0_2_AFFINITY_LEVEL_ON);
-
-       GUEST_DONE();
-}
-
-int main(void)
-{
-       uint64_t target_mpidr, obs_pc, obs_x0;
-       struct kvm_vcpu_init init;
-       struct kvm_vm *vm;
-       struct ucall uc;
-
-       vm = vm_create(VM_MODE_DEFAULT, DEFAULT_GUEST_PHY_PAGES, O_RDWR);
-       kvm_vm_elf_load(vm, program_invocation_name);
-       ucall_init(vm, NULL);
-
-       vm_ioctl(vm, KVM_ARM_PREFERRED_TARGET, &init);
-       init.features[0] |= (1 << KVM_ARM_VCPU_PSCI_0_2);
-
-       aarch64_vcpu_add_default(vm, VCPU_ID_SOURCE, &init, guest_main);
-
-       /*
-        * make sure the target is already off when executing the test.
-        */
-       init.features[0] |= (1 << KVM_ARM_VCPU_POWER_OFF);
-       aarch64_vcpu_add_default(vm, VCPU_ID_TARGET, &init, guest_main);
-
-       get_reg(vm, VCPU_ID_TARGET, KVM_ARM64_SYS_REG(SYS_MPIDR_EL1), &target_mpidr);
-       vcpu_args_set(vm, VCPU_ID_SOURCE, 1, target_mpidr & MPIDR_HWID_BITMASK);
-       vcpu_run(vm, VCPU_ID_SOURCE);
-
-       switch (get_ucall(vm, VCPU_ID_SOURCE, &uc)) {
-       case UCALL_DONE:
-               break;
-       case UCALL_ABORT:
-               TEST_FAIL("%s at %s:%ld", (const char *)uc.args[0], __FILE__,
-                         uc.args[1]);
-               break;
-       default:
-               TEST_FAIL("Unhandled ucall: %lu", uc.cmd);
-       }
-
-       get_reg(vm, VCPU_ID_TARGET, ARM64_CORE_REG(regs.pc), &obs_pc);
-       get_reg(vm, VCPU_ID_TARGET, ARM64_CORE_REG(regs.regs[0]), &obs_x0);
-
-       TEST_ASSERT(obs_pc == CPU_ON_ENTRY_ADDR,
-                   "unexpected target cpu pc: %lx (expected: %lx)",
-                   obs_pc, CPU_ON_ENTRY_ADDR);
-       TEST_ASSERT(obs_x0 == CPU_ON_CONTEXT_ID,
-                   "unexpected target context id: %lx (expected: %lx)",
-                   obs_x0, CPU_ON_CONTEXT_ID);
-
-       kvm_vm_free(vm);
-       return 0;
-}
diff --git a/tools/testing/selftests/kvm/aarch64/psci_test.c b/tools/testing/selftests/kvm/aarch64/psci_test.c
new file mode 100644 (file)
index 0000000..4c5f681
--- /dev/null
@@ -0,0 +1,121 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * psci_cpu_on_test - Test that the observable state of a vCPU targeted by the
+ * CPU_ON PSCI call matches what the caller requested.
+ *
+ * Copyright (c) 2021 Google LLC.
+ *
+ * This is a regression test for a race between KVM servicing the PSCI call and
+ * userspace reading the vCPUs registers.
+ */
+
+#define _GNU_SOURCE
+
+#include <linux/psci.h>
+
+#include "kvm_util.h"
+#include "processor.h"
+#include "test_util.h"
+
+#define VCPU_ID_SOURCE 0
+#define VCPU_ID_TARGET 1
+
+#define CPU_ON_ENTRY_ADDR 0xfeedf00dul
+#define CPU_ON_CONTEXT_ID 0xdeadc0deul
+
+static uint64_t psci_cpu_on(uint64_t target_cpu, uint64_t entry_addr,
+                           uint64_t context_id)
+{
+       register uint64_t x0 asm("x0") = PSCI_0_2_FN64_CPU_ON;
+       register uint64_t x1 asm("x1") = target_cpu;
+       register uint64_t x2 asm("x2") = entry_addr;
+       register uint64_t x3 asm("x3") = context_id;
+
+       asm("hvc #0"
+           : "=r"(x0)
+           : "r"(x0), "r"(x1), "r"(x2), "r"(x3)
+           : "memory");
+
+       return x0;
+}
+
+static uint64_t psci_affinity_info(uint64_t target_affinity,
+                                  uint64_t lowest_affinity_level)
+{
+       register uint64_t x0 asm("x0") = PSCI_0_2_FN64_AFFINITY_INFO;
+       register uint64_t x1 asm("x1") = target_affinity;
+       register uint64_t x2 asm("x2") = lowest_affinity_level;
+
+       asm("hvc #0"
+           : "=r"(x0)
+           : "r"(x0), "r"(x1), "r"(x2)
+           : "memory");
+
+       return x0;
+}
+
+static void guest_main(uint64_t target_cpu)
+{
+       GUEST_ASSERT(!psci_cpu_on(target_cpu, CPU_ON_ENTRY_ADDR, CPU_ON_CONTEXT_ID));
+       uint64_t target_state;
+
+       do {
+               target_state = psci_affinity_info(target_cpu, 0);
+
+               GUEST_ASSERT((target_state == PSCI_0_2_AFFINITY_LEVEL_ON) ||
+                            (target_state == PSCI_0_2_AFFINITY_LEVEL_OFF));
+       } while (target_state != PSCI_0_2_AFFINITY_LEVEL_ON);
+
+       GUEST_DONE();
+}
+
+int main(void)
+{
+       uint64_t target_mpidr, obs_pc, obs_x0;
+       struct kvm_vcpu_init init;
+       struct kvm_vm *vm;
+       struct ucall uc;
+
+       vm = vm_create(VM_MODE_DEFAULT, DEFAULT_GUEST_PHY_PAGES, O_RDWR);
+       kvm_vm_elf_load(vm, program_invocation_name);
+       ucall_init(vm, NULL);
+
+       vm_ioctl(vm, KVM_ARM_PREFERRED_TARGET, &init);
+       init.features[0] |= (1 << KVM_ARM_VCPU_PSCI_0_2);
+
+       aarch64_vcpu_add_default(vm, VCPU_ID_SOURCE, &init, guest_main);
+
+       /*
+        * make sure the target is already off when executing the test.
+        */
+       init.features[0] |= (1 << KVM_ARM_VCPU_POWER_OFF);
+       aarch64_vcpu_add_default(vm, VCPU_ID_TARGET, &init, guest_main);
+
+       get_reg(vm, VCPU_ID_TARGET, KVM_ARM64_SYS_REG(SYS_MPIDR_EL1), &target_mpidr);
+       vcpu_args_set(vm, VCPU_ID_SOURCE, 1, target_mpidr & MPIDR_HWID_BITMASK);
+       vcpu_run(vm, VCPU_ID_SOURCE);
+
+       switch (get_ucall(vm, VCPU_ID_SOURCE, &uc)) {
+       case UCALL_DONE:
+               break;
+       case UCALL_ABORT:
+               TEST_FAIL("%s at %s:%ld", (const char *)uc.args[0], __FILE__,
+                         uc.args[1]);
+               break;
+       default:
+               TEST_FAIL("Unhandled ucall: %lu", uc.cmd);
+       }
+
+       get_reg(vm, VCPU_ID_TARGET, ARM64_CORE_REG(regs.pc), &obs_pc);
+       get_reg(vm, VCPU_ID_TARGET, ARM64_CORE_REG(regs.regs[0]), &obs_x0);
+
+       TEST_ASSERT(obs_pc == CPU_ON_ENTRY_ADDR,
+                   "unexpected target cpu pc: %lx (expected: %lx)",
+                   obs_pc, CPU_ON_ENTRY_ADDR);
+       TEST_ASSERT(obs_x0 == CPU_ON_CONTEXT_ID,
+                   "unexpected target context id: %lx (expected: %lx)",
+                   obs_x0, CPU_ON_CONTEXT_ID);
+
+       kvm_vm_free(vm);
+       return 0;
+}