[SOLVED] Proxmox VE with XDP

Lidorelias

New Member
Nov 24, 2020
6
0
1
23
Hey, I want to use an XDP program in Proxmox VE 6.2-1 (Linux pve 5.4.78-2-pve)
I already installed with apt the following packages:
python3-bcc​
bpfcc-tools​
python3-bpfcc​
libbpfcc​
libbpfcc-dev​
pve-headers-5.4.78-2-pve​
Then, I wrote a python file and a .c file:

Python
Python:
from bcc import BPF
b = BPF(src_file="test.c")

test.c
C:
// I added the following lines because I got a lot of errors about asm_inline
#ifdef asm_inline
#undef asm_inline
#define asm_inline asm
#endif

#include <linux/bpf.h>
int test(struct xdp_md *ctx)
{
    bpf_trace_printk("hello\n");
    return XDP_PASS;
}

After finally making the python importing BPF from bcc, the python unable to compile the c file and throw the following errors:
Code:
In file included from /virtual/main.c:7:
include/linux/bpf.h:118:3: error: variable has incomplete type 'struct bpf_spin_lock'
                (struct bpf_spin_lock){};
                ^~~~~~~~~~~~~~~~~~~~~~~~
include/linux/bpf.h:117:11: note: forward declaration of 'struct bpf_spin_lock'
        *(struct bpf_spin_lock *)(dst + map->spin_lock_off) =
                 ^
include/linux/bpf.h:128:22: error: invalid application of 'sizeof' to an incomplete type 'struct bpf_spin_lock'
                memcpy(dst + off + sizeof(struct bpf_spin_lock),
                                   ^     ~~~~~~~~~~~~~~~~~~~~~~
include/linux/bpf.h:128:36: note: forward declaration of 'struct bpf_spin_lock'
                memcpy(dst + off + sizeof(struct bpf_spin_lock),
                                                 ^
include/linux/bpf.h:129:22: error: invalid application of 'sizeof' to an incomplete type 'struct bpf_spin_lock'
                       src + off + sizeof(struct bpf_spin_lock),
                                   ^     ~~~~~~~~~~~~~~~~~~~~~~
include/linux/bpf.h:128:36: note: forward declaration of 'struct bpf_spin_lock'
                memcpy(dst + off + sizeof(struct bpf_spin_lock),
                                                 ^
include/linux/bpf.h:130:34: error: invalid application of 'sizeof' to an incomplete type 'struct bpf_spin_lock'
                       map->value_size - off - sizeof(struct bpf_spin_lock));
                                               ^     ~~~~~~~~~~~~~~~~~~~~~~
include/linux/bpf.h:128:36: note: forward declaration of 'struct bpf_spin_lock'
                memcpy(dst + off + sizeof(struct bpf_spin_lock),
                                                 ^
include/linux/bpf.h:457:39: error: use of undeclared identifier 'BPF_F_RDONLY_PROG'
        u32 access_flags = map->map_flags & (BPF_F_RDONLY_PROG | BPF_F_WRONLY_PROG);
                                             ^
include/linux/bpf.h:457:59: error: use of undeclared identifier 'BPF_F_WRONLY_PROG'
        u32 access_flags = map->map_flags & (BPF_F_RDONLY_PROG | BPF_F_WRONLY_PROG);
                                                                 ^
include/linux/bpf.h:462:21: error: use of undeclared identifier 'BPF_F_RDONLY_PROG'
        if (access_flags & BPF_F_RDONLY_PROG)
                           ^
include/linux/bpf.h:464:26: error: use of undeclared identifier 'BPF_F_WRONLY_PROG'
        else if (access_flags & BPF_F_WRONLY_PROG)
                                ^
include/linux/bpf.h:472:26: error: use of undeclared identifier 'BPF_F_RDONLY_PROG'
        return (access_flags & (BPF_F_RDONLY_PROG | BPF_F_WRONLY_PROG)) !=
                                ^
include/linux/bpf.h:472:46: error: use of undeclared identifier 'BPF_F_WRONLY_PROG'
        return (access_flags & (BPF_F_RDONLY_PROG | BPF_F_WRONLY_PROG)) !=
                                                    ^
include/linux/bpf.h:473:10: error: use of undeclared identifier 'BPF_F_RDONLY_PROG'
               (BPF_F_RDONLY_PROG | BPF_F_WRONLY_PROG);
                ^
include/linux/bpf.h:473:30: error: use of undeclared identifier 'BPF_F_WRONLY_PROG'
               (BPF_F_RDONLY_PROG | BPF_F_WRONLY_PROG);
                                    ^
12 errors generated.
Traceback (most recent call last):
  File "test.py", line 3, in <module>
    b = BPF(src_file="test.c")
  File "/usr/lib/python3/dist-packages/bcc/__init__.py", line 331, in __init__
    raise Exception("Failed to compile BPF module %s" % src_file)
Exception: Failed to compile BPF module b'test.c'

What am I missing? how I can make it works without even get the asm_inline errors? is all of that related to the versions I am using?
I managed to successfully use XDP on a regular ubuntu machine with regular Linux-headers but in Proxmox I didn't.
Thanks for your help.
 
Last edited:
On a hunch - try installing the bpfcc tools (all of the bpf packages you installed above) from the buster backports repository
 
On a hunch - try installing the bpfcc tools (all of the bpf packages you installed above) from the buster backports repository
Thanks for your reply!
How the buster backports repository is different from the regular? I already installed all of bpf packages from apt.
 
the backports repository carries newer version of certain packages:
https://backports.debian.org/

at least in my experience the bpf tools from backports work with the PVE kernels (while the ones in the regular buster repositories don't)

I hope this helps!
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!