[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 17/20] target/arm: Do memory type alignment check when translation
From: |
Peter Maydell |
Subject: |
[PULL 17/20] target/arm: Do memory type alignment check when translation disabled |
Date: |
Tue, 5 Mar 2024 13:52:34 +0000 |
From: Richard Henderson <richard.henderson@linaro.org>
If translation is disabled, the default memory type is Device, which
requires alignment checking. This is more optimally done early via
the MemOp given to the TCG memory operation.
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reported-by: Idan Horowitz <idan.horowitz@gmail.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 20240301204110.656742-6-richard.henderson@linaro.org
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1204
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/tcg/hflags.c | 34 ++++++++++++++++++++++++++++++++--
1 file changed, 32 insertions(+), 2 deletions(-)
diff --git a/target/arm/tcg/hflags.c b/target/arm/tcg/hflags.c
index 8e5d35d9227..5da1b0fc1d4 100644
--- a/target/arm/tcg/hflags.c
+++ b/target/arm/tcg/hflags.c
@@ -26,6 +26,35 @@ static inline bool fgt_svc(CPUARMState *env, int el)
FIELD_EX64(env->cp15.fgt_exec[FGTREG_HFGITR], HFGITR_EL2, SVC_EL1);
}
+/* Return true if memory alignment should be enforced. */
+static bool aprofile_require_alignment(CPUARMState *env, int el, uint64_t
sctlr)
+{
+#ifdef CONFIG_USER_ONLY
+ return false;
+#else
+ /* Check the alignment enable bit. */
+ if (sctlr & SCTLR_A) {
+ return true;
+ }
+
+ /*
+ * If translation is disabled, then the default memory type is
+ * Device(-nGnRnE) instead of Normal, which requires that alignment
+ * be enforced. Since this affects all ram, it is most efficient
+ * to handle this during translation.
+ */
+ if (sctlr & SCTLR_M) {
+ /* Translation enabled: memory type in PTE via MAIR_ELx. */
+ return false;
+ }
+ if (el < 2 && (arm_hcr_el2_eff(env) & (HCR_DC | HCR_VM))) {
+ /* Stage 2 translation enabled: memory type in PTE. */
+ return false;
+ }
+ return true;
+#endif
+}
+
static CPUARMTBFlags rebuild_hflags_common(CPUARMState *env, int fp_el,
ARMMMUIdx mmu_idx,
CPUARMTBFlags flags)
@@ -121,8 +150,9 @@ static CPUARMTBFlags rebuild_hflags_a32(CPUARMState *env,
int fp_el,
{
CPUARMTBFlags flags = {};
int el = arm_current_el(env);
+ uint64_t sctlr = arm_sctlr(env, el);
- if (arm_sctlr(env, el) & SCTLR_A) {
+ if (aprofile_require_alignment(env, el, sctlr)) {
DP_TBFLAG_ANY(flags, ALIGN_MEM, 1);
}
@@ -223,7 +253,7 @@ static CPUARMTBFlags rebuild_hflags_a64(CPUARMState *env,
int el, int fp_el,
sctlr = regime_sctlr(env, stage1);
- if (sctlr & SCTLR_A) {
+ if (aprofile_require_alignment(env, el, sctlr)) {
DP_TBFLAG_ANY(flags, ALIGN_MEM, 1);
}
--
2.34.1
- [PULL 00/20] target-arm queue, Peter Maydell, 2024/03/05
- [PULL 03/20] tests/qtest: Add testcase for BCM2835 BSC, Peter Maydell, 2024/03/05
- [PULL 10/20] hw/misc/stm32l4x5_rcc: Add write protections to CR register, Peter Maydell, 2024/03/05
- [PULL 12/20] tests/qtest/stm32l4x5_rcc-test.c: Add tests for the STM32L4x5_RCC, Peter Maydell, 2024/03/05
- [PULL 06/20] hw/misc/stm32l4x5_rcc: Add an internal clock multiplexer object, Peter Maydell, 2024/03/05
- [PULL 17/20] target/arm: Do memory type alignment check when translation disabled,
Peter Maydell <=
- [PULL 19/20] atomic.h: Reword confusing comment for qatomic_cmpxchg, Peter Maydell, 2024/03/05
- [PULL 15/20] accel/tcg: Add tlb_fill_flags to CPUTLBEntryFull, Peter Maydell, 2024/03/05
- [PULL 08/20] hw/misc/stm32l4x5_rcc: Initialize PLLs and clock multiplexers, Peter Maydell, 2024/03/05
- [PULL 16/20] accel/tcg: Add TLB_CHECK_ALIGNED, Peter Maydell, 2024/03/05
- [PULL 07/20] hw/misc/stm32l4x5_rcc: Add an internal PLL Clock object, Peter Maydell, 2024/03/05
- [PULL 09/20] hw/misc/stm32l4x5_rcc: Handle Register Updates, Peter Maydell, 2024/03/05
- [PULL 02/20] hw/arm: Connect BSC to BCM2835 board as I2C0, I2C1 and I2C2, Peter Maydell, 2024/03/05
- [PULL 14/20] exec/memattrs: Remove target_tlb_bit*, Peter Maydell, 2024/03/05
- [PULL 20/20] qemu-options.hx: Don't claim "-serial" has limit of 4 serial ports, Peter Maydell, 2024/03/05
- [PULL 01/20] hw/i2c: Implement Broadcom Serial Controller (BSC), Peter Maydell, 2024/03/05