Skip to content

Commit b2e086c

Browse files
cupermiranakryiko
authored andcommitted
selftests/bpf: Change functions definitions to support GCC
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 <[email protected]> Signed-off-by: Andrii Nakryiko <[email protected]> Acked-by: Yonghong Song <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent 207cf6e commit b2e086c

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

tools/testing/selftests/bpf/progs/test_xdp_noinline.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,14 @@ bool encap_v6(struct xdp_md *xdp, struct ctl_value *cval,
318318
return true;
319319
}
320320

321+
#ifndef __clang__
322+
#pragma GCC push_options
323+
/* GCC optimization collapses functions and increases the number of arguments
324+
* beyond the compatible amount supported by BPF.
325+
*/
326+
#pragma GCC optimize("-fno-ipa-sra")
327+
#endif
328+
321329
static __attribute__ ((noinline))
322330
bool encap_v4(struct xdp_md *xdp, struct ctl_value *cval,
323331
struct packet_description *pckt,
@@ -372,6 +380,10 @@ bool encap_v4(struct xdp_md *xdp, struct ctl_value *cval,
372380
return true;
373381
}
374382

383+
#ifndef __clang__
384+
#pragma GCC pop_options
385+
#endif
386+
375387
static __attribute__ ((noinline))
376388
int swap_mac_and_send(void *data, void *data_end)
377389
{
@@ -588,12 +600,13 @@ static void connection_table_lookup(struct real_definition **real,
588600
__attribute__ ((noinline))
589601
static int process_l3_headers_v6(struct packet_description *pckt,
590602
__u8 *protocol, __u64 off,
591-
__u16 *pkt_bytes, void *data,
592-
void *data_end)
603+
__u16 *pkt_bytes, void *extra_args[2])
593604
{
594605
struct ipv6hdr *ip6h;
595606
__u64 iph_len;
596607
int action;
608+
void *data = extra_args[0];
609+
void *data_end = extra_args[1];
597610

598611
ip6h = data + off;
599612
if (ip6h + 1 > data_end)
@@ -619,11 +632,12 @@ static int process_l3_headers_v6(struct packet_description *pckt,
619632
__attribute__ ((noinline))
620633
static int process_l3_headers_v4(struct packet_description *pckt,
621634
__u8 *protocol, __u64 off,
622-
__u16 *pkt_bytes, void *data,
623-
void *data_end)
635+
__u16 *pkt_bytes, void *extra_args[2])
624636
{
625637
struct iphdr *iph;
626638
int action;
639+
void *data = extra_args[0];
640+
void *data_end = extra_args[1];
627641

628642
iph = data + off;
629643
if (iph + 1 > data_end)
@@ -666,13 +680,14 @@ static int process_packet(void *data, __u64 off, void *data_end,
666680
__u8 protocol;
667681
__u32 vip_num;
668682
int action;
683+
void *extra_args[2] = { data, data_end };
669684

670685
if (is_ipv6)
671686
action = process_l3_headers_v6(&pckt, &protocol, off,
672-
&pkt_bytes, data, data_end);
687+
&pkt_bytes, extra_args);
673688
else
674689
action = process_l3_headers_v4(&pckt, &protocol, off,
675-
&pkt_bytes, data, data_end);
690+
&pkt_bytes, extra_args);
676691
if (action >= 0)
677692
return action;
678693
protocol = pckt.flow.proto;

0 commit comments

Comments
 (0)