Skip to contentSkip to conversation

target/s390x/cpu: Restrict CPUS390XState declaration to 'cpu.h'

PATCH In review Philippe Mathieu-Daudé 3 participants 11 messages Nov 6, 2023 – Nov 7, 2023

lore
Share & tools
lore
#0 lore raw

cover target/s390x/cpu: Restrict CPUS390XState declaration to 'cpu.h'

In order to restrict CPUS390XState declaration to "cpu.h" (both target-specific):
- have the following prototypes take a S390CPU* instead:
. css_do_sic()
. sclp_service_call()
. sclp_service_call_protected()
- restrict cpu_get_tb_cpu_state() definition to TCG

Philippe Mathieu-Daudé (4):
hw/s390x/css: Have css_do_sic() take S390CPU instead of CPUS390XState hw/s390x/sclp: Have sclp_service_call[_protected]() take S390CPU* target/s390x/cpu: Restrict cpu_get_tb_cpu_state() definition to TCG target/s390x/cpu: Restrict CPUS390XState declaration to 'cpu.h'

 include/hw/s390x/css.h         |  2 +-
 include/hw/s390x/sclp.h        |  5 ++---
 target/s390x/cpu-qom.h         |  2 --
 target/s390x/cpu.h             | 11 ++++++++---
 hw/s390x/css.c                 |  3 ++-
 hw/s390x/sclp.c                |  7 ++++---
 target/s390x/kvm/kvm.c         |  4 ++--
 target/s390x/tcg/misc_helper.c |  5 +++--
 8 files changed, 22 insertions(+), 17 deletions(-)
Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/4 hw/s390x/css: Have css_do_sic() take S390CPU instead of CPUS390XState

"hw/s390x/css.h" is a header used by target-agnostic objects (such hw/s390x/virtio-ccw-gpu.c), thus can not use target-specific types, such CPUS390XState.

Have css_do_sic() take S390CPU a pointer, which is target-agnostic.

---
 include/hw/s390x/css.h         | 2 +-
 hw/s390x/css.c                 | 3 ++-
 target/s390x/kvm/kvm.c         | 2 +-
 target/s390x/tcg/misc_helper.c | 3 ++-
 4 files changed, 6 insertions(+), 4 deletions(-)
include/hw/s390x/css.h +1 -1
index 75e5381613..ba72ee3dd2 100644
@@ -233,7 +233,7 @@ typedef enum {
 } CssIoAdapterType;
 
 void css_adapter_interrupt(CssIoAdapterType type, uint8_t isc);
-int css_do_sic(CPUS390XState *env, uint8_t isc, uint16_t mode);
+int css_do_sic(S390CPU *cpu, uint8_t isc, uint16_t mode);
 uint32_t css_get_adapter_id(CssIoAdapterType type, uint8_t isc);
 void css_register_io_adapters(CssIoAdapterType type, bool swap, bool maskable,
                               uint8_t flags, Error **errp);
hw/s390x/css.c +2 -1
index 95d1b3a3ce..bcedec2fc8 100644
@@ -644,8 +644,9 @@ void css_conditional_io_interrupt(SubchDev *sch)
     }
 }
 
