Skip to contentSkip to conversation

storage keys, attestation, migration tests

GIT PULL Claudio Imbrenda 3 participants 33 messages May 12, 2022 – Oct 5, 2022 KVM

lore
Share & tools
lore
#0 lore raw

Hi Paolo,

please merge the following changes:
* improved host detection
* overall cleanups
* storage key tests
* some migration tests
* attestation UV interface

MERGE:
https://gitlab.com/kvm-unit-tests/kvm-unit-tests/-/merge_requests/30

PIPELINE:
https://gitlab.com/imbrenda/kvm-unit-tests/-/pipelines/537301867

PULL:
https://gitlab.com/imbrenda/kvm-unit-tests.git s390x-next-2022-05

Janis Schoetterl-Glausch (3):
s390x: Give name to return value of tprot()
s390x: Test effect of storage keys on some instructions Disable s390x skey test in GitLab CI

Janosch Frank (10):
lib: s390x: hardware: Add host_is_qemu() function
s390x: css: Skip if we're not run by qemu
s390x: diag308: Only test subcode 2 under QEMU
s390x: pfmf: Initialize pfmf_r1 union on declaration
s390x: snippets: asm: Add license and copyright headers
s390x: pv-diags: Cleanup includes
s390x: css: Cleanup includes
s390x: iep: Cleanup includes
s390x: mvpg: Cleanup includes
s390x: uv-host: Fix pgm tests

Nico Boehr (9):
s390x: gs: move to new header file
s390x: add test for SIGP STORE_ADTL_STATUS order
s390x: epsw: fix report_pop_prefix() when running under non-QEMU
s390x: tprot: use lib include for mmu.h
s390x: smp: make stop stopped cpu look the same as the running case
lib: s390x: add support for SCLP console read
s390x: add support for migration tests
s390x: don't run migration tests under PV
s390x: add basic migration test

Steffen Eiden (6):
s390x: uv-host: Add invalid command attestation check
s390x: lib: Add QUI getter
s390x: uv-guest: remove duplicated checks
s390x: uv-guest: Remove double report_prefix_pop
s390x: uv-guest: add share bit test
s390x: Add attestation tests

 scripts/s390x/func.bash                    |   2 +-
 s390x/run                                  |   7 +-
 s390x/Makefile                             |   4 +
 lib/s390x/asm/arch_def.h                   |  31 +-
 lib/s390x/asm/uv.h                         |  28 +-
 lib/s390x/asm/vector.h                     |  16 +
 lib/s390x/gs.h                             |  69 ++++
 lib/s390x/hardware.h                       |   5 +
 lib/s390x/sclp.h                           |   8 +
 lib/s390x/uv.h                             |   1 +
 lib/s390x/sclp-console.c                   |  79 +++-
 lib/s390x/sclp.c                           |   6 +-
 lib/s390x/uv.c                             |   8 +
 s390x/snippets/asm/snippet-pv-diag-288.S   |   9 +
 s390x/snippets/asm/snippet-pv-diag-500.S   |   9 +
 s390x/snippets/asm/snippet-pv-diag-yield.S |   9 +
 s390x/adtl-status.c                        | 408 +++++++++++++++++++++
 s390x/css.c                                |  18 +-
 s390x/diag308.c                            |  18 +-
 s390x/epsw.c                               |   4 +-
 s390x/gs.c                                 |  54 +--
 s390x/iep.c                                |   3 +-
 s390x/migration.c                          | 198 ++++++++++
 s390x/mvpg.c                               |   3 -
 s390x/pfmf.c                               |  39 +-
 s390x/pv-attest.c                          | 225 ++++++++++++
 s390x/pv-diags.c                           |  17 +-
 s390x/skey.c                               | 249 +++++++++++++
 s390x/smp.c                                |   5 +-
 s390x/tprot.c                              |  26 +-
 s390x/uv-guest.c                           |  51 ++-
 s390x/uv-host.c                            |   3 +-
 s390x/unittests.cfg                        |  30 ++
 .gitlab-ci.yml                             |   2 +-
 34 files changed, 1483 insertions(+), 161 deletions(-)
 create mode 100644 lib/s390x/asm/vector.h
 create mode 100644 lib/s390x/gs.h
 create mode 100644 s390x/adtl-status.c
 create mode 100644 s390x/migration.c
 create mode 100644 s390x/pv-attest.c
Signature · 1 line
2.36.1
#1 lore raw

[kvm-unit-tests GIT PULL 03/28] s390x: epsw: fix report_pop_prefix() when running under non-QEMU

From: Nico Boehr <[email protected]>

When we don't run in QEMU, we didn't push a prefix, hence pop won't work. Fix this by pushing the prefix before the QEMU check.

---
 s390x/epsw.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
