[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 18/20] target/arm: Do memory type alignment check when translation
From: |
Peter Maydell |
Subject: |
[PULL 18/20] target/arm: Do memory type alignment check when translation enabled |
Date: |
Tue, 5 Mar 2024 13:52:35 +0000 |
From: Richard Henderson <richard.henderson@linaro.org>
If translation is enabled, and the PTE memory type is Device,
enable checking alignment via TLB_CHECK_ALIGNMENT. While the
check is done later than it should be per the ARM, it's better
than not performing the check at all.
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 20240301204110.656742-7-richard.henderson@linaro.org
[PMM: tweaks to comment text]
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/ptw.c | 39 +++++++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
diff --git a/target/arm/ptw.c b/target/arm/ptw.c
index ba1a27ca2b5..31ae43f60ed 100644
--- a/target/arm/ptw.c
+++ b/target/arm/ptw.c
@@ -471,6 +471,16 @@ static bool granule_protection_check(CPUARMState *env,
uint64_t paddress,
return false;
}
+static bool S1_attrs_are_device(uint8_t attrs)
+{
+ /*
+ * This slightly under-decodes the MAIR_ELx field:
+ * 0b0000dd01 is Device with FEAT_XS, otherwise UNPREDICTABLE;
+ * 0b0000dd1x is UNPREDICTABLE.
+ */
+ return (attrs & 0xf0) == 0;
+}
+
static bool S2_attrs_are_device(uint64_t hcr, uint8_t attrs)
{
/*
@@ -1684,6 +1694,7 @@ static bool get_phys_addr_lpae(CPUARMState *env,
S1Translate *ptw,
bool aarch64 = arm_el_is_aa64(env, el);
uint64_t descriptor, new_descriptor;
ARMSecuritySpace out_space;
+ bool device;
/* TODO: This code does not support shareability levels. */
if (aarch64) {
@@ -2106,6 +2117,12 @@ static bool get_phys_addr_lpae(CPUARMState *env,
S1Translate *ptw,
if (regime_is_stage2(mmu_idx)) {
result->cacheattrs.is_s2_format = true;
result->cacheattrs.attrs = extract32(attrs, 2, 4);
+ /*
+ * Security state does not really affect HCR_EL2.FWB;
+ * we only need to filter FWB for aa32 or other FEAT.
+ */
+ device = S2_attrs_are_device(arm_hcr_el2_eff(env),
+ result->cacheattrs.attrs);
} else {
/* Index into MAIR registers for cache attributes */
uint8_t attrindx = extract32(attrs, 2, 3);
@@ -2118,6 +2135,28 @@ static bool get_phys_addr_lpae(CPUARMState *env,
S1Translate *ptw,
if (aarch64 && cpu_isar_feature(aa64_bti, cpu)) {
result->f.extra.arm.guarded = extract64(attrs, 50, 1); /* GP */
}
+ device = S1_attrs_are_device(result->cacheattrs.attrs);
+ }
+
+ /*
+ * Enable alignment checks on Device memory.
+ *
+ * Per R_XCHFJ, this check is mis-ordered. The correct ordering
+ * for alignment, permission, and stage 2 faults should be:
+ * - Alignment fault caused by the memory type
+ * - Permission fault
+ * - A stage 2 fault on the memory access
+ * but due to the way the TCG softmmu TLB operates, we will have
+ * implicitly done the permission check and the stage2 lookup in
+ * finding the TLB entry, so the alignment check cannot be done sooner.
+ *
+ * In v7, for a CPU without the Virtualization Extensions this
+ * access is UNPREDICTABLE; we choose to make it take the alignment
+ * fault as is required for a v7VE CPU. (QEMU doesn't emulate any
+ * CPUs with ARM_FEATURE_LPAE but not ARM_FEATURE_V7VE anyway.)
+ */
+ if (device) {
+ result->f.tlb_fill_flags |= TLB_CHECK_ALIGNED;
}
/*
--
2.34.1
- [PULL 16/20] accel/tcg: Add TLB_CHECK_ALIGNED, (continued)
- [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
- [PULL 11/20] hw/arm/stm32l4x5_soc.c: Use the RCC Sysclk, Peter Maydell, 2024/03/05
- [PULL 05/20] hw/misc/stm32l4x5_rcc: Implement STM32L4x5_RCC skeleton, Peter Maydell, 2024/03/05
- [PULL 04/20] hw/char/pl011: Add support for loopback, Peter Maydell, 2024/03/05
- [PULL 18/20] target/arm: Do memory type alignment check when translation enabled,
Peter Maydell <=
- [PULL 13/20] target/arm: Support 32-byte alignment in pow2_align, Peter Maydell, 2024/03/05
- Re: [PULL 00/20] target-arm queue, Peter Maydell, 2024/03/05
- [PULL 00/20] target-arm queue, Peter Maydell, 2024/03/11
- [PULL 03/20] contrib/elf2dmp: Assume error by default, Peter Maydell, 2024/03/11
- [PULL 08/20] contrib/elf2dmp: Fix error reporting style in pdb.c, Peter Maydell, 2024/03/11
- [PULL 15/20] contrib/elf2dmp: Use rol64() to decode, Peter Maydell, 2024/03/11
- [PULL 12/20] contrib/elf2dmp: Always destroy PA space, Peter Maydell, 2024/03/11
- [PULL 18/20] contrib/elf2dmp: Clamp QEMU note to file size, Peter Maydell, 2024/03/11
- [PULL 11/20] contrib/elf2dmp: Always check for PA resolution failure, Peter Maydell, 2024/03/11
- [PULL 20/20] docs: update copyright date to the year 2024, Peter Maydell, 2024/03/11