Commit b2e086cb authored by Cupertino Miranda's avatar Cupertino Miranda Committed by Andrii Nakryiko
Browse files

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: default avatarCupertino Miranda <cupertino.miranda@oracle.com>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Acked-by: default avatarYonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/bpf/20240507122220.207820-3-cupertino.miranda@oracle.com
parent 207cf6e6
Loading
Loading
Loading
Loading
+21 −6
Original line number Diff line number Diff line
@@ -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;