Skip to contentSkip to conversation

tcg: Move TCG_GUEST_DEFAULT_MO -> TCGCPUOps::guest_default_memory_order

RFC Superseded Philippe Mathieu-Daudé 4 participants 19 messages Mar 21, 2025 RISC-V

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover tcg: Move TCG_GUEST_DEFAULT_MO -> TCGCPUOps::guest_default_memory_order

Hi,

In this series we replace the TCG_GUEST_DEFAULT_MO definition from "cpu-param.h" by a 'guest_default_memory_order' field in TCGCPUOps.

Since tcg_req_mo() now accesses tcg_ctx, this impact the cpu_req_mo() calls in accel/tcg/{cputlb,user-exec}.c.

The long term goal is to be able to use targets with distinct guest memory order restrictions.

Philippe Mathieu-Daudé (4):
tcg: Always define TCG_GUEST_DEFAULT_MO
tcg: Simplify tcg_req_mo() macro
tcg: Have tcg_req_mo() use runtime TCGContext::guest_mo
tcg: Define guest_default_memory_order in TCGCPUOps

 accel/tcg/internal-target.h   | 13 ++-----------
 include/accel/tcg/cpu-ops.h   |  8 ++++++++
 target/alpha/cpu-param.h      |  3 ---
 target/arm/cpu-param.h        |  3 ---
 target/avr/cpu-param.h        |  2 --
 target/hppa/cpu-param.h       |  8 --------
 target/i386/cpu-param.h       |  3 ---
 target/loongarch/cpu-param.h  |  2 --
 target/microblaze/cpu-param.h |  3 ---
 target/mips/cpu-param.h       |  2 --
 target/openrisc/cpu-param.h   |  2 --
 target/ppc/cpu-param.h        |  2 --
 target/riscv/cpu-param.h      |  2 --
 target/s390x/cpu-param.h      |  6 ------
 target/sparc/cpu-param.h      | 23 -----------------------
 target/xtensa/cpu-param.h     |  3 ---
 accel/tcg/tcg-all.c           |  3 ---
 accel/tcg/translate-all.c     |  6 +-----
 target/alpha/cpu.c            |  3 +++
 target/arm/cpu.c              |  3 +++
 target/arm/tcg/cpu-v7m.c      |  3 +++
 target/avr/cpu.c              |  1 +
 target/hexagon/cpu.c          |  2 ++
 target/hppa/cpu.c             |  8 ++++++++
 target/i386/tcg/tcg-cpu.c     |  5 +++++
 target/loongarch/cpu.c        |  2 ++
 target/m68k/cpu.c             |  3 +++
 target/microblaze/cpu.c       |  3 +++
 target/mips/cpu.c             |  2 ++
 target/openrisc/cpu.c         |  2 ++
 target/ppc/cpu_init.c         |  2 ++
 target/riscv/tcg/tcg-cpu.c    |  2 ++
 target/rx/cpu.c               |  3 +++
 target/s390x/cpu.c            |  6 ++++++
 target/sh4/cpu.c              |  3 +++
 target/sparc/cpu.c            | 23 +++++++++++++++++++++++
 target/tricore/cpu.c          |  2 ++
 target/xtensa/cpu.c           |  3 +++
 38 files changed, 92 insertions(+), 83 deletions(-)
Signature · 1 line
2.47.1
#1 lore raw

PATCH 1/4 tcg: Always define TCG_GUEST_DEFAULT_MO

We only require the TCG_GUEST_DEFAULT_MO for MTTCG-enabled frontends, otherwise we use a default value of TCG_MO_ALL.

In order to simplify, require the definition for all targets, defining it for hexagon, m68k, rx, sh4 and tricore.

---
 target/hexagon/cpu-param.h | 3 +++
 target/m68k/cpu-param.h    | 3 +++
 target/rx/cpu-param.h      | 3 +++
 target/sh4/cpu-param.h     | 3 +++
 target/tricore/cpu-param.h | 3 +++
 accel/tcg/translate-all.c  | 4 ----
 6 files changed, 15 insertions(+), 4 deletions(-)
target/hexagon/cpu-param.h +3 -0
index 45ee7b46409..2d57ea6caf9 100644
@@ -23,4 +23,7 @@
 #define TARGET_PHYS_ADDR_SPACE_BITS 36
 #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
+/* MTTCG not yet supported: require strict ordering */
+#define TCG_GUEST_DEFAULT_MO        TCG_MO_ALL
+
 #endif
target/m68k/cpu-param.h +3 -0
index 7afbf6d302d..1a909eaa13e 100644
@@ -17,4 +17,7 @@
 #define TARGET_PHYS_ADDR_SPACE_BITS 32
 #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
+/* MTTCG not yet supported: require strict ordering */
+#define TCG_GUEST_DEFAULT_MO        TCG_MO_ALL
+
 #endif
target/rx/cpu-param.h +3 -0
index ef1970a09e9..2ce199164d7 100644
@@ -24,4 +24,7 @@
 #define TARGET_PHYS_ADDR_SPACE_BITS 32
 #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
+/* MTTCG not yet supported: require strict ordering */
+#define TCG_GUEST_DEFAULT_MO        TCG_MO_ALL
+
 #endif
target/sh4/cpu-param.h +3 -0
index 2b6e11dd0ac..1bc90d4695e 100644
@@ -16,4 +16,7 @@
 # define TARGET_VIRT_ADDR_SPACE_BITS 32
 #endif
 
+/* MTTCG not yet supported: require strict ordering */
+#define TCG_GUEST_DEFAULT_MO        TCG_MO_ALL
+
 #endif
target/tricore/cpu-param.h +3 -0
index 790242ef3d2..923459370cc 100644
@@ -12,4 +12,7 @@
 #define TARGET_PHYS_ADDR_SPACE_BITS 32
 #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
+/* MTTCG not yet supported: require strict ordering */
+#define TCG_GUEST_DEFAULT_MO        TCG_MO_ALL
+
 #endif
accel/tcg/translate-all.c +0 -4
index 82bc16bd535..fb9f83dbba3 100644
@@ -349,11 +349,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
     tcg_ctx->tlb_dyn_max_bits = CPU_TLB_DYN_MAX_BITS;
 #endif
     tcg_ctx->insn_start_words = TARGET_INSN_START_WORDS;
-#ifdef TCG_GUEST_DEFAULT_MO
     tcg_ctx->guest_mo = TCG_GUEST_DEFAULT_MO;
-#else
-    tcg_ctx->guest_mo = TCG_MO_ALL;
-#endif
 
  restart_translate:
     trace_translate_block(tb, pc, tb->tc.ptr);
Signature · 1 line
2.47.1
Reviewed-by Anton Johansson on v1 1/4
#2 lore raw

Re: [PATCH-for-10.1 1/4] tcg: Always define TCG_GUEST_DEFAULT_MO

Quoted 7 lines · Philippe Mathieu-Daudé

We only require the TCG_GUEST_DEFAULT_MO for MTTCG-enabled frontends, otherwise we use a default value of TCG_MO_ALL.

In order to simplify, require the definition for all targets, defining it for hexagon, m68k, rx, sh4 and tricore.

Quoted 8 lines
---
 target/hexagon/cpu-param.h | 3 +++
 target/m68k/cpu-param.h    | 3 +++
 target/rx/cpu-param.h      | 3 +++
 target/sh4/cpu-param.h     | 3 +++
 target/tricore/cpu-param.h | 3 +++
 accel/tcg/translate-all.c  | 4 ----
 6 files changed, 15 insertions(+), 4 deletions(-)
Reviewed-by on v1 1/4
#3 lore raw

Re: [PATCH-for-10.1 1/4] tcg: Always define TCG_GUEST_DEFAULT_MO

In reply to Philippe Mathieu-Daudé
Quoted 7 lines · Philippe Mathieu-Daudé

We only require the TCG_GUEST_DEFAULT_MO for MTTCG-enabled frontends, otherwise we use a default value of TCG_MO_ALL.

In order to simplify, require the definition for all targets, defining it for hexagon, m68k, rx, sh4 and tricore.

Quoted 8 lines
---
  target/hexagon/cpu-param.h | 3 +++
  target/m68k/cpu-param.h    | 3 +++
  target/rx/cpu-param.h      | 3 +++
  target/sh4/cpu-param.h     | 3 +++
  target/tricore/cpu-param.h | 3 +++
  accel/tcg/translate-all.c  | 4 ----
  6 files changed, 15 insertions(+), 4 deletions(-)

r~

Reviewed-by on v1 1/4
#4 lore raw

Re: [PATCH-for-10.1 1/4] tcg: Always define TCG_GUEST_DEFAULT_MO

In reply to Philippe Mathieu-Daudé
Quoted 82 lines · Philippe Mathieu-Daudé

We only require the TCG_GUEST_DEFAULT_MO for MTTCG-enabled frontends, otherwise we use a default value of TCG_MO_ALL.

In order to simplify, require the definition for all targets, defining it for hexagon, m68k, rx, sh4 and tricore.

---
  target/hexagon/cpu-param.h | 3 +++
  target/m68k/cpu-param.h    | 3 +++
  target/rx/cpu-param.h      | 3 +++
  target/sh4/cpu-param.h     | 3 +++
  target/tricore/cpu-param.h | 3 +++
  accel/tcg/translate-all.c  | 4 ----
  6 files changed, 15 insertions(+), 4 deletions(-)
target/hexagon/cpu-param.h +3 -0
index 45ee7b46409..2d57ea6caf9 100644
@@ -23,4 +23,7 @@
  #define TARGET_PHYS_ADDR_SPACE_BITS 36
  #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
+/* MTTCG not yet supported: require strict ordering */
+#define TCG_GUEST_DEFAULT_MO        TCG_MO_ALL
+
  #endif
target/m68k/cpu-param.h +3 -0
index 7afbf6d302d..1a909eaa13e 100644
@@ -17,4 +17,7 @@
  #define TARGET_PHYS_ADDR_SPACE_BITS 32
  #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
+/* MTTCG not yet supported: require strict ordering */
+#define TCG_GUEST_DEFAULT_MO        TCG_MO_ALL
+
  #endif
target/rx/cpu-param.h +3 -0
index ef1970a09e9..2ce199164d7 100644
@@ -24,4 +24,7 @@
  #define TARGET_PHYS_ADDR_SPACE_BITS 32
  #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
+/* MTTCG not yet supported: require strict ordering */
+#define TCG_GUEST_DEFAULT_MO        TCG_MO_ALL
+
  #endif
target/sh4/cpu-param.h +3 -0
index 2b6e11dd0ac..1bc90d4695e 100644
@@ -16,4 +16,7 @@
  # define TARGET_VIRT_ADDR_SPACE_BITS 32
  #endif
 
+/* MTTCG not yet supported: require strict ordering */
+#define TCG_GUEST_DEFAULT_MO        TCG_MO_ALL
+
  #endif
target/tricore/cpu-param.h +3 -0
index 790242ef3d2..923459370cc 100644
@@ -12,4 +12,7 @@
  #define TARGET_PHYS_ADDR_SPACE_BITS 32
  #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
+/* MTTCG not yet supported: require strict ordering */
+#define TCG_GUEST_DEFAULT_MO        TCG_MO_ALL
+
  #endif
accel/tcg/translate-all.c +0 -0
index 82bc16bd535..fb9f83dbba3 100644
@@ -349,11 +349,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
      tcg_ctx->tlb_dyn_max_bits = CPU_TLB_DYN_MAX_BITS;

accel/tcg/translate-all.c TranslationBlock *tb_gen_code(CPUState *cpu, · line 355

Quoted 10 lines
accel/tcg/translate-all.c +0 -4
  #endif
      tcg_ctx->insn_start_words = TARGET_INSN_START_WORDS;
-#ifdef TCG_GUEST_DEFAULT_MO
      tcg_ctx->guest_mo = TCG_GUEST_DEFAULT_MO;
-#else
-    tcg_ctx->guest_mo = TCG_MO_ALL;
-#endif
 
   restart_translate:
      trace_translate_block(tb, pc, tb->tc.ptr);
#5 lore raw

PATCH 2/4 tcg: Simplify tcg_req_mo() macro

In reply to Philippe Mathieu-Daudé

Now that TCG_GUEST_DEFAULT_MO is always defined,
simplify the tcg_req_mo() macro.

---
 accel/tcg/internal-target.h | 9 +--------
 accel/tcg/tcg-all.c         | 3 ---
 2 files changed, 1 insertion(+), 11 deletions(-)
accel/tcg/internal-target.h +1 -8
index 2cdf11c905e..1cb35dba99e 100644
@@ -50,17 +50,10 @@ G_NORETURN void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr);
  * memory ordering vs the host memory ordering.  A non-zero
  * result indicates that some barrier is required.
  *
- * If TCG_GUEST_DEFAULT_MO is not defined, assume that the
- * guest requires strict ordering.
- *
  * This is a macro so that it's constant even without optimization.
  */
-#ifdef TCG_GUEST_DEFAULT_MO
-# define tcg_req_mo(type) \
+#define tcg_req_mo(type) \
     ((type) & TCG_GUEST_DEFAULT_MO & ~TCG_TARGET_DEFAULT_MO)
-#else
-# define tcg_req_mo(type) ((type) & ~TCG_TARGET_DEFAULT_MO)
-#endif
 
 /**
  * cpu_req_mo:
accel/tcg/tcg-all.c +0 -3
index c1a30b01219..cb632cc8cc7 100644
@@ -77,9 +77,6 @@ static bool default_mttcg_enabled(void)
         return false;
     }
 #ifdef TARGET_SUPPORTS_MTTCG
-# ifndef TCG_GUEST_DEFAULT_MO
-#  error "TARGET_SUPPORTS_MTTCG without TCG_GUEST_DEFAULT_MO"
-# endif
     return true;
 #else
     return false;
Signature · 1 line
2.47.1
Reviewed-by Anton Johansson on v1 2/4
#6 lore raw

Re: [PATCH-for-10.1 2/4] tcg: Simplify tcg_req_mo() macro

Quoted 49 lines · Philippe Mathieu-Daudé

Now that TCG_GUEST_DEFAULT_MO is always defined,
simplify the tcg_req_mo() macro.

---
 accel/tcg/internal-target.h | 9 +--------
 accel/tcg/tcg-all.c         | 3 ---
 2 files changed, 1 insertion(+), 11 deletions(-)
accel/tcg/internal-target.h +1 -8
index 2cdf11c905e..1cb35dba99e 100644
@@ -50,17 +50,10 @@ G_NORETURN void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr);
  * memory ordering vs the host memory ordering.  A non-zero
  * result indicates that some barrier is required.
  *
- * If TCG_GUEST_DEFAULT_MO is not defined, assume that the
- * guest requires strict ordering.
- *
  * This is a macro so that it's constant even without optimization.
  */
-#ifdef TCG_GUEST_DEFAULT_MO
-# define tcg_req_mo(type) \
+#define tcg_req_mo(type) \
     ((type) & TCG_GUEST_DEFAULT_MO & ~TCG_TARGET_DEFAULT_MO)
-#else
-# define tcg_req_mo(type) ((type) & ~TCG_TARGET_DEFAULT_MO)
-#endif
 
 /**
  * cpu_req_mo:
accel/tcg/tcg-all.c +0 -3
index c1a30b01219..cb632cc8cc7 100644
@@ -77,9 +77,6 @@ static bool default_mttcg_enabled(void)
         return false;
     }
 #ifdef TARGET_SUPPORTS_MTTCG
-# ifndef TCG_GUEST_DEFAULT_MO
-#  error "TARGET_SUPPORTS_MTTCG without TCG_GUEST_DEFAULT_MO"
-# endif
     return true;
 #else
     return false;
Signature · 1 line
2.47.1
Reviewed-by on v1 2/4
#7 lore raw

Re: [PATCH-for-10.1 2/4] tcg: Simplify tcg_req_mo() macro

In reply to Philippe Mathieu-Daudé
Quoted 8 lines · Philippe Mathieu-Daudé

Now that TCG_GUEST_DEFAULT_MO is always defined,
simplify the tcg_req_mo() macro.

---
  accel/tcg/internal-target.h | 9 +--------
  accel/tcg/tcg-all.c         | 3 ---
  2 files changed, 1 insertion(+), 11 deletions(-)

r~

Reviewed-by on v1 2/4
#8 lore raw

Re: [PATCH-for-10.1 2/4] tcg: Simplify tcg_req_mo() macro

In reply to Philippe Mathieu-Daudé
Quoted 37 lines · Philippe Mathieu-Daudé

Now that TCG_GUEST_DEFAULT_MO is always defined,
simplify the tcg_req_mo() macro.

---
  accel/tcg/internal-target.h | 9 +--------
  accel/tcg/tcg-all.c         | 3 ---
  2 files changed, 1 insertion(+), 11 deletions(-)
accel/tcg/internal-target.h +1 -8
index 2cdf11c905e..1cb35dba99e 100644
@@ -50,17 +50,10 @@ G_NORETURN void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr);
   * memory ordering vs the host memory ordering.  A non-zero
   * result indicates that some barrier is required.
   *
- * If TCG_GUEST_DEFAULT_MO is not defined, assume that the
- * guest requires strict ordering.
- *
   * This is a macro so that it's constant even without optimization.
   */
-#ifdef TCG_GUEST_DEFAULT_MO
-# define tcg_req_mo(type) \
+#define tcg_req_mo(type) \
      ((type) & TCG_GUEST_DEFAULT_MO & ~TCG_TARGET_DEFAULT_MO)
-#else
-# define tcg_req_mo(type) ((type) & ~TCG_TARGET_DEFAULT_MO)
-#endif
 
  /**
   * cpu_req_mo:
accel/tcg/tcg-all.c +0 -0
index c1a30b01219..cb632cc8cc7 100644

accel/tcg/tcg-all.c static bool default_mttcg_enabled(void) · line 82

Quoted 9 lines
accel/tcg/tcg-all.c +0 -3
@@ -77,9 +77,6 @@ static bool default_mttcg_enabled(void)
          return false;
      }
  #ifdef TARGET_SUPPORTS_MTTCG
-# ifndef TCG_GUEST_DEFAULT_MO
-#  error "TARGET_SUPPORTS_MTTCG without TCG_GUEST_DEFAULT_MO"
-# endif
      return true;
  #else
      return false;
#9 lore raw

RFC 3/4 tcg: Have tcg_req_mo() use runtime TCGContext::guest_mo

In reply to Philippe Mathieu-Daudé

In order to use TCG with multiple targets, replace the compile time use of TCG_GUEST_DEFAULT_MO by a runtime access to tcg_ctx->guest_mo.

---
 accel/tcg/internal-target.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
accel/tcg/internal-target.h +1 -3
index 1cb35dba99e..014ee756f9d 100644
@@ -49,11 +49,9 @@ G_NORETURN void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr);
  * Filter @type to the barrier that is required for the guest
  * memory ordering vs the host memory ordering.  A non-zero
  * result indicates that some barrier is required.
- *
- * This is a macro so that it's constant even without optimization.
  */
 #define tcg_req_mo(type) \
-    ((type) & TCG_GUEST_DEFAULT_MO & ~TCG_TARGET_DEFAULT_MO)
+    ((type) & tcg_ctx->guest_mo & ~TCG_TARGET_DEFAULT_MO)
 
 /**
  * cpu_req_mo:
Signature · 1 line
2.47.1
#10 lore raw

Re: [RFC PATCH-for-10.1 3/4] tcg: Have tcg_req_mo() use runtime TCGContext::guest_mo

Quoted 29 lines · Philippe Mathieu-Daudé

In order to use TCG with multiple targets, replace the compile time use of TCG_GUEST_DEFAULT_MO by a runtime access to tcg_ctx->guest_mo.

---
 accel/tcg/internal-target.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
accel/tcg/internal-target.h +1 -3
index 1cb35dba99e..014ee756f9d 100644
@@ -49,11 +49,9 @@ G_NORETURN void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr);
  * Filter @type to the barrier that is required for the guest
  * memory ordering vs the host memory ordering.  A non-zero
  * result indicates that some barrier is required.
- *
- * This is a macro so that it's constant even without optimization.
  */
 #define tcg_req_mo(type) \
-    ((type) & TCG_GUEST_DEFAULT_MO & ~TCG_TARGET_DEFAULT_MO)
+    ((type) & tcg_ctx->guest_mo & ~TCG_TARGET_DEFAULT_MO)
 
 /**
  * cpu_req_mo:
Signature · 1 line
2.47.1

I'll parrot some older feedback by Richard

https://lore.kernel.org/all/[email protected]/

but tcg_ctx->guest_mo can be undefined or bogus here. Could we not take cpu and access cpu->cc->tcg_ops->guest_default_memory_order directly instead?

#11 lore raw

Re: [RFC PATCH-for-10.1 3/4] tcg: Have tcg_req_mo() use runtime TCGContext::guest_mo

Quoted 33 lines · Anton Johansson
Quoted 29 lines · Philippe Mathieu-Daudé

In order to use TCG with multiple targets, replace the compile time use of TCG_GUEST_DEFAULT_MO by a runtime access to tcg_ctx->guest_mo.

---
  accel/tcg/internal-target.h | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
accel/tcg/internal-target.h +1 -3
index 1cb35dba99e..014ee756f9d 100644
@@ -49,11 +49,9 @@ G_NORETURN void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr);
   * Filter @type to the barrier that is required for the guest
   * memory ordering vs the host memory ordering.  A non-zero
   * result indicates that some barrier is required.
- *
- * This is a macro so that it's constant even without optimization.
   */
  #define tcg_req_mo(type) \
