From: Eric Leblond <eric@regit.org>
To: netdev <netdev@vger.kernel.org>
Subject: ebpf: issue with clang
Date: Thu, 09 Jun 2016 23:10:05 +0200 [thread overview]
Message-ID: <1465506605.23482.10.camel@regit.org> (raw)
Hello,
I'm working on integrating ebpf cluster load balancing for AF_PACKET
and I've got some problem to get real code inside the EBPF filter.
I've tried different command lines in the build process. One of them
is:
clang-3.9 -Wall -O2 -emit-llvm -c hash_ports.c -o - | llc-3.9 -march=bpf -filetype=obj -o hash_ports.bpf
If I use that one, then the generated code is almost void. If I remove
the -O2 then I've got a generated code that fails during load. When not
using -O2, I manage to load a trivial filter (return of static value).
The C code is the following (a derivative of http-simple-filter.c used
for testing):
int filter(struct __sk_buff *skb) {
uint8_t *cursor = 0;
struct ethernet_t *ethernet = cursor_advance(cursor, sizeof(*ethernet));
if (!(ethernet->type == (unsigned int)0x0800)) {
goto DEFAULT;
}
struct ip_t *ip = cursor_advance(cursor, sizeof(*ip));
if (ip->nextp != IP_TCP) {
goto DEFAULT;
}
return 1;
DEFAULT:
return 0;
}
And error is as follows
bpf: Permission denied
bpf verifier:
0: (7b) *(u64 *)(r10 -16) = r1
1: (b7) r1 = 0
2: (7b) *(u64 *)(r10 -24) = r1
3: (7b) *(u64 *)(r10 -40) = r1
4: (79) r2 = *(u64 *)(r10 -24)
5: (07) r2 += 14
6: (7b) *(u64 *)(r10 -24) = r2
7: (79) r2 = *(u64 *)(r10 -40)
8: (7b) *(u64 *)(r10 -48) = r2
9: (7b) *(u64 *)(r10 -32) = r2
10: (71) r3 = *(u8 *)(r2 +12)
R2 invalid mem access 'inv'
This has been tested with a 4.6.0 kernel and a 4.5.x kernel.
What did I miss here ?
BR,
--
Eric Leblond <eric@regit.org>
Blog: https://home.regit.org/
next reply other threads:[~2016-06-09 21:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-09 21:10 Eric Leblond [this message]
2016-06-10 0:34 ` ebpf: issue with clang Alexei Starovoitov
2016-06-12 17:37 ` Eric Leblond
2016-06-12 18:35 ` Daniel Borkmann
2016-06-12 20:53 ` Eric Leblond
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1465506605.23482.10.camel@regit.org \
--to=eric@regit.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.