Skip to contentSkip to conversation

selftests/bpf: use __bpf_constant_htons in test_prog.c for flow dissector

PATCH Applied Stanislav Fomichev 3 participants 3 messages Feb 27, 2019 – Feb 28, 2019

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/bpf: use __bpf_constant_htons in test_prog.c for flow dissector

Older GCC (<4.8) isn't smart enough to optimize !__builtin_constant_p() branch in bpf_htons.

I recently fixed it for pkt_v4 and pkt_v6 in commit a0517a0f7ef23 ("selftests/bpf: use __bpf_constant_htons in test_prog.c"), but later added another bunch of bpf_htons in commit bf0f0fd939451 ("selftests/bpf:
add simple BPF_PROG_TEST_RUN examples for flow dissector").

Fixes bf0f0fd939451 ("selftests/bpf: add simple BPF_PROG_TEST_RUN examples for flow dissector")
---
 tools/testing/selftests/bpf/test_progs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/test_progs.c +2 -2
index c59d2e015d16..87cde42559f7 100644
@@ -1954,7 +1954,7 @@ static struct bpf_flow_keys pkt_v4_flow_keys = {
 	.thoff = sizeof(struct iphdr),
 	.addr_proto = ETH_P_IP,
 	.ip_proto = IPPROTO_TCP,
-	.n_proto = bpf_htons(ETH_P_IP),
+	.n_proto = __bpf_constant_htons(ETH_P_IP),
 };
 
 static struct bpf_flow_keys pkt_v6_flow_keys = {
@@ -1962,7 +1962,7 @@ static struct bpf_flow_keys pkt_v6_flow_keys = {
 	.thoff = sizeof(struct ipv6hdr),
 	.addr_proto = ETH_P_IPV6,
 	.ip_proto = IPPROTO_TCP,
-	.n_proto = bpf_htons(ETH_P_IPV6),
+	.n_proto = __bpf_constant_htons(ETH_P_IPV6),
 };
 
 static void test_flow_dissector(void)
Signature · 1 line
2.21.0.rc2.261.ga7da99ff1b-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Stanislav Fomichev

Older GCC (<4.8) isn't smart enough to optimize !__builtin_constant_p() branch in bpf_htons.

Quoted 8 lines

I recently fixed it for pkt_v4 and pkt_v6 in commit a0517a0f7ef23 ("selftests/bpf: use __bpf_constant_htons in test_prog.c"), but later added another bunch of bpf_htons in commit bf0f0fd939451 ("selftests/bpf:
add simple BPF_PROG_TEST_RUN examples for flow dissector").

Fixes bf0f0fd939451 ("selftests/bpf: add simple BPF_PROG_TEST_RUN examples for flow dissector")
Quoted 29 lines
---
 tools/testing/selftests/bpf/test_progs.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/testing/selftests/bpf/test_progs.c +2 -3
index c59d2e015d16..87cde42559f7 100644
@@ -1954,7 +1954,7 @@ static struct bpf_flow_keys pkt_v4_flow_keys = {
        .thoff = sizeof(struct iphdr),
        .addr_proto = ETH_P_IP,
        .ip_proto = IPPROTO_TCP,
-       .n_proto = bpf_htons(ETH_P_IP),
+       .n_proto = __bpf_constant_htons(ETH_P_IP),
 };
 
 static struct bpf_flow_keys pkt_v6_flow_keys = {
@@ -1962,7 +1962,7 @@ static struct bpf_flow_keys pkt_v6_flow_keys = {
        .thoff = sizeof(struct ipv6hdr),
        .addr_proto = ETH_P_IPV6,
        .ip_proto = IPPROTO_TCP,
-       .n_proto = bpf_htons(ETH_P_IPV6),
+       .n_proto = __bpf_constant_htons(ETH_P_IPV6),
 };
 
 static void test_flow_dissector(void)
--

2.21.0.rc2.261.ga7da99ff1b-goog

maintainer Applied
#2 lore raw
In reply to Stanislav Fomichev
Quoted 11 lines · Stanislav Fomichev

Older GCC (<4.8) isn't smart enough to optimize !__builtin_constant_p() branch in bpf_htons.

I recently fixed it for pkt_v4 and pkt_v6 in commit a0517a0f7ef23 ("selftests/bpf: use __bpf_constant_htons in test_prog.c"), but later added another bunch of bpf_htons in commit bf0f0fd939451 ("selftests/bpf:
add simple BPF_PROG_TEST_RUN examples for flow dissector").

Fixes bf0f0fd939451 ("selftests/bpf: add simple BPF_PROG_TEST_RUN examples for flow dissector")

Applied, thanks!