Centos-kernel-stream-9/samples/bpf
Herton R. Krzesinski a1b9805d99 kbuild: use $(src) instead of $(srctree)/$(src) for source directory
JIRA: https://issues.redhat.com/browse/RHEL-107194

commit b1992c3772e69a6fd0e3fc81cd4d2820c8b6eca0
Author: Masahiro Yamada <masahiroy@kernel.org>
Date:   Sat Apr 27 23:55:02 2024 +0900

    kbuild: use $(src) instead of $(srctree)/$(src) for source directory

    Kbuild conventionally uses $(obj)/ for generated files, and $(src)/ for
    checked-in source files. It is merely a convention without any functional
    difference. In fact, $(obj) and $(src) are exactly the same, as defined
    in scripts/Makefile.build:

        src := $(obj)

    When the kernel is built in a separate output directory, $(src) does
    not accurately reflect the source directory location. While Kbuild
    resolves this discrepancy by specifying VPATH=$(srctree) to search for
    source files, it does not cover all cases. For example, when adding a
    header search path for local headers, -I$(srctree)/$(src) is typically
    passed to the compiler.

    This introduces inconsistency between upstream and downstream Makefiles
    because $(src) is used instead of $(srctree)/$(src) for the latter.

    To address this inconsistency, this commit changes the semantics of
    $(src) so that it always points to the directory in the source tree.

    Going forward, the variables used in Makefiles will have the following
    meanings:

      $(obj)     - directory in the object tree
      $(src)     - directory in the source tree  (changed by this commit)
      $(objtree) - the top of the kernel object tree
      $(srctree) - the top of the kernel source tree

    Consequently, $(srctree)/$(src) in upstream Makefiles need to be replaced
    with $(src).

    Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
    Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>

Conflicts:

There is a extensive list of fixes/conflicts due the amount of files originally
changed by this commit, plus the difference of rhel-9 code against upstream. All
conflicts/differences are listed below:

- Context difference at Documentation/Makefile since RHEL 9 does not have the
  change "docs: allow to pass extra DOCS_CSS themes via make" and later changes.
- Conflict at Documentation/devicetree/bindings/Makefile, patch find_cmd instead
  of find_all_cmd since RHEL-9 doesn't have "dt-bindings: Consider
  DT_SCHEMA_FILES when finding all json-schema", "dt-bindings: kbuild: Split
  targets out to separate rules" and later changes.
- Conflict at Documentation/kbuild/makefiles.rst due different identation since
  RHEL-9 doesn't have the change "docs/kbuild/makefiles: clean up indentation
  and whitespace"
- Patched additional $(srctree)/$(src) references at:
   * arch/arm/mach-davinci/Makefile
   * arch/arm/mach-omap2/Makefile
   * arch/arm/mach-spear/Makefile
   * arch/arm/plat-pxa/Makefile
   * arch/arm/plat-versatile/Makefile
   * arch/ia64/kernel/Makefile
   * arch/nds32/boot/Makefile
   * arch/nds32/kernel/vdso/Makefile
   * drivers/net/ethernet/hisilicon/hns3/hns3pf/Makefile
   * drivers/net/ethernet/hisilicon/hns3/hns3vf/Makefile
   * drivers/staging/rtl8188eu/Makefile
   * drivers/staging/unisys/visorhba/Makefile
   * drivers/staging/unisys/visornic/Makefile
   * scripts/gcc-plugins/Makefile
  Since RHEL-9 does not have later upstream changes that dropped/made those
  references uneeded.
- Conflict at arch/arm/mach-s3c/Makefile since RHEL-9 doesn't have
  "ARM: s3c: remove s3c24xx specific hacks" and related changes. Also,
  extra locations needed patching because of not having the changes
  "ARM: s3c: remove all s3c24xx support" and "ARM: s3c: fix include path".
  Due lacking the last change also arch/arm/mach-s3c/Makefile.s3c64xx needs
  additional two places patched as well.
- Conflict at arch/arm/plat-orion/Makefile since RHEL-9 doesn't have
  the commit "ARM: orion: fix include path" and its previous related
  changes.
- Dropped changes for arch/loongarch since it doesn't exist on rhel-9
- Dropped changes to arch/parisc/kernel/{vdso32,vdso64}/Makefile since RHEL 9
  does not have the change "parisc: Add vDSO support" and later updates to it.
