All of lore.kernel.org
 help / color / mirror / Atom feed
* assembler mnenomics for call/tailcall plus maps...
@ 2017-04-27 20:42 David Miller
  2017-04-28  2:06   ` Alexei Starovoitov
  0 siblings, 1 reply; 7+ messages in thread
From: David Miller @ 2017-04-27 20:42 UTC (permalink / raw)
  To: ast, daniel; +Cc: netdev, xdp-newbies


Can you guys give me some kind of idea of how it might be nice to
represent calls and tailcalls in assembler files?

And also the emission of maps.

Right now I just have the assembler looking for 32-bit immediate
values for call and tailcall instructions.

Looking at samples/bpf/sockex3_kern.c we have:

struct bpf_map_def SEC("maps") jmp_table = {
	.type = BPF_MAP_TYPE_PROG_ARRAY,
	.key_size = sizeof(u32),
	.value_size = sizeof(u32),
	.max_entries = 8,
};

#define PARSE_VLAN 1
#define PARSE_MPLS 2
#define PARSE_IP 3
#define PARSE_IPV6 4

/* protocol dispatch routine.
 * It tail-calls next BPF program depending on eth proto
 * Note, we could have used:
 * bpf_tail_call(skb, &jmp_table, proto);
 * but it would need large prog_array
 */
static inline void parse_eth_proto(struct __sk_buff *skb, u32 proto)
{
	switch (proto) {
	case ETH_P_8021Q:
	case ETH_P_8021AD:
		bpf_tail_call(skb, &jmp_table, PARSE_VLAN);
		break;
	case ETH_P_MPLS_UC:
	case ETH_P_MPLS_MC:
		bpf_tail_call(skb, &jmp_table, PARSE_MPLS);
		break;
	case ETH_P_IP:
		bpf_tail_call(skb, &jmp_table, PARSE_IP);
		break;
	case ETH_P_IPV6:
		bpf_tail_call(skb, &jmp_table, PARSE_IPV6);
		break;
	}
}

and these bpf_tail_call() invocations seem to expand to something like:

	call	1 ! PARSE_VLAN
	call	2 ! PARSE_MPLS
	call	3 ! PARSE_IP
	call	4 ! PARSE_IPV6

in the resultant ELF file.

Thanks.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-04-30 15:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-27 20:42 assembler mnenomics for call/tailcall plus maps David Miller
2017-04-28  2:06 ` Alexei Starovoitov
2017-04-28  2:06   ` Alexei Starovoitov
2017-04-29 18:38   ` David Miller
2017-04-30  6:35     ` Alexei Starovoitov
2017-04-30  6:35       ` Alexei Starovoitov
2017-04-30 15:27       ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.