Re: [RFC][PATCH 1/6] x86: Annotate _THIS_IP_

From: Mark Rutland
Date: Tue Nov 23 2021 - 08:53:55 EST


On Mon, Nov 22, 2021 at 06:03:02PM +0100, Peter Zijlstra wrote:
> In order to find _THIS_IP_ code references in objtool, annotate them.

Just to check my understanding, IIUC this is because in later patches
you'll look at text relocations to spot missing ENDBRs, and when doing
so you need to filter out _THIS_IP_ instances, since those don't need an
ENDBR. Is that right?

Just checking I haven't missed some other concern that might apply to
arm64's BTI (Branch Target Identifier), which are analagous to ENDBR.

Thanks,
Mark.

> Signed-off-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
> ---
> arch/x86/include/asm/linkage.h | 11 +++++++++++
> include/linux/instruction_pointer.h | 5 +++++
> 2 files changed, 16 insertions(+)
>
> --- a/arch/x86/include/asm/linkage.h
> +++ b/arch/x86/include/asm/linkage.h
> @@ -3,10 +3,21 @@
> #define _ASM_X86_LINKAGE_H
>
> #include <linux/stringify.h>
> +#include <asm/asm.h>
>
> #undef notrace
> #define notrace __attribute__((no_instrument_function))
>
> +#define _THIS_IP_ \
> + ({ __label__ __here; \
> + __here: \
> + asm_volatile_goto ( \
> + ".pushsection .discard.this_ip\n\t" \
> + _ASM_PTR " %l[__here]\n\t" \
> + ".popsection\n\t" \
> + : : : : __here); \
> + (unsigned long)&&__here; })
> +
> #ifdef CONFIG_X86_32
> #define asmlinkage CPP_ASMLINKAGE __attribute__((regparm(0)))
> #endif /* CONFIG_X86_32 */
> --- a/include/linux/instruction_pointer.h
> +++ b/include/linux/instruction_pointer.h
> @@ -2,7 +2,12 @@
> #ifndef _LINUX_INSTRUCTION_POINTER_H
> #define _LINUX_INSTRUCTION_POINTER_H
>
> +#include <asm/linkage.h>
> +
> #define _RET_IP_ (unsigned long)__builtin_return_address(0)
> +
> +#ifndef _THIS_IP_
> #define _THIS_IP_ ({ __label__ __here; __here: (unsigned long)&&__here; })
> +#endif
>
> #endif /* _LINUX_INSTRUCTION_POINTER_H */
>
>