kvm: vmx: Silence a shift wrap warning
Subsystems (3)
PATCH 1/1 kvm: vmx: Silence a shift wrap warning
This code generates a Smatch warning:
arch/x86/kvm/vmx/nested.c:4828 handle_vmfunc() warn: should '(1 << function)' be a 64 bit type?
The warning is generated because "vmcs12->vm_function_control" is a u64 but the shift can only test the lower 32 bits. This doesn't cause a problem in the current code because we only use BIT(0). This patch just silences the static checker warning.
--- arch/x86/kvm/vmx/nested.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kvm/vmx/nested.c +1 -1
@@ -4825,7 +4825,7 @@ static int handle_vmfunc(struct kvm_vcpu *vcpu) } vmcs12 =get_vmcs12 (vcpu); -if ((vmcs12->vm_function_control & (1 << function)) =0 ) +if ((vmcs12->vm_function_control & (1ULL << function)) =0 ) goto fail;switch (function) {
Signature · 1 line
2.17.1
Quoted 19 lines · Dan Carpenter
This code generates a Smatch warning:
arch/x86/kvm/vmx/nested.c:4828handle_vmfunc()warn: should '(1 << function)' be a 64 bit type?The warning is generated because "
vmcs12->vm_function_control" is a u64 but the shift can only test the lower 32 bits. This doesn't cause a problem in the current code because we only use BIT(0). This patch just silences the static checker warning.Signed-off-by Dan Carpenter <[email protected]>--- arch/x86/kvm/vmx/nested.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kvm/vmx/nested.c +0
-0
arch/x86/kvm/vmx/nested.c static int handle_vmfunc(struct kvm_vcpu *vcpu) · line 4828
Quoted 5 lines
arch/x86/kvm/vmx/nested.c +1
-1@@ -4825,7 +4825,7 @@ static int handle_vmfunc(struct kvm_vcpu *vcpu) } vmcs12 =get_vmcs12 (vcpu); -if ((vmcs12->vm_function_control & (1 << function)) =0 ) +if ((vmcs12->vm_function_control & (1ULL << function)) =0 )
I guess one set of parentheses could be dropped here, while touching the line.
Quoted 4 lines
arch/x86/kvm/vmx/nested.c +0
-0goto fail;switch (function) {
Signature · 3 lines
Thanks, David / dhildenb
Quoted 22 lines · David Hildenbrand
Quoted 21 lines · Dan Carpenter
This code generates a Smatch warning:
arch/x86/kvm/vmx/nested.c:4828handle_vmfunc()warn: should '(1 << function)' be a 64 bit type?The warning is generated because "
vmcs12->vm_function_control" is a u64 but the shift can only test the lower 32 bits. This doesn't cause a problem in the current code because we only use BIT(0). This patch just silences the static checker warning.Signed-off-by Dan Carpenter <[email protected]>--- arch/x86/kvm/vmx/nested.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kvm/vmx/nested.c +0
-0@@ -4825,7 +4825,7 @@ static int handle_vmfunc(struct kvm_vcpu *vcpu) }
Quoted 6 lines
arch/x86/kvm/vmx/nested.c static int handle_vmfunc(struct kvm_vcpu *vcpu) · line 4828
Quoted 3 lines
arch/x86/kvm/vmx/nested.c +1
-1vmcs12 =get_vmcs12 (vcpu); -if ((vmcs12->vm_function_control & (1 << function)) =0 ) +if ((vmcs12->vm_function_control & (1ULL << function)) =0 )I guess one set of parentheses could be dropped here, while touching the line.
The problem is bitwise AND has low precedence so the parenthesis are either required or they improve readability. You could write it like this:
if ((vmcs12->vm_function_control & 1ULL << function) = 0)
but no one does.
Quoted 3 lines
Reviewed-by David Hildenbrand <[email protected]>
Thanks!
regards,
dan carpenter
Quoted 30 lines · Dan Carpenter
Quoted 22 lines · David Hildenbrand
Quoted 21 lines · Dan Carpenter
This code generates a Smatch warning:
arch/x86/kvm/vmx/nested.c:4828handle_vmfunc()warn: should '(1 << function)' be a 64 bit type?The warning is generated because "
vmcs12->vm_function_control" is a u64 but the shift can only test the lower 32 bits. This doesn't cause a problem in the current code because we only use BIT(0). This patch just silences the static checker warning.Signed-off-by Dan Carpenter <[email protected]>--- arch/x86/kvm/vmx/nested.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)arch/x86/kvm/vmx/nested.c +0
-0@@ -4825,7 +4825,7 @@ static int handle_vmfunc(struct kvm_vcpu *vcpu) }Quoted 6 lines
arch/x86/kvm/vmx/nested.c static int handle_vmfunc(struct kvm_vcpu *vcpu) · line 4828
Quoted 3 lines
arch/x86/kvm/vmx/nested.c +1
-1vmcs12 =get_vmcs12 (vcpu); -if ((vmcs12->vm_function_control & (1 << function)) =0 ) +if ((vmcs12->vm_function_control & (1ULL << function)) =0 )I guess one set of parentheses could be dropped here, while touching the line.
Quoted 7 lines
The problem is bitwise AND has low precedence so the parenthesis are either required or they improve readability. You could write it like this:
if ((vmcs12->vm_function_control & 1ULL << function) = 0)but no one does.
Yes, you're right, my intuition was wrong this time :)
Cheers!
Quoted 10 lines
Quoted 4 lines
Reviewed-by David Hildenbrand <[email protected]>Thanks!
regards,
dan carpenter
Signature · 3 lines
Thanks, David / dhildenb