arm64: do not descend to vdso directories twice
PATCH 1/1 arm64: do not descend to vdso directories twice
arm64 descends into each vdso directory twice; first in vdso_prepare, second during the ordinary build process.
PPC mimicked it and uncovered a problem [1]. In the first descend, Kbuild directly visits the vdso directories, therefore it does not inherit subdir-ccflags-y from upper directories.
This means the command line parameters may differ between the two. If it happens, the offset values in the generated headers might be different from real offsets of vdso.so in the kernel.
This potential danger should be avoided. The vdso directories are built in the vdso_prepare stage, so the second descend is unneeded.
---
arch/arm64/Makefile | 10 ++++++----
arch/arm64/kernel/Makefile | 5 +++--
arch/arm64/kernel/{vdso/vdso.S => vdso-wrap.S} | 0
arch/arm64/kernel/vdso/Makefile | 1 -
arch/arm64/kernel/{vdso32/vdso.S => vdso32-wrap.S} | 0
arch/arm64/kernel/vdso32/Makefile | 1 -
6 files changed, 9 insertions(+), 8 deletions(-)
rename arch/arm64/kernel/{vdso/vdso.S => vdso-wrap.S} (100%)
rename arch/arm64/kernel/{vdso32/vdso.S => vdso32-wrap.S} (100%)arch/arm64/Makefile +6 -4
@@ -179,10 +179,12 @@ ifeq ($(KBUILD_EXTMOD),) # this hack. prepare: vdso_prepare vdso_prepare: prepare0 - $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso include/generated/vdso-offsets.h - $(if $(CONFIG_COMPAT_VDSO),$(Q)$(MAKE) \ - $(build)=arch/arm64/kernel/vdso32 \ - include/generated/vdso32-offsets.h) + $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso \ + include/generated/vdso-offsets.h arch/arm64/kernel/vdso/vdso.so +ifdef CONFIG_COMPAT_VDSO + $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso32 \ + include/generated/vdso32-offsets.h arch/arm64/kernel/vdso32/vdso.so +endif endif define archhelp
arch/arm64/kernel/Makefile +3 -2
@@ -59,9 +59,10 @@ obj-$(CONFIG_CRASH_CORE) += crash_core.o obj-$(CONFIG_ARM_SDE_INTERFACE) += sdei.o obj-$(CONFIG_ARM64_PTR_AUTH) += pointer_auth.o obj-$(CONFIG_ARM64_MTE) += mte.o +obj-y += vdso-wrap.o +obj-$(CONFIG_COMPAT_VDSO) += vdso32-wrap.o -obj-y += vdso/ probes/ -obj-$(CONFIG_COMPAT_VDSO) += vdso32/ +obj-y += probes/ head-y := head.o extra-y += $(head-y) vmlinux.lds
arch/arm64/kernel/vdso-wrap.S renamed from arch/arm64/kernel/vdso/vdso.S +0 -0
arch/arm64/kernel/vdso/Makefile +0 -1
@@ -45,7 +45,6 @@ endif # Disable gcov profiling for VDSO code GCOV_PROFILE := n -obj-y += vdso.o targets += vdso.lds CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
arch/arm64/kernel/vdso32-wrap.S renamed from arch/arm64/kernel/vdso32/vdso.S +0 -0
arch/arm64/kernel/vdso32/Makefile +0 -1
@@ -155,7 +155,6 @@ c-obj-vdso-gettimeofday := $(addprefix $(obj)/, $(c-obj-vdso-gettimeofday)) asm-obj-vdso := $(addprefix $(obj)/, $(asm-obj-vdso)) obj-vdso := $(c-obj-vdso) $(c-obj-vdso-gettimeofday) $(asm-obj-vdso) -obj-y += vdso.o targets += vdso.lds CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
Signature · 1 line
2.27.0
Hi Masahiro,
Quoted 7 lines · Masahiro Yamada
arm64 descends into each vdso directory twice; first in
vdso_prepare, second during the ordinary build process.PPC mimicked it and uncovered a problem [1]. In the first descend,
Kbuilddirectly visits the vdso directories, therefore it does not inherit subdir-ccflags-y from upper directories.
Quoted 9 lines
This means the command line parameters may differ between the two. If it happens, the offset values in the generated headers might be different from real offsets of vdso.so in the kernel.
This potential danger should be avoided. The vdso directories are built in the
vdso_preparestage, so the second descend is unneeded.
I could not reproduce the problem you are reporting on arm64. Could you please provide some steps?
In my case the vDSO library is not rebuilt as a result of the procedure reported in the email you linked at [1].
Quoted 22 lines
Signed-off-by Masahiro Yamada <[email protected]>---
arch/arm64/Makefile | 10 ++++++---- arch/arm64/kernel/Makefile | 5 +++-- arch/arm64/kernel/{vdso/vdso.S => vdso-wrap.S} | 0 arch/arm64/kernel/vdso/Makefile | 1 - arch/arm64/kernel/{vdso32/vdso.S => vdso32-wrap.S} | 0 arch/arm64/kernel/vdso32/Makefile | 1 - 6 files changed, 9 insertions(+), 8 deletions(-) rename arch/arm64/kernel/{vdso/vdso.S => vdso-wrap.S} (100%) rename arch/arm64/kernel/{vdso32/vdso.S => vdso32-wrap.S} (100%)arch/arm64/Makefile +0
-1@@ -179,10 +179,12 @@ ifeq ($(KBUILD_EXTMOD),) # this hack. prepare: vdso_prepare vdso_prepare: prepare0 - $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso include/generated/vdso-offsets.h
arch/arm64/Makefile ifeq ($(KBUILD_EXTMOD),) · line 188
Quoted 10 lines
arch/arm64/Makefile +6
-3- $(if $(CONFIG_COMPAT_VDSO),$(Q)$(MAKE) \ - $(build)=arch/arm64/kernel/vdso32 \ - include/generated/vdso32-offsets.h) + $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso \ + include/generated/vdso-offsets.h arch/arm64/kernel/vdso/vdso.so +ifdef CONFIG_COMPAT_VDSO + $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso32 \ + include/generated/vdso32-offsets.h arch/arm64/kernel/vdso32/vdso.so +endif endif
The reason why it is currently done in two phases (a bit hacky as per comment) is because vdso-offsets.h is required to be generated before compiling kernel/. Please refer to the comment in arch/arm64/Makefile.
Could you explain how your change satisfies the dependency?
Quoted 52 lines
arch/arm64/Makefile +0
-0define archhelparch/arm64/kernel/Makefile +3
-2@@ -59,9 +59,10 @@ obj-$(CONFIG_CRASH_CORE) += crash_core.o obj-$(CONFIG_ARM_SDE_INTERFACE) += sdei.o obj-$(CONFIG_ARM64_PTR_AUTH) += pointer_auth.o obj-$(CONFIG_ARM64_MTE) += mte.o +obj-y += vdso-wrap.o +obj-$(CONFIG_COMPAT_VDSO) += vdso32-wrap.o -obj-y += vdso/ probes/ -obj-$(CONFIG_COMPAT_VDSO) += vdso32/ +obj-y += probes/ head-y := head.o extra-y += $(head-y) vmlinux.ldsarch/arm64/kernel/vdso-wrap.S renamed from arch/arm64/kernel/vdso/vdso.S +0
-0arch/arm64/kernel/vdso/Makefile +0
-1@@ -45,7 +45,6 @@ endif # Disable gcov profiling for VDSO code GCOV_PROFILE := n -obj-y += vdso.o targets += vdso.lds CPPFLAGS_vdso.lds += -P -C -U$(ARCH)arch/arm64/kernel/vdso32-wrap.S renamed from arch/arm64/kernel/vdso32/vdso.S +0
-0arch/arm64/kernel/vdso32/Makefile +0
-1@@ -155,7 +155,6 @@ c-obj-vdso-gettimeofday := $(addprefix $(obj)/, $(c-obj-vdso-gettimeofday)) asm-obj-vdso := $(addprefix $(obj)/, $(asm-obj-vdso)) obj-vdso := $(c-obj-vdso) $(c-obj-vdso-gettimeofday) $(asm-obj-vdso) -obj-y += vdso.o targets += vdso.lds CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
Signature · 2 lines
Regards, Vincenzo
Quoted 15 lines · Vincenzo Frascino
Hi Masahiro,
Quoted 11 lines · Masahiro Yamada
arm64 descends into each vdso directory twice; first in
vdso_prepare, second during the ordinary build process.PPC mimicked it and uncovered a problem [1]. In the first descend,
Kbuilddirectly visits the vdso directories, therefore it does not inherit subdir-ccflags-y from upper directories.This means the command line parameters may differ between the two. If it happens, the offset values in the generated headers might be different from real offsets of vdso.so in the kernel.
Quoted 8 lines
Quoted 5 lines
This potential danger should be avoided. The vdso directories are built in the
vdso_preparestage, so the second descend is unneeded.I could not reproduce the problem you are reporting on arm64. Could you please provide some steps?
As far as I see in arm64 Makefiles, you cannot reproduce it. So, this is a _potential_ problem.
When somebody adds subdir-ccflags-y to arch/arm64/Kbuild or arch/arm64/kernel/Makefile,
the real issue will suddenly come up.
arm64 is the first arch that implemented vdso-offsets.h
arch maintainers tend to copy Makefiles from existing ones.
Now PPC is the second with almost the same Makefile implementation.
This time, powerpc hit the problem because arch/powerpc/Kbuild has subdir-ccflags-y.
I do not want to be bothered every time arch maintainers hit this issue. So, I want to fix arm64 first,
then powerpc will eventually copy the correct Makefiles.
Quoted 31 lines
In my case the vDSO library is not rebuilt as a result of the procedure reported in the email you linked at [1].
Quoted 28 lines
Signed-off-by Masahiro Yamada <[email protected]>---
arch/arm64/Makefile | 10 ++++++---- arch/arm64/kernel/Makefile | 5 +++-- arch/arm64/kernel/{vdso/vdso.S => vdso-wrap.S} | 0 arch/arm64/kernel/vdso/Makefile | 1 - arch/arm64/kernel/{vdso32/vdso.S => vdso32-wrap.S} | 0 arch/arm64/kernel/vdso32/Makefile | 1 - 6 files changed, 9 insertions(+), 8 deletions(-) rename arch/arm64/kernel/{vdso/vdso.S => vdso-wrap.S} (100%) rename arch/arm64/kernel/{vdso32/vdso.S => vdso32-wrap.S} (100%)arch/arm64/Makefile +3
-4@@ -179,10 +179,12 @@ ifeq ($(KBUILD_EXTMOD),) # this hack. prepare: vdso_prepare vdso_prepare: prepare0 - $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso include/generated/vdso-offsets.h - $(if $(CONFIG_COMPAT_VDSO),$(Q)$(MAKE) \ - $(build)=arch/arm64/kernel/vdso32 \ - include/generated/vdso32-offsets.h) + $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso \ + include/generated/vdso-offsets.h arch/arm64/kernel/vdso/vdso.so +ifdef CONFIG_COMPAT_VDSO
Quoted 8 lines
arch/arm64/Makefile ifeq ($(KBUILD_EXTMOD),) · line 188
Quoted 4 lines
arch/arm64/Makefile +3
-0+ $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso32 \ + include/generated/vdso32-offsets.h arch/arm64/kernel/vdso32/vdso.so +endif endifThe reason why it is currently done in two phases (a bit hacky as per comment) is because
vdso-offsets.his required to be generated before compilingkernel/. Please refer to the comment inarch/arm64/Makefile.
Yes, I know.
Quoted 2 lines
Could you explain how your change satisfies the dependency?
vdso_prepare completes before Kbuild starts ordinary descending. So *.so files and vdso-offsets.h exist
when Kbuild builds arch/arm64/kernel/.
Quoted 47 lines
Quoted 47 lines
arch/arm64/Makefile +0
-0define archhelparch/arm64/kernel/Makefile +3
-2@@ -59,9 +59,10 @@ obj-$(CONFIG_CRASH_CORE) += crash_core.o obj-$(CONFIG_ARM_SDE_INTERFACE) += sdei.o obj-$(CONFIG_ARM64_PTR_AUTH) += pointer_auth.o obj-$(CONFIG_ARM64_MTE) += mte.o +obj-y += vdso-wrap.o +obj-$(CONFIG_COMPAT_VDSO) += vdso32-wrap.o -obj-y += vdso/ probes/ -obj-$(CONFIG_COMPAT_VDSO) += vdso32/ +obj-y += probes/ head-y := head.o extra-y += $(head-y) vmlinux.ldsarch/arm64/kernel/vdso-wrap.S renamed from arch/arm64/kernel/vdso/vdso.S +0
-0arch/arm64/kernel/vdso/Makefile +0
-1@@ -45,7 +45,6 @@ endif # Disable gcov profiling for VDSO code GCOV_PROFILE := n -obj-y += vdso.o targets += vdso.lds CPPFLAGS_vdso.lds += -P -C -U$(ARCH)arch/arm64/kernel/vdso32-wrap.S renamed from arch/arm64/kernel/vdso32/vdso.S +0
-0arch/arm64/kernel/vdso32/Makefile +0
-0@@ -155,7 +155,6 @@ c-obj-vdso-gettimeofday := $(addprefix $(obj)/, $(c-obj-vdso-gettimeofday)) asm-obj-vdso := $(addprefix $(obj)/, $(asm-obj-vdso)) obj-vdso := $(c-obj-vdso) $(c-obj-vdso-gettimeofday) $(asm-obj-vdso)
Quoted 9 lines
arch/arm64/kernel/vdso32/Makefile c-obj-vdso-gettimeofday := $(addprefix $(obj)/, $(c-obj-vdso-gettimeofday)) · line 160
Quoted 5 lines
arch/arm64/kernel/vdso32/Makefile +0
-1-obj-y += vdso.o targets += vdso.lds CPPFLAGS_vdso.lds += -P -C -U$(ARCH)--
Regards,
Vincenzo
--
Best Regards
Masahiro Yamada
Quoted 39 lines · Masahiro Yamada
Quoted 15 lines · Vincenzo Frascino
Hi Masahiro,
Quoted 11 lines · Masahiro Yamada
arm64 descends into each vdso directory twice; first in
vdso_prepare, second during the ordinary build process.PPC mimicked it and uncovered a problem [1]. In the first descend,
Kbuilddirectly visits the vdso directories, therefore it does not inherit subdir-ccflags-y from upper directories.This means the command line parameters may differ between the two. If it happens, the offset values in the generated headers might be different from real offsets of vdso.so in the kernel.
Quoted 8 lines
Quoted 5 lines
This potential danger should be avoided. The vdso directories are built in the
vdso_preparestage, so the second descend is unneeded.I could not reproduce the problem you are reporting on arm64. Could you please provide some steps?
As far as I see in arm64 Makefiles, you cannot reproduce it. So, this is a _potential_ problem.
When somebody adds subdir-ccflags-y to
arch/arm64/Kbuildorarch/arm64/kernel/Makefile,
the real issue will suddenly come up.arm64 is the first arch that implemented
vdso-offsets.harch maintainers tend to copy Makefiles from existing ones.
Quoted 10 lines
Now PPC is the second with almost the same
Makefileimplementation.This time, powerpc hit the problem because
arch/powerpc/Kbuildhas subdir-ccflags-y.I do not want to be bothered every time arch maintainers hit this issue. So, I want to fix arm64 first,
then powerpc will eventually copy the correct Makefiles.
Ok this seems a problem related to a top down approach in the ccflags propagation, which as it stands does not affect arm64, hence IMHO we should not fix what is not broken, but I do not have a strong opinion on this.
Quoted 42 lines
Quoted 33 lines
In my case the vDSO library is not rebuilt as a result of the procedure reported in the email you linked at [1].
Quoted 28 lines
Signed-off-by Masahiro Yamada <[email protected]>---
arch/arm64/Makefile | 10 ++++++---- arch/arm64/kernel/Makefile | 5 +++-- arch/arm64/kernel/{vdso/vdso.S => vdso-wrap.S} | 0 arch/arm64/kernel/vdso/Makefile | 1 - arch/arm64/kernel/{vdso32/vdso.S => vdso32-wrap.S} | 0 arch/arm64/kernel/vdso32/Makefile | 1 - 6 files changed, 9 insertions(+), 8 deletions(-) rename arch/arm64/kernel/{vdso/vdso.S => vdso-wrap.S} (100%) rename arch/arm64/kernel/{vdso32/vdso.S => vdso32-wrap.S} (100%)arch/arm64/Makefile +3
-4@@ -179,10 +179,12 @@ ifeq ($(KBUILD_EXTMOD),) # this hack. prepare: vdso_prepare vdso_prepare: prepare0 - $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso include/generated/vdso-offsets.h - $(if $(CONFIG_COMPAT_VDSO),$(Q)$(MAKE) \ - $(build)=arch/arm64/kernel/vdso32 \ - include/generated/vdso32-offsets.h) + $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso \ + include/generated/vdso-offsets.h arch/arm64/kernel/vdso/vdso.so +ifdef CONFIG_COMPAT_VDSOQuoted 8 lines
arch/arm64/Makefile ifeq ($(KBUILD_EXTMOD),) · line 188
Quoted 4 lines
arch/arm64/Makefile +3
-0+ $(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso32 \ + include/generated/vdso32-offsets.h arch/arm64/kernel/vdso32/vdso.so +endif endifThe reason why it is currently done in two phases (a bit hacky as per comment) is because
vdso-offsets.his required to be generated before compilingkernel/. Please refer to the comment inarch/arm64/Makefile.
Quoted 10 lines
Yes, I know.
Quoted 2 lines
Could you explain how your change satisfies the dependency?
vdso_preparecompletes beforeKbuildstarts ordinary descending. So *.so files andvdso-offsets.hexist
whenKbuildbuildsarch/arm64/kernel/.
This is not immediately obvious, could you please mention it in the commit message?
Nit: Could you please re-organize the code as follows in order to limit the changes (untested)?
$(Q)$(MAKE) $(build)=arch/arm64/kernel/vdso include/generated/vdso-offsets.h \
arch/arm64/kernel/vdso/vdso.so
$(if $(CONFIG_COMPAT_VDSO),$(Q)$(MAKE) \ $(build)=arch/arm64/kernel/vdso32 \ include/generated/vdso32-offsets.h \ arch/arm64/kernel/vdso32/vdso.so)
Quoted 67 lines
Quoted 51 lines
Quoted 51 lines
arch/arm64/Makefile +0
-0define archhelparch/arm64/kernel/Makefile +3
-2@@ -59,9 +59,10 @@ obj-$(CONFIG_CRASH_CORE) += crash_core.o obj-$(CONFIG_ARM_SDE_INTERFACE) += sdei.o obj-$(CONFIG_ARM64_PTR_AUTH) += pointer_auth.o obj-$(CONFIG_ARM64_MTE) += mte.o +obj-y += vdso-wrap.o +obj-$(CONFIG_COMPAT_VDSO) += vdso32-wrap.o -obj-y += vdso/ probes/ -obj-$(CONFIG_COMPAT_VDSO) += vdso32/ +obj-y += probes/ head-y := head.o extra-y += $(head-y) vmlinux.ldsarch/arm64/kernel/vdso-wrap.S renamed from arch/arm64/kernel/vdso/vdso.S +0
-0arch/arm64/kernel/vdso/Makefile +0
-1@@ -45,7 +45,6 @@ endif # Disable gcov profiling for VDSO code GCOV_PROFILE := n -obj-y += vdso.o targets += vdso.lds CPPFLAGS_vdso.lds += -P -C -U$(ARCH)arch/arm64/kernel/vdso32-wrap.S renamed from arch/arm64/kernel/vdso32/vdso.S +0
-0arch/arm64/kernel/vdso32/Makefile +0
-0@@ -155,7 +155,6 @@ c-obj-vdso-gettimeofday := $(addprefix $(obj)/, $(c-obj-vdso-gettimeofday)) asm-obj-vdso := $(addprefix $(obj)/, $(asm-obj-vdso)) obj-vdso := $(c-obj-vdso) $(c-obj-vdso-gettimeofday) $(asm-obj-vdso)Quoted 9 lines
arch/arm64/kernel/vdso32/Makefile c-obj-vdso-gettimeofday := $(addprefix $(obj)/, $(c-obj-vdso-gettimeofday)) · line 160
Quoted 5 lines
arch/arm64/kernel/vdso32/Makefile +0
-1-obj-y += vdso.o targets += vdso.lds CPPFLAGS_vdso.lds += -P -C -U$(ARCH)--
Regards,
Vincenzo--
Best Regards
Masahiro Yamada
Signature · 2 lines
Regards, Vincenzo
Quoted 8 lines · Masahiro Yamada
arm64 descends into each vdso directory twice; first in
vdso_prepare, second during the ordinary build process.PPC mimicked it and uncovered a problem [1]. In the first descend,
Kbuilddirectly visits the vdso directories, therefore it does not inherit subdir-ccflags-y from upper directories.[...]
Applied to arm64 (for-next/vdso), thanks!
[1/1] arm64: do not descend to vdso directories twice
https://git.kernel.org/arm64/c/a5b8ca97fbf8
Cheers,
Signature · 10 lines
Will https://fixes.arm64.dev https://next.arm64.dev https://will.arm64.dev _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel