[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 32/35] target/arm: Define and use new load_cpu_field_low32()
|
From: |
Peter Maydell |
|
Subject: |
[PULL 32/35] target/arm: Define and use new load_cpu_field_low32() |
|
Date: |
Tue, 2 May 2023 13:14:56 +0100 |
In several places in the 32-bit Arm translate.c, we try to use
load_cpu_field() to load from a CPUARMState field into a TCGv_i32
where the field is actually 64-bit. This works on little-endian
hosts, but gives the wrong half of the register on big-endian.
Add a new load_cpu_field_low32() which loads the low 32 bits
of a 64-bit field into a TCGv_i32. The new macro includes a
compile-time check against accidentally using it on a field
of the wrong size. Use it to fix the two places in the code
where we were using load_cpu_field() on a 64-bit field.
This fixes a bug where on big-endian hosts the guest would
crash after executing an ERET instruction, and a more corner
case one where some UNDEFs for attempted accesses to MSR
banked registers from Secure EL1 might go to the wrong EL.
Cc: qemu-stable@nongnu.org
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-id: 20230424153909.1419369-2-peter.maydell@linaro.org
---
target/arm/translate-a32.h | 7 +++++++
target/arm/tcg/translate.c | 4 ++--
2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/target/arm/translate-a32.h b/target/arm/translate-a32.h
index 5339c22f1e0..99eea85fa86 100644
--- a/target/arm/translate-a32.h
+++ b/target/arm/translate-a32.h
@@ -61,6 +61,13 @@ static inline TCGv_i32 load_cpu_offset(int offset)
#define load_cpu_field(name) load_cpu_offset(offsetof(CPUARMState, name))
+/* Load from the low half of a 64-bit field to a TCGv_i32 */
+#define load_cpu_field_low32(name) \
+ ({ \
+ QEMU_BUILD_BUG_ON(sizeof_field(CPUARMState, name) != 8); \
+ load_cpu_offset(offsetoflow32(CPUARMState, name)); \
+ })
+
void store_cpu_offset(TCGv_i32 var, int offset, int size);
#define store_cpu_field(var, name) \
diff --git a/target/arm/tcg/translate.c b/target/arm/tcg/translate.c
index 3c8401e9086..74684767249 100644
--- a/target/arm/tcg/translate.c
+++ b/target/arm/tcg/translate.c
@@ -2816,7 +2816,7 @@ static bool msr_banked_access_decode(DisasContext *s, int
r, int sysm, int rn,
if (arm_dc_feature(s, ARM_FEATURE_AARCH64) &&
dc_isar_feature(aa64_sel2, s)) {
/* Target EL is EL<3 minus SCR_EL3.EEL2> */
- tcg_el = load_cpu_field(cp15.scr_el3);
+ tcg_el = load_cpu_field_low32(cp15.scr_el3);
tcg_gen_sextract_i32(tcg_el, tcg_el, ctz32(SCR_EEL2), 1);
tcg_gen_addi_i32(tcg_el, tcg_el, 3);
} else {
@@ -6396,7 +6396,7 @@ static bool trans_ERET(DisasContext *s, arg_ERET *a)
}
if (s->current_el == 2) {
/* ERET from Hyp uses ELR_Hyp, not LR */
- tmp = load_cpu_field(elr_el[2]);
+ tmp = load_cpu_field_low32(elr_el[2]);
} else {
tmp = load_reg(s, 14);
}
--
2.34.1
- [PULL 28/35] hw/arm/boot: Make write_bootloader() public as arm_write_bootloader(), (continued)
- [PULL 28/35] hw/arm/boot: Make write_bootloader() public as arm_write_bootloader(), Peter Maydell, 2023/05/02
- [PULL 26/35] docs/about/deprecated.rst: Add "since 7.1" tag to dtb-kaslr-seed deprecation, Peter Maydell, 2023/05/02
- [PULL 25/35] qmp: Deprecate 'singlestep' member of StatusInfo, Peter Maydell, 2023/05/02
- [PULL 14/35] hw/net: npcm7xx_emc: set MAC in register space, Peter Maydell, 2023/05/02
- [PULL 27/35] hw/net/msf2-emac: Don't modify descriptor in-place in emac_store_desc(), Peter Maydell, 2023/05/02
- [PULL 23/35] hmp: Add 'one-insn-per-tb' command equivalent to 'singlestep', Peter Maydell, 2023/05/02
- [PULL 16/35] make one-insn-per-tb an accel option, Peter Maydell, 2023/05/02
- [PULL 31/35] hw/intc/allwinner-a10-pic: Don't use set_bit()/clear_bit(), Peter Maydell, 2023/05/02
- [PULL 33/35] target/arm: Add compile time asserts to load/store_cpu_field macros, Peter Maydell, 2023/05/02
- [PULL 24/35] qapi/run-state.json: Fix missing newline at end of file, Peter Maydell, 2023/05/02
- [PULL 32/35] target/arm: Define and use new load_cpu_field_low32(),
Peter Maydell <=
- [PULL 05/35] target/arm: Move 64-bit TCG CPUs into tcg/, Peter Maydell, 2023/05/02
- [PULL 22/35] accel/tcg: Report one-insn-per-tb in 'info jit', not 'info status', Peter Maydell, 2023/05/02
- [PULL 10/35] arm/Kconfig: Always select SEMIHOSTING when TCG is present, Peter Maydell, 2023/05/02
- [PULL 06/35] tests/qtest: Adjust and document query-cpu-model-expansion test for arm, Peter Maydell, 2023/05/02
- [PULL 08/35] tests/qtest: Fix tests when no KVM or TCG are present, Peter Maydell, 2023/05/02
- [PULL 12/35] tests/qtest: Restrict tpm-tis-i2c-test to CONFIG_TCG, Peter Maydell, 2023/05/02
- [PULL 13/35] gitlab-ci: Check building KVM-only aarch64 target, Peter Maydell, 2023/05/02
- [PULL 17/35] softmmu: Don't use 'singlestep' global in QMP and HMP commands, Peter Maydell, 2023/05/02
- [PULL 21/35] Document that -singlestep command line option is deprecated, Peter Maydell, 2023/05/02
- [PULL 18/35] accel/tcg: Use one_insn_per_tb global instead of old singlestep global, Peter Maydell, 2023/05/02