Skip to content
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

kpatch-build fails: unable to locate patch-hook.o since linux commit 13b25489b6f8 #1430

Open
sumanthkorikkar opened this issue Dec 23, 2024 · 0 comments

Comments

@sumanthkorikkar
Copy link
Contributor

Hi All,

Starting from linux commit 13b25489b6f8 ("kbuild: change working directory to external module directory with M="), the kpatch-build fails

Error log:
meminfo.o: changed function: meminfo_proc_show                                  
make V=1 -C /mnt/linux M=/root/.kpatch/tmp/patch CFLAGS_MODULE=''               
make[1]: Entering directory '/mnt/linux'                                        
make  -C /root/.kpatch/tmp/patch \                                              
-f /mnt/linux/Makefile                                                          
make[2]: Entering directory '/root/.kpatch/tmp/patch'                           
make --no-print-directory -C /root/.kpatch/tmp/patch \                          
-f /mnt/linux/Makefile                                                          
make -f /mnt/linux/scripts/Makefile.build obj=. need-builtin=1 need-modorder=1  
# cmd_mod test-data-new.mod                                                     
  printf '%s\n'   patch-hook.o output.o | awk '!x[$0]++ { print("./"$0) }' > test-data-new.mod
# LDS     kpatch.lds                                                            
  gcc -E -Wp,-MMD,./.kpatch.lds.d -nostdinc -I/mnt/linux/arch/s390/include -I/mnt/linux/arch/s390/include/generated -I/mnt/linux/include -I/mnt/linux/include -I/mnt/linux/arch/s390/include/uapi -I/mnt/linux/arch/s390/include/generated/uapi -I/mnt/linux/include/uapi -I/mnt/linux/include/generated/uapi -include /mnt/linux/include/linux/compiler-version.h -include /mnt/linux/include/linux/kconfig.h -D__KERNEL__ -fmacro-prefix-map=/mnt/linux/=   -P -Us390 -D__ASSEMBLY__ -DLINKER_SCRIPT -o kpatch.lds kpatch.lds.S
make V=1 -C /mnt/linux M=/root/.kpatch/tmp/patch CFLAGS_MODULE='' patch-hook.o  
make -f /mnt/linux/scripts/Makefile.build obj=. need-builtin=1 need-modorder=1 ./patch-hook.o
make[6]: *** No rule to make target 'patch-hook.o'.  Stop. `

Error notes:

- make -C changes the directory to /mnt/linux.
- With linux commit 13b25489b6f8, make inturn switches the working directory to the external module directory /root/.kpatch/tmp/patch.
- $(KPATCH_MAKE) patch-hook.o is called, which inturn changes directory back to /mnt/linux and patch-hook.o is not found

Previous working state:

checking file fs/proc/meminfo.c                                                 
Hunk #1 succeeded at 31 (offset 2 lines).                                       
Hunk #2 succeeded at 153 with fuzz 2 (offset 6 lines).                          
patching file fs/proc/meminfo.c                                                 
Hunk #1 succeeded at 31 (offset 2 lines).                                       
Hunk #2 succeeded at 153 with fuzz 2 (offset 6 lines).                          
  CALL    scripts/checksyscalls.sh                                              
  CC      fs/proc/meminfo.o                                                     
  AR      fs/proc/built-in.a                                                    
meminfo.o: changed function: meminfo_proc_show                                  
make V=1 -C /mnt/linux M=/root/.kpatch/tmp/patch CFLAGS_MODULE=''               
make[1]: Entering directory '/mnt/linux'                                        
make --no-print-directory -C /mnt/linux \                                       
-f /mnt/linux/Makefile                                                          
make -f ./scripts/Makefile.build obj=/root/.kpatch/tmp/patch need-builtin=1 need-modorder=1   <<<<< obj=/root/.kpatch/tmp/patch  -> via KBUILD_EXTMOD 
# cmd_mod /root/.kpatch/tmp/patch/test-data-new.mod                             
  printf '%s\n'   patch-hook.o output.o | awk '!x[$0]++ { print("/root/.kpatch/tmp/patch/"$0) }' > /root/.kpatch/tmp/patch/test-data-new.mod
# LDS     /root/.kpatch/tmp/patch/kpatch.lds                                    
  gcc -E -Wp,-MMD,/root/.kpatch/tmp/patch/.kpatch.lds.d -nostdinc -I./arch/s390/include -I./arch/s390/include/generated  -I./include -I./arch/s390/include/uapi -I./arch/s390/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h -D__KERNEL__ -fmacro-prefix-map=./=   -P -Us390 -D__ASSEMBLY__ -DLINKER_SCRIPT -o /root/.kpatch/tmp/patch/kpatch.lds /root/.kpatch/tmp/patch/kpatch.lds.S
# CC [M]  /root/.kpatch/tmp/patch/patch-hook.o  <<====
# CC [M]  /root/.kpatch/tmp/patch/patch-hook.o                                  
  gcc -Wp,-MMD,/root/.kpatch/tmp/patch/.patch-hook.o.d -nostdinc -I./arch/s390/include -I./arch/s390/include/generated  -I./include -I./arch/s390/include/uapi -I./arch/s390/include/generated/uapi -I./include/uapi -I./include/generated/uapi -include ./include/linux/compiler-version.h -include ./include/linux/kconfig.h -include ./include/linux/compiler_types.h -D__KERNEL__ -fmacro-prefix-map=./= -std=gnu11 -fshort-wchar -funsigned-char -fno-common -fno-PIE -fno-strict-aliasing -m64 -fPIC -mpacked-stack -mbackchain -msoft-float -march=z13 -mtune=z13 -Wa,-I./arch/s390/include -mindirect-branch=thunk-extern -mfunction-return=thunk-extern -mindirect-branch-table -DCC_USING_EXPOLINE -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -DCONFIG_AS_CFI_VAL_OFFSET=1 -fno-delete-null-pointer-checks -O2 -fno-allow-store-data-races -fno-stack-protector -ftrivial-auto-var-init=zero -fno-stack-clash-protection -pg -mrecord-mcount -mnop-mcount -mfentry -DCC_USING_NOP_MCOUNT -DCC_USING_FENTRY -fno-inline-functions-called-once -falign-functions=8 -fstrict-flex-arrays=3 -fno-strict-overflow -fno-stack-check -fconserve-stack -Wall -Wundef -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Werror=strict-prototypes -Wno-format-security -Wno-trigraphs -Wno-frame-address -Wno-address-of-packed-member -Wmissing-declarations -Wmissing-prototypes -Wframe-larger-than=2048 -Wno-main -Wno-dangling-pointer -Wvla -Wno-pointer-sign -Wcast-function-type -Wno-stringop-overflow -Wno-array-bounds -Wno-alloc-size-larger-than -Wimplicit-fallthrough=5 -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wenum-conversion -Wextra -Wunused -Wno-unused-but-set-variable -Wno-unused-const-variable -Wno-packed-not-aligned -Wno-format-overflow -Wno-format-truncation -Wno-stringop-truncation -Wno-override-init -Wno-missing-field-initializers -Wno-type-limits -Wno-shift-negative-value -Wno-maybe-uninitialized -Wno-sign-compare -Wno-unused-parameter -g -gdwarf-4 -I/root/kpatch/kmod/patch -mno-pic-data-is-text-relative -fno-section-anchors  -DMODULE -fPIC  -DKBUILD_BASENAME='"patch_hook"' -DKBUILD_MODNAME='"test_data_new"' -D__KBUILD_MODNAME=kmod_test_data_new -c -o /root/.kpatch/tmp/patch/patch-hook.o /root/.kpatch/tmp/patch/patch-hook.c
...

Possible resolution:

- Remove $(KPATCH_MAKE) patch-hook.o in Makefile. This would mean make patch-hook.o cannot be performed directly. 
- Dependencies in Makefile:
  $(KPATCH_NAME)-objs += patch-hook.o output.o
  patch-hook.o: patch-hook.c kpatch-patch-hook.c livepatch-patch-hook.c
- However, If any of the above sources are updated, kpatch module would  be rebuilt anyways.

Possible resolution patch:

diff --git a/kmod/patch/Makefile b/kmod/patch/Makefile
index bb4d49c..c684387 100644
--- a/kmod/patch/Makefile
+++ b/kmod/patch/Makefile
@@ -1,5 +1,5 @@
 KPATCH_BUILD ?= /lib/modules/$(shell uname -r)/build
-KPATCH_MAKE = $(MAKE) -C $(KPATCH_BUILD) M=$(PWD) CFLAGS_MODULE='$(CFLAGS_MODULE)'
+KPATCH_MAKE = $(MAKE) V=1 -C $(KPATCH_BUILD) M=$(PWD) CFLAGS_MODULE='$(CFLAGS_MODULE)'
 LDFLAGS += $(KPATCH_LDFLAGS)
 
 # object files that this Makefile can (re)build on its own
@@ -19,7 +19,6 @@ $(KPATCH_NAME).ko:
 $(obj)/$(KPATCH_NAME).o: $(src)/kpatch.lds
 
 patch-hook.o: patch-hook.c kpatch-patch-hook.c livepatch-patch-hook.c
-       $(KPATCH_MAKE) patch-hook.o
 
 clean:
        $(RM) -Rf .*.o.cmd .*.ko.cmd .tmp_versions $(BUILDABLE_OBJS) *.ko *.mod.c \

Resolution output:

meminfo.o: changed function: meminfo_proc_show                                  
make V=1 -C /mnt/linux M=/root/.kpatch/tmp/patch CFLAGS_MODULE=''               
make[1]: Entering directory '/mnt/linux'                                        
make  -C /root/.kpatch/tmp/patch \                                              
-f /mnt/linux/Makefile                                                          
make[2]: Entering directory '/root/.kpatch/tmp/patch'                           
make --no-print-directory -C /root/.kpatch/tmp/patch \                          
-f /mnt/linux/Makefile                                                          
make -f /mnt/linux/scripts/Makefile.build obj=. need-builtin=1 need-modorder=1    <<<< obj=.
# cmd_mod test-data-new.mod                                                     
  printf '%s\n'   patch-hook.o output.o | awk '!x[$0]++ { print("./"$0) }' > test-data-new.mod
# LDS     kpatch.lds                                                            
  gcc -E -Wp,-MMD,./.kpatch.lds.d -nostdinc -I/mnt/linux/arch/s390/include -I/mnt/linux/arch/s390/include/generated -I/mnt/linux/include -I/mnt/linux/include -I/mnt/linux/arch/s390/include/uapi -I/mnt/linux/arch/s390/include/generated/uapi -I/mnt/linux/include/uapi -I/mnt/linux/include/generated/uapi -include /mnt/linux/include/linux/compiler-version.h -include /mnt/linux/include/linux/kconfig.h -D__KERNEL__ -fmacro-prefix-map=/mnt/linux/=   -P -Us390 -D__ASSEMBLY__ -DLINKER_SCRIPT -o kpatch.lds kpatch.lds.S
# CC [M]  patch-hook.o  <<<<                                                         
  gcc -Wp,-MMD,./.patch-hook.o.d -nostdinc -I/mnt/linux/arch/s390/include -I/mnt/linux/arch/s390/include/generated -I/mnt/linux/include -I/mnt/linux/include -I/mnt/linux/arch/s390/include/uapi -I/mnt/linux/arch/s390/include/generated/uapi -I/mnt/linux/include/uapi -I/mnt/linux/include/generated/uapi -include /mnt/linux/include/linux/compiler-version.h -include /mnt/linux/include/linux/kconfig.h -include /mnt/linux/include/linux/compiler_types.h -D__KERNEL__ -fmacro-prefix-map=/mnt/linux/= -std=gnu11 -fshort-wchar -funsigned-char -fno-common -fno-PIE -fno-strict-aliasing -m64 -fPIC -mpacked-stack -mbackchain -msoft-float -march=z13 -mtune=z13 -Wa,-I/mnt/linux/arch/s390/include -mindirect-branch=thunk-extern -mfunction-return=thunk-extern -mindirect-branch-table -DCC_USING_EXPOLINE -pipe -Wno-sign-compare -fno-asynchronous-unwind-tables -DCONFIG_AS_CFI_VAL_OFFSET=1 -fno-delete-null-pointer-checks -O2 -fno-allow-store-data-races -fno-stack-protector -ftrivial-auto-var-init=zero -fno-stack-clash-protection -pg -mrecord-mcount -mnop-mcount -mfentry -DCC_USING_NOP_MCOUNT -DCC_USING_FENTRY -fno-inline-functions-called-once -falign-functions=8 -fstrict-flex-arrays=3 -fno-strict-overflow -fno-stack-check -fconserve-stack -Wall -Wundef -Werror=implicit-function-declaration -Werror=implicit-int -Werror=return-type -Werror=strict-prototypes -Wno-format-security -Wno-trigraphs -Wno-frame-address -Wno-address-of-packed-member -Wmissing-declarations -Wmissing-prototypes -Wframe-larger-than=2048 -Wno-main -Wno-dangling-pointer -Wvla -Wno-pointer-sign -Wcast-function-type -Wno-stringop-overflow -Wno-array-bounds -Wno-alloc-size-larger-than -Wimplicit-fallthrough=5 -Werror=date-time -Werror=incompatible-pointer-types -Werror=designated-init -Wenum-conversion -Wextra -Wunused -Wno-unused-but-set-variable -Wno-unused-const-variable -Wno-packed-not-aligned -Wno-format-overflow -Wno-format-truncation -Wno-stringop-truncation -Wno-override-init -Wno-missing-field-initializers -Wno-type-limits -Wno-shift-negative-value -Wno-maybe-uninitialized -Wno-sign-compare -Wno-unused-parameter -g -gdwarf-4 -I/root/kpatch/kmod/patch -mno-pic-data-is-text-relative -fno-section-anchors  -DMODULE -fPIC  -DKBUILD_BASENAME='"patch_hook"' -DKBUILD_MODNAME='"test_data_new"' -D__KBUILD_MODNAME=kmod_test_data_new -c -o patch-hook.o patch-hook.c
...  

Let me know, if this solution is optimal or reasonable. If yes, I will proceed with the patch.

Thank you,
Sumanth

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant