diff mbox series

[kvm-unit-tests,4/6] lib: s390x: sie: Improve validity handling and make it vm specific

Message ID 20220729082633.277240-5-frankja@linux.ibm.com (mailing list archive)
State New, archived
Headers show
Series s390x: PV fixups | expand

Commit Message

Janosch Frank July 29, 2022, 8:26 a.m. UTC
The current library doesn't support running multiple vms at once as it
stores the validity once and not per vm. Let's move the validity
handling into the vm and introduce a new function to retrieve the vir.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
---
 lib/s390x/sie.c | 26 +++++++++++++-------------
 lib/s390x/sie.h |  6 ++++--
 2 files changed, 17 insertions(+), 15 deletions(-)

Comments

Steffen Eiden July 29, 2022, 2:25 p.m. UTC | #1
On 7/29/22 10:26, Janosch Frank wrote:
> The current library doesn't support running multiple vms at once as it
> stores the validity once and not per vm. Let's move the validity
> handling into the vm and introduce a new function to retrieve the vir.
> 
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Steffen Eiden <seiden@linux.ibm.com>
Nico Boehr Aug. 2, 2022, 7:23 a.m. UTC | #2
Quoting Janosch Frank (2022-07-29 10:26:31)
> The current library doesn't support running multiple vms at once as it
> stores the validity once and not per vm. Let's move the validity
> handling into the vm and introduce a new function to retrieve the vir.
> 
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>

Reviewed-by: Nico Boehr <nrb@linux.ibm.com>

One tiny suggestion below.

[...]
> diff --git a/lib/s390x/sie.c b/lib/s390x/sie.c
> index 00aff713..c3a53ad6 100644
> --- a/lib/s390x/sie.c
> +++ b/lib/s390x/sie.c
> @@ -15,19 +15,21 @@
>  #include <libcflat.h>
>  #include <alloc_page.h>
>  
> -static bool validity_expected;
> -static uint16_t vir;           /* Validity interception reason */
> -
> -void sie_expect_validity(void)
> +void sie_expect_validity(struct vm *vm)
>  {
> -       validity_expected = true;
> -       vir = 0;
> +       vm->validity_expected = true;
>  }
>  
> -void sie_check_validity(uint16_t vir_exp)
> +uint16_t sie_get_validity(struct vm *vm)
>  {
> +       return vm->sblk->ipb >> 16;
> +}

Since one should only call this function when we had a validity, maybe add:

assert (vm->sblk->icptcode == ICPT_VALIDITY);
diff mbox series

Patch

diff --git a/lib/s390x/sie.c b/lib/s390x/sie.c
index 00aff713..c3a53ad6 100644
--- a/lib/s390x/sie.c
+++ b/lib/s390x/sie.c
@@ -15,19 +15,21 @@ 
 #include <libcflat.h>
 #include <alloc_page.h>
 
-static bool validity_expected;
-static uint16_t vir;		/* Validity interception reason */
-
-void sie_expect_validity(void)
+void sie_expect_validity(struct vm *vm)
 {
-	validity_expected = true;
-	vir = 0;
+	vm->validity_expected = true;
 }
 
-void sie_check_validity(uint16_t vir_exp)
+uint16_t sie_get_validity(struct vm *vm)
 {
+	return vm->sblk->ipb >> 16;
+}
+
+void sie_check_validity(struct vm *vm, uint16_t vir_exp)
+{
+	uint16_t vir = sie_get_validity(vm);
+
 	report(vir_exp == vir, "VALIDITY: %x", vir);
-	vir = 0;
 }
 
 void sie_handle_validity(struct vm *vm)
@@ -35,11 +37,9 @@  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;
+	if (!vm->validity_expected)
+		report_abort("VALIDITY: %x", sie_get_validity(vm));
+	vm->validity_expected = false;
 }
 
 void sie(struct vm *vm)
diff --git a/lib/s390x/sie.h b/lib/s390x/sie.h
index de91ea5a..320c4218 100644
--- a/lib/s390x/sie.h
+++ b/lib/s390x/sie.h
@@ -233,14 +233,16 @@  struct vm {
 	struct vm_uv uv;			/* PV UV information */
 	/* Ptr to first guest page */
 	uint8_t *guest_mem;
+	bool validity_expected;
 };
 
 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_expect_validity(struct vm *vm);
+uint16_t sie_get_validity(struct vm *vm);
+void sie_check_validity(struct vm *vm, uint16_t vir_exp);
 void sie_handle_validity(struct vm *vm);
 void sie_guest_sca_create(struct vm *vm);
 void sie_guest_create(struct vm *vm, uint64_t guest_mem, uint64_t guest_mem_len);