All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH kvm-unit-tests 0/2] arm/arm64: introduce PSCI tests
@ 2017-02-27 17:32 Andrew Jones
  2017-02-27 17:32 ` [PATCH kvm-unit-tests 1/2] arm/arm64: Add " Andrew Jones
  2017-02-27 17:32 ` [PATCH kvm-unit-tests 2/2] arm/arm64: psci: support testing tcg Andrew Jones
  0 siblings, 2 replies; 4+ messages in thread
From: Andrew Jones @ 2017-02-27 17:32 UTC (permalink / raw)
  To: kvm, kvmarm

Andrew Jones (1):
  arm/arm64: psci: support testing tcg

Levente Kurusa (1):
  arm/arm64: Add PSCI tests

 arm/Makefile.common |   1 +
 arm/psci.c          | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 arm/unittests.cfg   |   6 +++
 3 files changed, 151 insertions(+)
 create mode 100644 arm/psci.c

-- 
2.9.3

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH kvm-unit-tests 1/2] arm/arm64: Add PSCI tests
  2017-02-27 17:32 [PATCH kvm-unit-tests 0/2] arm/arm64: introduce PSCI tests Andrew Jones
@ 2017-02-27 17:32 ` Andrew Jones
  2017-03-03 14:19   ` Radim Krčmář
  2017-02-27 17:32 ` [PATCH kvm-unit-tests 2/2] arm/arm64: psci: support testing tcg Andrew Jones
  1 sibling, 1 reply; 4+ messages in thread
From: Andrew Jones @ 2017-02-27 17:32 UTC (permalink / raw)
  To: kvm, kvmarm; +Cc: Levente Kurusa

From: Levente Kurusa <lkurusa@redhat.com>

The cpu_on test exposed two races in KVM's PSCI emulation.

Signed-off-by: Levente Kurusa <lkurusa@redhat.com>
[Rewrote the cpu_on test to improve the chance of hitting the race.
 Also added affinity-info tests and made some minor cleanups. -drew]
Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 arm/Makefile.common |   1 +
 arm/psci.c          | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 arm/unittests.cfg   |   6 +++
 3 files changed, 119 insertions(+)
 create mode 100644 arm/psci.c

diff --git a/arm/Makefile.common b/arm/Makefile.common
index f7193c3e6d64..74c7394eb7c1 100644
--- a/arm/Makefile.common
+++ b/arm/Makefile.common
@@ -14,6 +14,7 @@ tests-common += $(TEST_DIR)/spinlock-test.flat
 tests-common += $(TEST_DIR)/pci-test.flat
 tests-common += $(TEST_DIR)/pmu.flat
 tests-common += $(TEST_DIR)/gic.flat
+tests-common += $(TEST_DIR)/psci.flat
 
 tests-all = $(tests-common) $(tests)
 all: $(tests-all)
diff --git a/arm/psci.c b/arm/psci.c
new file mode 100644
index 000000000000..e571afb92c7e
--- /dev/null
+++ b/arm/psci.c
@@ -0,0 +1,112 @@
+/*
+ * PSCI tests
+ *
+ * Copyright (C) 2017, Red Hat, Inc.
+ * Author: Levente Kurusa <lkurusa@redhat.com>
+ * Author: Andrew Jones <drjones@redhat.com>
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.
+ */
+#include <libcflat.h>
+#include <asm/smp.h>
+#include <asm/psci.h>
+
+static bool psci_invalid_function(void)
+{
+	return psci_invoke(1337, 0, 0, 0) == PSCI_RET_NOT_SUPPORTED;
+}
+
+static int psci_affinity_info(unsigned long target_affinity, uint32_t lowest_affinity_level)
+{
+#ifdef __arm__
+	return psci_invoke(PSCI_0_2_FN_AFFINITY_INFO, target_affinity, lowest_affinity_level, 0);
+#else
+	return psci_invoke(PSCI_0_2_FN64_AFFINITY_INFO, target_affinity, lowest_affinity_level, 0);
+#endif
+}
+
+static bool psci_affinity_info_on(void)
+{
+	return psci_affinity_info(cpus[0], 0) == PSCI_0_2_AFFINITY_LEVEL_ON;
+}
+
+static bool psci_affinity_info_off(void)
+{
+	return psci_affinity_info(cpus[1], 0) == PSCI_0_2_AFFINITY_LEVEL_OFF;
+}
+
+static int cpu_on_ret[NR_CPUS];
+static cpumask_t cpu_on_ready, cpu_on_done;
+static volatile int cpu_on_start;
+
+static void cpu_on_secondary_entry(void)
+{
+	int cpu = smp_processor_id();
+
+	cpumask_set_cpu(cpu, &cpu_on_ready);
+	while (!cpu_on_start)
+		cpu_relax();
+	cpu_on_ret[cpu] = psci_cpu_on(cpus[1], __pa(halt));
+	cpumask_set_cpu(cpu, &cpu_on_done);
+	halt();
+}
+
+static bool psci_cpu_on_test(void)
+{
+	bool failed = false;
+	int cpu;
+
+	cpumask_set_cpu(1, &cpu_on_ready);
+	cpumask_set_cpu(1, &cpu_on_done);
+
+	for_each_present_cpu(cpu) {
+		if (cpu < 2)
+			continue;
+		smp_boot_secondary(cpu, cpu_on_secondary_entry);
+	}
+
+	cpumask_set_cpu(0, &cpu_on_ready);
+	while (!cpumask_full(&cpu_on_ready))
+		cpu_relax();
+
+	cpu_on_start = 1;
+	smp_mb();
+
+	cpu_on_ret[0] = psci_cpu_on(cpus[1], __pa(halt));
+	cpumask_set_cpu(0, &cpu_on_done);
+
+	while (!cpumask_full(&cpu_on_done))
+		cpu_relax();
+
+	for_each_present_cpu(cpu) {
+		if (cpu == 1)
+			continue;
+		if (cpu_on_ret[cpu] != PSCI_RET_SUCCESS && cpu_on_ret[cpu] != PSCI_RET_ALREADY_ON) {
+			report_info("unexpected cpu_on return value: caller=CPU%d, ret=%d", cpu, cpu_on_ret[cpu]);
+			failed = true;
+		}
+	}
+
+	return !failed;
+}
+
+int main(void)
+{
+	int ver = psci_invoke(PSCI_0_2_FN_PSCI_VERSION, 0, 0, 0);
+
+	report_info("PSCI version %d.%d", PSCI_VERSION_MAJOR(ver),
+					  PSCI_VERSION_MINOR(ver));
+	report("invalid-function", psci_invalid_function());
+	report("affinity-info-on", psci_affinity_info_on());
+	report("affinity-info-off", psci_affinity_info_off());
+	report("cpu-on", psci_cpu_on_test());
+
+#if 0
+	report_summary();
+	psci_invoke(PSCI_0_2_FN_SYSTEM_OFF, 0, 0, 0);
+	report("system-off", false);
+	return 1; /* only reaches here if system-off fails */
+#else
+	return report_summary();
+#endif
+}
diff --git a/arm/unittests.cfg b/arm/unittests.cfg
index 8cf94729d86e..c98658f7488b 100644
--- a/arm/unittests.cfg
+++ b/arm/unittests.cfg
@@ -91,3 +91,9 @@ file = gic.flat
 smp = $MAX_SMP
 extra_params = -machine gic-version=3 -append 'ipi'
 groups = gic
+
+# Test PSCI emulation
+[psci]
+file = psci.flat
+smp = $MAX_SMP
+groups = nodefault,psci
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH kvm-unit-tests 2/2] arm/arm64: psci: support testing tcg
  2017-02-27 17:32 [PATCH kvm-unit-tests 0/2] arm/arm64: introduce PSCI tests Andrew Jones
  2017-02-27 17:32 ` [PATCH kvm-unit-tests 1/2] arm/arm64: Add " Andrew Jones
