Skip to contentSkip to conversation

x86: Added LA57 support to is_canonical

PATCH Applied Lara Lazier 2 participants 2 messages Aug 13, 2021 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: Added LA57 support to is_canonical

In case LA57 is enabled, the function is_canonical would need to check if the address is correctly sign-extended from bit 57 (instead of 48) to bit 63.

---
 lib/x86/processor.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
lib/x86/processor.h +4 -1
index a08ea1f..3b43fc4 100644
@@ -640,7 +640,10 @@ static inline void write_pkru(u32 pkru)
 
 static inline bool is_canonical(u64 addr)
 {
-	return (s64)(addr << 16) >> 16 == addr;
+	int va_width = (raw_cpuid(0x80000008, 0).a & 0xff00) >> 8;
+	int shift_amt = 64 - va_width;
+
+	return (s64)(addr << shift_amt) >> shift_amt == addr;
 }
 
 static inline void clear_bit(int bit, u8 *addr)
Signature · 1 line
2.25.1
maintainer Applied
#1 lore raw
Quoted 16 lines · Lara Lazier

In case LA57 is enabled, the function is_canonical would need to check if the address is correctly sign-extended from bit 57 (instead of 48) to bit 63.

---
  lib/x86/processor.h | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
lib/x86/processor.h +0 -0
index a08ea1f..3b43fc4 100644
@@ -640,7 +640,10 @@ static inline void write_pkru(u32 pkru)
 

lib/x86/processor.h static inline void write_pkru(u32 pkru) · line 649

Quoted 10 lines
lib/x86/processor.h +4 -1
  static inline bool is_canonical(u64 addr)
  {
-	return (s64)(addr << 16) >> 16 == addr;
+	int va_width = (raw_cpuid(0x80000008, 0).a & 0xff00) >> 8;
+	int shift_amt = 64 - va_width;
+
+	return (s64)(addr << shift_amt) >> shift_amt == addr;
  }
 
  static inline void clear_bit(int bit, u8 *addr)

Queued, thanks.

Paolo