public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [kvm:queue 27/38] arch/x86/kvm/hyperv.c:186:41: sparse: incorrect type in argument 2 (different modifiers)
@ 2015-09-18 13:39 kbuild test robot
  2015-09-18 13:51 ` Denis V. Lunev
  0 siblings, 1 reply; 8+ messages in thread
From: kbuild test robot @ 2015-09-18 13:39 UTC (permalink / raw)
  To: Andrey Smetanin
  Cc: kbuild-all, Paolo Bonzini, Roman Kagan, Denis V. Lunev, kvm

tree:   https://git.kernel.org/pub/scm/virt/kvm/kvm.git queue
head:   ed393e4134de0dd02d8ba98ca8ce3ae65d1eb567
commit: 46f4c309534b10ca1026273abe38955d3cff4023 [27/38] kvm/x86: Hyper-V HV_X64_MSR_VP_RUNTIME support
reproduce:
  # apt-get install sparse
  git checkout 46f4c309534b10ca1026273abe38955d3cff4023
  make ARCH=x86_64 allmodconfig
  make C=1 CF=-D__CHECK_ENDIAN__


sparse warnings: (new ones prefixed by >>)

>> arch/x86/kvm/hyperv.c:186:41: sparse: incorrect type in argument 2 (different modifiers)
   arch/x86/kvm/hyperv.c:186:41:    expected unsigned long [nocast] [usertype] *ut
   arch/x86/kvm/hyperv.c:186:41:    got unsigned long *<noident>
>> arch/x86/kvm/hyperv.c:186:41: sparse: implicit cast to nocast type
>> arch/x86/kvm/hyperv.c:186:49: sparse: incorrect type in argument 3 (different modifiers)
   arch/x86/kvm/hyperv.c:186:49:    expected unsigned long [nocast] [usertype] *st
   arch/x86/kvm/hyperv.c:186:49:    got unsigned long *<noident>
   arch/x86/kvm/hyperv.c:186:49: sparse: implicit cast to nocast type

vim +186 arch/x86/kvm/hyperv.c

   170				kvm_make_request(KVM_REQ_HV_RESET, vcpu);
   171			}
   172			break;
   173		default:
   174			vcpu_unimpl(vcpu, "Hyper-V uhandled wrmsr: 0x%x data 0x%llx\n",
   175				    msr, data);
   176			return 1;
   177		}
   178		return 0;
   179	}
   180	
   181	/* Calculate cpu time spent by current task in 100ns units */
   182	static u64 current_task_runtime_100ns(void)
   183	{
   184		cputime_t utime, stime;
   185	
 > 186		task_cputime_adjusted(current, &utime, &stime);
   187		return div_u64(cputime_to_nsecs(utime + stime), 100);
   188	}
   189	
   190	static int kvm_hv_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data, bool host)
   191	{
   192		struct kvm_vcpu_hv *hv = &vcpu->arch.hyperv;
   193	
   194		switch (msr) {

---
0-DAY kernel test infrastructure                Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all                   Intel Corporation

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

* Re: [kvm:queue 27/38] arch/x86/kvm/hyperv.c:186:41: sparse: incorrect type in argument 2 (different modifiers)
  2015-09-18 13:39 [kvm:queue 27/38] arch/x86/kvm/hyperv.c:186:41: sparse: incorrect type in argument 2 (different modifiers) kbuild test robot
@ 2015-09-18 13:51 ` Denis V. Lunev
  2015-09-18 13:55   ` Paolo Bonzini
  0 siblings, 1 reply; 8+ messages in thread
From: Denis V. Lunev @ 2015-09-18 13:51 UTC (permalink / raw)
  To: kbuild test robot, Andrey Smetanin
  Cc: kbuild-all, Paolo Bonzini, Roman Kagan, kvm

On 09/18/2015 04:39 PM, kbuild test robot wrote:
> tree:   https://git.kernel.org/pub/scm/virt/kvm/kvm.git queue
> head:   ed393e4134de0dd02d8ba98ca8ce3ae65d1eb567
> commit: 46f4c309534b10ca1026273abe38955d3cff4023 [27/38] kvm/x86: Hyper-V HV_X64_MSR_VP_RUNTIME support
> reproduce:
>    # apt-get install sparse
>    git checkout 46f4c309534b10ca1026273abe38955d3cff4023
>    make ARCH=x86_64 allmodconfig
>    make C=1 CF=-D__CHECK_ENDIAN__
>
>
> sparse warnings: (new ones prefixed by >>)
>
>>> arch/x86/kvm/hyperv.c:186:41: sparse: incorrect type in argument 2 (different modifiers)
>     arch/x86/kvm/hyperv.c:186:41:    expected unsigned long [nocast] [usertype] *ut
>     arch/x86/kvm/hyperv.c:186:41:    got unsigned long *<noident>
>>> arch/x86/kvm/hyperv.c:186:41: sparse: implicit cast to nocast type
>>> arch/x86/kvm/hyperv.c:186:49: sparse: incorrect type in argument 3 (different modifiers)
>     arch/x86/kvm/hyperv.c:186:49:    expected unsigned long [nocast] [usertype] *st
>     arch/x86/kvm/hyperv.c:186:49:    got unsigned long *<noident>
>     arch/x86/kvm/hyperv.c:186:49: sparse: implicit cast to nocast type
>
> vim +186 arch/x86/kvm/hyperv.c
>
>     170				kvm_make_request(KVM_REQ_HV_RESET, vcpu);
>     171			}
>     172			break;
>     173		default:
>     174			vcpu_unimpl(vcpu, "Hyper-V uhandled wrmsr: 0x%x data 0x%llx\n",
>     175				    msr, data);
>     176			return 1;
>     177		}
>     178		return 0;
>     179	}
>     180	
>     181	/* Calculate cpu time spent by current task in 100ns units */
>     182	static u64 current_task_runtime_100ns(void)
>     183	{
>     184		cputime_t utime, stime;
>     185	
>   > 186		task_cputime_adjusted(current, &utime, &stime);
>     187		return div_u64(cputime_to_nsecs(utime + stime), 100);
>     188	}
>     189	
>     190	static int kvm_hv_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data, bool host)
>     191	{
>     192		struct kvm_vcpu_hv *hv = &vcpu->arch.hyperv;
>     193	
>     194		switch (msr) {
>
> ---
> 0-DAY kernel test infrastructure                Open Source Technology Center
> https://lists.01.org/pipermail/kbuild-all                   Intel Corporation
can not get an idea what is this warning about...
For me it looks pretty lame.

Den

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

* Re: [kvm:queue 27/38] arch/x86/kvm/hyperv.c:186:41: sparse: incorrect type in argument 2 (different modifiers)
  2015-09-18 13:51 ` Denis V. Lunev
