Commit Graph

129 Commits

Author SHA1 Message Date
Jerome Marchand 6646872b81 btf: remove redundant CONFIG_BPF test in scripts/link-vmlinux.sh
JIRA: https://issues.redhat.com/browse/RHEL-63880

Conflicts: Context change due to missing commit ddf41329839f ("kbuild:
refactor variables in scripts/link-vmlinux.sh")

commit c980dc9c67a94ab716ffc06767cb435480bda09d
Author: Masahiro Yamada <masahiroy@kernel.org>
Date:   Sat Sep 14 02:37:52 2024 +0900

    btf: remove redundant CONFIG_BPF test in scripts/link-vmlinux.sh

    CONFIG_DEBUG_INFO_BTF depends on CONFIG_BPF_SYSCALL, which in turn
    selects CONFIG_BPF.

    When CONFIG_DEBUG_INFO_BTF=y, CONFIG_BPF=y is always met.

    Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
    Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
    Acked-by: Andrii Nakryiko <andrii@kernel.org>
    Reviewed-by: Nathan Chancellor <nathan@kernel.org>
    Link: https://lore.kernel.org/r/20240913173759.1316390-1-masahiroy@kernel.org
    Signed-off-by: Alexei Starovoitov <ast@kernel.org>

Signed-off-by: Jerome Marchand <jmarchan@redhat.com>
2025-01-21 11:27:07 +01:00
Donald Dutile 62e0432100 kbuild: stop merging *.symversions
JIRA: https://issues.redhat.com/browse/RHEL-28063

Conflicts:
  RHEL doesn't make the same tmp files, so cleanup context is different.
  Synch to RHEL src to apply one line removal in hunk 3 in vmlinux.sh
  With objtool patch series to cs9/RHEL-9.5, have to remove 3 shell
  functions no longer in scripts/link-vmlinux.sh.

commit 7375cbcf2343a9337b19846e76dfd94c3af98a27
Author: Masahiro Yamada <masahiroy@kernel.org>
Date:   Fri May 13 20:39:23 2022 +0900

    kbuild: stop merging *.symversions

    Now modpost reads symbol versions from .*.cmd files.

    The merged *.symversions are no longer needed.

    Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
    Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
    Tested-by: Nathan Chancellor <nathan@kernel.org>
    Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM-14 (x86-64)

Signed-off-by: Donald Dutile <ddutile@redhat.com>
2024-06-17 14:17:17 -04:00
Donald Dutile ba0625ee4c kbuild: link symbol CRCs at final link, removing CONFIG_MODULE_REL_CRCS
JIRA: https://issues.redhat.com/browse/RHEL-28063

Conflicts:
	Minor ordering in patch-diff listing, but content the same.
	Well, after the objtool update, cs9 05c520e6c2 backport of upstream
	5d45950dffb and cs9 b206f546c7 backport of upstream b42d230650241 were
	applied out of order.  Maintain those changes by dropping 3
	shell functions.

commit 7b4537199a4a8480b8c3ba37a2d44765ce76cd9b
Author: Masahiro Yamada <masahiroy@kernel.org>
Date:   Fri May 13 20:39:22 2022 +0900

    kbuild: link symbol CRCs at final link, removing CONFIG_MODULE_REL_CRCS

    include/{linux,asm-generic}/export.h defines a weak symbol, __crc_*
    as a placeholder.

    Genksyms writes the version CRCs into the linker script, which will be
    used for filling the __crc_* symbols. The linker script format depends
    on CONFIG_MODULE_REL_CRCS. If it is enabled, __crc_* holds the offset
    to the reference of CRC.

    It is time to get rid of this complexity.

    Now that modpost parses text files (.*.cmd) to collect all the CRCs,
    it can generate C code that will be linked to the vmlinux or modules.

    Generate a new C file, .vmlinux.export.c, which contains the CRCs of
    symbols exported by vmlinux. It is compiled and linked to vmlinux in
    scripts/link-vmlinux.sh.

    Put the CRCs of symbols exported by modules into the existing *.mod.c
    files. No additional build step is needed for modules. As before,
    *.mod.c are compiled and linked to *.ko in scripts/Makefile.modfinal.

    No linker magic is used here. The new C implementation works in the
    same way, whether CONFIG_RELOCATABLE is enabled or not.
    CONFIG_MODULE_REL_CRCS is no longer needed.

    Previously, Kbuild invoked additional $(LD) to update the CRCs in
    objects, but this step is unneeded too.

    Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
    Tested-by: Nathan Chancellor <nathan@kernel.org>
    Tested-by: Nicolas Schier <nicolas@fjasle.eu>
    Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
    Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM-14 (x86-64)

Signed-off-by: Donald Dutile <ddutile@redhat.com>
2024-06-17 14:17:17 -04:00
Donald Dutile 9c1329a879 kbuild: generate a list of objects in vmlinux
JIRA: https://issues.redhat.com/browse/RHEL-28063

Conflict: Upstream a78b6af was backported in cs9 e84b28
          so source diff occurs; just apply rm of .obj files.

commit e493f472752000968f5b30aac10391288cfbf5b1
Author: Masahiro Yamada <masahiroy@kernel.org>
Date:   Thu May 5 16:22:34 2022 +0900

    kbuild: generate a list of objects in vmlinux

    A *.mod file lists the member objects of a module, but vmlinux does
    not have such a file.

    Generate this list to allow modpost to know all the member objects.

    Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
    Reviewed-by: Nicolas Schier <nicolas@fjasle.eu>
    Tested-by: Nathan Chancellor <nathan@kernel.org>

Signed-off-by: Donald Dutile <ddutile@redhat.com>
2024-06-17 14:17:16 -04:00
Donald Dutile 1c7ced2303 scripts: ftrace - move the sort-processing in ftrace_init
JIRA: https://issues.redhat.com/browse/RHEL-28063

commit 72b3942a173c387b27860ba1069636726e208777
Author: Yinan Liu <yinan@linux.alibaba.com>
Date:   Sun Dec 12 19:33:58 2021 +0800

    scripts: ftrace - move the sort-processing in ftrace_init

    When the kernel starts, the initialization of ftrace takes
    up a portion of the time (approximately 6~8ms) to sort mcount
    addresses. We can save this time by moving mcount-sorting to
    compile time.

    Link: https://lkml.kernel.org/r/20211212113358.34208-2-yinan@linux.alibaba.com

    Signed-off-by: Yinan Liu <yinan@linux.alibaba.com>
    Reported-by: kernel test robot <lkp@intel.com>
    Reported-by: kernel test robot <oliver.sang@intel.com>
    Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

Signed-off-by: Donald Dutile <ddutile@redhat.com>
2024-06-17 14:17:12 -04:00
Donald Dutile 3456e51ad2 scripts: update the comments of kallsyms support
JIRA: https://issues.redhat.com/browse/RHEL-28063

commit 2216cf68cf56808323bff44d43083422a1c4e2f9
Author: Hui Su <suhui_kernel@163.com>
Date:   Fri Oct 8 19:24:38 2021 +0800

    scripts: update the comments of kallsyms support

    update the comments of kallsyms support.

    Fixes: af73d78bd3 ("kbuild: Remove debug info from kallsyms linking")
    Signed-off-by: Hui Su <suhui_kernel@163.com>
    Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

Signed-off-by: Donald Dutile <ddutile@redhat.com>
2024-06-17 14:17:11 -04:00
Donald Dutile 681e8d877e kbuild: merge vmlinux_link() between ARCH=um and other architectures
JIRA: https://issues.redhat.com/browse/RHEL-28063

Conflicts:

commit 5df77ad61fd71b1b342ba40d913ad5595480691c
Author: Masahiro Yamada <masahiroy@kernel.org>
Date:   Thu Aug 19 09:57:39 2021 +0900

    kbuild: merge vmlinux_link() between ARCH=um and other architectures

    For ARCH=um, ${CC} is used as the linker driver. Hence, the linker
    options are prefixed with -Wl, .

    Merge the similar code.

    I replaced the -T option with the long option --script= so that it
    works well with/without ${wl}.

    Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
    Reviewed-by: Kees Cook <keescook@chromium.org>

Signed-off-by: Donald Dutile <ddutile@redhat.com>
2024-06-17 14:17:11 -04:00
Donald Dutile 3dfafb0624 kbuild: do not remove 'linux' link in scripts/link-vmlinux.sh
JIRA: https://issues.redhat.com/browse/RHEL-28063

commit d40aecd108d2a6413d53f6f8339e787a23150595
Author: Masahiro Yamada <masahiroy@kernel.org>
Date:   Thu Aug 19 09:57:38 2021 +0900

    kbuild: do not remove 'linux' link in scripts/link-vmlinux.sh

    arch/um/Makefile passes the -f option to the ln command:

      linux: vmlinux
              @echo '  LINK $@'
              $(Q)ln -f $< $@

    So, the hard link is always re-created, and the old one is removed
    anyway.

    Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
    Reviewed-by: Kees Cook <keescook@chromium.org>

Signed-off-by: Donald Dutile <ddutile@redhat.com>
2024-06-17 14:17:11 -04:00
Donald Dutile db0a3984ce kbuild: merge vmlinux_link() between the ordinary link and Clang LTO
JIRA: https://issues.redhat.com/browse/RHEL-28063

Conflicts:
 RHEL commit b2098ee852 backported upstream 8f1305124e out-of-order with respect to
 this upstream backport.  Just update the CONFIG_LTO_CLANG | X86_KERNEL_IBT if-check
 to apply this patch.

commit 8f1305124ea48943d1dd07683ed4f82c69b232ee
Author: Masahiro Yamada <masahiroy@kernel.org>
Date:   Thu Aug 19 09:57:37 2021 +0900

    kbuild: merge vmlinux_link() between the ordinary link and Clang LTO

    When Clang LTO is enabled, vmlinux_link() reuses vmlinux.o instead of
    re-linking ${KBUILD_VMLINUX_OBJS} and ${KBUILD_VMLINUX_LIBS}.

    That is the only difference here, so merge the similar code.

    Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
    Reviewed-by: Kees Cook <keescook@chromium.org>

Signed-off-by: Donald Dutile <ddutile@redhat.com>
2024-06-17 14:17:11 -04:00
Joe Lawrence b206f546c7 kbuild: factor out the common objtool arguments
JIRA: https://issues.redhat.com/browse/RHEL-2773
Conflicts:
	scripts/Makefile.build
	scripts/Makefile.lib
	scripts/link-vmlinux.sh
	- Undo previous RHEL-only conflict workarounds in these files
	  from cs-9 commits that avoided this backport:
	  - 69cd8c67c7 ("x86: Add prefix symbols for function
	    padding")
	  - 2354000bfc ("objtool: Add entry UNRET validation")
	  - 73afd5ec29 ("objtool: Add --hacks=skylake")
	  - 21de65cbaf ("x86/ibt: Implement FineIBT")
	  - af8931b273 ("kbuild: Fixup the IBT kbuild changes")
	  - eeb9f34df065 ("x86/srso: Fix unret validation dependencies")
	scripts/Makefile.vmlinux_o
	- cs-9 is doesn't have 9ec6ab6ee5ca ("kbuild: use objtool-args-y
	  to clean up objtool arguments"), add CONFIG_CPU_SRSO check to
	  objtool_args and not vmlinux-objtool-args

commit b42d2306502419688190aa6dd4dab4a6def24b3d
Author: Masahiro Yamada <masahiroy@kernel.org>
Date:   Sun May 29 00:47:04 2022 +0900

    kbuild: factor out the common objtool arguments

    scripts/Makefile.build and scripts/link-vmlinux.sh have similar setups
    for the objtool arguments.

    It was difficult to factor out them because all the vmlinux build rules
    were written in a shell script. It is somewhat tedious to touch the two
    files every time a new objtool option is supported.

    To reduce the code duplication, move the objtool for vmlinux.o into
    scripts/Makefile.vmlinux_o. Then, move the common macros to Makefile.lib
    so they are shared between Makefile.build and Makefile.vmlinux_o.

    Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
    Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM-14 (x86-64)

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2024-04-11 13:36:04 -04:00
Joe Lawrence 05c520e6c2 kbuild: move vmlinux.o link to scripts/Makefile.vmlinux_o
JIRA: https://issues.redhat.com/browse/RHEL-2773
Conflicts:
	scripts/link-vmlinux.sh
	- cs-9 is missing upstream commit 7375cbcf2343 ("kbuild: stop
	  merging *.symversions") and related modpost enhancements.
	  That said, cs-9 doesn't support CONFIG_LTO_CLANG, so it's only
	  deadcode either way.  Remove it from this file and push it off
	  to a future merge conflict resolution should lto/clang become
	  a requirement.

commit 5d45950dfbb1540bba3e3762a3497de8b4a715d3
Author: Masahiro Yamada <masahiroy@kernel.org>
Date:   Sun May 29 00:47:03 2022 +0900

    kbuild: move vmlinux.o link to scripts/Makefile.vmlinux_o

    This is a preparation for moving the objtool rule in the next commit.

    Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
    Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM-14 (x86-64)

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2024-04-03 16:10:00 -04:00
Joe Lawrence e84b28ff5e kbuild: remove redundant cleanups in scripts/link-vmlinux.sh
JIRA: https://issues.redhat.com/browse/RHEL-2773
Conflicts:
	scripts/link-vmlinux.sh
	- diff-context, cs-9 does not have upstream 26ef40de5cbb
	  ("kbuild: move .vmlinux.objs rule to Makefile.modpost") or
	  5d4aeffbf709 ("kbuild: rebuild .vmlinux.export.o when its prerequisite
	  is updated")

commit a78b6afa9913890e92aede1c17e72dec7e528549
Author: Masahiro Yamada <masahiroy@kernel.org>
Date:   Sun May 29 00:47:01 2022 +0900

    kbuild: remove redundant cleanups in scripts/link-vmlinux.sh

    These are cleaned by the top Makefile.

    vmlinux.o and .vmlinux.d matches the '*.[aios]' and '.*.d' patterns
    respectively.

    Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
    Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM-14 (x86-64)

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2024-04-03 16:10:00 -04:00
Prarit Bhargava ec115ccc57 objtool: Add --mnop as an option to --mcount
JIRA: https://issues.redhat.com/browse/RHEL-25415

Conflicts: The handling of objtool args is different in RHEL9 than it is
upstream.  The scripts/Makefile.lib chunk is correctly applied to
scripts/link-vmlinux.sh in RHEL9.

commit 280981d6994e0700abd36647b141e73059851e66
Author: Sathvika Vasireddy <sv@linux.ibm.com>
Date:   Mon Nov 14 23:27:49 2022 +0530

    objtool: Add --mnop as an option to --mcount

    Some architectures (powerpc) may not support ftrace locations being nop'ed
    out at build time. Introduce CONFIG_HAVE_OBJTOOL_NOP_MCOUNT for objtool, as
    a means for architectures to enable nop'ing of ftrace locations. Add --mnop
    as an option to objtool --mcount, to indicate support for the same.

    Also, make sure that --mnop can be passed as an option to objtool only when
    --mcount is passed.

    Tested-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
    Reviewed-by: Naveen N. Rao <naveen.n.rao@linux.vnet.ibm.com>
    Acked-by: Josh Poimboeuf <jpoimboe@kernel.org>
    Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu>
    Signed-off-by: Sathvika Vasireddy <sv@linux.ibm.com>
    Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
    Link: https://lore.kernel.org/r/20221114175754.1131267-12-sv@linux.ibm.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:43:05 -04:00
Prarit Bhargava 90afb09040 objtool: Add CONFIG_HAVE_UACCESS_VALIDATION
JIRA: https://issues.redhat.com/browse/RHEL-25415

Conflicts: Minor drift issues.

commit 5f3da8c08508df82823566c32f753071c8ad36af
Author: Josh Poimboeuf <jpoimboe@kernel.org>
Date:   Tue Apr 19 09:05:09 2022 -0700

    objtool: Add CONFIG_HAVE_UACCESS_VALIDATION

    Allow an arch specify that it has objtool uaccess validation with
    CONFIG_HAVE_UACCESS_VALIDATION.  For now, doing so unconditionally
    selects CONFIG_OBJTOOL.

    Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Link: https://lkml.kernel.org/r/d393d5e2fe73aec6e8e41d5c24f4b6fe8583f2d8.1650384225.git.jpoimboe@redhat.com

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:42:36 -04:00
Prarit Bhargava a726257f31 x86/cpu: Remove CONFIG_X86_SMAP and "nosmap"
JIRA: https://issues.redhat.com/browse/RHEL-25415

Conflicts: Minor drift issues between upstream and RHEL9.

commit dbae0a934f09208075ec3e73491bd0844e1397b3
Author: Borislav Petkov <bp@suse.de>
Date:   Thu Jan 27 12:56:23 2022 +0100

    x86/cpu: Remove CONFIG_X86_SMAP and "nosmap"

    Those were added as part of the SMAP enablement but SMAP is currently
    an integral part of kernel proper and there's no need to disable it
    anymore.

    Rip out that functionality. Leave --uaccess default on for objtool as
    this is what objtool should do by default anyway.

    If still needed - clearcpuid=smap.

    Signed-off-by: Borislav Petkov <bp@suse.de>
    Reviewed-by: Lai Jiangshan <jiangshanlai@gmail.com>
    Reviewed-by: Kees Cook <keescook@chromium.org>
    Link: https://lore.kernel.org/r/20220127115626.14179-4-bp@alien8.de

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
2024-03-20 09:42:31 -04:00
Waiman Long 65ade2d14e x86/srso: Fix unret validation dependencies
JIRA: https://issues.redhat.com/browse/RHEL-8594
CVE: CVE-2023-20569
Upstream Status: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git
Conflicts: A merge conflict for the scripts/Makefile.vmlinux_o hunk
	   due to missing upstream commit 5d45950dfbb1 ("kbuild: move
	   vmlinux.o link to scripts/Makefile.vmlinux_o"). Instead,
	   the change is applied to scripts/link-vmlinux.sh and include
	   the missing hunk of the merge upstream commit f43b9876e857
	   ("x86/retbleed: Add fine grained Kconfig knobs").

commit eeb9f34df065f42f0c9195b322ba6df420c9fc92
Author: Josh Poimboeuf <jpoimboe@kernel.org>
Date:   Mon, 4 Sep 2023 22:04:53 -0700

    x86/srso: Fix unret validation dependencies

    CONFIG_CPU_SRSO isn't dependent on CONFIG_CPU_UNRET_ENTRY (AMD
    Retbleed), so the two features are independently configurable.  Fix
    several issues for the (presumably rare) case where CONFIG_CPU_SRSO is
    enabled but CONFIG_CPU_UNRET_ENTRY isn't.

    Fixes: fb3bd914b3ec ("x86/srso: Add a Speculative RAS Overflow mitigation")
    Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
    Signed-off-by: Ingo Molnar <mingo@kernel.org>
    Signed-off-by: Borislav Petkov (AMD) <bp@alien8.de>
    Acked-by: Borislav Petkov (AMD) <bp@alien8.de>
    Link: https://lore.kernel.org/r/299fb7740174d0f2335e91c58af0e9c242b4bac1.1693889988.git.jpoimboe@kernel.org

Signed-off-by: Waiman Long <longman@redhat.com>
2023-10-22 20:24:07 -04:00
Waiman Long 73afd5ec29 objtool: Add --hacks=skylake
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2190342
Conflicts: The scripts/Makefile.lib hunk is applied with modification to
	   scripts/Makefile.build and scripts/link-vmlinux.sh due
	   to missing upstream commit 9ec6ab6ee5ca ("kbuild: use
	   objtool-args-y to clean up objtool arguments") & other
	   related commits.

commit 0c0a6d8934e2081df93ba0bfc0cf615cc9c06988
Author: Peter Zijlstra <peterz@infradead.org>
Date:   Thu, 15 Sep 2022 13:11:10 +0200

    objtool: Add --hacks=skylake

    Make the call/func sections selectable via the --hacks option.

    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Link: https://lore.kernel.org/r/20220915111146.120821440@infradead.org

Signed-off-by: Waiman Long <longman@redhat.com>
2023-06-30 20:17:17 -04:00
Waiman Long b9351344b3 kbuild: clean .tmp_* pattern by make clean
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2190342
Conflicts: A merge conflict in the scripts/link-vmlinux.sh hunk
	   due to missing upstream commit 7375cbcf2343 ("kbuild: stop
	   merging *.symversions").

commit b0d6207bad2cb5a6f2099ac4a6ea4e76864dd596
Author: Masahiro Yamada <masahiroy@kernel.org>
Date:   Sun, 29 May 2022 00:47:02 +0900

    kbuild: clean .tmp_* pattern by make clean

    Change the "make clean" rule to remove all the .tmp_* files.

    .tmp_objdiff is the only exception, which should be removed by
    "make mrproper".

    Rename the record directory of objdiff, .tmp_objdiff to .objdiff to
    avoid the removal by "make clean".

    Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
    Tested-by: Sedat Dilek <sedat.dilek@gmail.com> # LLVM-14 (x86-64)

Signed-off-by: Waiman Long <longman@redhat.com>
2023-06-30 19:59:54 -04:00
Waiman Long 3a42bee6bb kbuild: fix empty ${PYTHON} in scripts/link-vmlinux.sh
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2190342

commit 099c22bdca406733c80f3d34ea2d2554bd15fb16
Author: Masahiro Yamada <masahiroy@kernel.org>
Date:   Tue, 29 Mar 2022 11:14:36 +0900

    kbuild: fix empty ${PYTHON} in scripts/link-vmlinux.sh

    The two commits

      d8d2d38275 ("kbuild: remove PYTHON variable")
      a8cccdd954 ("init: lto: ensure initcall ordering")

    were applied in the same development cycle, into two different trees.

    After they were merged together, this ${PYTHON} expands to an empty
    string.

    Therefore, ${srctree}/scripts/jobserver-exec is executed directly.
    (it has the executable bit set)

    This is working but let's fix the code into the intended form.

    Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
    Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
    Reviewed-by: Sedat Dilek <sedat.dilek@gmail.com>

Signed-off-by: Waiman Long <longman@redhat.com>
2023-06-30 19:59:52 -04:00
Joe Lawrence 69cd8c67c7 x86: Add prefix symbols for function padding
JIRA: https://issues.redhat.com/browse/RHEL-255

Conflicts:
	scripts/Makefile.lib
	- cs-9 doesn't have b42d23065024 ("kbuild: factor out the
	  common objtool arguments") or 9ec6ab6ee5ca ("kbuild: use
	  objtool-args-y to clean up objtool arguments"), which moved
	  moved objtool_args from scripts/Makefile.build and objtooltopt
	  from scripts/link-vmlinux.sh to scripts/Makefile.lib.  Add the
	  --prefix option to both of former files instead.

	  At the same time, provide scripts/link-vmlinux.sh workarounds
	  to read the CONFIG_FUNCTION_PADDING_BYTES value and only
	  enable objtool for vmlinux.o given the same configuration
	  conditions in b42d23065024.

commit b341b20d648bb7e9a3307c33163e7399f0913e66
Author: Peter Zijlstra <peterz@infradead.org>
Date:   Fri Oct 28 21:08:19 2022 +0200

    x86: Add prefix symbols for function padding

    When code is compiled with:

      -fpatchable-function-entry=${PADDING_BYTES},${PADDING_BYTES}

    functions will have PADDING_BYTES of NOP in front of them. Unwinders
    and other things that symbolize code locations will typically
    attribute these bytes to the preceding function.

    Given that these bytes nominally belong to the following symbol this
    mis-attribution is confusing.

    Inspired by the fact that CFI_CLANG emits __cfi_##name symbols to
    claim these bytes, use objtool to emit __pfx_##name symbols to do
    the same when CFI_CLANG is not used.

    This then shows the callthunk for symbol 'name' as:

      __pfx_##name+0x6/0x10

    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Tested-by: Yujie Liu <yujie.liu@intel.com>
    Link: https://lkml.kernel.org/r/20221028194453.592512209@infradead.org

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2023-05-18 15:09:34 -04:00
Joe Lawrence 2354000bfc objtool: Add entry UNRET validation
JIRA: https://issues.redhat.com/browse/RHEL-255
Conflicts:
	arch/x86/include/asm/nospec-branch.h
	- cs-9 already has upstream f43b9876e857 ("x86/retbleed: Add
	  fine grained Kconfig knobs"), check for CONFIG_CPU_UNRET_ENTRY
	  or CONFIG_CPU_IBPB_ENTRY instead of CONFIG_RETPOLINE

	tools/objtool/builtin-check.c
	tools/objtool/include/objtool/builtin.h
	- c9-9 already has upstream f43b9876e857 ("x86/retbleed: Add
	  fine grained Kconfig knobs")

	include/linux/objtool.h
	tools/include/linux/objtool.h
	- cs-9 already has upstream 8faea26e6111 ("objtool: Re-add
	  UNWIND_HINT_{SAVE_RESTORE}"), insert UNWIND_HINT_TYPE_ENTRY
	  into the available 4th enum

	tools/objtool/check.c
	- cs-9 already has upstream 8faea26e6111 ("objtool: Re-add
	  UNWIND_HINT_{SAVE_RESTORE}"), apply
	  UNWIND_HINT_TYPE_REGS_PARTIAL hunk in read_unwind_hints()
	  manually

	tools/objtool/include/objtool/check.h
	- cs-9 already has upstream 8faea26e6111 ("objtool: Re-add
	  UNWIND_HINT_{SAVE_RESTORE}"), which added save and restore
	  values to struct instruction.  While we're here, fix the
	  alignment of the bitfields that said omitted.

	scripts/Makefile.vmlinux_o
	- cs-9 doesn't have upstream 5d45950dfbb1 ("kbuild: move
	  vmlinux.o link to scripts/Makefile.vmlinux_o") or b42d23065024
	  ("kbuild: factor out the common objtool arguments"), so add
	  objtool --unret option in scripts/link-vmlinux.sh

commit a09a6e2399ba0595c3042b3164f3ca68a3cff33e
Author: Peter Zijlstra <peterz@infradead.org>
Date:   Tue Jun 14 23:16:03 2022 +0200

    objtool: Add entry UNRET validation

    Since entry asm is tricky, add a validation pass that ensures the
    retbleed mitigation has been done before the first actual RET
    instruction.

    Entry points are those that either have UNWIND_HINT_ENTRY, which acts
    as UNWIND_HINT_EMPTY but marks the instruction as an entry point, or
    those that have UWIND_HINT_IRET_REGS at +0.

    This is basically a variant of validate_branch() that is
    intra-function and it will simply follow all branches from marked
    entry points and ensures that all paths lead to ANNOTATE_UNRET_END.

    If a path hits RET or an indirection the path is a fail and will be
    reported.

    There are 3 ANNOTATE_UNRET_END instances:

     - UNTRAIN_RET itself
     - exception from-kernel; this path doesn't need UNTRAIN_RET
     - all early exceptions; these also don't need UNTRAIN_RET

    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Signed-off-by: Borislav Petkov <bp@suse.de>
    Reviewed-by: Josh Poimboeuf <jpoimboe@kernel.org>
    Signed-off-by: Borislav Petkov <bp@suse.de>

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2023-05-18 15:09:33 -04:00
Joe Lawrence 4452c87386 objtool: Remove --lto and --vmlinux in favor of --link
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2121207
Conflicts:
	scripts/Makefile.build
	- rhel9 doesn't have d31ed5d767c0 ("kbuild: Fixup the IBT kbuild
	  changes")

commit 753da4179d08b625d8df72e97724e22749969fd3
Author: Josh Poimboeuf <jpoimboe@redhat.com>
Date:   Mon Apr 18 09:50:43 2022 -0700

    objtool: Remove --lto and --vmlinux in favor of --link

    The '--lto' option is a confusing way of telling objtool to do stack
    validation despite it being a linked object.  It's no longer needed now
    that an explicit '--stackval' option exists.  The '--vmlinux' option is
    also redundant.

    Remove both options in favor of a straightforward '--link' option which
    identifies a linked object.

    Also, implicitly set '--link' with a warning if the user forgets to do
    so and we can tell that it's a linked object.  This makes it easier for
    manual vmlinux runs.

    Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Reviewed-by: Miroslav Benes <mbenes@suse.cz>
    Link: https://lkml.kernel.org/r/dcd3ceffd15a54822c6183e5766d21ad06082b45.1650300597.git.jpoimboe@redhat.com

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-10-27 15:26:52 -04:00
Joe Lawrence 5c9d56d641 objtool: Rename "VMLINUX_VALIDATION" -> "NOINSTR_VALIDATION"
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2121207

commit 0f620cefd7753175b6258fed85f76c2014ec3799
Author: Josh Poimboeuf <jpoimboe@redhat.com>
Date:   Mon Apr 18 09:50:41 2022 -0700

    objtool: Rename "VMLINUX_VALIDATION" -> "NOINSTR_VALIDATION"

    CONFIG_VMLINUX_VALIDATION is just the validation of the "noinstr" rules.
    That name is a misnomer, because now objtool actually does vmlinux
    validation for other reasons.

    Rename CONFIG_VMLINUX_VALIDATION to CONFIG_NOINSTR_VALIDATION.

    Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Reviewed-by: Miroslav Benes <mbenes@suse.cz>
    Link: https://lkml.kernel.org/r/173f07e2d6d1afc0874aed975a61783207c6a531.1650300597.git.jpoimboe@redhat.com

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-10-27 15:26:52 -04:00
Joe Lawrence 1c95421e0c objtool: Make noinstr hacks optional
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2121207
Conflicts:
	lib/Kconfig.debug
	- rhel9 doesn't have upstream bece04b5b41d ("kcov: fix generic
	  Kconfig dependencies if ARCH_WANTS_NO_INSTR")

	lib/Kconfig.kcsan
	- rhel9 doesn't have upstream 69562e4983d9 ("kcsan: Add core
	  support for a subset of weak memory modeling"), so can't
	  update KCSAN_WEAK_MEMORY dependencies

commit 22102f4559beaabcea614b29ee090c6a214f002f
Author: Josh Poimboeuf <jpoimboe@redhat.com>
Date:   Mon Apr 18 09:50:40 2022 -0700

    objtool: Make noinstr hacks optional

    Objtool has some hacks in place to workaround toolchain limitations
    which otherwise would break no-instrumentation rules.  Make the hacks
    explicit (and optional for other arches) by turning it into a cmdline
    option and kernel config option.

    Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Reviewed-by: Miroslav Benes <mbenes@suse.cz>
    Link: https://lkml.kernel.org/r/b326eeb9c33231b9dfbb925f194ed7ee40edcd7c.1650300597.git.jpoimboe@redhat.com

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-10-27 15:26:52 -04:00
Joe Lawrence 24b5577e5a objtool: Make jump label hack optional
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2121207

commit 4ab7674f5951ac6a8ac4fa8828090edb64a4771f
Author: Josh Poimboeuf <jpoimboe@redhat.com>
Date:   Mon Apr 18 09:50:39 2022 -0700

    objtool: Make jump label hack optional

    Objtool secretly does a jump label hack to overcome the limitations of
    the toolchain.  Make the hack explicit (and optional for other arches)
    by turning it into a cmdline option and kernel config option.

    Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Reviewed-by: Miroslav Benes <mbenes@suse.cz>
    Link: https://lkml.kernel.org/r/3bdcbfdd27ecb01ddec13c04bdf756a583b13d24.1650300597.git.jpoimboe@redhat.com

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-10-27 15:26:52 -04:00
Joe Lawrence de76019265 objtool: Make static call annotation optional
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2121207
Conflicts:
	scripts/Makefile.build
	tools/objtool/builtin-check.c
	tools/objtool/include/objtool/builtin.h
	- (diff context) rhel9 already has upstream f43b9876e857
	  ("x86/retbleed: Add fine grained Kconfig knobs"), which added
	  --rethunk option

commit 26e176896a5bb9222ae3433da902edd2566a61a4
Author: Josh Poimboeuf <jpoimboe@redhat.com>
Date:   Mon Apr 18 09:50:38 2022 -0700

    objtool: Make static call annotation optional

    As part of making objtool more modular, put the existing static call
    code behind a new '--static-call' option.

    Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Reviewed-by: Miroslav Benes <mbenes@suse.cz>
    Link: https://lkml.kernel.org/r/d59ac57ef3d6d8380cdce20322314c9e2e556750.1650300597.git.jpoimboe@redhat.com

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-10-27 15:26:52 -04:00
Joe Lawrence d094a92b30 objtool: Make stack validation frame-pointer-specific
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2121207

commit 72064474964724c59ddff58a581a31b1ede75cf9
Author: Josh Poimboeuf <jpoimboe@redhat.com>
Date:   Mon Apr 18 09:50:37 2022 -0700

    objtool: Make stack validation frame-pointer-specific

    Now that CONFIG_STACK_VALIDATION is frame-pointer specific, do the same
    for the '--stackval' option.  Now the '--no-fp' option is redundant and
    can be removed.

    Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Reviewed-by: Miroslav Benes <mbenes@suse.cz>
    Link: https://lkml.kernel.org/r/f563fa064b3b63d528de250c72012d49e14742a3.1650300597.git.jpoimboe@redhat.com

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-10-27 15:26:51 -04:00
Joe Lawrence c2c4f22d4a objtool: Add CONFIG_OBJTOOL
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2121207
Conflicts:
	arch/x86/Kconfig
	- (diff context) rhel9 doesn't have upstream f6a2c2b2de81
	  ("x86/Kconfig: Only allow CONFIG_X86_KERNEL_IBT with ld.lld
	  >= 14.0.0")
	- (diff context) rhel9 doesn't have upstream 4ed308c445a1
	  ("ftrace: Have architectures opt-in for mcount build time
	  sorting")
	- rhel9 already has upstream f43b9876e857 ("x86/retbleed: Add
	  fine grained Kconfig knobs"), which moved config RETPOLINE
	  lower in the file, adds config RETHUNK, etc.
	- (diff context) rhel9 already has upstream 1e9fdf21a433
	  ("mmu_gather: Remove per arch tlb_{start,end}_vma()"), which
          added MMU_GATHER_MERGE_VMAS

	arch/x86/kernel/alternative.c
	- rhel9 already has upstream
	  f43b9876e857 ("x86/retbleed: Add fine grained Kconfig knobs")
	  which introduced CONFIG_RETHUNK

	lib/Kconfig.debug
	- rhel9 doesn't have upstream bece04b5b41d ("kcov: fix generic
	  Kconfig dependencies if ARCH_WANTS_NO_INSTR")

	lib/Kconfig.kcsan
	- rhel9 doesn't have upstream 69562e4983d9 ("kcsan: Add core
	  support for a subset of weak memory modeling"), so can't
	  update KCSAN_WEAK_MEMORY dependencies

commit 03f16cd020eb8bb2eb837e2090086f296a9fa91d
Author: Josh Poimboeuf <jpoimboe@redhat.com>
Date:   Mon Apr 18 09:50:36 2022 -0700

    objtool: Add CONFIG_OBJTOOL

    Now that stack validation is an optional feature of objtool, add
    CONFIG_OBJTOOL and replace most usages of CONFIG_STACK_VALIDATION with
    it.

    CONFIG_STACK_VALIDATION can now be considered to be frame-pointer
    specific.  CONFIG_UNWINDER_ORC is already inherently valid for live
    patching, so no need to "validate" it.

    Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Reviewed-by: Miroslav Benes <mbenes@suse.cz>
    Link: https://lkml.kernel.org/r/939bf3d85604b2a126412bf11af6e3bd3b872bcb.1650300597.git.jpoimboe@redhat.com

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-10-27 15:26:51 -04:00
Joe Lawrence 9d949ad038 objtool: Make stack validation optional
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2121207

commit 7dce62041ac34b613a5ed1bd937117e492e06dc8
Author: Josh Poimboeuf <jpoimboe@redhat.com>
Date:   Mon Apr 18 09:50:33 2022 -0700

    objtool: Make stack validation optional

    Make stack validation an explicit cmdline option so that individual
    objtool features can be enabled individually by other arches.

    Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Reviewed-by: Miroslav Benes <mbenes@suse.cz>
    Link: https://lkml.kernel.org/r/52da143699574d756e65ca4c9d4acaffe9b0fe5f.1650300597.git.jpoimboe@redhat.com

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>

squash with 3158d8573495d
2022-10-27 15:26:51 -04:00
Joe Lawrence bb89dd33f5 objtool: Ditch subcommands
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2121207
Conflicts:
	scripts/Makefile.build
	tools/objtool/builtin-check.c
	tools/objtool/include/objtool/builtin.h
	- (diff context) rhel9 already has upstream f43b9876e857
	  ("x86/retbleed: Add fine grained Kconfig knobs"),
	  which added --rethunk option and CONFIG_RETHUNK

commit b51277eb9775ce916f9efd2c51533e481180c1e8
Author: Josh Poimboeuf <jpoimboe@redhat.com>
Date:   Mon Apr 18 09:50:27 2022 -0700

    objtool: Ditch subcommands

    Objtool has a fairly singular focus.  It runs on object files and does
    validations and transformations which can be combined in various ways.
    The subcommand model has never been a good fit, making it awkward to
    combine and remove options.

    Remove the "check" and "orc" subcommands in favor of a more traditional
    cmdline option model.  This makes it much more flexible to use, and
    easier to port individual features to other arches.

    Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Reviewed-by: Miroslav Benes <mbenes@suse.cz>
    Link: https://lkml.kernel.org/r/5c61ebf805e90aefc5fa62bc63468ffae53b9df6.1650300597.git.jpoimboe@redhat.com

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-10-27 15:26:51 -04:00
Joe Lawrence 330dad14bf objtool: Reorganize cmdline options
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2121207
Conflicts:
	scripts/Makefile.build
	- rhel9 already has CONFIG_RETHUNK from upstream f43b9876e857
	  ("x86/retbleed: Add fine grained Kconfig knobs")

	tools/objtool/builtin-check.c
	- rhel9 already has upstream f43b9876e857 ("x86/retbleed: Add fine
	  grained Kconfig knobs"), which added --rethunk option

	tools/objtool/check.c
	tools/objtool/include/objtool/builtin.h
	- rhel9 already has upstream f43b9876e857 ("x86/retbleed: Add fine
	  grained Kconfig knobs"), account for rethunk code

commit 2daf7faba7ded8703e4b4ebc8b161f22272fc91a
Author: Josh Poimboeuf <jpoimboe@redhat.com>
Date:   Mon Apr 18 09:50:26 2022 -0700

    objtool: Reorganize cmdline options

    Split the existing options into two groups: actions, which actually do
    something; and options, which modify the actions in some way.

    Also there's no need to have short flags for all the non-action options.
    Reserve short flags for the more important actions.

    While at it:

    - change a few of the short flags to be more intuitive

    - make option descriptions more consistently descriptive

    - sort options in the source like they are when printed

    - move options to a global struct

    Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Reviewed-by: Miroslav Benes <mbenes@suse.cz>
    Link: https://lkml.kernel.org/r/9dcaa752f83aca24b1b21f0b0eeb28a0c181c0b0.1650300597.git.jpoimboe@redhat.com

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-10-27 15:26:51 -04:00
Joe Lawrence 7977f5a98a objtool: Enable unreachable warnings for CLANG LTO
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2121207

commit 4a5de9b76fcb3f477f73d5a63f6e27709e8af81f
Author: Josh Poimboeuf <jpoimboe@redhat.com>
Date:   Mon Apr 18 09:50:20 2022 -0700

    objtool: Enable unreachable warnings for CLANG LTO

    With IBT support in, objtool is now fully capable of following vmlinux
    code flow in LTO mode.  Start reporting unreachable warnings for Clang
    LTO as well.

    Fixes: ed53a0d97192 ("x86/alternative: Use .ibt_endbr_seal to seal indirect calls")
    Signed-off-by: Josh Poimboeuf <jpoimboe@redhat.com>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Link: https://lkml.kernel.org/r/7b12df54bceeb0761fe9fc8269ea0c00501214a9.1650300597.git.jpoimboe@redhat.com

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-10-27 15:26:50 -04:00
Joe Lawrence b2098ee852 x86/alternative: Use .ibt_endbr_seal to seal indirect calls
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2121207
Conflicts:
	arch/x86/include/asm/alternative.h
	arch/x86/kernel/alternative.c
	arch/x86/kernel/module.c
	- rhel9 already contains upstream 15e67227c49a
	  ("x86: Undo return-thunk damage") which added return sites
	scripts/link-vmlinux.sh
	- (diff context) rhel9 doesn't have 8f1305124ea4 ("kbuild: merge
	  vmlinux_link() between the ordinary link and Clang LTO")
	- (diff context) rhel9 doesn't have 5df77ad61fd7 ("kbuild: merge
	  vmlinux_link() between ARCH=um and other architectures")

commit ed53a0d971926e484d86cce617ec02a7ee85c3fe
Author: Peter Zijlstra <peterz@infradead.org>
Date:   Tue Mar 8 16:30:56 2022 +0100

    x86/alternative: Use .ibt_endbr_seal to seal indirect calls

    Objtool's --ibt option generates .ibt_endbr_seal which lists
    superfluous ENDBR instructions. That is those instructions for which
    the function is never indirectly called.

    Overwrite these ENDBR instructions with a NOP4 such that these
    function can never be indirect called, reducing the number of viable
    ENDBR targets in the kernel.

    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>
    Link: https://lore.kernel.org/r/20220308154319.822545231@infradead.org

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-10-27 14:27:59 -04:00
Joe Lawrence 59a78fdd7e objtool: Rename --duplicate to --lto
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2121207
Conflicts:
	tools/objtool/builtin-check.c
	tools/objtool/include/objtool/builtin.h
	- rhel9 already contains backport of upstream f43b9876e857
	  ("x86/retbleed: Add fine grained Kconfig knobs"), which added
	  rethunk option

commit 53f7109ef957315ab53205ba3a3f4f48874c0428
Author: Peter Zijlstra <peterz@infradead.org>
Date:   Tue Mar 8 16:30:45 2022 +0100

    objtool: Rename --duplicate to --lto

    In order to prepare for LTO like objtool runs for modules, rename the
    duplicate argument to lto.

    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Acked-by: Josh Poimboeuf <jpoimboe@redhat.com>
    Link: https://lore.kernel.org/r/20220308154319.172584233@infradead.org

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>
2022-10-27 14:27:58 -04:00
Joe Lawrence b0c5d68f8d kbuild: do not include include/config/auto.conf from shell scripts
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2121207
Conflicts:
	scripts/link-vmlinux.sh
	- rhel9 is missing upstream 8f1305124ea4 ("kbuild: merge
	  vmlinux_link() between the ordinary link and Clang LTO"),
	  rhel9 already has upstream e463a09af2f0 ("x86: Add
	  straight-line-speculation mitigation"), manually update
	  vmlinux_link for is_enabled() helper

commit 7d153696e5db1e37387c2f7ec06ffc8d4aac70a4
Author: Masahiro Yamada <masahiroy@kernel.org>
Date:   Tue Dec 14 11:53:52 2021 +0900

    kbuild: do not include include/config/auto.conf from shell scripts

    Richard Weinberger pointed out the risk of sourcing the kernel config
    from shell scripts [1], and proposed some patches [2], [3]. It is a good
    point, but it took a long time because I was wondering how to fix this.

    This commit goes with simple grep approach because there are only a few
    scripts including the kernel configuration.

    scripts/link_vmlinux.sh has references to a bunch of CONFIG options,
    all of which are boolean. I added is_enabled() helper as
    scripts/package/{mkdebian,builddeb} do.

    scripts/gen_autoksyms.sh uses 'eval', stating "to expand the whitelist
    path". I removed it since it is the issue we are trying to fix.

    I was a bit worried about the cost of invoking the grep command over
    again. I extracted the grep parts from it, and measured the cost. It
    was approximately 0.03 sec, which I hope is acceptable.

    [test code]

      $ cat test-grep.sh
      #!/bin/sh

      is_enabled() {
              grep -q "^$1=y" include/config/auto.conf
      }

      is_enabled CONFIG_LTO_CLANG
      is_enabled CONFIG_LTO_CLANG
      is_enabled CONFIG_STACK_VALIDATION
      is_enabled CONFIG_UNWINDER_ORC
      is_enabled CONFIG_FTRACE_MCOUNT_USE_OBJTOOL
      is_enabled CONFIG_VMLINUX_VALIDATION
      is_enabled CONFIG_FRAME_POINTER
      is_enabled CONFIG_GCOV_KERNEL
      is_enabled CONFIG_LTO_CLANG
      is_enabled CONFIG_RETPOLINE
      is_enabled CONFIG_X86_SMAP
      is_enabled CONFIG_LTO_CLANG
      is_enabled CONFIG_VMLINUX_MAP
      is_enabled CONFIG_KALLSYMS_ALL
      is_enabled CONFIG_KALLSYMS_ABSOLUTE_PERCPU
      is_enabled CONFIG_KALLSYMS_BASE_RELATIVE
      is_enabled CONFIG_DEBUG_INFO_BTF
      is_enabled CONFIG_KALLSYMS
      is_enabled CONFIG_DEBUG_INFO_BTF
      is_enabled CONFIG_BPF
      is_enabled CONFIG_BUILDTIME_TABLE_SORT
      is_enabled CONFIG_KALLSYMS

      $ time ./test-grep.sh
      real    0m0.036s
      user    0m0.027s
      sys     m0.009s

    [1]: https://lore.kernel.org/all/1919455.eZKeABUfgV@blindfold/
    [2]: https://lore.kernel.org/all/20180219092245.26404-1-richard@nod.at/
    [3]: https://lore.kernel.org/all/20210920213957.1064-2-richard@nod.at/
    Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
    Reviewed-by: Nicolas Schier <n.schier@avm.de>

Signed-off-by: Joe Lawrence <joe.lawrence@redhat.com>

squash with dd3c841
2022-10-27 14:27:57 -04:00
Waiman Long 50b1d44aad x86: Add straight-line-speculation mitigation
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2090231
Conflicts: Merge conflict in arch/x86/lib/retpoline.S due to the
	   presence of a later upstream commit d45476d98324
	   ("x86/speculation: Rename RETPOLINE_AMD to RETPOLINE_LFENCE").

commit e463a09af2f0677b9485a7e8e4e70b396b2ffb6f
Author: Peter Zijlstra <peterz@infradead.org>
Date:   Sat, 4 Dec 2021 14:43:44 +0100

    x86: Add straight-line-speculation mitigation

    Make use of an upcoming GCC feature to mitigate
    straight-line-speculation for x86:

      https://gcc.gnu.org/g:53a643f8568067d7700a9f2facc8ba39974973d3
      https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102952
      https://bugs.llvm.org/show_bug.cgi?id=52323

    It's built tested on x86_64-allyesconfig using GCC-12 and GCC-11.

    Maintenance overhead of this should be fairly low due to objtool
    validation.

    Size overhead of all these additional int3 instructions comes to:

         text          data     bss     dec     hex filename
      22267751      6933356 2011368 31212475        1dc43bb defconfig-build/vmlinux
      22804126      6933356 1470696 31208178        1dc32f2 defconfig-build/vmlinux.sls

    Or roughly 2.4% additional text.

    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    Signed-off-by: Borislav Petkov <bp@suse.de>
    Link: https://lore.kernel.org/r/20211204134908.140103474@infradead.org

Signed-off-by: Waiman Long <longman@redhat.com>
2022-07-29 11:55:56 -04:00
Yauheni Kaliuta e32d828036 kbuild: Unify options for BTF generation for vmlinux and modules
Bugzilla: http://bugzilla.redhat.com/2069045

commit 9741e07ece7c247dd65e1aa01e16b683f01c05a8
Author: Jiri Olsa <jolsa@redhat.com>
Date:   Fri Oct 29 14:57:29 2021 +0200

    kbuild: Unify options for BTF generation for vmlinux and modules
    
    Using new PAHOLE_FLAGS variable to pass extra arguments to
    pahole for both vmlinux and modules BTF data generation.
    
    Adding new scripts/pahole-flags.sh script that detect and
    prints pahole options.
    
    [ fixed issues found by kernel test robot ]
    
    Signed-off-by: Jiri Olsa <jolsa@kernel.org>
    Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
    Acked-by: Andrii Nakryiko <andrii@kernel.org>
    Link: https://lore.kernel.org/bpf/20211029125729.70002-1-jolsa@kernel.org

Signed-off-by: Yauheni Kaliuta <ykaliuta@redhat.com>
2022-06-03 17:23:55 +03:00
Linus Torvalds 81361b837a Kbuild updates for v5.14
- Increase the -falign-functions alignment for the debug option.
 
  - Remove ugly libelf checks from the top Makefile.
 
  - Make the silent build (-s) more silent.
 
  - Re-compile the kernel if KBUILD_BUILD_TIMESTAMP is specified.
 
  - Various script cleanups
 -----BEGIN PGP SIGNATURE-----
 
 iQJJBAABCgAzFiEEbmPs18K1szRHjPqEPYsBB53g2wYFAmDon90VHG1hc2FoaXJv
 eUBrZXJuZWwub3JnAAoJED2LAQed4NsGWFUP/RGNwlGD/YV1xg0ZmM0/ynBzzOy2
 3dcr3etJZpipQDeqnHy3jt0esgMVlbkTdrHvP+2hpNaeXFwjF1fDHjhur9m8ZkVD
 efOA6nugOnNwhy2G3BvtCJv+Vhb+KZ0nNLB27z3Bl0LGP6LJdMRNAxFBJMv4k3aR
 F3sABugwCpnT2/YtuprxRl2/3/CyLur5NjY24FD+ugON3JIWfl6ETbHeFmxr1JE4
 mE+zaN5AwYuSuH9LpdRy85XVCcW/FFqP/DwOFllVvCCCNvvS0KWYSNHWfEsKdR75
 hmAAaS/rpi2eaL0vp88sNhAtYnhMSf+uFu0fyfYeWZuJqMt4Xz5xZKAzDsifCdif
 aQ6UEPDjiKABh9gpX26BMd2CXzkGR+L4qZ7iBPfO586Iy7opajrFX9kIj5U7ZtCl
 wsPat/9+18xpVJOTe0sss3idId7Ft4cRoW5FQMEAW2EWJ9fXAG1yDxEREj1V5gFx
 sMXtpmCoQag968qjfARvP08s3MB1P4Ij6tXcioGqHuEWeJLxOMK/KWyafQUg611d
 0kSWNO0OMo+odBj6j/vM+MIIaPhgwtZnPgw2q4uHGMcemzQxaEvGW+G/5a5qEpTv
 SKm8W24wXplNot4tuTGWq5/jANRJcMvVsyC48DYT81OZEOWrIc0kDV4v4qZToTxW
 97jn1NKa2H6L0J1V
 =Za8V
 -----END PGP SIGNATURE-----

Merge tag 'kbuild-v5.14' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild

Pull Kbuild updates from Masahiro Yamada:

 - Increase the -falign-functions alignment for the debug option.

 - Remove ugly libelf checks from the top Makefile.

 - Make the silent build (-s) more silent.

 - Re-compile the kernel if KBUILD_BUILD_TIMESTAMP is specified.

 - Various script cleanups

* tag 'kbuild-v5.14' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild: (27 commits)
  scripts: add generic syscallnr.sh
  scripts: check duplicated syscall number in syscall table
  sparc: syscalls: use pattern rules to generate syscall headers
  parisc: syscalls: use pattern rules to generate syscall headers
  nds32: add arch/nds32/boot/.gitignore
  kbuild: mkcompile_h: consider timestamp if KBUILD_BUILD_TIMESTAMP is set
  kbuild: modpost: Explicitly warn about unprototyped symbols
  kbuild: remove trailing slashes from $(KBUILD_EXTMOD)
  kconfig.h: explain IS_MODULE(), IS_ENABLED()
  kconfig: constify long_opts
  scripts/setlocalversion: simplify the short version part
  scripts/setlocalversion: factor out 12-chars hash construction
  scripts/setlocalversion: add more comments to -dirty flag detection
  scripts/setlocalversion: remove workaround for old make-kpkg
  scripts/setlocalversion: remove mercurial, svn and git-svn supports
  kbuild: clean up ${quiet} checks in shell scripts
  kbuild: sink stdout from cmd for silent build
  init: use $(call cmd,) for generating include/generated/compile.h
  kbuild: merge scripts/mkmakefile to top Makefile
  sh: move core-y in arch/sh/Makefile to arch/sh/Kbuild
  ...
2021-07-10 11:01:38 -07:00
Andrii Nakryiko a0b8200d06 kbuild: skip per-CPU BTF generation for pahole v1.18-v1.21
Commit "mm/page_alloc: convert per-cpu list protection to local_lock" will
introduce a zero-sized per-CPU variable, which causes pahole to generate
invalid BTF.  Only pahole versions 1.18 through 1.21 are impacted, as
before 1.18 pahole doesn't know anything about per-CPU variables, and 1.22
contains the proper fix for the issue.

Luckily, pahole 1.18 got --skip_encoding_btf_vars option disabling BTF
generation for per-CPU variables in anticipation of some unanticipated
problems.  So use this escape hatch to disable per-CPU var BTF info on
those problematic pahole versions.  Users relying on availability of
per-CPU var BTFs would need to upgrade to pahole 1.22+, but everyone won't
notice any regressions.

Link: https://lkml.kernel.org/r/20210530002536.3193829-1-andrii@kernel.org
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Mel Gorman <mgorman@techsingularity.net>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Hao Luo <haoluo@google.com>
Cc: Michal Suchanek <msuchanek@suse.de>
Cc: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2021-06-29 10:53:54 -07:00
Javier Martinez Canillas ff2e6efda0 kbuild: Quote OBJCOPY var to avoid a pahole call break the build
The ccache tool can be used to speed up cross-compilation, by calling the
compiler and binutils through ccache. For example, following should work:

    $ export ARCH=arm64 CROSS_COMPILE="ccache aarch64-linux-gnu-"

    $ make M=drivers/gpu/drm/rockchip/

but pahole fails to extract the BTF info from DWARF, breaking the build:

      CC [M]  drivers/gpu/drm/rockchip//rockchipdrm.mod.o
      LD [M]  drivers/gpu/drm/rockchip//rockchipdrm.ko
      BTF [M] drivers/gpu/drm/rockchip//rockchipdrm.ko
    aarch64-linux-gnu-objcopy: invalid option -- 'J'
    Usage: aarch64-linux-gnu-objcopy [option(s)] in-file [out-file]
     Copies a binary file, possibly transforming it in the process
    ...
    make[1]: *** [scripts/Makefile.modpost:156: __modpost] Error 2
    make: *** [Makefile:1866: modules] Error 2

this fails because OBJCOPY is set to "ccache aarch64-linux-gnu-copy" and
later pahole is executed with the following command line:

    LLVM_OBJCOPY=$(OBJCOPY) $(PAHOLE) -J --btf_base vmlinux $@

which gets expanded to:

    LLVM_OBJCOPY=ccache aarch64-linux-gnu-objcopy pahole -J ...

instead of:

    LLVM_OBJCOPY="ccache aarch64-linux-gnu-objcopy" pahole -J ...

Fixes: 5f9ae91f7c ("kbuild: Build kernel module BTFs if BTF is enabled and pahole supports it")
Signed-off-by: Javier Martinez Canillas <javierm@redhat.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Link: https://lore.kernel.org/bpf/20210526215228.3729875-1-javierm@redhat.com
2021-05-27 11:32:56 -07:00
Masahiro Yamada c39013ee64 kbuild: clean up ${quiet} checks in shell scripts
There were efforts to make 'make -s' really silent when it is a
warning-free build.

The conventional way was to let a shell script check ${quiet}, and if
it is 'silent_', suppress the stdout by itself.

With the previous commit, the 'cmd' takes care of it now. The 'cmd' is
also invoked from if_changed, if_changed_dep, and if_changed_rule.

You can omit ${quiet} checks in shell scripts when they are invoked
from the 'cmd' macro.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2021-05-27 04:01:50 +09:00
Andi Kleen 51eb95e2da kbuild: Don't remove link-vmlinux temporary files on exit/signal
Keep them around until they are cleaned up by make clean. This
uses a bit more disk space, but makes it easier to debug any
problems with the kernel link process.

Suggested-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2021-05-06 02:16:41 +09:00
Linus Torvalds b0030af53a Kbuild updates for v5.13
- Evaluate $(call cc-option,...) etc. only for build targets
 
  - Add CONFIG_VMLINUX_MAP to generate .map file when linking vmlinux
 
  - Remove unnecessary --gcc-toolchains Clang flag because the --prefix
    flag finds the toolchains
 
  - Do not pass Clang's --prefix flag when using the integrated as
 
  - Check the assembler version in Kconfig time
 
  - Add new CONFIG options, AS_VERSION, AS_IS_GNU, AS_IS_LLVM to clean up
    some dependencies in Kconfig
 
  - Fix invalid Module.symvers creation when building only modules without
    vmlinux
 
  - Fix false-positive modpost warnings when CONFIG_TRIM_UNUSED_KSYMS is
    set, but there is no module to build
 
  - Refactor module installation Makefile
 
  - Support zstd for module compression
 
  - Convert alpha and ia64 to use generic shell scripts to generate the
    syscall headers
 
  - Add a new elfnote to indicate if the kernel was built with LTO, which
    will be used by pahole
 
  - Flatten the directory structure under include/config/ so CONFIG options
    and filenames match
 
  - Change the deb source package name from linux-$(KERNELRELEASE) to
    linux-upstream
 -----BEGIN PGP SIGNATURE-----
 
 iQJJBAABCgAzFiEEbmPs18K1szRHjPqEPYsBB53g2wYFAmCKOLUVHG1hc2FoaXJv
 eUBrZXJuZWwub3JnAAoJED2LAQed4NsGdq8P/2z+saxIWGXVWt0ggavR0vimcY4e
 NQIKGu9uZpo/lfoC78UG8HO+XvzvPUrcRuOX+WIVr2GfScgVnweDukexUAY0/2oi
 4UvqhndJ0sjEwRj8mXXJ0O+PED+OtgrqrbhkLq9wHQd/jpSD4XEWXwn1g1XVrTZu
 WbwP6b1G/Rnjp2lz3HKC017rPkmfsCFQB7r+hbJGKhT0rCaceheUuBvGa/XqLknr
 IOyaUAY76u3Gtj6fVY1rk70kQgDMF8+LJPgdSSZ/XPCvbNJQAeop36EeRNfmxGIh
 vQhFJRJeqy+K5MhCpdGtTGYDawlmQVn/f/99SkDw9F04S4ZL2Xnaaqw4L1QDhjTh
 xBlckbPvmq36F4xSqWd5kYF3iwS+LsEJROwZKFLEVDb3zMsRQPEGQM/556QmrBi2
 5KXzwOYEJKuobWr1hQ3PwLumJKTPGLvGEFB3Bq2eG8LrgpOAHPI4ejC2EBu0vCez
 QbskP2lPlMj3MbL5iZg+6ZRlOChZ7RUrSDj6+iTeOcinmXHqQONCL6qy+um4Rfcb
 zUkfwTlqM9d88u6AbO2VvQMOobMjvp4bvmqi/Xv8IiTukLHco4tc8zTuySmZwSyI
 rd3RKYn367qWztX5YyaoGRPVmlMG7ssbRc4fkXiV13vfeZebNfVwlX/CHv9+IWwN
 RVnMhYBhUZR68h6z
 =ti9L
 -----END PGP SIGNATURE-----

Merge tag 'kbuild-v5.13' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild

Pull Kbuild updates from Masahiro Yamada:

 - Evaluate $(call cc-option,...) etc. only for build targets

 - Add CONFIG_VMLINUX_MAP to generate .map file when linking vmlinux

 - Remove unnecessary --gcc-toolchains Clang flag because the --prefix
   flag finds the toolchains

 - Do not pass Clang's --prefix flag when using the integrated as

 - Check the assembler version in Kconfig time

 - Add new CONFIG options, AS_VERSION, AS_IS_GNU, AS_IS_LLVM to clean up
   some dependencies in Kconfig

 - Fix invalid Module.symvers creation when building only modules
   without vmlinux

 - Fix false-positive modpost warnings when CONFIG_TRIM_UNUSED_KSYMS is
   set, but there is no module to build

 - Refactor module installation Makefile

 - Support zstd for module compression

 - Convert alpha and ia64 to use generic shell scripts to generate the
   syscall headers

 - Add a new elfnote to indicate if the kernel was built with LTO, which
   will be used by pahole

 - Flatten the directory structure under include/config/ so CONFIG
   options and filenames match

 - Change the deb source package name from linux-$(KERNELRELEASE) to
   linux-upstream

* tag 'kbuild-v5.13' of git://git.kernel.org/pub/scm/linux/kernel/git/masahiroy/linux-kbuild: (42 commits)
  kbuild: Add $(KBUILD_HOSTLDFLAGS) to 'has_libelf' test
  kbuild: deb-pkg: change the source package name to linux-upstream
  tools: do not include scripts/Kbuild.include
  kbuild: redo fake deps at include/config/*.h
  kbuild: remove TMPO from try-run
  MAINTAINERS: add pattern for dummy-tools
  kbuild: add an elfnote for whether vmlinux is built with lto
  ia64: syscalls: switch to generic syscallhdr.sh
  ia64: syscalls: switch to generic syscalltbl.sh
  alpha: syscalls: switch to generic syscallhdr.sh
  alpha: syscalls: switch to generic syscalltbl.sh
  sysctl: use min() helper for namecmp()
  kbuild: add support for zstd compressed modules
  kbuild: remove CONFIG_MODULE_COMPRESS
  kbuild: merge scripts/Makefile.modsign to scripts/Makefile.modinst
  kbuild: move module strip/compression code into scripts/Makefile.modinst
  kbuild: refactor scripts/Makefile.modinst
  kbuild: rename extmod-prefix to extmod_prefix
  kbuild: check module name conflict for external modules as well
  kbuild: show the target directory for depmod log
  ...
2021-04-29 14:24:39 -07:00
Rasmus Villemoes 0b956e2041 kbuild: apply fixdep logic to link-vmlinux.sh
The patch adding CONFIG_VMLINUX_MAP revealed a small defect in the
build system: link-vmlinux.sh takes decisions based on CONFIG_*
options, but changing one of those does not always lead to vmlinux
being linked again.

For most of the CONFIG_* knobs referenced previously, this has
probably been hidden by those knobs also affecting some object file,
hence indirectly also vmlinux.

But CONFIG_VMLINUX_MAP is only handled inside link-vmlinux.sh, and
changing CONFIG_VMLINUX_MAP=n to CONFIG_VMLINUX_MAP=y does not cause
the build system to re-link (and hence have vmlinux.map
emitted). Since that map file is mostly a debugging aid, this is
merely a nuisance which is easily worked around by just deleting
vmlinux and building again.

But one could imagine other (possibly future) CONFIG options that
actually do affect the vmlinux binary but which are not captured
through some object file dependency.

To fix this, make link-vmlinux.sh emit a .vmlinux.d file in the same
format as the dependency files generated by gcc, and apply the fixdep
logic to that. I've tested that this correctly works with both in-tree
and out-of-tree builds.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2021-04-25 05:12:32 +09:00
Rasmus Villemoes 5cc1247204 kbuild: add CONFIG_VMLINUX_MAP expert option
It can be quite useful to have ld emit a link map file, in order to
debug or verify that special sections end up where they are supposed
to, and to see what LD_DEAD_CODE_DATA_ELIMINATION manages to get rid
of.

The only reason I'm not just adding this unconditionally is that the
.map file can be rather large (several MB), and that's a waste of
space when one isn't interested in these things. Also make it depend
on CONFIG_EXPERT.

Signed-off-by: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2021-04-25 05:12:26 +09:00
Ilya Leoshkevich db16c1fe92 bpf: Generate BTF_KIND_FLOAT when linking vmlinux
pahole v1.21 supports the --btf_gen_floats flag, which makes it
generate the information about the floating-point types [1].

Adjust link-vmlinux.sh to pass this flag to pahole in case it's
supported, which is determined using a simple version check.

[1] https://lore.kernel.org/dwarves/YHRiXNX1JUF2Az0A@kernel.org/

Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210413190043.21918-1-iii@linux.ibm.com
2021-04-13 14:34:27 -07:00
Sami Tolvanen b1a1a1a09b kbuild: lto: postpone objtool
With LTO, LLVM bitcode won't be compiled into native code until
modpost_link, or modfinal for modules. This change postpones calls
to objtool until after these steps, and moves objtool_args to
Makefile.lib, so the arguments can be reused in Makefile.modfinal.

As we didn't have objects to process earlier, we use --duplicate
when processing vmlinux.o. This change also disables unreachable
instruction warnings with LTO to avoid warnings about the int3
padding between functions.

Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
2021-02-23 12:46:57 -08:00
Sami Tolvanen 41425ebe20 objtool: Split noinstr validation from --vmlinux
This change adds a --noinstr flag to objtool to allow us to specify
that we're processing vmlinux.o without also enabling noinstr
validation. This is needed to avoid false positives with LTO when we
run objtool on vmlinux.o without CONFIG_DEBUG_ENTRY.

Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
2021-02-23 12:46:57 -08:00
Sami Tolvanen 0e731dbc18 objtool: Don't autodetect vmlinux.o
With LTO, we run objtool on vmlinux.o, but don't want noinstr
validation. This change requires --vmlinux to be passed to objtool
explicitly.

Suggested-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
2021-02-23 12:46:57 -08:00
Sami Tolvanen a8cccdd954 init: lto: ensure initcall ordering
With LTO, the compiler doesn't necessarily obey the link order for
initcalls, and initcall variables need globally unique names to avoid
collisions at link time.

This change exports __KBUILD_MODNAME and adds the initcall_id() macro,
which uses it together with __COUNTER__ and __LINE__ to help ensure
these variables have unique names, and moves each variable to its own
section when LTO is enabled, so the correct order can be specified using
a linker script.

The generate_initcall_ordering.pl script uses nm to find initcalls from
the object files passed to the linker, and generates a linker script
that specifies the same order for initcalls that we would have without
LTO. With LTO enabled, the script is called in link-vmlinux.sh through
jobserver-exec to limit the number of jobs spawned.

Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20201211184633.3213045-8-samitolvanen@google.com
2021-01-14 08:21:09 -08:00