-    ((type) & TCG_GUEST_DEFAULT_MO & ~TCG_TARGET_DEFAULT_MO)
+    ((type) & tcg_ctx->guest_mo & ~TCG_TARGET_DEFAULT_MO)
 
  /**
   * cpu_req_mo:
Signature · 1 line
2.47.1

I'll parrot some older feedback by Richard

Quoted 5 lines
   https://lore.kernel.org/all/[email protected]/

but tcg_ctx->guest_mo can be undefined or bogus here. Could we not take cpu and access cpu->cc->tcg_ops->guest_default_memory_order directly instead?

Yes, cpu_req_mo() has access to @cpu.

#12 lore raw

Re: [RFC PATCH-for-10.1 3/4] tcg: Have tcg_req_mo() use runtime TCGContext::guest_mo

In reply to Philippe Mathieu-Daudé
Quoted 14 lines · Philippe Mathieu-Daudé

In order to use TCG with multiple targets, replace the compile time use of TCG_GUEST_DEFAULT_MO by a runtime access to tcg_ctx->guest_mo.

---
  accel/tcg/internal-target.h | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
accel/tcg/internal-target.h +0 -0
index 1cb35dba99e..014ee756f9d 100644

accel/tcg/internal-target.h G_NORETURN void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr); · line 54

Quoted 9 lines
accel/tcg/internal-target.h +1 -3
@@ -49,11 +49,9 @@ G_NORETURN void cpu_io_recompile(CPUState *cpu, uintptr_t retaddr);
   * Filter @type to the barrier that is required for the guest
   * memory ordering vs the host memory ordering.  A non-zero
   * result indicates that some barrier is required.
- *
- * This is a macro so that it's constant even without optimization.
   */
  #define tcg_req_mo(type) \
-    ((type) & TCG_GUEST_DEFAULT_MO & ~TCG_TARGET_DEFAULT_MO)
+    ((type) & tcg_ctx->guest_mo & ~TCG_TARGET_DEFAULT_MO)

Incorrect. The setting in tcg_ctx is only valid during compilation.

This macro is used during execution, in cpu_req_mo(), from the cpu memory access routines.

r~

#13 lore raw

RFC 4/4 tcg: Define guest_default_memory_order in TCGCPUOps

In reply to Philippe Mathieu-Daudé

Add the TCGCPUOps::guest_default_memory_order field and have each target initialize it.

Use it to set TCGContext::guest_mo in tb_gen_code(), removing the need for the TCG_GUEST_DEFAULT_MO definition.

---
 include/accel/tcg/cpu-ops.h   |  8 ++++++++
 target/alpha/cpu-param.h      |  3 ---
 target/arm/cpu-param.h        |  3 ---
 target/avr/cpu-param.h        |  2 --
 target/hexagon/cpu-param.h    |  3 ---
 target/hppa/cpu-param.h       |  8 --------
 target/i386/cpu-param.h       |  3 ---
 target/loongarch/cpu-param.h  |  2 --
 target/m68k/cpu-param.h       |  3 ---
 target/microblaze/cpu-param.h |  3 ---
 target/mips/cpu-param.h       |  2 --
 target/openrisc/cpu-param.h   |  2 --
 target/ppc/cpu-param.h        |  2 --
 target/riscv/cpu-param.h      |  2 --
 target/rx/cpu-param.h         |  3 ---
 target/s390x/cpu-param.h      |  6 ------
 target/sh4/cpu-param.h        |  3 ---
 target/sparc/cpu-param.h      | 23 -----------------------
 target/tricore/cpu-param.h    |  3 ---
 target/xtensa/cpu-param.h     |  3 ---
 accel/tcg/translate-all.c     |  2 +-
 target/alpha/cpu.c            |  3 +++
 target/arm/cpu.c              |  3 +++
 target/arm/tcg/cpu-v7m.c      |  3 +++
 target/avr/cpu.c              |  1 +
 target/hexagon/cpu.c          |  2 ++
 target/hppa/cpu.c             |  8 ++++++++
 target/i386/tcg/tcg-cpu.c     |  5 +++++
 target/loongarch/cpu.c        |  2 ++
 target/m68k/cpu.c             |  3 +++
 target/microblaze/cpu.c       |  3 +++
 target/mips/cpu.c             |  2 ++
 target/openrisc/cpu.c         |  2 ++
 target/ppc/cpu_init.c         |  2 ++
 target/riscv/tcg/tcg-cpu.c    |  2 ++
 target/rx/cpu.c               |  3 +++
 target/s390x/cpu.c            |  6 ++++++
 target/sh4/cpu.c              |  3 +++
 target/sparc/cpu.c            | 23 +++++++++++++++++++++++
 target/tricore/cpu.c          |  2 ++
 target/xtensa/cpu.c           |  3 +++
 41 files changed, 90 insertions(+), 80 deletions(-)
include/accel/tcg/cpu-ops.h +8 -0
index f60e5303f21..5fd299cefb6 100644
@@ -16,8 +16,16 @@
 #include "exec/memop.h"
 #include "exec/mmu-access-type.h"
 #include "exec/vaddr.h"
