Skip to contentSkip to conversation

accel/tcg: Extract cpu-loop API out of 'exec/cpu-common.h'

PATCH Applied Philippe Mathieu-Daudé 2 participants 15 messages Jun 17 – Jun 18

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover accel/tcg: Extract cpu-loop API out of 'exec/cpu-common.h'

Missing review: 8 & 9

Since v1:
- Do not un-inline cpu_loop_exit_requested()

We still try to clarify our different APIs, in particular TCG emulation vs hardware accelerators. Extract the TCG vcpu loop methods out of the generic "exec/cpu-common.h" and move them under the 'accel/tcg/' namespace.

Philippe Mathieu-Daudé (11):
target/arm: Restrict TCG specific headers
hw/s390x/ipl: Remove TCG dependency in handle_diag_308() accel/tcg: Remove cpu_loop_exit() stub
accel/tcg: Move cpu_exec() out of 'exec/cpu-common.h' accel/tcg: Move cpu_exec_step_atomic() out of 'exec/cpu-common.h' accel/tcg: Move cpu_unwind_state_data() out of 'exec/cpu-common.h' accel/tcg: Move cpu_restore_state() out of 'exec/cpu-common.h' accel/tcg: Have cpu_loop_exit_requested() take const @cpu argument accel/tcg: Move cpu_loop_exit_requested() out of 'exec/cpu-common.h' accel/tcg: Move cpu_loop_exit_*() out of 'exec/cpu-common.h' accel/tcg: Restrict headers being TCG specific

 bsd-user/freebsd/os-proc.h           |  1 +
 include/accel/tcg/cpu-loop.h         | 73 ++++++++++++++++++++++++++++
 include/accel/tcg/cpu-mmu-index.h    |  4 ++
 include/accel/tcg/cpu-ops.h          |  4 ++
 include/accel/tcg/getpc.h            |  4 ++
 include/accel/tcg/helper-retaddr.h   |  4 ++
 include/accel/tcg/probe.h            |  4 ++
 include/accel/tcg/tb-cpu-state.h     |  4 ++
 include/exec/cpu-common.h            | 56 ---------------------
 include/hw/core/cpu.h                | 20 ++++++++
 include/user/cpu_loop.h              |  2 +-
 target/arm/internals.h               |  4 +-
 target/s390x/s390x-internal.h        |  3 +-
 accel/stubs/tcg-stub.c               | 20 --------
 accel/tcg/cpu-exec-common.c          |  1 +
 accel/tcg/cpu-exec.c                 |  1 +
 accel/tcg/cputlb.c                   |  1 +
 accel/tcg/tb-maint.c                 |  1 +
 accel/tcg/tcg-accel-ops-mttcg.c      |  1 +
 accel/tcg/tcg-accel-ops-rr.c         |  1 +
 accel/tcg/tcg-accel-ops.c            |  1 +
 accel/tcg/tcg-runtime.c              |  1 +
 accel/tcg/translate-all.c            |  1 +
 accel/tcg/user-exec.c                |  1 +
 accel/tcg/watchpoint.c               |  1 +
 bsd-user/main.c                      |  1 +
 hw/misc/mips_itu.c                   |  1 +
 hw/s390x/ipl.c                       |  5 --
 plugins/api.c                        |  1 +
 semihosting/console.c                |  1 +
 target/alpha/helper.c                |  1 +
 target/alpha/mem_helper.c            |  1 +
 target/arm/cpu-irq.c                 |  3 +-
 target/arm/tcg/helper-a64.c          |  2 +
 target/arm/tcg/op_helper.c           |  1 +
 target/arm/tcg/tlb_helper.c          |  1 +
 target/avr/helper.c                  |  1 +
 target/hexagon/op_helper.c           |  1 +
 target/hppa/cpu.c                    |  1 +
 target/hppa/mem_helper.c             |  1 +
 target/hppa/op_helper.c              |  1 +
 target/i386/helper.c                 |  1 +
 target/i386/tcg/excp_helper.c        |  1 +
 target/i386/tcg/misc_helper.c        |  1 +
 target/i386/tcg/system/bpt_helper.c  |  1 +
 target/i386/tcg/system/misc_helper.c |  1 +
 target/i386/tcg/system/svm_helper.c  |  1 +
 target/i386/tcg/user/excp_helper.c   |  1 +
 target/i386/tcg/user/seg_helper.c    |  1 +
 target/loongarch/tcg/tcg_cpu.c       |  1 +
 target/loongarch/tcg/tlb_helper.c    |  1 +
 target/m68k/helper.c                 |  1 +
 target/m68k/op_helper.c              |  1 +
 target/microblaze/helper.c           |  1 +
 target/microblaze/op_helper.c        |  1 +
 target/mips/tcg/exception.c          |  1 +
 target/mips/tcg/system/tlb_helper.c  |  1 +
 target/or1k/exception_helper.c       |  1 +
 target/or1k/fpu_helper.c             |  1 +
 target/or1k/mmu.c                    |  1 +
 target/or1k/sys_helper.c             |  1 +
 target/ppc/tcg-excp_helper.c         |  1 +
 target/ppc/user_only_helper.c        |  1 +
 target/riscv/cpu_helper.c            |  1 +
 target/riscv/csr.c                   |  1 +
 target/riscv/op_helper.c             |  1 +
 target/rx/op_helper.c                |  1 +
 target/s390x/diag.c                  | 32 ++++++------
 target/s390x/mmu_helper.c            |  3 ++
 target/s390x/tcg/cc_helper.c         |  1 +
 target/s390x/tcg/debug.c             |  1 +
 target/s390x/tcg/excp_helper.c       |  1 +
 target/s390x/tcg/mem_helper.c        |  2 +
 target/s390x/tcg/misc_helper.c       |  6 ++-
 target/sh4/helper.c                  |  1 +
 target/sh4/op_helper.c               |  1 +
 target/sparc/helper.c                |  1 +
 target/sparc/mmu_helper.c            |  1 +
 target/tricore/helper.c              |  1 +
 target/tricore/op_helper.c           |  1 +
 target/xtensa/exc_helper.c           |  1 +
 target/xtensa/helper.c               |  1 +
 accel/stubs/meson.build              |  1 -
 83 files changed, 215 insertions(+), 103 deletions(-)
 create mode 100644 include/accel/tcg/cpu-loop.h
 delete mode 100644 accel/stubs/tcg-stub.c
Signature · 1 line
2.53.0
#1 lore raw

PATCH v2 1/11 target/arm: Restrict TCG specific headers

Avoid including TCG-specific headers in non-TCG builds.

---
 target/arm/internals.h | 4 +++-
 target/arm/cpu-irq.c   | 3 ++-
 2 files changed, 5 insertions(+), 2 deletions(-)
target/arm/internals.h +3 -1
index f7a57d3ea70..fcce3804f34 100644
@@ -29,9 +29,11 @@
 #include "exec/vaddr.h"
 #include "exec/breakpoint.h"
 #include "exec/memop.h"
+#ifdef CONFIG_TCG
 #include "accel/tcg/tb-cpu-state.h"
-#include "hw/core/registerfields.h"
 #include "tcg/tcg-gvec-desc.h"
+#endif
+#include "hw/core/registerfields.h"
 #include "system/memory.h"
 #include "syndrome.h"
 #include "cpu-features.h"
target/arm/cpu-irq.c +2 -1
index fe514cc93af..883e8a176c3 100644
@@ -8,10 +8,11 @@
 
 #include "qemu/osdep.h"
 #include "cpu.h"
-#include "accel/tcg/cpu-ops.h"
 #include "internals.h"
 
 #ifdef CONFIG_TCG