-int css_do_sic(CPUS390XState *env, uint8_t isc, uint16_t mode)
+int css_do_sic(S390CPU *cpu, uint8_t isc, uint16_t mode)
 {
+    CPUS390XState *env = &cpu->env;
     S390FLICState *fs = s390_get_flic();
     S390FLICStateClass *fsc = s390_get_flic_class(fs);
     int r;
target/s390x/kvm/kvm.c +1 -1
index 0f0e784b2a..1ddad0bec1 100644
@@ -1358,7 +1358,7 @@ static int kvm_sic_service_call(S390CPU *cpu, struct kvm_run *run)
 
     mode = env->regs[r1] & 0xffff;
     isc = (env->regs[r3] >> 27) & 0x7;
-    r = css_do_sic(env, isc, mode);
+    r = css_do_sic(cpu, isc, mode);
     if (r) {
         kvm_s390_program_interrupt(cpu, -r);
     }
target/s390x/tcg/misc_helper.c +2 -1
index e85658ce22..56c7f00cf9 100644
@@ -761,10 +761,11 @@ void HELPER(stpcifc)(CPUS390XState *env, uint32_t r1, uint64_t fiba,
 
 void HELPER(sic)(CPUS390XState *env, uint64_t r1, uint64_t r3)
 {
+    S390CPU *cpu = env_archcpu(env);
     int r;
 
     qemu_mutex_lock_iothread();
-    r = css_do_sic(env, (r3 >> 27) & 0x7, r1 & 0xffff);
+    r = css_do_sic(cpu, (r3 >> 27) & 0x7, r1 & 0xffff);
     qemu_mutex_unlock_iothread();
     /* css_do_sic() may actually return a PGM_xxx value to inject */
     if (r) {
Signature · 1 line
2.41.0
#2 lore raw

PATCH 2/4 hw/s390x/sclp: Have sclp_service_call[_protected]() take S390CPU*

In reply to Philippe Mathieu-Daudé

"hw/s390x/sclp.h" is a header used by target-agnostic objects (such hw/char/sclpconsole[-lm].c), thus can not use target-specific types, such CPUS390XState.

Have sclp_service_call[_protected]() take a S390CPU pointer, which is target-agnostic.

---
 include/hw/s390x/sclp.h        | 5 ++---
 hw/s390x/sclp.c                | 7 ++++---
 target/s390x/kvm/kvm.c         | 2 +-
 target/s390x/tcg/misc_helper.c | 2 +-
 4 files changed, 8 insertions(+), 8 deletions(-)
include/hw/s390x/sclp.h +2 -3
index 9aef6d9370..e229b81a67 100644
@@ -227,8 +227,7 @@ static inline int sccb_data_len(SCCB *sccb)
 void s390_sclp_init(void);
 void sclp_service_interrupt(uint32_t sccb);
 void raise_irq_cpu_hotplug(void);
-int sclp_service_call(CPUS390XState *env, uint64_t sccb, uint32_t code);
-int sclp_service_call_protected(CPUS390XState *env, uint64_t sccb,
-                                uint32_t code);
+int sclp_service_call(S390CPU *cpu, uint64_t sccb, uint32_t code);
+int sclp_service_call_protected(S390CPU *cpu, uint64_t sccb, uint32_t code);
 
 #endif
hw/s390x/sclp.c +4 -3
index d339cbb7e4..893e71a41b 100644
@@ -269,9 +269,9 @@ static void sclp_execute(SCLPDevice *sclp, SCCB *sccb, uint32_t code)
  * service_interrupt call.
  */
 #define SCLP_PV_DUMMY_ADDR 0x4000
-int sclp_service_call_protected(CPUS390XState *env, uint64_t sccb,
-                                uint32_t code)
+int sclp_service_call_protected(S390CPU *cpu, uint64_t sccb, uint32_t code)
 {
+    CPUS390XState *env = &cpu->env;
     SCLPDevice *sclp = get_sclp_device();
     SCLPDeviceClass *sclp_c = SCLP_GET_CLASS(sclp);
     SCCBHeader header;
@@ -296,8 +296,9 @@ out_write:
     return 0;
 }
 
-int sclp_service_call(CPUS390XState *env, uint64_t sccb, uint32_t code)
+int sclp_service_call(S390CPU *cpu, uint64_t sccb, uint32_t code)
 {
+    CPUS390XState *env = &cpu->env;
     SCLPDevice *sclp = get_sclp_device();
     SCLPDeviceClass *sclp_c = SCLP_GET_CLASS(sclp);
     SCCBHeader header;
target/s390x/kvm/kvm.c +1 -1
index 1ddad0bec1..a12fbfc026 100644
@@ -1174,7 +1174,7 @@ static void kvm_sclp_service_call(S390CPU *cpu, struct kvm_run *run,
         break;
     case ICPT_PV_INSTR:
         g_assert(s390_is_pv());
-        sclp_service_call_protected(env, sccb, code);
+        sclp_service_call_protected(cpu, sccb, code);
         /* Setting the CC is done by the Ultravisor. */
         break;
     case ICPT_INSTRUCTION:
target/s390x/tcg/misc_helper.c +1 -1
index 56c7f00cf9..6aa7907438 100644
@@ -102,7 +102,7 @@ uint64_t HELPER(stck)(CPUS390XState *env)
 uint32_t HELPER(servc)(CPUS390XState *env, uint64_t r1, uint64_t r2)
 {
     qemu_mutex_lock_iothread();
-    int r = sclp_service_call(env, r1, r2);
+    int r = sclp_service_call(env_archcpu(env), r1, r2);
     qemu_mutex_unlock_iothread();
     if (r < 0) {
         tcg_s390_program_interrupt(env, -r, GETPC());
Signature · 1 line
2.41.0
#3 lore raw

Re: [PATCH 2/4] hw/s390x/sclp: Have sclp_service_call[_protected]() take S390CPU*

Quoted 62 lines · Philippe Mathieu-Daudé

"hw/s390x/sclp.h" is a header used by target-agnostic objects (such hw/char/sclpconsole[-lm].c), thus can not use target-specific types, such CPUS390XState.

Have sclp_service_call[_protected]() take a S390CPU pointer, which is target-agnostic.

---
  include/hw/s390x/sclp.h        | 5 ++---
  hw/s390x/sclp.c                | 7 ++++---
  target/s390x/kvm/kvm.c         | 2 +-
  target/s390x/tcg/misc_helper.c | 2 +-
  4 files changed, 8 insertions(+), 8 deletions(-)
include/hw/s390x/sclp.h +2 -3
index 9aef6d9370..e229b81a67 100644
@@ -227,8 +227,7 @@ static inline int sccb_data_len(SCCB *sccb)
  void s390_sclp_init(void);
  void sclp_service_interrupt(uint32_t sccb);
  void raise_irq_cpu_hotplug(void);
-int sclp_service_call(CPUS390XState *env, uint64_t sccb, uint32_t code);
-int sclp_service_call_protected(CPUS390XState *env, uint64_t sccb,
-                                uint32_t code);
+int sclp_service_call(S390CPU *cpu, uint64_t sccb, uint32_t code);
+int sclp_service_call_protected(S390CPU *cpu, uint64_t sccb, uint32_t code);
 
  #endif
hw/s390x/sclp.c +4 -3
index d339cbb7e4..893e71a41b 100644
@@ -269,9 +269,9 @@ static void sclp_execute(SCLPDevice *sclp, SCCB *sccb, uint32_t code)
   * service_interrupt call.
   */
  #define SCLP_PV_DUMMY_ADDR 0x4000
-int sclp_service_call_protected(CPUS390XState *env, uint64_t sccb,
-                                uint32_t code)
+int sclp_service_call_protected(S390CPU *cpu, uint64_t sccb, uint32_t code)
  {
+    CPUS390XState *env = &cpu->env;
      SCLPDevice *sclp = get_sclp_device();
      SCLPDeviceClass *sclp_c = SCLP_GET_CLASS(sclp);
      SCCBHeader header;
@@ -296,8 +296,9 @@ out_write:
      return 0;
  }
 
-int sclp_service_call(CPUS390XState *env, uint64_t sccb, uint32_t code)
+int sclp_service_call(S390CPU *cpu, uint64_t sccb, uint32_t code)
  {
+    CPUS390XState *env = &cpu->env;
      SCLPDevice *sclp = get_sclp_device();
      SCLPDeviceClass *sclp_c = SCLP_GET_CLASS(sclp);
      SCCBHeader header;
target/s390x/kvm/kvm.c +0 -0
index 1ddad0bec1..a12fbfc026 100644

target/s390x/kvm/kvm.c static void kvm_sclp_service_call(S390CPU *cpu, struct kvm_run *run, · line 1180

Quoted 8 lines
target/s390x/kvm/kvm.c +1 -1
@@ -1174,7 +1174,7 @@ static void kvm_sclp_service_call(S390CPU *cpu, struct kvm_run *run,
          break;
      case ICPT_PV_INSTR:
          g_assert(s390_is_pv());
-        sclp_service_call_protected(env, sccb, code);
+        sclp_service_call_protected(cpu, sccb, code);
          /* Setting the CC is done by the Ultravisor. */
          break;
      case ICPT_INSTRUCTION:

Here I forgot:
-- >8 --
@@ -1179,7 +1179,7 @@ static void kvm_sclp_service_call(S390CPU *cpu, struct kvm_run *run,

         break;
     case ICPT_INSTRUCTION:
         g_assert(!s390_is_pv());
-        r = sclp_service_call(env, sccb, code);
+        r = sclp_service_call(cpu, sccb, code);
         if (r < 0) {
             kvm_s390_program_interrupt(cpu, -r);
             return;

---

Quoted 13 lines
target/s390x/tcg/misc_helper.c +1 -1
index 56c7f00cf9..6aa7907438 100644
@@ -102,7 +102,7 @@ uint64_t HELPER(stck)(CPUS390XState *env)
  uint32_t HELPER(servc)(CPUS390XState *env, uint64_t r1, uint64_t r2)
  {
      qemu_mutex_lock_iothread();
-    int r = sclp_service_call(env, r1, r2);
+    int r = sclp_service_call(env_archcpu(env), r1, r2);
      qemu_mutex_unlock_iothread();
      if (r < 0) {
          tcg_s390_program_interrupt(env, -r, GETPC());
#4 lore raw

PATCH 3/4 target/s390x/cpu: Restrict cpu_get_tb_cpu_state() definition to TCG

In reply to Philippe Mathieu-Daudé

cpu_get_tb_cpu_state() is TCG specific. Another accelerator calling it would be a bug, so restrict the definition to TCG, along with "tcg_s390x.h" header inclusion.

---
 target/s390x/cpu.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
target/s390x/cpu.h +6 -1
index 38d7197f4c..110902fa3c 100644
@@ -29,7 +29,6 @@
 #include "cpu_models.h"
 #include "exec/cpu-defs.h"
 #include "qemu/cpu-float.h"
-#include "tcg/tcg_s390x.h"
 #include "qapi/qapi-types-machine-common.h"
 
 #define ELF_MACHINE_UNAME "S390X"
@@ -383,6 +382,10 @@ static inline int cpu_mmu_index(CPUS390XState *env, bool ifetch)
 #endif
 }
 
+#ifdef CONFIG_TCG
+
+#include "tcg/tcg_s390x.h"
+
 static inline void cpu_get_tb_cpu_state(CPUS390XState *env, vaddr *pc,
                                         uint64_t *cs_base, uint32_t *flags)
 {
@@ -405,6 +408,8 @@ static inline void cpu_get_tb_cpu_state(CPUS390XState *env, vaddr *pc,
     }
 }
 
+#endif /* CONFIG_TCG */
+
 /* PER bits from control register 9 */
 #define PER_CR9_EVENT_BRANCH           0x80000000
 #define PER_CR9_EVENT_IFETCH           0x40000000
Signature · 1 line
2.41.0
#5 lore raw

PATCH 4/4 target/s390x/cpu: Restrict CPUS390XState declaration to 'cpu.h'

In reply to Philippe Mathieu-Daudé

"target/s390x/cpu-qom.h" has to be target-agnostic. However, it currently declares CPUS390XState, which is target-specific. Move that declaration to "cpu.h".

---
 target/s390x/cpu-qom.h | 2 --
 target/s390x/cpu.h     | 4 ++--
 2 files changed, 2 insertions(+), 4 deletions(-)
target/s390x/cpu-qom.h +0 -2
index fcd70daddf..ccf126b7a9 100644
@@ -33,8 +33,6 @@ OBJECT_DECLARE_CPU_TYPE(S390CPU, S390CPUClass, S390_CPU)
 typedef struct S390CPUModel S390CPUModel;
 typedef struct S390CPUDef S390CPUDef;
 
-typedef struct CPUArchState CPUS390XState;
-
 typedef enum cpu_reset_type {
     S390_CPU_RESET_NORMAL,
     S390_CPU_RESET_INITIAL,
target/s390x/cpu.h +2 -2
index 110902fa3c..942589c597 100644
@@ -55,7 +55,7 @@ typedef struct PSW {
     uint64_t addr;
 } PSW;
 
-struct CPUArchState {
+typedef struct CPUArchState {
     uint64_t regs[16];     /* GP registers */
     /*
      * The floating point registers are part of the vector registers.
@@ -157,7 +157,7 @@ struct CPUArchState {
     /* currently processed sigp order */
     uint8_t sigp_order;
 
-};
+} CPUS390XState;
 
 static inline uint64_t *get_freg(CPUS390XState *cs, int nr)
 {
Signature · 1 line
2.41.0
Reviewed-by on v1 4/4
#6 lore raw
Quoted 10 lines · Philippe Mathieu-Daudé

Date: Mon, 6 Nov 2023 12:44:59 +0100
From: Philippe Mathieu-Daudé <[email protected]>
Subject: [PATCH 4/4] target/s390x/cpu: Restrict CPUS390XState declaration
to 'cpu.h'
X-Mailer: git-send-email 2.41.0

"target/s390x/cpu-qom.h" has to be target-agnostic. However, it currently declares CPUS390XState, which is target-specific. Move that declaration to "cpu.h".

Quoted 5 lines
---
 target/s390x/cpu-qom.h | 2 --
 target/s390x/cpu.h     | 4 ++--
 2 files changed, 2 insertions(+), 4 deletions(-)

Sorry be late, as the response for [1],

[1]: https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 39 lines
target/s390x/cpu-qom.h +0 -2
index fcd70daddf..ccf126b7a9 100644
@@ -33,8 +33,6 @@ OBJECT_DECLARE_CPU_TYPE(S390CPU, S390CPUClass, S390_CPU)
 typedef struct S390CPUModel S390CPUModel;
 typedef struct S390CPUDef S390CPUDef;
 
-typedef struct CPUArchState CPUS390XState;
-
 typedef enum cpu_reset_type {
     S390_CPU_RESET_NORMAL,
     S390_CPU_RESET_INITIAL,
target/s390x/cpu.h +2 -2
index 110902fa3c..942589c597 100644
@@ -55,7 +55,7 @@ typedef struct PSW {
     uint64_t addr;
 } PSW;
 
-struct CPUArchState {
+typedef struct CPUArchState {
     uint64_t regs[16];     /* GP registers */
     /*
      * The floating point registers are part of the vector registers.
@@ -157,7 +157,7 @@ struct CPUArchState {
     /* currently processed sigp order */
     uint8_t sigp_order;
 
-};
+} CPUS390XState;
 
 static inline uint64_t *get_freg(CPUS390XState *cs, int nr)
 {
Signature · 1 line
2.41.0
#7 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 6 lines · Philippe Mathieu-Daudé

In order to restrict CPUS390XState declaration to "cpu.h" (both target-specific):
- have the following prototypes take a S390CPU* instead:

   . css_do_sic()
   . sclp_service_call()
   . sclp_service_call_protected()
Quoted 7 lines

- restrict cpu_get_tb_cpu_state() definition to TCG

Philippe Mathieu-Daudé (4):

   hw/s390x/css: Have css_do_sic() take S390CPU instead of CPUS390XState
   hw/s390x/sclp: Have sclp_service_call[_protected]() take S390CPU*
   target/s390x/cpu: Restrict cpu_get_tb_cpu_state() definition to TCG
   target/s390x/cpu: Restrict CPUS390XState declaration to 'cpu.h'

Patches look reasonable. Thanks, queued them now!

Thomas

#8 lore raw
Quoted 9 lines · Thomas Huth
Quoted 8 lines · Philippe Mathieu-Daudé

In order to restrict CPUS390XState declaration to "cpu.h" (both target-specific):
- have the following prototypes take a S390CPU* instead:
   . css_do_sic()
   . sclp_service_call()
   . sclp_service_call_protected()
- restrict cpu_get_tb_cpu_state() definition to TCG

Quoted 7 lines
Quoted 5 lines

Philippe Mathieu-Daudé (4):
   hw/s390x/css: Have css_do_sic() take S390CPU instead of CPUS390XState hw/s390x/sclp: Have sclp_service_call[_protected]() take S390CPU* target/s390x/cpu: Restrict cpu_get_tb_cpu_state() definition to TCG target/s390x/cpu: Restrict CPUS390XState declaration to 'cpu.h'

Patches look reasonable. Thanks, queued them now!

Thanks, since I wasn't sure the series would be reviewed in time for soft freeze, I didn't mention it would be more convenient for me to take it via my hw-misc tree. Since you kindly reviewed it, I'll take it :) Thanks!

Phil.

#9 lore raw
Quoted 16 lines · Philippe Mathieu-Daudé
Quoted 15 lines · Thomas Huth
Quoted 13 lines · Philippe Mathieu-Daudé

In order to restrict CPUS390XState declaration to "cpu.h" (both target-specific):
- have the following prototypes take a S390CPU* instead:
   . css_do_sic()
   . sclp_service_call()
   . sclp_service_call_protected()
- restrict cpu_get_tb_cpu_state() definition to TCG

Philippe Mathieu-Daudé (4):
   hw/s390x/css: Have css_do_sic() take S390CPU instead of CPUS390XState hw/s390x/sclp: Have sclp_service_call[_protected]() take S390CPU* target/s390x/cpu: Restrict cpu_get_tb_cpu_state() definition to TCG target/s390x/cpu: Restrict CPUS390XState declaration to 'cpu.h'

Quoted 6 lines
Quoted 1 line

Patches look reasonable. Thanks, queued them now!

Thanks, since I wasn't sure the series would be reviewed in time for soft freeze, I didn't mention it would be more convenient for me to take it via my hw-misc tree. Since you kindly reviewed it, I'll take it :) Thanks!

All right, I'll drop them from my queue again then.

Thomas

Reviewed-by on the v1 series
#10 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 14 lines · Philippe Mathieu-Daudé

In order to restrict CPUS390XState declaration to "cpu.h" (both target-specific):
- have the following prototypes take a S390CPU* instead:

   . css_do_sic()
   . sclp_service_call()
   . sclp_service_call_protected()

- restrict cpu_get_tb_cpu_state() definition to TCG

Philippe Mathieu-Daudé (4):

   hw/s390x/css: Have css_do_sic() take S390CPU instead of CPUS390XState
   hw/s390x/sclp: Have sclp_service_call[_protected]() take S390CPU*
   target/s390x/cpu: Restrict cpu_get_tb_cpu_state() definition to TCG
   target/s390x/cpu: Restrict CPUS390XState declaration to 'cpu.h'
Quoted 10 lines
  include/hw/s390x/css.h         |  2 +-
  include/hw/s390x/sclp.h        |  5 ++---
  target/s390x/cpu-qom.h         |  2 --
  target/s390x/cpu.h             | 11 ++++++++---
  hw/s390x/css.c                 |  3 ++-
  hw/s390x/sclp.c                |  7 ++++---
  target/s390x/kvm/kvm.c         |  4 ++--
  target/s390x/tcg/misc_helper.c |  5 +++--
  8 files changed, 22 insertions(+), 17 deletions(-)

FWIW:

Series: