diff mbox series

[kvm-unit-tests,v2,7/7] lib: s390x: sie: Properly populate SCA

Message ID 20221020090009.2189-8-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
CPU0 is the only cpu that's being used but we should still mark it as
online and set the SDA in the SCA.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Nico Boehr <nrb@linux.ibm.com>
---
 lib/s390x/sie.c |  8 ++++++++
 lib/s390x/sie.h | 35 ++++++++++++++++++++++++++++++++++-
 2 files changed, 42 insertions(+), 1 deletion(-)

Comments

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

> CPU0 is the only cpu that's being used but we should still mark it as
> online and set the SDA in the SCA.
> 
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
> Reviewed-by: Nico Boehr <nrb@linux.ibm.com>

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

> ---
>  lib/s390x/sie.c |  8 ++++++++
>  lib/s390x/sie.h | 35 ++++++++++++++++++++++++++++++++++-
>  2 files changed, 42 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/s390x/sie.c b/lib/s390x/sie.c
> index 6efad965..a71985b6 100644
> --- a/lib/s390x/sie.c
> +++ b/lib/s390x/sie.c
> @@ -9,6 +9,7 @@
>   */
>  
>  #include <asm/barrier.h>
> +#include <bitops.h>
>  #include <libcflat.h>
>  #include <sie.h>
>  #include <asm/page.h>
> @@ -72,6 +73,13 @@ void sie_guest_sca_create(struct vm *vm)
>  	vm->sblk->scaoh = ((uint64_t)vm->sca >> 32);
>  	vm->sblk->scaol = (uint64_t)vm->sca & ~0x3fU;
>  	vm->sblk->ecb2 |= ECB2_ESCA;
> +
> +	/* Enable SIGP sense running interpretation */
> +	vm->sblk->ecb |= ECB_SRSI;
> +
> +	/* We assume that cpu 0 is always part of the vm */
> +	vm->sca->mcn[0] = BIT(63);
> +	vm->sca->cpu[0].sda = (uint64_t)vm->sblk;
>  }
>  
>  /* Initializes the struct vm members like the SIE control block. */
> diff --git a/lib/s390x/sie.h b/lib/s390x/sie.h
> index 3e3605c9..a27a8401 100644
> --- a/lib/s390x/sie.h
> +++ b/lib/s390x/sie.h
> @@ -202,6 +202,39 @@ union {
>  	uint64_t	pv_grregs[16];		/* 0x0380 */
>  } __attribute__((packed));
>  
> +union esca_sigp_ctrl {
> +	uint16_t value;
> +	struct {
> +		uint8_t c : 1;
> +		uint8_t reserved: 7;
> +		uint8_t scn;
> +	};
> +};
> +
> +struct esca_entry {
> +	union esca_sigp_ctrl sigp_ctrl;
> +	uint16_t   reserved1[3];
> +	uint64_t   sda;
> +	uint64_t   reserved2[6];
> +};
> +
> +union ipte_control {
> +	unsigned long val;
> +	struct {
> +		unsigned long k  : 1;
> +		unsigned long kh : 31;
> +		unsigned long kg : 32;
> +	};
> +};
> +
> +struct esca_block {
> +	union ipte_control ipte_control;
> +	uint64_t   reserved1[7];
> +	uint64_t   mcn[4];
> +	uint64_t   reserved2[20];
> +	struct esca_entry cpu[256];
> +};
> +
>  struct vm_uv {
>  	uint64_t vm_handle;
>  	uint64_t vcpu_handle;
> @@ -230,7 +263,7 @@ struct vm_save_area {
>  struct vm {
>  	struct kvm_s390_sie_block *sblk;
>  	struct vm_save_area save_area;
> -	void *sca;				/* System Control Area */
> +	struct esca_block *sca;			/* System Control Area */
>  	uint8_t *crycb;				/* Crypto Control Block */
>  	struct vm_uv uv;			/* PV UV information */
>  	/* Ptr to first guest page */
diff mbox series

Patch

diff --git a/lib/s390x/sie.c b/lib/s390x/sie.c
index 6efad965..a71985b6 100644
--- a/lib/s390x/sie.c
+++ b/lib/s390x/sie.c
@@ -9,6 +9,7 @@ 
  */
 
 #include <asm/barrier.h>
+#include <bitops.h>
 #include <libcflat.h>
 #include <sie.h>
 #include <asm/page.h>
@@ -72,6 +73,13 @@  void sie_guest_sca_create(struct vm *vm)
 	vm->sblk->scaoh = ((uint64_t)vm->sca >> 32);
 	vm->sblk->scaol = (uint64_t)vm->sca & ~0x3fU;
 	vm->sblk->ecb2 |= ECB2_ESCA;
+
+	/* Enable SIGP sense running interpretation */
+	vm->sblk->ecb |= ECB_SRSI;
+
+	/* We assume that cpu 0 is always part of the vm */
+	vm->sca->mcn[0] = BIT(63);
+	vm->sca->cpu[0].sda = (uint64_t)vm->sblk;
 }
 
 /* Initializes the struct vm members like the SIE control block. */
diff --git a/lib/s390x/sie.h b/lib/s390x/sie.h
index 3e3605c9..a27a8401 100644
--- a/lib/s390x/sie.h
+++ b/lib/s390x/sie.h
@@ -202,6 +202,39 @@  union {
 	uint64_t	pv_grregs[16];		/* 0x0380 */
 } __attribute__((packed));
 
+union esca_sigp_ctrl {
+	uint16_t value;
+	struct {
+		uint8_t c : 1;
+		uint8_t reserved: 7;
+		uint8_t scn;
+	};
+};
+
+struct esca_entry {
+	union esca_sigp_ctrl sigp_ctrl;
+	uint16_t   reserved1[3];
+	uint64_t   sda;
+	uint64_t   reserved2[6];
+};
+
+union ipte_control {
+	unsigned long val;
+	struct {
+		unsigned long k  : 1;
+		unsigned long kh : 31;
+		unsigned long kg : 32;
+	};
+};
+
+struct esca_block {
+	union ipte_control ipte_control;
+	uint64_t   reserved1[7];
+	uint64_t   mcn[4];
+	uint64_t   reserved2[20];
+	struct esca_entry cpu[256];
+};
+
 struct vm_uv {
 	uint64_t vm_handle;
 	uint64_t vcpu_handle;
@@ -230,7 +263,7 @@  struct vm_save_area {
 struct vm {
 	struct kvm_s390_sie_block *sblk;
 	struct vm_save_area save_area;
-	void *sca;				/* System Control Area */
+	struct esca_block *sca;			/* System Control Area */
 	uint8_t *crycb;				/* Crypto Control Block */
 	struct vm_uv uv;			/* PV UV information */
 	/* Ptr to first guest page */