Skip to contentSkip to conversation

scripts/runtime: Add ability to mark test as don't run by default

PATCH Applied Suraj Jitindar Singh 4 participants 9 messages Aug 19, 2016 – Aug 27, 2016 KVM

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/5 scripts/runtime: Add ability to mark test as don't run by default

Invoking run_tests.sh without the -g parameter will by default run all of the tests for a given architecture. This patch series will add a test which has the ability to bring down the host and thus it might be nice if we double check that the user actually wants to run that test instead of them unknowingly bringing down a machine they might not want to.

In order to do this add the option for a tests' group parameter in unittests.cfg to include "nodefault" on order to indicate that it shouldn't be run be default.

When tests are invoked via run_tests.sh those with the nodefault group parameter will be skipped unless explicitly specified by the "-g" command line option. When tests with the nodefault group parameter are built and run standalone the user will be prompted on invocation to confirm that they actually want to run the test.

This allows a developer to mark a test as having potentially adverse effects and thus requires an extra level of confirmation from the user before they are invoked. Existing functionality will be preserved and new tests can choose any group other than "nodefault" if they want to be run by default.

---

Change Log:

V2 -> V3:
- Move checking on standalone invokation into a function "skip_nodefault" in scripts/runtime.bash
V3 -> V4:
- Remove superfluous "STANDALONE=yes"
V4 -> V5:
- Cosmetic changes

---
 arm/unittests.cfg     |  3 +++
 powerpc/unittests.cfg |  3 +++
 scripts/runtime.bash  | 25 ++++++++++++++++++++++++-
 x86/unittests.cfg     |  3 +++
 4 files changed, 33 insertions(+), 1 deletion(-)
arm/unittests.cfg +3 -0
index ffd12e5..3f6fa45 100644
@@ -12,6 +12,9 @@
 #					# specific to only one.
 # groups = <group_name1> <group_name2> ...	# Used to identify test cases
 #						# with run_tests -g ...
+#						# Specify group_name=nodefault
+#						# to have test not run by
+#						# default
 # accel = kvm|tcg		# Optionally specify if test must run with
 #				# kvm or tcg. If not specified, then kvm will
 #				# be used when available.
powerpc/unittests.cfg +3 -0
index ed4fdbe..0098cb6 100644
@@ -12,6 +12,9 @@
 #					# specific to only one.
 # groups = <group_name1> <group_name2> ...	# Used to identify test cases
 #						# with run_tests -g ...
+#						# Specify group_name=nodefault
+#						# to have test not run by
+#						# default
 # accel = kvm|tcg		# Optionally specify if test must run with
 #				# kvm or tcg. If not specified, then kvm will
 #				# be used when available.
scripts/runtime.bash +24 -1
index 0503cf0..1bd87bc 100644
@@ -32,6 +32,23 @@ get_cmdline()
     echo "TESTNAME=$testname TIMEOUT=$timeout ACCEL=$accel $RUNTIME_arch_run $kernel -smp $smp $opts"
 }
 
