Re: [patch V4 part 1 20/36] vmlinux.lds.h: Create section for protection against instrumentation

From: Peter Zijlstra
Date: Wed May 06 2020 - 12:29:07 EST


On Wed, May 06, 2020 at 09:08:31AM -0700, Sean Christopherson wrote:
> On Tue, May 05, 2020 at 03:16:22PM +0200, Thomas Gleixner wrote:
> > Provide also a set of markers: instr_begin()/end()
> >
> > These are used to mark code inside a noinstr function which calls
> > into regular instrumentable text section as safe.
>
> ...
>
> > --- a/include/linux/compiler.h
> > +++ b/include/linux/compiler.h
> > @@ -120,10 +120,27 @@ void ftrace_likely_update(struct ftrace_
> > /* Annotate a C jump table to allow objtool to follow the code flow */
> > #define __annotate_jump_table __section(.rodata..c_jump_table)
> >
> > +/* Begin/end of an instrumentation safe region */
> > +#define instr_begin() ({ \
> > + asm volatile("%c0:\n\t" \
> > + ".pushsection .discard.instr_begin\n\t" \
> > + ".long %c0b - .\n\t" \
> > + ".popsection\n\t" : : "i" (__COUNTER__)); \
> > +})
> > +
> > +#define instr_end() ({ \
> > + asm volatile("%c0:\n\t" \
> > + ".pushsection .discard.instr_end\n\t" \
> > + ".long %c0b - .\n\t" \
> > + ".popsection\n\t" : : "i" (__COUNTER__)); \
> > +})
>
> Any chance we could spell these out, i.e. instrumentation_begin/end()? I
> can't help but read these as "instruction_begin/end". At a glance, the
> long names shouldn't cause any wrap/indentation issues.

The kernel naming convention is insn for instruction, not instr. That
said, you're not the first to be confused by this.