@ 2015-09-18 13:55   ` Paolo Bonzini
  2015-09-18 13:57     ` Denis V. Lunev
  2015-09-18 14:40     ` Roman Kagan
  0 siblings, 2 replies; 8+ messages in thread
From: Paolo Bonzini @ 2015-09-18 13:55 UTC (permalink / raw)
  To: Denis V. Lunev, kbuild test robot, Andrey Smetanin
  Cc: kbuild-all, Roman Kagan, kvm



On 18/09/2015 15:51, Denis V. Lunev wrote:
>>     185   
>>   > 186        task_cputime_adjusted(current, &utime, &stime);
>>     187        return div_u64(cputime_to_nsecs(utime + stime), 100);
>>     188    }
>>     189   
>>     190    static int kvm_hv_set_msr(struct kvm_vcpu *vcpu, u32 msr,
>> u64 data, bool host)
>>     191    {
>>     192        struct kvm_vcpu_hv *hv = &vcpu->arch.hyperv;
>>     193   
>>     194        switch (msr) {
>>
>> ---
>> 0-DAY kernel test infrastructure                Open Source Technology
>> Center
>> https://lists.01.org/pipermail/kbuild-all                   Intel
>> Corporation
> can not get an idea what is this warning about...
> For me it looks pretty lame.

I think it wants you to do

-	return div_u64(cputime_to_nsecs(utime + stime), 100);
+	return div_u64(cputime_to_nsecs(utime) +
+		       cputime_to_nsecs(stime), 100);

Paolo

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

* Re: [kvm:queue 27/38] arch/x86/kvm/hyperv.c:186:41: sparse: incorrect type in argument 2 (different modifiers)
  2015-09-18 13:55   ` Paolo Bonzini
