Kernel KVM virtualization development
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH v3 0/2] s390x: Add migration test for guest TOD clock
@ 2022-10-11 17:00 Nico Boehr
  2022-10-11 17:00 ` [kvm-unit-tests PATCH v3 1/2] lib/s390x: move TOD clock related functions to library Nico Boehr
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Nico Boehr @ 2022-10-11 17:00 UTC (permalink / raw)
  To: kvm; +Cc: frankja, imbrenda, borntraeger

v2->v3:
---
- check the clock is really set after setting (thanks Claudio)
- remove unneeded memory clobber (thanks Claudio)
- add comment to explain what we're testing (thanks Christian)

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 not go backwards 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 | 54 +++++++++++++++++++++++++++++++++++++++++++
 s390x/sck.c           | 32 -------------------------
 s390x/unittests.cfg   |  4 ++++
 5 files changed, 108 insertions(+), 33 deletions(-)
 create mode 100644 s390x/migration-sck.c

-- 
2.36.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [kvm-unit-tests PATCH v3 1/2] lib/s390x: move TOD clock related functions to library
  2022-10-11 17:00 [kvm-unit-tests PATCH v3 0/2] s390x: Add migration test for guest TOD clock Nico Boehr
@ 2022-10-11 17:00 ` Nico Boehr
  2022-10-11 17:06   ` Claudio Imbrenda
  2022-10-11 17:00 ` [kvm-unit-tests PATCH v3 2/2] s390x: add migration TOD clock test Nico Boehr
  2022-10-11 17:09 ` [kvm-unit-tests PATCH v3 0/2] s390x: Add migration test for guest TOD clock Claudio Imbrenda
  2 siblings, 1 reply; 6+ messages in thread
From: Nico Boehr @ 2022-10-11 17:00 UTC (permalink / raw)
  To: kvm; +Cc: frankja, imbrenda, borntraeger

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, express get_clock_us() with
stck() and remove an unneeded memory clobber.

Signed-off-by: Nico Boehr <nrb@linux.ibm.com>
---
 lib/s390x/asm/time.h | 50 +++++++++++++++++++++++++++++++++++++++++++-
 s390x/sck.c          | 32 ----------------------------
 2 files changed, 49 insertions(+), 33 deletions(-)

diff --git a/lib/s390x/asm/time.h b/lib/s390x/asm/time.h
index d8d91d68a667..ad689b098eab 100644
--- a/lib/s390x/asm/time.h
+++ b/lib/s390x/asm/time.h
@@ -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"
+	);
+
+	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"
+	);
+
+	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;
 }
diff --git a/s390x/sck.c b/s390x/sck.c
index 88d52b74a586..dff496187602 100644
--- a/s390x/sck.c
+++ b/s390x/sck.c
@@ -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,
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [kvm-unit-tests PATCH v3 2/2] s390x: add migration TOD clock test
  2022-10-11 17:00 [kvm-unit-tests PATCH v3 0/2] s390x: Add migration test for guest TOD clock Nico Boehr
  2022-10-11 17:00 ` [kvm-unit-tests PATCH v3 1/2] lib/s390x: move TOD clock related functions to library Nico Boehr
@ 2022-10-11 17:00 ` Nico Boehr
  2022-10-11 17:07   ` Claudio Imbrenda
  2022-10-11 17:09 ` [kvm-unit-tests PATCH v3 0/2] s390x: Add migration test for guest TOD clock Claudio Imbrenda
  2 siblings, 1 reply; 6+ messages in thread
From: Nico Boehr @ 2022-10-11 17:00 UTC (permalink / raw)
  To: kvm; +Cc: frankja, imbrenda, borntraeger

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

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
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [kvm-unit-tests PATCH v3 1/2] lib/s390x: move TOD clock related functions to library
  2022-10-11 17:00 ` [kvm-unit-tests PATCH v3 1/2] lib/s390x: move TOD clock related functions to library Nico Boehr
@ 2022-10-11 17:06   ` Claudio Imbrenda
  0 siblings, 0 replies; 6+ messages in thread
From: Claudio Imbrenda @ 2022-10-11 17:06 UTC (permalink / raw)
  To: Nico Boehr; +Cc: kvm, frankja, borntraeger

On Tue, 11 Oct 2022 19:00:23 +0200
Nico Boehr <nrb@linux.ibm.com> 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, express get_clock_us() with
> stck() and remove an unneeded memory clobber.
> 
> Signed-off-by: Nico Boehr <nrb@linux.ibm.com>

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

> ---
>  lib/s390x/asm/time.h | 50 +++++++++++++++++++++++++++++++++++++++++++-
>  s390x/sck.c          | 32 ----------------------------
>  2 files changed, 49 insertions(+), 33 deletions(-)
> 
> diff --git a/lib/s390x/asm/time.h b/lib/s390x/asm/time.h
> index d8d91d68a667..ad689b098eab 100644
> --- a/lib/s390x/asm/time.h
> +++ b/lib/s390x/asm/time.h
> @@ -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"
> +	);
> +
> +	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"
> +	);
> +
> +	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;
>  }
> diff --git a/s390x/sck.c b/s390x/sck.c
> index 88d52b74a586..dff496187602 100644
> --- a/s390x/sck.c
> +++ b/s390x/sck.c
> @@ -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,


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [kvm-unit-tests PATCH v3 2/2] s390x: add migration TOD clock test
  2022-10-11 17:00 ` [kvm-unit-tests PATCH v3 2/2] s390x: add migration TOD clock test Nico Boehr
@ 2022-10-11 17:07   ` Claudio Imbrenda
  0 siblings, 0 replies; 6+ messages in thread
From: Claudio Imbrenda @ 2022-10-11 17:07 UTC (permalink / raw)
  To: Nico Boehr; +Cc: kvm, frankja, borntraeger

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


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [kvm-unit-tests PATCH v3 0/2] s390x: Add migration test for guest TOD clock
  2022-10-11 17:00 [kvm-unit-tests PATCH v3 0/2] s390x: Add migration test for guest TOD clock Nico Boehr
  2022-10-11 17:00 ` [kvm-unit-tests PATCH v3 1/2] lib/s390x: move TOD clock related functions to library Nico Boehr
  2022-10-11 17:00 ` [kvm-unit-tests PATCH v3 2/2] s390x: add migration TOD clock test Nico Boehr
@ 2022-10-11 17:09 ` Claudio Imbrenda
  2 siblings, 0 replies; 6+ messages in thread
From: Claudio Imbrenda @ 2022-10-11 17:09 UTC (permalink / raw)
  To: Nico Boehr; +Cc: kvm, frankja, borntraeger

On Tue, 11 Oct 2022 19:00:22 +0200
Nico Boehr <nrb@linux.ibm.com> wrote:

> v2->v3:
> ---
> - check the clock is really set after setting (thanks Claudio)
> - remove unneeded memory clobber (thanks Claudio)
> - add comment to explain what we're testing (thanks Christian)
> 
> 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 not go backwards 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.
> 

thanks, picked

> 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 | 54 +++++++++++++++++++++++++++++++++++++++++++
>  s390x/sck.c           | 32 -------------------------
>  s390x/unittests.cfg   |  4 ++++
>  5 files changed, 108 insertions(+), 33 deletions(-)
>  create mode 100644 s390x/migration-sck.c
> 


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-10-11 17:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-11 17:00 [kvm-unit-tests PATCH v3 0/2] s390x: Add migration test for guest TOD clock Nico Boehr
2022-10-11 17:00 ` [kvm-unit-tests PATCH v3 1/2] lib/s390x: move TOD clock related functions to library Nico Boehr
2022-10-11 17:06   ` Claudio Imbrenda
2022-10-11 17:00 ` [kvm-unit-tests PATCH v3 2/2] s390x: add migration TOD clock test Nico Boehr
2022-10-11 17:07   ` Claudio Imbrenda
2022-10-11 17:09 ` [kvm-unit-tests PATCH v3 0/2] s390x: Add migration test for guest TOD clock Claudio Imbrenda

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox