diff mbox series

[kvm-unit-tests,v3,2/2] s390x: add migration TOD clock test

Message ID 20221011170024.972135-3-nrb@linux.ibm.com (mailing list archive)
State Mainlined
Headers show
Series s390x: Add migration test for guest TOD clock | expand

Commit Message

Nico Boehr Oct. 11, 2022, 5 p.m. UTC
On migration, we expect the guest clock value to be preserved. Add a
test to verify this:
- advance the guest TOD by much more than we need to migrate
- migrate the guest
- get the guest TOD

After migration, assert the guest TOD value is at least the value we set
before migration. This is the minimal check for architectural
compliance; implementations may decide to do something more
sophisticated.

Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 s390x/Makefile        |  1 +
 s390x/migration-sck.c | 54 +++++++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg   |  4 ++++
 3 files changed, 59 insertions(+)
 create mode 100644 s390x/migration-sck.c

Comments

Claudio Imbrenda Oct. 11, 2022, 5:07 p.m. UTC | #1
On Tue, 11 Oct 2022 19:00:24 +0200
Nico Boehr <nrb@linux.ibm.com> wrote:

> On migration, we expect the guest clock value to be preserved. Add a
> test to verify this:
> - advance the guest TOD by much more than we need to migrate
> - migrate the guest
> - get the guest TOD
> 
> After migration, assert the guest TOD value is at least the value we set
> before migration. This is the minimal check for architectural
> compliance; implementations may decide to do something more
> sophisticated.
> 
> Signed-off-by: Nico Boehr <nrb@linux.ibm.com>

Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>

> ---
>  s390x/Makefile        |  1 +
>  s390x/migration-sck.c | 54 +++++++++++++++++++++++++++++++++++++++++++
>  s390x/unittests.cfg   |  4 ++++
>  3 files changed, 59 insertions(+)
>  create mode 100644 s390x/migration-sck.c
> 
> diff --git a/s390x/Makefile b/s390x/Makefile
> index 649486f2d4a0..fba09bc2df3a 100644
> --- a/s390x/Makefile
> +++ b/s390x/Makefile
> @@ -36,6 +36,7 @@ tests += $(TEST_DIR)/migration-cmm.elf
>  tests += $(TEST_DIR)/migration-skey.elf
>  tests += $(TEST_DIR)/panic-loop-extint.elf
>  tests += $(TEST_DIR)/panic-loop-pgm.elf
> +tests += $(TEST_DIR)/migration-sck.elf
>  
>  pv-tests += $(TEST_DIR)/pv-diags.elf
>  
> diff --git a/s390x/migration-sck.c b/s390x/migration-sck.c
> new file mode 100644
> index 000000000000..2d9a195ab4c4
> --- /dev/null
> +++ b/s390x/migration-sck.c
> @@ -0,0 +1,54 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/*
> + * SET CLOCK migration tests
> + *
> + * Copyright IBM Corp. 2022
> + *
> + * Authors:
> + *  Nico Boehr <nrb@linux.ibm.com>
> + */
> +
> +#include <libcflat.h>
> +#include <asm/time.h>
> +
> +static void test_sck_migration(void)
> +{
> +	uint64_t now_before_set = 0, now_after_set = 0, now_after_migration, time_to_set, time_to_advance;
> +	int cc;
> +
> +	stckf(&now_before_set);
> +
> +	/* Advance the clock by a lot more than we might ever need to migrate (600s) */
> +	time_to_advance = (600ULL * 1000000) << STCK_SHIFT_US;
> +	time_to_set = now_before_set + time_to_advance;
> +
> +	cc = sck(&time_to_set);
> +	report(!cc, "setting clock succeeded");
> +
> +	/* Check the clock is running after being set */
> +	cc = stckf(&now_after_set);
> +	report(!cc, "clock running after set");
> +	report(now_after_set >= time_to_set, "TOD clock value is larger than what has been set");
> +
> +	puts("Please migrate me, then press return\n");
> +	(void)getchar();
> +
> +	cc = stckf(&now_after_migration);
> +	report(!cc, "clock still set");
> +
> +	/*
> +	 * The architectural requirement for the TOD clock is that it doesn't move backwards after
> +	 * migration. Implementations can just migrate the guest TOD value or do something more
> +	 * sophisticated (e.g. slowly adjust to the host TOD).
> +	 */
> +	report(now_after_migration >= time_to_set, "TOD clock value did not jump backwards");
> +}
> +
> +int main(void)
> +{
> +	report_prefix_push("migration-sck");
> +
> +	test_sck_migration();
> +	report_prefix_pop();
> +	return report_summary();
> +}
> diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg
> index f9f102abfa89..2c04ae7c7c15 100644
> --- a/s390x/unittests.cfg
> +++ b/s390x/unittests.cfg
> @@ -197,3 +197,7 @@ file = panic-loop-pgm.elf
>  groups = panic
>  accel = kvm
>  timeout = 5
> +
> +[migration-sck]
> +file = migration-sck.elf
> +groups = migration
diff mbox series

