Home Home > GIT Browse
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGary Lin <glin@suse.com>2019-11-06 17:49:33 +0800
committerGary Lin <glin@suse.com>2019-11-06 17:49:38 +0800
commited6737da598d568823bb5915f4f7b659288139da (patch)
treecba32aa571f497ecd7f08296429ce21c1e0616f2
parent2b3b7a6b1d93a146b2ac26851dd696623542b8c7 (diff)
selftests/bpf: introduce bpf_cpu_to_be64 and bpf_be64_to_cpu
(bsc#1155518).
-rw-r--r--patches.suse/selftests-bpf-introduce-bpf_cpu_to_be64-and-bpf_be64.patch127
-rw-r--r--series.conf1
2 files changed, 128 insertions, 0 deletions
diff --git a/patches.suse/selftests-bpf-introduce-bpf_cpu_to_be64-and-bpf_be64.patch b/patches.suse/selftests-bpf-introduce-bpf_cpu_to_be64-and-bpf_be64.patch
new file mode 100644
index 0000000000..b0d58fdea2
--- /dev/null
+++ b/patches.suse/selftests-bpf-introduce-bpf_cpu_to_be64-and-bpf_be64.patch
@@ -0,0 +1,127 @@
+From: Ilya Leoshkevich <iii@linux.ibm.com>
+Date: Fri, 30 Aug 2019 13:07:29 +0200
+Subject: selftests/bpf: introduce bpf_cpu_to_be64 and bpf_be64_to_cpu
+Patch-mainline: v5.4-rc1
+Git-commit: b9632679944307f3caab183fa69a4d79ffeb40ce
+References: bsc#1155518
+
+test_lwt_seg6local and test_seg6_loop use custom 64-bit endianness
+conversion macros. Centralize their definitions in bpf_endian.h in order
+to reduce code duplication. This will also be useful when bpf_endian.h
+is promoted to an offical libbpf header.
+
+Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
+Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
+Acked-by: Gary Lin <glin@suse.com>
+---
+ tools/testing/selftests/bpf/bpf_endian.h | 14 ++++++++++++++
+ tools/testing/selftests/bpf/progs/test_lwt_seg6local.c | 16 ++++++----------
+ tools/testing/selftests/bpf/progs/test_seg6_loop.c | 8 ++------
+ 3 files changed, 22 insertions(+), 16 deletions(-)
+
+--- a/tools/testing/selftests/bpf/bpf_endian.h
++++ b/tools/testing/selftests/bpf/bpf_endian.h
+@@ -29,6 +29,10 @@
+ # 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_be64_to_cpu(x) __builtin_bswap64(x)
++# define __bpf_cpu_to_be64(x) __builtin_bswap64(x)
++# define __bpf_constant_be64_to_cpu(x) ___constant_swab64(x)
++# define __bpf_constant_cpu_to_be64(x) ___constant_swab64(x)
+ #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+ # define __bpf_ntohs(x) (x)
+ # define __bpf_htons(x) (x)
+@@ -38,6 +42,10 @@
+ # define __bpf_htonl(x) (x)
+ # define __bpf_constant_ntohl(x) (x)
+ # define __bpf_constant_htonl(x) (x)
++# define __bpf_be64_to_cpu(x) (x)
++# define __bpf_cpu_to_be64(x) (x)
++# define __bpf_constant_be64_to_cpu(x) (x)
++# define __bpf_constant_cpu_to_be64(x) (x)
+ #else
+ # error "Fix your compiler's __BYTE_ORDER__?!"
+ #endif
+@@ -54,5 +62,11 @@
+ #define bpf_ntohl(x) \
+ (__builtin_constant_p(x) ? \
+ __bpf_constant_ntohl(x) : __bpf_ntohl(x))
++#define bpf_cpu_to_be64(x) \
++ (__builtin_constant_p(x) ? \
++ __bpf_constant_cpu_to_be64(x) : __bpf_cpu_to_be64(x))
++#define bpf_be64_to_cpu(x) \
++ (__builtin_constant_p(x) ? \
++ __bpf_constant_be64_to_cpu(x) : __bpf_be64_to_cpu(x))
+
+ #endif /* __BPF_ENDIAN__ */
+--- a/tools/testing/selftests/bpf/progs/test_lwt_seg6local.c
++++ b/tools/testing/selftests/bpf/progs/test_lwt_seg6local.c
+@@ -12,10 +12,6 @@
+
+ #define SR6_FLAG_ALERT (1 << 4)
+
+-#define htonll(x) ((bpf_htonl(1)) == 1 ? (x) : ((uint64_t)bpf_htonl((x) & \
+- 0xFFFFFFFF) << 32) | bpf_htonl((x) >> 32))
+-#define ntohll(x) ((bpf_ntohl(1)) == 1 ? (x) : ((uint64_t)bpf_ntohl((x) & \
+- 0xFFFFFFFF) << 32) | bpf_ntohl((x) >> 32))
+ #define BPF_PACKET_HEADER __attribute__((packed))
+
+ struct ip6_t {
+@@ -276,8 +272,8 @@ int has_egr_tlv(struct __sk_buff *skb, s
+ return 0;
+
+ // check if egress TLV value is correct
+- if (ntohll(egr_addr.hi) == 0xfd00000000000000 &&
+- ntohll(egr_addr.lo) == 0x4)
++ if (bpf_be64_to_cpu(egr_addr.hi) == 0xfd00000000000000 &&
++ bpf_be64_to_cpu(egr_addr.lo) == 0x4)
+ return 1;
+ }
+
+@@ -308,8 +304,8 @@ int __encap_srh(struct __sk_buff *skb)
+
+ #pragma clang loop unroll(full)
+ for (unsigned long long lo = 0; lo < 4; lo++) {
+- seg->lo = htonll(4 - lo);
+- seg->hi = htonll(hi);
++ seg->lo = bpf_cpu_to_be64(4 - lo);
++ seg->hi = bpf_cpu_to_be64(hi);
+ seg = (struct ip6_addr_t *)((char *)seg + sizeof(*seg));
+ }
+
+@@ -349,8 +345,8 @@ int __add_egr_x(struct __sk_buff *skb)
+ if (err)
+ return BPF_DROP;
+
+- addr.lo = htonll(lo);
+- addr.hi = htonll(hi);
++ addr.lo = bpf_cpu_to_be64(lo);
++ addr.hi = bpf_cpu_to_be64(hi);
+ err = bpf_lwt_seg6_action(skb, SEG6_LOCAL_ACTION_END_X,
+ (void *)&addr, sizeof(addr));
+ if (err)
+--- a/tools/testing/selftests/bpf/progs/test_seg6_loop.c
++++ b/tools/testing/selftests/bpf/progs/test_seg6_loop.c
+@@ -12,10 +12,6 @@
+
+ #define SR6_FLAG_ALERT (1 << 4)
+
+-#define htonll(x) ((bpf_htonl(1)) == 1 ? (x) : ((uint64_t)bpf_htonl((x) & \
+- 0xFFFFFFFF) << 32) | bpf_htonl((x) >> 32))
+-#define ntohll(x) ((bpf_ntohl(1)) == 1 ? (x) : ((uint64_t)bpf_ntohl((x) & \
+- 0xFFFFFFFF) << 32) | bpf_ntohl((x) >> 32))
+ #define BPF_PACKET_HEADER __attribute__((packed))
+
+ struct ip6_t {
+@@ -251,8 +247,8 @@ int __add_egr_x(struct __sk_buff *skb)
+ if (err)
+ return BPF_DROP;
+
+- addr.lo = htonll(lo);
+- addr.hi = htonll(hi);
++ addr.lo = bpf_cpu_to_be64(lo);
++ addr.hi = bpf_cpu_to_be64(hi);
+ err = bpf_lwt_seg6_action(skb, SEG6_LOCAL_ACTION_END_X,
+ (void *)&addr, sizeof(addr));
+ if (err)
diff --git a/series.conf b/series.conf
index 53d0301f77..177ecb3e9f 100644
--- a/series.conf
+++ b/series.conf
@@ -1135,6 +1135,7 @@
patches.suse/mlx5e-modify-driver-for-handling-offsets.patch
patches.suse/net-mlx5e-Allow-XSK-frames-smaller-than-a-page.patch
patches.suse/libbpf-add-flags-to-umem-config.patch
+ patches.suse/selftests-bpf-introduce-bpf_cpu_to_be64-and-bpf_be64.patch
patches.suse/i40e-fix-xdp-handle-calculations.patch
patches.suse/ixgbe-fix-xdp-handle-calculations.patch
patches.suse/xsk-avoid-store-tearing-when-assigning-queues.patch