From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AH8x227S8bPEJ9885HCiPqs2mMqnECGkW86BoSozT8Zyi0H/y7hEmfhbS7/tZj3rH6h12piz3HmV ARC-Seal: i=1; a=rsa-sha256; t=1516721585; cv=none; d=google.com; s=arc-20160816; b=hjhJbKS9uB68SjYgZXBZ/JBBwovhLyhEe4PDNCOqvIqVEsA0abfJOvdKooa6BhO/ex iylwaRnp7bb0aV7lGN4L2frEQMcSKeW5P2B/NqNqUS9nDNBow2Cv7x5Ou5XW4sqXO5td XWs052NcmW+fjJ8QEJNf2Padt3+kYw05758HwYAi0OTfxhUnEjFDAx9BGA5C79Tbr9EZ DSK/Jz1ArwSrDWyIUu6MzOi0ts1s2tAv1VtGgErbhmRn6CBIa8EAaNZMQH+9YNHyhxpc DJRxqM8RR6OsB12r94bPW760aqRNvsSEESaiqxLFnTTM0aq83UQX2258Ulr+t82DpW7X ITlQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-disposition:mime-version:references:subject:cc:to:from:date :user-agent:message-id:dkim-signature:arc-authentication-results; bh=PnatMXp8/38byPI4eLkIblipUNeo9WbjntewmX35ndw=; b=FIXtQTsftI0ihCUhgEq91oqmrSvumpHXlcAu/JAu9/Gsl0QP5K+SSxTJnV9XUc4+Bh KiAbZfOVMocWgODK2s51tIlnd+LORWnkC0Om2+BdrIHEOkq8ny1+Pbx26CR2DzjtkTZl tnhsv7EBKNZ3Mz7tfO7amEZrN4AiZ5lY/4VfQYLLzfeGU4jv9jEVBYjnzmICoO9R26Ig ybmglKGOnpyqsoxXDh+5nr+eOqo+7OkX3qkn5xSyhYaRZ0czXCbo6sDRse1HzOq9IVA9 BrDhWkhJdLXCIobCU7VqTbmYGeJ2bn2O0xcm/2hUEQxfOuuL6W5sTKLz4ZmXHByaE0za JmEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=merlin.20170209 header.b=1Bv5kL3o; spf=pass (google.com: best guess record for domain of peterz@infradead.org designates 205.233.59.134 as permitted sender) smtp.mailfrom=peterz@infradead.org Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=merlin.20170209 header.b=1Bv5kL3o; spf=pass (google.com: best guess record for domain of peterz@infradead.org designates 205.233.59.134 as permitted sender) smtp.mailfrom=peterz@infradead.org Message-Id: <20180123152639.049872416@infradead.org> User-Agent: quilt/0.63-1 Date: Tue, 23 Jan 2018 16:25:57 +0100 From: Peter Zijlstra To: David Woodhouse , Thomas Gleixner , Josh Poimboeuf Cc: linux-kernel@vger.kernel.org, Dave Hansen , Ashok Raj , Tim Chen , Andy Lutomirski , Linus Torvalds , Greg KH , Andrea Arcangeli , Andi Kleen , Arjan Van De Ven , Dan Williams , Paolo Bonzini , Jun Nakajima , Asit Mallick , Jason Baron , Peter Zijlstra Subject: [PATCH 18/24] objtool: More complex static jump implementation References: <20180123152539.374360046@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline; filename=peterz-objtool-fancy.patch X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: =?utf-8?q?1590397853824354061?= X-GMAIL-MSGID: =?utf-8?q?1590397853824354061?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: When using something like: -#define sched_feat(x) (static_branch_##x(&sched_feat_keys[__SCHED_FEAT_##x])) +#define sched_feat(x) (static_branch_##x(&sched_feat_keys[__SCHED_FEAT_##x]) && \ + (arch_static_assert(), true)) we get an objtool assertion fail like: kernel/sched/fair.o: warning: objtool: hrtick_update()+0xd: static assert FAIL where: 0000000000001140 : 1140: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1) 1145: c3 retq 1146: 48 8b b7 30 09 00 00 mov 0x930(%rdi),%rsi 114d: 8b 87 d8 09 00 00 mov 0x9d8(%rdi),%eax 1153: 48 0f a3 05 00 00 00 bt %rax,0x0(%rip) # 115b 115a: 00 1157: R_X86_64_PC32 __cpu_active_mask-0x4 and: RELOCATION RECORDS FOR [__jump_table]: 0000000000000150 R_X86_64_64 .text+0x0000000000001140 0000000000000158 R_X86_64_64 .text+0x0000000000001146 RELOCATION RECORDS FOR [.discard.jump_assert]: 0000000000000028 R_X86_64_64 .text+0x000000000000114d IOW, GCC managed to place the assertion 1 instruction _after_ the static jump target (it lifted a load over it). So while the code generation is fine, the assertion gets placed wrong. We can 'fix' this by not only considering the immediate static jump locations but also all the unconditional code after it, terminating the basic block on any unconditional instruction or branch entry point. Signed-off-by: Peter Zijlstra (Intel) --- tools/objtool/check.c | 41 +++++++++++++++++++++++++++++++++++++++++ tools/objtool/check.h | 1 + 2 files changed, 42 insertions(+) --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -520,6 +520,8 @@ static int add_jump_destinations(struct dest_off); return -1; } + + insn->jump_dest->branch_target++; } return 0; @@ -1205,6 +1207,41 @@ static int assert_static_jumps(struct ob return 0; } +static int grow_static_blocks(struct objtool_file *file) +{ + struct instruction *insn; + bool static_block = false; + + for_each_insn(file, insn) { + if (!static_block && !insn->static_jump_dest) + continue; + + if (insn->static_jump_dest) { + static_block = true; + continue; + } + + if (insn->branch_target) { + static_block = false; + continue; + } else switch (insn->type) { + case INSN_JUMP_CONDITIONAL: + case INSN_JUMP_UNCONDITIONAL: + case INSN_JUMP_DYNAMIC: + case INSN_CALL: + case INSN_CALL_DYNAMIC: + case INSN_RETURN: + case INSN_BUG: + static_block = false; + continue; + } + + insn->static_jump_dest = static_block; + } + + return 0; +} + static int decode_sections(struct objtool_file *file) { int ret; @@ -1247,6 +1284,10 @@ static int decode_sections(struct objtoo if (ret) return ret; + ret = grow_static_blocks(file); + if (ret) + return ret; + return 0; } --- a/tools/objtool/check.h +++ b/tools/objtool/check.h @@ -46,6 +46,7 @@ struct instruction { unsigned long immediate; bool alt_group, visited, dead_end, ignore, hint, save, restore, ignore_alts; bool retpoline_safe, static_jump_dest; + unsigned int branch_target; struct symbol *call_dest; struct instruction *jump_dest; struct list_head alts;