Skip to contentSkip to conversation

exec: Rework of various headers (user focused)

PATCH Superseded Philippe Mathieu-Daudé 5 participants 56 messages Dec 11, 2023 – Dec 26, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

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.

Regards,

Phil.

Philippe Mathieu-Daudé (24):
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 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 hw/ppc/spapr_hcall: Remove unused 'exec/exec-all.h' included header hw/misc/mips_itu: Remove unnecessary 'exec/exec-all.h' header hw/s390x/ipl: Remove unused 'exec/exec-all.h' included header target/i386: Include missing 'exec/exec-all.h' header accel/tcg: Include missing 'hw/core/cpu.h' header
gdbstub: Include missing 'hw/core/cpu.h' header exec/cpu-all: Remove unused headers
exec/cpu-all: Reduce 'qemu/rcu.h' header inclusion 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 'tcg/abi_ptr.h' header exec/cpu_ldst: Avoid including 'cpu.h'
exec/cpu-all: Restrict inclusion of 'exec/user/guest-base.h' exec/cpu-all: Extract page-protection definitions to
page-prot-common.h
target: Restrict 'sysemu/reset.h' to system emulation

 meson.build                                   |  2 +-
 accel/tcg/user-retaddr.h                      | 28 ++++++++++
 bsd-user/bsd-mem.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/cpu-all.h                        | 50 +++---------------
 include/exec/cpu_ldst.h                       | 51 ++++---------------
 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/user/abitypes.h                  |  9 +++-
 include/exec/user/guest-base.h                |  6 +++
 include/semihosting/uaccess.h                 |  3 +-
 include/tcg/abi_ptr.h                         | 32 ++++++++++++
 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                       |  6 +++
 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                             |  1 +
 cpu-target.c                                  |  1 +
 gdbstub/gdbstub.c                             |  1 +
 hw/misc/mips_itu.c                            |  3 +-
 hw/ppc/ppc440_bamboo.c                        |  1 +
 hw/ppc/sam460ex.c                             |  1 +
 hw/ppc/spapr_hcall.c                          |  1 -
 hw/ppc/virtex_ml507.c                         |  1 +
 hw/s390x/ipl.c                                |  1 -
 linux-user/arm/cpu_loop.c                     |  1 +
 linux-user/elfload.c                          |  2 +
 linux-user/main.c                             |  1 +
 linux-user/mmap.c                             |  1 +
 linux-user/nios2/cpu_loop.c                   |  1 +
 linux-user/signal.c                           |  1 +
 linux-user/syscall.c                          |  1 +
 page-target.c                                 | 43 ++++++++++++++++
 semihosting/guestfd.c                         |  1 -
 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/cpu.c                             |  2 +-
 target/i386/tcg/fpu_helper.c                  |  1 +
 target/i386/tcg/sysemu/excp_helper.c          |  1 +
 target/loongarch/cpu.c                        |  2 +
 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 +
 118 files changed, 332 insertions(+), 192 deletions(-)
 create mode 100644 accel/tcg/user-retaddr.h
 create mode 100644 include/exec/page-prot-common.h
 create mode 100644 include/tcg/abi_ptr.h
 create mode 100644 page-target.c
Signature · 1 line
2.41.0
#1 lore raw

PATCH 1/24 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

Re: [PATCH 01/24] exec: Include 'cpu.h' before validating CPUArchState placement

Quoted 8 lines · Philippe Mathieu-Daudé

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(-)
Reviewed-by
#3 lore raw

Re: [PATCH 01/24] exec: Include 'cpu.h' before validating CPUArchState placement

Quoted 8 lines · Warner Losh
Quoted 3 lines · Philippe Mathieu-Daudé

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

Quoted 8 lines
Quoted 5 lines
---
 include/exec/cpu-all.h | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Brain f**** I meant:

#4 lore raw

PATCH 2/24 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
Reviewed-by on v1 2/24
#5 lore raw

Re: [PATCH 02/24] exec: Expose 'target_page.h' API to user emulation

Quoted 11 lines · 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
Reviewed-by on v1 2/24
#6 lore raw

Re: [PATCH 02/24] exec: Expose 'target_page.h' API to user emulation

In reply to Philippe Mathieu-Daudé
Quoted 10 lines · 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

r~

#7 lore raw

PATCH 3/24 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       |  6 ++++++
 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, 64 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 +6 -0
index bb3d7ef6f7..4548103a18 100644
@@ -21,4 +21,10 @@
 
 #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
#8 lore raw

Re: [PATCH 03/24] target: Define TCG_GUEST_DEFAULT_MO in 'cpu-param.h'

Quoted 50 lines · 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       |  6 ++++++
  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, 64 insertions(+), 62 deletions(-)
target/hppa/cpu-param.h +0 -0
index bb3d7ef6f7..4548103a18 100644

target/hppa/cpu-param.h line 27

Quoted 7 lines
target/hppa/cpu-param.h +4 -0
@@ -21,4 +21,10 @@
 
  #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.  */

Forgot to squash:

-- >8 --
@@ -24,5 +24,7 @@
/* 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. */
+/*
+ * ??? 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.
+ */
---

Quoted 20 lines
target/hppa/cpu-param.h +2 -0
+#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
Reviewed-by on v1 3/24
#9 lore raw

Re: [PATCH 03/24] target: Define TCG_GUEST_DEFAULT_MO in 'cpu-param.h'

In reply to Philippe Mathieu-Daudé
Quoted 7 lines · 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

Quoted 7 lines

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.

---

r~

Acked-by on v1 3/24
#10 lore raw

Re: [PATCH 03/24] target: Define TCG_GUEST_DEFAULT_MO in 'cpu-param.h'

In reply to Philippe Mathieu-Daudé
Quoted 11 lines · 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.

Thanks,
Nick

#11 lore raw

PATCH 4/24 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
Reviewed-by on v1 4/24
#12 lore raw

Re: [PATCH 04/24] accel: Include missing 'exec/cpu_ldst.h' header

Quoted 11 lines · 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(+)

r~

#13 lore raw

PATCH 5/24 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
#15 lore raw

PATCH 6/24 semihosting/guestfd: Remove unused 'semihosting/uaccess.h' header

In reply to Philippe Mathieu-Daudé

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

---
 semihosting/guestfd.c | 1 -
 1 file changed, 1 deletion(-)
semihosting/guestfd.c +0 -1
index 955c2efbd0..fd7e609790 100644
@@ -15,7 +15,6 @@
 #ifdef CONFIG_USER_ONLY
 #include "qemu.h"
 #else
-#include "semihosting/uaccess.h"
 #include CONFIG_DEVICES
 #endif
 
Signature · 1 line
2.41.0
#16 lore raw

Re: [PATCH 06/24] semihosting/guestfd: Remove unused 'semihosting/uaccess.h' header

Quoted 12 lines · Philippe Mathieu-Daudé

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

---
  semihosting/guestfd.c | 1 -
  1 file changed, 1 deletion(-)
semihosting/guestfd.c +0 -0
index 955c2efbd0..fd7e609790 100644

semihosting/guestfd.c line 18

Quoted 4 lines
semihosting/guestfd.c +0 -1
@@ -15,7 +15,6 @@
  #ifdef CONFIG_USER_ONLY
  #include "qemu.h"
  #else
-#include "semihosting/uaccess.h"

Then I would be surprised if qemu.h is required either -- that's where uaccess is done for user-only.

r~

#17 lore raw

Re: [PATCH 06/24] semihosting/guestfd: Remove unused 'semihosting/uaccess.h' header

Quoted 8 lines · Richard Henderson
Quoted 7 lines · Philippe Mathieu-Daudé

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

---
  semihosting/guestfd.c | 1 -

  1 file changed, 1 deletion(-)
Quoted 11 lines

semihosting/guestfd.c line 18

Quoted 9 lines
semihosting/guestfd.c +0 -1
index 955c2efbd0..fd7e609790 100644
@@ -15,7 +15,6 @@
   #ifdef CONFIG_USER_ONLY
   #include "qemu.h"
   #else
-#include "semihosting/uaccess.h"

Then I would be surprised if qemu.h is required either -- that's where uaccess is done for user-only.

