1. Feb 11, 2021
  2. Jan 27, 2021
  3. Jan 19, 2021
  4. Jan 15, 2021
  5. Jan 14, 2021
    • 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