Skip to contentSkip to conversation

hw/s390x/ipl: Remove TCG dependency in handle_diag_308()

PATCH In review Philippe Mathieu-Daudé 3 participants 8 messages Jun 17

lore
Share & tools
lore
#0 lore raw

v4 cover hw/s390x/ipl: Remove TCG dependency in handle_diag_308()

Required to decouple TCG from the TYPE_S390_IPL and properly extract the TCG cpu-loop.h API:
https://lore.kernel.org/qemu-devel/[email protected]/

Since v3:
- include pre-requisites (Jared)
- return instead of break (Richard)

Philippe Mathieu-Daudé (3):
target/s390x: Factor common s390_ipl_read/write() helpers target/s390x: Replace legacy cpu_physical_memory_read/write() calls hw/s390x/ipl: Remove TCG dependency in handle_diag_308()

 target/s390x/s390x-internal.h  |  3 +-
 hw/s390x/ipl.c                 |  5 ---
 target/s390x/diag.c            | 75 +++++++++++++++++++---------------
 target/s390x/tcg/misc_helper.c |  5 ++-
 4 files changed, 47 insertions(+), 41 deletions(-)
Signature · 1 line
2.53.0
#1 lore raw

PATCH v4 1/3 target/s390x: Factor common s390_ipl_read/write() helpers

From: Philippe Mathieu-Daudé <[email protected]>

Prevent duplication factoring common helpers.

Message-Id: <[email protected]>

---
 target/s390x/diag.c | 41 +++++++++++++++++++++++------------------
 1 file changed, 23 insertions(+), 18 deletions(-)
target/s390x/diag.c +23 -18
index da44b0133ed..bc1791067d8 100644
@@ -73,11 +73,30 @@ static int diag308_parm_check(CPUS390XState *env, uint64_t r1, uint64_t addr,
     return 0;
 }
 
+static void s390_ipl_read(CPUS390XState *env, uint64_t addr,
+                          IplParameterBlock *iplb, size_t size)
+{
+    if (s390_is_pv()) {
+        s390_cpu_pv_mem_read(env_archcpu(env), 0, iplb, size);
+    } else {
+        cpu_physical_memory_read(addr, iplb, size);
+    }
+}
+
+static void s390_ipl_write(CPUS390XState *env, uint64_t addr,
+                           IplParameterBlock *iplb, size_t size)
+{
+    if (s390_is_pv()) {
+        s390_cpu_pv_mem_write(env_archcpu(env), 0, iplb, size);
+    } else {
+        cpu_physical_memory_write(addr, iplb, size);
+    }
+}
+
 void handle_diag_308(CPUS390XState *env, uint64_t r1, uint64_t r3, uintptr_t ra)
 {
     bool valid;
     CPUState *cs = env_cpu(env);
-    S390CPU *cpu = env_archcpu(env);
     uint64_t addr =  env->regs[r1];
     uint64_t subcode = env->regs[r3];
     IplParameterBlock *iplb;
@@ -114,22 +133,12 @@ void handle_diag_308(CPUS390XState *env, uint64_t r1, uint64_t r3, uintptr_t ra)
             return;
         }
         iplb = g_new0(IplParameterBlock, 1);
-        if (!s390_is_pv()) {
-            cpu_physical_memory_read(addr, iplb, sizeof(iplb->len));
-        } else {
-            s390_cpu_pv_mem_read(cpu, 0, iplb, sizeof(iplb->len));
-        }
-
+        s390_ipl_read(env, addr, iplb, sizeof(iplb->len));
         if (!iplb_valid_len(iplb)) {
             env->regs[r1 + 1] = DIAG_308_RC_INVALID;
             goto out;
         }
-
-        if (!s390_is_pv()) {
-            cpu_physical_memory_read(addr, iplb, be32_to_cpu(iplb->len));
-        } else {
-            s390_cpu_pv_mem_read(cpu, 0, iplb, be32_to_cpu(iplb->len));
-        }
+        s390_ipl_read(env, addr, iplb, be32_to_cpu(iplb->len));
 
         valid = subcode == DIAG308_PV_SET ? iplb_valid_pv(iplb) : iplb_valid(iplb);
         if (!valid) {
@@ -164,11 +173,7 @@ out:
             return;
         }
 
-        if (!s390_is_pv()) {
-            cpu_physical_memory_write(addr, iplb, be32_to_cpu(iplb->len));
-        } else {
-            s390_cpu_pv_mem_write(cpu, 0, iplb, be32_to_cpu(iplb->len));
-        }
+        s390_ipl_write(env, addr, iplb, be32_to_cpu(iplb->len));
         env->regs[r1 + 1] = DIAG_308_RC_OK;
         return;
     case DIAG308_PV_START:
Signature · 1 line
2.53.0
Reviewed-by on v4 1/3
#2 lore raw

Re: [PATCH v4 1/3] target/s390x: Factor common s390_ipl_read/write() helpers

Quoted 10 lines · Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

Prevent duplication factoring common helpers.

Message-Id: <[email protected]>
---

#3 lore raw

PATCH v4 2/3 target/s390x: Replace legacy cpu_physical_memory_read/write() calls

In reply to Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

cpu_physical_memory_read() and cpu_physical_memory_write() are legacy (see commit b7ecba0f6f6), replace by address_space_read() and address_space_write() respectively, accessing the per-vCPU address space instead of the global &address_space_memory one.

Message-Id: <[email protected]>

---
 target/s390x/diag.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
target/s390x/diag.c +4 -2
index bc1791067d8..01cc802eaed 100644
@@ -79,7 +79,8 @@ static void s390_ipl_read(CPUS390XState *env, uint64_t addr,
     if (s390_is_pv()) {
         s390_cpu_pv_mem_read(env_archcpu(env), 0, iplb, size);
     } else {
-        cpu_physical_memory_read(addr, iplb, size);
+        address_space_read(cpu_get_address_space(env_cpu(env), 0), addr,
+                           MEMTXATTRS_UNSPECIFIED, iplb, size);
     }
 }
 
@@ -89,7 +90,8 @@ static void s390_ipl_write(CPUS390XState *env, uint64_t addr,
     if (s390_is_pv()) {
         s390_cpu_pv_mem_write(env_archcpu(env), 0, iplb, size);
     } else {
-        cpu_physical_memory_write(addr, iplb, size);
+        address_space_write(cpu_get_address_space(env_cpu(env), 0), addr,
+                            MEMTXATTRS_UNSPECIFIED, iplb, size);
     }
 }
 
Signature · 1 line
2.53.0
Reviewed-by on v4 2/3
#4 lore raw

Re: [PATCH v4 2/3] target/s390x: Replace legacy cpu_physical_memory_read/write() calls

Quoted 7 lines · Philippe Mathieu-Daudé

From: Philippe Mathieu-Daudé <[email protected]>

cpu_physical_memory_read() and cpu_physical_memory_write() are legacy (see commit b7ecba0f6f6), replace by address_space_read() and address_space_write() respectively, accessing the per-vCPU address space instead of the global &address_space_memory one.

Quoted 5 lines

Message-Id: <[email protected]>
---

#5 lore raw

PATCH v4 3/3 hw/s390x/ipl: Remove TCG dependency in handle_diag_308()

In reply to Philippe Mathieu-Daudé

Rather than calling a TCG specific method in s390_ipl_reset_request(), have handle_diag_308() return whether a vCPU reset is pending, and use that in the TCG DIAG helper to return to the main loop.

---
 target/s390x/s390x-internal.h  |  3 ++-
 hw/s390x/ipl.c                 |  5 -----
 target/s390x/diag.c            | 32 ++++++++++++++++----------------
 target/s390x/tcg/misc_helper.c |  5 ++++-
 4 files changed, 22 insertions(+), 23 deletions(-)
target/s390x/s390x-internal.h +2 -1
index e7e4f2b45d4..35d1e34ef4d 100644
@@ -385,7 +385,8 @@ int mmu_translate_real(CPUS390XState *env, hwaddr raddr, int rw,
 
 /* misc_helper.c */
 int handle_diag_288(CPUS390XState *env, uint64_t r1, uint64_t r3);
-void handle_diag_308(CPUS390XState *env, uint64_t r1, uint64_t r3,
+/* Return whether a CPU reset is pending */
+bool handle_diag_308(CPUS390XState *env, uint64_t r1, uint64_t r3,
                      uintptr_t ra);
 
 
hw/s390x/ipl.c +0 -5
index 1babcd2b7dd..28d22cdba41 100644
@@ -17,7 +17,6 @@
 #include "qapi/error.h"
 #include "system/reset.h"
 #include "system/runstate.h"
-#include "system/tcg.h"
 #include "elf.h"
 #include "hw/core/loader.h"
 #include "hw/core/qdev-properties.h"
@@ -689,10 +688,6 @@ void s390_ipl_reset_request(CPUState *cs, enum s390_reset reset_type)
     } else {
         qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET);
     }
-    /* as this is triggered by a CPU, make sure to exit the loop */
-    if (tcg_enabled()) {
-        cpu_loop_exit(cs);
-    }
 }
 
 void s390_ipl_get_reset_request(CPUState **cs, enum s390_reset *reset_type)
target/s390x/diag.c +16 -16
index 01cc802eaed..80f09584789 100644
@@ -95,7 +95,7 @@ static void s390_ipl_write(CPUS390XState *env, uint64_t addr,
     }
 }
 
