2024-02-17 05:55:23

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 1/2] kbuild: change tool coverage variables to take the path relative to $(obj)

Commit 54b8ae66ae1a ("kbuild: change *FLAGS_<basetarget>.o to take the
path relative to $(obj)") changed the syntax of per-file compiler flags.

The situation is the same for the following variables:

OBJECT_FILES_NON_STANDARD_<basetarget>.o
GCOV_PROFILE_<basetarget>.o
KASAN_SANITIZE_<basetarget>.o
KMSAN_SANITIZE_<basetarget>.o
KMSAN_ENABLE_CHECKS_<basetarget>.o
UBSAN_SANITIZE_<basetarget>.o
KCOV_INSTRUMENT_<basetarget>.o
KCSAN_SANITIZE_<basetarget>.o
KCSAN_INSTRUMENT_BARRIERS_<basetarget>.o

The <basetarget> is the filename of the target with its directory and
suffix stripped.

This syntax comes into a trouble when two files with the same basename
appear in one Makefile, for example:

obj-y += dir1/foo.o
obj-y += dir2/foo.o
OBJECT_FILES_NON_STANDARD_foo.o := y

OBJECT_FILES_NON_STANDARD_foo.o is applied to both dir1/foo.o and
dir2/foo.o. This syntax is not flexbile enough to handle cases where
one of them is a standard object, but the other is not.

It is more sensible to use the relative path to the Makefile, like this:

obj-y += dir1/foo.o
OBJECT_FILES_NON_STANDARD_dir1/foo.o := y
obj-y += dir2/foo.o
OBJECT_FILES_NON_STANDARD_dir2/foo.o := y

To maintain the current behavior, I made adjustments to two Makefiles:

- arch/x86/entry/vdso/Makefile, which compiles vclock_gettime.o and
vdso32/vclock_gettime.o

- arch/x86/kvm/Makefile, which compiles vmx/vmenter.o and svm/vmenter.o

Signed-off-by: Masahiro Yamada <[email protected]>
---

arch/x86/entry/vdso/Makefile | 2 ++
arch/x86/kvm/Makefile | 3 ++-
scripts/Makefile.build | 2 +-
scripts/Makefile.lib | 16 ++++++++--------
4 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vdso/Makefile
index 7a97b17f28b7..148adfdb2325 100644
--- a/arch/x86/entry/vdso/Makefile
+++ b/arch/x86/entry/vdso/Makefile
@@ -9,7 +9,9 @@ include $(srctree)/lib/vdso/Makefile
# Sanitizer runtimes are unavailable and cannot be linked here.
KASAN_SANITIZE := n
KMSAN_SANITIZE_vclock_gettime.o := n
+KMSAN_SANITIZE_vdso32/vclock_gettime.o := n
KMSAN_SANITIZE_vgetcpu.o := n
+KMSAN_SANITIZE_vdso32/vgetcpu.o := n

UBSAN_SANITIZE := n
KCSAN_SANITIZE := n
diff --git a/arch/x86/kvm/Makefile b/arch/x86/kvm/Makefile
index 475b5fa917a6..a88bb14266b6 100644
--- a/arch/x86/kvm/Makefile
+++ b/arch/x86/kvm/Makefile
@@ -4,7 +4,8 @@ ccflags-y += -I $(srctree)/arch/x86/kvm
ccflags-$(CONFIG_KVM_WERROR) += -Werror

ifeq ($(CONFIG_FRAME_POINTER),y)
-OBJECT_FILES_NON_STANDARD_vmenter.o := y
+OBJECT_FILES_NON_STANDARD_vmx/vmenter.o := y
+OBJECT_FILES_NON_STANDARD_svm/vmenter.o := y
endif

include $(srctree)/virt/kvm/Makefile.kvm
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 4971f54c855e..256db2a0e984 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -214,7 +214,7 @@ endif # CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT
# 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
# 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file

-is-standard-object = $(if $(filter-out y%, $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y)
+is-standard-object = $(if $(filter-out y%, $(OBJECT_FILES_NON_STANDARD_$(target-stem).o)$(OBJECT_FILES_NON_STANDARD)n),y)

$(obj)/%.o: objtool-enabled = $(if $(is-standard-object),$(if $(delay-objtool),$(is-single-obj-m),y))

diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index b35d39022a30..328c0d77ed48 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -154,7 +154,7 @@ _cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(target-stem).lds)
#
ifeq ($(CONFIG_GCOV_KERNEL),y)
_c_flags += $(if $(patsubst n%,, \
- $(GCOV_PROFILE_$(basetarget).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), \
+ $(GCOV_PROFILE_$(target-stem).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), \
$(CFLAGS_GCOV))
endif

@@ -165,29 +165,29 @@ endif
ifeq ($(CONFIG_KASAN),y)
ifneq ($(CONFIG_KASAN_HW_TAGS),y)
_c_flags += $(if $(patsubst n%,, \
- $(KASAN_SANITIZE_$(basetarget).o)$(KASAN_SANITIZE)y), \
+ $(KASAN_SANITIZE_$(target-stem).o)$(KASAN_SANITIZE)y), \
$(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE))
endif
endif

ifeq ($(CONFIG_KMSAN),y)
_c_flags += $(if $(patsubst n%,, \
- $(KMSAN_SANITIZE_$(basetarget).o)$(KMSAN_SANITIZE)y), \
+ $(KMSAN_SANITIZE_$(target-stem).o)$(KMSAN_SANITIZE)y), \
$(CFLAGS_KMSAN))
_c_flags += $(if $(patsubst n%,, \
- $(KMSAN_ENABLE_CHECKS_$(basetarget).o)$(KMSAN_ENABLE_CHECKS)y), \
+ $(KMSAN_ENABLE_CHECKS_$(target-stem).o)$(KMSAN_ENABLE_CHECKS)y), \
, -mllvm -msan-disable-checks=1)
endif