@ 2015-09-18 13:57     ` Denis V. Lunev
  2015-09-18 14:40     ` Roman Kagan
  1 sibling, 0 replies; 8+ messages in thread
From: Denis V. Lunev @ 2015-09-18 13:57 UTC (permalink / raw)
  To: Paolo Bonzini, kbuild test robot, Andrey Smetanin
  Cc: kbuild-all, Roman Kagan, kvm

On 09/18/2015 04:55 PM, Paolo Bonzini wrote:
>
> On 18/09/2015 15:51, Denis V. Lunev wrote:
>>>      185
>>>    > 186        task_cputime_adjusted(current, &utime, &stime);
>>>      187        return div_u64(cputime_to_nsecs(utime + stime), 100);
>>>      188    }
>>>      189
>>>      190    static int kvm_hv_set_msr(struct kvm_vcpu *vcpu, u32 msr,
>>> u64 data, bool host)
>>>      191    {
>>>      192        struct kvm_vcpu_hv *hv = &vcpu->arch.hyperv;
>>>      193
>>>      194        switch (msr) {
>>>
>>> ---
>>> 0-DAY kernel test infrastructure                Open Source Technology
>>> Center
>>> https://lists.01.org/pipermail/kbuild-all                   Intel
>>> Corporation
>> can not get an idea what is this warning about...
>> For me it looks pretty lame.
> I think it wants you to do
>
> -	return div_u64(cputime_to_nsecs(utime + stime), 100);
> +	return div_u64(cputime_to_nsecs(utime) +
> +		       cputime_to_nsecs(stime), 100);
>
> Paolo
ok, I'll check but warning points here

   > 186        task_cputime_adjusted(current, &utime, &stime);

and says about parameters 2 and 3. There is no parameter 3
in div_u64 call :)


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

* Re: [kvm:queue 27/38] arch/x86/kvm/hyperv.c:186:41: sparse: incorrect type in argument 2 (different modifiers)
  2015-09-18 13:55   ` Paolo Bonzini
  2015-09-18 13:57     ` Denis V. Lunev
@ 2015-09-18 14:40     ` Roman Kagan
  2015-09-18 14:41       ` Paolo Bonzini
  1 sibling, 1 reply; 8+ messages in thread
From: Roman Kagan @ 2015-09-18 14:40 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Denis V. Lunev, kbuild test robot, Andrey Smetanin, kbuild-all,
	kvm

On Fri, Sep 18, 2015 at 03:55:00PM +0200, Paolo Bonzini wrote:
> 
> 
> On 18/09/2015 15:51, Denis V. Lunev wrote:
> >>     185   
> >>   > 186        task_cputime_adjusted(current, &utime, &stime);
> >>     187        return div_u64(cputime_to_nsecs(utime + stime), 100);
> >>     188    }
> >>     189   
> >>     190    static int kvm_hv_set_msr(struct kvm_vcpu *vcpu, u32 msr,
> >> u64 data, bool host)
> >>     191    {
> >>     192        struct kvm_vcpu_hv *hv = &vcpu->arch.hyperv;
> >>     193   
> >>     194        switch (msr) {
> >>
> >> ---
> >> 0-DAY kernel test infrastructure                Open Source Technology
> >> Center
> >> https://lists.01.org/pipermail/kbuild-all                   Intel
> >> Corporation
> > can not get an idea what is this warning about...
> > For me it looks pretty lame.
> 
> I think it wants you to do
> 
> -	return div_u64(cputime_to_nsecs(utime + stime), 100);
> +	return div_u64(cputime_to_nsecs(utime) +
> +		       cputime_to_nsecs(stime), 100);

The warning is pretty specific about the point where it triggered.

I have reduced it to the following standalone reproducer:

%%% cat x.c
#ifdef __CHECKER__
# define __nocast       __attribute__((nocast))
#else
# define __nocast
#endif

typedef unsigned long __nocast cputime_t;

extern void task_cputime_adjusted(cputime_t *);
extern void current_task_runtime_100ns(void);

void current_task_runtime_100ns(void)
{
        cputime_t utime;

        task_cputime_adjusted(&utime);
}
%%% gcc -c x.c -Wall -Werror -O2; echo $?
0
%%% sparse x.c
x.c:16:32: warning: incorrect type in argument 1 (different modifiers)
x.c:16:32:    expected unsigned long [nocast] [usertype] *<noident>
x.c:16:32:    got unsigned long *<noident>
x.c:16:32: warning: implicit cast to nocast type

Looks like a sparse bug to me.

Roman.

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

* Re: [kvm:queue 27/38] arch/x86/kvm/hyperv.c:186:41: sparse: incorrect type in argument 2 (different modifiers)
  2015-09-18 14:40     ` Roman Kagan
@ 2015-09-18 14:41       ` Paolo Bonzini
  2015-09-18 15:06         ` [kbuild-all] " Fengguang Wu
  0 siblings, 1 reply; 8+ messages in thread
From: Paolo Bonzini @ 2015-09-18 14:41 UTC (permalink / raw)
  To: Roman Kagan, Denis V. Lunev, kbuild test robot, Andrey Smetanin,
	kbuild-all, kvm



On 18/09/2015 16:40, Roman Kagan wrote:
> typedef unsigned long __nocast cputime_t;
> 
> extern void task_cputime_adjusted(cputime_t *);
> extern void current_task_runtime_100ns(void);
> 
> void current_task_runtime_100ns(void)
> {
>         cputime_t utime;
> 
>         task_cputime_adjusted(&utime);
> }
> %%% gcc -c x.c -Wall -Werror -O2; echo $?
> 0
> %%% sparse x.c
> x.c:16:32: warning: incorrect type in argument 1 (different modifiers)
> x.c:16:32:    expected unsigned long [nocast] [usertype] *<noident>
> x.c:16:32:    got unsigned long *<noident>
> x.c:16:32: warning: implicit cast to nocast type
> 
> Looks like a sparse bug to me.

Indeed...

Paolo

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

* Re: [kbuild-all] [kvm:queue 27/38] arch/x86/kvm/hyperv.c:186:41: sparse: incorrect type in argument 2 (different modifiers)
  2015-09-18 14:41       ` Paolo Bonzini
@ 2015-09-18 15:06         ` Fengguang Wu
  2016-01-05 13:51           ` Luc Van Oostenryck
  0 siblings, 1 reply; 8+ messages in thread
From: Fengguang Wu @ 2015-09-18 15:06 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Roman Kagan, Denis V. Lunev, Andrey Smetanin, kbuild-all, kvm,
	Christopher Li, Linux-Sparse

[CC sparse people]

On Fri, Sep 18, 2015 at 04:41:56PM +0200, Paolo Bonzini wrote:
> 
> 
> On 18/09/2015 16:40, Roman Kagan wrote:
> > typedef unsigned long __nocast cputime_t;
> > 
> > extern void task_cputime_adjusted(cputime_t *);
> > extern void current_task_runtime_100ns(void);
> > 
> > void current_task_runtime_100ns(void)
> > {
> >         cputime_t utime;
> > 
> >         task_cputime_adjusted(&utime);
> > }
> > %%% gcc -c x.c -Wall -Werror -O2; echo $?
> > 0
> > %%% sparse x.c
> > x.c:16:32: warning: incorrect type in argument 1 (different modifiers)
> > x.c:16:32:    expected unsigned long [nocast] [usertype] *<noident>
> > x.c:16:32:    got unsigned long *<noident>
> > x.c:16:32: warning: implicit cast to nocast type
> > 
> > Looks like a sparse bug to me.
> 
> Indeed...
> 
> Paolo
> _______________________________________________
> kbuild-all mailing list
> kbuild-all@lists.01.org
> https://lists.01.org/mailman/listinfo/kbuild-all

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

* Re: [kbuild-all] [kvm:queue 27/38] arch/x86/kvm/hyperv.c:186:41: sparse: incorrect type in argument 2 (different modifiers)
  2015-09-18 15:06         ` [kbuild-all] " Fengguang Wu
@ 2016-01-05 13:51           ` Luc Van Oostenryck
  0 siblings, 0 replies; 8+ messages in thread
From: Luc Van Oostenryck @ 2016-01-05 13:51 UTC (permalink / raw)
  To: Fengguang Wu
  Cc: Paolo Bonzini, Roman Kagan, Denis V. Lunev, Andrey Smetanin,
	kbuild-all, kvm, Christopher Li, Linux-Sparse

On Fri, Sep 18, 2015 at 11:06:44PM +0800, Fengguang Wu wrote:
> [CC sparse people]
> 
> On Fri, Sep 18, 2015 at 04:41:56PM +0200, Paolo Bonzini wrote:
> > 
> > 
> > On 18/09/2015 16:40, Roman Kagan wrote:
> > > typedef unsigned long __nocast cputime_t;
> > > 
> > > extern void task_cputime_adjusted(cputime_t *);
> > > extern void current_task_runtime_100ns(void);
> > > 
> > > void current_task_runtime_100ns(void)
> > > {
> > >         cputime_t utime;
> > > 
> > >         task_cputime_adjusted(&utime);
> > > }
> > > %%% gcc -c x.c -Wall -Werror -O2; echo $?
> > > 0
> > > %%% sparse x.c
> > > x.c:16:32: warning: incorrect type in argument 1 (different modifiers)
> > > x.c:16:32:    expected unsigned long [nocast] [usertype] *<noident>
> > > x.c:16:32:    got unsigned long *<noident>
> > > x.c:16:32: warning: implicit cast to nocast type
> > > 
> > > Looks like a sparse bug to me.
> > 
> > Indeed...
> > 
> > Paolo

The problem is that the intent and semantic of 'nocast' is not clear at all.
There is an explanation about 'nocast' vs. 'bitwise' here:
	https://git.kernel.org/cgit/devel/sparse/sparse.git/tree/Documentation/sparse.txt
but it doesn't give much info about the exact wanted behaviour.

Since for the kernel 'nocast' is only used for cputime_t & cputime64_t,
I think it should be clarified and fixed if needed.
A patch proposal is following.

Regards,
Luc

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

end of thread, other threads:[~2016-01-05 13:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-18 13:39 [kvm:queue 27/38] arch/x86/kvm/hyperv.c:186:41: sparse: incorrect type in argument 2 (different modifiers) kbuild test robot
2015-09-18 13:51 ` Denis V. Lunev
2015-09-18 13:55   ` Paolo Bonzini
2015-09-18 13:57     ` Denis V. Lunev
2015-09-18 14:40     ` Roman Kagan
2015-09-18 14:41       ` Paolo Bonzini
2015-09-18 15:06         ` [kbuild-all] " Fengguang Wu
2016-01-05 13:51           ` Luc Van Oostenryck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox