* [PATCH v4 01/17] exec/tswap: target code can use TARGET_BIG_ENDIAN instead of target_words_bigendian()
2025-03-13 16:38 [PATCH v4 00/17] make system memory API available for common code Pierrick Bouvier
@ 2025-03-13 16:38 ` Pierrick Bouvier
2025-03-13 16:38 ` [PATCH v4 02/17] exec/tswap: implement {ld, st}.*_p as functions instead of macros Pierrick Bouvier
` (16 subsequent siblings)
17 siblings, 0 replies; 22+ messages in thread
From: Pierrick Bouvier @ 2025-03-13 16:38 UTC (permalink / raw)
To: qemu-devel
Cc: Paul Durrant, Philippe Mathieu-Daudé, Harsh Prateek Bora,
Liu Zhiwei, Edgar E. Iglesias, xen-devel, Peter Xu, alex.bennee,
manos.pitsidianakis, Stefano Stabellini, Paolo Bonzini, qemu-ppc,
Richard Henderson, kvm, David Hildenbrand, Palmer Dabbelt,
Weiwei Li, qemu-riscv, Alistair Francis, Anthony PERARD,
Yoshinori Sato, Daniel Henrique Barboza, Nicholas Piggin,
Pierrick Bouvier
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
include/exec/tswap.h | 11 ++++++-----
cpu-target.c | 1 +
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/include/exec/tswap.h b/include/exec/tswap.h
index ecd4faef015..2683da0adb7 100644
--- a/include/exec/tswap.h
+++ b/include/exec/tswap.h
@@ -13,13 +13,14 @@
/**
* target_words_bigendian:
* Returns true if the (default) endianness of the target is big endian,
- * false otherwise. Note that in target-specific code, you can use
- * TARGET_BIG_ENDIAN directly instead. On the other hand, common
- * code should normally never need to know about the endianness of the
- * target, so please do *not* use this function unless you know very well
- * what you are doing!
+ * false otherwise. Common code should normally never need to know about the
+ * endianness of the target, so please do *not* use this function unless you
+ * know very well what you are doing!
*/
bool target_words_bigendian(void);
+#ifdef COMPILING_PER_TARGET
+#define target_words_bigendian() TARGET_BIG_ENDIAN
+#endif
/*
* If we're in target-specific code, we can hard-code the swapping
diff --git a/cpu-target.c b/cpu-target.c
index cae77374b38..519b0f89005 100644
--- a/cpu-target.c
+++ b/cpu-target.c
@@ -155,6 +155,7 @@ void cpu_abort(CPUState *cpu, const char *fmt, ...)
abort();
}
+#undef target_words_bigendian
bool target_words_bigendian(void)
{
return TARGET_BIG_ENDIAN;
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v4 02/17] exec/tswap: implement {ld, st}.*_p as functions instead of macros
2025-03-13 16:38 [PATCH v4 00/17] make system memory API available for common code Pierrick Bouvier
2025-03-13 16:38 ` [PATCH v4 01/17] exec/tswap: target code can use TARGET_BIG_ENDIAN instead of target_words_bigendian() Pierrick Bouvier
@ 2025-03-13 16:38 ` Pierrick Bouvier
2025-03-13 16:38 ` [PATCH v4 03/17] exec/memory_ldst: extract memory_ldst declarations from cpu-all.h Pierrick Bouvier
` (15 subsequent siblings)
17 siblings, 0 replies; 22+ messages in thread
From: Pierrick Bouvier @ 2025-03-13 16:38 UTC (permalink / raw)
To: qemu-devel
Cc: Paul Durrant, Philippe Mathieu-Daudé, Harsh Prateek Bora,
Liu Zhiwei, Edgar E. Iglesias, xen-devel, Peter Xu, alex.bennee,
manos.pitsidianakis, Stefano Stabellini, Paolo Bonzini, qemu-ppc,
Richard Henderson, kvm, David Hildenbrand, Palmer Dabbelt,
Weiwei Li, qemu-riscv, Alistair Francis, Anthony PERARD,
Yoshinori Sato, Daniel Henrique Barboza, Nicholas Piggin,
Pierrick Bouvier
Defining functions allows to use them from common code, by not depending
on TARGET_BIG_ENDIAN.
Remove previous macros from exec/cpu-all.h.
By moving them out of cpu-all.h, we'll be able to break dependency on
cpu.h for memory related functions coming in next commits.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
include/exec/cpu-all.h | 25 ---------------
include/exec/tswap.h | 70 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 70 insertions(+), 25 deletions(-)
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
index 8cd6c00cf89..e56c064d46f 100644
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
@@ -38,31 +38,6 @@
#define BSWAP_NEEDED
#endif
-/* Target-endianness CPU memory access functions. These fit into the
- * {ld,st}{type}{sign}{size}{endian}_p naming scheme described in bswap.h.
- */
-#if TARGET_BIG_ENDIAN
-#define lduw_p(p) lduw_be_p(p)
-#define ldsw_p(p) ldsw_be_p(p)
-#define ldl_p(p) ldl_be_p(p)
-#define ldq_p(p) ldq_be_p(p)
-#define stw_p(p, v) stw_be_p(p, v)
-#define stl_p(p, v) stl_be_p(p, v)
-#define stq_p(p, v) stq_be_p(p, v)
-#define ldn_p(p, sz) ldn_be_p(p, sz)
-#define stn_p(p, sz, v) stn_be_p(p, sz, v)
-#else
-#define lduw_p(p) lduw_le_p(p)
-#define ldsw_p(p) ldsw_le_p(p)
-#define ldl_p(p) ldl_le_p(p)
-#define ldq_p(p) ldq_le_p(p)
-#define stw_p(p, v) stw_le_p(p, v)
-#define stl_p(p, v) stl_le_p(p, v)
-#define stq_p(p, v) stq_le_p(p, v)
-#define ldn_p(p, sz) ldn_le_p(p, sz)
-#define stn_p(p, sz, v) stn_le_p(p, sz, v)
-#endif
-
/* MMU memory access macros */
#if !defined(CONFIG_USER_ONLY)
diff --git a/include/exec/tswap.h b/include/exec/tswap.h
index 2683da0adb7..84060a49994 100644
--- a/include/exec/tswap.h
+++ b/include/exec/tswap.h
@@ -80,4 +80,74 @@ static inline void tswap64s(uint64_t *s)
}
}
+/* Return ld{word}_{le,be}_p following target endianness. */
+#define LOAD_IMPL(word, args...) \
+do { \
+ if (target_words_bigendian()) { \
+ return glue(glue(ld, word), _be_p)(args); \
+ } else { \
+ return glue(glue(ld, word), _le_p)(args); \
+ } \
+} while (0)
+
+static inline int lduw_p(const void *ptr)
+{
+ LOAD_IMPL(uw, ptr);
+}
+
+static inline int ldsw_p(const void *ptr)
+{
+ LOAD_IMPL(sw, ptr);
+}
+
+static inline int ldl_p(const void *ptr)
+{
+ LOAD_IMPL(l, ptr);
+}
+
+static inline uint64_t ldq_p(const void *ptr)
+{
+ LOAD_IMPL(q, ptr);
+}
+
+static inline uint64_t ldn_p(const void *ptr, int sz)
+{
+ LOAD_IMPL(n, ptr, sz);
+}
+
+#undef LOAD_IMPL
+
+/* Call st{word}_{le,be}_p following target endianness. */
+#define STORE_IMPL(word, args...) \
+do { \
+ if (target_words_bigendian()) { \
+ glue(glue(st, word), _be_p)(args); \
+ } else { \
+ glue(glue(st, word), _le_p)(args); \
+ } \
+} while (0)
+
+
+static inline void stw_p(void *ptr, uint16_t v)
+{
+ STORE_IMPL(w, ptr, v);
+}
+
+static inline void stl_p(void *ptr, uint32_t v)
+{
+ STORE_IMPL(l, ptr, v);
+}
+
+static inline void stq_p(void *ptr, uint64_t v)
+{
+ STORE_IMPL(q, ptr, v);
+}
+
+static inline void stn_p(void *ptr, int sz, uint64_t v)
+{
+ STORE_IMPL(n, ptr, sz, v);
+}
+
+#undef STORE_IMPL
+
#endif /* TSWAP_H */
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v4 03/17] exec/memory_ldst: extract memory_ldst declarations from cpu-all.h
2025-03-13 16:38 [PATCH v4 00/17] make system memory API available for common code Pierrick Bouvier
2025-03-13 16:38 ` [PATCH v4 01/17] exec/tswap: target code can use TARGET_BIG_ENDIAN instead of target_words_bigendian() Pierrick Bouvier
2025-03-13 16:38 ` [PATCH v4 02/17] exec/tswap: implement {ld, st}.*_p as functions instead of macros Pierrick Bouvier
@ 2025-03-13 16:38 ` Pierrick Bouvier
2025-03-13 16:38 ` [PATCH v4 04/17] exec/memory_ldst_phys: extract memory_ldst_phys " Pierrick Bouvier
` (14 subsequent siblings)
17 siblings, 0 replies; 22+ messages in thread
From: Pierrick Bouvier @ 2025-03-13 16:38 UTC (permalink / raw)
To: qemu-devel
Cc: Paul Durrant, Philippe Mathieu-Daudé, Harsh Prateek Bora,
Liu Zhiwei, Edgar E. Iglesias, xen-devel, Peter Xu, alex.bennee,
manos.pitsidianakis, Stefano Stabellini, Paolo Bonzini, qemu-ppc,
Richard Henderson, kvm, David Hildenbrand, Palmer Dabbelt,
Weiwei Li, qemu-riscv, Alistair Francis, Anthony PERARD,
Yoshinori Sato, Daniel Henrique Barboza, Nicholas Piggin,
Pierrick Bouvier
They are now accessible through exec/memory.h instead, and we make sure
all variants are available for common or target dependent code.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
include/exec/cpu-all.h | 12 ------------
include/exec/memory_ldst.h.inc | 4 ----
2 files changed, 16 deletions(-)
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
index e56c064d46f..0e8205818a4 100644
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
@@ -44,18 +44,6 @@
#include "exec/hwaddr.h"
-#define SUFFIX
-#define ARG1 as
-#define ARG1_DECL AddressSpace *as
-#define TARGET_ENDIANNESS
-#include "exec/memory_ldst.h.inc"
-
-#define SUFFIX _cached_slow
-#define ARG1 cache
-#define ARG1_DECL MemoryRegionCache *cache
-#define TARGET_ENDIANNESS
-#include "exec/memory_ldst.h.inc"
-
static inline void stl_phys_notdirty(AddressSpace *as, hwaddr addr, uint32_t val)
{
address_space_stl_notdirty(as, addr, val,
diff --git a/include/exec/memory_ldst.h.inc b/include/exec/memory_ldst.h.inc
index 92ad74e9560..7270235c600 100644
--- a/include/exec/memory_ldst.h.inc
+++ b/include/exec/memory_ldst.h.inc
@@ -19,7 +19,6 @@
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
-#ifdef TARGET_ENDIANNESS
uint16_t glue(address_space_lduw, SUFFIX)(ARG1_DECL,
hwaddr addr, MemTxAttrs attrs, MemTxResult *result);
uint32_t glue(address_space_ldl, SUFFIX)(ARG1_DECL,
@@ -34,7 +33,6 @@ void glue(address_space_stl, SUFFIX)(ARG1_DECL,
hwaddr addr, uint32_t val, MemTxAttrs attrs, MemTxResult *result);
void glue(address_space_stq, SUFFIX)(ARG1_DECL,
hwaddr addr, uint64_t val, MemTxAttrs attrs, MemTxResult *result);
-#else
uint8_t glue(address_space_ldub, SUFFIX)(ARG1_DECL,
hwaddr addr, MemTxAttrs attrs, MemTxResult *result);
uint16_t glue(address_space_lduw_le, SUFFIX)(ARG1_DECL,
@@ -63,9 +61,7 @@ void glue(address_space_stq_le, SUFFIX)(ARG1_DECL,
hwaddr addr, uint64_t val, MemTxAttrs attrs, MemTxResult *result);
void glue(address_space_stq_be, SUFFIX)(ARG1_DECL,
hwaddr addr, uint64_t val, MemTxAttrs attrs, MemTxResult *result);
-#endif
#undef ARG1_DECL
#undef ARG1
#undef SUFFIX
-#undef TARGET_ENDIANNESS
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v4 04/17] exec/memory_ldst_phys: extract memory_ldst_phys declarations from cpu-all.h
2025-03-13 16:38 [PATCH v4 00/17] make system memory API available for common code Pierrick Bouvier
` (2 preceding siblings ...)
2025-03-13 16:38 ` [PATCH v4 03/17] exec/memory_ldst: extract memory_ldst declarations from cpu-all.h Pierrick Bouvier
@ 2025-03-13 16:38 ` Pierrick Bouvier
2025-03-13 16:38 ` [PATCH v4 05/17] exec/memory.h: make devend_memop "target defines" agnostic Pierrick Bouvier
` (13 subsequent siblings)
17 siblings, 0 replies; 22+ messages in thread
From: Pierrick Bouvier @ 2025-03-13 16:38 UTC (permalink / raw)
To: qemu-devel
Cc: Paul Durrant, Philippe Mathieu-Daudé, Harsh Prateek Bora,
Liu Zhiwei, Edgar E. Iglesias, xen-devel, Peter Xu, alex.bennee,
manos.pitsidianakis, Stefano Stabellini, Paolo Bonzini, qemu-ppc,
Richard Henderson, kvm, David Hildenbrand, Palmer Dabbelt,
Weiwei Li, qemu-riscv, Alistair Francis, Anthony PERARD,
Yoshinori Sato, Daniel Henrique Barboza, Nicholas Piggin,
Pierrick Bouvier
They are now accessible through exec/memory.h instead, and we make sure
all variants are available for common or target dependent code.
Move stl_phys_notdirty function as well.
Cached endianness agnostic version rely on st/ld*_p, which is available
through tswap.h.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
include/exec/cpu-all.h | 29 -----------------------------
include/exec/memory.h | 10 ++++++++++
include/exec/memory_ldst_phys.h.inc | 5 +----
3 files changed, 11 insertions(+), 33 deletions(-)
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
index 0e8205818a4..902ca1f3c7b 100644
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
@@ -38,35 +38,6 @@
#define BSWAP_NEEDED
#endif
-/* MMU memory access macros */
-
-#if !defined(CONFIG_USER_ONLY)
-
-#include "exec/hwaddr.h"
-
-static inline void stl_phys_notdirty(AddressSpace *as, hwaddr addr, uint32_t val)
-{
- address_space_stl_notdirty(as, addr, val,
- MEMTXATTRS_UNSPECIFIED, NULL);
-}
-
-#define SUFFIX
-#define ARG1 as
-#define ARG1_DECL AddressSpace *as
-#define TARGET_ENDIANNESS
-#include "exec/memory_ldst_phys.h.inc"
-
-/* Inline fast path for direct RAM access. */
-#define ENDIANNESS
-#include "exec/memory_ldst_cached.h.inc"
-
-#define SUFFIX _cached
-#define ARG1 cache
-#define ARG1_DECL MemoryRegionCache *cache
-#define TARGET_ENDIANNESS
-#include "exec/memory_ldst_phys.h.inc"
-#endif
-
/* page related stuff */
#include "exec/cpu-defs.h"
#include "exec/target_page.h"
diff --git a/include/exec/memory.h b/include/exec/memory.h
index d09af58c971..da21e9150b5 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -21,6 +21,7 @@
#include "exec/memattrs.h"
#include "exec/memop.h"
#include "exec/ramlist.h"
+#include "exec/tswap.h"
#include "qemu/bswap.h"
#include "qemu/queue.h"
#include "qemu/int128.h"
@@ -2732,6 +2733,12 @@ MemTxResult address_space_write_rom(AddressSpace *as, hwaddr addr,
#define ARG1_DECL AddressSpace *as
#include "exec/memory_ldst.h.inc"
+static inline void stl_phys_notdirty(AddressSpace *as, hwaddr addr, uint32_t val)
+{
+ address_space_stl_notdirty(as, addr, val,
+ MEMTXATTRS_UNSPECIFIED, NULL);
+}
+
#define SUFFIX
#define ARG1 as
#define ARG1_DECL AddressSpace *as
@@ -2798,6 +2805,9 @@ static inline void address_space_stb_cached(MemoryRegionCache *cache,
}
}
+#define ENDIANNESS
+#include "exec/memory_ldst_cached.h.inc"
+
#define ENDIANNESS _le
#include "exec/memory_ldst_cached.h.inc"
diff --git a/include/exec/memory_ldst_phys.h.inc b/include/exec/memory_ldst_phys.h.inc
index ecd678610d1..db67de75251 100644
--- a/include/exec/memory_ldst_phys.h.inc
+++ b/include/exec/memory_ldst_phys.h.inc
@@ -19,7 +19,6 @@
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
-#ifdef TARGET_ENDIANNESS
static inline uint16_t glue(lduw_phys, SUFFIX)(ARG1_DECL, hwaddr addr)
{
return glue(address_space_lduw, SUFFIX)(ARG1, addr,
@@ -55,7 +54,7 @@ static inline void glue(stq_phys, SUFFIX)(ARG1_DECL, hwaddr addr, uint64_t val)
glue(address_space_stq, SUFFIX)(ARG1, addr, val,
MEMTXATTRS_UNSPECIFIED, NULL);
}
-#else
+
static inline uint8_t glue(ldub_phys, SUFFIX)(ARG1_DECL, hwaddr addr)
{
return glue(address_space_ldub, SUFFIX)(ARG1, addr,
@@ -139,9 +138,7 @@ static inline void glue(stq_be_phys, SUFFIX)(ARG1_DECL, hwaddr addr, uint64_t va
glue(address_space_stq_be, SUFFIX)(ARG1, addr, val,
MEMTXATTRS_UNSPECIFIED, NULL);
}
-#endif
#undef ARG1_DECL
#undef ARG1
#undef SUFFIX
-#undef TARGET_ENDIANNESS
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v4 05/17] exec/memory.h: make devend_memop "target defines" agnostic
2025-03-13 16:38 [PATCH v4 00/17] make system memory API available for common code Pierrick Bouvier
` (3 preceding siblings ...)
2025-03-13 16:38 ` [PATCH v4 04/17] exec/memory_ldst_phys: extract memory_ldst_phys " Pierrick Bouvier
@ 2025-03-13 16:38 ` Pierrick Bouvier
2025-03-13 16:38 ` [PATCH v4 06/17] codebase: prepare to remove cpu.h from exec/exec-all.h Pierrick Bouvier
` (12 subsequent siblings)
17 siblings, 0 replies; 22+ messages in thread
From: Pierrick Bouvier @ 2025-03-13 16:38 UTC (permalink / raw)
To: qemu-devel
Cc: Paul Durrant, Philippe Mathieu-Daudé, Harsh Prateek Bora,
Liu Zhiwei, Edgar E. Iglesias, xen-devel, Peter Xu, alex.bennee,
manos.pitsidianakis, Stefano Stabellini, Paolo Bonzini, qemu-ppc,
Richard Henderson, kvm, David Hildenbrand, Palmer Dabbelt,
Weiwei Li, qemu-riscv, Alistair Francis, Anthony PERARD,
Yoshinori Sato, Daniel Henrique Barboza, Nicholas Piggin,
Pierrick Bouvier
Will allow to make system/memory.c common later.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
include/exec/memory.h | 16 ++++------------
1 file changed, 4 insertions(+), 12 deletions(-)
diff --git a/include/exec/memory.h b/include/exec/memory.h
index da21e9150b5..069021ac3ff 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -3138,25 +3138,17 @@ address_space_write_cached(MemoryRegionCache *cache, hwaddr addr,
MemTxResult address_space_set(AddressSpace *as, hwaddr addr,
uint8_t c, hwaddr len, MemTxAttrs attrs);
-#ifdef COMPILING_PER_TARGET
/* enum device_endian to MemOp. */
static inline MemOp devend_memop(enum device_endian end)
{
QEMU_BUILD_BUG_ON(DEVICE_HOST_ENDIAN != DEVICE_LITTLE_ENDIAN &&
DEVICE_HOST_ENDIAN != DEVICE_BIG_ENDIAN);
-#if HOST_BIG_ENDIAN != TARGET_BIG_ENDIAN
- /* Swap if non-host endianness or native (target) endianness */
- return (end == DEVICE_HOST_ENDIAN) ? 0 : MO_BSWAP;
-#else
- const int non_host_endianness =
- DEVICE_LITTLE_ENDIAN ^ DEVICE_BIG_ENDIAN ^ DEVICE_HOST_ENDIAN;
-
- /* In this case, native (target) endianness needs no swap. */
- return (end == non_host_endianness) ? MO_BSWAP : 0;
-#endif
+ bool big_endian = (end == DEVICE_NATIVE_ENDIAN
+ ? target_words_bigendian()
+ : end == DEVICE_BIG_ENDIAN);
+ return big_endian ? MO_BE : MO_LE;
}
-#endif /* COMPILING_PER_TARGET */
/*
* Inhibit technologies that require discarding of pages in RAM blocks, e.g.,
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v4 06/17] codebase: prepare to remove cpu.h from exec/exec-all.h
2025-03-13 16:38 [PATCH v4 00/17] make system memory API available for common code Pierrick Bouvier
` (4 preceding siblings ...)
2025-03-13 16:38 ` [PATCH v4 05/17] exec/memory.h: make devend_memop "target defines" agnostic Pierrick Bouvier
@ 2025-03-13 16:38 ` Pierrick Bouvier
2025-03-13 16:38 ` [PATCH v4 07/17] exec/exec-all: remove dependency on cpu.h Pierrick Bouvier
` (11 subsequent siblings)
17 siblings, 0 replies; 22+ messages in thread
From: Pierrick Bouvier @ 2025-03-13 16:38 UTC (permalink / raw)
To: qemu-devel
Cc: Paul Durrant, Philippe Mathieu-Daudé, Harsh Prateek Bora,
Liu Zhiwei, Edgar E. Iglesias, xen-devel, Peter Xu, alex.bennee,
manos.pitsidianakis, Stefano Stabellini, Paolo Bonzini, qemu-ppc,
Richard Henderson, kvm, David Hildenbrand, Palmer Dabbelt,
Weiwei Li, qemu-riscv, Alistair Francis, Anthony PERARD,
Yoshinori Sato, Daniel Henrique Barboza, Nicholas Piggin,
Pierrick Bouvier
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
include/tcg/tcg-op.h | 1 +
target/ppc/helper_regs.h | 2 ++
hw/ppc/spapr_nested.c | 1 +
hw/sh4/sh7750.c | 1 +
page-vary-target.c | 2 +-
target/ppc/tcg-excp_helper.c | 1 +
target/riscv/bitmanip_helper.c | 2 +-
7 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/include/tcg/tcg-op.h b/include/tcg/tcg-op.h
index a02850583bd..bc46b5570c4 100644
--- a/include/tcg/tcg-op.h
+++ b/include/tcg/tcg-op.h
@@ -9,6 +9,7 @@
#define TCG_TCG_OP_H
#include "tcg/tcg-op-common.h"
+#include "exec/target_long.h"
#ifndef TARGET_LONG_BITS
#error must include QEMU headers
diff --git a/target/ppc/helper_regs.h b/target/ppc/helper_regs.h
index 8196c1346dc..b928c2c452d 100644
--- a/target/ppc/helper_regs.h
+++ b/target/ppc/helper_regs.h
@@ -20,6 +20,8 @@
#ifndef HELPER_REGS_H
#define HELPER_REGS_H
+#include "target/ppc/cpu.h"
+
void hreg_swap_gpr_tgpr(CPUPPCState *env);
void hreg_compute_hflags(CPUPPCState *env);
void hreg_update_pmu_hflags(CPUPPCState *env);
diff --git a/hw/ppc/spapr_nested.c b/hw/ppc/spapr_nested.c
index 201f6292033..a79e398c132 100644
--- a/hw/ppc/spapr_nested.c
+++ b/hw/ppc/spapr_nested.c
@@ -2,6 +2,7 @@
#include "qemu/cutils.h"
#include "exec/exec-all.h"
#include "exec/cputlb.h"
+#include "exec/target_long.h"
#include "helper_regs.h"
#include "hw/ppc/ppc.h"
#include "hw/ppc/spapr.h"
diff --git a/hw/sh4/sh7750.c b/hw/sh4/sh7750.c
index 6faf0e3ca8b..41306fb6008 100644
--- a/hw/sh4/sh7750.c
+++ b/hw/sh4/sh7750.c
@@ -29,6 +29,7 @@
#include "hw/irq.h"
#include "hw/sh4/sh.h"
#include "system/system.h"
+#include "target/sh4/cpu.h"
#include "hw/qdev-properties.h"
#include "hw/qdev-properties-system.h"
#include "sh7750_regs.h"
diff --git a/page-vary-target.c b/page-vary-target.c
index 3f81144cda8..84ddeb7c26a 100644
--- a/page-vary-target.c
+++ b/page-vary-target.c
@@ -21,7 +21,7 @@
#include "qemu/osdep.h"
#include "exec/page-vary.h"
-#include "exec/exec-all.h"
+#include "exec/target_page.h"
bool set_preferred_target_page_bits(int bits)
{
diff --git a/target/ppc/tcg-excp_helper.c b/target/ppc/tcg-excp_helper.c
index 5a189dc3d70..c422648cfdd 100644
--- a/target/ppc/tcg-excp_helper.c
+++ b/target/ppc/tcg-excp_helper.c
@@ -19,6 +19,7 @@
#include "qemu/osdep.h"
#include "qemu/main-loop.h"
#include "qemu/log.h"
+#include "target/ppc/cpu.h"
#include "exec/cpu_ldst.h"
#include "exec/exec-all.h"
#include "exec/helper-proto.h"
diff --git a/target/riscv/bitmanip_helper.c b/target/riscv/bitmanip_helper.c
index b99c4a39a1f..e9c8d7f7780 100644
--- a/target/riscv/bitmanip_helper.c
+++ b/target/riscv/bitmanip_helper.c
@@ -20,7 +20,7 @@
#include "qemu/osdep.h"
#include "qemu/host-utils.h"
-#include "exec/exec-all.h"
+#include "exec/target_long.h"
#include "exec/helper-proto.h"
#include "tcg/tcg.h"
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v4 07/17] exec/exec-all: remove dependency on cpu.h
2025-03-13 16:38 [PATCH v4 00/17] make system memory API available for common code Pierrick Bouvier
` (5 preceding siblings ...)
2025-03-13 16:38 ` [PATCH v4 06/17] codebase: prepare to remove cpu.h from exec/exec-all.h Pierrick Bouvier
@ 2025-03-13 16:38 ` Pierrick Bouvier
2025-03-13 16:38 ` [PATCH v4 08/17] exec/memory-internal: " Pierrick Bouvier
` (10 subsequent siblings)
17 siblings, 0 replies; 22+ messages in thread
From: Pierrick Bouvier @ 2025-03-13 16:38 UTC (permalink / raw)
To: qemu-devel
Cc: Paul Durrant, Philippe Mathieu-Daudé, Harsh Prateek Bora,
Liu Zhiwei, Edgar E. Iglesias, xen-devel, Peter Xu, alex.bennee,
manos.pitsidianakis, Stefano Stabellini, Paolo Bonzini, qemu-ppc,
Richard Henderson, kvm, David Hildenbrand, Palmer Dabbelt,
Weiwei Li, qemu-riscv, Alistair Francis, Anthony PERARD,
Yoshinori Sato, Daniel Henrique Barboza, Nicholas Piggin,
Pierrick Bouvier
Previous commit changed files relying transitively on it.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
include/exec/exec-all.h | 1 -
1 file changed, 1 deletion(-)
diff --git a/include/exec/exec-all.h b/include/exec/exec-all.h
index dd5c40f2233..19b0eda44a7 100644
--- a/include/exec/exec-all.h
+++ b/include/exec/exec-all.h
@@ -20,7 +20,6 @@
#ifndef EXEC_ALL_H
#define EXEC_ALL_H
-#include "cpu.h"
#if defined(CONFIG_USER_ONLY)
#include "exec/cpu_ldst.h"
#endif
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v4 08/17] exec/memory-internal: remove dependency on cpu.h
2025-03-13 16:38 [PATCH v4 00/17] make system memory API available for common code Pierrick Bouvier
` (6 preceding siblings ...)
2025-03-13 16:38 ` [PATCH v4 07/17] exec/exec-all: remove dependency on cpu.h Pierrick Bouvier
@ 2025-03-13 16:38 ` Pierrick Bouvier
2025-03-13 16:38 ` [PATCH v4 09/17] exec/ram_addr: " Pierrick Bouvier
` (9 subsequent siblings)
17 siblings, 0 replies; 22+ messages in thread
From: Pierrick Bouvier @ 2025-03-13 16:38 UTC (permalink / raw)
To: qemu-devel
Cc: Paul Durrant, Philippe Mathieu-Daudé, Harsh Prateek Bora,
Liu Zhiwei, Edgar E. Iglesias, xen-devel, Peter Xu, alex.bennee,
manos.pitsidianakis, Stefano Stabellini, Paolo Bonzini, qemu-ppc,
Richard Henderson, kvm, David Hildenbrand, Palmer Dabbelt,
Weiwei Li, qemu-riscv, Alistair Francis, Anthony PERARD,
Yoshinori Sato, Daniel Henrique Barboza, Nicholas Piggin,
Pierrick Bouvier
Needed so compilation units including it can be common.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
include/exec/memory-internal.h | 2 --
1 file changed, 2 deletions(-)
diff --git a/include/exec/memory-internal.h b/include/exec/memory-internal.h
index 100c1237ac2..b729f3b25ad 100644
--- a/include/exec/memory-internal.h
+++ b/include/exec/memory-internal.h
@@ -20,8 +20,6 @@
#ifndef MEMORY_INTERNAL_H
#define MEMORY_INTERNAL_H
-#include "cpu.h"
-
#ifndef CONFIG_USER_ONLY
static inline AddressSpaceDispatch *flatview_to_dispatch(FlatView *fv)
{
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v4 09/17] exec/ram_addr: remove dependency on cpu.h
2025-03-13 16:38 [PATCH v4 00/17] make system memory API available for common code Pierrick Bouvier
` (7 preceding siblings ...)
2025-03-13 16:38 ` [PATCH v4 08/17] exec/memory-internal: " Pierrick Bouvier
@ 2025-03-13 16:38 ` Pierrick Bouvier
2025-03-13 16:38 ` [PATCH v4 10/17] system/kvm: make kvm_flush_coalesced_mmio_buffer() accessible for common code Pierrick Bouvier
` (8 subsequent siblings)
17 siblings, 0 replies; 22+ messages in thread
From: Pierrick Bouvier @ 2025-03-13 16:38 UTC (permalink / raw)
To: qemu-devel
Cc: Paul Durrant, Philippe Mathieu-Daudé, Harsh Prateek Bora,
Liu Zhiwei, Edgar E. Iglesias, xen-devel, Peter Xu, alex.bennee,
manos.pitsidianakis, Stefano Stabellini, Paolo Bonzini, qemu-ppc,
Richard Henderson, kvm, David Hildenbrand, Palmer Dabbelt,
Weiwei Li, qemu-riscv, Alistair Francis, Anthony PERARD,
Yoshinori Sato, Daniel Henrique Barboza, Nicholas Piggin,
Pierrick Bouvier
Needed so compilation units including it can be common.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
include/exec/ram_addr.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
index e4c28fbec9b..f5d574261a3 100644
--- a/include/exec/ram_addr.h
+++ b/include/exec/ram_addr.h
@@ -20,13 +20,14 @@
#define RAM_ADDR_H
#ifndef CONFIG_USER_ONLY
-#include "cpu.h"
#include "system/xen.h"
#include "system/tcg.h"
#include "exec/cputlb.h"
#include "exec/ramlist.h"
#include "exec/ramblock.h"
#include "exec/exec-all.h"
+#include "exec/memory.h"
+#include "exec/target_page.h"
#include "qemu/rcu.h"
#include "exec/hwaddr.h"
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v4 10/17] system/kvm: make kvm_flush_coalesced_mmio_buffer() accessible for common code
2025-03-13 16:38 [PATCH v4 00/17] make system memory API available for common code Pierrick Bouvier
` (8 preceding siblings ...)
2025-03-13 16:38 ` [PATCH v4 09/17] exec/ram_addr: " Pierrick Bouvier
@ 2025-03-13 16:38 ` Pierrick Bouvier
2025-03-13 16:38 ` [PATCH v4 11/17] exec/ram_addr: call xen_hvm_modified_memory only if xen is enabled Pierrick Bouvier
` (7 subsequent siblings)
17 siblings, 0 replies; 22+ messages in thread
From: Pierrick Bouvier @ 2025-03-13 16:38 UTC (permalink / raw)
To: qemu-devel
Cc: Paul Durrant, Philippe Mathieu-Daudé, Harsh Prateek Bora,
Liu Zhiwei, Edgar E. Iglesias, xen-devel, Peter Xu, alex.bennee,
manos.pitsidianakis, Stefano Stabellini, Paolo Bonzini, qemu-ppc,
Richard Henderson, kvm, David Hildenbrand, Palmer Dabbelt,
Weiwei Li, qemu-riscv, Alistair Francis, Anthony PERARD,
Yoshinori Sato, Daniel Henrique Barboza, Nicholas Piggin,
Pierrick Bouvier
This function is used by system/physmem.c will be turn into common code
in next commit.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
include/system/kvm.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/include/system/kvm.h b/include/system/kvm.h
index ab17c09a551..21da3b8b052 100644
--- a/include/system/kvm.h
+++ b/include/system/kvm.h
@@ -210,11 +210,11 @@ bool kvm_arm_supports_user_irq(void);
int kvm_on_sigbus_vcpu(CPUState *cpu, int code, void *addr);
int kvm_on_sigbus(int code, void *addr);
-#ifdef COMPILING_PER_TARGET
-#include "cpu.h"
-
void kvm_flush_coalesced_mmio_buffer(void);
+#ifdef COMPILING_PER_TARGET
+#include "cpu.h"
+
/**
* kvm_update_guest_debug(): ensure KVM debug structures updated
* @cs: the CPUState for this cpu
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v4 11/17] exec/ram_addr: call xen_hvm_modified_memory only if xen is enabled
2025-03-13 16:38 [PATCH v4 00/17] make system memory API available for common code Pierrick Bouvier
` (9 preceding siblings ...)
2025-03-13 16:38 ` [PATCH v4 10/17] system/kvm: make kvm_flush_coalesced_mmio_buffer() accessible for common code Pierrick Bouvier
@ 2025-03-13 16:38 ` Pierrick Bouvier
2025-03-13 16:38 ` [PATCH v4 12/17] hw/xen: add stubs for various functions Pierrick Bouvier
` (6 subsequent siblings)
17 siblings, 0 replies; 22+ messages in thread
From: Pierrick Bouvier @ 2025-03-13 16:38 UTC (permalink / raw)
To: qemu-devel
Cc: Paul Durrant, Philippe Mathieu-Daudé, Harsh Prateek Bora,
Liu Zhiwei, Edgar E. Iglesias, xen-devel, Peter Xu, alex.bennee,
manos.pitsidianakis, Stefano Stabellini, Paolo Bonzini, qemu-ppc,
Richard Henderson, kvm, David Hildenbrand, Palmer Dabbelt,
Weiwei Li, qemu-riscv, Alistair Francis, Anthony PERARD,
Yoshinori Sato, Daniel Henrique Barboza, Nicholas Piggin,
Pierrick Bouvier
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
include/exec/ram_addr.h | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/include/exec/ram_addr.h b/include/exec/ram_addr.h
index f5d574261a3..92e8708af76 100644
--- a/include/exec/ram_addr.h
+++ b/include/exec/ram_addr.h
@@ -339,7 +339,9 @@ static inline void cpu_physical_memory_set_dirty_range(ram_addr_t start,
}
}
- xen_hvm_modified_memory(start, length);
+ if (xen_enabled()) {
+ xen_hvm_modified_memory(start, length);
+ }
}
#if !defined(_WIN32)
@@ -415,7 +417,9 @@ uint64_t cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap,
}
}
- xen_hvm_modified_memory(start, pages << TARGET_PAGE_BITS);
+ if (xen_enabled()) {
+ xen_hvm_modified_memory(start, pages << TARGET_PAGE_BITS);
+ }
} else {
uint8_t clients = tcg_enabled() ? DIRTY_CLIENTS_ALL : DIRTY_CLIENTS_NOCODE;
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v4 12/17] hw/xen: add stubs for various functions
2025-03-13 16:38 [PATCH v4 00/17] make system memory API available for common code Pierrick Bouvier
` (10 preceding siblings ...)
2025-03-13 16:38 ` [PATCH v4 11/17] exec/ram_addr: call xen_hvm_modified_memory only if xen is enabled Pierrick Bouvier
@ 2025-03-13 16:38 ` Pierrick Bouvier
2025-03-14 13:35 ` Anthony PERARD
2025-03-13 16:38 ` [PATCH v4 13/17] system/physmem: compilation unit is now common to all targets Pierrick Bouvier
` (5 subsequent siblings)
17 siblings, 1 reply; 22+ messages in thread
From: Pierrick Bouvier @ 2025-03-13 16:38 UTC (permalink / raw)
To: qemu-devel
Cc: Paul Durrant, Philippe Mathieu-Daudé, Harsh Prateek Bora,
Liu Zhiwei, Edgar E. Iglesias, xen-devel, Peter Xu, alex.bennee,
manos.pitsidianakis, Stefano Stabellini, Paolo Bonzini, qemu-ppc,
Richard Henderson, kvm, David Hildenbrand, Palmer Dabbelt,
Weiwei Li, qemu-riscv, Alistair Francis, Anthony PERARD,
Yoshinori Sato, Daniel Henrique Barboza, Nicholas Piggin,
Pierrick Bouvier
Those functions are used by system/physmem.c, and are called only if
xen is enabled (which happens only if CONFIG_XEN is not set).
So we can crash in case those are called.
Acked-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
hw/xen/xen_stubs.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++
hw/xen/meson.build | 3 +++
2 files changed, 59 insertions(+)
create mode 100644 hw/xen/xen_stubs.c
diff --git a/hw/xen/xen_stubs.c b/hw/xen/xen_stubs.c
new file mode 100644
index 00000000000..19cee84bbb4
--- /dev/null
+++ b/hw/xen/xen_stubs.c
@@ -0,0 +1,56 @@
+/*
+ * Various stubs for xen functions
+ *
+ * Those functions are used only if xen_enabled(). This file is linked only if
+ * CONFIG_XEN is not set, so they should never be called.
+ *
+ * Copyright (c) 2025 Linaro, Ltd.
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "system/xen.h"
+#include "system/xen-mapcache.h"
+
+void xen_hvm_modified_memory(ram_addr_t start, ram_addr_t length)
+{
+ g_assert_not_reached();
+}
+
+void xen_ram_alloc(ram_addr_t ram_addr, ram_addr_t size,
+ struct MemoryRegion *mr, Error **errp)
+{
+ g_assert_not_reached();
+}
+
+bool xen_mr_is_memory(MemoryRegion *mr)
+{
+ g_assert_not_reached();
+}
+
+void xen_invalidate_map_cache_entry(uint8_t *buffer)
+{
+ g_assert_not_reached();
+}
+
+void xen_invalidate_map_cache(void)
+{
+ g_assert_not_reached();
+}
+
+ram_addr_t xen_ram_addr_from_mapcache(void *ptr)
+{
+ g_assert_not_reached();
+}
+
+uint8_t *xen_map_cache(MemoryRegion *mr,
+ hwaddr phys_addr,
+ hwaddr size,
+ ram_addr_t ram_addr_offset,
+ uint8_t lock,
+ bool dma,
+ bool is_write)
+{
+ g_assert_not_reached();
+}
diff --git a/hw/xen/meson.build b/hw/xen/meson.build
index 4a486e36738..a1850e76988 100644
--- a/hw/xen/meson.build
+++ b/hw/xen/meson.build
@@ -9,6 +9,9 @@ system_ss.add(when: ['CONFIG_XEN_BUS'], if_true: files(
system_ss.add(when: ['CONFIG_XEN', xen], if_true: files(
'xen-operations.c',
+),
+if_false: files(
+ 'xen_stubs.c',
))
xen_specific_ss = ss.source_set()
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [PATCH v4 12/17] hw/xen: add stubs for various functions
2025-03-13 16:38 ` [PATCH v4 12/17] hw/xen: add stubs for various functions Pierrick Bouvier
@ 2025-03-14 13:35 ` Anthony PERARD
2025-03-14 17:20 ` Pierrick Bouvier
0 siblings, 1 reply; 22+ messages in thread
From: Anthony PERARD @ 2025-03-14 13:35 UTC (permalink / raw)
To: Pierrick Bouvier
Cc: qemu-devel, Paul Durrant, Philippe Mathieu-Daudé,
Harsh Prateek Bora, Liu Zhiwei, Edgar E. Iglesias, xen-devel,
Peter Xu, alex.bennee, manos.pitsidianakis, Stefano Stabellini,
Paolo Bonzini, qemu-ppc, Richard Henderson, kvm,
David Hildenbrand, Palmer Dabbelt, Weiwei Li, qemu-riscv,
Alistair Francis, Yoshinori Sato, Daniel Henrique Barboza,
Nicholas Piggin
On Thu, Mar 13, 2025 at 09:38:58AM -0700, Pierrick Bouvier wrote:
> Those functions are used by system/physmem.c, and are called only if
> xen is enabled (which happens only if CONFIG_XEN is not set).
You mean, 's/is not set/is set/'?
>
> So we can crash in case those are called.
>
> Acked-by: Richard Henderson <richard.henderson@linaro.org>
> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> ---
> diff --git a/hw/xen/xen_stubs.c b/hw/xen/xen_stubs.c
> new file mode 100644
> index 00000000000..19cee84bbb4
> --- /dev/null
> +++ b/hw/xen/xen_stubs.c
> +
> +void xen_invalidate_map_cache(void)
> +{
Is this stub actually necessary? xen_invalidate_map_cache() doesn't
seems to be used outside of xen's code.
In anycase:
Acked-by: Anthony PERARD <anthony.perard@vates.tech>
Thanks,
--
Anthony Perard | Vates XCP-ng Developer
XCP-ng & Xen Orchestra - Vates solutions
web: https://vates.tech
^ permalink raw reply [flat|nested] 22+ messages in thread
* Re: [PATCH v4 12/17] hw/xen: add stubs for various functions
2025-03-14 13:35 ` Anthony PERARD
@ 2025-03-14 17:20 ` Pierrick Bouvier
0 siblings, 0 replies; 22+ messages in thread
From: Pierrick Bouvier @ 2025-03-14 17:20 UTC (permalink / raw)
To: Anthony PERARD
Cc: qemu-devel, Paul Durrant, Philippe Mathieu-Daudé,
Harsh Prateek Bora, Liu Zhiwei, Edgar E. Iglesias, xen-devel,
Peter Xu, alex.bennee, manos.pitsidianakis, Stefano Stabellini,
Paolo Bonzini, qemu-ppc, Richard Henderson, kvm,
David Hildenbrand, Palmer Dabbelt, Weiwei Li, qemu-riscv,
Alistair Francis, Yoshinori Sato, Daniel Henrique Barboza,
Nicholas Piggin
On 3/14/25 06:35, Anthony PERARD wrote:
> On Thu, Mar 13, 2025 at 09:38:58AM -0700, Pierrick Bouvier wrote:
>> Those functions are used by system/physmem.c, and are called only if
>> xen is enabled (which happens only if CONFIG_XEN is not set).
>
> You mean, 's/is not set/is set/'?
Right, I'll update the comment.
>>
>> So we can crash in case those are called.
>>
>> Acked-by: Richard Henderson <richard.henderson@linaro.org>
>> Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
>> ---
>> diff --git a/hw/xen/xen_stubs.c b/hw/xen/xen_stubs.c
>> new file mode 100644
>> index 00000000000..19cee84bbb4
>> --- /dev/null
>> +++ b/hw/xen/xen_stubs.c
>> +
>> +void xen_invalidate_map_cache(void)
>> +{
>
> Is this stub actually necessary? xen_invalidate_map_cache() doesn't
> seems to be used outside of xen's code.
>
You're right again, I added it by mistake.
> In anycase:
> Acked-by: Anthony PERARD <anthony.perard@vates.tech>
>
> Thanks,
>
^ permalink raw reply [flat|nested] 22+ messages in thread
* [PATCH v4 13/17] system/physmem: compilation unit is now common to all targets
2025-03-13 16:38 [PATCH v4 00/17] make system memory API available for common code Pierrick Bouvier
` (11 preceding siblings ...)
2025-03-13 16:38 ` [PATCH v4 12/17] hw/xen: add stubs for various functions Pierrick Bouvier
@ 2025-03-13 16:38 ` Pierrick Bouvier
2025-03-13 16:39 ` [PATCH v4 14/17] include/exec/memory: extract devend_big_endian from devend_memop Pierrick Bouvier
` (4 subsequent siblings)
17 siblings, 0 replies; 22+ messages in thread
From: Pierrick Bouvier @ 2025-03-13 16:38 UTC (permalink / raw)
To: qemu-devel
Cc: Paul Durrant, Philippe Mathieu-Daudé, Harsh Prateek Bora,
Liu Zhiwei, Edgar E. Iglesias, xen-devel, Peter Xu, alex.bennee,
manos.pitsidianakis, Stefano Stabellini, Paolo Bonzini, qemu-ppc,
Richard Henderson, kvm, David Hildenbrand, Palmer Dabbelt,
Weiwei Li, qemu-riscv, Alistair Francis, Anthony PERARD,
Yoshinori Sato, Daniel Henrique Barboza, Nicholas Piggin,
Pierrick Bouvier
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
system/meson.build | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/system/meson.build b/system/meson.build
index eec07a94513..bd82ef132e7 100644
--- a/system/meson.build
+++ b/system/meson.build
@@ -3,7 +3,6 @@ specific_ss.add(when: 'CONFIG_SYSTEM_ONLY', if_true: [files(
'ioport.c',
'globals-target.c',
'memory.c',
- 'physmem.c',
)])
system_ss.add(files(
@@ -16,6 +15,7 @@ system_ss.add(files(
'dma-helpers.c',
'globals.c',
'memory_mapping.c',
+ 'physmem.c',
'qdev-monitor.c',
'qtest.c',
'rtc.c',
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v4 14/17] include/exec/memory: extract devend_big_endian from devend_memop
2025-03-13 16:38 [PATCH v4 00/17] make system memory API available for common code Pierrick Bouvier
` (12 preceding siblings ...)
2025-03-13 16:38 ` [PATCH v4 13/17] system/physmem: compilation unit is now common to all targets Pierrick Bouvier
@ 2025-03-13 16:39 ` Pierrick Bouvier
2025-03-13 16:39 ` [PATCH v4 15/17] include/exec/memory: move devend functions to memory-internal.h Pierrick Bouvier
` (3 subsequent siblings)
17 siblings, 0 replies; 22+ messages in thread
From: Pierrick Bouvier @ 2025-03-13 16:39 UTC (permalink / raw)
To: qemu-devel
Cc: Paul Durrant, Philippe Mathieu-Daudé, Harsh Prateek Bora,
Liu Zhiwei, Edgar E. Iglesias, xen-devel, Peter Xu, alex.bennee,
manos.pitsidianakis, Stefano Stabellini, Paolo Bonzini, qemu-ppc,
Richard Henderson, kvm, David Hildenbrand, Palmer Dabbelt,
Weiwei Li, qemu-riscv, Alistair Francis, Anthony PERARD,
Yoshinori Sato, Daniel Henrique Barboza, Nicholas Piggin,
Pierrick Bouvier
we'll use it in system/memory.c.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
include/exec/memory.h | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/include/exec/memory.h b/include/exec/memory.h
index 069021ac3ff..70177304a92 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -3138,16 +3138,22 @@ address_space_write_cached(MemoryRegionCache *cache, hwaddr addr,
MemTxResult address_space_set(AddressSpace *as, hwaddr addr,
uint8_t c, hwaddr len, MemTxAttrs attrs);
-/* enum device_endian to MemOp. */
-static inline MemOp devend_memop(enum device_endian end)
+/* returns true if end is big endian. */
+static inline bool devend_big_endian(enum device_endian end)
{
QEMU_BUILD_BUG_ON(DEVICE_HOST_ENDIAN != DEVICE_LITTLE_ENDIAN &&
DEVICE_HOST_ENDIAN != DEVICE_BIG_ENDIAN);
- bool big_endian = (end == DEVICE_NATIVE_ENDIAN
- ? target_words_bigendian()
- : end == DEVICE_BIG_ENDIAN);
- return big_endian ? MO_BE : MO_LE;
+ if (end == DEVICE_NATIVE_ENDIAN) {
+ return target_words_bigendian();
+ }
+ return end == DEVICE_BIG_ENDIAN;
+}
+
+/* enum device_endian to MemOp. */
+static inline MemOp devend_memop(enum device_endian end)
+{
+ return devend_big_endian(end) ? MO_BE : MO_LE;
}
/*
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v4 15/17] include/exec/memory: move devend functions to memory-internal.h
2025-03-13 16:38 [PATCH v4 00/17] make system memory API available for common code Pierrick Bouvier
` (13 preceding siblings ...)
2025-03-13 16:39 ` [PATCH v4 14/17] include/exec/memory: extract devend_big_endian from devend_memop Pierrick Bouvier
@ 2025-03-13 16:39 ` Pierrick Bouvier
2025-03-13 16:47 ` Richard Henderson
2025-03-13 16:39 ` [PATCH v4 16/17] system/memory: make compilation unit common Pierrick Bouvier
` (2 subsequent siblings)
17 siblings, 1 reply; 22+ messages in thread
From: Pierrick Bouvier @ 2025-03-13 16:39 UTC (permalink / raw)
To: qemu-devel
Cc: Paul Durrant, Philippe Mathieu-Daudé, Harsh Prateek Bora,
Liu Zhiwei, Edgar E. Iglesias, xen-devel, Peter Xu, alex.bennee,
manos.pitsidianakis, Stefano Stabellini, Paolo Bonzini, qemu-ppc,
Richard Henderson, kvm, David Hildenbrand, Palmer Dabbelt,
Weiwei Li, qemu-riscv, Alistair Francis, Anthony PERARD,
Yoshinori Sato, Daniel Henrique Barboza, Nicholas Piggin,
Pierrick Bouvier
Only system/physmem.c and system/memory.c use those functions, so we can
move then to internal header.
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
include/exec/memory-internal.h | 19 +++++++++++++++++++
include/exec/memory.h | 18 ------------------
2 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/include/exec/memory-internal.h b/include/exec/memory-internal.h
index b729f3b25ad..c75178a3d6b 100644
--- a/include/exec/memory-internal.h
+++ b/include/exec/memory-internal.h
@@ -43,5 +43,24 @@ void address_space_dispatch_free(AddressSpaceDispatch *d);
void mtree_print_dispatch(struct AddressSpaceDispatch *d,
MemoryRegion *root);
+
+/* returns true if end is big endian. */
+static inline bool devend_big_endian(enum device_endian end)
+{
+ QEMU_BUILD_BUG_ON(DEVICE_HOST_ENDIAN != DEVICE_LITTLE_ENDIAN &&
+ DEVICE_HOST_ENDIAN != DEVICE_BIG_ENDIAN);
+
+ if (end == DEVICE_NATIVE_ENDIAN) {
+ return target_words_bigendian();
+ }
+ return end == DEVICE_BIG_ENDIAN;
+}
+
+/* enum device_endian to MemOp. */
+static inline MemOp devend_memop(enum device_endian end)
+{
+ return devend_big_endian(end) ? MO_BE : MO_LE;
+}
+
#endif
#endif
diff --git a/include/exec/memory.h b/include/exec/memory.h
index 70177304a92..a3bb0542bf6 100644
--- a/include/exec/memory.h
+++ b/include/exec/memory.h
@@ -3138,24 +3138,6 @@ address_space_write_cached(MemoryRegionCache *cache, hwaddr addr,
MemTxResult address_space_set(AddressSpace *as, hwaddr addr,
uint8_t c, hwaddr len, MemTxAttrs attrs);
-/* returns true if end is big endian. */
-static inline bool devend_big_endian(enum device_endian end)
-{
- QEMU_BUILD_BUG_ON(DEVICE_HOST_ENDIAN != DEVICE_LITTLE_ENDIAN &&
- DEVICE_HOST_ENDIAN != DEVICE_BIG_ENDIAN);
-
- if (end == DEVICE_NATIVE_ENDIAN) {
- return target_words_bigendian();
- }
- return end == DEVICE_BIG_ENDIAN;
-}
-
-/* enum device_endian to MemOp. */
-static inline MemOp devend_memop(enum device_endian end)
-{
- return devend_big_endian(end) ? MO_BE : MO_LE;
-}
-
/*
* Inhibit technologies that require discarding of pages in RAM blocks, e.g.,
* to manage the actual amount of memory consumed by the VM (then, the memory
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v4 16/17] system/memory: make compilation unit common
2025-03-13 16:38 [PATCH v4 00/17] make system memory API available for common code Pierrick Bouvier
` (14 preceding siblings ...)
2025-03-13 16:39 ` [PATCH v4 15/17] include/exec/memory: move devend functions to memory-internal.h Pierrick Bouvier
@ 2025-03-13 16:39 ` Pierrick Bouvier
2025-03-13 16:39 ` [PATCH v4 17/17] system/ioport: " Pierrick Bouvier
2025-03-13 16:42 ` [PATCH v4 00/17] make system memory API available for common code Pierrick Bouvier
17 siblings, 0 replies; 22+ messages in thread
From: Pierrick Bouvier @ 2025-03-13 16:39 UTC (permalink / raw)
To: qemu-devel
Cc: Paul Durrant, Philippe Mathieu-Daudé, Harsh Prateek Bora,
Liu Zhiwei, Edgar E. Iglesias, xen-devel, Peter Xu, alex.bennee,
manos.pitsidianakis, Stefano Stabellini, Paolo Bonzini, qemu-ppc,
Richard Henderson, kvm, David Hildenbrand, Palmer Dabbelt,
Weiwei Li, qemu-riscv, Alistair Francis, Anthony PERARD,
Yoshinori Sato, Daniel Henrique Barboza, Nicholas Piggin,
Pierrick Bouvier
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
system/memory.c | 17 +++++------------
system/meson.build | 2 +-
2 files changed, 6 insertions(+), 13 deletions(-)
diff --git a/system/memory.c b/system/memory.c
index 4c829793a0a..eddd21a6cdb 100644
--- a/system/memory.c
+++ b/system/memory.c
@@ -353,15 +353,6 @@ static void flatview_simplify(FlatView *view)
}
}
-static bool memory_region_big_endian(MemoryRegion *mr)
-{
-#if TARGET_BIG_ENDIAN
- return mr->ops->endianness != DEVICE_LITTLE_ENDIAN;
-#else
- return mr->ops->endianness == DEVICE_BIG_ENDIAN;
-#endif
-}
-
static void adjust_endianness(MemoryRegion *mr, uint64_t *data, MemOp op)
{
if ((op & MO_BSWAP) != devend_memop(mr->ops->endianness)) {
@@ -563,7 +554,7 @@ static MemTxResult access_with_adjusted_size(hwaddr addr,
/* FIXME: support unaligned access? */
access_size = MAX(MIN(size, access_size_max), access_size_min);
access_mask = MAKE_64BIT_MASK(0, access_size * 8);
- if (memory_region_big_endian(mr)) {
+ if (devend_big_endian(mr->ops->endianness)) {
for (i = 0; i < size; i += access_size) {
r |= access_fn(mr, addr + i, value, access_size,
(size - access_size - i) * 8, access_mask, attrs);
@@ -2584,7 +2575,8 @@ void memory_region_add_eventfd(MemoryRegion *mr,
unsigned i;
if (size) {
- adjust_endianness(mr, &mrfd.data, size_memop(size) | MO_TE);
+ MemOp mop = (target_words_bigendian() ? MO_BE : MO_LE) | size_memop(size);
+ adjust_endianness(mr, &mrfd.data, mop);
}
memory_region_transaction_begin();
for (i = 0; i < mr->ioeventfd_nb; ++i) {
@@ -2619,7 +2611,8 @@ void memory_region_del_eventfd(MemoryRegion *mr,
unsigned i;
if (size) {
- adjust_endianness(mr, &mrfd.data, size_memop(size) | MO_TE);
+ MemOp mop = (target_words_bigendian() ? MO_BE : MO_LE) | size_memop(size);
+ adjust_endianness(mr, &mrfd.data, mop);
}
memory_region_transaction_begin();
for (i = 0; i < mr->ioeventfd_nb; ++i) {
diff --git a/system/meson.build b/system/meson.build
index bd82ef132e7..4f44b78df31 100644
--- a/system/meson.build
+++ b/system/meson.build
@@ -2,7 +2,6 @@ specific_ss.add(when: 'CONFIG_SYSTEM_ONLY', if_true: [files(
'arch_init.c',
'ioport.c',
'globals-target.c',
- 'memory.c',
)])
system_ss.add(files(
@@ -15,6 +14,7 @@ system_ss.add(files(
'dma-helpers.c',
'globals.c',
'memory_mapping.c',
+ 'memory.c',
'physmem.c',
'qdev-monitor.c',
'qtest.c',
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* [PATCH v4 17/17] system/ioport: make compilation unit common
2025-03-13 16:38 [PATCH v4 00/17] make system memory API available for common code Pierrick Bouvier
` (15 preceding siblings ...)
2025-03-13 16:39 ` [PATCH v4 16/17] system/memory: make compilation unit common Pierrick Bouvier
@ 2025-03-13 16:39 ` Pierrick Bouvier
2025-03-13 16:42 ` [PATCH v4 00/17] make system memory API available for common code Pierrick Bouvier
17 siblings, 0 replies; 22+ messages in thread
From: Pierrick Bouvier @ 2025-03-13 16:39 UTC (permalink / raw)
To: qemu-devel
Cc: Paul Durrant, Philippe Mathieu-Daudé, Harsh Prateek Bora,
Liu Zhiwei, Edgar E. Iglesias, xen-devel, Peter Xu, alex.bennee,
manos.pitsidianakis, Stefano Stabellini, Paolo Bonzini, qemu-ppc,
Richard Henderson, kvm, David Hildenbrand, Palmer Dabbelt,
Weiwei Li, qemu-riscv, Alistair Francis, Anthony PERARD,
Yoshinori Sato, Daniel Henrique Barboza, Nicholas Piggin,
Pierrick Bouvier
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
---
system/ioport.c | 1 -
system/meson.build | 2 +-
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/system/ioport.c b/system/ioport.c
index 55c2a752396..89daae9d602 100644
--- a/system/ioport.c
+++ b/system/ioport.c
@@ -26,7 +26,6 @@
*/
#include "qemu/osdep.h"
-#include "cpu.h"
#include "exec/ioport.h"
#include "exec/memory.h"
#include "exec/address-spaces.h"
diff --git a/system/meson.build b/system/meson.build
index 4f44b78df31..063301c3ad0 100644
--- a/system/meson.build
+++ b/system/meson.build
@@ -1,6 +1,5 @@
specific_ss.add(when: 'CONFIG_SYSTEM_ONLY', if_true: [files(
'arch_init.c',
- 'ioport.c',
'globals-target.c',
)])
@@ -13,6 +12,7 @@ system_ss.add(files(
'dirtylimit.c',
'dma-helpers.c',
'globals.c',
+ 'ioport.c',
'memory_mapping.c',
'memory.c',
'physmem.c',
--
2.39.5
^ permalink raw reply related [flat|nested] 22+ messages in thread
* Re: [PATCH v4 00/17] make system memory API available for common code
2025-03-13 16:38 [PATCH v4 00/17] make system memory API available for common code Pierrick Bouvier
` (16 preceding siblings ...)
2025-03-13 16:39 ` [PATCH v4 17/17] system/ioport: " Pierrick Bouvier
@ 2025-03-13 16:42 ` Pierrick Bouvier
17 siblings, 0 replies; 22+ messages in thread
From: Pierrick Bouvier @ 2025-03-13 16:42 UTC (permalink / raw)
To: qemu-devel
Cc: Paul Durrant, Philippe Mathieu-Daudé, Harsh Prateek Bora,
Liu Zhiwei, Edgar E. Iglesias, xen-devel, Peter Xu, alex.bennee,
manos.pitsidianakis, Stefano Stabellini, Paolo Bonzini, qemu-ppc,
Richard Henderson, kvm, David Hildenbrand, Palmer Dabbelt,
Weiwei Li, qemu-riscv, Alistair Francis, Anthony PERARD,
Yoshinori Sato, Daniel Henrique Barboza, Nicholas Piggin
Hi,
patch 12 (adding xen stubs, so would need someone from hw/xen) and 15
are missing reviews.
Thanks,
Pierrick
On 3/13/25 09:38, Pierrick Bouvier wrote:
> The main goal of this series is to be able to call any memory ld/st function
> from code that is *not* target dependent. As a positive side effect, we can
> turn related system compilation units into common code.
>
> The first 5 patches remove dependency of memory API to cpu headers and remove
> dependency to target specific code. This could be a series on its own, but it's
> great to be able to turn system memory compilation units into common code to
> make sure it can't regress, and prove it achieves the desired result.
>
> The next patches remove more dependencies on cpu headers (exec-all,
> memory-internal, ram_addr).
> Then, we add access to a needed function from kvm, some xen stubs, and we
> finally can turn our compilation units into common code.
>
> Every commit was tested to build correctly for all targets (on windows, linux,
> macos), and the series was fully tested by running all tests we have (linux,
> x86_64 host).
>
> v2:
> - reorder first commits (tswap change first, so memory cached functions can use it)
> - move st/ld*_p functions to tswap instead of bswap
> - add define for target_words_bigendian when COMPILING_PER_TARGET, equals to
> TARGET_BIG_ENDIAN (avoid overhead in target code)
> - rewrite devend_memop
> - remove useless exec-all.h in concerned patch
> - extract devend_big_endian function to reuse in system/memory.c
> - rewrite changes to system/memory.c
>
> v3:
> - move devend functions to memory_internal.h
> - completed description for commits removing cpu.h dependency
>
> v4:
> - rebase on top of master
> * missing include in 'codebase: prepare to remove cpu.h from exec/exec-all.h'
> * meson build conflict
>
> Pierrick Bouvier (17):
> exec/tswap: target code can use TARGET_BIG_ENDIAN instead of
> target_words_bigendian()
> exec/tswap: implement {ld,st}.*_p as functions instead of macros
> exec/memory_ldst: extract memory_ldst declarations from cpu-all.h
> exec/memory_ldst_phys: extract memory_ldst_phys declarations from
> cpu-all.h
> exec/memory.h: make devend_memop "target defines" agnostic
> codebase: prepare to remove cpu.h from exec/exec-all.h
> exec/exec-all: remove dependency on cpu.h
> exec/memory-internal: remove dependency on cpu.h
> exec/ram_addr: remove dependency on cpu.h
> system/kvm: make kvm_flush_coalesced_mmio_buffer() accessible for
> common code
> exec/ram_addr: call xen_hvm_modified_memory only if xen is enabled
> hw/xen: add stubs for various functions
> system/physmem: compilation unit is now common to all targets
> include/exec/memory: extract devend_big_endian from devend_memop
> include/exec/memory: move devend functions to memory-internal.h
> system/memory: make compilation unit common
> system/ioport: make compilation unit common
>
> include/exec/cpu-all.h | 66 -----------------------
> include/exec/exec-all.h | 1 -
> include/exec/memory-internal.h | 21 +++++++-
> include/exec/memory.h | 30 ++++-------
> include/exec/ram_addr.h | 11 ++--
> include/exec/tswap.h | 81 +++++++++++++++++++++++++++--
> include/system/kvm.h | 6 +--
> include/tcg/tcg-op.h | 1 +
> target/ppc/helper_regs.h | 2 +
> include/exec/memory_ldst.h.inc | 4 --
> include/exec/memory_ldst_phys.h.inc | 5 +-
> cpu-target.c | 1 +
> hw/ppc/spapr_nested.c | 1 +
> hw/sh4/sh7750.c | 1 +
> hw/xen/xen_stubs.c | 56 ++++++++++++++++++++
> page-vary-target.c | 2 +-
> system/ioport.c | 1 -
> system/memory.c | 17 ++----
> target/ppc/tcg-excp_helper.c | 1 +
> target/riscv/bitmanip_helper.c | 2 +-
> hw/xen/meson.build | 3 ++
> system/meson.build | 6 +--
> 22 files changed, 193 insertions(+), 126 deletions(-)
> create mode 100644 hw/xen/xen_stubs.c
>
^ permalink raw reply [flat|nested] 22+ messages in thread