• Peter Zijlstra's avatar
    x86/alternatives: Optimize optimize_nops() · 23c1ad53
    Peter Zijlstra authored
    Currently, optimize_nops() scans to see if the alternative starts with
    NOPs. However, the emit pattern is:
    
      141:	\oldinstr
      142:	.skip (len-(142b-141b)), 0x90
    
    That is, when 'oldinstr' is short, the tail is padded with NOPs. This case
    never gets optimized.
    
    Rewrite optimize_nops() to replace any trailing string of NOPs inside
    the alternative to larger NOPs. Also run it irrespective of patching,
    replacing NOPs in both the original and replaced code.
    
    A direct consequence is that 'padlen' becomes superfluous, so remove it.
    
     [ bp:
       - Adjust commit message
       - remove a stale comment about needing to pad
       - add a comment in optimize_nops()
       - exit early if the NOP verif. loop catches a mismatch - function
         should not not add NOPs in that case
       - fix the "optimized NOPs" offsets output ]
    Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
    Signed-off-by: default avatarBorislav Petkov <bp@suse.de>
    Signed-off-by: default avatarIngo Molnar <mingo@kernel.org>
    Link: https://lkml.kernel.org/r/20210326151259.442992235@infradead.org
    23c1ad53
alternative.h 12.3 KB