Skip to contentSkip to conversation

s390x: Diag 308 improvements

PATCH Applied Janosch Frank 4 participants 8 messages Jan 11, 2019 – Jan 14, 2019

lore
Share & tools
lore
#0 lore raw

cover s390x: Diag 308 improvements

Let's make it architecture compliant and a bit more readable.

Each non implemented diag 308 supcode should result in a specification exception. Operating systems use the exceptions to query which codes are available.

Janosch Frank (2):
s390x: Diag308 move common parameter checking into function
s390x: Return specification exception for unimplemented diag 308
subcodes

 target/s390x/diag.c | 36 +++++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 17 deletions(-)
Signature · 1 line
2.14.3
#1 lore raw

PATCH 1/2 s390x: Diag308 move common parameter checking into function

Let's make that switch statement a bit shorter.

---
 target/s390x/diag.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)
target/s390x/diag.c +18 -16
index acb0f3d4af..cfd7222ddd 100644
@@ -53,6 +53,22 @@ int handle_diag_288(CPUS390XState *env, uint64_t r1, uint64_t r3)
 #define DIAG_308_RC_NO_CONF         0x0102
 #define DIAG_308_RC_INVALID         0x0402
 
+static int diag308_parm_check(CPUS390XState *env, uint64_t r1, uint64_t addr,
+                              uintptr_t ra)
+{
+    if ((r1 & 1) || (addr & 0x0fffULL)) {
+        s390_program_interrupt(env, PGM_SPECIFICATION, ILEN_AUTO, ra);
+        return -EINVAL;
+    }
+    if (!address_space_access_valid(&address_space_memory, addr,
+                                    sizeof(IplParameterBlock), true,
+                                    MEMTXATTRS_UNSPECIFIED)) {
+        s390_program_interrupt(env, PGM_ADDRESSING, ILEN_AUTO, ra);
+        return -EFAULT;
+    }
+    return 0;
+}
+
 void handle_diag_308(CPUS390XState *env, uint64_t r1, uint64_t r3, uintptr_t ra)
 {
     CPUState *cs = CPU(s390_env_get_cpu(env));
@@ -81,14 +97,7 @@ void handle_diag_308(CPUS390XState *env, uint64_t r1, uint64_t r3, uintptr_t ra)
         s390_ipl_reset_request(cs, S390_RESET_REIPL);
         break;
     case 5:
-        if ((r1 & 1) || (addr & 0x0fffULL)) {
-            s390_program_interrupt(env, PGM_SPECIFICATION, ILEN_AUTO, ra);
-            return;
-        }
-        if (!address_space_access_valid(&address_space_memory, addr,
-                                        sizeof(IplParameterBlock), false,
-                                        MEMTXATTRS_UNSPECIFIED)) {
-            s390_program_interrupt(env, PGM_ADDRESSING, ILEN_AUTO, ra);
+        if (diag308_parm_check(env, r1, addr, ra)) {
             return;
         }
         iplb = g_new0(IplParameterBlock, 1);
@@ -111,14 +120,7 @@ out:
         g_free(iplb);
         return;
     case 6:
-        if ((r1 & 1) || (addr & 0x0fffULL)) {
-            s390_program_interrupt(env, PGM_SPECIFICATION, ILEN_AUTO, ra);
-            return;
-        }
-        if (!address_space_access_valid(&address_space_memory, addr,
-                                        sizeof(IplParameterBlock), true,
-                                        MEMTXATTRS_UNSPECIFIED)) {
-            s390_program_interrupt(env, PGM_ADDRESSING, ILEN_AUTO, ra);
+        if (diag308_parm_check(env, r1, addr, ra)) {
             return;
         }
         iplb = s390_ipl_get_iplb();
Signature · 1 line
2.14.3
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] s390x: Diag308 move common parameter checking into function

Quoted 14 lines · Janosch Frank

Let's make that switch statement a bit shorter.

---
 target/s390x/diag.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)
target/s390x/diag.c +0 -0
index acb0f3d4af..cfd7222ddd 100644
@@ -53,6 +53,22 @@ int handle_diag_288(CPUS390XState *env, uint64_t r1, uint64_t r3)
 #define DIAG_308_RC_NO_CONF         0x0102
 #define DIAG_308_RC_INVALID         0x0402

target/s390x/diag.c int handle_diag_288(CPUS390XState *env, uint64_t r1, uint64_t r3) · line 64

Quoted 10 lines
target/s390x/diag.c +9 -0
 
+static int diag308_parm_check(CPUS390XState *env, uint64_t r1, uint64_t addr,
+                              uintptr_t ra)
+{
+    if ((r1 & 1) || (addr & 0x0fffULL)) {
+        s390_program_interrupt(env, PGM_SPECIFICATION, ILEN_AUTO, ra);
+        return -EINVAL;
+    }
+    if (!address_space_access_valid(&address_space_memory, addr,
+                                    sizeof(IplParameterBlock), true,

This is wrong, you would check for writing although you are only reading. (true vs. false)

Quoted 43 lines
target/s390x/diag.c +9 -16
+                                    MEMTXATTRS_UNSPECIFIED)) {
+        s390_program_interrupt(env, PGM_ADDRESSING, ILEN_AUTO, ra);
+        return -EFAULT;
+    }
+    return 0;
+}
+
 void handle_diag_308(CPUS390XState *env, uint64_t r1, uint64_t r3, uintptr_t ra)
 {
     CPUState *cs = CPU(s390_env_get_cpu(env));
@@ -81,14 +97,7 @@ void handle_diag_308(CPUS390XState *env, uint64_t r1, uint64_t r3, uintptr_t ra)
         s390_ipl_reset_request(cs, S390_RESET_REIPL);
         break;
     case 5:
-        if ((r1 & 1) || (addr & 0x0fffULL)) {
-            s390_program_interrupt(env, PGM_SPECIFICATION, ILEN_AUTO, ra);
-            return;
-        }
-        if (!address_space_access_valid(&address_space_memory, addr,
-                                        sizeof(IplParameterBlock), false,
-                                        MEMTXATTRS_UNSPECIFIED)) {
-            s390_program_interrupt(env, PGM_ADDRESSING, ILEN_AUTO, ra);
+        if (diag308_parm_check(env, r1, addr, ra)) {
             return;
         }
         iplb = g_new0(IplParameterBlock, 1);
@@ -111,14 +120,7 @@ out:
         g_free(iplb);
         return;
     case 6:
-        if ((r1 & 1) || (addr & 0x0fffULL)) {
-            s390_program_interrupt(env, PGM_SPECIFICATION, ILEN_AUTO, ra);
-            return;
-        }
-        if (!address_space_access_valid(&address_space_memory, addr,
-                                        sizeof(IplParameterBlock), true,
-                                        MEMTXATTRS_UNSPECIFIED)) {
-            s390_program_interrupt(env, PGM_ADDRESSING, ILEN_AUTO, ra);
+        if (diag308_parm_check(env, r1, addr, ra)) {
             return;
         }
         iplb = s390_ipl_get_iplb();
Signature · 3 lines
Thanks,

David / dhildenb
#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] s390x: Diag308 move common parameter checking into function

Quoted 16 lines · David Hildenbrand
Quoted 15 lines · Janosch Frank

Let's make that switch statement a bit shorter.

---
 target/s390x/diag.c | 34 ++++++++++++++++++----------------
 1 file changed, 18 insertions(+), 16 deletions(-)
target/s390x/diag.c +0 -0
index acb0f3d4af..cfd7222ddd 100644
@@ -53,6 +53,22 @@ int handle_diag_288(CPUS390XState *env, uint64_t r1, uint64_t r3)
 #define DIAG_308_RC_NO_CONF         0x0102
 #define DIAG_308_RC_INVALID         0x0402
 
Quoted 12 lines

target/s390x/diag.c int handle_diag_288(CPUS390XState *env, uint64_t r1, uint64_t r3) · line 64

Quoted 9 lines
target/s390x/diag.c +9 -0
+static int diag308_parm_check(CPUS390XState *env, uint64_t r1, uint64_t addr,
+                              uintptr_t ra)
+{
+    if ((r1 & 1) || (addr & 0x0fffULL)) {
+        s390_program_interrupt(env, PGM_SPECIFICATION, ILEN_AUTO, ra);
+        return -EINVAL;
+    }
+    if (!address_space_access_valid(&address_space_memory, addr,
+                                    sizeof(IplParameterBlock), true,

This is wrong, you would check for writing although you are only reading. (true vs. false)

Friday morning patches are the best patches :)
Let's drop that one for now, we'll touch it again, if we need to tinker there.

#4 lore raw

PATCH 2/2 s390x: Return specification exception for unimplemented diag 308 subcodes

In reply to Janosch Frank

The architecture specifies specification exceptions for all unavailable subcodes.

The presence of subcodes is indicated by checking some query subcode. For example 6 will indicate that 3-6 are available. So future systems might call new subcodes to check for new features. This should not trigger a hw error, instead we return the architectured specification exception.

---
 target/s390x/diag.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/s390x/diag.c +1 -1
index cfd7222ddd..c28cf1d9f1 100644
@@ -132,7 +132,7 @@ out:
         }
         return;
     default:
-        hw_error("Unhandled diag308 subcode %" PRIx64, subcode);
+        s390_program_interrupt(env, PGM_SPECIFICATION, ILEN_AUTO, ra);
         break;
     }
 }
Signature · 1 line
2.14.3
Reviewed-by on v1 2/2
#5 lore raw

Re: [Qemu-devel] [PATCH 2/2] s390x: Return specification exception for unimplemented diag 308 subcodes

Quoted 11 lines · Janosch Frank

The architecture specifies specification exceptions for all unavailable subcodes.

The presence of subcodes is indicated by checking some query subcode. For example 6 will indicate that 3-6 are available. So future systems might call new subcodes to check for new features. This should not trigger a hw error, instead we return the architectured specification exception.

Yes, PIC06 is definitively the right thing to do.

Quoted 18 lines
---
 target/s390x/diag.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/s390x/diag.c +1 -1
index cfd7222ddd..c28cf1d9f1 100644
@@ -132,7 +132,7 @@ out:
         }
         return;
     default:
-        hw_error("Unhandled diag308 subcode %" PRIx64, subcode);
+        s390_program_interrupt(env, PGM_SPECIFICATION, ILEN_AUTO, ra);
         break;
     }
 }