+skip_nodefault()
+{
+    [ "$STANDALONE" != "yes" ] && return 0
+
+    while true; do
+        read -p "Test marked not to be run by default, are you sure (y/N)? " yn
+        case $yn in
+            "Y" | "y" | "Yes" | "yes")
+                return 1
+                ;;
+            "" | "N" | "n" | "No" | "no" | "q" | "quit" | "exit")
+                return 0
+                ;;
+        esac
+    done
+}
+
 function run()
 {
     local testname="$1"
@@ -48,10 +65,16 @@ function run()
         return
     fi
 
-    if [ -n "$only_group" ] && ! grep -q "$only_group" <<<$groups; then
+    if [ -n "$only_group" ] && ! grep -qw "$only_group" <<<$groups; then
         return
     fi
 
+    if [ -z "$only_group" ] && grep -qw "nodefault" <<<$groups &&
+            skip_nodefault; then
+        echo -e "`SKIP` $testname (test marked as manual run only)"
+        return;
+    fi
+
     if [ -n "$arch" ] && [ "$arch" != "$ARCH" ]; then
         echo "`SKIP` $1 ($arch only)"
         return 2
x86/unittests.cfg +3 -0
index 60747cf..4a1f74e 100644
@@ -12,6 +12,9 @@
 #					# specific to only one.
 # groups = <group_name1> <group_name2> ...	# Used to identify test cases
 #						# with run_tests -g ...
+#						# Specify group_name=nodefault
+#						# to have test not run by
+#						# default
 # accel = kvm|tcg		# Optionally specify if test must run with
 #				# kvm or tcg. If not specified, then kvm will
 #				# be used when available.
Signature · 1 line
2.5.5
#1 lore raw

PATCH v5 2/5 lib/powerpc: Add generic decrementer exception handler

Add the lib/powerpc/handlers.c file and associated header files as a place to implement generic exception handler functions for inclusion in tests.

Add a generic exception handler for a decrementer (0x900) interrupt which will reset the decrementer to its maximum value.

---

Change Log:

V2 -> V3:
- Whitespace changes

---
 lib/powerpc/asm/handlers.h |  8 ++++++++
 lib/powerpc/handlers.c     | 22 ++++++++++++++++++++++
 lib/ppc64/asm/handlers.h   |  1 +
 powerpc/Makefile.common    |  1 +
 4 files changed, 32 insertions(+)
 create mode 100644 lib/powerpc/asm/handlers.h
 create mode 100644 lib/powerpc/handlers.c
 create mode 100644 lib/ppc64/asm/handlers.h
lib/powerpc/asm/handlers.h new file +8 -0
new file mode 100644
index 0000000..64ba727
@@ -0,0 +1,8 @@
+#ifndef _ASMPOWERPC_HANDLERS_H_
+#define _ASMPOWERPC_HANDLERS_H_
+
+#include <asm/ptrace.h>
+
+void dec_except_handler(struct pt_regs *regs, void *data);
+
+#endif /* _ASMPOWERPC_HANDLERS_H_ */
lib/powerpc/handlers.c new file +22 -0
new file mode 100644
index 0000000..be8226a
@@ -0,0 +1,22 @@
+/*
+ * Generic exception handlers for registration and use in tests
+ *
+ * Copyright 2016 Suraj Jitindar Singh, IBM.
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.
+ */
+
+#include <libcflat.h>
+#include <asm/handlers.h>
+#include <asm/ptrace.h>
+
+/*
+ * Generic handler for decrementer exceptions (0x900)
+ * Just reset the decrementer back to its maximum value (0x7FFFFFFF)
+ */
+void dec_except_handler(struct pt_regs *regs __unused, void *data __unused)
+{
+	uint32_t dec = 0x7FFFFFFF;
+
+	asm volatile ("mtdec %0" : : "r" (dec));
+}
lib/ppc64/asm/handlers.h new file +1 -0
new file mode 100644
index 0000000..92e6fb2
@@ -0,0 +1 @@
+#include "../../powerpc/asm/handlers.h"
powerpc/Makefile.common +1 -0
index 3f8887d..404194b 100644
@@ -36,6 +36,7 @@ cflatobjs += lib/powerpc/hcall.o
 cflatobjs += lib/powerpc/setup.o
 cflatobjs += lib/powerpc/rtas.o
 cflatobjs += lib/powerpc/processor.o
+cflatobjs += lib/powerpc/handlers.o
 
 FLATLIBS = $(libcflat) $(LIBFDT_archive)
 %.elf: CFLAGS += $(arch_CFLAGS)
Signature · 1 line
2.5.5
#2 lore raw

PATCH v5 3/5 lib/powerpc: Add function to start secondary threads

In reply to Suraj Jitindar Singh

Add the lib/powerpc/smp.c file and associated header files as a place to implement generic smp functionality for inclusion in tests.

Add functions start_all_cpus(), start_cpu() and start_thread() to start all stopped threads of all cpus, all stopped threads of a single cpu or a single stopped thread of a guest at a given execution location, respectively.

---

Change Log:

V2 -> V3:
- start_thread now returns int to reflect error, success or failure to start thread
- start_cpu returns number of threads on cpu and number successfully started
- start_all_cpus checks if number of threads started = total number of threads - 1
V3 -> V4:
- Style changes
V4 -> V5:
- Cosmetic changes

---
 lib/powerpc/asm/smp.h   |  22 +++++++++++
 lib/powerpc/smp.c       | 103 ++++++++++++++++++++++++++++++++++++++++++++++++
 lib/ppc64/asm/smp.h     |   1 +
 powerpc/Makefile.common |   1 +
 4 files changed, 127 insertions(+)
 create mode 100644 lib/powerpc/asm/smp.h
 create mode 100644 lib/powerpc/smp.c
 create mode 100644 lib/ppc64/asm/smp.h
lib/powerpc/asm/smp.h new file +22 -0
new file mode 100644
index 0000000..21940b4
@@ -0,0 +1,22 @@
+#ifndef _ASMPOWERPC_SMP_H_
+#define _ASMPOWERPC_SMP_H_
+
+#include <libcflat.h>
+
+extern int nr_threads;
+
+struct start_threads {
+	int nr_threads;
+	int nr_started;
+};
+
+typedef void (*secondary_entry_fn)(void);
+
+extern void halt(void);
+
+extern int start_thread(int cpu_id, secondary_entry_fn entry, uint32_t r3);
+extern struct start_threads start_cpu(int cpu_node, secondary_entry_fn entry,
+				      uint32_t r3);
+extern bool start_all_cpus(secondary_entry_fn entry, uint32_t r3);
+
+#endif /* _ASMPOWERPC_SMP_H_ */
lib/powerpc/smp.c new file +103 -0

103 lines not on this page · raw message

lib/ppc64/asm/smp.h new file +1 -0
new file mode 100644
index 0000000..67ced75
@@ -0,0 +1 @@
+#include "../../powerpc/asm/smp.h"
powerpc/Makefile.common +1 -0
index 404194b..677030a 100644
@@ -37,6 +37,7 @@ cflatobjs += lib/powerpc/setup.o
 cflatobjs += lib/powerpc/rtas.o
 cflatobjs += lib/powerpc/processor.o
 cflatobjs += lib/powerpc/handlers.o
+cflatobjs += lib/powerpc/smp.o
 
 FLATLIBS = $(libcflat) $(LIBFDT_archive)
 %.elf: CFLAGS += $(arch_CFLAGS)
Signature · 1 line
2.5.5
#3 lore raw

PATCH v5 4/5 lib/powerpc: Implement generic delay function for use in unit tests

In reply to Suraj Jitindar Singh

It would be nice if we had a generic delay function which could be used in unit tests, add one.

Add the variable tb_hz used to store the time base frequency which is read from the device tree on setup.

Add functions mdelay, udelay and delay in processor.c to delay for a given number of milliseconds, microseconds and time base ticks respectively.

---

Change Log:

V2 -> V3:
- Add patch to series
V3 -> V4:
- Reword sleep->delay
- Move cpu_relax to asm-generic/barrier.h
- Add assert to catch when delay fns called with too large values
V4 -> V5:
- Remove unnecessary assert statements

---
 lib/asm-generic/barrier.h   |  4 ++++
 lib/powerpc/asm/processor.h | 19 +++++++++++++++++++
 lib/powerpc/asm/setup.h     |  2 ++
 lib/powerpc/processor.c     | 15 +++++++++++++++
 lib/powerpc/setup.c         |  9 +++++++++
 5 files changed, 49 insertions(+)
lib/asm-generic/barrier.h +4 -0
index 12ae782..6a990ff 100644
@@ -28,4 +28,8 @@
 #define smp_wmb()	wmb()
 #endif
 
+#ifndef cpu_relax
+#define cpu_relax()	asm volatile ("":::"memory")
+#endif
+
 #endif /* _ASM_BARRIER_H_ */
lib/powerpc/asm/processor.h +19 -0
index 09692bd..ac001e1 100644
@@ -1,6 +1,7 @@
 #ifndef _ASMPOWERPC_PROCESSOR_H_
 #define _ASMPOWERPC_PROCESSOR_H_
 
+#include <libcflat.h>
 #include <asm/ptrace.h>
 
 #ifndef __ASSEMBLY__
@@ -8,4 +9,22 @@ void handle_exception(int trap, void (*func)(struct pt_regs *, void *), void *);
 void do_handle_exception(struct pt_regs *regs);
 #endif /* __ASSEMBLY__ */
 
+static inline uint64_t get_tb(void)
+{
+	uint64_t tb;
+
+	asm volatile ("mfspr %[tb],268" : [tb] "=r" (tb));
+
+	return tb;
+}
+
+extern void delay(uint64_t cycles);
+extern void udelay(uint64_t us);
+
+static inline void mdelay(uint64_t ms)
+{
+	while (ms--)
+		udelay(1000);
+}
+
 #endif /* _ASMPOWERPC_PROCESSOR_H_ */
lib/powerpc/asm/setup.h +2 -0
index b1e1e5a..23b4156 100644
@@ -11,6 +11,8 @@
 extern u32 cpus[NR_CPUS];
 extern int nr_cpus;
 
+extern uint64_t tb_hz;
+
 #define NR_MEM_REGIONS		8
 #define MR_F_PRIMARY		(1U << 0)
 struct mem_region {
lib/powerpc/processor.c +15 -0
index a78bc3c..056a61f 100644
@@ -5,6 +5,8 @@
 #include <libcflat.h>
 #include <asm/processor.h>
 #include <asm/ptrace.h>
+#include <asm/setup.h>
+#include <asm/barrier.h>
 
 static struct {
 	void (*func)(struct pt_regs *, void *data);
@@ -36,3 +38,16 @@ void do_handle_exception(struct pt_regs *regs)
 	printf("unhandled cpu exception 0x%lx\n", regs->trap);
 	abort();
 }
+
+void delay(uint64_t cycles)
+{
+	uint64_t start = get_tb();
+
+	while ((get_tb() - start) < cycles)
+		cpu_relax();
+}
+
+void udelay(uint64_t us)
+{
+	delay((us * tb_hz) / 1000000);
+}
lib/powerpc/setup.c +9 -0
index e3d2afa..9153f7b 100644
@@ -24,6 +24,7 @@ extern void setup_args_progname(const char *args);
 
 u32 cpus[NR_CPUS] = { [0 ... NR_CPUS-1] = (~0U) };
 int nr_cpus;
+uint64_t tb_hz;
 
 struct mem_region mem_regions[NR_MEM_REGIONS];
 phys_addr_t __physical_start, __physical_end;
@@ -32,6 +33,7 @@ unsigned __icache_bytes, __dcache_bytes;
 struct cpu_set_params {
 	unsigned icache_bytes;
 	unsigned dcache_bytes;
+	uint64_t tb_hz;
 };
 
 #define EXCEPTION_STACK_SIZE	(32*1024) /* 32kB */
@@ -72,6 +74,12 @@ static void cpu_set(int fdtnode, u32 regval, void *info)
 		data = (u32 *)prop->data;
 		params->dcache_bytes = fdt32_to_cpu(*data);
 
+		prop = fdt_get_property(dt_fdt(), fdtnode,
+					"timebase-frequency", NULL);
+		assert(prop != NULL);
+		data = (u32 *)prop->data;
+		params->tb_hz = fdt32_to_cpu(*data);
+
 		read_common_info = true;
 	}
 }
