Skip to contentSkip to conversation

s390x: SIE cleanup 2

PATCH Superseded Janosch Frank 3 participants 19 messages Jul 29, 2021 – Aug 3, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover s390x: SIE cleanup 2

Time to deduplicate code before we copy it around even more.

Most problems originated from my desire to rapidly integrate SIE PV support and as more and more people are using the SIE support it's time to have a SIE library.

The SIE lib is by no means perfect. For that we might need a few more iterations but it's good enough that we only need a bit of code in the tests to get a guest going. This means we have a low entry to test development which is my main goal.

Janosch Frank (4):
s390x: sie: Add sie lib validity handling
s390x: lib: Introduce HPAGE_* constants
s390x: lib: sie: Add struct vm (de)initialization functions
lib: s390x: sie: Move sie function into library

 lib/s390x/asm/page.h |  4 +++
 lib/s390x/sie.c      | 84 ++++++++++++++++++++++++++++++++++++++++++++
 lib/s390x/sie.h      |  7 ++++
 s390x/Makefile       |  1 +
 s390x/mvpg-sie.c     | 31 ++--------------
 s390x/sie.c          | 41 ++-------------------
 6 files changed, 101 insertions(+), 67 deletions(-)
 create mode 100644 lib/s390x/sie.c
Signature · 1 line
2.30.2
#1 lore raw

PATCH 1/4 s390x: sie: Add sie lib validity handling

Let's start off the SIE lib with validity handling code since that has the least amount of dependencies to other files.

---
 lib/s390x/sie.c  | 41 +++++++++++++++++++++++++++++++++++++++++
 lib/s390x/sie.h  |  3 +++
 s390x/Makefile   |  1 +
 s390x/mvpg-sie.c |  2 +-
 s390x/sie.c      |  7 +------
 5 files changed, 47 insertions(+), 7 deletions(-)
 create mode 100644 lib/s390x/sie.c
