-
Notifications
You must be signed in to change notification settings - Fork 579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add vagrant VM support and XDP_USE_NEED_WAKEUP for advanced03 #70
Open
chaudron
wants to merge
4
commits into
xdp-project:master
Choose a base branch
from
chaudron:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d3c1045
vagrant: add vagrant support to build latest bpf-next in VM
chaudron eaf1e96
advanced03: add support for the XDP_USE_NEED_WAKEUP API
chaudron ce93ed3
advanced03: add some basic kernel version checking for AF_XDP support
chaudron 3f89b0e
advanced03: fix compilation of custom xdp program on older kernels
chaudron File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,3 +66,6 @@ trace_load_and_stats | |
trace_load_and_stats | ||
trace_read | ||
xdp_sample_pkts_user | ||
|
||
# Vagrant directory | ||
.vagrant/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
/* SPDX-License-Identifier: GPL-2.0 */ | ||
|
||
#include <linux/bpf.h> | ||
#include <linux/version.h> | ||
|
||
#include "bpf_helpers.h" | ||
|
||
|
@@ -18,6 +19,17 @@ struct bpf_map_def SEC("maps") xdp_stats_map = { | |
.max_entries = 64, | ||
}; | ||
|
||
#if LINUX_VERSION_CODE < KERNEL_VERSION(5,3,0) | ||
|
||
/* Kernel version before 5.3 needed an additional map */ | ||
struct bpf_map_def SEC("maps") qidconf_map = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see this map referred to anywhere; how is it actually used on those old kernels? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Think this is part of the older libbpf installing int |
||
.type = BPF_MAP_TYPE_ARRAY, | ||
.key_size = sizeof(int), | ||
.value_size = sizeof(int), | ||
.max_entries = 64, | ||
}; | ||
#endif | ||
|
||
SEC("xdp_sock") | ||
int xdp_sock_prog(struct xdp_md *ctx) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# -*- fill-column: 76; -*- | ||
#+TITLE: Vagrant image for xdp-tutorial with latest bpf-next kernel | ||
#+OPTIONS: ^:nil | ||
|
||
This Vagrant configuration can be used to test the xdp-tutorial using a | ||
virtual machine based on Fedora29 with the latest bpf-next kernel. | ||
|
||
* Configure Vagrant | ||
This example uses the libvirt back-end, which needs to be installed: | ||
|
||
#+begin_example sh | ||
vagrant plugin install vagrant-libvirt | ||
#+end_example | ||
|
||
In addition, we also need the /reload/ plugin to reboot the machine: | ||
|
||
#+begin_example sh | ||
vagrant plugin install vagrant-reload | ||
#+end_example | ||
|
||
|
||
* Configure the virtual machine | ||
The more cores and memory you will assign to the VM the faster it will build | ||
the kernel. Please modify the Valgrantfile to change the default 8 cores and | ||
4G of memory: | ||
|
||
#+begin_example ruby | ||
config.vm.provider :libvirt do |libvirt| | ||
libvirt.cpus = 8 | ||
libvirt.memory = 4096 | ||
libvirt.storage :file, :size => '50G', :bus => 'scsi' | ||
end | ||
#+end_example | ||
|
||
|
||
* Start the Vagrant vm | ||
To start the virtual machine you need to execute the below from the vagrant | ||
directory: | ||
|
||
#+begin_example sh | ||
$ vagrant up | ||
Bringing machine 'default' up with 'libvirt' provider... | ||
==> default: Checking if box 'generic/fedora29' version '1.9.24' is up to date... | ||
==> default: Creating image (snapshot of base box volume). | ||
==> default: Creating domain with the following settings... | ||
==> default: -- Name: vagrant_default | ||
==> default: -- Domain type: kvm | ||
==> default: -- Cpus: 8 | ||
==> default: -- Feature: acpi | ||
... | ||
... | ||
default: -D __BPF_TRACING__ \ | ||
default: -I../libbpf/src//root/usr/include/ -g -I/usr/include/x86_64-linux-gnu -I../headers/ \ | ||
default: -Wall \ | ||
default: -Wno-unused-value \ | ||
default: -Wno-pointer-sign \ | ||
default: -Wno-compare-distinct-pointer-types \ | ||
default: -Werror \ | ||
default: -O2 -emit-llvm -c -g -o af_xdp_kern.ll af_xdp_kern.c | ||
default: llc -march=bpf -filetype=obj -o af_xdp_kern.o af_xdp_kern.ll | ||
default: make[1]: Leaving directory '/home/vagrant/xdp-tutorial/advanced03-AF_XDP' | ||
#+end_example | ||
|
||
NOTE: The above will take some time as it will build the kernel from scratch. | ||
|
||
If the installation completed successfully you can access the VM as follows: | ||
|
||
#+begin_example sh | ||
$ vagrant ssh default | ||
[vagrant@xdp-tutorial ~]$ ls | ||
dp-tutorial | ||
[vagrant@xdp-tutorial ~]$ cd xdp-tutorial/advanced03-AF_XDP/ | ||
[vagrant@xdp-tutorial advanced03-AF_XDP]$ | ||
[vagrant@xdp-tutorial advanced03-AF_XDP]$ ls | ||
af_xdp_kern.c af_xdp_kern.o af_xdp_user.c README.org | ||
af_xdp_kern.ll af_xdp_user Makefile | ||
#+end_example |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# | ||
# NOTE: This script requeres the reload pluging, install it as follows: | ||
# vagrant plugin install vagrant-reload | ||
# | ||
|
||
Vagrant.configure("2") do |config| | ||
|
||
config.vm.provider :libvirt do |libvirt| | ||
libvirt.cpus = 8 | ||
libvirt.memory = 4096 | ||
libvirt.storage :file, :size => '50G', :bus => 'scsi' | ||
# libvirt.storage_pool_path = '/home/user/.local/share/libvirt/images' | ||
end | ||
|
||
config.vm.box = "generic/fedora29" | ||
config.vm.hostname = "xdp-tutorial" | ||
|
||
config.vm.provision :shell, path: "bootstrap.sh" | ||
config.vm.provision :reload | ||
config.vm.provision :shell, privileged: false, path: "bootstrap_post_kernel.sh" | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#!/usr/bin/env bash | ||
|
||
# | ||
# Install required packages | ||
# | ||
dnf install -y \ | ||
bc \ | ||
bpftool \ | ||
clang \ | ||
elfutils-libelf-devel \ | ||
emacs-nox \ | ||
fedora-packager \ | ||
fedpkg \ | ||
flex bison \ | ||
kernel-headers \ | ||
libpcap-devel \ | ||
llvm \ | ||
ncurses-devel \ | ||
openssl-devel \ | ||
perf \ | ||
pesign \ | ||
rpmdevtools | ||
|
||
# | ||
# Initialize the extra disk needed to build the kernel | ||
# | ||
if ! grep -q $(blkid /dev/sdb1 -o value -s UUID) /etc/fstab | ||
then | ||
parted /dev/sdb mklabel gpt | ||
parted /dev/sdb mkpart primary 0% 100% | ||
mkfs.xfs /dev/sdb1 | ||
mkdir /data | ||
echo "UUID=$(blkid /dev/sdb1 -o value -s UUID) /data xfs defaults 0 0" >> /etc/fstab | ||
mount /data | ||
fi | ||
|
||
# | ||
# Build the latest bpf-next kernel | ||
# | ||
cd /data | ||
git clone https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git linux_kernel | ||
# This was successfully tested with commit bdb15a29cc28f8155e20f7fb58b60ffc452f2d1b | ||
cd linux_kernel | ||
cp /boot/config-$(uname -r) .config | ||
make olddefconfig | ||
make -j $(nproc) bzImage | ||
make -j $(nproc) modules | ||
make modules_install | ||
make headers_install | ||
make install | ||
|
||
# | ||
# Boot the new kernel, and make sure IPv6 is enabled | ||
# | ||
grubby --set-default-index=1 | ||
sed -i 's/net.ipv6.conf.all.disable_ipv6 = 1/net.ipv6.conf.all.disable_ipv6 = 0/g' /etc/sysctl.conf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env bash | ||
|
||
# | ||
# Clone and build the tutorial | ||
# | ||
git clone --recurse-submodules https://github.com/xdp-project/xdp-tutorial.git | ||
# This was successfully tested with commit 94471eed572a733a71b096975b3cb72509113e6f | ||
cd xdp-tutorial | ||
make |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not the right approach to check against a kernel version.
(Because distros will backport changes)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, but due to the lack of any run-time checks, what would you suggest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead we have to write a bpf probe that can detect this (like bpftool does).
@tohojo have added a configure script in his XDP-tools repo.
In this case, we likely need to confine the check to the
advanced03-AF_XDP/
directory, and we can likely add it as part of the Makefile.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The configure script just sets some variables; so we can do that in the top-level and only react to them in advanced03. I've been meaning to port over some of the build stuff I did in xdp-tools to this repo anyway, so this sounds like a way forward :)