selftests/bpf: Change functions definitions to support GCC
authorCupertino Miranda <cupertino.miranda@oracle.com>
Tue, 7 May 2024 12:22:20 +0000 (13:22 +0100)
committerAndrii Nakryiko <andrii@kernel.org>
Tue, 7 May 2024 21:41:00 +0000 (14:41 -0700)
The test_xdp_noinline.c contains 2 functions that use more then 5
arguments. This patch collapses the 2 last arguments in an array.
Also in GCC and ipa_sra optimization increases the number of arguments
used in function encap_v4. This pass disables the optimization for that
particular file.

Signed-off-by: Cupertino Miranda <cupertino.miranda@oracle.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Yonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/bpf/20240507122220.207820-3-cupertino.miranda@oracle.com
tools/testing/selftests/bpf/progs/test_xdp_noinline.c

index 5c7e4758a0cab9e38297d353f8926209041063b5..fad94e41cef9d85f10f15e15b403bdb2687b1bed 100644 (file)
@@ -318,6 +318,14 @@ bool encap_v6(struct xdp_md *xdp, struct ctl_value *cval,
        return true;
 }
 
+#ifndef __clang__
+#pragma GCC push_options
+/* GCC optimization collapses functions and increases the number of arguments
+ * beyond the compatible amount supported by BPF.
+ */
+#pragma GCC optimize("-fno-ipa-sra")
+#endif
+
 static __attribute__ ((noinline))
 bool encap_v4(struct xdp_md *xdp, struct ctl_value *cval,
              struct packet_description *pckt,
@@ -372,6 +380,10 @@ bool encap_v4(struct xdp_md *xdp, struct ctl_value *cval,
        return true;
 }
 
+#ifndef __clang__
+#pragma GCC pop_options
+#endif
+
 static __attribute__ ((noinline))
 int swap_mac_and_send(void *data, void *data_end)
 {
@@ -588,12 +600,13 @@ static void connection_table_lookup(struct real_definition **real,
 __attribute__ ((noinline))
 static int process_l3_headers_v6(struct packet_description *pckt,
                                 __u8 *protocol, __u64 off,
-                                __u16 *pkt_bytes, void *data,
-                                void *data_end)
+                                __u16 *pkt_bytes, void *extra_args[2])
 {
        struct ipv6hdr *ip6h;
        __u64 iph_len;
        int action;
+       void *data = extra_args[0];
+       void *data_end = extra_args[1];
 
        ip6h = data + off;
        if (ip6h + 1 > data_end)
@@ -619,11 +632,12 @@ static int process_l3_headers_v6(struct packet_description *pckt,
 __attribute__ ((noinline))
 static int process_l3_headers_v4(struct packet_description *pckt,
                                 __u8 *protocol, __u64 off,
-                                __u16 *pkt_bytes, void *data,
-                                void *data_end)
+                                __u16 *pkt_bytes, void *extra_args[2])
 {
        struct iphdr *iph;
        int action;
+       void *data = extra_args[0];
+       void *data_end = extra_args[1];
 
        iph = data + off;
        if (iph + 1 > data_end)
@@ -666,13 +680,14 @@ static int process_packet(void *data, __u64 off, void *data_end,
        __u8 protocol;
        __u32 vip_num;
        int action;
+       void *extra_args[2] = { data, data_end };
 
        if (is_ipv6)
                action = process_l3_headers_v6(&pckt, &protocol, off,
-                                              &pkt_bytes, data, data_end);
+                                              &pkt_bytes, extra_args);
        else
                action = process_l3_headers_v4(&pckt, &protocol, off,
-                                              &pkt_bytes, data, data_end);
+                                              &pkt_bytes, extra_args);
        if (action >= 0)
                return action;
        protocol = pckt.flow.proto;