Skip to content

Commit

Permalink
Kernel upgrade (#184)
Browse files Browse the repository at this point in the history
Upgrade kernel versions and bring kernel 5.10.
  • Loading branch information
thiagoftsm authored Jan 7, 2021
1 parent 446b4f0 commit 46572eb
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 20 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ jobs:
fail-fast: false
matrix:
kernel_version:
- '5.4.20'
- '5.10.3'
- '5.4.85'
- '4.16.18'
- '4.18.0'
- '4.14.171'
- '4.14.212'
- '3.10.0'
libc:
- static
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ jobs:
strategy:
matrix:
kernel_version:
- '5.4.20'
- '5.10.3'
- '5.4.85'
- '4.16.18'
- '4.18.0'
- '4.14.171'
- '4.14.212'
- '3.10.0'
libc:
- static
Expand Down
22 changes: 11 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ NETDATA_KERNEL_VERSION=$(shell echo $(KERNEL_VERSION) | tr -s "." "_")

VER_MAJOR=$(shell echo $(KERNEL_VERSION) | cut -d. -f1)
VER_MINOR=$(shell echo $(KERNEL_VERSION) | cut -d. -f2)
VER_PATCH=$(shell echo $(KERNEL_VERSION) | cut -d. -f3)
#VER_PATCH=$(shell echo $(KERNEL_VERSION) | cut -d. -f3)

_LIBC ?= glibc

EXTRA_CFLAGS += -fno-stack-protector

all: $(KERNEL_PROGRAM)
cp $(KERNEL_DIR)rprocess_kern.o rnetdata_ebpf_process.$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH).o
cp $(KERNEL_DIR)pprocess_kern.o pnetdata_ebpf_process.$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH).o
cp $(KERNEL_DIR)rnetwork_viewer_kern.o rnetdata_ebpf_socket.$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH).o
cp $(KERNEL_DIR)pnetwork_viewer_kern.o pnetdata_ebpf_socket.$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH).o
if [ -f pnetdata_ebpf_process.$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH).o ]; then tar -cf artifacts/netdata_ebpf-$(FIRST_KERNEL_VERSION)_$(NETDATA_KERNEL_VERSION)-$(_LIBC).tar [pr]netdata_ebpf_*.$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH).o; else echo "ERROR: Cannot find BPF programs"; exit 1; fi
if [ "$${DEBUG:-0}" -eq 1 ]; then tar -uvf artifacts/netdata_ebpf-$(FIRST_KERNEL_VERSION)_$(NETDATA_KERNEL_VERSION)-$(_LIBC).tar tools/check-kernel-config.sh; fi
xz artifacts/netdata_ebpf-$(FIRST_KERNEL_VERSION)_$(NETDATA_KERNEL_VERSION)-$(_LIBC).tar
( cd artifacts; sha256sum netdata_ebpf-$(FIRST_KERNEL_VERSION)_$(NETDATA_KERNEL_VERSION)-$(_LIBC).tar.xz > netdata_ebpf-$(FIRST_KERNEL_VERSION)_$(NETDATA_KERNEL_VERSION)-$(_LIBC).tar.xz.sha256sum )
cp $(KERNEL_DIR)rprocess_kern.o rnetdata_ebpf_process.$(VER_MAJOR).$(VER_MINOR).o
cp $(KERNEL_DIR)pprocess_kern.o pnetdata_ebpf_process.$(VER_MAJOR).$(VER_MINOR).o
cp $(KERNEL_DIR)rnetwork_viewer_kern.o rnetdata_ebpf_socket.$(VER_MAJOR).$(VER_MINOR).o
cp $(KERNEL_DIR)pnetwork_viewer_kern.o pnetdata_ebpf_socket.$(VER_MAJOR).$(VER_MINOR).o
if [ -f pnetdata_ebpf_process.$(VER_MAJOR).$(VER_MINOR).o ]; then tar -cf artifacts/netdata_ebpf-$(FIRST_KERNEL_VERSION)_$(VER_MAJOR).$(VER_MINOR)-$(_LIBC).tar [pr]netdata_ebpf_*.$(VER_MAJOR).$(VER_MINOR).o; else echo "ERROR: Cannot find BPF programs"; exit 1; fi
if [ "$${DEBUG:-0}" -eq 1 ]; then tar -uvf artifacts/netdata_ebpf-$(FIRST_KERNEL_VERSION)_$(VER_MAJOR).$(VER_MINOR)-$(_LIBC).tar tools/check-kernel-config.sh; fi
xz artifacts/netdata_ebpf-$(FIRST_KERNEL_VERSION)_$(VER_MAJOR).$(VER_MINOR)-$(_LIBC).tar
( cd artifacts; sha256sum netdata_ebpf-$(FIRST_KERNEL_VERSION)_$(VER_MAJOR).$(VER_MINOR)-$(_LIBC).tar.xz > netdata_ebpf-$(FIRST_KERNEL_VERSION)_$(VER_MAJOR).$(VER_MINOR)-$(_LIBC).tar.xz.sha256sum )

$(KERNEL_PROGRAM):
cd $(KERNEL_DIR) && $(MAKE) all;

clean:
if [ -f pnetdata_ebpf_process.$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH).o ] ; then rm *.o; fi
if [ -f pnetdata_ebpf_process.$(VER_MAJOR).$(VER_MINOR).o ] ; then rm *.o; fi
cd $(KERNEL_DIR) && $(MAKE) clean;
rm artifacts/*

install:
cp *netdata_ebpf_process.$(VER_MAJOR).$(VER_MINOR).$(VER_PATCH).o /usr/libexec/netdata/plugins.d/
cp *netdata_ebpf_process.$(VER_MAJOR).$(VER_MINOR).o /usr/libexec/netdata/plugins.d/
File renamed without changes.
File renamed without changes.
Empty file added kernel-patches/5.4.85/.gitkeep
Empty file.
86 changes: 86 additions & 0 deletions kernel/process_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -417,11 +417,19 @@ int netdata_sys_readv(struct pt_regs* ctx)
return 0;
}

#if (LINUX_VERSION_CODE <= KERNEL_VERSION(5,5,19))
#if NETDATASEL < 2
SEC("kretprobe/do_sys_open")
#else
SEC("kprobe/do_sys_open")
#endif
#else
#if NETDATASEL < 2
SEC("kretprobe/do_sys_openat2")
#else
SEC("kprobe/do_sys_openat2")
#endif // Endif NETDATASEL
#endif //ENDIF KERNEL VERSION
int netdata_sys_open(struct pt_regs* ctx)
{
#if NETDATASEL < 2
Expand Down Expand Up @@ -572,6 +580,8 @@ int netdata_release_task(struct pt_regs* ctx)
return 0;
}

#if (LINUX_VERSION_CODE <= KERNEL_VERSION(5,9,16))

#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,2,0))
# if NETDATASEL < 2
SEC("kretprobe/_do_fork")
Expand Down Expand Up @@ -739,6 +749,82 @@ int netdata_clone(struct pt_regs* ctx)
}
#endif



#else // End kernel <= 5.9.16

#if NETDATASEL < 2
// https://lore.kernel.org/patchwork/patch/1290639/
SEC("kretprobe/kernel_clone")
#else
SEC("kprobe/kernel_clone")
#endif
int netdata_sys_clone(struct pt_regs *ctx)
{
#if NETDATASEL < 2
int ret = (int)PT_REGS_RC(ctx);
#endif
struct netdata_pid_stat_t data = { };
struct netdata_pid_stat_t *fill;
__u64 pid_tgid = bpf_get_current_pid_tgid();
__u32 pid = (__u32)(pid_tgid >> 32);
__u32 tgid = (__u32)( 0x00000000FFFFFFFF & pid_tgid);

int threads = 0;
struct kernel_clone_args *args = (struct kernel_clone_args *)PT_REGS_PARM1(ctx);
int exit_signal;
bpf_probe_read(&exit_signal, sizeof(int), (void *)&args->exit_signal);
// SIGCHLD is used by vfork/fork
if (exit_signal != SIGCHLD) {
threads = 1;
netdata_update_global(NETDATA_KEY_CALLS_SYS_CLONE, 1);
}

netdata_update_global(NETDATA_KEY_CALLS_DO_FORK, 1);
fill = bpf_map_lookup_elem(&tbl_pid_stats ,&pid);
if (fill) {
fill->release_call = 0;
netdata_update_u32(&fill->fork_call, 1) ;

if(threads) {
netdata_update_u32(&fill->clone_call, 1) ;
}

#if NETDATASEL < 2
if (ret < 0) {
netdata_update_u32(&fill->fork_err, 1) ;
netdata_update_global(NETDATA_KEY_ERROR_DO_FORK, 1);
if(threads) {
netdata_update_global(NETDATA_KEY_ERROR_SYS_CLONE, 1);
netdata_update_u32(&fill->clone_err, 1) ;
}
}
#endif
} else {
data.pid_tgid = pid_tgid;
data.pid = tgid;
data.fork_call = 1;
if(threads) {
data.clone_call = 1;
}
#if NETDATASEL < 2
if (ret < 0) {
netdata_update_global(NETDATA_KEY_ERROR_DO_FORK, 1);
data.fork_err = 1;
if (threads) {
netdata_update_global(NETDATA_KEY_ERROR_SYS_CLONE, 1);
data.clone_err = 1;
}
}
#endif

bpf_map_update_elem(&tbl_pid_stats, &pid, &data, BPF_ANY);
}
return 0;
}

#endif

#if NETDATASEL < 2
SEC("kretprobe/__close_fd")
#else
Expand Down
13 changes: 8 additions & 5 deletions tools/complement.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,25 @@ parse_kernel_version() {
first_kernel() {
kver=$(parse_kernel_version "${1}")

ver5_10_0="005010000"
ver4_18_0="004018000"
ver4_17_0="004017000"
ver4_15_0="004015000"
ver4_11_0="004011000"
ver3_10_0="003010000"

if [ "${kver}" -eq "${ver3_10_0}" ]; then
kpkg="3.10.0";
kpkg="3.10";
elif [ "${kver}" -eq "${ver4_18_0}" ]; then
kpkg="4.18.0";
kpkg="4.18";
elif [ "${kver}" -ge "${ver5_10_0}" ]; then
kpkg="5.10";
elif [ "${kver}" -ge "${ver4_17_0}" ]; then
kpkg="4.17.0";
kpkg="4.17";
elif [ "${kver}" -ge "${ver4_15_0}" ]; then
kpkg="4.15.0";
kpkg="4.15";
elif [ "${kver}" -ge "${ver4_11_0}" ]; then
kpkg="4.11.0";
kpkg="4.11";
fi

echo "${kpkg}"
Expand Down

0 comments on commit 46572eb

Please sign in to comment.