-void handle_diag_308(CPUS390XState *env, uint64_t r1, uint64_t r3, uintptr_t ra)
+bool handle_diag_308(CPUS390XState *env, uint64_t r1, uint64_t r3, uintptr_t ra)
 {
     bool valid;
     CPUState *cs = env_cpu(env);
@@ -105,34 +105,34 @@ void handle_diag_308(CPUS390XState *env, uint64_t r1, uint64_t r3, uintptr_t ra)
 
     if (env->psw.mask & PSW_MASK_PSTATE) {
         s390_program_interrupt(env, PGM_PRIVILEGED, ra);
-        return;
+        return false;
     }
 
     if (subcode & ~0x0ffffULL) {
         s390_program_interrupt(env, PGM_SPECIFICATION, ra);
-        return;
+        return false;
     }
 
     if (subcode >= DIAG308_PV_SET && !s390_has_feat(S390_FEAT_UNPACK)) {
         s390_program_interrupt(env, PGM_SPECIFICATION, ra);
-        return;
+        return false;
     }
 
     switch (subcode) {
     case DIAG308_RESET_MOD_CLR:
         s390_ipl_reset_request(cs, S390_RESET_MODIFIED_CLEAR);
-        break;
+        return true;
     case DIAG308_RESET_LOAD_NORM:
         s390_ipl_reset_request(cs, S390_RESET_LOAD_NORMAL);
-        break;
+        return true;
     case DIAG308_LOAD_CLEAR:
         /* Well we still lack the clearing bit... */
         s390_ipl_reset_request(cs, S390_RESET_REIPL);
-        break;
+        return true;
     case DIAG308_SET:
     case DIAG308_PV_SET:
         if (diag308_parm_check(env, r1, addr, ra, false)) {
-            return;
+            return false;
         }
         iplb = g_new0(IplParameterBlock, 1);
         s390_ipl_read(env, addr, iplb, sizeof(iplb->len));
@@ -159,11 +159,11 @@ void handle_diag_308(CPUS390XState *env, uint64_t r1, uint64_t r3, uintptr_t ra)
         env->regs[r1 + 1] = DIAG_308_RC_OK;
 out:
         g_free(iplb);
-        return;
+        return false;
     case DIAG308_STORE:
     case DIAG308_PV_STORE:
         if (diag308_parm_check(env, r1, addr, ra, true)) {
-            return;
+            return false;
         }
         if (subcode == DIAG308_PV_STORE) {
             iplb = s390_ipl_get_iplb_pv();
@@ -172,30 +172,30 @@ out:
         }
         if (!iplb) {
             env->regs[r1 + 1] = DIAG_308_RC_NO_CONF;
-            return;
+            return false;
         }
 
         s390_ipl_write(env, addr, iplb, be32_to_cpu(iplb->len));
         env->regs[r1 + 1] = DIAG_308_RC_OK;
-        return;
+        return false;
     case DIAG308_PV_START:
         iplb = s390_ipl_get_iplb_pv();
         if (!iplb) {
             env->regs[r1 + 1] = DIAG_308_RC_NO_PV_CONF;
-            return;
+            return false;
         }
 
         if (kvm_enabled() && kvm_s390_get_hpage_1m()) {
             error_report("Protected VMs can currently not be backed with "
                          "huge pages");
             env->regs[r1 + 1] = DIAG_308_RC_INVAL_FOR_PV;
-            return;
+            return false;
         }
 
         s390_ipl_reset_request(cs, S390_RESET_PV);
-        break;
+        return true;
     default:
         s390_program_interrupt(env, PGM_SPECIFICATION, ra);
-        break;
+        return false;
     }
 }
target/s390x/tcg/misc_helper.c +4 -1
index 3d13c8bd8ea..036be93fb32 100644
@@ -135,7 +135,10 @@ void HELPER(diag)(CPUS390XState *env, uint32_t r1, uint32_t r3, uint32_t num)
     case 0x308:
         /* ipl */
         bql_lock();
-        handle_diag_308(env, r1, r3, GETPC());
+        if (handle_diag_308(env, r1, r3, GETPC())) {
+            /* As reset is triggered by the CPU, make sure to exit the loop */
+            cpu_loop_exit(CPU(env_archcpu(env)));
+        }
         bql_unlock();
         r = 0;
         break;
Signature · 1 line
2.53.0
Reviewed-by on v4 3/3
#6 lore raw
Quoted 11 lines · Philippe Mathieu-Daudé

Rather than calling a TCG specific method in s390_ipl_reset_request(), have handle_diag_308() return whether a vCPU reset is pending, and use that in the TCG DIAG helper to return to the main loop.

---
  target/s390x/s390x-internal.h  |  3 ++-
  hw/s390x/ipl.c                 |  5 -----
  target/s390x/diag.c            | 32 ++++++++++++++++----------------
  target/s390x/tcg/misc_helper.c |  5 ++++-
  4 files changed, 22 insertions(+), 23 deletions(-)

r~

Reviewed-by on v4 3/3
#7 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 4 lines · Philippe Mathieu-Daudé

Rather than calling a TCG specific method in s390_ipl_reset_request(), have handle_diag_308() return whether a vCPU reset is pending, and use that in the TCG DIAG helper to return to the main loop.

Quoted 8 lines
---
  target/s390x/s390x-internal.h  |  3 ++-
  hw/s390x/ipl.c                 |  5 -----
  target/s390x/diag.c            | 32 ++++++++++++++++----------------
  target/s390x/tcg/misc_helper.c |  5 ++++-
  4 files changed, 22 insertions(+), 23 deletions(-)