xen/arm: traps: Fix sign extension logic in sign_extend()
PATCH 1/1 xen/arm: traps: Fix sign extension logic in sign_extend()
At the moment, we always sign extend to the full register width, i.e. 64-bit on Arm64, even though for byte and half-word accesses the destination can also be a W (32-bit) register (LDRSB Wt, LDRSH Wt). In that case, the architecture requires bits [63:32] of Xt to be zero, but a subsequent use of Xt by the guest sees them set to ones. Fix it.
--- xen/arch/arm/include/asm/traps.h | 6 ++++++ 1 file changed, 6 insertions(+)
xen/arch/arm/include/asm/traps.h +6 -0
@@ -111,6 +111,12 @@ static inline register_t sign_extend(const struct hsr_dabt dabt, register_t r)*/ BUILD_BUG_ON (sizeof (register_t) !=sizeof (unsigned long )); r |= (~0UL ) << size; + +#ifdef CONFIG_ARM_64 +/* When loading to W register we should only sign extend to 32-bit */ +if ( !dabt.sf ) + r = (uint32_t )r; +#endif }return r;
Signature · 1 line
2.43.0
Quoted 8 lines · Michal Orzel
At the moment, we always sign extend to the full register width, i.e. 64-bit on Arm64, even though for byte and half-word accesses the destination can also be a W (32-bit) register (LDRSB Wt, LDRSH Wt). In that case, the architecture requires bits [63:32] of Xt to be zero, but a subsequent use of Xt by the guest sees them set to ones. Fix it.
Fixes ac0ca6895b65 ("xen/arm: io: Support sign-extension for every read access")Signed-off-by Michal Orzel <[email protected]>
Quoted 24 lines
--- xen/arch/arm/include/asm/traps.h | 6 ++++++ 1 file changed, 6 insertions(+)xen/arch/arm/include/asm/traps.h +6
-0@@ -111,6 +111,12 @@ static inline register_t sign_extend(const struct hsr_dabt dabt, register_t r)*/ BUILD_BUG_ON (sizeof (register_t) !=sizeof (unsigned long )); r |= (~0UL ) << size; + +#ifdef CONFIG_ARM_64 +/* When loading to W register we should only sign extend to 32-bit */ +if ( !dabt.sf ) + r = (uint32_t )r; +#endif }return r;Signature · 1 line
2.43.0