@ 2017-02-27 17:32 ` Andrew Jones
  1 sibling, 0 replies; 4+ messages in thread
From: Andrew Jones @ 2017-02-27 17:32 UTC (permalink / raw)
  To: kvm, kvmarm

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 arm/psci.c | 34 +++++++++++++++++++++++++++++++++-
 1 file changed, 33 insertions(+), 1 deletion(-)

diff --git a/arm/psci.c b/arm/psci.c
index e571afb92c7e..3c5f43877fde 100644
--- a/arm/psci.c
+++ b/arm/psci.c
@@ -8,12 +8,44 @@
  * This work is licensed under the terms of the GNU LGPL, version 2.
  */
 #include <libcflat.h>
+#include <asm/processor.h>
 #include <asm/smp.h>
 #include <asm/psci.h>
 
+static bool invalid_function_exception;
+
+#ifdef __arm__
+static void invalid_function_handler(struct pt_regs *regs __unused)
+{
+	invalid_function_exception = true;
+}
+#else
+static void invalid_function_handler(struct pt_regs *regs, unsigned int esr __unused)
+{
+	invalid_function_exception = true;
+	regs->pc += 4;
+}
+#endif
+
+static void install_invalid_function_handler(exception_fn handler)
+{
+#ifdef __arm__
+	install_exception_handler(EXCPTN_UND, handler);
+#else
+	install_exception_handler(EL1H_SYNC, ESR_EL1_EC_UNKNOWN, handler);
+#endif
+}
+
 static bool psci_invalid_function(void)
 {
-	return psci_invoke(1337, 0, 0, 0) == PSCI_RET_NOT_SUPPORTED;
+	bool pass;
+
+	install_invalid_function_handler(invalid_function_handler);
+
+	pass = psci_invoke(1337, 0, 0, 0) == PSCI_RET_NOT_SUPPORTED || invalid_function_exception;
+
+	install_invalid_function_handler(NULL);
+	return pass;
 }
 
 static int psci_affinity_info(unsigned long target_affinity, uint32_t lowest_affinity_level)
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH kvm-unit-tests 1/2] arm/arm64: Add PSCI tests
  2017-02-27 17:32 ` [PATCH kvm-unit-tests 1/2] arm/arm64: Add " Andrew Jones
