Patchwork [kvm-unit-tests,v2,5/5] lib: arm: Fallback to psci_system_off() in exit()

login
register
mail settings
Submitter Alexandru Elisei
Date Feb. 1, 2019, 11:16 a.m.
Message ID <20190201111641.8299-6-alexandru.elisei@arm.com>
Download mbox | patch
Permalink /patch/715675/
State New
Headers show

Comments

Alexandru Elisei - Feb. 1, 2019, 11:16 a.m.
On arm and arm64, kvm-unit-tests uses the QEMU chr-testdev device to shut
down the virtual machine at the end of a test. The function
psci_system_off() provides another mechanism for terminating the virtual
machine.

chr-testdev is implemented on top of virtio console. If the virtual machine
manager doesn't emulate a virtio console, then chr_testdev_exit() will fail.
If this happens, try to use psci_system_off() to terminate the test.

This patch makes it possible for a virtual machine manager which doesn't
have support for chr-testdev, but has been configured not to emulate a
virtio console, to gracefully terminate a virtual machine after a test has
been completed.

There is one limitation to using psci_system_off() to terminate a test:
chr-testdev allows kvm-unit-tests to specify an exit code;
psci_system_off() has no such mechanism.

Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
---
 lib/arm/io.c | 2 ++
 1 file changed, 2 insertions(+)
Andrew Jones - Feb. 3, 2019, 5:23 p.m.
On Fri, Feb 01, 2019 at 11:16:41AM +0000, Alexandru Elisei wrote:
> On arm and arm64, kvm-unit-tests uses the QEMU chr-testdev device to shut
> down the virtual machine at the end of a test. The function
> psci_system_off() provides another mechanism for terminating the virtual
> machine.
> 
> chr-testdev is implemented on top of virtio console. If the virtual machine
> manager doesn't emulate a virtio console, then chr_testdev_exit() will fail.
> If this happens, try to use psci_system_off() to terminate the test.
> 
> This patch makes it possible for a virtual machine manager which doesn't
> have support for chr-testdev, but has been configured not to emulate a
> virtio console, to gracefully terminate a virtual machine after a test has
> been completed.
> 
> There is one limitation to using psci_system_off() to terminate a test:
> chr-testdev allows kvm-unit-tests to specify an exit code;
> psci_system_off() has no such mechanism.
> 
> Signed-off-by: Alexandru Elisei <alexandru.elisei@arm.com>
> ---
>  lib/arm/io.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/lib/arm/io.c b/lib/arm/io.c
> index 0d5ab9510ec8..bbb93e63fa3d 100644
> --- a/lib/arm/io.c
> +++ b/lib/arm/io.c
> @@ -12,6 +12,7 @@
>  #include <devicetree.h>
>  #include <chr-testdev.h>
>  #include <config.h>
> +#include <asm/psci.h>
>  #include <asm/spinlock.h>
>  #include <asm/io.h>
>  
> @@ -90,6 +91,7 @@ void puts(const char *s)
>  void exit(int code)
>  {
>  	chr_testdev_exit(code);
> +	psci_system_off();
>  	halt(code);
>  	__builtin_unreachable();
>  }
> -- 
> 2.17.0
>

Reviewed-by: Andrew Jones <drjones@redhat.com>

Patch

diff --git a/lib/arm/io.c b/lib/arm/io.c
index 0d5ab9510ec8..bbb93e63fa3d 100644
--- a/lib/arm/io.c
+++ b/lib/arm/io.c
@@ -12,6 +12,7 @@ 
 #include <devicetree.h>
 #include <chr-testdev.h>
 #include <config.h>
+#include <asm/psci.h>
 #include <asm/spinlock.h>
 #include <asm/io.h>
 
@@ -90,6 +91,7 @@  void puts(const char *s)
 void exit(int code)
 {
 	chr_testdev_exit(code);
+	psci_system_off();
 	halt(code);
 	__builtin_unreachable();
 }