[v3,12/17] s390x: protvirt: Set guest IPL PSW
diff mbox series

Message ID 20200214151636.8764-13-frankja@linux.ibm.com
State New
Headers show
Series
  • s390x: Protected Virtualization support
Related show

Commit Message

Janosch Frank Feb. 14, 2020, 3:16 p.m. UTC
Handling of CPU reset and setting of the IPL psw from guest storage at
offset 0 is done by a Ultravisor call. Let's only fetch it if
necessary.

Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
---
 hw/s390x/pv.c             |  6 ++++++
 hw/s390x/pv.h             |  2 ++
 linux-headers/linux/kvm.h |  1 +
 target/s390x/cpu.c        | 23 ++++++++++++++---------
 4 files changed, 23 insertions(+), 9 deletions(-)

Patch
diff mbox series

diff --git a/hw/s390x/pv.c b/hw/s390x/pv.c
index 5b6a26cba9..845764859c 100644
--- a/hw/s390x/pv.c
+++ b/hw/s390x/pv.c
@@ -28,6 +28,7 @@  const char* cmd_names[] = {
     "VM_UNSHARE_ALL",
     "VCPU_CREATE",
     "VCPU_DESTROY",
+    "VCPU_SET_IPL_PSW",
     NULL
 };
 
@@ -124,6 +125,11 @@  int s390_pv_set_sec_parms(uint64_t origin, uint64_t length)
     return s390_pv_cmd(KVM_PV_VM_SET_SEC_PARMS, &args);
 }
 
+void s390_pv_set_ipl_psw(CPUState *cs)
+{
+    s390_pv_cmd_vcpu_exit(cs, KVM_PV_VCPU_SET_IPL_PSW, NULL);
+}
+
 /*
  * Called for each component in the SE type IPL parameter block 0.
  */
diff --git a/hw/s390x/pv.h b/hw/s390x/pv.h
index 7d20bdd12e..3d37af01ad 100644
--- a/hw/s390x/pv.h
+++ b/hw/s390x/pv.h
@@ -19,6 +19,7 @@  void s390_pv_vm_destroy(void);
 void s390_pv_vcpu_destroy(CPUState *cs);
 int s390_pv_vcpu_create(CPUState *cs);
 int s390_pv_set_sec_parms(uint64_t origin, uint64_t length);
+void s390_pv_set_ipl_psw(CPUState *cs);
 int s390_pv_unpack(uint64_t addr, uint64_t size, uint64_t tweak);
 void s390_pv_perf_clear_reset(void);
 int s390_pv_verify(void);
@@ -29,6 +30,7 @@  void s390_pv_vm_destroy(void) {}
 void s390_pv_vcpu_destroy(CPUState *cs) {}
 int s390_pv_vcpu_create(CPUState *cs) { return 0; }
 int s390_pv_set_sec_parms(uint64_t origin, uint64_t length) { return 0; }
+void s390_pv_set_ipl_psw(CPUState *cs) {}
 int s390_pv_unpack(uint64_t addr, uint64_t size, uint64_t tweak) { return 0: }
 void s390_pv_perf_clear_reset(void) {}
 int s390_pv_verify(void) { return 0; }
diff --git a/linux-headers/linux/kvm.h b/linux-headers/linux/kvm.h
index c6f0d04115..85094bf443 100644
--- a/linux-headers/linux/kvm.h
+++ b/linux-headers/linux/kvm.h
@@ -1503,6 +1503,7 @@  enum pv_cmd_id {
 	KVM_PV_VM_UNSHARE_ALL,
 	KVM_PV_VCPU_CREATE,
 	KVM_PV_VCPU_DESTROY,
+	KVM_PV_VCPU_SET_IPL_PSW,
 };
 
 struct kvm_pv_cmd {
diff --git a/target/s390x/cpu.c b/target/s390x/cpu.c
index 1dbd84b9d7..24bb0d83ae 100644
--- a/target/s390x/cpu.c
+++ b/target/s390x/cpu.c
@@ -78,16 +78,21 @@  static bool s390_cpu_has_work(CPUState *cs)
 static void s390_cpu_load_normal(CPUState *s)
 {
     S390CPU *cpu = S390_CPU(s);
-    uint64_t spsw = ldq_phys(s->as, 0);
-
-    cpu->env.psw.mask = spsw & 0xffffffff80000000ULL;
-    /*
-     * Invert short psw indication, so SIE will report a specification
-     * exception if it was not set.
-     */
-    cpu->env.psw.mask ^= PSW_MASK_SHORTPSW;
-    cpu->env.psw.addr = spsw & 0x7fffffffULL;
+    CPUS390XState *env = &cpu->env;
+    uint64_t spsw;
 
+    if (!env->pv) {
+        spsw = ldq_phys(s->as, 0);
+        cpu->env.psw.mask = spsw & 0xffffffff80000000ULL;
+        /*
+         * Invert short psw indication, so SIE will report a specification
+         * exception if it was not set.
+         */
+        cpu->env.psw.mask ^= PSW_MASK_SHORTPSW;
+        cpu->env.psw.addr = spsw & 0x7fffffffULL;
+    } else {
+        s390_pv_set_ipl_psw(s);
+    }
     s390_cpu_set_state(S390_CPU_STATE_OPERATING, cpu);
 }
 #endif