s390x/epsw.c +2 -2
index 5b73f4b3..d8090d95 100644
@@ -97,13 +97,13 @@ static void test_epsw(void)
 
 int main(int argc, char **argv)
 {
+	report_prefix_push("epsw");
+
 	if (!host_is_kvm() && !host_is_tcg()) {
 		report_skip("Not running under QEMU");
 		goto done;
 	}
 
-	report_prefix_push("epsw");
-
 	test_epsw();
 
 done:
Signature · 1 line
2.36.1
#2 lore raw

[kvm-unit-tests GIT PULL 01/28] s390x: gs: move to new header file

In reply to Claudio Imbrenda

From: Nico Boehr <[email protected]>

Move the guarded-storage related structs and instructions to a new header file because we will also need them for the SIGP store additional status tests.

---
 lib/s390x/gs.h | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++
 s390x/gs.c     | 54 +--------------------------------------
 2 files changed, 70 insertions(+), 53 deletions(-)
 create mode 100644 lib/s390x/gs.h
lib/s390x/gs.h new file +69 -0
new file mode 100644
index 00000000..9c94e580
@@ -0,0 +1,69 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Guarded storage related definitions
+ *
+ * Copyright 2018 IBM Corp.
+ *
+ * Authors:
+ *    Martin Schwidefsky <[email protected]>
+ *    Janosch Frank <[email protected]>
+ */
+#include <stdint.h>
+
+#ifndef _S390X_GS_H_
+#define _S390X_GS_H_
+
+struct gs_cb {
+	uint64_t reserved;
+	uint64_t gsd;
+	uint64_t gssm;
+	uint64_t gs_epl_a;
+};
+
+struct gs_epl {
+	uint8_t pad1;
+	union {
+		uint8_t gs_eam;
+		struct {
+			uint8_t		: 6;
+			uint8_t e	: 1;
+			uint8_t b	: 1;
+		};
+	};
+	union {
+		uint8_t gs_eci;
+		struct {
+			uint8_t tx	: 1;
+			uint8_t cx	: 1;
+			uint8_t		: 5;
+			uint8_t in	: 1;
+		};
+	};
+	union {
+		uint8_t gs_eai;
+		struct {
+			uint8_t		: 1;
+			uint8_t t	: 1;
+			uint8_t as	: 2;
+			uint8_t ar	: 4;
+		};
+	};
+	uint32_t pad2;
+	uint64_t gs_eha;
+	uint64_t gs_eia;
+	uint64_t gs_eoa;
+	uint64_t gs_eir;
+	uint64_t gs_era;
+};
+
+static inline void load_gs_cb(struct gs_cb *gs_cb)
+{
+	asm volatile(".insn rxy,0xe3000000004d,0,%0" : : "Q" (*gs_cb));
+}
+
+static inline void store_gs_cb(struct gs_cb *gs_cb)
+{
+	asm volatile(".insn rxy,0xe30000000049,0,%0" : : "Q" (*gs_cb));
+}
+
+#endif
s390x/gs.c +1 -53

66 lines not on this page · raw message

Signature · 1 line
2.36.1
#3 lore raw

[kvm-unit-tests GIT PULL 05/28] s390x: smp: make stop stopped cpu look the same as the running case

In reply to Claudio Imbrenda

From: Nico Boehr <[email protected]>

Adjust the stop stopped CPU case such that it looks the same as the stop running CPU case: use the nowait variant, handle the error code in the same way and make the report messages look the same.

---
 s390x/smp.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
s390x/smp.c +3 -2
index 5257852c..de3aba71 100644
@@ -144,8 +144,9 @@ static void test_stop(void)
 	report(smp_cpu_stopped(1), "cpu stopped");
 
 	report_prefix_push("stop stopped CPU");
-	report(!smp_cpu_stop(1), "STOP succeeds");
-	report(smp_cpu_stopped(1), "CPU is stopped");
+	rc = smp_cpu_stop_nowait(1);
+	report(!rc, "return code");
+	report(smp_cpu_stopped(1), "cpu stopped");
 	report_prefix_pop();
 
 	report_prefix_pop();
Signature · 1 line
2.36.1
#4 lore raw

[kvm-unit-tests GIT PULL 04/28] s390x: tprot: use lib include for mmu.h

In reply to Claudio Imbrenda

From: Nico Boehr <[email protected]>

mmu.h should come from the library includes

---
 s390x/tprot.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
s390x/tprot.c +1 -1
index 460a0db7..760e7ecd 100644
@@ -12,7 +12,7 @@
 #include <bitops.h>
 #include <asm/pgtable.h>
 #include <asm/interrupt.h>
-#include "mmu.h"
+#include <mmu.h>
 #include <vmalloc.h>
 #include <sclp.h>
 
Signature · 1 line
2.36.1
#5 lore raw

[kvm-unit-tests GIT PULL 02/28] s390x: add test for SIGP STORE_ADTL_STATUS order

In reply to Claudio Imbrenda

From: Nico Boehr <[email protected]>

Add a test for SIGP STORE_ADDITIONAL_STATUS order.

There are several cases to cover:
- when neither vector nor guarded-storage facility is available, check the order is rejected.
- when one of the facilities is there, test the order is rejected and adtl_status is not touched when the target CPU is running or when an invalid CPU address is specified. Also check the order is rejected in case of invalid alignment.
- when the vector facility is there, write some data to the CPU's vector registers and check we get the right contents.
- when the guarded-storage facility is there, populate the CPU's guarded-storage registers with some data and again check we get the right contents.

To make sure we cover all these cases, adjust unittests.cfg to run the test with both guarded-storage and vector facility off and on. In TCG, we don't have guarded-storage support, so we just run with vector facility off and on.

---
 s390x/Makefile         |   1 +
 lib/s390x/asm/vector.h |  16 ++
 s390x/adtl-status.c    | 408 +++++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg    |  25 +++
 4 files changed, 450 insertions(+)
 create mode 100644 lib/s390x/asm/vector.h
 create mode 100644 s390x/adtl-status.c
s390x/Makefile +1 -0
index 8ff84db5..c11f6efb 100644
@@ -29,6 +29,7 @@ tests += $(TEST_DIR)/mvpg-sie.elf
 tests += $(TEST_DIR)/spec_ex-sie.elf
 tests += $(TEST_DIR)/firq.elf
 tests += $(TEST_DIR)/epsw.elf
+tests += $(TEST_DIR)/adtl-status.elf
 
 pv-tests += $(TEST_DIR)/pv-diags.elf
 
lib/s390x/asm/vector.h new file +16 -0
new file mode 100644
index 00000000..ee48bfa6
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Vector facility related defines and functions
+ *
+ * Copyright IBM Corp. 2022
+ *
+ * Authors:
+ *    Nico Boehr <[email protected]>
+ */
+#ifndef _ASMS390X_VECTOR_H_
+#define _ASMS390X_VECTOR_H_
+
+#define VEC_REGISTER_NUM 32
+#define VEC_REGISTER_SIZE 16
+
+#endif
s390x/adtl-status.c new file +408 -0

408 lines not on this page · raw message

s390x/unittests.cfg +25 -0
index 743013b2..256c7169 100644
@@ -146,3 +146,28 @@ extra_params = -device virtio-net-ccw
 
 [tprot]
 file = tprot.elf
+
+[adtl-status-kvm]
+file = adtl-status.elf
+smp = 2
+accel = kvm
+extra_params = -cpu host,gs=on,vx=on
+
+[adtl-status-no-vec-no-gs-kvm]
+file = adtl-status.elf
+smp = 2
+accel = kvm
+extra_params = -cpu host,gs=off,vx=off
+
+[adtl-status-tcg]
+file = adtl-status.elf
+smp = 2
+accel = tcg
+# no guarded-storage support in tcg
+extra_params = -cpu qemu,vx=on
+
+[adtl-status-no-vec-no-gs-tcg]
+file = adtl-status.elf
+smp = 2
+accel = tcg
+extra_params = -cpu qemu,gs=off,vx=off
Signature · 1 line
2.36.1
#6 lore raw

Re: [kvm-unit-tests GIT PULL 02/28] s390x: add test for SIGP STORE_ADTL_STATUS order

On 12/05/2022 11.34, Claudio Imbrenda wrote:
[...]

Quoted 5 lines
s390x/unittests.cfg +0 -0
index 743013b2..256c7169 100644

s390x/unittests.cfg extra_params = -device virtio-net-ccw · line 154

Quoted 9 lines
s390x/unittests.cfg +6 -0
@@ -146,3 +146,28 @@ extra_params = -device virtio-net-ccw
 
  [tprot]
  file = tprot.elf
+
+[adtl-status-kvm]
+file = adtl-status.elf
+smp = 2
+accel = kvm
+extra_params = -cpu host,gs=on,vx=on

FWIW, on my z13 LPAR, I now see a warning:

SKIP adtl-status-kvm (qemu-kvm: can't apply global host-s390x-cpu.gs=on: Feature 'gs' is not available for CPU model 'z13.2', it was introduced with later models.)

Could we silence that somehow?

Thomas

#7 lore raw

Re: [kvm-unit-tests GIT PULL 02/28] s390x: add test for SIGP STORE_ADTL_STATUS order

Hi Thomas,

Quoting Thomas Huth (2022-09-20 17:53:28)

Quoted 19 lines · Claudio Imbrenda

[...]

Quoted 5 lines
s390x/unittests.cfg +0 -0
index 743013b2..256c7169 100644

s390x/unittests.cfg extra_params = -device virtio-net-ccw · line 154

Quoted 9 lines
s390x/unittests.cfg +6 -0
@@ -146,3 +146,28 @@ extra_params = -device virtio-net-ccw
 
  [tprot]
  file = tprot.elf
+
+[adtl-status-kvm]
+file = adtl-status.elf
+smp = 2
+accel = kvm
+extra_params = -cpu host,gs=on,vx=on

FWIW, on my z13 LPAR, I now see a warning:

Quoted 5 lines

SKIP adtl-status-kvm (qemu-kvm: can't apply global host-s390x-cpu.gs=on:
Feature 'gs' is not available for CPU model 'z13.2', it was introduced with later models.)

Could we silence that somehow?

instead of a SKIP, what would you expect to see in this case? Or do you mean the message inside the parenthesis?

Nico

#8 lore raw

Re: [kvm-unit-tests GIT PULL 02/28] s390x: add test for SIGP STORE_ADTL_STATUS order

Quoted 22 lines · Nico Boehr

Hi Thomas,

Quoting Thomas Huth (2022-09-20 17:53:28)

Quoted 19 lines · Claudio Imbrenda

[...]

Quoted 5 lines
s390x/unittests.cfg +0 -0
index 743013b2..256c7169 100644

s390x/unittests.cfg extra_params = -device virtio-net-ccw · line 154

Quoted 9 lines
s390x/unittests.cfg +6 -0
@@ -146,3 +146,28 @@ extra_params = -device virtio-net-ccw
 
   [tprot]
   file = tprot.elf
+
+[adtl-status-kvm]
+file = adtl-status.elf
+smp = 2
+accel = kvm
+extra_params = -cpu host,gs=on,vx=on

FWIW, on my z13 LPAR, I now see a warning:

Quoted 7 lines
Quoted 5 lines

SKIP adtl-status-kvm (qemu-kvm: can't apply global host-s390x-cpu.gs=on:
Feature 'gs' is not available for CPU model 'z13.2', it was introduced with later models.)

Could we silence that somehow?

instead of a SKIP, what would you expect to see in this case? Or do you mean the message inside the parenthesis?

I meant the message inside the parenthesis ... but thinking about it twice, it's maybe even useful to have it here ... so I'm also fine if we keep it. ... it's just a little bit long ...

Thomas

#9 lore raw

Re: [kvm-unit-tests GIT PULL 02/28] s390x: add test for SIGP STORE_ADTL_STATUS order

Quoting Thomas Huth (2022-10-05 15:25:03)

Quoted 27 lines · Nico Boehr
Quoted 26 lines

Hi Thomas,

Quoting Thomas Huth (2022-09-20 17:53:28)

Quoted 23 lines · Claudio Imbrenda

[...]

Quoted 5 lines
s390x/unittests.cfg +0 -0
index 743013b2..256c7169 100644

s390x/unittests.cfg extra_params = -device virtio-net-ccw · line 154

Quoted 9 lines
s390x/unittests.cfg +6 -0
@@ -146,3 +146,28 @@ extra_params = -device virtio-net-ccw
 
   [tprot]
   file = tprot.elf
+
+[adtl-status-kvm]
+file = adtl-status.elf
+smp = 2
+accel = kvm
+extra_params = -cpu host,gs=on,vx=on

FWIW, on my z13 LPAR, I now see a warning:

SKIP adtl-status-kvm (qemu-kvm: can't apply global host-s390x-cpu.gs=on:
Feature 'gs' is not available for CPU model 'z13.2', it was introduced with later models.)

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

Could we silence that somehow?

instead of a SKIP, what would you expect to see in this case? Or do you mean the message inside the parenthesis?

I meant the message inside the parenthesis ... but thinking about it twice, it's maybe even useful to have it here ... so I'm also fine if we keep it. ... it's just a little bit long ...

We could have

cpu = host

in unittest.cfg for adtl-status-kvm.

But this would mean if the host doesn't support vector or gs, we would just see

PASS adtl-status-kvm

with some skipped tests. So, to me, it feels like the current solution is better even if the error message is ugly and long.

#10 lore raw

[kvm-unit-tests GIT PULL 09/28] s390x: pfmf: Initialize pfmf_r1 union on declaration

In reply to Claudio Imbrenda

From: Janosch Frank <[email protected]>

Let's make this test look a bit nicer.

---
 s390x/pfmf.c | 39 +++++++++++++++++++--------------------
 1 file changed, 19 insertions(+), 20 deletions(-)
s390x/pfmf.c +19 -20
index aa130529..178abb5a 100644
@@ -28,7 +28,11 @@ static void test_priv(void)
 
 static void test_4k_key(void)
 {
-	union pfmf_r1 r1;
+	union pfmf_r1 r1 = {
+		.reg.sk = 1,
+		.reg.fsc = PFMF_FSC_4K,
+		.reg.key = 0x30,
+	};
 	union skey skey;
 
 	report_prefix_push("4K");
@@ -36,10 +40,6 @@ static void test_4k_key(void)
 		report_skip("storage key removal facility is active");
 		goto out;
 	}
-	r1.val = 0;
-	r1.reg.sk = 1;
-	r1.reg.fsc = PFMF_FSC_4K;
-	r1.reg.key = 0x30;
 	pfmf(r1.val, pagebuf);
 	skey.val = get_storage_key(pagebuf);
 	skey.val &= SKEY_ACC | SKEY_FP;
@@ -52,18 +52,19 @@ static void test_1m_key(void)
 {
 	int i;
 	bool rp = true;
-	union pfmf_r1 r1;
 	union skey skey;
+	union pfmf_r1 r1 = {
+		.reg.fsc = PFMF_FSC_1M,
+		.reg.key = 0x30,
+		.reg.sk = 1,
+	};
 
 	report_prefix_push("1M");
 	if (test_facility(169)) {
 		report_skip("storage key removal facility is active");
 		goto out;
 	}
-	r1.val = 0;
-	r1.reg.sk = 1;
-	r1.reg.fsc = PFMF_FSC_1M;
-	r1.reg.key = 0x30;
+
 	pfmf(r1.val, pagebuf);
 	for (i = 0; i < 256; i++) {
 		skey.val = get_storage_key(pagebuf + i * PAGE_SIZE);
@@ -80,11 +81,10 @@ out:
 
 static void test_4k_clear(void)
 {
-	union pfmf_r1 r1;
-
-	r1.val = 0;
-	r1.reg.cf = 1;
-	r1.reg.fsc = PFMF_FSC_4K;
+	union pfmf_r1 r1 = {
+		.reg.cf = 1,
+		.reg.fsc = PFMF_FSC_4K,
+	};
 
 	report_prefix_push("4K");
 	memset(pagebuf, 42, PAGE_SIZE);
@@ -97,13 +97,12 @@ static void test_4k_clear(void)
 static void test_1m_clear(void)
 {
 	int i;
-	union pfmf_r1 r1;
+	union pfmf_r1 r1 = {
+		.reg.cf = 1,
+		.reg.fsc = PFMF_FSC_1M,
+	};
 	unsigned long sum = 0;
 
-	r1.val = 0;
-	r1.reg.cf = 1;
-	r1.reg.fsc = PFMF_FSC_1M;
-
 	report_prefix_push("1M");
 	memset(pagebuf, 42, PAGE_SIZE * 256);
 	pfmf(r1.val, pagebuf);
Signature · 1 line
2.36.1
#11 lore raw

[kvm-unit-tests GIT PULL 13/28] s390x: iep: Cleanup includes

In reply to Claudio Imbrenda

From: Janosch Frank <[email protected]>

We don't use barriers so let's remove the include.

---
 s390x/iep.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
s390x/iep.c +1 -2
index 8d5e044b..4b3e09a7 100644
@@ -9,11 +9,10 @@
  */
 #include <libcflat.h>
 #include <vmalloc.h>
+#include <mmu.h>
 #include <asm/facility.h>
 #include <asm/interrupt.h>
-#include <mmu.h>
 #include <asm/pgtable.h>
-#include <asm-generic/barrier.h>
 
 static void test_iep(void)
 {
Signature · 1 line
2.36.1
#12 lore raw

[kvm-unit-tests GIT PULL 06/28] lib: s390x: hardware: Add host_is_qemu() function

In reply to Claudio Imbrenda

From: Janosch Frank <[email protected]>

In the future we'll likely need to check if we're hosted on QEMU so let's make this as easy as possible by providing a dedicated function.

---
 lib/s390x/hardware.h | 5 +++++
 1 file changed, 5 insertions(+)
lib/s390x/hardware.h +5 -0
index 01eeb261..86fe873c 100644
@@ -45,6 +45,11 @@ static inline bool host_is_lpar(void)
 	return detect_host() == HOST_IS_LPAR;
 }
 
+static inline bool host_is_qemu(void)
+{
+	return host_is_tcg() || host_is_kvm();
+}
+
 static inline bool machine_is_z15(void)
 {
 	uint16_t machine = get_machine_id();
Signature · 1 line
2.36.1
#13 lore raw

[kvm-unit-tests GIT PULL 07/28] s390x: css: Skip if we're not run by qemu

In reply to Claudio Imbrenda

From: Janosch Frank <[email protected]>

There's no guarantee that we even find a device at the address we're testing for if we're not running under QEMU.

---
 s390x/css.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
s390x/css.c +10 -1
index a333e55a..13a1509f 100644
@@ -15,6 +15,7 @@
 #include <interrupt.h>
 #include <asm/arch_def.h>
 #include <alloc_page.h>
+#include <hardware.h>
 
 #include <malloc_io.h>
 #include <css.h>
@@ -642,13 +643,21 @@ int main(int argc, char *argv[])
 	int i;
 
 	report_prefix_push("Channel Subsystem");
+
+	/* There's no guarantee where our devices are without qemu */
+	if (!host_is_qemu()) {
+		report_skip("Not running under QEMU");
+		goto done;
+	}
+
 	enable_io_isc(0x80 >> IO_SCH_ISC);
 	for (i = 0; tests[i].name; i++) {
 		report_prefix_push(tests[i].name);
 		tests[i].func();
 		report_prefix_pop();
 	}
-	report_prefix_pop();
 
+done:
+	report_prefix_pop();
 	return report_summary();
 }
Signature · 1 line
2.36.1
#14 lore raw

[kvm-unit-tests GIT PULL 12/28] s390x: css: Cleanup includes

In reply to Claudio Imbrenda

From: Janosch Frank <[email protected]>

Most includes were related to allocation but that's done in the io allocation library so having them in the test doesn't make sense.

---
 s390x/css.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
s390x/css.c +3 -6
index 13a1509f..fabe5237 100644
@@ -9,17 +9,14 @@
  */
 
 #include <libcflat.h>
-#include <alloc_phys.h>
-#include <asm/page.h>
-#include <string.h>
 #include <interrupt.h>
-#include <asm/arch_def.h>
-#include <alloc_page.h>
 #include <hardware.h>
 
+#include <asm/arch_def.h>
+#include <asm/page.h>
+
 #include <malloc_io.h>
 #include <css.h>
-#include <asm/barrier.h>
 
 #define DEFAULT_CU_TYPE		0x3832 /* virtio-ccw */
 static unsigned long cu_type = DEFAULT_CU_TYPE;
Signature · 1 line
2.36.1
#15 lore raw

[kvm-unit-tests GIT PULL 11/28] s390x: pv-diags: Cleanup includes

In reply to Claudio Imbrenda

From: Janosch Frank <[email protected]>

This file has way too much includes. Time to remove some.

---
 s390x/pv-diags.c | 17 ++---------------
 1 file changed, 2 insertions(+), 15 deletions(-)
s390x/pv-diags.c +2 -15
index 6899b859..9ced68c7 100644
@@ -8,23 +8,10 @@
  *  Janosch Frank <[email protected]>
  */
 #include <libcflat.h>
-#include <asm/asm-offsets.h>
-#include <asm-generic/barrier.h>
-#include <asm/interrupt.h>
-#include <asm/pgtable.h>
-#include <mmu.h>
-#include <asm/page.h>
-#include <asm/facility.h>
-#include <asm/mem.h>
-#include <asm/sigp.h>
-#include <smp.h>
-#include <alloc_page.h>
-#include <vmalloc.h>
-#include <sclp.h>
 #include <snippet.h>
 #include <sie.h>
-#include <uv.h>
-#include <asm/uv.h>
+#include <sclp.h>
+#include <asm/facility.h>
 
 static struct vm vm;
 
Signature · 1 line
2.36.1
#16 lore raw

[kvm-unit-tests GIT PULL 14/28] s390x: mvpg: Cleanup includes

In reply to Claudio Imbrenda

From: Janosch Frank <[email protected]>

Time to remove unneeded includes.

---
 s390x/mvpg.c | 3 ---
 1 file changed, 3 deletions(-)
s390x/mvpg.c +0 -3
index 62f0fc5a..04e5218f 100644
@@ -9,15 +9,12 @@
  */
 #include <libcflat.h>
 #include <asm/asm-offsets.h>
-#include <asm-generic/barrier.h>
 #include <asm/interrupt.h>
 #include <asm/pgtable.h>
 #include <mmu.h>
 #include <asm/page.h>
 #include <asm/facility.h>
 #include <asm/mem.h>
-#include <asm/sigp.h>
-#include <smp.h>
 #include <alloc_page.h>
 #include <bitops.h>
 #include <hardware.h>
Signature · 1 line
2.36.1
#17 lore raw

[kvm-unit-tests GIT PULL 08/28] s390x: diag308: Only test subcode 2 under QEMU

In reply to Claudio Imbrenda

From: Janosch Frank <[email protected]>

Other hypervisors might implement it and therefore not send a specification exception.

---
 s390x/diag308.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
s390x/diag308.c +17 -1
index c9d6c499..ea41b455 100644
@@ -8,6 +8,7 @@
 #include <libcflat.h>
 #include <asm/asm-offsets.h>
 #include <asm/interrupt.h>
+#include <hardware.h>
 
 /* The diagnose calls should be blocked in problem state */
 static void test_priv(void)
@@ -75,7 +76,7 @@ static void test_subcode6(void)
 /* Unsupported subcodes should generate a specification exception */
 static void test_unsupported_subcode(void)
 {
-	int subcodes[] = { 2, 0x101, 0xffff, 0x10001, -1 };
+	int subcodes[] = { 0x101, 0xffff, 0x10001, -1 };
 	int idx;
 
 	for (idx = 0; idx < ARRAY_SIZE(subcodes); idx++) {
@@ -85,6 +86,21 @@ static void test_unsupported_subcode(void)
 		check_pgm_int_code(PGM_INT_CODE_SPECIFICATION);
 		report_prefix_pop();
 	}
+
+	/*
+	 * Subcode 2 is not available under QEMU but might be on other
+	 * hypervisors so we only check for the specification
+	 * exception on QEMU.
+	 */
+	report_prefix_pushf("0x%04x", 2);
+	if (host_is_qemu()) {
+		expect_pgm_int();
+		asm volatile ("diag %0,%1,0x308" :: "d"(0), "d"(2));
+		check_pgm_int_code(PGM_INT_CODE_SPECIFICATION);
+	} else {
+		report_skip("subcode is supported");
+	}
+	report_prefix_pop();
 }
 
 static struct {
Signature · 1 line
2.36.1
#18 lore raw

[kvm-unit-tests GIT PULL 10/28] s390x: snippets: asm: Add license and copyright headers

In reply to Claudio Imbrenda

From: Janosch Frank <[email protected]>

Time for some cleanup of the snippets to make them look like any other test file.

---
 s390x/snippets/asm/snippet-pv-diag-288.S   | 9 +++++++++
 s390x/snippets/asm/snippet-pv-diag-500.S   | 9 +++++++++
 s390x/snippets/asm/snippet-pv-diag-yield.S | 9 +++++++++
 3 files changed, 27 insertions(+)
s390x/snippets/asm/snippet-pv-diag-288.S +9 -0
index e3e63121..aaee3cd1 100644
@@ -1,3 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Diagnose 0x288 snippet used for PV interception testing.
+ *
+ * Copyright (c) 2021 IBM Corp
+ *
+ * Authors:
+ *  Janosch Frank <[email protected]>
+ */
 #include <asm/asm-offsets.h>
 .section .text
 
s390x/snippets/asm/snippet-pv-diag-500.S +9 -0
index 50c06779..8dd66bd9 100644
@@ -1,3 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Diagnose 0x500 snippet used for PV interception tests
+ *
+ * Copyright (c) 2021 IBM Corp
+ *
+ * Authors:
+ *  Janosch Frank <[email protected]>
+ */
 #include <asm/asm-offsets.h>
 .section .text
 
s390x/snippets/asm/snippet-pv-diag-yield.S +9 -0
index 5795cf0f..78a5b07a 100644
@@ -1,3 +1,12 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Diagnose 0x44 and 0x9c snippet used for PV interception tests
+ *
+ * Copyright (c) 2021 IBM Corp
+ *
+ * Authors:
+ *  Janosch Frank <[email protected]>
+ */
 .section .text
 
 xgr	%r0, %r0
Signature · 1 line
2.36.1
#19 lore raw

[kvm-unit-tests GIT PULL 15/28] s390x: uv-host: Fix pgm tests

In reply to Claudio Imbrenda

From: Janosch Frank <[email protected]>

We don't want to re-enter the UV call on a cc > 1 for this test.

---
 s390x/uv-host.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
s390x/uv-host.c +1 -1
index d3018e3c..5ac8a32c 100644
@@ -76,7 +76,7 @@ static void test_priv(void)
 		uvcb.cmd = cmds[i].cmd;
 		uvcb.len = cmds[i].len;
 		enter_pstate();
-		uv_call(0, (uint64_t)&uvcb);
+		uv_call_once(0, (uint64_t)&uvcb);
 		pgm = clear_pgm_int();
 		report(pgm == PGM_INT_CODE_PRIVILEGED_OPERATION, "%s", cmds[i].name);
 	}
Signature · 1 line
2.36.1
#20 lore raw

[kvm-unit-tests GIT PULL 17/28] s390x: add support for migration tests

In reply to Claudio Imbrenda

From: Nico Boehr <[email protected]>

Now that we have SCLP console read support, run our tests with migration_cmd, so we can get migration support on s390x.

---
 s390x/run | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
s390x/run +1 -1
index 064ecd1b..2bcdabba 100755
@@ -25,7 +25,7 @@ M+=",accel=$ACCEL"
 command="$qemu -nodefaults -nographic $M"
 command+=" -chardev stdio,id=con0 -device sclpconsole,chardev=con0"
 command+=" -kernel"
-command="$(timeout_cmd) $command"
+command="$(migration_cmd) $(timeout_cmd) $command"
 
 # We return the exit code via stdout, not via the QEMU return code
 run_qemu_status $command "$@"
Signature · 1 line
2.36.1
#21 lore raw

[kvm-unit-tests GIT PULL 20/28] s390x: Give name to return value of tprot()

In reply to Claudio Imbrenda

From: Janis Schoetterl-Glausch <[email protected]>

Improve readability by making the return value of tprot() an enum.

No functional change intended.

---
 lib/s390x/asm/arch_def.h | 11 +++++++++--
 lib/s390x/sclp.c         |  6 +++---
 s390x/tprot.c            | 24 ++++++++++++------------
 3 files changed, 24 insertions(+), 17 deletions(-)
lib/s390x/asm/arch_def.h +9 -2
index bab3c374..46c370e6 100644
@@ -228,7 +228,14 @@ static inline uint64_t stidp(void)
 	return cpuid;
 }
 
-static inline int tprot(unsigned long addr, char access_key)
+enum tprot_permission {
+	TPROT_READ_WRITE = 0,
+	TPROT_READ = 1,
+	TPROT_RW_PROTECTED = 2,
+	TPROT_TRANSL_UNAVAIL = 3,
+};
+
+static inline enum tprot_permission tprot(unsigned long addr, char access_key)
 {
 	int cc;
 
@@ -237,7 +244,7 @@ static inline int tprot(unsigned long addr, char access_key)
 		"	ipm	%0\n"
 		"	srl	%0,28\n"
 		: "=d" (cc) : "a" (addr), "a" (access_key << 4) : "cc");
-	return cc;
+	return (enum tprot_permission)cc;
 }
 
 static inline void lctlg(int cr, uint64_t value)
lib/s390x/sclp.c +3 -3
index 33985eb4..b8204c5f 100644
@@ -198,7 +198,7 @@ int sclp_service_call(unsigned int command, void *sccb)
 void sclp_memory_setup(void)
 {
 	uint64_t rnmax, rnsize;
-	int cc;
+	enum tprot_permission permission;
 
 	assert(read_info);
 
@@ -222,9 +222,9 @@ void sclp_memory_setup(void)
 	/* probe for r/w memory up to max memory size */
 	while (ram_size < max_ram_size) {
 		expect_pgm_int();
-		cc = tprot(ram_size + storage_increment_size - 1, 0);
+		permission = tprot(ram_size + storage_increment_size - 1, 0);
 		/* stop once we receive an exception or have protected memory */
-		if (clear_pgm_int() || cc != 0)
+		if (clear_pgm_int() || permission != TPROT_READ_WRITE)
 			break;
 		ram_size += storage_increment_size;
 	}
s390x/tprot.c +12 -12
index 760e7ecd..a4281abb 100644
@@ -20,26 +20,26 @@ static uint8_t pagebuf[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
 
 static void test_tprot_rw(void)
 {
-	int cc;
+	enum tprot_permission permission;
 
 	report_prefix_push("Page read/writeable");
 
-	cc = tprot((unsigned long)pagebuf, 0);
-	report(cc == 0, "CC = 0");
+	permission = tprot((unsigned long)pagebuf, 0);
+	report(permission == TPROT_READ_WRITE, "CC = 0");
 
 	report_prefix_pop();
 }
 
 static void test_tprot_ro(void)
 {
-	int cc;
+	enum tprot_permission permission;
 
 	report_prefix_push("Page readonly");
 
 	protect_dat_entry(pagebuf, PAGE_ENTRY_P, 5);
 
-	cc = tprot((unsigned long)pagebuf, 0);
-	report(cc == 1, "CC = 1");
+	permission = tprot((unsigned long)pagebuf, 0);
+	report(permission == TPROT_READ, "CC = 1");
 
 	unprotect_dat_entry(pagebuf, PAGE_ENTRY_P, 5);
 
@@ -48,28 +48,28 @@ static void test_tprot_ro(void)
 
 static void test_tprot_low_addr_prot(void)
 {
-	int cc;
+	enum tprot_permission permission;
 
 	report_prefix_push("low-address protection");
 
 	low_prot_enable();
-	cc = tprot(0, 0);
+	permission = tprot(0, 0);
 	low_prot_disable();
-	report(cc == 1, "CC = 1");
+	report(permission == TPROT_READ, "CC = 1");
 
 	report_prefix_pop();
 }
 
 static void test_tprot_transl_unavail(void)
 {
-	int cc;
+	enum tprot_permission permission;
 
 	report_prefix_push("Page translation unavailable");
 
 	protect_dat_entry(pagebuf, PAGE_ENTRY_I, 5);
 
-	cc = tprot((unsigned long)pagebuf, 0);
-	report(cc == 3, "CC = 3");
+	permission = tprot((unsigned long)pagebuf, 0);
+	report(permission == TPROT_TRANSL_UNAVAIL, "CC = 3");
 
 	unprotect_dat_entry(pagebuf, PAGE_ENTRY_I, 5);
 
Signature · 1 line
2.36.1
#22 lore raw

[kvm-unit-tests GIT PULL 18/28] s390x: don't run migration tests under PV

In reply to Claudio Imbrenda

From: Nico Boehr <[email protected]>

PV doesn't support migration, so don't run the migration tests there.

---
 scripts/s390x/func.bash | 2 +-
 s390x/run               | 5 +++++
 2 files changed, 6 insertions(+), 1 deletion(-)
scripts/s390x/func.bash +1 -1
index bf799a56..2a941bbb 100644
@@ -21,7 +21,7 @@ function arch_cmd_s390x()
 	"$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout"
 
 	# run PV test case
-	if [ "$ACCEL" = 'tcg' ]; then
+	if [ "$ACCEL" = 'tcg' ] || find_word "migration" "$groups"; then
 		return
 	fi
 	kernel=${kernel%.elf}.pv.bin
s390x/run +5 -0
index 2bcdabba..24138f68 100755
@@ -20,6 +20,11 @@ if [ "${1: -7}" = ".pv.bin" ] || [ "${TESTNAME: -3}" = "_PV" ] && [ "$ACCEL" = "
 	exit 2
 fi
 
+if [ "${1: -7}" = ".pv.bin" ] || [ "${TESTNAME: -3}" = "_PV" ] && [ "$MIGRATION" = "yes" ]; then
+	echo "Migration isn't supported under Protected Virtualization"
+	exit 2
+fi
+
 M='-machine s390-ccw-virtio'
 M+=",accel=$ACCEL"
 command="$qemu -nodefaults -nographic $M"
Signature · 1 line
2.36.1
#23 lore raw

[kvm-unit-tests GIT PULL 19/28] s390x: add basic migration test

In reply to Claudio Imbrenda

From: Nico Boehr <[email protected]>

Add a basic migration test for s390x. This tests the guarded-storage registers and vector registers are preserved on migration.

Check for the respective facilities. Since it is possible neither guarded-storage nor vector are there, add an additional report_pass() such that least one PASS is reported.

---
 s390x/Makefile      |   1 +
 s390x/migration.c   | 198 ++++++++++++++++++++++++++++++++++++++++++++
 s390x/unittests.cfg |   5 ++
 3 files changed, 204 insertions(+)
 create mode 100644 s390x/migration.c
s390x/Makefile +1 -0
index f38f442b..5336ed8a 100644
@@ -30,6 +30,7 @@ tests += $(TEST_DIR)/spec_ex-sie.elf
 tests += $(TEST_DIR)/firq.elf
 tests += $(TEST_DIR)/epsw.elf
 tests += $(TEST_DIR)/adtl-status.elf
+tests += $(TEST_DIR)/migration.elf
 
 pv-tests += $(TEST_DIR)/pv-diags.elf
 
s390x/migration.c new file +198 -0

198 lines not on this page · raw message

s390x/unittests.cfg +5 -0
index 256c7169..b456b288 100644
@@ -171,3 +171,8 @@ file = adtl-status.elf
 smp = 2
 accel = tcg
 extra_params = -cpu qemu,gs=off,vx=off
+
+[migration]
+file = migration.elf
+groups = migration
+smp = 2
Signature · 1 line
2.36.1
#24 lore raw

[kvm-unit-tests GIT PULL 16/28] lib: s390x: add support for SCLP console read

In reply to Claudio Imbrenda

From: Nico Boehr <[email protected]>

Add a basic implementation for reading from the SCLP ASCII console. The goal of this is to support migration tests on s390x. To know when the migration has been finished, we need to listen for a newline on our console.

Hence, this implementation is focused on the SCLP ASCII console of QEMU and currently won't work under e.g. LPAR.

---
 s390x/Makefile           |  1 +
 lib/s390x/sclp.h         |  8 ++++
 lib/s390x/sclp-console.c | 79 +++++++++++++++++++++++++++++++++++++---
 3 files changed, 82 insertions(+), 6 deletions(-)
s390x/Makefile +1 -0
index c11f6efb..f38f442b 100644
@@ -75,6 +75,7 @@ cflatobjs += lib/alloc_phys.o
 cflatobjs += lib/alloc_page.o
 cflatobjs += lib/vmalloc.o
 cflatobjs += lib/alloc_phys.o
+cflatobjs += lib/getchar.o
 cflatobjs += lib/s390x/io.o
 cflatobjs += lib/s390x/stack.o
 cflatobjs += lib/s390x/sclp.o
lib/s390x/sclp.h +8 -0
index fead007a..e48a5a3d 100644
@@ -313,6 +313,14 @@ typedef struct ReadEventData {
 	uint32_t mask;
 } __attribute__((packed)) ReadEventData;
 
+#define SCLP_EVENT_ASCII_TYPE_DATA_STREAM_FOLLOWS 0
+typedef struct ReadEventDataAsciiConsole {
+	SCCBHeader h;
+	EventBufferHeader ebh;
+	uint8_t type;
+	char data[];
+} __attribute__((packed)) ReadEventDataAsciiConsole;
+
 extern char _sccb[];
 void sclp_setup_int(void);
 void sclp_handle_ext(void);
lib/s390x/sclp-console.c +73 -6

107 lines not on this page · raw message

Signature · 1 line
2.36.1
#25 lore raw

[kvm-unit-tests GIT PULL 23/28] s390x: uv-host: Add invalid command attestation check

In reply to Claudio Imbrenda

From: Steffen Eiden <[email protected]>

Adds an invalid command test for attestation in the uv-host.

---
 lib/s390x/asm/uv.h | 23 ++++++++++++++++++++++-
 s390x/uv-host.c    |  1 +
 2 files changed, 23 insertions(+), 1 deletion(-)
lib/s390x/asm/uv.h +22 -1
index 70bf65c4..7c8c399d 100644
@@ -1,7 +1,7 @@
 /*
  * s390x Ultravisor related definitions
  *
- * Copyright (c) 2020 IBM Corp
+ * Copyright IBM Corp. 2020, 2022
  *
  * Authors:
  *  Janosch Frank <[email protected]>
@@ -47,6 +47,7 @@
 #define UVC_CMD_UNPIN_PAGE_SHARED	0x0342
 #define UVC_CMD_SET_SHARED_ACCESS	0x1000
 #define UVC_CMD_REMOVE_SHARED_ACCESS	0x1001
+#define UVC_CMD_ATTESTATION		0x1020
 
 /* Bits in installed uv calls */
 enum uv_cmds_inst {
@@ -71,6 +72,7 @@ enum uv_cmds_inst {
 	BIT_UVC_CMD_UNSHARE_ALL = 20,
 	BIT_UVC_CMD_PIN_PAGE_SHARED = 21,
 	BIT_UVC_CMD_UNPIN_PAGE_SHARED = 22,
+	BIT_UVC_CMD_ATTESTATION = 28,
 };
 
 struct uv_cb_header {
@@ -178,6 +180,25 @@ struct uv_cb_cfs {
 	u64 paddr;
 }  __attribute__((packed))  __attribute__((aligned(8)));
 
+/* Retrieve Attestation Measurement */
+struct uv_cb_attest {
+	struct uv_cb_header header;	/* 0x0000 */
+	uint64_t reserved08[2];		/* 0x0008 */
+	uint64_t arcb_addr;		/* 0x0018 */
+	uint64_t continuation_token;	/* 0x0020 */
+	uint8_t  reserved28[6];		/* 0x0028 */
+	uint16_t user_data_length;	/* 0x002e */
+	uint8_t  user_data[256];	/* 0x0030 */
+	uint32_t reserved130[3];	/* 0x0130 */
+	uint32_t measurement_length;	/* 0x013c */
+	uint64_t measurement_address;	/* 0x0140 */
+	uint8_t  config_uid[16];	/* 0x0148 */
+	uint32_t reserved158;		/* 0x0158 */
+	uint32_t add_data_length;	/* 0x015c */
+	uint64_t add_data_address;	/* 0x0160 */
+	uint64_t reserved168[4];	/* 0x0168 */
+}  __attribute__((packed))  __attribute__((aligned(8)));
+
 /* Set Secure Config Parameter */
 struct uv_cb_ssc {
 	struct uv_cb_header header;
s390x/uv-host.c +1 -0
index 5ac8a32c..a1a6d120 100644
@@ -418,6 +418,7 @@ static struct cmd_list invalid_cmds[] = {
 	{ "bogus", 0x4242, sizeof(struct uv_cb_header), -1},
 	{ "share", UVC_CMD_SET_SHARED_ACCESS, sizeof(struct uv_cb_share), BIT_UVC_CMD_SET_SHARED_ACCESS },
 	{ "unshare", UVC_CMD_REMOVE_SHARED_ACCESS, sizeof(struct uv_cb_share), BIT_UVC_CMD_REMOVE_SHARED_ACCESS },
+	{ "attest", UVC_CMD_ATTESTATION, sizeof(struct uv_cb_attest), BIT_UVC_CMD_ATTESTATION },
 	{ NULL, 0, 0 },
 };
 
Signature · 1 line
2.36.1
#26 lore raw

[kvm-unit-tests GIT PULL 24/28] s390x: lib: Add QUI getter

In reply to Claudio Imbrenda

From: Steffen Eiden <[email protected]>

Some tests need the information provided by the QUI UVC and lib/s390x/uv.c already has cached the qui result. Let's add a function to avoid unnecessary QUI UVCs.

---
 lib/s390x/uv.h | 1 +
 lib/s390x/uv.c | 8 ++++++++
 2 files changed, 9 insertions(+)
lib/s390x/uv.h +1 -0
index 8175d9c6..44264861 100644
@@ -8,6 +8,7 @@
 bool uv_os_is_guest(void);
 bool uv_os_is_host(void);
 bool uv_query_test_call(unsigned int nr);
+const struct uv_cb_qui *uv_get_query_data(void);
 void uv_init(void);
 int uv_setup(void);
 void uv_create_guest(struct vm *vm);
lib/s390x/uv.c +8 -0
index 6fe11dff..3b4cafa9 100644
@@ -47,6 +47,14 @@ bool uv_query_test_call(unsigned int nr)
 	return test_bit_inv(nr, uvcb_qui.inst_calls_list);
 }
 
+const struct uv_cb_qui *uv_get_query_data(void)
+{
+	/* Query needs to be called first */
+	assert(uvcb_qui.header.rc == 1 || uvcb_qui.header.rc == 0x100);
+
+	return &uvcb_qui;
+}
+
 int uv_setup(void)
 {
 	if (!test_facility(158))
Signature · 1 line
2.36.1
#27 lore raw

[kvm-unit-tests GIT PULL 22/28] Disable s390x skey test in GitLab CI

In reply to Claudio Imbrenda

From: Janis Schoetterl-Glausch <[email protected]>

The test cases newly added to skey.c require kernel 5.18.

---
 .gitlab-ci.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
.gitlab-ci.yml +1 -1
index 4f3049d8..e5768f1d 100644
@@ -166,7 +166,7 @@ s390x-kvm:
   - ./configure --arch=s390x
   - make -j$(nproc)
   - ACCEL=kvm ./run_tests.sh
-      selftest-setup intercept emulator sieve sthyi skey diag10 diag308 pfmf
+      selftest-setup intercept emulator sieve sthyi diag10 diag308 pfmf
       cmm vector gs iep cpumodel diag288 stsi sclp-1g sclp-3g css skrf sie
       | tee results.txt
   - grep -q PASS results.txt && ! grep -q FAIL results.txt
Signature · 1 line
2.36.1
#28 lore raw

[kvm-unit-tests GIT PULL 28/28] s390x: Add attestation tests

In reply to Claudio Imbrenda

From: Steffen Eiden <[email protected]>

Adds several tests to verify correct error paths of attestation.

---
 s390x/Makefile     |   1 +
 lib/s390x/asm/uv.h |   5 +-
 s390x/pv-attest.c  | 225 +++++++++++++++++++++++++++++++++++++++++++++
 s390x/uv-guest.c   |  11 ++-
 4 files changed, 240 insertions(+), 2 deletions(-)
 create mode 100644 s390x/pv-attest.c
s390x/Makefile +1 -0
index 5336ed8a..a8e04aa6 100644
@@ -31,6 +31,7 @@ tests += $(TEST_DIR)/firq.elf
 tests += $(TEST_DIR)/epsw.elf
 tests += $(TEST_DIR)/adtl-status.elf
 tests += $(TEST_DIR)/migration.elf
+tests += $(TEST_DIR)/pv-attest.elf
 
 pv-tests += $(TEST_DIR)/pv-diags.elf
 
lib/s390x/asm/uv.h +4 -1
index 7c8c399d..38920461 100644
@@ -108,7 +108,10 @@ struct uv_cb_qui {
 	u8  reserved88[158 - 136];	/* 0x0088 */
 	uint16_t max_guest_cpus;	/* 0x009e */
 	u64 uv_feature_indications;	/* 0x00a0 */
-	u8  reserveda8[200 - 168];	/* 0x00a8 */
+	uint8_t  reserveda8[224 - 168];	/* 0x00a8 */
+	uint64_t supp_att_hdr_ver;	/* 0x00e0 */
+	uint64_t supp_paf;		/* 0x00e8 */
+	uint8_t  reservedf0[256 - 240];	/* 0x00f0 */
 }  __attribute__((packed))  __attribute__((aligned(8)));
 
 struct uv_cb_cgc {
s390x/pv-attest.c new file +225 -0

225 lines not on this page · raw message

s390x/uv-guest.c +10 -1
index 152ad807..c16f19d4 100644
@@ -2,7 +2,7 @@
 /*
  * Guest Ultravisor Call tests
  *
- * Copyright (c) 2020 IBM Corp
+ * Copyright IBM Corp. 2020, 2022
  *
  * Authors:
  *  Janosch Frank <[email protected]>
@@ -53,6 +53,15 @@ static void test_priv(void)
 	check_pgm_int_code(PGM_INT_CODE_PRIVILEGED_OPERATION);
 	report_prefix_pop();
 
+	report_prefix_push("attest");
+	uvcb.cmd = UVC_CMD_ATTESTATION;
+	uvcb.len = sizeof(struct uv_cb_attest);
+	expect_pgm_int();
+	enter_pstate();
+	uv_call_once(0, (uint64_t)&uvcb);
+	check_pgm_int_code(PGM_INT_CODE_PRIVILEGED_OPERATION);
+	report_prefix_pop();
+
 	report_prefix_pop();
 }
 
Signature · 1 line
2.36.1
#29 lore raw

[kvm-unit-tests GIT PULL 27/28] s390x: uv-guest: add share bit test

In reply to Claudio Imbrenda

From: Steffen Eiden <[email protected]>

The UV facility bits shared/unshared must both be set or none.

---
 s390x/uv-guest.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
s390x/uv-guest.c +16 -0
index fd2cfef1..152ad807 100644
@@ -157,6 +157,16 @@ static void test_invalid(void)
 	report_prefix_pop();
 }
 
+static void test_share_bits(void)
+{
+	bool unshare = uv_query_test_call(BIT_UVC_CMD_REMOVE_SHARED_ACCESS);
+	bool share = uv_query_test_call(BIT_UVC_CMD_SET_SHARED_ACCESS);
+
+	report_prefix_push("query");
+	report(!(share ^ unshare), "share bits are identical");
+	report_prefix_pop();
+}
+
 int main(void)
 {
 	bool has_uvc = test_facility(158);
@@ -167,6 +177,12 @@ int main(void)
 		goto done;
 	}
 
+	/*
+	 * Needs to be done before the guest-fence,
+	 * as the fence tests if both shared bits are present
+	 */
+	test_share_bits();
+
 	if (!uv_os_is_guest()) {
 		report_skip("Not a protected guest");
 		goto done;
Signature · 1 line
2.36.1
#30 lore raw

[kvm-unit-tests GIT PULL 26/28] s390x: uv-guest: Remove double report_prefix_pop

In reply to Claudio Imbrenda

From: Steffen Eiden <[email protected]>

---
 s390x/uv-guest.c | 2 --
 1 file changed, 2 deletions(-)
s390x/uv-guest.c +0 -2
index 728c60aa..fd2cfef1 100644
@@ -111,8 +111,6 @@ static void test_sharing(void)
 	cc = uv_call(0, (u64)&uvcb);
 	report(cc == 0 && uvcb.header.rc == UVC_RC_EXECUTED, "unshare");
 	report_prefix_pop();
-
-	report_prefix_pop();
 }
 
 static struct {
Signature · 1 line
2.36.1
#31 lore raw

[kvm-unit-tests GIT PULL 25/28] s390x: uv-guest: remove duplicated checks

In reply to Claudio Imbrenda

From: Steffen Eiden <[email protected]>

Removing some tests which are done at other points in the code implicitly.

In lib/s390x/uc.c#setup_uv(void) the rc of the qui result is verified using asserts.
The whole test is fenced by lib/s390x/uc.c#uv_os_is_guest(void) that checks if SET and REMOVE SHARED is present.

---
 s390x/uv-guest.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)
s390x/uv-guest.c +7 -15
index 99120cae..728c60aa 100644
@@ -69,23 +69,15 @@ static void test_query(void)
 	cc = uv_call(0, (u64)&uvcb);
 	report(cc == 1 && uvcb.header.rc == UVC_RC_INV_LEN, "length");
 
-	uvcb.header.len = sizeof(uvcb);
-	cc = uv_call(0, (u64)&uvcb);
-	report((!cc && uvcb.header.rc == UVC_RC_EXECUTED) ||
-	       (cc == 1 && uvcb.header.rc == 0x100),
-		"successful query");
-
 	/*
-	 * These bits have been introduced with the very first
-	 * Ultravisor version and are expected to always be available
-	 * because they are basic building blocks.
+	 * BIT_UVC_CMD_QUI, BIT_UVC_CMD_SET_SHARED_ACCESS and
+	 * BIT_UVC_CMD_REMOVE_SHARED_ACCESS are always present as they
+	 * have been introduced with the first Ultravisor version.
+	 * However, we only need to check for QUI as
+	 * SET/REMOVE SHARED are used to fence this test to be only
+	 * executed by protected guests.
 	 */
-	report(test_bit_inv(BIT_UVC_CMD_QUI, &uvcb.inst_calls_list[0]),
-	       "query indicated");
-	report(test_bit_inv(BIT_UVC_CMD_SET_SHARED_ACCESS, &uvcb.inst_calls_list[0]),
-	       "share indicated");
-	report(test_bit_inv(BIT_UVC_CMD_REMOVE_SHARED_ACCESS, &uvcb.inst_calls_list[0]),
-	       "unshare indicated");
+	report(uv_query_test_call(BIT_UVC_CMD_QUI), "query indicated");
 	report_prefix_pop();
 }
 
Signature · 1 line
2.36.1
#32 lore raw

[kvm-unit-tests GIT PULL 21/28] s390x: Test effect of storage keys on some instructions

In reply to Claudio Imbrenda

From: Janis Schoetterl-Glausch <[email protected]>

Some instructions are emulated by KVM. Test that KVM correctly emulates storage key checking for two of those instructions (STORE CPU ADDRESS, SET PREFIX).
Test success and error conditions, including coverage of storage and fetch protection override.
Also add test for TEST PROTECTION, even if that instruction will not be emulated by KVM under normal conditions.

---
 lib/s390x/asm/arch_def.h |  20 ++--
 s390x/skey.c             | 249 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 260 insertions(+), 9 deletions(-)
lib/s390x/asm/arch_def.h +11 -9
index 46c370e6..72553819 100644
@@ -55,15 +55,17 @@ struct psw {
 #define PSW_MASK_BA			0x0000000080000000UL
 #define PSW_MASK_64			(PSW_MASK_BA | PSW_MASK_EA)
 
-#define CTL0_LOW_ADDR_PROT		(63 - 35)
-#define CTL0_EDAT			(63 - 40)
-#define CTL0_IEP			(63 - 43)
-#define CTL0_AFP			(63 - 45)
-#define CTL0_VECTOR			(63 - 46)
-#define CTL0_EMERGENCY_SIGNAL		(63 - 49)
-#define CTL0_EXTERNAL_CALL		(63 - 50)
-#define CTL0_CLOCK_COMPARATOR		(63 - 52)
-#define CTL0_SERVICE_SIGNAL		(63 - 54)
+#define CTL0_LOW_ADDR_PROT			(63 - 35)
+#define CTL0_EDAT				(63 - 40)
+#define CTL0_FETCH_PROTECTION_OVERRIDE		(63 - 38)
+#define CTL0_STORAGE_PROTECTION_OVERRIDE	(63 - 39)
+#define CTL0_IEP				(63 - 43)
+#define CTL0_AFP				(63 - 45)
+#define CTL0_VECTOR				(63 - 46)
+#define CTL0_EMERGENCY_SIGNAL			(63 - 49)
+#define CTL0_EXTERNAL_CALL			(63 - 50)
+#define CTL0_CLOCK_COMPARATOR			(63 - 52)
+#define CTL0_SERVICE_SIGNAL			(63 - 54)
 #define CR0_EXTM_MASK			0x0000000000006200UL /* Combined external masks */
 
 #define CTL2_GUARDED_STORAGE		(63 - 59)
s390x/skey.c +249 -0

267 lines not on this page · raw message

Signature · 1 line
2.36.1