Indeed we can remove it.

#18 lore raw

PATCH 7/24 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
#19 lore raw

PATCH 8/24 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
#20 lore raw

PATCH 9/24 hw/ppc/spapr_hcall: Remove unused 'exec/exec-all.h' included header

In reply to Philippe Mathieu-Daudé
---
 hw/ppc/spapr_hcall.c | 1 -
 1 file changed, 1 deletion(-)
hw/ppc/spapr_hcall.c +0 -1
index 522a2396c7..fcefd1d1c7 100644
@@ -8,7 +8,6 @@
 #include "qemu/main-loop.h"
 #include "qemu/module.h"
 #include "qemu/error-report.h"
-#include "exec/exec-all.h"
 #include "exec/tb-flush.h"
 #include "helper_regs.h"
 #include "hw/ppc/ppc.h"
Signature · 1 line
2.41.0
Acked-by on v1 9/24
#21 lore raw

Re: [PATCH 09/24] hw/ppc/spapr_hcall: Remove unused 'exec/exec-all.h' included header

Quoted 1 line · Philippe Mathieu-Daudé
Quoted 16 lines
---
 hw/ppc/spapr_hcall.c | 1 -
 1 file changed, 1 deletion(-)
hw/ppc/spapr_hcall.c +0 -1
index 522a2396c7..fcefd1d1c7 100644
@@ -8,7 +8,6 @@
 #include "qemu/main-loop.h"
 #include "qemu/module.h"
 #include "qemu/error-report.h"
-#include "exec/exec-all.h"
 #include "exec/tb-flush.h"
 #include "helper_regs.h"
 #include "hw/ppc/ppc.h"
#22 lore raw

PATCH 10/24 hw/misc/mips_itu: Remove unnecessary 'exec/exec-all.h' header

In reply to Philippe Mathieu-Daudé

mips_itu.c only requires declarations from "hw/core/cpu.h" and "cpu.h". Avoid including the huge "exec/exec-all.h" header.

---
 hw/misc/mips_itu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/misc/mips_itu.c +2 -1
index 5a83ccc4e8..37aea0e737 100644
@@ -22,9 +22,10 @@
 #include "qemu/log.h"
 #include "qemu/module.h"
 #include "qapi/error.h"
-#include "exec/exec-all.h"
+#include "hw/core/cpu.h"
 #include "hw/misc/mips_itu.h"
 #include "hw/qdev-properties.h"
