Skip to contentSkip to conversation

exec: Rework of various headers (user focused)

PATCH In review Philippe Mathieu-Daudé 3 participants 36 messages Dec 12, 2023 – Dec 14, 2023

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

v2 cover exec: Rework of various headers (user focused)

Hi,

These patches are extracted from a bigger work where "exec/{exec,cpu,translate}-all.h" are split in various specific APIs. This helped:
- differenciate/build:
. user VS system
. target-specific VS generic
which is necessary for heterogeneous build
- reduced header pressure
- clarify APIs

This series is focused on user (vs system) cleanups. More useful changes will come after.

Since v1:
- Addressed Richard comments
- Added R-b tags

Regards,

Phil.

Philippe Mathieu-Daudé (23):
exec: Include 'cpu.h' before validating CPUArchState placement
exec: Expose 'target_page.h' API to user emulation
target: Define TCG_GUEST_DEFAULT_MO in 'cpu-param.h'
accel: Include missing 'exec/cpu_ldst.h' header
gdbstub: Include missing 'hw/core/cpu.h' header semihosting/uaccess: Avoid including 'cpu.h' semihosting/guestfd: Remove unused 'semihosting/uaccess.h' header host/load-extract: Include missing 'qemu/atomic.h' and 'qemu/int128.h' host/atomic128: Include missing 'qemu/atomic.h' header target/i386: Include missing 'exec/exec-all.h' header accel/tcg: Include missing 'hw/core/cpu.h' header exec/cpu-all: Remove unused 'qemu/thread.h' header exec/cpu-all: Reduce 'qemu/rcu.h' header inclusion exec/cpu-all: Remove unused tswapls() definitions
exec: Declare target_words_bigendian() in 'exec/tswap.h'
exec: Move [b]tswapl() declarations to 'exec/user/tswap-target.h' target/ppc/excp_helper: Avoid 'abi_ptr' in system emulation accel/tcg: Un-inline retaddr helpers to 'user-retaddr.h' exec/user: Do not include 'cpu.h' in 'abitypes.h'
exec: Declare abi_ptr type in its own 'abi_ptr.h' header exec/cpu-all: Restrict inclusion of 'exec/user/guest-base.h' exec/cpu-all: Extract page-protection definitions to
page-prot-common.h
exec/cpu_ldst: Avoid including 'cpu.h'

 meson.build                                   |  2 +-
 accel/tcg/user-retaddr.h                      | 28 +++++++++
 bsd-user/bsd-mem.h                            |  1 +
 bsd-user/freebsd/target_os_elf.h              |  1 +
 bsd-user/freebsd/target_os_stack.h            |  1 +
 bsd-user/netbsd/target_os_elf.h               |  1 +
 bsd-user/openbsd/target_os_elf.h              |  1 +
 bsd-user/qemu.h                               |  1 +
 host/include/generic/host/atomic128-cas.h     |  2 +
 host/include/generic/host/atomic128-ldst.h    |  2 +
 .../generic/host/load-extract-al16-al8.h      |  3 +
 include/exec/abi_ptr.h                        | 33 +++++++++++
 include/exec/cpu-all.h                        | 59 ++-----------------
 include/exec/cpu_ldst.h                       | 52 ++++------------
 include/exec/exec-all.h                       |  1 +
 include/exec/page-prot-common.h               | 38 ++++++++++++
 include/exec/ram_addr.h                       |  1 +
 include/exec/translator.h                     |  5 +-
 include/exec/tswap.h                          | 12 +++-
 include/exec/user/abitypes.h                  |  8 ++-
 include/exec/user/guest-base.h                |  6 ++
 include/exec/user/tswap-target.h              | 22 +++++++
 include/hw/core/cpu.h                         | 11 ----
 include/semihosting/uaccess.h                 |  3 +-
 target/alpha/cpu-param.h                      |  3 +
 target/alpha/cpu.h                            |  3 -
 target/arm/cpu-param.h                        |  8 ++-
 target/arm/cpu.h                              |  4 +-
 target/avr/cpu-param.h                        |  2 +
 target/avr/cpu.h                              |  2 -
 target/hppa/cpu-param.h                       |  8 +++
 target/hppa/cpu.h                             |  6 --
 target/i386/cpu-param.h                       |  3 +
 target/i386/cpu.h                             |  3 -
 target/loongarch/cpu-param.h                  |  2 +
 target/loongarch/cpu.h                        |  2 -
 target/microblaze/cpu-param.h                 |  3 +
 target/microblaze/cpu.h                       |  3 -
 target/mips/cpu-param.h                       |  2 +
 target/mips/cpu.h                             |  2 -
 target/openrisc/cpu-param.h                   |  2 +
 target/openrisc/cpu.h                         |  2 -
 target/ppc/cpu-param.h                        |  2 +
 target/ppc/cpu.h                              |  2 -
 target/ppc/internal.h                         |  1 +
 target/ppc/mmu-radix64.h                      |  2 +
 target/riscv/cpu-param.h                      |  2 +
 target/riscv/cpu.h                            |  2 -
 target/s390x/cpu-param.h                      |  6 ++
 target/s390x/cpu.h                            |  3 -
 target/sparc/cpu-param.h                      | 23 ++++++++
 target/sparc/cpu.h                            | 23 --------
 target/xtensa/cpu-param.h                     |  3 +
 target/xtensa/cpu.h                           |  3 -
 accel/tcg/cpu-exec.c                          |  3 +
 accel/tcg/cputlb.c                            |  2 +
 accel/tcg/tb-maint.c                          |  1 +
 accel/tcg/tcg-accel-ops.c                     |  2 +
 accel/tcg/translator.c                        |  1 +
 accel/tcg/user-exec.c                         |  2 +
 bsd-user/main.c                               |  1 +
 bsd-user/mmap.c                               |  1 +
 bsd-user/signal.c                             |  2 +
 bsd-user/strace.c                             |  1 +
 cpu-target.c                                  |  2 +
 disas/disas.c                                 |  1 +
 gdbstub/gdbstub.c                             |  1 +
 hw/audio/virtio-snd.c                         |  2 +-
 hw/core/cpu-sysemu.c                          |  2 +-
 hw/core/generic-loader.c                      |  2 +-
 hw/display/vga.c                              |  2 +-
 hw/ppc/ppc440_bamboo.c                        |  1 +
 hw/ppc/sam460ex.c                             |  1 +
 hw/ppc/virtex_ml507.c                         |  1 +
 hw/virtio/virtio.c                            |  1 +
 linux-user/arm/cpu_loop.c                     |  1 +
 linux-user/elfload.c                          |  3 +
 linux-user/i386/signal.c                      |  1 +
 linux-user/main.c                             |  1 +
 linux-user/mmap.c                             |  1 +
 linux-user/nios2/cpu_loop.c                   |  1 +
 linux-user/ppc/signal.c                       |  1 +
 linux-user/signal.c                           |  1 +
 linux-user/syscall.c                          |  1 +
 page-target.c                                 | 43 ++++++++++++++
 semihosting/guestfd.c                         |  5 +-
 system/physmem.c                              | 36 +----------
 target/alpha/helper.c                         |  1 +
 target/arm/ptw.c                              |  1 +
 target/arm/tcg/m_helper.c                     |  1 +
 target/arm/tcg/mte_helper.c                   |  1 +
 target/arm/tcg/sve_helper.c                   |  1 +
 target/avr/helper.c                           |  1 +
 target/cris/mmu.c                             |  1 +
 target/hexagon/translate.c                    |  1 +
 target/hppa/mem_helper.c                      |  1 +
 target/hppa/translate.c                       |  1 +
 target/i386/tcg/fpu_helper.c                  |  1 +
 target/i386/tcg/sysemu/excp_helper.c          |  1 +
 target/loongarch/tlb_helper.c                 |  1 +
 target/m68k/helper.c                          |  1 +
 target/microblaze/cpu.c                       |  1 +
 target/microblaze/helper.c                    |  1 +
 target/microblaze/mmu.c                       |  1 +
 target/microblaze/translate.c                 |  1 +
 target/mips/sysemu/physaddr.c                 |  1 +
 target/mips/tcg/sysemu/tlb_helper.c           |  1 +
 target/nios2/helper.c                         |  1 +
 target/nios2/mmu.c                            |  1 +
 target/nios2/translate.c                      |  1 +
 target/openrisc/mmu.c                         |  1 +
 target/ppc/excp_helper.c                      |  2 +-
 target/ppc/mmu-hash32.c                       |  1 +
 target/ppc/mmu-hash64.c                       |  1 +
 target/ppc/mmu-radix64.c                      |  1 +
 target/ppc/mmu_common.c                       |  1 +
 target/ppc/mmu_helper.c                       |  1 +
 target/riscv/cpu_helper.c                     |  1 +
 target/riscv/pmp.c                            |  1 +
 target/riscv/vector_helper.c                  |  1 +
 target/rx/cpu.c                               |  1 +
 target/s390x/mmu_helper.c                     |  1 +
 target/s390x/tcg/mem_helper.c                 |  1 +
 target/sh4/helper.c                           |  1 +
 target/sparc/ldst_helper.c                    |  1 +
 target/sparc/mmu_helper.c                     |  1 +
 target/tricore/helper.c                       |  1 +
 target/xtensa/mmu_helper.c                    |  1 +
 target/xtensa/op_helper.c                     |  1 +
 129 files changed, 380 insertions(+), 216 deletions(-)
 create mode 100644 accel/tcg/user-retaddr.h
 create mode 100644 include/exec/abi_ptr.h
 create mode 100644 include/exec/page-prot-common.h
 create mode 100644 include/exec/user/tswap-target.h
 create mode 100644 page-target.c
Signature · 1 line
2.41.0
#1 lore raw

PATCH v2 1/23 exec: Include 'cpu.h' before validating CPUArchState placement

CPUArchState 'env' field is defined within the ArchCPU structure, so we need to include each target "cpu.h" header which defines it.

---
 include/exec/cpu-all.h | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
include/exec/cpu-all.h +5 -4
index 5340907cfd..9a7b5737d3 100644
@@ -411,10 +411,6 @@ static inline bool tlb_hit(uint64_t tlb_addr, vaddr addr)
 /* accel/tcg/cpu-exec.c */
 int cpu_exec(CPUState *cpu);
 
-/* Validate correct placement of CPUArchState. */
-QEMU_BUILD_BUG_ON(offsetof(ArchCPU, parent_obj) != 0);
-QEMU_BUILD_BUG_ON(offsetof(ArchCPU, env) != sizeof(CPUState));
-
 /**
  * env_archcpu(env)
  * @env: The architecture environment
@@ -437,4 +433,9 @@ static inline CPUState *env_cpu(CPUArchState *env)
     return (void *)env - sizeof(CPUState);
 }
 
+/* Validate correct placement of CPUArchState. */
+#include "cpu.h"
+QEMU_BUILD_BUG_ON(offsetof(ArchCPU, parent_obj) != 0);
+QEMU_BUILD_BUG_ON(offsetof(ArchCPU, env) != sizeof(CPUState));
+
 #endif /* CPU_ALL_H */
Signature · 1 line
2.41.0
#2 lore raw

PATCH v2 2/23 exec: Expose 'target_page.h' API to user emulation

In reply to Philippe Mathieu-Daudé

User-only objects might benefit from the "exec/target_page.h" API, which allows to build some objects once for all targets.

---
 meson.build      |  2 +-
 page-target.c    | 43 +++++++++++++++++++++++++++++++++++++++++++
 system/physmem.c | 35 -----------------------------------
 3 files changed, 44 insertions(+), 36 deletions(-)
 create mode 100644 page-target.c
meson.build +1 -1
index d2c4c2adb3..5fdc4ef8db 100644
@@ -3488,7 +3488,7 @@ if get_option('b_lto')
   pagevary = declare_dependency(link_with: pagevary)
 endif
 common_ss.add(pagevary)
-specific_ss.add(files('page-vary-target.c'))
+specific_ss.add(files('page-target.c', 'page-vary-target.c'))
 
 subdir('backends')
 subdir('disas')
page-target.c new file +43 -0

43 lines not on this page · raw message

system/physmem.c +0 -35
index a63853a7bc..4bdb3d0592 100644
@@ -3422,41 +3422,6 @@ int cpu_memory_rw_debug(CPUState *cpu, vaddr addr,
     return 0;
 }
 
