Web lists-archives.com

Re: [PATCH] tcp: don't use __constant_cpu_to_be32




On (03/14/19 05:42), Eric Dumazet wrote:
> > cpu_to_be32() is capable enough to detect __builtin_constant_p()
> > and to use an appropriate compile time ___constant_swahb32()
> > function.
> >
> > So we can use cpu_to_be32() instead of __constant_cpu_to_be32().
> 
> 
> I dunno, this is uapi, this might break user space for some funky compiler ?
> I do not even know if cpu_to_be32() _is_ uapi.

Hmm, excellent point.

Looking at

if_pppox.h:#define PTT_EOL		__cpu_to_be16(0x0000)
if_pppox.h:#define PTT_SRV_NAME	__cpu_to_be16(0x0101)
if_pppox.h:#define PTT_AC_NAME	__cpu_to_be16(0x0102)
if_pppox.h:#define PTT_HOST_UNIQ	__cpu_to_be16(0x0103)
if_pppox.h:#define PTT_AC_COOKIE	__cpu_to_be16(0x0104)
if_pppox.h:#define PTT_VENDOR 	__cpu_to_be16(0x0105)
if_pppox.h:#define PTT_RELAY_SID	__cpu_to_be16(0x0110)
if_pppox.h:#define PTT_SRV_ERR     __cpu_to_be16(0x0201)
if_pppox.h:#define PTT_SYS_ERR  	__cpu_to_be16(0x0202)
if_pppox.h:#define PTT_GEN_ERR  	__cpu_to_be16(0x0203)
if_tunnel.h:#define GRE_CSUM	__cpu_to_be16(0x8000)
if_tunnel.h:#define GRE_ROUTING	__cpu_to_be16(0x4000)
if_tunnel.h:#define GRE_KEY		__cpu_to_be16(0x2000)
if_tunnel.h:#define GRE_SEQ		__cpu_to_be16(0x1000)
if_tunnel.h:#define GRE_STRICT	__cpu_to_be16(0x0800)
if_tunnel.h:#define GRE_REC		__cpu_to_be16(0x0700)
if_tunnel.h:#define GRE_ACK		__cpu_to_be16(0x0080)
if_tunnel.h:#define GRE_FLAGS	__cpu_to_be16(0x0078)
if_tunnel.h:#define GRE_VERSION	__cpu_to_be16(0x0007)
if_tunnel.h:#define GRE_VERSION_0		__cpu_to_be16(0x0000)
if_tunnel.h:#define GRE_VERSION_1		__cpu_to_be16(0x0001)
if_tunnel.h:#define GRE_PROTO_PPP		__cpu_to_be16(0x880b)

You are right, probably would need __cpu_to_be32, which also does
the constant folding.

=-=-=-=-=

Subject: [PATCH] tcp: don't use __constant_cpu_to_be32

__cpu_to_be32() can detect __builtin_constant_p() at compile time.
So we can use __cpu_to_be32() instead of __constant_cpu_to_be32().

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@xxxxxxxxx>
---
 include/uapi/linux/tcp.h | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/include/uapi/linux/tcp.h b/include/uapi/linux/tcp.h
index 8bb6cc5f3235..cf9c246a59c8 100644
--- a/include/uapi/linux/tcp.h
+++ b/include/uapi/linux/tcp.h
@@ -70,16 +70,16 @@ union tcp_word_hdr {
 #define tcp_flag_word(tp) ( ((union tcp_word_hdr *)(tp))->words [3]) 
 
 enum { 
-	TCP_FLAG_CWR = __constant_cpu_to_be32(0x00800000),
-	TCP_FLAG_ECE = __constant_cpu_to_be32(0x00400000),
-	TCP_FLAG_URG = __constant_cpu_to_be32(0x00200000),
-	TCP_FLAG_ACK = __constant_cpu_to_be32(0x00100000),
-	TCP_FLAG_PSH = __constant_cpu_to_be32(0x00080000),
-	TCP_FLAG_RST = __constant_cpu_to_be32(0x00040000),
-	TCP_FLAG_SYN = __constant_cpu_to_be32(0x00020000),
-	TCP_FLAG_FIN = __constant_cpu_to_be32(0x00010000),
-	TCP_RESERVED_BITS = __constant_cpu_to_be32(0x0F000000),
-	TCP_DATA_OFFSET = __constant_cpu_to_be32(0xF0000000)
+	TCP_FLAG_CWR = __cpu_to_be32(0x00800000),
+	TCP_FLAG_ECE = __cpu_to_be32(0x00400000),
+	TCP_FLAG_URG = __cpu_to_be32(0x00200000),
+	TCP_FLAG_ACK = __cpu_to_be32(0x00100000),
+	TCP_FLAG_PSH = __cpu_to_be32(0x00080000),
+	TCP_FLAG_RST = __cpu_to_be32(0x00040000),
+	TCP_FLAG_SYN = __cpu_to_be32(0x00020000),
+	TCP_FLAG_FIN = __cpu_to_be32(0x00010000),
+	TCP_RESERVED_BITS = __cpu_to_be32(0x0F000000),
+	TCP_DATA_OFFSET = __cpu_to_be32(0xF0000000)
 }; 
 
 /*
-- 
2.21.0