Skip to contentSkip to conversation

s390x: Add migration test for guest TOD clock

PATCH Superseded Nico Boehr 3 participants 8 messages Oct 11, 2022 KVM

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Nico Boehr

author
#0 lore raw

v2 cover s390x: Add migration test for guest TOD clock

v1->v2:
---
- remove unneeded include
- advance clock by 10 minutes instead of 1 minute (thanks Claudio)
- express get_clock_us() using stck() (thanks Claudio)

The guest TOD clock should be preserved on migration. Add a test to verify that.

To reduce code duplication, move some of the time-related defined from the sck test to the library.

Nico Boehr (2):
lib/s390x: move TOD clock related functions to library
s390x: add migration TOD clock test

 lib/s390x/asm/time.h  | 50 ++++++++++++++++++++++++++++++++++++++++++-
 s390x/Makefile        |  1 +
 s390x/migration-sck.c | 44 +++++++++++++++++++++++++++++++++++++
 s390x/sck.c           | 32 ---------------------------
 s390x/unittests.cfg   |  4 ++++
 5 files changed, 98 insertions(+), 33 deletions(-)
 create mode 100644 s390x/migration-sck.c
Signature · 1 line
2.36.1
author
#1 lore raw

PATCH v2 1/2 lib/s390x: move TOD clock related functions to library

The TOD-clock related functions can be useful for other tests beside the sck test, hence move them to the library.

While at it, add a wrapper for stckf and express get_clock_us() with stck() to reduce code duplication.

---
 lib/s390x/asm/time.h | 50 +++++++++++++++++++++++++++++++++++++++++++-
 s390x/sck.c          | 32 ----------------------------
 2 files changed, 49 insertions(+), 33 deletions(-)
lib/s390x/asm/time.h +49 -1
index d8d91d68a667..c5e1797fd29e 100644
@@ -18,11 +18,59 @@
 
 #define CPU_TIMER_SHIFT_US	S390_CLOCK_SHIFT_US
 
+static inline int sck(uint64_t *time)
+{
+	int cc;
+
+	asm volatile(
+		"	sck %[time]\n"
+		"	ipm %[cc]\n"
+		"	srl %[cc],28\n"
+		: [cc] "=d"(cc)
+		: [time] "Q"(*time)
+		: "cc"
+	);
+
+	return cc;
+}
+
+static inline int stck(uint64_t *time)
+{
+	int cc;
+
+	asm volatile(
+		"	stck %[time]\n"
+		"	ipm %[cc]\n"
+		"	srl %[cc],28\n"
+		: [cc] "=d" (cc), [time] "=Q" (*time)
+		:
+		: "cc", "memory"
+	);
+
+	return cc;
+}
+
+static inline int stckf(uint64_t *time)
+{
+	int cc;
+
+	asm volatile(
+		"	stckf %[time]\n"
+		"	ipm %[cc]\n"
+		"	srl %[cc],28\n"
+		: [cc] "=d" (cc), [time] "=Q" (*time)
+		:
+		: "cc", "memory"
+	);
+
+	return cc;
+}
+
 static inline uint64_t get_clock_us(void)
 {
 	uint64_t clk;
 
-	asm volatile(" stck %0 " : : "Q"(clk) : "memory");
+	stck(&clk);
 
 	return clk >> STCK_SHIFT_US;
 }
s390x/sck.c +0 -32
index 88d52b74a586..dff496187602 100644
@@ -12,38 +12,6 @@
 #include <asm/interrupt.h>
 #include <asm/time.h>
 