-/*
- * Allows code that needs to deal with migration bitmaps etc to still be built
- * target independent.
- */
-size_t qemu_target_page_size(void)
-{
-    return TARGET_PAGE_SIZE;
-}
-
-int qemu_target_page_mask(void)
-{
-    return TARGET_PAGE_MASK;
-}
-
-int qemu_target_page_bits(void)
-{
-    return TARGET_PAGE_BITS;
-}
-
-int qemu_target_page_bits_min(void)
-{
-    return TARGET_PAGE_BITS_MIN;
-}
-
-/* Convert target pages to MiB (2**20). */
-size_t qemu_target_pages_to_MiB(size_t pages)
-{
-    int page_bits = TARGET_PAGE_BITS;
-
-    /* So far, the largest (non-huge) page size is 64k, i.e. 16 bits. */
-    g_assert(page_bits < 20);
-
-    return pages >> (20 - page_bits);
-}
-
 bool cpu_physical_memory_is_io(hwaddr phys_addr)
 {
     MemoryRegion*mr;
Signature · 1 line
2.41.0
#3 lore raw

PATCH v2 3/23 target: Define TCG_GUEST_DEFAULT_MO in 'cpu-param.h'

In reply to Philippe Mathieu-Daudé

accel/tcg/ files requires the following definitions:

- TARGET_LONG_BITS
- TARGET_PAGE_BITS
- TARGET_PHYS_ADDR_SPACE_BITS
- TCG_GUEST_DEFAULT_MO

The first 3 are defined in "cpu-param.h". The last one in "cpu.h", with a bunch of definitions irrelevant for TCG. By moving the TCG_GUEST_DEFAULT_MO definition to "cpu-param.h", we can simplify various accel/tcg includes.

---
 target/alpha/cpu-param.h      |  3 +++
 target/alpha/cpu.h            |  3 ---
 target/arm/cpu-param.h        |  8 +++++---
 target/arm/cpu.h              |  3 ---
 target/avr/cpu-param.h        |  2 ++
 target/avr/cpu.h              |  2 --
 target/hppa/cpu-param.h       |  8 ++++++++
 target/hppa/cpu.h             |  6 ------
 target/i386/cpu-param.h       |  3 +++
 target/i386/cpu.h             |  3 ---
 target/loongarch/cpu-param.h  |  2 ++
 target/loongarch/cpu.h        |  2 --
 target/microblaze/cpu-param.h |  3 +++
 target/microblaze/cpu.h       |  3 ---
 target/mips/cpu-param.h       |  2 ++
 target/mips/cpu.h             |  2 --
 target/openrisc/cpu-param.h   |  2 ++
 target/openrisc/cpu.h         |  2 --
 target/ppc/cpu-param.h        |  2 ++
 target/ppc/cpu.h              |  2 --
 target/riscv/cpu-param.h      |  2 ++
 target/riscv/cpu.h            |  2 --
 target/s390x/cpu-param.h      |  6 ++++++
 target/s390x/cpu.h            |  3 ---
 target/sparc/cpu-param.h      | 23 +++++++++++++++++++++++
 target/sparc/cpu.h            | 23 -----------------------
 target/xtensa/cpu-param.h     |  3 +++
 target/xtensa/cpu.h           |  3 ---
 28 files changed, 66 insertions(+), 62 deletions(-)
target/alpha/cpu-param.h +3 -0
index 68c46f7998..419e454702 100644
@@ -15,4 +15,7 @@
 #define TARGET_PHYS_ADDR_SPACE_BITS  44
 #define TARGET_VIRT_ADDR_SPACE_BITS  (30 + TARGET_PAGE_BITS)
 
+/* Alpha processors have a weak memory model */
+#define TCG_GUEST_DEFAULT_MO      (0)
+
 #endif
target/alpha/cpu.h +0 -3
index d672e911dd..5d9aa09ed9 100644
@@ -24,9 +24,6 @@
 #include "exec/cpu-defs.h"
 #include "qemu/cpu-float.h"
 
-/* Alpha processors have a weak memory model */
-#define TCG_GUEST_DEFAULT_MO      (0)
-
 #define ICACHE_LINE_SIZE 32
 #define DCACHE_LINE_SIZE 32
 
target/arm/cpu-param.h +5 -3
index f9b462a98f..59a5f9e480 100644
@@ -23,14 +23,16 @@
 # ifdef TARGET_AARCH64
 #  define TARGET_TAGGED_ADDRESSES
 # endif
-#else
+#else /* !CONFIG_USER_ONLY */
 /*
  * ARMv7 and later CPUs have 4K pages minimum, but ARMv5 and v6
  * have to support 1K tiny pages.
  */
 # define TARGET_PAGE_BITS_VARY
 # define TARGET_PAGE_BITS_MIN  10
-
-#endif
+#endif /* !CONFIG_USER_ONLY */
+
+/* ARM processors have a weak memory model */
+#define TCG_GUEST_DEFAULT_MO      (0)
 
 #endif
target/arm/cpu.h +0 -3
index a0282e0d28..ea5c8660dc 100644
@@ -27,9 +27,6 @@
 #include "exec/cpu-defs.h"
 #include "qapi/qapi-types-common.h"
 
-/* ARM processors have a weak memory model */
-#define TCG_GUEST_DEFAULT_MO      (0)
-
 #ifdef TARGET_AARCH64
 #define KVM_HAVE_MCE_INJECTION 1
 #endif
target/avr/cpu-param.h +2 -0
index 9a92bc74fc..93c2f470d0 100644
@@ -32,4 +32,6 @@
 #define TARGET_PHYS_ADDR_SPACE_BITS 24
 #define TARGET_VIRT_ADDR_SPACE_BITS 24
 
+#define TCG_GUEST_DEFAULT_MO 0
+
 #endif
target/avr/cpu.h +0 -2
index 7960c5c57a..02a787b4f3 100644
@@ -30,8 +30,6 @@
 
 #define CPU_RESOLVING_TYPE TYPE_AVR_CPU
 
-#define TCG_GUEST_DEFAULT_MO 0
-
 /*
  * AVR has two memory spaces, data & code.
  * e.g. both have 0 address
target/hppa/cpu-param.h +8 -0
index bb3d7ef6f7..473d489f01 100644
@@ -21,4 +21,12 @@
 
 #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/hppa/cpu.h +0 -6
index 8be45c69c9..6b10ab20ba 100644
@@ -25,12 +25,6 @@
 #include "qemu/cpu-float.h"
 #include "qemu/interval-tree.h"
 
-/* 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
-
 #define MMU_ABS_W_IDX     6
 #define MMU_ABS_IDX       7
 #define MMU_KERNEL_IDX    8
target/i386/cpu-param.h +3 -0
index 911b4cd51b..5e15335203 100644
@@ -24,4 +24,7 @@
 #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/i386/cpu.h +0 -3
index cd2e295bd6..852adf35db 100644
@@ -30,9 +30,6 @@
 
 #define XEN_NR_VIRQS 24
 
-/* 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)
-
 #define KVM_HAVE_MCE_INJECTION 1
 
 /* support for self modifying code even if the modified instruction is
target/loongarch/cpu-param.h +2 -0
index cfe195db4e..db5ad1c69f 100644
@@ -14,4 +14,6 @@
 
 #define TARGET_PAGE_BITS 12
 
+#define TCG_GUEST_DEFAULT_MO (0)
+
 #endif
target/loongarch/cpu.h +0 -2
index 00d1fba597..dd1ab75ce9 100644
@@ -39,8 +39,6 @@
 
 #define IOCSR_MEM_SIZE          0x428
 
-#define TCG_GUEST_DEFAULT_MO (0)
-
 #define FCSR0_M1    0x1f         /* FCSR1 mask, Enables */
 #define FCSR0_M2    0x1f1f0000   /* FCSR2 mask, Cause and Flags */
 #define FCSR0_M3    0x300        /* FCSR3 mask, Round Mode */
target/microblaze/cpu-param.h +3 -0
index 9770b0eb52..e530fead1c 100644
@@ -29,4 +29,7 @@
 /* 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/microblaze/cpu.h +0 -3
index b5374365f5..943bae67d1 100644
@@ -24,9 +24,6 @@
 #include "exec/cpu-defs.h"
 #include "qemu/cpu-float.h"
 
-/* MicroBlaze is always in-order. */
-#define TCG_GUEST_DEFAULT_MO  TCG_MO_ALL
-
 typedef struct CPUArchState CPUMBState;
 #if !defined(CONFIG_USER_ONLY)
 #include "mmu.h"
target/mips/cpu-param.h +2 -0
index 594c91a156..6f6ac1688f 100644
@@ -30,4 +30,6 @@
 #define TARGET_PAGE_BITS_MIN 12
 #endif
 
+#define TCG_GUEST_DEFAULT_MO (0)
+
 #endif
target/mips/cpu.h +0 -2
index 52f13f0363..620db820f8 100644
@@ -10,8 +10,6 @@
 #include "hw/clock.h"
 #include "mips-defs.h"
 
-#define TCG_GUEST_DEFAULT_MO (0)
-
 typedef struct CPUMIPSTLBContext CPUMIPSTLBContext;
 
 /* MSA Context */
target/openrisc/cpu-param.h +2 -0
index 3f08207485..fbfc0f568b 100644
@@ -13,4 +13,6 @@
 #define TARGET_PHYS_ADDR_SPACE_BITS 32
 #define TARGET_VIRT_ADDR_SPACE_BITS 32
 
+#define TCG_GUEST_DEFAULT_MO (0)
+
 #endif
target/openrisc/cpu.h +0 -2
index dedeb89f8e..e757e84caf 100644
@@ -24,8 +24,6 @@
 #include "exec/cpu-defs.h"
 #include "fpu/softfloat-types.h"
 
-#define TCG_GUEST_DEFAULT_MO (0)
-
 /**
  * OpenRISCCPUClass:
  * @parent_realize: The parent class' realize handler.
target/ppc/cpu-param.h +2 -0
index 0a0416e0a8..c5565beae2 100644
@@ -33,4 +33,6 @@
 #endif
 #define TARGET_PAGE_BITS 12
 
+#define TCG_GUEST_DEFAULT_MO 0
+
 #endif
target/ppc/cpu.h +0 -2
index f8101ffa29..f21d8de6ff 100644
@@ -29,8 +29,6 @@
 
 #define CPU_RESOLVING_TYPE TYPE_POWERPC_CPU
 
-#define TCG_GUEST_DEFAULT_MO 0
-
 #define TARGET_PAGE_BITS_64K 16
 #define TARGET_PAGE_BITS_16M 24
 
target/riscv/cpu-param.h +2 -0
index b2a9396dec..1fbd64939d 100644
@@ -28,4 +28,6 @@
  *  - M mode HLV/HLVX/HSV 0b111
  */
 
+#define TCG_GUEST_DEFAULT_MO 0
+
 #endif
target/riscv/cpu.h +0 -2
index d74b361be6..01cddf5180 100644
@@ -42,8 +42,6 @@ typedef struct CPUArchState CPURISCVState;
 # define TYPE_RISCV_CPU_BASE            TYPE_RISCV_CPU_BASE64
 #endif
 
-#define TCG_GUEST_DEFAULT_MO 0
-
 /*
  * RISC-V-specific extra insn start words:
  * 1: Original instruction opcode
target/s390x/cpu-param.h +6 -0
index 84ca08626b..11d23b600d 100644
@@ -13,4 +13,10 @@
 #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/s390x/cpu.h +0 -3
index fa3aac4f97..10a63821b5 100644
@@ -33,9 +33,6 @@
 
 #define ELF_MACHINE_UNAME "S390X"
 
-/* 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)
-
 #define TARGET_HAS_PRECISE_SMC
 
 #define TARGET_INSN_START_EXTRA_WORDS 2
target/sparc/cpu-param.h +23 -0
index cb11980404..82293fb844 100644
@@ -23,4 +23,27 @@
 # 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/sparc/cpu.h +0 -23
index 6999a10a40..10b04d37c6 100644
@@ -6,29 +6,6 @@
 #include "exec/cpu-defs.h"
 #include "qemu/cpu-float.h"
 
-/*
- * 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)
-
 #if !defined(TARGET_SPARC64)
 #define TARGET_DPREGS 16
 #else
target/xtensa/cpu-param.h +3 -0
index b1da0555de..0000725f2f 100644
@@ -17,4 +17,7 @@
 #define TARGET_VIRT_ADDR_SPACE_BITS 32
 #endif
 
+/* Xtensa processors have a weak memory model */
+#define TCG_GUEST_DEFAULT_MO      (0)
+
 #endif
target/xtensa/cpu.h +0 -3
index 8a423706d8..ca32657041 100644
@@ -34,9 +34,6 @@
 #include "hw/clock.h"
 #include "xtensa-isa.h"
 
-/* Xtensa processors have a weak memory model */
-#define TCG_GUEST_DEFAULT_MO      (0)
-
 enum {
     /* Additional instructions */
     XTENSA_OPTION_CODE_DENSITY,
Signature · 1 line
2.41.0
#4 lore raw

PATCH v2 4/23 accel: Include missing 'exec/cpu_ldst.h' header

In reply to Philippe Mathieu-Daudé

Theses files call cpu_ldl_code() which is declared in "exec/cpu_ldst.h".

---
 accel/tcg/translator.c        | 1 +
 target/hexagon/translate.c    | 1 +
 target/microblaze/cpu.c       | 1 +
 target/microblaze/translate.c | 1 +
 target/nios2/translate.c      | 1 +
 5 files changed, 5 insertions(+)
accel/tcg/translator.c +1 -0
index 38c34009a5..5b019a0852 100644
@@ -12,6 +12,7 @@
 #include "qemu/error-report.h"
 #include "exec/exec-all.h"
 #include "exec/translator.h"
+#include "exec/cpu_ldst.h"
 #include "exec/plugin-gen.h"
 #include "tcg/tcg-op-common.h"
 #include "internal-target.h"
target/hexagon/translate.c +1 -0
index 666c061180..744dc4fc3f 100644
@@ -23,6 +23,7 @@
 #include "exec/helper-gen.h"
 #include "exec/helper-proto.h"
 #include "exec/translation-block.h"
+#include "exec/cpu_ldst.h"
 #include "exec/log.h"
 #include "internal.h"
 #include "attribs.h"
target/microblaze/cpu.c +1 -0
index bbb3335cad..91d7cd9061 100644
@@ -28,6 +28,7 @@
 #include "qemu/module.h"
 #include "hw/qdev-properties.h"
 #include "exec/exec-all.h"
+#include "exec/cpu_ldst.h"
 #include "exec/gdbstub.h"
 #include "fpu/softfloat-helpers.h"
 #include "tcg/tcg.h"
target/microblaze/translate.c +1 -0
index 49bfb4a0ea..1c9a364c2b 100644
@@ -22,6 +22,7 @@
 #include "cpu.h"
 #include "disas/disas.h"
 #include "exec/exec-all.h"
+#include "exec/cpu_ldst.h"
 #include "tcg/tcg-op.h"
 #include "exec/helper-proto.h"
 #include "exec/helper-gen.h"
target/nios2/translate.c +1 -0
index e806623594..a74eb6909f 100644
@@ -25,6 +25,7 @@
 #include "cpu.h"
 #include "tcg/tcg-op.h"
 #include "exec/exec-all.h"
+#include "exec/cpu_ldst.h"
 #include "disas/disas.h"
 #include "exec/helper-proto.h"
 #include "exec/helper-gen.h"
Signature · 1 line
2.41.0
#5 lore raw

PATCH v2 5/23 gdbstub: Include missing 'hw/core/cpu.h' header

In reply to Philippe Mathieu-Daudé

Functions such gdb_get_cpu_pid() dereference CPUState so require the structure declaration from "hw/core/cpu.h":

  static uint32_t gdb_get_cpu_pid(CPUState *cpu)
  {
    ...
    return cpu->cluster_index + 1;
  }
---
 gdbstub/gdbstub.c | 1 +
 1 file changed, 1 insertion(+)
gdbstub/gdbstub.c +1 -0
index 46d752bbc2..034a4ac211 100644
@@ -37,6 +37,7 @@
 #include "hw/cpu/cluster.h"
 #include "hw/boards.h"
 #endif
+#include "hw/core/cpu.h"
 
 #include "sysemu/hw_accel.h"
 #include "sysemu/runstate.h"
Signature · 1 line
2.41.0
#6 lore raw

PATCH v2 6/23 semihosting/uaccess: Avoid including 'cpu.h'

In reply to Philippe Mathieu-Daudé

"semihosting/uaccess.h" only requires declarations from "exec/cpu-defs.h". Avoid including the huge "cpu.h".

---
 include/semihosting/uaccess.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/semihosting/uaccess.h +1 -1
index 3963eafc3e..6c8835fbcb 100644
@@ -14,7 +14,7 @@
 #error Cannot include semihosting/uaccess.h from user emulation
 #endif
 
-#include "cpu.h"
+#include "exec/cpu-defs.h"
 
 #define get_user_u64(val, addr)                                         \
     ({ uint64_t val_ = 0;                                               \
Signature · 1 line
2.41.0
#7 lore raw

PATCH v2 7/23 semihosting/guestfd: Remove unused 'semihosting/uaccess.h' header

In reply to Philippe Mathieu-Daudé

Nothing in guestfd.c requires "semihosting/uaccess.h" nor "qemu.h".

---
 semihosting/guestfd.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
semihosting/guestfd.c +1 -4
index 955c2efbd0..d3241434c5 100644
@@ -12,10 +12,7 @@
 #include "gdbstub/syscalls.h"
 #include "semihosting/semihost.h"
 #include "semihosting/guestfd.h"
-#ifdef CONFIG_USER_ONLY
-#include "qemu.h"
-#else
-#include "semihosting/uaccess.h"
+#ifndef CONFIG_USER_ONLY
 #include CONFIG_DEVICES
 #endif
 
Signature · 1 line
2.41.0
Reviewed-by on v2 7/23
#8 lore raw

Re: [PATCH v2 07/23] semihosting/guestfd: Remove unused 'semihosting/uaccess.h' header

Quoted 26 lines · Philippe Mathieu-Daudé

Nothing in guestfd.c requires "semihosting/uaccess.h" nor "qemu.h".

---
 semihosting/guestfd.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
semihosting/guestfd.c +1 -4
index 955c2efbd0..d3241434c5 100644
@@ -12,10 +12,7 @@
 #include "gdbstub/syscalls.h"
 #include "semihosting/semihost.h"
 #include "semihosting/guestfd.h"
-#ifdef CONFIG_USER_ONLY
-#include "qemu.h"
-#else
-#include "semihosting/uaccess.h"
+#ifndef CONFIG_USER_ONLY
 #include CONFIG_DEVICES
 #endif
 
Signature · 1 line
2.41.0
Signature · 2 lines
Anton Johansson
rev.ng Labs Srl.
#9 lore raw

PATCH v2 8/23 host/load-extract: Include missing 'qemu/atomic.h' and 'qemu/int128.h'

In reply to Philippe Mathieu-Daudé

int128_make128(), int128_getlo() and int128_urshift() are declared in "qemu/int128.h". qatomic_read__nocheck() is declared in "qemu/atomic.h".

---
 host/include/generic/host/load-extract-al16-al8.h | 3 +++
 1 file changed, 3 insertions(+)
host/include/generic/host/load-extract-al16-al8.h +3 -0
index d95556130f..6b47339b57 100644
@@ -8,6 +8,9 @@
 #ifndef HOST_LOAD_EXTRACT_AL16_AL8_H
 #define HOST_LOAD_EXTRACT_AL16_AL8_H
 
+#include "qemu/atomic.h"
+#include "qemu/int128.h"
+
 /**
  * load_atom_extract_al16_or_al8:
  * @pv: host address
Signature · 1 line
2.41.0
Reviewed-by on v2 8/23
#10 lore raw

Re: [PATCH v2 08/23] host/load-extract: Include missing 'qemu/atomic.h' and 'qemu/int128.h'

Quoted 26 lines · Philippe Mathieu-Daudé

int128_make128(), int128_getlo() and int128_urshift() are declared in "qemu/int128.h". qatomic_read__nocheck() is declared in "qemu/atomic.h".

---
 host/include/generic/host/load-extract-al16-al8.h | 3 +++
 1 file changed, 3 insertions(+)
host/include/generic/host/load-extract-al16-al8.h +3 -0
index d95556130f..6b47339b57 100644
@@ -8,6 +8,9 @@
 #ifndef HOST_LOAD_EXTRACT_AL16_AL8_H
 #define HOST_LOAD_EXTRACT_AL16_AL8_H
 
+#include "qemu/atomic.h"
+#include "qemu/int128.h"
+
 /**
  * load_atom_extract_al16_or_al8:
  * @pv: host address
Signature · 1 line
2.41.0
#11 lore raw

PATCH v2 9/23 host/atomic128: Include missing 'qemu/atomic.h' header

In reply to Philippe Mathieu-Daudé

qatomic_cmpxchg__nocheck(), qatomic_read__nocheck(), qatomic_set__nocheck() are defined in "qemu/atomic.h". Include it in order to avoid:

In file included from include/exec/helper-proto.h:10:
In file included from include/exec/helper-proto-common.h:10:
In file included from include/qemu/atomic128.h:61:
In file included from host/include/aarch64/host/atomic128-cas.h:16:
host/include/generic/host/atomic128-cas.h:23:11: error: call to undeclared function 'qatomic_cmpxchg__nocheck'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]

    r.i = qatomic_cmpxchg__nocheck(ptr_align, c.i, n.i);
          ^
---
 host/include/generic/host/atomic128-cas.h  | 2 ++
 host/include/generic/host/atomic128-ldst.h | 2 ++
 2 files changed, 4 insertions(+)
host/include/generic/host/atomic128-cas.h +2 -0
index 6b40cc2271..4824f14659 100644
@@ -11,6 +11,8 @@
 #ifndef HOST_ATOMIC128_CAS_H
 #define HOST_ATOMIC128_CAS_H
 
+#include "qemu/atomic.h"
+
 #if defined(CONFIG_ATOMIC128)
 static inline Int128 ATTRIBUTE_ATOMIC128_OPT
 atomic16_cmpxchg(Int128 *ptr, Int128 cmp, Int128 new)
host/include/generic/host/atomic128-ldst.h +2 -0
index 691e6a8531..12e4aca2da 100644
@@ -11,6 +11,8 @@
 #ifndef HOST_ATOMIC128_LDST_H
 #define HOST_ATOMIC128_LDST_H
 
+#include "qemu/atomic.h"
+
 #if defined(CONFIG_ATOMIC128)
 # define HAVE_ATOMIC128_RO 1
 # define HAVE_ATOMIC128_RW 1
Signature · 1 line
2.41.0
#12 lore raw

Re: [PATCH v2 09/23] host/atomic128: Include missing 'qemu/atomic.h' header

Quoted 47 lines · Philippe Mathieu-Daudé

qatomic_cmpxchg__nocheck(), qatomic_read__nocheck(), qatomic_set__nocheck() are defined in "qemu/atomic.h". Include it in order to avoid:

In file included from include/exec/helper-proto.h:10:
In file included from include/exec/helper-proto-common.h:10:
In file included from include/qemu/atomic128.h:61:
In file included from host/include/aarch64/host/atomic128-cas.h:16:
host/include/generic/host/atomic128-cas.h:23:11: error: call to undeclared function 'qatomic_cmpxchg__nocheck'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]

    r.i = qatomic_cmpxchg__nocheck(ptr_align, c.i, n.i);
          ^
---
 host/include/generic/host/atomic128-cas.h  | 2 ++
 host/include/generic/host/atomic128-ldst.h | 2 ++
 2 files changed, 4 insertions(+)
host/include/generic/host/atomic128-cas.h +2 -0
index 6b40cc2271..4824f14659 100644
@@ -11,6 +11,8 @@
 #ifndef HOST_ATOMIC128_CAS_H
 #define HOST_ATOMIC128_CAS_H
 
+#include "qemu/atomic.h"
+
 #if defined(CONFIG_ATOMIC128)
 static inline Int128 ATTRIBUTE_ATOMIC128_OPT
 atomic16_cmpxchg(Int128 *ptr, Int128 cmp, Int128 new)
host/include/generic/host/atomic128-ldst.h +2 -0
index 691e6a8531..12e4aca2da 100644
@@ -11,6 +11,8 @@
 #ifndef HOST_ATOMIC128_LDST_H
 #define HOST_ATOMIC128_LDST_H
 
+#include "qemu/atomic.h"
+
 #if defined(CONFIG_ATOMIC128)
 # define HAVE_ATOMIC128_RO 1
 # define HAVE_ATOMIC128_RW 1
Signature · 1 line
2.41.0

What about the int128.h includes? I guess those definitions are acquired from atomic128.h that includes -cas.h/-ldst.h?

#13 lore raw

PATCH v2 10/23 target/i386: Include missing 'exec/exec-all.h' header

In reply to Philippe Mathieu-Daudé

The XRSTOR instruction ends calling tlb_flush(), declared in "exec/exec-all.h".

---
 target/i386/tcg/fpu_helper.c | 1 +
 1 file changed, 1 insertion(+)
target/i386/tcg/fpu_helper.c +1 -0
index 4430d3d380..3bb018fbae 100644
@@ -21,6 +21,7 @@
 #include <math.h>
 #include "cpu.h"
 #include "tcg-cpu.h"
+#include "exec/exec-all.h"
 #include "exec/cpu_ldst.h"
 #include "exec/helper-proto.h"
 #include "fpu/softfloat.h"
Signature · 1 line
2.41.0
#14 lore raw

PATCH v2 11/23 accel/tcg: Include missing 'hw/core/cpu.h' header

In reply to Philippe Mathieu-Daudé

tcg_cpu_init_cflags() accesses CPUState fields, so requires "hw/core/cpu.h" to get its structure definition.

---
 accel/tcg/tcg-accel-ops.c | 2 ++
 1 file changed, 2 insertions(+)
accel/tcg/tcg-accel-ops.c +2 -0
index 1b57290682..58806e2d7f 100644
@@ -37,6 +37,8 @@
 #include "exec/tb-flush.h"
 #include "exec/gdbstub.h"
 
+#include "hw/core/cpu.h"
+
 #include "tcg-accel-ops.h"
 #include "tcg-accel-ops-mttcg.h"
 #include "tcg-accel-ops-rr.h"
Signature · 1 line
2.41.0
Reviewed-by on v2 11/23
#15 lore raw

Re: [PATCH v2 11/23] accel/tcg: Include missing 'hw/core/cpu.h' header

Quoted 24 lines · Philippe Mathieu-Daudé

tcg_cpu_init_cflags() accesses CPUState fields, so requires "hw/core/cpu.h" to get its structure definition.

---
 accel/tcg/tcg-accel-ops.c | 2 ++
 1 file changed, 2 insertions(+)
accel/tcg/tcg-accel-ops.c +2 -0
index 1b57290682..58806e2d7f 100644
@@ -37,6 +37,8 @@
 #include "exec/tb-flush.h"
 #include "exec/gdbstub.h"
 
+#include "hw/core/cpu.h"
+
 #include "tcg-accel-ops.h"
 #include "tcg-accel-ops-mttcg.h"
 #include "tcg-accel-ops-rr.h"
Signature · 1 line
2.41.0
#16 lore raw

PATCH v2 12/23 exec/cpu-all: Remove unused 'qemu/thread.h' header

In reply to Philippe Mathieu-Daudé

Nothing is required from the "qemu/thread.h".

---
 include/exec/cpu-all.h | 1 -
 1 file changed, 1 deletion(-)
include/exec/cpu-all.h +0 -1
index 9a7b5737d3..26b44ca125 100644
@@ -22,7 +22,6 @@
 #include "exec/cpu-common.h"
 #include "exec/memory.h"
 #include "exec/tswap.h"
-#include "qemu/thread.h"
 #include "hw/core/cpu.h"
 #include "qemu/rcu.h"
 
Signature · 1 line
2.41.0
Reviewed-by on v2 12/23
#17 lore raw

Re: [PATCH v2 12/23] exec/cpu-all: Remove unused 'qemu/thread.h' header

Quoted 22 lines · Philippe Mathieu-Daudé

Nothing is required from the "qemu/thread.h".

---
 include/exec/cpu-all.h | 1 -
 1 file changed, 1 deletion(-)
include/exec/cpu-all.h +0 -1
index 9a7b5737d3..26b44ca125 100644
@@ -22,7 +22,6 @@
 #include "exec/cpu-common.h"
 #include "exec/memory.h"
 #include "exec/tswap.h"
-#include "qemu/thread.h"
 #include "hw/core/cpu.h"
 #include "qemu/rcu.h"
 
Signature · 1 line
2.41.0
#18 lore raw

PATCH v2 13/23 exec/cpu-all: Reduce 'qemu/rcu.h' header inclusion

In reply to Philippe Mathieu-Daudé

"exec/cpu-all.h" doesn't need definitions from "qemu/rcu.h", however "exec/ram_addr.h" does.

---
 include/exec/cpu-all.h  | 1 -
 include/exec/ram_addr.h | 1 +
 2 files changed, 1 insertion(+), 1 deletion(-)
include/exec/cpu-all.h +0 -1
index 26b44ca125..5b5379b94c 100644
@@ -23,7 +23,6 @@
 #include "exec/memory.h"
 #include "exec/tswap.h"
 #include "hw/core/cpu.h"
-#include "qemu/rcu.h"
 
 /* some important defines:
  *
include/exec/ram_addr.h +1 -0
index 90676093f5..aab7d6c57c 100644
@@ -25,6 +25,7 @@
 #include "sysemu/tcg.h"
 #include "exec/ramlist.h"
 #include "exec/ramblock.h"
+#include "qemu/rcu.h"
 
 extern uint64_t total_dirty_pages;
 
Signature · 1 line
2.41.0
#19 lore raw

PATCH v2 14/23 exec/cpu-all: Remove unused tswapls() definitions

In reply to Philippe Mathieu-Daudé

Last use of tswapls() was removed 2 years ago in commit aee14c77f4 ("linux-user: Rewrite do_getdents, do_getdents64").

---
 include/exec/cpu-all.h | 2 --
 1 file changed, 2 deletions(-)
include/exec/cpu-all.h +0 -2
index 5b5379b94c..b042d94892 100644
@@ -38,11 +38,9 @@
 
 #if TARGET_LONG_SIZE == 4
 #define tswapl(s) tswap32(s)
-#define tswapls(s) tswap32s((uint32_t *)(s))
 #define bswaptls(s) bswap32s(s)
 #else
 #define tswapl(s) tswap64(s)
-#define tswapls(s) tswap64s((uint64_t *)(s))
 #define bswaptls(s) bswap64s(s)
 #endif
 
Signature · 1 line
2.41.0
Reviewed-by on v2 14/23
#20 lore raw

Re: [PATCH v2 14/23] exec/cpu-all: Remove unused tswapls() definitions

Quoted 27 lines · Philippe Mathieu-Daudé

Last use of tswapls() was removed 2 years ago in commit aee14c77f4 ("linux-user: Rewrite do_getdents, do_getdents64").

---
 include/exec/cpu-all.h | 2 --
 1 file changed, 2 deletions(-)
include/exec/cpu-all.h +0 -2
index 5b5379b94c..b042d94892 100644
@@ -38,11 +38,9 @@
 
 #if TARGET_LONG_SIZE == 4
 #define tswapl(s) tswap32(s)
-#define tswapls(s) tswap32s((uint32_t *)(s))
 #define bswaptls(s) bswap32s(s)
 #else
 #define tswapl(s) tswap64(s)
-#define tswapls(s) tswap64s((uint64_t *)(s))
 #define bswaptls(s) bswap64s(s)
 #endif
 
Signature · 1 line
2.41.0
#21 lore raw

PATCH v2 15/23 exec: Declare target_words_bigendian() in 'exec/tswap.h'

In reply to Philippe Mathieu-Daudé

We usually check target endianess before swapping values, so target_words_bigendian() declaration makes sense in "exec/tswap.h" with the target swapping helpers.

Remove "hw/core/cpu.h" when it was only included to get the target_words_bigendian() declaration.

---
 include/exec/tswap.h     | 12 +++++++++++-
 include/hw/core/cpu.h    | 11 -----------
 cpu-target.c             |  1 +
 disas/disas.c            |  1 +
 hw/audio/virtio-snd.c    |  2 +-
 hw/core/cpu-sysemu.c     |  2 +-
 hw/core/generic-loader.c |  2 +-
 hw/display/vga.c         |  2 +-
 hw/virtio/virtio.c       |  1 +
 9 files changed, 18 insertions(+), 16 deletions(-)
include/exec/tswap.h +11 -1
index 68944a880b..77954bbc2b 100644
@@ -8,9 +8,19 @@
 #ifndef TSWAP_H
 #define TSWAP_H
 
-#include "hw/core/cpu.h"
 #include "qemu/bswap.h"
 
+/**
+ * target_words_bigendian:
+ * Returns true if the (default) endianness of the target is big endian,
+ * false otherwise. Note that in target-specific code, you can use
+ * TARGET_BIG_ENDIAN directly instead. On the other hand, common
+ * code should normally never need to know about the endianness of the
+ * target, so please do *not* use this function unless you know very well
+ * what you are doing!
+ */
+bool target_words_bigendian(void);
+
 /*
  * If we're in target-specific code, we can hard-code the swapping
  * condition, otherwise we have to do (slower) run-time checks.
include/hw/core/cpu.h +0 -11
index 3208b938f7..d6b077da71 100644
@@ -1153,17 +1153,6 @@ bool cpu_exec_realizefn(CPUState *cpu, Error **errp);
 void cpu_exec_unrealizefn(CPUState *cpu);
 void cpu_exec_reset_hold(CPUState *cpu);
 
-/**
- * target_words_bigendian:
- * Returns true if the (default) endianness of the target is big endian,
- * false otherwise. Note that in target-specific code, you can use
- * TARGET_BIG_ENDIAN directly instead. On the other hand, common
- * code should normally never need to know about the endianness of the
- * target, so please do *not* use this function unless you know very well
- * what you are doing!
- */
-bool target_words_bigendian(void);
-
 const char *target_name(void);
 
 void page_size_init(void);
cpu-target.c +1 -0
index 997ca2e846..4c1e19ca81 100644
@@ -33,6 +33,7 @@
 #endif
 #include "sysemu/cpus.h"
 #include "sysemu/tcg.h"
+#include "exec/tswap.h"
 #include "exec/replay-core.h"
 #include "exec/cpu-common.h"
 #include "exec/exec-all.h"
disas/disas.c +1 -0
index 0d2d06c2ec..89a1e7d767 100644
@@ -6,6 +6,7 @@
 #include "disas/disas.h"
 #include "disas/capstone.h"
 #include "hw/core/cpu.h"
+#include "exec/tswap.h"
 #include "exec/memory.h"
 
 /* Filled in by elfload.c.  Simplistic, but will do for now. */
hw/audio/virtio-snd.c +1 -1
index 137fa77a01..a80f23aa71 100644
@@ -20,11 +20,11 @@
 #include "qemu/log.h"
 #include "qemu/error-report.h"
 #include "include/qemu/lockable.h"
+#include "exec/tswap.h"
 #include "sysemu/runstate.h"
 #include "trace.h"
 #include "qapi/error.h"
 #include "hw/audio/virtio-snd.h"
-#include "hw/core/cpu.h"
 
 #define VIRTIO_SOUND_VM_VERSION 1
 #define VIRTIO_SOUND_JACK_DEFAULT 0
hw/core/cpu-sysemu.c +1 -1
index d0d6a910f9..2a9a2a4eb5 100644
@@ -20,7 +20,7 @@
 
 #include "qemu/osdep.h"
 #include "qapi/error.h"
-#include "hw/core/cpu.h"
+#include "exec/tswap.h"
 #include "hw/core/sysemu-cpu-ops.h"
 
 bool cpu_paging_enabled(const CPUState *cpu)
hw/core/generic-loader.c +1 -1
index d4b5c501d8..ea8628b892 100644
@@ -31,7 +31,7 @@
  */
 
 #include "qemu/osdep.h"
-#include "hw/core/cpu.h"
+#include "exec/tswap.h"
 #include "sysemu/dma.h"
 #include "sysemu/reset.h"
 #include "hw/boards.h"
hw/display/vga.c +1 -1
index 37557c3442..d11a30a785 100644
@@ -26,7 +26,7 @@
 #include "qemu/units.h"
 #include "sysemu/reset.h"
 #include "qapi/error.h"
-#include "hw/core/cpu.h"
+#include "exec/tswap.h"
 #include "hw/display/vga.h"
 #include "hw/i386/x86.h"
 #include "hw/pci/pci.h"
hw/virtio/virtio.c +1 -0
index 3a160f86ed..28dc1f4c15 100644
@@ -20,6 +20,7 @@
 #include "qemu/log.h"
 #include "qemu/main-loop.h"
 #include "qemu/module.h"
+#include "exec/tswap.h"
 #include "qom/object_interfaces.h"
 #include "hw/core/cpu.h"
 #include "hw/virtio/virtio.h"
Signature · 1 line
2.41.0
Reviewed-by on v2 15/23
#22 lore raw

Re: [PATCH v2 15/23] exec: Declare target_words_bigendian() in 'exec/tswap.h'

Quoted 25 lines · Philippe Mathieu-Daudé

We usually check target endianess before swapping values, so target_words_bigendian() declaration makes sense in "exec/tswap.h" with the target swapping helpers.

Remove "hw/core/cpu.h" when it was only included to get the target_words_bigendian() declaration.

---
 include/exec/tswap.h     | 12 +++++++++++-
 include/hw/core/cpu.h    | 11 -----------
 cpu-target.c             |  1 +
 disas/disas.c            |  1 +
 hw/audio/virtio-snd.c    |  2 +-
 hw/core/cpu-sysemu.c     |  2 +-
 hw/core/generic-loader.c |  2 +-
 hw/display/vga.c         |  2 +-
 hw/virtio/virtio.c       |  1 +
 9 files changed, 18 insertions(+), 16 deletions(-)
include/exec/tswap.h +0 -0
index 68944a880b..77954bbc2b 100644

include/exec/tswap.h line 11

Quoted 5 lines
include/exec/tswap.h +0 -1
@@ -8,9 +8,19 @@
 #ifndef TSWAP_H
 #define TSWAP_H
 
-#include "hw/core/cpu.h"
 #include "qemu/bswap.h"

This breaks system/qtest.c which gets first_cpu from hw/core/cpu.h through the inclusion of tswap.h...

../system/qtest.c:548:33: error: ‘first_cpu’ undeclared (first use in this function);
548 | address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
| ^~~~~~~~~

Adding hw/core/cpu.h to system/qtest.c seems sufficient.

Otherwise,

#23 lore raw

Re: [PATCH v2 15/23] exec: Declare target_words_bigendian() in 'exec/tswap.h'

Quoted 35 lines · Anton Johansson
Quoted 25 lines · Philippe Mathieu-Daudé

We usually check target endianess before swapping values, so target_words_bigendian() declaration makes sense in "exec/tswap.h" with the target swapping helpers.

Remove "hw/core/cpu.h" when it was only included to get the target_words_bigendian() declaration.

---
  include/exec/tswap.h     | 12 +++++++++++-
  include/hw/core/cpu.h    | 11 -----------
  cpu-target.c             |  1 +
  disas/disas.c            |  1 +
  hw/audio/virtio-snd.c    |  2 +-
  hw/core/cpu-sysemu.c     |  2 +-
  hw/core/generic-loader.c |  2 +-
  hw/display/vga.c         |  2 +-
  hw/virtio/virtio.c       |  1 +
  9 files changed, 18 insertions(+), 16 deletions(-)
include/exec/tswap.h +0 -0
index 68944a880b..77954bbc2b 100644

include/exec/tswap.h line 11

Quoted 5 lines
include/exec/tswap.h +0 -1
@@ -8,9 +8,19 @@
  #ifndef TSWAP_H
  #define TSWAP_H
 
-#include "hw/core/cpu.h"
  #include "qemu/bswap.h"

This breaks system/qtest.c which gets first_cpu from hw/core/cpu.h through the inclusion of tswap.h...

Quoted 3 lines

../system/qtest.c:548:33: error: ‘first_cpu’ undeclared (first use in this function);
548 | address_space_write(first_cpu->as, addr, MEMTXATTRS_UNSPECIFIED,
| ^~~~~~~~~

Doh sorry, in this series I dropped some already reviewed patches, and extracted some not-that-related series. I was lazy to add the many 'Based-on:' tags on the cover.

What you mentioned here is fixed here:
https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 4 lines

Adding hw/core/cpu.h to system/qtest.c seems sufficient.

Otherwise,

Thanks!

#24 lore raw

PATCH v2 16/23 exec: Move [b]tswapl() declarations to 'exec/user/tswap-target.h'

In reply to Philippe Mathieu-Daudé

tswapl() and bswaptls() are target-dependent and only used by user emulation. Move their definitions to a new header:
"exec/user/tswap-target.h".

---
 bsd-user/freebsd/target_os_elf.h   |  1 +
 bsd-user/freebsd/target_os_stack.h |  1 +
 bsd-user/netbsd/target_os_elf.h    |  1 +
 bsd-user/openbsd/target_os_elf.h   |  1 +
 include/exec/cpu-all.h             |  8 --------
 include/exec/user/abitypes.h       |  1 +
 include/exec/user/tswap-target.h   | 22 ++++++++++++++++++++++
 bsd-user/signal.c                  |  1 +
 bsd-user/strace.c                  |  1 +
 linux-user/elfload.c               |  1 +
 linux-user/i386/signal.c           |  1 +
 linux-user/ppc/signal.c            |  1 +
 12 files changed, 32 insertions(+), 8 deletions(-)
 create mode 100644 include/exec/user/tswap-target.h
bsd-user/freebsd/target_os_elf.h +1 -0
index 9df17d56d8..27d8ce036c 100644
@@ -22,6 +22,7 @@
 
 #include "target_arch_elf.h"
 #include "elf.h"
+#include "exec/user/tswap-target.h"
 
 #define bsd_get_ncpu() 1 /* until we pull in bsd-proc.[hc] */
 
bsd-user/freebsd/target_os_stack.h +1 -0
index d15fc3263f..6125208182 100644
@@ -23,6 +23,7 @@
 #include <sys/param.h>
 #include "target_arch_sigtramp.h"
 #include "qemu/guest-random.h"
+#include "exec/user/tswap-target.h"
 
 /*
  * The initial FreeBSD stack is as follows:
bsd-user/netbsd/target_os_elf.h +1 -0
index 2f3cb20871..23b422bfce 100644
@@ -22,6 +22,7 @@
 
 #include "target_arch_elf.h"
 #include "elf.h"
+#include "exec/user/tswap-target.h"
 
 /* this flag is uneffective under linux too, should be deleted */
 #ifndef MAP_DENYWRITE
bsd-user/openbsd/target_os_elf.h +1 -0
index 6dca9c5a85..fc1dfa2e49 100644
@@ -22,6 +22,7 @@
 
 #include "target_arch_elf.h"
 #include "elf.h"
+#include "exec/user/tswap-target.h"
 
 /* this flag is uneffective under linux too, should be deleted */
 #ifndef MAP_DENYWRITE
include/exec/cpu-all.h +0 -8
index b042d94892..95af418920 100644
@@ -36,14 +36,6 @@
 #define BSWAP_NEEDED
 #endif
 
-#if TARGET_LONG_SIZE == 4
-#define tswapl(s) tswap32(s)
-#define bswaptls(s) bswap32s(s)
-#else
-#define tswapl(s) tswap64(s)
-#define bswaptls(s) bswap64s(s)
-#endif
-
 /* Target-endianness CPU memory access functions. These fit into the
  * {ld,st}{type}{sign}{size}{endian}_p naming scheme described in bswap.h.
  */
include/exec/user/abitypes.h +1 -0
index 6178453d94..ed10d5fe7e 100644
@@ -2,6 +2,7 @@
 #define EXEC_USER_ABITYPES_H
 
 #include "cpu.h"
+#include "exec/user/tswap-target.h"
 
 #ifdef TARGET_ABI32
 #define TARGET_ABI_BITS 32
include/exec/user/tswap-target.h new file +22 -0
new file mode 100644
index 0000000000..ff302436fe
@@ -0,0 +1,22 @@
+/*
+ * target-specific swap() definitions
+ *
+ *  Copyright (c) 2003 Fabrice Bellard
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+#ifndef EXEC_USER_TSWAP_H
+#define EXEC_USER_TSWAP_H
+
+#include "exec/cpu-defs.h"
+#include "exec/tswap.h"
+
+#if TARGET_LONG_SIZE == 4
+#define tswapl(s) tswap32(s)
+#define bswaptls(s) bswap32s(s)
+#else
+#define tswapl(s) tswap64(s)
+#define bswaptls(s) bswap64s(s)
+#endif
+
+#endif
bsd-user/signal.c +1 -0
index ca31470772..7b2d25230a 100644
@@ -21,6 +21,7 @@
 #include "qemu/osdep.h"
 #include "qemu/log.h"
 #include "qemu.h"
+#include "exec/user/tswap-target.h"
 #include "gdbstub/user.h"
 #include "signal-common.h"
 #include "trace.h"
bsd-user/strace.c +1 -0
index 96499751eb..a1b738e63c 100644
@@ -22,6 +22,7 @@
 #include <sys/ioccom.h>
 
 #include "qemu.h"
+#include "exec/user/tswap-target.h"
 
 #include "os-strace.h"  /* OS dependent strace print functions */
 
linux-user/elfload.c +1 -0
index cf9e74468b..debea5c355 100644
@@ -6,6 +6,7 @@
 #include <sys/shm.h>
 
 #include "qemu.h"
+#include "exec/user/tswap-target.h"
 #include "user-internals.h"
 #include "signal-common.h"
 #include "loader.h"
linux-user/i386/signal.c +1 -0
index bc5d45302e..eea1fa68c9 100644
@@ -21,6 +21,7 @@
 #include "user-internals.h"
 #include "signal-common.h"
 #include "linux-user/trace.h"
+#include "exec/user/tswap-target.h"
 
 /* from the Linux kernel - /arch/x86/include/uapi/asm/sigcontext.h */
 
linux-user/ppc/signal.c +1 -0
index 7e7302823b..988b59a916 100644
@@ -21,6 +21,7 @@
 #include "user-internals.h"
 #include "signal-common.h"
 #include "linux-user/trace.h"
+#include "exec/user/tswap-target.h"
 #include "vdso-asmoffset.h"
 
 /* See arch/powerpc/include/asm/ucontext.h.  Only used for 32-bit PPC;
Signature · 1 line
2.41.0
Reviewed-by on v2 16/23
#25 lore raw

Re: [PATCH v2 16/23] exec: Move [b]tswapl() declarations to 'exec/user/tswap-target.h'

Quoted 191 lines · Philippe Mathieu-Daudé

tswapl() and bswaptls() are target-dependent and only used by user emulation. Move their definitions to a new header:
"exec/user/tswap-target.h".

---
 bsd-user/freebsd/target_os_elf.h   |  1 +
 bsd-user/freebsd/target_os_stack.h |  1 +
 bsd-user/netbsd/target_os_elf.h    |  1 +
 bsd-user/openbsd/target_os_elf.h   |  1 +
 include/exec/cpu-all.h             |  8 --------
 include/exec/user/abitypes.h       |  1 +
 include/exec/user/tswap-target.h   | 22 ++++++++++++++++++++++
 bsd-user/signal.c                  |  1 +
 bsd-user/strace.c                  |  1 +
 linux-user/elfload.c               |  1 +
 linux-user/i386/signal.c           |  1 +
 linux-user/ppc/signal.c            |  1 +
 12 files changed, 32 insertions(+), 8 deletions(-)
 create mode 100644 include/exec/user/tswap-target.h
bsd-user/freebsd/target_os_elf.h +1 -0
index 9df17d56d8..27d8ce036c 100644
@@ -22,6 +22,7 @@
 
 #include "target_arch_elf.h"
 #include "elf.h"
+#include "exec/user/tswap-target.h"
 
 #define bsd_get_ncpu() 1 /* until we pull in bsd-proc.[hc] */
 
bsd-user/freebsd/target_os_stack.h +1 -0
index d15fc3263f..6125208182 100644
@@ -23,6 +23,7 @@
 #include <sys/param.h>
 #include "target_arch_sigtramp.h"
 #include "qemu/guest-random.h"
+#include "exec/user/tswap-target.h"
 
 /*
  * The initial FreeBSD stack is as follows:
bsd-user/netbsd/target_os_elf.h +1 -0
index 2f3cb20871..23b422bfce 100644
@@ -22,6 +22,7 @@
 
 #include "target_arch_elf.h"
 #include "elf.h"
+#include "exec/user/tswap-target.h"
 
 /* this flag is uneffective under linux too, should be deleted */
 #ifndef MAP_DENYWRITE
bsd-user/openbsd/target_os_elf.h +1 -0
index 6dca9c5a85..fc1dfa2e49 100644
@@ -22,6 +22,7 @@
 
 #include "target_arch_elf.h"
 #include "elf.h"
+#include "exec/user/tswap-target.h"
 
 /* this flag is uneffective under linux too, should be deleted */
 #ifndef MAP_DENYWRITE
include/exec/cpu-all.h +0 -8
index b042d94892..95af418920 100644
@@ -36,14 +36,6 @@
 #define BSWAP_NEEDED
 #endif
 
-#if TARGET_LONG_SIZE == 4
-#define tswapl(s) tswap32(s)
-#define bswaptls(s) bswap32s(s)
-#else
-#define tswapl(s) tswap64(s)
-#define bswaptls(s) bswap64s(s)
-#endif
-
 /* Target-endianness CPU memory access functions. These fit into the
  * {ld,st}{type}{sign}{size}{endian}_p naming scheme described in bswap.h.
  */
include/exec/user/abitypes.h +1 -0
index 6178453d94..ed10d5fe7e 100644
@@ -2,6 +2,7 @@
 #define EXEC_USER_ABITYPES_H
 
 #include "cpu.h"
+#include "exec/user/tswap-target.h"
 
 #ifdef TARGET_ABI32
 #define TARGET_ABI_BITS 32
include/exec/user/tswap-target.h new file +22 -0
new file mode 100644
index 0000000000..ff302436fe
@@ -0,0 +1,22 @@
+/*
+ * target-specific swap() definitions
+ *
+ *  Copyright (c) 2003 Fabrice Bellard
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+#ifndef EXEC_USER_TSWAP_H
+#define EXEC_USER_TSWAP_H
+
+#include "exec/cpu-defs.h"
+#include "exec/tswap.h"
+
+#if TARGET_LONG_SIZE == 4
+#define tswapl(s) tswap32(s)
+#define bswaptls(s) bswap32s(s)
+#else
+#define tswapl(s) tswap64(s)
+#define bswaptls(s) bswap64s(s)
+#endif
+
+#endif
bsd-user/signal.c +1 -0
index ca31470772..7b2d25230a 100644
@@ -21,6 +21,7 @@
 #include "qemu/osdep.h"
 #include "qemu/log.h"
 #include "qemu.h"
+#include "exec/user/tswap-target.h"
 #include "gdbstub/user.h"
 #include "signal-common.h"
 #include "trace.h"
bsd-user/strace.c +1 -0
index 96499751eb..a1b738e63c 100644
@@ -22,6 +22,7 @@
 #include <sys/ioccom.h>
 
 #include "qemu.h"
+#include "exec/user/tswap-target.h"
 
 #include "os-strace.h"  /* OS dependent strace print functions */
 
linux-user/elfload.c +1 -0
index cf9e74468b..debea5c355 100644
@@ -6,6 +6,7 @@
 #include <sys/shm.h>
 
 #include "qemu.h"
+#include "exec/user/tswap-target.h"
 #include "user-internals.h"
 #include "signal-common.h"
 #include "loader.h"
linux-user/i386/signal.c +1 -0
index bc5d45302e..eea1fa68c9 100644
@@ -21,6 +21,7 @@
 #include "user-internals.h"
 #include "signal-common.h"
 #include "linux-user/trace.h"
+#include "exec/user/tswap-target.h"
 
 /* from the Linux kernel - /arch/x86/include/uapi/asm/sigcontext.h */
 
linux-user/ppc/signal.c +1 -0
index 7e7302823b..988b59a916 100644
@@ -21,6 +21,7 @@
 #include "user-internals.h"
 #include "signal-common.h"
 #include "linux-user/trace.h"
+#include "exec/user/tswap-target.h"
 #include "vdso-asmoffset.h"
 
 /* See arch/powerpc/include/asm/ucontext.h.  Only used for 32-bit PPC;
Signature · 1 line
2.41.0
#26 lore raw

PATCH v2 17/23 target/ppc/excp_helper: Avoid 'abi_ptr' in system emulation

In reply to Philippe Mathieu-Daudé

'abi_ptr' is a user specific type. The system emulation equivalent is 'target_ulong'. Use it in ppc_ldl_code() to emphasis this is not an user emulation function.

---
 target/ppc/excp_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/ppc/excp_helper.c +1 -1
index a42743a3e0..3d7c9bbf1a 100644
@@ -142,7 +142,7 @@ static inline bool insn_need_byteswap(CPUArchState *env)
     return !!(env->msr & ((target_ulong)1 << MSR_LE));
 }
 
-static uint32_t ppc_ldl_code(CPUArchState *env, abi_ptr addr)
+static uint32_t ppc_ldl_code(CPUArchState *env, target_ulong addr)
 {
     uint32_t insn = cpu_ldl_code(env, addr);
 
Signature · 1 line
2.41.0
Reviewed-by on v2 17/23
#27 lore raw

Re: [PATCH v2 17/23] target/ppc/excp_helper: Avoid 'abi_ptr' in system emulation

Quoted 14 lines · Philippe Mathieu-Daudé

'abi_ptr' is a user specific type. The system emulation equivalent is 'target_ulong'. Use it in ppc_ldl_code() to emphasis this is not an user emulation function.

---
  target/ppc/excp_helper.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
target/ppc/excp_helper.c +0 -0
index a42743a3e0..3d7c9bbf1a 100644

target/ppc/excp_helper.c static inline bool insn_need_byteswap(CPUArchState *env) · line 148

Quoted 8 lines
target/ppc/excp_helper.c +1 -1
@@ -142,7 +142,7 @@ static inline bool insn_need_byteswap(CPUArchState *env)
      return !!(env->msr & ((target_ulong)1 << MSR_LE));
  }
 
-static uint32_t ppc_ldl_code(CPUArchState *env, abi_ptr addr)
+static uint32_t ppc_ldl_code(CPUArchState *env, target_ulong addr)
  {
      uint32_t insn = cpu_ldl_code(env, addr);
 
#28 lore raw

PATCH v2 18/23 accel/tcg: Un-inline retaddr helpers to 'user-retaddr.h'

In reply to Philippe Mathieu-Daudé

set_helper_retaddr() is only used in accel/tcg/user-exec.c.

clear_helper_retaddr() is only used in accel/tcg/user-exec.c and accel/tcg/user-exec.c.

No need to expose their definitions to all user-emulation files including "exec/cpu_ldst.h", move them to a new "user-retaddr.h" header (restricted to accel/tcg/).

---
 accel/tcg/user-retaddr.h | 28 ++++++++++++++++++++++++++++
 include/exec/cpu_ldst.h  | 28 ++--------------------------
 accel/tcg/cpu-exec.c     |  3 +++
 accel/tcg/user-exec.c    |  1 +
 4 files changed, 34 insertions(+), 26 deletions(-)
 create mode 100644 accel/tcg/user-retaddr.h
accel/tcg/user-retaddr.h new file +28 -0
new file mode 100644
index 0000000000..e0f57e1994
@@ -0,0 +1,28 @@
+#ifndef ACCEL_TCG_USER_RETADDR_H
+#define ACCEL_TCG_USER_RETADDR_H
+
+#include "qemu/atomic.h"
+
+extern __thread uintptr_t helper_retaddr;
+
+static inline void set_helper_retaddr(uintptr_t ra)
+{
+    helper_retaddr = ra;
+    /*
+     * Ensure that this write is visible to the SIGSEGV handler that
+     * may be invoked due to a subsequent invalid memory operation.
+     */
+    signal_barrier();
+}
+
+static inline void clear_helper_retaddr(void)
+{
+    /*
+     * Ensure that previous memory operations have succeeded before
+     * removing the data visible to the signal handler.
+     */
+    signal_barrier();
+    helper_retaddr = 0;
+}
+
+#endif
include/exec/cpu_ldst.h +2 -26
index 6061e33ac9..25e7239cc5 100644
@@ -300,31 +300,7 @@ Int128 cpu_atomic_cmpxchgo_be_mmu(CPUArchState *env, abi_ptr addr,
                                   Int128 cmpv, Int128 newv,
                                   MemOpIdx oi, uintptr_t retaddr);
 
-#if defined(CONFIG_USER_ONLY)
-
-extern __thread uintptr_t helper_retaddr;
-
-static inline void set_helper_retaddr(uintptr_t ra)
-{
-    helper_retaddr = ra;
-    /*
-     * Ensure that this write is visible to the SIGSEGV handler that
-     * may be invoked due to a subsequent invalid memory operation.
-     */
-    signal_barrier();
-}
-
-static inline void clear_helper_retaddr(void)
-{
-    /*
-     * Ensure that previous memory operations have succeeded before
-     * removing the data visible to the signal handler.
-     */
-    signal_barrier();
-    helper_retaddr = 0;
-}
-
-#else
+#if !defined(CONFIG_USER_ONLY)
 
 #include "tcg/oversized-guest.h"
 
@@ -376,7 +352,7 @@ static inline CPUTLBEntry *tlb_entry(CPUState *cpu, uintptr_t mmu_idx,
     return &cpu->neg.tlb.f[mmu_idx].table[tlb_index(cpu, mmu_idx, addr)];
 }
 
-#endif /* defined(CONFIG_USER_ONLY) */
+#endif /* !defined(CONFIG_USER_ONLY) */
 
 #if TARGET_BIG_ENDIAN
 # define cpu_lduw_data        cpu_lduw_be_data
accel/tcg/cpu-exec.c +3 -0
index c938eb96f8..e591992d0c 100644
@@ -44,6 +44,9 @@
 #include "tb-context.h"
 #include "internal-common.h"
 #include "internal-target.h"
+#if defined(CONFIG_USER_ONLY)
+#include "user-retaddr.h"
+#endif
 
 /* -icount align implementation. */
 
accel/tcg/user-exec.c +1 -0
index 68b252cb8e..2575f0842f 100644
@@ -31,6 +31,7 @@
 #include "tcg/tcg-ldst.h"
 #include "internal-common.h"
 #include "internal-target.h"
+#include "user-retaddr.h"
 
 __thread uintptr_t helper_retaddr;
 
Signature · 1 line
2.41.0
#29 lore raw

PATCH v2 19/23 exec/user: Do not include 'cpu.h' in 'abitypes.h'

In reply to Philippe Mathieu-Daudé

"exec/user/abitypes.h" requires:

- "exec/cpu-defs.h" (TARGET_LONG_BITS)
- "exec/tswap.h" (tswap32)

In order to avoid "cpu.h", pick the minimum required headers.

Assert this user-specific header is only included from user emulation.

---
 include/exec/user/abitypes.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
include/exec/user/abitypes.h +6 -1
index ed10d5fe7e..fbb55684d3 100644
@@ -1,7 +1,12 @@
 #ifndef EXEC_USER_ABITYPES_H
 #define EXEC_USER_ABITYPES_H
 
-#include "cpu.h"
+#ifndef CONFIG_USER_ONLY
+#error Cannot include this header from system emulation
+#endif
+
+#include "exec/cpu-defs.h"
+#include "exec/tswap.h"
 #include "exec/user/tswap-target.h"
 
 #ifdef TARGET_ABI32
Signature · 1 line
2.41.0
Reviewed-by on v2 19/23
#30 lore raw

Re: [PATCH v2 19/23] exec/user: Do not include 'cpu.h' in 'abitypes.h'

Quoted 7 lines · Philippe Mathieu-Daudé

"exec/user/abitypes.h" requires:

- "exec/cpu-defs.h" (TARGET_LONG_BITS)
- "exec/tswap.h" (tswap32)

In order to avoid "cpu.h", pick the minimum required headers.

Quoted 7 lines

Assert this user-specific header is only included from user emulation.

---
  include/exec/user/abitypes.h | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)
#31 lore raw

PATCH v2 20/23 exec: Declare abi_ptr type in its own 'abi_ptr.h' header

In reply to Philippe Mathieu-Daudé

The abi_ptr type is declared in "exec/cpu_ldst.h" with all the load/store helpers. Some source files requiring abi_ptr type don't need the load/store helpers. In order to simplify, create a new "exec/abi_ptr.h" header.

---
 include/exec/abi_ptr.h    | 33 +++++++++++++++++++++++++++++++++
 include/exec/cpu_ldst.h   | 17 +++--------------
 include/exec/exec-all.h   |  1 +
 include/exec/translator.h |  5 ++++-
 accel/tcg/cputlb.c        |  1 +
 5 files changed, 42 insertions(+), 15 deletions(-)
 create mode 100644 include/exec/abi_ptr.h
include/exec/abi_ptr.h new file +33 -0
new file mode 100644
index 0000000000..2b6ae470c4
@@ -0,0 +1,33 @@
+/*
+ * QEMU abi_ptr type
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+#ifndef EXEC_ABI_PTR_H
+#define EXEC_ABI_PTR_H
+
+#include "cpu-param.h"
+
+#if defined(CONFIG_USER_ONLY)
+/*
+ * sparc32plus has 64bit long but 32bit space address
+ * this can make bad result with g2h() and h2g()
+ */
+#if TARGET_VIRT_ADDR_SPACE_BITS <= 32
+typedef uint32_t abi_ptr;
+#define TARGET_ABI_FMT_ptr "%x"
+#else
+typedef uint64_t abi_ptr;
+#define TARGET_ABI_FMT_ptr "%"PRIx64
+#endif
+
+#else /* !CONFIG_USER_ONLY */
+
+#include "exec/target_long.h"
+
+typedef target_ulong abi_ptr;
+#define TARGET_ABI_FMT_ptr TARGET_FMT_lx
+
+#endif /* !CONFIG_USER_ONLY */
+
+#endif
include/exec/cpu_ldst.h +3 -14
index 25e7239cc5..64e0319996 100644
@@ -63,20 +63,11 @@
 #define CPU_LDST_H
 
 #include "exec/memopidx.h"
+#include "exec/abi_ptr.h"
 #include "qemu/int128.h"
 #include "cpu.h"
 
 #if defined(CONFIG_USER_ONLY)
-/* sparc32plus has 64bit long but 32bit space address
- * this can make bad result with g2h() and h2g()
- */
-#if TARGET_VIRT_ADDR_SPACE_BITS <= 32
-typedef uint32_t abi_ptr;
-#define TARGET_ABI_FMT_ptr "%x"
-#else
-typedef uint64_t abi_ptr;
-#define TARGET_ABI_FMT_ptr "%"PRIx64
-#endif
 
 #ifndef TARGET_TAGGED_ADDRESSES
 static inline abi_ptr cpu_untagged_addr(CPUState *cs, abi_ptr x)
@@ -120,10 +111,8 @@ static inline bool guest_range_valid_untagged(abi_ulong start, abi_ulong len)
     assert(h2g_valid(x)); \
     h2g_nocheck(x); \
 })
-#else
-typedef target_ulong abi_ptr;
-#define TARGET_ABI_FMT_ptr TARGET_FMT_lx
-#endif
+
+#endif /* CONFIG_USER_ONLY */
 
 uint32_t cpu_ldub_data(CPUArchState *env, abi_ptr ptr);
 int cpu_ldsb_data(CPUArchState *env, abi_ptr ptr);
include/exec/exec-all.h +1 -0
index df3d93a2e2..5b6be2de6c 100644
@@ -22,6 +22,7 @@
 
 #include "cpu.h"
 #if defined(CONFIG_USER_ONLY)
+#include "exec/abi_ptr.h"
 #include "exec/cpu_ldst.h"
 #endif
 #include "exec/translation-block.h"
include/exec/translator.h +4 -1
index 6d3f59d095..574058b900 100644
@@ -19,7 +19,10 @@
  */
 
 #include "qemu/bswap.h"
-#include "exec/cpu_ldst.h"	/* for abi_ptr */
+#include "exec/cpu-common.h"
+#include "exec/cpu-defs.h"
+#include "exec/abi_ptr.h"
+#include "cpu.h"
 
 /**
  * gen_intermediate_code
accel/tcg/cputlb.c +1 -0
index db3f93fda9..852a55fbb6 100644
@@ -34,6 +34,7 @@
 #include "qemu/atomic.h"
 #include "qemu/atomic128.h"
 #include "exec/translate-all.h"
+#include "exec/abi_ptr.h"
 #include "trace.h"
 #include "tb-hash.h"
 #include "internal-common.h"
Signature · 1 line
2.41.0
#32 lore raw

PATCH v2 21/23 exec/cpu-all: Restrict inclusion of 'exec/user/guest-base.h'

In reply to Philippe Mathieu-Daudé

Declare 'have_guest_base' in "exec/user/guest-base.h". Very few files require this header, so explicitly include it there instead of "exec/cpu-all.h" which is used in many source files.
Assert this user-specific header is only included from user emulation.

---
 include/exec/cpu-all.h         | 3 ---
 include/exec/cpu_ldst.h        | 2 ++
 include/exec/user/guest-base.h | 6 ++++++
 bsd-user/main.c                | 1 +
 linux-user/elfload.c           | 1 +
 linux-user/main.c              | 1 +
 6 files changed, 11 insertions(+), 3 deletions(-)
include/exec/cpu-all.h +0 -3
index 95af418920..d2ddfae286 100644
@@ -65,9 +65,6 @@
 
 #if defined(CONFIG_USER_ONLY)
 #include "exec/user/abitypes.h"
-#include "exec/user/guest-base.h"
-
-extern bool have_guest_base;
 
 /*
  * If non-zero, the guest virtual address space is a contiguous subset
include/exec/cpu_ldst.h +2 -0
index 64e0319996..e039cc7f80 100644
@@ -69,6 +69,8 @@
 
 #if defined(CONFIG_USER_ONLY)
 
+#include "exec/user/guest-base.h"
+
 #ifndef TARGET_TAGGED_ADDRESSES
 static inline abi_ptr cpu_untagged_addr(CPUState *cs, abi_ptr x)
 {
include/exec/user/guest-base.h +6 -0
index afe2ab7fbb..cf40151360 100644
@@ -7,6 +7,12 @@
 #ifndef EXEC_USER_GUEST_BASE_H
 #define EXEC_USER_GUEST_BASE_H
 
+#ifndef CONFIG_USER_ONLY
+#error Cannot include this header from system emulation
+#endif
+
 extern uintptr_t guest_base;
 
+extern bool have_guest_base;
+
 #endif
bsd-user/main.c +1 -0
index e6014f517e..c331d727e1 100644
@@ -36,6 +36,7 @@
 #include "qemu/help_option.h"
 #include "qemu/module.h"
 #include "exec/exec-all.h"
+#include "exec/user/guest-base.h"
 #include "tcg/startup.h"
 #include "qemu/timer.h"
 #include "qemu/envlist.h"
linux-user/elfload.c +1 -0
index debea5c355..a8c106ec0c 100644
@@ -7,6 +7,7 @@
 
 #include "qemu.h"
 #include "exec/user/tswap-target.h"
+#include "exec/user/guest-base.h"
 #include "user-internals.h"
 #include "signal-common.h"
 #include "loader.h"
linux-user/main.c +1 -0
index 0cdaf30d34..84691d707b 100644
@@ -38,6 +38,7 @@
 #include "qemu/help_option.h"
 #include "qemu/module.h"
 #include "qemu/plugin.h"
+#include "exec/user/guest-base.h"
 #include "exec/exec-all.h"
 #include "exec/gdbstub.h"
 #include "gdbstub/user.h"
Signature · 1 line
2.41.0
#33 lore raw

PATCH v2 22/23 exec/cpu-all: Extract page-protection definitions to page-prot-common.h

In reply to Philippe Mathieu-Daudé

Extract page-protection definitions from "exec/cpu-all.h" to "exec/page-prot-common.h".

The list of files requiring the new header was generated using:

$ git grep -wE \
  'PAGE_(READ|WRITE|EXEC|BITS|VALID|ANON|RESERVED|TARGET_.|PASSTHROUGH)'
---
 bsd-user/bsd-mem.h                   |  1 +
 bsd-user/qemu.h                      |  1 +
 include/exec/cpu-all.h               | 35 +------------------------
 include/exec/page-prot-common.h      | 38 ++++++++++++++++++++++++++++
 include/semihosting/uaccess.h        |  1 +
 target/arm/cpu.h                     |  1 +
 target/ppc/internal.h                |  1 +
 target/ppc/mmu-radix64.h             |  2 ++
 accel/tcg/cputlb.c                   |  1 +
 accel/tcg/tb-maint.c                 |  1 +
 accel/tcg/user-exec.c                |  1 +
 bsd-user/mmap.c                      |  1 +
 bsd-user/signal.c                    |  1 +
 cpu-target.c                         |  1 +
 hw/ppc/ppc440_bamboo.c               |  1 +
 hw/ppc/sam460ex.c                    |  1 +
 hw/ppc/virtex_ml507.c                |  1 +
 linux-user/arm/cpu_loop.c            |  1 +
 linux-user/elfload.c                 |  1 +
 linux-user/mmap.c                    |  1 +
 linux-user/nios2/cpu_loop.c          |  1 +
 linux-user/signal.c                  |  1 +
 linux-user/syscall.c                 |  1 +
 system/physmem.c                     |  1 +
 target/alpha/helper.c                |  1 +
 target/arm/ptw.c                     |  1 +
 target/arm/tcg/m_helper.c            |  1 +
 target/arm/tcg/mte_helper.c          |  1 +
 target/arm/tcg/sve_helper.c          |  1 +
 target/avr/helper.c                  |  1 +
 target/cris/mmu.c                    |  1 +
 target/hppa/mem_helper.c             |  1 +
 target/hppa/translate.c              |  1 +
 target/i386/tcg/sysemu/excp_helper.c |  1 +
 target/loongarch/tlb_helper.c        |  1 +
 target/m68k/helper.c                 |  1 +
 target/microblaze/helper.c           |  1 +
 target/microblaze/mmu.c              |  1 +
 target/mips/sysemu/physaddr.c        |  1 +
 target/mips/tcg/sysemu/tlb_helper.c  |  1 +
 target/nios2/helper.c                |  1 +
 target/nios2/mmu.c                   |  1 +
 target/openrisc/mmu.c                |  1 +
 target/ppc/mmu-hash32.c              |  1 +
 target/ppc/mmu-hash64.c              |  1 +
 target/ppc/mmu-radix64.c             |  1 +
 target/ppc/mmu_common.c              |  1 +
 target/ppc/mmu_helper.c              |  1 +
 target/riscv/cpu_helper.c            |  1 +
 target/riscv/pmp.c                   |  1 +
 target/riscv/vector_helper.c         |  1 +
 target/rx/cpu.c                      |  1 +
 target/s390x/mmu_helper.c            |  1 +
 target/s390x/tcg/mem_helper.c        |  1 +
 target/sh4/helper.c                  |  1 +
 target/sparc/ldst_helper.c           |  1 +
 target/sparc/mmu_helper.c            |  1 +
 target/tricore/helper.c              |  1 +
 target/xtensa/mmu_helper.c           |  1 +
 target/xtensa/op_helper.c            |  1 +
 60 files changed, 98 insertions(+), 34 deletions(-)
 create mode 100644 include/exec/page-prot-common.h
bsd-user/bsd-mem.h +1 -0
index 21d9bab889..f95472bcab 100644
@@ -56,6 +56,7 @@
 #include <fcntl.h>
 
 #include "qemu-bsd.h"
+#include "exec/page-prot-common.h"
 
 extern struct bsd_shm_regions bsd_shm_regions[];
 extern abi_ulong target_brk;
bsd-user/qemu.h +1 -0
index dc842fffa7..1e38d2cb66 100644
@@ -36,6 +36,7 @@ extern char **environ;
 #include "target_os_signal.h"
 #include "target.h"
 #include "exec/gdbstub.h"
+#include "exec/page-prot-common.h"
 #include "qemu/clang-tsa.h"
 
 #include "qemu-os.h"
include/exec/cpu-all.h +1 -34
index d2ddfae286..1e67085d47 100644
@@ -19,6 +19,7 @@
 #ifndef CPU_ALL_H
 #define CPU_ALL_H
 
+#include "exec/page-prot-common.h"
 #include "exec/cpu-common.h"
 #include "exec/memory.h"
 #include "exec/tswap.h"
@@ -156,40 +157,6 @@ extern const TargetPageBits target_page;
 
 #define TARGET_PAGE_ALIGN(addr) ROUND_UP((addr), TARGET_PAGE_SIZE)
 
-/* same as PROT_xxx */
-#define PAGE_READ      0x0001
-#define PAGE_WRITE     0x0002
-#define PAGE_EXEC      0x0004
-#define PAGE_BITS      (PAGE_READ | PAGE_WRITE | PAGE_EXEC)
-#define PAGE_VALID     0x0008
-/*
- * Original state of the write flag (used when tracking self-modifying code)
- */
-#define PAGE_WRITE_ORG 0x0010
-/*
- * Invalidate the TLB entry immediately, helpful for s390x
- * Low-Address-Protection. Used with PAGE_WRITE in tlb_set_page_with_attrs()
- */
-#define PAGE_WRITE_INV 0x0020
-/* For use with page_set_flags: page is being replaced; target_data cleared. */
-#define PAGE_RESET     0x0040
-/* For linux-user, indicates that the page is MAP_ANON. */
-#define PAGE_ANON      0x0080
-
-#if defined(CONFIG_BSD) && defined(CONFIG_USER_ONLY)
-/* FIXME: Code that sets/uses this is broken and needs to go away.  */
-#define PAGE_RESERVED  0x0100
-#endif
-/* Target-specific bits that will be used via page_get_flags().  */
-#define PAGE_TARGET_1  0x0200
-#define PAGE_TARGET_2  0x0400
-
-/*
- * For linux-user, indicates that the page is mapped with the same semantics
- * in both guest and host.
- */
-#define PAGE_PASSTHROUGH 0x0800
-
 #if defined(CONFIG_USER_ONLY)
 void page_dump(FILE *f);
 
include/exec/page-prot-common.h new file +38 -0
new file mode 100644
index 0000000000..a38157e8b9
@@ -0,0 +1,38 @@
+#ifndef EXEC_PAGE_PROT_COMMON_H
+#define EXEC_PAGE_PROT_COMMON_H
+
+/* same as PROT_xxx */
+#define PAGE_READ      0x0001
+#define PAGE_WRITE     0x0002
+#define PAGE_EXEC      0x0004
+#define PAGE_BITS      (PAGE_READ | PAGE_WRITE | PAGE_EXEC)
+#define PAGE_VALID     0x0008
+/*
+ * Original state of the write flag (used when tracking self-modifying code)
+ */
+#define PAGE_WRITE_ORG 0x0010
+/*
+ * Invalidate the TLB entry immediately, helpful for s390x
+ * Low-Address-Protection. Used with PAGE_WRITE in tlb_set_page_with_attrs()
+ */
+#define PAGE_WRITE_INV 0x0020
+/* For use with page_set_flags: page is being replaced; target_data cleared. */
+#define PAGE_RESET     0x0040
+/* For linux-user, indicates that the page is MAP_ANON. */
+#define PAGE_ANON      0x0080
+
+#if defined(CONFIG_BSD) && defined(CONFIG_USER_ONLY)
+/* FIXME: Code that sets/uses this is broken and needs to go away.  */
+#define PAGE_RESERVED  0x0100
+#endif
+/* Target-specific bits that will be used via page_get_flags().  */
+#define PAGE_TARGET_1  0x0200
+#define PAGE_TARGET_2  0x0400
+
+/*
+ * For linux-user, indicates that the page is mapped with the same semantics
+ * in both guest and host.
+ */
+#define PAGE_PASSTHROUGH 0x0800
+
+#endif
include/semihosting/uaccess.h +1 -0
index 6c8835fbcb..02783cca33 100644
@@ -15,6 +15,7 @@
 #endif
 
 #include "exec/cpu-defs.h"
+#include "exec/page-prot-common.h"
 
 #define get_user_u64(val, addr)                                         \
     ({ uint64_t val_ = 0;                                               \
target/arm/cpu.h +1 -0
index ea5c8660dc..c14012e07d 100644
@@ -25,6 +25,7 @@
 #include "hw/registerfields.h"
 #include "cpu-qom.h"
 #include "exec/cpu-defs.h"
+#include "exec/page-prot-common.h"
 #include "qapi/qapi-types-common.h"
 
 #ifdef TARGET_AARCH64
target/ppc/internal.h +1 -0
index 5b20ecbd33..6bcfbcbed8 100644
@@ -19,6 +19,7 @@
 #define PPC_INTERNAL_H
 
 #include "hw/registerfields.h"
+#include "exec/page-prot-common.h"
 
 /* PM instructions */
 typedef enum {
target/ppc/mmu-radix64.h +2 -0
index 4c768aa5cc..1a3fd8f65b 100644
@@ -3,6 +3,8 @@
 
 #ifndef CONFIG_USER_ONLY
 
+#include "exec/page-prot-common.h"
+
 /* Radix Quadrants */
 #define R_EADDR_MASK            0x3FFFFFFFFFFFFFFF
 #define R_EADDR_VALID_MASK      0xC00FFFFFFFFFFFFF
accel/tcg/cputlb.c +1 -0
index 852a55fbb6..4e9d6fdb19 100644
@@ -21,6 +21,7 @@
 #include "qemu/main-loop.h"
 #include "hw/core/tcg-cpu-ops.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "exec/memory.h"
 #include "exec/cpu_ldst.h"
 #include "exec/cputlb.h"
accel/tcg/tb-maint.c +1 -0
index da39a43bd8..717e31e602 100644
@@ -23,6 +23,7 @@
 #include "exec/cputlb.h"
 #include "exec/log.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "exec/tb-flush.h"
 #include "exec/translate-all.h"
 #include "sysemu/tcg.h"
accel/tcg/user-exec.c +1 -0
index 2575f0842f..5ce602b8d6 100644
@@ -25,6 +25,7 @@
 #include "qemu/rcu.h"
 #include "exec/cpu_ldst.h"
 #include "exec/translate-all.h"
+#include "exec/page-prot-common.h"
 #include "exec/helper-proto.h"
 #include "qemu/atomic128.h"
 #include "trace/trace-root.h"
bsd-user/mmap.c +1 -0
index 3ef11b2807..deb384605e 100644
@@ -17,6 +17,7 @@
  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 #include "qemu/osdep.h"
+#include "exec/page-prot-common.h"
 
 #include "qemu.h"
 
bsd-user/signal.c +1 -0
index 7b2d25230a..699ac60837 100644
@@ -21,6 +21,7 @@
 #include "qemu/osdep.h"
 #include "qemu/log.h"
 #include "qemu.h"
+#include "exec/page-prot-common.h"
 #include "exec/user/tswap-target.h"
 #include "gdbstub/user.h"
 #include "signal-common.h"
cpu-target.c +1 -0
index 4c1e19ca81..a7209e8de9 100644
@@ -21,6 +21,7 @@
 #include "qapi/error.h"
 
 #include "exec/target_page.h"
+#include "exec/page-prot-common.h"
 #include "hw/qdev-core.h"
 #include "hw/qdev-properties.h"
 #include "qemu/error-report.h"
hw/ppc/ppc440_bamboo.c +1 -0
index a189942de4..45a215be6d 100644
@@ -15,6 +15,7 @@
 #include "qemu/units.h"
 #include "qemu/datadir.h"
 #include "qemu/error-report.h"
+#include "exec/page-prot-common.h"
 #include "net/net.h"
 #include "hw/pci/pci.h"
 #include "hw/boards.h"
hw/ppc/sam460ex.c +1 -0
index 1e615b8d35..ffe467fb16 100644
@@ -21,6 +21,7 @@
 #include "kvm_ppc.h"
 #include "sysemu/device_tree.h"
 #include "sysemu/block-backend.h"
+#include "exec/page-prot-common.h"
 #include "hw/loader.h"
 #include "elf.h"
 #include "exec/memory.h"
hw/ppc/virtex_ml507.c +1 -0
index d02f330650..e2da13c064 100644
@@ -25,6 +25,7 @@
 #include "qemu/osdep.h"
 #include "qemu/datadir.h"
 #include "qemu/units.h"
+#include "exec/page-prot-common.h"
 #include "cpu.h"
 #include "hw/sysbus.h"
 #include "hw/char/serial.h"
linux-user/arm/cpu_loop.c +1 -0
index b404117ff3..0d05daea91 100644
@@ -24,6 +24,7 @@
 #include "cpu_loop-common.h"
 #include "signal-common.h"
 #include "semihosting/common-semi.h"
+#include "exec/page-prot-common.h"
 #include "target/arm/syndrome.h"
 
 #define get_user_code_u32(x, gaddr, env)                \
linux-user/elfload.c +1 -0
index a8c106ec0c..84484fee97 100644
@@ -8,6 +8,7 @@
 #include "qemu.h"
 #include "exec/user/tswap-target.h"
 #include "exec/user/guest-base.h"
+#include "exec/page-prot-common.h"
 #include "user-internals.h"
 #include "signal-common.h"
 #include "loader.h"
linux-user/mmap.c +1 -0
index 96c9433e27..d37803fc8c 100644
@@ -20,6 +20,7 @@
 #include <sys/shm.h>
 #include "trace.h"
 #include "exec/log.h"
+#include "exec/page-prot-common.h"
 #include "qemu.h"
 #include "user-internals.h"
 #include "user-mmap.h"
linux-user/nios2/cpu_loop.c +1 -0
index da77ede76b..03434abe3b 100644
@@ -22,6 +22,7 @@
 #include "user-internals.h"
 #include "cpu_loop-common.h"
 #include "signal-common.h"
+#include "exec/page-prot-common.h"
 
 void cpu_loop(CPUNios2State *env)
 {
linux-user/signal.c +1 -0
index b35d1e512f..50cba136db 100644
@@ -19,6 +19,7 @@
 #include "qemu/osdep.h"
 #include "qemu/bitops.h"
 #include "gdbstub/user.h"
+#include "exec/page-prot-common.h"
 #include "hw/core/tcg-cpu-ops.h"
 
 #include <sys/ucontext.h>
linux-user/syscall.c +1 -0
index e384e14248..3d2467d7c8 100644
@@ -25,6 +25,7 @@
 #include "qemu/plugin.h"
 #include "tcg/startup.h"
 #include "target_mman.h"
+#include "exec/page-prot-common.h"
 #include <elf.h>
 #include <endian.h>
 #include <grp.h>
system/physmem.c +1 -0
index 4bdb3d0592..0bea47b5d2 100644
@@ -31,6 +31,7 @@
 #endif /* CONFIG_TCG */
 
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "exec/target_page.h"
 #include "hw/qdev-core.h"
 #include "hw/qdev-properties.h"
target/alpha/helper.c +1 -0
index 970c869771..ea7a769644 100644
@@ -21,6 +21,7 @@
 #include "qemu/log.h"
 #include "cpu.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "fpu/softfloat-types.h"
 #include "exec/helper-proto.h"
 #include "qemu/qemu-print.h"
target/arm/ptw.c +1 -0
index 1762b058ae..5eca492db4 100644
@@ -11,6 +11,7 @@
 #include "qemu/range.h"
 #include "qemu/main-loop.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "cpu.h"
 #include "internals.h"
 #include "cpu-features.h"
target/arm/tcg/m_helper.c +1 -0
index a26adb75aa..1198b32929 100644
@@ -16,6 +16,7 @@
 #include "qemu/bitops.h"
 #include "qemu/log.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #ifdef CONFIG_TCG
 #include "exec/cpu_ldst.h"
 #include "semihosting/common-semi.h"
target/arm/tcg/mte_helper.c +1 -0
index ffb8ea1c34..47f512e6c6 100644
@@ -22,6 +22,7 @@
 #include "cpu.h"
 #include "internals.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "exec/ram_addr.h"
 #include "exec/cpu_ldst.h"
 #include "exec/helper-proto.h"
target/arm/tcg/sve_helper.c +1 -0
index f006d152cc..7713b7a4d4 100644
@@ -21,6 +21,7 @@
 #include "cpu.h"
 #include "internals.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "exec/helper-proto.h"
 #include "tcg/tcg-gvec-desc.h"
 #include "fpu/softfloat.h"
target/avr/helper.c +1 -0
index fdc9884ea0..62758b00ed 100644
@@ -24,6 +24,7 @@
 #include "cpu.h"
 #include "hw/core/tcg-cpu-ops.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "exec/cpu_ldst.h"
 #include "exec/address-spaces.h"
 #include "exec/helper-proto.h"
target/cris/mmu.c +1 -0
index b574ec6e5b..dee485419d 100644
@@ -21,6 +21,7 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "mmu.h"
 
 #ifdef DEBUG
target/hppa/mem_helper.c +1 -0
index 08abd1a9f9..0d78e273f6 100644
@@ -21,6 +21,7 @@
 #include "qemu/log.h"
 #include "cpu.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "exec/helper-proto.h"
 #include "hw/core/cpu.h"
 #include "trace.h"
target/hppa/translate.c +1 -0
index 3ef39b1bd7..7e3867e4aa 100644
@@ -22,6 +22,7 @@
 #include "disas/disas.h"
 #include "qemu/host-utils.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "tcg/tcg-op.h"
 #include "tcg/tcg-op-gvec.h"
 #include "exec/helper-proto.h"
target/i386/tcg/sysemu/excp_helper.c +1 -0
index 5b86f439ad..a3bf3b7292 100644
@@ -21,6 +21,7 @@
 #include "cpu.h"
 #include "exec/cpu_ldst.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "tcg/helper-tcg.h"
 
 typedef struct TranslateParams {
target/loongarch/tlb_helper.c +1 -0
index 449043c68b..7f0e413e1e 100644
@@ -13,6 +13,7 @@
 #include "internals.h"
 #include "exec/helper-proto.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "exec/cpu_ldst.h"
 #include "exec/log.h"
 #include "cpu-csr.h"
target/m68k/helper.c +1 -0
index 0a1544cd68..7a69c4a28d 100644
@@ -21,6 +21,7 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "exec/gdbstub.h"
 #include "exec/helper-proto.h"
 #include "gdbstub/helpers.h"
target/microblaze/helper.c +1 -0
index 98bdb82de8..e4ce57560d 100644
@@ -21,6 +21,7 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "qemu/host-utils.h"
 #include "exec/log.h"
 
target/microblaze/mmu.c +1 -0
index 75651979a9..c0b0844f71 100644
@@ -22,6 +22,7 @@
 #include "qemu/log.h"
 #include "cpu.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 
 static unsigned int tlb_decode_size(unsigned int f)
 {
target/mips/sysemu/physaddr.c +1 -0
index 05990aa5bb..7ac51c6019 100644
@@ -19,6 +19,7 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "../internal.h"
 
 static int is_seg_am_mapped(unsigned int am, bool eu, int mmu_idx)
target/mips/tcg/sysemu/tlb_helper.c +1 -0
index 4ede904800..d0cb46bd1b 100644
@@ -22,6 +22,7 @@
 #include "cpu.h"
 #include "internal.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "exec/cpu_ldst.h"
 #include "exec/log.h"
 #include "exec/helper-proto.h"
target/nios2/helper.c +1 -0
index bb3b09e5a7..b64caa11f6 100644
@@ -23,6 +23,7 @@
 #include "cpu.h"
 #include "qemu/host-utils.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "exec/cpu_ldst.h"
 #include "exec/log.h"
 #include "exec/helper-proto.h"
target/nios2/mmu.c +1 -0
index d9b690b78e..da7f20cc07 100644
@@ -22,6 +22,7 @@
 #include "qemu/qemu-print.h"
 #include "cpu.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "mmu.h"
 #include "exec/helper-proto.h"
 #include "trace/trace-target_nios2.h"
target/openrisc/mmu.c +1 -0
index 603c26715e..6ca7cc023e 100644
@@ -22,6 +22,7 @@
 #include "qemu/log.h"
 #include "cpu.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "gdbstub/helpers.h"
 #include "qemu/host-utils.h"
 #include "hw/loader.h"
target/ppc/mmu-hash32.c +1 -0
index 3976416840..da446632c9 100644
@@ -21,6 +21,7 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "sysemu/kvm.h"
 #include "kvm_ppc.h"
 #include "internal.h"
target/ppc/mmu-hash64.c +1 -0
index d645c0bb94..1633a0e5d0 100644
@@ -21,6 +21,7 @@
 #include "qemu/units.h"
 #include "cpu.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "qemu/error-report.h"
 #include "qemu/qemu-print.h"
 #include "sysemu/hw_accel.h"
target/ppc/mmu-radix64.c +1 -0
index 5823e039e6..13f5ed7fb7 100644
@@ -20,6 +20,7 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "qemu/error-report.h"
 #include "sysemu/kvm.h"
 #include "kvm_ppc.h"
target/ppc/mmu_common.c +1 -0
index 6ca5d12207..83a91a92ea 100644
@@ -25,6 +25,7 @@
 #include "mmu-hash64.h"
 #include "mmu-hash32.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "exec/log.h"
 #include "helper_regs.h"
 #include "qemu/error-report.h"
target/ppc/mmu_helper.c +1 -0
index f87d35379a..6368dceb16 100644
@@ -25,6 +25,7 @@
 #include "mmu-hash64.h"
 #include "mmu-hash32.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "exec/log.h"
 #include "helper_regs.h"
 #include "qemu/error-report.h"
target/riscv/cpu_helper.c +1 -0
index e7e23b34f4..565e6614d9 100644
@@ -24,6 +24,7 @@
 #include "internals.h"
 #include "pmu.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "instmap.h"
 #include "tcg/tcg-op.h"
 #include "trace.h"
target/riscv/pmp.c +1 -0
index 162e88a90a..59f4c3d481 100644
@@ -25,6 +25,7 @@
 #include "cpu.h"
 #include "trace.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 
 static bool pmp_write_cfg(CPURISCVState *env, uint32_t addr_index,
                           uint8_t val);
target/riscv/vector_helper.c +1 -0
index c1c3a4d1ea..968bff34f2 100644
@@ -22,6 +22,7 @@
 #include "cpu.h"
 #include "exec/memop.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "exec/cpu_ldst.h"
 #include "exec/helper-proto.h"
 #include "fpu/softfloat.h"
target/rx/cpu.c +1 -0
index 9cc9d9d15e..6cc3173a1e 100644
@@ -22,6 +22,7 @@
 #include "cpu.h"
 #include "migration/vmstate.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "hw/loader.h"
 #include "fpu/softfloat.h"
 #include "tcg/debug-assert.h"
target/s390x/mmu_helper.c +1 -0
index fbb2f1b4d4..0b2240e39a 100644
@@ -24,6 +24,7 @@
 #include "sysemu/kvm.h"
 #include "sysemu/tcg.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "trace.h"
 #include "hw/hw.h"
 #include "hw/s390x/storage-keys.h"
target/s390x/tcg/mem_helper.c +1 -0
index 84103251b9..2a8ee4df6b 100644
@@ -25,6 +25,7 @@
 #include "tcg_s390x.h"
 #include "exec/helper-proto.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "exec/cpu_ldst.h"
 #include "hw/core/tcg-cpu-ops.h"
 #include "qemu/int128.h"
target/sh4/helper.c +1 -0
index 5a6f653c12..c9f41d1e2e 100644
@@ -21,6 +21,7 @@
 
 #include "cpu.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "exec/log.h"
 
 #if !defined(CONFIG_USER_ONLY)
target/sparc/ldst_helper.c +1 -0
index 09066d5487..078e25e363 100644
@@ -23,6 +23,7 @@
 #include "tcg/tcg.h"
 #include "exec/helper-proto.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "exec/cpu_ldst.h"
 #include "asi.h"
 
target/sparc/mmu_helper.c +1 -0
index 453498c670..e723868148 100644
@@ -21,6 +21,7 @@
 #include "qemu/log.h"
 #include "cpu.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "qemu/qemu-print.h"
 #include "trace.h"
 
target/tricore/helper.c +1 -0
index 7e5da3cb23..e736630a79 100644
@@ -20,6 +20,7 @@
 #include "hw/registerfields.h"
 #include "cpu.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 #include "fpu/softfloat-helpers.h"
 #include "qemu/qemu-print.h"
 
target/xtensa/mmu_helper.c +1 -0
index 12552a3347..d7611f1168 100644
@@ -33,6 +33,7 @@
 #include "exec/helper-proto.h"
 #include "qemu/host-utils.h"
 #include "exec/exec-all.h"
+#include "exec/page-prot-common.h"
 
 #define XTENSA_MPU_SEGMENT_MASK 0x0000001f
 #define XTENSA_MPU_ACC_RIGHTS_MASK 0x00000f00
target/xtensa/op_helper.c +1 -0
index 496754ba57..a9048ad6ac 100644
@@ -28,6 +28,7 @@
 #include "qemu/osdep.h"
 #include "cpu.h"
 #include "exec/helper-proto.h"
+#include "exec/page-prot-common.h"
 #include "qemu/host-utils.h"
 #include "exec/exec-all.h"
 #include "qemu/atomic.h"
Signature · 1 line
2.41.0
#34 lore raw

PATCH v2 23/23 exec/cpu_ldst: Avoid including 'cpu.h'

In reply to Philippe Mathieu-Daudé

"exec/cpu_ldst.h" doesn't need to huge "cpu.h" header, but simply:

- exec/cpu-defs.h (TARGET_LONG_BITS)
- exec/tlb-common.h (CPUTLBEntry)

 - exec/user/abitypes.h      (abi_ulong)
 - exec/user/guest-base.h    (guest_base)
 - exec/cpu-all.h            (GUEST_ADDR_MAX and env_cpu)

---
env_cpu() will soon be removed from "exec/cpu-all.h". Do we want to move GUEST_ADDR_MAX declaration to "user/guest-base.h", eventually renaming it as "user/guest-addr.h"?

---
 include/exec/cpu_ldst.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
include/exec/cpu_ldst.h +4 -1
index e039cc7f80..ec0784bf15 100644
@@ -65,11 +65,14 @@
 #include "exec/memopidx.h"
 #include "exec/abi_ptr.h"
 #include "qemu/int128.h"
-#include "cpu.h"
+#include "exec/cpu-defs.h"
+#include "exec/tlb-common.h"
 
 #if defined(CONFIG_USER_ONLY)
 
+#include "exec/user/abitypes.h"
 #include "exec/user/guest-base.h"
+#include "exec/cpu-all.h"
 
 #ifndef TARGET_TAGGED_ADDRESSES
 static inline abi_ptr cpu_untagged_addr(CPUState *cs, abi_ptr x)
Signature · 1 line
2.41.0
#35 lore raw
In reply to Philippe Mathieu-Daudé
Quoted 10 lines · Philippe Mathieu-Daudé

Philippe Mathieu-Daudé (23):

exec/cpu-all: Remove unused tswapls() definitions
exec: Move [b]tswapl() declarations to 'exec/user/tswap-target.h' target/ppc/excp_helper: Avoid 'abi_ptr' in system emulation accel/tcg: Un-inline retaddr helpers to 'user-retaddr.h' exec/user: Do not include 'cpu.h' in 'abitypes.h'
exec: Declare abi_ptr type in its own 'abi_ptr.h' header exec/cpu-all: Restrict inclusion of 'exec/user/guest-base.h'

Quoted 3 lines
  include/exec/user/abitypes.h                  |  8 ++-
  include/exec/user/guest-base.h                |  6 ++
  include/exec/user/tswap-target.h              | 22 +++++++

Missing:

-- >8 --

MAINTAINERS +1 -1
index 695e0bd34f..1341862c2c 100644
@@ -3615,6 +3615,7 @@ Overall usermode emulation
 M: Riku Voipio <[email protected]>
 S: Maintained
 F: accel/tcg/user-exec*.c
+F: include/exec/user/
 F: include/user/
 F: common-user/
---

(Although maybe the M: tag need some update)