From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AH8x226i9/F/FbqW0ovwEep/WiexAY0xiG8E/mA2tUpFdR/9x/Cz5o1qwExp6wvn4kqxM2xBlsF/ ARC-Seal: i=1; a=rsa-sha256; t=1516721588; cv=none; d=google.com; s=arc-20160816; b=Uj/VuZxqul9yVNHwztj0E1h90DMb9KvtCiGjAVyMzUVAINF5Khdwq3DHwVqyx1Snuf kku4dfHYzwsxmjmFg7QCw47djIS+9pBu+W+uPTScMb58qIdyw1SGuErusygCVqQsWbE7 y/iEj0qygH4/fVvbV9IzCo4gm5khAy4sbBR7d3yYxYICVe6kXUs+SoDCETgDADFoXhsl WyO+8n6V7xwdqz1XUkpJTppF1cewdrOmE6ulgGDtU/2Cyvp5trbBkii1gHiRLcEYgTYO kdS48ty76V/4GxClhDn3J8QCWSWm5dtFryNZmDlV4D6CGgS+xdjxAPfYHi2TM7yIXu+4 4Ozg== 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=v/BKNQ82hvIxrB1RbpJ/LWye9TcLeRMU2JJT/lQGHVs=; b=I6G8MmIfnWCDqhIqmeLL771Zk2feN5D+mrtNV/2Wyas+WYf8VDoopfXgiALZdpJPk0 xBtBP3RqSWH6a4xRPomo1nUKMEsLaaEcfCZVQ07u/LUiNOi7aDN5Ke20NhGR4hPVGSiN 0zzZIGUC1ncBoGvvqOZR9D1uAy/xvWnJUsBPddubbUDDHROgx23MZaA7s0Yx5/4V7Ktd cIdDXwRrzCq1RqvZQ4BXVyqx++0dxYX6MTuFHlsTUbxw65R3FdgvY1ErsLp4kVJpj3O/ lDXb41Aw2bwax49PGaw0RQ41hzv8wDN51Gf2ZuqXxwO/FAloVbVl3oSTkwyhQ2N7sSU/ xw5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=merlin.20170209 header.b=ruXrrC94; 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=ruXrrC94; 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: <20180123152638.933608293@infradead.org> User-Agent: quilt/0.63-1 Date: Tue, 23 Jan 2018 16:25:55 +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 , Borislav Petkov Subject: [PATCH 16/24] objtool: Implement jump_assert for _static_cpu_has() References: <20180123152539.374360046@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline; filename=peterz-objtool-static_cpu_has.patch X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: =?utf-8?q?1590397856853943906?= X-GMAIL-MSGID: =?utf-8?q?1590397856853943906?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: Unlike the jump_label bits, static_cpu_has is implemented with alternatives. We use the new type field to distinguish them from any other alternatives Like jump_labels, make static_cpu_has set static_jump_dest on the instructions after the static branch such that we can assert on it. Cc: Thomas Gleixner Cc: Borislav Petkov Cc: Josh Poimboeuf Signed-off-by: Peter Zijlstra (Intel) --- tools/objtool/check.c | 21 +++++++++++++++++++++ tools/objtool/special.c | 26 +++++++++++++++----------- tools/objtool/special.h | 1 + 3 files changed, 37 insertions(+), 11 deletions(-) --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -636,6 +636,12 @@ static int handle_group_alt(struct objto fake_jump->ignore = true; if (!special_alt->new_len) { + /* + * The NOP case for _static_cpu_has() + */ + if (special_alt->static_cpu_has) + fake_jump->jump_dest->static_jump_dest = true; + *new_insn = fake_jump; return 0; } @@ -664,6 +670,21 @@ static int handle_group_alt(struct objto insn->sec, insn->offset); return -1; } + + if (special_alt->static_cpu_has) { + if (insn->type != INSN_JUMP_UNCONDITIONAL) { + WARN_FUNC("not an unconditional jump in _static_cpu_has()", + insn->sec, insn->offset); + } + if (insn->jump_dest == fake_jump) { + WARN_FUNC("jump inside alternative for _static_cpu_has()", + insn->sec, insn->offset); + } + /* + * The JMP+disp case for _static_cpu_has() + */ + insn->jump_dest->static_jump_dest = true; + } } if (!last_new_insn) { --- a/tools/objtool/special.c +++ b/tools/objtool/special.c @@ -40,6 +40,10 @@ #define ALT_FEATURE_OFFSET 8 #define ALT_ORIG_LEN_OFFSET 10 #define ALT_NEW_LEN_OFFSET 11 +#define ALT_TYPE_OFFSET 13 + +#define ALT_TYPE_DEFAULT 0 +#define ALT_TYPE_STATIC_CPU_HAS 1 #define X86_FEATURE_POPCNT (4*32+23) @@ -48,7 +52,6 @@ struct special_entry { bool group, jump_or_nop; unsigned char size, orig, new; unsigned char orig_len, new_len; /* group only */ - unsigned char feature; /* ALTERNATIVE macro CPU feature */ }; struct special_entry entries[] = { @@ -60,7 +63,6 @@ struct special_entry entries[] = { .orig_len = ALT_ORIG_LEN_OFFSET, .new = ALT_NEW_OFFSET, .new_len = ALT_NEW_LEN_OFFSET, - .feature = ALT_FEATURE_OFFSET, }, { .sec = "__jump_table", @@ -84,24 +86,23 @@ static int get_alt_entry(struct elf *elf { struct rela *orig_rela, *new_rela; unsigned long offset; + void *data; offset = idx * entry->size; + data = sec->data->d_buf + offset; alt->group = entry->group; alt->jump_or_nop = entry->jump_or_nop; if (alt->group) { - alt->orig_len = *(unsigned char *)(sec->data->d_buf + offset + - entry->orig_len); - alt->new_len = *(unsigned char *)(sec->data->d_buf + offset + - entry->new_len); - } - - if (entry->feature) { unsigned short feature; + unsigned char type; - feature = *(unsigned short *)(sec->data->d_buf + offset + - entry->feature); + alt->orig_len = *(unsigned char *)(data + entry->orig_len); + alt->new_len = *(unsigned char *)(data + entry->new_len); + + feature = *(unsigned short *)(data + ALT_FEATURE_OFFSET); + type = *(unsigned char *)(data + ALT_TYPE_OFFSET); /* * It has been requested that we don't validate the !POPCNT @@ -110,6 +111,9 @@ static int get_alt_entry(struct elf *elf */ if (feature == X86_FEATURE_POPCNT) alt->skip_orig = true; + + if (type == ALT_TYPE_STATIC_CPU_HAS) + alt->static_cpu_has = true; } orig_rela = find_rela_by_dest(sec, offset + entry->orig); --- a/tools/objtool/special.h +++ b/tools/objtool/special.h @@ -27,6 +27,7 @@ struct special_alt { bool group; bool skip_orig; bool jump_or_nop; + bool static_cpu_has; struct section *orig_sec; unsigned long orig_off;