902636
From da81f2b579987ea12929f0ec803716bc16a93df7 Mon Sep 17 00:00:00 2001
902636
From: Thomas Huth <thuth@redhat.com>
902636
Date: Fri, 29 May 2020 05:53:49 -0400
902636
Subject: [PATCH 07/42] s390x: Beautify diag308 handling
902636
MIME-Version: 1.0
902636
Content-Type: text/plain; charset=UTF-8
902636
Content-Transfer-Encoding: 8bit
902636
902636
RH-Author: Thomas Huth <thuth@redhat.com>
902636
Message-id: <20200529055420.16855-8-thuth@redhat.com>
902636
Patchwork-id: 97022
902636
O-Subject: [RHEL-8.3.0 qemu-kvm PATCH v2 07/38] s390x: Beautify diag308 handling
902636
Bugzilla: 1828317
902636
RH-Acked-by: Claudio Imbrenda <cimbrend@redhat.com>
902636
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
902636
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
902636
RH-Acked-by: David Hildenbrand <david@redhat.com>
902636
902636
From: Janosch Frank <frankja@linux.ibm.com>
902636
902636
Let's improve readability by:
902636
* Using constants for the subcodes
902636
* Moving parameter checking into a function
902636
* Removing subcode > 6 check as the default case catches that
902636
902636
Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
902636
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
902636
Reviewed-by: Thomas Huth <thuth@redhat.com>
902636
Reviewed-by: David Hildenbrand <david@redhat.com>
902636
Message-Id: <20191127175046.4911-6-frankja@linux.ibm.com>
902636
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
902636
(cherry picked from commit 0b7fd817e0f383760e37ca9286150d5816cf0594)
902636
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
902636
---
902636
 target/s390x/diag.c | 54 +++++++++++++++++++++++++++------------------
902636
 1 file changed, 32 insertions(+), 22 deletions(-)
902636
902636
diff --git a/target/s390x/diag.c b/target/s390x/diag.c
902636
index 53c2f81f2a..b5aec06d6b 100644
902636
--- a/target/s390x/diag.c
902636
+++ b/target/s390x/diag.c
902636
@@ -53,6 +53,29 @@ int handle_diag_288(CPUS390XState *env, uint64_t r1, uint64_t r3)
902636
 #define DIAG_308_RC_NO_CONF         0x0102
902636
 #define DIAG_308_RC_INVALID         0x0402
902636
 
902636
+#define DIAG308_RESET_MOD_CLR       0
902636
+#define DIAG308_RESET_LOAD_NORM     1
902636
+#define DIAG308_LOAD_CLEAR          3
902636
+#define DIAG308_LOAD_NORMAL_DUMP    4
902636
+#define DIAG308_SET                 5
902636
+#define DIAG308_STORE               6
902636
+
902636
+static int diag308_parm_check(CPUS390XState *env, uint64_t r1, uint64_t addr,
902636
+                              uintptr_t ra, bool write)
902636
+{
902636
+    if ((r1 & 1) || (addr & ~TARGET_PAGE_MASK)) {
902636
+        s390_program_interrupt(env, PGM_SPECIFICATION, ra);
902636
+        return -1;
902636
+    }
902636
+    if (!address_space_access_valid(&address_space_memory, addr,
902636
+                                    sizeof(IplParameterBlock), write,
902636
+                                    MEMTXATTRS_UNSPECIFIED)) {
902636
+        s390_program_interrupt(env, PGM_ADDRESSING, ra);
902636
+        return -1;
902636
+    }
902636
+    return 0;
902636
+}
902636
+
902636
 void handle_diag_308(CPUS390XState *env, uint64_t r1, uint64_t r3, uintptr_t ra)
902636
 {
902636
     CPUState *cs = env_cpu(env);
902636
@@ -65,30 +88,24 @@ void handle_diag_308(CPUS390XState *env, uint64_t r1, uint64_t r3, uintptr_t ra)
902636
         return;
902636
     }
902636
 
902636
-    if ((subcode & ~0x0ffffULL) || (subcode > 6)) {
902636
+    if (subcode & ~0x0ffffULL) {
902636
         s390_program_interrupt(env, PGM_SPECIFICATION, ra);
902636
         return;
902636
     }
902636
 
902636
     switch (subcode) {
902636
-    case 0:
902636
+    case DIAG308_RESET_MOD_CLR:
902636
         s390_ipl_reset_request(cs, S390_RESET_MODIFIED_CLEAR);
902636
         break;
902636
-    case 1:
902636
+    case DIAG308_RESET_LOAD_NORM:
902636
         s390_ipl_reset_request(cs, S390_RESET_LOAD_NORMAL);
902636
         break;
902636
-    case 3:
902636
+    case DIAG308_LOAD_CLEAR:
902636
+        /* Well we still lack the clearing bit... */
902636
         s390_ipl_reset_request(cs, S390_RESET_REIPL);
902636
         break;
902636
-    case 5:
902636
-        if ((r1 & 1) || (addr & 0x0fffULL)) {
902636
-            s390_program_interrupt(env, PGM_SPECIFICATION, ra);
902636
-            return;
902636
-        }
902636
-        if (!address_space_access_valid(&address_space_memory, addr,
902636
-                                        sizeof(IplParameterBlock), false,
902636
-                                        MEMTXATTRS_UNSPECIFIED)) {
902636
-            s390_program_interrupt(env, PGM_ADDRESSING, ra);
902636
+    case DIAG308_SET:
902636
+        if (diag308_parm_check(env, r1, addr, ra, false)) {
902636
             return;
902636
         }
902636
         iplb = g_new0(IplParameterBlock, 1);
902636
@@ -110,15 +127,8 @@ void handle_diag_308(CPUS390XState *env, uint64_t r1, uint64_t r3, uintptr_t ra)
902636
 out:
902636
         g_free(iplb);
902636
         return;
902636
-    case 6:
902636
-        if ((r1 & 1) || (addr & 0x0fffULL)) {
902636
-            s390_program_interrupt(env, PGM_SPECIFICATION, ra);
902636
-            return;
902636
-        }
902636
-        if (!address_space_access_valid(&address_space_memory, addr,
902636
-                                        sizeof(IplParameterBlock), true,
902636
-                                        MEMTXATTRS_UNSPECIFIED)) {
902636
-            s390_program_interrupt(env, PGM_ADDRESSING, ra);
902636
+    case DIAG308_STORE:
902636
+        if (diag308_parm_check(env, r1, addr, ra, true)) {
902636
             return;
902636
         }
902636
         iplb = s390_ipl_get_iplb();
902636
-- 
902636
2.27.0
902636