+#include "accel/tcg/cpu-ops.h"
+
 static inline bool arm_excp_unmasked(CPUState *cs, unsigned int excp_idx,
                                      unsigned int target_el,
                                      unsigned int cur_el, bool secure,
Signature · 1 line
2.53.0
#2 lore raw

PATCH v2 2/11 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 fa50749a7d3..4cca21c6217 100644
@@ -18,7 +18,6 @@
 #include "system/physmem.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"
@@ -690,10 +689,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
#3 lore raw

PATCH v2 3/11 accel/tcg: Remove cpu_loop_exit() stub

In reply to Philippe Mathieu-Daudé

Last commit removed the last non-TCG use of cpu_loop_exit(). This method is now only called within TCG files, so we can remove its stub for non-TCG accelerators.

---
 accel/stubs/tcg-stub.c  | 20 --------------------
 accel/stubs/meson.build |  1 -
 2 files changed, 21 deletions(-)
 delete mode 100644 accel/stubs/tcg-stub.c
accel/stubs/tcg-stub.c deleted +0 -20
deleted file mode 100644
index 855e5d43171..00000000000
@@ -1,20 +0,0 @@
-/*
- * QEMU TCG accelerator stub
- *
- * Copyright Red Hat, Inc. 2013
- *
- * Author: Paolo Bonzini     <[email protected]>
- *
- * This work is licensed under the terms of the GNU GPL, version 2 or later.
- * See the COPYING file in the top-level directory.
- *
- */
-
-#include "qemu/osdep.h"
-#include "system/tcg.h"
-#include "exec/cpu-common.h"
-
-G_NORETURN void cpu_loop_exit(CPUState *cpu)
-{
-    g_assert_not_reached();
-}
accel/stubs/meson.build +0 -1
index ccad583e647..7c6d7ad9432 100644
@@ -4,7 +4,6 @@ stub_ss.add(files(
   'nitro-stub.c',
   'mshv-stub.c',
   'nvmm-stub.c',
-  'tcg-stub.c',
   'whpx-stub.c',
   'xen-stub.c',
 ))
Signature · 1 line
2.53.0
#4 lore raw

PATCH v2 4/11 accel/tcg: Move cpu_exec() out of 'exec/cpu-common.h'

In reply to Philippe Mathieu-Daudé

In order to keep TCG-specific functions under a TCG API namespace, add the "accel/tcg/cpu-loop.h" header and move cpu_exec() declaration to it. Add a bit of documentation.

Include "accel/tcg/cpu-loop.h" where appropriate.

---
 bsd-user/freebsd/os-proc.h   |  1 +
 include/accel/tcg/cpu-loop.h | 16 ++++++++++++++++
 include/exec/cpu-common.h    |  3 ---
 include/user/cpu_loop.h      |  2 +-
 accel/tcg/cpu-exec.c         |  1 +
 accel/tcg/tcg-accel-ops.c    |  1 +
 bsd-user/main.c              |  1 +
 7 files changed, 21 insertions(+), 4 deletions(-)
 create mode 100644 include/accel/tcg/cpu-loop.h
bsd-user/freebsd/os-proc.h +1 -0
index 72ccf23e17e..1cf3c43de34 100644
@@ -14,6 +14,7 @@
 #include <sys/procdesc.h>
 #include <sys/wait.h>
 
+#include "accel/tcg/cpu-loop.h"
 #include "target_arch_cpu.h"
 
 pid_t safe_wait4(pid_t wpid, int *status, int options, struct rusage *rusage);
include/accel/tcg/cpu-loop.h new file +16 -0
new file mode 100644
index 00000000000..528adb5588c
@@ -0,0 +1,16 @@
+#ifndef ACCEL_TCG_CPU_LOOP_COMMON_H
+#define ACCEL_TCG_CPU_LOOP_COMMON_H
+
+#ifndef CONFIG_TCG
+#error Can only include this header with TCG
+#endif
+
+/**
+ * cpu_exec:
+ * @cpu: the cpu context
+ *
+ * Returns one of the EXCP_* definitions (see "exec/cpu-common.h").
+ */
+int cpu_exec(CPUState *cpu);
+
+#endif
include/exec/cpu-common.h +0 -3
index 883389b0abf..ac3ab0e1cdf 100644
@@ -114,9 +114,6 @@ G_NORETURN void cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc);
 #endif /* CONFIG_TCG */
 G_NORETURN void cpu_loop_exit(CPUState *cpu);
 
-/* accel/tcg/cpu-exec.c */
-int cpu_exec(CPUState *cpu);
-
 /**
  * env_archcpu(env)
  * @env: The architecture environment
include/user/cpu_loop.h +1 -1
index 346e37ede8b..c9d49398f01 100644
@@ -22,7 +22,7 @@
 
 #include "exec/vaddr.h"
 #include "exec/mmu-access-type.h"
-
+#include "accel/tcg/cpu-loop.h"
 
 /**
  * adjust_signal_pc:
accel/tcg/cpu-exec.c +1 -0
index 7292ff15060..9c754b03656 100644
@@ -22,6 +22,7 @@
 #include "qapi/error.h"
 #include "qapi/type-helpers.h"
 #include "hw/core/cpu.h"
+#include "accel/tcg/cpu-loop.h"
 #include "accel/tcg/cpu-ops.h"
 #include "accel/tcg/helper-retaddr.h"
 #include "trace.h"
accel/tcg/tcg-accel-ops.c +1 -0
index 3bd98005042..c179cd4adeb 100644
@@ -28,6 +28,7 @@
 #include "qemu/osdep.h"
 #include "accel/accel-ops.h"
 #include "accel/accel-cpu-ops.h"
+#include "accel/tcg/cpu-loop.h"
 #include "system/tcg.h"
 #include "system/replay.h"
 #include "exec/icount.h"
bsd-user/main.c +1 -0
index 73aae8c3274..4f1544342eb 100644
@@ -39,6 +39,7 @@
 #include "user/guest-base.h"
 #include "user/page-protection.h"
 #include "accel/accel-ops.h"
+#include "accel/tcg/cpu-loop.h"
 #include "tcg/startup.h"
 #include "qemu/timer.h"
 #include "qemu/envlist.h"
Signature · 1 line
2.53.0
#5 lore raw

PATCH v2 5/11 accel/tcg: Move cpu_exec_step_atomic() out of 'exec/cpu-common.h'

In reply to Philippe Mathieu-Daudé

Move the TCG-specific cpu_exec_step_atomic() declaration out of the generic "exec/cpu-common.h" header, to the recently created "accel/tcg/cpu-loop.h" one.

Include "accel/tcg/cpu-loop.h" where appropriate.

---
 include/accel/tcg/cpu-loop.h    | 2 ++
 include/exec/cpu-common.h       | 2 --
 accel/tcg/tcg-accel-ops-mttcg.c | 1 +
 accel/tcg/tcg-accel-ops-rr.c    | 1 +
 4 files changed, 4 insertions(+), 2 deletions(-)
include/accel/tcg/cpu-loop.h +2 -0
index 528adb5588c..d8a5f98f9cf 100644
@@ -13,4 +13,6 @@
  */
 int cpu_exec(CPUState *cpu);
 
+void cpu_exec_step_atomic(CPUState *cpu);
+
 #endif
include/exec/cpu-common.h +0 -2
index ac3ab0e1cdf..ea9a49a1435 100644
@@ -21,8 +21,6 @@
 #define EXCP_YIELD      0x10004 /* cpu wants to yield timeslice to another */
 #define EXCP_ATOMIC     0x10005 /* stop-the-world and emulate atomic */
 
-void cpu_exec_step_atomic(CPUState *cpu);
-
 #define REAL_HOST_PAGE_ALIGN(addr) ROUND_UP((addr), qemu_real_host_page_size())
 
 /* The CPU list lock nests outside page_(un)lock or mmap_(un)lock */
accel/tcg/tcg-accel-ops-mttcg.c +1 -0
index 4160e2ba947..69560fdb9d8 100644
@@ -32,6 +32,7 @@
 #include "qemu/notify.h"
 #include "qemu/guest-random.h"
 #include "hw/core/boards.h"
+#include "accel/tcg/cpu-loop.h"
 #include "tcg/startup.h"
 #include "tcg-accel-ops.h"
 #include "tcg-accel-ops-mttcg.h"
accel/tcg/tcg-accel-ops-rr.c +1 -0
index f84342e0449..5b132d3d5d8 100644
@@ -32,6 +32,7 @@
 #include "qemu/notify.h"
 #include "qemu/guest-random.h"
 #include "exec/cpu-common.h"
+#include "accel/tcg/cpu-loop.h"
 #include "tcg/startup.h"
 #include "tcg-accel-ops.h"
 #include "tcg-accel-ops-rr.h"
Signature · 1 line
2.53.0
#6 lore raw

PATCH v2 6/11 accel/tcg: Move cpu_unwind_state_data() out of 'exec/cpu-common.h'

In reply to Philippe Mathieu-Daudé

Move the TCG-specific cpu_unwind_state_data() declaration out of the generic "exec/cpu-common.h" header, to the recently created "accel/tcg/cpu-loop.h" one.

Include "accel/tcg/cpu-loop.h" where appropriate.

---
 include/accel/tcg/cpu-loop.h | 13 +++++++++++++
 include/exec/cpu-common.h    | 13 -------------
 accel/tcg/translate-all.c    |  1 +
 target/i386/helper.c         |  1 +
 target/or1k/sys_helper.c     |  1 +
 target/riscv/csr.c           |  1 +
 6 files changed, 17 insertions(+), 13 deletions(-)
include/accel/tcg/cpu-loop.h +13 -0
index d8a5f98f9cf..f328aaa0377 100644
@@ -15,4 +15,17 @@ int cpu_exec(CPUState *cpu);
 
 void cpu_exec_step_atomic(CPUState *cpu);
 
+/**
+ * cpu_unwind_state_data:
+ * @cpu: the cpu context
+ * @host_pc: the host pc within the translation
+ * @data: output data
+ *
+ * Attempt to load the unwind state for a host pc occurring in
+ * translated code.  If @host_pc is not in translated code, the
+ * function returns false; otherwise @data is loaded.
+ * This is the same unwind info as given to restore_state_to_opc.
+ */
+bool cpu_unwind_state_data(CPUState *cpu, uintptr_t host_pc, uint64_t *data);
+
 #endif
include/exec/cpu-common.h +0 -13
index ea9a49a1435..ba98304c5fa 100644
@@ -64,19 +64,6 @@ void list_cpus(void);
 #ifdef CONFIG_TCG
 #include "qemu/atomic.h"
 
-/**
- * cpu_unwind_state_data:
- * @cpu: the cpu context
- * @host_pc: the host pc within the translation
- * @data: output data
- *
- * Attempt to load the unwind state for a host pc occurring in
- * translated code.  If @host_pc is not in translated code, the
- * function returns false; otherwise @data is loaded.
- * This is the same unwind info as given to restore_state_to_opc.
- */
-bool cpu_unwind_state_data(CPUState *cpu, uintptr_t host_pc, uint64_t *data);
-
 /**
  * cpu_restore_state:
  * @cpu: the cpu context
accel/tcg/translate-all.c +1 -0
index 05d9ce512a4..78c560c7980 100644
@@ -29,6 +29,7 @@
 #include "qemu/target-info.h"
 #include "exec/log.h"
 #include "exec/icount.h"
+#include "accel/tcg/cpu-loop.h"
 #include "accel/tcg/cpu-ops.h"
 #include "tb-jmp-cache.h"
 #include "tb-hash.h"
target/i386/helper.c +1 -0
index c3cba04e142..68362141621 100644
@@ -32,6 +32,7 @@
 #endif
 #include "qemu/log.h"
 #ifdef CONFIG_TCG
+#include "accel/tcg/cpu-loop.h"
 #include "tcg/insn-start-words.h"
 #endif
 
target/or1k/sys_helper.c +1 -0
index ca627bd7194..8ffa31b84fd 100644
@@ -23,6 +23,7 @@
 #include "exec/cputlb.h"
 #include "exec/target_page.h"
 #include "exec/helper-proto.h"
+#include "accel/tcg/cpu-loop.h"
 #include "exception.h"
 #ifndef CONFIG_USER_ONLY
 #include "hw/core/boards.h"
target/riscv/csr.c +1 -0
index 5514e0f455f..de583396f29 100644
@@ -26,6 +26,7 @@
 #include "time_helper.h"
 #include "exec/cputlb.h"
 #include "exec/icount.h"
+#include "accel/tcg/cpu-loop.h"
 #include "accel/tcg/getpc.h"
 #include "qemu/guest-random.h"
 #include "qapi/error.h"
Signature · 1 line
2.53.0
#7 lore raw

PATCH v2 7/11 accel/tcg: Move cpu_restore_state() out of 'exec/cpu-common.h'

In reply to Philippe Mathieu-Daudé

Move the TCG-specific cpu_restore_state() declaration out of the generic "exec/cpu-common.h" header, to the recently created "accel/tcg/cpu-loop.h" one.

Include "accel/tcg/cpu-loop.h" where appropriate.

---
 include/accel/tcg/cpu-loop.h        | 12 ++++++++++++
 include/exec/cpu-common.h           | 12 ------------
 accel/tcg/cpu-exec-common.c         |  1 +
 accel/tcg/user-exec.c               |  1 +
 target/alpha/helper.c               |  1 +
 target/alpha/mem_helper.c           |  1 +
 target/arm/tcg/op_helper.c          |  1 +
 target/arm/tcg/tlb_helper.c         |  1 +
 target/hppa/cpu.c                   |  1 +
 target/hppa/mem_helper.c            |  1 +
 target/hppa/op_helper.c             |  1 +
 target/i386/tcg/system/svm_helper.c |  1 +
 target/m68k/op_helper.c             |  1 +
 target/microblaze/helper.c          |  1 +
 target/ppc/tcg-excp_helper.c        |  1 +
 target/s390x/tcg/excp_helper.c      |  1 +
 target/sh4/op_helper.c              |  1 +
 target/tricore/op_helper.c          |  1 +
 target/xtensa/helper.c              |  1 +
 19 files changed, 29 insertions(+), 12 deletions(-)
include/accel/tcg/cpu-loop.h +12 -0
index f328aaa0377..2fc38c8f1c4 100644
@@ -28,4 +28,16 @@ void cpu_exec_step_atomic(CPUState *cpu);
  */
 bool cpu_unwind_state_data(CPUState *cpu, uintptr_t host_pc, uint64_t *data);
 
+/**
+ * cpu_restore_state:
+ * @cpu: the cpu context
+ * @host_pc: the host pc within the translation
+ * @return: true if state was restored, false otherwise
+ *
+ * Attempt to restore the state for a fault occurring in translated
+ * code. If @host_pc is not in translated code no state is
+ * restored and the function returns false.
+ */
+bool cpu_restore_state(CPUState *cpu, uintptr_t host_pc);
+
 #endif
include/exec/cpu-common.h +0 -12
index ba98304c5fa..3757ab15967 100644
@@ -64,18 +64,6 @@ void list_cpus(void);
 #ifdef CONFIG_TCG
 #include "qemu/atomic.h"
 
-/**
- * cpu_restore_state:
- * @cpu: the cpu context
- * @host_pc: the host pc within the translation
- * @return: true if state was restored, false otherwise
- *
- * Attempt to restore the state for a fault occurring in translated
- * code. If @host_pc is not in translated code no state is
- * restored and the function returns false.
- */
-bool cpu_restore_state(CPUState *cpu, uintptr_t host_pc);
-
 /**
  * cpu_loop_exit_requested:
  * @cpu: The CPU state to be tested
accel/tcg/cpu-exec-common.c +1 -0
index c5c513f1e4a..e48ea31373f 100644
@@ -21,6 +21,7 @@
 #include "exec/log.h"
 #include "system/tcg.h"
 #include "qemu/plugin.h"
+#include "accel/tcg/cpu-loop.h"
 #include "internal-common.h"
 
 bool tcg_allowed;
accel/tcg/user-exec.c +1 -0
index d283d3cc724..7704e4017dd 100644
@@ -25,6 +25,7 @@
 #include "qemu/bitops.h"
 #include "qemu/rcu.h"
 #include "accel/tcg/cpu-ldst-common.h"
+#include "accel/tcg/cpu-loop.h"
 #include "accel/tcg/helper-retaddr.h"
 #include "accel/tcg/probe.h"
 #include "user/cpu_loop.h"
target/alpha/helper.c +1 -0
index 2abf07c1919..c3614ecafda 100644
@@ -28,6 +28,7 @@
 #include "exec/helper-proto.h"
 #include "qemu/qemu-print.h"
 #include "system/memory.h"
+#include "accel/tcg/cpu-loop.h"
 #include "qemu/plugin.h"
 
 
target/alpha/mem_helper.c +1 -0
index 572ea9cb418..b3988417e4b 100644
@@ -21,6 +21,7 @@
 #include "cpu.h"
 #include "exec/helper-proto.h"
 #include "accel/tcg/cpu-ldst.h"
+#include "accel/tcg/cpu-loop.h"
 
 static void do_unaligned_access(CPUAlphaState *env, vaddr addr, uintptr_t retaddr)
 {
target/arm/tcg/op_helper.c +1 -0
index 504526153a6..9f9ea39be5a 100644
@@ -23,6 +23,7 @@
 #include "helper.h"
 #include "internals.h"
 #include "cpu-features.h"
+#include "accel/tcg/cpu-loop.h"
 #include "accel/tcg/probe.h"
 #include "cpregs.h"
 
target/arm/tcg/tlb_helper.c +1 -0
index f90765cb597..2ce63734099 100644
@@ -8,6 +8,7 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
 #include "helper.h"
+#include "accel/tcg/cpu-loop.h"
 #include "internals.h"
 #include "cpu-features.h"
 
target/hppa/cpu.c +1 -0
index 6443122cf1a..a68152f9682 100644
@@ -29,6 +29,7 @@
 #include "fpu/softfloat.h"
 #include "tcg/tcg.h"
 #include "hw/hppa/hppa_hardware.h"
+#include "accel/tcg/cpu-loop.h"
 #include "accel/tcg/cpu-ops.h"
 
 static void hppa_cpu_set_pc(CPUState *cs, vaddr value)
target/hppa/mem_helper.c +1 -0
index f5076492264..01e6149c811 100644
@@ -21,6 +21,7 @@
 #include "qemu/log.h"
 #include "cpu.h"
 #include "exec/cputlb.h"
+#include "accel/tcg/cpu-loop.h"
 #include "accel/tcg/cpu-mmu-index.h"
 #include "accel/tcg/probe.h"
 #include "exec/page-protection.h"
target/hppa/op_helper.c +1 -0
index f961046e4c5..76a8d8a0d34 100644
@@ -22,6 +22,7 @@
 #include "cpu.h"
 #include "exec/helper-proto.h"
 #include "accel/tcg/cpu-ldst.h"
+#include "accel/tcg/cpu-loop.h"
 #include "accel/tcg/probe.h"
 #include "qemu/timer.h"
 #include "trace.h"
target/i386/tcg/system/svm_helper.c +1 -0
index d5ffabc2f4d..52a234e7fac 100644
@@ -23,6 +23,7 @@
 #include "exec/helper-proto.h"
 #include "exec/cputlb.h"
 #include "accel/tcg/cpu-ldst.h"
+#include "accel/tcg/cpu-loop.h"
 #include "tcg/helper-tcg.h"
 
 /* Secure Virtual Machine helpers */
target/m68k/op_helper.c +1 -0
index 8148a8852e7..38f7a689814 100644
@@ -21,6 +21,7 @@
 #include "cpu.h"
 #include "exec/helper-proto.h"
 #include "accel/tcg/cpu-ldst.h"
+#include "accel/tcg/cpu-loop.h"
 #include "semihosting/semihost.h"
 #include "qemu/plugin.h"
 
target/microblaze/helper.c +1 -0
index 6a982c18c0f..05a90f5ecb2 100644
@@ -21,6 +21,7 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
 #include "exec/cputlb.h"
+#include "accel/tcg/cpu-loop.h"
 #include "accel/tcg/cpu-mmu-index.h"
 #include "exec/page-protection.h"
 #include "exec/target_page.h"
target/ppc/tcg-excp_helper.c +1 -0
index 5e6c1e326d4..b04f07a6377 100644
@@ -21,6 +21,7 @@
 #include "qemu/log.h"
 #include "target/ppc/cpu.h"
 #include "accel/tcg/cpu-ldst.h"
+#include "accel/tcg/cpu-loop.h"
 #include "exec/helper-proto.h"
 #include "system/runstate.h"
 
target/s390x/tcg/excp_helper.c +1 -0
index 05e448d3f20..d952bb20cf1 100644
@@ -24,6 +24,7 @@
 #include "exec/helper-proto.h"
 #include "exec/cputlb.h"
 #include "exec/target_page.h"
+#include "accel/tcg/cpu-loop.h"
 #include "s390x-internal.h"
 #include "tcg_s390x.h"
 #ifndef CONFIG_USER_ONLY
target/sh4/op_helper.c +1 -0
index cf0f80e4a54..90c065b217b 100644
@@ -20,6 +20,7 @@
 #include "cpu.h"
 #include "exec/helper-proto.h"
 #include "accel/tcg/cpu-ldst.h"
+#include "accel/tcg/cpu-loop.h"
 #include "fpu/softfloat.h"
 
 #ifndef CONFIG_USER_ONLY
target/tricore/op_helper.c +1 -0
index 3cff5000c73..46b17da2bc6 100644
@@ -19,6 +19,7 @@
 #include "qemu/host-utils.h"
 #include "exec/helper-proto.h"
 #include "accel/tcg/cpu-ldst.h"
+#include "accel/tcg/cpu-loop.h"
 #include "qemu/plugin.h"
 #include <zlib.h> /* for crc32 */
 
target/xtensa/helper.c +1 -0
index 2d93b45036d..5a0e8655146 100644
@@ -32,6 +32,7 @@
 #include "exec/target_page.h"
 #include "gdbstub/helpers.h"
 #include "exec/helper-proto.h"
+#include "accel/tcg/cpu-loop.h"
 #include "qemu/error-report.h"
 #include "qemu/qemu-print.h"
 #include "qemu/host-utils.h"
Signature · 1 line
2.53.0
#8 lore raw

PATCH v2 8/11 accel/tcg: Have cpu_loop_exit_requested() take const @cpu argument

In reply to Philippe Mathieu-Daudé

Since the CPUState argument is simply read-only accessed, make it const.

---
 include/exec/cpu-common.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/exec/cpu-common.h +1 -1
index 3757ab15967..9919ffb1838 100644
@@ -76,7 +76,7 @@ void list_cpus(void);
  * call can be used to check if it makes sense to return to the main loop
  * or to continue executing the interruptible instruction.
  */
-static inline bool cpu_loop_exit_requested(CPUState *cpu)
+static inline bool cpu_loop_exit_requested(const CPUState *cpu)
 {
     return (int32_t)qatomic_read(&cpu->neg.icount_decr.u32) < 0;
 }
Signature · 1 line
2.53.0
Reviewed-by on v2 8/11
#9 lore raw

Re: [PATCH v2 08/11] accel/tcg: Have cpu_loop_exit_requested() take const @cpu argument

Quoted 12 lines · Philippe Mathieu-Daudé

Since the CPUState argument is simply read-only accessed, make it const.

---
  include/exec/cpu-common.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
include/exec/cpu-common.h +0 -0
index 3757ab15967..9919ffb1838 100644

include/exec/cpu-common.h void list_cpus(void);

Quoted 9 lines
include/exec/cpu-common.h +1 -2
@@ -76,7 +76,7 @@ void list_cpus(void);
   * call can be used to check if it makes sense to return to the main loop
   * or to continue executing the interruptible instruction.
   */
-static inline bool cpu_loop_exit_requested(CPUState *cpu)
+static inline bool cpu_loop_exit_requested(const CPUState *cpu)
  {
      return (int32_t)qatomic_read(&cpu->neg.icount_decr.u32) < 0;
  }
-- 2.53.0

r~

#10 lore raw

PATCH v2 9/11 accel/tcg: Move cpu_loop_exit_requested() out of 'exec/cpu-common.h'

In reply to Philippe Mathieu-Daudé

cpu_loop_exit_requested() is part of the TCG cpu-loop API, defined in "accel/tcg/cpu-loop.h". Ideally we'd move it declaration there, but it is defined inlined and access CPUState internal fields, itself defined in "hw/core/cpu.h". Since keeping it inlined in the 3 call sites is important, move the definition to "hw/core/cpu.h" and call it a day.

