All of lore.kernel.org
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH 0/6] s390x: uv: Extend guest test and add host test
@ 2021-03-16  9:16 Janosch Frank
  2021-03-16  9:16 ` [kvm-unit-tests PATCH 1/6] s390x: uv-guest: Add invalid share location test Janosch Frank
                   ` (6 more replies)
  0 siblings, 7 replies; 23+ messages in thread
From: Janosch Frank @ 2021-03-16  9:16 UTC (permalink / raw)
  To: kvm; +Cc: linux-s390, thuth, david, imbrenda

My stack of patches is starting to lean, so lets try to put some of
them upstream...

The first part is just additions to the UV guest test and a library
that makes checking the installed UV calls easier. Additionally we now
check for the proper UV share/unshare availability when allocating IO
memory instead of only relying on stfle 158.

The second part adds a UV host test with a large number UV of return
code checks. This is currently a guest 1 test.

Janosch Frank (6):
  s390x: uv-guest: Add invalid share location test
  s390x: Add more Ultravisor command structure definitions
  s390x: uv: Add UV lib
  s390x: Test for share/unshare call support before using them
  s390x: uv-guest: Test invalid commands
  s390x: Add UV host test

 lib/s390x/asm/uv.h    | 152 ++++++++++++-
 lib/s390x/io.c        |   2 +
 lib/s390x/malloc_io.c |   5 +-
 lib/s390x/uv.c        |  48 ++++
 lib/s390x/uv.h        |  10 +
 s390x/Makefile        |   2 +
 s390x/uv-guest.c      |  57 ++++-
 s390x/uv-host.c       | 513 ++++++++++++++++++++++++++++++++++++++++++
 8 files changed, 776 insertions(+), 13 deletions(-)
 create mode 100644 lib/s390x/uv.c
 create mode 100644 lib/s390x/uv.h
 create mode 100644 s390x/uv-host.c

-- 
2.27.0


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

* [kvm-unit-tests PATCH 1/6] s390x: uv-guest: Add invalid share location test
  2021-03-16  9:16 [kvm-unit-tests PATCH 0/6] s390x: uv: Extend guest test and add host test Janosch Frank
@ 2021-03-16  9:16 ` Janosch Frank
  2021-04-19 11:24   ` Thomas Huth
                     ` (2 more replies)
  2021-03-16  9:16 ` [kvm-unit-tests PATCH 2/6] s390x: Add more Ultravisor command structure definitions Janosch Frank
                   ` (5 subsequent siblings)
  6 siblings, 3 replies; 23+ messages in thread
From: Janosch Frank @ 2021-03-16  9:16 UTC (permalink / raw)
  To: kvm; +Cc: linux-s390, thuth, david, imbrenda

Let's also test sharing unavailable memory.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
 s390x/uv-guest.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/s390x/uv-guest.c b/s390x/uv-guest.c
index 99544442..a13669ab 100644
--- a/s390x/uv-guest.c
+++ b/s390x/uv-guest.c
@@ -15,6 +15,7 @@
 #include <asm/interrupt.h>
 #include <asm/facility.h>
 #include <asm/uv.h>
+#include <sclp.h>
 
 static unsigned long page;
 
@@ -99,6 +100,10 @@ static void test_sharing(void)
 	uvcb.header.len = sizeof(uvcb);
 	cc = uv_call(0, (u64)&uvcb);
 	report(cc == 0 && uvcb.header.rc == UVC_RC_EXECUTED, "share");
+	uvcb.paddr = get_ram_size() + PAGE_SIZE;
+	cc = uv_call(0, (u64)&uvcb);
+	report(cc == 1 && uvcb.header.rc == 0x101, "invalid memory");
+	uvcb.paddr = page;
 	report_prefix_pop();
 
 	report_prefix_push("unshare");
-- 
2.27.0


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

* [kvm-unit-tests PATCH 2/6] s390x: Add more Ultravisor command structure definitions
  2021-03-16  9:16 [kvm-unit-tests PATCH 0/6] s390x: uv: Extend guest test and add host test Janosch Frank
  2021-03-16  9:16 ` [kvm-unit-tests PATCH 1/6] s390x: uv-guest: Add invalid share location test Janosch Frank
@ 2021-03-16  9:16 ` Janosch Frank
  2021-04-20 14:09   ` Claudio Imbrenda
  2021-04-21 11:13   ` Cornelia Huck
  2021-03-16  9:16 ` [kvm-unit-tests PATCH 3/6] s390x: uv: Add UV lib Janosch Frank
                   ` (4 subsequent siblings)
  6 siblings, 2 replies; 23+ messages in thread
From: Janosch Frank @ 2021-03-16  9:16 UTC (permalink / raw)
  To: kvm; +Cc: linux-s390, thuth, david, imbrenda

They are needed in the new UV tests.

As we now extend the size of the query struct, we need to set the
length in the UV guest query test to a constant instead of using
sizeof.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
 lib/s390x/asm/uv.h | 148 ++++++++++++++++++++++++++++++++++++++++++++-
 s390x/uv-guest.c   |   2 +-
 2 files changed, 148 insertions(+), 2 deletions(-)

diff --git a/lib/s390x/asm/uv.h b/lib/s390x/asm/uv.h
index 9c491844..11f70a9f 100644
--- a/lib/s390x/asm/uv.h
+++ b/lib/s390x/asm/uv.h
@@ -17,16 +17,54 @@
 #define UVC_RC_INV_STATE	0x0003
 #define UVC_RC_INV_LEN		0x0005
 #define UVC_RC_NO_RESUME	0x0007
+#define UVC_RC_INV_GHANDLE	0x0020
+#define UVC_RC_INV_CHANDLE	0x0021
 
 #define UVC_CMD_QUI			0x0001
+#define UVC_CMD_INIT_UV			0x000f
+#define UVC_CMD_CREATE_SEC_CONF		0x0100
+#define UVC_CMD_DESTROY_SEC_CONF	0x0101
+#define UVC_CMD_CREATE_SEC_CPU		0x0120
+#define UVC_CMD_DESTROY_SEC_CPU		0x0121
+#define UVC_CMD_CONV_TO_SEC_STOR	0x0200
+#define UVC_CMD_CONV_FROM_SEC_STOR	0x0201
+#define UVC_CMD_SET_SEC_CONF_PARAMS	0x0300
+#define UVC_CMD_UNPACK_IMG		0x0301
+#define UVC_CMD_VERIFY_IMG		0x0302
+#define UVC_CMD_CPU_RESET		0x0310
+#define UVC_CMD_CPU_RESET_INITIAL	0x0311
+#define UVC_CMD_PERF_CONF_CLEAR_RESET	0x0320
+#define UVC_CMD_CPU_RESET_CLEAR		0x0321
+#define UVC_CMD_CPU_SET_STATE		0x0330
+#define UVC_CMD_SET_UNSHARED_ALL	0x0340
+#define UVC_CMD_PIN_PAGE_SHARED		0x0341
+#define UVC_CMD_UNPIN_PAGE_SHARED	0x0342
 #define UVC_CMD_SET_SHARED_ACCESS	0x1000
 #define UVC_CMD_REMOVE_SHARED_ACCESS	0x1001
 
 /* Bits in installed uv calls */
 enum uv_cmds_inst {
 	BIT_UVC_CMD_QUI = 0,
+	BIT_UVC_CMD_INIT_UV = 1,
+	BIT_UVC_CMD_CREATE_SEC_CONF = 2,
+	BIT_UVC_CMD_DESTROY_SEC_CONF = 3,
+	BIT_UVC_CMD_CREATE_SEC_CPU = 4,
+	BIT_UVC_CMD_DESTROY_SEC_CPU = 5,
+	BIT_UVC_CMD_CONV_TO_SEC_STOR = 6,
+	BIT_UVC_CMD_CONV_FROM_SEC_STOR = 7,
 	BIT_UVC_CMD_SET_SHARED_ACCESS = 8,
 	BIT_UVC_CMD_REMOVE_SHARED_ACCESS = 9,
+	BIT_UVC_CMD_SET_SEC_PARMS = 11,
+	BIT_UVC_CMD_UNPACK_IMG = 13,
+	BIT_UVC_CMD_VERIFY_IMG = 14,
+	BIT_UVC_CMD_CPU_RESET = 15,
+	BIT_UVC_CMD_CPU_RESET_INITIAL = 16,
+	BIT_UVC_CMD_CPU_SET_STATE = 17,
+	BIT_UVC_CMD_PREPARE_CLEAR_RESET = 18,
+	BIT_UVC_CMD_CPU_PERFORM_CLEAR_RESET = 19,
+	BIT_UVC_CMD_UNSHARE_ALL = 20,
+	BIT_UVC_CMD_PIN_PAGE_SHARED = 21,
+	BIT_UVC_CMD_UNPIN_PAGE_SHARED = 22,
 };
 
 struct uv_cb_header {
@@ -36,13 +74,81 @@ struct uv_cb_header {
 	u16 rrc;	/* Return Reason Code */
 } __attribute__((packed))  __attribute__((aligned(8)));
 
+struct uv_cb_init {
+	struct uv_cb_header header;
+	u64 reserved08[2];
+	u64 stor_origin;
+	u64 stor_len;
+	u64 reserved28[4];
+
+} __attribute__((packed))  __attribute__((aligned(8)));
+
 struct uv_cb_qui {
 	struct uv_cb_header header;
 	u64 reserved08;
 	u64 inst_calls_list[4];
-	u64 reserved30[15];
+	u64 reserved30[2];
+	u64 uv_base_stor_len;
+	u64 reserved48;
+	u64 conf_base_phys_stor_len;
+	u64 conf_base_virt_stor_len;
+	u64 conf_virt_var_stor_len;
+	u64 cpu_stor_len;
+	u32 reserved70[3];
+	u32 max_num_sec_conf;
+	u64 max_guest_stor_addr;
+	u8  reserved88[158 - 136];
+	u16 max_guest_cpus;
+	u8  reserveda0[200 - 160];
+}  __attribute__((packed))  __attribute__((aligned(8)));
+
+struct uv_cb_cgc {
+	struct uv_cb_header header;
+	u64 reserved08[2];
+	u64 guest_handle;
+	u64 conf_base_stor_origin;
+	u64 conf_var_stor_origin;
+	u64 reserved30;
+	u64 guest_stor_origin;
+	u64 guest_stor_len;
+	u64 guest_sca;
+	u64 guest_asce;
+	u64 reserved60[5];
 } __attribute__((packed))  __attribute__((aligned(8)));
 
+struct uv_cb_csc {
+	struct uv_cb_header header;
+	u64 reserved08[2];
+	u64 cpu_handle;
+	u64 guest_handle;
+	u64 stor_origin;
+	u8  reserved30[6];
+	u16 num;
+	u64 state_origin;
+	u64 reserved[4];
+} __attribute__((packed))  __attribute__((aligned(8)));
+
+struct uv_cb_unp {
+	struct uv_cb_header header;
+	u64 reserved08[2];
+	u64 guest_handle;
+	u64 gaddr;
+	u64 tweak[2];
+	u64 reserved38[3];
+} __attribute__((packed))  __attribute__((aligned(8)));
+
+/*
+ * A common UV call struct for the following calls:
+ * Destroy cpu/config
+ * Verify
+ */
+struct uv_cb_nodata {
+	struct uv_cb_header header;
+	u64 reserved08[2];
+	u64 handle;
+	u64 reserved20[4];
+}  __attribute__((packed))  __attribute__((aligned(8)));
+
 struct uv_cb_share {
 	struct uv_cb_header header;
 	u64 reserved08[3];
@@ -50,6 +156,32 @@ struct uv_cb_share {
 	u64 reserved28;
 } __attribute__((packed))  __attribute__((aligned(8)));
 
+/* Convert to Secure */
+struct uv_cb_cts {
+	struct uv_cb_header header;
+	u64 reserved08[2];
+	u64 guest_handle;
+	u64 gaddr;
+}  __attribute__((packed))  __attribute__((aligned(8)));
+
+/* Convert from Secure / Pin Page Shared */
+struct uv_cb_cfs {
+	struct uv_cb_header header;
+	u64 reserved08[2];
+	u64 paddr;
+}  __attribute__((packed))  __attribute__((aligned(8)));
+
+/* Set Secure Config Parameter */
+struct uv_cb_ssc {
+	struct uv_cb_header header;
+	u64 reserved08[2];
+	u64 guest_handle;
+	u64 sec_header_origin;
+	u32 sec_header_len;
+	u32 reserved2c;
+	u64 reserved30[4];
+} __attribute__((packed))  __attribute__((aligned(8)));
+
 static inline int uv_call_once(unsigned long r1, unsigned long r2)
 {
 	int cc;
@@ -118,4 +250,18 @@ static inline int uv_remove_shared(unsigned long addr)
 	return share(addr, UVC_CMD_REMOVE_SHARED_ACCESS);
 }
 
+struct uv_cb_cpu_set_state {
+	struct uv_cb_header header;
+	u64 reserved08[2];
+	u64 cpu_handle;
+	u8  reserved20[7];
+	u8  state;
+	u64 reserved28[5];
+};
+
+#define PV_CPU_STATE_OPR	1
+#define PV_CPU_STATE_STP	2
+#define PV_CPU_STATE_CHKSTP	3
+#define PV_CPU_STATE_OPR_LOAD	5
+
 #endif
diff --git a/s390x/uv-guest.c b/s390x/uv-guest.c
index a13669ab..95a968c5 100644
--- a/s390x/uv-guest.c
+++ b/s390x/uv-guest.c
@@ -59,7 +59,7 @@ static void test_query(void)
 {
 	struct uv_cb_qui uvcb = {
 		.header.cmd = UVC_CMD_QUI,
-		.header.len = sizeof(uvcb) - 8,
+		.header.len = 0xa0,
 	};
 	int cc;
 
-- 
2.27.0


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

* [kvm-unit-tests PATCH 3/6] s390x: uv: Add UV lib
  2021-03-16  9:16 [kvm-unit-tests PATCH 0/6] s390x: uv: Extend guest test and add host test Janosch Frank
  2021-03-16  9:16 ` [kvm-unit-tests PATCH 1/6] s390x: uv-guest: Add invalid share location test Janosch Frank
  2021-03-16  9:16 ` [kvm-unit-tests PATCH 2/6] s390x: Add more Ultravisor command structure definitions Janosch Frank
@ 2021-03-16  9:16 ` Janosch Frank
  2021-04-20 14:15   ` Claudio Imbrenda
  2021-03-16  9:16 ` [kvm-unit-tests PATCH 4/6] s390x: Test for share/unshare call support before using them Janosch Frank
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 23+ messages in thread
From: Janosch Frank @ 2021-03-16  9:16 UTC (permalink / raw)
  To: kvm; +Cc: linux-s390, thuth, david, imbrenda

Let's add a UV library to make checking the UV feature bit easier.
In the future this library file can take care of handling UV
initialization and UV guest creation.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
 lib/s390x/asm/uv.h |  4 ++--
 lib/s390x/io.c     |  2 ++
 lib/s390x/uv.c     | 48 ++++++++++++++++++++++++++++++++++++++++++++++
 lib/s390x/uv.h     | 10 ++++++++++
 s390x/Makefile     |  1 +
 5 files changed, 63 insertions(+), 2 deletions(-)
 create mode 100644 lib/s390x/uv.c
 create mode 100644 lib/s390x/uv.h

diff --git a/lib/s390x/asm/uv.h b/lib/s390x/asm/uv.h
index 11f70a9f..b22cbaa8 100644
--- a/lib/s390x/asm/uv.h
+++ b/lib/s390x/asm/uv.h
@@ -9,8 +9,8 @@
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2.
  */
-#ifndef UV_H
-#define UV_H
+#ifndef ASM_S390X_UV_H
+#define ASM_S390X_UV_H
 
 #define UVC_RC_EXECUTED		0x0001
 #define UVC_RC_INV_CMD		0x0002
diff --git a/lib/s390x/io.c b/lib/s390x/io.c
index ef9f59e3..a4f1b113 100644
--- a/lib/s390x/io.c
+++ b/lib/s390x/io.c
@@ -14,6 +14,7 @@
 #include <asm/facility.h>
 #include <asm/sigp.h>
 #include "sclp.h"
+#include "uv.h"
 #include "smp.h"
 
 extern char ipl_args[];
@@ -38,6 +39,7 @@ void setup(void)
 	sclp_facilities_setup();
 	sclp_console_setup();
 	sclp_memory_setup();
+	uv_setup();
 	smp_setup();
 }
 
diff --git a/lib/s390x/uv.c b/lib/s390x/uv.c
new file mode 100644
index 00000000..a84a85fc
--- /dev/null
+++ b/lib/s390x/uv.c
@@ -0,0 +1,48 @@
+#include <libcflat.h>
+#include <bitops.h>
+#include <alloc.h>
+#include <alloc_page.h>
+#include <asm/page.h>
+#include <asm/arch_def.h>
+
+#include <asm/facility.h>
+#include <asm/uv.h>
+#include <uv.h>
+
+static struct uv_cb_qui uvcb_qui = {
+	.header.cmd = UVC_CMD_QUI,
+	.header.len = sizeof(uvcb_qui),
+};
+
+bool uv_os_is_guest(void)
+{
+	return uv_query_test_feature(BIT_UVC_CMD_SET_SHARED_ACCESS)
+		&& uv_query_test_feature(BIT_UVC_CMD_REMOVE_SHARED_ACCESS);
+}
+
+bool uv_os_is_host(void)
+{
+	return uv_query_test_feature(BIT_UVC_CMD_INIT_UV);
+}
+
+bool uv_query_test_feature(int nr)
+{
+	/* Query needs to be called first */
+	if (!uvcb_qui.header.rc)
+		return false;
+
+	return test_bit_inv(nr, uvcb_qui.inst_calls_list);
+}
+
+int uv_setup(void)
+{
+	int cc;
+
+	if (!test_facility(158))
+		return 0;
+
+	cc = uv_call(0, (u64)&uvcb_qui);
+	assert(cc == 0);
+
+	return cc == 0;
+}
diff --git a/lib/s390x/uv.h b/lib/s390x/uv.h
new file mode 100644
index 00000000..159bf8e5
--- /dev/null
+++ b/lib/s390x/uv.h
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef UV_H
+#define UV_H
+
+bool uv_os_is_guest(void);
+bool uv_os_is_host(void);
+bool uv_query_test_feature(int nr);
+int uv_setup(void);
+
+#endif /* UV_H */
diff --git a/s390x/Makefile b/s390x/Makefile
index b92de9c5..bbf177fa 100644
--- a/s390x/Makefile
+++ b/s390x/Makefile
@@ -67,6 +67,7 @@ cflatobjs += lib/s390x/vm.o
 cflatobjs += lib/s390x/css_dump.o
 cflatobjs += lib/s390x/css_lib.o
 cflatobjs += lib/s390x/malloc_io.o
+cflatobjs += lib/s390x/uv.o
 
 OBJDIRS += lib/s390x
 
-- 
2.27.0


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

* [kvm-unit-tests PATCH 4/6] s390x: Test for share/unshare call support before using them
  2021-03-16  9:16 [kvm-unit-tests PATCH 0/6] s390x: uv: Extend guest test and add host test Janosch Frank
                   ` (2 preceding siblings ...)
  2021-03-16  9:16 ` [kvm-unit-tests PATCH 3/6] s390x: uv: Add UV lib Janosch Frank
@ 2021-03-16  9:16 ` Janosch Frank
  2021-04-20 14:18   ` Claudio Imbrenda
  2021-03-16  9:16 ` [kvm-unit-tests PATCH 5/6] s390x: uv-guest: Test invalid commands Janosch Frank
                   ` (2 subsequent siblings)
  6 siblings, 1 reply; 23+ messages in thread
From: Janosch Frank @ 2021-03-16  9:16 UTC (permalink / raw)
  To: kvm; +Cc: linux-s390, thuth, david, imbrenda

Testing for facility only means the UV Call facility is available.
The UV will only indicate the share/unshare calls for a protected
guest 2, so let's also check that.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
 lib/s390x/malloc_io.c | 5 +++--
 s390x/uv-guest.c      | 6 ++++++
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/lib/s390x/malloc_io.c b/lib/s390x/malloc_io.c
index 1dcf1691..78582eac 100644
--- a/lib/s390x/malloc_io.c
+++ b/lib/s390x/malloc_io.c
@@ -19,6 +19,7 @@
 #include <alloc_page.h>
 #include <asm/facility.h>
 #include <bitops.h>
