lkml.org 
[lkml]   [2018]   [Jan]   [18]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    Date
    From
    From
    Subject[PATCH 10/35] x86/jump_label: Implement arch_static_assert()
    Implement the static (branch) assertion. It simply emits the address
    of the next instruction into a special section which objtool will read
    and validate against either __jump_table or .altinstructions.

    Use like:

    if (static_branch_likely(_key)) {
    arch_static_assert();
    /* do stuff */
    }

    Or

    if (static_cpu_has(_feat)) {
    arch_static_assert();
    /* do stuff */
    }

    Cc: Borislav Petkov <bp@alien8.de>
    Cc: Thomas Gleixner <tglx@linutronix.de>
    Cc: Josh Poimboeuf <jpoimboe@redhat.com>
    Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
    ---
    arch/x86/include/asm/jump_label.h | 23 +++++++++++++++++++++++
    1 file changed, 23 insertions(+)

    --- a/arch/x86/include/asm/jump_label.h
    +++ b/arch/x86/include/asm/jump_label.h
    @@ -62,6 +62,29 @@ static __always_inline bool arch_static_
    return true;
    }

    +/*
    + * Annotation for objtool; asserts that the previous instruction is the
    + * jump_label patch site. Or rather, that the next instruction is a static
    + * branch target.
    + *
    + * Use like:
    + *
    + * if (static_branch_likely(key)) {
    + * arch_static_assert();
    + * do_code();
    + * }
    + *
    + * Also works with static_cpu_has().
    + */
    +static __always_inline void arch_static_assert(void)
    +{
    + asm volatile ("1:\n\t"
    + ".pushsection .discard.jump_assert \n\t"
    + _ASM_ALIGN "\n\t"
    + _ASM_PTR "1b \n\t"
    + ".popsection \n\t");
    +}
    +
    #ifdef CONFIG_X86_64
    typedef u64 jump_label_t;
    #else

    \
     
     \ /
      Last update: 2018-01-18 16:00    [W:4.160 / U:0.056 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site