netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rds: ib: force endiannes annotation
@ 2019-04-29  6:09 Nicholas Mc Guire
  2019-04-29 11:00 ` Edward Cree
  0 siblings, 1 reply; 7+ messages in thread
From: Nicholas Mc Guire @ 2019-04-29  6:09 UTC (permalink / raw)
  To: Santosh Shilimkar
  Cc: David S. Miller, netdev, linux-rdma, rds-devel, linux-kernel,
	Nicholas Mc Guire

While the endiannes is being handled correctly as indicated by the comment
above the offending line - sparse was unhappy with the missing annotation
as be64_to_cpu() expects a __be64 argument. To mitigate this annotation
issue forced annotation is introduced. Note that this patch has no impact
on the generated binary.

Signed-off-by: Nicholas Mc Guire <hofrat@osadl.org>
---

Problem located by an experimental coccinelle script to locate
patters that make sparse unhappy (false positives):
net/rds/ib_recv.c:827:23: warning: cast to restricted __le64

Patch was compile-tested with: x86_64_defconfig + RDS_RDMA=m

Patch was verified not to change the binary by diffing the
generated object code before and after applying the patch.

Patch is against 5.1-rc6 (localversion-next is 20190426)

 net/rds/ib_recv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
index 7055985..a070a2d 100644
--- a/net/rds/ib_recv.c
+++ b/net/rds/ib_recv.c
@@ -824,7 +824,7 @@ static void rds_ib_cong_recv(struct rds_connection *conn,
 	}
 
 	/* the congestion map is in little endian order */
-	uncongested = le64_to_cpu(uncongested);
+	uncongested = le64_to_cpu((__force __le64)uncongested);
 
 	rds_cong_map_updated(map, uncongested);
 }
-- 
2.1.4


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

* Re: [PATCH] rds: ib: force endiannes annotation
  2019-04-29  6:09 [PATCH] rds: ib: force endiannes annotation Nicholas Mc Guire
@ 2019-04-29 11:00 ` Edward Cree
  2019-04-29 11:18   ` Nicholas Mc Guire
  0 siblings, 1 reply; 7+ messages in thread
From: Edward Cree @ 2019-04-29 11:00 UTC (permalink / raw)
  To: Nicholas Mc Guire, Santosh Shilimkar
  Cc: David S. Miller, netdev, linux-rdma, rds-devel, linux-kernel

On 29/04/2019 07:09, Nicholas Mc Guire wrote:
> diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
> index 7055985..a070a2d 100644
> --- a/net/rds/ib_recv.c
> +++ b/net/rds/ib_recv.c
> @@ -824,7 +824,7 @@ static void rds_ib_cong_recv(struct rds_connection *conn,
>  	}
>  
>  	/* the congestion map is in little endian order */
> -	uncongested = le64_to_cpu(uncongested);
> +	uncongested = le64_to_cpu((__force __le64)uncongested);
>  
>  	rds_cong_map_updated(map, uncongested);
>  }
Again, a __force cast doesn't seem necessary here.  It looks like the
 code is just using the wrong types; if all of src, dst and uncongested
 were __le64 instead of uint64_t, and the last two lines replaced with
 rds_cong_map_updated(map, le64_to_cpu(uncongested)); then the semantics
 would be kept with neither sparse errors nor __force.

__force is almost never necessary and mostly just masks other bugs or
 endianness confusion in the surrounding code.  Instead of adding a
 __force, either fix the code to be sparse-clean or leave the sparse
 warning in place so that future developers know there's something not
 right.

-Ed

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

* Re: [PATCH] rds: ib: force endiannes annotation
  2019-04-29 11:00 ` Edward Cree
