Skip to contentSkip to conversation

powerpc: Test SPR persistency during migration

PATCH In review Thomas Huth 5 participants 9 messages Mar 22, 2017 – Mar 24, 2017 KVM

lore
Share & tools
lore
#0 lore raw

v4 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.

v4:
- Fix the error paths in run_migration() - use "exit 2" instead of "exit 1" to avoid trouble with the return code magic in the powerpc/run script and make sure to terminate the two QEMU instances in case of migration failure.

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   |  63 ++++++++++
 scripts/runtime.bash    |   3 +
 7 files changed, 380 insertions(+), 2 deletions(-)
 create mode 100644 powerpc/sprs.c
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH v4 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 script 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 script 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 | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++
 scripts/runtime.bash  |  3 +++
 3 files changed, 67 insertions(+), 1 deletion(-)
powerpc/run +1 -1
index 6269abb..d92608e 100755
@@ -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 +63 -0

66 lines not on this page · raw message

scripts/runtime.bash +3 -0
index 98f1835..e630279 100644
@@ -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
#3 lore raw

PATCH v4 2/2 powerpc: Add Special Purpose Register persistency test

In reply to Thomas Huth

This 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
index 1869f44..e536ffe 100644
@@ -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
index 2204e3b..ec673b3 100644
@@ -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
index 20dbde6..fb6b70e 100644
@@ -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
Reviewed-by on v4 1/2
#2 lore raw

Re: [kvm-unit-tests PATCH v4 1/2] Add the possibility to do simple migration tests

In reply to Thomas Huth
Quoted 39 lines · Thomas Huth

To be able to do simple migration tests with kvm-unit-tests, too, add a helper script 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 script 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 | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++
 scripts/runtime.bash  |  3 +++
 3 files changed, 67 insertions(+), 1 deletion(-)
powerpc/run +1 -1
index 6269abb..d92608e 100755
@@ -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 +1 -0
index 1610f3b..96bd5c4 100644
@@ -70,3 +70,66 @@ timeout_cmd ()
 		echo "timeout -k 1s --foreground $TIMEOUT"
 	fi
 }
+

scripts/arch-run.bash timeout_cmd () · line 83

Quoted 10 lines
scripts/arch-run.bash +10 -0
+qmp ()
+{
+	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)" >&2
+		exit 2

I would sort of still prefer $FUNCNAME over $0 here, but I don't feel that strongly about it. Nice catch on the 'exit 2'. 2 is indeed our designated error code for run-script failures.

Quoted 27 lines
scripts/arch-run.bash +27 -0
+	fi
+
+	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}
+

scripts/arch-run.bash timeout_cmd () · line 120

Quoted 10 lines
scripts/arch-run.bash +10 -0
+	# Wait for the migration to complete
+	migstatus=`qmp ${qmp1} '"query-migrate"' | grep return`
+	while ! grep -q '"completed"' <<<"$migstatus" ; do
+		sleep 1
+		migstatus=`qmp ${qmp1} '"query-migrate"' | grep return`
+		if grep -q '"failed"' <<<"$migstatus" ; then
+			echo "ERROR: Migration failed." >&2
+			qmp ${qmp1} '"quit"'> ${qmpout1} 2>/dev/null
+			qmp ${qmp2} '"quit"'> ${qmpout2} 2>/dev/null
+			exit 2

Also a nice improvement, ensuring the qemu processes quit.

Quoted 32 lines
scripts/arch-run.bash +15 -0
+		fi
+	done
+	qmp ${qmp1} '"quit"'> ${qmpout1} 2>/dev/null
+
+	qmp ${qmp2} '"inject-nmi"'> ${qmpout2}
+
+	wait
+}
+
+migration_cmd ()
+{
+	if [ "$MIGRATION" = "yes" ]; then
+		echo "run_migration"
+	fi
+}
scripts/runtime.bash +3 -0
index 98f1835..e630279 100644
@@ -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
#4 lore raw
In reply to Thomas Huth
Quoted 25 lines · Thomas Huth

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.

v4:
- Fix the error paths in run_migration() - use "exit 2" instead of "exit 1" to avoid trouble with the return code magic in the powerpc/run script and make sure to terminate the two QEMU instances in case of migration failure.

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

Quoted 10 lines
 powerpc/Makefile.common |   3 +-
 powerpc/cstart64.S      |   2 +
 powerpc/run             |   2 +-
 powerpc/sprs.c          | 304 ++++++++++++++++++++++++++++++++++++++++++++++++
 powerpc/unittests.cfg   |   5 +
 scripts/arch-run.bash   |  63 ++++++++++
 scripts/runtime.bash    |   3 +
 7 files changed, 380 insertions(+), 2 deletions(-)
 create mode 100644 powerpc/sprs.c

Really nice work.

I've tested with TCG and KVM HV and it works fine.

It hangs with KVM PR, but I have an "emulation at f60 failed (00000000)" in kernel logs, did you see that?

Laurent

#5 lore raw
Quoted 37 lines · Laurent Vivier
Quoted 25 lines · Thomas Huth

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.

v4:
- Fix the error paths in run_migration() - use "exit 2" instead of "exit 1" to avoid trouble with the return code magic in the powerpc/run script and make sure to terminate the two QEMU instances in case of migration failure.

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

Quoted 10 lines
 powerpc/Makefile.common |   3 +-
 powerpc/cstart64.S      |   2 +
 powerpc/run             |   2 +-
 powerpc/sprs.c          | 304 ++++++++++++++++++++++++++++++++++++++++++++++++
 powerpc/unittests.cfg   |   5 +
 scripts/arch-run.bash   |  63 ++++++++++
 scripts/runtime.bash    |   3 +
 7 files changed, 380 insertions(+), 2 deletions(-)
 create mode 100644 powerpc/sprs.c
