From nobody Thu Feb 12 20:23:36 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 6F4AE187346 for ; Fri, 7 Jun 2024 11:17:08 +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=1717759028; cv=none; b=Jiy4QyIC6R7Ks5XX5fqw+9tT4FFtPY79dkQqU4XLWRjy/sFGlFq5x3JpssuFnhsORnON+MUIeuKMqjZfuYVAjyolQJQwE41t5L7Rtto1BvgyB9tOxtVu2L9j5TIWwwchG+C8L0Ak3ItBx7Xk0naGpPvQB3lwFqJlM1mxMzSrKIQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717759028; c=relaxed/simple; bh=9t/V6lr+JXo0ko6oV1wFcYKchLmN9d+xrlxuBH0B4uw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YZlD+9ziNARmi5OmuQSZA6bfBjSl37ycfmPie0/yk25B04gT4l5i0gM/vWAYwtnSVmKpxGvBthxptj+feR1YJLiq8r7jCO1SQ+3DGvcEYtlUcNH3o6IfR3wGsjDzWJ/HRRyeR/gE/zj3EQlpRb0uZQBqk8YN7hM597sV+cmlSmg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LjC6ZkdH; 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="LjC6ZkdH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 760FEC32786; Fri, 7 Jun 2024 11:17:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717759028; bh=9t/V6lr+JXo0ko6oV1wFcYKchLmN9d+xrlxuBH0B4uw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LjC6ZkdHpeOiJwD8KULbH05n5M/aDnRcFKFFGGnaWUSpRoS1uCeOolAzyzEv1hP+6 mUYhWu44yslRj8norBzhDPTrCJr+CmzPPYHm/oc53KO0If2gbXF1L1SKDaZ9ItYJcQ vA9IJsyeVt6FBK/2knj2zfmULJeOO1QSy95+jHJ3VI0QYYWQXACDQLzoifobQTTlyt SkPDGB6mxZYCDvYgabn8jbw5y+jmkeywAyfWnRuw09rorSSRQ/+6jsl6H8Eh58lHp4 P6C2i44xqMz+SyiUqgWkqpoPLHH9ASRxCSDy/Gi7lnINa/PW2b2jp3wh5vd6hRgRU1 bCAjgZS+uyZuw== From: Borislav Petkov To: X86 ML Cc: LKML , "Borislav Petkov (AMD)" Subject: [PATCH v1 01/14] x86/alternative: Zap alternative_ternary() Date: Fri, 7 Jun 2024 13:16:48 +0200 Message-ID: <20240607111701.8366-2-bp@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240607111701.8366-1-bp@kernel.org> References: <20240607111701.8366-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) Acked-by: Peter Zijlstra (Intel) --- 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 Thu Feb 12 20:23:36 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 1C5F018C35E for ; Fri, 7 Jun 2024 11:17:10 +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=1717759030; cv=none; b=psbdfd5m7qfVJqmk8UIh9kKIp3W4rsY46Zq/d8O8X46L4FnG7A6Kb7EKlXzbBh3GIRa4b6tSBQlilG01S/lGuiEL2mc/qoHIjsKMwktLNJ5LtYUBbDfYX1DiaecViP9fkn48htliX1kOR9bvyCgP44scdIaZRQBJfVbRHEx6OJ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717759030; c=relaxed/simple; bh=7tC0oNifdOJ0UhMRH23bCedmsLzj3p9oIwgK8SYAmGs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SAAZ/Sw7S49bxdCFKR+ibWOlXZQVKmv8OxkL46N9DoMdT3yOtgZH0qwjqPmmcnrA76w4Wyk5bwhxiHqZLX2lMbvOTmKc2v/3FgRXl3ROG4fm+1jn9HG2RWjTb3DZ8lEadGq0LPz3zudVVcTP3IC+9FP0k8lMNpUyHZobbgl/PhE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QTDxnFI9; 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="QTDxnFI9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE5F4C2BBFC; Fri, 7 Jun 2024 11:17:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717759030; bh=7tC0oNifdOJ0UhMRH23bCedmsLzj3p9oIwgK8SYAmGs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QTDxnFI9eZ9hRcQGgZo291b2qbfTqafmfGDGgpWXjOkP1VZJ7zovhXI3xWKWoVaM7 4AIL10Up1sYCEtxqAnziVciYVsun/QTWyR46IKrWPRc4lgzEfsmv9PJuR+gkbOTE4L gk/AdoGgnPCdtqDxhHGYYW2DEX519fTHjc/9OwZxbZnoWcVSUp37xP4iNWKJAQMniQ hpvwXn2lCf1LbBh8GXFzRAmYOJfkwnw5l9QVuEdDKZskH3qOu3LgAfM8oYvLGZ4T43 HqWWBhtbJZCHYpeekUujqbhN/dDq6b/C8Aj1Mrxr2OGz4pI0P7EW9erNndl4WGtVZ1 HZLw0Kgr5ARGA== From: Borislav Petkov To: X86 ML Cc: LKML , Peter Zijlstra , Borislav Petkov Subject: [PATCH v1 02/14] x86/alternatives: Add nested alternatives macros Date: Fri, 7 Jun 2024 13:16:49 +0200 Message-ID: <20240607111701.8366-3-bp@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240607111701.8366-1-bp@kernel.org> References: <20240607111701.8366-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. - Use the %c constraint everywhere instead of %P and document the difference for future reference. ] 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 Acked-by: Peter Zijlstra (Intel) --- arch/x86/include/asm/alternative.h | 120 ++++++++++++++++++++++++++++- arch/x86/kernel/alternative.c | 20 ++++- tools/objtool/arch/x86/special.c | 23 ++++++ tools/objtool/special.c | 16 ++-- 4 files changed, 167 insertions(+), 12 deletions(-) diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alte= rnative.h index 6db78909180a..7d9ebc516bde 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,32 @@ static inline int alternatives_text_reserved(void *st= art, void *end) 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 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. + * + * Use the %c operand modifier which is the generic way to print a bare + * constant expression with all syntax-specific punctuation omitted. %P + * is the x86-specific variant which can handle constants too, for + * historical reasons, but it should be used primarily for PIC + * references: i.e., if used for a function, it would add the PLT + * suffix. + */ #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 %c[old]", "call %c[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 +384,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 %c[old]", "call %c[new1]", ft_= flags1,\ + "call %c[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 +489,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 +524,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 +551,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 +581,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 Thu Feb 12 20:23:36 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 61384190463 for ; Fri, 7 Jun 2024 11:17:11 +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=1717759031; cv=none; b=sF5N7zzBfRJI+gON9fGcmUQiXnFofflHsp3hfcUSJ+rqTcV4i9xIH3aniqUm+HkLwP5qrls+P8psXjnGFW+dddb0doCEY+ZnIk28yR7YuQtivWtTmVwFGFv8d1enlVSpnMgxZ2Dwd0GnkcvcRX4oD1iaw4pqF09X7HPAeQOIwLM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717759031; c=relaxed/simple; bh=vziuIUlIcL3EGLmUnsFyHCZrIa0y4BZwVvEBzkBn1Og=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CWYWoPoaOrvWaOuW6vt3zedDpV2NFmUUabea3868Mc/5sPQyRUtS2iy6rrJuAZ/GYcnB932oTuYX4kzEQAGrQcng+uGyWyaDB/4LIOa3nTanWg3EOfegjMvmiAsk+kmt3Cyt3PG3r31UicYw0aPfQpPLT3swF5exmmNsZuDO80k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QPLRjesl; 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="QPLRjesl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 68C26C32781; Fri, 7 Jun 2024 11:17:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717759031; bh=vziuIUlIcL3EGLmUnsFyHCZrIa0y4BZwVvEBzkBn1Og=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QPLRjeslzhWdmICfKo0WrcZj8hxdiWojzbiKznAwLYS1YX05UkRQ5PtuX+Of5Gq+C 4SoQ5RmGpeupqgybdJEBUANYRMfbQwyV53PAr5KuLkmH4IrDs4BDLf0olTHbL0G/fZ qU44LTOzZBp59hZvmXBC1ODCGWYZ9eun8/zcVIUj1iyAjDJf1lhAhk4zMWLaJRVn7l Uqq43iUrLaJyinVTRHJs0IdyolbVcIkXUSThuiokbEvYz1hhkF1uwTDg7VHWLPr8ki PpnZDxyERGfLyFFHLsd44rlDmAvd9J1wv9uWssJIMuc7PniWieVrwmcp4nWgtNm7i8 P98o6Q7u6k7Fg== From: Borislav Petkov To: X86 ML Cc: LKML , "Borislav Petkov (AMD)" Subject: [PATCH v1 03/14] x86/alternative: Convert alternative() Date: Fri, 7 Jun 2024 13:16:50 +0200 Message-ID: <20240607111701.8366-4-bp@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240607111701.8366-1-bp@kernel.org> References: <20240607111701.8366-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) Acked-by: Peter Zijlstra (Intel) --- 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 7d9ebc516bde..c05bff2e3626 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 Thu Feb 12 20:23:36 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 A8882190682 for ; Fri, 7 Jun 2024 11:17:12 +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=1717759032; cv=none; b=hXFOVhOxT5e8YkVeuUMOSXReB/Wd4xF3JgmePFdakNroAMzziGa27Ekw6iGKeYFpOCfbN1g5VPnjGRsJd+RVgEeU8IVS4zIOk/5HIt6nb/n0cABlOiDDjw5Lsnc18JE755tR5BprgNuVj11LKRE96hDcv0xq0wrlnKT3T/XfCqQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717759032; c=relaxed/simple; bh=2DjrnYCMqznW+ee14tuQDAv3aZSnRa37n15txMb0Zbo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YoCaK6pJctyBAP/pVgpLVyghEMrLcbowTH5/nfm/CZXjlnrqc+um2PEX+PDb9HV1NNZW2a/MqzajAtSoBonFRW7tP6ZHWCYmFxqhXBelb7WJPvLzY+HYLqc+3ZLvD7knw1ISy6lz0148UwxKjQWAfBbtpW9DuWP7mMRjAkyE3PQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oXBczZUW; 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="oXBczZUW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B04E9C32786; Fri, 7 Jun 2024 11:17:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717759032; bh=2DjrnYCMqznW+ee14tuQDAv3aZSnRa37n15txMb0Zbo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oXBczZUWLuSgjM04SGEQayG3SxQ7dDGesv49NDsEu21QcbgK4KvOL6f83/SUkrlRv gWfHcUbB68DCd6PmCHnmx+yz7K0CSB6kvffh+tzypCZLiXs1sZ4ct+3BZQ6DbEKE2T tIebI1pgdWTWlj5/Et8lLq6pn/dtMpBVZPo3HWRGwrqI2lSpFFanbjAhhYTgz3xlUb PrutTGZaLXTJoC6wfCpi33WsHnHKWsSPkTAY3mYjJ9L6mkG3IvbwyUaGVP0Oc7q31G xDMgZjp98oCwrToFwcVtovqeA/mT9acijIvfcH1gqmVagGc+0+gilXH7u9TToiWNNS VoIAdLgoIjBfQ== From: Borislav Petkov To: X86 ML Cc: LKML , "Borislav Petkov (AMD)" Subject: [PATCH v1 04/14] x86/alternative: Convert alternative_2() Date: Fri, 7 Jun 2024 13:16:51 +0200 Message-ID: <20240607111701.8366-5-bp@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240607111701.8366-1-bp@kernel.org> References: <20240607111701.8366-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) Acked-by: Peter Zijlstra (Intel) --- 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 c05bff2e3626..21ead5dea15a 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 Thu Feb 12 20:23:36 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 F009519146B for ; Fri, 7 Jun 2024 11:17:13 +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=1717759034; cv=none; b=eBwCku0rq5vSUWvyqju8g7+dlZYpRD3w9TyAxXqTHWhxgiCQooQstrfy5BkrQ4e6xJ3AnpZlc8fJ0pbMPxmeclRP4yk+CL09JYYyboOG5dzv9AGwSKozcGOB9b8MhLeTA8VuI408mHR1piQGeBPQJcIrml5mYIny0zL/izEi84M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717759034; c=relaxed/simple; bh=jzhujQuJXGlLkVBXPJVMy7/GVgi305oTlkYSmvQWPSI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bfJy3+dxGkvGk9bWuamUJGhNhlWFUWAgb0yWFosIZyk3H2c2LR08dN+hLsrHeDhncBbOoQdEFTL3DqabiKCg8sd3reSrvzqXeDhaJF+1+AS1au9rgvfOOFnz70CsQ1SvLbsJ7mmMcniED6s0LudJnEniwC3pG/tof/8MbbSgG6o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ixcC4Ay+; 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="ixcC4Ay+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 038E8C32781; Fri, 7 Jun 2024 11:17:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717759033; bh=jzhujQuJXGlLkVBXPJVMy7/GVgi305oTlkYSmvQWPSI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ixcC4Ay+mySyaHhLRSmQ3DYtgRjZenrqrtGQld+I6dDbX7+sJvGJOifTfTLZuZCCO oJiOiCu3WDZdJaQr1/N6HVSwCZ3e2EcKaITf+ykV8nB0lU+svDH9VwCWBJNnOcPhG7 fdfAbBHnCx6pLoU3xlY4gTdPh72vTHGcoflESECeRjnRBqZxb6hR43VnkLBa4w9+T1 bqk+2cmYxzyTIFioqZxoQMHc34ykpZuISTti7J5PpVV850sIgk4y2zyXDRpDH9Cw3u 2wGMV1yl4dhaGoZlTDfhY1Glx2BhVgP1KgeS1dFUTzfhveLD99w9Hi7qs0iBv3mc2M phf5kWSqwcwPw== From: Borislav Petkov To: X86 ML Cc: LKML , "Borislav Petkov (AMD)" Subject: [PATCH v1 05/14] x86/alternative: Convert alternative_input() Date: Fri, 7 Jun 2024 13:16:52 +0200 Message-ID: <20240607111701.8366-6-bp@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240607111701.8366-1-bp@kernel.org> References: <20240607111701.8366-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) Acked-by: Peter Zijlstra (Intel) --- 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 21ead5dea15a..428d6efeb333 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 */ @@ -356,10 +356,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 %c[old]", "call %c[new]", ft_fla= gs) \ : output : [old] "i" (oldfunc), [new] "i" (newfunc), ## input) --=20 2.43.0 From nobody Thu Feb 12 20:23:36 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 9C43519309F for ; Fri, 7 Jun 2024 11:17:15 +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=1717759035; cv=none; b=I5sir601KUsy+OdDMcMFKWrC5OeWsrCmeGXwCf022q2mXbeeaIsg7cFmZAQYR7HR1p7JpRdbfsBn4er2pm7qytHf06GWSH4/7gNTChKgWuWxDazVUYDJzLLLRyST4iDK2dVypsmuPzWUwyPssJ0BVlP+YLJqE1pFjiYuXk9laQs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717759035; c=relaxed/simple; bh=0HCrS9uz4EYBWWuk9AcMKlySTziLWW736XUxfxX+jiI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hint7jC/jTGTtx1Ki6stTuFCWRK7mcJyHOrxd9bLWGd4wYFBnXr/6jU1lGn7QvmN2X93NWBzOs/j0Elp4tancZQ9c45vPm3SQ2vya0KeoOs/Xcow3mNjHLk79V+lQBCV+FzLqRX25L088wPyWZjrnOuoKJj6WOOt+MEtKEWv7/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=daIHVpvE; 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="daIHVpvE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4B202C4AF08; Fri, 7 Jun 2024 11:17:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717759035; bh=0HCrS9uz4EYBWWuk9AcMKlySTziLWW736XUxfxX+jiI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=daIHVpvES9VNvuR9PbB68XZV+OO9B20a/uGZBKngLVoIYxOInrYZ2Glp/P/DXiv3x V6uORJoGgfsnDna3dPKOAH72VugYFeC1/5V/I80Q8QGIr1U4HuJERo4DTqmQH28doB ZADbwSNoE7duI6tamzLg6biRvQU9w2YiFpWMJgn5zPqHbyW7nJ4VTDn42Q5ElkKoP0 Z2qDVYBwVt3nlvIkndIGU+Xoaf8F0fTH5wK2csCTbqIqP9IF/oiWCfVFC5PPx8+7WK Mr9eGZ0VkbVEYlPS62HZBcm9my7MPDNq4yPdMrtD1ycdBzCktYLkMm3Xnqo07wbDqG IMwqyN1HSr8NQ== From: Borislav Petkov To: X86 ML Cc: LKML , "Borislav Petkov (AMD)" Subject: [PATCH v1 06/14] x86/alternative: Convert alternative_io() Date: Fri, 7 Jun 2024 13:16:53 +0200 Message-ID: <20240607111701.8366-7-bp@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240607111701.8366-1-bp@kernel.org> References: <20240607111701.8366-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) Acked-by: Peter Zijlstra (Intel) --- 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 428d6efeb333..6a746811c602 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -335,11 +335,7 @@ 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) \ - : output : "i" (0), ## input) - -#define n_alternative_io(oldinstr, newinstr, ft_flags, output, input...) \ - asm_inline volatile (N_ALTERNATIVE(oldinstr, newinstr, ft_flags) \ + asm_inline volatile(N_ALTERNATIVE(oldinstr, newinstr, ft_flags) \ : output : "i" (0), ## input) =20 /* --=20 2.43.0 From nobody Thu Feb 12 20:23:36 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 8ADB5194088 for ; Fri, 7 Jun 2024 11:17:16 +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=1717759036; cv=none; b=KcR4GOAqUdV2CmkBGZev5PQXCcDlGm5sEnpp/c8Sdu9u+qX8++qyvPaFLvNDykLgkw899Rtpq3HkYl9s2X0Ptgq/VOsmiOa9zmXJurqUxqMi1iXLSpv4THfxyeDeH3Yb+Ouh9+Q8bx8GxpcF/C8GUYQjaEChENshL7PusFWuYc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717759036; c=relaxed/simple; bh=rn3s2RmxRTxbJSVhbZdiuz/L02U5NGxr5eXKw3dd/jk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=elCF1CXggKcSS4bU3zx88enZCzv8GmKj8/8YmnhQrhXVgBsEaXboRBjvTppfHw3lbx739P8oMroBzpxiHcFf49VyM0jIEc5J3eSEENMfQXQhAHFpzrrraGHGZ2Qw8aM7dXhW5ZgROVmdhWvKE15Vv0Q2tWfIIAQC60ylKirXUZ0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jAlGygxt; 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="jAlGygxt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9279CC32781; Fri, 7 Jun 2024 11:17:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717759036; bh=rn3s2RmxRTxbJSVhbZdiuz/L02U5NGxr5eXKw3dd/jk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jAlGygxt/5UT/TLCnemWs8OthpPmhH83tJBf3skKLcvb9c4BE5zfzBF0LAkvMkMqv KsIe6cq8tDQtCCxdCEbcyXnCSS0uOZ3eo5fKrpONoDB6zsRpNTcHGZu5goMHI8iY3M ihReNCHhOD/hEU80p0c5SC9ObZbBc9GeZ2p+H0tuYt+ZUZuwbo+BsX6hT2zhKHhhlt IHH8R0g3cBnyRVWzTU3+jLHlORJABSE7uRZvOn/C0iP7FxLu8qDOOdx92z4rYWa71+ Oye59vKSoGL4Gc6LqC5RwPh95xOUaUudpJvrs5gNukjhKT4I17mMNyIV+rNkWxfyNS +qVCuaALmJTdw== From: Borislav Petkov To: X86 ML Cc: LKML , "Borislav Petkov (AMD)" Subject: [PATCH v1 07/14] x86/alternative: Convert alternative_call() Date: Fri, 7 Jun 2024 13:16:54 +0200 Message-ID: <20240607111701.8366-8-bp@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240607111701.8366-1-bp@kernel.org> References: <20240607111701.8366-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) Acked-by: Peter Zijlstra (Intel) --- 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 6a746811c602..b6597574fa43 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -349,11 +349,7 @@ static inline int alternatives_text_reserved(void *sta= rt, void *end) * suffix. */ #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 %c[old]", "call %c[new]", ft_fla= gs) \ + asm_inline volatile(N_ALTERNATIVE("call %c[old]", "call %c[new]", ft_flag= s) \ : output : [old] "i" (oldfunc), [new] "i" (newfunc), ## input) =20 /* --=20 2.43.0 From nobody Thu Feb 12 20:23:36 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 DC1BD1940B5 for ; Fri, 7 Jun 2024 11:17: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=1717759037; cv=none; b=CbgTW44w/PXrhNwdT1gELzSY96VBvxEvQIKlFokPgve2o5ocxcOtSMErUQnb8DwL8L29japBGL1SJpgo9e96SIQSuISMdnpI73OS4IeBX6rlZawJNbioAKclJgXqd2ZB3+xGgSKl459g+uok3REBJIzLrqxQztEqoA87E6Uhf/I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717759037; c=relaxed/simple; bh=SkAL6P8aesAmbpCT2O5FROApQPOqWnWIL7i4C/sp/ug=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LJSIxhBcGS7PXqBqdHNS/ms3wQydmb/SCqnjbCiWttghGINUXnJMZ15WvQctBVBkGXQh/3ictrncS+NRLToBFijR5MLw5ddNDtFcffWfN8joDaLku4H4xTAnx2v+NToYmBT7xNNu5HgqtwdvO1/CRb8TPhEvGqKJ8mtwLJVc+Fw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dtOt/ExG; 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="dtOt/ExG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DA878C4AF07; Fri, 7 Jun 2024 11:17:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717759037; bh=SkAL6P8aesAmbpCT2O5FROApQPOqWnWIL7i4C/sp/ug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dtOt/ExG7mZegohbTeKdWc1S0nbNzsMDDcgUzeac90GfN2BehWlvUchO/MaUQ8xUC Ex3D/s0pkZnBq0VKivMuoNKEzvvOXCOrefExiUXfgPyQYPSiDo4lUqKwmRpYjsuudW DgOP93iJ/aEjLI1aecLwJ5ASB7+mzag9tFa3JoKArjI8m6lf5R+kDSxdSxYxxiUNae RIilEd4RZnH7M5sVnITDm6S0RXRUoT04X7U4EGkqbMJkgtfVh+HqZCwpM2ZFdEUC6N uU8FWW99E5/KLQehIIHGhlmBdEa6eNwKqrpEdS3EXqrxidTl7lUmF9xFhZGFAkhpBo WWpj2Zx2ETCbg== From: Borislav Petkov To: X86 ML Cc: LKML , "Borislav Petkov (AMD)" Subject: [PATCH v1 08/14] x86/alternative: Convert alternative_call_2() Date: Fri, 7 Jun 2024 13:16:55 +0200 Message-ID: <20240607111701.8366-9-bp@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240607111701.8366-1-bp@kernel.org> References: <20240607111701.8366-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) Acked-by: Peter Zijlstra (Intel) --- 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 b6597574fa43..bc260f27d7f1 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -358,23 +358,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 %c[old]", "call %c[new1]", ft_f= lags1, \ + "call %c[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 %c[old]", "call %c[new1]", ft_= flags1,\ - "call %c[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 Thu Feb 12 20:23:36 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 7261419414D for ; Fri, 7 Jun 2024 11:17: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=1717759039; cv=none; b=fLr2N2tp+uO48yREIc2ATCtnDz055D+S2lBvdpSlEq7tIwBKIxGNNd7cpyv3KmN/eitZg2kMxRQLNFsXQZsvI5m9bSo31d9FzcLYUcRJnpPldn9vLx7XT8UWDi1b+kc8ekVeQhdl/AULwoJNsDoKHSEbnBw/4zMfDFWRwwNe3aw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717759039; c=relaxed/simple; bh=jX1K1qcahG4Vu37vWyHa5G78VbBr/6o4XnfwKu5fGm8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kfndsI/s6NLJfMI5gTK9Fy60BXxGBZSKMLUOxzRIFG7PWxAMfVtYP6oRY6C7xzE4uN4ZsB4iRmFJBuE9aLfHyVC7mvr4gxVDTUQlY+Sg5gFCAo6gwXlkKkx7DQMdTllabQeV0iK8MdoHoEYavdGeV9PY66/Xok2Q45J/m4Nr92s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZUFMFR2c; 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="ZUFMFR2c" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E3E8C32786; Fri, 7 Jun 2024 11:17:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717759039; bh=jX1K1qcahG4Vu37vWyHa5G78VbBr/6o4XnfwKu5fGm8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZUFMFR2cNGUKSMc+qXLfgKCE7sTZwvnPDvT0zcTZzXKja6Cx/0HKLgMW3OZQYzg/V u6mPG6WxhlugDq43S4MaoNzhH1+Wvnuu37kjc++smZa5P2SM3hdPIwScqEHFBNV5S4 xiSp8fg81N3DqUjW3kLmxDlSEE4BDWkNzLZiZeoKL8FU4xZEVVnvYsBZhJO7z6j0Rf HEaNeoSGJRg4/cup/XKNR71pTkV1oJh9MLG0LB7dfAfzfPz0DbmjSXz4CVcdaxJBwO G0rA3UnN5omC9AcsmC0/HPdoz12dvKfMAaMokc0xw+D4txcmwtfdEJHa70B/hjRXAX 8tiIEWevUjtyw== From: Borislav Petkov To: X86 ML Cc: LKML , "Borislav Petkov (AMD)" Subject: [PATCH v1 09/14] x86/alternative: Convert ALTERNATIVE_TERNARY() Date: Fri, 7 Jun 2024 13:16:56 +0200 Message-ID: <20240607111701.8366-10-bp@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240607111701.8366-1-bp@kernel.org> References: <20240607111701.8366-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) Acked-by: Peter Zijlstra (Intel) --- 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 bc260f27d7f1..007baab32c14 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 Thu Feb 12 20:23:36 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 770181946D0 for ; Fri, 7 Jun 2024 11:17:20 +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=1717759040; cv=none; b=N/TMf8LX4t4fSv5ToOHeFq1aRyutTHpIREsAVSL0MsOHvSjkFvI5CIE2a4K/FYTgrwpgKLuZPTC5fNaTNh6NRtmyvdQSK3i7yq+306HH+ZWg5cQfi3h9ldiXwLOPGsem2G/yZtDC/QTXdJH+0MieuXDrBHEIIUvNkp1eZEe054k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717759040; c=relaxed/simple; bh=Kpx+YjQbXZ46f/l7nC+io8PAVstKFYCXDtl4IwhcbhA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XLyHliRxrKSPnyEQmR6RH614rL1u0LOyRRnDu8cr0wgcEPmH9C/vHE5KSvjs7hii9z9t8Fyxcpd7Ll0zLRdIdm+ofZZ5JySAiKfxWhR5OExa2Q4jUcUUaHJFd/7FPCb/BRBnxedLTZfFpFPbqb6EJdBbsDVGlRJtql/Gj/FxEsg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oDBIfceO; 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="oDBIfceO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75CA8C2BBFC; Fri, 7 Jun 2024 11:17:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717759040; bh=Kpx+YjQbXZ46f/l7nC+io8PAVstKFYCXDtl4IwhcbhA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oDBIfceOM0a8ua9YZzce3mzEdeqnp0h4vluwItzCJmjEMCZm1C4fct/0Jzsr3HGge FxZJ6e2ksFpMUBHNyrNIsSLPIjSTVQCBMgDc+926ixSAIbEKmNSq6BFhLl4D4ermwe s70m2OMf1tdzM/ZblhraGTb8x3STZ3fgusR/jciDd1wIkikSzuooyyTJXaDG0+6jZR GvoRvnertpnxICoIn5IAn1Orh3RTcbYAeSZLUoyeFg2PGEcpqMNpxwG9Ohb9wmwOpQ K5D4Tnx/Q7Hroz2I2p/u5gMGTXocz+ZgSuHe5m2pwIM1sBK3MrcUgrJHSGVhMiZN+H RCXLJRkGmUQJA== From: Borislav Petkov To: X86 ML Cc: LKML , "Borislav Petkov (AMD)" Subject: [PATCH v1 10/14] x86/alternative: Convert ALTERNATIVE_3() Date: Fri, 7 Jun 2024 13:16:57 +0200 Message-ID: <20240607111701.8366-11-bp@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240607111701.8366-1-bp@kernel.org> References: <20240607111701.8366-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)" Zap the hack of using an ALTERNATIVE_3() internal label, as suggested by bgerst: https://lore.kernel.org/r/CAMzpN2i4oJ-Dv0qO46Fd-DxNv5z9=3Dx%2BvO%2B8g=3D4= 7NiiAf8QEJYA@mail.gmail.com in favor of a label local to this macro only, as it should be done. Signed-off-by: Borislav Petkov (AMD) Acked-by: Peter Zijlstra (Intel) --- arch/x86/include/asm/alternative.h | 24 ++++-------------------- arch/x86/kernel/fpu/xstate.h | 14 +++++--------- 2 files changed, 9 insertions(+), 29 deletions(-) diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alte= rnative.h index 007baab32c14..fba12ad237e2 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..2ee0b9c53dcc 100644 --- a/arch/x86/kernel/fpu/xstate.h +++ b/arch/x86/kernel/fpu/xstate.h @@ -106,21 +106,17 @@ static inline u64 xfeatures_mask_independent(void) * Otherwise, if XSAVEOPT is enabled, XSAVEOPT replaces XSAVE because XSAV= EOPT * supports modified optimization which is not supported by XSAVE. * - * We use XSAVE as a fallback. - * - * The 661 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. + * Use XSAVE as a fallback. */ #define XSTATE_XSAVE(st, lmask, hmask, err) \ - asm volatile(ALTERNATIVE_3(XSAVE, \ + asm volatile("1: " ALTERNATIVE_3(XSAVE, \ XSAVEOPT, X86_FEATURE_XSAVEOPT, \ XSAVEC, X86_FEATURE_XSAVEC, \ XSAVES, X86_FEATURE_XSAVES) \ "\n" \ "xor %[err], %[err]\n" \ "3:\n" \ - _ASM_EXTABLE_TYPE_REG(661b, 3b, EX_TYPE_EFAULT_REG, %[err]) \ + _ASM_EXTABLE_TYPE_REG(1b, 3b, EX_TYPE_EFAULT_REG, %[err]) \ : [err] "=3Dr" (err) \ : "D" (st), "m" (*st), "a" (lmask), "d" (hmask) \ : "memory") @@ -130,11 +126,11 @@ static inline u64 xfeatures_mask_independent(void) * XSAVE area format. */ #define XSTATE_XRESTORE(st, lmask, hmask) \ - asm volatile(ALTERNATIVE(XRSTOR, \ + asm volatile("1: " ALTERNATIVE(XRSTOR, \ XRSTORS, X86_FEATURE_XSAVES) \ "\n" \ "3:\n" \ - _ASM_EXTABLE_TYPE(661b, 3b, EX_TYPE_FPU_RESTORE) \ + _ASM_EXTABLE_TYPE(1b, 3b, EX_TYPE_FPU_RESTORE) \ : \ : "D" (st), "m" (*st), "a" (lmask), "d" (hmask) \ : "memory") --=20 2.43.0 From nobody Thu Feb 12 20:23:36 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 B6ED3194A66 for ; Fri, 7 Jun 2024 11:17: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=1717759041; cv=none; b=f6ec+Z0vG7sXmtA55lMbkbQj/pYgkDY0+Jj+LM0AN2fLw3AZlqVkjwbWZKHGRswVbs0t784RnihaIxpGqYxJLfm9s+Fz0L7bist+GxLpmqZCimSbWgRioYhfM2wQp7Lg2ODlZOFL/ba1UPwl17icHrDH01rPjnrlJvp35c0thV0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717759041; c=relaxed/simple; bh=oymOvMLk8fkLJdktfsSVSNeV3MCBYDn9eT/+zmcMkd0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JE3468yoH/+DcN2j6q+NklHUYptIKbEwpje8HAm20sTBzYB7DA+MTIAnLxOluJFmZObkDiAKbF7d59QOOq7LxryLrAiK7wTXJcXJZh9jePZW1jWW8iGTuM0q4wpZpVioDY8u2S5ZdP9VUw10XpNPhd6kQfm9E22z4xQjodt+w60= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=W0tNkTZ7; 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="W0tNkTZ7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BDA41C32786; Fri, 7 Jun 2024 11:17:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717759041; bh=oymOvMLk8fkLJdktfsSVSNeV3MCBYDn9eT/+zmcMkd0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W0tNkTZ7XozcsyWrqWqZqtNrsfPEsBCCzIfKyMYNGODHCB1XD/XGDKn8ks6dRXEne ZjQDNb8roBZsoK9ch2KI+dnYwdUBiHnFxpwb5r0ZWL2Xns5GNFZdlOYIEJYHHeyKYE L2e3xTewGEAUDLOyUaYgA2VzTca0BFNPMsGwQj0N2ZbtmNqacA2YRsCY7OqUGWtwG6 dZigM2VwRoiqM7PwIXKRGZrJIDTBiA6OQ0+ztbqk9BU2P0wLzpacgiR1Vb10B5aGVe 5WOdJcRyKchaPBAtYrNID00K/8SelYMB2OVNoY/PDy36ofdJuC55mEN85g4szQCp9h qiZTxkd7QkZQA== From: Borislav Petkov To: X86 ML Cc: LKML , "Borislav Petkov (AMD)" Subject: [PATCH v1 11/14] x86/alternative: Convert the asm ALTERNATIVE() macro Date: Fri, 7 Jun 2024 13:16:58 +0200 Message-ID: <20240607111701.8366-12-bp@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240607111701.8366-1-bp@kernel.org> References: <20240607111701.8366-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) Acked-by: Peter Zijlstra (Intel) --- 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 fba12ad237e2..31b9a47b9df9 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -422,24 +422,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 ; \ @@ -455,12 +437,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 Thu Feb 12 20:23:36 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 0E5DD194ACE for ; Fri, 7 Jun 2024 11:17: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=1717759043; cv=none; b=RwHoGA4S1EuQjnXv6wfQLem2TolBUP9B9LgExtc5lZgXT+Lext4fIWn3SNemxbaXSNyxCdisd5xG7Cuq+eXDSjg8U/HcchbzStALYrFOXJg/R6Emm5FMlwb3tbyPc83aqgbgbgjB67wFlfF10rn2UgvS3KqBu18K/LwS7+87o/U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717759043; c=relaxed/simple; bh=mpY13cDkkhjPXE7HFQg9dp0vJygGBsKGCPtYHRFiDNg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cDMrcGYgVsCOQ/t/K4T5OO/cxP+OBk7ZoPwhTMAlSw6aWVXbkqFvqXP0C6y7J+qj0nLbcxhR4+usDYoP0QFkYwoO0zZQmxSF4nDEHQ7Wjos0KRQHiXrvSFfRU6hkqtf7W/qbL7apussyNuYpieyYKn3QllOgymtB7qjeE5HE2Yw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=N0dr1a/z; 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="N0dr1a/z" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 11108C32781; Fri, 7 Jun 2024 11:17:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717759042; bh=mpY13cDkkhjPXE7HFQg9dp0vJygGBsKGCPtYHRFiDNg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N0dr1a/zUT0YJDJx7FZ8xtqt506EpZ5LgYMjavemuBY96qINCnQ1lYCnNtplv9pt+ FARGAMMCoAIb8o/Ei8LZ4KxSlZZqkYYvvY1ytzuadGr28pWygQ/yrzkKHUf5liDPPC S7Sm0H73qxqpA1lmtUWytKZnq3reKrlPVsVRhxSDLNGgL3WnjY5ED4NXifaXq1z9aA 4122btdhG1ig+qm4EpWZPP+FcR0Io1DHoDrYrBtnAVZ/rbiqpnkXs79IRNdYgaWhQP Nfk8HAa6fNm5YWKdW7pRvw8KbpBZ1ssQ6/pq/JOEuQ55UyJ00dMLv6bON0LQees03e hX1afN9dYZ+4w== From: Borislav Petkov To: X86 ML Cc: LKML , "Borislav Petkov (AMD)" Subject: [PATCH v1 12/14] x86/alternative: Convert the asm ALTERNATIVE_2() macro Date: Fri, 7 Jun 2024 13:16:59 +0200 Message-ID: <20240607111701.8366-13-bp@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240607111701.8366-1-bp@kernel.org> References: <20240607111701.8366-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) Acked-by: Peter Zijlstra (Intel) --- 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 31b9a47b9df9..28e07a038964 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -461,28 +461,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 Thu Feb 12 20:23:36 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 56151194C6A for ; Fri, 7 Jun 2024 11:17: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=1717759044; cv=none; b=Lla6q9WbEugznDPGcjQfPGPTKZ0diD0f2vNlUTQ8ju8RuId3L6LkNmyGTV6kFYmGmom/tRxVNjuijnwpZLCIPhIPCXZbeF+3T59xkXK0H9PWEMzxUCtS3M80utZf9kioEwP9PNQ7GSLRxtDWUoOMIHmnr0lKikrW+mOGKkhtdhs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717759044; c=relaxed/simple; bh=BOkJs2FsO7d8uNtY+3OezgdrS5yyqUklsYRb9p4/cHo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AqHFCKiR1o0QNiVtxG88Ktk8QA0wdeNRuLxUqaVq/26v3rx0jcS8jA0jhWA/tOGE842fHGm7q7qGu8xevNwll0PTsY8w0oOcqdMtUFA1lPgjloyp20w84pm/7bGZSGrjPVdMXhPD7Dz69ojhTTXp6c7Lui4GcSoCE5I/povQZ74= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Svmy+BAa; 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="Svmy+BAa" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C048C4AF0B; Fri, 7 Jun 2024 11:17:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717759044; bh=BOkJs2FsO7d8uNtY+3OezgdrS5yyqUklsYRb9p4/cHo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Svmy+BAae22V871Em27Q07St8n3Zp45mP38pOHn2sdeGOp+aegDS9xThazfLNUBLp 4n0aelZx370IJyIESbYe1hZ9t0MaDiRsVnNPChLQ9bSAf3U41/CCTTQkQpavrzIMV2 Rubx1i005loSncmH69UMt0V9LUotZmMtbXG5DfZNiJKuX0uk1S2p7aCOXoJuAQ/tMr 0bFbzCYlVvQ3sFYV26fi2aLYAqNFduHhBOxN5+yAVwgFy52xmuKmpTo89INm6x8EEW Yja5UWa6uMwr/UPL1lYKQBuoEMwf069HsxTNNxU+qX1PvCLarnYvOi1y6OgiSTeHfP 4kIgrsW+7HCFA== From: Borislav Petkov To: X86 ML Cc: LKML , "Borislav Petkov (AMD)" Subject: [PATCH v1 13/14] x86/alternative: Convert the asm ALTERNATIVE_3() macro Date: Fri, 7 Jun 2024 13:17:00 +0200 Message-ID: <20240607111701.8366-14-bp@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240607111701.8366-1-bp@kernel.org> References: <20240607111701.8366-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) Acked-by: Peter Zijlstra (Intel) --- 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 28e07a038964..5278cfb1f745 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -466,31 +466,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 Thu Feb 12 20:23:36 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 9CB151953AA for ; Fri, 7 Jun 2024 11:17:25 +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=1717759045; cv=none; b=JD+Pu9Q8T+nl0gTzwO0kl34xNEdikJWi8nbwfUA/YZFo6EB8RnG9KcHcY+VjazfxR1HXAyp3AZTbLNOT1wS+znYaEDwz42qgEqpBUiC7SCq1855TLDdtwfyCsPnSxTRwxyvuVYKx8jhx7orQOnzp/6lL+DSS+x1K7XQF7zDGy3I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717759045; c=relaxed/simple; bh=e9iRNryW1ZYwYrV88AUG4mS07yNvEDiLvNnz8sJJtyg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FRkUXDrxk9AMalOtZXJWcQa1zzWP9Qt+6eclmBElGQ4XSUmrQPAyrUW7YcwVeTyvlngqPQKFOTkmnLef0VNr5ntVeb3K6de1/fvkSM+d1KJpWTt4/kZfBJAlejrtLnKGii8m/kVu8wKTEST0x2YUSfn+4zMRmtEULKzJGnJxZo0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qIBKrS7b; 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="qIBKrS7b" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A3C1CC32786; Fri, 7 Jun 2024 11:17:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717759045; bh=e9iRNryW1ZYwYrV88AUG4mS07yNvEDiLvNnz8sJJtyg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qIBKrS7bvjY2/9q8qDAlQmYKB/WGKckmaprCJwDrAg3JkOn0RIPKzAtBfHXINr5Nm /TgYKbOrO17dv0+gY0CNXtVdIiT6QGShWMMRIiSJutz/eSYARjgMzroaQ/eE0QgbiL 0BN6YB7YkI4+859mfzSR28VxIHDqTwbMNM8g8dKeSDLxxwP7Jx7nzqc4ImIrQXAMxT Qy+B8AyPKk7td5XQgehbhE/FNjrlRn3cOupA+q7m6s9acMIkkkxi+VrWdH+sNp4QTg b2PVIg3oz+xTPRrTvnO7g1FayncNj1JMYWaqepAY+hwf8jM0cnDHyXIcwjnhS69AzP /+KD6khO/B//g== From: Borislav Petkov To: X86 ML Cc: LKML , "Borislav Petkov (AMD)" Subject: [PATCH v1 14/14] x86/alternative: Replace the old macros Date: Fri, 7 Jun 2024 13:17:01 +0200 Message-ID: <20240607111701.8366-15-bp@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240607111701.8366-1-bp@kernel.org> References: <20240607111701.8366-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) Acked-by: Peter Zijlstra (Intel) --- arch/x86/include/asm/alternative.h | 144 +++++++---------------------- 1 file changed, 32 insertions(+), 112 deletions(-) diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alte= rnative.h index 5278cfb1f745..4973edbe9289 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,12 +228,12 @@ 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 /* @@ -327,7 +247,7 @@ static inline int alternatives_text_reserved(void *star= t, void *end) * suffix. */ #define alternative_call(oldfunc, newfunc, ft_flags, output, input...) \ - asm_inline volatile(N_ALTERNATIVE("call %c[old]", "call %c[new]", ft_flag= s) \ + asm_inline volatile(ALTERNATIVE("call %c[old]", "call %c[new]", ft_flags)= \ : output : [old] "i" (oldfunc), [new] "i" (newfunc), ## input) =20 /* @@ -338,7 +258,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 %c[old]", "call %c[new1]", ft_f= lags1, \ + asm_inline volatile(ALTERNATIVE_2("call %c[old]", "call %c[new1]", ft_fla= gs1, \ "call %c[new2]", ft_flags2) \ : output, ASM_CALL_CONSTRAINT \ : [old] "i" (oldfunc), [new1] "i" (newfunc1), \ @@ -422,7 +342,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: \ @@ -438,7 +358,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 @@ -461,12 +381,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 --=20 2.43.0