@ 2019-04-29 11:18   ` Nicholas Mc Guire
  2019-04-29 12:02     ` Edward Cree
  2019-04-29 12:21     ` Christoph Hellwig
  0 siblings, 2 replies; 7+ messages in thread
From: Nicholas Mc Guire @ 2019-04-29 11:18 UTC (permalink / raw)
  To: Edward Cree
  Cc: Nicholas Mc Guire, Santosh Shilimkar, David S. Miller, netdev,
	linux-rdma, rds-devel, linux-kernel

On Mon, Apr 29, 2019 at 12:00:06PM +0100, Edward Cree wrote:
> On 29/04/2019 07:09, Nicholas Mc Guire wrote:
> > diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
> > index 7055985..a070a2d 100644
> > --- a/net/rds/ib_recv.c
> > +++ b/net/rds/ib_recv.c
> > @@ -824,7 +824,7 @@ static void rds_ib_cong_recv(struct rds_connection *conn,
> >  	}
> >  
> >  	/* the congestion map is in little endian order */
> > -	uncongested = le64_to_cpu(uncongested);
> > +	uncongested = le64_to_cpu((__force __le64)uncongested);
> >  
> >  	rds_cong_map_updated(map, uncongested);
> >  }
> Again, a __force cast doesn't seem necessary here.  It looks like the
>  code is just using the wrong types; if all of src, dst and uncongested
>  were __le64 instead of uint64_t, and the last two lines replaced with
>  rds_cong_map_updated(map, le64_to_cpu(uncongested)); then the semantics
>  would be kept with neither sparse errors nor __force.
> 
> __force is almost never necessary and mostly just masks other bugs or
>  endianness confusion in the surrounding code.  Instead of adding a
>  __force, either fix the code to be sparse-clean or leave the sparse
>  warning in place so that future developers know there's something not
>  right.
>
changing uncongested to __le64 is not an option here - it would only move
the sparse warnings to those other locatoins where the ports that 
became uncongested are being or'ed into uncongested.

I'm not using __force as the prime way to silence sparse - I try to find
an alternative first - the problem is in line 805
                for (k = 0; k < to_copy; k += 8) {
                        /* Record ports that became uncongested, ie
                         * bits that changed from 0 to 1. */
                        uncongested |= ~(*src) & *dst;
                        *dst++ = *src++;
                }
And in this case the endianness handling does seem right.

But ok with me to leave it in as it is - if you think that the __force
here is not justified.

thanks for your comments and notably the explainations !

thx!
hofrat
alternative 
 

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

* Re: [PATCH] rds: ib: force endiannes annotation
  2019-04-29 11:18   ` Nicholas Mc Guire
