[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 12/28] target/arm: Fix mte page crossing test
From: |
Peter Maydell |
Subject: |
[PULL 12/28] target/arm: Fix mte page crossing test |
Date: |
Tue, 15 Jun 2021 16:43:49 +0100 |
From: Richard Henderson <richard.henderson@linaro.org>
The test was off-by-one, because tag_last points to the
last byte of the tag to check, thus tag_last - prev_page
will equal TARGET_PAGE_SIZE when we use the first byte
of the next page.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/403
Reported-by: Peter Collingbourne <pcc@google.com>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 20210612195707.840217-1-richard.henderson@linaro.org
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
target/arm/mte_helper.c | 2 +-
tests/tcg/aarch64/mte-7.c | 31 +++++++++++++++++++++++++++++++
tests/tcg/aarch64/Makefile.target | 2 +-
3 files changed, 33 insertions(+), 2 deletions(-)
create mode 100644 tests/tcg/aarch64/mte-7.c
diff --git a/target/arm/mte_helper.c b/target/arm/mte_helper.c
index 166b9d260f8..9e615cc513c 100644
--- a/target/arm/mte_helper.c
+++ b/target/arm/mte_helper.c
@@ -730,7 +730,7 @@ static int mte_probe_int(CPUARMState *env, uint32_t desc,
uint64_t ptr,
prev_page = ptr & TARGET_PAGE_MASK;
next_page = prev_page + TARGET_PAGE_SIZE;
- if (likely(tag_last - prev_page <= TARGET_PAGE_SIZE)) {
+ if (likely(tag_last - prev_page < TARGET_PAGE_SIZE)) {
/* Memory access stays on one page. */
tag_size = ((tag_byte_last - tag_byte_first) / (2 * TAG_GRANULE)) + 1;
mem1 = allocation_tag_mem(env, mmu_idx, ptr, type, sizem1 + 1,
diff --git a/tests/tcg/aarch64/mte-7.c b/tests/tcg/aarch64/mte-7.c
new file mode 100644
index 00000000000..a981de62d4a
--- /dev/null
+++ b/tests/tcg/aarch64/mte-7.c
@@ -0,0 +1,31 @@
+/*
+ * Memory tagging, unaligned access crossing pages.
+ * https://gitlab.com/qemu-project/qemu/-/issues/403
+ *
+ * Copyright (c) 2021 Linaro Ltd
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "mte.h"
+
+int main(int ac, char **av)
+{
+ void *p;
+
+ enable_mte(PR_MTE_TCF_SYNC);
+ p = alloc_mte_mem(2 * 0x1000);
+
+ /* Tag the pointer. */
+ p = (void *)((unsigned long)p | (1ul << 56));
+
+ /* Store tag in sequential granules. */
+ asm("stg %0, [%0]" : : "r"(p + 0x0ff0));
+ asm("stg %0, [%0]" : : "r"(p + 0x1000));
+
+ /*
+ * Perform an unaligned store with tag 1 crossing the pages.
+ * Failure dies with SIGSEGV.
+ */
+ asm("str %0, [%0]" : : "r"(p + 0x0ffc));
+ return 0;
+}
diff --git a/tests/tcg/aarch64/Makefile.target
b/tests/tcg/aarch64/Makefile.target
index 928357b10a9..2c05c90d170 100644
--- a/tests/tcg/aarch64/Makefile.target
+++ b/tests/tcg/aarch64/Makefile.target
@@ -37,7 +37,7 @@ AARCH64_TESTS += bti-2
# MTE Tests
ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_ARMV8_MTE),)
-AARCH64_TESTS += mte-1 mte-2 mte-3 mte-4 mte-5 mte-6
+AARCH64_TESTS += mte-1 mte-2 mte-3 mte-4 mte-5 mte-6 mte-7
mte-%: CFLAGS += -march=armv8.5-a+memtag
endif
--
2.20.1
- [PULL 00/28] target-arm queue, Peter Maydell, 2021/06/15
- [PULL 01/28] hw/intc/arm_gicv3_cpuif: Tolerate spurious EOIR writes, Peter Maydell, 2021/06/15
- [PULL 02/28] target/arm: Diagnose UNALLOCATED in disas_simd_two_reg_misc_fp16, Peter Maydell, 2021/06/15
- [PULL 03/28] target/arm: Remove fprintf from disas_simd_mod_imm, Peter Maydell, 2021/06/15
- [PULL 04/28] target/arm: Diagnose UNALLOCATED in disas_simd_three_reg_same_fp16, Peter Maydell, 2021/06/15
- [PULL 05/28] hw: virt: consider hw_compat_6_0, Peter Maydell, 2021/06/15
- [PULL 07/28] hw/arm: quanta-gbs-bmc add i2c comments, Peter Maydell, 2021/06/15
- [PULL 06/28] hw/arm: add quanta-gbs-bmc machine, Peter Maydell, 2021/06/15
- [PULL 08/28] hw/intc/armv7m_nvic: Remove stale comment, Peter Maydell, 2021/06/15
- [PULL 12/28] target/arm: Fix mte page crossing test,
Peter Maydell <=
- [PULL 11/28] target/arm: Use acpi_ghes_present() to see if we report ACPI memory errors, Peter Maydell, 2021/06/15
- [PULL 13/28] hw/arm: gsj add i2c comments, Peter Maydell, 2021/06/15
- [PULL 09/28] hw/acpi: Provide stub version of acpi_ghes_record_errors(), Peter Maydell, 2021/06/15
- [PULL 14/28] hw/arm: gsj add pca9548, Peter Maydell, 2021/06/15
- [PULL 15/28] hw/arm: quanta-q71l add pca954x muxes, Peter Maydell, 2021/06/15
- [PULL 10/28] hw/acpi: Provide function acpi_ghes_present(), Peter Maydell, 2021/06/15
- [PULL 19/28] target/arm: Add handling for PSR.ECI/ICI, Peter Maydell, 2021/06/15
- [PULL 20/28] target/arm: Let vfp_access_check() handle late NOCP checks, Peter Maydell, 2021/06/15
- [PULL 21/28] target/arm: Implement MVE LCTP, Peter Maydell, 2021/06/15
- [PULL 22/28] target/arm: Implement MVE WLSTP insn, Peter Maydell, 2021/06/15