Quoted 6 lines

Really nice work.

I've tested with TCG and KVM HV and it works fine.

It hangs with KVM PR, but I have an "emulation at f60 failed (00000000)" in kernel logs, did you see that?

Yes, it's because KVM-PR does not support some of the SPRs yet and apparently always injects a program exception in that case. So there is something left to do for KVM-PR here...

I think KVM-PR should not inject a program interrupt here, since according to the PowerISA (v2.07), the mtspr/mfspr should be treated as no-op for unknown SPRs when the CPU is not running in PRoblem state...

Thomas

#8 lore raw
In reply to Laurent Vivier
Quoted 37 lines · Laurent Vivier
Quoted 25 lines · Thomas Huth

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.

v4:
- Fix the error paths in run_migration() - use "exit 2" instead of "exit 1" to avoid trouble with the return code magic in the powerpc/run script and make sure to terminate the two QEMU instances in case of migration failure.

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

Quoted 10 lines
 powerpc/Makefile.common |   3 +-
 powerpc/cstart64.S      |   2 +
 powerpc/run             |   2 +-
 powerpc/sprs.c          | 304 ++++++++++++++++++++++++++++++++++++++++++++++++
 powerpc/unittests.cfg   |   5 +
 scripts/arch-run.bash   |  63 ++++++++++
 scripts/runtime.bash    |   3 +
 7 files changed, 380 insertions(+), 2 deletions(-)
 create mode 100644 powerpc/sprs.c
Quoted 1 line

Really nice work.

Yes.

I hope to have some time to hack a little your script to use a minimal image with a guest agent and do a ping to check that migration has succeeded. That would increase the scope of what is being migrated. Good for regression tests, specially when we are modifying the interrupt or mmu models.

Thanks,

C.

Quoted 7 lines

I've tested with TCG and KVM HV and it works fine.

It hangs with KVM PR, but I have an "emulation at f60 failed (00000000)" in kernel logs, did you see that?

Laurent

#6 lore raw
In reply to Thomas Huth
Quoted 45 lines · Thomas Huth
Quoted 37 lines · Laurent Vivier
Quoted 25 lines · Thomas Huth

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.

v4:
- Fix the error paths in run_migration() - use "exit 2" instead of "exit 1" to avoid trouble with the return code magic in the powerpc/run script and make sure to terminate the two QEMU instances in case of migration failure.

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

Quoted 10 lines
 powerpc/Makefile.common |   3 +-
 powerpc/cstart64.S      |   2 +
 powerpc/run             |   2 +-
 powerpc/sprs.c          | 304 ++++++++++++++++++++++++++++++++++++++++++++++++
 powerpc/unittests.cfg   |   5 +
 scripts/arch-run.bash   |  63 ++++++++++
 scripts/runtime.bash    |   3 +
 7 files changed, 380 insertions(+), 2 deletions(-)
 create mode 100644 powerpc/sprs.c
Quoted 6 lines

Really nice work.

I've tested with TCG and KVM HV and it works fine.

It hangs with KVM PR, but I have an "emulation at f60 failed (00000000)" in kernel logs, did you see that?

Quoted 7 lines

Yes, it's because KVM-PR does not support some of the SPRs yet and apparently always injects a program exception in that case. So there is something left to do for KVM-PR here...

I think KVM-PR should not inject a program interrupt here, since according to the PowerISA (v2.07), the mtspr/mfspr should be treated as no-op for unknown SPRs when the CPU is not running in PRoblem state...

I agree, let's fix it.

I did try to fix it some time ago, but at that stage Alex Graf didn't want to change the behaviour (I think because he thought the existing behaviour was better for debugging). However, we could have the architecturally correct behaviour but still have a way to log the unimplemented SPR accesses for debugging.

Paul.

#7 lore raw
Quoted 54 lines · Paul Mackerras
Quoted 45 lines · Thomas Huth
Quoted 37 lines · Laurent Vivier
Quoted 25 lines · Thomas Huth

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.

v4:
- Fix the error paths in run_migration() - use "exit 2" instead of "exit 1" to avoid trouble with the return code magic in the powerpc/run script and make sure to terminate the two QEMU instances in case of migration failure.

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

Quoted 10 lines
 powerpc/Makefile.common |   3 +-
 powerpc/cstart64.S      |   2 +
 powerpc/run             |   2 +-
 powerpc/sprs.c          | 304 ++++++++++++++++++++++++++++++++++++++++++++++++
 powerpc/unittests.cfg   |   5 +
 scripts/arch-run.bash   |  63 ++++++++++
 scripts/runtime.bash    |   3 +
 7 files changed, 380 insertions(+), 2 deletions(-)
 create mode 100644 powerpc/sprs.c
Quoted 6 lines

Really nice work.

I've tested with TCG and KVM HV and it works fine.

It hangs with KVM PR, but I have an "emulation at f60 failed (00000000)" in kernel logs, did you see that?

Quoted 7 lines

Yes, it's because KVM-PR does not support some of the SPRs yet and apparently always injects a program exception in that case. So there is something left to do for KVM-PR here...

I think KVM-PR should not inject a program interrupt here, since according to the PowerISA (v2.07), the mtspr/mfspr should be treated as no-op for unknown SPRs when the CPU is not running in PRoblem state...

Quoted 7 lines

I agree, let's fix it.

I did try to fix it some time ago, but at that stage Alex Graf didn't want to change the behaviour (I think because he thought the existing behaviour was better for debugging). However, we could have the architecturally correct behaviour but still have a way to log the unimplemented SPR accesses for debugging.

Right, it should be enough for debugging to have a way to log this. Could you dig out your patch, or shall I try to come up with a new one?

Thomas