• Nick Desaulniers's avatar
    x86/bug: Merge annotate_reachable() into _BUG_FLAGS() asm · bfb1a7c9
    Nick Desaulniers authored
    In __WARN_FLAGS(), we had two asm statements (abbreviated):
    
      asm volatile("ud2");
      asm volatile(".pushsection .discard.reachable");
    
    These pair of statements are used to trigger an exception, but then help
    objtool understand that for warnings, control flow will be restored
    immediately afterwards.
    
    The problem is that volatile is not a compiler barrier. GCC explicitly
    documents this:
    
    > Note that the compiler can move even volatile asm instructions
    > relative to other code, including across jump instructions.
    
    Also, no clobbers are specified to prevent instructions from subsequent
    statements from being scheduled by compiler before the second asm
    statement. This can lead to instructions from subsequent statements
    being emitted by the compiler before the second asm statement.
    
    Providing a scheduling model such as via -march= options enables the
    compiler to better schedule instructions with known latencies to hide
    latencies from data hazards compared to inline asm statements in which
    latencies are not estimated.
    
    If an instruction gets scheduled by the compiler between the two asm
    statements, then objtool will think that it is not reachable, producing
    a warning.
    
    To prevent instructions from being scheduled in between the two asm
    statements, merge them.
    
    Also remove an unnecessary unreachable() asm annotation from BUG() in
    favor of __builtin_unreachable(). objtool is able to track that the ud2
    from BUG() terminates control flow within the function.
    
    Link: https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Volatile
    Link: https://github.com/ClangBuiltLinux/linux/issues/1483Signed-off-by: default avatarNick Desaulniers <ndesaulniers@google.com>
    Signed-off-by: default avatarJosh Poimboeuf <jpoimboe@redhat.com>
    Link: https://lore.kernel.org/r/20220202205557.2260694-1-ndesaulniers@google.com
    bfb1a7c9
bug.h 2.33 KB