Problem with atomic operations on arm32 with BPF

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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";




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux