From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Google-Smtp-Source: AH8x22501JJHikKO8/fr+pMY/iV6wXCeZvkAaU0uHcIO3GJ0974/t3vDxz3E988a8RqbKRs4NtlL ARC-Seal: i=1; a=rsa-sha256; t=1516721587; cv=none; d=google.com; s=arc-20160816; b=TX/jjvOJuYI4xPPaEqNy719Jv15ju9BFFUFg0S883kEEXbW1SfqfglKuenX7qd1jfc TET3OFOS027f8t1gee5+JCU0I3oDv6ichoQiHuw0gw5gw5QjfOHJDUrUOCmCXECgMPcB r5P+E212EguAp1M0EQ7HpgcQdgrN7u0LKkiqboVtAJEjisdPinYe3bt+qlZis6b+E6cK 89PIxyoZJgml9h0w6+r+apPQdCwe7eTfgmnVZNm7zmZALPpCvZJj+cT7mFCGGuAGQC5+ XDky7/vdMUos5CKO23rTR1NozwJBNEnYYRRr9c3Xi7qQkN0uQOR99LWFL/pHpBIctb7j u0QQ== 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=H3dFypSPRprordoQTgL1FdCwwRp1Woyjnyi9jyCH3Rc=; b=jtk+jLqwaRN0NYKwPhekY7hLTYdBS63cKUUQqRe0jQKXdKGT+n7MyJauBSc3SyFjEe TMS8J5MC55HCXWPHAB0DlBzVsDlNKXQVQy5ds7oO6QosXXhmFsF575moAq2kNUfD7oNO aX9NwbSsSDbsMktsBUtKogyNgBKwG6/de8fN5LaPubF3KOZeK3wKKQof5dwmUO0YK0fz zJsmvI1a86P7iBXEScu9bGzmIvcMcLr8ZMXVV0KX6mwpoVWkOBMQWyMRCRB3VzfP5iDZ LNO9pWnABH2hXdqzUlySlKFFZdi4R+FmZ8jvze8yO6JRSqu3e4N1ZF7PlRrkhuMrlhVi tBtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=merlin.20170209 header.b=SBiKJ9m1; 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=SBiKJ9m1; 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.815589591@infradead.org> User-Agent: quilt/0.63-1 Date: Tue, 23 Jan 2018 16:25:53 +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 , Borislav Petkov Subject: [PATCH 14/24] x86: Add a type field to alt_instr References: <20180123152539.374360046@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline; filename=peterz-alternative-type.patch X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: =?utf-8?q?1590397855930872827?= X-GMAIL-MSGID: =?utf-8?q?1590397855930872827?= X-Mailing-List: linux-kernel@vger.kernel.org List-ID: Add a type field to the alternative description. For now this will be used to annotate static_cpu_has() but possible future uses include using it to implement alternative alignment and special NOP handling. Suggested-by: Borislav Petkov Reviewed-by: Borislav Petkov Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/include/asm/alternative-asm.h | 3 ++- arch/x86/include/asm/alternative.h | 6 +++++- arch/x86/include/asm/cpufeature.h | 2 ++ arch/x86/kernel/alternative.c | 4 ++-- tools/objtool/special.c | 2 +- 5 files changed, 12 insertions(+), 5 deletions(-) --- a/arch/x86/include/asm/alternative-asm.h +++ b/arch/x86/include/asm/alternative-asm.h @@ -25,13 +25,14 @@ * enough information for the alternatives patching code to patch an * instruction. See apply_alternatives(). */ -.macro altinstruction_entry orig alt feature orig_len alt_len pad_len +.macro altinstruction_entry orig alt feature orig_len alt_len pad_len type=0 .long \orig - . .long \alt - . .word \feature .byte \orig_len .byte \alt_len .byte \pad_len + .byte \type .endm /* --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -45,6 +45,8 @@ #define LOCK_PREFIX "" #endif +#define ALT_TYPE_DEFAULT 0 + struct alt_instr { s32 instr_offset; /* original instruction */ s32 repl_offset; /* offset to replacement instruction */ @@ -52,6 +54,7 @@ struct alt_instr { u8 instrlen; /* length of original instruction */ u8 replacementlen; /* length of new instruction */ u8 padlen; /* length of build-time padding */ + u8 type; /* type of alternative */ } __packed; /* @@ -127,7 +130,8 @@ static inline int alternatives_text_rese " .word " __stringify(feature) "\n" /* feature bit */ \ " .byte " alt_total_slen "\n" /* source len */ \ " .byte " alt_rlen(num) "\n" /* replacement len */ \ - " .byte " alt_pad_len "\n" /* pad len */ + " .byte " alt_pad_len "\n" /* pad len */ \ + " .byte 0 \n" /* type */ #define ALTINSTR_REPLACEMENT(newinstr, feature, num) /* replacement */ \ b_replacement(num)":\n\t" newinstr "\n" e_replacement(num) ":\n\t" --- a/arch/x86/include/asm/cpufeature.h +++ b/arch/x86/include/asm/cpufeature.h @@ -157,6 +157,7 @@ static __always_inline __pure bool _stat " .byte 3b - 1b\n" /* src len */ " .byte 5f - 4f\n" /* repl len */ " .byte 3b - 2b\n" /* pad len */ + " .byte 0\n" /* type */ ".previous\n" ".section .altinstr_replacement,\"ax\"\n" "4: jmp %l[t_no]\n" @@ -169,6 +170,7 @@ static __always_inline __pure bool _stat " .byte 3b - 1b\n" /* src len */ " .byte 0\n" /* repl len */ " .byte 0\n" /* pad len */ + " .byte 0\n" /* type */ ".previous\n" ".section .altinstr_aux,\"ax\"\n" "6:\n" --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -400,11 +400,11 @@ void __init_or_module noinline apply_alt continue; } - DPRINTK("feat: %d*32+%d, old: (%p, len: %d), repl: (%p, len: %d), pad: %d", + DPRINTK("feat: %d*32+%d, old: (%p, len: %d), repl: (%p, len: %d), pad: %d, type: %d", a->cpuid >> 5, a->cpuid & 0x1f, instr, a->instrlen, - replacement, a->replacementlen, a->padlen); + replacement, a->replacementlen, a->padlen, a->type); DUMP_BYTES(instr, a->instrlen, "%p: old_insn: ", instr); DUMP_BYTES(replacement, a->replacementlen, "%p: rpl_insn: ", replacement); --- a/tools/objtool/special.c +++ b/tools/objtool/special.c @@ -34,7 +34,7 @@ #define JUMP_ORIG_OFFSET 0 #define JUMP_NEW_OFFSET 8 -#define ALT_ENTRY_SIZE 13 +#define ALT_ENTRY_SIZE 14 #define ALT_ORIG_OFFSET 0 #define ALT_NEW_OFFSET 4 #define ALT_FEATURE_OFFSET 8