yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
77c23f
From 5a8b40c3fdafeb49072f8643210bea00ce1478c4 Mon Sep 17 00:00:00 2001
77c23f
From: Thomas Huth <thuth@redhat.com>
77c23f
Date: Fri, 29 May 2020 05:54:10 -0400
77c23f
Subject: [PATCH 28/42] s390x: protvirt: SCLP interpretation
77c23f
77c23f
RH-Author: Thomas Huth <thuth@redhat.com>
77c23f
Message-id: <20200529055420.16855-29-thuth@redhat.com>
77c23f
Patchwork-id: 97053
77c23f
O-Subject: [RHEL-8.3.0 qemu-kvm PATCH v2 28/38] s390x: protvirt: SCLP interpretation
77c23f
Bugzilla: 1828317
77c23f
RH-Acked-by: Claudio Imbrenda <cimbrend@redhat.com>
77c23f
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
77c23f
RH-Acked-by: David Hildenbrand <david@redhat.com>
77c23f
77c23f
From: Janosch Frank <frankja@linux.ibm.com>
77c23f
77c23f
SCLP for a protected guest is done over the SIDAD, so we need to use
77c23f
the s390_cpu_pv_mem_* functions to access the SIDAD instead of guest
77c23f
memory when reading/writing SCBs.
77c23f
77c23f
To not confuse the sclp emulation, we set 0x4000 as the SCCB address,
77c23f
since the function that injects the sclp external interrupt would
77c23f
reject a zero sccb address.
77c23f
77c23f
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
77c23f
Reviewed-by: David Hildenbrand <david@redhat.com>
77c23f
Reviewed-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
77c23f
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
77c23f
Reviewed-by: Christian Borntraeger <borntraeger@de.ibm.com>
77c23f
Message-Id: <20200319131921.2367-10-frankja@linux.ibm.com>
77c23f
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
77c23f
(cherry picked from commit 0f73c5b30b8ba6c0828608be496d2f59a5427539)
77c23f
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
77c23f
---
77c23f
 hw/s390x/sclp.c         | 56 +++++++++++++++++++++++++++++++++--------
77c23f
 include/hw/s390x/sclp.h |  2 ++
77c23f
 target/s390x/kvm.c      | 25 ++++++++++++++----
77c23f
 3 files changed, 67 insertions(+), 16 deletions(-)
77c23f
77c23f
diff --git a/hw/s390x/sclp.c b/hw/s390x/sclp.c
77c23f
index f57ce7b739..1c380a49cc 100644
77c23f
--- a/hw/s390x/sclp.c
77c23f
+++ b/hw/s390x/sclp.c
77c23f
@@ -33,6 +33,22 @@ static inline SCLPDevice *get_sclp_device(void)
77c23f
     return sclp;
77c23f
 }
77c23f
 
77c23f
+static inline bool sclp_command_code_valid(uint32_t code)
77c23f
+{
77c23f
+    switch (code & SCLP_CMD_CODE_MASK) {
77c23f
+    case SCLP_CMDW_READ_SCP_INFO:
77c23f
+    case SCLP_CMDW_READ_SCP_INFO_FORCED:
77c23f
+    case SCLP_CMDW_READ_CPU_INFO:
77c23f
+    case SCLP_CMDW_CONFIGURE_IOA:
77c23f
+    case SCLP_CMDW_DECONFIGURE_IOA:
77c23f
+    case SCLP_CMD_READ_EVENT_DATA:
77c23f
+    case SCLP_CMD_WRITE_EVENT_DATA:
77c23f
+    case SCLP_CMD_WRITE_EVENT_MASK:
77c23f
+        return true;
77c23f
+    }
77c23f
+    return false;
77c23f
+}
77c23f
+
77c23f
 static void prepare_cpu_entries(SCLPDevice *sclp, CPUEntry *entry, int *count)
77c23f
 {
77c23f
     MachineState *ms = MACHINE(qdev_get_machine());
77c23f
@@ -193,6 +209,34 @@ static void sclp_execute(SCLPDevice *sclp, SCCB *sccb, uint32_t code)
77c23f
     }
77c23f
 }
77c23f
 
77c23f
+/*
77c23f
+ * We only need the address to have something valid for the
77c23f
+ * service_interrupt call.
77c23f
+ */
77c23f
+#define SCLP_PV_DUMMY_ADDR 0x4000
77c23f
+int sclp_service_call_protected(CPUS390XState *env, uint64_t sccb,
77c23f
+                                uint32_t code)
77c23f
+{
77c23f
+    SCLPDevice *sclp = get_sclp_device();
77c23f
+    SCLPDeviceClass *sclp_c = SCLP_GET_CLASS(sclp);
77c23f
+    SCCB work_sccb;
77c23f
+    hwaddr sccb_len = sizeof(SCCB);
77c23f
+
77c23f
+    s390_cpu_pv_mem_read(env_archcpu(env), 0, &work_sccb, sccb_len);
77c23f
+
77c23f
+    if (!sclp_command_code_valid(code)) {
77c23f
+        work_sccb.h.response_code = cpu_to_be16(SCLP_RC_INVALID_SCLP_COMMAND);
77c23f
+        goto out_write;
77c23f
+    }
77c23f
+
77c23f
+    sclp_c->execute(sclp, &work_sccb, code);
77c23f
+out_write:
77c23f
+    s390_cpu_pv_mem_write(env_archcpu(env), 0, &work_sccb,
77c23f
+                          be16_to_cpu(work_sccb.h.length));
77c23f
+    sclp_c->service_interrupt(sclp, SCLP_PV_DUMMY_ADDR);
77c23f
+    return 0;
77c23f
+}
77c23f
+
77c23f
 int sclp_service_call(CPUS390XState *env, uint64_t sccb, uint32_t code)
77c23f
 {
77c23f
     SCLPDevice *sclp = get_sclp_device();
77c23f
@@ -230,17 +274,7 @@ int sclp_service_call(CPUS390XState *env, uint64_t sccb, uint32_t code)
77c23f
         goto out;
77c23f
     }
77c23f
 
77c23f
-    switch (code & SCLP_CMD_CODE_MASK) {
77c23f
-    case SCLP_CMDW_READ_SCP_INFO:
77c23f
-    case SCLP_CMDW_READ_SCP_INFO_FORCED:
77c23f
-    case SCLP_CMDW_READ_CPU_INFO:
77c23f
-    case SCLP_CMDW_CONFIGURE_IOA:
77c23f
-    case SCLP_CMDW_DECONFIGURE_IOA:
77c23f
-    case SCLP_CMD_READ_EVENT_DATA:
77c23f
-    case SCLP_CMD_WRITE_EVENT_DATA:
77c23f
-    case SCLP_CMD_WRITE_EVENT_MASK:
77c23f
-        break;
77c23f
-    default:
77c23f
+    if (!sclp_command_code_valid(code)) {
77c23f
         work_sccb.h.response_code = cpu_to_be16(SCLP_RC_INVALID_SCLP_COMMAND);
77c23f
         goto out_write;
77c23f
     }
77c23f
diff --git a/include/hw/s390x/sclp.h b/include/hw/s390x/sclp.h
77c23f
index c54413b78c..c0a3faa37d 100644
77c23f
--- a/include/hw/s390x/sclp.h
77c23f
+++ b/include/hw/s390x/sclp.h
77c23f
@@ -217,5 +217,7 @@ void s390_sclp_init(void);
77c23f
 void sclp_service_interrupt(uint32_t sccb);
77c23f
 void raise_irq_cpu_hotplug(void);
77c23f
 int sclp_service_call(CPUS390XState *env, uint64_t sccb, uint32_t code);
77c23f
+int sclp_service_call_protected(CPUS390XState *env, uint64_t sccb,
77c23f
+                                uint32_t code);
77c23f
 
77c23f
 #endif
77c23f
diff --git a/target/s390x/kvm.c b/target/s390x/kvm.c
77c23f
index 6809a5ac40..56fe60c49c 100644
77c23f
--- a/target/s390x/kvm.c
77c23f
+++ b/target/s390x/kvm.c
77c23f
@@ -1230,12 +1230,27 @@ static void kvm_sclp_service_call(S390CPU *cpu, struct kvm_run *run,
77c23f
     sccb = env->regs[ipbh0 & 0xf];
77c23f
     code = env->regs[(ipbh0 & 0xf0) >> 4];
77c23f
 
77c23f
-    r = sclp_service_call(env, sccb, code);
77c23f
-    if (r < 0) {
77c23f
-        kvm_s390_program_interrupt(cpu, -r);
77c23f
-        return;
77c23f
+    switch (run->s390_sieic.icptcode) {
77c23f
+    case ICPT_PV_INSTR_NOTIFICATION:
77c23f
+        g_assert(s390_is_pv());
77c23f
+        /* The notification intercepts are currently handled by KVM */
77c23f
+        error_report("unexpected SCLP PV notification");
77c23f
+        exit(1);
77c23f
+        break;
77c23f
+    case ICPT_PV_INSTR:
77c23f
+        g_assert(s390_is_pv());
77c23f
+        sclp_service_call_protected(env, sccb, code);
77c23f
+        /* Setting the CC is done by the Ultravisor. */
77c23f
+        break;
77c23f
+    case ICPT_INSTRUCTION:
77c23f
+        g_assert(!s390_is_pv());
77c23f
+        r = sclp_service_call(env, sccb, code);
77c23f
+        if (r < 0) {
77c23f
+            kvm_s390_program_interrupt(cpu, -r);
77c23f
+            return;
77c23f
+        }
77c23f
+        setcc(cpu, r);
77c23f
     }
77c23f
-    setcc(cpu, r);
77c23f
 }
77c23f
 
77c23f
 static int handle_b2(S390CPU *cpu, struct kvm_run *run, uint8_t ipa1)
77c23f
-- 
77c23f
2.27.0
77c23f