---
 include/exec/cpu-common.h     | 19 -------------------
 include/hw/core/cpu.h         | 20 ++++++++++++++++++++
 target/arm/tcg/helper-a64.c   |  1 +
 target/s390x/tcg/mem_helper.c |  1 +
 4 files changed, 22 insertions(+), 19 deletions(-)
include/exec/cpu-common.h +0 -19
index 9919ffb1838..aedd60a6986 100644
@@ -62,25 +62,6 @@ void cpu_destroy_address_spaces(CPUState *cpu);
 void list_cpus(void);
 
 #ifdef CONFIG_TCG
-#include "qemu/atomic.h"
-
-/**
- * cpu_loop_exit_requested:
- * @cpu: The CPU state to be tested
- *
- * Indicate if somebody asked for a return of the CPU to the main loop
- * (e.g., via cpu_exit() or cpu_interrupt()).
- *
- * This is helpful for architectures that support interruptible
- * instructions. After writing back all state to registers/memory, this
- * call can be used to check if it makes sense to return to the main loop
- * or to continue executing the interruptible instruction.
- */
-static inline bool cpu_loop_exit_requested(const CPUState *cpu)
-{
-    return (int32_t)qatomic_read(&cpu->neg.icount_decr.u32) < 0;
-}
-
 G_NORETURN void cpu_loop_exit_noexc(CPUState *cpu);
 G_NORETURN void cpu_loop_exit_atomic(CPUState *cpu, uintptr_t pc);
 G_NORETURN void cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc);
include/hw/core/cpu.h +20 -0
index 72666189774..eaf30d13e8e 100644
@@ -612,6 +612,26 @@ static inline CPUTLBDescFast *cpu_tlb_fast(CPUState *cpu, int mmu_idx)
 {
     return &cpu->neg.tlb.f[mmuidx_to_fast_index(mmu_idx)];
 }
+
+#include "qemu/atomic.h"
+
+/**
+ * cpu_loop_exit_requested:
+ * @cpu: The CPU state to be tested
+ *
+ * Indicate if somebody asked for a return of the CPU to the main loop
+ * (e.g., via cpu_exit() or cpu_interrupt()).
+ *
+ * This is helpful for architectures that support interruptible
+ * instructions. After writing back all state to registers/memory, this
+ * call can be used to check if it makes sense to return to the main loop
+ * or to continue executing the interruptible instruction.
+ */
+static inline bool cpu_loop_exit_requested(const CPUState *cpu)
+{
+    return (int32_t)qatomic_read(&cpu->neg.icount_decr.u32) < 0;
+}
+
 #endif
 
 typedef QTAILQ_HEAD(CPUTailQ, CPUState) CPUTailQ;
target/arm/tcg/helper-a64.c +1 -0
index a0f9215f1c9..cdac560d086 100644
@@ -43,6 +43,7 @@
 #include "user/page-protection.h"
 #endif
 #include "vec_internal.h"
+#include "hw/core/cpu.h"
 
 #define HELPER_H "tcg/helper-a64-defs.h"
 #include "exec/helper-info.c.inc"
target/s390x/tcg/mem_helper.c +1 -0
index 8474a694110..bfe0208324c 100644
@@ -43,6 +43,7 @@
 #include "hw/core/boards.h"
 #include "system/memory.h"
 #endif
+#include "hw/core/cpu.h"
 
 #ifdef CONFIG_USER_ONLY
 # define user_or_likely(X)    true
Signature · 1 line
2.53.0
#11 lore raw

Re: [PATCH v2 09/11] accel/tcg: Move cpu_loop_exit_requested() out of 'exec/cpu-common.h'

Quoted 50 lines · Philippe Mathieu-Daudé

cpu_loop_exit_requested() is part of the TCG cpu-loop API, defined in "accel/tcg/cpu-loop.h". Ideally we'd move it declaration there, but it is defined inlined and access CPUState internal fields, itself defined in "hw/core/cpu.h". Since keeping it inlined in the 3 call sites is important, move the definition to "hw/core/cpu.h" and call it a day.

---
  include/exec/cpu-common.h     | 19 -------------------
  include/hw/core/cpu.h         | 20 ++++++++++++++++++++
  target/arm/tcg/helper-a64.c   |  1 +
  target/s390x/tcg/mem_helper.c |  1 +
  4 files changed, 22 insertions(+), 19 deletions(-)
include/exec/cpu-common.h +0 -19
index 9919ffb1838..aedd60a6986 100644
@@ -62,25 +62,6 @@ void cpu_destroy_address_spaces(CPUState *cpu);
  void list_cpus(void);
 
  #ifdef CONFIG_TCG
-#include "qemu/atomic.h"
-
-/**
- * cpu_loop_exit_requested:
- * @cpu: The CPU state to be tested
- *
- * Indicate if somebody asked for a return of the CPU to the main loop
- * (e.g., via cpu_exit() or cpu_interrupt()).
- *
- * This is helpful for architectures that support interruptible
- * instructions. After writing back all state to registers/memory, this
- * call can be used to check if it makes sense to return to the main loop
- * or to continue executing the interruptible instruction.
- */
-static inline bool cpu_loop_exit_requested(const CPUState *cpu)
-{
-    return (int32_t)qatomic_read(&cpu->neg.icount_decr.u32) < 0;
-}
-
  G_NORETURN void cpu_loop_exit_noexc(CPUState *cpu);
  G_NORETURN void cpu_loop_exit_atomic(CPUState *cpu, uintptr_t pc);
  G_NORETURN void cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc);
include/hw/core/cpu.h +0 -0
index 72666189774..eaf30d13e8e 100644

include/hw/core/cpu.h static inline CPUTLBDescFast *cpu_tlb_fast(CPUState *cpu, int mmu_idx) · line 616

Quoted 5 lines
include/hw/core/cpu.h +2 -0
@@ -612,6 +612,26 @@ static inline CPUTLBDescFast *cpu_tlb_fast(CPUState *cpu, int mmu_idx)
  {
      return &cpu->neg.tlb.f[mmuidx_to_fast_index(mmu_idx)];
  }
+
+#include "qemu/atomic.h"

We already use qatomic_load_acquire within this header (without including atomic.h). Just put the include properly at the top of the file.

Quoted 16 lines
target/arm/tcg/helper-a64.c +1 -0
index a0f9215f1c9..cdac560d086 100644
@@ -43,6 +43,7 @@
  #include "user/page-protection.h"
  #endif
  #include "vec_internal.h"
+#include "hw/core/cpu.h">
  #define HELPER_H "tcg/helper-a64-defs.h"
  #include "exec/helper-info.c.inc"
target/s390x/tcg/mem_helper.c +0 -0
index 8474a694110..bfe0208324c 100644

target/s390x/tcg/mem_helper.c line 49

Quoted 7 lines
target/s390x/tcg/mem_helper.c +1 -0
@@ -43,6 +43,7 @@
  #include "hw/core/boards.h"
  #include "system/memory.h"
  #endif
+#include "hw/core/cpu.h"
 
  #ifdef CONFIG_USER_ONLY
  # define user_or_likely(X)    true

Do we honestly need these? This *must* have been done by target/arch/cpu.h.

r~

#12 lore raw

PATCH v2 10/11 accel/tcg: Move cpu_loop_exit_*() out of 'exec/cpu-common.h'

In reply to Philippe Mathieu-Daudé

Move the following TCG-specific cpu_loop_exit_*() declarations out of the generic "exec/cpu-common.h" header, to the recently created "accel/tcg/cpu-loop.h" one, documenting them:

- cpu_loop_exit_noexc()
- cpu_loop_exit_atomic()
- cpu_loop_exit_restore()
- cpu_loop_exit()

Include "accel/tcg/cpu-loop.h" where appropriate.