+#include "tcg/tcg-mo.h"
 
 struct TCGCPUOps {
+
+    /**
+     * @guest_default_memory_order: default barrier that is required
+     *                              for the guest memory ordering.
+     */
+    TCGBar guest_default_memory_order;
+
     /**
      * @initialize: Initialize TCG state
      *
target/alpha/cpu-param.h +0 -3
index ff06e41497a..c74556d2667 100644
@@ -25,7 +25,4 @@
 # define TARGET_VIRT_ADDR_SPACE_BITS  (30 + TARGET_PAGE_BITS)
 #endif
 
-/* Alpha processors have a weak memory model */
-#define TCG_GUEST_DEFAULT_MO      (0)
-
 #endif
target/arm/cpu-param.h +0 -3
index 896b35bd6d5..55de4d54544 100644
@@ -38,7 +38,4 @@
 # define TARGET_PAGE_BITS_MIN  10
 #endif /* !CONFIG_USER_ONLY */
 
-/* ARM processors have a weak memory model */
-#define TCG_GUEST_DEFAULT_MO      (0)
-
 #endif
target/avr/cpu-param.h +0 -2
index 81f3f49ee1f..11e827109c0 100644
@@ -31,6 +31,4 @@
 #define TARGET_PHYS_ADDR_SPACE_BITS 24
 #define TARGET_VIRT_ADDR_SPACE_BITS 24
 
-#define TCG_GUEST_DEFAULT_MO 0
-
 #endif
target/hexagon/cpu-param.h +0 -3
index 2d57ea6caf9..45ee7b46409 100644
@@ -23,7 +23,4 @@
 #define TARGET_PHYS_ADDR_SPACE_BITS 36
 #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
-/* MTTCG not yet supported: require strict ordering */
-#define TCG_GUEST_DEFAULT_MO        TCG_MO_ALL
-
 #endif
target/hppa/cpu-param.h +0 -8
index 7ed6b5741e7..e0b2c7c9157 100644
@@ -19,12 +19,4 @@
 
 #define TARGET_PAGE_BITS 12
 
-/* PA-RISC 1.x processors have a strong memory model.  */
-/*
- * ??? While we do not yet implement PA-RISC 2.0, those processors have
- * a weak memory model, but with TLB bits that force ordering on a per-page
- * basis.  It's probably easier to fall back to a strong memory model.
- */
-#define TCG_GUEST_DEFAULT_MO        TCG_MO_ALL
-
 #endif
target/i386/cpu-param.h +0 -3
index b0e884c5d70..909bc027923 100644
@@ -22,7 +22,4 @@
 #endif
 #define TARGET_PAGE_BITS 12
 
-/* The x86 has a strong memory model with some store-after-load re-ordering */
-#define TCG_GUEST_DEFAULT_MO      (TCG_MO_ALL & ~TCG_MO_ST_LD)
-
 #endif
target/loongarch/cpu-param.h +0 -2
index 52437946e56..071567712b3 100644
@@ -13,6 +13,4 @@
 
 #define TARGET_PAGE_BITS 12
 
-#define TCG_GUEST_DEFAULT_MO (0)
-
 #endif
target/m68k/cpu-param.h +0 -3
index 1a909eaa13e..7afbf6d302d 100644
@@ -17,7 +17,4 @@
 #define TARGET_PHYS_ADDR_SPACE_BITS 32
 #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
-/* MTTCG not yet supported: require strict ordering */
-#define TCG_GUEST_DEFAULT_MO        TCG_MO_ALL
-
 #endif
target/microblaze/cpu-param.h +0 -3
index c866ec6c149..6a0714bb3d7 100644
@@ -27,7 +27,4 @@
 /* FIXME: MB uses variable pages down to 1K but linux only uses 4k.  */
 #define TARGET_PAGE_BITS 12
 
-/* MicroBlaze is always in-order. */
-#define TCG_GUEST_DEFAULT_MO  TCG_MO_ALL
-
 #endif
target/mips/cpu-param.h +0 -2
index 11b3ac0ac63..35fb6ea7243 100644
@@ -25,6 +25,4 @@
 #define TARGET_PAGE_BITS_MIN 12
 #endif
 
-#define TCG_GUEST_DEFAULT_MO (0)
-
 #endif
target/openrisc/cpu-param.h +0 -2
index 37627f2c394..3011bf5fcca 100644
@@ -12,6 +12,4 @@
 #define TARGET_PHYS_ADDR_SPACE_BITS 32
 #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
-#define TCG_GUEST_DEFAULT_MO (0)
-
 #endif
target/ppc/cpu-param.h +0 -2
index 6c4525fdf3c..2cee113ddd3 100644
@@ -38,6 +38,4 @@
 # define TARGET_PAGE_BITS 12
 #endif
 
-#define TCG_GUEST_DEFAULT_MO 0
-
 #endif
target/riscv/cpu-param.h +0 -2
index fba30e966a8..a80310ef2c5 100644
@@ -26,6 +26,4 @@
  *  - M mode HLV/HLVX/HSV 0b111
  */
 
-#define TCG_GUEST_DEFAULT_MO 0
-
 #endif
target/rx/cpu-param.h +0 -3
index 2ce199164d7..ef1970a09e9 100644
@@ -24,7 +24,4 @@
 #define TARGET_PHYS_ADDR_SPACE_BITS 32
 #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
-/* MTTCG not yet supported: require strict ordering */
-#define TCG_GUEST_DEFAULT_MO        TCG_MO_ALL
-
 #endif
target/s390x/cpu-param.h +0 -6
index 5c331ec424c..a5f798eeae7 100644
@@ -12,10 +12,4 @@
 #define TARGET_PHYS_ADDR_SPACE_BITS 64
 #define TARGET_VIRT_ADDR_SPACE_BITS 64
 
-/*
- * The z/Architecture has a strong memory model with some
- * store-after-load re-ordering.
- */
-#define TCG_GUEST_DEFAULT_MO      (TCG_MO_ALL & ~TCG_MO_ST_LD)
-
 #endif
target/sh4/cpu-param.h +0 -3
index 1bc90d4695e..2b6e11dd0ac 100644
@@ -16,7 +16,4 @@
 # define TARGET_VIRT_ADDR_SPACE_BITS 32
 #endif
 
-/* MTTCG not yet supported: require strict ordering */
-#define TCG_GUEST_DEFAULT_MO        TCG_MO_ALL
-
 #endif
target/sparc/cpu-param.h +0 -23
index 6952ee2b826..6e8e2a51469 100644
@@ -21,27 +21,4 @@
 # define TARGET_VIRT_ADDR_SPACE_BITS 32
 #endif
 
-/*
- * From Oracle SPARC Architecture 2015:
- *
- *   Compatibility notes: The PSO memory model described in SPARC V8 and
- *   SPARC V9 compatibility architecture specifications was never implemented
- *   in a SPARC V9 implementation and is not included in the Oracle SPARC
- *   Architecture specification.
- *
- *   The RMO memory model described in the SPARC V9 specification was
- *   implemented in some non-Sun SPARC V9 implementations, but is not
- *   directly supported in Oracle SPARC Architecture 2015 implementations.
- *
- * Therefore always use TSO in QEMU.
- *
- * D.5 Specification of Partial Store Order (PSO)
- *   ... [loads] are followed by an implied MEMBAR #LoadLoad | #LoadStore.
- *
- * D.6 Specification of Total Store Order (TSO)
- *   ... PSO with the additional requirement that all [stores] are followed
- *   by an implied MEMBAR #StoreStore.
- */
-#define TCG_GUEST_DEFAULT_MO  (TCG_MO_LD_LD | TCG_MO_LD_ST | TCG_MO_ST_ST)
-
 #endif
target/tricore/cpu-param.h +0 -3
index 923459370cc..790242ef3d2 100644
@@ -12,7 +12,4 @@
 #define TARGET_PHYS_ADDR_SPACE_BITS 32
 #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
-/* MTTCG not yet supported: require strict ordering */
-#define TCG_GUEST_DEFAULT_MO        TCG_MO_ALL
-
 #endif
target/xtensa/cpu-param.h +0 -3
index 5e4848ad059..06d85218b84 100644
@@ -16,7 +16,4 @@
 #define TARGET_VIRT_ADDR_SPACE_BITS 32
 #endif
 
-/* Xtensa processors have a weak memory model */
-#define TCG_GUEST_DEFAULT_MO      (0)
-
 #endif
accel/tcg/translate-all.c +1 -1
index fb9f83dbba3..26442e83776 100644
@@ -349,7 +349,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
     tcg_ctx->tlb_dyn_max_bits = CPU_TLB_DYN_MAX_BITS;
 #endif
     tcg_ctx->insn_start_words = TARGET_INSN_START_WORDS;
-    tcg_ctx->guest_mo = TCG_GUEST_DEFAULT_MO;
+    tcg_ctx->guest_mo = cpu->cc->tcg_ops->guest_default_memory_order;
 
  restart_translate:
     trace_translate_block(tb, pc, tb->tc.ptr);
target/alpha/cpu.c +3 -0
index 584c2aa76bd..e5e14976f51 100644
@@ -239,6 +239,9 @@ static const TCGCPUOps alpha_tcg_ops = {
     .synchronize_from_tb = alpha_cpu_synchronize_from_tb,
     .restore_state_to_opc = alpha_restore_state_to_opc,
 
+    /* Alpha processors have a weak memory model */
+    .guest_default_memory_order = 0,
+
 #ifdef CONFIG_USER_ONLY
     .record_sigsegv = alpha_cpu_record_sigsegv,
     .record_sigbus = alpha_cpu_record_sigbus,
target/arm/cpu.c +3 -0
index 01786ac7879..8b9f2acf82b 100644
@@ -2675,6 +2675,9 @@ static const TCGCPUOps arm_tcg_ops = {
     .debug_excp_handler = arm_debug_excp_handler,
     .restore_state_to_opc = arm_restore_state_to_opc,
 
+    /* ARM processors have a weak memory model */
+    .guest_default_memory_order = 0,
+
 #ifdef CONFIG_USER_ONLY
     .record_sigsegv = arm_cpu_record_sigsegv,
     .record_sigbus = arm_cpu_record_sigbus,
target/arm/tcg/cpu-v7m.c +3 -0
index c4dd3092726..df6b7198944 100644
@@ -238,6 +238,9 @@ static const TCGCPUOps arm_v7m_tcg_ops = {
     .debug_excp_handler = arm_debug_excp_handler,
     .restore_state_to_opc = arm_restore_state_to_opc,
 
+    /* ARM processors have a weak memory model */
+    .guest_default_memory_order = 0,
+
 #ifdef CONFIG_USER_ONLY
     .record_sigsegv = arm_cpu_record_sigsegv,
     .record_sigbus = arm_cpu_record_sigbus,
target/avr/cpu.c +1 -0
index 834c7082aa7..24e52e28f44 100644
@@ -216,6 +216,7 @@ static const TCGCPUOps avr_tcg_ops = {
     .cpu_exec_halt = avr_cpu_has_work,
     .tlb_fill = avr_cpu_tlb_fill,
     .do_interrupt = avr_cpu_do_interrupt,
+    .guest_default_memory_order = 0,
 };
 
 static void avr_cpu_class_init(ObjectClass *oc, void *data)
target/hexagon/cpu.c +2 -0
index 766b6786511..34734b0edb0 100644
@@ -324,6 +324,8 @@ static const TCGCPUOps hexagon_tcg_ops = {
     .translate_code = hexagon_translate_code,
     .synchronize_from_tb = hexagon_cpu_synchronize_from_tb,
     .restore_state_to_opc = hexagon_restore_state_to_opc,
+    /* MTTCG not yet supported: require strict ordering */
+    .guest_default_memory_order = TCG_MO_ALL,
 };
 
 static void hexagon_cpu_class_init(ObjectClass *c, void *data)
target/hppa/cpu.c +8 -0
index 2a85495d02f..997bd69db19 100644
@@ -257,6 +257,14 @@ static const TCGCPUOps hppa_tcg_ops = {
     .synchronize_from_tb = hppa_cpu_synchronize_from_tb,
     .restore_state_to_opc = hppa_restore_state_to_opc,
 
+    /* PA-RISC 1.x processors have a strong memory model.  */
+    /*
+     * ??? While we do not yet implement PA-RISC 2.0, those processors have
+     * a weak memory model, but with TLB bits that force ordering on a per-page
+     * basis.  It's probably easier to fall back to a strong memory model.
+     */
+    .guest_default_memory_order = TCG_MO_ALL,
+
 #ifndef CONFIG_USER_ONLY
     .tlb_fill_align = hppa_cpu_tlb_fill_align,
     .cpu_exec_interrupt = hppa_cpu_exec_interrupt,
target/i386/tcg/tcg-cpu.c +5 -0
index b8aff825eec..4a76c475971 100644
@@ -128,6 +128,11 @@ static const TCGCPUOps x86_tcg_ops = {
     .debug_check_breakpoint = x86_debug_check_breakpoint,
     .need_replay_interrupt = x86_need_replay_interrupt,
 #endif /* !CONFIG_USER_ONLY */
+
+    /*
+     * The x86 has a strong memory model with some store-after-load re-ordering
+     */
+    .guest_default_memory_order = TCG_MO_ALL & ~TCG_MO_ST_LD,
 };
 
 static void x86_tcg_cpu_init_ops(AccelCPUClass *accel_cpu, CPUClass *cc)
target/loongarch/cpu.c +2 -0
index ea1665e2705..c39ff056157 100644
@@ -869,6 +869,8 @@ static const TCGCPUOps loongarch_tcg_ops = {
     .synchronize_from_tb = loongarch_cpu_synchronize_from_tb,
     .restore_state_to_opc = loongarch_restore_state_to_opc,
 
+    .guest_default_memory_order = 0,
+
 #ifndef CONFIG_USER_ONLY
     .tlb_fill = loongarch_cpu_tlb_fill,
     .cpu_exec_interrupt = loongarch_cpu_exec_interrupt,
target/m68k/cpu.c +3 -0
index 0065e1c1ca5..e96b379e266 100644
@@ -593,6 +593,9 @@ static const TCGCPUOps m68k_tcg_ops = {
     .translate_code = m68k_translate_code,
     .restore_state_to_opc = m68k_restore_state_to_opc,
 
+    /* MTTCG not yet supported: require strict ordering */
+    .guest_default_memory_order = TCG_MO_ALL,
+
 #ifndef CONFIG_USER_ONLY
     .tlb_fill = m68k_cpu_tlb_fill,
     .cpu_exec_interrupt = m68k_cpu_exec_interrupt,
target/microblaze/cpu.c +3 -0
index f3bebea856e..4b9ef6e52c4 100644
@@ -432,6 +432,9 @@ static const TCGCPUOps mb_tcg_ops = {
     .synchronize_from_tb = mb_cpu_synchronize_from_tb,
     .restore_state_to_opc = mb_restore_state_to_opc,
 
+    /* MicroBlaze is always in-order. */
+    .guest_default_memory_order = TCG_MO_ALL,
+
 #ifndef CONFIG_USER_ONLY
     .tlb_fill = mb_cpu_tlb_fill,
     .cpu_exec_interrupt = mb_cpu_exec_interrupt,
target/mips/cpu.c +2 -0
index b207106dd79..5ddc9bbb829 100644
@@ -554,6 +554,8 @@ static const TCGCPUOps mips_tcg_ops = {
     .synchronize_from_tb = mips_cpu_synchronize_from_tb,
     .restore_state_to_opc = mips_restore_state_to_opc,
 
+    .guest_default_memory_order = 0,
+
 #if !defined(CONFIG_USER_ONLY)
     .tlb_fill = mips_cpu_tlb_fill,
     .cpu_exec_interrupt = mips_cpu_exec_interrupt,
target/openrisc/cpu.c +2 -0
index e8abf1f8b5c..6a878aaadd8 100644
@@ -248,6 +248,8 @@ static const TCGCPUOps openrisc_tcg_ops = {
     .synchronize_from_tb = openrisc_cpu_synchronize_from_tb,
     .restore_state_to_opc = openrisc_restore_state_to_opc,
 
+    .guest_default_memory_order = 0,
+
 #ifndef CONFIG_USER_ONLY
     .tlb_fill = openrisc_cpu_tlb_fill,
     .cpu_exec_interrupt = openrisc_cpu_exec_interrupt,
target/ppc/cpu_init.c +2 -0
index 8b590e7f17c..28fbbb8d3c1 100644
@@ -7490,6 +7490,8 @@ static const TCGCPUOps ppc_tcg_ops = {
   .translate_code = ppc_translate_code,
   .restore_state_to_opc = ppc_restore_state_to_opc,
 
+  .guest_default_memory_order = 0,
+
 #ifdef CONFIG_USER_ONLY
   .record_sigsegv = ppc_cpu_record_sigsegv,
 #else
target/riscv/tcg/tcg-cpu.c +2 -0
index 5aef9eef366..fb903992faa 100644
@@ -139,6 +139,8 @@ static const TCGCPUOps riscv_tcg_ops = {
     .synchronize_from_tb = riscv_cpu_synchronize_from_tb,
     .restore_state_to_opc = riscv_restore_state_to_opc,
 
+    .guest_default_memory_order = 0,
+
 #ifndef CONFIG_USER_ONLY
     .tlb_fill = riscv_cpu_tlb_fill,
     .cpu_exec_interrupt = riscv_cpu_exec_interrupt,
target/rx/cpu.c +3 -0
index 0ba0d55ab5b..6a24e7e9136 100644
@@ -212,6 +212,9 @@ static const TCGCPUOps rx_tcg_ops = {
     .cpu_exec_interrupt = rx_cpu_exec_interrupt,
     .cpu_exec_halt = rx_cpu_has_work,
     .do_interrupt = rx_cpu_do_interrupt,
+
+    /* MTTCG not yet supported: require strict ordering */
+    .guest_default_memory_order = TCG_MO_ALL,
 };
 
 static void rx_cpu_class_init(ObjectClass *klass, void *data)
target/s390x/cpu.c +6 -0
index d73142600bf..12fd853c00a 100644
@@ -360,6 +360,12 @@ static const TCGCPUOps s390_tcg_ops = {
     .debug_excp_handler = s390x_cpu_debug_excp_handler,
     .do_unaligned_access = s390x_cpu_do_unaligned_access,
 #endif /* !CONFIG_USER_ONLY */
+
+    /*
+     * The z/Architecture has a strong memory model with some
+     * store-after-load re-ordering.
+     */
+    .guest_default_memory_order = TCG_MO_ALL & ~TCG_MO_ST_LD,
 };
 #endif /* CONFIG_TCG */
 
target/sh4/cpu.c +3 -0
index ce84bdf539a..ce9ed75107a 100644
@@ -267,6 +267,9 @@ static const TCGCPUOps superh_tcg_ops = {
     .synchronize_from_tb = superh_cpu_synchronize_from_tb,
     .restore_state_to_opc = superh_restore_state_to_opc,
 
+    /* MTTCG not yet supported: require strict ordering */
+    .guest_default_memory_order = TCG_MO_ALL,
+
 #ifndef CONFIG_USER_ONLY
     .tlb_fill = superh_cpu_tlb_fill,
     .cpu_exec_interrupt = superh_cpu_exec_interrupt,
target/sparc/cpu.c +23 -0
index 57161201173..39bd0c42855 100644
@@ -1005,6 +1005,29 @@ static const TCGCPUOps sparc_tcg_ops = {
     .synchronize_from_tb = sparc_cpu_synchronize_from_tb,
     .restore_state_to_opc = sparc_restore_state_to_opc,
 
+    /*
+     * From Oracle SPARC Architecture 2015:
+     *
+     *   Compatibility notes: The PSO memory model described in SPARC V8 and
+     *   SPARC V9 compatibility architecture specifications was never
+     *   implemented in a SPARC V9 implementation and is not included in the
+     *   Oracle SPARC Architecture specification.
+     *
+     *   The RMO memory model described in the SPARC V9 specification was
+     *   implemented in some non-Sun SPARC V9 implementations, but is not
+     *   directly supported in Oracle SPARC Architecture 2015 implementations.
+     *
+     * Therefore always use TSO in QEMU.
+     *
+     * D.5 Specification of Partial Store Order (PSO)
+     *   ... [loads] are followed by an implied MEMBAR #LoadLoad | #LoadStore.
+     *
+     * D.6 Specification of Total Store Order (TSO)
+     *   ... PSO with the additional requirement that all [stores] are followed
+     *   by an implied MEMBAR #StoreStore.
+     */
+    .guest_default_memory_order = TCG_MO_LD_LD | TCG_MO_LD_ST | TCG_MO_ST_ST,
+
 #ifndef CONFIG_USER_ONLY
     .tlb_fill = sparc_cpu_tlb_fill,
     .cpu_exec_interrupt = sparc_cpu_exec_interrupt,
target/tricore/cpu.c +2 -0
index 16acc4ecb92..e0a48065948 100644
@@ -179,6 +179,8 @@ static const TCGCPUOps tricore_tcg_ops = {
     .tlb_fill = tricore_cpu_tlb_fill,
     .cpu_exec_interrupt = tricore_cpu_exec_interrupt,
     .cpu_exec_halt = tricore_cpu_has_work,
+    /* MTTCG not yet supported: require strict ordering */
+    .guest_default_memory_order = TCG_MO_ALL,
 };
 
 static void tricore_cpu_class_init(ObjectClass *c, void *data)
target/xtensa/cpu.c +3 -0
index 7663b62d01e..dd9061ba469 100644
@@ -237,6 +237,9 @@ static const TCGCPUOps xtensa_tcg_ops = {
     .debug_excp_handler = xtensa_breakpoint_handler,
     .restore_state_to_opc = xtensa_restore_state_to_opc,
 
+    /* Xtensa processors have a weak memory model */
+    .guest_default_memory_order = 0,
+
 #ifndef CONFIG_USER_ONLY
     .tlb_fill = xtensa_cpu_tlb_fill,
     .cpu_exec_interrupt = xtensa_cpu_exec_interrupt,
Signature · 1 line
2.47.1
#14 lore raw

Re: [RFC PATCH-for-10.1 4/4] tcg: Define guest_default_memory_order in TCGCPUOps

Quoted 42 lines · Philippe Mathieu-Daudé

Add the TCGCPUOps::guest_default_memory_order field and have each target initialize it.

Use it to set TCGContext::guest_mo in tb_gen_code(), removing the need for the TCG_GUEST_DEFAULT_MO definition.

---
  include/accel/tcg/cpu-ops.h   |  8 ++++++++
  target/alpha/cpu-param.h      |  3 ---
  target/arm/cpu-param.h        |  3 ---
  target/avr/cpu-param.h        |  2 --
  target/hexagon/cpu-param.h    |  3 ---
  target/hppa/cpu-param.h       |  8 --------
  target/i386/cpu-param.h       |  3 ---
  target/loongarch/cpu-param.h  |  2 --
  target/m68k/cpu-param.h       |  3 ---
  target/microblaze/cpu-param.h |  3 ---
  target/mips/cpu-param.h       |  2 --
  target/openrisc/cpu-param.h   |  2 --
  target/ppc/cpu-param.h        |  2 --
  target/riscv/cpu-param.h      |  2 --
  target/rx/cpu-param.h         |  3 ---
  target/s390x/cpu-param.h      |  6 ------
  target/sh4/cpu-param.h        |  3 ---
  target/sparc/cpu-param.h      | 23 -----------------------
  target/tricore/cpu-param.h    |  3 ---
  target/xtensa/cpu-param.h     |  3 ---
  accel/tcg/translate-all.c     |  2 +-
  target/alpha/cpu.c            |  3 +++
  target/arm/cpu.c              |  3 +++
  target/arm/tcg/cpu-v7m.c      |  3 +++
  target/avr/cpu.c              |  1 +
  target/hexagon/cpu.c          |  2 ++
  target/hppa/cpu.c             |  8 ++++++++
  target/i386/tcg/tcg-cpu.c     |  5 +++++
  target/loongarch/cpu.c        |  2 ++
  target/m68k/cpu.c             |  3 +++
  target/microblaze/cpu.c       |  3 +++
  target/mips/cpu.c             |  2 ++
  target/openrisc/cpu.c         |  2 ++
  target/ppc/cpu_init.c         |  2 ++
Quoted 8 lines
  target/riscv/tcg/tcg-cpu.c    |  2 ++
  target/rx/cpu.c               |  3 +++
  target/s390x/cpu.c            |  6 ++++++
  target/sh4/cpu.c              |  3 +++
  target/sparc/cpu.c            | 23 +++++++++++++++++++++++
  target/tricore/cpu.c          |  2 ++
  target/xtensa/cpu.c           |  3 +++
  41 files changed, 90 insertions(+), 80 deletions(-)

Missing one TCG_GUEST_DEFAULT_MO mention in docs:

-- >8 --

docs/devel/multi-thread-tcg.rst +2 -2
index b0f473961dd..14a2a9dc7b5 100644
@@ -31,2 +31,2 @@ combinations where the host memory model is able to accommodate the
-guest (TCG_GUEST_DEFAULT_MO & ~TCG_TARGET_DEFAULT_MO is zero) and the
-guest has had the required work done to support this safely
+guest (TCGCPUOps::guest_default_memory_order & ~TCG_TARGET_DEFAULT_MO is zero)
+and the guest has had the required work done to support this safely

---

Reviewed-by Anton Johansson on v1 4/4
#15 lore raw

Re: [RFC PATCH-for-10.1 4/4] tcg: Define guest_default_memory_order in TCGCPUOps

In reply to Philippe Mathieu-Daudé
Quoted 42 lines · Philippe Mathieu-Daudé

Add the TCGCPUOps::guest_default_memory_order field and have each target initialize it.

Use it to set TCGContext::guest_mo in tb_gen_code(), removing the need for the TCG_GUEST_DEFAULT_MO definition.

---
 include/accel/tcg/cpu-ops.h   |  8 ++++++++
 target/alpha/cpu-param.h      |  3 ---
 target/arm/cpu-param.h        |  3 ---
 target/avr/cpu-param.h        |  2 --
 target/hexagon/cpu-param.h    |  3 ---
 target/hppa/cpu-param.h       |  8 --------
 target/i386/cpu-param.h       |  3 ---
 target/loongarch/cpu-param.h  |  2 --
 target/m68k/cpu-param.h       |  3 ---
 target/microblaze/cpu-param.h |  3 ---
 target/mips/cpu-param.h       |  2 --
 target/openrisc/cpu-param.h   |  2 --
 target/ppc/cpu-param.h        |  2 --
 target/riscv/cpu-param.h      |  2 --
 target/rx/cpu-param.h         |  3 ---
 target/s390x/cpu-param.h      |  6 ------
 target/sh4/cpu-param.h        |  3 ---
 target/sparc/cpu-param.h      | 23 -----------------------
 target/tricore/cpu-param.h    |  3 ---
 target/xtensa/cpu-param.h     |  3 ---
 accel/tcg/translate-all.c     |  2 +-
 target/alpha/cpu.c            |  3 +++
 target/arm/cpu.c              |  3 +++
 target/arm/tcg/cpu-v7m.c      |  3 +++
 target/avr/cpu.c              |  1 +
 target/hexagon/cpu.c          |  2 ++
 target/hppa/cpu.c             |  8 ++++++++
 target/i386/tcg/tcg-cpu.c     |  5 +++++
 target/loongarch/cpu.c        |  2 ++
 target/m68k/cpu.c             |  3 +++
 target/microblaze/cpu.c       |  3 +++
 target/mips/cpu.c             |  2 ++
 target/openrisc/cpu.c         |  2 ++
 target/ppc/cpu_init.c         |  2 ++
Quoted 8 lines
 target/riscv/tcg/tcg-cpu.c    |  2 ++
 target/rx/cpu.c               |  3 +++
 target/s390x/cpu.c            |  6 ++++++
 target/sh4/cpu.c              |  3 +++
 target/sparc/cpu.c            | 23 +++++++++++++++++++++++
 target/tricore/cpu.c          |  2 ++
 target/xtensa/cpu.c           |  3 +++
 41 files changed, 90 insertions(+), 80 deletions(-)

This is a nice change!:)

Reviewed-by on v1 4/4
#16 lore raw

Re: [RFC PATCH-for-10.1 4/4] tcg: Define guest_default_memory_order in TCGCPUOps

In reply to Philippe Mathieu-Daudé
Quoted 8 lines · Philippe Mathieu-Daudé

Add theTCGCPUOps::guest_default_memory_order field and have each target initialize it.

Use it to setTCGContext::guest_mo in tb_gen_code(), removing the need for the TCG_GUEST_DEFAULT_MO definition.

---

r~

Reviewed-by on v1 4/4
#17 lore raw

Re: [RFC PATCH-for-10.1 4/4] tcg: Define guest_default_memory_order in TCGCPUOps

In reply to Philippe Mathieu-Daudé
Quoted 627 lines · Philippe Mathieu-Daudé

Add the TCGCPUOps::guest_default_memory_order field and have each target initialize it.

Use it to set TCGContext::guest_mo in tb_gen_code(), removing the need for the TCG_GUEST_DEFAULT_MO definition.

---
  include/accel/tcg/cpu-ops.h   |  8 ++++++++
  target/alpha/cpu-param.h      |  3 ---
  target/arm/cpu-param.h        |  3 ---
  target/avr/cpu-param.h        |  2 --
  target/hexagon/cpu-param.h    |  3 ---
  target/hppa/cpu-param.h       |  8 --------
  target/i386/cpu-param.h       |  3 ---
  target/loongarch/cpu-param.h  |  2 --
  target/m68k/cpu-param.h       |  3 ---
  target/microblaze/cpu-param.h |  3 ---
  target/mips/cpu-param.h       |  2 --
  target/openrisc/cpu-param.h   |  2 --
  target/ppc/cpu-param.h        |  2 --
  target/riscv/cpu-param.h      |  2 --
  target/rx/cpu-param.h         |  3 ---
  target/s390x/cpu-param.h      |  6 ------
  target/sh4/cpu-param.h        |  3 ---
  target/sparc/cpu-param.h      | 23 -----------------------
  target/tricore/cpu-param.h    |  3 ---
  target/xtensa/cpu-param.h     |  3 ---
  accel/tcg/translate-all.c     |  2 +-
  target/alpha/cpu.c            |  3 +++
  target/arm/cpu.c              |  3 +++
  target/arm/tcg/cpu-v7m.c      |  3 +++
  target/avr/cpu.c              |  1 +
  target/hexagon/cpu.c          |  2 ++
  target/hppa/cpu.c             |  8 ++++++++
  target/i386/tcg/tcg-cpu.c     |  5 +++++
  target/loongarch/cpu.c        |  2 ++
  target/m68k/cpu.c             |  3 +++
  target/microblaze/cpu.c       |  3 +++
  target/mips/cpu.c             |  2 ++
  target/openrisc/cpu.c         |  2 ++
  target/ppc/cpu_init.c         |  2 ++
  target/riscv/tcg/tcg-cpu.c    |  2 ++
  target/rx/cpu.c               |  3 +++
  target/s390x/cpu.c            |  6 ++++++
  target/sh4/cpu.c              |  3 +++
  target/sparc/cpu.c            | 23 +++++++++++++++++++++++
  target/tricore/cpu.c          |  2 ++
  target/xtensa/cpu.c           |  3 +++
  41 files changed, 90 insertions(+), 80 deletions(-)
include/accel/tcg/cpu-ops.h +8 -0
index f60e5303f21..5fd299cefb6 100644
@@ -16,8 +16,16 @@
  #include "exec/memop.h"
  #include "exec/mmu-access-type.h"
  #include "exec/vaddr.h"
+#include "tcg/tcg-mo.h"
 
  struct TCGCPUOps {
+
+    /**
+     * @guest_default_memory_order: default barrier that is required
+     *                              for the guest memory ordering.
+     */
+    TCGBar guest_default_memory_order;
+
      /**
       * @initialize: Initialize TCG state
       *
target/alpha/cpu-param.h +0 -3
index ff06e41497a..c74556d2667 100644
@@ -25,7 +25,4 @@
  # define TARGET_VIRT_ADDR_SPACE_BITS  (30 + TARGET_PAGE_BITS)
  #endif
 
-/* Alpha processors have a weak memory model */
-#define TCG_GUEST_DEFAULT_MO      (0)
-
  #endif
target/arm/cpu-param.h +0 -3
index 896b35bd6d5..55de4d54544 100644
@@ -38,7 +38,4 @@
  # define TARGET_PAGE_BITS_MIN  10
  #endif /* !CONFIG_USER_ONLY */
 
-/* ARM processors have a weak memory model */
-#define TCG_GUEST_DEFAULT_MO      (0)
-
  #endif
target/avr/cpu-param.h +0 -2
index 81f3f49ee1f..11e827109c0 100644
@@ -31,6 +31,4 @@
  #define TARGET_PHYS_ADDR_SPACE_BITS 24
  #define TARGET_VIRT_ADDR_SPACE_BITS 24
 
-#define TCG_GUEST_DEFAULT_MO 0
-
  #endif
target/hexagon/cpu-param.h +0 -3
index 2d57ea6caf9..45ee7b46409 100644
@@ -23,7 +23,4 @@
  #define TARGET_PHYS_ADDR_SPACE_BITS 36
  #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
-/* MTTCG not yet supported: require strict ordering */
-#define TCG_GUEST_DEFAULT_MO        TCG_MO_ALL
-
  #endif
target/hppa/cpu-param.h +0 -8
index 7ed6b5741e7..e0b2c7c9157 100644
@@ -19,12 +19,4 @@
 
  #define TARGET_PAGE_BITS 12
 
-/* PA-RISC 1.x processors have a strong memory model.  */
-/*
- * ??? While we do not yet implement PA-RISC 2.0, those processors have
- * a weak memory model, but with TLB bits that force ordering on a per-page
- * basis.  It's probably easier to fall back to a strong memory model.
- */
-#define TCG_GUEST_DEFAULT_MO        TCG_MO_ALL
-
  #endif
target/i386/cpu-param.h +0 -3
index b0e884c5d70..909bc027923 100644
@@ -22,7 +22,4 @@
  #endif
  #define TARGET_PAGE_BITS 12
 
-/* The x86 has a strong memory model with some store-after-load re-ordering */
-#define TCG_GUEST_DEFAULT_MO      (TCG_MO_ALL & ~TCG_MO_ST_LD)
-
  #endif
target/loongarch/cpu-param.h +0 -2
index 52437946e56..071567712b3 100644
@@ -13,6 +13,4 @@
 
  #define TARGET_PAGE_BITS 12
 
-#define TCG_GUEST_DEFAULT_MO (0)
-
  #endif
target/m68k/cpu-param.h +0 -3
index 1a909eaa13e..7afbf6d302d 100644
@@ -17,7 +17,4 @@
  #define TARGET_PHYS_ADDR_SPACE_BITS 32
  #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
-/* MTTCG not yet supported: require strict ordering */
-#define TCG_GUEST_DEFAULT_MO        TCG_MO_ALL
-
  #endif
target/microblaze/cpu-param.h +0 -3
index c866ec6c149..6a0714bb3d7 100644
@@ -27,7 +27,4 @@
  /* FIXME: MB uses variable pages down to 1K but linux only uses 4k.  */
  #define TARGET_PAGE_BITS 12
 
-/* MicroBlaze is always in-order. */
-#define TCG_GUEST_DEFAULT_MO  TCG_MO_ALL
-
  #endif
target/mips/cpu-param.h +0 -2
index 11b3ac0ac63..35fb6ea7243 100644
@@ -25,6 +25,4 @@
  #define TARGET_PAGE_BITS_MIN 12
  #endif
 
-#define TCG_GUEST_DEFAULT_MO (0)
-
  #endif
target/openrisc/cpu-param.h +0 -2
index 37627f2c394..3011bf5fcca 100644
@@ -12,6 +12,4 @@
  #define TARGET_PHYS_ADDR_SPACE_BITS 32
  #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
-#define TCG_GUEST_DEFAULT_MO (0)
-
  #endif
target/ppc/cpu-param.h +0 -2
index 6c4525fdf3c..2cee113ddd3 100644
@@ -38,6 +38,4 @@
  # define TARGET_PAGE_BITS 12
  #endif
 
-#define TCG_GUEST_DEFAULT_MO 0
-
  #endif
target/riscv/cpu-param.h +0 -2
index fba30e966a8..a80310ef2c5 100644
@@ -26,6 +26,4 @@
   *  - M mode HLV/HLVX/HSV 0b111
   */
 
-#define TCG_GUEST_DEFAULT_MO 0
-
  #endif
target/rx/cpu-param.h +0 -3
index 2ce199164d7..ef1970a09e9 100644
@@ -24,7 +24,4 @@
  #define TARGET_PHYS_ADDR_SPACE_BITS 32
  #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
-/* MTTCG not yet supported: require strict ordering */
-#define TCG_GUEST_DEFAULT_MO        TCG_MO_ALL
-
  #endif
target/s390x/cpu-param.h +0 -6
index 5c331ec424c..a5f798eeae7 100644
@@ -12,10 +12,4 @@
  #define TARGET_PHYS_ADDR_SPACE_BITS 64
  #define TARGET_VIRT_ADDR_SPACE_BITS 64
 
-/*
- * The z/Architecture has a strong memory model with some
- * store-after-load re-ordering.
- */
-#define TCG_GUEST_DEFAULT_MO      (TCG_MO_ALL & ~TCG_MO_ST_LD)
-
  #endif
target/sh4/cpu-param.h +0 -3
index 1bc90d4695e..2b6e11dd0ac 100644
@@ -16,7 +16,4 @@
  # define TARGET_VIRT_ADDR_SPACE_BITS 32
  #endif
 
-/* MTTCG not yet supported: require strict ordering */
-#define TCG_GUEST_DEFAULT_MO        TCG_MO_ALL
-
  #endif
target/sparc/cpu-param.h +0 -23
index 6952ee2b826..6e8e2a51469 100644
@@ -21,27 +21,4 @@
  # define TARGET_VIRT_ADDR_SPACE_BITS 32
  #endif
 
-/*
- * From Oracle SPARC Architecture 2015:
- *
- *   Compatibility notes: The PSO memory model described in SPARC V8 and
- *   SPARC V9 compatibility architecture specifications was never implemented
- *   in a SPARC V9 implementation and is not included in the Oracle SPARC
- *   Architecture specification.
- *
- *   The RMO memory model described in the SPARC V9 specification was
- *   implemented in some non-Sun SPARC V9 implementations, but is not
- *   directly supported in Oracle SPARC Architecture 2015 implementations.
- *
- * Therefore always use TSO in QEMU.
- *
- * D.5 Specification of Partial Store Order (PSO)
- *   ... [loads] are followed by an implied MEMBAR #LoadLoad | #LoadStore.
- *
- * D.6 Specification of Total Store Order (TSO)
- *   ... PSO with the additional requirement that all [stores] are followed
- *   by an implied MEMBAR #StoreStore.
- */
-#define TCG_GUEST_DEFAULT_MO  (TCG_MO_LD_LD | TCG_MO_LD_ST | TCG_MO_ST_ST)
-
  #endif
target/tricore/cpu-param.h +0 -3
index 923459370cc..790242ef3d2 100644
@@ -12,7 +12,4 @@
  #define TARGET_PHYS_ADDR_SPACE_BITS 32
  #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
-/* MTTCG not yet supported: require strict ordering */
-#define TCG_GUEST_DEFAULT_MO        TCG_MO_ALL
-
  #endif
target/xtensa/cpu-param.h +0 -3
index 5e4848ad059..06d85218b84 100644
@@ -16,7 +16,4 @@
  #define TARGET_VIRT_ADDR_SPACE_BITS 32
  #endif
 
-/* Xtensa processors have a weak memory model */
-#define TCG_GUEST_DEFAULT_MO      (0)
-
  #endif
accel/tcg/translate-all.c +1 -1
index fb9f83dbba3..26442e83776 100644
@@ -349,7 +349,7 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
      tcg_ctx->tlb_dyn_max_bits = CPU_TLB_DYN_MAX_BITS;
  #endif
      tcg_ctx->insn_start_words = TARGET_INSN_START_WORDS;
-    tcg_ctx->guest_mo = TCG_GUEST_DEFAULT_MO;
+    tcg_ctx->guest_mo = cpu->cc->tcg_ops->guest_default_memory_order;
 
   restart_translate:
      trace_translate_block(tb, pc, tb->tc.ptr);
target/alpha/cpu.c +3 -0
index 584c2aa76bd..e5e14976f51 100644
@@ -239,6 +239,9 @@ static const TCGCPUOps alpha_tcg_ops = {
      .synchronize_from_tb = alpha_cpu_synchronize_from_tb,
      .restore_state_to_opc = alpha_restore_state_to_opc,
 
+    /* Alpha processors have a weak memory model */
+    .guest_default_memory_order = 0,
+
  #ifdef CONFIG_USER_ONLY
      .record_sigsegv = alpha_cpu_record_sigsegv,
      .record_sigbus = alpha_cpu_record_sigbus,
target/arm/cpu.c +3 -0
index 01786ac7879..8b9f2acf82b 100644
@@ -2675,6 +2675,9 @@ static const TCGCPUOps arm_tcg_ops = {
      .debug_excp_handler = arm_debug_excp_handler,
      .restore_state_to_opc = arm_restore_state_to_opc,
 
+    /* ARM processors have a weak memory model */
+    .guest_default_memory_order = 0,
+
  #ifdef CONFIG_USER_ONLY
      .record_sigsegv = arm_cpu_record_sigsegv,
      .record_sigbus = arm_cpu_record_sigbus,
target/arm/tcg/cpu-v7m.c +3 -0
index c4dd3092726..df6b7198944 100644
@@ -238,6 +238,9 @@ static const TCGCPUOps arm_v7m_tcg_ops = {
      .debug_excp_handler = arm_debug_excp_handler,
      .restore_state_to_opc = arm_restore_state_to_opc,
 
+    /* ARM processors have a weak memory model */
+    .guest_default_memory_order = 0,
+
  #ifdef CONFIG_USER_ONLY
      .record_sigsegv = arm_cpu_record_sigsegv,
      .record_sigbus = arm_cpu_record_sigbus,
target/avr/cpu.c +1 -0
index 834c7082aa7..24e52e28f44 100644
@@ -216,6 +216,7 @@ static const TCGCPUOps avr_tcg_ops = {
      .cpu_exec_halt = avr_cpu_has_work,
      .tlb_fill = avr_cpu_tlb_fill,
      .do_interrupt = avr_cpu_do_interrupt,
+    .guest_default_memory_order = 0,
  };
 
  static void avr_cpu_class_init(ObjectClass *oc, void *data)
target/hexagon/cpu.c +2 -0
index 766b6786511..34734b0edb0 100644
@@ -324,6 +324,8 @@ static const TCGCPUOps hexagon_tcg_ops = {
      .translate_code = hexagon_translate_code,
      .synchronize_from_tb = hexagon_cpu_synchronize_from_tb,
      .restore_state_to_opc = hexagon_restore_state_to_opc,
+    /* MTTCG not yet supported: require strict ordering */
+    .guest_default_memory_order = TCG_MO_ALL,
  };
 
  static void hexagon_cpu_class_init(ObjectClass *c, void *data)
target/hppa/cpu.c +8 -0
index 2a85495d02f..997bd69db19 100644
@@ -257,6 +257,14 @@ static const TCGCPUOps hppa_tcg_ops = {
      .synchronize_from_tb = hppa_cpu_synchronize_from_tb,
      .restore_state_to_opc = hppa_restore_state_to_opc,
 
+    /* PA-RISC 1.x processors have a strong memory model.  */
+    /*
+     * ??? While we do not yet implement PA-RISC 2.0, those processors have
+     * a weak memory model, but with TLB bits that force ordering on a per-page
+     * basis.  It's probably easier to fall back to a strong memory model.
+     */
+    .guest_default_memory_order = TCG_MO_ALL,
+
  #ifndef CONFIG_USER_ONLY
      .tlb_fill_align = hppa_cpu_tlb_fill_align,
      .cpu_exec_interrupt = hppa_cpu_exec_interrupt,
target/i386/tcg/tcg-cpu.c +5 -0
index b8aff825eec..4a76c475971 100644
@@ -128,6 +128,11 @@ static const TCGCPUOps x86_tcg_ops = {
      .debug_check_breakpoint = x86_debug_check_breakpoint,
      .need_replay_interrupt = x86_need_replay_interrupt,
  #endif /* !CONFIG_USER_ONLY */
+
+    /*
+     * The x86 has a strong memory model with some store-after-load re-ordering
+     */
+    .guest_default_memory_order = TCG_MO_ALL & ~TCG_MO_ST_LD,
  };
 
  static void x86_tcg_cpu_init_ops(AccelCPUClass *accel_cpu, CPUClass *cc)
target/loongarch/cpu.c +2 -0
index ea1665e2705..c39ff056157 100644
@@ -869,6 +869,8 @@ static const TCGCPUOps loongarch_tcg_ops = {
      .synchronize_from_tb = loongarch_cpu_synchronize_from_tb,
      .restore_state_to_opc = loongarch_restore_state_to_opc,
 
+    .guest_default_memory_order = 0,
+
  #ifndef CONFIG_USER_ONLY
      .tlb_fill = loongarch_cpu_tlb_fill,
      .cpu_exec_interrupt = loongarch_cpu_exec_interrupt,
target/m68k/cpu.c +3 -0
index 0065e1c1ca5..e96b379e266 100644
@@ -593,6 +593,9 @@ static const TCGCPUOps m68k_tcg_ops = {
      .translate_code = m68k_translate_code,
      .restore_state_to_opc = m68k_restore_state_to_opc,
 
+    /* MTTCG not yet supported: require strict ordering */
+    .guest_default_memory_order = TCG_MO_ALL,
+
  #ifndef CONFIG_USER_ONLY
      .tlb_fill = m68k_cpu_tlb_fill,
      .cpu_exec_interrupt = m68k_cpu_exec_interrupt,
target/microblaze/cpu.c +3 -0
index f3bebea856e..4b9ef6e52c4 100644
@@ -432,6 +432,9 @@ static const TCGCPUOps mb_tcg_ops = {
      .synchronize_from_tb = mb_cpu_synchronize_from_tb,
      .restore_state_to_opc = mb_restore_state_to_opc,
 
+    /* MicroBlaze is always in-order. */
+    .guest_default_memory_order = TCG_MO_ALL,
+
  #ifndef CONFIG_USER_ONLY
      .tlb_fill = mb_cpu_tlb_fill,
      .cpu_exec_interrupt = mb_cpu_exec_interrupt,
target/mips/cpu.c +2 -0
index b207106dd79..5ddc9bbb829 100644
@@ -554,6 +554,8 @@ static const TCGCPUOps mips_tcg_ops = {
      .synchronize_from_tb = mips_cpu_synchronize_from_tb,
      .restore_state_to_opc = mips_restore_state_to_opc,
 
+    .guest_default_memory_order = 0,
+
  #if !defined(CONFIG_USER_ONLY)
      .tlb_fill = mips_cpu_tlb_fill,
      .cpu_exec_interrupt = mips_cpu_exec_interrupt,
target/openrisc/cpu.c +2 -0
index e8abf1f8b5c..6a878aaadd8 100644
@@ -248,6 +248,8 @@ static const TCGCPUOps openrisc_tcg_ops = {
      .synchronize_from_tb = openrisc_cpu_synchronize_from_tb,
      .restore_state_to_opc = openrisc_restore_state_to_opc,
 
+    .guest_default_memory_order = 0,
+
  #ifndef CONFIG_USER_ONLY
      .tlb_fill = openrisc_cpu_tlb_fill,
      .cpu_exec_interrupt = openrisc_cpu_exec_interrupt,
target/ppc/cpu_init.c +2 -0
index 8b590e7f17c..28fbbb8d3c1 100644
@@ -7490,6 +7490,8 @@ static const TCGCPUOps ppc_tcg_ops = {
    .translate_code = ppc_translate_code,
    .restore_state_to_opc = ppc_restore_state_to_opc,
 
+  .guest_default_memory_order = 0,
+
  #ifdef CONFIG_USER_ONLY
    .record_sigsegv = ppc_cpu_record_sigsegv,
  #else
target/riscv/tcg/tcg-cpu.c +2 -0
index 5aef9eef366..fb903992faa 100644
@@ -139,6 +139,8 @@ static const TCGCPUOps riscv_tcg_ops = {
      .synchronize_from_tb = riscv_cpu_synchronize_from_tb,
      .restore_state_to_opc = riscv_restore_state_to_opc,
 
+    .guest_default_memory_order = 0,
+
  #ifndef CONFIG_USER_ONLY
      .tlb_fill = riscv_cpu_tlb_fill,
      .cpu_exec_interrupt = riscv_cpu_exec_interrupt,
target/rx/cpu.c +3 -0
index 0ba0d55ab5b..6a24e7e9136 100644
@@ -212,6 +212,9 @@ static const TCGCPUOps rx_tcg_ops = {
      .cpu_exec_interrupt = rx_cpu_exec_interrupt,
      .cpu_exec_halt = rx_cpu_has_work,
      .do_interrupt = rx_cpu_do_interrupt,
+
+    /* MTTCG not yet supported: require strict ordering */
+    .guest_default_memory_order = TCG_MO_ALL,
  };
 
  static void rx_cpu_class_init(ObjectClass *klass, void *data)
target/s390x/cpu.c +6 -0
index d73142600bf..12fd853c00a 100644
@@ -360,6 +360,12 @@ static const TCGCPUOps s390_tcg_ops = {
      .debug_excp_handler = s390x_cpu_debug_excp_handler,
      .do_unaligned_access = s390x_cpu_do_unaligned_access,
  #endif /* !CONFIG_USER_ONLY */
+
+    /*
+     * The z/Architecture has a strong memory model with some
+     * store-after-load re-ordering.
+     */
+    .guest_default_memory_order = TCG_MO_ALL & ~TCG_MO_ST_LD,
  };
  #endif /* CONFIG_TCG */
 
target/sh4/cpu.c +3 -0
index ce84bdf539a..ce9ed75107a 100644
@@ -267,6 +267,9 @@ static const TCGCPUOps superh_tcg_ops = {
      .synchronize_from_tb = superh_cpu_synchronize_from_tb,
      .restore_state_to_opc = superh_restore_state_to_opc,
 
+    /* MTTCG not yet supported: require strict ordering */
+    .guest_default_memory_order = TCG_MO_ALL,
+
  #ifndef CONFIG_USER_ONLY
      .tlb_fill = superh_cpu_tlb_fill,
      .cpu_exec_interrupt = superh_cpu_exec_interrupt,
target/sparc/cpu.c +23 -0
index 57161201173..39bd0c42855 100644
@@ -1005,6 +1005,29 @@ static const TCGCPUOps sparc_tcg_ops = {
      .synchronize_from_tb = sparc_cpu_synchronize_from_tb,
      .restore_state_to_opc = sparc_restore_state_to_opc,
 
+    /*
+     * From Oracle SPARC Architecture 2015:
+     *
+     *   Compatibility notes: The PSO memory model described in SPARC V8 and
+     *   SPARC V9 compatibility architecture specifications was never
+     *   implemented in a SPARC V9 implementation and is not included in the
+     *   Oracle SPARC Architecture specification.
+     *
+     *   The RMO memory model described in the SPARC V9 specification was
+     *   implemented in some non-Sun SPARC V9 implementations, but is not
+     *   directly supported in Oracle SPARC Architecture 2015 implementations.
+     *
+     * Therefore always use TSO in QEMU.
+     *
+     * D.5 Specification of Partial Store Order (PSO)
+     *   ... [loads] are followed by an implied MEMBAR #LoadLoad | #LoadStore.
+     *
+     * D.6 Specification of Total Store Order (TSO)
+     *   ... PSO with the additional requirement that all [stores] are followed
+     *   by an implied MEMBAR #StoreStore.
+     */
+    .guest_default_memory_order = TCG_MO_LD_LD | TCG_MO_LD_ST | TCG_MO_ST_ST,
+
  #ifndef CONFIG_USER_ONLY
      .tlb_fill = sparc_cpu_tlb_fill,
      .cpu_exec_interrupt = sparc_cpu_exec_interrupt,
target/tricore/cpu.c +2 -0
index 16acc4ecb92..e0a48065948 100644
@@ -179,6 +179,8 @@ static const TCGCPUOps tricore_tcg_ops = {
      .tlb_fill = tricore_cpu_tlb_fill,
      .cpu_exec_interrupt = tricore_cpu_exec_interrupt,
      .cpu_exec_halt = tricore_cpu_has_work,
+    /* MTTCG not yet supported: require strict ordering */
+    .guest_default_memory_order = TCG_MO_ALL,
  };
 
  static void tricore_cpu_class_init(ObjectClass *c, void *data)
target/xtensa/cpu.c +0 -0
index 7663b62d01e..dd9061ba469 100644

target/xtensa/cpu.c static const TCGCPUOps xtensa_tcg_ops = { · line 245

Quoted 9 lines
target/xtensa/cpu.c +3 -0
@@ -237,6 +237,9 @@ static const TCGCPUOps xtensa_tcg_ops = {
      .debug_excp_handler = xtensa_breakpoint_handler,
      .restore_state_to_opc = xtensa_restore_state_to_opc,
 
+    /* Xtensa processors have a weak memory model */
+    .guest_default_memory_order = 0,
+
  #ifndef CONFIG_USER_ONLY
      .tlb_fill = xtensa_cpu_tlb_fill,
      .cpu_exec_interrupt = xtensa_cpu_exec_interrupt,

Excellent.
It's definitely a nice paradigm to move those things here instead of having them optionally defined in headers. I've been bitten by that on the latest series remove cpu-all.h.

Reviewed-by Anton Johansson on the v1 series
#18 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 49 lines · Philippe Mathieu-Daudé

Hi,

In this series we replace the TCG_GUEST_DEFAULT_MO definition from "cpu-param.h" by a 'guest_default_memory_order' field in TCGCPUOps.

Since tcg_req_mo() now accesses tcg_ctx, this impact the cpu_req_mo() calls in accel/tcg/{cputlb,user-exec}.c.

The long term goal is to be able to use targets with distinct guest memory order restrictions.

Philippe Mathieu-Daudé (4):
tcg: Always define TCG_GUEST_DEFAULT_MO
tcg: Simplify tcg_req_mo() macro
tcg: Have tcg_req_mo() use runtime TCGContext::guest_mo
tcg: Define guest_default_memory_order in TCGCPUOps

 accel/tcg/internal-target.h   | 13 ++-----------
 include/accel/tcg/cpu-ops.h   |  8 ++++++++
 target/alpha/cpu-param.h      |  3 ---
 target/arm/cpu-param.h        |  3 ---
 target/avr/cpu-param.h        |  2 --
 target/hppa/cpu-param.h       |  8 --------
 target/i386/cpu-param.h       |  3 ---
 target/loongarch/cpu-param.h  |  2 --
 target/microblaze/cpu-param.h |  3 ---
 target/mips/cpu-param.h       |  2 --
 target/openrisc/cpu-param.h   |  2 --
 target/ppc/cpu-param.h        |  2 --
 target/riscv/cpu-param.h      |  2 --
 target/s390x/cpu-param.h      |  6 ------
 target/sparc/cpu-param.h      | 23 -----------------------
 target/xtensa/cpu-param.h     |  3 ---
 accel/tcg/tcg-all.c           |  3 ---
 accel/tcg/translate-all.c     |  6 +-----
 target/alpha/cpu.c            |  3 +++
 target/arm/cpu.c              |  3 +++
 target/arm/tcg/cpu-v7m.c      |  3 +++
 target/avr/cpu.c              |  1 +
 target/hexagon/cpu.c          |  2 ++
 target/hppa/cpu.c             |  8 ++++++++
 target/i386/tcg/tcg-cpu.c     |  5 +++++
 target/loongarch/cpu.c        |  2 ++
 target/m68k/cpu.c             |  3 +++
 target/microblaze/cpu.c       |  3 +++
 target/mips/cpu.c             |  2 ++
 target/openrisc/cpu.c         |  2 ++
 target/ppc/cpu_init.c         |  2 ++
Quoted 12 lines
 target/riscv/tcg/tcg-cpu.c    |  2 ++
 target/rx/cpu.c               |  3 +++
 target/s390x/cpu.c            |  6 ++++++
 target/sh4/cpu.c              |  3 +++
 target/sparc/cpu.c            | 23 +++++++++++++++++++++++
 target/tricore/cpu.c          |  2 ++
 target/xtensa/cpu.c           |  3 +++
 38 files changed, 92 insertions(+), 83 deletions(-)
Signature · 1 line
2.47.1