linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next v1] net: Use csum_replace_... and csum_sub() helpers instead of opencoding
@ 2022-02-17 15:43 Christophe Leroy
  2022-02-17 17:24 ` Jakub Kicinski
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Christophe Leroy @ 2022-02-17 15:43 UTC (permalink / raw)
  To: David S. Miller, Jakub Kicinski, Pablo Neira Ayuso,
	Jozsef Kadlecsik, Florian Westphal
  Cc: Christophe Leroy, linux-kernel, netdev, netfilter-devel, coreteam

In a couple places, open coded calculation can be avoided
and replaced by the equivalent csum_replace4() and
csum_replace_by_diff().

There's also one place where csum_sub() should be used instead of
csum_add().

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
---
 net/core/utils.c            | 4 ++--
 net/netfilter/nft_payload.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/net/core/utils.c b/net/core/utils.c
index 1f31a39236d5..938495bc1d34 100644
--- a/net/core/utils.c
+++ b/net/core/utils.c
@@ -476,9 +476,9 @@ void inet_proto_csum_replace_by_diff(__sum16 *sum, struct sk_buff *skb,
 				     __wsum diff, bool pseudohdr)
 {
 	if (skb->ip_summed != CHECKSUM_PARTIAL) {
-		*sum = csum_fold(csum_add(diff, ~csum_unfold(*sum)));
+		csum_replace_by_diff(sum, diff);
 		if (skb->ip_summed == CHECKSUM_COMPLETE && pseudohdr)
-			skb->csum = ~csum_add(diff, ~skb->csum);
+			skb->csum = ~csum_sub(diff, skb->csum);
 	} else if (pseudohdr) {
 		*sum = ~csum_fold(csum_add(diff, csum_unfold(*sum)));
 	}
diff --git a/net/netfilter/nft_payload.c b/net/netfilter/nft_payload.c
index 5cc06aef4345..b6cfd0759bc5 100644
--- a/net/netfilter/nft_payload.c
+++ b/net/netfilter/nft_payload.c
@@ -557,7 +557,7 @@ const struct nft_expr_ops nft_payload_fast_ops = {
 
 static inline void nft_csum_replace(__sum16 *sum, __wsum fsum, __wsum tsum)
 {
-	*sum = csum_fold(csum_add(csum_sub(~csum_unfold(*sum), fsum), tsum));
+	csum_replace4(sum, fsum, tsum);
 	if (*sum == 0)
 		*sum = CSUM_MANGLED_0;
 }
-- 
2.34.1


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

* Re: [PATCH net-next v1] net: Use csum_replace_... and csum_sub() helpers instead of opencoding
  2022-02-17 15:43 [PATCH net-next v1] net: Use csum_replace_... and csum_sub() helpers instead of opencoding Christophe Leroy
@ 2022-02-17 17:24 ` Jakub Kicinski
  2022-02-17 18:11   ` Christophe Leroy
  2022-02-18  7:43 ` kernel test robot
  2022-04-22 11:48 ` kernel test robot
  2 siblings, 1 reply; 8+ messages in thread
From: Jakub Kicinski @ 2022-02-17 17:24 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: David S. Miller, Pablo Neira Ayuso, Jozsef Kadlecsik,
	Florian Westphal, linux-kernel, netdev, netfilter-devel,
	coreteam

On Thu, 17 Feb 2022 16:43:55 +0100 Christophe Leroy wrote:
>  static inline void nft_csum_replace(__sum16 *sum, __wsum fsum, __wsum tsum)
>  {
> -	*sum = csum_fold(csum_add(csum_sub(~csum_unfold(*sum), fsum), tsum));
> +	csum_replace4(sum, fsum, tsum);

Sparse says:

net/netfilter/nft_payload.c:560:28: warning: incorrect type in argument 2 (different base types)
net/netfilter/nft_payload.c:560:28:    expected restricted __be32 [usertype] from
net/netfilter/nft_payload.c:560:28:    got restricted __wsum [usertype] fsum

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

* Re: [PATCH net-next v1] net: Use csum_replace_... and csum_sub() helpers instead of opencoding
  2022-02-17 17:24 ` Jakub Kicinski
@ 2022-02-17 18:11   ` Christophe Leroy
  2022-02-17 18:14     ` Jakub Kicinski
  0 siblings, 1 reply; 8+ messages in thread
From: Christophe Leroy @ 2022-02-17 18:11 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: David S. Miller, Pablo Neira Ayuso, Jozsef Kadlecsik,
	Florian Westphal, linux-kernel, netdev, netfilter-devel,
	coreteam



