[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen staging] xen/arm: traps: Fix sign extension logic in sign_extend()



commit 69625555f5cdd2d3b83ead3e4fd2bc7b7e819bb3
Author:     Michal Orzel <michal.orzel@xxxxxxx>
AuthorDate: Wed Nov 18 09:37:42 2026 +0100
Commit:     Michal Orzel <michal.orzel@xxxxxxx>
CommitDate: Thu Nov 19 08:18:28 2026 +0100

    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.
    
    Fixes: ac0ca6895b65 ("xen/arm: io: Support sign-extension for every read 
access")
    Signed-off-by: Michal Orzel <michal.orzel@xxxxxxx>
    Reviewed-by: Stefano Stabellini <sstabellini@xxxxxxxxxx>
---
 xen/arch/arm/include/asm/traps.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/xen/arch/arm/include/asm/traps.h b/xen/arch/arm/include/asm/traps.h
index 3b40afe262..c5b6ff5b78 100644
--- a/xen/arch/arm/include/asm/traps.h
+++ b/xen/arch/arm/include/asm/traps.h
@@ -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;
--
generated by git-patchbot for /home/xen/git/xen.git#staging



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.