From: Brian Cain <brian.cain@oss.qualcomm.com>
To: qemu-devel@nongnu.org
Cc: Fabiano Rosas <farosas@suse.de>,
Brian Cain <brian.cain@oss.qualcomm.com>,
Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>,
Laurent Vivier <lvivier@redhat.com>, Peter Xu <peterx@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: [PATCH-for-11.2 v2 06/12] target/hexagon: take exceptions for cache operations
Date: Fri, 20 Nov 2026 10:20:25 -0800 [thread overview]
Message-ID: <20261120182031.560481-7-brian.cain@oss.qualcomm.com> (raw)
In-Reply-To: <20261120182031.560481-1-brian.cain@oss.qualcomm.com>
The dcinva, dccleaninva, dccleana and icinva instructions did nothing
in system mode, but the hardware translates their address. A data cache
operation takes a TLB miss exception if the address is unmapped, and a
privilege exception if the mapping can be neither read nor written. An
instruction cache operation only takes the TLB miss exception.
Probe the address through the normal TLB fill path, which also reports
the packet that faulted.
This enables the mmu_cacheops systest.
Link: https://lore.kernel.org/qemu-devel/20261117183629.2002840-7-marco.liebel@oss.qualcomm.com/
Signed-off-by: Brian Cain <brian.cain@oss.qualcomm.com>
---
target/hexagon/gen_tcg.h | 18 +++++++---
target/hexagon/helper.h | 2 ++
target/hexagon/op_helper.c | 42 +++++++++++++++++++++++
tests/functional/hexagon/test_systests.py | 4 +++
4 files changed, 62 insertions(+), 4 deletions(-)
diff --git a/target/hexagon/gen_tcg.h b/target/hexagon/gen_tcg.h
index e82f89aee42..40f35eb8199 100644
--- a/target/hexagon/gen_tcg.h
+++ b/target/hexagon/gen_tcg.h
@@ -512,23 +512,33 @@
#define fGEN_TCG_Y2_dczeroa(SHORTCODE) SHORTCODE
#define fGEN_TCG_Y2_dczeroa_nt(SHORTCODE) SHORTCODE
-/* In linux-user mode, these are not modelled, suppress compiler warning */
+#ifdef CONFIG_USER_ONLY
+/* In linux-user mode, the data cache is not modelled */
#define fGEN_TCG_Y2_dcinva(SHORTCODE) \
do { RsV = RsV; } while (0)
#define fGEN_TCG_Y2_dccleaninva(SHORTCODE) \
do { RsV = RsV; } while (0)
#define fGEN_TCG_Y2_dccleana(SHORTCODE) \
do { RsV = RsV; } while (0)
-
-#ifdef CONFIG_USER_ONLY
#define fGEN_TCG_Y2_icinva(SHORTCODE) \
gen_helper_insn_cache_op(tcg_env, RsV, \
tcg_constant_tl(insn->slot), \
tcg_constant_tl(ctx->mem_idx), \
tcg_constant_tl(ctx->pkt.pc))
#else
+/*
+ * In system mode the caches are not modelled either, but the operations
+ * translate their address so they can take TLB miss and privilege exceptions.
+ */
+#define fGEN_TCG_Y2_dcinva(SHORTCODE) \
+ gen_helper_data_cache_op(tcg_env, RsV, tcg_constant_tl(ctx->mem_idx))
+#define fGEN_TCG_Y2_dccleaninva(SHORTCODE) \
+ gen_helper_data_cache_op(tcg_env, RsV, tcg_constant_tl(ctx->mem_idx))
+#define fGEN_TCG_Y2_dccleana(SHORTCODE) \
+ gen_helper_data_cache_op(tcg_env, RsV, tcg_constant_tl(ctx->mem_idx))
#define fGEN_TCG_Y2_icinva(SHORTCODE) \
- do { RsV = RsV; } while (0)
+ gen_helper_insn_cache_op_check(tcg_env, RsV, \
+ tcg_constant_tl(ctx->mem_idx))
#endif
#define fGEN_TCG_V2_CHECK_AND_WRITE_VSP(VSP) \
diff --git a/target/hexagon/helper.h b/target/hexagon/helper.h
index e658f8068f4..e7e7ab2c02e 100644
--- a/target/hexagon/helper.h
+++ b/target/hexagon/helper.h
@@ -159,6 +159,8 @@ DEF_HELPER_5(insn_cache_op, void, env, i32, int, int, i32)
#if !defined(CONFIG_USER_ONLY)
DEF_HELPER_4(raise_stack_overflow, void, env, i32, i32, i32)
+DEF_HELPER_3(data_cache_op, void, env, i32, i32)
+DEF_HELPER_3(insn_cache_op_check, void, env, i32, i32)
DEF_HELPER_2(swi, void, env, i32)
DEF_HELPER_2(cswi, void, env, i32)
DEF_HELPER_2(ciad, void, env, i32)
diff --git a/target/hexagon/op_helper.c b/target/hexagon/op_helper.c
index cdb731160eb..bdd5defc9ec 100644
--- a/target/hexagon/op_helper.c
+++ b/target/hexagon/op_helper.c
@@ -25,6 +25,7 @@
#include "exec/helper-proto.h"
#include "exec/mmap-lock.h"
#include "exec/target_page.h"
+#include "exec/tlb-flags.h"
#include "exec/translation-block.h"
#include "fpu/softfloat.h"
#include "exec/cpu-interrupt.h"
@@ -1659,6 +1660,47 @@ void HELPER(vwhist128qm)(CPUHexagonState *env, int32_t uiV)
}
#ifndef CONFIG_USER_ONLY
+/*
+ * The data cache operations translate their address. They take a TLB miss
+ * exception if the address is not mapped, and a privilege exception if the
+ * mapping allows neither reads nor writes.
+ */
+void HELPER(data_cache_op)(CPUHexagonState *env, target_ulong RsV,
+ uint32_t mmu_idx)
+{
+ uintptr_t ra = GETPC();
+ void *host;
+
+ if ((probe_access_flags(env, RsV, 1, MMU_DATA_LOAD, mmu_idx, true,
+ &host, ra) & TLB_INVALID_MASK) &&
+ (probe_access_flags(env, RsV, 1, MMU_DATA_STORE, mmu_idx, true,
+ &host, ra) & TLB_INVALID_MASK)) {
+ /* Not accessible at all, take the exception for a read */
+ probe_read(env, RsV, 1, mmu_idx, ra);
+ }
+}
+
+/*
+ * The instruction cache operations only take a TLB miss exception, whether
+ * or not the mapping can be executed.
+ */
+void HELPER(insn_cache_op_check)(CPUHexagonState *env, target_ulong RsV,
+ uint32_t mmu_idx)
+{
+ hwaddr phys;
+ int prot;
+ uint64_t size;
+ int32_t excp;
+
+ if (!hexagon_cpu_mmu_enabled(env)) {
+ return;
+ }
+ if (!hex_tlb_find_match(env, RsV, MMU_INST_FETCH, &phys, &prot, &size,
+ &excp, mmu_idx)) {
+ probe_access(env, RsV, 1, MMU_INST_FETCH, mmu_idx, GETPC());
+ }
+}
+
void HELPER(raise_stack_overflow)(CPUHexagonState *env, uint32_t slot,
uint32_t badva, uint32_t pc)
{
diff --git a/tests/functional/hexagon/test_systests.py b/tests/functional/hexagon/test_systests.py
index f997563baca..5dc05256aae 100755
--- a/tests/functional/hexagon/test_systests.py
+++ b/tests/functional/hexagon/test_systests.py
@@ -92,6 +92,10 @@ def test_framelimit(self):
exception at the allocframe packet."""
self.run_exit_zero("framelimit")
+ def test_mmu_cacheops(self):
+ """Cache operations raise TLB miss and privilege exceptions."""
+ self.run_exit_zero("mmu_cacheops")
+
def test_access(self):
"""access checks R_OK|W_OK on _testfile_access."""
testfile = self.scratch_file("_testfile_access")
--
2.34.1
next prev parent reply other threads:[~2026-11-20 18:21 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-20 18:20 [PATCH-for-11.2 v2 00/12] Hexagon: fix systests + migration Brian Cain
2026-11-20 18:20 ` [PATCH-for-11.2 v2 01/12] target/hexagon: read the old predicate value through C4 Brian Cain
2026-11-20 18:20 ` [PATCH-for-11.2 v2 02/12] target/hexagon: bound packet lookahead to the current page Brian Cain
2026-11-20 18:20 ` [PATCH-for-11.2 v2 03/12] target/hexagon: fix get_exe_mode assertion in hexagon_stop_thread Brian Cain
2026-11-23 17:51 ` Pierrick Bouvier
2026-11-20 18:20 ` [PATCH-for-11.2 v2 04/12] target/hexagon: deliver floating point exceptions after the packet Brian Cain
2026-11-23 17:52 ` Pierrick Bouvier
2026-11-20 18:20 ` [PATCH-for-11.2 v2 05/12] target/hexagon: report the faulting packet for stack limit exceptions Brian Cain
2026-11-23 18:01 ` Pierrick Bouvier
2026-11-20 18:20 ` Brian Cain [this message]
2026-11-23 18:02 ` [PATCH-for-11.2 v2 06/12] target/hexagon: take exceptions for cache operations Pierrick Bouvier
2026-11-23 19:11 ` Brian Cain
2026-11-20 18:20 ` [PATCH-for-11.2 v2 07/12] target/hexagon: raise decode failures at the faulting packet Brian Cain
2026-11-23 18:03 ` Pierrick Bouvier
2026-11-20 18:20 ` [PATCH-for-11.2 v2 08/12] hw/hexagon: update the glob-reg vmstate ver Brian Cain
2026-11-23 18:04 ` Pierrick Bouvier
2026-11-20 18:20 ` [PATCH-for-11.2 v2 09/12] tests/functional/hexagon: run the rest of the tests Brian Cain
2026-11-20 18:20 ` [PATCH-for-11.2 v2 10/12] tests/tcg/hexagon: packet and COF corner cases Brian Cain
2026-11-23 18:06 ` Pierrick Bouvier
2026-11-23 19:08 ` Brian Cain
2026-11-20 18:20 ` [PATCH-for-11.2 v2 11/12] hw/hexagon: honor configured RAM backends Brian Cain
2026-11-23 18:08 ` Pierrick Bouvier
2026-11-20 18:20 ` [PATCH-for-11.2 v2 12/12] hw/hexagon: version the virt machine type Brian Cain
2026-11-23 17:37 ` Pierrick Bouvier
2026-11-23 17:47 ` Daniel P. Berrangé
2026-11-23 19:03 ` Brian Cain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261120182031.560481-7-brian.cain@oss.qualcomm.com \
--to=brian.cain@oss.qualcomm.com \
--cc=farosas@suse.de \
--cc=lvivier@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=pierrick.bouvier@oss.qualcomm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.