[kvm-unit-tests PATCH v2 06/10] lib: s390: sie: Add PV guest register handling

Janosch Frank
2021-12-07T16:02:14Z

Protected guests have their registers stored to / loaded from offset 0x380
of the sie control block. So we need to copy over the GRs to/from that
offset for format 4 (PV) guests before and after we enter SIE.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
---
lib/s390x/sie.c | 8 ++++++++
lib/s390x/sie.h | 2 ++
2 files changed, 10 insertions(+)

diff --git a/lib/s390x/sie.c b/lib/s390x/sie.c
index 51d3b94e..00aff713 100644
--- a/lib/s390x/sie.c
+++ b/lib/s390x/sie.c
@@ -44,6 +44,10 @@ void sie_handle_validity(struct vm *vm)

void sie(struct vm *vm)
{
+ if (vm->sblk->sdf == 2)
+ memcpy(vm->sblk->pv_grregs, vm->save_area.guest.grs,
+ sizeof(vm->save_area.guest.grs));
+
/* Reset icptcode so we don't trip over it below */
vm->sblk->icptcode = 0;

@@ -53,6 +57,10 @@ void sie(struct vm *vm)
}
vm->save_area.guest.grs[14] = vm->sblk->gg14;
vm->save_area.guest.grs[15] = vm->sblk->gg15;
+
+ if (vm->sblk->sdf == 2)
+ memcpy(vm->save_area.guest.grs, vm->sblk->pv_grregs,
+ sizeof(vm->save_area.guest.grs));
}

void sie_guest_sca_create(struct vm *vm)
diff --git a/lib/s390x/sie.h b/lib/s390x/sie.h
index 6d209793..de91ea5a 100644
--- a/lib/s390x/sie.h
+++ b/lib/s390x/sie.h
@@ -198,6 +198,8 @@ union {
uint64_t itdba; /* 0x01e8 */
uint64_t riccbd; /* 0x01f0 */
uint64_t gvrd; /* 0x01f8 */
+ uint64_t reserved200[48]; /* 0x0200 */
+ uint64_t pv_grregs[16]; /* 0x0380 */
} __attribute__((packed));

struct vm_uv {
--
2.32.0