+#include <uv.h>
 
 static int share_pages(void *p, int count)
 {
@@ -47,7 +48,7 @@ void *alloc_io_mem(int size, int flags)
 	assert(size);
 
 	p = alloc_pages_flags(order, AREA_DMA31 | flags);
-	if (!p || !test_facility(158))
+	if (!p || !uv_os_is_guest())
 		return p;
 
 	n = share_pages(p, 1 << order);
@@ -65,7 +66,7 @@ void free_io_mem(void *p, int size)
 
 	assert(IS_ALIGNED((uintptr_t)p, PAGE_SIZE));
 
-	if (test_facility(158))
+	if (uv_os_is_guest())
 		unshare_pages(p, 1 << order);
 	free_pages(p);
 }
diff --git a/s390x/uv-guest.c b/s390x/uv-guest.c
index 95a968c5..8915b2f1 100644
--- a/s390x/uv-guest.c
+++ b/s390x/uv-guest.c
@@ -16,6 +16,7 @@
 #include <asm/facility.h>
 #include <asm/uv.h>
 #include <sclp.h>
+#include <uv.h>
 
 static unsigned long page;
 
@@ -141,6 +142,11 @@ int main(void)
 		goto done;
 	}
 
+	if (!uv_os_is_guest()) {
+		report_skip("Not a protected guest");
+		goto done;
+	}
+
 	page = (unsigned long)alloc_page();
 	test_priv();
 	test_invalid();
-- 
2.27.0


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

* [kvm-unit-tests PATCH 5/6] s390x: uv-guest: Test invalid commands
  2021-03-16  9:16 [kvm-unit-tests PATCH 0/6] s390x: uv: Extend guest test and add host test Janosch Frank
                   ` (3 preceding siblings ...)
  2021-03-16  9:16 ` [kvm-unit-tests PATCH 4/6] s390x: Test for share/unshare call support before using them Janosch Frank
@ 2021-03-16  9:16 ` Janosch Frank
  2021-04-20 14:26   ` Claudio Imbrenda
  2021-03-16  9:16 ` [kvm-unit-tests PATCH 6/6] s390x: Add UV host test Janosch Frank
  2021-04-19  7:24 ` [kvm-unit-tests PATCH 0/6] s390x: uv: Extend guest test and add " Janosch Frank
  6 siblings, 1 reply; 23+ messages in thread
From: Janosch Frank @ 2021-03-16  9:16 UTC (permalink / raw)
  To: kvm; +Cc: linux-s390, thuth, david, imbrenda

Let's check if the commands that are not indicated as available
produce a invalid command error.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
 s390x/uv-guest.c | 44 +++++++++++++++++++++++++++++++++++++-------
 1 file changed, 37 insertions(+), 7 deletions(-)

diff --git a/s390x/uv-guest.c b/s390x/uv-guest.c
index 8915b2f1..517e3c66 100644
--- a/s390x/uv-guest.c
+++ b/s390x/uv-guest.c
@@ -120,16 +120,46 @@ static void test_sharing(void)
 	report_prefix_pop();
 }
 
+static struct {
+	const char *name;
+	uint16_t cmd;
+	uint16_t len;
+} invalid_cmds[] = {
+	{ "bogus", 0x4242, sizeof(struct uv_cb_header) },
+	{ "init", UVC_CMD_INIT_UV, sizeof(struct uv_cb_init) },
+	{ "create conf", UVC_CMD_CREATE_SEC_CONF, sizeof(struct uv_cb_cgc) },
+	{ "destroy conf", UVC_CMD_DESTROY_SEC_CONF, sizeof(struct uv_cb_nodata) },
+	{ "create cpu", UVC_CMD_CREATE_SEC_CPU, sizeof(struct uv_cb_csc) },
+	{ "destroy cpu", UVC_CMD_DESTROY_SEC_CPU, sizeof(struct uv_cb_nodata) },
+	{ "conv to", UVC_CMD_CONV_TO_SEC_STOR, sizeof(struct uv_cb_cts) },
+	{ "conv from", UVC_CMD_CONV_FROM_SEC_STOR, sizeof(struct uv_cb_cfs) },
+	{ "set sec conf", UVC_CMD_SET_SEC_CONF_PARAMS, sizeof(struct uv_cb_ssc) },
+	{ "unpack", UVC_CMD_UNPACK_IMG, sizeof(struct uv_cb_unp) },
+	{ "verify", UVC_CMD_VERIFY_IMG, sizeof(struct uv_cb_nodata) },
+	{ "cpu reset", UVC_CMD_CPU_RESET, sizeof(struct uv_cb_nodata) },
+	{ "cpu initial reset", UVC_CMD_CPU_RESET_INITIAL, sizeof(struct uv_cb_nodata) },
+	{ "conf clear reset", UVC_CMD_PERF_CONF_CLEAR_RESET, sizeof(struct uv_cb_nodata) },
+	{ "cpu clear reset", UVC_CMD_CPU_RESET_CLEAR, sizeof(struct uv_cb_nodata) },
+	{ "cpu set state", UVC_CMD_CPU_SET_STATE, sizeof(struct uv_cb_cpu_set_state) },
+	{ "pin shared", UVC_CMD_PIN_PAGE_SHARED, sizeof(struct uv_cb_cfs) },
+	{ "unpin shared", UVC_CMD_UNPIN_PAGE_SHARED, sizeof(struct uv_cb_cts) },
+	{ NULL, 0, 0 },
+};
+
 static void test_invalid(void)
 {
-	struct uv_cb_header uvcb = {
-		.len = 16,
-		.cmd = 0x4242,
-	};
-	int cc;
+	struct uv_cb_header *hdr = (void *)page;
+	int cc, i;
 
-	cc = uv_call(0, (u64)&uvcb);
-	report(cc == 1 && uvcb.rc == UVC_RC_INV_CMD, "invalid command");
+	report_prefix_push("invalid");
+	for (i = 0; invalid_cmds[i].name; i++) {
+		hdr->cmd = invalid_cmds[i].cmd;
+		hdr->len = invalid_cmds[i].len;
+		cc = uv_call(0, (u64)hdr);
+		report(cc == 1 && hdr->rc == UVC_RC_INV_CMD, "%s",
+		       invalid_cmds[i].name);
+	}
+	report_prefix_pop();
 }
 
 int main(void)
-- 
2.27.0


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

* [kvm-unit-tests PATCH 6/6] s390x: Add UV host test
  2021-03-16  9:16 [kvm-unit-tests PATCH 0/6] s390x: uv: Extend guest test and add host test Janosch Frank
                   ` (4 preceding siblings ...)
  2021-03-16  9:16 ` [kvm-unit-tests PATCH 5/6] s390x: uv-guest: Test invalid commands Janosch Frank
@ 2021-03-16  9:16 ` Janosch Frank
  2021-04-20 15:47   ` Claudio Imbrenda
  2021-04-19  7:24 ` [kvm-unit-tests PATCH 0/6] s390x: uv: Extend guest test and add " Janosch Frank
  6 siblings, 1 reply; 23+ messages in thread
From: Janosch Frank @ 2021-03-16  9:16 UTC (permalink / raw)
  To: kvm; +Cc: linux-s390, thuth, david, imbrenda

Let's also test the UV host interfaces.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
 s390x/Makefile  |   1 +
 s390x/uv-host.c | 513 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 514 insertions(+)
 create mode 100644 s390x/uv-host.c

diff --git a/s390x/Makefile b/s390x/Makefile
index bbf177fa..8de926ab 100644
--- a/s390x/Makefile
+++ b/s390x/Makefile
@@ -21,6 +21,7 @@ tests += $(TEST_DIR)/css.elf
 tests += $(TEST_DIR)/uv-guest.elf
 tests += $(TEST_DIR)/sie.elf
 tests += $(TEST_DIR)/mvpg.elf
+tests += $(TEST_DIR)/uv-host.elf
 
 tests_binary = $(patsubst %.elf,%.bin,$(tests))
 ifneq ($(HOST_KEY_DOCUMENT),)
diff --git a/s390x/uv-host.c b/s390x/uv-host.c
new file mode 100644
index 00000000..746abd8e
--- /dev/null
+++ b/s390x/uv-host.c
@@ -0,0 +1,513 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Guest Ultravisor Call tests
+ *
+ * Copyright (c) 2021 IBM Corp
+ *
+ * Authors:
+ *  Janosch Frank <frankja@linux.ibm.com>
+ */
+
+#include <libcflat.h>
+#include <alloc.h>
+#include <vmalloc.h>
+#include <sclp.h>
+#include <smp.h>
+#include <asm/page.h>
+#include <asm/sigp.h>
+#include <asm/pgtable.h>
+#include <asm/asm-offsets.h>
+#include <asm/interrupt.h>
+#include <asm/facility.h>
+#include <asm/uv.h>
+#include <asm-generic/barrier.h>
+
+static struct uv_cb_qui uvcb_qui;
+static struct uv_cb_init uvcb_init;
+static struct uv_cb_cgc uvcb_cgc;
+static struct uv_cb_csc uvcb_csc;
+
+extern int diag308_load_reset(u64 code);
+
+struct cmd_list{
+	const char *name;
+	uint16_t cmd;
+	uint16_t len;
+};
+
+static void cpu_loop(void)
+{
+	for (;;) {}
+}
+
+static struct cmd_list cmds[] = {
+	{ "init", UVC_CMD_INIT_UV, sizeof(struct uv_cb_init) },
+	{ "create conf", UVC_CMD_CREATE_SEC_CONF, sizeof(struct uv_cb_cgc) },
+	{ "destroy conf", UVC_CMD_DESTROY_SEC_CONF, sizeof(struct uv_cb_nodata) },
+	{ "create cpu", UVC_CMD_CREATE_SEC_CPU, sizeof(struct uv_cb_csc) },
+	{ "destroy cpu", UVC_CMD_DESTROY_SEC_CPU, sizeof(struct uv_cb_nodata) },
+	{ "conv to", UVC_CMD_CONV_TO_SEC_STOR, sizeof(struct uv_cb_cts) },
+	{ "conv from", UVC_CMD_CONV_FROM_SEC_STOR, sizeof(struct uv_cb_cfs) },
+	{ "set sec conf", UVC_CMD_SET_SEC_CONF_PARAMS, sizeof(struct uv_cb_ssc) },
+	{ "unpack", UVC_CMD_UNPACK_IMG, sizeof(struct uv_cb_unp) },
+	{ "verify", UVC_CMD_VERIFY_IMG, sizeof(struct uv_cb_nodata) },
+	{ "cpu reset", UVC_CMD_CPU_RESET, sizeof(struct uv_cb_nodata) },
+	{ "cpu initial reset", UVC_CMD_CPU_RESET_INITIAL, sizeof(struct uv_cb_nodata) },
+	{ "conf clear reset", UVC_CMD_PERF_CONF_CLEAR_RESET, sizeof(struct uv_cb_nodata) },
+	{ "cpu clear reset", UVC_CMD_CPU_RESET_CLEAR, sizeof(struct uv_cb_nodata) },
+	{ "cpu set state", UVC_CMD_CPU_SET_STATE, sizeof(struct uv_cb_cpu_set_state) },
+	{ "pin shared", UVC_CMD_PIN_PAGE_SHARED, sizeof(struct uv_cb_cfs) },
+	{ "unpin shared", UVC_CMD_UNPIN_PAGE_SHARED, sizeof(struct uv_cb_cts) },
+	{ NULL, 0, 0 },
+};
+
+static void test_priv(void)
+{
+	struct uv_cb_header uvcb = {};
+	uint16_t pgm;
+	int i;
+
+	report_prefix_push("privileged");
+	for (i = 0; cmds[i].name; i++) {
+		expect_pgm_int();
+		uvcb.cmd = cmds[i].cmd;
+		uvcb.len = cmds[i].len;
+		enter_pstate();
+		uv_call(0, (uint64_t)&uvcb);
+		pgm = clear_pgm_int();
+		report(pgm == PGM_INT_CODE_PRIVILEGED_OPERATION, "%s", cmds[i].name);
+	}
+	report_prefix_pop();
+}
+
+static void test_config_destroy(void)
+{
+	int rc;
+	struct uv_cb_nodata uvcb = {
+		.header.cmd = UVC_CMD_DESTROY_SEC_CONF,
+		.header.len = sizeof(uvcb),
+		.handle = uvcb_cgc.guest_handle,
+	};
+
+	report_prefix_push("dsc");
+	uvcb.header.len -= 8;
+	rc = uv_call(0, (uint64_t)&uvcb);
+	report(rc == 1 && uvcb.header.rc == UVC_RC_INV_LEN,
+	       "hdr invalid length");
+	uvcb.header.len += 8;
+
+	uvcb.handle += 1;
+	rc = uv_call(0, (uint64_t)&uvcb);
+	report(rc == 1 && uvcb.header.rc == UVC_RC_INV_GHANDLE, "invalid handle");
+	uvcb.handle -= 1;
+
+	rc = uv_call(0, (uint64_t)&uvcb);
+	report(rc == 0 && uvcb.header.rc == UVC_RC_EXECUTED, "success");
+	report_prefix_pop();
+}
+
+static void test_cpu_destroy(void)
+{
+	int rc;
+	struct uv_cb_nodata uvcb = {
+		.header.len = sizeof(uvcb),
+		.header.cmd = UVC_CMD_DESTROY_SEC_CPU,
+		.handle = uvcb_csc.cpu_handle,
+	};
+
+	report_prefix_push("dcpu");
+
+	uvcb.header.len -= 8;
+	rc = uv_call(0, (uint64_t)&uvcb);
+	report(rc == 1 && uvcb.header.rc == UVC_RC_INV_LEN,
+	       "hdr invalid length");
+	uvcb.header.len += 8;
+
+	uvcb.handle += 1;
+	rc = uv_call(0, (uint64_t)&uvcb);
+	report(rc == 1 && uvcb.header.rc == UVC_RC_INV_CHANDLE, "invalid handle");
+	uvcb.handle -= 1;
+
+	rc = uv_call(0, (uint64_t)&uvcb);
+	report(rc == 0 && uvcb.header.rc == UVC_RC_EXECUTED, "success");
+
+	report_prefix_pop();
+}
+
+static void test_cpu_create(void)
+{
+	int rc;
+	unsigned long tmp;
+
+	report_prefix_push("csc");
+	uvcb_csc.header.len = sizeof(uvcb_csc);
+	uvcb_csc.header.cmd = UVC_CMD_CREATE_SEC_CPU;
+	uvcb_csc.guest_handle = uvcb_cgc.guest_handle;
+	uvcb_csc.stor_origin = (unsigned long)memalign(PAGE_SIZE, uvcb_qui.cpu_stor_len);
+	uvcb_csc.state_origin = (unsigned long)memalign(PAGE_SIZE, PAGE_SIZE);
+
+	uvcb_csc.header.len -= 8;
+	rc = uv_call(0, (uint64_t)&uvcb_csc);
+	report(uvcb_csc.header.rc == UVC_RC_INV_LEN && rc == 1 &&
+	       !uvcb_csc.cpu_handle, "hdr invalid length");
+	uvcb_csc.header.len += 8;
+
+	uvcb_csc.guest_handle += 1;
+	rc = uv_call(0, (uint64_t)&uvcb_csc);
+	report(uvcb_csc.header.rc == UVC_RC_INV_GHANDLE && rc == 1,
+	       "invalid guest handle");
+	uvcb_csc.guest_handle -= 1;
+
+	uvcb_csc.num = uvcb_qui.max_guest_cpus + 1;
+	rc = uv_call(0, (uint64_t)&uvcb_csc);
+	report(uvcb_csc.header.rc == 0x103 && rc == 1,
+	       "invalid cpu #");
+	uvcb_csc.num = 0;
+
+	tmp = uvcb_csc.stor_origin;
+	uvcb_csc.stor_origin = get_max_ram_size() + PAGE_SIZE;
+	rc = uv_call(0, (uint64_t)&uvcb_csc);
+	report(uvcb_csc.header.rc == 0x105 && rc == 1,
+	       "cpu stor inaccessible");
+	uvcb_csc.stor_origin = tmp;
+
+	tmp = uvcb_csc.stor_origin;
+	uvcb_csc.stor_origin = 0;
+	rc = uv_call(0, (uint64_t)&uvcb_csc);
+	report(uvcb_csc.header.rc == 0x106 && rc == 1,
+	       "cpu stor in lowcore");
+	uvcb_csc.stor_origin = tmp;
+
+	tmp = uvcb_csc.state_origin;
+	uvcb_csc.state_origin = get_max_ram_size() + PAGE_SIZE;
+	rc = uv_call(0, (uint64_t)&uvcb_csc);
+	report(uvcb_csc.header.rc == 0x107 && rc == 1,
+	       "SIE SD inaccessible");
+	uvcb_csc.state_origin = tmp;
+
+	rc = uv_call(0, (uint64_t)&uvcb_csc);
+	report(rc == 0 && uvcb_csc.header.rc == UVC_RC_EXECUTED &&
+	       uvcb_csc.cpu_handle, "success");
+
+	tmp = uvcb_csc.stor_origin;
+	uvcb_csc.stor_origin = (unsigned long)memalign(PAGE_SIZE, uvcb_qui.cpu_stor_len);
+	rc = uv_call(0, (uint64_t)&uvcb_csc);
+	report(rc == 1 && uvcb_csc.header.rc == 0x104, "already defined");
+	uvcb_csc.stor_origin = tmp;
+	report_prefix_pop();
+}
+
+static void test_config_create(void)
+{
+	int rc;
+	unsigned long vsize, tmp;
+	static struct uv_cb_cgc uvcb;
+
+	uvcb_cgc.header.cmd = UVC_CMD_CREATE_SEC_CONF;
+	uvcb_cgc.header.len = sizeof(uvcb_cgc);
+	report_prefix_push("cgc");
+
+	uvcb_cgc.guest_stor_origin = 0;
+	uvcb_cgc.guest_stor_len = 42 * (1UL << 20);
+	vsize = uvcb_qui.conf_base_virt_stor_len +
+		((uvcb_cgc.guest_stor_len / (1UL << 20)) * uvcb_qui.conf_virt_var_stor_len);
+
+	uvcb_cgc.conf_base_stor_origin = (uint64_t)memalign(PAGE_SIZE * 4, uvcb_qui.conf_base_phys_stor_len);
+	uvcb_cgc.conf_var_stor_origin = (uint64_t)memalign(PAGE_SIZE, vsize);
+	uvcb_cgc.guest_asce = (uint64_t)memalign(PAGE_SIZE, 4 * PAGE_SIZE) | ASCE_DT_SEGMENT | REGION_TABLE_LENGTH | ASCE_P;
+	uvcb_cgc.guest_sca = (uint64_t)memalign(PAGE_SIZE * 4, PAGE_SIZE * 4);
+
+	uvcb_cgc.header.len -= 8;
+	rc = uv_call(0, (uint64_t)&uvcb_cgc);
+	report(uvcb_cgc.header.rc == UVC_RC_INV_LEN && rc == 1 &&
+	       !uvcb_cgc.guest_handle, "hdr invalid length");
+	uvcb_cgc.header.len += 8;
+
+	uvcb_cgc.guest_stor_origin = uvcb_qui.max_guest_stor_addr + (1UL << 20) * 2 + 1;
+	rc = uv_call(0, (uint64_t)&uvcb_cgc);
+	report(uvcb_cgc.header.rc == 0x101 && rc == 1,
+	       "MSO > max guest addr");
+	uvcb_cgc.guest_stor_origin = 0;
+
+	uvcb_cgc.guest_stor_origin = uvcb_qui.max_guest_stor_addr - (1UL << 20);
+	rc = uv_call(0, (uint64_t)&uvcb_cgc);
+	report(uvcb_cgc.header.rc == 0x102 && rc == 1,
+	       "MSO + MSL > max guest addr");
+	uvcb_cgc.guest_stor_origin = 0;
+
+	uvcb_cgc.guest_asce &= ~ASCE_P;
+	rc = uv_call(0, (uint64_t)&uvcb_cgc);
+	report(uvcb_cgc.header.rc == 0x105 && rc == 1,
+	       "ASCE private bit missing");
+	uvcb_cgc.guest_asce |= ASCE_P;
+
+	uvcb_cgc.guest_asce |= 0x20;
+	rc = uv_call(0, (uint64_t)&uvcb_cgc);
+	report(uvcb_cgc.header.rc == 0x105 && rc == 1,
+	       "ASCE bit 58 set");
+	uvcb_cgc.guest_asce &= ~0x20;
+
+	tmp = uvcb_cgc.conf_base_stor_origin;
+	uvcb_cgc.conf_base_stor_origin = get_max_ram_size() + 8;
+	rc = uv_call(0, (uint64_t)&uvcb_cgc);
+	report(uvcb_cgc.header.rc == 0x108 && rc == 1,
+	       "base storage origin > available memory");
+	uvcb_cgc.conf_base_stor_origin = tmp;
+
+	tmp = uvcb_cgc.conf_base_stor_origin;
+	uvcb_cgc.conf_base_stor_origin = 0x1000;
+	rc = uv_call(0, (uint64_t)&uvcb_cgc);
+	report(uvcb_cgc.header.rc == 0x109 && rc == 1,
+	       "base storage origin contains lowcore");
+	uvcb_cgc.conf_base_stor_origin = tmp;
+
+	if (smp_query_num_cpus() == 1) {
+		sigp_retry(1, SIGP_SET_PREFIX,
+			   uvcb_cgc.conf_var_stor_origin + PAGE_SIZE, NULL);
+		rc = uv_call(0, (uint64_t)&uvcb_cgc);
+		report(uvcb_cgc.header.rc == 0x10e && rc == 1 &&
+		       !uvcb_cgc.guest_handle, "variable storage area contains lowcore");
+		sigp_retry(1, SIGP_SET_PREFIX, 0x0, NULL);
+	}
+
+	tmp = uvcb_cgc.guest_sca;
+	uvcb_cgc.guest_sca = 0;
+	rc = uv_call(0, (uint64_t)&uvcb_cgc);
+	report(uvcb_cgc.header.rc == 0x10c && rc == 1,
+	       "sca == 0");
+	uvcb_cgc.guest_sca = tmp;
+
+	tmp = uvcb_cgc.guest_sca;
+	uvcb_cgc.guest_sca = get_max_ram_size() + + PAGE_SIZE * 4;
+	rc = uv_call(0, (uint64_t)&uvcb_cgc);
+	report(uvcb_cgc.header.rc == 0x10d && rc == 1,
+	       "sca inaccessible");
+	uvcb_cgc.guest_sca = tmp;
+
+	rc = uv_call(0, (uint64_t)&uvcb_cgc);
+	report(rc == 0 && uvcb_cgc.header.rc == UVC_RC_EXECUTED, "successful");
+
+	uvcb_cgc.header.rc = 0;
+	uvcb_cgc.header.rrc = 0;
+	tmp = uvcb_cgc.guest_handle;
+	uvcb_cgc.guest_handle = 0;
+	rc = uv_call(0, (uint64_t)&uvcb_cgc);
+	report(uvcb_cgc.header.rc >= 0x100 && rc == 1, "reuse uvcb");
+	uvcb_cgc.guest_handle = tmp;
+
+	/* Copy over most data from uvcb_cgc, so we have the ASCE that was used. */
+	memcpy(&uvcb, &uvcb_cgc, sizeof(uvcb));
+
+	/* Reset the header and handle */
+	uvcb.header.rc = 0;
+	uvcb.header.rrc = 0;
+	uvcb.guest_handle = 0;
+
+	/* Use new storage areas. */
+	uvcb.conf_base_stor_origin = (uint64_t)memalign(PAGE_SIZE * 4, uvcb_qui.conf_base_phys_stor_len);
+	uvcb.conf_var_stor_origin = (uint64_t)memalign(PAGE_SIZE, vsize);
+
+	rc = uv_call(0, (uint64_t)&uvcb);
+	report(uvcb.header.rc >= 0x104 && rc == 1 && !uvcb.guest_handle,
+	       "reuse ASCE");
+	free((void *)uvcb.conf_base_stor_origin);
+	free((void *)uvcb.conf_var_stor_origin);
+
+
+	/* Missing: 106, 10a, a0b */
+	report_prefix_pop();
+}
+
+static void test_init(void)
+{
+	int rc;
+	uint64_t mem;
+	struct psw psw;
+
+	/* Donated storage needs to be over 2GB */
+	mem = (uint64_t)memalign(1UL << 31, uvcb_qui.uv_base_stor_len);
+
+	uvcb_init.header.len = sizeof(uvcb_init);
+	uvcb_init.header.cmd = UVC_CMD_INIT_UV;
+	uvcb_init.stor_origin = mem;
+	uvcb_init.stor_len = uvcb_qui.uv_base_stor_len;
+
+	report_prefix_push("init");
+	uvcb_init.header.len -= 8;
+	rc = uv_call(0, (uint64_t)&uvcb_init);
+	report(rc == 1 && uvcb_init.header.rc == UVC_RC_INV_LEN,
+	       "hdr invalid length");
+	uvcb_init.header.len += 8;
+
+	uvcb_init.stor_len -= 8;
+	rc = uv_call(0, (uint64_t)&uvcb_init);
+	report(rc == 1 && uvcb_init.header.rc == 0x103,
+	       "storage invalid length");
+	uvcb_init.stor_len += 8;
+
+	uvcb_init.stor_origin =  get_max_ram_size() + 8;
+	rc = uv_call(0, (uint64_t)&uvcb_init);
+	report(rc == 1 && uvcb_init.header.rc == 0x104,
+	       "storage origin invalid");
+	uvcb_init.stor_origin = mem;
+
+	uvcb_init.stor_origin = get_max_ram_size() - 8;
+	rc = uv_call(0, (uint64_t)&uvcb_init);
+	report(rc == 1 && uvcb_init.header.rc == 0x105,
+	       "storage + length invalid");
+	uvcb_init.stor_origin = mem;
+
+	uvcb_init.stor_origin = 1UL << 30;
+	rc = uv_call(0, (uint64_t)&uvcb_init);
+	report(rc == 1 && uvcb_init.header.rc == 0x108,
+	       "storage below 2GB");
+	uvcb_init.stor_origin = mem;
+
+	psw.mask = extract_psw_mask();
+	psw.addr = (unsigned long)cpu_loop;
+	smp_cpu_setup(1, psw);
+	rc = uv_call(0, (uint64_t)&uvcb_init);
+	report(rc == 1 && uvcb_init.header.rc == 0x102,
+	       "too many running cpus");
+	smp_cpu_stop(1);
+
+	rc = uv_call(0, (uint64_t)&uvcb_init);
+	report(rc == 0 && uvcb_init.header.rc == UVC_RC_EXECUTED, "successful");
+
+	mem = (uint64_t)memalign(1UL << 31, uvcb_qui.uv_base_stor_len);
+	rc = uv_call(0, (uint64_t)&uvcb_init);
+	report(rc == 1 && uvcb_init.header.rc == 0x101, "double init");
+	free((void *)mem);
+
+	report_prefix_pop();
+}
+
+static void test_query(void)
+{
+	uvcb_qui.header.cmd = UVC_CMD_QUI;
+	uvcb_qui.header.len = sizeof(uvcb_qui);
+	uint64_t *call_list = &uvcb_qui.inst_calls_list[0];
+
+	report_prefix_push("query");
+	uvcb_qui.header.len = 0xa0;
+	uv_call(0, (uint64_t)&uvcb_qui);
+	report(uvcb_qui.header.rc == UVC_RC_INV_LEN, "length");
+
+	uvcb_qui.header.len = 0xa8;
+	uv_call(0, (uint64_t)&uvcb_qui);
+	report(uvcb_qui.header.rc == 0x100, "insf length");
+
+	uvcb_qui.header.len = sizeof(uvcb_qui);
+	uv_call(0, (uint64_t)&uvcb_qui);
+	report(uvcb_qui.header.rc == UVC_RC_EXECUTED, "successful query");
+
+	report(test_bit_inv(BIT_UVC_CMD_QUI, call_list) &&
+	       test_bit_inv(BIT_UVC_CMD_INIT_UV, call_list),
+	       "query and init indicated");
+
+	report(test_bit_inv(BIT_UVC_CMD_CREATE_SEC_CONF, call_list) &&
+	       test_bit_inv(BIT_UVC_CMD_DESTROY_SEC_CONF, call_list),
+	       "create/destroy vm indicated");
+
+	report(test_bit_inv(BIT_UVC_CMD_CREATE_SEC_CPU, call_list) &&
+	       test_bit_inv(BIT_UVC_CMD_DESTROY_SEC_CPU, call_list),
+	       "create/destroy cpu indicated");
+
+	report(test_bit_inv(BIT_UVC_CMD_CONV_TO_SEC_STOR, call_list) &&
+	       test_bit_inv(BIT_UVC_CMD_CONV_FROM_SEC_STOR, call_list),
+	       "convert to/from secure storage indicated");
+
+	report(test_bit_inv(BIT_UVC_CMD_SET_SEC_PARMS, call_list) &&
+	       test_bit_inv(BIT_UVC_CMD_UNPACK_IMG, call_list) &&
+	       test_bit_inv(BIT_UVC_CMD_CPU_SET_STATE, call_list) &&
+	       test_bit_inv(BIT_UVC_CMD_VERIFY_IMG, call_list),
+	       "set sec parm, setcpu state, unpack and verify indicated");
+
+	report(test_bit_inv(BIT_UVC_CMD_CPU_RESET, call_list) &&
+	       test_bit_inv(BIT_UVC_CMD_CPU_RESET_INITIAL, call_list) &&
+	       test_bit_inv(BIT_UVC_CMD_CPU_PERFORM_CLEAR_RESET, call_list),
+	       "resets indicated");
+
+	report(test_bit_inv(BIT_UVC_CMD_PREPARE_CLEAR_RESET, call_list) &&
+	       test_bit_inv(BIT_UVC_CMD_UNSHARE_ALL, call_list),
+	       "prepare reset and unshare all indicated");
+
+	report(test_bit_inv(BIT_UVC_CMD_PIN_PAGE_SHARED, call_list) &&
+	       test_bit_inv(BIT_UVC_CMD_UNPIN_PAGE_SHARED, call_list),
+	       "(un)pin shared page indicated");
+
+	report(!test_bit_inv(BIT_UVC_CMD_SET_SHARED_ACCESS, call_list) &&
+	       !test_bit_inv(BIT_UVC_CMD_REMOVE_SHARED_ACCESS, call_list),
+	       "(un)share not indicated");
+
+	report_prefix_pop();
+}
+
+static struct cmd_list invalid_cmds[] = {
+	{ "bogus", 0x4242, sizeof(struct uv_cb_header) },
+	{ "share", UVC_CMD_SET_SHARED_ACCESS, sizeof(struct uv_cb_share) },
+	{ "unshare", UVC_CMD_REMOVE_SHARED_ACCESS, sizeof(struct uv_cb_share) },
+	{ NULL, 0, 0 },
+};
+
+static void test_invalid(void)
+{
+	struct uv_cb_header hdr = {};
+	int i, cc;
+
+	report_prefix_push("invalid");
+	for (i = 0; invalid_cmds[i].name; i++) {
+		hdr.cmd = invalid_cmds[i].cmd;
+		hdr.len = invalid_cmds[i].len;
+		cc = uv_call(0, (uint64_t)&hdr);
+		report(cc == 1 && hdr.rc == UVC_RC_INV_CMD, "%s",
+		       invalid_cmds[i].name);
+	}
+	report_prefix_pop();
+}
+
+static void test_clear(void)
+{
+	uint64_t *tmp = (void *)uvcb_init.stor_origin;
+
+	diag308_load_reset(1);
+	sclp_console_setup();
+	report(!*tmp, "memory cleared after reset 1");
+}
+
+static void setup_vmem(void)
+{
+	uint64_t asce, mask;
+
+	setup_mmu(get_max_ram_size());
+	asce = stctg(1);
+	lctlg(13, asce);
+	mask = extract_psw_mask() | 0x0000C00000000000UL;
+	load_psw_mask(mask);
+}
+
+int main(void)
+{
+	bool has_uvc = test_facility(158);
+
+	report_prefix_push("uvc");
+	if (!has_uvc) {
+		report_skip("Ultravisor call facility is not available");
+		goto done;
+	}
+
+	test_priv();
+	test_invalid();
+	test_query();
+	test_init();
+
+	setup_vmem();
+	test_config_create();
+	test_cpu_create();
+	test_cpu_destroy();
+	test_config_destroy();
+	test_clear();
+
+done:
+	return report_summary();
+}
-- 
2.27.0


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

* Re: [kvm-unit-tests PATCH 0/6] s390x: uv: Extend guest test and add host test
  2021-03-16  9:16 [kvm-unit-tests PATCH 0/6] s390x: uv: Extend guest test and add host test Janosch Frank
                   ` (5 preceding siblings ...)
  2021-03-16  9:16 ` [kvm-unit-tests PATCH 6/6] s390x: Add UV host test Janosch Frank
@ 2021-04-19  7:24 ` Janosch Frank
  6 siblings, 0 replies; 23+ messages in thread
