1. 10 Feb, 2021 10 commits
  2. 26 Jan, 2021 18 commits
  3. 19 Jan, 2021 1 commit
  4. 14 Jan, 2021 11 commits
    • Nick Desaulniers's avatar
      x86/entry: Emit a symbol for register restoring thunk · 5e6dca82
      Nick Desaulniers authored
      Arnd found a randconfig that produces the warning:
      
        arch/x86/entry/thunk_64.o: warning: objtool: missing symbol for insn at
        offset 0x3e
      
      when building with LLVM_IAS=1 (Clang's integrated assembler). Josh
      notes:
      
        With the LLVM assembler not generating section symbols, objtool has no
        way to reference this code when it generates ORC unwinder entries,
        because this code is outside of any ELF function.
      
        The limitation now being imposed by objtool is that all code must be
        contained in an ELF symbol.  And .L symbols don't create such symbols.
      
        So basically, you can use an .L symbol *inside* a function or a code
        segment, you just can't use the .L symbol to contain the code using a
        SYM_*_START/END annotation pair.
      
      Fangrui notes that this optimization is helpful for reducing image size
      when compiling with -ffunction-sections and -fdata-sections. I have
      observed on the order of tens of thousands of symbols for the kernel
      images built with those flags.
      
      A patch has been authored against GNU binutils to match this behavior
      of not generating unused section symbols ([1]), so this will
      also become a problem for users of GNU binutils once they upgrade to 2.36.
      
      Omit the .L prefix on a label so that the assembler will emit an entry
      into the symbol table for the label, with STB_LOCAL binding. This
      enables objtool to generate proper unwind info here with LLVM_IAS=1 or
      GNU binutils 2.36+.
      
       [ bp: Massage commit message. ]
      Reported-by: default avatarArnd Bergmann <arnd@arndb.de>
      Suggested-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
      Suggested-by: default avatarBorislav Petkov <bp@alien8.de>
      Suggested-by: default avatarMark Brown <broonie@kernel.org>
      Signed-off-by: default avatarNick Desaulniers <ndesaulniers@google.com>
      Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
      Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Acked-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
      Link: https://lkml.kernel.org/r/20210112194625.4181814-1-ndesaulniers@google.com
      Link: https://github.com/ClangBuiltLinux/linux/issues/1209
      Link: https://reviews.llvm.org/D93783
      Link: https://sourceware.org/binutils/docs/as/Symbol-Names.html
      Link: https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=d1bcae833b32f1408485ce69f844dcd7ded093a8 [1]
      5e6dca82
    • Josh Poimboeuf's avatar
      objtool: Support stack layout changes in alternatives · c9c324dc
      Josh Poimboeuf authored
      The ORC unwinder showed a warning [1] which revealed the stack layout
      didn't match what was expected.  The problem was that paravirt patching
      had replaced "CALL *pv_ops.irq.save_fl" with "PUSHF;POP".  That changed
      the stack layout between the PUSHF and the POP, so unwinding from an
      interrupt which occurred between those two instructions would fail.
      
      Part of the agreed upon solution was to rework the custom paravirt
      patching code to use alternatives instead, since objtool already knows
      how to read alternatives (and converging runtime patching infrastructure
      is always a good thing anyway).  But the main problem still remains,
      which is that runtime patching can change the stack layout.
      
      Making stack layout changes in alternatives was disallowed with commit
      7117f16b ("objtool: Fix ORC vs alternatives"), but now that paravirt
      is going to be doing it, it needs to be supported.
      
      One way to do so would be to modify the ORC table when the code gets
      patched.  But ORC is simple -- a good thing! -- and it's best to leave
      it alone.
      
      Instead, support stack layout changes by "flattening" all possible stack
      states (CFI) from parallel alternative code streams into a single set of
      linear states.  The only necessary limitation is that CFI conflicts are
      disallowed at all possible instruction boundaries.
      
      For example, this scenario is allowed:
      
                Alt1                    Alt2                    Alt3
      
         0x00   CALL *pv_ops.save_fl    CALL xen_save_fl        PUSHF
         0x01                                                   POP %RAX
         0x02                                                   NOP
         ...
         0x05                           NOP
         ...
         0x07   <insn>
      
      The unwind information for offset-0x00 is identical for all 3
      alternatives.  Similarly offset-0x05 and higher also are identical (and
      the same as 0x00).  However offset-0x01 has deviating CFI, but that is
      only relevant for Alt3, neither of the other alternative instruction
      streams will ever hit that offset.
      
      This scenario is NOT allowed:
      
                Alt1                    Alt2
      
         0x00   CALL *pv_ops.save_fl    PUSHF
         0x01                           NOP6
         ...
         0x07   NOP                     POP %RAX
      
      The problem here is that offset-0x7, which is an instruction boundary in
      both possible instruction patch streams, has two conflicting stack
      layouts.
      
      [ The above examples were stolen from Peter Zijlstra. ]
      
      The new flattened CFI array is used both for the detection of conflicts
      (like the second example above) and the generation of linear ORC
      entries.
      
      BTW, another benefit of these changes is that, thanks to some related
      cleanups (new fake nops and alt_group struct) objtool can finally be rid
      of fake jumps, which were a constant source of headaches.
      
      [1] https://lkml.kernel.org/r/20201111170536.arx2zbn4ngvjoov7@treble
      
      Cc: Shinichiro Kawasaki <shinichiro.kawasaki@wdc.com>
      Signed-off-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
      c9c324dc
    • Josh Poimboeuf's avatar
      objtool: Add 'alt_group' struct · b23cc71c
      Josh Poimboeuf authored
      Create a new struct associated with each group of alternatives
      instructions.  This will help with the removal of fake jumps, and more
      importantly with adding support for stack layout changes in
      alternatives.
      Signed-off-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
      b23cc71c
    • Josh Poimboeuf's avatar
      objtool: Refactor ORC section generation · ab4e0744
      Josh Poimboeuf authored
      Decouple ORC entries from instructions.  This simplifies the
      control/data flow, and is going to make it easier to support alternative
      instructions which change the stack layout.
      Signed-off-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
      ab4e0744
    • Vasily Gorbik's avatar
      x86/insn: Fix vector instruction decoding on big endian cross-compiles · 5ed934e5
      Vasily Gorbik authored
      Running instruction decoder posttest on an s390 host with an x86 target
      with allyesconfig shows errors. Instructions used in a couple of kernel
      objects could not be correctly decoded on big endian system.
      
        insn_decoder_test: warning: objdump says 6 bytes, but insn_get_length() says 5
        insn_decoder_test: warning: Found an x86 instruction decoder bug, please report this.
        insn_decoder_test: warning: ffffffff831eb4e1:    62 d1 fd 48 7f 04 24    vmovdqa64 %zmm0,(%r12)
        insn_decoder_test: warning: objdump says 7 bytes, but insn_get_length() says 6
        insn_decoder_test: warning: Found an x86 instruction decoder bug, please report this.
        insn_decoder_test: warning: ffffffff831eb4e8:    62 51 fd 48 7f 44 24 01         vmovdqa64 %zmm8,0x40(%r12)
        insn_decoder_test: warning: objdump says 8 bytes, but insn_get_length() says 6
      
      This is because in a few places instruction field bytes are set directly
      with further usage of "value". To address that introduce and use a
      insn_set_byte() helper, which correctly updates "value" on big endian
      systems.
      Signed-off-by: default avatarVasily Gorbik <gor@linux.ibm.com>
      Acked-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Signed-off-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
      5ed934e5
    • Vasily Gorbik's avatar
      objtool: Rework header include paths · 7786032e
      Vasily Gorbik authored
      Currently objtool headers are being included either by their base name
      or included via ../ from a parent directory. In case of a base name usage:
      
       #include "warn.h"
       #include "arch_elf.h"
      
      it does not make it apparent from which directory the file comes from.
      To make it slightly better, and actually to avoid name clashes some arch
      specific files have "arch_" suffix. And files from an arch folder have
      to revert to including via ../ e.g:
       #include "../../elf.h"
      
      With additional architectures support and the code base growth there is
      a need for clearer headers naming scheme for multiple reasons:
      1. to make it instantly obvious where these files come from (objtool
         itself / objtool arch|generic folders / some other external files),
      2. to avoid name clashes of objtool arch specific headers, potential
         obtool arch generic headers and the system header files (there is
         /usr/include/elf.h already),
      3. to avoid ../ includes and improve code readability.
      4. to give a warm fuzzy feeling to developers who are mostly kernel
         developers and are accustomed to linux kernel headers arranging
         scheme.
      
      Doesn't this make it instantly obvious where are these files come from?
      
       #include <objtool/warn.h>
       #include <arch/elf.h>
      
      And doesn't it look nicer to avoid ugly ../ includes? Which also
      guarantees this is elf.h from the objtool and not /usr/include/elf.h.
      
       #include <objtool/elf.h>
      
      This patch defines and implements new objtool headers arranging
      scheme. Which is:
      - all generic headers go to include/objtool (similar to include/linux)
      - all arch headers go to arch/$(SRCARCH)/include/arch (to get arch
        prefix). This is similar to linux arch specific "asm/*" headers but we
        are not abusing "asm" name and calling it what it is. This also helps
        to prevent name clashes (arch is not used in system headers or kernel
        exports).
      
      To bring objtool to this state the following things are done:
      1. current top level tools/objtool/ headers are moved into
         include/objtool/ subdirectory,
      2. arch specific headers, currently only arch/x86/include/ are moved into
         arch/x86/include/arch/ and were stripped of "arch_" suffix,
      3. new -I$(srctree)/tools/objtool/include include path to make
         includes like <objtool/warn.h> possible,
      4. rewriting file includes,
      5. make git not to ignore include/objtool/ subdirectory.
      Signed-off-by: default avatarVasily Gorbik <gor@linux.ibm.com>
      Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Acked-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Signed-off-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
      7786032e
    • Vasily Gorbik's avatar
      objtool: Fix x86 orc generation on big endian cross-compiles · 8bfe2732
      Vasily Gorbik authored
      Correct objtool orc generation endianness problems to enable fully
      functional x86 cross-compiles on big endian hardware.
      
      Introduce bswap_if_needed() macro, which does a byte swap if target
      endianness doesn't match the host, i.e. cross-compilation for little
      endian on big endian and vice versa.  The macro is used for conversion
      of multi-byte values which are read from / about to be written to a
      target native endianness ELF file.
      Signed-off-by: default avatarVasily Gorbik <gor@linux.ibm.com>
      Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Acked-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Signed-off-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
      8bfe2732
    • Martin Schwidefsky's avatar
      objtool: Fix reloc generation on big endian cross-compiles · a1a664ec
      Martin Schwidefsky authored
      Relocations generated in elf_rebuild_rel[a]_reloc_section() are broken
      if objtool is built and run on a big endian system.
      
      The following errors pop up during x86 cross-compilation:
      
        x86_64-9.1.0-ld: fs/efivarfs/inode.o: bad reloc symbol index (0x2000000 >= 0x22) for offset 0 in section `.orc_unwind_ip'
        x86_64-9.1.0-ld: final link failed: bad value
      
      Convert those functions to use gelf_update_rel[a](), similar to what
      elf_write_reloc() does.
      Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
      Co-developed-by: default avatarVasily Gorbik <gor@linux.ibm.com>
      Signed-off-by: default avatarVasily Gorbik <gor@linux.ibm.com>
      Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Acked-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Signed-off-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
      a1a664ec
    • Martin Schwidefsky's avatar
      x86/insn: Support big endian cross-compiles · 1d509f2a
      Martin Schwidefsky authored
      The x86 instruction decoder code is shared across the kernel source and
      the tools. Currently objtool seems to be the only tool from build tools
      needed which breaks x86 cross-compilation on big endian systems. Make
      the x86 instruction decoder build host endianness agnostic to support
      x86 cross-compilation and enable objtool to implement endianness
      awareness for big endian architectures support.
      Signed-off-by: default avatarMartin Schwidefsky <schwidefsky@de.ibm.com>
      Co-developed-by: default avatarVasily Gorbik <gor@linux.ibm.com>
      Signed-off-by: default avatarVasily Gorbik <gor@linux.ibm.com>
      Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Acked-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Signed-off-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
      1d509f2a
    • Vasily Gorbik's avatar
      x86/tools: Use tools headers for instruction decoder selftests · c8d7b7e5
      Vasily Gorbik authored
      Currently the x86 instruction decoder is used from:
      - the kernel itself,
      - from tools like objtool and perf,
      - within x86 tools, i.e. instruction decoder selftests.
      
      The first two cases are similar, because tools headers try to mimic
      kernel headers.
      
      Instruction decoder selftests include some of the kernel headers
      directly, including uapi headers. This works until headers dependencies
      are kept to a minimum and tools are not cross-compiled. Since the goal
      of the x86 instruction decoder selftests is not to verify uapi headers,
      move it to using tools headers, like is already done for vdso2c tool,
      mkpiggy and other tools in arch/x86/boot/.
      Signed-off-by: default avatarVasily Gorbik <gor@linux.ibm.com>
      Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Acked-by: default avatarMasami Hiramatsu <mhiramat@kernel.org>
      Signed-off-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
      c8d7b7e5
    • Julien Thierry's avatar
      objtool: Make SP memory operation match PUSH/POP semantics · 201ef5a9
      Julien Thierry authored
      Architectures without PUSH/POP instructions will always access the stack
      though memory operations (SRC/DEST_INDIRECT). Make those operations have
      the same effect on the CFA as PUSH/POP, with no stack pointer
      modification.
      Signed-off-by: default avatarJulien Thierry <jthierry@redhat.com>
      Acked-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
      Signed-off-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
      201ef5a9