ifeq ($(CONFIG_UBSAN),y)
_c_flags += $(if $(patsubst n%,, \
- $(UBSAN_SANITIZE_$(basetarget).o)$(UBSAN_SANITIZE)$(CONFIG_UBSAN_SANITIZE_ALL)), \
+ $(UBSAN_SANITIZE_$(target-stem).o)$(UBSAN_SANITIZE)$(CONFIG_UBSAN_SANITIZE_ALL)), \
$(CFLAGS_UBSAN))
endif

ifeq ($(CONFIG_KCOV),y)
_c_flags += $(if $(patsubst n%,, \
- $(KCOV_INSTRUMENT_$(basetarget).o)$(KCOV_INSTRUMENT)$(CONFIG_KCOV_INSTRUMENT_ALL)), \
+ $(KCOV_INSTRUMENT_$(target-stem).o)$(KCOV_INSTRUMENT)$(CONFIG_KCOV_INSTRUMENT_ALL)), \
$(CFLAGS_KCOV))
endif

@@ -197,12 +197,12 @@ endif
#
ifeq ($(CONFIG_KCSAN),y)
_c_flags += $(if $(patsubst n%,, \
- $(KCSAN_SANITIZE_$(basetarget).o)$(KCSAN_SANITIZE)y), \
+ $(KCSAN_SANITIZE_$(target-stem).o)$(KCSAN_SANITIZE)y), \
$(CFLAGS_KCSAN))
# Some uninstrumented files provide implied barriers required to avoid false
# positives: set KCSAN_INSTRUMENT_BARRIERS for barrier instrumentation only.
_c_flags += $(if $(patsubst n%,, \
- $(KCSAN_INSTRUMENT_BARRIERS_$(basetarget).o)$(KCSAN_INSTRUMENT_BARRIERS)n), \
+ $(KCSAN_INSTRUMENT_BARRIERS_$(target-stem).o)$(KCSAN_INSTRUMENT_BARRIERS)n), \
-D__KCSAN_INSTRUMENT_BARRIERS__)
endif

--
2.40.1



2024-02-17 05:55:36

by Masahiro Yamada

[permalink] [raw]
Subject: [PATCH 2/2] kbuild: change DTC_FLAGS_<basetarget>.o to take the path relative to $(obj)

For the same rationale as commit 54b8ae66ae1a ("kbuild: change
*FLAGS_<basetarget>.o to take the path relative to $(obj)").

Signed-off-by: Masahiro Yamada <[email protected]>
---

scripts/Makefile.lib | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 328c0d77ed48..56f7fe2b476d 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -368,7 +368,7 @@ DTC_FLAGS += -Wnode_name_chars_strict \
-Wunique_unit_address
endif

-DTC_FLAGS += $(DTC_FLAGS_$(basetarget))
+DTC_FLAGS += $(DTC_FLAGS_$(target-stem))

# Set -@ if the target is a base DTB that overlay is applied onto
DTC_FLAGS += $(if $(filter $(patsubst $(obj)/%,%,$@), $(base-dtb-y)), -@)
--
2.40.1


2024-02-21 15:17:35

by Nicolas Schier

[permalink] [raw]
Subject: Re: [PATCH 1/2] kbuild: change tool coverage variables to take the path relative to $(obj)

On Sat 17 Feb 2024 14:55:03 GMT, Masahiro Yamada wrote:
> Commit 54b8ae66ae1a ("kbuild: change *FLAGS_<basetarget>.o to take the
> path relative to $(obj)") changed the syntax of per-file compiler flags.
>
> The situation is the same for the following variables:
>
> OBJECT_FILES_NON_STANDARD_<basetarget>.o
> GCOV_PROFILE_<basetarget>.o
> KASAN_SANITIZE_<basetarget>.o
> KMSAN_SANITIZE_<basetarget>.o
> KMSAN_ENABLE_CHECKS_<basetarget>.o
> UBSAN_SANITIZE_<basetarget>.o
> KCOV_INSTRUMENT_<basetarget>.o
> KCSAN_SANITIZE_<basetarget>.o
> KCSAN_INSTRUMENT_BARRIERS_<basetarget>.o
>
> The <basetarget> is the filename of the target with its directory and
> suffix stripped.
>
> This syntax comes into a trouble when two files with the same basename
> appear in one Makefile, for example:
>
> obj-y += dir1/foo.o
> obj-y += dir2/foo.o
> OBJECT_FILES_NON_STANDARD_foo.o := y
>
> OBJECT_FILES_NON_STANDARD_foo.o is applied to both dir1/foo.o and
> dir2/foo.o. This syntax is not flexbile enough to handle cases where
> one of them is a standard object, but the other is not.
>
> It is more sensible to use the relative path to the Makefile, like this:
>
> obj-y += dir1/foo.o
> OBJECT_FILES_NON_STANDARD_dir1/foo.o := y
> obj-y += dir2/foo.o
> OBJECT_FILES_NON_STANDARD_dir2/foo.o := y
>
> To maintain the current behavior, I made adjustments to two Makefiles:
>
> - arch/x86/entry/vdso/Makefile, which compiles vclock_gettime.o and
> vdso32/vclock_gettime.o
>
> - arch/x86/kvm/Makefile, which compiles vmx/vmenter.o and svm/vmenter.o
>
> Signed-off-by: Masahiro Yamada <[email protected]>
> ---
>
> arch/x86/entry/vdso/Makefile | 2 ++
> arch/x86/kvm/Makefile | 3 ++-
> scripts/Makefile.build | 2 +-
> scripts/Makefile.lib | 16 ++++++++--------
> 4 files changed, 13 insertions(+), 10 deletions(-)
>
> diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vdso/Makefile
> index 7a97b17f28b7..148adfdb2325 100644
> --- a/arch/x86/entry/vdso/Makefile
> +++ b/arch/x86/entry/vdso/Makefile
> @@ -9,7 +9,9 @@ include $(srctree)/lib/vdso/Makefile
> # Sanitizer runtimes are unavailable and cannot be linked here.
> KASAN_SANITIZE := n
> KMSAN_SANITIZE_vclock_gettime.o := n
> +KMSAN_SANITIZE_vdso32/vclock_gettime.o := n
> KMSAN_SANITIZE_vgetcpu.o := n
> +KMSAN_SANITIZE_vdso32/vgetcpu.o := n
>
> UBSAN_SANITIZE := n
> KCSAN_SANITIZE := n
> diff --git a/arch/x86/kvm/Makefile b/arch/x86/kvm/Makefile
> index 475b5fa917a6..a88bb14266b6 100644
> --- a/arch/x86/kvm/Makefile
> +++ b/arch/x86/kvm/Makefile
> @@ -4,7 +4,8 @@ ccflags-y += -I $(srctree)/arch/x86/kvm
> ccflags-$(CONFIG_KVM_WERROR) += -Werror
>
> ifeq ($(CONFIG_FRAME_POINTER),y)
> -OBJECT_FILES_NON_STANDARD_vmenter.o := y
> +OBJECT_FILES_NON_STANDARD_vmx/vmenter.o := y
> +OBJECT_FILES_NON_STANDARD_svm/vmenter.o := y
> endif
>
> include $(srctree)/virt/kvm/Makefile.kvm
> diff --git a/scripts/Makefile.build b/scripts/Makefile.build
> index 4971f54c855e..256db2a0e984 100644
> --- a/scripts/Makefile.build
> +++ b/scripts/Makefile.build
> @@ -214,7 +214,7 @@ endif # CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT
> # 'OBJECT_FILES_NON_STANDARD_foo.o := 'y': skip objtool checking for a file
> # 'OBJECT_FILES_NON_STANDARD_foo.o := 'n': override directory skip for a file
>
> -is-standard-object = $(if $(filter-out y%, $(OBJECT_FILES_NON_STANDARD_$(basetarget).o)$(OBJECT_FILES_NON_STANDARD)n),y)
> +is-standard-object = $(if $(filter-out y%, $(OBJECT_FILES_NON_STANDARD_$(target-stem).o)$(OBJECT_FILES_NON_STANDARD)n),y)
>
> $(obj)/%.o: objtool-enabled = $(if $(is-standard-object),$(if $(delay-objtool),$(is-single-obj-m),y))
>
> diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
> index b35d39022a30..328c0d77ed48 100644
> --- a/scripts/Makefile.lib
> +++ b/scripts/Makefile.lib
> @@ -154,7 +154,7 @@ _cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(target-stem).lds)
> #
> ifeq ($(CONFIG_GCOV_KERNEL),y)
> _c_flags += $(if $(patsubst n%,, \
> - $(GCOV_PROFILE_$(basetarget).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), \
> + $(GCOV_PROFILE_$(target-stem).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), \
> $(CFLAGS_GCOV))
> endif
>
> @@ -165,29 +165,29 @@ endif
> ifeq ($(CONFIG_KASAN),y)
> ifneq ($(CONFIG_KASAN_HW_TAGS),y)
> _c_flags += $(if $(patsubst n%,, \
> - $(KASAN_SANITIZE_$(basetarget).o)$(KASAN_SANITIZE)y), \
> + $(KASAN_SANITIZE_$(target-stem).o)$(KASAN_SANITIZE)y), \
> $(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE))
> endif
> endif
>
> ifeq ($(CONFIG_KMSAN),y)
> _c_flags += $(if $(patsubst n%,, \
> - $(KMSAN_SANITIZE_$(basetarget).o)$(KMSAN_SANITIZE)y), \
> + $(KMSAN_SANITIZE_$(target-stem).o)$(KMSAN_SANITIZE)y), \
> $(CFLAGS_KMSAN))
> _c_flags += $(if $(patsubst n%,, \
> - $(KMSAN_ENABLE_CHECKS_$(basetarget).o)$(KMSAN_ENABLE_CHECKS)y), \
> + $(KMSAN_ENABLE_CHECKS_$(target-stem).o)$(KMSAN_ENABLE_CHECKS)y), \
> , -mllvm -msan-disable-checks=1)
> endif
>
> ifeq ($(CONFIG_UBSAN),y)
> _c_flags += $(if $(patsubst n%,, \
> - $(UBSAN_SANITIZE_$(basetarget).o)$(UBSAN_SANITIZE)$(CONFIG_UBSAN_SANITIZE_ALL)), \
> + $(UBSAN_SANITIZE_$(target-stem).o)$(UBSAN_SANITIZE)$(CONFIG_UBSAN_SANITIZE_ALL)), \
> $(CFLAGS_UBSAN))
> endif
>
> ifeq ($(CONFIG_KCOV),y)
> _c_flags += $(if $(patsubst n%,, \
> - $(KCOV_INSTRUMENT_$(basetarget).o)$(KCOV_INSTRUMENT)$(CONFIG_KCOV_INSTRUMENT_ALL)), \
> + $(KCOV_INSTRUMENT_$(target-stem).o)$(KCOV_INSTRUMENT)$(CONFIG_KCOV_INSTRUMENT_ALL)), \
> $(CFLAGS_KCOV))
> endif
>
> @@ -197,12 +197,12 @@ endif
> #
> ifeq ($(CONFIG_KCSAN),y)
> _c_flags += $(if $(patsubst n%,, \
> - $(KCSAN_SANITIZE_$(basetarget).o)$(KCSAN_SANITIZE)y), \
> + $(KCSAN_SANITIZE_$(target-stem).o)$(KCSAN_SANITIZE)y), \
> $(CFLAGS_KCSAN))
> # Some uninstrumented files provide implied barriers required to avoid false
> # positives: set KCSAN_INSTRUMENT_BARRIERS for barrier instrumentation only.
> _c_flags += $(if $(patsubst n%,, \
> - $(KCSAN_INSTRUMENT_BARRIERS_$(basetarget).o)$(KCSAN_INSTRUMENT_BARRIERS)n), \
> + $(KCSAN_INSTRUMENT_BARRIERS_$(target-stem).o)$(KCSAN_INSTRUMENT_BARRIERS)n), \
> -D__KCSAN_INSTRUMENT_BARRIERS__)
> endif
>
> --
> 2.40.1
>