---
 include/accel/tcg/cpu-loop.h         | 30 ++++++++++++++++++++++++++++
 include/exec/cpu-common.h            |  7 -------
 accel/tcg/cputlb.c                   |  1 +
 accel/tcg/tb-maint.c                 |  1 +
 accel/tcg/tcg-runtime.c              |  1 +
 accel/tcg/watchpoint.c               |  1 +
 hw/misc/mips_itu.c                   |  1 +
 plugins/api.c                        |  1 +
 semihosting/console.c                |  1 +
 target/arm/tcg/helper-a64.c          |  1 +
 target/avr/helper.c                  |  1 +
 target/hexagon/op_helper.c           |  1 +
 target/i386/tcg/excp_helper.c        |  1 +
 target/i386/tcg/misc_helper.c        |  1 +
 target/i386/tcg/system/bpt_helper.c  |  1 +
 target/i386/tcg/system/misc_helper.c |  1 +
 target/i386/tcg/user/excp_helper.c   |  1 +
 target/i386/tcg/user/seg_helper.c    |  1 +
 target/loongarch/tcg/tcg_cpu.c       |  1 +
 target/loongarch/tcg/tlb_helper.c    |  1 +
 target/m68k/helper.c                 |  1 +
 target/microblaze/op_helper.c        |  1 +
 target/mips/tcg/exception.c          |  1 +
 target/mips/tcg/system/tlb_helper.c  |  1 +
 target/or1k/exception_helper.c       |  1 +
 target/or1k/fpu_helper.c             |  1 +
 target/or1k/mmu.c                    |  1 +
 target/ppc/user_only_helper.c        |  1 +
 target/riscv/cpu_helper.c            |  1 +
 target/riscv/op_helper.c             |  1 +
 target/rx/op_helper.c                |  1 +
 target/s390x/mmu_helper.c            |  3 +++
 target/s390x/tcg/cc_helper.c         |  1 +
 target/s390x/tcg/debug.c             |  1 +
 target/s390x/tcg/mem_helper.c        |  1 +
 target/s390x/tcg/misc_helper.c       |  1 +
 target/sh4/helper.c                  |  1 +
 target/sparc/helper.c                |  1 +
 target/sparc/mmu_helper.c            |  1 +
 target/tricore/helper.c              |  1 +
 target/xtensa/exc_helper.c           |  1 +
 41 files changed, 71 insertions(+), 7 deletions(-)
include/accel/tcg/cpu-loop.h +30 -0
index 2fc38c8f1c4..8559e99efaf 100644
@@ -5,6 +5,8 @@
 #error Can only include this header with TCG
 #endif
 
+#include "qemu/atomic.h"
+
 /**
  * cpu_exec:
  * @cpu: the cpu context
@@ -40,4 +42,32 @@ bool cpu_unwind_state_data(CPUState *cpu, uintptr_t host_pc, uint64_t *data);
  */
 bool cpu_restore_state(CPUState *cpu, uintptr_t host_pc);
 
+/**
+ * cpu_loop_exit_noexc:
+ * @cpu: the cpu context
+ *
+ * Exit the current TB, but without causing any exception to be raised.
+ */
+G_NORETURN void cpu_loop_exit_noexc(CPUState *cpu);
+
+/**
+ * cpu_loop_exit_restore:
+ * @cpu: the cpu context
+ * @host_pc: the host pc within the translation
+ *
+ * Attempt to restore the state for a fault occurring in translated
+ * code. If @host_pc is not in translated code no state is
+ * restored. Finally, exit the current TB.
+ */
+G_NORETURN void cpu_loop_exit_restore(CPUState *cpu, uintptr_t host_pc);
+G_NORETURN void cpu_loop_exit_atomic(CPUState *cpu, uintptr_t host_pc);
+
+/**
+ * cpu_loop_exit:
+ * @cpu: the cpu context
+ *
+ * Exit the current TB.
+ */
+G_NORETURN void cpu_loop_exit(CPUState *cpu);
+
 #endif
include/exec/cpu-common.h +0 -7
index aedd60a6986..da359ee3128 100644
@@ -61,13 +61,6 @@ void cpu_destroy_address_spaces(CPUState *cpu);
 /* vl.c */
 void list_cpus(void);
 
