From nobody Fri Feb 13 06:06:27 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86D93158844 for ; Fri, 31 May 2024 12:35:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717158917; cv=none; b=jAwuIskMj5LA2ttyJGncLPacIlaM9AhkxZr8Cn9QFboKiJjRhbuDaXr2m3QvMXBunE5/quASJ5D4VfsdQw95YHK4CyROjTEwygjl1MC7VqdDdJrBrjTT+ryuFCHSLCDxxe5lrltWe7uQqQRFUOmkgvI5Nf1oyXOL9fQp2gJNo7s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717158917; c=relaxed/simple; bh=9t/V6lr+JXo0ko6oV1wFcYKchLmN9d+xrlxuBH0B4uw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V3YBoNiq8QoflaMOBHexd47dbDaw1YUL5q3bttEYUOMXZIT0rES04R7nOPcZtHZDIzkJjrIv/TKT6ly+6+v1zCtwqkLjJu3MoXmxd8SjpA0PKmRnLfklTqizOrhtXENlLoqAR3ZfP0weRmo9h5rMQwpXeaizvZo33hdL2knWreI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=lko8zPPA; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="lko8zPPA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20FDBC32786; Fri, 31 May 2024 12:35:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717158917; bh=9t/V6lr+JXo0ko6oV1wFcYKchLmN9d+xrlxuBH0B4uw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lko8zPPAPktjqk+dyMkOTnRhDoggyTctDZErDEUn+DmFwHj6kOJbpgxFRczveQ6CV DfvY+ez/OYnFZw2X82y25U5EMpUlgKV4YfiPCBrhV30/GfvxGCxt2BYhB1/bz2PtPY xDsqPdj5WIcdb8JHPnDYQh/D5Z2iKZXBCXip3hcsVbgGZtBYEXbTSLNk18+DwoTNy0 vB6+7vy+aKfyM5MKzSgtWJ7N84UJNstAja/Y5BTotOrbQBP1hEtXyOP7dl0Gyx9ljw o2VTbvbKJBIJ5hHKhs0DxBh+GQ8Q1wZKmWhO8eFglFeWSSRGVfnc5k/2naQwOi+eiw TNmg7fZVQMDmw== From: Borislav Petkov To: X86 ML Cc: LKML , "Borislav Petkov (AMD)" Subject: [PATCH 01/14] x86/alternative: Zap alternative_ternary() Date: Fri, 31 May 2024 14:34:58 +0200 Message-ID: <20240531123512.21427-2-bp@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240531123512.21427-1-bp@kernel.org> References: <20240531123512.21427-1-bp@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Borislav Petkov (AMD)" Unused. Signed-off-by: Borislav Petkov (AMD) --- arch/x86/include/asm/alternative.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alte= rnative.h index ba99ef75f56c..6db78909180a 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -271,9 +271,6 @@ static inline int alternatives_text_reserved(void *star= t, void *end) #define alternative_2(oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2= ) \ asm_inline volatile(ALTERNATIVE_2(oldinstr, newinstr1, ft_flags1, newinst= r2, ft_flags2) ::: "memory") =20 -#define alternative_ternary(oldinstr, ft_flags, newinstr_yes, newinstr_no)= \ - asm_inline volatile(ALTERNATIVE_TERNARY(oldinstr, ft_flags, newinstr_yes,= newinstr_no) ::: "memory") - /* * Alternative inline assembly with input. * --=20 2.43.0 From nobody Fri Feb 13 06:06:27 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 05EBC158A34 for ; Fri, 31 May 2024 12:35:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717158919; cv=none; b=oDY3zZOIFae0uzlRjntUe7SSh6/SOlBv5KTp8p7t8X8MwPL5Nh9zVqnS5jX6/YPIACePVum8OrwkAHUYjsefAckXmADskw6wf/LqkWAie3hpBk2F2Cr1dMX8nA9AVI4rqJf5p73X0pMzNjtvdDpAVc+vuBU8etmi3cZDoie/Lko= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717158919; c=relaxed/simple; bh=djd/4b8XodmEOYNor304vVtzD3Y1BqyhAwOAF49HUnQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=buZ12l7BS7Ng/jhcAiD/0Y2YHOWlcfrgrWQmRZQWhvDBoZirnDjWC5GXTofemGBwLAH2SHgE6q8ryVe80q6eBElEEhrOlF7gepTaaKrqrdsyaDBCa/3blxsXD45rUscjkRjaXCSUr4Ek95COGL2YcBeL7wz0saWdAkZZqCbG4Gs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UwxbnC0g; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="UwxbnC0g" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 61358C32789; Fri, 31 May 2024 12:35:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717158918; bh=djd/4b8XodmEOYNor304vVtzD3Y1BqyhAwOAF49HUnQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UwxbnC0gwjshJFlnjgDeT+HC0OshleZC+ZkQN1uuJ7I85z8AvfOxC5rQKQ7joG8BG AfWEl6uGflITOMpOsq2n5iklrH/emtVVZMWviw23t079Vq8mM1jGz6RZWgG25NIUyl SZdYpnoJZwATm+KuFnIjPwdl/2iDuYnWjeVsfvj4Md8Tm+njDwRgspr4QcXugeikEq dejq3nJFLib2FmG96wg5ZNVfXw0tNLxd1O/sFfW67TP5DIxcpEvqsFdbI0ghA0b06P x7F3uhvwAv71IZcsAnNB2M6MELw8ZS5ZwBZZINRzh+0xWTSeCM1p9wF6XkikRL+R7c JEFjvpWDUDyvw== From: Borislav Petkov To: X86 ML Cc: LKML , Peter Zijlstra , Borislav Petkov Subject: [PATCH 02/14] x86/alternatives: Add nested alternatives macros Date: Fri, 31 May 2024 14:34:59 +0200 Message-ID: <20240531123512.21427-3-bp@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240531123512.21427-1-bp@kernel.org> References: <20240531123512.21427-1-bp@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Peter Zijlstra Instead of making increasingly complicated ALTERNATIVE_n() implementations, use a nested alternative expression. The only difference between: ALTERNATIVE_2(oldinst, newinst1, flag1, newinst2, flag2) and ALTERNATIVE(ALTERNATIVE(oldinst, newinst1, flag1), newinst2, flag2) is that the outer alternative can add additional padding when the inner alternative is the shorter one, which then results in alt_instr::instrlen being inconsistent. However, this is easily remedied since the alt_instr entries will be consecutive and it is trivial to compute the max(alt_instr::instrlen) at runtime while patching. Specifically, after this the ALTERNATIVE_2 macro, after CPP expansion (and manual layout), looks like this: .macro ALTERNATIVE_2 oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2 740: 740: \oldinstr ; 741: .skip -(((744f-743f)-(741b-740b)) > 0) * ((744f-743f)-(741b-740b)),0= x90 ; 742: .pushsection .altinstructions,"a" ; altinstr_entry 740b,743f,\ft_flags1,742b-740b,744f-743f ; .popsection ; .pushsection .altinstr_replacement,"ax" ; 743: \newinstr1 ; 744: .popsection ; ; 741: .skip -(((744f-743f)-(741b-740b)) > 0) * ((744f-743f)-(741b-740b)),0= x90 ; 742: .pushsection .altinstructions,"a" ; altinstr_entry 740b,743f,\ft_flags2,742b-740b,744f-743f ; .popsection ; .pushsection .altinstr_replacement,"ax" ; 743: \newinstr2 ; 744: .popsection ; .endm The only label that is ambiguous is 740, however they all reference the same spot, so that doesn't matter. NOTE: obviously only @oldinstr may be an alternative; making @newinstr an alternative would mean patching .altinstr_replacement which very likely isn't what is intended, also the labels will be confused in that case. [ bp: Debug an issue where it would match the wrong two insns and and consider them nested due to the same signed offsets in the .alternative section and use instr_va() to compare the full virtual addresses instead. - Use new labels to denote that the new, nested alternatives are being used when staring at preprocessed output. ] Signed-off-by: Peter Zijlstra Co-developed-by: Borislav Petkov (AMD) Signed-off-by: Borislav Petkov (AMD) Link: https://lkml.kernel.org/r/20230628104952.GA2439977@hirez.programming.= kicks-ass.net --- arch/x86/include/asm/alternative.h | 110 ++++++++++++++++++++++++++++- arch/x86/kernel/alternative.c | 20 +++++- tools/objtool/arch/x86/special.c | 23 ++++++ tools/objtool/special.c | 16 ++--- 4 files changed, 158 insertions(+), 11 deletions(-) diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alte= rnative.h index 6db78909180a..8554c2c339ff 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -161,8 +161,13 @@ static inline int alternatives_text_reserved(void *sta= rt, void *end) =20 #define alt_end_marker "663" #define alt_slen "662b-661b" +#define n_alt_slen "772b-771b" + #define alt_total_slen alt_end_marker"b-661b" +#define n_alt_total_slen "773b-771b" + #define alt_rlen(num) e_replacement(num)"f-"b_replacement(num)"f" +#define n_alt_rlen "775f-774f" =20 #define OLDINSTR(oldinstr, num) \ "# ALT: oldnstr\n" \ @@ -172,6 +177,14 @@ static inline int alternatives_text_reserved(void *sta= rt, void *end) "((" alt_rlen(num) ")-(" alt_slen ")),0x90\n" \ alt_end_marker ":\n" =20 +#define N_OLDINSTR(oldinstr) \ + "# N_ALT: oldinstr\n" \ + "771:\n\t" oldinstr "\n772:\n" \ + "# N_ALT: padding\n" \ + ".skip -(((" n_alt_rlen ")-(" n_alt_slen ")) > 0) * " \ + "((" n_alt_rlen ")-(" n_alt_slen ")),0x90\n" \ + "773:\n" + /* * gas compatible max based on the idea from: * http://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax @@ -209,10 +222,25 @@ static inline int alternatives_text_reserved(void *st= art, void *end) " .byte " alt_total_slen "\n" /* source len */ \ " .byte " alt_rlen(num) "\n" /* replacement len */ =20 +#define N_ALTINSTR_ENTRY(ft_flags) \ + ".pushsection .altinstructions,\"a\"\n" \ + " .long 771b - .\n" /* label */ \ + " .long 774f - .\n" /* new instruction */ \ + " .4byte " __stringify(ft_flags) "\n" /* feature + flags */ \ + " .byte " n_alt_total_slen "\n" /* source len */ \ + " .byte " n_alt_rlen "\n" /* replacement len */ \ + ".popsection\n" + #define ALTINSTR_REPLACEMENT(newinstr, num) /* replacement */ \ "# ALT: replacement " #num "\n" \ b_replacement(num)":\n\t" newinstr "\n" e_replacement(num) ":\n" =20 +#define N_ALTINSTR_REPLACEMENT(newinstr) /* replacement */ \ + ".pushsection .altinstr_replacement, \"ax\"\n" \ + "# N_ALT: replacement\n" \ + "774:\n\t" newinstr "\n775:\n" \ + ".popsection\n" + /* alternative assembly primitive: */ #define ALTERNATIVE(oldinstr, newinstr, ft_flags) \ OLDINSTR(oldinstr, 1) \ @@ -223,6 +251,12 @@ static inline int alternatives_text_reserved(void *sta= rt, void *end) ALTINSTR_REPLACEMENT(newinstr, 1) \ ".popsection\n" =20 +/* Nested alternatives macro variant */ +#define N_ALTERNATIVE(oldinstr, newinstr, ft_flags) \ + N_OLDINSTR(oldinstr) \ + N_ALTINSTR_ENTRY(ft_flags) \ + N_ALTINSTR_REPLACEMENT(newinstr) + #define ALTERNATIVE_2(oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2= ) \ OLDINSTR_2(oldinstr, 1, 2) \ ".pushsection .altinstructions,\"a\"\n" \ @@ -234,11 +268,21 @@ static inline int alternatives_text_reserved(void *st= art, void *end) ALTINSTR_REPLACEMENT(newinstr2, 2) \ ".popsection\n" =20 +#define N_ALTERNATIVE_2(oldinst, newinst1, flag1, newinst2, flag2) \ + N_ALTERNATIVE(N_ALTERNATIVE(oldinst, newinst1, flag1), \ + newinst2, flag2) + /* If @feature is set, patch in @newinstr_yes, otherwise @newinstr_no. */ #define ALTERNATIVE_TERNARY(oldinstr, ft_flags, newinstr_yes, newinstr_no)= \ ALTERNATIVE_2(oldinstr, newinstr_no, X86_FEATURE_ALWAYS, \ newinstr_yes, ft_flags) =20 +/* If @feature is set, patch in @newinstr_yes, otherwise @newinstr_no. */ +#define N_ALTERNATIVE_TERNARY(oldinstr, ft_flags, newinstr_yes, newinstr_n= o) \ + N_ALTERNATIVE_2(oldinstr, newinstr_no, X86_FEATURE_ALWAYS, \ + newinstr_yes, ft_flags) + + #define ALTERNATIVE_3(oldinsn, newinsn1, ft_flags1, newinsn2, ft_flags2, \ newinsn3, ft_flags3) \ OLDINSTR_3(oldinsn, 1, 2, 3) \ @@ -253,6 +297,12 @@ static inline int alternatives_text_reserved(void *sta= rt, void *end) ALTINSTR_REPLACEMENT(newinsn3, 3) \ ".popsection\n" =20 + +#define N_ALTERNATIVE_3(oldinst, newinst1, flag1, newinst2, flag2, \ + newinst3, flag3) \ + N_ALTERNATIVE(N_ALTERNATIVE_2(oldinst, newinst1, flag1, newinst2, flag2),= \ + newinst3, flag3) + /* * Alternative instructions for different CPU types or capabilities. * @@ -271,6 +321,12 @@ static inline int alternatives_text_reserved(void *sta= rt, void *end) #define alternative_2(oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2= ) \ asm_inline volatile(ALTERNATIVE_2(oldinstr, newinstr1, ft_flags1, newinst= r2, ft_flags2) ::: "memory") =20 +#define n_alternative(oldinstr, newinstr, ft_flags) \ + asm_inline volatile (N_ALTERNATIVE(oldinstr, newinstr, ft_flags) : : : "m= emory") + +#define n_alternative_2(oldinstr, newinstr1, ft_flags1, newinstr2, ft_flag= s2) \ + asm_inline volatile(N_ALTERNATIVE_2(oldinstr, newinstr1, ft_flags1, newin= str2, ft_flags2) ::: "memory") + /* * Alternative inline assembly with input. * @@ -288,11 +344,24 @@ static inline int alternatives_text_reserved(void *st= art, void *end) asm_inline volatile (ALTERNATIVE(oldinstr, newinstr, ft_flags) \ : output : "i" (0), ## input) =20 +#define n_alternative_io(oldinstr, newinstr, ft_flags, output, input...) \ + asm_inline volatile (N_ALTERNATIVE(oldinstr, newinstr, ft_flags) \ + : output : "i" (0), ## input) + + /* Like alternative_io, but for replacing a direct call with another one. = */ #define alternative_call(oldfunc, newfunc, ft_flags, output, input...) \ asm_inline volatile (ALTERNATIVE("call %c[old]", "call %c[new]", ft_flags= ) \ : output : [old] "i" (oldfunc), [new] "i" (newfunc), ## input) =20 +#define n_alternative_input(oldinstr, newinstr, ft_flags, input...) \ + asm_inline volatile (N_ALTERNATIVE(oldinstr, newinstr, ft_flags) \ + : : "i" (0), ## input) + +#define n_alternative_call(oldfunc, newfunc, ft_flags, output, input...) \ + asm_inline volatile (N_ALTERNATIVE("call %P[old]", "call %P[new]", ft_fla= gs) \ + : output : [old] "i" (oldfunc), [new] "i" (newfunc), ## input) + /* * Like alternative_call, but there are two features and respective functi= ons. * If CPU has feature2, function2 is used. @@ -307,6 +376,15 @@ static inline int alternatives_text_reserved(void *sta= rt, void *end) : [old] "i" (oldfunc), [new1] "i" (newfunc1), \ [new2] "i" (newfunc2), ## input) =20 +#define n_alternative_call_2(oldfunc, newfunc1, ft_flags1, newfunc2, ft_fl= ags2, \ + output, input...) \ + asm_inline volatile (N_ALTERNATIVE_2("call %P[old]", "call %P[new1]", ft_= flags1,\ + "call %P[new2]", ft_flags2) \ + : output, ASM_CALL_CONSTRAINT \ + : [old] "i" (oldfunc), [new1] "i" (newfunc1), \ + [new2] "i" (newfunc2), ## input) + + /* * use this macro(s) if you need more than one output parameter * in alternative_io @@ -403,6 +481,27 @@ void nop_func(void); .popsection .endm =20 +#define __N_ALTERNATIVE(oldinst, newinst, flag) \ +740: \ + oldinst ; \ +741: \ + .skip -(((744f-743f)-(741b-740b)) > 0) * ((744f-743f)-(741b-740b)),0x90 ;\ +742: \ + .pushsection .altinstructions,"a" ; \ + altinstr_entry 740b,743f,flag,742b-740b,744f-743f ; \ + .popsection ; \ + .pushsection .altinstr_replacement,"ax" ; \ +743: \ + newinst ; \ +744: \ + .popsection ; + + +.macro N_ALTERNATIVE oldinstr, newinstr, ft_flags + __N_ALTERNATIVE(\oldinstr, \newinstr, \ft_flags) +.endm + + #define old_len 141b-140b #define new_len1 144f-143f #define new_len2 145f-144f @@ -417,7 +516,6 @@ void nop_func(void); #define alt_max_2(a, b) ((a) ^ (((a) ^ (b)) & -(-((a) < (b))))) #define alt_max_3(a, b, c) (alt_max_2(alt_max_2(a, b), c)) =20 - /* * Same as ALTERNATIVE macro above but for two alternatives. If CPU * has @feature1, it replaces @oldinstr with @newinstr1. If CPU has @@ -445,6 +543,11 @@ void nop_func(void); .popsection .endm =20 +.macro N_ALTERNATIVE_2 oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2 + __N_ALTERNATIVE(__N_ALTERNATIVE(\oldinstr, \newinstr1, \ft_flags1), + \newinstr2, \ft_flags2) +.endm + .macro ALTERNATIVE_3 oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2,= newinstr3, ft_flags3 140: \oldinstr @@ -470,6 +573,11 @@ void nop_func(void); .popsection .endm =20 +.macro N_ALTERNATIVE_3 oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags= 2, newinstr3, ft_flags3 + __N_ALTERNATIVE(N_ALTERNATIVE_2(\oldinstr, \newinstr1, \ft_flags1, \newin= str2, \ft_flags2), + \newinstr3, \ft_flags3) +.endm + /* If @feature is set, patch in @newinstr_yes, otherwise @newinstr_no. */ #define ALTERNATIVE_TERNARY(oldinstr, ft_flags, newinstr_yes, newinstr_no)= \ ALTERNATIVE_2 oldinstr, newinstr_no, X86_FEATURE_ALWAYS, \ diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 89de61243272..37596a417094 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -432,6 +432,11 @@ static int alt_replace_call(u8 *instr, u8 *insn_buff, = struct alt_instr *a) return 5; } =20 +static inline u8 * instr_va(struct alt_instr *i) +{ + return (u8 *)&i->instr_offset + i->instr_offset; +} + /* * Replace instructions with better alternatives for this CPU type. This r= uns * before SMP is initialized to avoid SMP problems with self modifying cod= e. @@ -447,7 +452,7 @@ void __init_or_module noinline apply_alternatives(struc= t alt_instr *start, { u8 insn_buff[MAX_PATCH_LEN]; u8 *instr, *replacement; - struct alt_instr *a; + struct alt_instr *a, *b; =20 DPRINTK(ALT, "alt table %px, -> %px", start, end); =20 @@ -473,7 +478,18 @@ void __init_or_module noinline apply_alternatives(stru= ct alt_instr *start, for (a =3D start; a < end; a++) { int insn_buff_sz =3D 0; =20 - instr =3D (u8 *)&a->instr_offset + a->instr_offset; + /* + * In case of nested ALTERNATIVE()s the outer alternative might + * add more padding. To ensure consistent patching find the max + * padding for all alt_instr entries for this site (nested + * alternatives result in consecutive entries). + */ + for (b =3D a+1; b < end && instr_va(b) =3D=3D instr_va(a); b++) { + u8 len =3D max(a->instrlen, b->instrlen); + a->instrlen =3D b->instrlen =3D len; + } + + instr =3D instr_va(a); replacement =3D (u8 *)&a->repl_offset + a->repl_offset; BUG_ON(a->instrlen > sizeof(insn_buff)); BUG_ON(a->cpuid >=3D (NCAPINTS + NBUGINTS) * 32); diff --git a/tools/objtool/arch/x86/special.c b/tools/objtool/arch/x86/spec= ial.c index 4134d27c696b..4ea0f9815fda 100644 --- a/tools/objtool/arch/x86/special.c +++ b/tools/objtool/arch/x86/special.c @@ -9,6 +9,29 @@ =20 void arch_handle_alternative(unsigned short feature, struct special_alt *a= lt) { + static struct special_alt *group, *prev; + + /* + * Recompute orig_len for nested ALTERNATIVE()s. + */ + if (group && group->orig_sec =3D=3D alt->orig_sec && + group->orig_off =3D=3D alt->orig_off) { + + struct special_alt *iter =3D group; + for (;;) { + unsigned int len =3D max(iter->orig_len, alt->orig_len); + iter->orig_len =3D alt->orig_len =3D len; + + if (iter =3D=3D prev) + break; + + iter =3D list_next_entry(iter, list); + } + + } else group =3D alt; + + prev =3D alt; + switch (feature) { case X86_FEATURE_SMAP: /* diff --git a/tools/objtool/special.c b/tools/objtool/special.c index 91b1950f5bd8..097a69db82a0 100644 --- a/tools/objtool/special.c +++ b/tools/objtool/special.c @@ -84,6 +84,14 @@ static int get_alt_entry(struct elf *elf, const struct s= pecial_entry *entry, entry->new_len); } =20 + orig_reloc =3D find_reloc_by_dest(elf, sec, offset + entry->orig); + if (!orig_reloc) { + WARN_FUNC("can't find orig reloc", sec, offset + entry->orig); + return -1; + } + + reloc_to_sec_off(orig_reloc, &alt->orig_sec, &alt->orig_off); + if (entry->feature) { unsigned short feature; =20 @@ -94,14 +102,6 @@ static int get_alt_entry(struct elf *elf, const struct = special_entry *entry, arch_handle_alternative(feature, alt); } =20 - orig_reloc =3D find_reloc_by_dest(elf, sec, offset + entry->orig); - if (!orig_reloc) { - WARN_FUNC("can't find orig reloc", sec, offset + entry->orig); - return -1; - } - - reloc_to_sec_off(orig_reloc, &alt->orig_sec, &alt->orig_off); - if (!entry->group || alt->new_len) { new_reloc =3D find_reloc_by_dest(elf, sec, offset + entry->new); if (!new_reloc) { --=20 2.43.0 From nobody Fri Feb 13 06:06:27 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3248D158D90 for ; Fri, 31 May 2024 12:35:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717158920; cv=none; b=ZDtcApOlvebUluBQmlliJFMuV+38XCqkJHF/7r2oSYfHUW+l94xxlPFO4IyJBsSyHKW1Cvg7NQOlPuS69lD+C3qDrNliMLTZ6Fkmt0sY8yNk884EGf8/ABGiY2GkBK6MeT2CQM3/EIJEUWH7Y6EAvbYlvYwbdfmJ7P6L5GiRNnQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717158920; c=relaxed/simple; bh=wqYNbMnNKnYTuOhIAZEDLwWTDb3cK6kIfqvEGugdDBg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mvH0/q3DLSnzB2bU5FW3lBcr2IVzsUBv8zNtpKt12rKgW2zXIxJsVPtQJfQmeuml/CRgivKDJycr57ntvTqjDSP3MU0FTP7VEmrXwDPPBvNFh4Z4AwoEIGZINgBtFx+8NQy6SXfWe1YlZ2sm4blvsvr8ngQdC3hnnd0zei/3R3g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jWZoEgU4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jWZoEgU4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02479C32781; Fri, 31 May 2024 12:35:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717158919; bh=wqYNbMnNKnYTuOhIAZEDLwWTDb3cK6kIfqvEGugdDBg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jWZoEgU4Xc0WVJuCLJ+6Hs6q4NpYSC10UkRGFzsiFumy7spbDFeCWjkrRybOA69Lx t12Pdcof10CDEDBY9JSOa5lHSkekKFVgYUQghHE/RfsQw20VQhHdH144HsewFyBbyP OkT73cy7BKoBZ/E4EteUrNzUfIls6+VXPggxKvXN7sxcU89EFD9aB6d4jrPjw32UjR nud6bhkWf6Y+jXnQAYEsex7N6da3frywY4+VokVYqNxiquO5QJpq4kydPw0r1yusU4 wAV4NA9p12tlnhrwvFNBIDCRINm1U+dc6wjw4ixHxk7XeT2t2TigXC29W1bbKcvLxl 21GUYz/sFR4Tg== From: Borislav Petkov To: X86 ML Cc: LKML , "Borislav Petkov (AMD)" Subject: [PATCH 03/14] x86/alternative: Convert alternative() Date: Fri, 31 May 2024 14:35:00 +0200 Message-ID: <20240531123512.21427-4-bp@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240531123512.21427-1-bp@kernel.org> References: <20240531123512.21427-1-bp@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Borislav Petkov (AMD)" Split conversion deliberately into minimal pieces to ease bisection because debugging alternatives is a nightmare. Signed-off-by: Borislav Petkov (AMD) --- arch/x86/include/asm/alternative.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alte= rnative.h index 8554c2c339ff..c622ec7c4462 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -316,14 +316,11 @@ static inline int alternatives_text_reserved(void *st= art, void *end) * without volatile and memory clobber. */ #define alternative(oldinstr, newinstr, ft_flags) \ - asm_inline volatile (ALTERNATIVE(oldinstr, newinstr, ft_flags) : : : "mem= ory") + asm_inline volatile(N_ALTERNATIVE(oldinstr, newinstr, ft_flags) : : : "me= mory") =20 #define alternative_2(oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2= ) \ asm_inline volatile(ALTERNATIVE_2(oldinstr, newinstr1, ft_flags1, newinst= r2, ft_flags2) ::: "memory") =20 -#define n_alternative(oldinstr, newinstr, ft_flags) \ - asm_inline volatile (N_ALTERNATIVE(oldinstr, newinstr, ft_flags) : : : "m= emory") - #define n_alternative_2(oldinstr, newinstr1, ft_flags1, newinstr2, ft_flag= s2) \ asm_inline volatile(N_ALTERNATIVE_2(oldinstr, newinstr1, ft_flags1, newin= str2, ft_flags2) ::: "memory") =20 --=20 2.43.0 From nobody Fri Feb 13 06:06:27 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 815D915884D for ; Fri, 31 May 2024 12:35:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717158921; cv=none; b=mVuyZGfk0RJI0IA3CHoWjo0F7klkGtfbSjKFmsCmN7u/EmIIIHHZAgO54NhbnHBtmDBNkd77JHK+RychFD2e4ph+Dj6Hp6/Q5X/cxRUxgMOZ2dcRKbNe3lWBKwn2W5wPm/8i6TqFhWsqfCqsalbZ6HD0FWwSFeef3IGpDGY0YeI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717158921; c=relaxed/simple; bh=OZwBq4zhE7sZbzL9CtiglYHCMatlBRlDf8o+veIibKs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aWpPqUH3Nqi1zRaKIQF7ui5tzPpJCJVxfNHKQOZqae2wXVb0EyTHrHw8nduz7X6r4vpKoNd4s6eP9j0EDk3zzBQPegeaTmJNbVc0+7W9jBIFBcl1RgWdIrIWU6krQH6OGT/dCUGNF0DRwGxc2RQJ+CPjjm51osqB/911OixFwjw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aMIg2FBG; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aMIg2FBG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41976C4AF07; Fri, 31 May 2024 12:35:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717158921; bh=OZwBq4zhE7sZbzL9CtiglYHCMatlBRlDf8o+veIibKs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aMIg2FBGQtew7H+4WbkjVChd1F9CQ3bw7TkT9hA1ddo3nml6Tsr5zspAvpS6Hh6DF hfoVmOE4Ia/SGGcxF4Xru9MqifCVnBlspdARggAnXiyiTzQ0+J8uEi6GN2H7VbMUT/ O75qoNcjFpdaRDpdMVZzV564wRZgi4YmDGh4oiYME68yvz7GVTaV3KGCN9GLz6Kj+q /+LdsrJets0FAODfcHGu5p/GNc7h2weHGYwWNyccJDxRcyjhmdgNLSSsyRSoIask1m sAJsDtJwu2ZV1cJRcDAGQRgTNcAf5c6um0Me6egqNw6K4l7Cb1YADLUv3SD6fvwqie vERkV2LmH5RKQ== From: Borislav Petkov To: X86 ML Cc: LKML , "Borislav Petkov (AMD)" Subject: [PATCH 04/14] x86/alternative: Convert alternative_2() Date: Fri, 31 May 2024 14:35:01 +0200 Message-ID: <20240531123512.21427-5-bp@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240531123512.21427-1-bp@kernel.org> References: <20240531123512.21427-1-bp@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Borislav Petkov (AMD)" Signed-off-by: Borislav Petkov (AMD) --- arch/x86/include/asm/alternative.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alte= rnative.h index c622ec7c4462..1dd445c6e2e1 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -319,9 +319,6 @@ static inline int alternatives_text_reserved(void *star= t, void *end) asm_inline volatile(N_ALTERNATIVE(oldinstr, newinstr, ft_flags) : : : "me= mory") =20 #define alternative_2(oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2= ) \ - asm_inline volatile(ALTERNATIVE_2(oldinstr, newinstr1, ft_flags1, newinst= r2, ft_flags2) ::: "memory") - -#define n_alternative_2(oldinstr, newinstr1, ft_flags1, newinstr2, ft_flag= s2) \ asm_inline volatile(N_ALTERNATIVE_2(oldinstr, newinstr1, ft_flags1, newin= str2, ft_flags2) ::: "memory") =20 /* --=20 2.43.0 From nobody Fri Feb 13 06:06:27 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC903158DD0 for ; Fri, 31 May 2024 12:35:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717158922; cv=none; b=i+RqQjgfcjelHpbtUOwH2E4/OLrVqtbJ3Hl6EA8iJVRK6rdalhIVAf0Mg49D19X5EV5H8vHlRa5yjg8Osv3txHG+ToHtUGRAyRtC17FyLB1dnaxV5LrZIuDWWXfcedk4gu4gW0fUrFjNTp1UW7IPDz729zpWCHtEvYO6l7JN7Do= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717158922; c=relaxed/simple; bh=cPNrNecxxrCgayY/BH4V35moVx5yb8yY03jdA/pam2c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WtFadKbiFMUTWPy5tutUZB0ATJ2RaRyAIj+ACEhwro0D390n9rz2oInLWoL3VHhE6Hda9NSVoAydLWTypETtVbxml7QfbkSJ5bb/A6O4nj/G8k1X3WJSl1P0jpTCx9l/QkdAc9vsF4qcO08TtTOoXBtBZYpbeexjfuSMuOaBfZc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=L83qQ9Yt; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="L83qQ9Yt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 81549C32781; Fri, 31 May 2024 12:35:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717158922; bh=cPNrNecxxrCgayY/BH4V35moVx5yb8yY03jdA/pam2c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L83qQ9YtDW9iL923oeMqVEjdUdofCz6Ge8O5JRm3tHTls5mIcbW2dmsReaGntWtLl BRGyCId/d/qi8pHT18CNmXI9N3hKurKf7xgBuA4l+69RGAuZVSe7IseS6D8Q+PFGuB EDd2SiKzA8a+UbCKTyLNPk7x4mvZtzNdF1V83TSo2iBKAfpYrLYXDrX6JLG9Oa4mvv 2N/6/bcYAw/8zv6UozON/42gp+D2zajxfSl02wAtCiNyy51CDCod2KiH9z95mKumhf CiC9oeOiwSTjz+tqdo4P3FVQH+PNyOOBrhufmNdVQaOI4akeS9zFF9dVbu+MvwkHRF mLRtJzPPskmEA== From: Borislav Petkov To: X86 ML Cc: LKML , "Borislav Petkov (AMD)" Subject: [PATCH 05/14] x86/alternative: Convert alternative_input() Date: Fri, 31 May 2024 14:35:02 +0200 Message-ID: <20240531123512.21427-6-bp@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240531123512.21427-1-bp@kernel.org> References: <20240531123512.21427-1-bp@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Borislav Petkov (AMD)" Signed-off-by: Borislav Petkov (AMD) --- arch/x86/include/asm/alternative.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alte= rnative.h index 1dd445c6e2e1..7f5f26fc42a9 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -330,7 +330,7 @@ static inline int alternatives_text_reserved(void *star= t, void *end) * Leaving an unused argument 0 to keep API compatibility. */ #define alternative_input(oldinstr, newinstr, ft_flags, input...) \ - asm_inline volatile (ALTERNATIVE(oldinstr, newinstr, ft_flags) \ + asm_inline volatile(N_ALTERNATIVE(oldinstr, newinstr, ft_flags) \ : : "i" (0), ## input) =20 /* Like alternative_input, but with a single output argument */ @@ -348,10 +348,6 @@ static inline int alternatives_text_reserved(void *sta= rt, void *end) asm_inline volatile (ALTERNATIVE("call %c[old]", "call %c[new]", ft_flags= ) \ : output : [old] "i" (oldfunc), [new] "i" (newfunc), ## input) =20 -#define n_alternative_input(oldinstr, newinstr, ft_flags, input...) \ - asm_inline volatile (N_ALTERNATIVE(oldinstr, newinstr, ft_flags) \ - : : "i" (0), ## input) - #define n_alternative_call(oldfunc, newfunc, ft_flags, output, input...) \ asm_inline volatile (N_ALTERNATIVE("call %P[old]", "call %P[new]", ft_fla= gs) \ : output : [old] "i" (oldfunc), [new] "i" (newfunc), ## input) --=20 2.43.0 From nobody Fri Feb 13 06:06:27 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 03EC815B96C for ; Fri, 31 May 2024 12:35:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717158925; cv=none; b=two4HPPXkgzUCiTB7E6zYuLgi2MItmdY5JZmDQ9uk1FLGFxyPgxV8qGkrTMn+3+7XjgElF5yeJfK5IfNwL9N09E451j8osdyD4TtqaidShZRlK2j11lrkOkap/vLCy3GrfYWuXmRjb71m7UnfdX3tIkAfS2u5BY6Zb5gVxbvxK0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717158925; c=relaxed/simple; bh=dN5HiwWgdZsCjkAa5Gu71vLMtjXHrncFvZfcWHAJ8xI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IfY/uUDaEtqj6LAlctrv9Eaa/+Hj9C2J8bxPLdXiK+NfiLF25DVHYR0k9Q/rJv1iMih+aV5QwlAYJSsHmGQ99hfRqoPziwhWrPhZNzqUHm4ktuFfFSlovC38ouB/ZXz2owmfQtUXMVVy5hKlYthtJHHHrmVwPaZheVtan9pfSWM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ac6XCjqX; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ac6XCjqX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C266CC116B1; Fri, 31 May 2024 12:35:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717158923; bh=dN5HiwWgdZsCjkAa5Gu71vLMtjXHrncFvZfcWHAJ8xI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ac6XCjqXy6vpdVp8dQaboG/+NmqFCXFQKzFnyIU3ScL046HCJ4PsyeTBllR4AGei1 HV6U/tPHWY9IXtXBTJasqbT62LeB/ugX1VQ5ovfxKHh0Pe24xDfz7LdzcMFEGYJOGq BeYbeaL0GNPuE/FpzhmxwlhV0jpnbOaA36pqqt4gasc0T+iGtYT4wYcTxZ6/PGSRdS WlO2Gn0QuKqwETXzMVGlIXRxJF6csiT0kx9xAiQaPPHlXMyYxP8LxH5VzC+unUPz3M BtVRgAuUDK/QJiZoOM49PTy9Txil5wqSpq5fctUFX5k8wvRpn+ogjtOiHyp3ZMls/x V5pUopQugPFUg== From: Borislav Petkov To: X86 ML Cc: LKML , "Borislav Petkov (AMD)" Subject: [PATCH 06/14] x86/alternative: Convert alternative_io() Date: Fri, 31 May 2024 14:35:03 +0200 Message-ID: <20240531123512.21427-7-bp@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240531123512.21427-1-bp@kernel.org> References: <20240531123512.21427-1-bp@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Borislav Petkov (AMD)" Signed-off-by: Borislav Petkov (AMD) --- arch/x86/include/asm/alternative.h | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alte= rnative.h index 7f5f26fc42a9..8a0a6ba4b741 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -335,14 +335,9 @@ static inline int alternatives_text_reserved(void *sta= rt, void *end) =20 /* Like alternative_input, but with a single output argument */ #define alternative_io(oldinstr, newinstr, ft_flags, output, input...) \ - asm_inline volatile (ALTERNATIVE(oldinstr, newinstr, ft_flags) \ + asm_inline volatile(N_ALTERNATIVE(oldinstr, newinstr, ft_flags) \ : output : "i" (0), ## input) =20 -#define n_alternative_io(oldinstr, newinstr, ft_flags, output, input...) \ - asm_inline volatile (N_ALTERNATIVE(oldinstr, newinstr, ft_flags) \ - : output : "i" (0), ## input) - - /* Like alternative_io, but for replacing a direct call with another one. = */ #define alternative_call(oldfunc, newfunc, ft_flags, output, input...) \ asm_inline volatile (ALTERNATIVE("call %c[old]", "call %c[new]", ft_flags= ) \ --=20 2.43.0 From nobody Fri Feb 13 06:06:27 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3F5C215B978 for ; Fri, 31 May 2024 12:35:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717158925; cv=none; b=O/+sngNK6l4QAXSUjia2D46+tNycRjrCFZWjqwoJ0dBSrk1OdfyjAz343k7y4gx41g36utBDnHdP6IBwx4VlL8IaxYUAKBlf0fM4+Uk+xaaM0M46pTNNhHftGgXwncoRgv5BFBHvGPZ85xLXVySF49+ZA21yCDAnQhN/I3tnCX4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717158925; c=relaxed/simple; bh=j0mGso8kNgtVmg3sLyotcKOfUTQN9/QvAP75p19vlTg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AQK3suHklcj4S6h9vud7bbpcalxmVwAaRrhpjv8bBi62xfZTy1nx3cdxzcAuRKzLC7k/QTABYaKAjk6kOFAK0JWFus/pcjMENdYgE9Q8QfhkfPIxNKyY/PYO78z97ntjDmuL68jVMMYXYwoS1HO3MJhqOuzfbGdBbmbN8tsfqJM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eM2ozbUv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="eM2ozbUv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0D3EEC32789; Fri, 31 May 2024 12:35:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717158924; bh=j0mGso8kNgtVmg3sLyotcKOfUTQN9/QvAP75p19vlTg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eM2ozbUvVXe39GTTF8OpF6nwnO+Dl7pzaar+wMEacViymfI/QXVJh8AYvs07tsgsM 8l9mFzbF2nBKCKGs6YaPTjAarPyZY4IdJg/SUlZDyqZoafkNjLiMG0evFxWwaZCvE9 GT0ObNnWZZrsb9+UGbKw8BTA7ZQMayQoWM7GFkPyDsVYuJL4qsr1GOwl06gFAE6rQI aaqiJBKrO2Cwo/CHC2ysDMKq6IPykgQTvCNIsLLhyxg7r3C/JCjHyGY5lR7ItxNyyd vTAJSJi+G9YiGVFmU+L3qMhhYr/DrZ4M+quL7fU2opVjFb0vs8zpfZu6fBxhaP+nUd 6Q8M5CMRyaJQA== From: Borislav Petkov To: X86 ML Cc: LKML , "Borislav Petkov (AMD)" Subject: [PATCH 07/14] x86/alternative: Convert alternative_call() Date: Fri, 31 May 2024 14:35:04 +0200 Message-ID: <20240531123512.21427-8-bp@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240531123512.21427-1-bp@kernel.org> References: <20240531123512.21427-1-bp@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Borislav Petkov (AMD)" Signed-off-by: Borislav Petkov (AMD) --- arch/x86/include/asm/alternative.h | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alte= rnative.h index 8a0a6ba4b741..bc696c60848d 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -340,11 +340,7 @@ static inline int alternatives_text_reserved(void *sta= rt, void *end) =20 /* Like alternative_io, but for replacing a direct call with another one. = */ #define alternative_call(oldfunc, newfunc, ft_flags, output, input...) \ - asm_inline volatile (ALTERNATIVE("call %c[old]", "call %c[new]", ft_flags= ) \ - : output : [old] "i" (oldfunc), [new] "i" (newfunc), ## input) - -#define n_alternative_call(oldfunc, newfunc, ft_flags, output, input...) \ - asm_inline volatile (N_ALTERNATIVE("call %P[old]", "call %P[new]", ft_fla= gs) \ + asm_inline volatile(N_ALTERNATIVE("call %P[old]", "call %P[new]", ft_flag= s) \ : output : [old] "i" (oldfunc), [new] "i" (newfunc), ## input) =20 /* --=20 2.43.0 From nobody Fri Feb 13 06:06:27 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 484DC161B4D for ; Fri, 31 May 2024 12:35:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717158926; cv=none; b=SiGOuGdPBQEAGY9ooZF+UoxcgrNHJfu4hE1bZGRssAkSJxkp8Wp5orImlSN/N8KhIMRN6pGVLHZk5ygvRHfD0k9f5inZeUT9IDyA/zQSKqnDoHVuaGz+hMOJtpjZNmftd9XMRo/uRFcpgBpiJCc/rjiyLn2pdmcUYgucJvTKVsM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717158926; c=relaxed/simple; bh=g+G19NKQbd6Xtqc8HQIhzpIDmFN7DdYjK8JTK7amgwM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EpXyP/QZN8c6LhdGBUxXZimOxP07z/hcbinyZtjc6aIGtfdcKb7lK/ZVb8ixCh9WEG1GjGhh7RjAx4HlIqNOfRcOx77YCX1Wh+3bCB5A/DfL22KlmMlPZP+JM1tJLfRBS4yZcKQXRAeA03zajcKfQLhNHZ6JHicsPl9pmz43H0I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iUAMAFaT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iUAMAFaT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C0A0C32786; Fri, 31 May 2024 12:35:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717158926; bh=g+G19NKQbd6Xtqc8HQIhzpIDmFN7DdYjK8JTK7amgwM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iUAMAFaT69xFtXeJ2GAUZn/DDtnT/opTJjnFLesIch99rPRQ0d5IMRLf6AmQ1ALXk G367ehtdFqXYEc5zRDTjANbnxHSMKwgaPdQGlWJLIboRuYHFkROtTPYquGUAqgD4PW H7gOk/Jcr01Xe7cIh1XTCHEvexiRWwuy0cqLiMiUaH5RPzlXvMITQj/j96ppjQrUxI sjUnAC7nQlHhzZBOJPpu/qe5Co2cxCfZouCvzDOozy31u9AqxNlcPetW3VRtxYZVq/ ovK0yEpYe0w+M/lzMQr5avxBQMVmHtKKlM98Tx76z9/2kMym6i9xD24ejF6/Bbma2D mOHdn7X7zMnQg== From: Borislav Petkov To: X86 ML Cc: LKML , "Borislav Petkov (AMD)" Subject: [PATCH 08/14] x86/alternative: Convert alternative_call_2() Date: Fri, 31 May 2024 14:35:05 +0200 Message-ID: <20240531123512.21427-9-bp@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240531123512.21427-1-bp@kernel.org> References: <20240531123512.21427-1-bp@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Borislav Petkov (AMD)" Signed-off-by: Borislav Petkov (AMD) --- arch/x86/include/asm/alternative.h | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alte= rnative.h index bc696c60848d..bad1558d6382 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -349,23 +349,14 @@ static inline int alternatives_text_reserved(void *st= art, void *end) * Otherwise, if CPU has feature1, function1 is used. * Otherwise, old function is used. */ -#define alternative_call_2(oldfunc, newfunc1, ft_flags1, newfunc2, ft_flag= s2, \ - output, input...) \ - asm_inline volatile (ALTERNATIVE_2("call %c[old]", "call %c[new1]", ft_fl= ags1, \ - "call %c[new2]", ft_flags2) \ - : output, ASM_CALL_CONSTRAINT \ - : [old] "i" (oldfunc), [new1] "i" (newfunc1), \ +#define alternative_call_2(oldfunc, newfunc1, ft_flags1, newfunc2, ft_flag= s2, \ + output, input...) \ + asm_inline volatile(N_ALTERNATIVE_2("call %P[old]", "call %P[new1]", ft_f= lags1, \ + "call %P[new2]", ft_flags2) \ + : output, ASM_CALL_CONSTRAINT \ + : [old] "i" (oldfunc), [new1] "i" (newfunc1), \ [new2] "i" (newfunc2), ## input) =20 -#define n_alternative_call_2(oldfunc, newfunc1, ft_flags1, newfunc2, ft_fl= ags2, \ - output, input...) \ - asm_inline volatile (N_ALTERNATIVE_2("call %P[old]", "call %P[new1]", ft_= flags1,\ - "call %P[new2]", ft_flags2) \ - : output, ASM_CALL_CONSTRAINT \ - : [old] "i" (oldfunc), [new1] "i" (newfunc1), \ - [new2] "i" (newfunc2), ## input) - - /* * use this macro(s) if you need more than one output parameter * in alternative_io --=20 2.43.0 From nobody Fri Feb 13 06:06:27 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8102A16F282 for ; Fri, 31 May 2024 12:35:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717158927; cv=none; b=myPJ5Gc3PlUQqAWbCS+iX8hoiXpKePJ3G+4q8UW9Hc0ZuNX31NwvP5Gk5itjREe/rXC6kou5NNJB8g8+oCNAQ9QKnln7OiE1sGfmj7KqXWT8JX3UygGWuZOFyFzp0xNj00VJvSqbAH0/pqd4nLGrycEkOQKSGcFXYBtMNgMyS5I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717158927; c=relaxed/simple; bh=oaM4gPS6c2Nwk34PW367bO82k88VoCS8rWqPUvkNmV8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q1rZzDKg712gTZ0oqMxEuOWPTwJURbWZl1Sx9OkSZagsq1cocGzrzqnDS7Hsrvun80JKVgkhCDI3KndAykRWj4VOpkcZ2egHMijmT8WJN7xl500sP2BDPyk/bcKl0IA4l+xEKYqLna+u3re3aIXcm5hcpgu3nVvvrqPoOWEBE5k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=g7ZhDjsE; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="g7ZhDjsE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B2F8C116B1; Fri, 31 May 2024 12:35:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717158927; bh=oaM4gPS6c2Nwk34PW367bO82k88VoCS8rWqPUvkNmV8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g7ZhDjsE0FvoznvJBgINAFKkO67JXsg0YiHRNBb2NKOuTRD2425e1wfiLO+hQUJyu 3HKNwX2UQM0Fghfvu+AA7vUXPC0TmK2QRtnyo3+Mpb2OOWhzJwVSzmT6l68gXfS7TO HxBkKNcwK/OVzrnX6LStI8hQTp8a5pjI+OXiD5WJ2T7f7yzJRoAfaGqBfNKjoA13j/ 1WTQYgy9q28C69mZFBMCdA10bVFJPht2Y8wKd9N1posNezDsvxQGFC23l0QPUx4Y56 vuJt2YIFJENUjQbQ81l40ppaau9wB9L0Vkrqu7NTPVxV7NqJvRV29sU6RJbLwt2mmJ SnBOqyPKCknGA== From: Borislav Petkov To: X86 ML Cc: LKML , "Borislav Petkov (AMD)" Subject: [PATCH 09/14] x86/alternative: Convert ALTERNATIVE_TERNARY() Date: Fri, 31 May 2024 14:35:06 +0200 Message-ID: <20240531123512.21427-10-bp@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240531123512.21427-1-bp@kernel.org> References: <20240531123512.21427-1-bp@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Borislav Petkov (AMD)" The C macro. Signed-off-by: Borislav Petkov (AMD) --- arch/x86/include/asm/alternative.h | 6 ------ 1 file changed, 6 deletions(-) diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alte= rnative.h index bad1558d6382..73ee18705ef1 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -274,15 +274,9 @@ static inline int alternatives_text_reserved(void *sta= rt, void *end) =20 /* If @feature is set, patch in @newinstr_yes, otherwise @newinstr_no. */ #define ALTERNATIVE_TERNARY(oldinstr, ft_flags, newinstr_yes, newinstr_no)= \ - ALTERNATIVE_2(oldinstr, newinstr_no, X86_FEATURE_ALWAYS, \ - newinstr_yes, ft_flags) - -/* If @feature is set, patch in @newinstr_yes, otherwise @newinstr_no. */ -#define N_ALTERNATIVE_TERNARY(oldinstr, ft_flags, newinstr_yes, newinstr_n= o) \ N_ALTERNATIVE_2(oldinstr, newinstr_no, X86_FEATURE_ALWAYS, \ newinstr_yes, ft_flags) =20 - #define ALTERNATIVE_3(oldinsn, newinsn1, ft_flags1, newinsn2, ft_flags2, \ newinsn3, ft_flags3) \ OLDINSTR_3(oldinsn, 1, 2, 3) \ --=20 2.43.0 From nobody Fri Feb 13 06:06:27 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BE5FE1761B8 for ; Fri, 31 May 2024 12:35:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717158928; cv=none; b=UpBd8kDm5iAjrmzJcgxAggIu6LJ2FqYzB2cLobn2rCEdxS1gyBLWj/MQpNe7TaKboeQ7HUJRoVcQhn2ojhjmz0TIkLo8TSiDDltCgFDla7DO54r1g70LJUL+bGwhQbf73lKnrMEJNLZSMsnWXNrkW7tGTPxItVhMr2YyGHsrwn0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717158928; c=relaxed/simple; bh=RVWUpI+ztxW7eltxB+4LrpXND84Y22vsqge4eJbKxJY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=t0qU/qsoVTpzRQFgqGu2u69vyeoK6sEhIDAfvaXPjjZn7EILo0ivJ/j9srIJ+wdnpNVwFRO3cHIKDG9wR7AToJ9di+e0CZeiIRwTVAu+VALwtXBSfCHt5gx9z2bD2774fB0dlR6oMSxE3UU92QOK7f17cOgjqjFEoq0dgRgGQ+k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jY6J2Q65; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jY6J2Q65" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CA65BC32781; Fri, 31 May 2024 12:35:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717158928; bh=RVWUpI+ztxW7eltxB+4LrpXND84Y22vsqge4eJbKxJY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jY6J2Q65F3fsacyYB4He5iDuCWRQZ+MMv00KcUN/h+x/JzPVLcJeMKfENjmIdb2Dj F9D1dH+wBzGH3ESctPFdLwcWi/1lxaJtKNqVjoxSJ5/e+J8cZ+XzgUPGY029buSfTw JLoRYNllgilzIP34f+qQ3Tueym7otnHmOBSnHmaxkBr3LqDCZsea86uPA8tMTYKMXY UkioHa5eCpM3WK6njjXOfGMbEyr+TqEVDdhmZ3/duGhn2VNmZj87FfPCP4vWvWklZH kCe/FK/3QPzywsUDYtXon3tke6n+g8KZXUDcCSJf2euJIZjwWVbcsjupHNH9Oxhi5H Q46fcMdIlCekw== From: Borislav Petkov To: X86 ML Cc: LKML , "Borislav Petkov (AMD)" Subject: [PATCH 10/14] x86/alternative: Convert ALTERNATIVE_3() Date: Fri, 31 May 2024 14:35:07 +0200 Message-ID: <20240531123512.21427-11-bp@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240531123512.21427-1-bp@kernel.org> References: <20240531123512.21427-1-bp@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Borislav Petkov (AMD)" Fixup label numbering too as the new macros have new label numbers. Signed-off-by: Borislav Petkov (AMD) --- arch/x86/include/asm/alternative.h | 24 ++++-------------------- arch/x86/kernel/fpu/xstate.h | 4 ++-- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alte= rnative.h index 73ee18705ef1..0df99855e003 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -277,26 +277,10 @@ static inline int alternatives_text_reserved(void *st= art, void *end) N_ALTERNATIVE_2(oldinstr, newinstr_no, X86_FEATURE_ALWAYS, \ newinstr_yes, ft_flags) =20 -#define ALTERNATIVE_3(oldinsn, newinsn1, ft_flags1, newinsn2, ft_flags2, \ - newinsn3, ft_flags3) \ - OLDINSTR_3(oldinsn, 1, 2, 3) \ - ".pushsection .altinstructions,\"a\"\n" \ - ALTINSTR_ENTRY(ft_flags1, 1) \ - ALTINSTR_ENTRY(ft_flags2, 2) \ - ALTINSTR_ENTRY(ft_flags3, 3) \ - ".popsection\n" \ - ".pushsection .altinstr_replacement, \"ax\"\n" \ - ALTINSTR_REPLACEMENT(newinsn1, 1) \ - ALTINSTR_REPLACEMENT(newinsn2, 2) \ - ALTINSTR_REPLACEMENT(newinsn3, 3) \ - ".popsection\n" - - -#define N_ALTERNATIVE_3(oldinst, newinst1, flag1, newinst2, flag2, \ - newinst3, flag3) \ - N_ALTERNATIVE(N_ALTERNATIVE_2(oldinst, newinst1, flag1, newinst2, flag2),= \ - newinst3, flag3) - +#define ALTERNATIVE_3(oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2= , \ + newinstr3, ft_flags3) \ + N_ALTERNATIVE(N_ALTERNATIVE_2(oldinstr, newinstr1, ft_flags1, newinstr2, = ft_flags2), \ + newinstr3, ft_flags3) /* * Alternative instructions for different CPU types or capabilities. * diff --git a/arch/x86/kernel/fpu/xstate.h b/arch/x86/kernel/fpu/xstate.h index 05df04f39628..4fe8501efc6c 100644 --- a/arch/x86/kernel/fpu/xstate.h +++ b/arch/x86/kernel/fpu/xstate.h @@ -108,7 +108,7 @@ static inline u64 xfeatures_mask_independent(void) * * We use XSAVE as a fallback. * - * The 661 label is defined in the ALTERNATIVE* macros as the address of t= he + * The 771 label is defined in the ALTERNATIVE* macros as the address of t= he * original instruction which gets replaced. We need to use it here as the * address of the instruction where we might get an exception at. */ @@ -120,7 +120,7 @@ static inline u64 xfeatures_mask_independent(void) "\n" \ "xor %[err], %[err]\n" \ "3:\n" \ - _ASM_EXTABLE_TYPE_REG(661b, 3b, EX_TYPE_EFAULT_REG, %[err]) \ + _ASM_EXTABLE_TYPE_REG(771b, 3b, EX_TYPE_EFAULT_REG, %[err]) \ : [err] "=3Dr" (err) \ : "D" (st), "m" (*st), "a" (lmask), "d" (hmask) \ : "memory") --=20 2.43.0 From nobody Fri Feb 13 06:06:27 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0837A17625F for ; Fri, 31 May 2024 12:35:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717158930; cv=none; b=F4Z3mstf4Ln+Y2sNH7pq6ToX1iQdQb1sgv7XMU7dLYT522wwZduiBbHkX6CbT/USrx89uD4OXxH7NyDbD7uxZiboH6L440BcPZH45Xpu8ERDkZ21FltJJlbi7Z3EKRclu6/Mp0ULEQ5GUGpelR/Q4JfSJSnS+/bHN4Xgj2RjQ6g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717158930; c=relaxed/simple; bh=fX9zdFndNsZ6Oozx6KKrax/RedQUUs+v/vZeMTOCjCg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ON+RAYnvD7iTp2eEJT0/kgkRVG4MljzPV//AdODb2qzXVzRH+DbfP0yUuvT9SWNp1dKnF5UMByL3qYe8gZUHRcsv1nl8bWJZRsfFOPhFPitF/e/UQqkBGgsaNbJMioTMkm66eKn8q2P1C0GyBn5sFEmGgcrsoIfMIkgZKiNhob8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=E4UYdC5A; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="E4UYdC5A" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 158A2C32781; Fri, 31 May 2024 12:35:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717158929; bh=fX9zdFndNsZ6Oozx6KKrax/RedQUUs+v/vZeMTOCjCg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E4UYdC5AAMlep3YEpHUIQzMelPybpqMLrdL6Ux1LTCiQFYlcJr40cZJ43JcrIZJkZ VE4BxD7MpWswtCIk8UC+jyzM5FAF4uwjpheHf9ndOCKmV0KCW0nb9zG2j69D0Jfh1c kmJk1tN1qZymULInPejRWQnX4AblcoNxT/mq+wmLW46GRGbwg96smBV2OVGr2LRZXO FzkIO33nGKcQE41nD/RrUkfObkL2TK/yEKorNDSQgFop7MCPA16kbM/aBXJYAx0ma4 r32Tjz79pr0uPc6r2mu69SebjghIAspBEUBW7p1vnjdV0BTAulxJYgSGKA+T+Vw8Fm VN8cn7I+jSiRg== From: Borislav Petkov To: X86 ML Cc: LKML , "Borislav Petkov (AMD)" Subject: [PATCH 11/14] x86/alternative: Convert the asm ALTERNATIVE() macro Date: Fri, 31 May 2024 14:35:08 +0200 Message-ID: <20240531123512.21427-12-bp@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240531123512.21427-1-bp@kernel.org> References: <20240531123512.21427-1-bp@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Borislav Petkov (AMD)" Signed-off-by: Borislav Petkov (AMD) --- arch/x86/include/asm/alternative.h | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alte= rnative.h index 0df99855e003..4b17267f3f2f 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -413,24 +413,6 @@ void nop_func(void); * @newinstr. ".skip" directive takes care of proper instruction padding * in case @newinstr is longer than @oldinstr. */ -.macro ALTERNATIVE oldinstr, newinstr, ft_flags -140: - \oldinstr -141: - .skip -(((144f-143f)-(141b-140b)) > 0) * ((144f-143f)-(141b-140b)),0x90 -142: - - .pushsection .altinstructions,"a" - altinstr_entry 140b,143f,\ft_flags,142b-140b,144f-143f - .popsection - - .pushsection .altinstr_replacement,"ax" -143: - \newinstr -144: - .popsection -.endm - #define __N_ALTERNATIVE(oldinst, newinst, flag) \ 740: \ oldinst ; \ @@ -446,12 +428,10 @@ void nop_func(void); 744: \ .popsection ; =20 - -.macro N_ALTERNATIVE oldinstr, newinstr, ft_flags +.macro ALTERNATIVE oldinstr, newinstr, ft_flags __N_ALTERNATIVE(\oldinstr, \newinstr, \ft_flags) .endm =20 - #define old_len 141b-140b #define new_len1 144f-143f #define new_len2 145f-144f --=20 2.43.0 From nobody Fri Feb 13 06:06:27 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 50C3C178360 for ; Fri, 31 May 2024 12:35:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717158931; cv=none; b=G3MKjCMSxyKd7Y/Wc/JzIfscwBE6IUJb3iBNYoxnt2vw/1O9GtgkyxZ4ww280dRdNYufsHgR36OjlGww6Y75TH9z4l9eRGb3qwSs5c3mqc6qwHdBmDZa8bfsiCRWsZ5EjuVVZ8gWrsPSyc/Z+69VOZE9gTKgjtVD1SBBWP7kIwc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717158931; c=relaxed/simple; bh=7NxE+QUoLbZ8CDIeAmX8OcSwhoxtLVNGR18li4xQTuY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rgwhDvymtVInYH8VvlkIHACrBTOjsZhmpUaK07jOFdQ8l9Q76V+G63IeHvioQ60RLHhjQj4DutXwmS9QROAvmppolvH3jFPh+RA+cazLIb1qQrh+jmSgn/rDFvq27EFP6l7Ttgcs8A9emQiUc8q7RZzV7BvhvZxaX+oBS0mSVHQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=K4EUF29H; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="K4EUF29H" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 54FA6C116B1; Fri, 31 May 2024 12:35:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717158931; bh=7NxE+QUoLbZ8CDIeAmX8OcSwhoxtLVNGR18li4xQTuY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=K4EUF29Hs2lsZEdvfsXQK9VFUJlOvrjEGJ77A4XkRQ1kfiEIP+W9c0umx70+V7sOn hZeni+vTxTNkxDjsayxljDu9yrIeCIQ8IJvBGGFZ8nyJsC38cU0LQnI/Y1EynmlBwr c0jzrMx2QDk7e+4kucMws8BWeE/8GfqD2a72tt0uyDZkH2xMvNoWobfCgLeffv9po6 PK9s9s9Hyu8Pzw6A0p6pPPPPx/vIQ6oNoS7QV94N1EBeJ4r9OcNmFU9NiNMVB+K+sg gveEZRVIAPZ+4cIRr6gYkn3ke5Rl+WFF7mdeY2d95dl3yUlwYrrtQWiub/l1upEoWV vxGxXY+KU4KuA== From: Borislav Petkov To: X86 ML Cc: LKML , "Borislav Petkov (AMD)" Subject: [PATCH 12/14] x86/alternative: Convert the asm ALTERNATIVE_2() macro Date: Fri, 31 May 2024 14:35:09 +0200 Message-ID: <20240531123512.21427-13-bp@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240531123512.21427-1-bp@kernel.org> References: <20240531123512.21427-1-bp@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Borislav Petkov (AMD)" Signed-off-by: Borislav Petkov (AMD) --- arch/x86/include/asm/alternative.h | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alte= rnative.h index 4b17267f3f2f..82a79e17e952 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -452,28 +452,6 @@ void nop_func(void); * @feature2, it replaces @oldinstr with @feature2. */ .macro ALTERNATIVE_2 oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2 -140: - \oldinstr -141: - .skip -((alt_max_2(new_len1, new_len2) - (old_len)) > 0) * \ - (alt_max_2(new_len1, new_len2) - (old_len)),0x90 -142: - - .pushsection .altinstructions,"a" - altinstr_entry 140b,143f,\ft_flags1,142b-140b,144f-143f - altinstr_entry 140b,144f,\ft_flags2,142b-140b,145f-144f - .popsection - - .pushsection .altinstr_replacement,"ax" -143: - \newinstr1 -144: - \newinstr2 -145: - .popsection -.endm - -.macro N_ALTERNATIVE_2 oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2 __N_ALTERNATIVE(__N_ALTERNATIVE(\oldinstr, \newinstr1, \ft_flags1), \newinstr2, \ft_flags2) .endm --=20 2.43.0 From nobody Fri Feb 13 06:06:27 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9015117C7A3 for ; Fri, 31 May 2024 12:35:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717158932; cv=none; b=aWwPJvSFGYCkrvfE1YzKsZHmiYnI0m8k8Eh7hTijg1k43bklg5uBEJ9L8XghxdTHg9kNa6fb+Gz1roUvp8fubsesbQ98wcw+8RTbZ+eo3hGs/2TPYp5nYQUKxlZwB7r7FQyY9sBeKhEd8Dg/+1r1Gu9O+oFy9AklJ5rMtDoJrvQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717158932; c=relaxed/simple; bh=/qlLGNymXFpWMsOYIm3n/ty8t96hW2L/4Kjnjwv0hN4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gTC0koQdAY4IDCfyjKlKnrc5kfy0jxHfiOIk5nvGxG9HUkzS/pIj3Yr9vnEuHiPkdxFIww81A42lQX6zc4OaMfbCkNg0oXNcEoU3tkZ1mwhxFXcuMPKJyvFwdH4RMCkOvxtanMXWFRa1ggx2J0qwqQ+Y0g8d03X/498IM3I3Dmw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=b82ZdiRb; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="b82ZdiRb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9420FC32789; Fri, 31 May 2024 12:35:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717158932; bh=/qlLGNymXFpWMsOYIm3n/ty8t96hW2L/4Kjnjwv0hN4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b82ZdiRbM5pH74g0M+NV0dSfQg8bfyn+67a8MkQx03D5WjNKtcMdPdgy1rxyx7cED OUUii0bxajdVRTKeJvFiTwgvJkmNgIwvAdnUeQ6IVeVdurmG0nZaSxrPS6+fAdOaX3 PBi9mObhWXJtetbdkefrp4thbn5wlPEugOPgxPByo9D+wRCypzIphqBdp4PnUTfR0d gSjoddIQJcZlSbmlmZ/opfOlAoanhg7R5sUzR/VUMDCmzcRfYn1D4RcpjMKlHHUEIr qjeD6BMP7P9g9b010lRcjuCDvUp6JzThS4qF2LALzZLGUQ61soyO/YrkVNg7OBIHy4 kcbgYwRpLTlNw== From: Borislav Petkov To: X86 ML Cc: LKML , "Borislav Petkov (AMD)" Subject: [PATCH 13/14] x86/alternative: Convert the asm ALTERNATIVE_3() macro Date: Fri, 31 May 2024 14:35:10 +0200 Message-ID: <20240531123512.21427-14-bp@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240531123512.21427-1-bp@kernel.org> References: <20240531123512.21427-1-bp@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Borislav Petkov (AMD)" Signed-off-by: Borislav Petkov (AMD) --- arch/x86/include/asm/alternative.h | 25 ------------------------- 1 file changed, 25 deletions(-) diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alte= rnative.h index 82a79e17e952..19b574331ffd 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -457,31 +457,6 @@ void nop_func(void); .endm =20 .macro ALTERNATIVE_3 oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2,= newinstr3, ft_flags3 -140: - \oldinstr -141: - .skip -((alt_max_3(new_len1, new_len2, new_len3) - (old_len)) > 0) * \ - (alt_max_3(new_len1, new_len2, new_len3) - (old_len)),0x90 -142: - - .pushsection .altinstructions,"a" - altinstr_entry 140b,143f,\ft_flags1,142b-140b,144f-143f - altinstr_entry 140b,144f,\ft_flags2,142b-140b,145f-144f - altinstr_entry 140b,145f,\ft_flags3,142b-140b,146f-145f - .popsection - - .pushsection .altinstr_replacement,"ax" -143: - \newinstr1 -144: - \newinstr2 -145: - \newinstr3 -146: - .popsection -.endm - -.macro N_ALTERNATIVE_3 oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags= 2, newinstr3, ft_flags3 __N_ALTERNATIVE(N_ALTERNATIVE_2(\oldinstr, \newinstr1, \ft_flags1, \newin= str2, \ft_flags2), \newinstr3, \ft_flags3) .endm --=20 2.43.0 From nobody Fri Feb 13 06:06:27 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C7B931586C1 for ; Fri, 31 May 2024 12:35:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717158933; cv=none; b=m5ulBHQxktqEToraRE5g0mOWuDkFV/dHE6yEpe2GOyaEryDMzDzHxgA3Axg12N6YFjBV66mBzVPQtPMwymBgWO3hIdbcb3EUqXwRPV86yXpBaGPOSmqQeCVAiv5aToA3RD5pAPqk6fPbZ99R6ZHSU/vB2GuPGRL9vSGGTP/9EgE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717158933; c=relaxed/simple; bh=duytlqQj8aupakjXZbZuEUtL1bnOnoFgPDJUWXroXHo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qe/lSNvFMVd+P5LwyW7ZXCUS88usdwayv9zPwjTLfASuB5gpP0pqk1olwYiOSdw8vhTHOY5i3C/+aH1b9wcRBkjKv2hNMHuXUjIldO9Qx8EIwWcI/3pkm5iODYr78IWIY7lBL+rSKVB+QhDrBaqTgYWcC3RJKCW+ZyaDePsAGe4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=edYPUPMO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="edYPUPMO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D338AC32781; Fri, 31 May 2024 12:35:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717158933; bh=duytlqQj8aupakjXZbZuEUtL1bnOnoFgPDJUWXroXHo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=edYPUPMO0venmdNIjTdYf5/woZ55IhefIVOAAJzCsBHwwNG1R2E3jgkpsse+9ufBo 9SAK2Tt4s4g1v8BF6LEecK41xq+B3cP12SEvpE6d+pRwODe4pgP6AaMtVzMJ6oIcVf QXaLhY3z4ylJbUnGENZfRjk/nDknwOFj6A5LnLg1+xQzDUTP6jGcs6P7ikg5PgydbV vm3NKHvHw4k+mD56x+EB9+6jo32m/Jjgd2dWkjOdmGrm+oRtcCps8ciAKOGRSVDYYq XGRInHRk9iake0tZEoZWBkdECm3T2WO9EeO6k476S+a1TJGDqO76RvLLBPuDto9HJh Er64S9zxxooZQ== From: Borislav Petkov To: X86 ML Cc: LKML , "Borislav Petkov (AMD)" Subject: [PATCH 14/14] x86/alternative: Replace the old macros Date: Fri, 31 May 2024 14:35:11 +0200 Message-ID: <20240531123512.21427-15-bp@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240531123512.21427-1-bp@kernel.org> References: <20240531123512.21427-1-bp@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Borislav Petkov (AMD)" Now that the new macros have been gradually put in place, replace the old ones. Leave the new label numbers starting at 7xx as a hint that the new nested alternatives are being used now. Signed-off-by: Borislav Petkov (AMD) --- arch/x86/include/asm/alternative.h | 144 +++++++---------------------- arch/x86/kernel/fpu/xstate.h | 2 +- 2 files changed, 33 insertions(+), 113 deletions(-) diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alte= rnative.h index 19b574331ffd..f02867092a49 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -156,131 +156,51 @@ static inline int alternatives_text_reserved(void *s= tart, void *end) =20 #define ALT_CALL_INSTR "call BUG_func" =20 -#define b_replacement(num) "664"#num -#define e_replacement(num) "665"#num +#define alt_slen "772b-771b" +#define alt_total_slen "773b-771b" +#define alt_rlen "775f-774f" =20 -#define alt_end_marker "663" -#define alt_slen "662b-661b" -#define n_alt_slen "772b-771b" - -#define alt_total_slen alt_end_marker"b-661b" -#define n_alt_total_slen "773b-771b" - -#define alt_rlen(num) e_replacement(num)"f-"b_replacement(num)"f" -#define n_alt_rlen "775f-774f" - -#define OLDINSTR(oldinstr, num) \ - "# ALT: oldnstr\n" \ - "661:\n\t" oldinstr "\n662:\n" \ - "# ALT: padding\n" \ - ".skip -(((" alt_rlen(num) ")-(" alt_slen ")) > 0) * " \ - "((" alt_rlen(num) ")-(" alt_slen ")),0x90\n" \ - alt_end_marker ":\n" - -#define N_OLDINSTR(oldinstr) \ - "# N_ALT: oldinstr\n" \ +#define OLDINSTR(oldinstr) \ + "# ALT: oldinstr\n" \ "771:\n\t" oldinstr "\n772:\n" \ - "# N_ALT: padding\n" \ - ".skip -(((" n_alt_rlen ")-(" n_alt_slen ")) > 0) * " \ - "((" n_alt_rlen ")-(" n_alt_slen ")),0x90\n" \ + "# ALT: padding\n" \ + ".skip -(((" alt_rlen ")-(" alt_slen ")) > 0) * " \ + "((" alt_rlen ")-(" alt_slen ")),0x90\n" \ "773:\n" =20 -/* - * gas compatible max based on the idea from: - * http://graphics.stanford.edu/~seander/bithacks.html#IntegerMinOrMax - * - * The additional "-" is needed because gas uses a "true" value of -1. - */ -#define alt_max_short(a, b) "((" a ") ^ (((" a ") ^ (" b ")) & -(-((" a ")= < (" b ")))))" - -/* - * Pad the second replacement alternative with additional NOPs if it is - * additionally longer than the first replacement alternative. - */ -#define OLDINSTR_2(oldinstr, num1, num2) \ - "# ALT: oldinstr2\n" \ - "661:\n\t" oldinstr "\n662:\n" \ - "# ALT: padding2\n" \ - ".skip -((" alt_max_short(alt_rlen(num1), alt_rlen(num2)) " - (" alt_slen= ")) > 0) * " \ - "(" alt_max_short(alt_rlen(num1), alt_rlen(num2)) " - (" alt_slen ")), 0= x90\n" \ - alt_end_marker ":\n" - -#define OLDINSTR_3(oldinsn, n1, n2, n3) \ - "# ALT: oldinstr3\n" \ - "661:\n\t" oldinsn "\n662:\n" \ - "# ALT: padding3\n" \ - ".skip -((" alt_max_short(alt_max_short(alt_rlen(n1), alt_rlen(n2)), alt_= rlen(n3)) \ - " - (" alt_slen ")) > 0) * " \ - "(" alt_max_short(alt_max_short(alt_rlen(n1), alt_rlen(n2)), alt_rlen(n3= )) \ - " - (" alt_slen ")), 0x90\n" \ - alt_end_marker ":\n" - -#define ALTINSTR_ENTRY(ft_flags, num) \ - " .long 661b - .\n" /* label */ \ - " .long " b_replacement(num)"f - .\n" /* new instruction */ \ - " .4byte " __stringify(ft_flags) "\n" /* feature + flags */ \ - " .byte " alt_total_slen "\n" /* source len */ \ - " .byte " alt_rlen(num) "\n" /* replacement len */ - -#define N_ALTINSTR_ENTRY(ft_flags) \ +#define ALTINSTR_ENTRY(ft_flags) \ ".pushsection .altinstructions,\"a\"\n" \ " .long 771b - .\n" /* label */ \ " .long 774f - .\n" /* new instruction */ \ " .4byte " __stringify(ft_flags) "\n" /* feature + flags */ \ - " .byte " n_alt_total_slen "\n" /* source len */ \ - " .byte " n_alt_rlen "\n" /* replacement len */ \ + " .byte " alt_total_slen "\n" /* source len */ \ + " .byte " alt_rlen "\n" /* replacement len */ \ ".popsection\n" =20 -#define ALTINSTR_REPLACEMENT(newinstr, num) /* replacement */ \ - "# ALT: replacement " #num "\n" \ - b_replacement(num)":\n\t" newinstr "\n" e_replacement(num) ":\n" - -#define N_ALTINSTR_REPLACEMENT(newinstr) /* replacement */ \ - ".pushsection .altinstr_replacement, \"ax\"\n" \ - "# N_ALT: replacement\n" \ - "774:\n\t" newinstr "\n775:\n" \ +#define ALTINSTR_REPLACEMENT(newinstr) /* replacement */ \ + ".pushsection .altinstr_replacement, \"ax\"\n" \ + "# ALT: replacement\n" \ + "774:\n\t" newinstr "\n775:\n" \ ".popsection\n" =20 /* alternative assembly primitive: */ #define ALTERNATIVE(oldinstr, newinstr, ft_flags) \ - OLDINSTR(oldinstr, 1) \ - ".pushsection .altinstructions,\"a\"\n" \ - ALTINSTR_ENTRY(ft_flags, 1) \ - ".popsection\n" \ - ".pushsection .altinstr_replacement, \"ax\"\n" \ - ALTINSTR_REPLACEMENT(newinstr, 1) \ - ".popsection\n" - -/* Nested alternatives macro variant */ -#define N_ALTERNATIVE(oldinstr, newinstr, ft_flags) \ - N_OLDINSTR(oldinstr) \ - N_ALTINSTR_ENTRY(ft_flags) \ - N_ALTINSTR_REPLACEMENT(newinstr) + OLDINSTR(oldinstr) \ + ALTINSTR_ENTRY(ft_flags) \ + ALTINSTR_REPLACEMENT(newinstr) =20 #define ALTERNATIVE_2(oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2= ) \ - OLDINSTR_2(oldinstr, 1, 2) \ - ".pushsection .altinstructions,\"a\"\n" \ - ALTINSTR_ENTRY(ft_flags1, 1) \ - ALTINSTR_ENTRY(ft_flags2, 2) \ - ".popsection\n" \ - ".pushsection .altinstr_replacement, \"ax\"\n" \ - ALTINSTR_REPLACEMENT(newinstr1, 1) \ - ALTINSTR_REPLACEMENT(newinstr2, 2) \ - ".popsection\n" - -#define N_ALTERNATIVE_2(oldinst, newinst1, flag1, newinst2, flag2) \ - N_ALTERNATIVE(N_ALTERNATIVE(oldinst, newinst1, flag1), \ - newinst2, flag2) + ALTERNATIVE(ALTERNATIVE(oldinstr, newinstr1, ft_flags1), newinstr2, ft_fl= ags2) =20 /* If @feature is set, patch in @newinstr_yes, otherwise @newinstr_no. */ #define ALTERNATIVE_TERNARY(oldinstr, ft_flags, newinstr_yes, newinstr_no)= \ - N_ALTERNATIVE_2(oldinstr, newinstr_no, X86_FEATURE_ALWAYS, \ - newinstr_yes, ft_flags) + ALTERNATIVE_2(oldinstr, newinstr_no, X86_FEATURE_ALWAYS, newinstr_yes, ft= _flags) =20 #define ALTERNATIVE_3(oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2= , \ newinstr3, ft_flags3) \ - N_ALTERNATIVE(N_ALTERNATIVE_2(oldinstr, newinstr1, ft_flags1, newinstr2, = ft_flags2), \ + ALTERNATIVE(ALTERNATIVE_2(oldinstr, newinstr1, ft_flags1, newinstr2, ft_f= lags2), \ newinstr3, ft_flags3) + /* * Alternative instructions for different CPU types or capabilities. * @@ -294,10 +214,10 @@ static inline int alternatives_text_reserved(void *st= art, void *end) * without volatile and memory clobber. */ #define alternative(oldinstr, newinstr, ft_flags) \ - asm_inline volatile(N_ALTERNATIVE(oldinstr, newinstr, ft_flags) : : : "me= mory") + asm_inline volatile(ALTERNATIVE(oldinstr, newinstr, ft_flags) : : : "memo= ry") =20 #define alternative_2(oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2= ) \ - asm_inline volatile(N_ALTERNATIVE_2(oldinstr, newinstr1, ft_flags1, newin= str2, ft_flags2) ::: "memory") + asm_inline volatile(ALTERNATIVE_2(oldinstr, newinstr1, ft_flags1, newinst= r2, ft_flags2) ::: "memory") =20 /* * Alternative inline assembly with input. @@ -308,17 +228,17 @@ static inline int alternatives_text_reserved(void *st= art, void *end) * Leaving an unused argument 0 to keep API compatibility. */ #define alternative_input(oldinstr, newinstr, ft_flags, input...) \ - asm_inline volatile(N_ALTERNATIVE(oldinstr, newinstr, ft_flags) \ + asm_inline volatile(ALTERNATIVE(oldinstr, newinstr, ft_flags) \ : : "i" (0), ## input) =20 /* Like alternative_input, but with a single output argument */ #define alternative_io(oldinstr, newinstr, ft_flags, output, input...) \ - asm_inline volatile(N_ALTERNATIVE(oldinstr, newinstr, ft_flags) \ + asm_inline volatile(ALTERNATIVE(oldinstr, newinstr, ft_flags) \ : output : "i" (0), ## input) =20 /* Like alternative_io, but for replacing a direct call with another one. = */ #define alternative_call(oldfunc, newfunc, ft_flags, output, input...) \ - asm_inline volatile(N_ALTERNATIVE("call %P[old]", "call %P[new]", ft_flag= s) \ + asm_inline volatile(ALTERNATIVE("call %P[old]", "call %P[new]", ft_flags)= \ : output : [old] "i" (oldfunc), [new] "i" (newfunc), ## input) =20 /* @@ -329,7 +249,7 @@ static inline int alternatives_text_reserved(void *star= t, void *end) */ #define alternative_call_2(oldfunc, newfunc1, ft_flags1, newfunc2, ft_flag= s2, \ output, input...) \ - asm_inline volatile(N_ALTERNATIVE_2("call %P[old]", "call %P[new1]", ft_f= lags1, \ + asm_inline volatile(ALTERNATIVE_2("call %P[old]", "call %P[new1]", ft_fla= gs1, \ "call %P[new2]", ft_flags2) \ : output, ASM_CALL_CONSTRAINT \ : [old] "i" (oldfunc), [new1] "i" (newfunc1), \ @@ -413,7 +333,7 @@ void nop_func(void); * @newinstr. ".skip" directive takes care of proper instruction padding * in case @newinstr is longer than @oldinstr. */ -#define __N_ALTERNATIVE(oldinst, newinst, flag) \ +#define __ALTERNATIVE(oldinst, newinst, flag) \ 740: \ oldinst ; \ 741: \ @@ -429,7 +349,7 @@ void nop_func(void); .popsection ; =20 .macro ALTERNATIVE oldinstr, newinstr, ft_flags - __N_ALTERNATIVE(\oldinstr, \newinstr, \ft_flags) + __ALTERNATIVE(\oldinstr, \newinstr, \ft_flags) .endm =20 #define old_len 141b-140b @@ -452,12 +372,12 @@ void nop_func(void); * @feature2, it replaces @oldinstr with @feature2. */ .macro ALTERNATIVE_2 oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2 - __N_ALTERNATIVE(__N_ALTERNATIVE(\oldinstr, \newinstr1, \ft_flags1), + __ALTERNATIVE(__ALTERNATIVE(\oldinstr, \newinstr1, \ft_flags1), \newinstr2, \ft_flags2) .endm =20 .macro ALTERNATIVE_3 oldinstr, newinstr1, ft_flags1, newinstr2, ft_flags2,= newinstr3, ft_flags3 - __N_ALTERNATIVE(N_ALTERNATIVE_2(\oldinstr, \newinstr1, \ft_flags1, \newin= str2, \ft_flags2), + __ALTERNATIVE(ALTERNATIVE_2(\oldinstr, \newinstr1, \ft_flags1, \newinstr2= , \ft_flags2), \newinstr3, \ft_flags3) .endm =20 diff --git a/arch/x86/kernel/fpu/xstate.h b/arch/x86/kernel/fpu/xstate.h index 4fe8501efc6c..70903c12a911 100644 --- a/arch/x86/kernel/fpu/xstate.h +++ b/arch/x86/kernel/fpu/xstate.h @@ -134,7 +134,7 @@ static inline u64 xfeatures_mask_independent(void) XRSTORS, X86_FEATURE_XSAVES) \ "\n" \ "3:\n" \ - _ASM_EXTABLE_TYPE(661b, 3b, EX_TYPE_FPU_RESTORE) \ + _ASM_EXTABLE_TYPE(771b, 3b, EX_TYPE_FPU_RESTORE) \ : \ : "D" (st), "m" (*st), "a" (lmask), "d" (hmask) \ : "memory") --=20 2.43.0