-static inline int sck(uint64_t *time)
-{
-	int cc;
-
-	asm volatile(
-		"	sck %[time]\n"
-		"	ipm %[cc]\n"
-		"	srl %[cc],28\n"
-		: [cc] "=d"(cc)
-		: [time] "Q"(*time)
-		: "cc"
-	);
-
-	return cc;
-}
-
-static inline int stck(uint64_t *time)
-{
-	int cc;
-
-	asm volatile(
-		"	stck %[time]\n"
-		"	ipm %[cc]\n"
-		"	srl %[cc],28\n"
-		: [cc] "=d" (cc), [time] "=Q" (*time)
-		:
-		: "cc", "memory"
-	);
-
-	return cc;
-}
-
 static void test_priv(void)
 {
 	uint64_t time_to_set_privileged = 0xfacef00dcafe0000,
Signature · 1 line
2.36.1
#2 lore raw

Re: [kvm-unit-tests PATCH v2 1/2] lib/s390x: move TOD clock related functions to library

Quoted 37 lines · On Tue, 11 Oct 2022 17:14:32 +0200 Nico Boehr <[email protected]> wrote:

The TOD-clock related functions can be useful for other tests beside the sck test, hence move them to the library.

While at it, add a wrapper for stckf and express get_clock_us() with stck() to reduce code duplication.

---
 lib/s390x/asm/time.h | 50 +++++++++++++++++++++++++++++++++++++++++++-
 s390x/sck.c          | 32 ----------------------------
 2 files changed, 49 insertions(+), 33 deletions(-)
lib/s390x/asm/time.h +17 -0
index d8d91d68a667..c5e1797fd29e 100644
@@ -18,11 +18,59 @@
 
 #define CPU_TIMER_SHIFT_US	S390_CLOCK_SHIFT_US
 
+static inline int sck(uint64_t *time)
+{
+	int cc;
+
+	asm volatile(
+		"	sck %[time]\n"
+		"	ipm %[cc]\n"
+		"	srl %[cc],28\n"
+		: [cc] "=d"(cc)
+		: [time] "Q"(*time)
+		: "cc"
+	);
+
+	return cc;
+}
+
+static inline int stck(uint64_t *time)

lib/s390x/asm/time.h line 47

Quoted 10 lines
lib/s390x/asm/time.h +10 -0
+{
+	int cc;
+
+	asm volatile(
+		"	stck %[time]\n"
+		"	ipm %[cc]\n"
+		"	srl %[cc],28\n"
+		: [cc] "=d" (cc), [time] "=Q" (*time)
+		:
+		: "cc", "memory"

why do you need "memory" ?

(I know it was in the old code, but probably it should not have)

Quoted 6 lines
lib/s390x/asm/time.h +6 -0
+	);
+
+	return cc;
+}
+
+static inline int stckf(uint64_t *time)

lib/s390x/asm/time.h line 63

Quoted 10 lines
lib/s390x/asm/time.h +10 -0
+{
+	int cc;
+
+	asm volatile(
+		"	stckf %[time]\n"
+		"	ipm %[cc]\n"
+		"	srl %[cc],28\n"
+		: [cc] "=d" (cc), [time] "=Q" (*time)
+		:
+		: "cc", "memory"

same here

Quoted 57 lines
lib/s390x/asm/time.h +6 -1
+	);
+
+	return cc;
+}
+
 static inline uint64_t get_clock_us(void)
 {
 	uint64_t clk;
 
-	asm volatile(" stck %0 " : : "Q"(clk) : "memory");
+	stck(&clk);
 
 	return clk >> STCK_SHIFT_US;
 }
s390x/sck.c +0 -32
index 88d52b74a586..dff496187602 100644
@@ -12,38 +12,6 @@
 #include <asm/interrupt.h>
 #include <asm/time.h>
 
-static inline int sck(uint64_t *time)
-{
-	int cc;
-
-	asm volatile(
-		"	sck %[time]\n"
-		"	ipm %[cc]\n"
-		"	srl %[cc],28\n"
-		: [cc] "=d"(cc)
-		: [time] "Q"(*time)
-		: "cc"
-	);
-
-	return cc;
-}
-
-static inline int stck(uint64_t *time)
-{
-	int cc;
-
-	asm volatile(
-		"	stck %[time]\n"
-		"	ipm %[cc]\n"
-		"	srl %[cc],28\n"
-		: [cc] "=d" (cc), [time] "=Q" (*time)
-		:
-		: "cc", "memory"
-	);
-
-	return cc;
-}
-
 static void test_priv(void)
 {
 	uint64_t time_to_set_privileged = 0xfacef00dcafe0000,
author
#3 lore raw

PATCH v2 2/2 s390x: add migration TOD clock test

In reply to Nico Boehr

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.

---
 s390x/Makefile        |  1 +
 s390x/migration-sck.c | 44 +++++++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg   |  4 ++++
 3 files changed, 49 insertions(+)
 create mode 100644 s390x/migration-sck.c
s390x/Makefile +1 -0
index 649486f2d4a0..fba09bc2df3a 100644
@@ -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
 
s390x/migration-sck.c new file +44 -0

44 lines not on this page · raw message

s390x/unittests.cfg +4 -0
index f9f102abfa89..2c04ae7c7c15 100644
@@ -197,3 +197,7 @@ file = panic-loop-pgm.elf
 groups = panic
 accel = kvm
 timeout = 5
+
+[migration-sck]
+file = migration-sck.elf
+groups = migration
Signature · 1 line
2.36.1
#4 lore raw

Re: [kvm-unit-tests PATCH v2 2/2] s390x: add migration TOD clock test

Quoted 51 lines · On Tue, 11 Oct 2022 17:14:33 +0200 Nico Boehr <[email protected]> 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.

---
 s390x/Makefile        |  1 +
 s390x/migration-sck.c | 44 +++++++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg   |  4 ++++
 3 files changed, 49 insertions(+)
 create mode 100644 s390x/migration-sck.c
s390x/Makefile +1 -0
index 649486f2d4a0..fba09bc2df3a 100644
@@ -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
 
s390x/migration-sck.c new file +16 -0
new file mode 100644
index 000000000000..286a693b4858
@@ -0,0 +1,44 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * SET CLOCK migration tests
+ *
+ * Copyright IBM Corp. 2022
+ *
+ * Authors:
+ *  Nico Boehr <[email protected]>
+ */
+
+#include <libcflat.h>
+#include <asm/time.h>
+
+static void test_sck_migration(void)
+{
+	uint64_t now_before_set = 0, now_after_migration, time_to_set, time_to_advance;

s390x/migration-sck.c line 26

Quoted 10 lines
s390x/migration-sck.c new file +10 -0
+	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");

I would also check here that the clock is set. This way we can differentiate between a migration issue or a more general (and more severe) clock issue. Even if we have this test somewhere else, this makes it easier when debugging to narrow down the issue to migration.

Quoted 30 lines
s390x/migration-sck.c new file +18 -0
+
+	puts("Please migrate me, then press return\n");
+	(void)getchar();
+
+	cc = stckf(&now_after_migration);
+	report(!cc, "clock still set");
+
+	report(now_after_migration >= time_to_set, "TOD clock value preserved");
+}
+
+int main(void)
+{
+	report_prefix_push("migration-sck");
+
+	test_sck_migration();
+	report_prefix_pop();
+	return report_summary();
+}
s390x/unittests.cfg +4 -0
index f9f102abfa89..2c04ae7c7c15 100644
@@ -197,3 +197,7 @@ file = panic-loop-pgm.elf
 groups = panic
 accel = kvm
 timeout = 5
+
+[migration-sck]
+file = migration-sck.elf
+groups = migration
#5 lore raw
In reply to Nico Boehr

Am 11.10.22 um 17:14 schrieb Nico Boehr:

Quoted 8 lines

v1->v2:
---
- remove unneeded include
- advance clock by 10 minutes instead of 1 minute (thanks Claudio)
- express get_clock_us() using stck() (thanks Claudio)

The guest TOD clock should be preserved on migration. Add a test to verify that.

I do not fully agree with this assumption. Its the way it curently is, but we might want to have a configurable or different behaviour in the future.

For example if the difference is smaller than time x it could be allowed to move the time forward to get the guest synced to the new host (never go backward though). Or to preserve the time but then slowly step towards the target system clock etc (or for this testcase step the epoch difference towards the original difference).

So we maybe want to have a comment in here somehow that this is the as-is behaviour.

Quoted 15 lines

To reduce code duplication, move some of the time-related defined from the sck test to the library.

Nico Boehr (2):
lib/s390x: move TOD clock related functions to library
s390x: add migration TOD clock test

  lib/s390x/asm/time.h  | 50 ++++++++++++++++++++++++++++++++++++++++++-
  s390x/Makefile        |  1 +
  s390x/migration-sck.c | 44 +++++++++++++++++++++++++++++++++++++
  s390x/sck.c           | 32 ---------------------------
  s390x/unittests.cfg   |  4 ++++
  5 files changed, 98 insertions(+), 33 deletions(-)

create mode 100644 s390x/migration-sck.c

#6 lore raw
Quoted 7 lines · On Tue, 11 Oct 2022 17:58:29 +0200 Christian Borntraeger…

Am 11.10.22 um 17:14 schrieb Nico Boehr:

Quoted 6 lines

v1->v2:
---
- remove unneeded include
- advance clock by 10 minutes instead of 1 minute (thanks Claudio)
- express get_clock_us() using stck() (thanks Claudio)

Quoted 6 lines
Quoted 2 lines

The guest TOD clock should be preserved on migration. Add a test to verify that.

I do not fully agree with this assumption. Its the way it curently is, but we might want to have a configurable or different behaviour in the future.

For example if the difference is smaller than time x it could be allowed to move the time forward to get the guest synced to the new host (never go backward though).

the test is actually testing that the clock does not go backwards, rather than staying the same

Quoted 3 lines

Or to preserve the time but then slowly step towards the target system clock etc (or for this testcase step the epoch difference towards the original difference).

So we maybe want to have a comment in here somehow that this is the as-is behaviour.

comments never hurt :)

Quoted 16 lines
Quoted 16 lines

To reduce code duplication, move some of the time-related defined from the sck test to the library.

Nico Boehr (2):
lib/s390x: move TOD clock related functions to library
s390x: add migration TOD clock test

  lib/s390x/asm/time.h  | 50 ++++++++++++++++++++++++++++++++++++++++++-
  s390x/Makefile        |  1 +
  s390x/migration-sck.c | 44 +++++++++++++++++++++++++++++++++++++
  s390x/sck.c           | 32 ---------------------------
  s390x/unittests.cfg   |  4 ++++
  5 files changed, 98 insertions(+), 33 deletions(-)

create mode 100644 s390x/migration-sck.c

#7 lore raw

Am 11.10.22 um 18:10 schrieb Claudio Imbrenda:

Quoted 13 lines
Quoted 10 lines · On Tue, 11 Oct 2022 17:58:29 +0200 Christian Borntraeger…

Am 11.10.22 um 17:14 schrieb Nico Boehr:

Quoted 8 lines

v1->v2:
---
- remove unneeded include
- advance clock by 10 minutes instead of 1 minute (thanks Claudio)
- express get_clock_us() using stck() (thanks Claudio)

The guest TOD clock should be preserved on migration. Add a test to verify that.

Quoted 6 lines
Quoted 3 lines

I do not fully agree with this assumption. Its the way it curently is, but we might want to have a configurable or different behaviour in the future.

For example if the difference is smaller than time x it could be allowed to move the time forward to get the guest synced to the new host (never go backward though).

the test is actually testing that the clock does not go backwards, rather than staying the same

I think this is an must and a perfectly valid test.