* Problem with atomic operations on arm32 with BPF
@ 2020-09-07 12:16 David Marcinkovic
2020-09-08 20:07 ` Andrii Nakryiko
0 siblings, 1 reply; 3+ messages in thread
From: David Marcinkovic @ 2020-09-07 12:16 UTC (permalink / raw)
To: bpf; +Cc: Luka Perkov, Borna Cafuk, Juraj Vijtiuk
Hello everyone,
I am trying to run a simple BPF example that uses the
`__sync_fetch_and_add` built-in function for atomic memory access. It
fails with `libbpf: load bpf program failed: ERROR:
strerror_r(524)=22` error message.
This error does not seem to occur on the amd64 architecture. I am
using clang version 10 for both, compiling on amd64 and
cross-compiling for arm32.
I am aware that those built-in functions are available for arm32. [0].
Why is this error occurring?
To demonstrate I have prepared one simple example program that uses
that built-in function for atomic memory access.
Any input is much appreciated,
Best regards,
David Marčinković
[0] https://developer.arm.com/documentation/dui0491/c/compiler-specific-features/gnu-builtin-functions?lang=en
example.c
-------------------
#include <stdio.h>
#include <bpf/libbpf.h>
#include <sys/resource.h>
#include <fcntl.h>
#include <unistd.h>
#include "example.skel.h"
void read_trace_pipe(void)
{
int trace_fd;
trace_fd = open("/sys/kernel/debug/tracing/trace_pipe", O_RDONLY, 0);
if (trace_fd < 0)
return;
while (1) {
static char buf[4096];
ssize_t sz;
sz = read(trace_fd, buf, sizeof(buf) - 1);
if (sz > 0) {
buf[sz] = 0;
puts(buf);
}
}
}
int main()
{
struct example_bpf *obj;
int err;
struct rlimit rlim_new = {
.rlim_cur = RLIM_INFINITY,
.rlim_max = RLIM_INFINITY,
};
err = setrlimit(RLIMIT_MEMLOCK, &rlim_new);
if (err) {
fprintf(stderr, "failed to increase rlimit: %d\n", err);
return 1;
}
obj = example_bpf__open();
if (!obj) {
fprintf(stderr, "failed to open and/or load BPF object\n");
return 1;
}
err = example_bpf__load(obj);
if (err) {
fprintf(stderr, "failed to load BPF object: %d\n", err);
goto cleanup;
}
err = example_bpf__attach(obj);
if (err) {
fprintf(stderr, "failed to attach BPF programs\n");
goto cleanup;
}
read_trace_pipe();
cleanup:
example_bpf__destroy(obj);
return err != 0;
}
example.bpf.c
-------------------
#include "vmlinux.h"
#include <bpf/bpf_helpers.h>
SEC("tracepoint/syscalls/sys_enter_execve")
int tracepoint__syscalls__sys_enter_execve(struct
trace_event_raw_sys_enter *ctx)
{
u32 variable = 0;
__sync_fetch_and_add(&variable, 1);
bpf_printk("Value of variable is: %u\n", variable);
return 0;
}
char LICENSE[] SEC("license") = "GPL";
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Problem with atomic operations on arm32 with BPF
2020-09-07 12:16 Problem with atomic operations on arm32 with BPF David Marcinkovic
@ 2020-09-08 20:07 ` Andrii Nakryiko
2020-09-11 10:14 ` David Marcinkovic
0 siblings, 1 reply; 3+ messages in thread
From: Andrii Nakryiko @ 2020-09-08 20:07 UTC (permalink / raw)
To: David Marcinkovic; +Cc: bpf, Luka Perkov, Borna Cafuk, Juraj Vijtiuk
On Mon, Sep 7, 2020 at 5:18 AM David Marcinkovic
<david.marcinkovic@sartura.hr> wrote:
>
> Hello everyone,
>
> I am trying to run a simple BPF example that uses the
> `__sync_fetch_and_add` built-in function for atomic memory access. It
> fails with `libbpf: load bpf program failed: ERROR:
> strerror_r(524)=22` error message.
>
> This error does not seem to occur on the amd64 architecture. I am
> using clang version 10 for both, compiling on amd64 and
> cross-compiling for arm32.
>
> I am aware that those built-in functions are available for arm32. [0].
> Why is this error occurring?
>
Seems like BPF JIT for arm32 doesn't yet support those atomic
operations, see [0]
[0] https://github.com/torvalds/linux/blob/master/arch/arm/net/bpf_jit_32.c#L1627
You might want to try running in interpreted mode and see if that
works for you. You'll lose speed, but will get functionality you need.
> To demonstrate I have prepared one simple example program that uses
> that built-in function for atomic memory access.
>
> Any input is much appreciated,
>
> Best regards,
> David Marčinković
>
> [0] https://developer.arm.com/documentation/dui0491/c/compiler-specific-features/gnu-builtin-functions?lang=en
>
[...]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Problem with atomic operations on arm32 with BPF
2020-09-08 20:07 ` Andrii Nakryiko
@ 2020-09-11 10:14 ` David Marcinkovic
0 siblings, 0 replies; 3+ messages in thread
From: David Marcinkovic @ 2020-09-11 10:14 UTC (permalink / raw)
To: Andrii Nakryiko; +Cc: bpf, Luka Perkov, Borna Cafuk, Juraj Vijtiuk
On Tue, Sep 8, 2020 at 10:07 PM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
>
> On Mon, Sep 7, 2020 at 5:18 AM David Marcinkovic
> <david.marcinkovic@sartura.hr> wrote:
> >
> > Hello everyone,
> >
> > I am trying to run a simple BPF example that uses the
> > `__sync_fetch_and_add` built-in function for atomic memory access. It
> > fails with `libbpf: load bpf program failed: ERROR:
> > strerror_r(524)=22` error message.
> >
> > This error does not seem to occur on the amd64 architecture. I am
> > using clang version 10 for both, compiling on amd64 and
> > cross-compiling for arm32.
> >
> > I am aware that those built-in functions are available for arm32. [0].
> > Why is this error occurring?
> >
>
> Seems like BPF JIT for arm32 doesn't yet support those atomic
> operations, see [0]
>
> [0] https://github.com/torvalds/linux/blob/master/arch/arm/net/bpf_jit_32.c#L1627
>
> You might want to try running in interpreted mode and see if that
> works for you. You'll lose speed, but will get functionality you need.
Thank you very much for your reply.
The program is working just fine when I disable the BPF Just In Time compiler.
>
> > To demonstrate I have prepared one simple example program that uses
> > that built-in function for atomic memory access.
> >
> > Any input is much appreciated,
> >
> > Best regards,
> > David Marčinković
> >
> > [0] https://developer.arm.com/documentation/dui0491/c/compiler-specific-features/gnu-builtin-functions?lang=en
> >
>
> [...]
I am curious if there is any way to enable or disable the JIT compiler
when starting the BPF program? I am aware that the BPF JIT can be
enabled or disabled by using the `/proc/sys/net/core/bpf_jit_enable`
file, but I would like to know whether there is a way to specify it
programmatically when loading the program. Let's consider one use case
where we want to run two different BPF programs: one with the JIT
compiler, one without it.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-09-11 10:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-07 12:16 Problem with atomic operations on arm32 with BPF David Marcinkovic
2020-09-08 20:07 ` Andrii Nakryiko
2020-09-11 10:14 ` David Marcinkovic
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).