diff mbox series

KVM: x86: Take a u64 when checking for a valid dr7 value

Message ID 20200124230722.8964-1-sean.j.christopherson@intel.com (mailing list archive)
State New, archived
Headers show
Series KVM: x86: Take a u64 when checking for a valid dr7 value | expand

Commit Message

Sean Christopherson Jan. 24, 2020, 11:07 p.m. UTC
Take a u64 instead of an unsigned long in kvm_dr7_valid() to fix a build
warning on i386 due to right-shifting a 32-bit value by 32 when checking
for bits being set in dr7[63:32].

Alternatively, the warning could be resolved by rewriting the check to
use an i386-friendly method, but taking a u64 fixes another oddity on
32-bit KVM.  Beause KVM implements natural width VMCS fields as u64s to
avoid layout issues between 32-bit and 64-bit, a devious guest can stuff
vmcs12->guest_dr7 with a 64-bit value even when both the guest and host
are 32-bit kernels.  KVM eventually drops vmcs12->guest_dr7[63:32] when
propagating vmcs12->guest_dr7 to vmcs02, but ideally KVM would not rely
on that behavior for correctness.

Cc: Jim Mattson <jmattson@google.com>
Cc: Krish Sadhukhan <krish.sadhukhan@oracle.com>
Fixes: ecb697d10f70 ("KVM: nVMX: Check GUEST_DR7 on vmentry of nested guests")
Reported-by: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
---
 arch/x86/kvm/x86.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Randy Dunlap Jan. 24, 2020, 11:44 p.m. UTC | #1
On 1/24/20 3:07 PM, Sean Christopherson wrote:
> Take a u64 instead of an unsigned long in kvm_dr7_valid() to fix a build
> warning on i386 due to right-shifting a 32-bit value by 32 when checking
> for bits being set in dr7[63:32].
> 
> Alternatively, the warning could be resolved by rewriting the check to
> use an i386-friendly method, but taking a u64 fixes another oddity on
> 32-bit KVM.  Beause KVM implements natural width VMCS fields as u64s to
> avoid layout issues between 32-bit and 64-bit, a devious guest can stuff
> vmcs12->guest_dr7 with a 64-bit value even when both the guest and host
> are 32-bit kernels.  KVM eventually drops vmcs12->guest_dr7[63:32] when
> propagating vmcs12->guest_dr7 to vmcs02, but ideally KVM would not rely
> on that behavior for correctness.
> 
> Cc: Jim Mattson <jmattson@google.com>
> Cc: Krish Sadhukhan <krish.sadhukhan@oracle.com>
> Fixes: ecb697d10f70 ("KVM: nVMX: Check GUEST_DR7 on vmentry of nested guests")
> Reported-by: Randy Dunlap <rdunlap@infradead.org>
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>

Acked-by: Randy Dunlap <rdunlap@infradead.org> # build-tested

Thanks.

> ---
>  arch/x86/kvm/x86.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
> index 2d2ff855773b..3624665acee4 100644
> --- a/arch/x86/kvm/x86.h
> +++ b/arch/x86/kvm/x86.h
> @@ -357,7 +357,7 @@ static inline bool kvm_pat_valid(u64 data)
>  	return (data | ((data & 0x0202020202020202ull) << 1)) == data;
>  }
>  
> -static inline bool kvm_dr7_valid(unsigned long data)
> +static inline bool kvm_dr7_valid(u64 data)
>  {
>  	/* Bits [63:32] are reserved */
>  	return !(data >> 32);
>
Paolo Bonzini Jan. 25, 2020, 9:32 a.m. UTC | #2
On 25/01/20 00:07, Sean Christopherson wrote:
> Take a u64 instead of an unsigned long in kvm_dr7_valid() to fix a build
> warning on i386 due to right-shifting a 32-bit value by 32 when checking
> for bits being set in dr7[63:32].
> 
> Alternatively, the warning could be resolved by rewriting the check to
> use an i386-friendly method, but taking a u64 fixes another oddity on
> 32-bit KVM.  Beause KVM implements natural width VMCS fields as u64s to
> avoid layout issues between 32-bit and 64-bit, a devious guest can stuff
> vmcs12->guest_dr7 with a 64-bit value even when both the guest and host
> are 32-bit kernels.  KVM eventually drops vmcs12->guest_dr7[63:32] when
> propagating vmcs12->guest_dr7 to vmcs02, but ideally KVM would not rely
> on that behavior for correctness.
> 
> Cc: Jim Mattson <jmattson@google.com>
> Cc: Krish Sadhukhan <krish.sadhukhan@oracle.com>
> Fixes: ecb697d10f70 ("KVM: nVMX: Check GUEST_DR7 on vmentry of nested guests")
> Reported-by: Randy Dunlap <rdunlap@infradead.org>
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> ---
>  arch/x86/kvm/x86.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
> index 2d2ff855773b..3624665acee4 100644
> --- a/arch/x86/kvm/x86.h
> +++ b/arch/x86/kvm/x86.h
> @@ -357,7 +357,7 @@ static inline bool kvm_pat_valid(u64 data)
>  	return (data | ((data & 0x0202020202020202ull) << 1)) == data;
>  }
>  
> -static inline bool kvm_dr7_valid(unsigned long data)
> +static inline bool kvm_dr7_valid(u64 data)
>  {
>  	/* Bits [63:32] are reserved */
>  	return !(data >> 32);
> 

Queued, thanks.

Paolo
Krish Sadhukhan Jan. 26, 2020, 7:49 a.m. UTC | #3
On 1/24/20 3:07 PM, Sean Christopherson wrote:
> Take a u64 instead of an unsigned long in kvm_dr7_valid() to fix a build
> warning on i386 due to right-shifting a 32-bit value by 32 when checking
> for bits being set in dr7[63:32].
>
> Alternatively, the warning could be resolved by rewriting the check to
> use an i386-friendly method, but taking a u64 fixes another oddity on
> 32-bit KVM.  Beause KVM implements natural width VMCS fields as u64s to
> avoid layout issues between 32-bit and 64-bit, a devious guest can stuff
> vmcs12->guest_dr7 with a 64-bit value even when both the guest and host
> are 32-bit kernels.  KVM eventually drops vmcs12->guest_dr7[63:32] when
> propagating vmcs12->guest_dr7 to vmcs02, but ideally KVM would not rely
> on that behavior for correctness.
>
> Cc: Jim Mattson <jmattson@google.com>
> Cc: Krish Sadhukhan <krish.sadhukhan@oracle.com>
> Fixes: ecb697d10f70 ("KVM: nVMX: Check GUEST_DR7 on vmentry of nested guests")
> Reported-by: Randy Dunlap <rdunlap@infradead.org>
> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com>
> ---
>   arch/x86/kvm/x86.h | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
> index 2d2ff855773b..3624665acee4 100644
> --- a/arch/x86/kvm/x86.h
> +++ b/arch/x86/kvm/x86.h
> @@ -357,7 +357,7 @@ static inline bool kvm_pat_valid(u64 data)
>   	return (data | ((data & 0x0202020202020202ull) << 1)) == data;
>   }
>   
> -static inline bool kvm_dr7_valid(unsigned long data)
> +static inline bool kvm_dr7_valid(u64 data)
>   {
>   	/* Bits [63:32] are reserved */
>   	return !(data >> 32);
Reviewed-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
diff mbox series

Patch

diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h
index 2d2ff855773b..3624665acee4 100644
--- a/arch/x86/kvm/x86.h
+++ b/arch/x86/kvm/x86.h
@@ -357,7 +357,7 @@  static inline bool kvm_pat_valid(u64 data)
 	return (data | ((data & 0x0202020202020202ull) << 1)) == data;
 }
 
-static inline bool kvm_dr7_valid(unsigned long data)
+static inline bool kvm_dr7_valid(u64 data)
 {
 	/* Bits [63:32] are reserved */
 	return !(data >> 32);