-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new(driver/bpf): added bpf configure system similar to the kmod one.
Then, added fix for rss_stat becoming an array in kernel 6.2. Signed-off-by: Federico Di Pierro <[email protected]>
- Loading branch information
Showing
9 changed files
with
164 additions
and
8 deletions.
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
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
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,45 @@ | ||
# SPDX-License-Identifier: GPL-2.0-only OR MIT | ||
# | ||
# Copyright (C) 2023 The Falco Authors. | ||
# | ||
# This file is dual licensed under either the MIT or GPL 2. See | ||
# MIT.txt or GPL.txt for full copies of the license. | ||
# | ||
|
||
always-y += test.o | ||
# kept for compatibility with kernels < 5.11 | ||
always = $(always-y) | ||
|
||
LLC ?= llc | ||
CLANG ?= clang | ||
|
||
KERNELDIR ?= /lib/modules/$(shell uname -r)/build | ||
|
||
# -fmacro-prefix-map is not supported on version of clang older than 10 | ||
# so remove it if necessary. | ||
IS_CLANG_OLDER_THAN_10 := $(shell expr `$(CLANG) -dumpversion | cut -f1 -d.` \<= 10) | ||
ifeq ($(IS_CLANG_OLDER_THAN_10), 1) | ||
KBUILD_CPPFLAGS := $(filter-out -fmacro-prefix-map=%,$(KBUILD_CPPFLAGS)) | ||
endif | ||
|
||
all: | ||
$(MAKE) -C $(KERNELDIR) M=$$PWD | ||
|
||
clean: | ||
$(MAKE) -C $(KERNELDIR) M=$$PWD clean | ||
@rm -f *~ | ||
|
||
$(obj)/test.o: $(src)/test.c | ||
$(CLANG) $(LINUXINCLUDE) \ | ||
$(KBUILD_CPPFLAGS) \ | ||
$(KBUILD_EXTRA_CPPFLAGS) \ | ||
-D__KERNEL__ \ | ||
-D__BPF_TRACING__ \ | ||
-Wno-gnu-variable-sized-type-not-at-end \ | ||
-Wno-address-of-packed-member \ | ||
-fno-jump-tables \ | ||
-fno-stack-protector \ | ||
-Wno-tautological-compare \ | ||
-Wno-unknown-attributes \ | ||
-O2 -g -emit-llvm -c $< -o $(patsubst %.o,%.ll,$@) | ||
$(LLC) -march=bpf -filetype=obj -o $@ $(patsubst %.o,%.ll,$@) |
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,13 @@ | ||
MODULE_MAKEFILE_DIR := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST)))) | ||
|
||
# Run the module build.sh (wrapper for make) script with an empty environment, but PATH | ||
HAS_@CONFIGURE_MODULE@ := $(shell env -i PATH="$(PATH)" KERNELDIR="$(KERNELDIR)" sh $(MODULE_MAKEFILE_DIR)/build.sh ; echo $$?) | ||
|
||
ifeq ($(HAS_@CONFIGURE_MODULE@),0) | ||
$(info [configure-bpf] Setting HAS_@CONFIGURE_MODULE@ flag) | ||
KBUILD_CPPFLAGS += -DHAS_@CONFIGURE_MODULE@ | ||
else | ||
HAS_@CONFIGURE_MODULE@_OUT := $(shell cat $(MODULE_MAKEFILE_DIR)/build.log) | ||
$(info [configure-bpf] Build output for HAS_@CONFIGURE_MODULE@:) | ||
$(info [configure-bpf] $(HAS_@CONFIGURE_MODULE@_OUT)) | ||
endif |
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,46 @@ | ||
// SPDX-License-Identifier: GPL-2.0-only OR MIT | ||
/* | ||
Copyright (C) 2023 The Falco Authors. | ||
This file is dual licensed under either the MIT or GPL 2. See MIT.txt | ||
or GPL2.txt for full copies of the license. | ||
*/ | ||
|
||
/* | ||
* Check that mm_struct's field `rss_stat` is an array. | ||
* See 6.2 kernel commit: https://github.com/torvalds/linux/commit/f1a7941243c102a44e8847e3b94ff4ff3ec56f25 | ||
*/ | ||
|
||
#include "../../quirks.h" | ||
|
||
#include <uapi/linux/bpf.h> | ||
|
||
#include "../../ppm_events_public.h" | ||
#include "../../bpf_helpers.h" | ||
#include "../../types.h" | ||
#include "../../maps.h" | ||
|
||
// struct mm_struct declaration | ||
#include <linux/mm_types.h> | ||
|
||
#ifdef BPF_SUPPORTS_RAW_TRACEPOINTS | ||
#define BPF_PROBE(prefix, event, type) \ | ||
__bpf_section(TP_NAME #event) \ | ||
int bpf_##event(struct type *ctx) | ||
#else | ||
#define BPF_PROBE(prefix, event, type) \ | ||
__bpf_section(TP_NAME prefix #event) \ | ||
int bpf_##event(struct type *ctx) | ||
#endif | ||
|
||
BPF_PROBE("signal/", signal_deliver, signal_deliver_args) | ||
{ | ||
long val; | ||
struct mm_struct *mm; | ||
val = mm->rss_stat[0].count; | ||
return 0; | ||
} | ||
|
||
char __license[] __bpf_section("license") = "Dual MIT/GPL"; |
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,13 @@ | ||
#!/bin/sh | ||
|
||
# | ||
# Copyright (C) 2023 The Falco Authors. | ||
# | ||
# This file is dual licensed under either the MIT or GPL 2. See | ||
# MIT.txt or GPL.txt for full copies of the license. | ||
# | ||
|
||
SCRIPT=$(readlink -f "$0") | ||
SCRIPT_DIR=$(dirname ${SCRIPT}) | ||
|
||
make -C ${SCRIPT_DIR} > ${SCRIPT_DIR}/build.log 2>&1 |
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