From 6b7ff79bb40a7dbb28e6aba320e4ac075e4c182d Mon Sep 17 00:00:00 2001 From: Zhipeng Xie Date: Fri, 18 Jan 2019 00:07:02 +0000 Subject: [PATCH] support force enable/disable for kernel 4.19 Signed-off-by: Zhipeng Xie --- kmod/patch/livepatch-patch-hook.c | 7 +++++-- kpatch-build/kpatch-build | 12 ++++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/kmod/patch/livepatch-patch-hook.c b/kmod/patch/livepatch-patch-hook.c index ce1c955..919dfc7 100644 --- a/kmod/patch/livepatch-patch-hook.c +++ b/kmod/patch/livepatch-patch-hook.c @@ -511,14 +511,17 @@ static int __init patch_init(void) #ifdef __HULK__ lfunc->old_size = func->kfunc->old_size; lfunc->new_size = func->kfunc->new_size; + lfunc->ref_name= func->kfunc->ref_name; + lfunc->ref_offset = func->kfunc->ref_offset; +#endif +#if defined(__HULK__) || defined(__KLP_SUPPORT_FORCE__) #ifdef __ALL_FORCE__ lfunc->force = 1; #else lfunc->force = patch_is_func_forced(func->kfunc->new_addr); #endif - lfunc->ref_name= func->kfunc->ref_name; - lfunc->ref_offset = func->kfunc->ref_offset; #endif + j++; } diff --git a/kpatch-build/kpatch-build b/kpatch-build/kpatch-build index a860f12..c227b44 100755 --- a/kpatch-build/kpatch-build +++ b/kpatch-build/kpatch-build @@ -279,7 +279,7 @@ find_special_section_data() { # shellcheck disable=SC2086 SPECIAL_VARS="$(readelf -wi "$VMLINUX" | gawk --non-decimal-data $AWK_OPTIONS ' - BEGIN { a = b = p = e = o = 0 } + BEGIN { a = b = p = e = o = f = 0 } # Set state if name matches a == 0 && /DW_AT_name.* alt_instr[[:space:]]*$/ {a = 1; next} @@ -287,6 +287,7 @@ find_special_section_data() { p == 0 && /DW_AT_name.* paravirt_patch_site[[:space:]]*$/ {p = 1; next} e == 0 && /DW_AT_name.* exception_table_entry[[:space:]]*$/ {e = 1; next} o == 0 && /DW_AT_name.* orc_entry[[:space:]]*$/ {o = 1; next} + f == 0 && /DW_AT_name.* klp_func[[:space:]]*$/ {f = 1; next} # Reset state unless this abbrev describes the struct size a == 1 && !/DW_AT_byte_size/ { a = 0; next } @@ -294,6 +295,8 @@ find_special_section_data() { p == 1 && !/DW_AT_byte_size/ { p = 0; next } e == 1 && !/DW_AT_byte_size/ { e = 0; next } o == 1 && !/DW_AT_byte_size/ { o = 0; next } + f == 1 && /DW_TAG_structure_type/ { f = 3; next } + f == 1 && /DW_AT_name.* force[[:space:]]*$/ {f = 2; next} # Now that we know the size, stop parsing for it a == 1 {printf("export ALT_STRUCT_SIZE=%d\n", $4); a = 2} @@ -301,9 +304,10 @@ find_special_section_data() { p == 1 {printf("export PARA_STRUCT_SIZE=%d\n", $4); p = 2} e == 1 {printf("export EX_STRUCT_SIZE=%d\n", $4); e = 2} o == 1 {printf("export ORC_STRUCT_SIZE=%d\n", $4); o = 2} + f == 2 {printf("export KLP_SUPPORT_FORCE=y\n"); f = 3} # Bail out once we have everything - a == 2 && b == 2 && (p == 2 || skip_p) && e == 2 && (o == 2 || skip_o) {exit}')" + a == 2 && b == 2 && (p == 2 || skip_p) && e == 2 && (o == 2 || skip_o) && f == 3 {exit}')" [[ -n "$SPECIAL_VARS" ]] && eval "$SPECIAL_VARS" @@ -957,6 +961,10 @@ if [[ -n "$NO_STACK_CHECK" ]];then export KCPPFLAGS="-D__ALL_FORCE__ $KCPPFLAGS" fi +if [[ -n "$KLP_SUPPORT_FORCE" ]];then + export KCPPFLAGS="-D__KLP_SUPPORT_FORCE__ $KCPPFLAGS" +fi + echo "Building patch module: $MODNAME.ko" if [[ -z "$USERSRCDIR" ]] && [[ "$DISTRO" = ubuntu ]]; then -- 1.7.5.4