@@ -86,6 +94,7 @@ static void cpu_init(void)
 	assert(ret = 0);
 	__icache_bytes = params.icache_bytes;
 	__dcache_bytes = params.dcache_bytes;
+	tb_hz = params.tb_hz;
 
 	/* Interrupt Endianness */
 
Signature · 1 line
2.5.5
#4 lore raw

PATCH v5 5/5 powerpc/tm: Add a test for H_CEDE while tm suspended

In reply to Suraj Jitindar Singh

On Power machines if a guest cedes while a tm transaction is in the suspended state then the checkpointed state of the vcpu may be lost and we lose the cpu in the host.

Add a file for tm tests "powerpc/tm.c" and add a test to check if the fix has been applied to the host kernel. If this fix hasn't been applied then the test will never complete and the cpu will be lost. Otherwise the test should succeed. Since this has the ability to mess things up in the host mark this test as don't run by default.

This vulnerability has been assigned the ID CVE-2016-5412.

Based on initial work done by: Cyril Bur <[email protected]>

---

Change Log:

V2 -> V3:
- Remove get_dec() and sleep() functions as sleep functionality is now provided by a generic implementation in processor.c.
- Replace TM instructions with raw machine code to support older compilers
V3 -> V4:
- Style Changes

---
 lib/powerpc/asm/hcall.h |   1 +
 powerpc/Makefile.common |   3 +-
 powerpc/tm.c            | 120 ++++++++++++++++++++++++++++++++++++++++++++++++
 powerpc/unittests.cfg   |   6 +++
 4 files changed, 129 insertions(+), 1 deletion(-)
 create mode 100644 powerpc/tm.c
