Skip to contentSkip to conversation

inet_ecn: Use csum16_add() helper for IP_ECN_set_* helpers

PATCH Superseded Toke Høiland-Jørgensen 2 participants 2 messages Dec 10, 2020 – Dec 11, 2020

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 inet_ecn: Use csum16_add() helper for IP_ECN_set_* helpers

Jakub pointed out that the IP_ECN_set* helpers basically open-code csum16_add(), so let's switch them over to using the helper instead.

v2:
- Use __be16 for check_add stack variable in IP_ECN_set_ce() (kbot)

---
 include/net/inet_ecn.h | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)
include/net/inet_ecn.h +5 -8
index 563457fec557..d916a458aceb 100644
@@ -8,6 +8,7 @@
 
 #include <net/inet_sock.h>
 #include <net/dsfield.h>
+#include <net/checksum.h>
 
 enum {
 	INET_ECN_NOT_ECT = 0,
@@ -75,8 +76,8 @@ static inline void INET_ECN_dontxmit(struct sock *sk)
 
 static inline int IP_ECN_set_ce(struct iphdr *iph)
 {
-	u32 check = (__force u32)iph->check;
 	u32 ecn = (iph->tos + 1) & INET_ECN_MASK;
+	__be16 check_add;
 
 	/*
 	 * After the last operation we have (in binary):
@@ -93,23 +94,19 @@ static inline int IP_ECN_set_ce(struct iphdr *iph)
 	 * INET_ECN_ECT_1 => check += htons(0xFFFD)
 	 * INET_ECN_ECT_0 => check += htons(0xFFFE)
 	 */
-	check += (__force u16)htons(0xFFFB) + (__force u16)htons(ecn);
+	check_add = htons(0xFFFB) + htons(ecn);
 
-	iph->check = (__force __sum16)(check + (check>=0xFFFF));
+	iph->check = csum16_add(iph->check, check_add);
 	iph->tos |= INET_ECN_CE;
 	return 1;
 }
 
 static inline int IP_ECN_set_ect1(struct iphdr *iph)
 {
-	u32 check = (__force u32)iph->check;
-
 	if ((iph->tos & INET_ECN_MASK) != INET_ECN_ECT_0)
 		return 0;
 
-	check += (__force u16)htons(0x1);
-
-	iph->check = (__force __sum16)(check + (check>=0xFFFF));
+	iph->check = csum16_add(iph->check, htons(0x1));
 	iph->tos ^= INET_ECN_MASK;
 	return 1;
 }
Signature · 1 line
2.29.2
#1 lore raw
I love your patch! Perhaps something to improve:

Hi "Toke,

I love your patch! Perhaps something to improve:

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

url:    https://github.com/0day-ci/linux/commits/Toke-H-iland-J-rgensen/inet_ecn-Use-csum16_add-helper-for-IP_ECN_set_-helpers/20201211-071305
base:   https://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next.git 51e13685bd93654e0e9b2559c8e103d6545ddf95
config: i386-randconfig-s001-20201209 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
reproduce:
        # apt-get install sparse
        # sparse version: v0.6.3-179-ga00755aa-dirty
        # https://github.com/0day-ci/linux/commit/30ca3d0f48b3d72f9ca0a3509eb63956484d02ad
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Toke-H-iland-J-rgensen/inet_ecn-Use-csum16_add-helper-for-IP_ECN_set_-helpers/20201211-071305
        git checkout 30ca3d0f48b3d72f9ca0a3509eb63956484d02ad
        # save the attached .config to linux build tree
        make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=i386 

If you fix the issue, kindly add following tag as appropriate

"sparse warnings: (new ones prefixed by >>)"
net/sched/sch_fq.c: note: in included file (through include/net/tcp.h):
include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer

>> include/net/inet_ecn.h:97:19: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be16 [usertype] check_add @@     got int @@

include/net/inet_ecn.h:97:19: sparse: expected restricted __be16 [usertype] check_add
include/net/inet_ecn.h:97:19: sparse: got int
--
net/sched/sch_sfq.c: note: in included file (through include/net/red.h):
include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer

>> include/net/inet_ecn.h:97:19: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be16 [usertype] check_add @@     got int @@
   include/net/inet_ecn.h:97:19: sparse:     expected restricted __be16 [usertype] check_add
   include/net/inet_ecn.h:97:19: sparse:     got int
   include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer
   include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer
>> include/net/inet_ecn.h:97:19: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be16 [usertype] check_add @@     got int @@
   include/net/inet_ecn.h:97:19: sparse:     expected restricted __be16 [usertype] check_add
   include/net/inet_ecn.h:97:19: sparse:     got int
   include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer
   include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer
>> include/net/inet_ecn.h:97:19: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be16 [usertype] check_add @@     got int @@
   include/net/inet_ecn.h:97:19: sparse:     expected restricted __be16 [usertype] check_add
   include/net/inet_ecn.h:97:19: sparse:     got int
   include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer
   include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer
>> include/net/inet_ecn.h:97:19: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be16 [usertype] check_add @@     got int @@

include/net/inet_ecn.h:97:19: sparse: expected restricted __be16 [usertype] check_add
include/net/inet_ecn.h:97:19: sparse: got int
--
net/sched/sch_sfb.c: note: in included file:
include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer

>> include/net/inet_ecn.h:97:19: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be16 [usertype] check_add @@     got int @@

include/net/inet_ecn.h:97:19: sparse: expected restricted __be16 [usertype] check_add
include/net/inet_ecn.h:97:19: sparse: got int
--
net/sched/sch_fq_codel.c: note: in included file (through include/net/codel.h):
include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer

>> include/net/inet_ecn.h:97:19: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be16 [usertype] check_add @@     got int @@
   include/net/inet_ecn.h:97:19: sparse:     expected restricted __be16 [usertype] check_add
   include/net/inet_ecn.h:97:19: sparse:     got int
   include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer
   include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer
>> include/net/inet_ecn.h:97:19: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be16 [usertype] check_add @@     got int @@
   include/net/inet_ecn.h:97:19: sparse:     expected restricted __be16 [usertype] check_add
   include/net/inet_ecn.h:97:19: sparse:     got int
   include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer
   include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer
>> include/net/inet_ecn.h:97:19: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be16 [usertype] check_add @@     got int @@

include/net/inet_ecn.h:97:19: sparse: expected restricted __be16 [usertype] check_add
include/net/inet_ecn.h:97:19: sparse: got int
--
net/sched/sch_choke.c: note: in included file:
include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer

>> include/net/inet_ecn.h:97:19: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be16 [usertype] check_add @@     got int @@
   include/net/inet_ecn.h:97:19: sparse:     expected restricted __be16 [usertype] check_add
   include/net/inet_ecn.h:97:19: sparse:     got int
   include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer
   include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer
>> include/net/inet_ecn.h:97:19: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be16 [usertype] check_add @@     got int @@

include/net/inet_ecn.h:97:19: sparse: expected restricted __be16 [usertype] check_add
include/net/inet_ecn.h:97:19: sparse: got int
--
net/sched/sch_codel.c: note: in included file (through include/net/codel.h):
include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer

>> include/net/inet_ecn.h:97:19: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be16 [usertype] check_add @@     got int @@
   include/net/inet_ecn.h:97:19: sparse:     expected restricted __be16 [usertype] check_add
   include/net/inet_ecn.h:97:19: sparse:     got int
   include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer
   include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer
>> include/net/inet_ecn.h:97:19: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be16 [usertype] check_add @@     got int @@
   include/net/inet_ecn.h:97:19: sparse:     expected restricted __be16 [usertype] check_add
   include/net/inet_ecn.h:97:19: sparse:     got int
   include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer
   include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer
>> include/net/inet_ecn.h:97:19: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be16 [usertype] check_add @@     got int @@

include/net/inet_ecn.h:97:19: sparse: expected restricted __be16 [usertype] check_add
include/net/inet_ecn.h:97:19: sparse: got int
--
net/sched/sch_red.c: note: in included file:
include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer

>> include/net/inet_ecn.h:97:19: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be16 [usertype] check_add @@     got int @@
   include/net/inet_ecn.h:97:19: sparse:     expected restricted __be16 [usertype] check_add
   include/net/inet_ecn.h:97:19: sparse:     got int
   include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer
   include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer
>> include/net/inet_ecn.h:97:19: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be16 [usertype] check_add @@     got int @@

include/net/inet_ecn.h:97:19: sparse: expected restricted __be16 [usertype] check_add
include/net/inet_ecn.h:97:19: sparse: got int
--
net/sched/sch_netem.c: note: in included file:
include/net/inet_ecn.h:97:21: sparse: sparse: restricted __be16 degrades to integer include/net/inet_ecn.h:97:37: sparse: sparse: restricted __be16 degrades to integer

>> include/net/inet_ecn.h:97:19: sparse: sparse: incorrect type in assignment (different base types) @@     expected restricted __be16 [usertype] check_add @@     got int @@

include/net/inet_ecn.h:97:19: sparse: expected restricted __be16 [usertype] check_add
include/net/inet_ecn.h:97:19: sparse: got int

vim +97 include/net/inet_ecn.h

    67	
    68	#define IP6_ECN_flow_init(label) do {		\
    69	      (label) &= ~htonl(INET_ECN_MASK << 20);	\
    70	    } while (0)
    71	
    72	#define	IP6_ECN_flow_xmit(sk, label) do {				\
    73		if (INET_ECN_is_capable(inet6_sk(sk)->tclass))			\
    74			(label) |= htonl(INET_ECN_ECT_0 << 20);			\
    75	    } while (0)
    76	
    77	static inline int IP_ECN_set_ce(struct iphdr *iph)
    78	{
    79		u32 ecn = (iph->tos + 1) & INET_ECN_MASK;
    80		__be16 check_add;
    81	
    82		/*
    83		 * After the last operation we have (in binary):
    84		 * INET_ECN_NOT_ECT => 01
    85		 * INET_ECN_ECT_1   => 10
    86		 * INET_ECN_ECT_0   => 11
    87		 * INET_ECN_CE      => 00
    88		 */
    89		if (!(ecn & 2))
    90			return !ecn;
    91	
    92		/*
    93		 * The following gives us:
    94		 * INET_ECN_ECT_1 => check += htons(0xFFFD)
    95		 * INET_ECN_ECT_0 => check += htons(0xFFFE)
    96		 */
  > 97		check_add = htons(0xFFFB) + htons(ecn);
    98	
    99		iph->check = csum16_add(iph->check, check_add);

100 iph->tos |= INET_ECN_CE;
101 return 1;
102 }
103

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