Patch

diff --git a/s390x/Makefile b/s390x/Makefile
index 649486f2d4a0..fba09bc2df3a 100644
--- a/s390x/Makefile
+++ b/s390x/Makefile
@@ -36,6 +36,7 @@  tests += $(TEST_DIR)/migration-cmm.elf
 tests += $(TEST_DIR)/migration-skey.elf
 tests += $(TEST_DIR)/panic-loop-extint.elf
 tests += $(TEST_DIR)/panic-loop-pgm.elf
+tests += $(TEST_DIR)/migration-sck.elf
 
 pv-tests += $(TEST_DIR)/pv-diags.elf
 
diff --git a/s390x/migration-sck.c b/s390x/migration-sck.c
new file mode 100644
index 000000000000..2d9a195ab4c4
--- /dev/null
+++ b/s390x/migration-sck.c
@@ -0,0 +1,54 @@ 
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * SET CLOCK migration tests
+ *
+ * Copyright IBM Corp. 2022
+ *
+ * Authors:
+ *  Nico Boehr <nrb@linux.ibm.com>
+ */
+
+#include <libcflat.h>
+#include <asm/time.h>
+
+static void test_sck_migration(void)
+{
+	uint64_t now_before_set = 0, now_after_set = 0, now_after_migration, time_to_set, time_to_advance;
+	int cc;
+
+	stckf(&now_before_set);
+
+	/* Advance the clock by a lot more than we might ever need to migrate (600s) */
+	time_to_advance = (600ULL * 1000000) << STCK_SHIFT_US;
+	time_to_set = now_before_set + time_to_advance;
+
+	cc = sck(&time_to_set);
+	report(!cc, "setting clock succeeded");
+
+	/* Check the clock is running after being set */
+	cc = stckf(&now_after_set);
+	report(!cc, "clock running after set");
+	report(now_after_set >= time_to_set, "TOD clock value is larger than what has been set");
+
+	puts("Please migrate me, then press return\n");
+	(void)getchar();
+
+	cc = stckf(&now_after_migration);
+	report(!cc, "clock still set");
+
+	/*
+	 * The architectural requirement for the TOD clock is that it doesn't move backwards after
+	 * migration. Implementations can just migrate the guest TOD value or do something more
+	 * sophisticated (e.g. slowly adjust to the host TOD).
+	 */
+	report(now_after_migration >= time_to_set, "TOD clock value did not jump backwards");
+}
+
+int main(void)
+{
+	report_prefix_push("migration-sck");
+
+	test_sck_migration();
+	report_prefix_pop();
+	return report_summary();
+}
diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg
index f9f102abfa89..2c04ae7c7c15 100644
--- a/s390x/unittests.cfg
+++ b/s390x/unittests.cfg
@@ -197,3 +197,7 @@  file = panic-loop-pgm.elf
 groups = panic
 accel = kvm
 timeout = 5
+
+[migration-sck]
+file = migration-sck.elf
+groups = migration