lib/powerpc/asm/hcall.h +1 -0
index 99bce79..80aa3e3 100644
@@ -18,6 +18,7 @@
 #define H_SET_SPRG0		0x24
 #define H_SET_DABR		0x28
 #define H_PAGE_INIT		0x2c
+#define H_CEDE			0xE0
 #define H_PUT_TERM_CHAR		0x58
 #define H_RANDOM		0x300
 #define H_SET_MODE		0x31C
powerpc/Makefile.common +2 -1
index 677030a..93e4f66 100644
@@ -8,7 +8,8 @@ tests-common = \
 	$(TEST_DIR)/selftest.elf \
 	$(TEST_DIR)/spapr_hcall.elf \
 	$(TEST_DIR)/rtas.elf \
-	$(TEST_DIR)/emulator.elf
+	$(TEST_DIR)/emulator.elf \
+	$(TEST_DIR)/tm.elf
 
 all: $(TEST_DIR)/boot_rom.bin test_cases
 
powerpc/tm.c new file +120 -0

120 lines not on this page · raw message

powerpc/unittests.cfg +6 -0
index 0098cb6..20dbde6 100644
@@ -53,3 +53,9 @@ groups = rtas
 
 [emulator]
 file = emulator.elf
+
+[h_cede_tm]
+file = tm.elf
+smp = 2,threads=2
+extra_params = -append "h_cede_tm"
+groups = nodefault,h_cede_tm
Signature · 1 line
2.5.5
#6 lore raw
In reply to Suraj Jitindar Singh
Quoted 22 lines · Suraj Jitindar Singh

