All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH kvm-unit-tests] x86: Added LA57 support to is_canonical
@ 2021-08-13 11:18 Lara Lazier
  2021-08-13 11:29 ` Paolo Bonzini
  0 siblings, 1 reply; 2+ messages in thread
From: Lara Lazier @ 2021-08-13 11:18 UTC (permalink / raw)
  To: kvm; +Cc: pbonzini, 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.

Signed-off-by: Lara Lazier <laramglazier@gmail.com>
---
 lib/x86/processor.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/x86/processor.h b/lib/x86/processor.h
index a08ea1f..3b43fc4 100644
--- a/lib/x86/processor.h
+++ b/lib/x86/processor.h
@@ -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)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH kvm-unit-tests] x86: Added LA57 support to is_canonical
  2021-08-13 11:18 [PATCH kvm-unit-tests] x86: Added LA57 support to is_canonical Lara Lazier
@ 2021-08-13 11:29 ` Paolo Bonzini
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2021-08-13 11:29 UTC (permalink / raw)
  To: Lara Lazier, kvm

On 13/08/21 13:18, Lara Lazier wrote:
> 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.
> 
> Signed-off-by: Lara Lazier <laramglazier@gmail.com>
> ---
>   lib/x86/processor.h | 5 ++++-
>   1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/lib/x86/processor.h b/lib/x86/processor.h
> index a08ea1f..3b43fc4 100644
> --- a/lib/x86/processor.h
> +++ b/lib/x86/processor.h
> @@ -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)
> 

Queued, thanks.

Paolo


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-13 11:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-13 11:18 [PATCH kvm-unit-tests] x86: Added LA57 support to is_canonical Lara Lazier
2021-08-13 11:29 ` Paolo Bonzini

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.