All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bpf, tests: tweak endianness selection
@ 2019-03-19  2:33 ` sergey.senozhatsky.work
  0 siblings, 0 replies; 9+ messages in thread
From: Sergey Senozhatsky @ 2019-03-19  2:33 UTC (permalink / raw)
  To: Shuah Khan, Alexei Starovoitov
  Cc: Stanislav Fomichev, Daniel Borkmann, Martin KaFai Lau, Song Liu,
	Yonghong Song, linux-kselftest, netdev, bpf, Sergey Senozhatsky

Not all compilers have __builtin_bswap16() and __builtin_bswap32(),
thus not all compilers are able to compile the following code
(bpf_htons):

	(__builtin_constant_p(x) ? \
	 	___constant_swab16(x) : __builtin_bswap16(x))

That's why, for instance, bpf_htons() doesn't work on GCC < 4.8:

	error: implicit declaration of function '__builtin_bswap16'

We can use __builtin_bswap16() only if compiler has this built-in,
that is, only if __HAVE_BUILTIN_BSWAP16__ is defined. Standard UAPI
__swab16()/__swab32() take care of that, and, additionally, handle
__builtin_constant_p() cases as well (if compiler doesn't provide
builtin bswap with constants folding):

 #ifdef __HAVE_BUILTIN_BSWAP16__
 #define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
 #else
 #define __swab16(x)                             \
         (__builtin_constant_p((__u16)(x)) ?     \
         ___constant_swab16(x) :                 \
         __fswab16(x))
 #endif

So we can tweak selftests/bpf/bpf_endian.h and use UAPI
__swab16()/__swab32().

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
---
 tools/testing/selftests/bpf/bpf_endian.h | 37 +++++-------------------
 1 file changed, 8 insertions(+), 29 deletions(-)

diff --git a/tools/testing/selftests/bpf/bpf_endian.h b/tools/testing/selftests/bpf/bpf_endian.h
index b25595ea4a78..ba06222963d5 100644
--- a/tools/testing/selftests/bpf/bpf_endian.h
+++ b/tools/testing/selftests/bpf/bpf_endian.h
@@ -20,38 +20,17 @@
  * use different targets.
  */
 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-# define __bpf_ntohs(x)			__builtin_bswap16(x)
-# define __bpf_htons(x)			__builtin_bswap16(x)
-# define __bpf_constant_ntohs(x)	___constant_swab16(x)
-# define __bpf_constant_htons(x)	___constant_swab16(x)
-# define __bpf_ntohl(x)			__builtin_bswap32(x)
-# define __bpf_htonl(x)			__builtin_bswap32(x)
-# define __bpf_constant_ntohl(x)	___constant_swab32(x)
-# define __bpf_constant_htonl(x)	___constant_swab32(x)
+# define bpf_ntohs(x)		__swab16(x)
+# define bpf_htons(x)		__swab16(x)
+# define bpf_ntohl(x)		__swab32(x)
+# define bpf_htonl(x)		__swab32(x)
 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-# define __bpf_ntohs(x)			(x)
-# define __bpf_htons(x)			(x)
-# define __bpf_constant_ntohs(x)	(x)
-# define __bpf_constant_htons(x)	(x)
-# define __bpf_ntohl(x)			(x)
-# define __bpf_htonl(x)			(x)
-# define __bpf_constant_ntohl(x)	(x)
-# define __bpf_constant_htonl(x)	(x)
+# define bpf_ntohs(x)		(x)
+# define bpf_htons(x)		(x)
+# define bpf_ntohl(x)		(x)
+# define bpf_htonl(x)		(x)
 #else
 # error "Fix your compiler's __BYTE_ORDER__?!"
 #endif
 
-#define bpf_htons(x)				\
-	(__builtin_constant_p(x) ?		\
-	 __bpf_constant_htons(x) : __bpf_htons(x))
-#define bpf_ntohs(x)				\
-	(__builtin_constant_p(x) ?		\
-	 __bpf_constant_ntohs(x) : __bpf_ntohs(x))
-#define bpf_htonl(x)				\
-	(__builtin_constant_p(x) ?		\
-	 __bpf_constant_htonl(x) : __bpf_htonl(x))
-#define bpf_ntohl(x)				\
-	(__builtin_constant_p(x) ?		\
-	 __bpf_constant_ntohl(x) : __bpf_ntohl(x))
-
 #endif /* __BPF_ENDIAN__ */
-- 
2.21.0


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

* [PATCH] bpf, tests: tweak endianness selection
@ 2019-03-19  2:33 ` sergey.senozhatsky.work
  0 siblings, 0 replies; 9+ messages in thread