Invoking run_tests.sh without the -g parameter will by default run all of the tests for a given architecture. This patch series will add a test which has the ability to bring down the host and thus it might be nice if we double check that the user actually wants to run that test instead of them unknowingly bringing down a machine they might not want to.

In order to do this add the option for a tests' group parameter in unittests.cfg to include "nodefault" on order to indicate that it shouldn't be run be default.

When tests are invoked via run_tests.sh those with the nodefault group parameter will be skipped unless explicitly specified by the "-g" command line option. When tests with the nodefault group parameter are built and run standalone the user will be prompted on invocation to confirm that they actually want to run the test.

This allows a developer to mark a test as having potentially adverse effects and thus requires an extra level of confirmation from the user before they are invoked. Existing functionality will be preserved and new tests can choose any group other than "nodefault" if they want to be run by default.

Quoted 3 lines

Thanks for the cosmetic refresh. My r-b is already on all patches, so the series is good to go for me.

drew

#7 lore raw
Quoted 23 lines · Andrew Jones
Quoted 22 lines · Suraj Jitindar Singh

Invoking run_tests.sh without the -g parameter will by default run all of the tests for a given architecture. This patch series will add a test which has the ability to bring down the host and thus it might be nice if we double check that the user actually wants to run that test instead of them unknowingly bringing down a machine they might not want to.

In order to do this add the option for a tests' group parameter in unittests.cfg to include "nodefault" on order to indicate that it shouldn't be run be default.

When tests are invoked via run_tests.sh those with the nodefault group parameter will be skipped unless explicitly specified by the "-g" command line option. When tests with the nodefault group parameter are built and run standalone the user will be prompted on invocation to confirm that they actually want to run the test.

This allows a developer to mark a test as having potentially adverse effects and thus requires an extra level of confirmation from the user before they are invoked. Existing functionality will be preserved and new tests can choose any group other than "nodefault" if they want to be run by default.

Quoted 6 lines
Quoted 3 lines

Thanks for the cosmetic refresh. My r-b is already on all patches, so the series is good to go for me.

Right, series also looks fine to me, too. Radim, Paolo, could you pick up the patches directly, or do you want me to queue them and send a pull request?

Thomas

#8 lore raw

2016-08-23 00:23+0200, Thomas Huth:

Quoted 8 lines · Andrew Jones
Quoted 3 lines · Suraj Jitindar Singh

Thanks for the cosmetic refresh. My r-b is already on all patches, so the series is good to go for me.

Right, series also looks fine to me, too. Radim, Paolo, could you pick up the patches directly, or do you want me to queue them and send a pull request?

Applied, thanks.

#5 lore raw

Re: [kvm-unit-tests PATCH V5 5/5] powerpc/tm: Add a test for H_CEDE while tm suspended

In reply to Suraj Jitindar Singh

2016-08-19 11:10+1000, Suraj Jitindar Singh:

powerpc/unittests.cfg groups = rtas · line 57

Quoted 7 lines
powerpc/unittests.cfg +5 -0
@@ -53,3 +53,9 @@ groups = rtas
+[h_cede_tm]
+file = tm.elf
+smp = 2,threads=2
+extra_params = -append "h_cede_tm"
+groups = nodefault,h_cede_tm

We have a bug in scripts/mkstandalone.sh that doesn't allow a space as a separator for groups: we overwrite args[3], but a space in groups shifts the position of the args[] we want to overwrite.

It causes no problems now, so I've added it to my after-vacation queue.