lib/s390x/sie.c new file +41 -0
new file mode 100644
index 00000000..9107519f
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Virtualization library that speeds up managing guests.
+ *
+ * Copyright (c) 2021 IBM Corp
+ *
+ * Authors:
+ *  Janosch Frank <[email protected]>
+ */
+
+#include <asm/barrier.h>
+#include <libcflat.h>
+#include <sie.h>
+
+static bool validity_expected;
+static uint16_t vir;
+
+void sie_expect_validity(void)
+{
+	validity_expected = true;
+	vir = 0;
+}
+
+void sie_check_validity(uint16_t vir_exp)
+{
+	report(vir_exp == vir, "VALIDITY: %x", vir);
+	mb();
+	vir = 0;
+}
+
+void sie_handle_validity(struct vm *vm)
+{
+	if (vm->sblk->icptcode != ICPT_VALIDITY)
+		return;
+
+	vir = vm->sblk->ipb >> 16;
+
+	if (!validity_expected)
+		report_abort("VALIDITY: %x", vir);
+	validity_expected = false;
+}
lib/s390x/sie.h +3 -0
index 6ba858a2..7ff98d2d 100644
@@ -197,5 +197,8 @@ struct vm {
 extern void sie_entry(void);
 extern void sie_exit(void);
 extern void sie64a(struct kvm_s390_sie_block *sblk, struct vm_save_area *save_area);
+void sie_expect_validity(void);
+void sie_check_validity(uint16_t vir_exp);
+void sie_handle_validity(struct vm *vm);
 
 #endif /* _S390X_SIE_H_ */
s390x/Makefile +1 -0
index 6565561b..ef8041a6 100644
@@ -71,6 +71,7 @@ cflatobjs += lib/s390x/css_dump.o
 cflatobjs += lib/s390x/css_lib.o
 cflatobjs += lib/s390x/malloc_io.o
 cflatobjs += lib/s390x/uv.o
+cflatobjs += lib/s390x/sie.o
 
 OBJDIRS += lib/s390x
 
s390x/mvpg-sie.c +1 -1
index 5e70f591..2ac91eec 100644
@@ -39,7 +39,7 @@ static void sie(struct vm *vm)
 
 	while (vm->sblk->icptcode == 0) {
 		sie64a(vm->sblk, &vm->save_area);
-		assert(vm->sblk->icptcode != ICPT_VALIDITY);
+		sie_handle_validity(vm);
 	}
 	vm->save_area.guest.grs[14] = vm->sblk->gg14;
 	vm->save_area.guest.grs[15] = vm->sblk->gg15;
s390x/sie.c +1 -6
index 134d3c4f..5c798a9e 100644
@@ -24,17 +24,12 @@ static u8 *guest;
 static u8 *guest_instr;
 static struct vm vm;
 
-static void handle_validity(struct vm *vm)
-{
-	report(0, "VALIDITY: %x", vm->sblk->ipb >> 16);
-}
 
 static void sie(struct vm *vm)
 {
 	while (vm->sblk->icptcode == 0) {
 		sie64a(vm->sblk, &vm->save_area);
-		if (vm->sblk->icptcode == ICPT_VALIDITY)
-			handle_validity(vm);
+		sie_handle_validity(vm);
 	}
 	vm->save_area.guest.grs[14] = vm->sblk->gg14;
 	vm->save_area.guest.grs[15] = vm->sblk->gg15;
Signature · 1 line
2.30.2
#2 lore raw

Re: [kvm-unit-tests PATCH 1/4] s390x: sie: Add sie lib validity handling

Quoted 36 lines · On Thu, 29 Jul 2021 13:48:00 +0000 Janosch Frank <[email protected]> wrote:

Let's start off the SIE lib with validity handling code since that has the least amount of dependencies to other files.

---
 lib/s390x/sie.c  | 41 +++++++++++++++++++++++++++++++++++++++++
 lib/s390x/sie.h  |  3 +++
 s390x/Makefile   |  1 +
 s390x/mvpg-sie.c |  2 +-
 s390x/sie.c      |  7 +------
 5 files changed, 47 insertions(+), 7 deletions(-)
 create mode 100644 lib/s390x/sie.c
lib/s390x/sie.c new file +17 -0
new file mode 100644
index 00000000..9107519f
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Virtualization library that speeds up managing guests.
+ *
+ * Copyright (c) 2021 IBM Corp
+ *
+ * Authors:
+ *  Janosch Frank <[email protected]>
+ */
+
+#include <asm/barrier.h>
+#include <libcflat.h>
+#include <sie.h>
+
+static bool validity_expected;
+static uint16_t vir;
+

lib/s390x/sie.c line 27

Quoted 10 lines
lib/s390x/sie.c new file +10 -0
+void sie_expect_validity(void)
+{
+	validity_expected = true;
+	vir = 0;
+}
+
+void sie_check_validity(uint16_t vir_exp)
+{
+	report(vir_exp == vir, "VALIDITY: %x", vir);
+	mb();

why the barrier?

Quoted 75 lines
lib/s390x/sie.c new file +14 -0
+	vir = 0;
+}
+
+void sie_handle_validity(struct vm *vm)
+{
+	if (vm->sblk->icptcode != ICPT_VALIDITY)
+		return;
+
+	vir = vm->sblk->ipb >> 16;
+
+	if (!validity_expected)
+		report_abort("VALIDITY: %x", vir);
+	validity_expected = false;
+}
lib/s390x/sie.h +2 -0
index 6ba858a2..7ff98d2d 100644
@@ -197,5 +197,8 @@ struct vm {
 extern void sie_entry(void);
 extern void sie_exit(void);
 extern void sie64a(struct kvm_s390_sie_block *sblk, struct
 vm_save_area *save_area); +void sie_expect_validity(void);
+void sie_check_validity(uint16_t vir_exp);
+void sie_handle_validity(struct vm *vm);
 
 #endif /* _S390X_SIE_H_ */
s390x/Makefile +1 -0
index 6565561b..ef8041a6 100644
@@ -71,6 +71,7 @@ cflatobjs += lib/s390x/css_dump.o
 cflatobjs += lib/s390x/css_lib.o
 cflatobjs += lib/s390x/malloc_io.o
 cflatobjs += lib/s390x/uv.o
+cflatobjs += lib/s390x/sie.o
 
 OBJDIRS += lib/s390x
 
s390x/mvpg-sie.c +1 -1
index 5e70f591..2ac91eec 100644
@@ -39,7 +39,7 @@ static void sie(struct vm *vm)
 
 	while (vm->sblk->icptcode == 0) {
 		sie64a(vm->sblk, &vm->save_area);
-		assert(vm->sblk->icptcode != ICPT_VALIDITY);
+		sie_handle_validity(vm);
 	}
 	vm->save_area.guest.grs[14] = vm->sblk->gg14;
 	vm->save_area.guest.grs[15] = vm->sblk->gg15;
s390x/sie.c +1 -6
index 134d3c4f..5c798a9e 100644
@@ -24,17 +24,12 @@ static u8 *guest;
 static u8 *guest_instr;
 static struct vm vm;
 
-static void handle_validity(struct vm *vm)
-{
-	report(0, "VALIDITY: %x", vm->sblk->ipb >> 16);
-}
 
 static void sie(struct vm *vm)
 {
 	while (vm->sblk->icptcode == 0) {
 		sie64a(vm->sblk, &vm->save_area);
-		if (vm->sblk->icptcode == ICPT_VALIDITY)
-			handle_validity(vm);
+		sie_handle_validity(vm);
 	}
 	vm->save_area.guest.grs[14] = vm->sblk->gg14;
 	vm->save_area.guest.grs[15] = vm->sblk->gg15;
#3 lore raw

Re: [kvm-unit-tests PATCH 1/4] s390x: sie: Add sie lib validity handling

Quoted 43 lines · Claudio Imbrenda
Quoted 40 lines · On Thu, 29 Jul 2021 13:48:00 +0000 Janosch Frank <[email protected]> wrote:

Let's start off the SIE lib with validity handling code since that has the least amount of dependencies to other files.

---
 lib/s390x/sie.c  | 41 +++++++++++++++++++++++++++++++++++++++++
 lib/s390x/sie.h  |  3 +++
 s390x/Makefile   |  1 +
 s390x/mvpg-sie.c |  2 +-
 s390x/sie.c      |  7 +------
 5 files changed, 47 insertions(+), 7 deletions(-)
 create mode 100644 lib/s390x/sie.c
lib/s390x/sie.c new file +21 -0
new file mode 100644
index 00000000..9107519f
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Virtualization library that speeds up managing guests.
+ *
+ * Copyright (c) 2021 IBM Corp
+ *
+ * Authors:
+ *  Janosch Frank <[email protected]>
+ */
+
+#include <asm/barrier.h>
+#include <libcflat.h>
+#include <sie.h>
+
+static bool validity_expected;
+static uint16_t vir;
+
+void sie_expect_validity(void)
+{
+	validity_expected = true;
+	vir = 0;
Quoted 8 lines

lib/s390x/sie.c line 27

Quoted 6 lines
lib/s390x/sie.c new file +6 -0
+}
+
+void sie_check_validity(uint16_t vir_exp)
+{
+	report(vir_exp == vir, "VALIDITY: %x", vir);
+	mb();

why the barrier?

That's left over, I'll remove it.

Quoted 77 lines
Quoted 76 lines
lib/s390x/sie.c new file +14 -0
+	vir = 0;
+}
+
+void sie_handle_validity(struct vm *vm)
+{
+	if (vm->sblk->icptcode != ICPT_VALIDITY)
+		return;
+
+	vir = vm->sblk->ipb >> 16;
+
+	if (!validity_expected)
+		report_abort("VALIDITY: %x", vir);
+	validity_expected = false;
+}
lib/s390x/sie.h +2 -0
index 6ba858a2..7ff98d2d 100644
@@ -197,5 +197,8 @@ struct vm {
 extern void sie_entry(void);
 extern void sie_exit(void);
 extern void sie64a(struct kvm_s390_sie_block *sblk, struct
 vm_save_area *save_area); +void sie_expect_validity(void);
+void sie_check_validity(uint16_t vir_exp);
+void sie_handle_validity(struct vm *vm);
 
 #endif /* _S390X_SIE_H_ */
s390x/Makefile +1 -0
index 6565561b..ef8041a6 100644
@@ -71,6 +71,7 @@ cflatobjs += lib/s390x/css_dump.o
 cflatobjs += lib/s390x/css_lib.o
 cflatobjs += lib/s390x/malloc_io.o
 cflatobjs += lib/s390x/uv.o
+cflatobjs += lib/s390x/sie.o
 
 OBJDIRS += lib/s390x
 
s390x/mvpg-sie.c +1 -1
index 5e70f591..2ac91eec 100644
@@ -39,7 +39,7 @@ static void sie(struct vm *vm)
 
 	while (vm->sblk->icptcode == 0) {
 		sie64a(vm->sblk, &vm->save_area);
-		assert(vm->sblk->icptcode != ICPT_VALIDITY);
+		sie_handle_validity(vm);
 	}
 	vm->save_area.guest.grs[14] = vm->sblk->gg14;
 	vm->save_area.guest.grs[15] = vm->sblk->gg15;
s390x/sie.c +1 -6
index 134d3c4f..5c798a9e 100644
@@ -24,17 +24,12 @@ static u8 *guest;
 static u8 *guest_instr;
 static struct vm vm;
 
-static void handle_validity(struct vm *vm)
-{
-	report(0, "VALIDITY: %x", vm->sblk->ipb >> 16);
-}
 
 static void sie(struct vm *vm)
 {
 	while (vm->sblk->icptcode == 0) {
 		sie64a(vm->sblk, &vm->save_area);
-		if (vm->sblk->icptcode == ICPT_VALIDITY)
-			handle_validity(vm);
+		sie_handle_validity(vm);
 	}
 	vm->save_area.guest.grs[14] = vm->sblk->gg14;
 	vm->save_area.guest.grs[15] = vm->sblk->gg15;
Reviewed-by
#4 lore raw

Re: [kvm-unit-tests PATCH 1/4] s390x: sie: Add sie lib validity handling

Quoted 53 lines · On Thu, 29 Jul 2021 16:33:31 +0200 Janosch Frank <[email protected]> wrote:
Quoted 43 lines · Claudio Imbrenda
Quoted 40 lines · On Thu, 29 Jul 2021 13:48:00 +0000 Janosch Frank <[email protected]> wrote:

Let's start off the SIE lib with validity handling code since that has the least amount of dependencies to other files.

---
 lib/s390x/sie.c  | 41 +++++++++++++++++++++++++++++++++++++++++
 lib/s390x/sie.h  |  3 +++
 s390x/Makefile   |  1 +
 s390x/mvpg-sie.c |  2 +-
 s390x/sie.c      |  7 +------
 5 files changed, 47 insertions(+), 7 deletions(-)
 create mode 100644 lib/s390x/sie.c
lib/s390x/sie.c new file +21 -0
new file mode 100644
index 00000000..9107519f
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Virtualization library that speeds up managing guests.
+ *
+ * Copyright (c) 2021 IBM Corp
+ *
+ * Authors:
+ *  Janosch Frank <[email protected]>
+ */
+
+#include <asm/barrier.h>
+#include <libcflat.h>
+#include <sie.h>
+
+static bool validity_expected;
+static uint16_t vir;
+
+void sie_expect_validity(void)
+{
+	validity_expected = true;
+	vir = 0;
Quoted 8 lines

lib/s390x/sie.c line 27

Quoted 6 lines
lib/s390x/sie.c new file +6 -0
+}
+
+void sie_check_validity(uint16_t vir_exp)
+{
+	report(vir_exp == vir, "VALIDITY: %x", vir);
+	mb();  

why the barrier?

Quoted 1 line

That's left over, I'll remove it.

with the barrier removed:

Quoted 78 lines
Quoted 77 lines
Quoted 76 lines
lib/s390x/sie.c new file +14 -0
+	vir = 0;
+}
+
+void sie_handle_validity(struct vm *vm)
+{
+	if (vm->sblk->icptcode != ICPT_VALIDITY)
+		return;
+
+	vir = vm->sblk->ipb >> 16;
+
+	if (!validity_expected)
+		report_abort("VALIDITY: %x", vir);
+	validity_expected = false;
+}
lib/s390x/sie.h +2 -0
index 6ba858a2..7ff98d2d 100644
@@ -197,5 +197,8 @@ struct vm {
 extern void sie_entry(void);
 extern void sie_exit(void);
 extern void sie64a(struct kvm_s390_sie_block *sblk, struct
 vm_save_area *save_area); +void sie_expect_validity(void);
+void sie_check_validity(uint16_t vir_exp);
+void sie_handle_validity(struct vm *vm);
 
 #endif /* _S390X_SIE_H_ */
s390x/Makefile +1 -0
index 6565561b..ef8041a6 100644
@@ -71,6 +71,7 @@ cflatobjs += lib/s390x/css_dump.o
 cflatobjs += lib/s390x/css_lib.o
 cflatobjs += lib/s390x/malloc_io.o
 cflatobjs += lib/s390x/uv.o
+cflatobjs += lib/s390x/sie.o
 
 OBJDIRS += lib/s390x
 
s390x/mvpg-sie.c +1 -1
index 5e70f591..2ac91eec 100644
@@ -39,7 +39,7 @@ static void sie(struct vm *vm)
 
 	while (vm->sblk->icptcode == 0) {
 		sie64a(vm->sblk, &vm->save_area);
-		assert(vm->sblk->icptcode != ICPT_VALIDITY);
+		sie_handle_validity(vm);
 	}
 	vm->save_area.guest.grs[14] = vm->sblk->gg14;
 	vm->save_area.guest.grs[15] = vm->sblk->gg15;
s390x/sie.c +1 -6
index 134d3c4f..5c798a9e 100644
@@ -24,17 +24,12 @@ static u8 *guest;
 static u8 *guest_instr;
 static struct vm vm;
 
-static void handle_validity(struct vm *vm)
-{
-	report(0, "VALIDITY: %x", vm->sblk->ipb >> 16);
-}
 
 static void sie(struct vm *vm)
 {
 	while (vm->sblk->icptcode == 0) {
 		sie64a(vm->sblk, &vm->save_area);
-		if (vm->sblk->icptcode == ICPT_VALIDITY)
-			handle_validity(vm);
+		sie_handle_validity(vm);
 	}
 	vm->save_area.guest.grs[14] = vm->sblk->gg14;
 	vm->save_area.guest.grs[15] = vm->sblk->gg15;  
#5 lore raw

Re: [kvm-unit-tests PATCH 1/4] s390x: sie: Add sie lib validity handling

In reply to Janosch Frank
Quoted 19 lines · Janosch Frank

Let's start off the SIE lib with validity handling code since that has the least amount of dependencies to other files.

---
  lib/s390x/sie.c  | 41 +++++++++++++++++++++++++++++++++++++++++
  lib/s390x/sie.h  |  3 +++
  s390x/Makefile   |  1 +
  s390x/mvpg-sie.c |  2 +-
  s390x/sie.c      |  7 +------
  5 files changed, 47 insertions(+), 7 deletions(-)

create mode 100644 lib/s390x/sie.c

lib/s390x/sie.c new file +0 -0
new file mode 100644
index 00000000..9107519f

lib/s390x/sie.c line 3

Quoted 3 lines
lib/s390x/sie.c new file +3 -0
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Virtualization library that speeds up managing guests.

"speeds up managing guests" ... so this means that guests can be scheduled faster? ;-)

lib/s390x/sie.c line 16

Quoted 12 lines
lib/s390x/sie.c new file +12 -0
+ * Copyright (c) 2021 IBM Corp
+ *
+ * Authors:
+ *  Janosch Frank <[email protected]>
+ */
+
+#include <asm/barrier.h>
+#include <libcflat.h>
+#include <sie.h>
+
+static bool validity_expected;
+static uint16_t vir;

What does "vir" stand for? A short comment would be nice.

Thomas

#6 lore raw

Re: [kvm-unit-tests PATCH 1/4] s390x: sie: Add sie lib validity handling

Quoted 14 lines · Thomas Huth
Quoted 13 lines · Janosch Frank

Let's start off the SIE lib with validity handling code since that has the least amount of dependencies to other files.

---
  lib/s390x/sie.c  | 41 +++++++++++++++++++++++++++++++++++++++++
  lib/s390x/sie.h  |  3 +++
  s390x/Makefile   |  1 +
  s390x/mvpg-sie.c |  2 +-
  s390x/sie.c      |  7 +------
  5 files changed, 47 insertions(+), 7 deletions(-)

create mode 100644 lib/s390x/sie.c

Quoted 12 lines

lib/s390x/sie.c line 3

Quoted 9 lines
lib/s390x/sie.c new file +3 -0
new file mode 100644
index 00000000..9107519f
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Virtualization library that speeds up managing guests.

"speeds up managing guests" ... so this means that guests can be scheduled faster? ;-)

Maybe once I implement scheduling which is not on my current plan.

Quoted 15 lines

lib/s390x/sie.c line 16

Quoted 13 lines
lib/s390x/sie.c new file +12 -0
+ * Copyright (c) 2021 IBM Corp
+ *
+ * Authors:
+ *  Janosch Frank <[email protected]>
+ */
+
+#include <asm/barrier.h>
+#include <libcflat.h>
+#include <sie.h>
+
+static bool validity_expected;
+static uint16_t vir;

What does "vir" stand for? A short comment would be nice.

So apparently it's called "Validity-Interception Reason" in the specification which makes sense in the context it's used :)

I'll add a few words.

Quoted 3 lines

Thomas

#7 lore raw

PATCH v2 1/1 s390x: sie: Add sie lib validity handling

In reply to Janosch Frank

Let's start off the SIE lib with validity handling code since that has the least amount of dependencies to other files.

---
 lib/s390x/sie.c  | 40 ++++++++++++++++++++++++++++++++++++++++
 lib/s390x/sie.h  |  3 +++
 s390x/Makefile   |  1 +
 s390x/mvpg-sie.c |  2 +-
 s390x/sie.c      |  7 +------
 5 files changed, 46 insertions(+), 7 deletions(-)
 create mode 100644 lib/s390x/sie.c
lib/s390x/sie.c new file +40 -0
new file mode 100644
index 00000000..15ba407c
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Virtualization library that speeds up managing guests.
+ *
+ * Copyright (c) 2021 IBM Corp
+ *
+ * Authors:
+ *  Janosch Frank <[email protected]>
+ */
+
+#include <asm/barrier.h>
+#include <libcflat.h>
+#include <sie.h>
+
+static bool validity_expected;
+static uint16_t vir;		/* Validity interception reason */
+
+void sie_expect_validity(void)
+{
+	validity_expected = true;
+	vir = 0;
+}
+
+void sie_check_validity(uint16_t vir_exp)
+{
+	report(vir_exp == vir, "VALIDITY: %x", vir);
+	vir = 0;
+}
+
+void sie_handle_validity(struct vm *vm)
+{
+	if (vm->sblk->icptcode != ICPT_VALIDITY)
+		return;
+
+	vir = vm->sblk->ipb >> 16;
+
+	if (!validity_expected)
+		report_abort("VALIDITY: %x", vir);
+	validity_expected = false;
+}
lib/s390x/sie.h +3 -0
index 6ba858a2..7ff98d2d 100644
@@ -197,5 +197,8 @@ struct vm {
 extern void sie_entry(void);
 extern void sie_exit(void);
 extern void sie64a(struct kvm_s390_sie_block *sblk, struct vm_save_area *save_area);
+void sie_expect_validity(void);
+void sie_check_validity(uint16_t vir_exp);
+void sie_handle_validity(struct vm *vm);
 
 #endif /* _S390X_SIE_H_ */
s390x/Makefile +1 -0
index 6565561b..ef8041a6 100644
@@ -71,6 +71,7 @@ cflatobjs += lib/s390x/css_dump.o
 cflatobjs += lib/s390x/css_lib.o
 cflatobjs += lib/s390x/malloc_io.o
 cflatobjs += lib/s390x/uv.o
+cflatobjs += lib/s390x/sie.o
 
 OBJDIRS += lib/s390x
 
s390x/mvpg-sie.c +1 -1
index 5e70f591..2ac91eec 100644
@@ -39,7 +39,7 @@ static void sie(struct vm *vm)
 
 	while (vm->sblk->icptcode == 0) {
 		sie64a(vm->sblk, &vm->save_area);
-		assert(vm->sblk->icptcode != ICPT_VALIDITY);
+		sie_handle_validity(vm);
 	}
 	vm->save_area.guest.grs[14] = vm->sblk->gg14;
 	vm->save_area.guest.grs[15] = vm->sblk->gg15;
s390x/sie.c +1 -6
index 134d3c4f..5c798a9e 100644
@@ -24,17 +24,12 @@ static u8 *guest;
 static u8 *guest_instr;
 static struct vm vm;
 
-static void handle_validity(struct vm *vm)
-{
-	report(0, "VALIDITY: %x", vm->sblk->ipb >> 16);
-}
 
 static void sie(struct vm *vm)
 {
 	while (vm->sblk->icptcode == 0) {
 		sie64a(vm->sblk, &vm->save_area);
-		if (vm->sblk->icptcode == ICPT_VALIDITY)
-			handle_validity(vm);
+		sie_handle_validity(vm);
 	}
 	vm->save_area.guest.grs[14] = vm->sblk->gg14;
 	vm->save_area.guest.grs[15] = vm->sblk->gg15;
Signature · 1 line
2.30.2
Reviewed-by on v2 1/1
#8 lore raw

Re: [kvm-unit-tests PATCH v2] s390x: sie: Add sie lib validity handling

Quoted 20 lines · Janosch Frank

Let's start off the SIE lib with validity handling code since that has the least amount of dependencies to other files.

---
  lib/s390x/sie.c  | 40 ++++++++++++++++++++++++++++++++++++++++
  lib/s390x/sie.h  |  3 +++
  s390x/Makefile   |  1 +
  s390x/mvpg-sie.c |  2 +-
  s390x/sie.c      |  7 +------
  5 files changed, 46 insertions(+), 7 deletions(-)

create mode 100644 lib/s390x/sie.c

lib/s390x/sie.c new file +0 -0
new file mode 100644
index 00000000..15ba407c

lib/s390x/sie.c line 3

Quoted 3 lines
lib/s390x/sie.c new file +3 -0
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Virtualization library that speeds up managing guests.

Maybe something like:

Library for managing various aspects of (nested) guests

?

Anyway:

#9 lore raw

PATCH 2/4 s390x: lib: Introduce HPAGE_* constants

In reply to Janosch Frank

They come in handy when working with 1MB blocks/addresses.

---
 lib/s390x/asm/page.h | 4 ++++
 1 file changed, 4 insertions(+)
lib/s390x/asm/page.h +4 -0
index f130f936..2f4afd06 100644
@@ -35,4 +35,8 @@ typedef struct { pteval_t pte; } pte_t;
 #define __pmd(x)	((pmd_t) { (x) } )
 #define __pte(x)	((pte_t) { (x) } )
 
+#define HPAGE_SHIFT		20
+#define HPAGE_SIZE		(_AC(1,UL) << HPAGE_SHIFT)
+#define HPAGE_MASK		(~(HPAGE_SIZE-1))
+
 #endif
Signature · 1 line
2.30.2
Reviewed-by on v1 2/4
#10 lore raw

Re: [kvm-unit-tests PATCH 2/4] s390x: lib: Introduce HPAGE_* constants

Quoted 3 lines · On Thu, 29 Jul 2021 13:48:01 +0000 Janosch Frank <[email protected]> wrote:

They come in handy when working with 1MB blocks/addresses.

Quoted 17 lines
---
 lib/s390x/asm/page.h | 4 ++++
 1 file changed, 4 insertions(+)
lib/s390x/asm/page.h +4 -0
index f130f936..2f4afd06 100644
@@ -35,4 +35,8 @@ typedef struct { pteval_t pte; } pte_t;
 #define __pmd(x)	((pmd_t) { (x) } )
 #define __pte(x)	((pte_t) { (x) } )
 
+#define HPAGE_SHIFT		20
+#define HPAGE_SIZE		(_AC(1,UL) << HPAGE_SHIFT)
+#define HPAGE_MASK		(~(HPAGE_SIZE-1))
+
 #endif
Reviewed-by on v1 2/4
#11 lore raw

Re: [kvm-unit-tests PATCH 2/4] s390x: lib: Introduce HPAGE_* constants

In reply to Janosch Frank
Quoted 13 lines · Janosch Frank

They come in handy when working with 1MB blocks/addresses.

---
  lib/s390x/asm/page.h | 4 ++++
  1 file changed, 4 insertions(+)
lib/s390x/asm/page.h +0 -0
index f130f936..2f4afd06 100644

lib/s390x/asm/page.h typedef struct { pteval_t pte; } pte_t; · line 42

Quoted 8 lines
lib/s390x/asm/page.h +4 -0
@@ -35,4 +35,8 @@ typedef struct { pteval_t pte; } pte_t;
  #define __pmd(x)	((pmd_t) { (x) } )
  #define __pte(x)	((pte_t) { (x) } )
 
+#define HPAGE_SHIFT		20
+#define HPAGE_SIZE		(_AC(1,UL) << HPAGE_SHIFT)
+#define HPAGE_MASK		(~(HPAGE_SIZE-1))
+
  #endif
#12 lore raw

PATCH 3/4 s390x: lib: sie: Add struct vm (de)initialization functions

In reply to Janosch Frank

Before I start copying the same code over and over lets move this into the library.

---
 lib/s390x/sie.c  | 30 ++++++++++++++++++++++++++++++
 lib/s390x/sie.h  |  3 +++
 s390x/mvpg-sie.c | 18 ++----------------
 s390x/sie.c      | 19 +++----------------
 4 files changed, 38 insertions(+), 32 deletions(-)
lib/s390x/sie.c +30 -0
index 9107519f..ec0c4867 100644
@@ -11,6 +11,9 @@
 #include <asm/barrier.h>
 #include <libcflat.h>
 #include <sie.h>
+#include <asm/page.h>
+#include <libcflat.h>
+#include <alloc_page.h>
 
 static bool validity_expected;
 static uint16_t vir;
@@ -39,3 +42,30 @@ void sie_handle_validity(struct vm *vm)
 		report_abort("VALIDITY: %x", vir);
 	validity_expected = false;
 }
+
+/* Initializes the struct vm members like the SIE control block. */
+void sie_guest_create(struct vm *vm, uint64_t guest_mem, uint64_t guest_mem_len)
+{
+	vm->sblk = alloc_page();
+	memset(vm->sblk, 0, PAGE_SIZE);
+	vm->sblk->cpuflags = CPUSTAT_ZARCH | CPUSTAT_RUNNING;
+	vm->sblk->ihcpu = 0xffff;
+	vm->sblk->prefix = 0;
+
+	/* Guest memory chunks are always 1MB */
+	assert(!(guest_mem_len & ~HPAGE_MASK));
+	/* Currently MSO/MSL is the easiest option */
+	vm->sblk->mso = (uint64_t)guest_mem;
+	vm->sblk->msl = (uint64_t)guest_mem + ((guest_mem_len - 1) & HPAGE_MASK);
+
+	/* CRYCB needs to be in the first 2GB */
+	vm->crycb = alloc_pages_flags(0, AREA_DMA31);
+	vm->sblk->crycbd = (uint32_t)(uintptr_t)vm->crycb;
+}
+
+/* Frees the memory that was gathered on initialization */
+void sie_guest_destroy(struct vm *vm)
+{
+	free_page(vm->crycb);
+	free_page(vm->sblk);
+}
lib/s390x/sie.h +3 -0
index 7ff98d2d..946bd164 100644
@@ -190,6 +190,7 @@ struct vm_save_area {
 struct vm {
 	struct kvm_s390_sie_block *sblk;
 	struct vm_save_area save_area;
+	uint8_t *crycb;				/* Crypto Control Block */
 	/* Ptr to first guest page */
 	uint8_t *guest_mem;
 };
@@ -200,5 +201,7 @@ extern void sie64a(struct kvm_s390_sie_block *sblk, struct vm_save_area *save_ar
 void sie_expect_validity(void);
 void sie_check_validity(uint16_t vir_exp);
 void sie_handle_validity(struct vm *vm);
+void sie_guest_create(struct vm *vm, uint64_t guest_mem, uint64_t guest_mem_len);
+void sie_guest_destroy(struct vm *vm);
 
 #endif /* _S390X_SIE_H_ */
s390x/mvpg-sie.c +2 -16
index 2ac91eec..71ae4f88 100644
@@ -110,22 +110,7 @@ static void setup_guest(void)
 	/* The first two pages are the lowcore */
 	guest_instr = guest + PAGE_SIZE * 2;
 
-	vm.sblk = alloc_page();
-
-	vm.sblk->cpuflags = CPUSTAT_ZARCH | CPUSTAT_RUNNING;
-	vm.sblk->prefix = 0;
-	/*
-	 * Pageable guest with the same ASCE as the test programm, but
-	 * the guest memory 0x0 is offset to start at the allocated
-	 * guest pages and end after 1MB.
-	 *
-	 * It's not pretty but faster and easier than managing guest ASCEs.
-	 */
-	vm.sblk->mso = (u64)guest;
-	vm.sblk->msl = (u64)guest;
-	vm.sblk->ihcpu = 0xffff;
-
-	vm.sblk->crycbd = (uint64_t)alloc_page();
+	sie_guest_create(&vm, (uint64_t)guest, HPAGE_SIZE);
 
 	vm.sblk->gpsw.addr = PAGE_SIZE * 4;
 	vm.sblk->gpsw.mask = 0x0000000180000000ULL;
@@ -150,6 +135,7 @@ int main(void)
 	setup_guest();
 	test_mvpg();
 	test_mvpg_pei();
+	sie_guest_destroy(&vm);
 
 done:
 	report_prefix_pop();
s390x/sie.c +3 -16
index 5c798a9e..9cb9b055 100644
@@ -84,22 +84,7 @@ static void setup_guest(void)
 	/* The first two pages are the lowcore */
 	guest_instr = guest + PAGE_SIZE * 2;
 
-	vm.sblk = alloc_page();
-
-	vm.sblk->cpuflags = CPUSTAT_ZARCH | CPUSTAT_RUNNING;
-	vm.sblk->prefix = 0;
-	/*
-	 * Pageable guest with the same ASCE as the test programm, but
-	 * the guest memory 0x0 is offset to start at the allocated
-	 * guest pages and end after 1MB.
-	 *
-	 * It's not pretty but faster and easier than managing guest ASCEs.
-	 */
-	vm.sblk->mso = (u64)guest;
-	vm.sblk->msl = (u64)guest;
-	vm.sblk->ihcpu = 0xffff;
-
-	vm.sblk->crycbd = (uint64_t)alloc_page();
+	sie_guest_create(&vm, (uint64_t)guest, HPAGE_SIZE);
 }
 
 int main(void)
@@ -112,6 +97,8 @@ int main(void)
 
 	setup_guest();
 	test_diags();
+	sie_guest_destroy(&vm);
+
 done:
 	report_prefix_pop();
 	return report_summary();
Signature · 1 line
2.30.2
Reviewed-by on v1 3/4
#13 lore raw

Re: [kvm-unit-tests PATCH 3/4] s390x: lib: sie: Add struct vm (de)initialization functions

Quoted 33 lines · On Thu, 29 Jul 2021 13:48:02 +0000 Janosch Frank <[email protected]> wrote:

Before I start copying the same code over and over lets move this into the library.

---
 lib/s390x/sie.c  | 30 ++++++++++++++++++++++++++++++
 lib/s390x/sie.h  |  3 +++
 s390x/mvpg-sie.c | 18 ++----------------
 s390x/sie.c      | 19 +++----------------
 4 files changed, 38 insertions(+), 32 deletions(-)
lib/s390x/sie.c +6 -0
index 9107519f..ec0c4867 100644
@@ -11,6 +11,9 @@
 #include <asm/barrier.h>
 #include <libcflat.h>
 #include <sie.h>
+#include <asm/page.h>
+#include <libcflat.h>
+#include <alloc_page.h>
 
 static bool validity_expected;
 static uint16_t vir;
@@ -39,3 +42,30 @@ void sie_handle_validity(struct vm *vm)
 		report_abort("VALIDITY: %x", vir);
 	validity_expected = false;
 }
+
+/* Initializes the struct vm members like the SIE control block. */
+void sie_guest_create(struct vm *vm, uint64_t guest_mem, uint64_t

guest_mem_len) +{

lib/s390x/sie.c void sie_handle_validity(struct vm *vm) · line 50

Quoted 2 lines
lib/s390x/sie.c +2 -0
+	vm->sblk = alloc_page();
+	memset(vm->sblk, 0, PAGE_SIZE);

you can skip the memset, the page allocator always zeroes the page, unless you explicitly pass FLAG_DONTZERO

regardless of that:

Quoted 118 lines
lib/s390x/sie.c +9 -0
+	vm->sblk->cpuflags = CPUSTAT_ZARCH | CPUSTAT_RUNNING;
+	vm->sblk->ihcpu = 0xffff;
+	vm->sblk->prefix = 0;
+
+	/* Guest memory chunks are always 1MB */
+	assert(!(guest_mem_len & ~HPAGE_MASK));
+	/* Currently MSO/MSL is the easiest option */
+	vm->sblk->mso = (uint64_t)guest_mem;
+	vm->sblk->msl = (uint64_t)guest_mem + ((guest_mem_len - 1) &

HPAGE_MASK); +

lib/s390x/sie.c +11 -0
+	/* CRYCB needs to be in the first 2GB */
+	vm->crycb = alloc_pages_flags(0, AREA_DMA31);
+	vm->sblk->crycbd = (uint32_t)(uintptr_t)vm->crycb;
+}
+
+/* Frees the memory that was gathered on initialization */
+void sie_guest_destroy(struct vm *vm)
+{
+	free_page(vm->crycb);
+	free_page(vm->sblk);
+}
lib/s390x/sie.h +1 -0
index 7ff98d2d..946bd164 100644
@@ -190,6 +190,7 @@ struct vm_save_area {
 struct vm {
 	struct kvm_s390_sie_block *sblk;
 	struct vm_save_area save_area;
+	uint8_t *crycb;				/* Crypto

Control Block */ /* Ptr to first guest page */

lib/s390x/sie.h +1 -0
 	uint8_t *guest_mem;
 };
@@ -200,5 +201,7 @@ extern void sie64a(struct kvm_s390_sie_block
 *sblk, struct vm_save_area *save_ar void sie_expect_validity(void);
 void sie_check_validity(uint16_t vir_exp);
 void sie_handle_validity(struct vm *vm);
+void sie_guest_create(struct vm *vm, uint64_t guest_mem, uint64_t
 guest_mem_len); +void sie_guest_destroy(struct vm *vm);
 
 #endif /* _S390X_SIE_H_ */
s390x/mvpg-sie.c +0 -6
index 2ac91eec..71ae4f88 100644
@@ -110,22 +110,7 @@ static void setup_guest(void)
 	/* The first two pages are the lowcore */
 	guest_instr = guest + PAGE_SIZE * 2;
 
-	vm.sblk = alloc_page();
-
-	vm.sblk->cpuflags = CPUSTAT_ZARCH | CPUSTAT_RUNNING;
-	vm.sblk->prefix = 0;
-	/*
-	 * Pageable guest with the same ASCE as the test programm,

but

s390x/mvpg-sie.c +0 -4
-	 * the guest memory 0x0 is offset to start at the allocated
-	 * guest pages and end after 1MB.
-	 *
-	 * It's not pretty but faster and easier than managing guest

ASCEs.

s390x/mvpg-sie.c +2 -6
-	 */
-	vm.sblk->mso = (u64)guest;
-	vm.sblk->msl = (u64)guest;
-	vm.sblk->ihcpu = 0xffff;
-
-	vm.sblk->crycbd = (uint64_t)alloc_page();
+	sie_guest_create(&vm, (uint64_t)guest, HPAGE_SIZE);
 
 	vm.sblk->gpsw.addr = PAGE_SIZE * 4;
 	vm.sblk->gpsw.mask = 0x0000000180000000ULL;
@@ -150,6 +135,7 @@ int main(void)
 	setup_guest();
 	test_mvpg();
 	test_mvpg_pei();
+	sie_guest_destroy(&vm);
 
 done:
 	report_prefix_pop();
s390x/sie.c +0 -6
index 5c798a9e..9cb9b055 100644
@@ -84,22 +84,7 @@ static void setup_guest(void)
 	/* The first two pages are the lowcore */
 	guest_instr = guest + PAGE_SIZE * 2;
 
-	vm.sblk = alloc_page();
-
-	vm.sblk->cpuflags = CPUSTAT_ZARCH | CPUSTAT_RUNNING;
-	vm.sblk->prefix = 0;
-	/*
-	 * Pageable guest with the same ASCE as the test programm,

but

s390x/sie.c +0 -4
-	 * the guest memory 0x0 is offset to start at the allocated
-	 * guest pages and end after 1MB.
-	 *
-	 * It's not pretty but faster and easier than managing guest

ASCEs.

s390x/sie.c +3 -6
-	 */
-	vm.sblk->mso = (u64)guest;
-	vm.sblk->msl = (u64)guest;
-	vm.sblk->ihcpu = 0xffff;
-
-	vm.sblk->crycbd = (uint64_t)alloc_page();
+	sie_guest_create(&vm, (uint64_t)guest, HPAGE_SIZE);
 }
 
 int main(void)
@@ -112,6 +97,8 @@ int main(void)
 
 	setup_guest();
 	test_diags();
+	sie_guest_destroy(&vm);
+
 done:
 	report_prefix_pop();
 	return report_summary();
#14 lore raw

Re: [kvm-unit-tests PATCH 3/4] s390x: lib: sie: Add struct vm (de)initialization functions

Quoted 26 lines · Claudio Imbrenda
Quoted 23 lines · On Thu, 29 Jul 2021 13:48:02 +0000 Janosch Frank <[email protected]> wrote:

Before I start copying the same code over and over lets move this into the library.

---
 lib/s390x/sie.c  | 30 ++++++++++++++++++++++++++++++
 lib/s390x/sie.h  |  3 +++
 s390x/mvpg-sie.c | 18 ++----------------
 s390x/sie.c      | 19 +++----------------
 4 files changed, 38 insertions(+), 32 deletions(-)
lib/s390x/sie.c +3 -0
index 9107519f..ec0c4867 100644
@@ -11,6 +11,9 @@
 #include <asm/barrier.h>
 #include <libcflat.h>
 #include <sie.h>
+#include <asm/page.h>
+#include <libcflat.h>
+#include <alloc_page.h>
 
Quoted 15 lines

lib/s390x/sie.c void sie_handle_validity(struct vm *vm) · line 50

Quoted 12 lines
lib/s390x/sie.c +3 -0
 static bool validity_expected;
 static uint16_t vir;
@@ -39,3 +42,30 @@ void sie_handle_validity(struct vm *vm)
 		report_abort("VALIDITY: %x", vir);
 	validity_expected = false;
 }
+
+/* Initializes the struct vm members like the SIE control block. */
+void sie_guest_create(struct vm *vm, uint64_t guest_mem, uint64_t

guest_mem_len) +{

lib/s390x/sie.c +2 -0
+	vm->sblk = alloc_page();
+	memset(vm->sblk, 0, PAGE_SIZE);

you can skip the memset, the page allocator always zeroes the page, unless you explicitly pass FLAG_DONTZERO

Yeah I thought as much but I still like to have that explicitly for ease of mind.

Quoted 4 lines

regardless of that:

Thanks

Quoted 120 lines
Quoted 119 lines
lib/s390x/sie.c +9 -0
+	vm->sblk->cpuflags = CPUSTAT_ZARCH | CPUSTAT_RUNNING;
+	vm->sblk->ihcpu = 0xffff;
+	vm->sblk->prefix = 0;
+
+	/* Guest memory chunks are always 1MB */
+	assert(!(guest_mem_len & ~HPAGE_MASK));
+	/* Currently MSO/MSL is the easiest option */
+	vm->sblk->mso = (uint64_t)guest_mem;
+	vm->sblk->msl = (uint64_t)guest_mem + ((guest_mem_len - 1) &

HPAGE_MASK); +

lib/s390x/sie.c +11 -0
+	/* CRYCB needs to be in the first 2GB */
+	vm->crycb = alloc_pages_flags(0, AREA_DMA31);
+	vm->sblk->crycbd = (uint32_t)(uintptr_t)vm->crycb;
+}
+
+/* Frees the memory that was gathered on initialization */
+void sie_guest_destroy(struct vm *vm)
+{
+	free_page(vm->crycb);
+	free_page(vm->sblk);
+}
lib/s390x/sie.h +1 -0
index 7ff98d2d..946bd164 100644
@@ -190,6 +190,7 @@ struct vm_save_area {
 struct vm {
 	struct kvm_s390_sie_block *sblk;
 	struct vm_save_area save_area;
+	uint8_t *crycb;				/* Crypto

Control Block */ /* Ptr to first guest page */

lib/s390x/sie.h +1 -0
 	uint8_t *guest_mem;
 };
@@ -200,5 +201,7 @@ extern void sie64a(struct kvm_s390_sie_block
 *sblk, struct vm_save_area *save_ar void sie_expect_validity(void);
 void sie_check_validity(uint16_t vir_exp);
 void sie_handle_validity(struct vm *vm);
+void sie_guest_create(struct vm *vm, uint64_t guest_mem, uint64_t
 guest_mem_len); +void sie_guest_destroy(struct vm *vm);
 
 #endif /* _S390X_SIE_H_ */
s390x/mvpg-sie.c +0 -6
index 2ac91eec..71ae4f88 100644
@@ -110,22 +110,7 @@ static void setup_guest(void)
 	/* The first two pages are the lowcore */
 	guest_instr = guest + PAGE_SIZE * 2;
 
-	vm.sblk = alloc_page();
-
-	vm.sblk->cpuflags = CPUSTAT_ZARCH | CPUSTAT_RUNNING;
-	vm.sblk->prefix = 0;
-	/*
-	 * Pageable guest with the same ASCE as the test programm,

but

s390x/mvpg-sie.c +0 -4
-	 * the guest memory 0x0 is offset to start at the allocated
-	 * guest pages and end after 1MB.
-	 *
-	 * It's not pretty but faster and easier than managing guest

ASCEs.

s390x/mvpg-sie.c +2 -6
-	 */
-	vm.sblk->mso = (u64)guest;
-	vm.sblk->msl = (u64)guest;
-	vm.sblk->ihcpu = 0xffff;
-
-	vm.sblk->crycbd = (uint64_t)alloc_page();
+	sie_guest_create(&vm, (uint64_t)guest, HPAGE_SIZE);
 
 	vm.sblk->gpsw.addr = PAGE_SIZE * 4;
 	vm.sblk->gpsw.mask = 0x0000000180000000ULL;
@@ -150,6 +135,7 @@ int main(void)
 	setup_guest();
 	test_mvpg();
 	test_mvpg_pei();
+	sie_guest_destroy(&vm);
 
 done:
 	report_prefix_pop();
s390x/sie.c +0 -6
index 5c798a9e..9cb9b055 100644
@@ -84,22 +84,7 @@ static void setup_guest(void)
 	/* The first two pages are the lowcore */
 	guest_instr = guest + PAGE_SIZE * 2;
 
-	vm.sblk = alloc_page();
-
-	vm.sblk->cpuflags = CPUSTAT_ZARCH | CPUSTAT_RUNNING;
-	vm.sblk->prefix = 0;
-	/*
-	 * Pageable guest with the same ASCE as the test programm,

but

s390x/sie.c +0 -4
-	 * the guest memory 0x0 is offset to start at the allocated
-	 * guest pages and end after 1MB.
-	 *
-	 * It's not pretty but faster and easier than managing guest

ASCEs.

s390x/sie.c +3 -6
-	 */
-	vm.sblk->mso = (u64)guest;
-	vm.sblk->msl = (u64)guest;
-	vm.sblk->ihcpu = 0xffff;
-
-	vm.sblk->crycbd = (uint64_t)alloc_page();
+	sie_guest_create(&vm, (uint64_t)guest, HPAGE_SIZE);
 }
 
 int main(void)
@@ -112,6 +97,8 @@ int main(void)
 
 	setup_guest();
 	test_diags();
+	sie_guest_destroy(&vm);
+
 done:
 	report_prefix_pop();
 	return report_summary();
Reviewed-by on v1 3/4
#15 lore raw

Re: [kvm-unit-tests PATCH 3/4] s390x: lib: sie: Add struct vm (de)initialization functions

In reply to Janosch Frank
Quoted 10 lines · Janosch Frank

Before I start copying the same code over and over lets move this into the library.

---
  lib/s390x/sie.c  | 30 ++++++++++++++++++++++++++++++
  lib/s390x/sie.h  |  3 +++
  s390x/mvpg-sie.c | 18 ++----------------
  s390x/sie.c      | 19 +++----------------
  4 files changed, 38 insertions(+), 32 deletions(-)
#16 lore raw

PATCH 4/4 lib: s390x: sie: Move sie function into library

In reply to Janosch Frank

Time to deduplicate more code.

---
 lib/s390x/sie.c  | 13 +++++++++++++
 lib/s390x/sie.h  |  1 +
 s390x/mvpg-sie.c | 13 -------------
 s390x/sie.c      | 17 -----------------
 4 files changed, 14 insertions(+), 30 deletions(-)
lib/s390x/sie.c +13 -0
index ec0c4867..d971e825 100644
@@ -43,6 +43,19 @@ void sie_handle_validity(struct vm *vm)
 	validity_expected = false;
 }
 
+void sie(struct vm *vm)
+{
+	/* Reset icptcode so we don't trip over it below */
+	vm->sblk->icptcode = 0;
+
+	while (vm->sblk->icptcode == 0) {
+		sie64a(vm->sblk, &vm->save_area);
+		sie_handle_validity(vm);
+	}
+	vm->save_area.guest.grs[14] = vm->sblk->gg14;
+	vm->save_area.guest.grs[15] = vm->sblk->gg15;
+}
+
 /* Initializes the struct vm members like the SIE control block. */
 void sie_guest_create(struct vm *vm, uint64_t guest_mem, uint64_t guest_mem_len)
 {
lib/s390x/sie.h +1 -0
index 946bd164..ca514ef3 100644
@@ -198,6 +198,7 @@ struct vm {
 extern void sie_entry(void);
 extern void sie_exit(void);
 extern void sie64a(struct kvm_s390_sie_block *sblk, struct vm_save_area *save_area);
+void sie(struct vm *vm);
 void sie_expect_validity(void);
 void sie_check_validity(uint16_t vir_exp);
 void sie_handle_validity(struct vm *vm);
s390x/mvpg-sie.c +0 -13
index 71ae4f88..70d2fcfa 100644
@@ -32,19 +32,6 @@ extern const char _binary_s390x_snippets_c_mvpg_snippet_gbin_start[];
 extern const char _binary_s390x_snippets_c_mvpg_snippet_gbin_end[];
 int binary_size;
 
-static void sie(struct vm *vm)
-{
-	/* Reset icptcode so we don't trip over it below */
-	vm->sblk->icptcode = 0;
-
-	while (vm->sblk->icptcode == 0) {
-		sie64a(vm->sblk, &vm->save_area);
-		sie_handle_validity(vm);
-	}
-	vm->save_area.guest.grs[14] = vm->sblk->gg14;
-	vm->save_area.guest.grs[15] = vm->sblk->gg15;
-}
-
 static void test_mvpg_pei(void)
 {
 	uint64_t **pei_dst = (uint64_t **)((uintptr_t) vm.sblk + 0xc0);
s390x/sie.c +0 -17
index 9cb9b055..ed2c3263 100644
@@ -24,22 +24,6 @@ static u8 *guest;
 static u8 *guest_instr;
 static struct vm vm;
 
-
-static void sie(struct vm *vm)
-{
-	while (vm->sblk->icptcode == 0) {
-		sie64a(vm->sblk, &vm->save_area);
-		sie_handle_validity(vm);
-	}
-	vm->save_area.guest.grs[14] = vm->sblk->gg14;
-	vm->save_area.guest.grs[15] = vm->sblk->gg15;
-}
-
-static void sblk_cleanup(struct vm *vm)
-{
-	vm->sblk->icptcode = 0;
-}
-
 static void test_diag(u32 instr)
 {
 	vm.sblk->gpsw.addr = PAGE_SIZE * 2;
@@ -51,7 +35,6 @@ static void test_diag(u32 instr)
 	report(vm.sblk->icptcode == ICPT_INST &&
 	       vm.sblk->ipa == instr >> 16 && vm.sblk->ipb == instr << 16,
 	       "Intercept data");
-	sblk_cleanup(&vm);
 }
 
 static struct {
Signature · 1 line
2.30.2
Reviewed-by on v1 4/4
#17 lore raw

Re: [kvm-unit-tests PATCH 4/4] lib: s390x: sie: Move sie function into library

Quoted 3 lines · On Thu, 29 Jul 2021 13:48:03 +0000 Janosch Frank <[email protected]> wrote:

Time to deduplicate more code.

Quoted 102 lines
---
 lib/s390x/sie.c  | 13 +++++++++++++
 lib/s390x/sie.h  |  1 +
 s390x/mvpg-sie.c | 13 -------------
 s390x/sie.c      | 17 -----------------
 4 files changed, 14 insertions(+), 30 deletions(-)
lib/s390x/sie.c +13 -0
index ec0c4867..d971e825 100644
@@ -43,6 +43,19 @@ void sie_handle_validity(struct vm *vm)
 	validity_expected = false;
 }
 
+void sie(struct vm *vm)
+{
+	/* Reset icptcode so we don't trip over it below */
+	vm->sblk->icptcode = 0;
+
+	while (vm->sblk->icptcode == 0) {
+		sie64a(vm->sblk, &vm->save_area);
+		sie_handle_validity(vm);
+	}
+	vm->save_area.guest.grs[14] = vm->sblk->gg14;
+	vm->save_area.guest.grs[15] = vm->sblk->gg15;
+}
+
 /* Initializes the struct vm members like the SIE control block. */
 void sie_guest_create(struct vm *vm, uint64_t guest_mem, uint64_t
 guest_mem_len) {
lib/s390x/sie.h +0 -0
index 946bd164..ca514ef3 100644
@@ -198,6 +198,7 @@ struct vm {
 extern void sie_entry(void);
 extern void sie_exit(void);
 extern void sie64a(struct kvm_s390_sie_block *sblk, struct
 vm_save_area *save_area); +void sie(struct vm *vm);
 void sie_expect_validity(void);
 void sie_check_validity(uint16_t vir_exp);
 void sie_handle_validity(struct vm *vm);
s390x/mvpg-sie.c +0 -0
index 71ae4f88..70d2fcfa 100644
@@ -32,19 +32,6 @@ extern const char

_binary_s390x_snippets_c_mvpg_snippet_gbin_start[]; extern const char _binary_s390x_snippets_c_mvpg_snippet_gbin_end[]; int binary_size;

s390x/mvpg-sie.c +0 -13
-static void sie(struct vm *vm)
-{
-	/* Reset icptcode so we don't trip over it below */
-	vm->sblk->icptcode = 0;
-
-	while (vm->sblk->icptcode == 0) {
-		sie64a(vm->sblk, &vm->save_area);
-		sie_handle_validity(vm);
-	}
-	vm->save_area.guest.grs[14] = vm->sblk->gg14;
-	vm->save_area.guest.grs[15] = vm->sblk->gg15;
-}
-
 static void test_mvpg_pei(void)
 {
 	uint64_t **pei_dst = (uint64_t **)((uintptr_t) vm.sblk +

0xc0); diff --git a/s390x/sie.c b/s390x/sie.c
index 9cb9b055..ed2c3263 100644

s390x/sie.c +0 -17
@@ -24,22 +24,6 @@ static u8 *guest;
 static u8 *guest_instr;
 static struct vm vm;
 
-
-static void sie(struct vm *vm)
-{
-	while (vm->sblk->icptcode == 0) {
-		sie64a(vm->sblk, &vm->save_area);
-		sie_handle_validity(vm);
-	}
-	vm->save_area.guest.grs[14] = vm->sblk->gg14;
-	vm->save_area.guest.grs[15] = vm->sblk->gg15;
-}
-
-static void sblk_cleanup(struct vm *vm)
-{
-	vm->sblk->icptcode = 0;
-}
-
 static void test_diag(u32 instr)
 {
 	vm.sblk->gpsw.addr = PAGE_SIZE * 2;
@@ -51,7 +35,6 @@ static void test_diag(u32 instr)
 	report(vm.sblk->icptcode == ICPT_INST &&
 	       vm.sblk->ipa == instr >> 16 && vm.sblk->ipb == instr
 << 16, "Intercept data");
-	sblk_cleanup(&vm);
 }
 
 static struct {
Reviewed-by on v1 4/4
#18 lore raw

Re: [kvm-unit-tests PATCH 4/4] lib: s390x: sie: Move sie function into library

In reply to Janosch Frank
Quoted 9 lines · Janosch Frank

Time to deduplicate more code.

---
  lib/s390x/sie.c  | 13 +++++++++++++
  lib/s390x/sie.h  |  1 +
  s390x/mvpg-sie.c | 13 -------------
  s390x/sie.c      | 17 -----------------
  4 files changed, 14 insertions(+), 30 deletions(-)