From: sergey.senozhatsky.work @ 2019-03-19  2:33 UTC (permalink / raw)


Not all compilers have __builtin_bswap16() and __builtin_bswap32(),
thus not all compilers are able to compile the following code
(bpf_htons):

	(__builtin_constant_p(x) ? \
	 	___constant_swab16(x) : __builtin_bswap16(x))

That's why, for instance, bpf_htons() doesn't work on GCC < 4.8:

	error: implicit declaration of function '__builtin_bswap16'

We can use __builtin_bswap16() only if compiler has this built-in,
that is, only if __HAVE_BUILTIN_BSWAP16__ is defined. Standard UAPI
__swab16()/__swab32() take care of that, and, additionally, handle
__builtin_constant_p() cases as well (if compiler doesn't provide
builtin bswap with constants folding):

 #ifdef __HAVE_BUILTIN_BSWAP16__
 #define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
 #else
 #define __swab16(x)                             \
         (__builtin_constant_p((__u16)(x)) ?     \
         ___constant_swab16(x) :                 \
         __fswab16(x))
 #endif

So we can tweak selftests/bpf/bpf_endian.h and use UAPI
__swab16()/__swab32().

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky at gmail.com>
---
 tools/testing/selftests/bpf/bpf_endian.h | 37 +++++-------------------
 1 file changed, 8 insertions(+), 29 deletions(-)

diff --git a/tools/testing/selftests/bpf/bpf_endian.h b/tools/testing/selftests/bpf/bpf_endian.h
index b25595ea4a78..ba06222963d5 100644
--- a/tools/testing/selftests/bpf/bpf_endian.h
+++ b/tools/testing/selftests/bpf/bpf_endian.h
@@ -20,38 +20,17 @@
  * use different targets.
  */
 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-# define __bpf_ntohs(x)			__builtin_bswap16(x)
-# define __bpf_htons(x)			__builtin_bswap16(x)
-# define __bpf_constant_ntohs(x)	___constant_swab16(x)
-# define __bpf_constant_htons(x)	___constant_swab16(x)
-# define __bpf_ntohl(x)			__builtin_bswap32(x)
-# define __bpf_htonl(x)			__builtin_bswap32(x)
-# define __bpf_constant_ntohl(x)	___constant_swab32(x)
-# define __bpf_constant_htonl(x)	___constant_swab32(x)
+# define bpf_ntohs(x)		__swab16(x)
+# define bpf_htons(x)		__swab16(x)
+# define bpf_ntohl(x)		__swab32(x)
+# define bpf_htonl(x)		__swab32(x)
 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-# define __bpf_ntohs(x)			(x)
-# define __bpf_htons(x)			(x)
-# define __bpf_constant_ntohs(x)	(x)
-# define __bpf_constant_htons(x)	(x)
-# define __bpf_ntohl(x)			(x)
-# define __bpf_htonl(x)			(x)
-# define __bpf_constant_ntohl(x)	(x)
-# define __bpf_constant_htonl(x)	(x)
+# define bpf_ntohs(x)		(x)
+# define bpf_htons(x)		(x)
+# define bpf_ntohl(x)		(x)
+# define bpf_htonl(x)		(x)
 #else
 # error "Fix your compiler's __BYTE_ORDER__?!"
 #endif
 
-#define bpf_htons(x)				\
-	(__builtin_constant_p(x) ?		\
-	 __bpf_constant_htons(x) : __bpf_htons(x))
-#define bpf_ntohs(x)				\
-	(__builtin_constant_p(x) ?		\
-	 __bpf_constant_ntohs(x) : __bpf_ntohs(x))
-#define bpf_htonl(x)				\
-	(__builtin_constant_p(x) ?		\
-	 __bpf_constant_htonl(x) : __bpf_htonl(x))
-#define bpf_ntohl(x)				\
-	(__builtin_constant_p(x) ?		\
-	 __bpf_constant_ntohl(x) : __bpf_ntohl(x))
-
 #endif /* __BPF_ENDIAN__ */
