[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 5/9] accel: Move CPUTLB to CPUState and assert offset
From: |
Anton Johansson |
Subject: |
[PATCH 5/9] accel: Move CPUTLB to CPUState and assert offset |
Date: |
Fri, 30 Jun 2023 14:25:47 +0200 |
As CPUTLB is now target-agnostic it can be moved from
CPUNegativeOffsetState to CPUState, and the negative offset from
CPUArchState can instead be statically asserted to be greater than
CPU_MAX_NEGATIVE_ENV_OFFSET.
This also opens up the door for reducing the dependency of common code
on CPUArchState.
Signed-off-by: Anton Johansson <anjo@rev.ng>
---
include/exec/cpu-all.h | 2 +-
include/exec/cpu-defs.h | 2 --
include/exec/tlb-common.h | 4 ++--
include/hw/core/cpu.h | 7 +++++++
accel/tcg/translate-all.c | 13 +++++++++++--
5 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
index 8018ce783e..706daa49ec 100644
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
@@ -453,7 +453,7 @@ static inline CPUNegativeOffsetState *cpu_neg(CPUState *cpu)
*/
static inline CPUTLB *env_tlb(CPUArchState *env)
{
- return &env_neg(env)->tlb;
+ return &env_cpu(env)->tlb;
}
#endif /* CPU_ALL_H */
diff --git a/include/exec/cpu-defs.h b/include/exec/cpu-defs.h
index dff6c37f6b..add0f3c541 100644
--- a/include/exec/cpu-defs.h
+++ b/include/exec/cpu-defs.h
@@ -25,7 +25,6 @@
#include "qemu/host-utils.h"
#include "qemu/thread.h"
-#include "exec/tlb-common.h"
#include "hw/core/cpu.h"
#include "cpu-param.h"
@@ -83,7 +82,6 @@
* before CPUArchState, as a field named "neg".
*/
typedef struct CPUNegativeOffsetState {
- CPUTLB tlb;
IcountDecr icount_decr;
} CPUNegativeOffsetState;
diff --git a/include/exec/tlb-common.h b/include/exec/tlb-common.h
index 838a1f0d2a..450c0156bf 100644
--- a/include/exec/tlb-common.h
+++ b/include/exec/tlb-common.h
@@ -190,8 +190,8 @@ typedef struct CPUTLBCommon {
/*
* The entire softmmu tlb, for all MMU modes.
* The meaning of each of the MMU modes is defined in the target code.
- * Since this is placed within CPUNegativeOffsetState, the smallest
- * negative offsets are at the end of the struct.
+ * Since this is placed within CPUState, the smallest negative offsets
+ * are at the end of the struct.
*/
typedef struct CPUTLB {
diff --git a/include/hw/core/cpu.h b/include/hw/core/cpu.h
index 0377f74d48..adf6158899 100644
--- a/include/hw/core/cpu.h
+++ b/include/hw/core/cpu.h
@@ -448,6 +448,13 @@ struct CPUState {
/* track IOMMUs whose translations we've cached in the TCG TLB */
GArray *iommu_notifiers;
+
+ /*
+ * The following fields needs to be within CPU_MAX_NEGATIVE_ENV_OFFSET of
+ * CPUArchState. As CPUArchState is assumed to follow CPUState in the
+ * ArchCPU struct these are placed last. This is checked statically.
+ */
+ CPUTLB tlb;
};
typedef QTAILQ_HEAD(CPUTailQ, CPUState) CPUTailQ;
diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c
index d3d4fbc1a4..5582aaf653 100644
--- a/accel/tcg/translate-all.c
+++ b/accel/tcg/translate-all.c
@@ -339,8 +339,17 @@ TranslationBlock *tb_gen_code(CPUState *cpu,
tcg_ctx->page_bits = TARGET_PAGE_BITS;
tcg_ctx->page_mask = TARGET_PAGE_MASK;
tcg_ctx->tlb_dyn_max_bits = CPU_TLB_DYN_MAX_BITS;
- tcg_ctx->tlb_fast_offset =
- (int)offsetof(ArchCPU, neg.tlb.f) - (int)offsetof(ArchCPU, env);
+
+#define TLB_FAST_OFFSET \
+ ((int)offsetof(ArchCPU, parent_obj.tlb.f) - (int)offsetof(ArchCPU, env))
+
+ QEMU_BUILD_BUG_ON(TLB_FAST_OFFSET < CPU_MAX_NEGATIVE_ENV_OFFSET ||
+ TLB_FAST_OFFSET > 0);
+
+ tcg_ctx->tlb_fast_offset = TLB_FAST_OFFSET;
+
+#undef TLB_FAST_OFFSET
+
#endif
tcg_ctx->insn_start_words = TARGET_INSN_START_WORDS;
#ifdef TCG_GUEST_DEFAULT_MO
--
2.41.0
- [PATCH 0/9] Collapse CPUNegativeOffsetState into CPUState, Anton Johansson, 2023/06/30
- [PATCH 6/9] Move IcountDecr to CPUState and assert offset, Anton Johansson, 2023/06/30
- [PATCH 1/9] target/arm: Replace TARGET_PAGE_ENTRY_EXTRA, Anton Johansson, 2023/06/30
- [PATCH 2/9] include: Move MMUAccessType to tlb-common.h, Anton Johansson, 2023/06/30
- [PATCH 7/9] include/exec: Remove [cpu|env]_neg() functions, Anton Johansson, 2023/06/30
- [PATCH 3/9] include/exec: Move CPUTLB and friends to tlb-common.h, Anton Johansson, 2023/06/30
- [PATCH 4/9] include/hw: introduce CPU_MAX_NEGATIVE_ENV_OFFSET, Anton Johansson, 2023/06/30
- [PATCH 9/9] include/exec: Remove CPUNegativeOffsetState, Anton Johansson, 2023/06/30
- [PATCH 8/9] target: Remove CPUNegativeOffsetState field from ArchCPU, Anton Johansson, 2023/06/30
- [PATCH 5/9] accel: Move CPUTLB to CPUState and assert offset,
Anton Johansson <=