-#ifdef CONFIG_TCG
-G_NORETURN void cpu_loop_exit_noexc(CPUState *cpu);
-G_NORETURN void cpu_loop_exit_atomic(CPUState *cpu, uintptr_t pc);
-G_NORETURN void cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc);
-#endif /* CONFIG_TCG */
-G_NORETURN void cpu_loop_exit(CPUState *cpu);
-
 /**
  * env_archcpu(env)
  * @env: The architecture environment
accel/tcg/cputlb.c +1 -0
index 31c8351231a..6860ac97081 100644
@@ -20,6 +20,7 @@
 #include "qemu/osdep.h"
 #include "qemu/main-loop.h"
 #include "qemu/target-info.h"
+#include "accel/tcg/cpu-loop.h"
 #include "accel/tcg/cpu-ops.h"
 #include "accel/tcg/iommu.h"
 #include "accel/tcg/probe.h"
accel/tcg/tb-maint.c +1 -0
index 0c7ac5a72c0..d9801a34275 100644
@@ -26,6 +26,7 @@
 #include "exec/mmap-lock.h"
 #include "exec/tb-flush.h"
 #include "exec/target_page.h"
+#include "accel/tcg/cpu-loop.h"
 #include "accel/tcg/cpu-ops.h"
 #include "tb-internal.h"
 #include "system/tcg.h"
accel/tcg/tcg-runtime.c +1 -0
index f483c9c2ba2..7c0aab98a80 100644
@@ -25,6 +25,7 @@
 #include "qemu/host-utils.h"
 #include "exec/cpu-common.h"
 #include "exec/helper-proto-common.h"
+#include "accel/tcg/cpu-loop.h"
 #include "accel/tcg/getpc.h"
 
 #define HELPER_H  "accel/tcg/tcg-runtime.h"
accel/tcg/watchpoint.c +1 -0
index cfb37a49e72..c75ed278459 100644
@@ -25,6 +25,7 @@
 #include "exec/translation-block.h"
 #include "system/tcg.h"
 #include "system/replay.h"
+#include "accel/tcg/cpu-loop.h"
 #include "accel/tcg/cpu-ops.h"
 #include "hw/core/cpu.h"
 #include "internal-common.h"
hw/misc/mips_itu.c +1 -0
index 82c0a90f704..c20eca28a1e 100644
@@ -25,6 +25,7 @@
 #include "hw/core/cpu.h"
 #include "hw/misc/mips_itu.h"
 #include "hw/core/qdev-properties.h"
+#include "accel/tcg/cpu-loop.h"
 #include "target/mips/cpu.h"
 
 #define ITC_TAG_ADDRSPACE_SZ (ITC_ADDRESSMAP_NUM * 8)
plugins/api.c +1 -0
index 2d5fe9327f7..690b5994f62 100644
@@ -40,6 +40,7 @@
 #include "qemu/plugin.h"
 #include "qemu/log.h"
 #include "system/memory.h"
+#include "accel/tcg/cpu-loop.h"
 #include "tcg/tcg.h"
 #include "exec/cpu-common.h"
 #include "exec/gdbstub.h"
semihosting/console.c +1 -0
index a4db8d8e76d..91e5d50d502 100644
@@ -18,6 +18,7 @@
 #include "qemu/osdep.h"
 #include "semihosting/semihost.h"
 #include "semihosting/console.h"
+#include "accel/tcg/cpu-loop.h"
 #include "exec/cpu-common.h"
 #include "exec/gdbstub.h"
 #include "qemu/log.h"
target/arm/tcg/helper-a64.c +1 -0
index cdac560d086..ca8cfc6c9a3 100644
@@ -31,6 +31,7 @@
 #include "qemu/crc32c.h"
 #include "exec/cpu-common.h"
 #include "accel/tcg/cpu-ldst.h"
+#include "accel/tcg/cpu-loop.h"
 #include "accel/tcg/helper-retaddr.h"
 #include "accel/tcg/probe.h"
 #include "exec/target_page.h"
target/avr/helper.c +1 -0
index f3be8483b27..f452c9d9040 100644
@@ -23,6 +23,7 @@
 #include "qemu/error-report.h"
 #include "cpu.h"
 #include "accel/tcg/cpu-ops.h"
+#include "accel/tcg/cpu-loop.h"
 #include "exec/cputlb.h"
 #include "exec/page-protection.h"
 #include "exec/target_page.h"
target/hexagon/op_helper.c +1 -0
index 368391bb846..0a946433644 100644
@@ -18,6 +18,7 @@
 #include "qemu/osdep.h"
 #include "qemu/log.h"
 #include "accel/tcg/cpu-ldst.h"
+#include "accel/tcg/cpu-loop.h"
 #include "accel/tcg/probe.h"
 #include "exec/helper-proto.h"
 #include "fpu/softfloat.h"
target/i386/tcg/excp_helper.c +1 -0
index 32f2784e923..1eaa602c91d 100644
@@ -18,6 +18,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "accel/tcg/cpu-loop.h"
 #include "cpu.h"
 #include "qemu/log.h"
 #include "system/runstate.h"
target/i386/tcg/misc_helper.c +1 -0
index 2b5f092a23f..f7342871ded 100644
@@ -19,6 +19,7 @@
 
 #include "qemu/osdep.h"
 #include "qemu/log.h"
+#include "accel/tcg/cpu-loop.h"
 #include "cpu.h"
 #include "exec/helper-proto.h"
 #include "exec/cputlb.h"
target/i386/tcg/system/bpt_helper.c +1 -0
index aebb5caac37..2feea69c8a1 100644
@@ -18,6 +18,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "accel/tcg/cpu-loop.h"
 #include "cpu.h"
 #include "exec/helper-proto.h"
 #include "exec/watchpoint.h"
target/i386/tcg/system/misc_helper.c +1 -0
index bb79d4e470e..2998b1aae75 100644
@@ -22,6 +22,7 @@
 #include "cpu.h"
 #include "exec/helper-proto.h"
 #include "accel/tcg/cpu-ldst.h"
+#include "accel/tcg/cpu-loop.h"
 #include "system/address-spaces.h"
 #include "system/memory.h"
 #include "exec/cputlb.h"
target/i386/tcg/user/excp_helper.c +1 -0
index 6c5df5e0e88..0957ad2e9ec 100644
@@ -18,6 +18,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "accel/tcg/cpu-loop.h"
 #include "cpu.h"
 #include "tcg/helper-tcg.h"
 
target/i386/tcg/user/seg_helper.c +1 -0
index 28bbef1bbae..3a4a6d5a745 100644
@@ -22,6 +22,7 @@
 #include "cpu.h"
 #include "exec/helper-proto.h"
 #include "accel/tcg/cpu-ldst.h"
+#include "accel/tcg/cpu-loop.h"
 #include "tcg/helper-tcg.h"
 #include "tcg/seg_helper.h"
 
target/loongarch/tcg/tcg_cpu.c +1 -0
index f556234d9d2..8dc4bb15a1d 100644
@@ -10,6 +10,7 @@
 #include "qemu/log.h"
 #include "qemu/plugin.h"
 #include "accel/tcg/cpu-ldst.h"
+#include "accel/tcg/cpu-loop.h"
 #include "accel/tcg/cpu-ops.h"
 #include "exec/translation-block.h"
 #include "exec/target_page.h"
target/loongarch/tcg/tlb_helper.c +1 -0
index 7623f4f9bdb..a4b90beca65 100644
@@ -17,6 +17,7 @@
 #include "exec/page-protection.h"
 #include "exec/target_page.h"
 #include "accel/tcg/cpu-ldst.h"
+#include "accel/tcg/cpu-loop.h"
 #include "exec/log.h"
 #include "cpu-csr.h"
 #include "tcg/tcg_loongarch.h"
target/m68k/helper.c +1 -0
index 2dd9ec1bdcb..5f91d206f59 100644
@@ -25,6 +25,7 @@
 #include "exec/target_page.h"
 #include "exec/gdbstub.h"
 #include "exec/helper-proto.h"
+#include "accel/tcg/cpu-loop.h"
 #include "system/memory.h"
 #include "gdbstub/helpers.h"
 #include "fpu/softfloat.h"
target/microblaze/op_helper.c +1 -0
index 84c60c2636e..3da0c68da39 100644
@@ -24,6 +24,7 @@
 #include "exec/helper-proto.h"
 #include "qemu/host-utils.h"
 #include "accel/tcg/cpu-ldst-common.h"
+#include "accel/tcg/cpu-loop.h"
 #include "fpu/softfloat.h"
 
 void helper_put(uint32_t id, uint32_t ctrl, uint32_t data)
target/mips/tcg/exception.c +1 -0
index d32bcebf469..630b8b809fa 100644
@@ -24,6 +24,7 @@
 #include "internal.h"
 #include "exec/helper-proto.h"
 #include "exec/translation-block.h"
+#include "accel/tcg/cpu-loop.h"
 
 target_ulong exception_resume_pc(CPUMIPSState *env)
 {
target/mips/tcg/system/tlb_helper.c +1 -0
index c850ddd9650..4398c6f80b4 100644
@@ -26,6 +26,7 @@
 #include "exec/page-protection.h"
 #include "exec/target_page.h"
 #include "accel/tcg/cpu-ldst.h"
+#include "accel/tcg/cpu-loop.h"
 #include "exec/log.h"
 #include "exec/helper-proto.h"
 
target/or1k/exception_helper.c +1 -0
index 3e76acae9c3..eeb82bc49f4 100644
@@ -18,6 +18,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "accel/tcg/cpu-loop.h"
 #include "exec/helper-proto.h"
 
 #include "target/or1k/cpu.h"
target/or1k/fpu_helper.c +1 -0
index 39b6195dd7d..e680606d4da 100644
@@ -19,6 +19,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "accel/tcg/cpu-loop.h"
 #include "cpu.h"
 #include "exec/helper-proto.h"
 #include "fpu/softfloat.h"
target/or1k/mmu.c +1 -0
index 3ff288a1f94..3fc56e1b771 100644
@@ -24,6 +24,7 @@
 #include "exec/cputlb.h"
 #include "exec/page-protection.h"
 #include "exec/target_page.h"
+#include "accel/tcg/cpu-loop.h"
 #include "qemu/host-utils.h"
 #include "hw/core/loader.h"
 
target/ppc/user_only_helper.c +1 -0
index ae210eb8474..cc6d7ee88aa 100644
@@ -19,6 +19,7 @@
  */
 
 #include "qemu/osdep.h"
+#include "accel/tcg/cpu-loop.h"
 #include "cpu.h"
 #include "internal.h"
 
target/riscv/cpu_helper.c +1 -0
index 17305e1bb75..97fea4d0c7e 100644
@@ -29,6 +29,7 @@
 #include "system/memory.h"
 #include "instmap.h"
 #include "tcg/tcg-op.h"
+#include "accel/tcg/cpu-loop.h"
 #include "accel/tcg/cpu-ops.h"
 #include "trace.h"
 #include "semihosting/common-semi.h"
target/riscv/op_helper.c +1 -0
index 81873014cb8..987ef67d177 100644
@@ -23,6 +23,7 @@
 #include "internals.h"
 #include "exec/cputlb.h"
 #include "accel/tcg/cpu-ldst.h"
+#include "accel/tcg/cpu-loop.h"
 #include "accel/tcg/probe.h"
 #include "exec/helper-proto.h"
 #include "exec/tlb-flags.h"
target/rx/op_helper.c +1 -0
index ca3e9e85fc7..36df7d377e5 100644
@@ -21,6 +21,7 @@
 #include "cpu.h"
 #include "exec/helper-proto.h"
 #include "accel/tcg/cpu-ldst.h"
+#include "accel/tcg/cpu-loop.h"
 #include "fpu/softfloat.h"
 #include "tcg/debug-assert.h"
 
target/s390x/mmu_helper.c +3 -0
index 255271b9d34..2f886d424a1 100644
@@ -24,6 +24,9 @@
 #include "system/kvm.h"
 #include "system/tcg.h"
 #include "system/memory.h"
+#ifdef CONFIG_TCG
+#include "accel/tcg/cpu-loop.h"
+#endif
 #include "exec/page-protection.h"
 #include "exec/target_page.h"
 #include "hw/core/hw-error.h"
target/s390x/tcg/cc_helper.c +1 -0
index 6595ac763c3..e538a75d713 100644
@@ -20,6 +20,7 @@
 
 #include "qemu/osdep.h"
 #include "cpu.h"
+#include "accel/tcg/cpu-loop.h"
 #include "s390x-internal.h"
 #include "tcg_s390x.h"
 #include "exec/helper-proto.h"
target/s390x/tcg/debug.c +1 -0
index 50d2853d443..99140b1ac9a 100644
@@ -7,6 +7,7 @@
 #include "qemu/osdep.h"
 #include "exec/breakpoint.h"
 #include "exec/watchpoint.h"
+#include "accel/tcg/cpu-loop.h"
 #include "target/s390x/cpu.h"
 #include "target/s390x/s390x-internal.h"
 #include "tcg_s390x.h"
target/s390x/tcg/mem_helper.c +1 -0
index bfe0208324c..ecdecd5102f 100644
@@ -28,6 +28,7 @@
 #include "exec/cputlb.h"
 #include "exec/page-protection.h"
 #include "accel/tcg/cpu-ldst.h"
+#include "accel/tcg/cpu-loop.h"
 #include "accel/tcg/probe.h"
 #include "exec/target_page.h"
 #include "exec/tlb-flags.h"
target/s390x/tcg/misc_helper.c +1 -0
index 036be93fb32..09a45e58a5d 100644
@@ -28,6 +28,7 @@
 #include "qemu/timer.h"
 #include "exec/cputlb.h"
 #include "accel/tcg/cpu-ldst-common.h"
+#include "accel/tcg/cpu-loop.h"
 #include "accel/tcg/cpu-mmu-index.h"
 #include "exec/target_page.h"
 #include "qapi/error.h"
target/sh4/helper.c +1 -0
index b3ec7ce64d0..b6b057f104b 100644
@@ -24,6 +24,7 @@
 #include "exec/page-protection.h"
 #include "exec/target_page.h"
 #include "exec/log.h"
+#include "accel/tcg/cpu-loop.h"
 #include "qemu/plugin.h"
 
 #if !defined(CONFIG_USER_ONLY)
target/sparc/helper.c +1 -0
index c5d88de37c9..8de261b0e30 100644
@@ -21,6 +21,7 @@
 #include "cpu.h"
 #include "qemu/timer.h"
 #include "qemu/host-utils.h"
+#include "accel/tcg/cpu-loop.h"
 #include "exec/cpu-common.h"
 #include "exec/helper-proto.h"
 
target/sparc/mmu_helper.c +1 -0
index e441ffb8f7e..07ba25dfcea 100644
@@ -21,6 +21,7 @@
 #include "qemu/log.h"
 #include "cpu.h"
 #include "exec/cputlb.h"
+#include "accel/tcg/cpu-loop.h"
 #include "accel/tcg/cpu-mmu-index.h"
 #include "exec/page-protection.h"
 #include "exec/target_page.h"
target/tricore/helper.c +1 -0
index ce1693622b7..273713a1473 100644
@@ -20,6 +20,7 @@
 #include "hw/core/registerfields.h"
 #include "cpu.h"
 #include "exec/cputlb.h"
+#include "accel/tcg/cpu-loop.h"
 #include "accel/tcg/cpu-mmu-index.h"
 #include "exec/page-protection.h"
 #include "exec/target_page.h"
target/xtensa/exc_helper.c +1 -0
index fdc522698dc..7cb67d179a8 100644
@@ -28,6 +28,7 @@
 #include "qemu/osdep.h"
 #include "qemu/log.h"
 #include "qemu/main-loop.h"
+#include "accel/tcg/cpu-loop.h"
 #include "cpu.h"
 #include "exec/helper-proto.h"
 #include "qemu/host-utils.h"
Signature · 1 line
2.53.0
#13 lore raw

PATCH v2 11/11 accel/tcg: Restrict headers being TCG specific

In reply to Philippe Mathieu-Daudé

Forbid including TCG-specific headers in non-TCG builds.

---
 include/accel/tcg/cpu-mmu-index.h  | 4 ++++
 include/accel/tcg/cpu-ops.h        | 4 ++++
 include/accel/tcg/getpc.h          | 4 ++++
 include/accel/tcg/helper-retaddr.h | 4 ++++
 include/accel/tcg/probe.h          | 4 ++++
 include/accel/tcg/tb-cpu-state.h   | 4 ++++
 6 files changed, 24 insertions(+)
include/accel/tcg/cpu-mmu-index.h +4 -0
index e681a90844c..e0fb6ef91c8 100644
@@ -9,6 +9,10 @@
 #ifndef ACCEL_TCG_CPU_MMU_INDEX_H
 #define ACCEL_TCG_CPU_MMU_INDEX_H
 
+#ifndef CONFIG_TCG
+#error Can only include this header with TCG
+#endif
+
 #include "hw/core/cpu.h"
 #include "accel/tcg/cpu-ops.h"
 #include "tcg/debug-assert.h"
include/accel/tcg/cpu-ops.h +4 -0
index 5950cdcaab1..710da12b828 100644
@@ -10,6 +10,10 @@
 #ifndef TCG_CPU_OPS_H
 #define TCG_CPU_OPS_H
 
+#ifndef CONFIG_TCG
+#error Can only include this header with TCG
+#endif
+
 #include "exec/breakpoint.h"
 #include "exec/hwaddr.h"
 #include "exec/memattrs.h"
include/accel/tcg/getpc.h +4 -0
index 0fc08addcf3..8a97ce34e76 100644
@@ -8,6 +8,10 @@
 #ifndef ACCEL_TCG_GETPC_H
 #define ACCEL_TCG_GETPC_H
 
+#ifndef CONFIG_TCG
+#error Can only include this header with TCG
+#endif
+
 /* GETPC is the true target of the return instruction that we'll execute.  */
 #ifdef CONFIG_TCG_INTERPRETER
 extern __thread uintptr_t tci_tb_ptr;
include/accel/tcg/helper-retaddr.h +4 -0
index 037fda2b83d..ebdc8b378d4 100644
@@ -6,6 +6,10 @@
 #ifndef ACCEL_TCG_HELPER_RETADDR_H
 #define ACCEL_TCG_HELPER_RETADDR_H
 
+#ifndef CONFIG_TCG
+#error Can only include this header with TCG
+#endif
+
 /*
  * For user-only, helpers that use guest to host address translation
  * must protect the actual host memory access by recording 'retaddr'
include/accel/tcg/probe.h +4 -0
index dd9ecbbdf11..0b788901ba0 100644
@@ -7,6 +7,10 @@
 #ifndef ACCEL_TCG_PROBE_H
 #define ACCEL_TCG_PROBE_H
 
+#ifndef CONFIG_TCG
+#error Can only include this header with TCG
+#endif
+
 #include "exec/mmu-access-type.h"
 #include "exec/vaddr.h"
 
include/accel/tcg/tb-cpu-state.h +4 -0
index 8f912900ca6..1903af4c2a2 100644
@@ -6,6 +6,10 @@
 #ifndef EXEC_TB_CPU_STATE_H
 #define EXEC_TB_CPU_STATE_H
 
+#ifndef CONFIG_TCG
+#error Can only include this header with TCG
+#endif
+
 #include "exec/vaddr.h"
 
 typedef struct TCGTBCPUState {
Signature · 1 line
2.53.0
#14 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 4 lines · Philippe Mathieu-Daudé

Philippe Mathieu-Daudé (11):
target/arm: Restrict TCG specific headers hw/s390x/ipl: Remove TCG dependency in handle_diag_308() accel/tcg: Remove cpu_loop_exit() stub

Quoted 8 lines

accel/tcg: Move cpu_exec() out of 'exec/cpu-common.h' accel/tcg: Move cpu_exec_step_atomic() out of 'exec/cpu-common.h' accel/tcg: Move cpu_unwind_state_data() out of 'exec/cpu-common.h' accel/tcg: Move cpu_restore_state() out of 'exec/cpu-common.h' accel/tcg: Have cpu_loop_exit_requested() take const @cpu argument accel/tcg: Move cpu_loop_exit_requested() out of 'exec/cpu-common.h' accel/tcg: Move cpu_loop_exit_*() out of 'exec/cpu-common.h' accel/tcg: Restrict headers being TCG specific

Queued except #9, thanks.