-- 
2.21.0

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

* [PATCH] bpf, tests: tweak endianness selection
@ 2019-03-19  2:33 ` sergey.senozhatsky.work
  0 siblings, 0 replies; 9+ messages in thread
From: Sergey Senozhatsky @ 2019-03-19  2:33 UTC (permalink / raw)


Not all compilers have __builtin_bswap16() and __builtin_bswap32(),
thus not all compilers are able to compile the following code
(bpf_htons):

	(__builtin_constant_p(x) ? \
	 	___constant_swab16(x) : __builtin_bswap16(x))

That's why, for instance, bpf_htons() doesn't work on GCC < 4.8:

	error: implicit declaration of function '__builtin_bswap16'

We can use __builtin_bswap16() only if compiler has this built-in,
that is, only if __HAVE_BUILTIN_BSWAP16__ is defined. Standard UAPI
__swab16()/__swab32() take care of that, and, additionally, handle
__builtin_constant_p() cases as well (if compiler doesn't provide
builtin bswap with constants folding):

 #ifdef __HAVE_BUILTIN_BSWAP16__
 #define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
 #else
 #define __swab16(x)                             \
         (__builtin_constant_p((__u16)(x)) ?     \
         ___constant_swab16(x) :                 \
         __fswab16(x))
 #endif

So we can tweak selftests/bpf/bpf_endian.h and use UAPI
__swab16()/__swab32().

Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky at gmail.com>
---
 tools/testing/selftests/bpf/bpf_endian.h | 37 +++++-------------------
 1 file changed, 8 insertions(+), 29 deletions(-)

diff --git a/tools/testing/selftests/bpf/bpf_endian.h b/tools/testing/selftests/bpf/bpf_endian.h
index b25595ea4a78..ba06222963d5 100644
--- a/tools/testing/selftests/bpf/bpf_endian.h
+++ b/tools/testing/selftests/bpf/bpf_endian.h
@@ -20,38 +20,17 @@
  * use different targets.
  */
 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-# define __bpf_ntohs(x)			__builtin_bswap16(x)
-# define __bpf_htons(x)			__builtin_bswap16(x)
-# define __bpf_constant_ntohs(x)	___constant_swab16(x)
-# define __bpf_constant_htons(x)	___constant_swab16(x)
-# define __bpf_ntohl(x)			__builtin_bswap32(x)
-# define __bpf_htonl(x)			__builtin_bswap32(x)
-# define __bpf_constant_ntohl(x)	___constant_swab32(x)
-# define __bpf_constant_htonl(x)	___constant_swab32(x)
+# define bpf_ntohs(x)		__swab16(x)
+# define bpf_htons(x)		__swab16(x)
+# define bpf_ntohl(x)		__swab32(x)
+# define bpf_htonl(x)		__swab32(x)
 #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-# define __bpf_ntohs(x)			(x)
-# define __bpf_htons(x)			(x)
-# define __bpf_constant_ntohs(x)	(x)
-# define __bpf_constant_htons(x)	(x)
-# define __bpf_ntohl(x)			(x)
-# define __bpf_htonl(x)			(x)
-# define __bpf_constant_ntohl(x)	(x)
-# define __bpf_constant_htonl(x)	(x)
+# define bpf_ntohs(x)		(x)
+# define bpf_htons(x)		(x)
+# define bpf_ntohl(x)		(x)
+# define bpf_htonl(x)		(x)
 #else
 # error "Fix your compiler's __BYTE_ORDER__?!"
 #endif
 
-#define bpf_htons(x)				\
-	(__builtin_constant_p(x) ?		\
-	 __bpf_constant_htons(x) : __bpf_htons(x))
-#define bpf_ntohs(x)				\
-	(__builtin_constant_p(x) ?		\
-	 __bpf_constant_ntohs(x) : __bpf_ntohs(x))
-#define bpf_htonl(x)				\
-	(__builtin_constant_p(x) ?		\
-	 __bpf_constant_htonl(x) : __bpf_htonl(x))
-#define bpf_ntohl(x)				\
-	(__builtin_constant_p(x) ?		\
-	 __bpf_constant_ntohl(x) : __bpf_ntohl(x))
-
 #endif /* __BPF_ENDIAN__ */
-- 
2.21.0

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

* Re: [PATCH] bpf, tests: tweak endianness selection
  2019-03-19  2:33 ` sergey.senozhatsky.work
  (?)