From: Janosch Frank @ 2021-04-19  7:24 UTC (permalink / raw)
  To: kvm; +Cc: linux-s390, thuth, david, imbrenda

On 3/16/21 10:16 AM, Janosch Frank wrote:
> My stack of patches is starting to lean, so lets try to put some of
> them upstream...
> 
> The first part is just additions to the UV guest test and a library
> that makes checking the installed UV calls easier. Additionally we now
> check for the proper UV share/unshare availability when allocating IO
> memory instead of only relying on stfle 158.
> 
> The second part adds a UV host test with a large number UV of return
> code checks. This is currently a guest 1 test.

Ping

> 
> Janosch Frank (6):
>   s390x: uv-guest: Add invalid share location test
>   s390x: Add more Ultravisor command structure definitions
>   s390x: uv: Add UV lib
>   s390x: Test for share/unshare call support before using them
>   s390x: uv-guest: Test invalid commands
>   s390x: Add UV host test
> 
>  lib/s390x/asm/uv.h    | 152 ++++++++++++-
>  lib/s390x/io.c        |   2 +
>  lib/s390x/malloc_io.c |   5 +-
>  lib/s390x/uv.c        |  48 ++++
>  lib/s390x/uv.h        |  10 +
>  s390x/Makefile        |   2 +
>  s390x/uv-guest.c      |  57 ++++-
>  s390x/uv-host.c       | 513 ++++++++++++++++++++++++++++++++++++++++++
>  8 files changed, 776 insertions(+), 13 deletions(-)
>  create mode 100644 lib/s390x/uv.c
>  create mode 100644 lib/s390x/uv.h
>  create mode 100644 s390x/uv-host.c
> 


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

* Re: [kvm-unit-tests PATCH 1/6] s390x: uv-guest: Add invalid share location test
  2021-03-16  9:16 ` [kvm-unit-tests PATCH 1/6] s390x: uv-guest: Add invalid share location test Janosch Frank
@ 2021-04-19 11:24   ` Thomas Huth
  2021-04-19 11:45     ` Janosch Frank
  2021-04-20 13:40   ` Claudio Imbrenda
  2021-04-21 11:04   ` Cornelia Huck
  2 siblings, 1 reply; 23+ messages in thread
From: Thomas Huth @ 2021-04-19 11:24 UTC (permalink / raw)
  To: Janosch Frank, kvm; +Cc: linux-s390, david, imbrenda

On 16/03/2021 10.16, Janosch Frank wrote:
> Let's also test sharing unavailable memory.
> 
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
> ---
>   s390x/uv-guest.c | 5 +++++
>   1 file changed, 5 insertions(+)
> 
> diff --git a/s390x/uv-guest.c b/s390x/uv-guest.c
> index 99544442..a13669ab 100644
> --- a/s390x/uv-guest.c
> +++ b/s390x/uv-guest.c
> @@ -15,6 +15,7 @@
>   #include <asm/interrupt.h>
>   #include <asm/facility.h>
>   #include <asm/uv.h>
> +#include <sclp.h>
>   
>   static unsigned long page;
>   
> @@ -99,6 +100,10 @@ static void test_sharing(void)
>   	uvcb.header.len = sizeof(uvcb);
>   	cc = uv_call(0, (u64)&uvcb);
>   	report(cc == 0 && uvcb.header.rc == UVC_RC_EXECUTED, "share");
> +	uvcb.paddr = get_ram_size() + PAGE_SIZE;
> +	cc = uv_call(0, (u64)&uvcb);
> +	report(cc == 1 && uvcb.header.rc == 0x101, "invalid memory");

Would it make sense to add a #define for 0x101 ?

Anyway:
Reviewed-by: Thomas Huth <thuth@redhat.com>


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

* Re: [kvm-unit-tests PATCH 1/6] s390x: uv-guest: Add invalid share location test
  2021-04-19 11:24   ` Thomas Huth
@ 2021-04-19 11:45     ` Janosch Frank
  2021-04-20  8:48       ` Thomas Huth
  0 siblings, 1 reply; 23+ messages in thread
From: Janosch Frank @ 2021-04-19 11:45 UTC (permalink / raw)
  To: Thomas Huth, kvm; +Cc: linux-s390, david, imbrenda

On 4/19/21 1:24 PM, Thomas Huth wrote:
> On 16/03/2021 10.16, Janosch Frank wrote:
>> Let's also test sharing unavailable memory.
>>
>> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
>> ---
>>   s390x/uv-guest.c | 5 +++++
>>   1 file changed, 5 insertions(+)
>>
>> diff --git a/s390x/uv-guest.c b/s390x/uv-guest.c
>> index 99544442..a13669ab 100644
>> --- a/s390x/uv-guest.c
>> +++ b/s390x/uv-guest.c
>> @@ -15,6 +15,7 @@
>>   #include <asm/interrupt.h>
>>   #include <asm/facility.h>
>>   #include <asm/uv.h>
>> +#include <sclp.h>
>>   
>>   static unsigned long page;
>>   
>> @@ -99,6 +100,10 @@ static void test_sharing(void)
>>   	uvcb.header.len = sizeof(uvcb);
>>   	cc = uv_call(0, (u64)&uvcb);
>>   	report(cc == 0 && uvcb.header.rc == UVC_RC_EXECUTED, "share");
>> +	uvcb.paddr = get_ram_size() + PAGE_SIZE;
>> +	cc = uv_call(0, (u64)&uvcb);
>> +	report(cc == 1 && uvcb.header.rc == 0x101, "invalid memory");
> 
> Would it make sense to add a #define for 0x101 ?
> 

The RCs change meaning with each UV call so we can only re-use a small
number of constants which wouldn't gain us a lot.

> Anyway:
> Reviewed-by: Thomas Huth <thuth@redhat.com>

Thanks!


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

* Re: [kvm-unit-tests PATCH 1/6] s390x: uv-guest: Add invalid share location test
  2021-04-19 11:45     ` Janosch Frank
@ 2021-04-20  8:48       ` Thomas Huth
  0 siblings, 0 replies; 23+ messages in thread
From: Thomas Huth @ 2021-04-20  8:48 UTC (permalink / raw)
  To: Janosch Frank, kvm; +Cc: linux-s390, david, imbrenda

On 19/04/2021 13.45, Janosch Frank wrote:
> On 4/19/21 1:24 PM, Thomas Huth wrote:
>> On 16/03/2021 10.16, Janosch Frank wrote:
>>> Let's also test sharing unavailable memory.
>>>
>>> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
>>> ---
>>>    s390x/uv-guest.c | 5 +++++
>>>    1 file changed, 5 insertions(+)
>>>
>>> diff --git a/s390x/uv-guest.c b/s390x/uv-guest.c
>>> index 99544442..a13669ab 100644
>>> --- a/s390x/uv-guest.c
>>> +++ b/s390x/uv-guest.c
>>> @@ -15,6 +15,7 @@
>>>    #include <asm/interrupt.h>
>>>    #include <asm/facility.h>
>>>    #include <asm/uv.h>
>>> +#include <sclp.h>
>>>    
>>>    static unsigned long page;
>>>    
>>> @@ -99,6 +100,10 @@ static void test_sharing(void)
>>>    	uvcb.header.len = sizeof(uvcb);
>>>    	cc = uv_call(0, (u64)&uvcb);
>>>    	report(cc == 0 && uvcb.header.rc == UVC_RC_EXECUTED, "share");
>>> +	uvcb.paddr = get_ram_size() + PAGE_SIZE;
>>> +	cc = uv_call(0, (u64)&uvcb);
>>> +	report(cc == 1 && uvcb.header.rc == 0x101, "invalid memory");
>>
>> Would it make sense to add a #define for 0x101 ?
>>
> 
> The RCs change meaning with each UV call so we can only re-use a small
> number of constants which wouldn't gain us a lot.

Ok, fair point. A define just for one spot does not make too much sense, indeed.

  Thomas


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