Looks good to me!

Reviewed-by: Nicolas Schier <[email protected]>


Attachments:
(No filename) (6.31 kB)
signature.asc (849.00 B)
Download all attachments

2024-02-21 15:22:31

by Nicolas Schier

[permalink] [raw]
Subject: Re: [PATCH 2/2] kbuild: change DTC_FLAGS_<basetarget>.o to take the path relative to $(obj)

On Sat 17 Feb 2024 14:55:04 GMT, Masahiro Yamada wrote:
> For the same rationale as commit 54b8ae66ae1a ("kbuild: change
> *FLAGS_<basetarget>.o to take the path relative to $(obj)").
>
> Signed-off-by: Masahiro Yamada <[email protected]>
> ---
>
> scripts/Makefile.lib | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
> index 328c0d77ed48..56f7fe2b476d 100644
> --- a/scripts/Makefile.lib
> +++ b/scripts/Makefile.lib
> @@ -368,7 +368,7 @@ DTC_FLAGS += -Wnode_name_chars_strict \
> -Wunique_unit_address
> endif
>
> -DTC_FLAGS += $(DTC_FLAGS_$(basetarget))
> +DTC_FLAGS += $(DTC_FLAGS_$(target-stem))
>
> # Set -@ if the target is a base DTB that overlay is applied onto
> DTC_FLAGS += $(if $(filter $(patsubst $(obj)/%,%,$@), $(base-dtb-y)), -@)
> --
> 2.40.1
>
>

Reviewed-by: Nicolas Schier <[email protected]>


Attachments:
(No filename) (931.00 B)
signature.asc (849.00 B)
Download all attachments

2024-02-21 15:24:34

by Sean Christopherson

[permalink] [raw]
Subject: Re: [PATCH 1/2] kbuild: change tool coverage variables to take the path relative to $(obj)

On Sat, Feb 17, 2024, Masahiro Yamada wrote:
> To maintain the current behavior, I made adjustments to two Makefiles:
>
> - arch/x86/entry/vdso/Makefile, which compiles vclock_gettime.o and
> vdso32/vclock_gettime.o
>
> - arch/x86/kvm/Makefile, which compiles vmx/vmenter.o and svm/vmenter.o
>
> Signed-off-by: Masahiro Yamada <[email protected]>
> ---
>
> arch/x86/entry/vdso/Makefile | 2 ++
> arch/x86/kvm/Makefile | 3 ++-
> scripts/Makefile.build | 2 +-
> scripts/Makefile.lib | 16 ++++++++--------
> 4 files changed, 13 insertions(+), 10 deletions(-)
>
> diff --git a/arch/x86/entry/vdso/Makefile b/arch/x86/entry/vdso/Makefile
> index 7a97b17f28b7..148adfdb2325 100644
> --- a/arch/x86/entry/vdso/Makefile
> +++ b/arch/x86/entry/vdso/Makefile
> @@ -9,7 +9,9 @@ include $(srctree)/lib/vdso/Makefile
> # Sanitizer runtimes are unavailable and cannot be linked here.
> KASAN_SANITIZE := n
> KMSAN_SANITIZE_vclock_gettime.o := n
> +KMSAN_SANITIZE_vdso32/vclock_gettime.o := n
> KMSAN_SANITIZE_vgetcpu.o := n
> +KMSAN_SANITIZE_vdso32/vgetcpu.o := n
>
> UBSAN_SANITIZE := n
> KCSAN_SANITIZE := n
> diff --git a/arch/x86/kvm/Makefile b/arch/x86/kvm/Makefile
> index 475b5fa917a6..a88bb14266b6 100644
> --- a/arch/x86/kvm/Makefile
> +++ b/arch/x86/kvm/Makefile
> @@ -4,7 +4,8 @@ ccflags-y += -I $(srctree)/arch/x86/kvm
> ccflags-$(CONFIG_KVM_WERROR) += -Werror
>
> ifeq ($(CONFIG_FRAME_POINTER),y)
> -OBJECT_FILES_NON_STANDARD_vmenter.o := y
> +OBJECT_FILES_NON_STANDARD_vmx/vmenter.o := y
> +OBJECT_FILES_NON_STANDARD_svm/vmenter.o := y
> endif

I'm 99% certain only svm/vmenter.S "needs" to be compiled with OBJECT_FILES_NON_STANDARD,
and that vmx/vmenter.S got caught in the crossfire off commit commit 7f4b5cde2409
("kvm: Disable objtool frame pointer checking for vmenter.S").

"Needs" in quotes because I don't see any reason when __svm_vcpu_run() can't play
the same games as __vmx_vcpu_run() to make stack validation happy, and
__svm_sev_es_vcpu_run() flat out shouldn't be touching RBP.

I'll throw together a series to (hopefully) remove OBJECT_FILES_NON_STANDARD
completely.

But for this patch/series, I think it makes sense to do a 1:1 conversion. That'll
make it much more straightforward to resolve the eventual conflict, assuming I am
successful in dropping OBJECT_FILES_NON_STANDARD.

Which is a very long-winded way of saying:

Acked-by: Sean Christopherson <[email protected]>