All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kvm: vmx: Silence a shift wrap warning
@ 2019-03-25  9:04 Dan Carpenter
  2019-03-25  9:29 ` David Hildenbrand
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Dan Carpenter @ 2019-03-25  9:04 UTC (permalink / raw)
  To: kernel-janitors

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.

Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 arch/x86/kvm/vmx/nested.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
index f24a2c225070..1f4398246bd9 100644
--- a/arch/x86/kvm/vmx/nested.c
+++ b/arch/x86/kvm/vmx/nested.c
@@ -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) {
-- 
2.17.1

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

* Re: [PATCH] kvm: vmx: Silence a shift wrap warning
  2019-03-25  9:04 [PATCH] kvm: vmx: Silence a shift wrap warning Dan Carpenter
@ 2019-03-25  9:29 ` David Hildenbrand
  2019-03-26  7:07 ` Dan Carpenter
  2019-03-26  8:10 ` David Hildenbrand
  2 siblings, 0 replies; 4+ messages in thread
From: David Hildenbrand @ 2019-03-25  9:29 UTC (permalink / raw)
  To: kernel-janitors

On 25.03.19 10:04, Dan Carpenter wrote:
> 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.
> 
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
>  arch/x86/kvm/vmx/nested.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> index f24a2c225070..1f4398246bd9 100644
> --- a/arch/x86/kvm/vmx/nested.c
> +++ b/arch/x86/kvm/vmx/nested.c
> @@ -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.

Reviewed-by: David Hildenbrand <david@redhat.com>

>  		goto fail;
>  
>  	switch (function) {
> 


-- 

Thanks,

David / dhildenb

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

* Re: [PATCH] kvm: vmx: Silence a shift wrap warning
  2019-03-25  9:04 [PATCH] kvm: vmx: Silence a shift wrap warning Dan Carpenter
  2019-03-25  9:29 ` David Hildenbrand
@ 2019-03-26  7:07 ` Dan Carpenter
  2019-03-26  8:10 ` David Hildenbrand
  2 siblings, 0 replies; 4+ messages in thread
From: Dan Carpenter @ 2019-03-26  7:07 UTC (permalink / raw)
  To: kernel-janitors

On Mon, Mar 25, 2019 at 10:29:40AM +0100, David Hildenbrand wrote:
> On 25.03.19 10:04, Dan Carpenter wrote:
> > 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.
> > 
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > ---
> >  arch/x86/kvm/vmx/nested.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
> > index f24a2c225070..1f4398246bd9 100644
> > --- a/arch/x86/kvm/vmx/nested.c
> > +++ b/arch/x86/kvm/vmx/nested.c
> > @@ -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.

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.

> 
> Reviewed-by: David Hildenbrand <david@redhat.com>
> 

Thanks!

regards,
dan carpenter

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

* Re: [PATCH] kvm: vmx: Silence a shift wrap warning
  2019-03-25  9:04 [PATCH] kvm: vmx: Silence a shift wrap warning Dan Carpenter
  2019-03-25  9:29 ` David Hildenbrand
  2019-03-26  7:07 ` Dan Carpenter
@ 2019-03-26  8:10 ` David Hildenbrand
  2 siblings, 0 replies; 4+ messages in thread
From: David Hildenbrand @ 2019-03-26  8:10 UTC (permalink / raw)
  To: kernel-janitors

On 26.03.19 08:07, Dan Carpenter wrote:
> On Mon, Mar 25, 2019 at 10:29:40AM +0100, David Hildenbrand wrote:
>> On 25.03.19 10:04, Dan Carpenter wrote:
>>> 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.
>>>
>>> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>>> ---
>>>  arch/x86/kvm/vmx/nested.c | 2 +-
>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>
>>> diff --git a/arch/x86/kvm/vmx/nested.c b/arch/x86/kvm/vmx/nested.c
>>> index f24a2c225070..1f4398246bd9 100644
>>> --- a/arch/x86/kvm/vmx/nested.c
>>> +++ b/arch/x86/kvm/vmx/nested.c
>>> @@ -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.
> 
> 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!

> 
>>
>> Reviewed-by: David Hildenbrand <david@redhat.com>
>>
> 
> Thanks!
> 
> regards,
> dan carpenter
> 


-- 

Thanks,

David / dhildenb

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

end of thread, other threads:[~2019-03-26  8:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-25  9:04 [PATCH] kvm: vmx: Silence a shift wrap warning Dan Carpenter
2019-03-25  9:29 ` David Hildenbrand
2019-03-26  7:07 ` Dan Carpenter
2019-03-26  8:10 ` David Hildenbrand

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.