Le 17/02/2022 à 18:24, Jakub Kicinski a écrit :
> On Thu, 17 Feb 2022 16:43:55 +0100 Christophe Leroy wrote:
>>   static inline void nft_csum_replace(__sum16 *sum, __wsum fsum, __wsum tsum)
>>   {
>> -	*sum = csum_fold(csum_add(csum_sub(~csum_unfold(*sum), fsum), tsum));
>> +	csum_replace4(sum, fsum, tsum);
> 
> Sparse says:
> 
> net/netfilter/nft_payload.c:560:28: warning: incorrect type in argument 2 (different base types)
> net/netfilter/nft_payload.c:560:28:    expected restricted __be32 [usertype] from
> net/netfilter/nft_payload.c:560:28:    got restricted __wsum [usertype] fsum

Yes I saw it in patchwork, thanks.

Looks like csum_replace4() expects __be32 inputs, I'll look at it but 
I'm not inclined at adding force cast, so will probably leave 
nft_csum_replace() as is.

Thanks
Christophe

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

* Re: [PATCH net-next v1] net: Use csum_replace_... and csum_sub() helpers instead of opencoding
  2022-02-17 18:11   ` Christophe Leroy
@ 2022-02-17 18:14     ` Jakub Kicinski
  2022-02-17 18:39       ` Christophe Leroy
  0 siblings, 1 reply; 8+ messages in thread
From: Jakub Kicinski @ 2022-02-17 18:14 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: David S. Miller, Pablo Neira Ayuso, Jozsef Kadlecsik,
	Florian Westphal, linux-kernel, netdev, netfilter-devel,
	coreteam

On Thu, 17 Feb 2022 18:11:58 +0000 Christophe Leroy wrote:
> Looks like csum_replace4() expects __be32 inputs, I'll look at it but 
> I'm not inclined at adding force cast, so will probably leave 
> nft_csum_replace() as is.

That may imply also leaving it in your tree..

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

* Re: [PATCH net-next v1] net: Use csum_replace_... and csum_sub() helpers instead of opencoding
  2022-02-17 18:14     ` Jakub Kicinski
@ 2022-02-17 18:39       ` Christophe Leroy
  2022-02-17 18:54         ` Jakub Kicinski
  0 siblings, 1 reply; 8+ messages in thread
From: Christophe Leroy @ 2022-02-17 18:39 UTC (permalink / raw)
  To: Jakub Kicinski
  Cc: David S. Miller, Pablo Neira Ayuso, Jozsef Kadlecsik,
	Florian Westphal, linux-kernel, netdev, netfilter-devel,
	coreteam



Le 17/02/2022 à 19:14, Jakub Kicinski a écrit :
> On Thu, 17 Feb 2022 18:11:58 +0000 Christophe Leroy wrote:
>> Looks like csum_replace4() expects __be32 inputs, I'll look at it but
>> I'm not inclined at adding force cast, so will probably leave
>> nft_csum_replace() as is.
> 
> That may imply also leaving it in your tree..

By "leave as is" I meant I'll drop the change.

I'll send v2 without this hunk.

Christophe

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

* Re: [PATCH net-next v1] net: Use csum_replace_... and csum_sub() helpers instead of opencoding
  2022-02-17 18:39       ` Christophe Leroy
@ 2022-02-17 18:54         ` Jakub Kicinski
  0 siblings, 0 replies; 8+ messages in thread
From: Jakub Kicinski @ 2022-02-17 18:54 UTC (permalink / raw)
  To: Christophe Leroy
  Cc: David S. Miller, Pablo Neira Ayuso, Jozsef Kadlecsik,
	Florian Westphal, linux-kernel, netdev, netfilter-devel,
	coreteam

On Thu, 17 Feb 2022 18:39:07 +0000 Christophe Leroy wrote:
> Le 17/02/2022 à 19:14, Jakub Kicinski a écrit :
> > On Thu, 17 Feb 2022 18:11:58 +0000 Christophe Leroy wrote:  
> >> Looks like csum_replace4() expects __be32 inputs, I'll look at it but
> >> I'm not inclined at adding force cast, so will probably leave
> >> nft_csum_replace() as is.  
> > 
> > That may imply also leaving it in your tree..  
> 
> By "leave as is" I meant I'll drop the change.
> 
> I'll send v2 without this hunk.

Thanks, sorry for the snarky comment, I read it as "take it or leave
it". I've heard too many of those lately.

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

* Re: [PATCH net-next v1] net: Use csum_replace_... and csum_sub() helpers instead of opencoding
  2022-02-17 15:43 [PATCH net-next v1] net: Use csum_replace_... and csum_sub() helpers instead of opencoding Christophe Leroy
  2022-02-17 17:24 ` Jakub Kicinski
@ 2022-02-18  7:43 ` kernel test robot
  2022-04-22 11:48 ` kernel test robot
  2 siblings, 0 replies; 8+ messages in thread
From: kernel test robot @ 2022-02-18  7:43 UTC (permalink / raw)
  To: Christophe Leroy, David S. Miller, Jakub Kicinski,
	Pablo Neira Ayuso, Jozsef Kadlecsik, Florian Westphal
  Cc: kbuild-all, netdev, Christophe Leroy, linux-kernel,
	netfilter-devel, coreteam

Hi Christophe,

I love your patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]

url:    https://github.com/0day-ci/linux/commits/Christophe-Leroy/net-Use-csum_replace_-and-csum_sub-helpers-instead-of-opencoding/20220217-234555
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git c8b441d2fbd0e005541c7363fd5346971b6febcb
config: x86_64-rhel-8.3-kselftests (https://download.01.org/0day-ci/archive/20220218/202202181535.l3nA3dto-lkp@intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.4-dirty
        # https://github.com/0day-ci/linux/commit/cec9ed7cf59fe6dafcec0a30811024d22fad8cbd
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Christophe-Leroy/net-Use-csum_replace_-and-csum_sub-helpers-instead-of-opencoding/20220217-234555
        git checkout cec9ed7cf59fe6dafcec0a30811024d22fad8cbd
        # save the config file to linux build tree
        mkdir build_dir
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


sparse warnings: (new ones prefixed by >>)
   net/netfilter/nft_payload.c: note: in included file (through include/net/sctp/sctp.h, include/net/sctp/checksum.h):
   include/net/sctp/structs.h:335:41: sparse: sparse: array of flexible structures
>> net/netfilter/nft_payload.c:560:28: sparse: sparse: incorrect type in argument 2 (different base types) @@     expected restricted __be32 [usertype] from @@     got restricted __wsum [usertype] fsum @@
   net/netfilter/nft_payload.c:560:28: sparse:     expected restricted __be32 [usertype] from
   net/netfilter/nft_payload.c:560:28: sparse:     got restricted __wsum [usertype] fsum
>> net/netfilter/nft_payload.c:560:34: sparse: sparse: incorrect type in argument 3 (different base types) @@     expected restricted __be32 [usertype] to @@     got restricted __wsum [usertype] tsum @@
   net/netfilter/nft_payload.c:560:34: sparse:     expected restricted __be32 [usertype] to
   net/netfilter/nft_payload.c:560:34: sparse:     got restricted __wsum [usertype] tsum
>> net/netfilter/nft_payload.c:560:28: sparse: sparse: incorrect type in argument 2 (different base types) @@     expected restricted __be32 [usertype] from @@     got restricted __wsum [usertype] fsum @@
   net/netfilter/nft_payload.c:560:28: sparse:     expected restricted __be32 [usertype] from
   net/netfilter/nft_payload.c:560:28: sparse:     got restricted __wsum [usertype] fsum
>> net/netfilter/nft_payload.c:560:34: sparse: sparse: incorrect type in argument 3 (different base types) @@     expected restricted __be32 [usertype] to @@     got restricted __wsum [usertype] tsum @@
   net/netfilter/nft_payload.c:560:34: sparse:     expected restricted __be32 [usertype] to
   net/netfilter/nft_payload.c:560:34: sparse:     got restricted __wsum [usertype] tsum

vim +560 net/netfilter/nft_payload.c

   557	
   558	static inline void nft_csum_replace(__sum16 *sum, __wsum fsum, __wsum tsum)
   559	{
 > 560		csum_replace4(sum, fsum, tsum);
   561		if (*sum == 0)
   562			*sum = CSUM_MANGLED_0;
   563	}
   564	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

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

* Re: [PATCH net-next v1] net: Use csum_replace_... and csum_sub() helpers instead of opencoding
  2022-02-17 15:43 [PATCH net-next v1] net: Use csum_replace_... and csum_sub() helpers instead of opencoding Christophe Leroy
  2022-02-17 17:24 ` Jakub Kicinski
  2022-02-18  7:43 ` kernel test robot
@ 2022-04-22 11:48 ` kernel test robot
  2 siblings, 0 replies; 8+ messages in thread
From: kernel test robot @ 2022-04-22 11:48 UTC (permalink / raw)
  To: Christophe Leroy, David S. Miller, Jakub Kicinski,
	Pablo Neira Ayuso, Jozsef Kadlecsik, Florian Westphal
  Cc: kbuild-all, netdev, Christophe Leroy, linux-kernel,
	netfilter-devel, coreteam

Hi Christophe,

I love your patch! Perhaps something to improve:

[auto build test WARNING on net-next/master]

url:    https://github.com/intel-lab-lkp/linux/commits/Christophe-Leroy/net-Use-csum_replace_-and-csum_sub-helpers-instead-of-opencoding/20220217-234555
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git c8b441d2fbd0e005541c7363fd5346971b6febcb
config: x86_64-rhel-8.3-kselftests (https://download.01.org/0day-ci/archive/20220422/202204221937.SbSpkzXW-lkp@intel.com/config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.4-dirty
        # https://github.com/intel-lab-lkp/linux/commit/cec9ed7cf59fe6dafcec0a30811024d22fad8cbd
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Christophe-Leroy/net-Use-csum_replace_-and-csum_sub-helpers-instead-of-opencoding/20220217-234555
        git checkout cec9ed7cf59fe6dafcec0a30811024d22fad8cbd
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' O=build_dir ARCH=x86_64 SHELL=/bin/bash

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>


sparse warnings: (new ones prefixed by >>)
   net/netfilter/nft_payload.c: note: in included file (through include/net/sctp/sctp.h, include/net/sctp/checksum.h):
   include/net/sctp/structs.h:335:41: sparse: sparse: array of flexible structures
>> net/netfilter/nft_payload.c:560:28: sparse: sparse: incorrect type in argument 2 (different base types) @@     expected restricted __be32 [usertype] from @@     got restricted __wsum [usertype] fsum @@
   net/netfilter/nft_payload.c:560:28: sparse:     expected restricted __be32 [usertype] from
   net/netfilter/nft_payload.c:560:28: sparse:     got restricted __wsum [usertype] fsum
>> net/netfilter/nft_payload.c:560:34: sparse: sparse: incorrect type in argument 3 (different base types) @@     expected restricted __be32 [usertype] to @@     got restricted __wsum [usertype] tsum @@
   net/netfilter/nft_payload.c:560:34: sparse:     expected restricted __be32 [usertype] to
   net/netfilter/nft_payload.c:560:34: sparse:     got restricted __wsum [usertype] tsum
>> net/netfilter/nft_payload.c:560:28: sparse: sparse: incorrect type in argument 2 (different base types) @@     expected restricted __be32 [usertype] from @@     got restricted __wsum [usertype] fsum @@
   net/netfilter/nft_payload.c:560:28: sparse:     expected restricted __be32 [usertype] from
   net/netfilter/nft_payload.c:560:28: sparse:     got restricted __wsum [usertype] fsum
>> net/netfilter/nft_payload.c:560:34: sparse: sparse: incorrect type in argument 3 (different base types) @@     expected restricted __be32 [usertype] to @@     got restricted __wsum [usertype] tsum @@
   net/netfilter/nft_payload.c:560:34: sparse:     expected restricted __be32 [usertype] to
   net/netfilter/nft_payload.c:560:34: sparse:     got restricted __wsum [usertype] tsum

vim +560 net/netfilter/nft_payload.c

   557	
   558	static inline void nft_csum_replace(__sum16 *sum, __wsum fsum, __wsum tsum)
   559	{
 > 560		csum_replace4(sum, fsum, tsum);
   561		if (*sum == 0)
   562			*sum = CSUM_MANGLED_0;
   563	}
   564	

-- 
0-DAY CI Kernel Test Service
https://01.org/lkp

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

end of thread, other threads:[~2022-04-22 11:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-17 15:43 [PATCH net-next v1] net: Use csum_replace_... and csum_sub() helpers instead of opencoding Christophe Leroy
2022-02-17 17:24 ` Jakub Kicinski
2022-02-17 18:11   ` Christophe Leroy
2022-02-17 18:14     ` Jakub Kicinski
2022-02-17 18:39       ` Christophe Leroy
2022-02-17 18:54         ` Jakub Kicinski
2022-02-18  7:43 ` kernel test robot
2022-04-22 11:48 ` kernel test robot

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).