Skip to contentSkip to conversation

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

PATCH Applied Sean Christopherson 4 participants 4 messages Jan 24, 2020 – Jan 26, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

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

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 <[email protected]>
Cc Krish Sadhukhan <[email protected]>
Fixes ecb697d10f70 ("KVM: nVMX: Check GUEST_DR7 on vmentry of nested guests")
---
 arch/x86/kvm/x86.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/x86.h +1 -1
index 2d2ff855773b..3624665acee4 100644
@@ -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);
Signature · 1 line
2.24.1
Acked-by on v1 1/1
#1 lore raw
Quoted 13 lines · Sean Christopherson

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.

Quoted 5 lines
Cc Jim Mattson <[email protected]>
Cc Krish Sadhukhan <[email protected]>
Fixes ecb697d10f70 ("KVM: nVMX: Check GUEST_DR7 on vmentry of nested guests")

Thanks.

Quoted 18 lines
---
 arch/x86/kvm/x86.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/x86.h +1 -1
index 2d2ff855773b..3624665acee4 100644
@@ -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);
Signature · 2 lines
~Randy
Reported-by: Randy Dunlap <[email protected]>
maintainer Applied
#2 lore raw
In reply to Sean Christopherson
Quoted 28 lines · Sean Christopherson

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 <[email protected]>
Cc Krish Sadhukhan <[email protected]>
Fixes ecb697d10f70 ("KVM: nVMX: Check GUEST_DR7 on vmentry of nested guests")
---
 arch/x86/kvm/x86.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/x86.h +0 -0
index 2d2ff855773b..3624665acee4 100644

arch/x86/kvm/x86.h static inline bool kvm_pat_valid(u64 data) · line 363

Quoted 8 lines
arch/x86/kvm/x86.h +1 -1
@@ -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

Reviewed-by on v1 1/1
#3 lore raw
In reply to Sean Christopherson
Quoted 27 lines · Sean Christopherson

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 <[email protected]>
Cc Krish Sadhukhan <[email protected]>
Fixes ecb697d10f70 ("KVM: nVMX: Check GUEST_DR7 on vmentry of nested guests")
---
  arch/x86/kvm/x86.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/x86.h +0 -0
index 2d2ff855773b..3624665acee4 100644

arch/x86/kvm/x86.h static inline bool kvm_pat_valid(u64 data) · line 363

Quoted 8 lines
arch/x86/kvm/x86.h +1 -1
@@ -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);