From: Dmitry Vyukov <dvyukov@google.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>,
LKML <linux-kernel@vger.kernel.org>,
"the arch/x86 maintainers" <x86@kernel.org>,
Marco Elver <elver@google.com>,
Andrey Konovalov <andreyknvl@google.com>,
Mark Rutland <mark.rutland@arm.com>,
mhelsley@vmware.com, Steven Rostedt <rostedt@goodmis.org>,
jthierry@redhat.com, mbenes@suse.cz
Subject: Re: [RFC][PATCH 3/3] objtool: Fix noinstr vs KCOV
Date: Mon, 15 Jun 2020 09:41:04 +0200 [thread overview]
Message-ID: <CACT4Y+Zj4=4C4rg6Y_EgQRjxS8_BcApxNeQRQVXewAsgQqQj8Q@mail.gmail.com> (raw)
In-Reply-To: <20200612143554.071314718@infradead.org>
On Fri, Jun 12, 2020 at 4:37 PM Peter Zijlstra <peterz@infradead.org> wrote:
>
> Since many compilers cannot disable KCOV with a function attribute,
> help it to NOP out any __sanitizer_cov_*() calls injected in noinstr
> code.
>
> This turns:
>
> 12: e8 00 00 00 00 callq 17 <lockdep_hardirqs_on+0x17>
> 13: R_X86_64_PLT32 __sanitizer_cov_trace_pc-0x4
>
> into:
>
> 12: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1)
> 13: R_X86_64_NONE __sanitizer_cov_trace_pc-0x4
>
> Just like recordmcount does.
>
> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Dmitry Vyukov <dvyukov@google.com>
Thanks!
> ---
> tools/objtool/arch.h | 2 ++
> tools/objtool/arch/x86/decode.c | 18 ++++++++++++++++++
> tools/objtool/arch/x86/include/arch_elf.h | 6 ++++++
> tools/objtool/check.c | 19 +++++++++++++++++++
> 4 files changed, 45 insertions(+)
>
> --- a/tools/objtool/arch.h
> +++ b/tools/objtool/arch.h
> @@ -84,4 +84,6 @@ unsigned long arch_jump_destination(stru
>
> unsigned long arch_dest_reloc_offset(int addend);
>
> +const char *arch_nop_insn(int len);
> +
> #endif /* _ARCH_H */
> --- a/tools/objtool/arch/x86/decode.c
> +++ b/tools/objtool/arch/x86/decode.c
> @@ -565,3 +565,21 @@ void arch_initial_func_cfi_state(struct
> state->regs[16].base = CFI_CFA;
> state->regs[16].offset = -8;
> }
> +
> +const char *arch_nop_insn(int len)
> +{
> + static const char nops[5][5] = {
> + /* 1 */ { 0x90 },
> + /* 2 */ { 0x66, 0x90 },
> + /* 3 */ { 0x0f, 0x1f, 0x00 },
> + /* 4 */ { 0x0f, 0x1f, 0x40, 0x00 },
> + /* 5 */ { 0x0f, 0x1f, 0x44, 0x00, 0x00 },
> + };
> +
> + if (len < 1 || len > 5) {
> + WARN("invalid NOP size: %d\n", len);
> + return NULL;
> + }
> +
> + return nops[len-1];
> +}
> --- /dev/null
> +++ b/tools/objtool/arch/x86/include/arch_elf.h
> @@ -0,0 +1,6 @@
> +#ifndef _OBJTOOL_ARCH_ELF
> +#define _OBJTOOL_ARCH_ELF
> +
> +#define R_NONE R_X86_64_NONE
> +
> +#endif /* _OBJTOOL_ARCH_ELF */
> --- a/tools/objtool/check.c
> +++ b/tools/objtool/check.c
> @@ -12,6 +12,7 @@
> #include "check.h"
> #include "special.h"
> #include "warn.h"
> +#include "arch_elf.h"
>
> #include <linux/hashtable.h>
> #include <linux/kernel.h>
> @@ -744,6 +745,24 @@ static int add_call_destinations(struct
> insn->call_dest = reloc->sym;
>
> /*
> + * Many compilers cannot disable KCOV with a function attribute
> + * so they need a little help, NOP out any KCOV calls from noinstr
> + * text.
> + */
> + if (insn->sec->noinstr &&
> + !strncmp(insn->call_dest->name, "__sanitizer_cov_", 16)) {
> + if (reloc) {
> + reloc->type = R_NONE;
> + elf_write_reloc(file->elf, reloc);
> + }
> +
> + elf_write_insn(file->elf, insn->sec,
> + insn->offset, insn->len,
> + arch_nop_insn(insn->len));
> + insn->type = INSN_NOP;
> + }
> +
> + /*
> * Whatever stack impact regular CALLs have, should be undone
> * by the RETURN of the called function.
> *
>
>
next prev parent reply other threads:[~2020-06-15 7:41 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-12 14:30 [RFC][PATCH 0/3] objtool: KCOV vs noinstr Peter Zijlstra
2020-06-12 14:30 ` [RFC][PATCH 1/3] objtool: Clean up elf_write() condition Peter Zijlstra
2020-06-15 18:34 ` Matt Helsley
2020-06-15 18:44 ` Peter Zijlstra
2020-06-16 8:32 ` Peter Zijlstra
2020-06-12 14:30 ` [RFC][PATCH 2/3] objtool: Provide elf_write_{insn,reloc}() Peter Zijlstra
2020-06-16 9:12 ` Peter Zijlstra
2020-06-16 19:51 ` Matt Helsley
2020-06-12 14:30 ` [RFC][PATCH 3/3] objtool: Fix noinstr vs KCOV Peter Zijlstra
2020-06-15 7:41 ` Dmitry Vyukov [this message]
2020-06-13 19:54 ` [RFC][PATCH 0/3] objtool: KCOV vs noinstr Matt Helsley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CACT4Y+Zj4=4C4rg6Y_EgQRjxS8_BcApxNeQRQVXewAsgQqQj8Q@mail.gmail.com' \
--to=dvyukov@google.com \
--cc=andreyknvl@google.com \
--cc=elver@google.com \
--cc=jpoimboe@redhat.com \
--cc=jthierry@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mbenes@suse.cz \
--cc=mhelsley@vmware.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).