@ 2019-03-19 16:01   ` sdf
  -1 siblings, 0 replies; 9+ messages in thread
From: Stanislav Fomichev @ 2019-03-19 16:01 UTC (permalink / raw)
  To: Sergey Senozhatsky
  Cc: Shuah Khan, Alexei Starovoitov, Stanislav Fomichev,
	Daniel Borkmann, Martin KaFai Lau, Song Liu, Yonghong Song,
	linux-kselftest, netdev, bpf, Sergey Senozhatsky

On 03/19, Sergey Senozhatsky wrote:
> Not all compilers have __builtin_bswap16() and __builtin_bswap32(),
> thus not all compilers are able to compile the following code
> (bpf_htons):
> 
> 	(__builtin_constant_p(x) ? \
> 	 	___constant_swab16(x) : __builtin_bswap16(x))
> 
> That's why, for instance, bpf_htons() doesn't work on GCC < 4.8:
> 
> 	error: implicit declaration of function '__builtin_bswap16'
> 
> We can use __builtin_bswap16() only if compiler has this built-in,
> that is, only if __HAVE_BUILTIN_BSWAP16__ is defined. Standard UAPI
> __swab16()/__swab32() take care of that, and, additionally, handle
> __builtin_constant_p() cases as well (if compiler doesn't provide
> builtin bswap with constants folding):
> 
>  #ifdef __HAVE_BUILTIN_BSWAP16__
>  #define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
>  #else
>  #define __swab16(x)                             \
>          (__builtin_constant_p((__u16)(x)) ?     \
>          ___constant_swab16(x) :                 \
>          __fswab16(x))
>  #endif
> 
> So we can tweak selftests/bpf/bpf_endian.h and use UAPI
> __swab16()/__swab32().
> 
> Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
> ---
>  tools/testing/selftests/bpf/bpf_endian.h | 37 +++++-------------------
>  1 file changed, 8 insertions(+), 29 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/bpf_endian.h b/tools/testing/selftests/bpf/bpf_endian.h
> index b25595ea4a78..ba06222963d5 100644
> --- a/tools/testing/selftests/bpf/bpf_endian.h
> +++ b/tools/testing/selftests/bpf/bpf_endian.h
> @@ -20,38 +20,17 @@
>   * use different targets.
>   */
>  #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
> -# define __bpf_ntohs(x)			__builtin_bswap16(x)
> -# define __bpf_htons(x)			__builtin_bswap16(x)
> -# define __bpf_constant_ntohs(x)	___constant_swab16(x)
> -# define __bpf_constant_htons(x)	___constant_swab16(x)
This breaks the build until your next patch is applied (in other
words, breaks bisection). Can we do it in three steps?
Convert to swab (without breaking existing tests), convert the tests,
remove unused __bpf_xyz defines?

Could you also send it as a series (git format-patch --thread)? Those
patches depend on each other. And pls use [PATCH bpf-next] ... subj.

> -# define __bpf_ntohl(x)			__builtin_bswap32(x)
> -# define __bpf_htonl(x)			__builtin_bswap32(x)
> -# define __bpf_constant_ntohl(x)	___constant_swab32(x)
> -# define __bpf_constant_htonl(x)	___constant_swab32(x)
> +# define bpf_ntohs(x)		__swab16(x)
> +# define bpf_htons(x)		__swab16(x)
> +# define bpf_ntohl(x)		__swab32(x)
> +# define bpf_htonl(x)		__swab32(x)
>  #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
> -# define __bpf_ntohs(x)			(x)
> -# define __bpf_htons(x)			(x)
> -# define __bpf_constant_ntohs(x)	(x)
> -# define __bpf_constant_htons(x)	(x)
> -# define __bpf_ntohl(x)			(x)
> -# define __bpf_htonl(x)			(x)
> -# define __bpf_constant_ntohl(x)	(x)
> -# define __bpf_constant_htonl(x)	(x)
> +# define bpf_ntohs(x)		(x)
> +# define bpf_htons(x)		(x)
> +# define bpf_ntohl(x)		(x)
> +# define bpf_htonl(x)		(x)
>  #else
>  # error "Fix your compiler's __BYTE_ORDER__?!"
>  #endif
>  
> -#define bpf_htons(x)				\
> -	(__builtin_constant_p(x) ?		\
> -	 __bpf_constant_htons(x) : __bpf_htons(x))
> -#define bpf_ntohs(x)				\
> -	(__builtin_constant_p(x) ?		\
> -	 __bpf_constant_ntohs(x) : __bpf_ntohs(x))
> -#define bpf_htonl(x)				\
> -	(__builtin_constant_p(x) ?		\
> -	 __bpf_constant_htonl(x) : __bpf_htonl(x))
> -#define bpf_ntohl(x)				\
> -	(__builtin_constant_p(x) ?		\
> -	 __bpf_constant_ntohl(x) : __bpf_ntohl(x))
> -
>  #endif /* __BPF_ENDIAN__ */
> -- 
> 2.21.0
> 

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

* [PATCH] bpf, tests: tweak endianness selection
@ 2019-03-19 16:01   ` sdf
  0 siblings, 0 replies; 9+ messages in thread
