Skip to contentSkip to conversation

target/hppa: Fix PSW V-bit packaging in cpu_hppa_get for hppa64

PATCH Superseded Helge Deller 3 participants 3 messages Sep 3, 2024

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/hppa: Fix PSW V-bit packaging in cpu_hppa_get for hppa64

While adding hppa64 support, the psw_v variable got extended from 32 to 64 bits. So, when packaging the PSW-V bit from the psw_v variable for interrupt processing, check bit 31 instead the 63th (sign) bit.

This fixes a hard to find Linux kernel boot issue where the loss of the PSW-V bit due to an ITLB interruption in the middle of a series of ds/addc instructions (from the divU milicode library) generated the wrong division result and thus triggered a Linux kernel crash.

Fixes 931adff31478 ("target/hppa: Update cpu_hppa_get/put_psw for hppa64")
target/hppa/helper.c +1 -1
index b79ddd8184..d4b1a3cd5a 100644
@@ -53,7 +53,7 @@ target_ulong cpu_hppa_get_psw(CPUHPPAState *env)
     }
 
     psw |= env->psw_n * PSW_N;
-    psw |= (env->psw_v < 0) * PSW_V;
+    psw |= ((env->psw_v >> 31) & 1) * PSW_V;
     psw |= env->psw | env->psw_xb;
 
     return psw;
Tested-by on v1 1/1
#1 lore raw
Quoted 9 lines · Helge Deller

While adding hppa64 support, the psw_v variable got extended from 32 to 64 bits. So, when packaging the PSW-V bit from the psw_v variable for interrupt processing, check bit 31 instead the 63th (sign) bit.

This fixes a hard to find Linux kernel boot issue where the loss of the PSW-V bit due to an ITLB interruption in the middle of a series of ds/addc instructions (from the divU milicode library) generated the wrong division result and thus triggered a Linux kernel crash.

Quoted 4 lines
Fixes 931adff31478 ("target/hppa: Update cpu_hppa_get/put_psw for hppa64")

Thanks!
Guenter

Quoted 14 lines
target/hppa/helper.c +1 -1
index b79ddd8184..d4b1a3cd5a 100644
@@ -53,7 +53,7 @@ target_ulong cpu_hppa_get_psw(CPUHPPAState *env)
      }
 
      psw |= env->psw_n * PSW_N;
-    psw |= (env->psw_v < 0) * PSW_V;
+    psw |= ((env->psw_v >> 31) & 1) * PSW_V;
      psw |= env->psw | env->psw_xb;
 
      return psw;
Reviewed-by on v1 1/1
#2 lore raw
In reply to Helge Deller
Quoted 19 lines · Helge Deller

While adding hppa64 support, the psw_v variable got extended from 32 to 64 bits. So, when packaging the PSW-V bit from the psw_v variable for interrupt processing, check bit 31 instead the 63th (sign) bit.

This fixes a hard to find Linux kernel boot issue where the loss of the PSW-V bit due to an ITLB interruption in the middle of a series of ds/addc instructions (from the divU milicode library) generated the wrong division result and thus triggered a Linux kernel crash.

Fixes 931adff31478 ("target/hppa: Update cpu_hppa_get/put_psw for hppa64")
target/hppa/helper.c +0 -0
index b79ddd8184..d4b1a3cd5a 100644

target/hppa/helper.c target_ulong cpu_hppa_get_psw(CPUHPPAState *env) · line 59

Quoted 8 lines
target/hppa/helper.c +1 -1
@@ -53,7 +53,7 @@ target_ulong cpu_hppa_get_psw(CPUHPPAState *env)
      }
 
      psw |= env->psw_n * PSW_N;
-    psw |= (env->psw_v < 0) * PSW_V;
+    psw |= ((env->psw_v >> 31) & 1) * PSW_V;
      psw |= env->psw | env->psw_xb;
 
      return psw;

While this is correct, we should also update cpu.h:

-    target_long psw_v;       /* in most significant bit */
+    target_long psw_v;       /* in bit 31 */

With that,

r~