+#include "target/mips/cpu.h"
 
 #define ITC_TAG_ADDRSPACE_SZ (ITC_ADDRESSMAP_NUM * 8)
 /* Initialize as 4kB area to fit all 32 cells with default 128B grain.
Signature · 1 line
2.41.0
#23 lore raw

PATCH 11/24 hw/s390x/ipl: Remove unused 'exec/exec-all.h' included header

In reply to Philippe Mathieu-Daudé
---
 hw/s390x/ipl.c | 1 -
 1 file changed, 1 deletion(-)
hw/s390x/ipl.c +0 -1
index 515dcf51b5..62182d81a0 100644
@@ -35,7 +35,6 @@
 #include "qemu/cutils.h"
 #include "qemu/option.h"
 #include "standard-headers/linux/virtio_ids.h"
-#include "exec/exec-all.h"
 
 #define KERN_IMAGE_START                0x010000UL
 #define LINUX_MAGIC_ADDR                0x010008UL
Signature · 1 line
2.41.0
#24 lore raw

PATCH 12/24 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
#26 lore raw

PATCH 13/24 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
#27 lore raw

PATCH 14/24 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
Reviewed-by on v1 14/24
#28 lore raw

Re: [PATCH 14/24] gdbstub: Include missing 'hw/core/cpu.h' header

Quoted 9 lines · 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;
  }
Quoted 5 lines
---
 gdbstub/gdbstub.c | 1 +
 1 file changed, 1 insertion(+)
#29 lore raw
In reply to Philippe Mathieu-Daudé

(Forgot to Cc rev.ng folks)

Quoted 45 lines · Philippe Mathieu-Daudé

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.

Regards,

Phil.

Philippe Mathieu-Daudé (24):
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 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 hw/ppc/spapr_hcall: Remove unused 'exec/exec-all.h' included header hw/misc/mips_itu: Remove unnecessary 'exec/exec-all.h' header hw/s390x/ipl: Remove unused 'exec/exec-all.h' included header target/i386: Include missing 'exec/exec-all.h' header accel/tcg: Include missing 'hw/core/cpu.h' header
gdbstub: Include missing 'hw/core/cpu.h' header exec/cpu-all: Remove unused headers
exec/cpu-all: Reduce 'qemu/rcu.h' header inclusion 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 'tcg/abi_ptr.h' header exec/cpu_ldst: Avoid including 'cpu.h'
exec/cpu-all: Restrict inclusion of 'exec/user/guest-base.h' exec/cpu-all: Extract page-protection definitions to
page-prot-common.h
target: Restrict 'sysemu/reset.h' to system emulation

#30 lore raw

PATCH 15/24 exec/cpu-all: Remove unused headers

In reply to Philippe Mathieu-Daudé

Nothing is required from the "qemu/thread.h" and
"hw/core/cpu.h" headers.

---
 include/exec/cpu-all.h | 2 --
 1 file changed, 2 deletions(-)
include/exec/cpu-all.h +0 -2
index 9a7b5737d3..b1e293a08f 100644
@@ -22,8 +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"
 
 /* some important defines:
Signature · 1 line
2.41.0
#31 lore raw

Re: [PATCH 15/24] exec/cpu-all: Remove unused headers

Quoted 13 lines · Philippe Mathieu-Daudé

Nothing is required from the "qemu/thread.h" and
"hw/core/cpu.h" headers.

---
  include/exec/cpu-all.h | 2 --
  1 file changed, 2 deletions(-)
include/exec/cpu-all.h +0 -0
index 9a7b5737d3..b1e293a08f 100644

include/exec/cpu-all.h line 26

Quoted 5 lines
include/exec/cpu-all.h +0 -2
@@ -22,8 +22,6 @@
  #include "exec/cpu-common.h"
  #include "exec/memory.h"
  #include "exec/tswap.h"
-#include "qemu/thread.h"
-#include "hw/core/cpu.h"

While thread.h is fine, I'm not sure removing hw/core/cpu.h from cpu-all.h is a good idea, and would explain the rather surprising changes to add core/cpu.h to other files.

r~

#32 lore raw

Re: [PATCH 15/24] exec/cpu-all: Remove unused headers

Quoted 9 lines · Richard Henderson
Quoted 8 lines · Philippe Mathieu-Daudé

Nothing is required from the "qemu/thread.h" and
"hw/core/cpu.h" headers.

---
  include/exec/cpu-all.h | 2 --

  1 file changed, 2 deletions(-)
Quoted 12 lines

include/exec/cpu-all.h line 26

Quoted 10 lines
include/exec/cpu-all.h +0 -2
index 9a7b5737d3..b1e293a08f 100644
@@ -22,8 +22,6 @@
   #include "exec/cpu-common.h"
   #include "exec/memory.h"
   #include "exec/tswap.h"
-#include "qemu/thread.h"
-#include "hw/core/cpu.h"

While thread.h is fine, I'm not sure removing hw/core/cpu.h from cpu-all.h is a good idea, and would explain the rather surprising changes to add core/cpu.h to other files.

"hw/core/cpu.h" defines the CPUState structure. Any code that deref CPUState needs to include its definition from "hw/core/cpu.h".

Similarly, files that don't deref CPUState/CPUClass/cpu_foo methods shouldn't be polluted by its declarations.

This series focuses on useremu, next comes sysemu and "exec/cpu-all.h" is split. I'll see if I can postpone this change.

#33 lore raw

PATCH 16/24 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 b1e293a08f..2d568ae4f0 100644
@@ -22,7 +22,6 @@
 #include "exec/cpu-common.h"
 #include "exec/memory.h"
 #include "exec/tswap.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
#35 lore raw

PATCH 17/24 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
Acked-by on v1 17/24
#36 lore raw

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

Quoted 5 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.

Quoted 17 lines
---
 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);
 
#37 lore raw

PATCH 18/24 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
Reviewed-by on v1 18/24
#38 lore raw

Re: [PATCH 18/24] accel/tcg: Un-inline retaddr helpers to 'user-retaddr.h'

Quoted 10 lines · 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/).

r~

#39 lore raw

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

In reply to Philippe Mathieu-Daudé

First, "exec/user/abitypes.h" is missing the following includes (they are included by "cpu.h"):
- "exec/target_long.h"
- "exec/cpu-all.h"
- "exec/tswap.h"
Second, it only requires the definitions from "cpu-param.h", not the huge "cpu.h".

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 | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
include/exec/user/abitypes.h +8 -1
index 6178453d94..1a8cd1ac74 100644
@@ -1,7 +1,14 @@
 #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 "cpu-param.h"
+#include "exec/target_long.h"
+#include "exec/cpu-all.h"
+#include "exec/tswap.h"
 
 #ifdef TARGET_ABI32
 #define TARGET_ABI_BITS 32
Signature · 1 line
2.41.0
#40 lore raw

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

Quoted 8 lines · Philippe Mathieu-Daudé

First, "exec/user/abitypes.h" is missing the following includes (they are included by "cpu.h"):
- "exec/target_long.h"
- "exec/cpu-all.h"
- "exec/tswap.h"
Second, it only requires the definitions from "cpu-param.h", not the huge "cpu.h".

Quoted 6 lines

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

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

Why is cpu-all.h required?

r~

#41 lore raw

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

Quoted 9 lines · Richard Henderson
Quoted 8 lines · Philippe Mathieu-Daudé

First, "exec/user/abitypes.h" is missing the following includes (they are included by "cpu.h"):
  - "exec/target_long.h"
  - "exec/cpu-all.h"
  - "exec/tswap.h"
Second, it only requires the definitions from "cpu-param.h", not the huge "cpu.h".

Quoted 8 lines
Quoted 6 lines

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

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

Why is cpu-all.h required?

include/exec/user/abitypes.h:85:12: error: implicit declaration of function ‘tswapl’; did you mean ‘tswapal’? [-Werror=implicit-function-declaration]

   85 |     return tswapl(v);
      |            ^~~~~~
      |            tswapal
$ git grep -w tswapl include
include/exec/cpu-all.h:40:#define tswapl(s) tswap32(s)
include/exec/cpu-all.h:44:#define tswapl(s) tswap64(s)
include/exec/user/abitypes.h:85:    return tswapl(v);

OK, I'll move tswapl() declarations to exec/user/abitypes.h.

#42 lore raw

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

Quoted 24 lines · Philippe Mathieu-Daudé
Quoted 9 lines · Richard Henderson
Quoted 8 lines · Philippe Mathieu-Daudé

First, "exec/user/abitypes.h" is missing the following includes (they are included by "cpu.h"):
  - "exec/target_long.h"
  - "exec/cpu-all.h"
  - "exec/tswap.h"
Second, it only requires the definitions from "cpu-param.h", not the huge "cpu.h".

Quoted 8 lines
Quoted 6 lines

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

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

Why is cpu-all.h required?

include/exec/user/abitypes.h:85:12: error: implicit declaration of function ‘tswapl’; did you mean ‘tswapal’? [-Werror=implicit-function-declaration]
   85 |     return tswapl(v);
      |            ^~~~~~
      |            tswapal

Quoted 6 lines
$ git grep -w tswapl include
include/exec/cpu-all.h:40:#define tswapl(s) tswap32(s)
include/exec/cpu-all.h:44:#define tswapl(s) tswap64(s)
include/exec/user/abitypes.h:85:    return tswapl(v);

OK, I'll move tswapl() declarations to exec/user/abitypes.h.

Better, to a new header.

#43 lore raw

PATCH 20/24 exec: Declare abi_ptr type in its own 'tcg/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 "tcg/abi_ptr.h" header.

---
 include/exec/cpu_ldst.h   | 17 +++--------------
 include/exec/exec-all.h   |  1 +
 include/exec/translator.h |  5 ++++-
 include/tcg/abi_ptr.h     | 32 ++++++++++++++++++++++++++++++++
 accel/tcg/cputlb.c        |  1 +
 5 files changed, 41 insertions(+), 15 deletions(-)
 create mode 100644 include/tcg/abi_ptr.h
include/exec/cpu_ldst.h +3 -14
index 25e7239cc5..c69f02b699 100644
@@ -65,18 +65,9 @@
 #include "exec/memopidx.h"
 #include "qemu/int128.h"
 #include "cpu.h"
+#include "tcg/abi_ptr.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..6a634c0889 100644
@@ -22,6 +22,7 @@
 
 #include "cpu.h"
 #if defined(CONFIG_USER_ONLY)
+#include "tcg/abi_ptr.h"
 #include "exec/cpu_ldst.h"
 #endif
 #include "exec/translation-block.h"
include/exec/translator.h +4 -1
index 6d3f59d095..16d2449292 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 "cpu.h"
+#include "tcg/abi_ptr.h"
 
 /**
  * gen_intermediate_code
include/tcg/abi_ptr.h new file +32 -0
new file mode 100644
index 0000000000..415e31cabb
@@ -0,0 +1,32 @@
+/*
+ * TCG abi_ptr type
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+#ifndef TCG_ABI_PTR_H
+#define TCG_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
accel/tcg/cputlb.c +1 -0
index db3f93fda9..c4500d3261 100644
@@ -41,6 +41,7 @@
 #ifdef CONFIG_PLUGIN
 #include "qemu/plugin-memory.h"
 #endif
+#include "tcg/abi_ptr.h"
 #include "tcg/tcg-ldst.h"
 #include "tcg/oversized-guest.h"
 
Signature · 1 line
2.41.0
#44 lore raw

Re: [PATCH 20/24] exec: Declare abi_ptr type in its own 'tcg/abi_ptr.h' header

Quoted 62 lines · 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 "tcg/abi_ptr.h" header.

---
  include/exec/cpu_ldst.h   | 17 +++--------------
  include/exec/exec-all.h   |  1 +
  include/exec/translator.h |  5 ++++-
  include/tcg/abi_ptr.h     | 32 ++++++++++++++++++++++++++++++++
  accel/tcg/cputlb.c        |  1 +
  5 files changed, 41 insertions(+), 15 deletions(-)

create mode 100644 include/tcg/abi_ptr.h

include/exec/cpu_ldst.h +3 -14
index 25e7239cc5..c69f02b699 100644
@@ -65,18 +65,9 @@
  #include "exec/memopidx.h"
  #include "qemu/int128.h"
  #include "cpu.h"
+#include "tcg/abi_ptr.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/tcg/abi_ptr.h new file +2 -0
new file mode 100644
index 0000000000..415e31cabb
@@ -0,0 +1,32 @@
+/*
+ * TCG abi_ptr type

include/tcg/abi_ptr.h line 12

Quoted 10 lines
include/tcg/abi_ptr.h new file +10 -0
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+#ifndef TCG_ABI_PTR_H
+#define TCG_ABI_PTR_H
+
+#include "cpu-param.h"
+
+#if defined(CONFIG_USER_ONLY)
+/* sparc32plus has 64bit long but 32bit space address

Forgot to squash:

-- >8 --
@@ -11,3 +11,4 @@
#if defined(CONFIG_USER_ONLY)
-/* sparc32plus has 64bit long but 32bit space address +/*
+ * sparc32plus has 64bit long but 32bit space address
* this can make bad result with g2h() and h2g()
---

Quoted 20 lines
include/tcg/abi_ptr.h new file +20 -0
+ * 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
Reviewed-by on v1 20/24
#45 lore raw

Re: [PATCH 20/24] exec: Declare abi_ptr type in its own 'tcg/abi_ptr.h' header

In reply to Philippe Mathieu-Daudé
Quoted 6 lines · 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 "tcg/abi_ptr.h" header.

Quoted 8 lines
---
  include/exec/cpu_ldst.h   | 17 +++--------------
  include/exec/exec-all.h   |  1 +
  include/exec/translator.h |  5 ++++-
  include/tcg/abi_ptr.h     | 32 ++++++++++++++++++++++++++++++++
  accel/tcg/cputlb.c        |  1 +
  5 files changed, 41 insertions(+), 15 deletions(-)

create mode 100644 include/tcg/abi_ptr.h

I'm unconvinced about this being tcg related, per se. Leave it in include/exec/, with exec/user/abitypes.h.

With that,

r~

#46 lore raw

Re: [PATCH 20/24] exec: Declare abi_ptr type in its own 'tcg/abi_ptr.h' header

Quoted 16 lines · Richard Henderson
Quoted 6 lines · 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 "tcg/abi_ptr.h" header.

Quoted 8 lines

---
  include/exec/cpu_ldst.h   | 17 +++-------------- include/exec/exec-all.h   |  1 + include/exec/translator.h |  5 ++++- include/tcg/abi_ptr.h     | 32 ++++++++++++++++++++++++++++++++ accel/tcg/cputlb.c        |  1 +

  5 files changed, 41 insertions(+), 15 deletions(-)

  create mode 100644 include/tcg/abi_ptr.h

Quoted 1 line

I'm unconvinced about this being tcg related, per se.

Indeed:

$ git grep -w abi_ptr -- tcg
$
Quoted 4 lines

Leave it in include/exec/, with exec/user/abitypes.h.

With that,

Thanks!

#47 lore raw

PATCH 21/24 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
- exec/tlb-common.h
- exec/user/abitypes.h
- exec/user/guest-base.h

---
 include/exec/cpu_ldst.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
include/exec/cpu_ldst.h +5 -1
index c69f02b699..a115553ee8 100644
@@ -64,11 +64,15 @@
 
 #include "exec/memopidx.h"
 #include "qemu/int128.h"
-#include "cpu.h"
+#include "exec/cpu-defs.h"
+#include "exec/tlb-common.h"
 #include "tcg/abi_ptr.h"
 
 #if defined(CONFIG_USER_ONLY)
 
+#include "exec/user/abitypes.h"
+#include "exec/user/guest-base.h"
+
 #ifndef TARGET_TAGGED_ADDRESSES
 static inline abi_ptr cpu_untagged_addr(CPUState *cs, abi_ptr x)
 {
Signature · 1 line
2.41.0
#48 lore raw

PATCH 22/24 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/user/guest-base.h | 6 ++++++
 bsd-user/main.c                | 1 +
 linux-user/elfload.c           | 1 +
 linux-user/main.c              | 1 +
 5 files changed, 9 insertions(+), 3 deletions(-)
include/exec/cpu-all.h +0 -3
index 2d568ae4f0..5b75d04ff6 100644
@@ -74,9 +74,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/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 cf9e74468b..f9e9ac1760 100644
@@ -6,6 +6,7 @@
 #include <sys/shm.h>
 
 #include "qemu.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
Reviewed-by on v1 22/24
#49 lore raw

Re: [PATCH 22/24] exec/cpu-all: Restrict inclusion of 'exec/user/guest-base.h'

Quoted 7 lines · 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.

Quoted 8 lines
---
  include/exec/cpu-all.h         | 3 ---
  include/exec/user/guest-base.h | 6 ++++++
  bsd-user/main.c                | 1 +
  linux-user/elfload.c           | 1 +
  linux-user/main.c              | 1 +
  5 files changed, 9 insertions(+), 3 deletions(-)

r~

#50 lore raw

PATCH 23/24 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 5b75d04ff6..881288a4de 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"
@@ -165,40 +166,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 c4500d3261..db154fe5ff 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 ca31470772..faf2062123 100644
@@ -21,6 +21,7 @@
 #include "qemu/osdep.h"
 #include "qemu/log.h"
 #include "qemu.h"
+#include "exec/page-prot-common.h"
 #include "gdbstub/user.h"
 #include "signal-common.h"
 #include "trace.h"
cpu-target.c +1 -0
index 997ca2e846..d1953ec037 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 f9e9ac1760..11c45ab293 100644
@@ -7,6 +7,7 @@
 
 #include "qemu.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
Acked-by on v1 23/24
#51 lore raw

Re: [PATCH 23/24] exec/cpu-all: Extract page-protection definitions to page-prot-common.h

Quoted 8 lines · 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)'

Looks trivial for ppc, so fine. But what's the difference between -common.h and -all.h suffix?

Thanks,
Nick

#52 lore raw

Re: [PATCH 23/24] exec/cpu-all: Extract page-protection definitions to page-prot-common.h

Hi Nicholas,

Quoted 7 lines · Nicholas Piggin
Quoted 6 lines · 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:

Quoted 7 lines
Quoted 2 lines
$ git grep -wE \
   'PAGE_(READ|WRITE|EXEC|BITS|VALID|ANON|RESERVED|TARGET_.|PASSTHROUGH)'

Looks trivial for ppc, so fine. But what's the difference between -common.h and -all.h suffix?

We believe historically '-all' was used for target-specific headers. However then headers got massaged and some ended using this suffix, although not anymore target specific.

Today for clarity we prefer using '-common' for generic (target agnostic) headers, and '-target' for target-specific ones.

I tried to clarify that here:
https://lore.kernel.org/qemu-devel/[email protected]/

Thanks for your review,

Phil.

#53 lore raw

PATCH 24/24 target: Restrict 'sysemu/reset.h' to system emulation

In reply to Philippe Mathieu-Daudé

vCPU "reset" is only possible with system emulation.

---
 target/i386/cpu.c      | 2 +-
 target/loongarch/cpu.c | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)
target/i386/cpu.c +1 -1
index dfb96217ad..17b6962d43 100644
@@ -24,7 +24,6 @@
 #include "qemu/hw-version.h"
 #include "cpu.h"
 #include "tcg/helper-tcg.h"
-#include "sysemu/reset.h"
 #include "sysemu/hvf.h"
 #include "hvf/hvf-i386.h"
 #include "kvm/kvm_i386.h"
@@ -37,6 +36,7 @@
 #include "hw/qdev-properties.h"
 #include "hw/i386/topology.h"
 #ifndef CONFIG_USER_ONLY
+#include "sysemu/reset.h"
 #include "qapi/qapi-commands-machine-target.h"
 #include "exec/address-spaces.h"
 #include "hw/boards.h"
target/loongarch/cpu.c +2 -0
index fc075952e6..b26187dfde 100644
@@ -17,7 +17,9 @@
 #include "internals.h"
 #include "fpu/softfloat-helpers.h"
 #include "cpu-csr.h"
+#ifndef CONFIG_USER_ONLY
 #include "sysemu/reset.h"
+#endif
 #include "tcg/tcg.h"
 #include "vec.h"
 
Signature · 1 line
2.41.0
Reviewed-by on v1 24/24
#55 lore raw

Re: [PATCH 24/24] target: Restrict 'sysemu/reset.h' to system emulation

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

vCPU "reset" is only possible with system emulation.

---
  target/i386/cpu.c      | 2 +-
  target/loongarch/cpu.c | 2 ++
  2 files changed, 3 insertions(+), 1 deletion(-)

Thanks.
Song Gao

Quoted 34 lines
target/i386/cpu.c +1 -1
index dfb96217ad..17b6962d43 100644
@@ -24,7 +24,6 @@
  #include "qemu/hw-version.h"
  #include "cpu.h"
  #include "tcg/helper-tcg.h"
-#include "sysemu/reset.h"
  #include "sysemu/hvf.h"
  #include "hvf/hvf-i386.h"
  #include "kvm/kvm_i386.h"
@@ -37,6 +36,7 @@
  #include "hw/qdev-properties.h"
  #include "hw/i386/topology.h"
  #ifndef CONFIG_USER_ONLY
+#include "sysemu/reset.h"
  #include "qapi/qapi-commands-machine-target.h"
  #include "exec/address-spaces.h"
  #include "hw/boards.h"
target/loongarch/cpu.c +2 -0
index fc075952e6..b26187dfde 100644
@@ -17,7 +17,9 @@
  #include "internals.h"
  #include "fpu/softfloat-helpers.h"
  #include "cpu-csr.h"
+#ifndef CONFIG_USER_ONLY
  #include "sysemu/reset.h"
+#endif
  #include "tcg/tcg.h"
  #include "vec.h"