* Re: [kvm-unit-tests PATCH 1/6] s390x: uv-guest: Add invalid share location test
  2021-03-16  9:16 ` [kvm-unit-tests PATCH 1/6] s390x: uv-guest: Add invalid share location test Janosch Frank
  2021-04-19 11:24   ` Thomas Huth
@ 2021-04-20 13:40   ` Claudio Imbrenda
  2021-04-21 11:04   ` Cornelia Huck
  2 siblings, 0 replies; 23+ messages in thread
From: Claudio Imbrenda @ 2021-04-20 13:40 UTC (permalink / raw)
  To: Janosch Frank; +Cc: kvm, linux-s390, thuth, david

On Tue, 16 Mar 2021 09:16:49 +0000
Janosch Frank <frankja@linux.ibm.com> wrote:

> Let's also test sharing unavailable memory.
> 
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>

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

> ---
>  s390x/uv-guest.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/s390x/uv-guest.c b/s390x/uv-guest.c
> index 99544442..a13669ab 100644
> --- a/s390x/uv-guest.c
> +++ b/s390x/uv-guest.c
> @@ -15,6 +15,7 @@
>  #include <asm/interrupt.h>
>  #include <asm/facility.h>
>  #include <asm/uv.h>
> +#include <sclp.h>
>  
>  static unsigned long page;
>  
> @@ -99,6 +100,10 @@ static void test_sharing(void)
>  	uvcb.header.len = sizeof(uvcb);
>  	cc = uv_call(0, (u64)&uvcb);
>  	report(cc == 0 && uvcb.header.rc == UVC_RC_EXECUTED,
> "share");
> +	uvcb.paddr = get_ram_size() + PAGE_SIZE;
> +	cc = uv_call(0, (u64)&uvcb);
> +	report(cc == 1 && uvcb.header.rc == 0x101, "invalid memory");
> +	uvcb.paddr = page;
>  	report_prefix_pop();
>  
>  	report_prefix_push("unshare");


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

* Re: [kvm-unit-tests PATCH 2/6] s390x: Add more Ultravisor command structure definitions
  2021-03-16  9:16 ` [kvm-unit-tests PATCH 2/6] s390x: Add more Ultravisor command structure definitions Janosch Frank
@ 2021-04-20 14:09   ` Claudio Imbrenda
  2021-04-21 11:13   ` Cornelia Huck
  1 sibling, 0 replies; 23+ messages in thread
From: Claudio Imbrenda @ 2021-04-20 14:09 UTC (permalink / raw)
  To: Janosch Frank; +Cc: kvm, linux-s390, thuth, david

On Tue, 16 Mar 2021 09:16:50 +0000
Janosch Frank <frankja@linux.ibm.com> wrote:

> They are needed in the new UV tests.
> 
> As we now extend the size of the query struct, we need to set the
> length in the UV guest query test to a constant instead of using
> sizeof.
> 
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>

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

> ---
>  lib/s390x/asm/uv.h | 148
> ++++++++++++++++++++++++++++++++++++++++++++- s390x/uv-guest.c   |
> 2 +- 2 files changed, 148 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/s390x/asm/uv.h b/lib/s390x/asm/uv.h
> index 9c491844..11f70a9f 100644
> --- a/lib/s390x/asm/uv.h
> +++ b/lib/s390x/asm/uv.h
> @@ -17,16 +17,54 @@
>  #define UVC_RC_INV_STATE	0x0003
>  #define UVC_RC_INV_LEN		0x0005
>  #define UVC_RC_NO_RESUME	0x0007
> +#define UVC_RC_INV_GHANDLE	0x0020
> +#define UVC_RC_INV_CHANDLE	0x0021
>  
>  #define UVC_CMD_QUI			0x0001
> +#define UVC_CMD_INIT_UV			0x000f
> +#define UVC_CMD_CREATE_SEC_CONF		0x0100
> +#define UVC_CMD_DESTROY_SEC_CONF	0x0101
> +#define UVC_CMD_CREATE_SEC_CPU		0x0120
> +#define UVC_CMD_DESTROY_SEC_CPU		0x0121
> +#define UVC_CMD_CONV_TO_SEC_STOR	0x0200
> +#define UVC_CMD_CONV_FROM_SEC_STOR	0x0201
> +#define UVC_CMD_SET_SEC_CONF_PARAMS	0x0300
> +#define UVC_CMD_UNPACK_IMG		0x0301
> +#define UVC_CMD_VERIFY_IMG		0x0302
> +#define UVC_CMD_CPU_RESET		0x0310
> +#define UVC_CMD_CPU_RESET_INITIAL	0x0311
> +#define UVC_CMD_PERF_CONF_CLEAR_RESET	0x0320
> +#define UVC_CMD_CPU_RESET_CLEAR		0x0321
> +#define UVC_CMD_CPU_SET_STATE		0x0330
> +#define UVC_CMD_SET_UNSHARED_ALL	0x0340
> +#define UVC_CMD_PIN_PAGE_SHARED		0x0341
> +#define UVC_CMD_UNPIN_PAGE_SHARED	0x0342
>  #define UVC_CMD_SET_SHARED_ACCESS	0x1000
>  #define UVC_CMD_REMOVE_SHARED_ACCESS	0x1001
>  
>  /* Bits in installed uv calls */
>  enum uv_cmds_inst {
>  	BIT_UVC_CMD_QUI = 0,
> +	BIT_UVC_CMD_INIT_UV = 1,
> +	BIT_UVC_CMD_CREATE_SEC_CONF = 2,
> +	BIT_UVC_CMD_DESTROY_SEC_CONF = 3,
> +	BIT_UVC_CMD_CREATE_SEC_CPU = 4,
> +	BIT_UVC_CMD_DESTROY_SEC_CPU = 5,
> +	BIT_UVC_CMD_CONV_TO_SEC_STOR = 6,
> +	BIT_UVC_CMD_CONV_FROM_SEC_STOR = 7,
>  	BIT_UVC_CMD_SET_SHARED_ACCESS = 8,
>  	BIT_UVC_CMD_REMOVE_SHARED_ACCESS = 9,
> +	BIT_UVC_CMD_SET_SEC_PARMS = 11,
> +	BIT_UVC_CMD_UNPACK_IMG = 13,
> +	BIT_UVC_CMD_VERIFY_IMG = 14,
> +	BIT_UVC_CMD_CPU_RESET = 15,
> +	BIT_UVC_CMD_CPU_RESET_INITIAL = 16,
> +	BIT_UVC_CMD_CPU_SET_STATE = 17,
> +	BIT_UVC_CMD_PREPARE_CLEAR_RESET = 18,
> +	BIT_UVC_CMD_CPU_PERFORM_CLEAR_RESET = 19,
> +	BIT_UVC_CMD_UNSHARE_ALL = 20,
> +	BIT_UVC_CMD_PIN_PAGE_SHARED = 21,
> +	BIT_UVC_CMD_UNPIN_PAGE_SHARED = 22,
>  };
>  
>  struct uv_cb_header {
> @@ -36,13 +74,81 @@ struct uv_cb_header {
>  	u16 rrc;	/* Return Reason Code */
>  } __attribute__((packed))  __attribute__((aligned(8)));
>  
> +struct uv_cb_init {
> +	struct uv_cb_header header;
> +	u64 reserved08[2];
> +	u64 stor_origin;
> +	u64 stor_len;
> +	u64 reserved28[4];
> +
> +} __attribute__((packed))  __attribute__((aligned(8)));
> +
>  struct uv_cb_qui {
>  	struct uv_cb_header header;
>  	u64 reserved08;
>  	u64 inst_calls_list[4];
> -	u64 reserved30[15];
> +	u64 reserved30[2];
> +	u64 uv_base_stor_len;
> +	u64 reserved48;
> +	u64 conf_base_phys_stor_len;
> +	u64 conf_base_virt_stor_len;
> +	u64 conf_virt_var_stor_len;
> +	u64 cpu_stor_len;
> +	u32 reserved70[3];
> +	u32 max_num_sec_conf;
> +	u64 max_guest_stor_addr;
> +	u8  reserved88[158 - 136];
> +	u16 max_guest_cpus;
> +	u8  reserveda0[200 - 160];
> +}  __attribute__((packed))  __attribute__((aligned(8)));
> +
> +struct uv_cb_cgc {
> +	struct uv_cb_header header;
> +	u64 reserved08[2];
> +	u64 guest_handle;
> +	u64 conf_base_stor_origin;
> +	u64 conf_var_stor_origin;
> +	u64 reserved30;
> +	u64 guest_stor_origin;
> +	u64 guest_stor_len;
> +	u64 guest_sca;
> +	u64 guest_asce;
> +	u64 reserved60[5];
>  } __attribute__((packed))  __attribute__((aligned(8)));
>  
> +struct uv_cb_csc {
> +	struct uv_cb_header header;
> +	u64 reserved08[2];
> +	u64 cpu_handle;
> +	u64 guest_handle;
> +	u64 stor_origin;
> +	u8  reserved30[6];
> +	u16 num;
> +	u64 state_origin;
> +	u64 reserved[4];
> +} __attribute__((packed))  __attribute__((aligned(8)));
> +
> +struct uv_cb_unp {
> +	struct uv_cb_header header;
> +	u64 reserved08[2];
> +	u64 guest_handle;
> +	u64 gaddr;
> +	u64 tweak[2];
> +	u64 reserved38[3];
> +} __attribute__((packed))  __attribute__((aligned(8)));
> +
> +/*
> + * A common UV call struct for the following calls:
> + * Destroy cpu/config
> + * Verify
> + */
> +struct uv_cb_nodata {
> +	struct uv_cb_header header;
> +	u64 reserved08[2];
> +	u64 handle;
> +	u64 reserved20[4];
> +}  __attribute__((packed))  __attribute__((aligned(8)));
> +
>  struct uv_cb_share {
>  	struct uv_cb_header header;
>  	u64 reserved08[3];
> @@ -50,6 +156,32 @@ struct uv_cb_share {
>  	u64 reserved28;
>  } __attribute__((packed))  __attribute__((aligned(8)));
>  
> +/* Convert to Secure */
> +struct uv_cb_cts {
> +	struct uv_cb_header header;
> +	u64 reserved08[2];
> +	u64 guest_handle;
> +	u64 gaddr;
> +}  __attribute__((packed))  __attribute__((aligned(8)));
> +
> +/* Convert from Secure / Pin Page Shared */
> +struct uv_cb_cfs {
> +	struct uv_cb_header header;
> +	u64 reserved08[2];
> +	u64 paddr;
> +}  __attribute__((packed))  __attribute__((aligned(8)));
> +
> +/* Set Secure Config Parameter */
> +struct uv_cb_ssc {
> +	struct uv_cb_header header;
> +	u64 reserved08[2];
> +	u64 guest_handle;
> +	u64 sec_header_origin;
> +	u32 sec_header_len;
> +	u32 reserved2c;
> +	u64 reserved30[4];
> +} __attribute__((packed))  __attribute__((aligned(8)));
> +
>  static inline int uv_call_once(unsigned long r1, unsigned long r2)
>  {
>  	int cc;
> @@ -118,4 +250,18 @@ static inline int uv_remove_shared(unsigned long
> addr) return share(addr, UVC_CMD_REMOVE_SHARED_ACCESS);
>  }
>  
> +struct uv_cb_cpu_set_state {
> +	struct uv_cb_header header;
> +	u64 reserved08[2];
> +	u64 cpu_handle;
> +	u8  reserved20[7];
> +	u8  state;
> +	u64 reserved28[5];
> +};
> +
> +#define PV_CPU_STATE_OPR	1
> +#define PV_CPU_STATE_STP	2
> +#define PV_CPU_STATE_CHKSTP	3
> +#define PV_CPU_STATE_OPR_LOAD	5
> +
>  #endif
> diff --git a/s390x/uv-guest.c b/s390x/uv-guest.c
> index a13669ab..95a968c5 100644
> --- a/s390x/uv-guest.c
> +++ b/s390x/uv-guest.c
> @@ -59,7 +59,7 @@ static void test_query(void)
>  {
>  	struct uv_cb_qui uvcb = {
>  		.header.cmd = UVC_CMD_QUI,
> -		.header.len = sizeof(uvcb) - 8,
> +		.header.len = 0xa0,
>  	};
>  	int cc;
>  


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

* Re: [kvm-unit-tests PATCH 3/6] s390x: uv: Add UV lib
  2021-03-16  9:16 ` [kvm-unit-tests PATCH 3/6] s390x: uv: Add UV lib Janosch Frank
@ 2021-04-20 14:15   ` Claudio Imbrenda
  2021-04-26 14:20     ` Janosch Frank
  0 siblings, 1 reply; 23+ messages in thread
From: Claudio Imbrenda @ 2021-04-20 14:15 UTC (permalink / raw)
  To: Janosch Frank; +Cc: kvm, linux-s390, thuth, david

On Tue, 16 Mar 2021 09:16:51 +0000
Janosch Frank <frankja@linux.ibm.com> wrote:

> Let's add a UV library to make checking the UV feature bit easier.
> In the future this library file can take care of handling UV
> initialization and UV guest creation.
> 
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>

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

but see some comments below

> ---
>  lib/s390x/asm/uv.h |  4 ++--
>  lib/s390x/io.c     |  2 ++
>  lib/s390x/uv.c     | 48
> ++++++++++++++++++++++++++++++++++++++++++++++ lib/s390x/uv.h     |
> 10 ++++++++++ s390x/Makefile     |  1 +
>  5 files changed, 63 insertions(+), 2 deletions(-)
>  create mode 100644 lib/s390x/uv.c
>  create mode 100644 lib/s390x/uv.h
> 
> diff --git a/lib/s390x/asm/uv.h b/lib/s390x/asm/uv.h
> index 11f70a9f..b22cbaa8 100644
> --- a/lib/s390x/asm/uv.h
> +++ b/lib/s390x/asm/uv.h
> @@ -9,8 +9,8 @@
>   * This code is free software; you can redistribute it and/or modify
> it
>   * under the terms of the GNU General Public License version 2.
>   */
> -#ifndef UV_H
> -#define UV_H
> +#ifndef ASM_S390X_UV_H
> +#define ASM_S390X_UV_H
>  
>  #define UVC_RC_EXECUTED		0x0001
>  #define UVC_RC_INV_CMD		0x0002
> diff --git a/lib/s390x/io.c b/lib/s390x/io.c
> index ef9f59e3..a4f1b113 100644
> --- a/lib/s390x/io.c
> +++ b/lib/s390x/io.c
> @@ -14,6 +14,7 @@
>  #include <asm/facility.h>
>  #include <asm/sigp.h>
>  #include "sclp.h"
> +#include "uv.h"
>  #include "smp.h"
>  
>  extern char ipl_args[];
> @@ -38,6 +39,7 @@ void setup(void)
>  	sclp_facilities_setup();
>  	sclp_console_setup();
>  	sclp_memory_setup();
> +	uv_setup();
>  	smp_setup();
>  }
>  
> diff --git a/lib/s390x/uv.c b/lib/s390x/uv.c
> new file mode 100644
> index 00000000..a84a85fc
> --- /dev/null
> +++ b/lib/s390x/uv.c
> @@ -0,0 +1,48 @@
> +#include <libcflat.h>
> +#include <bitops.h>
> +#include <alloc.h>
> +#include <alloc_page.h>
> +#include <asm/page.h>
> +#include <asm/arch_def.h>
> +
> +#include <asm/facility.h>
> +#include <asm/uv.h>
> +#include <uv.h>
> +
> +static struct uv_cb_qui uvcb_qui = {
> +	.header.cmd = UVC_CMD_QUI,
> +	.header.len = sizeof(uvcb_qui),
> +};
> +
> +bool uv_os_is_guest(void)
> +{
> +	return uv_query_test_feature(BIT_UVC_CMD_SET_SHARED_ACCESS)
> +		&&
> uv_query_test_feature(BIT_UVC_CMD_REMOVE_SHARED_ACCESS); +}
> +
> +bool uv_os_is_host(void)
> +{
> +	return uv_query_test_feature(BIT_UVC_CMD_INIT_UV);
> +}
> +
> +bool uv_query_test_feature(int nr)
> +{
> +	/* Query needs to be called first */
> +	if (!uvcb_qui.header.rc)
> +		return false;

why not an assert?

> +
> +	return test_bit_inv(nr, uvcb_qui.inst_calls_list);
> +}
> +
> +int uv_setup(void)
> +{
> +	int cc;
> +
> +	if (!test_facility(158))
> +		return 0;
> +
> +	cc = uv_call(0, (u64)&uvcb_qui);
> +	assert(cc == 0);
> +
> +	return cc == 0;

sooo... return 1?

> +}
> diff --git a/lib/s390x/uv.h b/lib/s390x/uv.h
> new file mode 100644
> index 00000000..159bf8e5
> --- /dev/null
> +++ b/lib/s390x/uv.h
> @@ -0,0 +1,10 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +#ifndef UV_H
> +#define UV_H
> +
> +bool uv_os_is_guest(void);
> +bool uv_os_is_host(void);
> +bool uv_query_test_feature(int nr);
> +int uv_setup(void);
> +
> +#endif /* UV_H */
> diff --git a/s390x/Makefile b/s390x/Makefile
> index b92de9c5..bbf177fa 100644
> --- a/s390x/Makefile
> +++ b/s390x/Makefile
> @@ -67,6 +67,7 @@ cflatobjs += lib/s390x/vm.o
>  cflatobjs += lib/s390x/css_dump.o
>  cflatobjs += lib/s390x/css_lib.o
>  cflatobjs += lib/s390x/malloc_io.o
> +cflatobjs += lib/s390x/uv.o
>  
>  OBJDIRS += lib/s390x
>  


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

* Re: [kvm-unit-tests PATCH 4/6] s390x: Test for share/unshare call support before using them
  2021-03-16  9:16 ` [kvm-unit-tests PATCH 4/6] s390x: Test for share/unshare call support before using them Janosch Frank
@ 2021-04-20 14:18   ` Claudio Imbrenda
  0 siblings, 0 replies; 23+ messages in thread
From: Claudio Imbrenda @ 2021-04-20 14:18 UTC (permalink / raw)
  To: Janosch Frank; +Cc: kvm, linux-s390, thuth, david

On Tue, 16 Mar 2021 09:16:52 +0000
Janosch Frank <frankja@linux.ibm.com> wrote:

> Testing for facility only means the UV Call facility is available.
> The UV will only indicate the share/unshare calls for a protected
> guest 2, so let's also check that.
> 
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>

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

> ---
>  lib/s390x/malloc_io.c | 5 +++--
>  s390x/uv-guest.c      | 6 ++++++
>  2 files changed, 9 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/s390x/malloc_io.c b/lib/s390x/malloc_io.c
> index 1dcf1691..78582eac 100644
> --- a/lib/s390x/malloc_io.c
> +++ b/lib/s390x/malloc_io.c
> @@ -19,6 +19,7 @@
>  #include <alloc_page.h>
>  #include <asm/facility.h>
>  #include <bitops.h>
> +#include <uv.h>
>  
>  static int share_pages(void *p, int count)
>  {
> @@ -47,7 +48,7 @@ void *alloc_io_mem(int size, int flags)
>  	assert(size);
>  
>  	p = alloc_pages_flags(order, AREA_DMA31 | flags);
> -	if (!p || !test_facility(158))
> +	if (!p || !uv_os_is_guest())
>  		return p;
>  
>  	n = share_pages(p, 1 << order);
> @@ -65,7 +66,7 @@ void free_io_mem(void *p, int size)
>  
>  	assert(IS_ALIGNED((uintptr_t)p, PAGE_SIZE));
>  
> -	if (test_facility(158))
> +	if (uv_os_is_guest())
>  		unshare_pages(p, 1 << order);
>  	free_pages(p);
>  }
> diff --git a/s390x/uv-guest.c b/s390x/uv-guest.c
> index 95a968c5..8915b2f1 100644
> --- a/s390x/uv-guest.c
> +++ b/s390x/uv-guest.c
> @@ -16,6 +16,7 @@
>  #include <asm/facility.h>
>  #include <asm/uv.h>
>  #include <sclp.h>
> +#include <uv.h>
>  
>  static unsigned long page;
>  
> @@ -141,6 +142,11 @@ int main(void)
>  		goto done;
>  	}
>  
> +	if (!uv_os_is_guest()) {
> +		report_skip("Not a protected guest");
> +		goto done;
> +	}
> +
>  	page = (unsigned long)alloc_page();
>  	test_priv();
>  	test_invalid();


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

* Re: [kvm-unit-tests PATCH 5/6] s390x: uv-guest: Test invalid commands
  2021-03-16  9:16 ` [kvm-unit-tests PATCH 5/6] s390x: uv-guest: Test invalid commands Janosch Frank
@ 2021-04-20 14:26   ` Claudio Imbrenda
  2021-04-26 13:40     ` Janosch Frank
  0 siblings, 1 reply; 23+ messages in thread
From: Claudio Imbrenda @ 2021-04-20 14:26 UTC (permalink / raw)
  To: Janosch Frank; +Cc: kvm, linux-s390, thuth, david

On Tue, 16 Mar 2021 09:16:53 +0000
Janosch Frank <frankja@linux.ibm.com> wrote:

> Let's check if the commands that are not indicated as available
> produce a invalid command error.

you say this, but you don't actually check that the commands are
actually reported as unavailable

> 
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
> ---
>  s390x/uv-guest.c | 44 +++++++++++++++++++++++++++++++++++++-------
>  1 file changed, 37 insertions(+), 7 deletions(-)
> 
> diff --git a/s390x/uv-guest.c b/s390x/uv-guest.c
> index 8915b2f1..517e3c66 100644
> --- a/s390x/uv-guest.c
> +++ b/s390x/uv-guest.c
> @@ -120,16 +120,46 @@ static void test_sharing(void)
>  	report_prefix_pop();
>  }
>  
> +static struct {
> +	const char *name;
> +	uint16_t cmd;
> +	uint16_t len;
> +} invalid_cmds[] = {
> +	{ "bogus", 0x4242, sizeof(struct uv_cb_header) },
> +	{ "init", UVC_CMD_INIT_UV, sizeof(struct uv_cb_init) },
> +	{ "create conf", UVC_CMD_CREATE_SEC_CONF, sizeof(struct
> uv_cb_cgc) },
> +	{ "destroy conf", UVC_CMD_DESTROY_SEC_CONF, sizeof(struct
> uv_cb_nodata) },
> +	{ "create cpu", UVC_CMD_CREATE_SEC_CPU, sizeof(struct
> uv_cb_csc) },
> +	{ "destroy cpu", UVC_CMD_DESTROY_SEC_CPU, sizeof(struct
> uv_cb_nodata) },
> +	{ "conv to", UVC_CMD_CONV_TO_SEC_STOR, sizeof(struct
> uv_cb_cts) },
> +	{ "conv from", UVC_CMD_CONV_FROM_SEC_STOR, sizeof(struct
> uv_cb_cfs) },
> +	{ "set sec conf", UVC_CMD_SET_SEC_CONF_PARAMS, sizeof(struct
> uv_cb_ssc) },
> +	{ "unpack", UVC_CMD_UNPACK_IMG, sizeof(struct uv_cb_unp) },
> +	{ "verify", UVC_CMD_VERIFY_IMG, sizeof(struct uv_cb_nodata)
> },
> +	{ "cpu reset", UVC_CMD_CPU_RESET, sizeof(struct
> uv_cb_nodata) },
> +	{ "cpu initial reset", UVC_CMD_CPU_RESET_INITIAL,
> sizeof(struct uv_cb_nodata) },
> +	{ "conf clear reset", UVC_CMD_PERF_CONF_CLEAR_RESET,
> sizeof(struct uv_cb_nodata) },
> +	{ "cpu clear reset", UVC_CMD_CPU_RESET_CLEAR, sizeof(struct
> uv_cb_nodata) },
> +	{ "cpu set state", UVC_CMD_CPU_SET_STATE, sizeof(struct
> uv_cb_cpu_set_state) },
> +	{ "pin shared", UVC_CMD_PIN_PAGE_SHARED, sizeof(struct
> uv_cb_cfs) },
> +	{ "unpin shared", UVC_CMD_UNPIN_PAGE_SHARED, sizeof(struct
> uv_cb_cts) },
> +	{ NULL, 0, 0 },
> +};
> +
>  static void test_invalid(void)
>  {
> -	struct uv_cb_header uvcb = {
> -		.len = 16,
> -		.cmd = 0x4242,
> -	};
> -	int cc;
> +	struct uv_cb_header *hdr = (void *)page;
> +	int cc, i;
>  
> -	cc = uv_call(0, (u64)&uvcb);
> -	report(cc == 1 && uvcb.rc == UVC_RC_INV_CMD, "invalid
> command");
> +	report_prefix_push("invalid");

here you just blindly loop over all the commands, without checking
their actual availability

> +	for (i = 0; invalid_cmds[i].name; i++) {

maybe you can add another field for the availability bit (or even put
them in the right order so the bit is the index) and here add something
like

if (uv_query_test_feature(i))
	continue;

so you will be sure the command is not available

> +		hdr->cmd = invalid_cmds[i].cmd;
> +		hdr->len = invalid_cmds[i].len;
> +		cc = uv_call(0, (u64)hdr);
> +		report(cc == 1 && hdr->rc == UVC_RC_INV_CMD, "%s",
> +		       invalid_cmds[i].name);
> +	}
> +	report_prefix_pop();
>  }
>  
>  int main(void)


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

* Re: [kvm-unit-tests PATCH 6/6] s390x: Add UV host test
  2021-03-16  9:16 ` [kvm-unit-tests PATCH 6/6] s390x: Add UV host test Janosch Frank
@ 2021-04-20 15:47   ` Claudio Imbrenda
  2021-04-26 14:31     ` Janosch Frank
  0 siblings, 1 reply; 23+ messages in thread
From: Claudio Imbrenda @ 2021-04-20 15:47 UTC (permalink / raw)
  To: Janosch Frank; +Cc: kvm, linux-s390, thuth, david

On Tue, 16 Mar 2021 09:16:54 +0000
Janosch Frank <frankja@linux.ibm.com> wrote:

> Let's also test the UV host interfaces.
> 
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>

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

the test is ok as is, but I do have a lot of ideas on how to
improve/extend it further. Once this is merged (and once I have some
time) I will send a few patches. 

> ---
>  s390x/Makefile  |   1 +
>  s390x/uv-host.c | 513
> ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 514
> insertions(+) create mode 100644 s390x/uv-host.c
> 
> diff --git a/s390x/Makefile b/s390x/Makefile
> index bbf177fa..8de926ab 100644
> --- a/s390x/Makefile
> +++ b/s390x/Makefile
> @@ -21,6 +21,7 @@ tests += $(TEST_DIR)/css.elf
>  tests += $(TEST_DIR)/uv-guest.elf
>  tests += $(TEST_DIR)/sie.elf
>  tests += $(TEST_DIR)/mvpg.elf
> +tests += $(TEST_DIR)/uv-host.elf
>  
>  tests_binary = $(patsubst %.elf,%.bin,$(tests))
>  ifneq ($(HOST_KEY_DOCUMENT),)
> diff --git a/s390x/uv-host.c b/s390x/uv-host.c
> new file mode 100644
> index 00000000..746abd8e
> --- /dev/null
> +++ b/s390x/uv-host.c
> @@ -0,0 +1,513 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +/*
> + * Guest Ultravisor Call tests
> + *
> + * Copyright (c) 2021 IBM Corp
> + *
> + * Authors:
> + *  Janosch Frank <frankja@linux.ibm.com>
> + */
> +
> +#include <libcflat.h>
> +#include <alloc.h>
> +#include <vmalloc.h>
> +#include <sclp.h>
> +#include <smp.h>
> +#include <asm/page.h>
> +#include <asm/sigp.h>
> +#include <asm/pgtable.h>
> +#include <asm/asm-offsets.h>
> +#include <asm/interrupt.h>
> +#include <asm/facility.h>
> +#include <asm/uv.h>
> +#include <asm-generic/barrier.h>
> +
> +static struct uv_cb_qui uvcb_qui;
> +static struct uv_cb_init uvcb_init;
> +static struct uv_cb_cgc uvcb_cgc;
> +static struct uv_cb_csc uvcb_csc;
> +
> +extern int diag308_load_reset(u64 code);
> +
> +struct cmd_list{
> +	const char *name;
> +	uint16_t cmd;
> +	uint16_t len;
> +};
> +
> +static void cpu_loop(void)
> +{
> +	for (;;) {}
> +}
> +
> +static struct cmd_list cmds[] = {
> +	{ "init", UVC_CMD_INIT_UV, sizeof(struct uv_cb_init) },
> +	{ "create conf", UVC_CMD_CREATE_SEC_CONF, sizeof(struct
> uv_cb_cgc) },
> +	{ "destroy conf", UVC_CMD_DESTROY_SEC_CONF, sizeof(struct
> uv_cb_nodata) },
> +	{ "create cpu", UVC_CMD_CREATE_SEC_CPU, sizeof(struct
> uv_cb_csc) },
> +	{ "destroy cpu", UVC_CMD_DESTROY_SEC_CPU, sizeof(struct
> uv_cb_nodata) },
> +	{ "conv to", UVC_CMD_CONV_TO_SEC_STOR, sizeof(struct
> uv_cb_cts) },
> +	{ "conv from", UVC_CMD_CONV_FROM_SEC_STOR, sizeof(struct
> uv_cb_cfs) },
> +	{ "set sec conf", UVC_CMD_SET_SEC_CONF_PARAMS, sizeof(struct
> uv_cb_ssc) },
> +	{ "unpack", UVC_CMD_UNPACK_IMG, sizeof(struct uv_cb_unp) },
> +	{ "verify", UVC_CMD_VERIFY_IMG, sizeof(struct uv_cb_nodata)
> },
> +	{ "cpu reset", UVC_CMD_CPU_RESET, sizeof(struct
> uv_cb_nodata) },
> +	{ "cpu initial reset", UVC_CMD_CPU_RESET_INITIAL,
> sizeof(struct uv_cb_nodata) },
> +	{ "conf clear reset", UVC_CMD_PERF_CONF_CLEAR_RESET,
> sizeof(struct uv_cb_nodata) },
> +	{ "cpu clear reset", UVC_CMD_CPU_RESET_CLEAR, sizeof(struct
> uv_cb_nodata) },
> +	{ "cpu set state", UVC_CMD_CPU_SET_STATE, sizeof(struct
> uv_cb_cpu_set_state) },
> +	{ "pin shared", UVC_CMD_PIN_PAGE_SHARED, sizeof(struct
> uv_cb_cfs) },
> +	{ "unpin shared", UVC_CMD_UNPIN_PAGE_SHARED, sizeof(struct
> uv_cb_cts) },
> +	{ NULL, 0, 0 },
> +};
> +
> +static void test_priv(void)
> +{
> +	struct uv_cb_header uvcb = {};
> +	uint16_t pgm;
> +	int i;
> +
> +	report_prefix_push("privileged");
> +	for (i = 0; cmds[i].name; i++) {
> +		expect_pgm_int();
> +		uvcb.cmd = cmds[i].cmd;
> +		uvcb.len = cmds[i].len;
> +		enter_pstate();
> +		uv_call(0, (uint64_t)&uvcb);
> +		pgm = clear_pgm_int();
> +		report(pgm == PGM_INT_CODE_PRIVILEGED_OPERATION,
> "%s", cmds[i].name);
> +	}
> +	report_prefix_pop();
> +}
> +
> +static void test_config_destroy(void)
> +{
> +	int rc;
> +	struct uv_cb_nodata uvcb = {
> +		.header.cmd = UVC_CMD_DESTROY_SEC_CONF,
> +		.header.len = sizeof(uvcb),
> +		.handle = uvcb_cgc.guest_handle,
> +	};
> +
> +	report_prefix_push("dsc");
> +	uvcb.header.len -= 8;
> +	rc = uv_call(0, (uint64_t)&uvcb);
> +	report(rc == 1 && uvcb.header.rc == UVC_RC_INV_LEN,
> +	       "hdr invalid length");
> +	uvcb.header.len += 8;
> +
> +	uvcb.handle += 1;
> +	rc = uv_call(0, (uint64_t)&uvcb);
> +	report(rc == 1 && uvcb.header.rc == UVC_RC_INV_GHANDLE,
> "invalid handle");
> +	uvcb.handle -= 1;
> +
> +	rc = uv_call(0, (uint64_t)&uvcb);
> +	report(rc == 0 && uvcb.header.rc == UVC_RC_EXECUTED,
> "success");
> +	report_prefix_pop();
> +}
> +
> +static void test_cpu_destroy(void)
> +{
> +	int rc;
> +	struct uv_cb_nodata uvcb = {
> +		.header.len = sizeof(uvcb),
> +		.header.cmd = UVC_CMD_DESTROY_SEC_CPU,
> +		.handle = uvcb_csc.cpu_handle,
> +	};
> +
> +	report_prefix_push("dcpu");
> +
> +	uvcb.header.len -= 8;
> +	rc = uv_call(0, (uint64_t)&uvcb);
> +	report(rc == 1 && uvcb.header.rc == UVC_RC_INV_LEN,
> +	       "hdr invalid length");
> +	uvcb.header.len += 8;
> +
> +	uvcb.handle += 1;
> +	rc = uv_call(0, (uint64_t)&uvcb);
> +	report(rc == 1 && uvcb.header.rc == UVC_RC_INV_CHANDLE,
> "invalid handle");
> +	uvcb.handle -= 1;
> +
> +	rc = uv_call(0, (uint64_t)&uvcb);
> +	report(rc == 0 && uvcb.header.rc == UVC_RC_EXECUTED,
> "success"); +
> +	report_prefix_pop();
> +}
> +
> +static void test_cpu_create(void)
> +{
> +	int rc;
> +	unsigned long tmp;
> +
> +	report_prefix_push("csc");
> +	uvcb_csc.header.len = sizeof(uvcb_csc);
> +	uvcb_csc.header.cmd = UVC_CMD_CREATE_SEC_CPU;
> +	uvcb_csc.guest_handle = uvcb_cgc.guest_handle;
> +	uvcb_csc.stor_origin = (unsigned long)memalign(PAGE_SIZE,
> uvcb_qui.cpu_stor_len);
> +	uvcb_csc.state_origin = (unsigned long)memalign(PAGE_SIZE,
> PAGE_SIZE); +
> +	uvcb_csc.header.len -= 8;
> +	rc = uv_call(0, (uint64_t)&uvcb_csc);
> +	report(uvcb_csc.header.rc == UVC_RC_INV_LEN && rc == 1 &&
> +	       !uvcb_csc.cpu_handle, "hdr invalid length");
> +	uvcb_csc.header.len += 8;
> +
> +	uvcb_csc.guest_handle += 1;
> +	rc = uv_call(0, (uint64_t)&uvcb_csc);
> +	report(uvcb_csc.header.rc == UVC_RC_INV_GHANDLE && rc == 1,
> +	       "invalid guest handle");
> +	uvcb_csc.guest_handle -= 1;
> +
> +	uvcb_csc.num = uvcb_qui.max_guest_cpus + 1;
> +	rc = uv_call(0, (uint64_t)&uvcb_csc);
> +	report(uvcb_csc.header.rc == 0x103 && rc == 1,
> +	       "invalid cpu #");
> +	uvcb_csc.num = 0;
> +
> +	tmp = uvcb_csc.stor_origin;
> +	uvcb_csc.stor_origin = get_max_ram_size() + PAGE_SIZE;
> +	rc = uv_call(0, (uint64_t)&uvcb_csc);
> +	report(uvcb_csc.header.rc == 0x105 && rc == 1,
> +	       "cpu stor inaccessible");
> +	uvcb_csc.stor_origin = tmp;
> +
> +	tmp = uvcb_csc.stor_origin;
> +	uvcb_csc.stor_origin = 0;
> +	rc = uv_call(0, (uint64_t)&uvcb_csc);
> +	report(uvcb_csc.header.rc == 0x106 && rc == 1,
> +	       "cpu stor in lowcore");
> +	uvcb_csc.stor_origin = tmp;
> +
> +	tmp = uvcb_csc.state_origin;
> +	uvcb_csc.state_origin = get_max_ram_size() + PAGE_SIZE;
> +	rc = uv_call(0, (uint64_t)&uvcb_csc);
> +	report(uvcb_csc.header.rc == 0x107 && rc == 1,
> +	       "SIE SD inaccessible");
> +	uvcb_csc.state_origin = tmp;
> +
> +	rc = uv_call(0, (uint64_t)&uvcb_csc);
> +	report(rc == 0 && uvcb_csc.header.rc == UVC_RC_EXECUTED &&
> +	       uvcb_csc.cpu_handle, "success");
> +
> +	tmp = uvcb_csc.stor_origin;
> +	uvcb_csc.stor_origin = (unsigned long)memalign(PAGE_SIZE,
> uvcb_qui.cpu_stor_len);
> +	rc = uv_call(0, (uint64_t)&uvcb_csc);
> +	report(rc == 1 && uvcb_csc.header.rc == 0x104, "already
> defined");
> +	uvcb_csc.stor_origin = tmp;
> +	report_prefix_pop();
> +}
> +
> +static void test_config_create(void)
> +{
> +	int rc;
> +	unsigned long vsize, tmp;
> +	static struct uv_cb_cgc uvcb;
> +
> +	uvcb_cgc.header.cmd = UVC_CMD_CREATE_SEC_CONF;
> +	uvcb_cgc.header.len = sizeof(uvcb_cgc);
> +	report_prefix_push("cgc");
> +
> +	uvcb_cgc.guest_stor_origin = 0;
> +	uvcb_cgc.guest_stor_len = 42 * (1UL << 20);
> +	vsize = uvcb_qui.conf_base_virt_stor_len +
> +		((uvcb_cgc.guest_stor_len / (1UL << 20)) *
> uvcb_qui.conf_virt_var_stor_len); +
> +	uvcb_cgc.conf_base_stor_origin =
> (uint64_t)memalign(PAGE_SIZE * 4, uvcb_qui.conf_base_phys_stor_len);
> +	uvcb_cgc.conf_var_stor_origin =
> (uint64_t)memalign(PAGE_SIZE, vsize);
> +	uvcb_cgc.guest_asce = (uint64_t)memalign(PAGE_SIZE, 4 *
> PAGE_SIZE) | ASCE_DT_SEGMENT | REGION_TABLE_LENGTH | ASCE_P;
> +	uvcb_cgc.guest_sca = (uint64_t)memalign(PAGE_SIZE * 4,
> PAGE_SIZE * 4); +
> +	uvcb_cgc.header.len -= 8;
> +	rc = uv_call(0, (uint64_t)&uvcb_cgc);
> +	report(uvcb_cgc.header.rc == UVC_RC_INV_LEN && rc == 1 &&
> +	       !uvcb_cgc.guest_handle, "hdr invalid length");
> +	uvcb_cgc.header.len += 8;
> +
> +	uvcb_cgc.guest_stor_origin = uvcb_qui.max_guest_stor_addr +
> (1UL << 20) * 2 + 1;
> +	rc = uv_call(0, (uint64_t)&uvcb_cgc);
> +	report(uvcb_cgc.header.rc == 0x101 && rc == 1,
> +	       "MSO > max guest addr");
> +	uvcb_cgc.guest_stor_origin = 0;
> +
> +	uvcb_cgc.guest_stor_origin = uvcb_qui.max_guest_stor_addr -
> (1UL << 20);
> +	rc = uv_call(0, (uint64_t)&uvcb_cgc);
> +	report(uvcb_cgc.header.rc == 0x102 && rc == 1,
> +	       "MSO + MSL > max guest addr");
> +	uvcb_cgc.guest_stor_origin = 0;
> +
> +	uvcb_cgc.guest_asce &= ~ASCE_P;
> +	rc = uv_call(0, (uint64_t)&uvcb_cgc);
> +	report(uvcb_cgc.header.rc == 0x105 && rc == 1,
> +	       "ASCE private bit missing");
> +	uvcb_cgc.guest_asce |= ASCE_P;
> +
> +	uvcb_cgc.guest_asce |= 0x20;
> +	rc = uv_call(0, (uint64_t)&uvcb_cgc);
> +	report(uvcb_cgc.header.rc == 0x105 && rc == 1,
> +	       "ASCE bit 58 set");
> +	uvcb_cgc.guest_asce &= ~0x20;
> +
> +	tmp = uvcb_cgc.conf_base_stor_origin;
> +	uvcb_cgc.conf_base_stor_origin = get_max_ram_size() + 8;
> +	rc = uv_call(0, (uint64_t)&uvcb_cgc);
> +	report(uvcb_cgc.header.rc == 0x108 && rc == 1,
> +	       "base storage origin > available memory");
> +	uvcb_cgc.conf_base_stor_origin = tmp;
> +
> +	tmp = uvcb_cgc.conf_base_stor_origin;
> +	uvcb_cgc.conf_base_stor_origin = 0x1000;
> +	rc = uv_call(0, (uint64_t)&uvcb_cgc);
> +	report(uvcb_cgc.header.rc == 0x109 && rc == 1,
> +	       "base storage origin contains lowcore");
> +	uvcb_cgc.conf_base_stor_origin = tmp;
> +
> +	if (smp_query_num_cpus() == 1) {
> +		sigp_retry(1, SIGP_SET_PREFIX,
> +			   uvcb_cgc.conf_var_stor_origin +
> PAGE_SIZE, NULL);
> +		rc = uv_call(0, (uint64_t)&uvcb_cgc);
> +		report(uvcb_cgc.header.rc == 0x10e && rc == 1 &&
> +		       !uvcb_cgc.guest_handle, "variable storage
> area contains lowcore");
> +		sigp_retry(1, SIGP_SET_PREFIX, 0x0, NULL);
> +	}
> +
> +	tmp = uvcb_cgc.guest_sca;
> +	uvcb_cgc.guest_sca = 0;
> +	rc = uv_call(0, (uint64_t)&uvcb_cgc);
> +	report(uvcb_cgc.header.rc == 0x10c && rc == 1,
> +	       "sca == 0");
> +	uvcb_cgc.guest_sca = tmp;
> +
> +	tmp = uvcb_cgc.guest_sca;
> +	uvcb_cgc.guest_sca = get_max_ram_size() + + PAGE_SIZE * 4;
> +	rc = uv_call(0, (uint64_t)&uvcb_cgc);
> +	report(uvcb_cgc.header.rc == 0x10d && rc == 1,
> +	       "sca inaccessible");
> +	uvcb_cgc.guest_sca = tmp;
> +
> +	rc = uv_call(0, (uint64_t)&uvcb_cgc);
> +	report(rc == 0 && uvcb_cgc.header.rc == UVC_RC_EXECUTED,
> "successful"); +
> +	uvcb_cgc.header.rc = 0;
> +	uvcb_cgc.header.rrc = 0;
> +	tmp = uvcb_cgc.guest_handle;
> +	uvcb_cgc.guest_handle = 0;
> +	rc = uv_call(0, (uint64_t)&uvcb_cgc);
> +	report(uvcb_cgc.header.rc >= 0x100 && rc == 1, "reuse uvcb");
> +	uvcb_cgc.guest_handle = tmp;
> +
> +	/* Copy over most data from uvcb_cgc, so we have the ASCE
> that was used. */
> +	memcpy(&uvcb, &uvcb_cgc, sizeof(uvcb));
> +
> +	/* Reset the header and handle */
> +	uvcb.header.rc = 0;
> +	uvcb.header.rrc = 0;
> +	uvcb.guest_handle = 0;
> +
> +	/* Use new storage areas. */
> +	uvcb.conf_base_stor_origin = (uint64_t)memalign(PAGE_SIZE *
> 4, uvcb_qui.conf_base_phys_stor_len);
> +	uvcb.conf_var_stor_origin = (uint64_t)memalign(PAGE_SIZE,
> vsize); +
> +	rc = uv_call(0, (uint64_t)&uvcb);
> +	report(uvcb.header.rc >= 0x104 && rc == 1 &&
> !uvcb.guest_handle,
> +	       "reuse ASCE");
> +	free((void *)uvcb.conf_base_stor_origin);
> +	free((void *)uvcb.conf_var_stor_origin);
> +
> +
> +	/* Missing: 106, 10a, a0b */
> +	report_prefix_pop();
> +}
> +
> +static void test_init(void)
> +{
> +	int rc;
> +	uint64_t mem;
> +	struct psw psw;
> +
> +	/* Donated storage needs to be over 2GB */
> +	mem = (uint64_t)memalign(1UL << 31,
> uvcb_qui.uv_base_stor_len); +
> +	uvcb_init.header.len = sizeof(uvcb_init);
> +	uvcb_init.header.cmd = UVC_CMD_INIT_UV;
> +	uvcb_init.stor_origin = mem;
> +	uvcb_init.stor_len = uvcb_qui.uv_base_stor_len;
> +
> +	report_prefix_push("init");
> +	uvcb_init.header.len -= 8;
> +	rc = uv_call(0, (uint64_t)&uvcb_init);
> +	report(rc == 1 && uvcb_init.header.rc == UVC_RC_INV_LEN,
> +	       "hdr invalid length");
> +	uvcb_init.header.len += 8;
> +
> +	uvcb_init.stor_len -= 8;
> +	rc = uv_call(0, (uint64_t)&uvcb_init);
> +	report(rc == 1 && uvcb_init.header.rc == 0x103,
> +	       "storage invalid length");
> +	uvcb_init.stor_len += 8;
> +
> +	uvcb_init.stor_origin =  get_max_ram_size() + 8;
> +	rc = uv_call(0, (uint64_t)&uvcb_init);
> +	report(rc == 1 && uvcb_init.header.rc == 0x104,
> +	       "storage origin invalid");
> +	uvcb_init.stor_origin = mem;
> +
> +	uvcb_init.stor_origin = get_max_ram_size() - 8;
> +	rc = uv_call(0, (uint64_t)&uvcb_init);
> +	report(rc == 1 && uvcb_init.header.rc == 0x105,
> +	       "storage + length invalid");
> +	uvcb_init.stor_origin = mem;
> +
> +	uvcb_init.stor_origin = 1UL << 30;
> +	rc = uv_call(0, (uint64_t)&uvcb_init);
> +	report(rc == 1 && uvcb_init.header.rc == 0x108,
> +	       "storage below 2GB");
> +	uvcb_init.stor_origin = mem;
> +
> +	psw.mask = extract_psw_mask();
> +	psw.addr = (unsigned long)cpu_loop;
> +	smp_cpu_setup(1, psw);
> +	rc = uv_call(0, (uint64_t)&uvcb_init);
> +	report(rc == 1 && uvcb_init.header.rc == 0x102,
> +	       "too many running cpus");
> +	smp_cpu_stop(1);
> +
> +	rc = uv_call(0, (uint64_t)&uvcb_init);
> +	report(rc == 0 && uvcb_init.header.rc == UVC_RC_EXECUTED,
> "successful"); +
> +	mem = (uint64_t)memalign(1UL << 31,
> uvcb_qui.uv_base_stor_len);
> +	rc = uv_call(0, (uint64_t)&uvcb_init);
> +	report(rc == 1 && uvcb_init.header.rc == 0x101, "double
> init");
> +	free((void *)mem);
> +
> +	report_prefix_pop();
> +}
> +
> +static void test_query(void)
> +{
> +	uvcb_qui.header.cmd = UVC_CMD_QUI;
> +	uvcb_qui.header.len = sizeof(uvcb_qui);
> +	uint64_t *call_list = &uvcb_qui.inst_calls_list[0];
> +
> +	report_prefix_push("query");
> +	uvcb_qui.header.len = 0xa0;
> +	uv_call(0, (uint64_t)&uvcb_qui);
> +	report(uvcb_qui.header.rc == UVC_RC_INV_LEN, "length");
> +
> +	uvcb_qui.header.len = 0xa8;
> +	uv_call(0, (uint64_t)&uvcb_qui);
> +	report(uvcb_qui.header.rc == 0x100, "insf length");
> +
> +	uvcb_qui.header.len = sizeof(uvcb_qui);
> +	uv_call(0, (uint64_t)&uvcb_qui);
> +	report(uvcb_qui.header.rc == UVC_RC_EXECUTED, "successful
> query"); +
> +	report(test_bit_inv(BIT_UVC_CMD_QUI, call_list) &&
> +	       test_bit_inv(BIT_UVC_CMD_INIT_UV, call_list),
> +	       "query and init indicated");
> +
> +	report(test_bit_inv(BIT_UVC_CMD_CREATE_SEC_CONF, call_list)
> &&
> +	       test_bit_inv(BIT_UVC_CMD_DESTROY_SEC_CONF, call_list),
> +	       "create/destroy vm indicated");
> +
> +	report(test_bit_inv(BIT_UVC_CMD_CREATE_SEC_CPU, call_list) &&
> +	       test_bit_inv(BIT_UVC_CMD_DESTROY_SEC_CPU, call_list),
> +	       "create/destroy cpu indicated");
> +
> +	report(test_bit_inv(BIT_UVC_CMD_CONV_TO_SEC_STOR, call_list)
> &&
> +	       test_bit_inv(BIT_UVC_CMD_CONV_FROM_SEC_STOR,
> call_list),
> +	       "convert to/from secure storage indicated");
> +
> +	report(test_bit_inv(BIT_UVC_CMD_SET_SEC_PARMS, call_list) &&
> +	       test_bit_inv(BIT_UVC_CMD_UNPACK_IMG, call_list) &&
> +	       test_bit_inv(BIT_UVC_CMD_CPU_SET_STATE, call_list) &&
> +	       test_bit_inv(BIT_UVC_CMD_VERIFY_IMG, call_list),
> +	       "set sec parm, setcpu state, unpack and verify
> indicated"); +
> +	report(test_bit_inv(BIT_UVC_CMD_CPU_RESET, call_list) &&
> +	       test_bit_inv(BIT_UVC_CMD_CPU_RESET_INITIAL,
> call_list) &&
> +	       test_bit_inv(BIT_UVC_CMD_CPU_PERFORM_CLEAR_RESET,
> call_list),
> +	       "resets indicated");
> +
> +	report(test_bit_inv(BIT_UVC_CMD_PREPARE_CLEAR_RESET,
> call_list) &&
> +	       test_bit_inv(BIT_UVC_CMD_UNSHARE_ALL, call_list),
> +	       "prepare reset and unshare all indicated");
> +
> +	report(test_bit_inv(BIT_UVC_CMD_PIN_PAGE_SHARED, call_list)
> &&
> +	       test_bit_inv(BIT_UVC_CMD_UNPIN_PAGE_SHARED,
> call_list),
> +	       "(un)pin shared page indicated");
> +
> +	report(!test_bit_inv(BIT_UVC_CMD_SET_SHARED_ACCESS,
> call_list) &&
> +	       !test_bit_inv(BIT_UVC_CMD_REMOVE_SHARED_ACCESS,
> call_list),
> +	       "(un)share not indicated");
> +
> +	report_prefix_pop();
> +}
> +
> +static struct cmd_list invalid_cmds[] = {
> +	{ "bogus", 0x4242, sizeof(struct uv_cb_header) },
> +	{ "share", UVC_CMD_SET_SHARED_ACCESS, sizeof(struct
> uv_cb_share) },
> +	{ "unshare", UVC_CMD_REMOVE_SHARED_ACCESS, sizeof(struct
> uv_cb_share) },
> +	{ NULL, 0, 0 },
> +};
> +
> +static void test_invalid(void)
> +{
> +	struct uv_cb_header hdr = {};
> +	int i, cc;
> +
> +	report_prefix_push("invalid");
> +	for (i = 0; invalid_cmds[i].name; i++) {
> +		hdr.cmd = invalid_cmds[i].cmd;
> +		hdr.len = invalid_cmds[i].len;
> +		cc = uv_call(0, (uint64_t)&hdr);
> +		report(cc == 1 && hdr.rc == UVC_RC_INV_CMD, "%s",
> +		       invalid_cmds[i].name);
> +	}
> +	report_prefix_pop();
> +}
> +
> +static void test_clear(void)
> +{
> +	uint64_t *tmp = (void *)uvcb_init.stor_origin;
> +
> +	diag308_load_reset(1);
> +	sclp_console_setup();
> +	report(!*tmp, "memory cleared after reset 1");
> +}
> +
> +static void setup_vmem(void)
> +{
> +	uint64_t asce, mask;
> +
> +	setup_mmu(get_max_ram_size());
> +	asce = stctg(1);
> +	lctlg(13, asce);
> +	mask = extract_psw_mask() | 0x0000C00000000000UL;
> +	load_psw_mask(mask);
> +}
> +
> +int main(void)
> +{
> +	bool has_uvc = test_facility(158);
> +
> +	report_prefix_push("uvc");
> +	if (!has_uvc) {
> +		report_skip("Ultravisor call facility is not
> available");
> +		goto done;
> +	}
> +
> +	test_priv();
> +	test_invalid();
> +	test_query();
> +	test_init();
> +
> +	setup_vmem();
> +	test_config_create();
> +	test_cpu_create();
> +	test_cpu_destroy();
> +	test_config_destroy();
> +	test_clear();
> +
> +done:
> +	return report_summary();
> +}


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

* Re: [kvm-unit-tests PATCH 1/6] s390x: uv-guest: Add invalid share location test
  2021-03-16  9:16 ` [kvm-unit-tests PATCH 1/6] s390x: uv-guest: Add invalid share location test Janosch Frank
  2021-04-19 11:24   ` Thomas Huth
  2021-04-20 13:40   ` Claudio Imbrenda
@ 2021-04-21 11:04   ` Cornelia Huck
  2 siblings, 0 replies; 23+ messages in thread
From: Cornelia Huck @ 2021-04-21 11:04 UTC (permalink / raw)
  To: Janosch Frank; +Cc: kvm, linux-s390, thuth, david, imbrenda

On Tue, 16 Mar 2021 09:16:49 +0000
Janosch Frank <frankja@linux.ibm.com> wrote:

> Let's also test sharing unavailable memory.
> 
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
> ---
>  s390x/uv-guest.c | 5 +++++
>  1 file changed, 5 insertions(+)

Reviewed-by: Cornelia Huck <cohuck@redhat.com>


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

* Re: [kvm-unit-tests PATCH 2/6] s390x: Add more Ultravisor command structure definitions
  2021-03-16  9:16 ` [kvm-unit-tests PATCH 2/6] s390x: Add more Ultravisor command structure definitions Janosch Frank
  2021-04-20 14:09   ` Claudio Imbrenda
@ 2021-04-21 11:13   ` Cornelia Huck
  2021-04-26 14:33     ` Janosch Frank
  1 sibling, 1 reply; 23+ messages in thread
From: Cornelia Huck @ 2021-04-21 11:13 UTC (permalink / raw)
  To: Janosch Frank; +Cc: kvm, linux-s390, thuth, david, imbrenda

On Tue, 16 Mar 2021 09:16:50 +0000
Janosch Frank <frankja@linux.ibm.com> wrote:

> They are needed in the new UV tests.
> 
> As we now extend the size of the query struct, we need to set the
> length in the UV guest query test to a constant instead of using
> sizeof.
> 
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
> ---
>  lib/s390x/asm/uv.h | 148 ++++++++++++++++++++++++++++++++++++++++++++-
>  s390x/uv-guest.c   |   2 +-
>  2 files changed, 148 insertions(+), 2 deletions(-)
> 

(...)

>  struct uv_cb_qui {
>  	struct uv_cb_header header;
>  	u64 reserved08;
>  	u64 inst_calls_list[4];
> -	u64 reserved30[15];
> +	u64 reserved30[2];
> +	u64 uv_base_stor_len;
> +	u64 reserved48;
> +	u64 conf_base_phys_stor_len;
> +	u64 conf_base_virt_stor_len;
> +	u64 conf_virt_var_stor_len;
> +	u64 cpu_stor_len;
> +	u32 reserved70[3];
> +	u32 max_num_sec_conf;
> +	u64 max_guest_stor_addr;
> +	u8  reserved88[158 - 136];
> +	u16 max_guest_cpus;
> +	u8  reserveda0[200 - 160];
> +}  __attribute__((packed))  __attribute__((aligned(8)));

(...)

> diff --git a/s390x/uv-guest.c b/s390x/uv-guest.c
> index a13669ab..95a968c5 100644
> --- a/s390x/uv-guest.c
> +++ b/s390x/uv-guest.c
> @@ -59,7 +59,7 @@ static void test_query(void)
>  {
>  	struct uv_cb_qui uvcb = {
>  		.header.cmd = UVC_CMD_QUI,
> -		.header.len = sizeof(uvcb) - 8,
> +		.header.len = 0xa0,

This is a magic constant coming out of nowhere. Could you please at
least add a comment to make clear what you are testing?

>  	};
>  	int cc;
>  


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

* Re: [kvm-unit-tests PATCH 5/6] s390x: uv-guest: Test invalid commands
  2021-04-20 14:26   ` Claudio Imbrenda
@ 2021-04-26 13:40     ` Janosch Frank
  0 siblings, 0 replies; 23+ messages in thread
From: Janosch Frank @ 2021-04-26 13:40 UTC (permalink / raw)
  To: Claudio Imbrenda; +Cc: kvm, linux-s390, thuth, david

On 4/20/21 4:26 PM, Claudio Imbrenda wrote:
> On Tue, 16 Mar 2021 09:16:53 +0000
> Janosch Frank <frankja@linux.ibm.com> wrote:
> 
>> Let's check if the commands that are not indicated as available
>> produce a invalid command error.
> 
> you say this, but you don't actually check that the commands are
> actually reported as unavailable

I'm a bit torn about this.

It is a UV guest test after all and we check that we are a UV guest in
main() so we are not able to accidentally run as a host. So those
indication bits and their associated calls should never be available.

> 
>>
>> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
>> ---
>>  s390x/uv-guest.c | 44 +++++++++++++++++++++++++++++++++++++-------
>>  1 file changed, 37 insertions(+), 7 deletions(-)
>>
>> diff --git a/s390x/uv-guest.c b/s390x/uv-guest.c
>> index 8915b2f1..517e3c66 100644
>> --- a/s390x/uv-guest.c
>> +++ b/s390x/uv-guest.c
>> @@ -120,16 +120,46 @@ static void test_sharing(void)
>>  	report_prefix_pop();
>>  }
>>  
>> +static struct {
>> +	const char *name;
>> +	uint16_t cmd;
>> +	uint16_t len;
>> +} invalid_cmds[] = {
>> +	{ "bogus", 0x4242, sizeof(struct uv_cb_header) },
>> +	{ "init", UVC_CMD_INIT_UV, sizeof(struct uv_cb_init) },
>> +	{ "create conf", UVC_CMD_CREATE_SEC_CONF, sizeof(struct
>> uv_cb_cgc) },
>> +	{ "destroy conf", UVC_CMD_DESTROY_SEC_CONF, sizeof(struct
>> uv_cb_nodata) },
>> +	{ "create cpu", UVC_CMD_CREATE_SEC_CPU, sizeof(struct
>> uv_cb_csc) },
>> +	{ "destroy cpu", UVC_CMD_DESTROY_SEC_CPU, sizeof(struct
>> uv_cb_nodata) },
>> +	{ "conv to", UVC_CMD_CONV_TO_SEC_STOR, sizeof(struct
>> uv_cb_cts) },
>> +	{ "conv from", UVC_CMD_CONV_FROM_SEC_STOR, sizeof(struct
>> uv_cb_cfs) },
>> +	{ "set sec conf", UVC_CMD_SET_SEC_CONF_PARAMS, sizeof(struct
>> uv_cb_ssc) },
>> +	{ "unpack", UVC_CMD_UNPACK_IMG, sizeof(struct uv_cb_unp) },
>> +	{ "verify", UVC_CMD_VERIFY_IMG, sizeof(struct uv_cb_nodata)
>> },
>> +	{ "cpu reset", UVC_CMD_CPU_RESET, sizeof(struct
>> uv_cb_nodata) },
>> +	{ "cpu initial reset", UVC_CMD_CPU_RESET_INITIAL,
>> sizeof(struct uv_cb_nodata) },
>> +	{ "conf clear reset", UVC_CMD_PERF_CONF_CLEAR_RESET,
>> sizeof(struct uv_cb_nodata) },
>> +	{ "cpu clear reset", UVC_CMD_CPU_RESET_CLEAR, sizeof(struct
>> uv_cb_nodata) },
>> +	{ "cpu set state", UVC_CMD_CPU_SET_STATE, sizeof(struct
>> uv_cb_cpu_set_state) },
>> +	{ "pin shared", UVC_CMD_PIN_PAGE_SHARED, sizeof(struct
>> uv_cb_cfs) },
>> +	{ "unpin shared", UVC_CMD_UNPIN_PAGE_SHARED, sizeof(struct
>> uv_cb_cts) },
>> +	{ NULL, 0, 0 },
>> +};
>> +
>>  static void test_invalid(void)
>>  {
>> -	struct uv_cb_header uvcb = {
>> -		.len = 16,
>> -		.cmd = 0x4242,
>> -	};
>> -	int cc;
>> +	struct uv_cb_header *hdr = (void *)page;
>> +	int cc, i;
>>  
>> -	cc = uv_call(0, (u64)&uvcb);
>> -	report(cc == 1 && uvcb.rc == UVC_RC_INV_CMD, "invalid
>> command");
>> +	report_prefix_push("invalid");
> 
> here you just blindly loop over all the commands, without checking
> their actual availability
> 
>> +	for (i = 0; invalid_cmds[i].name; i++) {
> 
> maybe you can add another field for the availability bit (or even put
> them in the right order so the bit is the index) and here add something
> like
> 
> if (uv_query_test_feature(i))
> 	continue;
> 
> so you will be sure the command is not available
> 
>> +		hdr->cmd = invalid_cmds[i].cmd;
>> +		hdr->len = invalid_cmds[i].len;
>> +		cc = uv_call(0, (u64)hdr);
>> +		report(cc == 1 && hdr->rc == UVC_RC_INV_CMD, "%s",
>> +		       invalid_cmds[i].name);
>> +	}
>> +	report_prefix_pop();
>>  }
>>  
>>  int main(void)
> 


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

* Re: [kvm-unit-tests PATCH 3/6] s390x: uv: Add UV lib
  2021-04-20 14:15   ` Claudio Imbrenda
@ 2021-04-26 14:20     ` Janosch Frank
  0 siblings, 0 replies; 23+ messages in thread
From: Janosch Frank @ 2021-04-26 14:20 UTC (permalink / raw)
  To: Claudio Imbrenda; +Cc: kvm, linux-s390, thuth, david

On 4/20/21 4:15 PM, Claudio Imbrenda wrote:
> On Tue, 16 Mar 2021 09:16:51 +0000
> Janosch Frank <frankja@linux.ibm.com> wrote:
> 
>> Let's add a UV library to make checking the UV feature bit easier.
>> In the future this library file can take care of handling UV
>> initialization and UV guest creation.
>>
>> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
> 
> Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>

Thanks

> 
> but see some comments below
> 
>> ---
>>  lib/s390x/asm/uv.h |  4 ++--
>>  lib/s390x/io.c     |  2 ++
>>  lib/s390x/uv.c     | 48
>> ++++++++++++++++++++++++++++++++++++++++++++++ lib/s390x/uv.h     |
>> 10 ++++++++++ s390x/Makefile     |  1 +
>>  5 files changed, 63 insertions(+), 2 deletions(-)
>>  create mode 100644 lib/s390x/uv.c
>>  create mode 100644 lib/s390x/uv.h
>>
>> diff --git a/lib/s390x/asm/uv.h b/lib/s390x/asm/uv.h
>> index 11f70a9f..b22cbaa8 100644
>> --- a/lib/s390x/asm/uv.h
>> +++ b/lib/s390x/asm/uv.h
>> @@ -9,8 +9,8 @@
>>   * This code is free software; you can redistribute it and/or modify
>> it
>>   * under the terms of the GNU General Public License version 2.
>>   */
>> -#ifndef UV_H
>> -#define UV_H
>> +#ifndef ASM_S390X_UV_H
>> +#define ASM_S390X_UV_H
>>  
>>  #define UVC_RC_EXECUTED		0x0001
>>  #define UVC_RC_INV_CMD		0x0002
>> diff --git a/lib/s390x/io.c b/lib/s390x/io.c
>> index ef9f59e3..a4f1b113 100644
>> --- a/lib/s390x/io.c
>> +++ b/lib/s390x/io.c
>> @@ -14,6 +14,7 @@
>>  #include <asm/facility.h>
>>  #include <asm/sigp.h>
>>  #include "sclp.h"
>> +#include "uv.h"
>>  #include "smp.h"
>>  
>>  extern char ipl_args[];
>> @@ -38,6 +39,7 @@ void setup(void)
>>  	sclp_facilities_setup();
>>  	sclp_console_setup();
>>  	sclp_memory_setup();
>> +	uv_setup();
>>  	smp_setup();
>>  }
>>  
>> diff --git a/lib/s390x/uv.c b/lib/s390x/uv.c
>> new file mode 100644
>> index 00000000..a84a85fc
>> --- /dev/null
>> +++ b/lib/s390x/uv.c
>> @@ -0,0 +1,48 @@
>> +#include <libcflat.h>
>> +#include <bitops.h>
>> +#include <alloc.h>
>> +#include <alloc_page.h>
>> +#include <asm/page.h>
>> +#include <asm/arch_def.h>
>> +
>> +#include <asm/facility.h>
>> +#include <asm/uv.h>
>> +#include <uv.h>
>> +
>> +static struct uv_cb_qui uvcb_qui = {
>> +	.header.cmd = UVC_CMD_QUI,
>> +	.header.len = sizeof(uvcb_qui),
>> +};
>> +
>> +bool uv_os_is_guest(void)
>> +{
>> +	return uv_query_test_feature(BIT_UVC_CMD_SET_SHARED_ACCESS)
>> +		&&
>> uv_query_test_feature(BIT_UVC_CMD_REMOVE_SHARED_ACCESS); +}
>> +
>> +bool uv_os_is_host(void)
>> +{
>> +	return uv_query_test_feature(BIT_UVC_CMD_INIT_UV);
>> +}
>> +
>> +bool uv_query_test_feature(int nr)
>> +{
>> +	/* Query needs to be called first */
>> +	if (!uvcb_qui.header.rc)
>> +		return false;
> 
> why not an assert?

I'd guess I had some weird reservation.
I'll add one though

> 
>> +
>> +	return test_bit_inv(nr, uvcb_qui.inst_calls_list);
>> +}
>> +
>> +int uv_setup(void)
>> +{
>> +	int cc;
>> +
>> +	if (!test_facility(158))
>> +		return 0;
>> +
>> +	cc = uv_call(0, (u64)&uvcb_qui);
>> +	assert(cc == 0);
>> +
>> +	return cc == 0;
> 
> sooo... return 1?

Yes

> 
>> +}
>> diff --git a/lib/s390x/uv.h b/lib/s390x/uv.h
>> new file mode 100644
>> index 00000000..159bf8e5
>> --- /dev/null
>> +++ b/lib/s390x/uv.h
>> @@ -0,0 +1,10 @@
>> +/* SPDX-License-Identifier: GPL-2.0-or-later */
>> +#ifndef UV_H
>> +#define UV_H
>> +
>> +bool uv_os_is_guest(void);
>> +bool uv_os_is_host(void);
>> +bool uv_query_test_feature(int nr);
>> +int uv_setup(void);
>> +
>> +#endif /* UV_H */
>> diff --git a/s390x/Makefile b/s390x/Makefile
>> index b92de9c5..bbf177fa 100644
>> --- a/s390x/Makefile
>> +++ b/s390x/Makefile
>> @@ -67,6 +67,7 @@ cflatobjs += lib/s390x/vm.o
>>  cflatobjs += lib/s390x/css_dump.o
>>  cflatobjs += lib/s390x/css_lib.o
>>  cflatobjs += lib/s390x/malloc_io.o
>> +cflatobjs += lib/s390x/uv.o
>>  
>>  OBJDIRS += lib/s390x
>>  
> 


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

* Re: [kvm-unit-tests PATCH 6/6] s390x: Add UV host test
  2021-04-20 15:47   ` Claudio Imbrenda
@ 2021-04-26 14:31     ` Janosch Frank
  0 siblings, 0 replies; 23+ messages in thread
From: Janosch Frank @ 2021-04-26 14:31 UTC (permalink / raw)
  To: Claudio Imbrenda; +Cc: kvm, linux-s390, thuth, david

On 4/20/21 5:47 PM, Claudio Imbrenda wrote:
> On Tue, 16 Mar 2021 09:16:54 +0000
> Janosch Frank <frankja@linux.ibm.com> wrote:
> 
>> Let's also test the UV host interfaces.
>>
>> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
> 
> Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>

Thanks

> 
> the test is ok as is, but I do have a lot of ideas on how to
> improve/extend it further. Once this is merged (and once I have some
> time) I will send a few patches. 

I'm always happy to take new code for this project.
At some point we might need to split it into separate files though :)

> 
>> ---
>>  s390x/Makefile  |   1 +
>>  s390x/uv-host.c | 513
>> ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 514
>> insertions(+) create mode 100644 s390x/uv-host.c
>>
>> diff --git a/s390x/Makefile b/s390x/Makefile
>> index bbf177fa..8de926ab 100644
>> --- a/s390x/Makefile
>> +++ b/s390x/Makefile
>> @@ -21,6 +21,7 @@ tests += $(TEST_DIR)/css.elf
>>  tests += $(TEST_DIR)/uv-guest.elf
>>  tests += $(TEST_DIR)/sie.elf
>>  tests += $(TEST_DIR)/mvpg.elf
>> +tests += $(TEST_DIR)/uv-host.elf
>>  
>>  tests_binary = $(patsubst %.elf,%.bin,$(tests))
>>  ifneq ($(HOST_KEY_DOCUMENT),)
>> diff --git a/s390x/uv-host.c b/s390x/uv-host.c
>> new file mode 100644
>> index 00000000..746abd8e
>> --- /dev/null
>> +++ b/s390x/uv-host.c
>> @@ -0,0 +1,513 @@
>> +/* SPDX-License-Identifier: GPL-2.0-only */
>> +/*
>> + * Guest Ultravisor Call tests
>> + *
>> + * Copyright (c) 2021 IBM Corp
>> + *
>> + * Authors:
>> + *  Janosch Frank <frankja@linux.ibm.com>
>> + */
>> +
>> +#include <libcflat.h>
>> +#include <alloc.h>
>> +#include <vmalloc.h>
>> +#include <sclp.h>
>> +#include <smp.h>
>> +#include <asm/page.h>
>> +#include <asm/sigp.h>
>> +#include <asm/pgtable.h>
>> +#include <asm/asm-offsets.h>
>> +#include <asm/interrupt.h>
>> +#include <asm/facility.h>
>> +#include <asm/uv.h>
>> +#include <asm-generic/barrier.h>
>> +
>> +static struct uv_cb_qui uvcb_qui;
>> +static struct uv_cb_init uvcb_init;
>> +static struct uv_cb_cgc uvcb_cgc;
>> +static struct uv_cb_csc uvcb_csc;
>> +
>> +extern int diag308_load_reset(u64 code);
>> +
>> +struct cmd_list{
>> +	const char *name;
>> +	uint16_t cmd;
>> +	uint16_t len;
>> +};
>> +
>> +static void cpu_loop(void)
>> +{
>> +	for (;;) {}
>> +}
>> +
>> +static struct cmd_list cmds[] = {
>> +	{ "init", UVC_CMD_INIT_UV, sizeof(struct uv_cb_init) },
>> +	{ "create conf", UVC_CMD_CREATE_SEC_CONF, sizeof(struct
>> uv_cb_cgc) },
>> +	{ "destroy conf", UVC_CMD_DESTROY_SEC_CONF, sizeof(struct
>> uv_cb_nodata) },
>> +	{ "create cpu", UVC_CMD_CREATE_SEC_CPU, sizeof(struct
>> uv_cb_csc) },
>> +	{ "destroy cpu", UVC_CMD_DESTROY_SEC_CPU, sizeof(struct
>> uv_cb_nodata) },
>> +	{ "conv to", UVC_CMD_CONV_TO_SEC_STOR, sizeof(struct
>> uv_cb_cts) },
>> +	{ "conv from", UVC_CMD_CONV_FROM_SEC_STOR, sizeof(struct
>> uv_cb_cfs) },
>> +	{ "set sec conf", UVC_CMD_SET_SEC_CONF_PARAMS, sizeof(struct
>> uv_cb_ssc) },
>> +	{ "unpack", UVC_CMD_UNPACK_IMG, sizeof(struct uv_cb_unp) },
>> +	{ "verify", UVC_CMD_VERIFY_IMG, sizeof(struct uv_cb_nodata)
>> },
>> +	{ "cpu reset", UVC_CMD_CPU_RESET, sizeof(struct
>> uv_cb_nodata) },
>> +	{ "cpu initial reset", UVC_CMD_CPU_RESET_INITIAL,
>> sizeof(struct uv_cb_nodata) },
>> +	{ "conf clear reset", UVC_CMD_PERF_CONF_CLEAR_RESET,
>> sizeof(struct uv_cb_nodata) },
>> +	{ "cpu clear reset", UVC_CMD_CPU_RESET_CLEAR, sizeof(struct
>> uv_cb_nodata) },
>> +	{ "cpu set state", UVC_CMD_CPU_SET_STATE, sizeof(struct
>> uv_cb_cpu_set_state) },
>> +	{ "pin shared", UVC_CMD_PIN_PAGE_SHARED, sizeof(struct
>> uv_cb_cfs) },
>> +	{ "unpin shared", UVC_CMD_UNPIN_PAGE_SHARED, sizeof(struct
>> uv_cb_cts) },
>> +	{ NULL, 0, 0 },
>> +};
>> +
>> +static void test_priv(void)
>> +{
>> +	struct uv_cb_header uvcb = {};
>> +	uint16_t pgm;
>> +	int i;
>> +
>> +	report_prefix_push("privileged");
>> +	for (i = 0; cmds[i].name; i++) {
>> +		expect_pgm_int();
>> +		uvcb.cmd = cmds[i].cmd;
>> +		uvcb.len = cmds[i].len;
>> +		enter_pstate();
>> +		uv_call(0, (uint64_t)&uvcb);
>> +		pgm = clear_pgm_int();
>> +		report(pgm == PGM_INT_CODE_PRIVILEGED_OPERATION,
>> "%s", cmds[i].name);
>> +	}
>> +	report_prefix_pop();
>> +}
>> +
>> +static void test_config_destroy(void)
>> +{
>> +	int rc;
>> +	struct uv_cb_nodata uvcb = {
>> +		.header.cmd = UVC_CMD_DESTROY_SEC_CONF,
>> +		.header.len = sizeof(uvcb),
>> +		.handle = uvcb_cgc.guest_handle,
>> +	};
>> +
>> +	report_prefix_push("dsc");
>> +	uvcb.header.len -= 8;
>> +	rc = uv_call(0, (uint64_t)&uvcb);
>> +	report(rc == 1 && uvcb.header.rc == UVC_RC_INV_LEN,
>> +	       "hdr invalid length");
>> +	uvcb.header.len += 8;
>> +
>> +	uvcb.handle += 1;
>> +	rc = uv_call(0, (uint64_t)&uvcb);
>> +	report(rc == 1 && uvcb.header.rc == UVC_RC_INV_GHANDLE,
>> "invalid handle");
>> +	uvcb.handle -= 1;
>> +
>> +	rc = uv_call(0, (uint64_t)&uvcb);
>> +	report(rc == 0 && uvcb.header.rc == UVC_RC_EXECUTED,
>> "success");
>> +	report_prefix_pop();
>> +}
>> +
>> +static void test_cpu_destroy(void)
>> +{
>> +	int rc;
>> +	struct uv_cb_nodata uvcb = {
>> +		.header.len = sizeof(uvcb),
>> +		.header.cmd = UVC_CMD_DESTROY_SEC_CPU,
>> +		.handle = uvcb_csc.cpu_handle,
>> +	};
>> +
>> +	report_prefix_push("dcpu");
>> +
>> +	uvcb.header.len -= 8;
>> +	rc = uv_call(0, (uint64_t)&uvcb);
>> +	report(rc == 1 && uvcb.header.rc == UVC_RC_INV_LEN,
>> +	       "hdr invalid length");
>> +	uvcb.header.len += 8;
>> +
>> +	uvcb.handle += 1;
>> +	rc = uv_call(0, (uint64_t)&uvcb);
>> +	report(rc == 1 && uvcb.header.rc == UVC_RC_INV_CHANDLE,
>> "invalid handle");
>> +	uvcb.handle -= 1;
>> +
>> +	rc = uv_call(0, (uint64_t)&uvcb);
>> +	report(rc == 0 && uvcb.header.rc == UVC_RC_EXECUTED,
>> "success"); +
>> +	report_prefix_pop();
>> +}
>> +
>> +static void test_cpu_create(void)
>> +{
>> +	int rc;
>> +	unsigned long tmp;
>> +
>> +	report_prefix_push("csc");
>> +	uvcb_csc.header.len = sizeof(uvcb_csc);
>> +	uvcb_csc.header.cmd = UVC_CMD_CREATE_SEC_CPU;
>> +	uvcb_csc.guest_handle = uvcb_cgc.guest_handle;
>> +	uvcb_csc.stor_origin = (unsigned long)memalign(PAGE_SIZE,
>> uvcb_qui.cpu_stor_len);
>> +	uvcb_csc.state_origin = (unsigned long)memalign(PAGE_SIZE,
>> PAGE_SIZE); +
>> +	uvcb_csc.header.len -= 8;
>> +	rc = uv_call(0, (uint64_t)&uvcb_csc);
>> +	report(uvcb_csc.header.rc == UVC_RC_INV_LEN && rc == 1 &&
>> +	       !uvcb_csc.cpu_handle, "hdr invalid length");
>> +	uvcb_csc.header.len += 8;
>> +
>> +	uvcb_csc.guest_handle += 1;
>> +	rc = uv_call(0, (uint64_t)&uvcb_csc);
>> +	report(uvcb_csc.header.rc == UVC_RC_INV_GHANDLE && rc == 1,
>> +	       "invalid guest handle");
>> +	uvcb_csc.guest_handle -= 1;
>> +
>> +	uvcb_csc.num = uvcb_qui.max_guest_cpus + 1;
>> +	rc = uv_call(0, (uint64_t)&uvcb_csc);
>> +	report(uvcb_csc.header.rc == 0x103 && rc == 1,
>> +	       "invalid cpu #");
>> +	uvcb_csc.num = 0;
>> +
>> +	tmp = uvcb_csc.stor_origin;
>> +	uvcb_csc.stor_origin = get_max_ram_size() + PAGE_SIZE;
>> +	rc = uv_call(0, (uint64_t)&uvcb_csc);
>> +	report(uvcb_csc.header.rc == 0x105 && rc == 1,
>> +	       "cpu stor inaccessible");
>> +	uvcb_csc.stor_origin = tmp;
>> +
>> +	tmp = uvcb_csc.stor_origin;
>> +	uvcb_csc.stor_origin = 0;
>> +	rc = uv_call(0, (uint64_t)&uvcb_csc);
>> +	report(uvcb_csc.header.rc == 0x106 && rc == 1,
>> +	       "cpu stor in lowcore");
>> +	uvcb_csc.stor_origin = tmp;
>> +
>> +	tmp = uvcb_csc.state_origin;
>> +	uvcb_csc.state_origin = get_max_ram_size() + PAGE_SIZE;
>> +	rc = uv_call(0, (uint64_t)&uvcb_csc);
>> +	report(uvcb_csc.header.rc == 0x107 && rc == 1,
>> +	       "SIE SD inaccessible");
>> +	uvcb_csc.state_origin = tmp;
>> +
>> +	rc = uv_call(0, (uint64_t)&uvcb_csc);
>> +	report(rc == 0 && uvcb_csc.header.rc == UVC_RC_EXECUTED &&
>> +	       uvcb_csc.cpu_handle, "success");
>> +
>> +	tmp = uvcb_csc.stor_origin;
>> +	uvcb_csc.stor_origin = (unsigned long)memalign(PAGE_SIZE,
>> uvcb_qui.cpu_stor_len);
>> +	rc = uv_call(0, (uint64_t)&uvcb_csc);
>> +	report(rc == 1 && uvcb_csc.header.rc == 0x104, "already
>> defined");
>> +	uvcb_csc.stor_origin = tmp;
>> +	report_prefix_pop();
>> +}
>> +
>> +static void test_config_create(void)
>> +{
>> +	int rc;
>> +	unsigned long vsize, tmp;
>> +	static struct uv_cb_cgc uvcb;
>> +
>> +	uvcb_cgc.header.cmd = UVC_CMD_CREATE_SEC_CONF;
>> +	uvcb_cgc.header.len = sizeof(uvcb_cgc);
>> +	report_prefix_push("cgc");
>> +
>> +	uvcb_cgc.guest_stor_origin = 0;
>> +	uvcb_cgc.guest_stor_len = 42 * (1UL << 20);
>> +	vsize = uvcb_qui.conf_base_virt_stor_len +
>> +		((uvcb_cgc.guest_stor_len / (1UL << 20)) *
>> uvcb_qui.conf_virt_var_stor_len); +
>> +	uvcb_cgc.conf_base_stor_origin =
>> (uint64_t)memalign(PAGE_SIZE * 4, uvcb_qui.conf_base_phys_stor_len);
>> +	uvcb_cgc.conf_var_stor_origin =
>> (uint64_t)memalign(PAGE_SIZE, vsize);
>> +	uvcb_cgc.guest_asce = (uint64_t)memalign(PAGE_SIZE, 4 *
>> PAGE_SIZE) | ASCE_DT_SEGMENT | REGION_TABLE_LENGTH | ASCE_P;
>> +	uvcb_cgc.guest_sca = (uint64_t)memalign(PAGE_SIZE * 4,
>> PAGE_SIZE * 4); +
>> +	uvcb_cgc.header.len -= 8;
>> +	rc = uv_call(0, (uint64_t)&uvcb_cgc);
>> +	report(uvcb_cgc.header.rc == UVC_RC_INV_LEN && rc == 1 &&
>> +	       !uvcb_cgc.guest_handle, "hdr invalid length");
>> +	uvcb_cgc.header.len += 8;
>> +
>> +	uvcb_cgc.guest_stor_origin = uvcb_qui.max_guest_stor_addr +
>> (1UL << 20) * 2 + 1;
>> +	rc = uv_call(0, (uint64_t)&uvcb_cgc);
>> +	report(uvcb_cgc.header.rc == 0x101 && rc == 1,
>> +	       "MSO > max guest addr");
>> +	uvcb_cgc.guest_stor_origin = 0;
>> +
>> +	uvcb_cgc.guest_stor_origin = uvcb_qui.max_guest_stor_addr -
>> (1UL << 20);
>> +	rc = uv_call(0, (uint64_t)&uvcb_cgc);
>> +	report(uvcb_cgc.header.rc == 0x102 && rc == 1,
>> +	       "MSO + MSL > max guest addr");
>> +	uvcb_cgc.guest_stor_origin = 0;
>> +
>> +	uvcb_cgc.guest_asce &= ~ASCE_P;
>> +	rc = uv_call(0, (uint64_t)&uvcb_cgc);
>> +	report(uvcb_cgc.header.rc == 0x105 && rc == 1,
>> +	       "ASCE private bit missing");
>> +	uvcb_cgc.guest_asce |= ASCE_P;
>> +
>> +	uvcb_cgc.guest_asce |= 0x20;
>> +	rc = uv_call(0, (uint64_t)&uvcb_cgc);
>> +	report(uvcb_cgc.header.rc == 0x105 && rc == 1,
>> +	       "ASCE bit 58 set");
>> +	uvcb_cgc.guest_asce &= ~0x20;
>> +
>> +	tmp = uvcb_cgc.conf_base_stor_origin;
>> +	uvcb_cgc.conf_base_stor_origin = get_max_ram_size() + 8;
>> +	rc = uv_call(0, (uint64_t)&uvcb_cgc);
>> +	report(uvcb_cgc.header.rc == 0x108 && rc == 1,
>> +	       "base storage origin > available memory");
>> +	uvcb_cgc.conf_base_stor_origin = tmp;
>> +
>> +	tmp = uvcb_cgc.conf_base_stor_origin;
>> +	uvcb_cgc.conf_base_stor_origin = 0x1000;
>> +	rc = uv_call(0, (uint64_t)&uvcb_cgc);
>> +	report(uvcb_cgc.header.rc == 0x109 && rc == 1,
>> +	       "base storage origin contains lowcore");
>> +	uvcb_cgc.conf_base_stor_origin = tmp;
>> +
>> +	if (smp_query_num_cpus() == 1) {
>> +		sigp_retry(1, SIGP_SET_PREFIX,
>> +			   uvcb_cgc.conf_var_stor_origin +
>> PAGE_SIZE, NULL);
>> +		rc = uv_call(0, (uint64_t)&uvcb_cgc);
>> +		report(uvcb_cgc.header.rc == 0x10e && rc == 1 &&
>> +		       !uvcb_cgc.guest_handle, "variable storage
>> area contains lowcore");
>> +		sigp_retry(1, SIGP_SET_PREFIX, 0x0, NULL);
>> +	}
>> +
>> +	tmp = uvcb_cgc.guest_sca;
>> +	uvcb_cgc.guest_sca = 0;
>> +	rc = uv_call(0, (uint64_t)&uvcb_cgc);
>> +	report(uvcb_cgc.header.rc == 0x10c && rc == 1,
>> +	       "sca == 0");
>> +	uvcb_cgc.guest_sca = tmp;
>> +
>> +	tmp = uvcb_cgc.guest_sca;
>> +	uvcb_cgc.guest_sca = get_max_ram_size() + + PAGE_SIZE * 4;
>> +	rc = uv_call(0, (uint64_t)&uvcb_cgc);
>> +	report(uvcb_cgc.header.rc == 0x10d && rc == 1,
>> +	       "sca inaccessible");
>> +	uvcb_cgc.guest_sca = tmp;
>> +
>> +	rc = uv_call(0, (uint64_t)&uvcb_cgc);
>> +	report(rc == 0 && uvcb_cgc.header.rc == UVC_RC_EXECUTED,
>> "successful"); +
>> +	uvcb_cgc.header.rc = 0;
>> +	uvcb_cgc.header.rrc = 0;
>> +	tmp = uvcb_cgc.guest_handle;
>> +	uvcb_cgc.guest_handle = 0;
>> +	rc = uv_call(0, (uint64_t)&uvcb_cgc);
>> +	report(uvcb_cgc.header.rc >= 0x100 && rc == 1, "reuse uvcb");
>> +	uvcb_cgc.guest_handle = tmp;
>> +
>> +	/* Copy over most data from uvcb_cgc, so we have the ASCE
>> that was used. */
>> +	memcpy(&uvcb, &uvcb_cgc, sizeof(uvcb));
>> +
>> +	/* Reset the header and handle */
>> +	uvcb.header.rc = 0;
>> +	uvcb.header.rrc = 0;
>> +	uvcb.guest_handle = 0;
>> +
>> +	/* Use new storage areas. */
>> +	uvcb.conf_base_stor_origin = (uint64_t)memalign(PAGE_SIZE *
>> 4, uvcb_qui.conf_base_phys_stor_len);
>> +	uvcb.conf_var_stor_origin = (uint64_t)memalign(PAGE_SIZE,
>> vsize); +
>> +	rc = uv_call(0, (uint64_t)&uvcb);
>> +	report(uvcb.header.rc >= 0x104 && rc == 1 &&
>> !uvcb.guest_handle,
>> +	       "reuse ASCE");
>> +	free((void *)uvcb.conf_base_stor_origin);
>> +	free((void *)uvcb.conf_var_stor_origin);
>> +
>> +
>> +	/* Missing: 106, 10a, a0b */
>> +	report_prefix_pop();
>> +}
>> +
>> +static void test_init(void)
>> +{
>> +	int rc;
>> +	uint64_t mem;
>> +	struct psw psw;
>> +
>> +	/* Donated storage needs to be over 2GB */
>> +	mem = (uint64_t)memalign(1UL << 31,
>> uvcb_qui.uv_base_stor_len); +
>> +	uvcb_init.header.len = sizeof(uvcb_init);
>> +	uvcb_init.header.cmd = UVC_CMD_INIT_UV;
>> +	uvcb_init.stor_origin = mem;
>> +	uvcb_init.stor_len = uvcb_qui.uv_base_stor_len;
>> +
>> +	report_prefix_push("init");
>> +	uvcb_init.header.len -= 8;
>> +	rc = uv_call(0, (uint64_t)&uvcb_init);
>> +	report(rc == 1 && uvcb_init.header.rc == UVC_RC_INV_LEN,
>> +	       "hdr invalid length");
>> +	uvcb_init.header.len += 8;
>> +
>> +	uvcb_init.stor_len -= 8;
>> +	rc = uv_call(0, (uint64_t)&uvcb_init);
>> +	report(rc == 1 && uvcb_init.header.rc == 0x103,
>> +	       "storage invalid length");
>> +	uvcb_init.stor_len += 8;
>> +
>> +	uvcb_init.stor_origin =  get_max_ram_size() + 8;
>> +	rc = uv_call(0, (uint64_t)&uvcb_init);
>> +	report(rc == 1 && uvcb_init.header.rc == 0x104,
>> +	       "storage origin invalid");
>> +	uvcb_init.stor_origin = mem;
>> +
>> +	uvcb_init.stor_origin = get_max_ram_size() - 8;
>> +	rc = uv_call(0, (uint64_t)&uvcb_init);
>> +	report(rc == 1 && uvcb_init.header.rc == 0x105,
>> +	       "storage + length invalid");
>> +	uvcb_init.stor_origin = mem;
>> +
>> +	uvcb_init.stor_origin = 1UL << 30;
>> +	rc = uv_call(0, (uint64_t)&uvcb_init);
>> +	report(rc == 1 && uvcb_init.header.rc == 0x108,
>> +	       "storage below 2GB");
>> +	uvcb_init.stor_origin = mem;
>> +
>> +	psw.mask = extract_psw_mask();
>> +	psw.addr = (unsigned long)cpu_loop;
>> +	smp_cpu_setup(1, psw);
>> +	rc = uv_call(0, (uint64_t)&uvcb_init);
>> +	report(rc == 1 && uvcb_init.header.rc == 0x102,
>> +	       "too many running cpus");
>> +	smp_cpu_stop(1);
>> +
>> +	rc = uv_call(0, (uint64_t)&uvcb_init);
>> +	report(rc == 0 && uvcb_init.header.rc == UVC_RC_EXECUTED,
>> "successful"); +
>> +	mem = (uint64_t)memalign(1UL << 31,
>> uvcb_qui.uv_base_stor_len);
>> +	rc = uv_call(0, (uint64_t)&uvcb_init);
>> +	report(rc == 1 && uvcb_init.header.rc == 0x101, "double
>> init");
>> +	free((void *)mem);
>> +
>> +	report_prefix_pop();
>> +}
>> +
>> +static void test_query(void)
>> +{
>> +	uvcb_qui.header.cmd = UVC_CMD_QUI;
>> +	uvcb_qui.header.len = sizeof(uvcb_qui);
>> +	uint64_t *call_list = &uvcb_qui.inst_calls_list[0];
>> +
>> +	report_prefix_push("query");
>> +	uvcb_qui.header.len = 0xa0;
>> +	uv_call(0, (uint64_t)&uvcb_qui);
>> +	report(uvcb_qui.header.rc == UVC_RC_INV_LEN, "length");
>> +
>> +	uvcb_qui.header.len = 0xa8;
>> +	uv_call(0, (uint64_t)&uvcb_qui);
>> +	report(uvcb_qui.header.rc == 0x100, "insf length");
>> +
>> +	uvcb_qui.header.len = sizeof(uvcb_qui);
>> +	uv_call(0, (uint64_t)&uvcb_qui);
>> +	report(uvcb_qui.header.rc == UVC_RC_EXECUTED, "successful
>> query"); +
>> +	report(test_bit_inv(BIT_UVC_CMD_QUI, call_list) &&
>> +	       test_bit_inv(BIT_UVC_CMD_INIT_UV, call_list),
>> +	       "query and init indicated");
>> +
>> +	report(test_bit_inv(BIT_UVC_CMD_CREATE_SEC_CONF, call_list)
>> &&
>> +	       test_bit_inv(BIT_UVC_CMD_DESTROY_SEC_CONF, call_list),
>> +	       "create/destroy vm indicated");
>> +
>> +	report(test_bit_inv(BIT_UVC_CMD_CREATE_SEC_CPU, call_list) &&
>> +	       test_bit_inv(BIT_UVC_CMD_DESTROY_SEC_CPU, call_list),
>> +	       "create/destroy cpu indicated");
>> +
>> +	report(test_bit_inv(BIT_UVC_CMD_CONV_TO_SEC_STOR, call_list)
>> &&
>> +	       test_bit_inv(BIT_UVC_CMD_CONV_FROM_SEC_STOR,
>> call_list),
>> +	       "convert to/from secure storage indicated");
>> +
>> +	report(test_bit_inv(BIT_UVC_CMD_SET_SEC_PARMS, call_list) &&
>> +	       test_bit_inv(BIT_UVC_CMD_UNPACK_IMG, call_list) &&
>> +	       test_bit_inv(BIT_UVC_CMD_CPU_SET_STATE, call_list) &&
>> +	       test_bit_inv(BIT_UVC_CMD_VERIFY_IMG, call_list),
>> +	       "set sec parm, setcpu state, unpack and verify
>> indicated"); +
>> +	report(test_bit_inv(BIT_UVC_CMD_CPU_RESET, call_list) &&
>> +	       test_bit_inv(BIT_UVC_CMD_CPU_RESET_INITIAL,
>> call_list) &&
>> +	       test_bit_inv(BIT_UVC_CMD_CPU_PERFORM_CLEAR_RESET,
>> call_list),
>> +	       "resets indicated");
>> +
>> +	report(test_bit_inv(BIT_UVC_CMD_PREPARE_CLEAR_RESET,
>> call_list) &&
>> +	       test_bit_inv(BIT_UVC_CMD_UNSHARE_ALL, call_list),
>> +	       "prepare reset and unshare all indicated");
>> +
>> +	report(test_bit_inv(BIT_UVC_CMD_PIN_PAGE_SHARED, call_list)
>> &&
>> +	       test_bit_inv(BIT_UVC_CMD_UNPIN_PAGE_SHARED,
>> call_list),
>> +	       "(un)pin shared page indicated");
>> +
>> +	report(!test_bit_inv(BIT_UVC_CMD_SET_SHARED_ACCESS,
>> call_list) &&
>> +	       !test_bit_inv(BIT_UVC_CMD_REMOVE_SHARED_ACCESS,
>> call_list),
>> +	       "(un)share not indicated");
>> +
>> +	report_prefix_pop();
>> +}
>> +
>> +static struct cmd_list invalid_cmds[] = {
>> +	{ "bogus", 0x4242, sizeof(struct uv_cb_header) },
>> +	{ "share", UVC_CMD_SET_SHARED_ACCESS, sizeof(struct
>> uv_cb_share) },
>> +	{ "unshare", UVC_CMD_REMOVE_SHARED_ACCESS, sizeof(struct
>> uv_cb_share) },
>> +	{ NULL, 0, 0 },
>> +};
>> +
>> +static void test_invalid(void)
>> +{
>> +	struct uv_cb_header hdr = {};
>> +	int i, cc;
>> +
>> +	report_prefix_push("invalid");
>> +	for (i = 0; invalid_cmds[i].name; i++) {
>> +		hdr.cmd = invalid_cmds[i].cmd;
>> +		hdr.len = invalid_cmds[i].len;
>> +		cc = uv_call(0, (uint64_t)&hdr);
>> +		report(cc == 1 && hdr.rc == UVC_RC_INV_CMD, "%s",
>> +		       invalid_cmds[i].name);
>> +	}
>> +	report_prefix_pop();
>> +}
>> +
>> +static void test_clear(void)
>> +{
>> +	uint64_t *tmp = (void *)uvcb_init.stor_origin;
>> +
>> +	diag308_load_reset(1);
>> +	sclp_console_setup();
>> +	report(!*tmp, "memory cleared after reset 1");
>> +}
>> +
>> +static void setup_vmem(void)
>> +{
>> +	uint64_t asce, mask;
>> +
>> +	setup_mmu(get_max_ram_size());
>> +	asce = stctg(1);
>> +	lctlg(13, asce);
>> +	mask = extract_psw_mask() | 0x0000C00000000000UL;
>> +	load_psw_mask(mask);
>> +}
>> +
>> +int main(void)
>> +{
>> +	bool has_uvc = test_facility(158);
>> +
>> +	report_prefix_push("uvc");
>> +	if (!has_uvc) {
>> +		report_skip("Ultravisor call facility is not
>> available");
>> +		goto done;
>> +	}
>> +
>> +	test_priv();
>> +	test_invalid();
>> +	test_query();
>> +	test_init();
>> +
>> +	setup_vmem();
>> +	test_config_create();
>> +	test_cpu_create();
>> +	test_cpu_destroy();
>> +	test_config_destroy();
>> +	test_clear();
>> +
>> +done:
>> +	return report_summary();
>> +}
> 


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

* Re: [kvm-unit-tests PATCH 2/6] s390x: Add more Ultravisor command structure definitions
  2021-04-21 11:13   ` Cornelia Huck
@ 2021-04-26 14:33     ` Janosch Frank
  0 siblings, 0 replies; 23+ messages in thread
From: Janosch Frank @ 2021-04-26 14:33 UTC (permalink / raw)
  To: Cornelia Huck; +Cc: kvm, linux-s390, thuth, david, imbrenda

On 4/21/21 1:13 PM, Cornelia Huck wrote:
> On Tue, 16 Mar 2021 09:16:50 +0000
> Janosch Frank <frankja@linux.ibm.com> wrote:
> 
>> They are needed in the new UV tests.
>>
>> As we now extend the size of the query struct, we need to set the
>> length in the UV guest query test to a constant instead of using
>> sizeof.
>>
>> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
>> ---
>>  lib/s390x/asm/uv.h | 148 ++++++++++++++++++++++++++++++++++++++++++++-
>>  s390x/uv-guest.c   |   2 +-
>>  2 files changed, 148 insertions(+), 2 deletions(-)
>>
> 
> (...)
> 
>>  struct uv_cb_qui {
>>  	struct uv_cb_header header;
>>  	u64 reserved08;
>>  	u64 inst_calls_list[4];
>> -	u64 reserved30[15];
>> +	u64 reserved30[2];
>> +	u64 uv_base_stor_len;
>> +	u64 reserved48;
>> +	u64 conf_base_phys_stor_len;
>> +	u64 conf_base_virt_stor_len;
>> +	u64 conf_virt_var_stor_len;
>> +	u64 cpu_stor_len;
>> +	u32 reserved70[3];
>> +	u32 max_num_sec_conf;
>> +	u64 max_guest_stor_addr;
>> +	u8  reserved88[158 - 136];
>> +	u16 max_guest_cpus;
>> +	u8  reserveda0[200 - 160];
>> +}  __attribute__((packed))  __attribute__((aligned(8)));
> 
> (...)
> 
>> diff --git a/s390x/uv-guest.c b/s390x/uv-guest.c
>> index a13669ab..95a968c5 100644
>> --- a/s390x/uv-guest.c
>> +++ b/s390x/uv-guest.c
>> @@ -59,7 +59,7 @@ static void test_query(void)
>>  {
>>  	struct uv_cb_qui uvcb = {
>>  		.header.cmd = UVC_CMD_QUI,
>> -		.header.len = sizeof(uvcb) - 8,
>> +		.header.len = 0xa0,
> 
> This is a magic constant coming out of nowhere. Could you please at
> least add a comment to make clear what you are testing?

Added:
/* A dword below the minimum length */

> 
>>  	};
>>  	int cc;
>>  
> 


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

end of thread, other threads:[~2021-04-26 14:33 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-16  9:16 [kvm-unit-tests PATCH 0/6] s390x: uv: Extend guest test and add host test Janosch Frank
2021-03-16  9:16 ` [kvm-unit-tests PATCH 1/6] s390x: uv-guest: Add invalid share location test Janosch Frank
2021-04-19 11:24   ` Thomas Huth
2021-04-19 11:45     ` Janosch Frank
2021-04-20  8:48       ` Thomas Huth
2021-04-20 13:40   ` Claudio Imbrenda
2021-04-21 11:04   ` Cornelia Huck
2021-03-16  9:16 ` [kvm-unit-tests PATCH 2/6] s390x: Add more Ultravisor command structure definitions Janosch Frank
2021-04-20 14:09   ` Claudio Imbrenda
2021-04-21 11:13   ` Cornelia Huck
2021-04-26 14:33     ` Janosch Frank
2021-03-16  9:16 ` [kvm-unit-tests PATCH 3/6] s390x: uv: Add UV lib Janosch Frank
2021-04-20 14:15   ` Claudio Imbrenda
2021-04-26 14:20     ` Janosch Frank
2021-03-16  9:16 ` [kvm-unit-tests PATCH 4/6] s390x: Test for share/unshare call support before using them Janosch Frank
2021-04-20 14:18   ` Claudio Imbrenda
2021-03-16  9:16 ` [kvm-unit-tests PATCH 5/6] s390x: uv-guest: Test invalid commands Janosch Frank
2021-04-20 14:26   ` Claudio Imbrenda
2021-04-26 13:40     ` Janosch Frank
2021-03-16  9:16 ` [kvm-unit-tests PATCH 6/6] s390x: Add UV host test Janosch Frank
2021-04-20 15:47   ` Claudio Imbrenda
2021-04-26 14:31     ` Janosch Frank
2021-04-19  7:24 ` [kvm-unit-tests PATCH 0/6] s390x: uv: Extend guest test and add " Janosch Frank

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.