[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 9/9] target/arm: Do memory type alignment check when translati
From: |
Richard Henderson |
Subject: |
[PATCH v2 9/9] target/arm: Do memory type alignment check when translation enabled |
Date: |
Wed, 21 Jun 2023 14:19:02 +0200 |
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>
---
target/arm/ptw.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/target/arm/ptw.c b/target/arm/ptw.c
index 37bcb17a9e..8dcd5d80ce 100644
--- a/target/arm/ptw.c
+++ b/target/arm/ptw.c
@@ -227,6 +227,16 @@ static bool regime_translation_disabled(CPUARMState *env,
ARMMMUIdx mmu_idx,
return (regime_sctlr(env, mmu_idx) & SCTLR_M) == 0;
}
+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)
{
/*
@@ -1274,6 +1284,7 @@ static bool get_phys_addr_lpae(CPUARMState *env,
S1Translate *ptw,
bool aarch64 = arm_el_is_aa64(env, el);
uint64_t descriptor, new_descriptor;
bool nstable;
+ bool device;
/* TODO: This code does not support shareability levels. */
if (aarch64) {
@@ -1623,6 +1634,8 @@ 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);
+ device = S2_attrs_are_device(arm_hcr_el2_eff_secstate(env, is_secure),
+ result->cacheattrs.attrs);
} else {
/* Index into MAIR registers for cache attributes */
uint8_t attrindx = extract32(attrs, 2, 3);
@@ -1635,6 +1648,21 @@ static bool get_phys_addr_lpae(CPUARMState *env,
S1Translate *ptw,
if (aarch64 && cpu_isar_feature(aa64_bti, cpu)) {
result->f.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, in that this alignment check
+ * should have priority 30, while the permission check should be next at
+ * priority 31 and stage2 translation faults come after that.
+ * 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.
+ */
+ if (device) {
+ result->f.tlb_fill_flags |= TLB_CHECK_ALIGNED;
}
/*
--
2.34.1
- [PATCH v2 0/9] {tcg,aarch64}: Add TLB_CHECK_ALIGNED, Richard Henderson, 2023/06/21
- [PATCH v2 1/9] accel/tcg: Store some tlb flags in CPUTLBEntryFull, Richard Henderson, 2023/06/21
- [PATCH v2 4/9] target/arm: Support 32-byte alignment in pow2_align, Richard Henderson, 2023/06/21
- [PATCH v2 2/9] accel/tcg: Move TLB_WATCHPOINT to TLB_SLOW_FLAGS_MASK, Richard Henderson, 2023/06/21
- [PATCH v2 5/9] exec/memattrs: Remove target_tlb_bit*, Richard Henderson, 2023/06/21
- [PATCH v2 9/9] target/arm: Do memory type alignment check when translation enabled,
Richard Henderson <=
- [PATCH v2 7/9] accel/tcg: Add TLB_CHECK_ALIGNED, Richard Henderson, 2023/06/21
- [PATCH v2 8/9] target/arm: Do memory type alignment check when translation disabled, Richard Henderson, 2023/06/21
- [PATCH v2 3/9] accel/tcg: Renumber TLB_DISCARD_WRITE, Richard Henderson, 2023/06/21
- [PATCH v2 6/9] accel/tcg: Add tlb_fill_flags to CPUTLBEntryFull, Richard Henderson, 2023/06/21