powerpc: Test SPR persistency during migration
v3 cover powerpc: Test SPR persistency during migration
Here's a KVM-unit-test to check the persistency of SPRs during migration. First patch adds a helper script for doing migration tests in the kvm-unit-test framework, and the second patch contains the SPR tester.
v3:
- Migration shell script code has been moved to a helper function in arch-run.bash, so that this now also works with the standalone tests.
- Introduced the helper function migration_cmd there, too, so that other architectures can use this, too.
- Use "$@" instead of $* when calling QEMU.
v2:
- Addressed review feedback from v1
- Now using cpu_relax() instead of asm volatile ("nop")
Thomas Huth (2):
Add the possibility to do simple migration tests
powerpc: Add Special Purpose Register persistency test
powerpc/Makefile.common | 3 +- powerpc/cstart64.S | 2 + powerpc/run | 2 +- powerpc/sprs.c | 304 ++++++++++++++++++++++++++++++++++++++++++++++++ powerpc/unittests.cfg | 5 + scripts/arch-run.bash | 61 ++++++++++ scripts/runtime.bash | 3 + 7 files changed, 378 insertions(+), 2 deletions(-) create mode 100644 powerpc/sprs.c
Signature · 1 line
1.8.3.1
PATCH v3 1/2 Add the possibility to do simple migration tests
To be able to do simple migration tests with kvm-unit-tests, too, add a helper function that does all the necessary work: Start two instances of QEMU (source and destination) with QMP sockets for sending commands to them, then trigger the migration from one instance to the other and finally signal the end of the migration to the guest by injecting an NMI.
This helper function is now used automatically for powerpc tests if the test is put into the "migration" group in the unittests.cfg file.
--- powerpc/run | 2 +- scripts/arch-run.bash | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ scripts/runtime.bash | 3 +++ 3 files changed, 65 insertions(+), 1 deletion(-)
powerpc/run +1 -1
@@ -46,7 +46,7 @@ M+=",accel=$ACCEL" command="$qemu -nodefaults $M -bios $FIRMWARE" [ -f "$ENV" ] && command+=" -initrd $ENV" command+=" -display none -serial stdio -kernel" -command="$(timeout_cmd) $command" +command="$(migration_cmd) $(timeout_cmd) $command" echo $command "$@" # powerpc tests currently exit with rtas-poweroff, which exits with 0.
scripts/arch-run.bash +61 -0
64 lines not on this page · raw message
scripts/runtime.bash +3 -0
@@ -99,6 +99,9 @@ function run() } cmdline=$(get_cmdline $kernel) + if grep -qw "migration" <<<$groups ; then + cmdline="MIGRATION=yes $cmdline" + fi if [ "$verbose" = "yes" ]; then echo $cmdline fi
Signature · 1 line
1.8.3.1
PATCH v3 2/2 powerpc: Add Special Purpose Register persistency test
In reply to Thomas HuthThis test has two purposes: First, check whether the hypervisor can be destabilized by writing random values into the SPRs of the PowerPC CPU (this indeed revealed a bug last year, see CVE-2016-3044). Second, this test can be used to check whether the SPRs are synchronized properly between the KVM host CPU and QEMU, e.g. when migrating the VM from one QEMU instance to another.
The test first fills the various SPRs with some non-zero value, then reads the values back into a first array. It then either sleeps a short period of time (for testing without migration, in the hope that we're rescheduled on another host CPU), or it waits for a key or NMI (with the '-w' option) so that it is possible to migrate the VM before continuing. The test then finally reads the values from the SPRs back into another array and then compares them with the initial values.
Currently the test only supports the SPRs from the PowerISA v2.01 (PowerPC 970) and PowerISA v2.07 specification (i.e. POWER8 CPUs), but other versions should be pretty easy to add later.
--- powerpc/Makefile.common | 3 +- powerpc/cstart64.S | 2 + powerpc/sprs.c | 304 ++++++++++++++++++++++++++++++++++++++++++++++++ powerpc/unittests.cfg | 5 + 4 files changed, 313 insertions(+), 1 deletion(-) create mode 100644 powerpc/sprs.c
powerpc/Makefile.common +2 -1
@@ -9,7 +9,8 @@ tests-common = \ $(TEST_DIR)/spapr_hcall.elf \ $(TEST_DIR)/rtas.elf \ $(TEST_DIR)/emulator.elf \ - $(TEST_DIR)/tm.elf + $(TEST_DIR)/tm.elf \ + $(TEST_DIR)/sprs.elf tests-all = $(tests-common) $(tests) all: $(TEST_DIR)/boot_rom.bin $(tests-all)
powerpc/cstart64.S +2 -0
@@ -247,6 +247,8 @@ call_handler: .globl __start_interrupts __start_interrupts: +VECTOR(0x100) +VECTOR(0x200) VECTOR(0x300) VECTOR(0x400) VECTOR(0x500)
powerpc/sprs.c new file +304 -0
304 lines not on this page · raw message
powerpc/unittests.cfg +5 -0
@@ -59,3 +59,8 @@ file = tm.elf smp = 2,threads=2 extra_params = -append "h_cede_tm" groups = nodefault,h_cede_tm + +[sprs] +file = sprs.elf +extra_params = -append '-w' +groups = migration
Signature · 1 line
1.8.3.1
Re: [kvm-unit-tests PATCH v3 1/2] Add the possibility to do simple migration tests
In reply to Thomas HuthQuoted 35 lines · Thomas Huth
To be able to do simple migration tests with kvm-unit-tests, too, add a helper function that does all the necessary work: Start two instances of QEMU (source and destination) with QMP sockets for sending commands to them, then trigger the migration from one instance to the other and finally signal the end of the migration to the guest by injecting an NMI.
This helper function is now used automatically for powerpc tests if the test is put into the "migration" group in the unittests.cfg file.Signed-off-by Thomas Huth <[email protected]>--- powerpc/run | 2 +- scripts/arch-run.bash | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ scripts/runtime.bash | 3 +++ 3 files changed, 65 insertions(+), 1 deletion(-)powerpc/run +1
-1@@ -46,7 +46,7 @@ M+=",accel=$ACCEL" command="$qemu -nodefaults $M -bios $FIRMWARE" [ -f "$ENV" ] && command+=" -initrd $ENV" command+=" -display none -serial stdio -kernel" -command="$(timeout_cmd) $command" +command="$(migration_cmd) $(timeout_cmd) $command" echo $command "$@" # powerpc tests currently exit with rtas-poweroff, which exits with 0.scripts/arch-run.bash +0
-0
scripts/arch-run.bash timeout_cmd () · line 75
Quoted 6 lines
scripts/arch-run.bash +3
-0@@ -70,3 +70,64 @@ timeout_cmd () echo "timeout -k 1s --foreground $TIMEOUT" fi } + +qmp () +{
Let's put the nc probe here, and instead of saying $0 needs nc, we can say which specific function with $FUNCNAME, i.e.
command -v nc >/dev/null 2>&1 || (echo "$FUNCNAME needs nc (netcat)"; exit 1)
We could also cache the results of the probe, if we don't want to do it on every invocation of qmp()
scripts/arch-run.bash timeout_cmd () · line 84
Quoted 9 lines
scripts/arch-run.bash +9
-0+ echo '{ "execute": "qmp_capabilities" }{ "execute":' "$2" '}' | nc -U $1 +} + +run_migration () +{ + if ! command -v nc >/dev/null 2>&1; then + echo "$0 needs nc (netcat)" + exit 1 + fi
With the above change we can remove this.
Quoted 29 lines
scripts/arch-run.bash +29
-0+ + qemu=$1 + shift + + migsock=`mktemp -u -t mig-helper-socket.XXXXXXXXXX` + migout1=`mktemp -t mig-helper-stdout1.XXXXXXXXXX` + qmp1=`mktemp -u -t mig-helper-qmp1.XXXXXXXXXX` + qmp2=`mktemp -u -t mig-helper-qmp2.XXXXXXXXXX` + qmpout1=/dev/null + qmpout2=/dev/null + + trap 'rm -f ${migout1} ${migsock} ${qmp1} ${qmp2}' EXIT + + $qemu "$@" -chardev socket,id=mon1,path=${qmp1},server,nowait \ + -mon chardev=mon1,mode=control | tee ${migout1} & + + $qemu "$@" -chardev socket,id=mon2,path=${qmp2},server,nowait \ + -mon chardev=mon2,mode=control -incoming unix:${migsock} & + + # The test must prompt the user to migrate, so wait for the "migrate" keyword + while ! grep -q -i "migrate" < ${migout1} ; do + sleep 1 + done + + qmp ${qmp1} '"migrate", "arguments": { "uri": "unix:'${migsock}'" }' > ${qmpout1} + + # Wait for the migration to complete + migstatus=`qmp ${qmp1} '"query-migrate"' | grep return` + while ! grep -q '"completed"' <<<"$migstatus" ; do
scripts/arch-run.bash timeout_cmd () · line 123
Quoted 10 lines
scripts/arch-run.bash +10
-0+ sleep 1 + migstatus=`qmp ${qmp1} '"query-migrate"' | grep return` + if grep -q '"failed"' <<<"$migstatus" ; then + echo "ERROR: Migration failed." + exit 1 + fi + done + qmp ${qmp1} '"quit"'> ${qmpout1} 2>/dev/null + + qmp ${qmp2} '"inject-nmi"'> ${qmpout2}
This script mostly works for ARM, except this part. The ARM processor types we currently care about in kvm-unit-tests are ARMv7 and ARMv8. While ARMv7 processors may support non-maskable FIQs, ARMv8 processors can not. So, I don't believe it will ever make sense to implement inject-nmi for ARMv8 processors, and thus when we want this to work with ARM unit tests we'll need a different way to inform the unit test that migration has completed.
That said, I'm OK with the patch going in now, as it works for both ppc and x86.
Thanks,
drew
Quoted 27 lines
scripts/arch-run.bash +10
-0+ + wait +} + +migration_cmd () +{ + if [ "$MIGRATION" = "yes" ]; then + echo "run_migration" + fi +}scripts/runtime.bash +3
-0@@ -99,6 +99,9 @@ function run() } cmdline=$(get_cmdline $kernel) + if grep -qw "migration" <<<$groups ; then + cmdline="MIGRATION=yes $cmdline" + fi if [ "$verbose" = "yes" ]; then echo $cmdline fiSignature · 1 line
1.8.3.1
Re: [kvm-unit-tests PATCH v3 1/2] Add the possibility to do simple migration tests
Quoted 46 lines · Andrew Jones
Quoted 35 lines · Thomas Huth
To be able to do simple migration tests with kvm-unit-tests, too, add a helper function that does all the necessary work: Start two instances of QEMU (source and destination) with QMP sockets for sending commands to them, then trigger the migration from one instance to the other and finally signal the end of the migration to the guest by injecting an NMI.
This helper function is now used automatically for powerpc tests if the test is put into the "migration" group in the unittests.cfg file.Signed-off-by Thomas Huth <[email protected]>--- powerpc/run | 2 +- scripts/arch-run.bash | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++ scripts/runtime.bash | 3 +++ 3 files changed, 65 insertions(+), 1 deletion(-)powerpc/run +1
-1@@ -46,7 +46,7 @@ M+=",accel=$ACCEL" command="$qemu -nodefaults $M -bios $FIRMWARE" [ -f "$ENV" ] && command+=" -initrd $ENV" command+=" -display none -serial stdio -kernel" -command="$(timeout_cmd) $command" +command="$(migration_cmd) $(timeout_cmd) $command" echo $command "$@" # powerpc tests currently exit with rtas-poweroff, which exits with 0.scripts/arch-run.bash +0
-0scripts/arch-run.bash timeout_cmd () · line 75
Quoted 6 lines
scripts/arch-run.bash +3
-0@@ -70,3 +70,64 @@ timeout_cmd () echo "timeout -k 1s --foreground $TIMEOUT" fi } + +qmp () +{Let's put the nc probe here, and instead of saying $0 needs nc, we can say which specific function with $FUNCNAME, i.e.
Quoted 4 lines
command -v nc >/dev/null 2>&1 || (echo "$FUNCNAME needs nc (netcat)"; exit 1)
We could also cache the results of the probe, if we don't want to do it on every invocation of
qmp()
I tried to move the check to the qmp() function, as you suggested, but that does not work as expected: The script then does not terminate anymore! Seems like the shell is waiting for the started QEMU processes to finish first, so I'd have to add some ugly error handling magic in that case to kill the background QEMU processes if nc is not available. I think it is easier if I keep the check at the beginning of run_migration() instead.
Quoted 8 lines
scripts/arch-run.bash timeout_cmd () · line 83
Quoted 8 lines
scripts/arch-run.bash +8
-0+ echo '{ "execute": "qmp_capabilities" }{ "execute":' "$2" '}' | nc -U $1 +} + +run_migration () +{ + if ! command -v nc >/dev/null 2>&1; then + echo "$0 needs nc (netcat)" + exit 1
I noticed that I should rather exit with "2" instead of "1" here ... otherwise run_tests.sh does not report a FAIL here. I'll send a new version with the fix...
Quoted 1 line
scripts/arch-run.bash timeout_cmd () · line 84
Quoted 1 line
scripts/arch-run.bash +1
-0+ fi
Thomas