From: sdf @ 2019-03-19 16:01 UTC (permalink / raw)


On 03/19, Sergey Senozhatsky wrote:
> Not all compilers have __builtin_bswap16() and __builtin_bswap32(),
> thus not all compilers are able to compile the following code
> (bpf_htons):
> 
> 	(__builtin_constant_p(x) ? \
> 	 	___constant_swab16(x) : __builtin_bswap16(x))
> 
> That's why, for instance, bpf_htons() doesn't work on GCC < 4.8:
> 
> 	error: implicit declaration of function '__builtin_bswap16'
> 
> We can use __builtin_bswap16() only if compiler has this built-in,
> that is, only if __HAVE_BUILTIN_BSWAP16__ is defined. Standard UAPI
> __swab16()/__swab32() take care of that, and, additionally, handle
> __builtin_constant_p() cases as well (if compiler doesn't provide
> builtin bswap with constants folding):
> 
>  #ifdef __HAVE_BUILTIN_BSWAP16__
>  #define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
>  #else
>  #define __swab16(x)                             \
>          (__builtin_constant_p((__u16)(x)) ?     \
>          ___constant_swab16(x) :                 \
>          __fswab16(x))
>  #endif
> 
> So we can tweak selftests/bpf/bpf_endian.h and use UAPI
> __swab16()/__swab32().
> 
> Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky at gmail.com>
> ---
>  tools/testing/selftests/bpf/bpf_endian.h | 37 +++++-------------------
>  1 file changed, 8 insertions(+), 29 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/bpf_endian.h b/tools/testing/selftests/bpf/bpf_endian.h
> index b25595ea4a78..ba06222963d5 100644
> --- a/tools/testing/selftests/bpf/bpf_endian.h
> +++ b/tools/testing/selftests/bpf/bpf_endian.h
> @@ -20,38 +20,17 @@
>   * use different targets.
>   */
>  #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
> -# define __bpf_ntohs(x)			__builtin_bswap16(x)
> -# define __bpf_htons(x)			__builtin_bswap16(x)
> -# define __bpf_constant_ntohs(x)	___constant_swab16(x)
> -# define __bpf_constant_htons(x)	___constant_swab16(x)
This breaks the build until your next patch is applied (in other
words, breaks bisection). Can we do it in three steps?
Convert to swab (without breaking existing tests), convert the tests,
remove unused __bpf_xyz defines?

Could you also send it as a series (git format-patch --thread)? Those
patches depend on each other. And pls use [PATCH bpf-next] ... subj.

> -# define __bpf_ntohl(x)			__builtin_bswap32(x)
> -# define __bpf_htonl(x)			__builtin_bswap32(x)
> -# define __bpf_constant_ntohl(x)	___constant_swab32(x)
> -# define __bpf_constant_htonl(x)	___constant_swab32(x)
> +# define bpf_ntohs(x)		__swab16(x)
> +# define bpf_htons(x)		__swab16(x)
> +# define bpf_ntohl(x)		__swab32(x)
> +# define bpf_htonl(x)		__swab32(x)
>  #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
> -# define __bpf_ntohs(x)			(x)
> -# define __bpf_htons(x)			(x)
> -# define __bpf_constant_ntohs(x)	(x)
> -# define __bpf_constant_htons(x)	(x)
> -# define __bpf_ntohl(x)			(x)
> -# define __bpf_htonl(x)			(x)
> -# define __bpf_constant_ntohl(x)	(x)
> -# define __bpf_constant_htonl(x)	(x)
> +# define bpf_ntohs(x)		(x)
> +# define bpf_htons(x)		(x)
> +# define bpf_ntohl(x)		(x)
> +# define bpf_htonl(x)		(x)
>  #else
>  # error "Fix your compiler's __BYTE_ORDER__?!"
>  #endif
>  
> -#define bpf_htons(x)				\
> -	(__builtin_constant_p(x) ?		\
> -	 __bpf_constant_htons(x) : __bpf_htons(x))
> -#define bpf_ntohs(x)				\
> -	(__builtin_constant_p(x) ?		\
> -	 __bpf_constant_ntohs(x) : __bpf_ntohs(x))
> -#define bpf_htonl(x)				\
> -	(__builtin_constant_p(x) ?		\
> -	 __bpf_constant_htonl(x) : __bpf_htonl(x))
> -#define bpf_ntohl(x)				\
> -	(__builtin_constant_p(x) ?		\
> -	 __bpf_constant_ntohl(x) : __bpf_ntohl(x))
> -
>  #endif /* __BPF_ENDIAN__ */
> -- 
> 2.21.0
> 

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

* [PATCH] bpf, tests: tweak endianness selection
@ 2019-03-19 16:01   ` sdf
  0 siblings, 0 replies; 9+ messages in thread
From: Stanislav Fomichev @ 2019-03-19 16:01 UTC (permalink / raw)


On 03/19, Sergey Senozhatsky wrote:
> Not all compilers have __builtin_bswap16() and __builtin_bswap32(),
> thus not all compilers are able to compile the following code
> (bpf_htons):
> 
> 	(__builtin_constant_p(x) ? \
> 	 	___constant_swab16(x) : __builtin_bswap16(x))
> 
> That's why, for instance, bpf_htons() doesn't work on GCC < 4.8:
> 
> 	error: implicit declaration of function '__builtin_bswap16'
> 
> We can use __builtin_bswap16() only if compiler has this built-in,
> that is, only if __HAVE_BUILTIN_BSWAP16__ is defined. Standard UAPI
> __swab16()/__swab32() take care of that, and, additionally, handle
> __builtin_constant_p() cases as well (if compiler doesn't provide
> builtin bswap with constants folding):
> 
>  #ifdef __HAVE_BUILTIN_BSWAP16__
>  #define __swab16(x) (__u16)__builtin_bswap16((__u16)(x))
>  #else
>  #define __swab16(x)                             \
>          (__builtin_constant_p((__u16)(x)) ?     \
>          ___constant_swab16(x) :                 \
>          __fswab16(x))
>  #endif
> 
> So we can tweak selftests/bpf/bpf_endian.h and use UAPI
> __swab16()/__swab32().
> 
> Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky at gmail.com>
> ---
>  tools/testing/selftests/bpf/bpf_endian.h | 37 +++++-------------------
>  1 file changed, 8 insertions(+), 29 deletions(-)
> 
> diff --git a/tools/testing/selftests/bpf/bpf_endian.h b/tools/testing/selftests/bpf/bpf_endian.h
> index b25595ea4a78..ba06222963d5 100644
> --- a/tools/testing/selftests/bpf/bpf_endian.h
> +++ b/tools/testing/selftests/bpf/bpf_endian.h
> @@ -20,38 +20,17 @@
>   * use different targets.
>   */
>  #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
> -# define __bpf_ntohs(x)			__builtin_bswap16(x)
> -# define __bpf_htons(x)			__builtin_bswap16(x)
> -# define __bpf_constant_ntohs(x)	___constant_swab16(x)
> -# define __bpf_constant_htons(x)	___constant_swab16(x)
This breaks the build until your next patch is applied (in other
words, breaks bisection). Can we do it in three steps?
Convert to swab (without breaking existing tests), convert the tests,
remove unused __bpf_xyz defines?

Could you also send it as a series (git format-patch --thread)? Those
patches depend on each other. And pls use [PATCH bpf-next] ... subj.

> -# define __bpf_ntohl(x)			__builtin_bswap32(x)
> -# define __bpf_htonl(x)			__builtin_bswap32(x)
> -# define __bpf_constant_ntohl(x)	___constant_swab32(x)
> -# define __bpf_constant_htonl(x)	___constant_swab32(x)
> +# define bpf_ntohs(x)		__swab16(x)
> +# define bpf_htons(x)		__swab16(x)
> +# define bpf_ntohl(x)		__swab32(x)
> +# define bpf_htonl(x)		__swab32(x)
>  #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
> -# define __bpf_ntohs(x)			(x)
> -# define __bpf_htons(x)			(x)
> -# define __bpf_constant_ntohs(x)	(x)
> -# define __bpf_constant_htons(x)	(x)
> -# define __bpf_ntohl(x)			(x)
> -# define __bpf_htonl(x)			(x)
> -# define __bpf_constant_ntohl(x)	(x)
> -# define __bpf_constant_htonl(x)	(x)
> +# define bpf_ntohs(x)		(x)
> +# define bpf_htons(x)		(x)
> +# define bpf_ntohl(x)		(x)
> +# define bpf_htonl(x)		(x)
>  #else
>  # error "Fix your compiler's __BYTE_ORDER__?!"
>  #endif
>  
> -#define bpf_htons(x)				\
> -	(__builtin_constant_p(x) ?		\
> -	 __bpf_constant_htons(x) : __bpf_htons(x))
> -#define bpf_ntohs(x)				\
> -	(__builtin_constant_p(x) ?		\
> -	 __bpf_constant_ntohs(x) : __bpf_ntohs(x))
> -#define bpf_htonl(x)				\
> -	(__builtin_constant_p(x) ?		\
> -	 __bpf_constant_htonl(x) : __bpf_htonl(x))
> -#define bpf_ntohl(x)				\
> -	(__builtin_constant_p(x) ?		\
> -	 __bpf_constant_ntohl(x) : __bpf_ntohl(x))
> -
>  #endif /* __BPF_ENDIAN__ */
> -- 
> 2.21.0
> 

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

* Re: [PATCH] bpf, tests: tweak endianness selection
  2019-03-19 16:01   ` sdf
  (?)
