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

Sean Christopherson
2020-05-06T16:08:33Z

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.

E.g. some of the usage in KVM is especially confusing

--- a/arch/x86/kvm/vmx/ops.h
+++ b/arch/x86/kvm/vmx/ops.h
@@ -146,7 +146,9 @@ do { \
: : op1 : "cc" : error, fault); \
return; \
error: \
+ instr_begin(); \
insn##_error(error_args); \
+ instr_end(); \
return; \
fault: \
kvm_spurious_fault(); \
@@ -161,7 +163,9 @@ do { \
: : op1, op2 : "cc" : error, fault); \
return; \
error: \
+ instr_begin(); \
insn##_error(error_args); \
+ instr_end(); \
return; \
fault: \
kvm_spurious_fault(); \