diff mbox series

[kvm-unit-tests,v2,6/7] lib: s390x: Enable reusability of VMs that were in PV mode

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

Commit Message

Janosch Frank Oct. 20, 2022, 9 a.m. UTC
Convert the sblk to non-PV when the PV guest is destroyed.

Early return in uv_init() instead of running into the assert. This is
necessary since snippet_pv_init() will always call uv_init().

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

Comments

Claudio Imbrenda Oct. 20, 2022, 9:26 a.m. UTC | #1
On Thu, 20 Oct 2022 09:00:08 +0000
Janosch Frank <frankja@linux.ibm.com> wrote:

> Convert the sblk to non-PV when the PV guest is destroyed.
> 
> Early return in uv_init() instead of running into the assert. This is
> necessary since snippet_pv_init() will always call uv_init().
> 
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>

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

> ---
>  lib/s390x/uv.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/s390x/uv.c b/lib/s390x/uv.c
> index 0b6eb843..99775929 100644
> --- a/lib/s390x/uv.c
> +++ b/lib/s390x/uv.c
> @@ -76,7 +76,8 @@ void uv_init(void)
>  	int cc;
>  
>  	/* Let's not do this twice */
> -	assert(!initialized);
> +	if (initialized)
> +		return;
>  	/* Query is done on initialization but let's check anyway */
>  	assert(uvcb_qui.header.rc == 1 || uvcb_qui.header.rc == 0x100);
>  
> @@ -188,6 +189,14 @@ void uv_destroy_guest(struct vm *vm)
>  	free_pages(vm->uv.conf_var_stor);
>  
>  	free_pages((void *)(vm->uv.asce & PAGE_MASK));
> +	memset(&vm->uv, 0, sizeof(vm->uv));
> +
> +	/* Convert the sblk back to non-PV */
> +	vm->save_area.guest.asce = stctg(1);
> +	vm->sblk->sdf = 0;
> +	vm->sblk->sidad = 0;
> +	vm->sblk->pv_handle_cpu = 0;
> +	vm->sblk->pv_handle_config = 0;
>  }
>  
>  int uv_unpack(struct vm *vm, uint64_t addr, uint64_t len, uint64_t tweak)
diff mbox series

Patch

diff --git a/lib/s390x/uv.c b/lib/s390x/uv.c
index 0b6eb843..99775929 100644
--- a/lib/s390x/uv.c
+++ b/lib/s390x/uv.c
@@ -76,7 +76,8 @@  void uv_init(void)
 	int cc;
 
 	/* Let's not do this twice */
-	assert(!initialized);
+	if (initialized)
+		return;
 	/* Query is done on initialization but let's check anyway */
 	assert(uvcb_qui.header.rc == 1 || uvcb_qui.header.rc == 0x100);
 
@@ -188,6 +189,14 @@  void uv_destroy_guest(struct vm *vm)
 	free_pages(vm->uv.conf_var_stor);
 
 	free_pages((void *)(vm->uv.asce & PAGE_MASK));
+	memset(&vm->uv, 0, sizeof(vm->uv));
+
+	/* Convert the sblk back to non-PV */
+	vm->save_area.guest.asce = stctg(1);
+	vm->sblk->sdf = 0;
+	vm->sblk->sidad = 0;
+	vm->sblk->pv_handle_cpu = 0;
+	vm->sblk->pv_handle_config = 0;
 }
 
 int uv_unpack(struct vm *vm, uint64_t addr, uint64_t len, uint64_t tweak)