@ 2017-03-03 14:19   ` Radim Krčmář
  0 siblings, 0 replies; 4+ messages in thread
From: Radim Krčmář @ 2017-03-03 14:19 UTC (permalink / raw)
  To: Andrew Jones; +Cc: Levente Kurusa, kvmarm, kvm

2017-02-27 18:32+0100, Andrew Jones:
> From: Levente Kurusa <lkurusa@redhat.com>
> 
> The cpu_on test exposed two races in KVM's PSCI emulation.
> 
> Signed-off-by: Levente Kurusa <lkurusa@redhat.com>
> [Rewrote the cpu_on test to improve the chance of hitting the race.
>  Also added affinity-info tests and made some minor cleanups. -drew]
> Signed-off-by: Andrew Jones <drjones@redhat.com>
> ---
>  arm/Makefile.common |   1 +
>  arm/psci.c          | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++
>  arm/unittests.cfg   |   6 +++
>  3 files changed, 119 insertions(+)
>  create mode 100644 arm/psci.c
> 
> diff --git a/arm/Makefile.common b/arm/Makefile.common
> index f7193c3e6d64..74c7394eb7c1 100644
> --- a/arm/Makefile.common
> +++ b/arm/Makefile.common
> @@ -14,6 +14,7 @@ tests-common += $(TEST_DIR)/spinlock-test.flat
>  tests-common += $(TEST_DIR)/pci-test.flat
>  tests-common += $(TEST_DIR)/pmu.flat
>  tests-common += $(TEST_DIR)/gic.flat
> +tests-common += $(TEST_DIR)/psci.flat
>  
>  tests-all = $(tests-common) $(tests)
>  all: $(tests-all)
> diff --git a/arm/psci.c b/arm/psci.c
> new file mode 100644
> index 000000000000..e571afb92c7e
> --- /dev/null
> +++ b/arm/psci.c
> @@ -0,0 +1,112 @@
> +/*
> + * PSCI tests
> + *
> + * Copyright (C) 2017, Red Hat, Inc.
> + * Author: Levente Kurusa <lkurusa@redhat.com>
> + * Author: Andrew Jones <drjones@redhat.com>
> + *
> + * This work is licensed under the terms of the GNU LGPL, version 2.
> + */
> +#include <libcflat.h>
> +#include <asm/smp.h>
> +#include <asm/psci.h>
> +
> +static bool psci_invalid_function(void)
> +{
> +	return psci_invoke(1337, 0, 0, 0) == PSCI_RET_NOT_SUPPORTED;
> +}
> +
> +static int psci_affinity_info(unsigned long target_affinity, uint32_t lowest_affinity_level)
> +{
> +#ifdef __arm__
> +	return psci_invoke(PSCI_0_2_FN_AFFINITY_INFO, target_affinity, lowest_affinity_level, 0);
> +#else
> +	return psci_invoke(PSCI_0_2_FN64_AFFINITY_INFO, target_affinity, lowest_affinity_level, 0);
> +#endif
> +}
> +
> +static bool psci_affinity_info_on(void)
> +{
> +	return psci_affinity_info(cpus[0], 0) == PSCI_0_2_AFFINITY_LEVEL_ON;
> +}
> +
> +static bool psci_affinity_info_off(void)
> +{
> +	return psci_affinity_info(cpus[1], 0) == PSCI_0_2_AFFINITY_LEVEL_OFF;

Please check that smp > 1 here

> +}
> +
> +static int cpu_on_ret[NR_CPUS];
> +static cpumask_t cpu_on_ready, cpu_on_done;
> +static volatile int cpu_on_start;
> +
> +static void cpu_on_secondary_entry(void)
> +{
> +	int cpu = smp_processor_id();
> +
> +	cpumask_set_cpu(cpu, &cpu_on_ready);
> +	while (!cpu_on_start)
> +		cpu_relax();
> +	cpu_on_ret[cpu] = psci_cpu_on(cpus[1], __pa(halt));
> +	cpumask_set_cpu(cpu, &cpu_on_done);
> +	halt();
> +}
> +
> +static bool psci_cpu_on_test(void)
> +{
> +	bool failed = false;
> +	int cpu;

and here too.

Thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-03-03 14:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-02-27 17:32 [PATCH kvm-unit-tests 0/2] arm/arm64: introduce PSCI tests Andrew Jones
2017-02-27 17:32 ` [PATCH kvm-unit-tests 1/2] arm/arm64: Add " Andrew Jones
2017-03-03 14:19   ` Radim Krčmář
2017-02-27 17:32 ` [PATCH kvm-unit-tests 2/2] arm/arm64: psci: support testing tcg Andrew Jones

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.