@ 2019-04-29 12:02     ` Edward Cree
  2019-04-29 12:22       ` Christoph Hellwig
  2019-04-29 12:21     ` Christoph Hellwig
  1 sibling, 1 reply; 7+ messages in thread
From: Edward Cree @ 2019-04-29 12:02 UTC (permalink / raw)
  To: Nicholas Mc Guire
  Cc: Nicholas Mc Guire, Santosh Shilimkar, David S. Miller, netdev,
	linux-rdma, rds-devel, linux-kernel

On 29/04/2019 12:18, Nicholas Mc Guire wrote:
> On Mon, Apr 29, 2019 at 12:00:06PM +0100, Edward Cree wrote:
>> Again, a __force cast doesn't seem necessary here.  It looks like the
>>  code is just using the wrong types; if all of src, dst and uncongested
>>  were __le64 instead of uint64_t, and the last two lines replaced with
>>  rds_cong_map_updated(map, le64_to_cpu(uncongested)); then the semantics
>>  would be kept with neither sparse errors nor __force.
>>
>> __force is almost never necessary and mostly just masks other bugs or
>>  endianness confusion in the surrounding code.  Instead of adding a
>>  __force, either fix the code to be sparse-clean or leave the sparse
>>  warning in place so that future developers know there's something not
>>  right.
>>
> changing uncongested to __le64 is not an option here - it would only move
> the sparse warnings to those other locatoins where the ports that 
> became uncongested are being or'ed into uncongested.
That's why I say to change *src and *dst too.  Sparse won't mind the
 conversion from void * to __le64 * when they're assigned, and the only
 operations we do on them...
>                         uncongested |= ~(*src) & *dst;
>                         *dst++ = *src++;
... are some bitwise ops on the values (bitwise ops are legal in any
 endianness) and incrementation of the pointers (which cares only about
 the pointee size, not type).

-Ed

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

* Re: [PATCH] rds: ib: force endiannes annotation
  2019-04-29 11:18   ` Nicholas Mc Guire
  2019-04-29 12:02     ` Edward Cree
@ 2019-04-29 12:21     ` Christoph Hellwig
  2019-04-29 12:37       ` Nicholas Mc Guire
  1 sibling, 1 reply; 7+ messages in thread
From: Christoph Hellwig @ 2019-04-29 12:21 UTC (permalink / raw)
  To: Nicholas Mc Guire
  Cc: Edward Cree, Nicholas Mc Guire, Santosh Shilimkar,
	David S. Miller, netdev, linux-rdma, rds-devel, linux-kernel

On Mon, Apr 29, 2019 at 01:18:36PM +0200, Nicholas Mc Guire wrote:
> changing uncongested to __le64 is not an option here - it would only move
> the sparse warnings to those other locatoins where the ports that 
> became uncongested are being or'ed into uncongested.

Than fix that a well.  Either by throwing in a conversion, or
add {be,le}XX_{and,or} helpers.

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

* Re: [PATCH] rds: ib: force endiannes annotation
  2019-04-29 12:02     ` Edward Cree
@ 2019-04-29 12:22       ` Christoph Hellwig
  0 siblings, 0 replies; 7+ messages in thread
From: Christoph Hellwig @ 2019-04-29 12:22 UTC (permalink / raw)
  To: Edward Cree
  Cc: Nicholas Mc Guire, Nicholas Mc Guire, Santosh Shilimkar,
	David S. Miller, netdev, linux-rdma, rds-devel, linux-kernel

On Mon, Apr 29, 2019 at 01:02:31PM +0100, Edward Cree wrote:
> ... are some bitwise ops on the values (bitwise ops are legal in any
>  endianness) and incrementation of the pointers (which cares only about
>  the pointee size, not type).

Oh, true.  That is why the underlying annotation is called __bitwise :)
I'll take my previous comment back.

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

* Re: [PATCH] rds: ib: force endiannes annotation
  2019-04-29 12:21     ` Christoph Hellwig
@ 2019-04-29 12:37       ` Nicholas Mc Guire
  0 siblings, 0 replies; 7+ messages in thread
From: Nicholas Mc Guire @ 2019-04-29 12:37 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Edward Cree, Nicholas Mc Guire, Santosh Shilimkar,
	David S. Miller, netdev, linux-rdma, rds-devel, linux-kernel

On Mon, Apr 29, 2019 at 05:21:32AM -0700, Christoph Hellwig wrote:
> On Mon, Apr 29, 2019 at 01:18:36PM +0200, Nicholas Mc Guire wrote:
> > changing uncongested to __le64 is not an option here - it would only move
> > the sparse warnings to those other locatoins where the ports that 
> > became uncongested are being or'ed into uncongested.
> 
> Than fix that a well.  Either by throwing in a conversion, or
> add {be,le}XX_{and,or} helpers.

ok - that is an option in that case - will try that route

thx!
hofrat

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

end of thread, other threads:[~2019-04-29 12:38 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-29  6:09 [PATCH] rds: ib: force endiannes annotation Nicholas Mc Guire
2019-04-29 11:00 ` Edward Cree
2019-04-29 11:18   ` Nicholas Mc Guire
2019-04-29 12:02     ` Edward Cree
2019-04-29 12:22       ` Christoph Hellwig
2019-04-29 12:21     ` Christoph Hellwig
2019-04-29 12:37       ` Nicholas Mc Guire

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).