- Dropped change to arch/riscv/kernel/compat_vdso/Makefile since RHEL 9 does
  not have the change "riscv: compat: vdso: Add COMPAT_VDSO base code implementation"
- Dropped change to arch/riscv/kvm/Makefile since there is no KVM support/commits
  in RHEL 9 for riscv.
- Apply change for arch/riscv/kernel/vdso/Makefile in a different place since
  RHEL-9 does not have the change "riscv: explicitly use symbol offsets for VDSO"
  which changed the location of the $(srctree)/$(src) reference
- Dropped change to certs/Makefile related to check-blacklist-hashes.awk since
  that script was only added with commit "certs: Check that builtin blacklist
  hashes are valid" which is not backported/available in RHEL 9 code right now.
- Dropped change to drivers/md/dm-vdo/Makefile since dm-vdo was never backported
  to RHEL-9 main.
- Dropped change to drivers/net/ethernet/fungible/funeth/Makefile since fungible
  ethernet driver/devices code is not available/backported to RHEL-9.
- Fixed conflict at drivers/net/ethernet/hisilicon/hns3/Makefile since RHEL-9
  does not have the change "net: hns3: refactor hns3 makefile to support
  hns3_common module"
- Fixed conflict at drivers/net/wireless/intel/iwlwifi/mvm/Makefile due already
  backported commit "wifi: iwlwifi: mvm: implement link grading"
- Dropped change to init/Makefile since we are not backporting
  "kbuild: build init/built-in.a just once" that introduced the section patched.
- Dropped change to rust/Makefile since there is no rust support backported
  to RHEL-9.
- Fixed conflict at scripts/dtc/Makefile since RHEL-9 does not have the change
  "dt-bindings: kbuild: Use DTB files for validation"
- Dropped change to security/tomoyo/Makefile since it's not needed, it's just
  reverting the change "tomoyo: fix broken dependency on *.conf.default" which
  was never applied to RHEL-9. However, we also bring a different change/patch
  location since RHEL-9 does not have the change "tomoyo: Omit use of bin2c".
- Dropped change to usr/include/Makefile since "kbuild: move headers_check.pl to
  usr/include/" is not being backported to RHEL-9.
- Misc/minor context differences at other places.

Signed-off-by: Herton R. Krzesinski <herton@redhat.com>
2025-08-19 20:06:24 -03:00
..
gnu bpf: Replace deprecated -target with --target= for Clang 2023-12-14 15:22:22 +01:00
.gitignore samples/bpf: Update .gitignore 2022-06-03 17:23:40 +03:00
Makefile kbuild: use $(src) instead of $(srctree)/$(src) for source directory 2025-08-19 20:06:24 -03:00
Makefile.target samples/bpf: Clean up samples/bpf build failes 2022-08-24 12:53:44 +02:00
README.rst samples/bpf: README: Update build dependencies required 2023-12-15 09:28:52 +01:00
asm_goto_workaround.h
bpf_insn.h samples/bpf: Relicense bpf_insn.h as GPL-2.0-only OR BSD-2-Clause 2022-04-29 18:17:13 +02:00
cookie_uid_helper_example.c samples/bpf: Get rid of deprecated libbpf API uses 2022-08-24 12:53:44 +02:00
cpustat_kern.c bpf: Remove unused variable "prev_state" 2024-11-26 08:57:39 +01:00
cpustat_user.c samples/bpf: Use %lu format specifier for unsigned long values 2024-06-25 11:07:33 +02:00
do_hbm_test.sh
fds_example.c samples: bpf: Replace sizeof(arr)/sizeof(arr[0]) with ARRAY_SIZE 2023-01-05 15:46:38 +01:00
hash_func01.h
hbm.c samples/bpf: Fix fout leak in hbm's run_bpf_prog 2023-09-22 09:12:37 +02:00
hbm.h
hbm_edt_kern.c samples/bpf: Fix double word in comments 2023-04-28 11:42:53 +02:00
hbm_kern.h samples/bpf: Fix build error due to -isystem removal 2022-04-19 15:52:59 +02:00
hbm_out_kern.c
ibumad_kern.c bpf: use canonical ftrace path 2023-09-22 09:12:16 +02:00
ibumad_user.c samples/bpf: Use libbpf 1.0 API mode instead of RLIMIT_MEMLOCK 2022-11-28 16:48:58 +02:00
lathist_kern.c
lathist_user.c
lwt_len_hist.bpf.c samples/bpf: change _kern suffix to .bpf with BPF test programs 2023-06-13 22:44:39 +02:00
lwt_len_hist.sh bpf: use canonical ftrace path 2023-09-22 09:12:16 +02:00
lwt_len_hist_user.c
map_perf_test.bpf.c samples/bpf: Use BPF_KSYSCALL macro in syscall tracing programs 2023-06-13 22:44:32 +02:00
map_perf_test_user.c bpf: Replace bpf_lpm_trie_key 0-length array with flexible array 2024-10-15 10:49:11 +02:00
net_shared.h samples/bpf: convert to vmlinux.h with tracing programs 2023-12-15 09:28:58 +01:00
offwaketime.bpf.c samples/bpf: make tracing programs to be more CO-RE centric 2023-12-15 09:28:58 +01:00
offwaketime_user.c samples/bpf: unify bpf program suffix to .bpf with tracing programs 2023-12-15 09:28:58 +01:00
parse_ldabs.c
parse_simple.c
parse_varlen.c
run_cookie_uid_helper_example.sh
sampleip_kern.c
sampleip_user.c samples/bpf: sampleip: Replace PAGE_OFFSET with _text address 2023-09-22 09:12:30 +02:00
sock_example.c samples: bpf: Replace sizeof(arr)/sizeof(arr[0]) with ARRAY_SIZE 2023-01-05 15:46:38 +01:00
sock_example.h
sock_flags.bpf.c samples/bpf: change _kern suffix to .bpf with BPF test programs 2023-06-13 22:44:39 +02:00
sockex1_kern.c
sockex1_user.c samples/bpf: Get rid of deprecated libbpf API uses 2022-08-24 12:53:44 +02:00
sockex2_kern.c
sockex2_user.c samples/bpf: Use libbpf 1.0 API mode instead of RLIMIT_MEMLOCK 2022-11-28 16:48:58 +02:00
sockex3_kern.c samples/bpf: Fix sockex3 error: Missing BPF prog type 2023-01-05 15:46:50 +01:00
sockex3_user.c samples/bpf: Fix sockex3 error: Missing BPF prog type 2023-01-05 15:46:50 +01:00
spintest.bpf.c samples/bpf: simplify spintest with kprobe.multi 2023-12-15 09:28:58 +01:00
spintest_user.c samples/bpf: simplify spintest with kprobe.multi 2023-12-15 09:28:58 +01:00
syscall_nrs.c
syscall_tp_kern.c samples: bpf: Fix syscall_tp openat argument 2024-03-27 10:27:56 +01:00
syscall_tp_user.c samples/bpf: syscall_tp_user: Fix array out-of-bound access 2024-03-27 10:27:49 +01:00
task_fd_query_kern.c samples/bpf: Replace blk_account_io_done() with __blk_account_io_done() 2023-03-06 14:54:14 +01:00
task_fd_query_user.c bpf: use canonical ftrace path 2023-09-22 09:12:16 +02:00
tc_l2_redirect.sh samples/bpf: ensure ipv6 is enabled before running tests 2023-06-13 22:44:36 +02:00
tc_l2_redirect_kern.c
tc_l2_redirect_user.c
tcbpf1_kern.c
tcp_basertt_kern.c samples/bpf: Fix buffer overflow in tcp_basertt 2023-10-12 11:40:58 +02:00
tcp_bpf.readme
tcp_bufs_kern.c
tcp_clamp_kern.c
tcp_cong_kern.c
tcp_dumpstats_kern.c
tcp_iw_kern.c
tcp_rwnd_kern.c
tcp_synrto_kern.c
tcp_tos_reflect_kern.c
test_cgrp2_array_pin.c samples/bpf: Get rid of deprecated libbpf API uses 2022-08-24 12:53:44 +02:00
test_cgrp2_attach.c samples: bpf: Replace sizeof(arr)/sizeof(arr[0]) with ARRAY_SIZE 2023-01-05 15:46:38 +01:00
test_cgrp2_sock.c samples/bpf: Get rid of deprecated libbpf API uses 2022-08-24 12:53:44 +02:00
test_cgrp2_sock.sh samples/bpf: refactor BPF functionality testing scripts 2023-06-13 22:44:37 +02:00
test_cgrp2_sock2.c
test_cgrp2_sock2.sh samples/bpf: change _kern suffix to .bpf with BPF test programs 2023-06-13 22:44:39 +02:00
test_cgrp2_tc.bpf.c samples/bpf: change _kern suffix to .bpf with BPF test programs 2023-06-13 22:44:39 +02:00
test_cgrp2_tc.sh samples/bpf: change _kern suffix to .bpf with BPF test programs 2023-06-13 22:44:39 +02:00
test_cls_bpf.sh
test_current_task_under_cgroup.bpf.c samples/bpf: Use BPF_KSYSCALL macro in syscall tracing programs 2023-06-13 22:44:32 +02:00
test_current_task_under_cgroup_user.c samples/bpf: Change _kern suffix to .bpf with syscall tracing program 2023-06-13 22:44:31 +02:00
test_lru_dist.c samples/bpf: remove unused function with test_lru_dist 2023-06-13 22:44:23 +02:00
test_lwt_bpf.c samples/bpf: use vmlinux.h instead of implicit headers in BPF test program 2023-06-13 22:44:39 +02:00
test_lwt_bpf.sh bpf: Replace deprecated -target with --target= for Clang 2023-12-14 15:22:22 +01:00
test_map_in_map.bpf.c samples/bpf: refactor syscall tracing programs using BPF_KSYSCALL macro 2023-12-15 09:28:58 +01:00
test_map_in_map_user.c samples/bpf: Use bpf_{btf,link,map,prog}_get_info_by_fd() 2023-06-13 22:45:39 +02:00
test_overhead_kprobe.bpf.c samples/bpf: make tracing programs to be more CO-RE centric 2023-12-15 09:28:58 +01:00
test_overhead_raw_tp.bpf.c samples/bpf: change _kern suffix to .bpf with BPF test programs 2023-06-13 22:44:39 +02:00
test_overhead_tp.bpf.c samples/bpf: convert to vmlinux.h with tracing programs 2023-12-15 09:28:58 +01:00
test_overhead_user.c samples/bpf: change _kern suffix to .bpf with BPF test programs 2023-06-13 22:44:39 +02:00
test_override_return.sh samples: bpf: Fix tracex7 error raised on the missing argument 2022-04-29 18:14:35 +02:00
test_probe_write_user.bpf.c samples/bpf: Use BPF_KSYSCALL macro in syscall tracing programs 2023-06-13 22:44:32 +02:00
test_probe_write_user_user.c samples/bpf: Change _kern suffix to .bpf with syscall tracing program 2023-06-13 22:44:31 +02:00
trace_event_kern.c
trace_event_user.c
trace_output.bpf.c samples/bpf: Change _kern suffix to .bpf with syscall tracing program 2023-06-13 22:44:31 +02:00
trace_output_user.c samples/bpf: Change _kern suffix to .bpf with syscall tracing program 2023-06-13 22:44:31 +02:00
tracex1.bpf.c samples/bpf: make tracing programs to be more CO-RE centric 2023-12-15 09:28:58 +01:00
tracex1_user.c samples/bpf: unify bpf program suffix to .bpf with tracing programs 2023-12-15 09:28:58 +01:00
tracex2.bpf.c samples/bpf: Fix tracex2 by using BPF_KSYSCALL macro 2023-06-13 22:44:31 +02:00
tracex2_user.c samples/bpf: Change _kern suffix to .bpf with syscall tracing program 2023-06-13 22:44:31 +02:00
tracex3.bpf.c samples/bpf: fix bio latency check with tracepoint 2023-12-15 09:28:58 +01:00
tracex3_user.c samples/bpf: unify bpf program suffix to .bpf with tracing programs 2023-12-15 09:28:58 +01:00
tracex4.bpf.c samples/bpf: tracex4: Fix failed to create kretprobe 'kmem_cache_alloc_node+0x0' 2025-01-21 11:27:00 +01:00
tracex4_user.c samples/bpf: unify bpf program suffix to .bpf with tracing programs 2023-12-15 09:28:58 +01:00
tracex5.bpf.c samples/bpf: make tracing programs to be more CO-RE centric 2023-12-15 09:28:58 +01:00
tracex5_user.c samples/bpf: unify bpf program suffix to .bpf with tracing programs 2023-12-15 09:28:58 +01:00
tracex6.bpf.c samples/bpf: fix broken map lookup probe 2023-12-15 09:28:58 +01:00
tracex6_user.c samples/bpf: unify bpf program suffix to .bpf with tracing programs 2023-12-15 09:28:58 +01:00
tracex7.bpf.c samples/bpf: unify bpf program suffix to .bpf with tracing programs 2023-12-15 09:28:58 +01:00
tracex7_user.c samples/bpf: unify bpf program suffix to .bpf with tracing programs 2023-12-15 09:28:58 +01:00
xdp1_kern.c samples/bpf: fixup some tools to be able to support xdp multibuffer 2023-01-05 15:46:50 +01:00
xdp1_user.c samples/bpf: Use bpf_{btf,link,map,prog}_get_info_by_fd() 2023-06-13 22:45:39 +02:00
xdp2_kern.c samples/bpf: Fix MAC address swapping in xdp2_kern 2023-01-05 15:46:53 +01:00
xdp2skb_meta.sh
xdp2skb_meta_kern.c
xdp_adjust_tail_kern.c
xdp_adjust_tail_user.c samples/bpf: Use bpf_{btf,link,map,prog}_get_info_by_fd() 2023-06-13 22:45:39 +02:00
xdp_fwd_kern.c
xdp_fwd_user.c samples/bpf: Use bpf_{btf,link,map,prog}_get_info_by_fd() 2023-06-13 22:45:39 +02:00
xdp_monitor.bpf.c samples: bpf: Convert xdp_monitor_kern.o to XDP samples helper 2022-04-29 18:14:46 +02:00
xdp_monitor_user.c samples/bpf: Use libbpf 1.0 API mode instead of RLIMIT_MEMLOCK 2022-11-28 16:48:58 +02:00
xdp_redirect.bpf.c samples: bpf: Convert xdp_redirect_kern.o to XDP samples helper 2022-04-29 18:14:46 +02:00
xdp_redirect_cpu.bpf.c samples/bpf: Update cpumap/devmap sec_name 2022-10-25 14:57:54 +02:00
xdp_redirect_cpu_user.c samples/bpf: Use bpf_{btf,link,map,prog}_get_info_by_fd() 2023-06-13 22:45:39 +02:00
xdp_redirect_map.bpf.c samples/bpf: Fix xdp_redirect_map egress devmap prog 2023-01-05 15:46:52 +01:00
xdp_redirect_map_multi.bpf.c samples/bpf: Update cpumap/devmap sec_name 2022-10-25 14:57:54 +02:00
xdp_redirect_map_multi_user.c samples/bpf: Use libbpf 1.0 API mode instead of RLIMIT_MEMLOCK 2022-11-28 16:48:58 +02:00
xdp_redirect_map_user.c samples/bpf: Fix xdp_redirect_map egress devmap prog 2023-01-05 15:46:52 +01:00
xdp_redirect_user.c samples/bpf: Use libbpf 1.0 API mode instead of RLIMIT_MEMLOCK 2022-11-28 16:48:58 +02:00
xdp_router_ipv4.bpf.c sample: bpf: xdp_router_ipv4: Allow the kernel to send arp requests 2022-11-30 12:47:07 +02:00
xdp_router_ipv4_user.c bpf: Replace bpf_lpm_trie_key 0-length array with flexible array 2024-10-15 10:49:11 +02:00
xdp_rxq_info_kern.c
xdp_rxq_info_user.c samples/bpf: Use bpf_{btf,link,map,prog}_get_info_by_fd() 2023-06-13 22:45:39 +02:00
xdp_sample.bpf.c samples: bpf: Add BPF support for devmap_xmit tracepoint 2022-04-29 18:14:45 +02:00
xdp_sample.bpf.h samples/bpf: split common macros to net_shared.h 2023-06-13 22:44:38 +02:00
xdp_sample_pkts_kern.c
xdp_sample_pkts_user.c samples/bpf: Use bpf_{btf,link,map,prog}_get_info_by_fd() 2023-06-13 22:45:39 +02:00
xdp_sample_shared.h samples: bpf: Add basic infrastructure for XDP samples 2022-04-29 18:14:44 +02:00
xdp_sample_user.c samples/bpf: Use libbpf 1.0 API mode instead of RLIMIT_MEMLOCK 2022-11-28 16:48:58 +02:00
xdp_sample_user.h samples/bpf: use preferred getters/setters instead of deprecated ones 2022-10-25 14:57:44 +02:00
xdp_tx_iptunnel_common.h
xdp_tx_iptunnel_kern.c samples/bpf: fixup some tools to be able to support xdp multibuffer 2023-01-05 15:46:50 +01:00
xdp_tx_iptunnel_user.c samples/bpf: Use bpf_{btf,link,map,prog}_get_info_by_fd() 2023-06-13 22:45:39 +02:00

README.rst

eBPF sample programs
====================

This directory contains a test stubs, verifier test-suite and examples
for using eBPF. The examples use libbpf from tools/lib/bpf.

Build dependencies
==================

Compiling requires having installed:
 * clang
 * llvm
 * pahole

Consult :ref:`Documentation/process/changes.rst <changes>` for the minimum
version numbers required and how to update them. Note that LLVM's tool
'llc' must support target 'bpf', list version and supported targets with
command: ``llc --version``

Clean and configuration
-----------------------

It can be needed to clean tools, samples or kernel before trying new arch or
after some changes (on demand)::

 make -C tools clean
 make -C samples/bpf clean
 make clean

Configure kernel, defconfig for instance
(see "tools/testing/selftests/bpf/config" for a reference config)::

 make defconfig

Kernel headers
--------------

There are usually dependencies to header files of the current kernel.
To avoid installing devel kernel headers system wide, as a normal
user, simply call::

 make headers_install

This will create a local "usr/include" directory in the git/build top
level directory, that the make system will automatically pick up first.

Compiling
=========

For building the BPF samples, issue the below command from the kernel
top level directory::

 make M=samples/bpf

It is also possible to call make from this directory.  This will just
hide the invocation of make as above.

Manually compiling LLVM with 'bpf' support
------------------------------------------

Since version 3.7.0, LLVM adds a proper LLVM backend target for the
BPF bytecode architecture.

By default llvm will build all non-experimental backends including bpf.
To generate a smaller llc binary one can use::

 -DLLVM_TARGETS_TO_BUILD="BPF"

We recommend that developers who want the fastest incremental builds
use the Ninja build system, you can find it in your system's package
manager, usually the package is ninja or ninja-build.

Quick sniplet for manually compiling LLVM and clang
(build dependencies are ninja, cmake and gcc-c++)::

 $ git clone https://github.com/llvm/llvm-project.git
 $ mkdir -p llvm-project/llvm/build
 $ cd llvm-project/llvm/build
 $ cmake .. -G "Ninja" -DLLVM_TARGETS_TO_BUILD="BPF;X86" \
            -DLLVM_ENABLE_PROJECTS="clang"    \
            -DCMAKE_BUILD_TYPE=Release        \
            -DLLVM_BUILD_RUNTIME=OFF
 $ ninja

It is also possible to point make to the newly compiled 'llc' or
'clang' command via redefining LLC or CLANG on the make command line::

 make M=samples/bpf LLC=~/git/llvm-project/llvm/build/bin/llc CLANG=~/git/llvm-project/llvm/build/bin/clang

Cross compiling samples
-----------------------
In order to cross-compile, say for arm64 targets, export CROSS_COMPILE and ARCH
environment variables before calling make. But do this before clean,
configuration and header install steps described above. This will direct make to
build samples for the cross target::

 export ARCH=arm64
 export CROSS_COMPILE="aarch64-linux-gnu-"

Headers can be also installed on RFS of target board if need to keep them in
sync (not necessarily and it creates a local "usr/include" directory also)::

 make INSTALL_HDR_PATH=~/some_sysroot/usr headers_install

Pointing LLC and CLANG is not necessarily if it's installed on HOST and have
in its targets appropriate arm64 arch (usually it has several arches).
Build samples::

 make M=samples/bpf

Or build samples with SYSROOT if some header or library is absent in toolchain,
say libelf, providing address to file system containing headers and libs,
can be RFS of target board::

 make M=samples/bpf SYSROOT=~/some_sysroot