diff --git a/patches/0017-Add-support-of-DYNAMIC_FTRACE_WITH_CALL_OPS-of-kerne.patch b/patches/0017-Add-support-of-DYNAMIC_FTRACE_WITH_CALL_OPS-of-kerne.patch new file mode 100644 index 0000000000000000000000000000000000000000..3b8917e6e7909c13dad238b47bf8f601a50cf775 --- /dev/null +++ b/patches/0017-Add-support-of-DYNAMIC_FTRACE_WITH_CALL_OPS-of-kerne.patch @@ -0,0 +1,57 @@ +From 5464a667fcd727b1d340634abc05ac6afea49225 Mon Sep 17 00:00:00 2001 +From: "zhangyongde.zyd" +Date: Tue, 13 Aug 2024 19:24:22 +0800 +Subject: [PATCH] Add support of DYNAMIC_FTRACE_WITH_CALL_OPS for kernel 6.6 + +Under architecture of aarch64, kernel may have CONFIG_DYNAMIC_FTRACE_WITH_CALL_OPS +enabled in kernel config, while have no effect to x86_64. With this config on, elf +function will leave 8 byte space for 2 nop instruction for hiddend code. We should +handle this kind of situation facing aarch64. We should judge if this config in +config file and remember to handle it. + +With kernel config CONFIG_DYNAMIC_FTRACE_WITH_CALL_OPS, the start of function +entries will have left 8 byte nop instructions for ftrace hidden instructions. + +But there are some other symbol at offset 0. So, to handle such situation, we +we should judge the offset only when the st_vaule is not the default offset +and this symbol is not with dynamic ftrace with call ops on with offset 8, should +raise an error. + +diff --git a/kpatch-build/create-diff-object.c b/kpatch-build/create-diff-object.c +index 4a99e01..aca68c0 100644 +--- a/kpatch-build/create-diff-object.c ++++ b/kpatch-build/create-diff-object.c +@@ -257,6 +257,7 @@ static void kpatch_bundle_symbols(struct kpatch_elf *kelf) + { + struct symbol *sym; + unsigned int expected_offset; ++ unsigned int dynamic_ftracecall_offset = 8; + + list_for_each_entry(sym, &kelf->symbols, list) { + if (is_bundleable(sym)) { +@@ -267,7 +268,8 @@ static void kpatch_bundle_symbols(struct kpatch_elf *kelf) + else + expected_offset = 0; + +- if (sym->sym.st_value != expected_offset) { ++ if (sym->sym.st_value != expected_offset && ++ ((!getenv("CONFIG_DYNAMIC_FTRACE_WITH_CALL_OPS") && sym->sym.st_value == dynamic_ftracecall_offset))) { + ERROR("symbol %s at offset %lu within section %s, expected %u", + sym->name, sym->sym.st_value, + sym->sec->name, expected_offset); +diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build +index a1823f0..c5cd850 100755 +--- a/kpatch-build/kpatch-build ++++ b/kpatch-build/kpatch-build +@@ -1210,6 +1210,8 @@ fi + [[ -n "$CONFIG_GCC_PLUGIN_LATENT_ENTROPY" ]] && die "kernel option 'CONFIG_GCC_PLUGIN_LATENT_ENTROPY' not supported" + [[ -n "$CONFIG_GCC_PLUGIN_RANDSTRUCT" ]] && die "kernel option 'CONFIG_GCC_PLUGIN_RANDSTRUCT' not supported" + ++grep -q "CONFIG_DYNAMIC_FTRACE_WITH_CALL_OPS=y" "$CONFIGFILE" && export CONFIG_DYNAMIC_FTRACE_WITH_CALL_OPS=1 ++ + # CONFIG_DEBUG_INFO_BTF invokes pahole, for which some versions don't + # support extended ELF sections. Disable the BTF typeinfo generation in + # link-vmlinux.sh and Makefile.modfinal since kpatch doesn't care about +-- +2.43.5 +