Reviewed-by on v1 2/2
#6 lore raw

Re: [Qemu-devel] [PATCH 2/2] s390x: Return specification exception for unimplemented diag 308 subcodes

In reply to Janosch Frank
Quoted 21 lines · Janosch Frank

The architecture specifies specification exceptions for all unavailable subcodes.

The presence of subcodes is indicated by checking some query subcode. For example 6 will indicate that 3-6 are available. So future systems might call new subcodes to check for new features. This should not trigger a hw error, instead we return the architectured specification exception.

---
 target/s390x/diag.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/s390x/diag.c +0 -0
index cfd7222ddd..c28cf1d9f1 100644

target/s390x/diag.c out: · line 138

Quoted 8 lines
target/s390x/diag.c +1 -1
@@ -132,7 +132,7 @@ out:
         }
         return;
     default:
-        hw_error("Unhandled diag308 subcode %" PRIx64, subcode);
+        s390_program_interrupt(env, PGM_SPECIFICATION, ILEN_AUTO, ra);
         break;
     }
 }
Signature · 3 lines
Thanks,

David / dhildenb
#7 lore raw

Re: [Qemu-devel] [PATCH 2/2] s390x: Return specification exception for unimplemented diag 308 subcodes

In reply to Janosch Frank
Quoted 9 lines · On Fri, 11 Jan 2019 12:36:57 +0100 Janosch Frank <[email protected]> wrote:

The architecture specifies specification exceptions for all unavailable subcodes.

The presence of subcodes is indicated by checking some query subcode. For example 6 will indicate that 3-6 are available. So future systems might call new subcodes to check for new features. This should not trigger a hw error, instead we return the architectured specification exception.

Quoted 5 lines
---
 target/s390x/diag.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Thanks, applied.