-
Notifications
You must be signed in to change notification settings - Fork 165
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
new(driver/bpf): added bpf configure system similar to the kmod one. #1729
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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 | ||
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. In this makefile we want to build a stupidly simple bpf probe. |
||
# 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,31 @@ | ||
// 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 "../../ppm_events_public.h" | ||
#include "../../types.h" | ||
|
||
// struct mm_struct declaration | ||
#include <linux/mm_types.h> | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,16 +27,6 @@ or GPL2.txt for full copies of the license. | |
#include "fillers.h" | ||
#include "builtins.h" | ||
|
||
#ifdef BPF_SUPPORTS_RAW_TRACEPOINTS | ||
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. Moved to |
||
#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 | ||
|
||
#define __NR_ia32_socketcall 102 | ||
|
||
BPF_PROBE("raw_syscalls/", sys_enter, sys_enter_args) | ||
|
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
Oops, something went wrong.
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.
probe.o
target must be visible when our makefile is called by kernel's makefile, ie: when we fall in theelse
branch now.