From: Richard Henderson <richard.henderson@linaro.org>
To: qemu-devel@nongnu.org
Cc: qemu-arm@nongnu.org
Subject: [PATCH 34/61] target/arm: Redirect VHE FOO_EL12 to FOO_EL1 during translation
Date: Wed, 27 Aug 2025 11:04:25 +1000 [thread overview]
Message-ID: <20250827010453.4059782-39-richard.henderson@linaro.org> (raw)
In-Reply-To: <20250827010453.4059782-1-richard.henderson@linaro.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
target/arm/cpregs.h | 22 ++++---------
target/arm/gdbstub.c | 2 ++
target/arm/helper.c | 57 +++-------------------------------
target/arm/tcg/translate-a64.c | 12 +++++++
4 files changed, 25 insertions(+), 68 deletions(-)
diff --git a/target/arm/cpregs.h b/target/arm/cpregs.h
index d34ed0d40b..f5d6a1c386 100644
--- a/target/arm/cpregs.h
+++ b/target/arm/cpregs.h
@@ -917,8 +917,12 @@ struct ARMCPRegInfo {
*/
uint32_t vhe_redir_to_el2;
- /* This is used only by VHE. */
- void *opaque;
+ /*
+ * With VHE, with E2H, at EL2+, access to this EL02/EL12 reg
+ * redirects to the EL0/EL1 reg with the specified key.
+ */
+ uint32_t vhe_redir_to_el01;
+
/*
* Value of this register, if it is ARM_CP_CONST. Otherwise, if
* fieldoffset is non-zero, the reset value of the register.
@@ -986,20 +990,6 @@ struct ARMCPRegInfo {
* fieldoffset is 0 then no reset will be done.
*/
CPResetFn *resetfn;
-
- /*
- * "Original" readfn, writefn, accessfn.
- * For ARMv8.1-VHE register aliases, we overwrite the read/write
- * accessor functions of various EL1/EL0 to perform the runtime
- * check for which sysreg should actually be modified, and then
- * forwards the operation. Before overwriting the accessors,
- * the original function is copied here, so that accesses that
- * really do go to the EL1/EL0 version proceed normally.
- * (The corresponding EL2 register is linked via opaque.)
- */
- CPReadFn *orig_readfn;
- CPWriteFn *orig_writefn;
- CPAccessFn *orig_accessfn;
};
void define_one_arm_cp_reg(ARMCPU *cpu, const ARMCPRegInfo *regs);
diff --git a/target/arm/gdbstub.c b/target/arm/gdbstub.c
index 3727dc01af..269bc6c132 100644
--- a/target/arm/gdbstub.c
+++ b/target/arm/gdbstub.c
@@ -253,6 +253,8 @@ static int arm_gdb_get_sysreg(CPUState *cs, GByteArray *buf, int reg)
(arm_hcr_el2_eff(env) & HCR_E2H) &&
arm_current_el(env) == 2) {
ri = get_arm_cp_reginfo(cpu->cp_regs, ri->vhe_redir_to_el2);
+ } else if (ri->vhe_redir_to_el01) {
+ ri = get_arm_cp_reginfo(cpu->cp_regs, ri->vhe_redir_to_el01);
}
return gdb_get_reg64(buf, (uint64_t)read_raw_cp_reg(env, ri));
case MO_32:
diff --git a/target/arm/helper.c b/target/arm/helper.c
index 3f69ce6cb5..a19406e136 100644
--- a/target/arm/helper.c
+++ b/target/arm/helper.c
@@ -4441,42 +4441,6 @@ static CPAccessResult access_el1nvvct(CPUARMState *env, const ARMCPRegInfo *ri,
return e2h_access(env, ri, isread);
}
-static uint64_t el2_e2h_e12_read(CPUARMState *env, const ARMCPRegInfo *ri)
-{
- /* Pass the EL1 register accessor its ri, not the EL12 alias ri */
- return ri->orig_readfn(env, ri->opaque);
-}
-
-static void el2_e2h_e12_write(CPUARMState *env, const ARMCPRegInfo *ri,
- uint64_t value)
-{
- /* Pass the EL1 register accessor its ri, not the EL12 alias ri */
- return ri->orig_writefn(env, ri->opaque, value);
-}
-
-static CPAccessResult el2_e2h_e12_access(CPUARMState *env,
- const ARMCPRegInfo *ri,
- bool isread)
-{
- if (arm_current_el(env) == 1) {
- /*
- * This must be a FEAT_NV access (will either trap or redirect
- * to memory). None of the registers with _EL12 aliases want to
- * apply their trap controls for this kind of access, so don't
- * call the orig_accessfn or do the "UNDEF when E2H is 0" check.
- */
- return CP_ACCESS_OK;
- }
- /* FOO_EL12 aliases only exist when E2H is 1; otherwise they UNDEF */
- if (!(arm_hcr_el2_eff(env) & HCR_E2H)) {
- return CP_ACCESS_UNDEFINED;
- }
- if (ri->orig_accessfn) {
- return ri->orig_accessfn(env, ri->opaque, isread);
- }
- return CP_ACCESS_OK;
-}
-
static void define_arm_vh_e2h_redirects_aliases(ARMCPU *cpu)
{
struct E2HAlias {
@@ -4566,9 +4530,6 @@ static void define_arm_vh_e2h_redirects_aliases(ARMCPU *cpu)
g_assert(strcmp(src_reg->name, a->src_name) == 0);
g_assert(strcmp(dst_reg->name, a->dst_name) == 0);
- /* None of the core system registers use opaque; we will. */
- g_assert(src_reg->opaque == NULL);
-
/* Create alias before redirection so we dup the right data. */
new_reg = g_memdup(src_reg, sizeof(ARMCPRegInfo));
@@ -4587,19 +4548,11 @@ static void define_arm_vh_e2h_redirects_aliases(ARMCPU *cpu)
>> CP_REG_ARM64_SYSREG_OP1_SHIFT;
new_reg->opc2 = (a->new_key & CP_REG_ARM64_SYSREG_OP2_MASK)
>> CP_REG_ARM64_SYSREG_OP2_SHIFT;
- new_reg->opaque = src_reg;
- new_reg->orig_readfn = src_reg->readfn ?: raw_read;
- new_reg->orig_writefn = src_reg->writefn ?: raw_write;
- new_reg->orig_accessfn = src_reg->accessfn;
- if (!new_reg->raw_readfn) {
- new_reg->raw_readfn = raw_read;
- }
- if (!new_reg->raw_writefn) {
- new_reg->raw_writefn = raw_write;
- }
- new_reg->readfn = el2_e2h_e12_read;
- new_reg->writefn = el2_e2h_e12_write;
- new_reg->accessfn = el2_e2h_e12_access;
+ new_reg->vhe_redir_to_el01 = a->src_key;
+ new_reg->readfn = NULL;
+ new_reg->writefn = NULL;
+ new_reg->accessfn = NULL;
+ new_reg->fieldoffset = 0;
/*
* If the _EL1 register is redirected to memory by FEAT_NV2,
diff --git a/target/arm/tcg/translate-a64.c b/target/arm/tcg/translate-a64.c
index 8fcc74d151..7de8717056 100644
--- a/target/arm/tcg/translate-a64.c
+++ b/target/arm/tcg/translate-a64.c
@@ -2580,6 +2580,18 @@ static void handle_sys(DisasContext *s, bool isread,
*/
key = ri->vhe_redir_to_el2;
ri = redirect_cpreg(s, key, isread);
+ } else if (ri->vhe_redir_to_el01 && s->current_el >= 2) {
+ /*
+ * This is one of the FOO_EL12 registers.
+ * With !E2H, they all UNDEF.
+ * With E2H, from EL2 or EL3, they redirect to FOO_EL1.
+ */
+ if (!s->e2h) {
+ gen_sysreg_undef(s, isread, op0, op1, op2, crn, crm, rt);
+ return;
+ }
+ key = ri->vhe_redir_to_el01;
+ ri = redirect_cpreg(s, key, isread);
}
if (ri->accessfn || (ri->fgt && s->fgt_active)) {
--
2.43.0
next prev parent reply other threads:[~2025-08-27 1:10 UTC|newest]
Thread overview: 94+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-27 1:03 [RFC PATCH 00/61] target/arm: Implement FEAT_SYSREG128 Richard Henderson
2025-08-27 1:03 ` [PATCH 01/61] target/arm: Introduce KVMID_AA64_SYS_REG64 Richard Henderson
2025-08-27 1:03 ` [PATCH 02/61] target/arm: Move compare_u64 to helper.c Richard Henderson
2025-08-28 12:19 ` Manos Pitsidianakis
2025-08-27 1:03 ` [PATCH 03/61] target/arm/hvf: Split out sysreg.c.inc Richard Henderson
2025-08-29 6:58 ` Manos Pitsidianakis
2025-08-27 1:03 ` [PATCH 4/7] target/arm/hvf: Add KVMID_TO_HVF, HVF_TO_KVMID Richard Henderson
2025-08-28 12:22 ` Manos Pitsidianakis
2025-08-27 1:03 ` [PATCH 04/61] target/arm/hvf: Reorder DEF_SYSREG arguments Richard Henderson
2025-08-28 12:17 ` Manos Pitsidianakis
2025-08-27 1:03 ` [PATCH 05/61] target/arm/hvf: Add KVMID_TO_HVF, HVF_TO_KVMID Richard Henderson
2025-08-29 6:59 ` Manos Pitsidianakis
2025-08-27 1:03 ` [PATCH 5/7] target/arm/hvf: Remove hvf_sreg_match.key Richard Henderson
2025-08-27 1:03 ` [PATCH 06/61] " Richard Henderson
2025-08-29 7:00 ` Manos Pitsidianakis
2025-08-27 1:03 ` [PATCH 6/7] target/arm/hvf: Replace hvf_sreg_match with hvf_sreg_list Richard Henderson
2025-08-27 1:03 ` [PATCH 07/61] " Richard Henderson
2025-08-27 1:03 ` [PATCH 7/7] target/arm/hvf: Sort the cpreg_indexes array Richard Henderson
2025-08-27 1:03 ` [PATCH 08/61] " Richard Henderson
2025-08-27 1:04 ` [PATCH 09/61] target/arm/hvf: Use raw_read, raw_write to access Richard Henderson
2025-08-27 1:04 ` [PATCH 10/61] target/arm: Use raw_write in cp_reg_reset Richard Henderson
2025-08-29 7:05 ` Manos Pitsidianakis
2025-08-27 1:04 ` [PATCH 11/61] target/arm: Rename all ARMCPRegInfo from opaque to ri Richard Henderson
2025-08-28 12:41 ` Manos Pitsidianakis
2025-08-27 1:04 ` [PATCH 12/61] target/arm: Drop define_one_arm_cp_reg_with_opaque Richard Henderson
2025-08-29 7:06 ` Manos Pitsidianakis
2025-08-27 1:04 ` [PATCH 13/61] target/arm: Restrict the scope of CPREG_FIELD32, CPREG_FIELD64 Richard Henderson
2025-08-29 7:09 ` Manos Pitsidianakis
2025-08-27 1:04 ` [PATCH 14/61] target/arm: Replace cpreg_field_is_64bit with cpreg_field_type Richard Henderson
2025-08-29 7:13 ` Manos Pitsidianakis
2025-09-03 4:48 ` Richard Henderson
2025-08-27 1:04 ` [PATCH 15/61] target/arm: Add CP_REG_AA32_64BIT_{SHIFT,MASK} Richard Henderson
2025-08-29 7:27 ` Manos Pitsidianakis
2025-08-29 13:55 ` Richard Henderson
2025-08-27 1:04 ` [PATCH 16/61] target/arm: Rename CP_REG_AA32_NS_{SHIFT,MASK} Richard Henderson
2025-08-29 7:30 ` Manos Pitsidianakis
2025-08-27 1:04 ` [PATCH 17/61] target/arm: Convert init_cpreg_list to g_hash_table_foreach Richard Henderson
2025-08-27 1:04 ` [PATCH 18/61] target/arm: Remove cp argument to ENCODE_AA64_CP_REG Richard Henderson
2025-08-29 7:36 ` Manos Pitsidianakis
2025-08-27 1:04 ` [PATCH 19/61] target/arm: Reorder ENCODE_AA64_CP_REG arguments Richard Henderson
2025-08-29 7:40 ` Manos Pitsidianakis
2025-08-27 1:04 ` [PATCH 20/61] target/arm: Split out add_cpreg_to_hashtable_aa{32,64} Richard Henderson
2025-08-27 1:04 ` [PATCH 21/61] target/arm: Improve asserts in define_one_arm_cp_reg Richard Henderson
2025-08-27 1:04 ` [PATCH 22/61] target/arm: Move cp processing to define_one_arm_cp_reg Richard Henderson
2025-08-27 1:04 ` [PATCH 23/61] target/arm: Move cpreg elimination " Richard Henderson
2025-08-27 1:04 ` [PATCH 24/61] target/arm: Add key parameter to add_cpreg_to_hashtable Richard Henderson
2025-08-27 1:04 ` [PATCH 25/61] target/arm: Split out alloc_cpreg Richard Henderson
2025-08-27 1:04 ` [PATCH 26/61] target/arm: Hoist the allocation of ARMCPRegInfo Richard Henderson
2025-08-27 1:04 ` [PATCH 27/61] target/arm: Remove name argument to alloc_cpreg Richard Henderson
2025-08-27 1:04 ` [PATCH 28/61] target/arm: Move alias setting for wildcards Richard Henderson
2025-08-27 1:04 ` [PATCH 29/61] target/arm: Move writeback of CP_ANY fields Richard Henderson
2025-08-27 1:04 ` [PATCH 30/61] target/arm: Move endianness fixup for 32-bit registers Richard Henderson
2025-08-27 1:04 ` [PATCH 31/61] target/arm: Rename TBFLAG_A64_NV2_MEM_E20 with *_E2H Richard Henderson
2025-08-27 1:04 ` [PATCH 32/61] target/arm: Split out redirect_cpreg Richard Henderson
2025-08-27 1:04 ` [PATCH 33/61] target/arm: Redirect VHE FOO_EL1 -> FOO_EL2 during translation Richard Henderson
2025-08-28 12:39 ` Manos Pitsidianakis
2025-08-27 1:04 ` Richard Henderson [this message]
2025-08-27 1:04 ` [PATCH 35/61] target/arm: Rename some cpreg to their aarch64 names Richard Henderson
2025-09-01 6:53 ` Manos Pitsidianakis
2025-08-27 1:04 ` [PATCH 36/61] target/arm: Remove define_arm_vh_e2h_redirects_aliases Richard Henderson
2025-08-27 1:04 ` [PATCH 37/61] target/arm: Implement isar tests for FEAT_SYSREG128, FEAT_SYSINSTR128 Richard Henderson
2025-09-01 6:55 ` Manos Pitsidianakis
2025-08-27 1:04 ` [PATCH 38/61] target/arm: Define CP_REG_SIZE_U128 Richard Henderson
2025-09-01 6:55 ` Manos Pitsidianakis
2025-08-27 1:04 ` [PATCH 39/61] target/arm: Update ARMCPRegInfo for 128-bit sysregs Richard Henderson
2025-09-01 6:56 ` Manos Pitsidianakis
2025-08-27 1:04 ` [PATCH 40/61] target/arm: Assert ARM_CP_128BIT only with ARM_CP_STATE_AA64 Richard Henderson
2025-09-01 6:58 ` Manos Pitsidianakis
2025-08-27 1:04 ` [PATCH 41/61] target/arm: Split add_cpreg_to_hashtable_aa64 Richard Henderson
2025-08-27 1:04 ` [PATCH 42/61] target/arm: Add raw_read128, raw_write128 Richard Henderson
2025-09-01 7:02 ` Manos Pitsidianakis
2025-08-27 1:04 ` [PATCH 43/61] target/arm: Add read_raw_cp_reg128, write_raw_cp_reg128 Richard Henderson
2025-09-01 7:05 ` Manos Pitsidianakis
2025-08-27 1:04 ` [PATCH 44/61] target/arm: Put 128-bit sysregs into a separate list Richard Henderson
2025-08-27 1:04 ` [PATCH 45/61] target/arm/kvm: Assert no 128-bit sysregs in kvm_arm_init_cpreg_list Richard Henderson
2025-08-27 1:04 ` [PATCH 46/61] target/arm/hvf: Assert no 128-bit sysregs in hvf_arch_init_vcpu Richard Henderson
2025-08-27 1:04 ` [PATCH 47/61] migration: Add vmstate_info_int128 Richard Henderson
2025-08-27 1:04 ` [PATCH 48/61] target/arm: Migrate cpreg128 registers Richard Henderson
2025-08-27 1:04 ` [PATCH 49/61] target/arm: Add syn_aa64_sysreg128trap Richard Henderson
2025-08-27 1:04 ` [PATCH 50/61] target/arm: Introduce helper_{get,set}_cp_reg128 Richard Henderson
2025-08-27 1:04 ` [PATCH 51/61] target/arm: Implement MRRS, MSRR, SYSP Richard Henderson
2025-08-27 1:04 ` [PATCH 52/61] include/qemu/compiler: Introduce HOST_ENDIAN_FIELDS Richard Henderson
2025-08-27 1:04 ` [PATCH 53/61] include/hw/core/cpu: Use HOST_ENDIAN_FIELDS in IcountDecr Richard Henderson
2025-08-27 1:04 ` [PATCH 54/61] include/qemu/host-utils: Use HOST_ENDIAN_FIELDS in muldiv64_rounding Richard Henderson
2025-08-27 1:04 ` [PATCH 55/61] target/arm: Use HOST_ENDIAN_FIELDS in CPUARMState Richard Henderson
2025-08-27 1:04 ` [PATCH 56/61] target/arm: Consolidate definitions of PAR Richard Henderson
2025-08-27 1:04 ` [PATCH 57/61] target/arm: Extend PAR_EL1 to 128-bit Richard Henderson
2025-08-27 1:04 ` [PATCH 58/61] target/arm: Consolidate definitions of TTBR[01] Richard Henderson
2025-08-27 1:04 ` [PATCH 59/61] target/arm: Split out flush_if_asid_change Richard Henderson
2025-08-27 1:04 ` [PATCH 60/61] target/arm: Use flush_if_asid_change in vmsa_ttbr_write Richard Henderson
2025-08-27 1:04 ` [PATCH 61/61] target/arm: Extend TTBR system registers to 128-bit Richard Henderson
2025-08-27 2:36 ` [RFC PATCH 00/61] target/arm: Implement FEAT_SYSREG128 Richard Henderson
2025-09-16 12:14 ` Peter Maydell
2025-09-16 12:29 ` Richard Henderson
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=20250827010453.4059782-39-richard.henderson@linaro.org \
--to=richard.henderson@linaro.org \
--cc=qemu-arm@nongnu.org \
--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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).