@ 2019-03-20  1:51     ` sergey.senozhatsky.work
  -1 siblings, 0 replies; 9+ messages in thread
From: Sergey Senozhatsky @ 2019-03-20  1:51 UTC (permalink / raw)
  To: Stanislav Fomichev
  Cc: Sergey Senozhatsky, Shuah Khan, Alexei Starovoitov,
	Stanislav Fomichev, Daniel Borkmann, Martin KaFai Lau, Song Liu,
	Yonghong Song, linux-kselftest, netdev, bpf, Sergey Senozhatsky

On (03/19/19 09:01), Stanislav Fomichev wrote:
> > diff --git a/tools/testing/selftests/bpf/bpf_endian.h b/tools/testing/selftests/bpf/bpf_endian.h
> > index b25595ea4a78..ba06222963d5 100644
> > --- a/tools/testing/selftests/bpf/bpf_endian.h
> > +++ b/tools/testing/selftests/bpf/bpf_endian.h
> > @@ -20,38 +20,17 @@
> >   * use different targets.
> >   */
> >  #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
> > -# define __bpf_ntohs(x)			__builtin_bswap16(x)
> > -# define __bpf_htons(x)			__builtin_bswap16(x)
> > -# define __bpf_constant_ntohs(x)	___constant_swab16(x)
> > -# define __bpf_constant_htons(x)	___constant_swab16(x)
> This breaks the build until your next patch is applied (in other
> words, breaks bisection). Can we do it in three steps?

Bummer!
I thought about applying the second patch (flow_dissector.c) first
and then the first one (bpf/bpf_endian.h).

> Convert to swab (without breaking existing tests), convert the tests,
> remove unused __bpf_xyz defines?

OK.

> Could you also send it as a series (git format-patch --thread)? Those
> patches depend on each other. And pls use [PATCH bpf-next] ... subj.

Right. I figured out that I also need to patch flow_dissector.c after
I sent out bpf/bpf_endian.h patch.

Sorry about that, will fix.

	-ss

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

* [PATCH] bpf, tests: tweak endianness selection
@ 2019-03-20  1:51     ` sergey.senozhatsky.work
  0 siblings, 0 replies; 9+ messages in thread
From: sergey.senozhatsky.work @ 2019-03-20  1:51 UTC (permalink / raw)


On (03/19/19 09:01), Stanislav Fomichev wrote:
> > diff --git a/tools/testing/selftests/bpf/bpf_endian.h b/tools/testing/selftests/bpf/bpf_endian.h
> > index b25595ea4a78..ba06222963d5 100644
> > --- a/tools/testing/selftests/bpf/bpf_endian.h
> > +++ b/tools/testing/selftests/bpf/bpf_endian.h
> > @@ -20,38 +20,17 @@
> >   * use different targets.
> >   */
> >  #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
> > -# define __bpf_ntohs(x)			__builtin_bswap16(x)
> > -# define __bpf_htons(x)			__builtin_bswap16(x)
> > -# define __bpf_constant_ntohs(x)	___constant_swab16(x)
> > -# define __bpf_constant_htons(x)	___constant_swab16(x)
> This breaks the build until your next patch is applied (in other
> words, breaks bisection). Can we do it in three steps?

Bummer!
I thought about applying the second patch (flow_dissector.c) first
and then the first one (bpf/bpf_endian.h).

> Convert to swab (without breaking existing tests), convert the tests,
> remove unused __bpf_xyz defines?

OK.

> Could you also send it as a series (git format-patch --thread)? Those
> patches depend on each other. And pls use [PATCH bpf-next] ... subj.

Right. I figured out that I also need to patch flow_dissector.c after
I sent out bpf/bpf_endian.h patch.

Sorry about that, will fix.

	-ss

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

* [PATCH] bpf, tests: tweak endianness selection
@ 2019-03-20  1:51     ` sergey.senozhatsky.work
  0 siblings, 0 replies; 9+ messages in thread
From: Sergey Senozhatsky @ 2019-03-20  1:51 UTC (permalink / raw)


On (03/19/19 09:01), Stanislav Fomichev wrote:
> > diff --git a/tools/testing/selftests/bpf/bpf_endian.h b/tools/testing/selftests/bpf/bpf_endian.h
> > index b25595ea4a78..ba06222963d5 100644
> > --- a/tools/testing/selftests/bpf/bpf_endian.h
> > +++ b/tools/testing/selftests/bpf/bpf_endian.h
> > @@ -20,38 +20,17 @@
> >   * use different targets.
> >   */
> >  #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
> > -# define __bpf_ntohs(x)			__builtin_bswap16(x)
> > -# define __bpf_htons(x)			__builtin_bswap16(x)
> > -# define __bpf_constant_ntohs(x)	___constant_swab16(x)
> > -# define __bpf_constant_htons(x)	___constant_swab16(x)
> This breaks the build until your next patch is applied (in other
> words, breaks bisection). Can we do it in three steps?

Bummer!
I thought about applying the second patch (flow_dissector.c) first
and then the first one (bpf/bpf_endian.h).

> Convert to swab (without breaking existing tests), convert the tests,
> remove unused __bpf_xyz defines?

OK.

> Could you also send it as a series (git format-patch --thread)? Those
> patches depend on each other. And pls use [PATCH bpf-next] ... subj.

Right. I figured out that I also need to patch flow_dissector.c after
I sent out bpf/bpf_endian.h patch.

Sorry about that, will fix.

	-ss

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

end of thread, other threads:[~2019-03-20  1:51 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-19  2:33 [PATCH] bpf, tests: tweak endianness selection Sergey Senozhatsky
2019-03-19  2:33 ` Sergey Senozhatsky
2019-03-19  2:33 ` sergey.senozhatsky.work
2019-03-19 16:01 ` Stanislav Fomichev
2019-03-19 16:01   ` Stanislav Fomichev
2019-03-19 16:01   ` sdf
2019-03-20  1:51   ` Sergey Senozhatsky
2019-03-20  1:51     ` Sergey Senozhatsky
2019-03-20  1:51     ` sergey.senozhatsky.work

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.