Skip to contentSkip to conversation

s390x: Add migration test for guest TOD clock

PATCH Superseded Nico Boehr 2 participants 6 messages Aug 26, 2022 – Oct 11, 2022 KVM

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Nico Boehr

author
#0 lore raw

cover s390x: Add migration test for guest TOD clock

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  | 48 +++++++++++++++++++++++++++++++++++++++++++
 s390x/Makefile        |  1 +
 s390x/migration-sck.c | 45 ++++++++++++++++++++++++++++++++++++++++
 s390x/sck.c           | 32 -----------------------------
 s390x/unittests.cfg   |  4 ++++
 5 files changed, 98 insertions(+), 32 deletions(-)
 create mode 100644 s390x/migration-sck.c
Signature · 1 line
2.36.1
author
#1 lore raw

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

---
 lib/s390x/asm/time.h | 48 ++++++++++++++++++++++++++++++++++++++++++++
 s390x/sck.c          | 32 -----------------------------
 2 files changed, 48 insertions(+), 32 deletions(-)
lib/s390x/asm/time.h +48 -0
index 7652a151e87a..81b57e2b4894 100644
@@ -28,6 +28,54 @@ static inline uint64_t get_clock_ms(void)
 	return get_clock_us() / 1000;
 }
 
+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 void udelay(unsigned long us)
 {
 	unsigned long startclk = get_clock_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 v1 1/2] lib/s390x: move TOD clock related functions to library

Quoted 54 lines · On Fri, 26 Aug 2022 10:49:43 +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.

---
 lib/s390x/asm/time.h | 48 ++++++++++++++++++++++++++++++++++++++++++++
 s390x/sck.c          | 32 -----------------------------
 2 files changed, 48 insertions(+), 32 deletions(-)
lib/s390x/asm/time.h +37 -0
index 7652a151e87a..81b57e2b4894 100644
@@ -28,6 +28,54 @@ static inline uint64_t get_clock_ms(void)
 	return get_clock_us() / 1000;
 }
 
+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(

lib/s390x/asm/time.h static inline uint64_t get_clock_ms(void) · line 77

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

please put these functions before all the other inline functions, and then fix get_clock_us to use the wrapper instead of the (broken) inline asm

Quoted 47 lines
lib/s390x/asm/time.h +1 -0
+
 static inline void udelay(unsigned long us)
 {
 	unsigned long startclk = get_clock_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

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

Quoting Claudio Imbrenda (2022-10-06 12:50:14)
[...]

Quoted 2 lines
Quoted 2 lines
lib/s390x/asm/time.h +0 -0
index 7652a151e87a..81b57e2b4894 100644

[...]

Quoted 1 line
Quoted 1 line

+static inline int sck(uint64_t *time)

[...]

Quoted 1 line
Quoted 1 line

+static inline int stck(uint64_t *time)

[...]

Quoted 1 line
Quoted 1 line

+static inline int stckf(uint64_t *time)

[...]

Quoted 4 lines

please put these functions before all the other inline functions, and then fix get_clock_us to use the wrapper instead of the (broken) inline asm

Yes, this makes sense, thanks.

author
#4 lore raw

PATCH 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 | 45 +++++++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg   |  4 ++++
 3 files changed, 50 insertions(+)
 create mode 100644 s390x/migration-sck.c
s390x/Makefile +1 -0
index efd5e0c13102..be8e647bb35f 100644
@@ -34,6 +34,7 @@ tests += $(TEST_DIR)/migration.elf
 tests += $(TEST_DIR)/pv-attest.elf
 tests += $(TEST_DIR)/migration-cmm.elf
 tests += $(TEST_DIR)/migration-skey.elf
+tests += $(TEST_DIR)/migration-sck.elf
 
 pv-tests += $(TEST_DIR)/pv-diags.elf
 
s390x/migration-sck.c new file +45 -0

45 lines not on this page · raw message

s390x/unittests.cfg +4 -0
index f7b1fc3dbca1..808e8a28ba96 100644
@@ -185,3 +185,7 @@ groups = migration
 [migration-skey]
 file = migration-skey.elf
 groups = migration
+
+[migration-sck]
+file = migration-sck.elf
+groups = migration
Signature · 1 line
2.36.1
#5 lore raw

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

Quoted 47 lines · On Fri, 26 Aug 2022 10:49:44 +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 | 45 +++++++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg   |  4 ++++
 3 files changed, 50 insertions(+)
 create mode 100644 s390x/migration-sck.c
s390x/Makefile +1 -0
index efd5e0c13102..be8e647bb35f 100644
@@ -34,6 +34,7 @@ tests += $(TEST_DIR)/migration.elf
 tests += $(TEST_DIR)/pv-attest.elf
 tests += $(TEST_DIR)/migration-cmm.elf
 tests += $(TEST_DIR)/migration-skey.elf
+tests += $(TEST_DIR)/migration-sck.elf
 
 pv-tests += $(TEST_DIR)/pv-diags.elf
 
s390x/migration-sck.c new file +12 -0
new file mode 100644
index 000000000000..701d33f9db5a
@@ -0,0 +1,45 @@
+/* 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>

s390x/migration-sck.c line 22

Quoted 10 lines
s390x/migration-sck.c new file +10 -0
+#include <bitops.h>
+
+static void test_sck_migration(void)
+{
+	uint64_t now_before_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 (60s) */

maybe give an even bigger value, just to be really sure. like 600s

s390x/migration-sck.c line 23

Quoted 1 line
s390x/migration-sck.c new file +1 -0
+	time_to_advance = (60ULL * 1000ULL * 1000ULL << STCK_SHIFT_US);

you can do * 1000000, and you don't need ULL everywhere; use the braces to help humans understand what's going on:

time_to_advance = (600ULL * 1000000) << STCK_SHIFT_US;

Quoted 34 lines
s390x/migration-sck.c new file +22 -0
+	time_to_set = now_before_set + time_to_advance;
+
+	cc = sck(&time_to_set);
+	report(!cc, "setting clock succeeded");
+
+	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 f7b1fc3dbca1..808e8a28ba96 100644
@@ -185,3 +185,7 @@ groups = migration
 [migration-skey]
 file = migration-skey.elf
 groups = migration
+
+[migration-sck]
+file = migration-sck.elf
+groups = migration