Skip to contentSkip to conversation

target/s390x/tcg/mem_helper: Test the right bits in psw_key_valid()

PATCH In review Thomas Huth 3 participants 3 messages Dec 5, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 target/s390x/tcg/mem_helper: Test the right bits in psw_key_valid()

The PSW key mask is a 16 bit field, and the psw_key variable is in the range from 0 to 15, so it does not make sense to use "0x80 >> psw_key" for testing the bits here. We should use 0x8000 instead.

---
Found by code inspection (Linux likely does not use these PSW key masks yet, otherwise we might have noticed earlier)

 target/s390x/tcg/mem_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/s390x/tcg/mem_helper.c +1 -1
index 9542fad59b..cb82cd1c1d 100644
@@ -51,7 +51,7 @@ static inline bool psw_key_valid(CPUS390XState *env, uint8_t psw_key)
 
     if (env->psw.mask & PSW_MASK_PSTATE) {
         /* PSW key has range 0..15, it is valid if the bit is 1 in the PKM */
-        return pkm & (0x80 >> psw_key);
+        return pkm & (0x8000 >> psw_key);
     }
     return true;
 }
Signature · 1 line
2.31.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 18 lines · Thomas Huth

The PSW key mask is a 16 bit field, and the psw_key variable is in the range from 0 to 15, so it does not make sense to use "0x80 >> psw_key" for testing the bits here. We should use 0x8000 instead.

---
Found by code inspection (Linux likely does not use these PSW key masks yet, otherwise we might have noticed earlier)

  target/s390x/tcg/mem_helper.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
target/s390x/tcg/mem_helper.c +0 -0
index 9542fad59b..cb82cd1c1d 100644

target/s390x/tcg/mem_helper.c static inline bool psw_key_valid(CPUS390XState *env, uint8_t psw_key) · line 57

Quoted 8 lines
target/s390x/tcg/mem_helper.c +1 -1
@@ -51,7 +51,7 @@ static inline bool psw_key_valid(CPUS390XState *env, uint8_t psw_key)
 
      if (env->psw.mask & PSW_MASK_PSTATE) {
          /* PSW key has range 0..15, it is valid if the bit is 1 in the PKM */
-        return pkm & (0x80 >> psw_key);
+        return pkm & (0x8000 >> psw_key);
      }
      return true;
  }

I assume a Fixes tag might be applicable (I remember I added that once).

Signature · 3 lines
Thanks,

David / dhildenb
Reviewed-by on v1 1/1
#2 lore raw
In reply to Thomas Huth
Quoted 6 lines · Thomas Huth

The PSW key mask is a 16 bit field, and the psw_key variable is in the range from 0 to 15, so it does not make sense to use "0x80 >> psw_key" for testing the bits here. We should use 0x8000 instead.

Quoted 20 lines

---
Found by code inspection (Linux likely does not use these PSW key masks yet, otherwise we might have noticed earlier)

 target/s390x/tcg/mem_helper.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/s390x/tcg/mem_helper.c +1 -1
index 9542fad59b..cb82cd1c1d 100644
@@ -51,7 +51,7 @@ static inline bool psw_key_valid(CPUS390XState *env, uint8_t psw_key)
 
     if (env->psw.mask & PSW_MASK_PSTATE) {
         /* PSW key has range 0..15, it is valid if the bit is 1 in the PKM */
-        return pkm & (0x80 >> psw_key);
+        return pkm & (0x8000 >> psw_key);
     }
     return true;
 }