From nobody Wed Dec 17 10:10:44 2025 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 E231716F8F5 for ; Fri, 28 Mar 2025 13:27: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=1743168446; cv=none; b=nkc2qLBnheECCt+LBPI8W6o7wKuFnILFfIaywc1CXoWsU9j+zQP5OlyvJkl30AhElDe1YXTFhGUw/dHvKqUiaAWM/UkJLsKwh8AcSZ+eWljMl5x2gclsx3n0tQ0g6LOGmZcIRyyto5v9ANdOoFg0cbygXpx51gAkYVP4+5gSQaY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168446; c=relaxed/simple; bh=rtowR0p5yc0zPA1Vl4ObrVmbHwWZEHknYKLd4kjcKNk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tszA6KfdgMX3cXyJk2Myj1CC2mF9E8UIneTQS5BtGX/eQ2vXOyBlDXex3dKkEgskdkGWuQpjbuGEgeTdr57GzXLbsIzac4UXMRWGvbeoQlfiZn0fnfeLNFMAJ+oFo8+a/9AMCjbY7OX/3wjeQI/9Tw0zc3U6iQHtZO6teP9APbw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=c9cPgOiU; 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="c9cPgOiU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71ECFC4CEEA; Fri, 28 Mar 2025 13:27:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168445; bh=rtowR0p5yc0zPA1Vl4ObrVmbHwWZEHknYKLd4kjcKNk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c9cPgOiUngpYs/Y3WJB9nIurZZ/zuLMWF5tdvsDInbBE0br+6iVsgshMX5PZaAARu cQ0NUG7aTs7r5nBhiQgR10heeRAbeXap2Zci6pKNfyYkI4Xg8AC3POOQ129fJ5hVAN otUScP1pmWsFfXH0DUk+hO/ZTNuKy2Ul05+9yDV2odwzR/YH0XifVEFT/wy7lUEJod AVrGzAb+/xSecjgSV1n74gWMKpZ3trN75qDtSKvSRq1DEW4khTvU4VwvKW6RAp0ZTC TIWb378ri0ND/kHi7UAq5tmxqXYSpi8a86mbNACWCNOkWX22ACz42Gsebp5p49m6XW 6PeYIf0OslOvw== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 01/49] x86/alternatives: Rename 'struct bp_patching_desc' to 'struct int3_patching_desc' Date: Fri, 28 Mar 2025 14:26:16 +0100 Message-ID: <20250328132704.1901674-2-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 5f448142aa99..4e932e95c744 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2471,17 +2471,17 @@ struct text_poke_loc { u8 old; }; =20 -struct bp_patching_desc { +struct int3_patching_desc { struct text_poke_loc *vec; int nr_entries; }; =20 static DEFINE_PER_CPU(atomic_t, bp_refs); =20 -static struct bp_patching_desc bp_desc; +static struct int3_patching_desc bp_desc; =20 static __always_inline -struct bp_patching_desc *try_get_desc(void) +struct int3_patching_desc *try_get_desc(void) { atomic_t *refs =3D this_cpu_ptr(&bp_refs); =20 @@ -2517,7 +2517,7 @@ static __always_inline int patch_cmp(const void *key,= const void *elt) =20 noinstr int poke_int3_handler(struct pt_regs *regs) { - struct bp_patching_desc *desc; + struct int3_patching_desc *desc; struct text_poke_loc *tp; int ret =3D 0; void *ip; --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 062C4187553 for ; Fri, 28 Mar 2025 13:27: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=1743168448; cv=none; b=HXVmCshO9IIE6woROqO9Y0Y/ciQSqBZRe32+fJ/3iYB/mOjAJY0hUSm7GfvaXfePISxaDC25K6eBRrN5l7lVXkSXg6OlDv/Sh3LCfTDOODPsGjguMipCJdce9OWo6WYJZu1//NIBR/+xP2qMOBXPQrSgx1yudPFV9DUKRc3iviw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168448; c=relaxed/simple; bh=eH4uwFqoC9JgVc1kv7VNnXR333bL5REyM/EgEQ04P/4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Pp3ferUTloX9Qjv9whcLT7HdTJ8uxM8LE86suh1dyXAt6gXwYBIJ9xkiA6wUkTmyFWYyDmbW/QLlaDkfCrRey+33gBMXungSb2u3w2rY3KackjKEbeWJzQjo6VYLtq2LY5yNbJfpkP6RS801WeKe+fk9A+Ld9+sc7nYgWZD7tT4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ePJKZ/P9; 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="ePJKZ/P9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E13C3C4CEE5; Fri, 28 Mar 2025 13:27:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168447; bh=eH4uwFqoC9JgVc1kv7VNnXR333bL5REyM/EgEQ04P/4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ePJKZ/P9dyz1VoMXkNDx7NK1NHbAJKW4iFYRrUbyzQZbi5TgrvEAuuXwcHdszxZfv df4LlX4wpxeAaprZ/S+Z3QU63HBXLZRhsTsjgEWDWAupq9w7QJPkf/RNwGSANTb/8B a0Ue/42zLtbgbtDrb/ryMgp4012HBPW73KDcVmYH0evc3l5nL7ivbJuO2g39oqytYx gDpO7+KHLUMbJnQ3vnOJ8fGJ1aY8VC0O5eTGUfUnMGqwWTvdXozrKtPmHARpRxdf7Z TpdFD+J6phc4o4LYWsRO0J4LaLXpY8v3vHjfjmXCc7RrfFdqELSsVow0fZwT1wwvB0 bwnO7MSBhgyiA== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 02/49] x86/alternatives: Rename 'bp_refs' to 'int3_refs' Date: Fri, 28 Mar 2025 14:26:17 +0100 Message-ID: <20250328132704.1901674-3-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 4e932e95c744..cb9ac69694fb 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2476,14 +2476,14 @@ struct int3_patching_desc { int nr_entries; }; =20 -static DEFINE_PER_CPU(atomic_t, bp_refs); +static DEFINE_PER_CPU(atomic_t, int3_refs); =20 static struct int3_patching_desc bp_desc; =20 static __always_inline struct int3_patching_desc *try_get_desc(void) { - atomic_t *refs =3D this_cpu_ptr(&bp_refs); + atomic_t *refs =3D this_cpu_ptr(&int3_refs); =20 if (!raw_atomic_inc_not_zero(refs)) return NULL; @@ -2493,7 +2493,7 @@ struct int3_patching_desc *try_get_desc(void) =20 static __always_inline void put_desc(void) { - atomic_t *refs =3D this_cpu_ptr(&bp_refs); + atomic_t *refs =3D this_cpu_ptr(&int3_refs); =20 smp_mb__before_atomic(); raw_atomic_dec(refs); @@ -2529,9 +2529,9 @@ noinstr int poke_int3_handler(struct pt_regs *regs) * Having observed our INT3 instruction, we now must observe * bp_desc with non-zero refcount: * - * bp_refs =3D 1 INT3 + * int3_refs =3D 1 INT3 * WMB RMB - * write INT3 if (bp_refs !=3D 0) + * write INT3 if (int3_refs !=3D 0) */ smp_rmb(); =20 @@ -2638,7 +2638,7 @@ static void text_poke_bp_batch(struct text_poke_loc *= tp, unsigned int nr_entries * ensure reading a non-zero refcount provides up to date bp_desc data. */ for_each_possible_cpu(i) - atomic_set_release(per_cpu_ptr(&bp_refs, i), 1); + atomic_set_release(per_cpu_ptr(&int3_refs, i), 1); =20 /* * Function tracing can enable thousands of places that need to be @@ -2760,7 +2760,7 @@ static void text_poke_bp_batch(struct text_poke_loc *= tp, unsigned int nr_entries * unused. */ for_each_possible_cpu(i) { - atomic_t *refs =3D per_cpu_ptr(&bp_refs, i); + atomic_t *refs =3D per_cpu_ptr(&int3_refs, i); =20 if (unlikely(!atomic_dec_and_test(refs))) atomic_cond_read_acquire(refs, !VAL); --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 DB25F1940A2 for ; Fri, 28 Mar 2025 13:27: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=1743168450; cv=none; b=sGPQr8K9MHqbiuPL9yN16MESxp+eFbCe585s9Q8tlo++gW4GncCmr1mhegUqcze7QKvTJzjH5WRgtjnp4eoKATTb0nbFGRDXqQvI/LpgvuBGyyJ64ddyhGqOoQRYpKnMiRzqmzWRhHPlcnted5Rj4bxmm/WDR4P8QiiNn01PoKs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168450; c=relaxed/simple; bh=7JfDcVoLgx2cHFr+F4A6UUUHRHLY28KYtLPQwaCZdD8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jET2cgY9UXX4DJK16M0FiJBuFFfB4JtlQkQgJLLQszk9U9MbiB3EgN6vnETX6XfCqSv1NvoJoRpiw2plqUGS2vbiA+aGDpw/aB/zulRw4uSNXfNgvAEtAZDQ4DCjrKik1vsPhcUYvuAE2rM1SUzOYdPHZz+4o8Y7qXKXV3dI/kA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=alPvwGcW; 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="alPvwGcW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5CB75C4CEE5; Fri, 28 Mar 2025 13:27:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168450; bh=7JfDcVoLgx2cHFr+F4A6UUUHRHLY28KYtLPQwaCZdD8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=alPvwGcWMAd0YE3HanXlMPA2Xywf033Kbq7EwjBhYwCLKbEa60Epe5BPvfJI8m+ku r9d79bEMiP0fbZQVTYTgYPGBjxDyL8efc/bzHsw76nzLilWK8z2GMjkG7LHN7wkJSn TcCudgX/PB16KmHpuPItYM0Z7LTPi5oCVZHQXGT/HFzFthkAjiBbdKWwUyu7Yfwfyj g83hB0PRtmnos7mvC3Bb4DANo/+rOD0QB2gc9HKCAWV44Q7KoTY8TvgDfS3GKYVQi7 fKnhYXFXkTuFOKO9oIBGSgmxWLRPh696uVYBL+XyNbR9Zdzk/IdSfrMY+T5mndHyOa CyUgkTikl6F5Q== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 03/49] x86/alternatives: Rename 'text_poke_bp_batch()' to 'smp_text_poke_batch_process()' Date: Fri, 28 Mar 2025 14:26:18 +0100 Message-ID: <20250328132704.1901674-4-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index cb9ac69694fb..7305c29bc8d1 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2467,7 +2467,7 @@ struct text_poke_loc { u8 len; u8 opcode; const u8 text[POKE_MAX_OPCODE_SIZE]; - /* see text_poke_bp_batch() */ + /* see smp_text_poke_batch_process() */ u8 old; }; =20 @@ -2540,7 +2540,7 @@ noinstr int poke_int3_handler(struct pt_regs *regs) return 0; =20 /* - * Discount the INT3. See text_poke_bp_batch(). + * Discount the INT3. See smp_text_poke_batch_process(). */ ip =3D (void *) regs->ip - INT3_INSN_SIZE; =20 @@ -2602,7 +2602,7 @@ static struct text_poke_loc tp_vec[TP_VEC_MAX]; static int tp_vec_nr; =20 /** - * text_poke_bp_batch() -- update instructions on live kernel on SMP + * smp_text_poke_batch_process() -- update instructions on live kernel on = SMP * @tp: vector of instructions to patch * @nr_entries: number of entries in the vector * @@ -2622,7 +2622,7 @@ static int tp_vec_nr; * replacing opcode * - sync cores */ -static void text_poke_bp_batch(struct text_poke_loc *tp, unsigned int nr_e= ntries) +static void smp_text_poke_batch_process(struct text_poke_loc *tp, unsigned= int nr_entries) { unsigned char int3 =3D INT3_INSN_OPCODE; unsigned int i; @@ -2866,7 +2866,7 @@ static bool tp_order_fail(void *addr) static void text_poke_flush(void *addr) { if (tp_vec_nr =3D=3D TP_VEC_MAX || tp_order_fail(addr)) { - text_poke_bp_batch(tp_vec, tp_vec_nr); + smp_text_poke_batch_process(tp_vec, tp_vec_nr); tp_vec_nr =3D 0; } } @@ -2902,5 +2902,5 @@ void __ref text_poke_bp(void *addr, const void *opcod= e, size_t len, const void * struct text_poke_loc tp; =20 text_poke_loc_init(&tp, addr, opcode, len, emulate); - text_poke_bp_batch(&tp, 1); + smp_text_poke_batch_process(&tp, 1); } --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 E1CCC1A3056 for ; Fri, 28 Mar 2025 13:27: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=1743168453; cv=none; b=gXBcKpVocpk1h5zRJbSBGVQUGcIG963+RvZJdsrDE7LSOEc8RJ1gkRle8dP9VNjeb217V/kOpknwkMPd5mnnraMjO4cql/MKPJXWAnAdy6iWcUYkSBk19zIn3swGgHz06F+7j4et7AU/gfX/NDgR9gt6C7CGGN7xTfYN0F7abKA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168453; c=relaxed/simple; bh=LiVUqAsMJ48dPQzAGR8ehSep4rPRAWG0dcSro6dk7pQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XAkmalpC4P7FeBJ0qaXaxCBlT9/Tf8IL50Fzj0/BqO6qFxNxeThx36tM4rog6mdIH1zIob7LloEFP6BcX3nC8IvpEQEnnjAaJQGth+/mLuXmprggq3WyBw5BV266dPGx66xzVqidXeIDRtgiNJCWHjxDt9Rvqt9pXwGiF97DUdg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nvf17xLJ; 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="nvf17xLJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CCB8BC4CEE4; Fri, 28 Mar 2025 13:27:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168452; bh=LiVUqAsMJ48dPQzAGR8ehSep4rPRAWG0dcSro6dk7pQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nvf17xLJHo6IjjafQpXwJ4Mt8F/OHUJNEnEj4mPeEt81sk7KzHALGFf76O1N75e46 YmHtfsAxrOupALyaqmVmqeUiz9IbV/sIYDnI+OCveA+o9Jffheh9PuL8iFIEPHvdyu fxZX8AQfqrXT5EdYvuaZvFyk9V/SNowKkk2RzCWJkzY61QG1IkJ8vvHfshPYqdgwBo IFreybiTc0L+XmTf09KYRN2qy29QKBp/fWdAhUxknirbtMo+/oDstCFIlPH52u9+6A LJCz3dpmtb7WRoZEBtyE0EjqZ2n1Ri78kc619sc4/Y3aAfrlt18fUGX19C11Az86B4 ztZ0F8UvPIbsw== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 04/49] x86/alternatives: Rename 'text_poke_bp()' to 'smp_text_poke_single()' Date: Fri, 28 Mar 2025 14:26:19 +0100 Message-ID: <20250328132704.1901674-5-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" Signed-off-by: Ingo Molnar --- arch/x86/include/asm/text-patching.h | 2 +- arch/x86/kernel/alternative.c | 4 ++-- arch/x86/kernel/ftrace.c | 8 ++++---- arch/x86/kernel/jump_label.c | 2 +- arch/x86/kernel/kprobes/opt.c | 2 +- arch/x86/kernel/static_call.c | 2 +- arch/x86/net/bpf_jit_comp.c | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/arch/x86/include/asm/text-patching.h b/arch/x86/include/asm/te= xt-patching.h index ab9e143ec9fe..5189188b5e49 100644 --- a/arch/x86/include/asm/text-patching.h +++ b/arch/x86/include/asm/text-patching.h @@ -39,7 +39,7 @@ extern void *text_poke_copy(void *addr, const void *opcod= e, size_t len); extern void *text_poke_copy_locked(void *addr, const void *opcode, size_t = len, bool core_ok); extern void *text_poke_set(void *addr, int c, size_t len); extern int poke_int3_handler(struct pt_regs *regs); -extern void text_poke_bp(void *addr, const void *opcode, size_t len, const= void *emulate); +extern void smp_text_poke_single(void *addr, const void *opcode, size_t le= n, const void *emulate); =20 extern void text_poke_queue(void *addr, const void *opcode, size_t len, co= nst void *emulate); extern void text_poke_finish(void); diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 7305c29bc8d1..826c389b22eb 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2887,7 +2887,7 @@ void __ref text_poke_queue(void *addr, const void *op= code, size_t len, const voi } =20 /** - * text_poke_bp() -- update instructions on live kernel on SMP + * smp_text_poke_single() -- update instructions on live kernel on SMP * @addr: address to patch * @opcode: opcode of new instruction * @len: length to copy @@ -2897,7 +2897,7 @@ void __ref text_poke_queue(void *addr, const void *op= code, size_t len, const voi * dynamically allocated memory. This function should be used when it is * not possible to allocate memory. */ -void __ref text_poke_bp(void *addr, const void *opcode, size_t len, const = void *emulate) +void __ref smp_text_poke_single(void *addr, const void *opcode, size_t len= , const void *emulate) { struct text_poke_loc tp; =20 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c index cace6e8d7cc7..7175a0404def 100644 --- a/arch/x86/kernel/ftrace.c +++ b/arch/x86/kernel/ftrace.c @@ -186,11 +186,11 @@ int ftrace_update_ftrace_func(ftrace_func_t func) =20 ip =3D (unsigned long)(&ftrace_call); new =3D ftrace_call_replace(ip, (unsigned long)func); - text_poke_bp((void *)ip, new, MCOUNT_INSN_SIZE, NULL); + smp_text_poke_single((void *)ip, new, MCOUNT_INSN_SIZE, NULL); =20 ip =3D (unsigned long)(&ftrace_regs_call); new =3D ftrace_call_replace(ip, (unsigned long)func); - text_poke_bp((void *)ip, new, MCOUNT_INSN_SIZE, NULL); + smp_text_poke_single((void *)ip, new, MCOUNT_INSN_SIZE, NULL); =20 return 0; } @@ -492,7 +492,7 @@ void arch_ftrace_update_trampoline(struct ftrace_ops *o= ps) mutex_lock(&text_mutex); /* Do a safe modify in case the trampoline is executing */ new =3D ftrace_call_replace(ip, (unsigned long)func); - text_poke_bp((void *)ip, new, MCOUNT_INSN_SIZE, NULL); + smp_text_poke_single((void *)ip, new, MCOUNT_INSN_SIZE, NULL); mutex_unlock(&text_mutex); } =20 @@ -586,7 +586,7 @@ static int ftrace_mod_jmp(unsigned long ip, void *func) const char *new; =20 new =3D ftrace_jmp_replace(ip, (unsigned long)func); - text_poke_bp((void *)ip, new, MCOUNT_INSN_SIZE, NULL); + smp_text_poke_single((void *)ip, new, MCOUNT_INSN_SIZE, NULL); return 0; } =20 diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c index f5b8ef02d172..166e12037199 100644 --- a/arch/x86/kernel/jump_label.c +++ b/arch/x86/kernel/jump_label.c @@ -102,7 +102,7 @@ __jump_label_transform(struct jump_entry *entry, return; } =20 - text_poke_bp((void *)jump_entry_code(entry), jlp.code, jlp.size, NULL); + smp_text_poke_single((void *)jump_entry_code(entry), jlp.code, jlp.size, = NULL); } =20 static void __ref jump_label_transform(struct jump_entry *entry, diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c index 36d6809c6c9e..9307a40f4983 100644 --- a/arch/x86/kernel/kprobes/opt.c +++ b/arch/x86/kernel/kprobes/opt.c @@ -488,7 +488,7 @@ void arch_optimize_kprobes(struct list_head *oplist) insn_buff[0] =3D JMP32_INSN_OPCODE; *(s32 *)(&insn_buff[1]) =3D rel; =20 - text_poke_bp(op->kp.addr, insn_buff, JMP32_INSN_SIZE, NULL); + smp_text_poke_single(op->kp.addr, insn_buff, JMP32_INSN_SIZE, NULL); =20 list_del_init(&op->list); } diff --git a/arch/x86/kernel/static_call.c b/arch/x86/kernel/static_call.c index 9e51242ed125..ca6c90d89407 100644 --- a/arch/x86/kernel/static_call.c +++ b/arch/x86/kernel/static_call.c @@ -108,7 +108,7 @@ static void __ref __static_call_transform(void *insn, e= num insn_type type, if (system_state =3D=3D SYSTEM_BOOTING || modinit) return text_poke_early(insn, code, size); =20 - text_poke_bp(insn, code, size, emulate); + smp_text_poke_single(insn, code, size, emulate); } =20 static void __static_call_validate(u8 *insn, bool tail, bool tramp) diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c index 72776dcb75aa..a6b650909c08 100644 --- a/arch/x86/net/bpf_jit_comp.c +++ b/arch/x86/net/bpf_jit_comp.c @@ -629,7 +629,7 @@ static int __bpf_arch_text_poke(void *ip, enum bpf_text= _poke_type t, goto out; ret =3D 1; if (memcmp(ip, new_insn, X86_PATCH_SIZE)) { - text_poke_bp(ip, new_insn, X86_PATCH_SIZE, NULL); + smp_text_poke_single(ip, new_insn, X86_PATCH_SIZE, NULL); ret =3D 0; } out: --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 60E921AD3E5 for ; Fri, 28 Mar 2025 13:27:35 +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=1743168455; cv=none; b=MvR8e4hq/6sqNfvW1qkH9tu6DIFJ/uOpJsDBL77YDopNgPyBbBY6KJ6WrYzQiob6sa3jiDBzp9djUGakWbLpbJnPEK/3ItW2iGvq8rcc8K0Jqf7DWfqDJ6Uk51lYMQIqj1oj3qFf2JM7etlCfJnSNb6im+204px+yjII8v27NgA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168455; c=relaxed/simple; bh=8DvdvOWy2kLAuTbQliXx0Rh+mCp0ZmFREu6YLMZjsPY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P/CxStG0t6VkngWhRLDOvGISSP09bfpYZHtYqXdo1tetykPDjHgU8g8JhyDWXWDYH0WyIIm6j+40JeHKwTGe84xtT7dS7lSsXi0i7clf8LcSEXNHiukxDHq06QiNVZcHum7+cM2hSls3FtA02BhIDW/dvSxLHxHpJENYJCvEhDA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nIHZ62c5; 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="nIHZ62c5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46952C4CEE5; Fri, 28 Mar 2025 13:27:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168455; bh=8DvdvOWy2kLAuTbQliXx0Rh+mCp0ZmFREu6YLMZjsPY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nIHZ62c5o1AZUn4vWh8rtBStwGp+TEmyccdkFJYdwBTOA8moAjrrUP8C8c6AHWG0+ jiHDj/CFPU6Zghmkv+0aI0a57y/Ozp8PQRqnNxvzw+prmZzCDgBvcTHnW0DIOh81LL Uy4EJwUxrfBxmgfCp9DOozYT+Eyr4sYDBwd9JfSk5vucJuOcAtGX+32rALmLeDlBgA 4pxJ54a3wUb76mxtjNjs/kAgu0Ls1xHLCAXG7S5pW3+X211j8VyxLJkCv6e21EZchb zDME/g5wpvbhekb629pfwN7549kQ4uaFepMP6r/JrFsNXFa/oCDJnZh36V5krsdaq+ u1PN5LDqDeznw== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 05/49] x86/alternatives: Rename 'poke_int3_handler()' to 'smp_text_poke_int3_trap_handler()' Date: Fri, 28 Mar 2025 14:26:20 +0100 Message-ID: <20250328132704.1901674-6-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" All related functions in this subsystem already have a text_poke_int3_ prefix - add it to the trap handler as well. Signed-off-by: Ingo Molnar --- arch/x86/include/asm/text-patching.h | 2 +- arch/x86/kernel/alternative.c | 2 +- arch/x86/kernel/traps.c | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/text-patching.h b/arch/x86/include/asm/te= xt-patching.h index 5189188b5e49..42eb607c8629 100644 --- a/arch/x86/include/asm/text-patching.h +++ b/arch/x86/include/asm/text-patching.h @@ -38,7 +38,7 @@ extern void *text_poke_copy(void *addr, const void *opcod= e, size_t len); #define text_poke_copy text_poke_copy extern void *text_poke_copy_locked(void *addr, const void *opcode, size_t = len, bool core_ok); extern void *text_poke_set(void *addr, int c, size_t len); -extern int poke_int3_handler(struct pt_regs *regs); +extern int smp_text_poke_int3_trap_handler(struct pt_regs *regs); extern void smp_text_poke_single(void *addr, const void *opcode, size_t le= n, const void *emulate); =20 extern void text_poke_queue(void *addr, const void *opcode, size_t len, co= nst void *emulate); diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 826c389b22eb..e4c97c39eda1 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2515,7 +2515,7 @@ static __always_inline int patch_cmp(const void *key,= const void *elt) return 0; } =20 -noinstr int poke_int3_handler(struct pt_regs *regs) +noinstr int smp_text_poke_int3_trap_handler(struct pt_regs *regs) { struct int3_patching_desc *desc; struct text_poke_loc *tp; diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index 9f88b8a78e50..e84fdc39de6a 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -882,16 +882,16 @@ static void do_int3_user(struct pt_regs *regs) DEFINE_IDTENTRY_RAW(exc_int3) { /* - * poke_int3_handler() is completely self contained code; it does (and + * smp_text_poke_int3_trap_handler() is completely self contained code; i= t does (and * must) *NOT* call out to anything, lest it hits upon yet another * INT3. */ - if (poke_int3_handler(regs)) + if (smp_text_poke_int3_trap_handler(regs)) return; =20 /* * irqentry_enter_from_user_mode() uses static_branch_{,un}likely() - * and therefore can trigger INT3, hence poke_int3_handler() must + * and therefore can trigger INT3, hence smp_text_poke_int3_trap_handler(= ) must * be done before. If the entry came from kernel mode, then use * nmi_enter() because the INT3 could have been hit in any context * including NMI. --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 44EA61B6556 for ; Fri, 28 Mar 2025 13:27:37 +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=1743168458; cv=none; b=Lvt6P1oU2WjoTQi2UgVrA8vSkgoHC+c7gGk3AF8WvkxUzk9KHaoEwxNu/FDb/qM7iTbajFu/2aSr4g6TGmEUPgDezzDeUSTIGlyuiijgwivQBhJZzD/Qp+k3PEUSXg5remdKAHgb9EEOTOacxzfQmNxB72YNFvjh9/N5RLEzyHY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168458; c=relaxed/simple; bh=8o6K40ijblzs8OnbnRHq/Lq5frgDQwlgFuhwMQhHKZ8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MP5MFJpXwTJQ+nhQ5HiYMLPOHUtbMmkbJYUJwn/6anNMCgIkq8C4pPwyrp86Wo9Z2D71uj+Dr31rGPXphLxYyE0jOALLw9YX+BxbymB87rSohKfZpAH4yhsph5dJrv6sla+V+hwNUJ9ELH7/OkFQULzZDV3nBAI3GGU+ZILN01c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=W1jXlEeW; 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="W1jXlEeW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B44CCC4CEEA; Fri, 28 Mar 2025 13:27:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168457; bh=8o6K40ijblzs8OnbnRHq/Lq5frgDQwlgFuhwMQhHKZ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W1jXlEeWcNq4IdRxNFLoE/UFqy8WdNXid6xioawOlNVXfiaFFU4qjhg7hu8ndYNI6 bOCMWHUnUY8rBNotL7IC4TR5LufIzMlwqQoidlk1vTokSCPXmoYJll/EcUac4mht9K LI+cDXm5ISQ/S7HPnXKrK1EZav6Yw+cqXiGWdwKr/bD2OZj6QY1reJsA3k/+yrBZ9G FutcstOqOCV81k9o8hE8xqBt+daUACU0rVZFhe05faLEkNqsJXTgaJPtDqUNZS0hmr phMzsq12P/2cz+9YsENhkazheXc3WWGbdmNT6Yn7XhgHuis35yvx5ctht9d5DO58cB 3RpJFbCFP75pw== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 06/49] x86/alternatives: Rename 'poking_mm' to 'text_poke_mm' Date: Fri, 28 Mar 2025 14:26:21 +0100 Message-ID: <20250328132704.1901674-7-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" Put it into the text_poke_* namespace of . Signed-off-by: Ingo Molnar --- arch/x86/include/asm/text-patching.h | 2 +- arch/x86/kernel/alternative.c | 18 +++++++++--------- arch/x86/mm/init.c | 8 ++++---- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/arch/x86/include/asm/text-patching.h b/arch/x86/include/asm/te= xt-patching.h index 42eb607c8629..afff3d886e30 100644 --- a/arch/x86/include/asm/text-patching.h +++ b/arch/x86/include/asm/text-patching.h @@ -128,7 +128,7 @@ void *text_gen_insn(u8 opcode, const void *addr, const = void *dest) } =20 extern int after_bootmem; -extern __ro_after_init struct mm_struct *poking_mm; +extern __ro_after_init struct mm_struct *text_poke_mm; extern __ro_after_init unsigned long poking_addr; =20 #ifndef CONFIG_UML_X86 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index e4c97c39eda1..01e2c42e45a2 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2191,7 +2191,7 @@ static inline temp_mm_state_t use_temporary_mm(struct= mm_struct *mm) return temp_state; } =20 -__ro_after_init struct mm_struct *poking_mm; +__ro_after_init struct mm_struct *text_poke_mm; __ro_after_init unsigned long poking_addr; =20 static inline void unuse_temporary_mm(temp_mm_state_t prev_state) @@ -2201,7 +2201,7 @@ static inline void unuse_temporary_mm(temp_mm_state_t= prev_state) switch_mm_irqs_off(NULL, prev_state.mm, current); =20 /* Clear the cpumask, to indicate no TLB flushing is needed anywhere */ - cpumask_clear_cpu(raw_smp_processor_id(), mm_cpumask(poking_mm)); + cpumask_clear_cpu(raw_smp_processor_id(), mm_cpumask(text_poke_mm)); =20 /* * Restore the breakpoints if they were disabled before the temporary mm @@ -2266,7 +2266,7 @@ static void *__text_poke(text_poke_f func, void *addr= , const void *src, size_t l /* * The lock is not really needed, but this allows to avoid open-coding. */ - ptep =3D get_locked_pte(poking_mm, poking_addr, &ptl); + ptep =3D get_locked_pte(text_poke_mm, poking_addr, &ptl); =20 /* * This must not fail; preallocated in poking_init(). @@ -2276,18 +2276,18 @@ static void *__text_poke(text_poke_f func, void *ad= dr, const void *src, size_t l local_irq_save(flags); =20 pte =3D mk_pte(pages[0], pgprot); - set_pte_at(poking_mm, poking_addr, ptep, pte); + set_pte_at(text_poke_mm, poking_addr, ptep, pte); =20 if (cross_page_boundary) { pte =3D mk_pte(pages[1], pgprot); - set_pte_at(poking_mm, poking_addr + PAGE_SIZE, ptep + 1, pte); + set_pte_at(text_poke_mm, poking_addr + PAGE_SIZE, ptep + 1, pte); } =20 /* * Loading the temporary mm behaves as a compiler barrier, which * guarantees that the PTE will be set at the time memcpy() is done. */ - prev =3D use_temporary_mm(poking_mm); + prev =3D use_temporary_mm(text_poke_mm); =20 kasan_disable_current(); func((u8 *)poking_addr + offset_in_page(addr), src, len); @@ -2299,9 +2299,9 @@ static void *__text_poke(text_poke_f func, void *addr= , const void *src, size_t l */ barrier(); =20 - pte_clear(poking_mm, poking_addr, ptep); + pte_clear(text_poke_mm, poking_addr, ptep); if (cross_page_boundary) - pte_clear(poking_mm, poking_addr + PAGE_SIZE, ptep + 1); + pte_clear(text_poke_mm, poking_addr + PAGE_SIZE, ptep + 1); =20 /* * Loading the previous page-table hierarchy requires a serializing @@ -2314,7 +2314,7 @@ static void *__text_poke(text_poke_f func, void *addr= , const void *src, size_t l * Flushing the TLB might involve IPIs, which would require enabled * IRQs, but not if the mm is not used, as it is in this point. */ - flush_tlb_mm_range(poking_mm, poking_addr, poking_addr + + flush_tlb_mm_range(text_poke_mm, poking_addr, poking_addr + (cross_page_boundary ? 2 : 1) * PAGE_SIZE, PAGE_SHIFT, false); =20 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c index bfa444a7dbb0..84b52a1ebd48 100644 --- a/arch/x86/mm/init.c +++ b/arch/x86/mm/init.c @@ -824,11 +824,11 @@ void __init poking_init(void) spinlock_t *ptl; pte_t *ptep; =20 - poking_mm =3D mm_alloc(); - BUG_ON(!poking_mm); + text_poke_mm =3D mm_alloc(); + BUG_ON(!text_poke_mm); =20 /* Xen PV guests need the PGD to be pinned. */ - paravirt_enter_mmap(poking_mm); + paravirt_enter_mmap(text_poke_mm); =20 /* * Randomize the poking address, but make sure that the following page @@ -848,7 +848,7 @@ void __init poking_init(void) * needed for poking now. Later, poking may be performed in an atomic * section, which might cause allocation to fail. */ - ptep =3D get_locked_pte(poking_mm, poking_addr, &ptl); + ptep =3D get_locked_pte(text_poke_mm, poking_addr, &ptl); BUG_ON(!ptep); pte_unmap_unlock(ptep, ptl); } --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 456D51531C5 for ; Fri, 28 Mar 2025 13:27:40 +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=1743168460; cv=none; b=Pbsr5+SGK1D5gdCjMSN3DF2gVj4GRaUBXcqdoucHfWGs3G+i3mEB+4ptFxA3YBQ+pchhzHgNPKTKGju5yxdXJoCYOj4KXE33wXeY+KZgp3f3zJ7TfdDB/Xy9QoV6c5TIehUAR9er1/NpAF4oTBGdX6SI2Jo9NTZzh4Vhv225K+E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168460; c=relaxed/simple; bh=rAe8xeIXLCa8fbzLU2IW+KrBlhrO0Yyq2mSGqwMYCNY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XIWFA4cWx1FR+QDfTBThiN2O2ayN9mBe5uzvxnOBExxPkIGVF0ZzvGHp3mmRMDIDtnGHxzwKcmgrOZuZeglP0xjptHTjHOaMMgSVYl2otdD2JjXlg+gHBjr8WR4HONl3GjhJUsCA3/RJP1KoxUzwayuwZp38dDPABptXU5BGDHU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rFplQq/G; 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="rFplQq/G" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E371C4CEEE; Fri, 28 Mar 2025 13:27:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168460; bh=rAe8xeIXLCa8fbzLU2IW+KrBlhrO0Yyq2mSGqwMYCNY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rFplQq/GvRTwI+YM9NEuRwTmSWYJPdK+CspDtvqgMMTakfWqrzwiZBsa+2zhxQCEc LRP25OvIS9ZorDwmcKgHTLgqMKWehy+CWGaklbK5VenP3CXAJx/PkHc3/UbtHeqnK+ AYqoVEcVlm4ZuubDNI2eq5aOcZ8+0EqNvjlsJ52sMQ1dFUXhtresCclyFiOVabxDCT N4RfgiW+yATCdPh/oaTETRuV3SWfqbSkMtPbVFKzZPEUtiAEbHFsbCvTJWdW9IE5N1 Fy+84ljZDxZDKfhMBYy/4F1ZadevLGdh/dso6c8EQU9w0CaD1THc6Qy8AdLDxos+SC KCMzq3OA1UH8A== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 07/49] x86/alternatives: Rename 'poking_addr' to 'text_poke_mm_addr' Date: Fri, 28 Mar 2025 14:26:22 +0100 Message-ID: <20250328132704.1901674-8-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" Put it into the text_poke_* namespace of . Signed-off-by: Ingo Molnar --- arch/x86/include/asm/text-patching.h | 2 +- arch/x86/kernel/alternative.c | 16 ++++++++-------- arch/x86/mm/init.c | 10 +++++----- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/arch/x86/include/asm/text-patching.h b/arch/x86/include/asm/te= xt-patching.h index afff3d886e30..7f296a05c5fe 100644 --- a/arch/x86/include/asm/text-patching.h +++ b/arch/x86/include/asm/text-patching.h @@ -129,7 +129,7 @@ void *text_gen_insn(u8 opcode, const void *addr, const = void *dest) =20 extern int after_bootmem; extern __ro_after_init struct mm_struct *text_poke_mm; -extern __ro_after_init unsigned long poking_addr; +extern __ro_after_init unsigned long text_poke_mm_addr; =20 #ifndef CONFIG_UML_X86 static __always_inline diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 01e2c42e45a2..e26fa6d9f133 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2192,7 +2192,7 @@ static inline temp_mm_state_t use_temporary_mm(struct= mm_struct *mm) } =20 __ro_after_init struct mm_struct *text_poke_mm; -__ro_after_init unsigned long poking_addr; +__ro_after_init unsigned long text_poke_mm_addr; =20 static inline void unuse_temporary_mm(temp_mm_state_t prev_state) { @@ -2266,7 +2266,7 @@ static void *__text_poke(text_poke_f func, void *addr= , const void *src, size_t l /* * The lock is not really needed, but this allows to avoid open-coding. */ - ptep =3D get_locked_pte(text_poke_mm, poking_addr, &ptl); + ptep =3D get_locked_pte(text_poke_mm, text_poke_mm_addr, &ptl); =20 /* * This must not fail; preallocated in poking_init(). @@ -2276,11 +2276,11 @@ static void *__text_poke(text_poke_f func, void *ad= dr, const void *src, size_t l local_irq_save(flags); =20 pte =3D mk_pte(pages[0], pgprot); - set_pte_at(text_poke_mm, poking_addr, ptep, pte); + set_pte_at(text_poke_mm, text_poke_mm_addr, ptep, pte); =20 if (cross_page_boundary) { pte =3D mk_pte(pages[1], pgprot); - set_pte_at(text_poke_mm, poking_addr + PAGE_SIZE, ptep + 1, pte); + set_pte_at(text_poke_mm, text_poke_mm_addr + PAGE_SIZE, ptep + 1, pte); } =20 /* @@ -2290,7 +2290,7 @@ static void *__text_poke(text_poke_f func, void *addr= , const void *src, size_t l prev =3D use_temporary_mm(text_poke_mm); =20 kasan_disable_current(); - func((u8 *)poking_addr + offset_in_page(addr), src, len); + func((u8 *)text_poke_mm_addr + offset_in_page(addr), src, len); kasan_enable_current(); =20 /* @@ -2299,9 +2299,9 @@ static void *__text_poke(text_poke_f func, void *addr= , const void *src, size_t l */ barrier(); =20 - pte_clear(text_poke_mm, poking_addr, ptep); + pte_clear(text_poke_mm, text_poke_mm_addr, ptep); if (cross_page_boundary) - pte_clear(text_poke_mm, poking_addr + PAGE_SIZE, ptep + 1); + pte_clear(text_poke_mm, text_poke_mm_addr + PAGE_SIZE, ptep + 1); =20 /* * Loading the previous page-table hierarchy requires a serializing @@ -2314,7 +2314,7 @@ static void *__text_poke(text_poke_f func, void *addr= , const void *src, size_t l * Flushing the TLB might involve IPIs, which would require enabled * IRQs, but not if the mm is not used, as it is in this point. */ - flush_tlb_mm_range(text_poke_mm, poking_addr, poking_addr + + flush_tlb_mm_range(text_poke_mm, text_poke_mm_addr, text_poke_mm_addr + (cross_page_boundary ? 2 : 1) * PAGE_SIZE, PAGE_SHIFT, false); =20 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c index 84b52a1ebd48..f8c74d19bebb 100644 --- a/arch/x86/mm/init.c +++ b/arch/x86/mm/init.c @@ -835,20 +835,20 @@ void __init poking_init(void) * will be mapped at the same PMD. We need 2 pages, so find space for 3, * and adjust the address if the PMD ends after the first one. */ - poking_addr =3D TASK_UNMAPPED_BASE; + text_poke_mm_addr =3D TASK_UNMAPPED_BASE; if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) - poking_addr +=3D (kaslr_get_random_long("Poking") & PAGE_MASK) % + text_poke_mm_addr +=3D (kaslr_get_random_long("Poking") & PAGE_MASK) % (TASK_SIZE - TASK_UNMAPPED_BASE - 3 * PAGE_SIZE); =20 - if (((poking_addr + PAGE_SIZE) & ~PMD_MASK) =3D=3D 0) - poking_addr +=3D PAGE_SIZE; + if (((text_poke_mm_addr + PAGE_SIZE) & ~PMD_MASK) =3D=3D 0) + text_poke_mm_addr +=3D PAGE_SIZE; =20 /* * We need to trigger the allocation of the page-tables that will be * needed for poking now. Later, poking may be performed in an atomic * section, which might cause allocation to fail. */ - ptep =3D get_locked_pte(text_poke_mm, poking_addr, &ptl); + ptep =3D get_locked_pte(text_poke_mm, text_poke_mm_addr, &ptl); BUG_ON(!ptep); pte_unmap_unlock(ptep, ptl); } --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 34E4E176AA1 for ; Fri, 28 Mar 2025 13:27:42 +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=1743168463; cv=none; b=aBwCCsDlIwQwwO6JfHaakmbjL5EUDQ5Tw9LZzofMjsLsWssZpaYPB0txPuIpozKvjuhPpTe3zV78F3m1uLihk/Yyr8b0sGlPmIaxb15uNO0MgbbL7OUnUWyBBMLMiSivXPBoK4iOID6B17UHUzrw20JakZ7M3ur6jPpm5wK4xik= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168463; c=relaxed/simple; bh=GE8HeLZucU92UNsXstVw9MZxxtj1Yl1kqraUQSeAw60=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CRNDbwPYxsW+X7iu3SVh6HFl1ZO58xTcMmNSST4K3yHGb/umkaHfoDbKHM5OGy3xbSmlYecfoGg+Pg8GBAqRM/adFt27c+4/793YQ4HXnk+BCjai+Q3kYYsuD9+5cOQ12RLrExy/qVUaxxxMguq2rZk+YWzfX3b9Ig7sG9AcWDY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=C9ybskcl; 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="C9ybskcl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9CE69C4CEEB; Fri, 28 Mar 2025 13:27:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168462; bh=GE8HeLZucU92UNsXstVw9MZxxtj1Yl1kqraUQSeAw60=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C9ybskclZ7nuDJVEH9lzo5+5sZDBuhUkjBO2DFVWVMPH9ht5rfuwkzCsfdIyhQUE5 9B4YYo/QofLy1myGdQItfygmqh3Se6tQ1F0pn471BpKAJmXboiHkTFOVBPtiWKllYf 85LYbkQumqb19FDYd1BYSNIUt4xHS/XqdqwcGnN8A2V+EeQPXwaI+Tba9n8o0Aku6A tu2R8jMGoMx/3SRa8le43aTaGY8mburu63NLE0dDLOZHpuhOAisrgpsLB9qBw18Ntd HvtJPmR9qOvaQKkbpY7+5Y2Tj808AqFzwJOEQslR46cQZREJ+cg0U4tIgqFnNB0ju3 DXokTCfcEWx8g== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 08/49] x86/alternatives: Rename 'bp_desc' to 'int3_desc' Date: Fri, 28 Mar 2025 14:26:23 +0100 Message-ID: <20250328132704.1901674-9-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index e26fa6d9f133..4aa407af8648 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2478,7 +2478,7 @@ struct int3_patching_desc { =20 static DEFINE_PER_CPU(atomic_t, int3_refs); =20 -static struct int3_patching_desc bp_desc; +static struct int3_patching_desc int3_desc; =20 static __always_inline struct int3_patching_desc *try_get_desc(void) @@ -2488,7 +2488,7 @@ struct int3_patching_desc *try_get_desc(void) if (!raw_atomic_inc_not_zero(refs)) return NULL; =20 - return &bp_desc; + return &int3_desc; } =20 static __always_inline void put_desc(void) @@ -2527,7 +2527,7 @@ noinstr int smp_text_poke_int3_trap_handler(struct pt= _regs *regs) =20 /* * Having observed our INT3 instruction, we now must observe - * bp_desc with non-zero refcount: + * int3_desc with non-zero refcount: * * int3_refs =3D 1 INT3 * WMB RMB @@ -2630,12 +2630,12 @@ static void smp_text_poke_batch_process(struct text= _poke_loc *tp, unsigned int n =20 lockdep_assert_held(&text_mutex); =20 - bp_desc.vec =3D tp; - bp_desc.nr_entries =3D nr_entries; + int3_desc.vec =3D tp; + int3_desc.nr_entries =3D nr_entries; =20 /* * Corresponds to the implicit memory barrier in try_get_desc() to - * ensure reading a non-zero refcount provides up to date bp_desc data. + * ensure reading a non-zero refcount provides up to date int3_desc data. */ for_each_possible_cpu(i) atomic_set_release(per_cpu_ptr(&int3_refs, i), 1); --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 94A561C0DED for ; Fri, 28 Mar 2025 13:27:45 +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=1743168465; cv=none; b=BgUJVHAeQZbIt4zM76U7UKm4Q0PnUhx73GyP0/WRERDDlUtmg4zU+Lk1r42t3U8U+du/yR58I+gcWvgEhJB6X+IMm0BGsQ0a8BHa7CSV17p3qtaT1ad0RUob39NcdqtS3N/vLTfy/HEi5yvRAKQabTe2fvtKVMzIj+ezAds32aQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168465; c=relaxed/simple; bh=hO8sGOUVr2S9ao7ZDOeqVbU0PtZL6iu3l8o/IHmYucM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HWVMxF7Yf0dIpukMz9q804GSYHMtxnANpYWfwzn+Kh0060flRtW5nMrE1o4mn5SXhapu4igRyQhkQAbrTK8IV+ZfSQgS7mCGTAYmLHa1mqoYjtfdhFUBWcKafOXgSicsYVqRu2KeuOIVSGWZFq+68yQgOKSIZZ0Xh1hEwR0Wf8Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=U0Ud4n3Y; 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="U0Ud4n3Y" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19323C4CEE4; Fri, 28 Mar 2025 13:27:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168465; bh=hO8sGOUVr2S9ao7ZDOeqVbU0PtZL6iu3l8o/IHmYucM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U0Ud4n3Y/wqNMXLuP3pft6F3fVQ0zWzInHdLIi1/orIFTjjuAZxdUT/kZv5JJkPAA 6itZ/o6OA+IQ8cZL4KknJIZkY8sJ841zukjP1MOyT8TMJwDQ0VBLLgwG40W7YLgbcT JwDovzdwt66SrtQIPXw0sBHDn8GmgSfatcTuA7eRz7NGbn2lQ8cSZszhuSr7+vdqGi z/YMqHPaFIHzFvQlU4wxuKsENYbmb5eHLgQYVoYxCZyNsSq5Gsz0KIIjKTl81BCLT6 eGYMfN+34CqyoE4rbNGAudAtjJaEj1zHhl5HlVZ0EbPbi8vG3dpoTb1qMOZbKcQVdT OB49hPyaNpdlg== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 09/49] x86/alternatives: Remove duplicate 'text_poke_early()' prototype Date: Fri, 28 Mar 2025 14:26:24 +0100 Message-ID: <20250328132704.1901674-10-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" It's declared in already. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 4aa407af8648..056872aebe6e 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -176,7 +176,6 @@ extern s32 __return_sites[], __return_sites_end[]; extern s32 __cfi_sites[], __cfi_sites_end[]; extern s32 __ibt_endbr_seal[], __ibt_endbr_seal_end[]; extern s32 __smp_locks[], __smp_locks_end[]; -void text_poke_early(void *addr, const void *opcode, size_t len); =20 /* * Matches NOP and NOPL, not any of the other possible NOPs. --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 19A2F1C4A16 for ; Fri, 28 Mar 2025 13:27:47 +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=1743168468; cv=none; b=ot9zgUi9ch/WlOmK6Vnn4BcdyBi6RJnaYl6Z0qTAo8F1igfjyAZi22QPZZaBek90Pe/BalVscCUIMk9mNZKfTcOT+oh/Qg/OaumH8tYYdym1ht7CaE/5wQets33EB9x0uF21vXTKIxNddJiNxoak80aCsukzGM7Tvi3eWXMOXqo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168468; c=relaxed/simple; bh=h6wSVJK60rUteIznqhWfFi3ILoiAB1JaIPfXXCevsxA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EHTh0+g2gWaMxHRLcwP1nPTaaq5cooTF3mWR83oc2j/4x5lh2BJiV6Uk6fpCtsdcqnXvYhrQZqOy25RUqy4I/GxkMdClYLD3NH1Owm7WqYStpymzI22UDFhb73xK7BRbuSsIrRt/XzvL5nzX1eFdAiSPWi0dHaa3yK/41ORRUUk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RoCyUysD; 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="RoCyUysD" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 91568C4CEEA; Fri, 28 Mar 2025 13:27:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168467; bh=h6wSVJK60rUteIznqhWfFi3ILoiAB1JaIPfXXCevsxA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RoCyUysDNsMgYcx+fgVhyNXG9HaMuUm4Rq5J4CLnXvUyPNTaLol/RqgJpkYaj3qCZ gf+/43s7n+NunTezRkcCkVh/6HWMjoJwlMduaSd/me2KNMGHV6D8RknHNB5y32lQMt 6JYQ1FellJfw5gHaV0bcZauLYE2u6rPIAX8OO3p+al3WGy0QPgNcuMc/8rc6zYO8VG dNfPjHS594j4weLsRXHD33dbHFL+xlQVP8MEaNvT8QvGwCDnRLI9RiNsg7NjuSraIS LPu7lwUxJ1ihJ75DEaiV5Nxk/a7ClC1f+v2/lb/DZFZuiROEy7Zdfd9wPQ16svRUC1 CnD/uFZglKsJw== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 10/49] x86/alternatives: Update comments in int3_emulate_push() Date: Fri, 28 Mar 2025 14:26:25 +0100 Message-ID: <20250328132704.1901674-11-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" The idtentry macro in entry_64.S hasn't had a create_gap option for 5 years - update the comment. (Also clean up the entire comment block while at it.) Signed-off-by: Ingo Molnar --- arch/x86/include/asm/text-patching.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/text-patching.h b/arch/x86/include/asm/te= xt-patching.h index 7f296a05c5fe..b7e8fb8f3648 100644 --- a/arch/x86/include/asm/text-patching.h +++ b/arch/x86/include/asm/text-patching.h @@ -142,13 +142,14 @@ static __always_inline void int3_emulate_push(struct pt_regs *regs, unsigned long val) { /* - * The int3 handler in entry_64.S adds a gap between the + * The INT3 handler in entry_64.S adds a gap between the * stack where the break point happened, and the saving of * pt_regs. We can extend the original stack because of - * this gap. See the idtentry macro's create_gap option. + * this gap. See the idtentry macro's X86_TRAP_BP logic. * - * Similarly entry_32.S will have a gap on the stack for (any) hardware - * exception and pt_regs; see FIXUP_FRAME. + * Similarly, entry_32.S will have a gap on the stack for + * (any) hardware exception and pt_regs; see the + * FIXUP_FRAME macro. */ regs->sp -=3D sizeof(unsigned long); *(unsigned long *)regs->sp =3D val; --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 2E2BC1DB13A for ; Fri, 28 Mar 2025 13:27:50 +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=1743168470; cv=none; b=DXXwRpqQspWvYwd5rzBZRk+qmE3IMdp3hoJHEYUyUCSEbks7m16I0eje/6FAxADMkRff1bMk+HDVQZEsmWcyfkh6X4p+o9kGg7Ocac+eadGavE/vOV38afxgIIWi3mHdmVgIbkgcOsUgafLBrihdUQrDRHd3DmuOf3ACOfSY/W0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168470; c=relaxed/simple; bh=zLq8STooLiEFACeGxzmrydh0oVt7CoI/XgW+S8Jj1Lo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MuuV/V4kRJP7MHmoFKqYBZmsQYbhnWG6m21wSgP5W/8ntOvuPfXi3UMo0J8Bi+qSmU8MtenFG4l7yJEvLUkYVLB8dtQDHw0zrmHRjY7YqboDHy8u6imO2tl+AXtRdwvoMeHB/v2ovXMtZPS8UDnjp0xKFFBsh3pH7z9fWIc5gDI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pfbadmiG; 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="pfbadmiG" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0DC71C4CEE5; Fri, 28 Mar 2025 13:27:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168470; bh=zLq8STooLiEFACeGxzmrydh0oVt7CoI/XgW+S8Jj1Lo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pfbadmiGpbYWlnhw5hVzrGSis1xttMCnZOXYr7flIxeoY9P409b32QvYHq3gXYXYB Nukm78B58Xq5AJnvRfdwTg3g9DGrHQj2PCNouwG8pkTgXb5oIC8YA7nqDviKHVsyZD x1yfqUqHmwTj/xfHqrF7CXR2QO2X6vDRTZcRW/f7uOM/7zvAtgTiMWILlyjEEdmL1n gFLEPTpaazFGlpzTjQ8l1huq4NS5NN/U4M7nBQZiTTC6sDef5LxGkpqcSo/4+gPLL3 2CTI7umDaH5RpdizheZ/T0tJP6SsBEvesI1pz5vwv2MArGb/zfIfs+GeVUOFd82uiw f4M23QRJ4MvuQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 11/49] x86/alternatives: Remove the confusing, inaccurate & unnecessary 'temp_mm_state_t' abstraction Date: Fri, 28 Mar 2025 14:26:26 +0100 Message-ID: <20250328132704.1901674-12-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" So the temp_mm_state_t abstraction used by use_temporary_mm() and unuse_temporary_mm() is super confusing: - The whole machinery is about temporarily switching to the text_poke_mm utility MM that got allocated during bootup for text-patching purposes alone: temp_mm_state_t prev; /* * Loading the temporary mm behaves as a compiler barrier, which * guarantees that the PTE will be set at the time memcpy() is done. */ prev =3D use_temporary_mm(text_poke_mm); - Yet the value that gets saved in the temp_mm_state_t variable is not the temporary MM ... but the previous MM... - Ie. we temporarily put the non-temporary MM into a variable that has the temp_mm_state_t type. This makes no sense whatsoever. - The confusion continues in unuse_temporary_mm(): static inline void unuse_temporary_mm(temp_mm_state_t prev_state) Here we unuse an MM that is ... not the temporary MM, but the previous MM. :-/ Fix up all this confusion by removing the unnecessary layer of abstraction and using a bog-standard 'struct mm_struct *prev_mm' variable to save the MM to. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 056872aebe6e..edff7714556e 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2139,10 +2139,6 @@ void __init_or_module text_poke_early(void *addr, co= nst void *opcode, } } =20 -typedef struct { - struct mm_struct *mm; -} temp_mm_state_t; - /* * Using a temporary mm allows to set temporary mappings that are not acce= ssible * by other CPUs. Such mappings are needed to perform sensitive memory wri= tes @@ -2156,9 +2152,9 @@ typedef struct { * loaded, thereby preventing interrupt handler bugs from overrid= ing * the kernel memory protection. */ -static inline temp_mm_state_t use_temporary_mm(struct mm_struct *mm) +static inline struct mm_struct *use_temporary_mm(struct mm_struct *temp_mm) { - temp_mm_state_t temp_state; + struct mm_struct *prev_mm; =20 lockdep_assert_irqs_disabled(); =20 @@ -2170,8 +2166,8 @@ static inline temp_mm_state_t use_temporary_mm(struct= mm_struct *mm) if (this_cpu_read(cpu_tlbstate_shared.is_lazy)) leave_mm(); =20 - temp_state.mm =3D this_cpu_read(cpu_tlbstate.loaded_mm); - switch_mm_irqs_off(NULL, mm, current); + prev_mm =3D this_cpu_read(cpu_tlbstate.loaded_mm); + switch_mm_irqs_off(NULL, temp_mm, current); =20 /* * If breakpoints are enabled, disable them while the temporary mm is @@ -2187,17 +2183,17 @@ static inline temp_mm_state_t use_temporary_mm(stru= ct mm_struct *mm) if (hw_breakpoint_active()) hw_breakpoint_disable(); =20 - return temp_state; + return prev_mm; } =20 __ro_after_init struct mm_struct *text_poke_mm; __ro_after_init unsigned long text_poke_mm_addr; =20 -static inline void unuse_temporary_mm(temp_mm_state_t prev_state) +static inline void unuse_temporary_mm(struct mm_struct *prev_mm) { lockdep_assert_irqs_disabled(); =20 - switch_mm_irqs_off(NULL, prev_state.mm, current); + switch_mm_irqs_off(NULL, prev_mm, current); =20 /* Clear the cpumask, to indicate no TLB flushing is needed anywhere */ cpumask_clear_cpu(raw_smp_processor_id(), mm_cpumask(text_poke_mm)); @@ -2228,7 +2224,7 @@ static void *__text_poke(text_poke_f func, void *addr= , const void *src, size_t l { bool cross_page_boundary =3D offset_in_page(addr) + len > PAGE_SIZE; struct page *pages[2] =3D {NULL}; - temp_mm_state_t prev; + struct mm_struct *prev_mm; unsigned long flags; pte_t pte, *ptep; spinlock_t *ptl; @@ -2286,7 +2282,7 @@ static void *__text_poke(text_poke_f func, void *addr= , const void *src, size_t l * Loading the temporary mm behaves as a compiler barrier, which * guarantees that the PTE will be set at the time memcpy() is done. */ - prev =3D use_temporary_mm(text_poke_mm); + prev_mm =3D use_temporary_mm(text_poke_mm); =20 kasan_disable_current(); func((u8 *)text_poke_mm_addr + offset_in_page(addr), src, len); @@ -2307,7 +2303,7 @@ static void *__text_poke(text_poke_f func, void *addr= , const void *src, size_t l * instruction that already allows the core to see the updated version. * Xen-PV is assumed to serialize execution in a similar manner. */ - unuse_temporary_mm(prev); + unuse_temporary_mm(prev_mm); =20 /* * Flushing the TLB might involve IPIs, which would require enabled --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 043D91E04BB for ; Fri, 28 Mar 2025 13:27:52 +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=1743168473; cv=none; b=Mn5cIoXKghsJ7+pvzWN7LMXWbnmjpMq11zho1nuZVohJ8YEvQ5UbR8kQWcsqrU3tLcY+/n8VyfxRbqiqKfo2KnYiJylS+BMSqn+85U3BdM0/4b7pNc0R1/12OZu/034r+SWQN1vvSbbhRj4G/sfEFhO74zrwke4ACXDCv2mozLo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168473; c=relaxed/simple; bh=wg2c5nr6TjMRQ/IqPjtCcjARvgm7PuxkEkeDA1S1opA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eFop2xyqpswpgBlmrT8F7+6r5yZbK0uNu3FbxdYsRmkqk/Mz9o36q+uMKHkle3BMZPMf8tpbl65t6DkgAZDd14HgiA7kOUsa4kZqKeuJaNKUPjrWKoDH7UfXV8l8gSH5T6vBeaflFIWOJsmhgmvn+E2P2e91o2rAFb3L1ctTUO0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UvNZh4gE; 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="UvNZh4gE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FDF5C4CEE4; Fri, 28 Mar 2025 13:27:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168472; bh=wg2c5nr6TjMRQ/IqPjtCcjARvgm7PuxkEkeDA1S1opA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UvNZh4gElrm3cnyAgkXJYO7wjqRmHbZh/zNDyTjz6cBLSES3VvfIruwC37gR1B5+j r5s2DB9hvalCib6HzCBHLmibaUSURHfNDAC8NMrdifWzi3gQirgWl+8AskltDCUpur LMIYkv+y/4gABos2EU+3FIpy4Ws0YXfF3CTj1iW15gSI9zNDscKk5ndFGJkZZsgt5f V8UA78CgXRlwGLxFKVOtLVlzTWKLKxQSLAy5kVjWQM+v98FevSw+0bUGqxM+YnGHq9 zeTyfXhAkabYP5VhdciBUlmxrSH3R0/oWcR4kyVRv5WsjOT50itL4eSoiZ1CXLPF8o YJNdDePekOsXA== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 12/49] x86/alternatives: Rename 'text_poke_flush()' to 'smp_text_poke_batch_flush()' Date: Fri, 28 Mar 2025 14:26:27 +0100 Message-ID: <20250328132704.1901674-13-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" This name is actually actively confusing, because the simple text_poke*() APIs use MM-switching based code patching, while text_poke_flush() is part of the INT3 based text_poke_int3_*() machinery that is an additional layer of functionality on top of regular text_poke*() functional= ity. Rename it to smp_text_poke_batch_flush() to make it clear which layer it belongs to. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index edff7714556e..e49c67c3942f 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2858,7 +2858,7 @@ static bool tp_order_fail(void *addr) return false; } =20 -static void text_poke_flush(void *addr) +static void smp_text_poke_batch_flush(void *addr) { if (tp_vec_nr =3D=3D TP_VEC_MAX || tp_order_fail(addr)) { smp_text_poke_batch_process(tp_vec, tp_vec_nr); @@ -2868,14 +2868,14 @@ static void text_poke_flush(void *addr) =20 void text_poke_finish(void) { - text_poke_flush(NULL); + smp_text_poke_batch_flush(NULL); } =20 void __ref text_poke_queue(void *addr, const void *opcode, size_t len, con= st void *emulate) { struct text_poke_loc *tp; =20 - text_poke_flush(addr); + smp_text_poke_batch_flush(addr); =20 tp =3D &tp_vec[tp_vec_nr++]; text_poke_loc_init(tp, addr, opcode, len, emulate); --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 689DA21ADA7 for ; Fri, 28 Mar 2025 13:27:55 +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=1743168475; cv=none; b=fpr2WorKrWj0BMHtf4UJLrSevYwdYw7HMlOXsMKM7rrDiHWEZcFP0mmO2MurJhStJEa/EFQrUkt0HGPEdkI1ar5hn2sOzYLq+Yhucev1eccEci0igYe0XLpovEggjUYAwOPt3niC3M+FCa0DAhT3yJniqrtq/FWiDh17TFFkwv4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168475; c=relaxed/simple; bh=HfOvQa+lwoC5GoD+LhBgT7EGXokznWxwSsuvBd33gUI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CdAXZ7/SmNszPUwDBYJQ2CtrLD7nycq9vjmts7FkdER2ancfW7WC9drm0EsFxTSdvsnyB0Q6zJHm8CvFvPfzImXuyhEZ+YwLYNZX7wBwTO0O3Y7VbZtblbjR2jjmal4ozhJx0EBalyQvvCt86i6zCbNyxkbU8SdZbZxdR6rskPM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SJh09HAE; 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="SJh09HAE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F186EC4CEEA; Fri, 28 Mar 2025 13:27:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168474; bh=HfOvQa+lwoC5GoD+LhBgT7EGXokznWxwSsuvBd33gUI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SJh09HAE0icOGLAl4XfwZ/BVrvSh0RF1dYaInxI+7MIDT3Z+HjuRuKYrVXjD2HUAg cWygHF31/zChase/KSMZwNIiZTgq0Ou4NisAjHJ3VyJHISX2PTxNqZ7gdXKawveF8f YPYdA9Gj6rp4HP6ZwTOYdzihoEZXUuPkr6+LydEwqhLN0hOTzDDn5RCjpGyRU5hF4S EtzqQJPHMTKXVjLCZc0U/7gH7T8MJBX+6GR/YAAe5dBt+aGyC1q6Zq4NlDYraOa/UV bP7+cjMvb+LlxXPV0buwXtspCfxPcLE3BuAmlv8OdW51ZWmQL3J7EfbXnCH7333YSr /Zmuw6dU+C63g== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 13/49] x86/alternatives: Rename 'text_poke_finish()' to 'smp_text_poke_batch_finish()' Date: Fri, 28 Mar 2025 14:26:28 +0100 Message-ID: <20250328132704.1901674-14-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" This name is actively confusing as well, because the simple text_poke*() APIs use MM-switching based code patching, while text_poke_finish() is part of the INT3 based text_poke_int3_*() machinery that is an additional layer of functionality on top of regular text_poke*() functional= ity. Rename it to smp_text_poke_batch_finish() to make it clear which layer it belongs to. Signed-off-by: Ingo Molnar --- arch/x86/include/asm/text-patching.h | 2 +- arch/x86/kernel/alternative.c | 2 +- arch/x86/kernel/ftrace.c | 4 ++-- arch/x86/kernel/jump_label.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/text-patching.h b/arch/x86/include/asm/te= xt-patching.h index b7e8fb8f3648..6534c40b7427 100644 --- a/arch/x86/include/asm/text-patching.h +++ b/arch/x86/include/asm/text-patching.h @@ -42,7 +42,7 @@ extern int smp_text_poke_int3_trap_handler(struct pt_regs= *regs); extern void smp_text_poke_single(void *addr, const void *opcode, size_t le= n, const void *emulate); =20 extern void text_poke_queue(void *addr, const void *opcode, size_t len, co= nst void *emulate); -extern void text_poke_finish(void); +extern void smp_text_poke_batch_finish(void); =20 #define INT3_INSN_SIZE 1 #define INT3_INSN_OPCODE 0xCC diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index e49c67c3942f..abe6a9fa9be7 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2866,7 +2866,7 @@ static void smp_text_poke_batch_flush(void *addr) } } =20 -void text_poke_finish(void) +void smp_text_poke_batch_finish(void) { smp_text_poke_batch_flush(NULL); } diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c index 7175a0404def..c35a928364b9 100644 --- a/arch/x86/kernel/ftrace.c +++ b/arch/x86/kernel/ftrace.c @@ -58,7 +58,7 @@ void ftrace_arch_code_modify_post_process(void) * module load, and we need to finish the text_poke_queue() * that they do, here. */ - text_poke_finish(); + smp_text_poke_batch_finish(); ftrace_poke_late =3D 0; mutex_unlock(&text_mutex); } @@ -250,7 +250,7 @@ void ftrace_replace_code(int enable) text_poke_queue((void *)rec->ip, new, MCOUNT_INSN_SIZE, NULL); ftrace_update_record(rec, enable); } - text_poke_finish(); + smp_text_poke_batch_finish(); } =20 void arch_ftrace_update_code(int command) diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c index 166e12037199..28be6eb6cb3d 100644 --- a/arch/x86/kernel/jump_label.c +++ b/arch/x86/kernel/jump_label.c @@ -143,6 +143,6 @@ bool arch_jump_label_transform_queue(struct jump_entry = *entry, void arch_jump_label_transform_apply(void) { mutex_lock(&text_mutex); - text_poke_finish(); + smp_text_poke_batch_finish(); mutex_unlock(&text_mutex); } --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 D943221B8F7 for ; Fri, 28 Mar 2025 13:27:57 +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=1743168477; cv=none; b=GwkhCoEQs7I9an4tjyIMcvDDpGpEqqKx2Apu3sGCBLw2xDHKfObDTWCw7absYXAvySqQtS9hFzr3P1br98n8AZ+lM6vNaFONAJL7Dv4xpBJjlBkui+U9WHTkSk7UweKZ+T0EEUFbPLINv/rPvKiztuP2h22gcECAbsHMO3nWLsw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168477; c=relaxed/simple; bh=Ay9k+hwCwyO8Rw+Z0t7cOKmrOufhTPPEd5PwqwP6Fdc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fnrRv7xAn6FF2z1SCXF9s0nj/dEgQDn9uTgkySv6cC4629nU0oIryPM1NC1fj623JnHU1BRHUKCcnyKXKEr/pM1yVcgROET1AEC03YtxuwxkE+E14FBMP22fGvp4hidC8+ZrWddNdadLLJuOikYtv9tvsQts564hkH3i/gwnQnY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mkXkaiWS; 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="mkXkaiWS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C422C4CEE5; Fri, 28 Mar 2025 13:27:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168477; bh=Ay9k+hwCwyO8Rw+Z0t7cOKmrOufhTPPEd5PwqwP6Fdc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mkXkaiWSIfTLcLdAXKSTL5111s4/0fdQkirzpfplPsIp81AqA+XpJJ2kxetKZCijR VnqcSQaLFE5cNqoHA0PK55R5xMkd0w92M28R1VmNKb42hZRhRFdQ7V/lCwIaZfeEZY B1aqyInrfUqUJKcqWZVqS0CPlnFxhS/oGWA+XQMGUX9x3Yf7P2TV7YJm0HCfVawmKO pzn9IzO53+5Bebi9VJJuXB3xO1IQvQBXRi6xA7nhWQTf9MWAO9QBr0UNlAQ6Hv5dHt qZBEvyhGekwip+b4XBOg0J60EJ6Ek6ZKKXJGDp3Ok4a6iry1CRngBIO1ifAboM/nev BE72pZ6JihLSw== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 14/49] x86/alternatives: Rename 'text_poke_queue()' to 'smp_text_poke_batch_add()' Date: Fri, 28 Mar 2025 14:26:29 +0100 Message-ID: <20250328132704.1901674-15-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" This name is actively confusing as well, because the simple text_poke*() APIs use MM-switching based code patching, while text_poke_queue() is part of the INT3 based text_poke_int3_*() machinery that is an additional layer of functionality on top of regular text_poke*() functional= ity. Rename it to smp_text_poke_batch_add() to make it clear which layer it belongs to. Signed-off-by: Ingo Molnar --- arch/x86/include/asm/text-patching.h | 2 +- arch/x86/kernel/alternative.c | 2 +- arch/x86/kernel/ftrace.c | 6 +++--- arch/x86/kernel/jump_label.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/text-patching.h b/arch/x86/include/asm/te= xt-patching.h index 6534c40b7427..20ce4eda6d47 100644 --- a/arch/x86/include/asm/text-patching.h +++ b/arch/x86/include/asm/text-patching.h @@ -41,7 +41,7 @@ extern void *text_poke_set(void *addr, int c, size_t len); extern int smp_text_poke_int3_trap_handler(struct pt_regs *regs); extern void smp_text_poke_single(void *addr, const void *opcode, size_t le= n, const void *emulate); =20 -extern void text_poke_queue(void *addr, const void *opcode, size_t len, co= nst void *emulate); +extern void smp_text_poke_batch_add(void *addr, const void *opcode, size_t= len, const void *emulate); extern void smp_text_poke_batch_finish(void); =20 #define INT3_INSN_SIZE 1 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index abe6a9fa9be7..3d395128f913 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2871,7 +2871,7 @@ void smp_text_poke_batch_finish(void) smp_text_poke_batch_flush(NULL); } =20 -void __ref text_poke_queue(void *addr, const void *opcode, size_t len, con= st void *emulate) +void __ref smp_text_poke_batch_add(void *addr, const void *opcode, size_t = len, const void *emulate) { struct text_poke_loc *tp; =20 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c index c35a928364b9..0853ba3fd04a 100644 --- a/arch/x86/kernel/ftrace.c +++ b/arch/x86/kernel/ftrace.c @@ -55,7 +55,7 @@ void ftrace_arch_code_modify_post_process(void) { /* * ftrace_make_{call,nop}() may be called during - * module load, and we need to finish the text_poke_queue() + * module load, and we need to finish the smp_text_poke_batch_add() * that they do, here. */ smp_text_poke_batch_finish(); @@ -119,7 +119,7 @@ ftrace_modify_code_direct(unsigned long ip, const char = *old_code, =20 /* replace the text with the new text */ if (ftrace_poke_late) - text_poke_queue((void *)ip, new_code, MCOUNT_INSN_SIZE, NULL); + smp_text_poke_batch_add((void *)ip, new_code, MCOUNT_INSN_SIZE, NULL); else text_poke_early((void *)ip, new_code, MCOUNT_INSN_SIZE); return 0; @@ -247,7 +247,7 @@ void ftrace_replace_code(int enable) break; } =20 - text_poke_queue((void *)rec->ip, new, MCOUNT_INSN_SIZE, NULL); + smp_text_poke_batch_add((void *)rec->ip, new, MCOUNT_INSN_SIZE, NULL); ftrace_update_record(rec, enable); } smp_text_poke_batch_finish(); diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c index 28be6eb6cb3d..a7949a54a0ff 100644 --- a/arch/x86/kernel/jump_label.c +++ b/arch/x86/kernel/jump_label.c @@ -135,7 +135,7 @@ bool arch_jump_label_transform_queue(struct jump_entry = *entry, =20 mutex_lock(&text_mutex); jlp =3D __jump_label_patch(entry, type); - text_poke_queue((void *)jump_entry_code(entry), jlp.code, jlp.size, NULL); + smp_text_poke_batch_add((void *)jump_entry_code(entry), jlp.code, jlp.siz= e, NULL); mutex_unlock(&text_mutex); return true; } --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 0145121B9D6 for ; Fri, 28 Mar 2025 13:27:59 +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=1743168480; cv=none; b=c7RO6Zdq0vJtMWM2APmeTZ25r0h6dl8gQkhvkD8YNkbRNCvWldVQAyA3+nRKHZ9ejjQG8R7gayGmHN3ynoS0ULyoO13ReVjCjX9V3KPgScmmS+fXnrwL4vfOt0iee8feDj7l7dWv3agccN57nCh2zuMMcCx6RWZDYajhgoebg6s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168480; c=relaxed/simple; bh=EmZDIqrK6Py0vyMWn7LpBxXQD66V6MlG1++ohPNXEJ8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q+iJYrnv4hEsHAoy/4kMXwI4H3183mlgTlFp8w/0hmdMemldI+kAPok4CmNF/8L5X5DdFoVMmo29pa2jeaEa6AJFF+ivmpQTYR2pcoeN6309AgsH/VewtxzzXC3xkzMcCbb5P0f7xTsbv3U4hXA57ExIpe0prk6YSpypAr8mgs4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AKWKoVr2; 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="AKWKoVr2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DE0BBC4CEEB; Fri, 28 Mar 2025 13:27:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168479; bh=EmZDIqrK6Py0vyMWn7LpBxXQD66V6MlG1++ohPNXEJ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AKWKoVr2wvbDDGFZRq4FPU3dKxO60Qz8/ViZyhz10eEt++zfU8BBZZvdJgjQ2h5qE OYlH6r/9zL7oufnn4Ld7NBKBFQJusCwPZ3i5oSPK8R7FC025m/E1/JNPc+3RtMLoSw s5DMz1aeDEK/Z0mHGs4OnKt2OOcbSIO9/sEzmkBRztqwi9ByvRu8aOE8+Rv/i6mgQA smssT7VmEpziDddtSFkdWWD0Io1Zqxh1cz0mV+B5J2sB9WWEtCyMt515TyBLSacBcN cYdBL2OnhWLK5zZ3IkIoVhlXgL1VAt6yiTMHD0bZEWcLuYxjW/jabWYOrrqxPFz0de +9odhRSguv1xA== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 15/49] x86/alternatives: Rename 'text_poke_loc_init()' to 'text_poke_int3_loc_init()' Date: Fri, 28 Mar 2025 14:26:30 +0100 Message-ID: <20250328132704.1901674-16-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" This name is actively confusing as well, because the simple text_poke*() APIs use MM-switching based code patching, while text_poke_loc_init() is part of the INT3 based text_poke_int3_*() machinery that is an additional layer of functionality on top of regular text_poke*() functional= ity. Rename it to text_poke_int3_loc_init() to make it clear which layer it belongs to. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 3d395128f913..36c7708f40e7 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2762,7 +2762,7 @@ static void smp_text_poke_batch_process(struct text_p= oke_loc *tp, unsigned int n } } =20 -static void text_poke_loc_init(struct text_poke_loc *tp, void *addr, +static void text_poke_int3_loc_init(struct text_poke_loc *tp, void *addr, const void *opcode, size_t len, const void *emulate) { struct insn insn; @@ -2878,7 +2878,7 @@ void __ref smp_text_poke_batch_add(void *addr, const = void *opcode, size_t len, c smp_text_poke_batch_flush(addr); =20 tp =3D &tp_vec[tp_vec_nr++]; - text_poke_loc_init(tp, addr, opcode, len, emulate); + text_poke_int3_loc_init(tp, addr, opcode, len, emulate); } =20 /** @@ -2896,6 +2896,6 @@ void __ref smp_text_poke_single(void *addr, const voi= d *opcode, size_t len, cons { struct text_poke_loc tp; =20 - text_poke_loc_init(&tp, addr, opcode, len, emulate); + text_poke_int3_loc_init(&tp, addr, opcode, len, emulate); smp_text_poke_batch_process(&tp, 1); } --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 CDF58199947 for ; Fri, 28 Mar 2025 13:28:02 +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=1743168482; cv=none; b=fuavPLCy+a25xCF3NG6ahAiiv4GYxoNqYtQFWG5itXIaSRAWvD3HA8+285819N5Agmt1hje3y4dt6YZzN2vJ+Z+qjcNWNKJjeH4pcc5FA9xaFEGc4d1BaMZMxVNBb7cslAKZS5hjOUCTr6U7OEdepPXYWuFD+JmttAVkkKsIuHY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168482; c=relaxed/simple; bh=Jm8mkSbJUIX+tfghF+bb0GA//0mSZU+y1smBbsVYmN8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aPHejLflSt5uySjCdmLBUYi+wKXoReL7nooiTzYDOWsqyfrf4u0/oR2HJSIdUa9ILuwrVKK9SOWJqBwartRGrn1g6l4dsUORR3nXP4Levo1U54Fi9yF7kPZMEcOzfNwat/JKYteEAofMRbXMrbxQ4yD6roPRmO3dg7EhsDHaFuI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=TY7w3E3B; 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="TY7w3E3B" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B085C4CEE5; Fri, 28 Mar 2025 13:28:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168482; bh=Jm8mkSbJUIX+tfghF+bb0GA//0mSZU+y1smBbsVYmN8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TY7w3E3BWo51noeKkzS7ZWLHs2BVuhRA/zW1g7kYG3ctwzSHKtx7tcBP+5jNLu/gD cz3KJgAtP1kvpKSHDrxBP9BXhATLqja3g1loWZLN5mSyDReBTC1v8A3iJ/7er90+vM gzQvLlu4vo2AotZ3mohREni9LQZ/KjO5Y8WfAyzBkd4lIvsad3YWPBqC+ekXHA3NS6 FGhjNMK9C0zARM1DtJXl1IseDI/r4L1hwnoOwv/j9XLmqEIHpnxx5/GKL2D9HbQbZY UNytcFeSaZn7Eap6z3nJv9Tp1dNBRHS+AkzKQja1bMOqR4z2TNeFWh04pm6KUY6QBY MVSOzcU/XZ2Wg== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 16/49] x86/alternatives: Rename 'struct text_poke_loc' to 'struct smp_text_poke_loc' Date: Fri, 28 Mar 2025 14:26:31 +0100 Message-ID: <20250328132704.1901674-17-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" Make it clear that this structure is part of the INT3 based SMP patching facility, not the regular text_poke*() MM-switch based facility. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 36c7708f40e7..c42bad65bb03 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2455,7 +2455,7 @@ void text_poke_sync(void) * this thing. When len =3D=3D 6 everything is prefixed with 0x0f and we m= ap * opcode to Jcc.d8, using len to distinguish. */ -struct text_poke_loc { +struct smp_text_poke_loc { /* addr :=3D _stext + rel_addr */ s32 rel_addr; s32 disp; @@ -2467,7 +2467,7 @@ struct text_poke_loc { }; =20 struct int3_patching_desc { - struct text_poke_loc *vec; + struct smp_text_poke_loc *vec; int nr_entries; }; =20 @@ -2494,14 +2494,14 @@ static __always_inline void put_desc(void) raw_atomic_dec(refs); } =20 -static __always_inline void *text_poke_addr(struct text_poke_loc *tp) +static __always_inline void *text_poke_addr(struct smp_text_poke_loc *tp) { return _stext + tp->rel_addr; } =20 static __always_inline int patch_cmp(const void *key, const void *elt) { - struct text_poke_loc *tp =3D (struct text_poke_loc *) elt; + struct smp_text_poke_loc *tp =3D (struct smp_text_poke_loc *) elt; =20 if (key < text_poke_addr(tp)) return -1; @@ -2513,7 +2513,7 @@ static __always_inline int patch_cmp(const void *key,= const void *elt) noinstr int smp_text_poke_int3_trap_handler(struct pt_regs *regs) { struct int3_patching_desc *desc; - struct text_poke_loc *tp; + struct smp_text_poke_loc *tp; int ret =3D 0; void *ip; =20 @@ -2544,7 +2544,7 @@ noinstr int smp_text_poke_int3_trap_handler(struct pt= _regs *regs) */ if (unlikely(desc->nr_entries > 1)) { tp =3D __inline_bsearch(ip, desc->vec, desc->nr_entries, - sizeof(struct text_poke_loc), + sizeof(struct smp_text_poke_loc), patch_cmp); if (!tp) goto out_put; @@ -2592,8 +2592,8 @@ noinstr int smp_text_poke_int3_trap_handler(struct pt= _regs *regs) return ret; } =20 -#define TP_VEC_MAX (PAGE_SIZE / sizeof(struct text_poke_loc)) -static struct text_poke_loc tp_vec[TP_VEC_MAX]; +#define TP_VEC_MAX (PAGE_SIZE / sizeof(struct smp_text_poke_loc)) +static struct smp_text_poke_loc tp_vec[TP_VEC_MAX]; static int tp_vec_nr; =20 /** @@ -2617,7 +2617,7 @@ static int tp_vec_nr; * replacing opcode * - sync cores */ -static void smp_text_poke_batch_process(struct text_poke_loc *tp, unsigned= int nr_entries) +static void smp_text_poke_batch_process(struct smp_text_poke_loc *tp, unsi= gned int nr_entries) { unsigned char int3 =3D INT3_INSN_OPCODE; unsigned int i; @@ -2762,7 +2762,7 @@ static void smp_text_poke_batch_process(struct text_p= oke_loc *tp, unsigned int n } } =20 -static void text_poke_int3_loc_init(struct text_poke_loc *tp, void *addr, +static void text_poke_int3_loc_init(struct smp_text_poke_loc *tp, void *ad= dr, const void *opcode, size_t len, const void *emulate) { struct insn insn; @@ -2843,7 +2843,7 @@ static void text_poke_int3_loc_init(struct text_poke_= loc *tp, void *addr, */ static bool tp_order_fail(void *addr) { - struct text_poke_loc *tp; + struct smp_text_poke_loc *tp; =20 if (!tp_vec_nr) return false; @@ -2873,7 +2873,7 @@ void smp_text_poke_batch_finish(void) =20 void __ref smp_text_poke_batch_add(void *addr, const void *opcode, size_t = len, const void *emulate) { - struct text_poke_loc *tp; + struct smp_text_poke_loc *tp; =20 smp_text_poke_batch_flush(addr); =20 @@ -2894,7 +2894,7 @@ void __ref smp_text_poke_batch_add(void *addr, const = void *opcode, size_t len, c */ void __ref smp_text_poke_single(void *addr, const void *opcode, size_t len= , const void *emulate) { - struct text_poke_loc tp; + struct smp_text_poke_loc tp; =20 text_poke_int3_loc_init(&tp, addr, opcode, len, emulate); smp_text_poke_batch_process(&tp, 1); --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 DC8DB19F11E for ; Fri, 28 Mar 2025 13:28:04 +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=1743168484; cv=none; b=TEw3l2XmflZSkgbzrX4pF5Lps0vX7pjwd4TccTJQ4z+htQskl8fHwGNPpV6Rstnm2dxnYgnlF5yeET0xTNP6g/PaIuWAcG9A/SCTh3m2Tagd22bYty/sygvHT5jXQXtRUk8yJMKFZVi6KFH2sUIfFWQHjlU29W8Va/bLYT+VtIQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168484; c=relaxed/simple; bh=boZD/XlVSSbX1UhA+7MyokLpMqSarvld+PJ451QKKOA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l9Lo/gYZc/uBK12oEfaddFQECTrFteapdfGl/6mYRiJlr5vuOqBbIr0qNlJhoyJ64RtphejqHGsi4U0ZZZ2iXKuqrZq6NVfu+jO5HL4L7c6e+IQQxJzPO4H/ST65UWVQ7JpRmnghjIJxDbFyIGmqCNtsjitN8nCCo35Png0iGrk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pXSvDO2g; 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="pXSvDO2g" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7A30C4CEE4; Fri, 28 Mar 2025 13:28:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168484; bh=boZD/XlVSSbX1UhA+7MyokLpMqSarvld+PJ451QKKOA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pXSvDO2gBHsaJ+CedL/XDmdGSDkcK3fksjDHNDeVesLmR2ATUt1C8Xf0rjLtDkTA9 gZNdkQJryQeiTxM/Chg8wusCTKReNCnLs33qpD0sdvAkvTjN4DvXGzmBAftPrvh6b+ kGkSSbIeyhGfNRaiK0JhIZi9dkgPkR401i5wu0Vt7yqBzw+JCQQJJ6Q3NZkoI54udZ HPILeaGvlGZIhqNqCbzG/b9N0dh9rHCN3Y/64XBlzJdzZWIlBh2zUgj804b8+7Lz3a iGMDbx3SJs4nFwomuKMQZb2oYtdiviwfmeioMhTDy/Klntob9IdsD/eQY4NOyZwklj zqlrz6m1z9xiA== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 17/49] x86/alternatives: Rename 'struct int3_patching_desc' to 'struct text_poke_int3_vec' Date: Fri, 28 Mar 2025 14:26:32 +0100 Message-ID: <20250328132704.1901674-18-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" Follow the INT3 text-poking nomenclature, and also adopt the 'vector' name for the entire object, instead of the rather opaque 'descriptor' naming. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index c42bad65bb03..db5b06ea08d0 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2466,17 +2466,17 @@ struct smp_text_poke_loc { u8 old; }; =20 -struct int3_patching_desc { +struct text_poke_int3_vec { struct smp_text_poke_loc *vec; int nr_entries; }; =20 static DEFINE_PER_CPU(atomic_t, int3_refs); =20 -static struct int3_patching_desc int3_desc; +static struct text_poke_int3_vec int3_desc; =20 static __always_inline -struct int3_patching_desc *try_get_desc(void) +struct text_poke_int3_vec *try_get_desc(void) { atomic_t *refs =3D this_cpu_ptr(&int3_refs); =20 @@ -2512,7 +2512,7 @@ static __always_inline int patch_cmp(const void *key,= const void *elt) =20 noinstr int smp_text_poke_int3_trap_handler(struct pt_regs *regs) { - struct int3_patching_desc *desc; + struct text_poke_int3_vec *desc; struct smp_text_poke_loc *tp; int ret =3D 0; void *ip; --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 B664821C9F1 for ; Fri, 28 Mar 2025 13:28:07 +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=1743168487; cv=none; b=c9Cs6CU4SlocWgGvsuuLcYc6Fabhi2xE18ZttlOj57j7eSuk9Fasrp9bMBRGeXKcyCHDGXkX1mtYDb59xKefugLtewyKMBOyONuq8LM2uVR3gEAFpIVWS6lUBxXf5BkbO10BBHD23xES0duhskXBif0GlKy4wn/fvjhRLUGdz20= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168487; c=relaxed/simple; bh=2tfunCb0ARRC7tOe0TGa/+kvokaSGZAYYEpTpB7gGKU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AMZBjeJgvxftJFprlztKp5Cr1G8EBDfrEQfIEStTF/ssazmll8b9RCcQyuhVyYPO/R9fWJg483v8gdkAzJC5o1TqPdyBcBt7PBMgAwT5HqgwQGr2aQVSZixNyao1ZZ5kXq+g/PAFQFwGs96S25DtW2UluxLVRcYPCPHOTtfkoDA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jfLi1gOA; 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="jfLi1gOA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40146C4CEE4; Fri, 28 Mar 2025 13:28:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168487; bh=2tfunCb0ARRC7tOe0TGa/+kvokaSGZAYYEpTpB7gGKU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jfLi1gOANRfVgpRsCKMICsx+f8TwJUtrnJ5BTiH8mEuTg0AnDZpcM/Zy94lKkhTFD GiY4dTa4U4xCrupzYy0AEsNhNBZs4msSIkMUoYpL7yoTnsHFURS7x1RdUr9K+6DLQC JyiDYpzS6Qbvrf1gM4beTrhp/jOWZIyGfhw8l7VfxE9uRLqlT9wvlOjbBerBDVn5sb 6ohGK03I6/cwQuq4id07WYHjTz7UumWAJI8oDrDayARecW+F2O/RUVzuiHnUvGOqMy Cotj+nfqLq2qxIKdUf/Am90WWVycrvXn8JK2x9C0ZVzi1WDcWit5pzC7AADZarZGFO cl0VjP8ue7KUQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 18/49] x86/alternatives: Rename 'int3_desc' to 'int3_vec' Date: Fri, 28 Mar 2025 14:26:33 +0100 Message-ID: <20250328132704.1901674-19-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index db5b06ea08d0..be836d1f6d99 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2473,7 +2473,7 @@ struct text_poke_int3_vec { =20 static DEFINE_PER_CPU(atomic_t, int3_refs); =20 -static struct text_poke_int3_vec int3_desc; +static struct text_poke_int3_vec int3_vec; =20 static __always_inline struct text_poke_int3_vec *try_get_desc(void) @@ -2483,7 +2483,7 @@ struct text_poke_int3_vec *try_get_desc(void) if (!raw_atomic_inc_not_zero(refs)) return NULL; =20 - return &int3_desc; + return &int3_vec; } =20 static __always_inline void put_desc(void) @@ -2522,7 +2522,7 @@ noinstr int smp_text_poke_int3_trap_handler(struct pt= _regs *regs) =20 /* * Having observed our INT3 instruction, we now must observe - * int3_desc with non-zero refcount: + * int3_vec with non-zero refcount: * * int3_refs =3D 1 INT3 * WMB RMB @@ -2625,12 +2625,12 @@ static void smp_text_poke_batch_process(struct smp_= text_poke_loc *tp, unsigned i =20 lockdep_assert_held(&text_mutex); =20 - int3_desc.vec =3D tp; - int3_desc.nr_entries =3D nr_entries; + int3_vec.vec =3D tp; + int3_vec.nr_entries =3D nr_entries; =20 /* * Corresponds to the implicit memory barrier in try_get_desc() to - * ensure reading a non-zero refcount provides up to date int3_desc data. + * ensure reading a non-zero refcount provides up to date int3_vec data. */ for_each_possible_cpu(i) atomic_set_release(per_cpu_ptr(&int3_refs, i), 1); --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 2BDFA1A5BA3 for ; Fri, 28 Mar 2025 13:28:09 +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=1743168490; cv=none; b=kulF+eDVrpYdN66uuX/LRDPYFFagprvPVCJx0R7EJ+K0OEh4wQqKlIKjyCPU/i+x8MznbMuZdyT/wtN0ZK7HKhshhnR4NfbQ07p4ITzIy7LC+BJje8soWrqde7ko+Vesu/zpbJPLQ+sv5K8NvCJmdl12RQnDEQjBEWZ9tbbybjI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168490; c=relaxed/simple; bh=r8Z2fP6YHKxTr2SeyufPmLln62c4toqKQlKYqjpgris=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uXzHV2aMFg+jAjQqKb7uDn1xTnXqYgLIh3rx7/T8jazm1DvKySzEKSyInRJOuSOXl66QMt4vgQM+12QdgTbUipO+o6hx11aOFdCkv7CnIm7+9I16Qa9cI2x0d0GS1D2lXemHrMny69v93iDgM2KAhjB6oXy6DxWkXWZYpL+dPHo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HY1NjDeC; 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="HY1NjDeC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1914C4CEEA; Fri, 28 Mar 2025 13:28:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168489; bh=r8Z2fP6YHKxTr2SeyufPmLln62c4toqKQlKYqjpgris=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HY1NjDeCzn3OnSHZyllX+xLqENVSUMqroyddoqnPo1meCdmsSheLV1VXvAgZmiWY8 CYmPkuMdvGmuGU1FJh+FyaBeKEvxUje2e8enh1yyySssm8C+SWTu4unHjuji7Ap8Fb ruUep7Xc0XpdTRgx7Me6pGMFAramaFptTo4fzojts8bgz0sAh41aeY5lw3be6k/4BD +tFWyyJ9H3WuW2pEK2kbt2HWUFTNDgGFinmZcdjuOTFJWRPXD8pTBDN+52FlMGW562 fkEiUgo84wqGPMFweCqCslRt+O+I3eogonzWFvLtPzNUjW0sCurug6JwrbZPBcekuU B9X47g9fDFqsg== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 19/49] x86/alternatives: Add text_mutex) assert to smp_text_poke_batch_flush() Date: Fri, 28 Mar 2025 14:26:34 +0100 Message-ID: <20250328132704.1901674-20-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" It's possible to escape the text_mutex-held assert in smp_text_poke_batch_process() if the caller uses a properly batched and sorted series of patch requests, so add an explicit lockdep_assert_held() to make sure it's held by all callers. All text_poke_int3_*() APIs will call either smp_text_poke_batch_process() or smp_text_poke_batch_flush() internally. The text_mutex must be held, because tp_vec and tp_vec_nr et al are all globals, and the INT3 patching machinery itself relies on external serialization. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index be836d1f6d99..378db5f0b59b 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2860,6 +2860,8 @@ static bool tp_order_fail(void *addr) =20 static void smp_text_poke_batch_flush(void *addr) { + lockdep_assert_held(&text_mutex); + if (tp_vec_nr =3D=3D TP_VEC_MAX || tp_order_fail(addr)) { smp_text_poke_batch_process(tp_vec, tp_vec_nr); tp_vec_nr =3D 0; --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 4080E21D00E for ; Fri, 28 Mar 2025 13:28: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=1743168492; cv=none; b=tsrkjf6j85Lan9Rql3tTKYY9wtHuW28o7KGYSGtkxVqW9176jb55Veg7N5fSruA9SJnH92UzKFdedStHAP5l68sd5HXiR5kfzXoHb3T/1mw8+4WiTlVDxBWJOQqyvM5sPoQvOxinTGrPcZ4JYGG0qogfmBMWPJKv5FT4el8zkUE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168492; c=relaxed/simple; bh=3Vbu6ubLpA0ZqAfgQmNZ68niwPxvET/82ncm/nT3hDQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sYquLfw2XRMGrL7de8XAsrNSB+/gTxqKTSrWhL79X9Svz7z8OeqKNNXgw9O2SALLGgTjE68aOi/Rs2WWKd27hv1VZdv4w6s6C+BbjCUuIPe7/qoccFi2jgTTo0vbbcxOORHFpQJ7ldxtqyNnrK2s7JtO5cbwHcnieONSNjTkSzM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JwrHk9Uc; 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="JwrHk9Uc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B673C4CEE5; Fri, 28 Mar 2025 13:28:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168492; bh=3Vbu6ubLpA0ZqAfgQmNZ68niwPxvET/82ncm/nT3hDQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JwrHk9UcsOeOh6aVMIANnSVAdhwoA0m/WnCUNKzFwvdgR3fT/m4bAW/3Z7rV1Ku1s ew7LO64NtoJISRxlOjaL6/Im+/GuC/QFO67yGCpcjjYX4aLRko5GN+3A20oP6BM+HY bXFcTyzoPR9euqXBdFb/sy5sQZUvbeAywo8Yif3a+EE/sOKnaFlrXlDHpGPCkj7p33 tjwmoNjtbHUxYcMR2/fpGXzUQtdWzkjBhChuroSeGa+2tolVq3CPlT2eQwg0efWREn YFw5HzTe1+vPbOZwuTGMSdwZUdQ8Idk+Iq+qDiMGoZIYTTrRGvhDbK2eVe524N5Yjz R3mHXZvvKI5OA== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 20/49] x86/alternatives: Assert that smp_text_poke_int3_trap_handler() can only ever handle 'tp_vec[]' based requests Date: Fri, 28 Mar 2025 14:26:35 +0100 Message-ID: <20250328132704.1901674-21-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 378db5f0b59b..5fe54f3c6211 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2510,6 +2510,10 @@ static __always_inline int patch_cmp(const void *key= , const void *elt) return 0; } =20 +#define TP_VEC_MAX (PAGE_SIZE / sizeof(struct smp_text_poke_loc)) +static struct smp_text_poke_loc tp_vec[TP_VEC_MAX]; +static int tp_vec_nr; + noinstr int smp_text_poke_int3_trap_handler(struct pt_regs *regs) { struct text_poke_int3_vec *desc; @@ -2534,6 +2538,8 @@ noinstr int smp_text_poke_int3_trap_handler(struct pt= _regs *regs) if (!desc) return 0; =20 + WARN_ON_ONCE(desc->vec !=3D tp_vec); + /* * Discount the INT3. See smp_text_poke_batch_process(). */ @@ -2592,10 +2598,6 @@ noinstr int smp_text_poke_int3_trap_handler(struct p= t_regs *regs) return ret; } =20 -#define TP_VEC_MAX (PAGE_SIZE / sizeof(struct smp_text_poke_loc)) -static struct smp_text_poke_loc tp_vec[TP_VEC_MAX]; -static int tp_vec_nr; - /** * smp_text_poke_batch_process() -- update instructions on live kernel on = SMP * @tp: vector of instructions to patch --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 AD4A121D584 for ; Fri, 28 Mar 2025 13:28:14 +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=1743168494; cv=none; b=MHGSxHfZ0CbCcl7cFZCqBVCJ8Vs6i+HKwtCNf4Djl/47jTVu8WzdR3AVdBuuBs2gN9eI2T9Yu2QJI06QVI8B4n/Jbbk9kzdOpOE4qr2oRwq9iLU+YSzGU15rYWv6rwyVsUXqMybp1+/q6u64MQRSir3I+ZEZLYrekykbGaSI64Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168494; c=relaxed/simple; bh=1MjuidLYoRQbBQZBlQfNFXuF6K0GxTisnjnQj3c/rfI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QynVEwy3dFfolECt5qkkWoUuOrlooCWFF+kvmgl2kNu/QToGcl7tdUo6nnjjF1v9Ek3nJcqkkEZwxSQYEzdFW5CDKKoPw31o+ipbF8xTaEsfRu0DpNtw1bjJIvAq2dLqihNFExQlRUX3lV+GN4owV9TrdAejE/B+ErYcUDs4Zsw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AUaj1hlT; 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="AUaj1hlT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 96D8AC4CEE5; Fri, 28 Mar 2025 13:28:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168494; bh=1MjuidLYoRQbBQZBlQfNFXuF6K0GxTisnjnQj3c/rfI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AUaj1hlTHzOgyyea6rjfjOE8v9Jl6QWS5kLfwtA9ZIPD/UetuFGgj4O15xjXTsaCZ TjOPlk/EGsrvd9UH2q9etrU6YDl7E33kjP8/wFlNSoIcI3W4fNoFqAI7aqJRSzA9L5 XLaW0KuwEClEMwQeG13jYuWXuc0SCElFK+KY42Gfh85nnZtkMI0Vnh08YwBPSJ+o0Q UN4GVYayB86j9FaoUxc76wtQcKNQtmmgjvuqPZWfSUt8SzWiH9YV6zqU2Qsi1r1eqC W1Cll7j3L6+VFLf6YVA86VckLl6w9qIsRJs5gu9LDwla8U91UTMd+Ou4owtv9rIuIB FXzUdiGODHNGw== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 21/49] x86/alternatives: Use non-inverted logic instead of 'tp_order_fail()' Date: Fri, 28 Mar 2025 14:26:36 +0100 Message-ID: <20250328132704.1901674-22-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" tp_order_fail() uses inverted logic: it returns true in case something is false, which is only a plus at the IOCCC. Instead rename it to regular parity as 'text_poke_addr_ordered()', and adjust the code accordingly. Also add a comment explaining how the address ordering should be understood. No change in functionality intended. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 5fe54f3c6211..66778dac257f 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2843,28 +2843,34 @@ static void text_poke_int3_loc_init(struct smp_text= _poke_loc *tp, void *addr, * We hard rely on the tp_vec being ordered; ensure this is so by flushing * early if needed. */ -static bool tp_order_fail(void *addr) +static bool text_poke_addr_ordered(void *addr) { struct smp_text_poke_loc *tp; =20 if (!tp_vec_nr) - return false; + return true; =20 if (!addr) /* force */ - return true; + return false; =20 - tp =3D &tp_vec[tp_vec_nr - 1]; + /* + * If the last current entry's address is higher than the + * new entry's address we'd like to add, then ordering + * is violated and we must first flush all pending patching + * requests: + */ + tp =3D &tp_vec[tp_vec_nr-1]; if ((unsigned long)text_poke_addr(tp) > (unsigned long)addr) - return true; + return false; =20 - return false; + return true; } =20 static void smp_text_poke_batch_flush(void *addr) { lockdep_assert_held(&text_mutex); =20 - if (tp_vec_nr =3D=3D TP_VEC_MAX || tp_order_fail(addr)) { + if (tp_vec_nr =3D=3D TP_VEC_MAX || !text_poke_addr_ordered(addr)) { smp_text_poke_batch_process(tp_vec, tp_vec_nr); tp_vec_nr =3D 0; } --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 8F82D21E096 for ; Fri, 28 Mar 2025 13:28: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=1743168500; cv=none; b=A0ul5Md31qwZ0RnLoJuH5JDGQlsb11lyzEOBfDCOd1WrFl1oSYXVJnjgDWkymLWc2KapmRpxgSNTqqexwp3Z57Mgb84Q0otgEvcfXBwsI2fQeTnMoCQMEueYtRsrB2zwheqkcpOrX0oGk/KFILAX8Zys9vf3cXbFEV3avIR7qn4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168500; c=relaxed/simple; bh=C4QxJVYUpLSEmHPMwaR93U0zu+QPPz4nEkMxWVyEGbU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YIZ/q+TycJV3KJkB9i0GnSUzGMKMtpqhu5thCediwRqlkAWx82ohtDP5vLqfaZz7NyoB763zvROobx+lK81pdSkJkG4FmcTHcub2lj+OW8a6ADZAP6iASqzQdrpxMwUF2rYrrcDq4IIIVVd1Fm+n4ltJC30CZavkMseANpEADUw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GJXbrO1e; 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="GJXbrO1e" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0EAA2C4CEE5; Fri, 28 Mar 2025 13:28:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168497; bh=C4QxJVYUpLSEmHPMwaR93U0zu+QPPz4nEkMxWVyEGbU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GJXbrO1eJ8h5kvqaCyJa4ug7JXs03iYFNwsIwySr7BOT6Ea1Qv5hLB/fe/kKAdIqb L1BzaSAd7ZXZBYY7TNFQ6mkVFFdLDdQICFzHMsVv/+zMSiqLElnsg4LmgYuQYctJF1 os8YkPXe8p7VYzVpo5mcksdWVuIVB4O7OWcc7PaQ0IJkqCSD82hF3JuBf+xRuUkY34 HMUmPnLvPb3Nk9Upd4ek9KHBPaeGrM8FGJBpjU7B/ulElrlbZMvjN7tXg3xDG24v6z g7ksY2Pn84UQ4M8BYiCPMT4r44/dJqSvtwqIA1EObt2HhpTmuer3YZ+YBN3HvvRkMg FyMjAhlvoHv4g== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 22/49] x86/alternatives: Remove the 'addr == NULL means forced-flush' hack from smp_text_poke_batch_finish()/smp_text_poke_batch_flush()/text_poke_addr_ordered() Date: Fri, 28 Mar 2025 14:26:37 +0100 Message-ID: <20250328132704.1901674-23-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" There's this weird hack used by smp_text_poke_batch_finish() to indicate a 'forced flush': smp_text_poke_batch_flush(NULL); Just open-code the vector-flush in a straightforward fashion: smp_text_poke_batch_process(tp_vec, tp_vec_nr); tp_vec_nr =3D 0; And get rid of !addr hack from text_poke_addr_ordered(). Leave a WARN_ON_ONCE(), just in case some external code learned to rely on this behavior. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 66778dac257f..ffffec4597b7 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2847,12 +2847,11 @@ static bool text_poke_addr_ordered(void *addr) { struct smp_text_poke_loc *tp; =20 + WARN_ON_ONCE(!addr); + if (!tp_vec_nr) return true; =20 - if (!addr) /* force */ - return false; - /* * If the last current entry's address is higher than the * new entry's address we'd like to add, then ordering @@ -2866,6 +2865,14 @@ static bool text_poke_addr_ordered(void *addr) return true; } =20 +void smp_text_poke_batch_finish(void) +{ + if (tp_vec_nr) { + smp_text_poke_batch_process(tp_vec, tp_vec_nr); + tp_vec_nr =3D 0; + } +} + static void smp_text_poke_batch_flush(void *addr) { lockdep_assert_held(&text_mutex); @@ -2876,11 +2883,6 @@ static void smp_text_poke_batch_flush(void *addr) } } =20 -void smp_text_poke_batch_finish(void) -{ - smp_text_poke_batch_flush(NULL); -} - void __ref smp_text_poke_batch_add(void *addr, const void *opcode, size_t = len, const void *emulate) { struct smp_text_poke_loc *tp; --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 9170C1ACECF for ; Fri, 28 Mar 2025 13:28: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=1743168499; cv=none; b=sL/8DTldwd2Zi1CGoAMCu2yHu8oEJmRKHkKHJK/4RAWravaFSDOFyokhciH9VFWM+HTQB7AvzI7RIxK+yVYSEZNQo+4XesLA1CykRXlhcfnuuTp2xNpwLs8+n3Uy81BMM0PO+tKzSF6U+RDRugd70qMmXrnumIDuE1L4nD+xy4E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168499; c=relaxed/simple; bh=zcSLh9zb2Qc3VpXhOklk3s3w0Tr/O8DBH2iEqzq6lck=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jgBr0p6ab6o/G6O8NSLurvjyJJf0BYiITSRhtpXF+k//qeoxbuoiHidcBJpxSePDbsW9QE8D8b+Smk619CDJKnYPtlAVxMSqda6ALgMjv7VFvZ3UfgcgRi7DroSVWG8zzNLnxZUPLCAaiaYwk1uN0Oly+0vn1qtMsW6kPy2pcz0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rJ4hPLrM; 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="rJ4hPLrM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F0CEC4CEEA; Fri, 28 Mar 2025 13:28:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168499; bh=zcSLh9zb2Qc3VpXhOklk3s3w0Tr/O8DBH2iEqzq6lck=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rJ4hPLrMaYHLD34kxbKrSiGFbLSno7OHB+POiTD4uR/rYUOiQ+ajr70d6SP/XXiFf LYIRbOmKb5AyvvSDBHXLPFVRtNWkY7D3YSiXeOy8WLtEEhZ9lIZCXsoL5qI9ujRUpu Fpl/jrQCegPJhF34UrO/xU/uOLmtkIGdEGiNtHrzkFV+jxOcwDuJTeZSFAdh+clQ+P /gWeJoY/GvEx5dSQxbPXpXo+0TGqzcxNbCL5/gBkUnZ3vgmHhN+pNxKn/MjXxw4Q+5 0tOxblXjOGlwJTFOKI/OuQ2dw7bO1ww67X2i1IStFrO+751bO6+biCqtwROf/zkQeE ZfHPSmrM0ce+A== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 23/49] x86/alternatives: Simplify smp_text_poke_single() by using tp_vec and existing APIs Date: Fri, 28 Mar 2025 14:26:38 +0100 Message-ID: <20250328132704.1901674-24-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" Instead of constructing a vector on-stack, just use the already available batch-patching vector - which should always be empty at this point. This will allow subsequent simplifications. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index ffffec4597b7..70abc636b87c 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2906,8 +2906,13 @@ void __ref smp_text_poke_batch_add(void *addr, const= void *opcode, size_t len, c */ void __ref smp_text_poke_single(void *addr, const void *opcode, size_t len= , const void *emulate) { - struct smp_text_poke_loc tp; + struct smp_text_poke_loc *tp; + + /* Batch-patching should not be mixed with single-patching: */ + WARN_ON_ONCE(tp_vec_nr !=3D 0); + + tp =3D &tp_vec[tp_vec_nr++]; + text_poke_int3_loc_init(tp, addr, opcode, len, emulate); =20 - text_poke_int3_loc_init(&tp, addr, opcode, len, emulate); - smp_text_poke_batch_process(&tp, 1); + smp_text_poke_batch_finish(); } --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 65956221544 for ; Fri, 28 Mar 2025 13:28: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=1743168502; cv=none; b=dSbGmbe/ki5ctN44BKe8bMBur1Ab/THdCcv9Rsu34MqVM8VA3bCWL2asFmpu0PMa3Zpx8LVLG1YdFy/LXUneBZaGGnv2XtjtGvL4CjChPmsgz3NzoF46NchR7hIedeCMgL+NQWW3/vMSGH8eew82v9w6Sbbvl615xG1/pZORLzU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168502; c=relaxed/simple; bh=n7ntESqylVRPbiYcAi7Lvjwrj3FNVhCQtHzxQk/n5tk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R6BeRCH9kmk5+IV3y4FgM5UEtaL+YMsFkU0VmMXDDyvzM0viDIg6M29zjQXPtpP3IPr6aVFKG+o+Qhv5FgWNBeI/rp+t+JCoo7Pzz506gJNxVXLjAQw01QxDMkGL++7HgkxLT1N2TZA2qHmk1NBqGYm+hmPuER5AMnklnC4w9Kw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=L1TqWFTm; 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="L1TqWFTm" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9A72C4CEE4; Fri, 28 Mar 2025 13:28:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168501; bh=n7ntESqylVRPbiYcAi7Lvjwrj3FNVhCQtHzxQk/n5tk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L1TqWFTmtzksYIF0lLS1ZEq6jZOf1ChDlXrOwOEddAUtOjUHp4AiiwVyRnaFFtQ+A /egvDvllKqpL33fEazBdnSNET6PokExuAEACzYMFLSlth/XpMkP3LLj/H7uPSSV3W5 +nNiGoCGiYfhOGAbCtH1Wf/bBsi2yhk3y2WurTcrdGaCrs+z+KP+CEyRWEz1tyAg9/ ds+f0AAqj29p3BkV7y88RjV5hdsm5RzMcTp9WJVkLdtVccxsZN4HvExjrfamgqaGj+ 4JpFaW9HBSHdg8x+At+C/7XejqoZOtQjxwexvl/d4dCfcw09ul50SfCkwUH0pfizcw RGwxfcl62nG5g== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 24/49] x86/alternatives: Assert input parameters in smp_text_poke_batch_process() Date: Fri, 28 Mar 2025 14:26:39 +0100 Message-ID: <20250328132704.1901674-25-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" At this point the 'tp' input parameter must always be the global 'tp_vec' array, and 'nr_entries' must always be equal to 'tp_vec_nr'. Assert these conditions - which will allow the removal of a layer of indirection between these values. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 70abc636b87c..6652863539e8 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2627,6 +2627,9 @@ static void smp_text_poke_batch_process(struct smp_te= xt_poke_loc *tp, unsigned i =20 lockdep_assert_held(&text_mutex); =20 + WARN_ON_ONCE(tp !=3D tp_vec); + WARN_ON_ONCE(nr_entries !=3D tp_vec_nr); + int3_vec.vec =3D tp; int3_vec.nr_entries =3D nr_entries; =20 --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 830CE221712 for ; Fri, 28 Mar 2025 13:28: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=1743168504; cv=none; b=K8uhzzWc56+1lqPPAGzMR0s6v9kwIpxabaGkn+NR1m6wPxBkC6oZ8oZrPR4WuyLeGN5SVW7q/xsmMPerhTL1r/46uX80H8+mKkocTz5zMNEHSTijVXYLVmp82W7mEAoazUTfTdJHk20n0Dw3pGx82F2zLS6Wz9QKQLt7iyPgcDM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168504; c=relaxed/simple; bh=Y6ocmv5f99Y6L2N6DHjb9Vsvz62TZ7FfSVZpY/5bE5c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EBcuXvyuv8DwUgS9EG8nkrVoYOhRIbS9z3lDtUibnsQuh3Vx2PB1IszPYBWsDeG5wQ9R2X5zLLTN9EGnbfRvsdAlscnUt+vaeuw+aUMI7CqeoN9rnowww+XDjzpWlMMQk9N5pA4o3j6+GoFW4ORYv/wmoo4HDalui0+PNrgTlM4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jurPrtSW; 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="jurPrtSW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62C3FC4CEEB; Fri, 28 Mar 2025 13:28:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168504; bh=Y6ocmv5f99Y6L2N6DHjb9Vsvz62TZ7FfSVZpY/5bE5c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jurPrtSW1tJMsnfzhJXA8AmMdrL4r/Hqs+zv3FIHsfyZQkTCK0wkO0kECUQFUxR6s 2Nt3btGgP+fe+j1us0NeqiXA3olh8n7RVsg3CeR1LeE3CwHEsB+X+RbPBeHWwv53dG EQV5OePXtE/prhpF4ePVApjhk0SuRUsuWbAj6JixrlijxbGHlZgSchEErEz7NxRz4v a6f3FkPGBCcx4RpInlAeN/J2m/WWIX4v0HO6lvoVO4nwzCWRhrQPLlp266e2PS/+m5 uqQlmX0u9TFefZt0UYF9R8B5TjBI5KQHC90R52PSUB2yYRYmwQuUkddzMKAoQZd6qg RB3oBi3xhV6TA== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 25/49] x86/alternatives: Introduce 'struct smp_text_poke_array' and move tp_vec and tp_vec_nr to it Date: Fri, 28 Mar 2025 14:26:40 +0100 Message-ID: <20250328132704.1901674-26-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" struct text_poke_array is an equivalent structure to these global variables: static struct smp_text_poke_loc tp_vec[TP_VEC_MAX]; static int tp_vec_nr; Note that we intentionally mirror much of the naming of 'struct text_poke_int3_vec', which will further highlight the unecessary layering going on in this code, and will ease its removal. No change in functionality. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 43 +++++++++++++++++++++++----------------= ---- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 6652863539e8..b4b5e4db8cf9 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2467,14 +2467,21 @@ struct smp_text_poke_loc { }; =20 struct text_poke_int3_vec { - struct smp_text_poke_loc *vec; int nr_entries; + struct smp_text_poke_loc *vec; }; =20 static DEFINE_PER_CPU(atomic_t, int3_refs); =20 static struct text_poke_int3_vec int3_vec; =20 +#define TP_ARRAY_NR_ENTRIES_MAX (PAGE_SIZE / sizeof(struct smp_text_poke_l= oc)) + +static struct smp_text_poke_array { + int nr_entries; + struct smp_text_poke_loc vec[TP_ARRAY_NR_ENTRIES_MAX]; +} text_poke_array; + static __always_inline struct text_poke_int3_vec *try_get_desc(void) { @@ -2510,10 +2517,6 @@ static __always_inline int patch_cmp(const void *key= , const void *elt) return 0; } =20 -#define TP_VEC_MAX (PAGE_SIZE / sizeof(struct smp_text_poke_loc)) -static struct smp_text_poke_loc tp_vec[TP_VEC_MAX]; -static int tp_vec_nr; - noinstr int smp_text_poke_int3_trap_handler(struct pt_regs *regs) { struct text_poke_int3_vec *desc; @@ -2538,7 +2541,7 @@ noinstr int smp_text_poke_int3_trap_handler(struct pt= _regs *regs) if (!desc) return 0; =20 - WARN_ON_ONCE(desc->vec !=3D tp_vec); + WARN_ON_ONCE(desc->vec !=3D text_poke_array.vec); =20 /* * Discount the INT3. See smp_text_poke_batch_process(). @@ -2627,8 +2630,8 @@ static void smp_text_poke_batch_process(struct smp_te= xt_poke_loc *tp, unsigned i =20 lockdep_assert_held(&text_mutex); =20 - WARN_ON_ONCE(tp !=3D tp_vec); - WARN_ON_ONCE(nr_entries !=3D tp_vec_nr); + WARN_ON_ONCE(tp !=3D text_poke_array.vec); + WARN_ON_ONCE(nr_entries !=3D text_poke_array.nr_entries); =20 int3_vec.vec =3D tp; int3_vec.nr_entries =3D nr_entries; @@ -2843,7 +2846,7 @@ static void text_poke_int3_loc_init(struct smp_text_p= oke_loc *tp, void *addr, } =20 /* - * We hard rely on the tp_vec being ordered; ensure this is so by flushing + * We hard rely on the text_poke_array.vec being ordered; ensure this is s= o by flushing * early if needed. */ static bool text_poke_addr_ordered(void *addr) @@ -2852,7 +2855,7 @@ static bool text_poke_addr_ordered(void *addr) =20 WARN_ON_ONCE(!addr); =20 - if (!tp_vec_nr) + if (!text_poke_array.nr_entries) return true; =20 /* @@ -2861,7 +2864,7 @@ static bool text_poke_addr_ordered(void *addr) * is violated and we must first flush all pending patching * requests: */ - tp =3D &tp_vec[tp_vec_nr-1]; + tp =3D &text_poke_array.vec[text_poke_array.nr_entries-1]; if ((unsigned long)text_poke_addr(tp) > (unsigned long)addr) return false; =20 @@ -2870,9 +2873,9 @@ static bool text_poke_addr_ordered(void *addr) =20 void smp_text_poke_batch_finish(void) { - if (tp_vec_nr) { - smp_text_poke_batch_process(tp_vec, tp_vec_nr); - tp_vec_nr =3D 0; + if (text_poke_array.nr_entries) { + smp_text_poke_batch_process(text_poke_array.vec, text_poke_array.nr_entr= ies); + text_poke_array.nr_entries =3D 0; } } =20 @@ -2880,9 +2883,9 @@ static void smp_text_poke_batch_flush(void *addr) { lockdep_assert_held(&text_mutex); =20 - if (tp_vec_nr =3D=3D TP_VEC_MAX || !text_poke_addr_ordered(addr)) { - smp_text_poke_batch_process(tp_vec, tp_vec_nr); - tp_vec_nr =3D 0; + if (text_poke_array.nr_entries =3D=3D TP_ARRAY_NR_ENTRIES_MAX || !text_po= ke_addr_ordered(addr)) { + smp_text_poke_batch_process(text_poke_array.vec, text_poke_array.nr_entr= ies); + text_poke_array.nr_entries =3D 0; } } =20 @@ -2892,7 +2895,7 @@ void __ref smp_text_poke_batch_add(void *addr, const = void *opcode, size_t len, c =20 smp_text_poke_batch_flush(addr); =20 - tp =3D &tp_vec[tp_vec_nr++]; + tp =3D &text_poke_array.vec[text_poke_array.nr_entries++]; text_poke_int3_loc_init(tp, addr, opcode, len, emulate); } =20 @@ -2912,9 +2915,9 @@ void __ref smp_text_poke_single(void *addr, const voi= d *opcode, size_t len, cons struct smp_text_poke_loc *tp; =20 /* Batch-patching should not be mixed with single-patching: */ - WARN_ON_ONCE(tp_vec_nr !=3D 0); + WARN_ON_ONCE(text_poke_array.nr_entries !=3D 0); =20 - tp =3D &tp_vec[tp_vec_nr++]; + tp =3D &text_poke_array.vec[text_poke_array.nr_entries++]; text_poke_int3_loc_init(tp, addr, opcode, len, emulate); =20 smp_text_poke_batch_finish(); --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 5B08C221DAA for ; Fri, 28 Mar 2025 13:28: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=1743168507; cv=none; b=IN2g4HufvJdxEGQqTbA+p56552ys4/5bdGBXazO7MDjrPm11G61m6paPvTI9CfMpcM+JGZK/wU+DGPSjlb+Eb6MpaFiZclgBHzzXvZyYbPMakC3KCncT8leb9RXF+DJuflYZ27h7lV7K2Cxup0C8DjIoz6VgFD0U0UIg32dlkRY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168507; c=relaxed/simple; bh=SSyOClHhqELj+2bJ2fcjNnX9/KncGhy59igRJXLeIxM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=W+Az/Dq3XRyPbD+XTNR2EPQ/rBzV3zrRtqPC0fdzHYGSlnMP3KeS9XbOHHkxxWtu4tzhlfI4qONSe9fjpDhIedpjuJQdHIW4ybLTUgVdmvDqYKs/Wkqhm1WCbUePCWg8BTMvQjTH81h1H5BhNvD9yB0BLZtGFgHQ5ZKIlmBMNwg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=V3iXrxSX; 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="V3iXrxSX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CFF3AC4CEE4; Fri, 28 Mar 2025 13:28:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168506; bh=SSyOClHhqELj+2bJ2fcjNnX9/KncGhy59igRJXLeIxM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V3iXrxSXQ1AMhNy9VlAXjBS4Kd1lcPJjNiKOEekCZxm+Tdq4608cCZn/lmXlEDOjl p4bwtSkwCDn+CQUKCGBAFmXrvRXSfJTKl/pRP2XPy1Gx6CPzCP1m5/e4xDIB0N2WI2 6lIY98o/sJ7xi8FSwXcDflXy2NZHlyd6LPNMZmwuKY0UzsIFmdATRUPteC1P9T5RE2 V/1PIFTNIsYhStahYpGoA9UFScar8BNv7WwT0QRRu3bWQfRwfTsSf93rWB+7pnNc4f ZbBE/EhOmw1H+EN2NhOl1o+UhJWS8arIfOW+4LgbbL6eVpkt6uYGMk1qey6SS9ld/b icBqMfVHwO6iw== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 26/49] x86/alternatives: Remove the tp_vec indirection Date: Fri, 28 Mar 2025 14:26:41 +0100 Message-ID: <20250328132704.1901674-27-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" At this point we are always working out of an uptodate text_poke_array, there's no need for smp_text_poke_int3_trap_handler() to read via the int3_vec indirection - remove it. This simplifies the code: 1 file changed, 5 insertions(+), 15 deletions(-) Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index b4b5e4db8cf9..82808deb1501 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2466,15 +2466,6 @@ struct smp_text_poke_loc { u8 old; }; =20 -struct text_poke_int3_vec { - int nr_entries; - struct smp_text_poke_loc *vec; -}; - -static DEFINE_PER_CPU(atomic_t, int3_refs); - -static struct text_poke_int3_vec int3_vec; - #define TP_ARRAY_NR_ENTRIES_MAX (PAGE_SIZE / sizeof(struct smp_text_poke_l= oc)) =20 static struct smp_text_poke_array { @@ -2482,15 +2473,17 @@ static struct smp_text_poke_array { struct smp_text_poke_loc vec[TP_ARRAY_NR_ENTRIES_MAX]; } text_poke_array; =20 +static DEFINE_PER_CPU(atomic_t, int3_refs); + static __always_inline -struct text_poke_int3_vec *try_get_desc(void) +struct smp_text_poke_array *try_get_desc(void) { atomic_t *refs =3D this_cpu_ptr(&int3_refs); =20 if (!raw_atomic_inc_not_zero(refs)) return NULL; =20 - return &int3_vec; + return &text_poke_array; } =20 static __always_inline void put_desc(void) @@ -2519,7 +2512,7 @@ static __always_inline int patch_cmp(const void *key,= const void *elt) =20 noinstr int smp_text_poke_int3_trap_handler(struct pt_regs *regs) { - struct text_poke_int3_vec *desc; + struct smp_text_poke_array *desc; struct smp_text_poke_loc *tp; int ret =3D 0; void *ip; @@ -2529,7 +2522,7 @@ noinstr int smp_text_poke_int3_trap_handler(struct pt= _regs *regs) =20 /* * Having observed our INT3 instruction, we now must observe - * int3_vec with non-zero refcount: + * text_poke_array with non-zero refcount: * * int3_refs =3D 1 INT3 * WMB RMB @@ -2633,12 +2626,9 @@ static void smp_text_poke_batch_process(struct smp_t= ext_poke_loc *tp, unsigned i WARN_ON_ONCE(tp !=3D text_poke_array.vec); WARN_ON_ONCE(nr_entries !=3D text_poke_array.nr_entries); =20 - int3_vec.vec =3D tp; - int3_vec.nr_entries =3D nr_entries; - /* * Corresponds to the implicit memory barrier in try_get_desc() to - * ensure reading a non-zero refcount provides up to date int3_vec data. + * ensure reading a non-zero refcount provides up to date text_poke_array= data. */ for_each_possible_cpu(i) atomic_set_release(per_cpu_ptr(&int3_refs, i), 1); --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 BDFFD221F0C for ; Fri, 28 Mar 2025 13:28:29 +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=1743168509; cv=none; b=QdBSHa+rPyT9Uz9Kc7it4bKwIUFehe8l2EqmbdszVt7DoWN7yr5CVpZbuqRNrGtAqsz+o+Enp4/KRij9YXizUd30FPA5G6KNwK3S7T7VBhHy+5e1B1EzJn8sh938Nxr4puqhN0tCS5NnzPAaQ3iUOQLUFqi0l3LKpDN5KgmXtWY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168509; c=relaxed/simple; bh=uAt6f5JWDsg7pV4F65Ak18vYpTNKpRpReb0TSAyEGpM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=baIQtHtjnxtbGSPuGinV4wwv+EIkmWes3EC/Z1kR8g4JcLwCb3Yzic4KICxTSjp6aEW56fe4b181J5mkeO1k8ht52O4L/j7eIyjfvGKIJokrPjBRApicdf3gFF18uh/OMjhTjieT4VmdVevwQ6u7h+p3wMuwm7kkepUek5eIkng= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=paYM3fPl; 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="paYM3fPl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4AC57C4CEEA; Fri, 28 Mar 2025 13:28:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168509; bh=uAt6f5JWDsg7pV4F65Ak18vYpTNKpRpReb0TSAyEGpM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=paYM3fPlldYQGvV0fTzoQjKuWmPy6MkcYAHxAfpzCADzWQsT+qFRyccDmRqEqZTy/ kUf06w1oOM5vwUJ4WPy0QcVCNbfCaMcN7BTQT928KqceSVasY9FVWAQGaR4R3wjlIF HQdivJrBey26vncGHHO2/TfJFBlvq/FvRfK+Qd64ESOPAuYTY6oQKzKnei7sclzSjW bgtwfwNbJ1tYbhCJjFejfZLYhC4F/MHQ8Nk1WP/xLa048K4iIm6mp5eqJd1F1pjN4Q dnm6hnpsRtDsefo3u+auFQM1gM8el7b0IL7YYfd48tzeKAQ95+VmhdMg5j0q5DO+6r 0Ek+LNltLsbaw== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 27/49] x86/alternatives: Rename 'try_get_desc()' to 'try_get_text_poke_array()' Date: Fri, 28 Mar 2025 14:26:42 +0100 Message-ID: <20250328132704.1901674-28-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" This better reflects what the underlying code is doing, there's no 'descriptor' indirection anymore. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 82808deb1501..26bb2a731208 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2476,7 +2476,7 @@ static struct smp_text_poke_array { static DEFINE_PER_CPU(atomic_t, int3_refs); =20 static __always_inline -struct smp_text_poke_array *try_get_desc(void) +struct smp_text_poke_array *try_get_text_poke_array(void) { atomic_t *refs =3D this_cpu_ptr(&int3_refs); =20 @@ -2530,7 +2530,7 @@ noinstr int smp_text_poke_int3_trap_handler(struct pt= _regs *regs) */ smp_rmb(); =20 - desc =3D try_get_desc(); + desc =3D try_get_text_poke_array(); if (!desc) return 0; =20 @@ -2627,7 +2627,7 @@ static void smp_text_poke_batch_process(struct smp_te= xt_poke_loc *tp, unsigned i WARN_ON_ONCE(nr_entries !=3D text_poke_array.nr_entries); =20 /* - * Corresponds to the implicit memory barrier in try_get_desc() to + * Corresponds to the implicit memory barrier in try_get_text_poke_array(= ) to * ensure reading a non-zero refcount provides up to date text_poke_array= data. */ for_each_possible_cpu(i) --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 4555D221701 for ; Fri, 28 Mar 2025 13:28: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=1743168512; cv=none; b=oFTGQeqYPxLVqG6pF7AWZdvKqMmuxaJ4p5kY+z1KCsUrigjtzxXq53M0XJxd69OIqJcEQyTYr5c4oQCjKL/P8LF/iZnksvHmIaWYO6q7iEvC3BpCtRBK71MDrC8esQ4o/itRZJ3f7rhtua1qMoP3zFkv1w87wNP44vN9HNxgehA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168512; c=relaxed/simple; bh=JHNktBcDC+hEvClPDgC0pyCSPg52Mir76gPQu3Ybfj8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AnQRJMq9zsYj9qDBcFggT6XAW7/pK4K/zUZMMD3w3rA0iQ6ldRCulOnbiLghLQKxmoDj47SMRyEJc18/vLzSx+FYnPIJLrFTWTXwEK/CdcjZfybcO85B/Wc8f1SAh2ky/ZTNECANBWPUz6JlAlzdwRfZTk0n5eUQvm7iV6Lo47U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=n3m2Uepb; 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="n3m2Uepb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9FD7C4AF09; Fri, 28 Mar 2025 13:28:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168511; bh=JHNktBcDC+hEvClPDgC0pyCSPg52Mir76gPQu3Ybfj8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=n3m2Uepbhq3kKKcRh8x2mXkH8w7wE4KUhvLG/jdBkI6yZNMHM5sl7/UJF3OwoI02v A/ctGNEDsGAm1TYsGSJyrT8DAKZOBI6b3mQL4Nw4LfJF2ygSxZYgnhOLLaxCtO2S6n TDGpxWcOMmvseX9PPsKKPh7ULntHJfmOvAYF3iQVaJMrsTVWNlonAfO1VxwRwfGJGj YeiG9FR7d4zkLNhKHhZ8Wxk2N4uIgAZSXvlDvcgeYzvf/Zkj+i+rLRulxwuEzdlzDL 47QohiYIkBkevI1U/v8SFcta5o0VAkvGlJK9IEuCl045bkdQKNm+XIZL51i4dHn8vZ XRJB8+BftFBkw== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 28/49] x86/alternatives: Rename 'put_desc()' to 'put_text_poke_array()' Date: Fri, 28 Mar 2025 14:26:43 +0100 Message-ID: <20250328132704.1901674-29-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" Just like with try_get_text_poke_array(), this name better reflects what the underlying code is doing, there's no 'descriptor' indirection anymore. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 26bb2a731208..202720228c98 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2486,7 +2486,7 @@ struct smp_text_poke_array *try_get_text_poke_array(v= oid) return &text_poke_array; } =20 -static __always_inline void put_desc(void) +static __always_inline void put_text_poke_array(void) { atomic_t *refs =3D this_cpu_ptr(&int3_refs); =20 @@ -2590,7 +2590,7 @@ noinstr int smp_text_poke_int3_trap_handler(struct pt= _regs *regs) ret =3D 1; =20 out_put: - put_desc(); + put_text_poke_array(); return ret; } =20 --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 4AFCE21C176 for ; Fri, 28 Mar 2025 13:28:34 +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=1743168514; cv=none; b=giMtvWWu7UZglkEsp77kHG3/Rsol3Hwlvgm7FepGaBRe+GveNZ/erICMJuGR3+gqYVxIOn3zfayeoQkspenCfqYQVtEB+UTSRP/wu3jt0MVnlMN8CncYIZ+bAjwP5XIv4CIlrLguBjcbRvv8+TJci9xMbDmtZj9ZU8Mkk+GEOQ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168514; c=relaxed/simple; bh=Xa2f3D7B4w1wZ6w2TtyrZD+X50/h41Gn+1E7MilGMBY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WaO25Zk1IKvfbSCO/kkl5w/hAasNdTIZAYgSxJch12UMscRa+dw2A5fUCaYA+IiHU/gnKHu7dhsBSaihBkzcOxlJTRCMCI7XHiX5mRkOXZDsbHHoT9iXvtGU57V4dWKnJo7lvOmnIUw4ssvvbCqfkjb1rBDlc7o4yjSNbn9kkXc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BcDYX5zQ; 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="BcDYX5zQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 367F9C4CEE4; Fri, 28 Mar 2025 13:28:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168514; bh=Xa2f3D7B4w1wZ6w2TtyrZD+X50/h41Gn+1E7MilGMBY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BcDYX5zQVMUyRCOITCnSsJ2LtnNoULUVn1tKRRhETxoJSGS4tAcnpAl6sQ9FrGGPH kWNVIXIrVsrfk38ktzrqVY0IiyA3JlGcZngCFH50SxdAhTjhFmc07CqZkv0EHATGpb FK9HGIMG7t/xdneLlJoQVfqqaqCVbsSydaY/Sm4RLMs1/qmLXcrQa5mSr/bgP6pgXp BEfmZ7m1hC/DJnpEaOWC5DinZ+voYJK/YPpCBDnECqv1P9Gsjzy43le4DEbxkuIuBM +MS8VMefLUr6cU6QDqKjJ7o1mwuLS9tVYMXVEy7MbLI4Xxte/HVryAIWXr1dTxb30W /z1hywaO6RCTQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 29/49] x86/alternatives: Simplify try_get_text_poke_array() Date: Fri, 28 Mar 2025 14:26:44 +0100 Message-ID: <20250328132704.1901674-30-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" There's no need to return a pointer on success - it's always the same pointer. Return a bool instead. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 202720228c98..12f0fd35773d 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2475,15 +2475,14 @@ static struct smp_text_poke_array { =20 static DEFINE_PER_CPU(atomic_t, int3_refs); =20 -static __always_inline -struct smp_text_poke_array *try_get_text_poke_array(void) +static bool try_get_text_poke_array(void) { atomic_t *refs =3D this_cpu_ptr(&int3_refs); =20 if (!raw_atomic_inc_not_zero(refs)) - return NULL; + return false; =20 - return &text_poke_array; + return true; } =20 static __always_inline void put_text_poke_array(void) @@ -2530,9 +2529,9 @@ noinstr int smp_text_poke_int3_trap_handler(struct pt= _regs *regs) */ smp_rmb(); =20 - desc =3D try_get_text_poke_array(); - if (!desc) + if (!try_get_text_poke_array()) return 0; + desc =3D &text_poke_array; =20 WARN_ON_ONCE(desc->vec !=3D text_poke_array.vec); =20 --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 BBBAB223710 for ; Fri, 28 Mar 2025 13:28:36 +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=1743168516; cv=none; b=g2KU+I0EE+6QGnGMbJMVVGB/5576O3UziWxsWWIJjA43mlXZpCnmUA25El6u1l43nU20MCYtpFFnB4OEG/4o/eQ2yi557cEcGviNh8LRDIjXUcbChIAZAWZhVXDO2RCKBprm7iFqdIYIq8G75G5uZcqiNShnxtjYYYW0j5aBtIU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168516; c=relaxed/simple; bh=EZlry9YGM4+MhtQBNcg39fAOXvL+lWRdpnTzqvT2UhM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jmt5SBz2Iu1ORqrKtqBwOisR7Q+Q8+JUoEANfTwbDfU5k+dOqQYBDxDO3yXbzpXIl7ZDWNdZuzIiJ1fcdABnpVdv0eywTV5Pd7bHc+cFQPQRDIVNdq7yHsAyyNN32uvmKYyh9obg1JKIsB3aGStV+Lk3JbLx1dWM9ND6YJcDDy4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HNSFqfGV; 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="HNSFqfGV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A472CC4CEE4; Fri, 28 Mar 2025 13:28:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168516; bh=EZlry9YGM4+MhtQBNcg39fAOXvL+lWRdpnTzqvT2UhM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HNSFqfGVTfKvfOjWziOFlNdh669b3TdSpU+laAE0LFq1TsZA6dhWxj1k97IROAACA 7lJg8vcJmerTTbeXF1ASYKaJN3bi76D8z1NVPW6mPLGDaTlS5W5VgMoxt9XpVI58SM PMHdPS/QHHBkRU0yTr2qm+5SmY3L+heWIZVp/j4457qQ6sC0WQegnWMZq9XCSWidTN ee4KA/xi1tQaizkDkMCOlbqNy4fzNc89Wa+4d8SlkFrDHES076vBqqBGiiXwA5xSR3 qyYUpBVjgWrg2TWXfSAl/4alw8UsR9DenUYNPhiYt0NjzYzN54PkpNXSicyFVHzgVn eZVCD1R67Utgg== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 30/49] x86/alternatives: Simplify smp_text_poke_int3_trap_handler() Date: Fri, 28 Mar 2025 14:26:45 +0100 Message-ID: <20250328132704.1901674-31-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" Remove the 'desc' local variable indirection and use text_poke_array directly. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 12f0fd35773d..57d7032eca41 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2511,7 +2511,6 @@ static __always_inline int patch_cmp(const void *key,= const void *elt) =20 noinstr int smp_text_poke_int3_trap_handler(struct pt_regs *regs) { - struct smp_text_poke_array *desc; struct smp_text_poke_loc *tp; int ret =3D 0; void *ip; @@ -2531,9 +2530,6 @@ noinstr int smp_text_poke_int3_trap_handler(struct pt= _regs *regs) =20 if (!try_get_text_poke_array()) return 0; - desc =3D &text_poke_array; - - WARN_ON_ONCE(desc->vec !=3D text_poke_array.vec); =20 /* * Discount the INT3. See smp_text_poke_batch_process(). @@ -2543,14 +2539,14 @@ noinstr int smp_text_poke_int3_trap_handler(struct = pt_regs *regs) /* * Skip the binary search if there is a single member in the vector. */ - if (unlikely(desc->nr_entries > 1)) { - tp =3D __inline_bsearch(ip, desc->vec, desc->nr_entries, + if (unlikely(text_poke_array.nr_entries > 1)) { + tp =3D __inline_bsearch(ip, text_poke_array.vec, text_poke_array.nr_entr= ies, sizeof(struct smp_text_poke_loc), patch_cmp); if (!tp) goto out_put; } else { - tp =3D desc->vec; + tp =3D text_poke_array.vec; if (text_poke_addr(tp) !=3D ip) goto out_put; } --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 3A4D722489F for ; Fri, 28 Mar 2025 13:28:39 +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=1743168519; cv=none; b=lYu4CE08Cf9H2EbFVsb+fV6cIVla7ZjlezwBtu+gMAyTUSW6H2/B6Q0TkHZxfNcjdyF3/zB7DtOwLMTenCKrDAHVaKWJc9m+mZm9WuLY801CeSUQOp4Z6+2xDA+m7oM6Ygsm6dlf+AetPgu+ppgRzdb4E653tnAV6/aEmmYeW3Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168519; c=relaxed/simple; bh=Ki1xwzET/LoJch+WTQUbvj+IJhDS6y8w3+EGnrbLpYc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DU5FBUs9m+cCVopJIBI4fRSwkQAdUWbAduZ9Fgv63949IzKpQFKnDa7wPs/1Buof1tizijE2luqU5scxt9vdXxJuo1IZ8fRtjiP4pXaPOdqIwnuMJmTluswrns+LNElxKZssIwHf9bqHOt1ohcF0FcqXJB8PmAEPaklIDrgYTFw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KPDhIUYT; 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="KPDhIUYT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2086FC4CEEA; Fri, 28 Mar 2025 13:28:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168519; bh=Ki1xwzET/LoJch+WTQUbvj+IJhDS6y8w3+EGnrbLpYc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KPDhIUYToqM//zxtj3/l8FWmmFtn3oIlfsq3VhCxo2EQiNxvpt9wGgyTProab3hp5 nXp/PeOi3M08VOoQitZQupmqSVPxQdS7DtQplxn6rE4nSlJqgiKo0n/HCOl1YYXLqx ixkPZIjTNofLrxpxsLUHOAaOJtkjOBTINn7dlzPAOhyGclZqS4D4rAvvgLk+I5fE22 Hcb7SxDWujgax4EDXw16hL9r3y1VQBMIFAgVjctkzkVXReg/e2/l6lZRDIPE2+JNu0 aB1cOpvFChSlmZGMNATic8Srx+HuvjWnN5bR1bGlNCjxURaHbZ+EmsPFYYjQqPN+1p QF7BVcK6eXCpg== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 31/49] x86/alternatives: Simplify smp_text_poke_batch_process() Date: Fri, 28 Mar 2025 14:26:46 +0100 Message-ID: <20250328132704.1901674-32-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" This function is now using the text_poke_array state exclusively, make that explicit by removing the redundant input parameters. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 43 ++++++++++++++++++++-------------------= ---- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 57d7032eca41..34d3c69595a0 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2591,8 +2591,8 @@ noinstr int smp_text_poke_int3_trap_handler(struct pt= _regs *regs) =20 /** * smp_text_poke_batch_process() -- update instructions on live kernel on = SMP - * @tp: vector of instructions to patch - * @nr_entries: number of entries in the vector + * @text_poke_array.vec: vector of instructions to patch + * @text_poke_array.nr_entries: number of entries in the vector * * Modify multi-byte instruction by using int3 breakpoint on SMP. * We completely avoid stop_machine() here, and achieve the @@ -2610,7 +2610,7 @@ noinstr int smp_text_poke_int3_trap_handler(struct pt= _regs *regs) * replacing opcode * - sync cores */ -static void smp_text_poke_batch_process(struct smp_text_poke_loc *tp, unsi= gned int nr_entries) +static void smp_text_poke_batch_process(void) { unsigned char int3 =3D INT3_INSN_OPCODE; unsigned int i; @@ -2618,9 +2618,6 @@ static void smp_text_poke_batch_process(struct smp_te= xt_poke_loc *tp, unsigned i =20 lockdep_assert_held(&text_mutex); =20 - WARN_ON_ONCE(tp !=3D text_poke_array.vec); - WARN_ON_ONCE(nr_entries !=3D text_poke_array.nr_entries); - /* * Corresponds to the implicit memory barrier in try_get_text_poke_array(= ) to * ensure reading a non-zero refcount provides up to date text_poke_array= data. @@ -2640,16 +2637,16 @@ static void smp_text_poke_batch_process(struct smp_= text_poke_loc *tp, unsigned i =20 /* * Corresponding read barrier in int3 notifier for making sure the - * nr_entries and handler are correctly ordered wrt. patching. + * text_poke_array.nr_entries and handler are correctly ordered wrt. patc= hing. */ smp_wmb(); =20 /* * First step: add a int3 trap to the address that will be patched. */ - for (i =3D 0; i < nr_entries; i++) { - tp[i].old =3D *(u8 *)text_poke_addr(&tp[i]); - text_poke(text_poke_addr(&tp[i]), &int3, INT3_INSN_SIZE); + for (i =3D 0; i < text_poke_array.nr_entries; i++) { + text_poke_array.vec[i].old =3D *(u8 *)text_poke_addr(&text_poke_array.ve= c[i]); + text_poke(text_poke_addr(&text_poke_array.vec[i]), &int3, INT3_INSN_SIZE= ); } =20 text_poke_sync(); @@ -2657,15 +2654,15 @@ static void smp_text_poke_batch_process(struct smp_= text_poke_loc *tp, unsigned i /* * Second step: update all but the first byte of the patched range. */ - for (do_sync =3D 0, i =3D 0; i < nr_entries; i++) { - u8 old[POKE_MAX_OPCODE_SIZE+1] =3D { tp[i].old, }; + for (do_sync =3D 0, i =3D 0; i < text_poke_array.nr_entries; i++) { + u8 old[POKE_MAX_OPCODE_SIZE+1] =3D { text_poke_array.vec[i].old, }; u8 _new[POKE_MAX_OPCODE_SIZE+1]; - const u8 *new =3D tp[i].text; - int len =3D tp[i].len; + const u8 *new =3D text_poke_array.vec[i].text; + int len =3D text_poke_array.vec[i].len; =20 if (len - INT3_INSN_SIZE > 0) { memcpy(old + INT3_INSN_SIZE, - text_poke_addr(&tp[i]) + INT3_INSN_SIZE, + text_poke_addr(&text_poke_array.vec[i]) + INT3_INSN_SIZE, len - INT3_INSN_SIZE); =20 if (len =3D=3D 6) { @@ -2674,7 +2671,7 @@ static void smp_text_poke_batch_process(struct smp_te= xt_poke_loc *tp, unsigned i new =3D _new; } =20 - text_poke(text_poke_addr(&tp[i]) + INT3_INSN_SIZE, + text_poke(text_poke_addr(&text_poke_array.vec[i]) + INT3_INSN_SIZE, new + INT3_INSN_SIZE, len - INT3_INSN_SIZE); =20 @@ -2705,7 +2702,7 @@ static void smp_text_poke_batch_process(struct smp_te= xt_poke_loc *tp, unsigned i * The old instruction is recorded so that the event can be * processed forwards or backwards. */ - perf_event_text_poke(text_poke_addr(&tp[i]), old, len, new, len); + perf_event_text_poke(text_poke_addr(&text_poke_array.vec[i]), old, len, = new, len); } =20 if (do_sync) { @@ -2721,16 +2718,16 @@ static void smp_text_poke_batch_process(struct smp_= text_poke_loc *tp, unsigned i * Third step: replace the first byte (int3) by the first byte of * replacing opcode. */ - for (do_sync =3D 0, i =3D 0; i < nr_entries; i++) { - u8 byte =3D tp[i].text[0]; + for (do_sync =3D 0, i =3D 0; i < text_poke_array.nr_entries; i++) { + u8 byte =3D text_poke_array.vec[i].text[0]; =20 - if (tp[i].len =3D=3D 6) + if (text_poke_array.vec[i].len =3D=3D 6) byte =3D 0x0f; =20 if (byte =3D=3D INT3_INSN_OPCODE) continue; =20 - text_poke(text_poke_addr(&tp[i]), &byte, INT3_INSN_SIZE); + text_poke(text_poke_addr(&text_poke_array.vec[i]), &byte, INT3_INSN_SIZE= ); do_sync++; } =20 @@ -2859,7 +2856,7 @@ static bool text_poke_addr_ordered(void *addr) void smp_text_poke_batch_finish(void) { if (text_poke_array.nr_entries) { - smp_text_poke_batch_process(text_poke_array.vec, text_poke_array.nr_entr= ies); + smp_text_poke_batch_process(); text_poke_array.nr_entries =3D 0; } } @@ -2869,7 +2866,7 @@ static void smp_text_poke_batch_flush(void *addr) lockdep_assert_held(&text_mutex); =20 if (text_poke_array.nr_entries =3D=3D TP_ARRAY_NR_ENTRIES_MAX || !text_po= ke_addr_ordered(addr)) { - smp_text_poke_batch_process(text_poke_array.vec, text_poke_array.nr_entr= ies); + smp_text_poke_batch_process(); text_poke_array.nr_entries =3D 0; } } --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 10118224B1E for ; Fri, 28 Mar 2025 13:28:41 +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=1743168523; cv=none; b=bgFXP7gor55U9TNptn5cKmym6yQJKTwOmZg5K7J/hnDnZvhz8jlzodn+u5QOKJMP3xfleF3OFTFb8sbiocIibMMKQ4zR62EZbzOjnS9YrtrqV6HN0hN1HPj2850Ps+YRgP1Ln8KAXsgQOupZVpNYiUeQCKWfqTLHLYhfjC6pFuM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168523; c=relaxed/simple; bh=UpTa7HbnLutWCablTZi3Ycvpp3cytPgIcdTdr0TMsb0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ovvxw2pv6rcoV8ujrr5Yy6gyaEVieJSZmkmVwuusT9jWDDMEjySSQrEWDtCw10+MuDEXs2DDBXWRVy3fS8W9vYU7e2qTR54zptOrwVpqHx1H1VA+eHL3xnOZT/RuDfnSueHNWMmhl/ecIkbj28YEg5EoeUO70KRf3+reQ7Z8iV0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MjzUUxYl; 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="MjzUUxYl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9002FC4CEE4; Fri, 28 Mar 2025 13:28:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168521; bh=UpTa7HbnLutWCablTZi3Ycvpp3cytPgIcdTdr0TMsb0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MjzUUxYllBLSh4Ll5420EkwL5zUrV0/z3CvlSER927Q7Fpo4gcaTlO73x21qqS9IF ZoNYEw5DUdLGV1bVMrMzUV+ZmX6aRQhKVVZVCqrpKroTjV99d3ZZuZ2IH6TZUmhL7A v4TgK8L7QMMiZ2b8Breoy0F2DZaA0mX20VsHZwflP3ycT6/kKBz69XB9Xnf0dWgsjv ZjVo/DSJxxmLdtiNUYqTaaBknr3IMYGHqQ4a199kMb4qSuhHsHLjnon6kcmUliYf1m +fNCypoxg4kJMlrTLWTY1h1UIfOuSUBZ2lxVK/6MSNjfSobnzu2Y4rRM7NruBqHt/c /jAKK8++EHIZw== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 32/49] x86/alternatives: Rename 'int3_refs' to 'text_poke_array_refs' Date: Fri, 28 Mar 2025 14:26:47 +0100 Message-ID: <20250328132704.1901674-33-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" Make it clear that these reference counts lock access to text_poke_array. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 34d3c69595a0..566b857d210d 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2473,11 +2473,11 @@ static struct smp_text_poke_array { struct smp_text_poke_loc vec[TP_ARRAY_NR_ENTRIES_MAX]; } text_poke_array; =20 -static DEFINE_PER_CPU(atomic_t, int3_refs); +static DEFINE_PER_CPU(atomic_t, text_poke_array_refs); =20 static bool try_get_text_poke_array(void) { - atomic_t *refs =3D this_cpu_ptr(&int3_refs); + atomic_t *refs =3D this_cpu_ptr(&text_poke_array_refs); =20 if (!raw_atomic_inc_not_zero(refs)) return false; @@ -2487,7 +2487,7 @@ static bool try_get_text_poke_array(void) =20 static __always_inline void put_text_poke_array(void) { - atomic_t *refs =3D this_cpu_ptr(&int3_refs); + atomic_t *refs =3D this_cpu_ptr(&text_poke_array_refs); =20 smp_mb__before_atomic(); raw_atomic_dec(refs); @@ -2522,9 +2522,9 @@ noinstr int smp_text_poke_int3_trap_handler(struct pt= _regs *regs) * Having observed our INT3 instruction, we now must observe * text_poke_array with non-zero refcount: * - * int3_refs =3D 1 INT3 + * text_poke_array_refs =3D 1 INT3 * WMB RMB - * write INT3 if (int3_refs !=3D 0) + * write INT3 if (text_poke_array_refs !=3D 0) */ smp_rmb(); =20 @@ -2623,7 +2623,7 @@ static void smp_text_poke_batch_process(void) * ensure reading a non-zero refcount provides up to date text_poke_array= data. */ for_each_possible_cpu(i) - atomic_set_release(per_cpu_ptr(&int3_refs, i), 1); + atomic_set_release(per_cpu_ptr(&text_poke_array_refs, i), 1); =20 /* * Function tracing can enable thousands of places that need to be @@ -2745,7 +2745,7 @@ static void smp_text_poke_batch_process(void) * unused. */ for_each_possible_cpu(i) { - atomic_t *refs =3D per_cpu_ptr(&int3_refs, i); + atomic_t *refs =3D per_cpu_ptr(&text_poke_array_refs, i); =20 if (unlikely(!atomic_dec_and_test(refs))) atomic_cond_read_acquire(refs, !VAL); --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 1D226225402 for ; Fri, 28 Mar 2025 13:28:44 +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=1743168524; cv=none; b=lTyzTuyjxINMHOHnz7cJqsp7dzRV+0r4MXc5exfff7KNCE/x2LKTJKjGhLhoL7pbKgdeiaAuJcyZhoe+JIcGPq9/vuKzeVOlCHhHi4NbzvrPunPH7jTST+RwFJi/fgd5HkA2X2EqekASwpf21dORbdu+RQ7NGTHXUGRqFIn+/AQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168524; c=relaxed/simple; bh=8OyhLe7uGzcgXDJMN1x4zhofshkuuXKUaY7vejc0fO8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=vEVrn8tYfKhWvBf16H0d/ERuq1p6PiksWHu72cCNqKk/AiAlBc7VLZ1f7oUCI2rERCf4YOUpFGixa4okzpPNCiw7JzeIOb9agDTEDCwrJOEgSjdGiIuXCBdJXvQoscnnaEH04+7VZTegKan58DArqW8SHy6Zqr12doINky81dFc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=L+/m6tAs; 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="L+/m6tAs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0AD7FC4CEEA; Fri, 28 Mar 2025 13:28:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168524; bh=8OyhLe7uGzcgXDJMN1x4zhofshkuuXKUaY7vejc0fO8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L+/m6tAssbkrEzLaEmJ4SnrauqToRmGIQaaUWWEnXZgGOnWwuiy9EisUeU4XAfzT5 qDHFhalKU6RrNtO5HXQS4L6VrC9JtpWpKfRe2LOFVLxg9PUIwTmTOJzcjSHaVaElF1 kERY2SfFjYbkzfUG37YmdsSlNxST4JmuQ0O1SUvO0X+OuPNOV/ANRxAIYtiMzjpo70 JRjjVZw7RxSNjYA56gUSXmieok4gPKRk1er0BHQ2gXOT5vhScEUsUaaMBaCDgBSj4V L7CNSdiguIkMvtDKoZjTFcfCIf/Zn5N+tOR47HJa71B6FJ+ZeklWvpmI1L/9RK6c69 7ztIuIVLl29+A== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 33/49] x86/alternatives: Move the text_poke_array manipulation into text_poke_int3_loc_init() and rename it to __smp_text_poke_batch_add() Date: Fri, 28 Mar 2025 14:26:48 +0100 Message-ID: <20250328132704.1901674-34-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" This simplifies the code and code generation a bit: text data bss dec hex filename 14802 1029 4112 19943 4de7 alternative.o.before 14784 1029 4112 19925 4dd5 alternative.o.after Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 566b857d210d..f0351abcbfaa 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2752,12 +2752,14 @@ static void smp_text_poke_batch_process(void) } } =20 -static void text_poke_int3_loc_init(struct smp_text_poke_loc *tp, void *ad= dr, - const void *opcode, size_t len, const void *emulate) +static void __smp_text_poke_batch_add(void *addr, const void *opcode, size= _t len, const void *emulate) { + struct smp_text_poke_loc *tp; struct insn insn; int ret, i =3D 0; =20 + tp =3D &text_poke_array.vec[text_poke_array.nr_entries++]; + if (len =3D=3D 6) i =3D 1; memcpy((void *)tp->text, opcode+i, len-i); @@ -2873,12 +2875,8 @@ static void smp_text_poke_batch_flush(void *addr) =20 void __ref smp_text_poke_batch_add(void *addr, const void *opcode, size_t = len, const void *emulate) { - struct smp_text_poke_loc *tp; - smp_text_poke_batch_flush(addr); - - tp =3D &text_poke_array.vec[text_poke_array.nr_entries++]; - text_poke_int3_loc_init(tp, addr, opcode, len, emulate); + __smp_text_poke_batch_add(addr, opcode, len, emulate); } =20 /** @@ -2894,13 +2892,9 @@ void __ref smp_text_poke_batch_add(void *addr, const= void *opcode, size_t len, c */ void __ref smp_text_poke_single(void *addr, const void *opcode, size_t len= , const void *emulate) { - struct smp_text_poke_loc *tp; - /* Batch-patching should not be mixed with single-patching: */ WARN_ON_ONCE(text_poke_array.nr_entries !=3D 0); =20 - tp =3D &text_poke_array.vec[text_poke_array.nr_entries++]; - text_poke_int3_loc_init(tp, addr, opcode, len, emulate); - + __smp_text_poke_batch_add(addr, opcode, len, emulate); smp_text_poke_batch_finish(); } --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 91435226D10 for ; Fri, 28 Mar 2025 13:28:46 +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=1743168526; cv=none; b=t7XLg17loDFz4rm0zaxBSDrwUxGikQng1ctpriKhbODpxuG0y22ro5UGBfSwdiOkJ4mFkbaZPqBdfr5PfeGEeFIpFcdI5Xhq9vkQG3rawgMW3qn38PAaDy8PhNre9vHL3L6YVjF/rBBfuzlfBk/msSHumuPiwLddJttD7vWBVFc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168526; c=relaxed/simple; bh=P/bBCR3/HDnjq/aCq0jw3PWY1OxhsZLcjt1pkx6Mco4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PwWzqYrCuPlEjIv1l6DP8JllJQ/Ae29G8uN0LGtKE1B0ecW7j7gRJ5nJz0vTJi/nFu8YZfAwz7H9ELb4u9/vH+aLzRyOW2T5SUBYjPsd4A8k59ys7mSwuOHNYNwgs7DSP4IJaY1OOwSC+Ee8Yf/EIL00S+jXvVjhiorVrC8smoM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MMUmYLVv; 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="MMUmYLVv" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 764CCC4CEE5; Fri, 28 Mar 2025 13:28:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168526; bh=P/bBCR3/HDnjq/aCq0jw3PWY1OxhsZLcjt1pkx6Mco4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MMUmYLVvfsKH/kUkIOYPLrjM5msT6/2eOZh2xLKd1jtC4MIPbpliTpwOqJ59SBehc 4woYkms2t8IcRfyQm16HL+zjoV37CZhl0KOb9oCF8A8ycKJ9s5faOzCfwZX4eaHqxU vWC0kmjEK0XFyWB/09fupJPEApwrlHpmWszxCE03F8o9ItuGbmpRaMaWXiIdt91z2C /wD5tLnLKWVVdsEWOr1xIDZ9htCMloz5qZE7MXpqWfg/L8T89VZ/XVuRCVnCmsw/RW WAWzby7sRaqIdeXAD1vIsmvbRemliAA60l5Z+qDzIxErt6HNYcPNE7bfXT8cmywOFy cnmjeQPx5YYlQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 34/49] x86/alternatives: Remove the mixed-patching restriction on smp_text_poke_single() Date: Fri, 28 Mar 2025 14:26:49 +0100 Message-ID: <20250328132704.1901674-35-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" At this point smp_text_poke_single(addr, opcode, len, emulate) is equivalen= t to: smp_text_poke_batch_add(addr, opcode, len, emulate); smp_text_poke_batch_finish(); So remove the restriction on mixing single-instruction patching with multi-instruction patching. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index f0351abcbfaa..4f880a435e98 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2892,9 +2892,6 @@ void __ref smp_text_poke_batch_add(void *addr, const = void *opcode, size_t len, c */ void __ref smp_text_poke_single(void *addr, const void *opcode, size_t len= , const void *emulate) { - /* Batch-patching should not be mixed with single-patching: */ - WARN_ON_ONCE(text_poke_array.nr_entries !=3D 0); - __smp_text_poke_batch_add(addr, opcode, len, emulate); smp_text_poke_batch_finish(); } --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 7134A22A1E1 for ; Fri, 28 Mar 2025 13:28:49 +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=1743168529; cv=none; b=fsgdxKEAixc2vzBAhAoynWWzPY2QQSpnoWJEXyMI0LpRxA1fVzo73lXJj9nL37vf0b6duKKowlxQyd5JxLF80KL+++AKBGsgTZ8gaQze6NUFH6V/7l3rkV5kFJzKtHftUeWVsJGVXdgdf8TE6IWe4wGVddeQ5UYS6sB9N4KptxQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168529; c=relaxed/simple; bh=lJU3ODFwidzxqO61R7s5hperFLlPIqDXHOUEM9oA12s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QbpU+Mp8g/6Nd19i0kPnOhJ7DGpFet0GCdUpsIUprEVXxZOtj8kz6f5tqanzTZ/Xux4KxkUj8IkIHqS29643xNZLQEPJxpWOitOjAmHsQuUyDjV2QhabsojwIxratAIrF1e2jEpRxBCFvds1MSEh0MXyxktF4KauvYq3Ynu5q8E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qkySPDNo; 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="qkySPDNo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E9905C4CEE4; Fri, 28 Mar 2025 13:28:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168528; bh=lJU3ODFwidzxqO61R7s5hperFLlPIqDXHOUEM9oA12s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qkySPDNo2sQXsMF7MwEXtg9Y1pq0eMXQPzS6TyWxY8ONDMSzByrbNyMgpz03R7PbN XnH2PbCUwyZ3nZK4qioMVRV8d4gRofRpqq4MDxR2EZssyzK9Wee03crFyc5uDavV7k Y6kKsfrubFxkJUTg9JskyS5TQBAwJlqvaYH47MvSIqt/IZcK1TgLSuK9dDvLyfkp8J 8oAFAYdPNSFHmX35PoW+1dOUJ6QBXPtwYSHjz4/bgU8UjofWHAz6PM1bkQfNsxIl5Y 4n6NIL/6dr1lH1iVQbnOcWKo1Q6QuOdbXyhDSxQZP7LNf8If9H83eQ0rokXb2g/Qme cdmka5PhNsW2Q== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 35/49] x86/alternatives: Document 'smp_text_poke_single()' Date: Fri, 28 Mar 2025 14:26:50 +0100 Message-ID: <20250328132704.1901674-36-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" Extend the documentation to better describe its purpose. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 4f880a435e98..a32959019589 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2880,7 +2880,7 @@ void __ref smp_text_poke_batch_add(void *addr, const = void *opcode, size_t len, c } =20 /** - * smp_text_poke_single() -- update instructions on live kernel on SMP + * smp_text_poke_single() -- update instruction on live kernel on SMP imme= diately * @addr: address to patch * @opcode: opcode of new instruction * @len: length to copy @@ -2888,7 +2888,8 @@ void __ref smp_text_poke_batch_add(void *addr, const = void *opcode, size_t len, c * * Update a single instruction with the vector in the stack, avoiding * dynamically allocated memory. This function should be used when it is - * not possible to allocate memory. + * not possible to allocate memory for a vector. The single instruction + * is patched in immediately. */ void __ref smp_text_poke_single(void *addr, const void *opcode, size_t len= , const void *emulate) { --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 DB22B17A2EC for ; Fri, 28 Mar 2025 13:28:51 +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=1743168531; cv=none; b=GTsEhzpmTprnnY2ZmX4I/k3nnDuoU4Woo/IRGRHCQVqNRM0CJGHC/8ZQb065moty2GZdq8N3aauEUaJDHZm36KYxPs1dgunm3VFktJv2BSsbvm1tez/j0bYtTKa20luJjZRGg3N3tvLDJ90YRUMxaZtF/7VT5MdNEsM7Q5xFrbU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168531; c=relaxed/simple; bh=TyCgl0WWPcOFP2Yn2IFD0dA42cp18RAgWIU+KtDMm2Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HuXKK5QvBJIY3UrwCHFHJ0daHKZv7GB2A6Ark1Wamr/STPsWOBYksN4oaIF9qimWkjrn2ksgI3C7bFKvf23w0soBhS1wm3qjYWBsF3Ski4to2K/hKVFBT/R+KIx3ofrieSYA6zk2juexPG81ByWCSh7grHjIHQ3N4IB/OEHOAGo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=YmXgEdeh; 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="YmXgEdeh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 661BCC4CEEA; Fri, 28 Mar 2025 13:28:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168531; bh=TyCgl0WWPcOFP2Yn2IFD0dA42cp18RAgWIU+KtDMm2Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YmXgEdehZg8Ga80NAc5jukulPYjNJT9nfyujIPdUriNAjuptXbeP9VmPs+7wq5XK5 UUjyLBHfsSBze+tHIkkMWjkNnCkM0/AI0xZPsdYnYXBkgdr2SlWgO7HcmebmxA+OjA V7DImR3ecyH/Z+p5oTrFC1OLXiRZyEabV8uwlfxTtVQ1oZy8BWrDdR2eXbClKdBlmw 8oAZEfz0hSHHnop+pj0rAHmzpD0uDy4qA+EnTsqAhNW64SQAUkfBuKeiP1FUYcq+Nm 6i7z+onIX/LIIKr45QqBqtPWJNybvU2f7WYwebhlJBYP3VLg0xneeGsgCj80REfRcr 1jGJx7QRD5EBw== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 36/49] x86/alternatives: Add documentation for smp_text_poke_batch_add() Date: Fri, 28 Mar 2025 14:26:51 +0100 Message-ID: <20250328132704.1901674-37-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index a32959019589..1df8fac6740d 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2873,6 +2873,19 @@ static void smp_text_poke_batch_flush(void *addr) } } =20 +/** + * smp_text_poke_batch_add() -- update instruction on live kernel on SMP, = batched + * @addr: address to patch + * @opcode: opcode of new instruction + * @len: length to copy + * @emulate: instruction to be emulated + * + * Add a new instruction to the current queue of to-be-patched instructions + * the kernel maintains. The patching request will not be executed immedia= tely, + * but becomes part of an array of patching requests, optimized for batched + * execution. All pending patching requests will be executed on the next + * smp_text_poke_batch_finish() call. + */ void __ref smp_text_poke_batch_add(void *addr, const void *opcode, size_t = len, const void *emulate) { smp_text_poke_batch_flush(addr); --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 EE26222B585 for ; Fri, 28 Mar 2025 13:28:53 +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=1743168534; cv=none; b=kJZmvkKqYed3gp5GdHJiiqhAhljzz+7Nfipk1R4KXNyfyEwVenMdhynuea4d2EM8volNti+Pm6Tkb3sAXS0nnPnT1WUPM3v+SOZypW854VKW2WMkCN1kpSGNLAO5r0KtZ6QgAv55knmIo/JgpMpdh9J7IZk3w8W/sWj5mk56X64= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168534; c=relaxed/simple; bh=mxduIR0UIOcfSzgudKU9hHk8lNuRDrIi6rjN++/rAQY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LMa1h+0eYOH51ub95YqM2d29kd4l7mvYZKZeHsHbN9wNJWnOMlBtWRBgALhjFczjRKQ/ezx/RvFnad0x2xPrXmV7GcJ0+T7NOBoR/j9AOAEVuZx6yGX2t4/1rqGmOaAMAtrBhVzBE70nsIhSb+1jHkcjDBoBdMzzx4FbcZfHrpg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XpINxB00; 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="XpINxB00" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D83FBC4CEEB; Fri, 28 Mar 2025 13:28:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168533; bh=mxduIR0UIOcfSzgudKU9hHk8lNuRDrIi6rjN++/rAQY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XpINxB00aHZc/ilLTWdpeOoI8NMT0fcuv/pb27qoRNPHllB7qVYaj8Cmh+BzzKs+y AFYJoEvijIPhbaL694VQlDx8F9AHP2yFYzV10WjWwH6NS+SrrdYjdBOx+869h3N/Az gwNwSaV4H8pMCcsGm42c7wtC+1qoU8KueSXJ+3SAOxCYzaVgEs0mts7ParrwV3ffmC 7+ODt7l9TWsiV62u3VKKvndRSmhrgB3PoVFhvzg80TvaxJWzMPebUsowhq8NA1UEXl vhxGb0geLQwbhdHyshPhKSSO6tpVDYXLZ7/E5+1pU5cKT5g/bAT2cuIkapAm8Fqd7G af1NqMQXgcRQA== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 37/49] x86/alternatives: Move text_poke_array completion from smp_text_poke_batch_finish() and smp_text_poke_batch_flush() to smp_text_poke_batch_process() Date: Fri, 28 Mar 2025 14:26:52 +0100 Message-ID: <20250328132704.1901674-38-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" Simplifies the code and improves code generation a bit: text data bss dec hex filename 14769 1017 4112 19898 4dba alternative.o.before 14742 1017 4112 19871 4d9f alternative.o.after Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 1df8fac6740d..5293929488f0 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2750,6 +2750,9 @@ static void smp_text_poke_batch_process(void) if (unlikely(!atomic_dec_and_test(refs))) atomic_cond_read_acquire(refs, !VAL); } + + /* They are all completed: */ + text_poke_array.nr_entries =3D 0; } =20 static void __smp_text_poke_batch_add(void *addr, const void *opcode, size= _t len, const void *emulate) @@ -2857,20 +2860,16 @@ static bool text_poke_addr_ordered(void *addr) =20 void smp_text_poke_batch_finish(void) { - if (text_poke_array.nr_entries) { + if (text_poke_array.nr_entries) smp_text_poke_batch_process(); - text_poke_array.nr_entries =3D 0; - } } =20 static void smp_text_poke_batch_flush(void *addr) { lockdep_assert_held(&text_mutex); =20 - if (text_poke_array.nr_entries =3D=3D TP_ARRAY_NR_ENTRIES_MAX || !text_po= ke_addr_ordered(addr)) { + if (text_poke_array.nr_entries =3D=3D TP_ARRAY_NR_ENTRIES_MAX || !text_po= ke_addr_ordered(addr)) smp_text_poke_batch_process(); - text_poke_array.nr_entries =3D 0; - } } =20 /** --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 74C2122D4ED for ; Fri, 28 Mar 2025 13:28:56 +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=1743168536; cv=none; b=OEZjEEEYf+LvKg5VtO80yZsoxNqn1g2zx58nr9LYkqwOo3NdDBLfIb/Ot2iDhp6T5tb7E+z8idEj3VJo16LJ6q2H9g8gd7BPxQPsy2U+Q5821rs841hhVR03FOvAAnVvztd8KjqQARAbCfF16ILi25v02NMC5MkB9aQchNYkf58= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168536; c=relaxed/simple; bh=EpzY1ysB9vvgVyONPFQ7L89dIUcTnCMnWw5EfRgCt8A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TKQpw4ckUh+tJp5vkKLUCzkF4ld0SHPHcgk2gO+EFdhKhSTpDCW6Fke6ZyTQeLAMi68+YeeJVssCMNcL6PEvJy+Fy5CDa1WTpM3BKjesv4COOccDpRt0s6SUAZqHpDlbHb8qO1zLHQEY0zb+ChNINjZZxVcGyNEFYBqbkF8MlsI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MOQClxIc; 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="MOQClxIc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 531E2C4CEE4; Fri, 28 Mar 2025 13:28:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168536; bh=EpzY1ysB9vvgVyONPFQ7L89dIUcTnCMnWw5EfRgCt8A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MOQClxIc+ZahvJ1elByNOWB+OVSzCoAtBs5aKsdB/ptmyFBIYO0QxB0o1vjJ+SbVv YC2BhNM8x5QGVcWAd+fj2aB5SzWhDx9cEIyReyaglg0bBVrmaNHSDuGHYwMZTwjAq5 eG+mnIw3QqQ/c5dg/fjJMvBCxABIWBsFvuByncNR7M8PsMhZK5dTkz/yBwD+2DulHR 4ZaQk6yvE2/8bBOsGxhFj8GA9VqBI916P1EpFLPGZpe1LW18hQLD+b6PpzmZabahCD TC1jDcutqgiCcgh+DniSsl/PNgzdNovZvu6RL8o/5pGf4RxMSo54+PfU8adCYBu6g0 pa9XvaNIpMHew== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 38/49] x86/alternatives: Rename 'text_poke_sync()' to 'smp_text_poke_sync_each_cpu()' Date: Fri, 28 Mar 2025 14:26:53 +0100 Message-ID: <20250328132704.1901674-39-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" Unlike sync_core(), text_poke_sync() is a very heavy operation, as it sends an IPI to every online CPU in the system and waits for completion. Reflect this in the name. Signed-off-by: Ingo Molnar --- arch/x86/include/asm/text-patching.h | 2 +- arch/x86/kernel/alternative.c | 12 ++++++------ arch/x86/kernel/kprobes/core.c | 4 ++-- arch/x86/kernel/kprobes/opt.c | 4 ++-- arch/x86/kernel/module.c | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/arch/x86/include/asm/text-patching.h b/arch/x86/include/asm/te= xt-patching.h index 20ce4eda6d47..6834e652d26c 100644 --- a/arch/x86/include/asm/text-patching.h +++ b/arch/x86/include/asm/text-patching.h @@ -32,7 +32,7 @@ extern void apply_relocation(u8 *buf, const u8 * const in= str, size_t instrlen, u * an inconsistent instruction while you patch. */ extern void *text_poke(void *addr, const void *opcode, size_t len); -extern void text_poke_sync(void); +extern void smp_text_poke_sync_each_cpu(void); extern void *text_poke_kgdb(void *addr, const void *opcode, size_t len); extern void *text_poke_copy(void *addr, const void *opcode, size_t len); #define text_poke_copy text_poke_copy diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 5293929488f0..b0bd8cd524c5 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2445,7 +2445,7 @@ static void do_sync_core(void *info) sync_core(); } =20 -void text_poke_sync(void) +void smp_text_poke_sync_each_cpu(void) { on_each_cpu(do_sync_core, NULL, 1); } @@ -2469,8 +2469,8 @@ struct smp_text_poke_loc { #define TP_ARRAY_NR_ENTRIES_MAX (PAGE_SIZE / sizeof(struct smp_text_poke_l= oc)) =20 static struct smp_text_poke_array { - int nr_entries; struct smp_text_poke_loc vec[TP_ARRAY_NR_ENTRIES_MAX]; + int nr_entries; } text_poke_array; =20 static DEFINE_PER_CPU(atomic_t, text_poke_array_refs); @@ -2649,7 +2649,7 @@ static void smp_text_poke_batch_process(void) text_poke(text_poke_addr(&text_poke_array.vec[i]), &int3, INT3_INSN_SIZE= ); } =20 - text_poke_sync(); + smp_text_poke_sync_each_cpu(); =20 /* * Second step: update all but the first byte of the patched range. @@ -2711,7 +2711,7 @@ static void smp_text_poke_batch_process(void) * not necessary and we'd be safe even without it. But * better safe than sorry (plus there's not only Intel). */ - text_poke_sync(); + smp_text_poke_sync_each_cpu(); } =20 /* @@ -2732,13 +2732,13 @@ static void smp_text_poke_batch_process(void) } =20 if (do_sync) - text_poke_sync(); + smp_text_poke_sync_each_cpu(); =20 /* * Remove and wait for refs to be zero. * * Notably, if after step-3 above the INT3 got removed, then the - * text_poke_sync() will have serialized against any running INT3 + * smp_text_poke_sync_each_cpu() will have serialized against any running= INT3 * handlers and the below spin-wait will not happen. * * IOW. unless the replacement instruction is INT3, this case goes diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c index 09608fd93687..47cb8eb138ba 100644 --- a/arch/x86/kernel/kprobes/core.c +++ b/arch/x86/kernel/kprobes/core.c @@ -808,7 +808,7 @@ void arch_arm_kprobe(struct kprobe *p) u8 int3 =3D INT3_INSN_OPCODE; =20 text_poke(p->addr, &int3, 1); - text_poke_sync(); + smp_text_poke_sync_each_cpu(); perf_event_text_poke(p->addr, &p->opcode, 1, &int3, 1); } =20 @@ -818,7 +818,7 @@ void arch_disarm_kprobe(struct kprobe *p) =20 perf_event_text_poke(p->addr, &int3, 1, &p->opcode, 1); text_poke(p->addr, &p->opcode, 1); - text_poke_sync(); + smp_text_poke_sync_each_cpu(); } =20 void arch_remove_kprobe(struct kprobe *p) diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c index 9307a40f4983..0aabd4c4e2c4 100644 --- a/arch/x86/kernel/kprobes/opt.c +++ b/arch/x86/kernel/kprobes/opt.c @@ -513,11 +513,11 @@ void arch_unoptimize_kprobe(struct optimized_kprobe *= op) JMP32_INSN_SIZE - INT3_INSN_SIZE); =20 text_poke(addr, new, INT3_INSN_SIZE); - text_poke_sync(); + smp_text_poke_sync_each_cpu(); text_poke(addr + INT3_INSN_SIZE, new + INT3_INSN_SIZE, JMP32_INSN_SIZE - INT3_INSN_SIZE); - text_poke_sync(); + smp_text_poke_sync_each_cpu(); =20 perf_event_text_poke(op->kp.addr, old, JMP32_INSN_SIZE, new, JMP32_INSN_S= IZE); } diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c index a7998f351701..231d6326d1fd 100644 --- a/arch/x86/kernel/module.c +++ b/arch/x86/kernel/module.c @@ -206,7 +206,7 @@ static int write_relocate_add(Elf64_Shdr *sechdrs, write, apply); =20 if (!early) { - text_poke_sync(); + smp_text_poke_sync_each_cpu(); mutex_unlock(&text_mutex); } =20 --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 49E001A264A for ; Fri, 28 Mar 2025 13:28:58 +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=1743168539; cv=none; b=E8F+JJgAl99U8wuVkQkSXr1t4k5PnKfdmLo9YfzYhK0nY3d7kG8ek0ZX+EN+CxTCMERVJbD6mxxKTEe9Ch+yIFUXEmOe9EzGEA8L5nvXWey0iWOsYX6ilQ/qiWMRzUQl8ytJJHlI9poXUezwRwhDYSkr73UndIGMsr/uZmnvFvs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168539; c=relaxed/simple; bh=C3C1rhpZSoOuLxMvz4zWWRzJI/0I8IitC6KQdEtD1BI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OcmX36BmVoCA9m1Ae00qFCtYCjUdo4HKkhkiuyz+2fMDAan3NdFS5T4bbcCjxzhhH/iHFTbXtSdLnm/XRHVFCwZUXQvWruyTLfOf5vdDnNYfassfTvjeL8KZcbfvkfkp8VZ1W0+uxGJmm6uK+ib4dbXYeknv6zUsGG2X+fIXRHo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=swt76V96; 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="swt76V96" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C4521C4CEE4; Fri, 28 Mar 2025 13:28:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168538; bh=C3C1rhpZSoOuLxMvz4zWWRzJI/0I8IitC6KQdEtD1BI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=swt76V96Pqa9xtEflZsHM7fnp87Z/tYNNrwRCcbohhGwBtTEZe07Lw11mzxdEJ6fV 5aph8rnBhp0khgFrvHaXFiuSHcrjyObaJ4lGZasLBkRjVxD8rUgrzAAU6YIgraqZZJ pzZkVsXs9mFuf00ufiaoN3v6K6jTNUBAqdMlWEZ4Hd7QQ7A8u1TUGqKJPAsBZPziU4 cSTBJUR8PIsOKbRmrUpuINMGvvOh27DiYCXwvEPqdOGSuXinL6SgZzlzOgr4xxXm+E i1eEqgZ00T5DVmpSYPHeA6z4qL5TS6hQRCTNTiYno4As4WPJ0agLz0U6gc8Zyd1l31 f0wmYR5ooqGOA== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 39/49] x86/alternatives: Simplify text_poke_addr_ordered() Date: Fri, 28 Mar 2025 14:26:54 +0100 Message-ID: <20250328132704.1901674-40-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" - Use direct 'void *' pointer comparison, there's no need to force the type to 'unsigned long'. - Remove the 'tp' local variable indirection Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index b0bd8cd524c5..27f1c7bdd384 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2838,8 +2838,6 @@ static void __smp_text_poke_batch_add(void *addr, con= st void *opcode, size_t len */ static bool text_poke_addr_ordered(void *addr) { - struct smp_text_poke_loc *tp; - WARN_ON_ONCE(!addr); =20 if (!text_poke_array.nr_entries) @@ -2851,8 +2849,7 @@ static bool text_poke_addr_ordered(void *addr) * is violated and we must first flush all pending patching * requests: */ - tp =3D &text_poke_array.vec[text_poke_array.nr_entries-1]; - if ((unsigned long)text_poke_addr(tp) > (unsigned long)addr) + if (text_poke_addr(text_poke_array.vec + text_poke_array.nr_entries-1) > = addr) return false; =20 return true; --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 C89B922E3E6 for ; Fri, 28 Mar 2025 13:29:01 +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=1743168541; cv=none; b=IVCmWnQG0BkzBduorLeUJ3eMaSQK1beO9sfMZ8eQ8rW340GZnsmyNfXdZTvmgl4P/IpbdSf8oFeDsFbzTS+LY/2muQi939kF64EqYSaq7W9grg7IriRJ9+w2DaWs7UKNooOqlO9P5IFMPZDbQpRRVtkHc5/rI1WfXLSdz2dzuq4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168541; c=relaxed/simple; bh=wH93hY2iOLzXDWLc6kNmAFjdkcDsvMoeDOlT9xfdYNo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iuTNMcGUdcJ1Xbj10IL6Pct8rDYqsMwz0q787xHTqZNxNp0YpNGJ4wyUEBEPvfS3IERm/VoQI45rZ4rHcIDKgZsk+RKM9xO+rYIeLnYJBmRdwwYn1CTwoRLe3FjppgRRrdYNiwkI/twMKVw2DwB9G+WoHPEw+R8yAEI5uG4d5Js= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dKrIMr7j; 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="dKrIMr7j" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C5B0C4CEE5; Fri, 28 Mar 2025 13:28:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168541; bh=wH93hY2iOLzXDWLc6kNmAFjdkcDsvMoeDOlT9xfdYNo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dKrIMr7jotNw5vgcEZszK1Vl5rlEI5P0Eum45e0Hg8XMOMi9XYwcTPEHsC7jfcSZU O13tDjJPRadtuUEfUUeLL1tZF6/G6jZ8/X+Ld+wopDor3Z8VohMf/lGCjE9Mz7CtYn ryFBc0jneR3/NF/1HjChURtwPRtRhlirCEgw8BonmBa32hSTCs+nQruwsuhIbeinxm NTW042GBRyMqH5UJ02FYAqFL5Fhs1ODY7rRPyEMQyNKUVIv2gWY4tjBquXKzpAj2ds 9vrNCA1t99hlCQs6jFRVZ9t+9UyLd5zwRwUS6mz5S2v/9Lj+O2bHBNTTnhQTR1Nl6J GIkYpEB6zGC0w== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 40/49] x86/alternatives: Constify text_poke_addr() Date: Fri, 28 Mar 2025 14:26:55 +0100 Message-ID: <20250328132704.1901674-41-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" This will also allow the simplification of patch_cmp(). Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 27f1c7bdd384..5823d4764d92 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2493,7 +2493,7 @@ static __always_inline void put_text_poke_array(void) raw_atomic_dec(refs); } =20 -static __always_inline void *text_poke_addr(struct smp_text_poke_loc *tp) +static __always_inline void *text_poke_addr(const struct smp_text_poke_loc= *tp) { return _stext + tp->rel_addr; } --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 CE9E922F16E for ; Fri, 28 Mar 2025 13:29:03 +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=1743168543; cv=none; b=Nu5yU5x2PosTLWJWK9sa4z3sW5g2FzW1Rpx9H8tkgJ5Vw+WmlTkZxNl4BMx9hAI2AV7wx+6kzrNJ7QHU4fM++X0OvmJPKd6OJaXmEeAGhUVCT2+y/IVig9Pi0RI2Q2rB2DbbRWQPDDpmr+iJwQiyEMXiUP8lpOqQvfTMp1MzxR8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168543; c=relaxed/simple; bh=z8thZ30CzrDJ57LgmatHsMKsdMaS7R3hQzYRqZJGI8k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p3uqGC/kUEekIZVl8VWwdb1oSTpHzXQbwNOSIXHz0TipeHAN7lYDtwGxb9gq1l4x3f7MhKmhoO7j3mQMjxyouL5JLiRjeex2syKKoYU6OtTiyVRcP44r3yqEEXZXYjVYmBebQmIzZWbdfOQTAK2BR89yAFv5vcR30sOm+HHl5M0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gaccyz+8; 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="gaccyz+8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B995EC4CEE4; Fri, 28 Mar 2025 13:29:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168543; bh=z8thZ30CzrDJ57LgmatHsMKsdMaS7R3hQzYRqZJGI8k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gaccyz+8yvbYp/ZyWSj3E56GtVzFy04xKDsXVnTV23mEtuwWd7Nd6E3DMk5ZXQNH2 zre+BNROiANBgtqBEaplBkegzA0EWhsRH+9szCzMqL2oa7ZoRIgyIW5Og+MoVaR/kX GJwBUj1sxCpZ6fK+BERcN2p3U/6SJOle6pzfOV9PFfjrJF/ENxMegIVWAeB8wroEqw s5uID9rneRt65uU4I6QaO6N26cgYBYyGxky65l1b4oWQqvhuH+x1DtcF4vxn7oo3v+ 1i+1WLztDJiRbQ/+18zgIUhvcdmwyzavaUwa0YlW513E9BMppUUmqhan9J6LSLzbBv n9YNkCEEemJJg== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 41/49] x86/alternatives: Simplify and clean up patch_cmp() Date: Fri, 28 Mar 2025 14:26:56 +0100 Message-ID: <20250328132704.1901674-42-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" - No need to cast over to 'struct smp_text_poke_loc *', void * is just fine for a binary search, - Use the canonical (a, b) input parameter nomenclature of cmp_func_t functions and rename the input parameters from (tp, elt) to (tpl_a, tpl_b). Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 5823d4764d92..d784738369d5 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2498,13 +2498,11 @@ static __always_inline void *text_poke_addr(const s= truct smp_text_poke_loc *tp) return _stext + tp->rel_addr; } =20 -static __always_inline int patch_cmp(const void *key, const void *elt) +static __always_inline int patch_cmp(const void *tpl_a, const void *tpl_b) { - struct smp_text_poke_loc *tp =3D (struct smp_text_poke_loc *) elt; - - if (key < text_poke_addr(tp)) + if (tpl_a < text_poke_addr(tpl_b)) return -1; - if (key > text_poke_addr(tp)) + if (tpl_a > text_poke_addr(tpl_b)) return 1; return 0; } --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 47D5522FF22 for ; Fri, 28 Mar 2025 13:29:06 +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=1743168546; cv=none; b=rMEV7edKVWLeOLxomGysClh7tDgBiG+11NJalL0GZyycVIst83sd6Qt75zC2eTytFYQIRzvW8ppwpurRrSCpJpCyQ34rukvWvyaBqrIKZMpI4nxuuXRrfEeF7O8JnPEmESTCQTvlGUtV1YV1dJ5D8iMYFJq5aCEdviVcZOMgCco= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168546; c=relaxed/simple; bh=BjN5lM/UNpRkCLA82KrVE2Zik517aStzYYQ/h795eDw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Jh95i6/sstxTUPt9mkKmSOWX+98qA74WJq+gIarx9MZoRTiauKJj0dFkdR0a/DoOQRuT+lOKddDCOGdhupz/IqO2qBQHxlP05prEoRFkGfYfSezqRlayrWYUePmO62BpyI6AUYwht3C6BGMuc6zUUc7XWPT/SPm3BpUxjymfKGE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=c9BqOdUA; 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="c9BqOdUA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 33D3EC4CEE4; Fri, 28 Mar 2025 13:29:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168546; bh=BjN5lM/UNpRkCLA82KrVE2Zik517aStzYYQ/h795eDw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c9BqOdUApFuDwMN8bvhN+8ou0bnHAgzeRdNK0zBAW4tJiqlcRkS9jdmPH2XCiGWoL 3VDs0vvUNLgITUlXEvnoc0eLiIw/Ktw25k7YzUm/vPcSoMF7yVAXu1MY5NM/3A6oUB 1eezVNMT1wsq4BnromfqiG4oaGIrR7n3iPmJvsL+CXUZsg2n+aFrHU8lNGqn+P3Ekm CIGV8U2xGFL09PIU16sJWJs10XMac6slqcQJFIGXsKzl941S5gGI1iQoNLQ41p4rXM 4BeWAs1gcY8qeDAkNWdMIyirMMxU+mTAFvQzvX4LBiPtBqrj60X7abv8rzMmU5hI6V SQFzsI6fpCEcQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 42/49] x86/alternatives: Standardize on 'tpl' local variable names for 'struct smp_text_poke_loc *' Date: Fri, 28 Mar 2025 14:26:57 +0100 Message-ID: <20250328132704.1901674-43-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" There's no toilet paper in this code. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 54 +++++++++++++++++++++++++++------------= --------------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index d784738369d5..62a6c69184c9 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2493,9 +2493,9 @@ static __always_inline void put_text_poke_array(void) raw_atomic_dec(refs); } =20 -static __always_inline void *text_poke_addr(const struct smp_text_poke_loc= *tp) +static __always_inline void *text_poke_addr(const struct smp_text_poke_loc= *tpl) { - return _stext + tp->rel_addr; + return _stext + tpl->rel_addr; } =20 static __always_inline int patch_cmp(const void *tpl_a, const void *tpl_b) @@ -2509,7 +2509,7 @@ static __always_inline int patch_cmp(const void *tpl_= a, const void *tpl_b) =20 noinstr int smp_text_poke_int3_trap_handler(struct pt_regs *regs) { - struct smp_text_poke_loc *tp; + struct smp_text_poke_loc *tpl; int ret =3D 0; void *ip; =20 @@ -2538,20 +2538,20 @@ noinstr int smp_text_poke_int3_trap_handler(struct = pt_regs *regs) * Skip the binary search if there is a single member in the vector. */ if (unlikely(text_poke_array.nr_entries > 1)) { - tp =3D __inline_bsearch(ip, text_poke_array.vec, text_poke_array.nr_entr= ies, + tpl =3D __inline_bsearch(ip, text_poke_array.vec, text_poke_array.nr_ent= ries, sizeof(struct smp_text_poke_loc), patch_cmp); - if (!tp) + if (!tpl) goto out_put; } else { - tp =3D text_poke_array.vec; - if (text_poke_addr(tp) !=3D ip) + tpl =3D text_poke_array.vec; + if (text_poke_addr(tpl) !=3D ip) goto out_put; } =20 - ip +=3D tp->len; + ip +=3D tpl->len; =20 - switch (tp->opcode) { + switch (tpl->opcode) { case INT3_INSN_OPCODE: /* * Someone poked an explicit INT3, they'll want to handle it, @@ -2564,16 +2564,16 @@ noinstr int smp_text_poke_int3_trap_handler(struct = pt_regs *regs) break; =20 case CALL_INSN_OPCODE: - int3_emulate_call(regs, (long)ip + tp->disp); + int3_emulate_call(regs, (long)ip + tpl->disp); break; =20 case JMP32_INSN_OPCODE: case JMP8_INSN_OPCODE: - int3_emulate_jmp(regs, (long)ip + tp->disp); + int3_emulate_jmp(regs, (long)ip + tpl->disp); break; =20 case 0x70 ... 0x7f: /* Jcc */ - int3_emulate_jcc(regs, tp->opcode & 0xf, (long)ip, tp->disp); + int3_emulate_jcc(regs, tpl->opcode & 0xf, (long)ip, tpl->disp); break; =20 default: @@ -2755,33 +2755,33 @@ static void smp_text_poke_batch_process(void) =20 static void __smp_text_poke_batch_add(void *addr, const void *opcode, size= _t len, const void *emulate) { - struct smp_text_poke_loc *tp; + struct smp_text_poke_loc *tpl; struct insn insn; int ret, i =3D 0; =20 - tp =3D &text_poke_array.vec[text_poke_array.nr_entries++]; + tpl =3D &text_poke_array.vec[text_poke_array.nr_entries++]; =20 if (len =3D=3D 6) i =3D 1; - memcpy((void *)tp->text, opcode+i, len-i); + memcpy((void *)tpl->text, opcode+i, len-i); if (!emulate) emulate =3D opcode; =20 ret =3D insn_decode_kernel(&insn, emulate); BUG_ON(ret < 0); =20 - tp->rel_addr =3D addr - (void *)_stext; - tp->len =3D len; - tp->opcode =3D insn.opcode.bytes[0]; + tpl->rel_addr =3D addr - (void *)_stext; + tpl->len =3D len; + tpl->opcode =3D insn.opcode.bytes[0]; =20 if (is_jcc32(&insn)) { /* * Map Jcc.d32 onto Jcc.d8 and use len to distinguish. */ - tp->opcode =3D insn.opcode.bytes[1] - 0x10; + tpl->opcode =3D insn.opcode.bytes[1] - 0x10; } =20 - switch (tp->opcode) { + switch (tpl->opcode) { case RET_INSN_OPCODE: case JMP32_INSN_OPCODE: case JMP8_INSN_OPCODE: @@ -2790,14 +2790,14 @@ static void __smp_text_poke_batch_add(void *addr, c= onst void *opcode, size_t len * next instruction can be padded with INT3. */ for (i =3D insn.length; i < len; i++) - BUG_ON(tp->text[i] !=3D INT3_INSN_OPCODE); + BUG_ON(tpl->text[i] !=3D INT3_INSN_OPCODE); break; =20 default: BUG_ON(len !=3D insn.length); } =20 - switch (tp->opcode) { + switch (tpl->opcode) { case INT3_INSN_OPCODE: case RET_INSN_OPCODE: break; @@ -2806,21 +2806,21 @@ static void __smp_text_poke_batch_add(void *addr, c= onst void *opcode, size_t len case JMP32_INSN_OPCODE: case JMP8_INSN_OPCODE: case 0x70 ... 0x7f: /* Jcc */ - tp->disp =3D insn.immediate.value; + tpl->disp =3D insn.immediate.value; break; =20 default: /* assume NOP */ switch (len) { case 2: /* NOP2 -- emulate as JMP8+0 */ BUG_ON(memcmp(emulate, x86_nops[len], len)); - tp->opcode =3D JMP8_INSN_OPCODE; - tp->disp =3D 0; + tpl->opcode =3D JMP8_INSN_OPCODE; + tpl->disp =3D 0; break; =20 case 5: /* NOP5 -- emulate as JMP32+0 */ BUG_ON(memcmp(emulate, x86_nops[len], len)); - tp->opcode =3D JMP32_INSN_OPCODE; - tp->disp =3D 0; + tpl->opcode =3D JMP32_INSN_OPCODE; + tpl->disp =3D 0; break; =20 default: /* unknown instruction */ --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 B9BA6230BC6 for ; Fri, 28 Mar 2025 13:29: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=1743168548; cv=none; b=ugRwu2e/gm0dO2gTqXzfTH2+lgkv5Ai4ZjsF3FY1zhglvZ34FP2cIP0hlBUm0YEBdIKpBJx/BHvthpd/GEWkTvtobJp7P2NPhVTu4eqdtqQA3QaUAZMWMmaaUHgDj06lSPLPebU/2cLScmS8RVSWE4sClkyBKw3A0pv5Ty5LQog= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168548; c=relaxed/simple; bh=Tw3+yQ7n3S2FF8XCTvEh5x8oO8/o/42rPxJyFoMdDQQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eASqbAUFCduucNHUAk2QYTx8C45YPePTm1Fn5DGDCMUjY2L51prNXDKtja/m/D5wyI8/uH8w3oWwWeF6tu26T7z1wod953nt+ZRK9vg693wF2A4d+ssVgE6h/d6UdTXiGF1JFi7rTV72++zGq70RO2w08QhBRJS3vJ/4THBaK1o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oyIWI5QJ; 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="oyIWI5QJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A416AC4CEEA; Fri, 28 Mar 2025 13:29:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168548; bh=Tw3+yQ7n3S2FF8XCTvEh5x8oO8/o/42rPxJyFoMdDQQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oyIWI5QJNPBzIo4vb6tFbl8GA1Ukku7bS+RZuQG7RjguOTSUfUmDYVkFfLYBUukxz JUkv1MUVPoO1UI1VNA6xbWs2TYddU7/ze9noLoA2nin6XBwqmQNA3I225ZelaxZfsb LZ/dI084vKUXVlb7ywphb6cdyK5+HfenyMBB5kvzvkkmB+B9M5DxafjTJCVXDB0aTv 09PktVvdBgsr8T3UH35qmG4glPfF8DXBKZ522wu42GnpMtXjIV0pSl6TBPcJ3xpbSg pEm4guSPuhWDNXo68p7DXVCCJQ5PgwQMYMdxF4XUXdxHdBRSXDouNDUmLkoMBca5+s VOHRk5xkpML3A== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 43/49] x86/alternatives: Rename 'TP_ARRAY_NR_ENTRIES_MAX' to 'TEXT_POKE_ARRAY_MAX' Date: Fri, 28 Mar 2025 14:26:58 +0100 Message-ID: <20250328132704.1901674-44-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" Standardize on TEXT_POKE_ namespace for CPP constants too. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 62a6c69184c9..04c536d36765 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2466,10 +2466,10 @@ struct smp_text_poke_loc { u8 old; }; =20 -#define TP_ARRAY_NR_ENTRIES_MAX (PAGE_SIZE / sizeof(struct smp_text_poke_l= oc)) +#define TEXT_POKE_ARRAY_MAX (PAGE_SIZE / sizeof(struct smp_text_poke_loc)) =20 static struct smp_text_poke_array { - struct smp_text_poke_loc vec[TP_ARRAY_NR_ENTRIES_MAX]; + struct smp_text_poke_loc vec[TEXT_POKE_ARRAY_MAX]; int nr_entries; } text_poke_array; =20 @@ -2863,7 +2863,7 @@ static void smp_text_poke_batch_flush(void *addr) { lockdep_assert_held(&text_mutex); =20 - if (text_poke_array.nr_entries =3D=3D TP_ARRAY_NR_ENTRIES_MAX || !text_po= ke_addr_ordered(addr)) + if (text_poke_array.nr_entries =3D=3D TEXT_POKE_ARRAY_MAX || !text_poke_a= ddr_ordered(addr)) smp_text_poke_batch_process(); } =20 --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 391AB231A3B for ; Fri, 28 Mar 2025 13:29: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=1743168551; cv=none; b=XIsO+QLB1qAA9BiflTWwknk+jT/ni88RjmWHgAMJQwPiDipP8hvl6LQqDDK63okofCPwXpHQGgDcGPEOik6AOWtQCAQ+n/XWJveIiwi6vk+tQZlL9Q5yYEuMYsPMGG3rHQPtY48NAP3RNJ+us50ijCPX6veLbYMG5uaHQ4SZyFI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168551; c=relaxed/simple; bh=+4TEvDCl9pn5l0P3G7gieMO9jEV4OUzziwSnm8xIndY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XYp48pWFqZZL8wxZI/lwqQ7VLrfXiUuEiBa38SREQUrk7+iwEErQnq2Cp/4iz3mN3kRq6liSFtIRGgDv2GJmR8SZEUdefaimc4mAAfAcZcEx0iTnLaAY4bURK5qI6kHWgyNbbeL5DG5JupFdI53JP4/f+8USS2bQJXAhnGLNtIs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dtjj+sFz; 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="dtjj+sFz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20B87C4CEE5; Fri, 28 Mar 2025 13:29:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168551; bh=+4TEvDCl9pn5l0P3G7gieMO9jEV4OUzziwSnm8xIndY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dtjj+sFzGoMZMaZ+Ophyla+bb6OEWlTup/vOmb80V6YTsu62ceX8w8G+TbZdbRfbx Rq64KeDTZOAghArmp8VwpC0FNLKntR9hcMbYgr4SnDkah6braluIQJTXvkPy9F36id +l2emSF6GX2byMTJA0WOaKiFTAtFBXU03VB4MSp73zpxRzKS6F8vHoQ1eVeQJ3JHmx GFkGKvreWE4TGpzvDjFLXnLDJXtONviMhIbrWhxp6apzY1uSIDHoJ1J4yh1HLAfN7C I/9q8Y3QfuepF8nDZNsOCdMngDMUjI4ZdwoBFMMxDaPavNZ7d4/YC8afqWPvXu00Bj Vf5qFwsGKC+Ew== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 44/49] x86/alternatives: Rename 'POKE_MAX_OPCODE_SIZE' to 'TEXT_POKE_MAX_OPCODE_SIZE' Date: Fri, 28 Mar 2025 14:26:59 +0100 Message-ID: <20250328132704.1901674-45-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" Join the TEXT_POKE_ namespace. Signed-off-by: Ingo Molnar --- arch/x86/include/asm/text-patching.h | 4 ++-- arch/x86/kernel/alternative.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/text-patching.h b/arch/x86/include/asm/te= xt-patching.h index 6834e652d26c..53ac94743e5d 100644 --- a/arch/x86/include/asm/text-patching.h +++ b/arch/x86/include/asm/text-patching.h @@ -11,7 +11,7 @@ * JUMP_LABEL_NOP_SIZE/RELATIVEJUMP_SIZE, which are 5. * Raise it if needed. */ -#define POKE_MAX_OPCODE_SIZE 5 +#define TEXT_POKE_MAX_OPCODE_SIZE 5 =20 extern void text_poke_early(void *addr, const void *opcode, size_t len); =20 @@ -82,7 +82,7 @@ static __always_inline int text_opcode_size(u8 opcode) } =20 union text_poke_insn { - u8 text[POKE_MAX_OPCODE_SIZE]; + u8 text[TEXT_POKE_MAX_OPCODE_SIZE]; struct { u8 opcode; s32 disp; diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 04c536d36765..d724ae8913da 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2461,7 +2461,7 @@ struct smp_text_poke_loc { s32 disp; u8 len; u8 opcode; - const u8 text[POKE_MAX_OPCODE_SIZE]; + const u8 text[TEXT_POKE_MAX_OPCODE_SIZE]; /* see smp_text_poke_batch_process() */ u8 old; }; @@ -2653,8 +2653,8 @@ static void smp_text_poke_batch_process(void) * Second step: update all but the first byte of the patched range. */ for (do_sync =3D 0, i =3D 0; i < text_poke_array.nr_entries; i++) { - u8 old[POKE_MAX_OPCODE_SIZE+1] =3D { text_poke_array.vec[i].old, }; - u8 _new[POKE_MAX_OPCODE_SIZE+1]; + u8 old[TEXT_POKE_MAX_OPCODE_SIZE+1] =3D { text_poke_array.vec[i].old, }; + u8 _new[TEXT_POKE_MAX_OPCODE_SIZE+1]; const u8 *new =3D text_poke_array.vec[i].text; int len =3D text_poke_array.vec[i].len; =20 --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 A3EA3233144 for ; Fri, 28 Mar 2025 13:29: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=1743168553; cv=none; b=XSaA5YMCEzHq+rW5ce6lJd9ZPXQc8zsqL6diuU6/kBOsEQAgBRq215ku88kaPr9T3bvJY75Ybb0BhPOIfo+KKRkrmlGTb/hJHfAC+lzpvm+2jOsf79PFpbyvK+2b5VYvn7xzOokcNthOBIymW4MA83Q7mNJ/JnTV0Vpuvl4U1MI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168553; c=relaxed/simple; bh=HxCB1zwS8eQL0a0e1XiRZ4zEUKNTLOu4NFQqFhJWyys=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=b6mncn1A8h6hdGdjbED6a6dqcDej0ZHzGIFA3jm9MjyrHvxwlsnE1j4pEo4AQx8SYCw2nHBxJkw5uxSGPoj7ZXHPZfdiw51vkauIR5Z8l9Dj53iwSwG7pgSp09qH+B3PQSp2HoBRYfgLDUhpN4/ENZglaKX7xgFGLdlaF8ioBd0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ElAyk2Fq; 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="ElAyk2Fq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90ECCC4CEE4; Fri, 28 Mar 2025 13:29:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168553; bh=HxCB1zwS8eQL0a0e1XiRZ4zEUKNTLOu4NFQqFhJWyys=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ElAyk2Fq7hPffw15UI8stR95Ii1uMG9M88cd79nUCgi1ePBqceaaoBVFITLCrKGKA 7udP8LDs3oMHIfhKIMJMTINI8QdlKbyFYnF2m9LqMVEPWZ0yXbbsw1Jx4R9PlAimAC 7PgEZ866Eo8lewSCjRDDjQzpktP5cVMIqHOUtCUfnDk3TyB57pqLJULO7iDdURl1lB lTLjuPlUWWY6uymTnHpOqB4hNcBdKL2rhIQjLMXQKmN+NwUoI/7IF9ljG9JImZ+YQk FPlnh7heuboUiNm0D3l9Mh38aL0jNEWJdLZvntlPqheowOQyjps23RU+XtKTCFaZLJ VLPodeggg8qKA== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 45/49] x86/alternatives: Simplify the #include section Date: Fri, 28 Mar 2025 14:27:00 +0100 Message-ID: <20250328132704.1901674-46-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" We accumulated lots of unnecessary header inclusions over the years, trim them. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index d724ae8913da..242c0b1f7e40 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -1,36 +1,14 @@ // SPDX-License-Identifier: GPL-2.0-only #define pr_fmt(fmt) "SMP alternatives: " fmt =20 -#include -#include +#include #include -#include -#include -#include -#include -#include #include #include -#include -#include -#include -#include -#include -#include -#include + #include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include -#include -#include +#include =20 int __read_mostly alternatives_patched; =20 --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 8250F23371C for ; Fri, 28 Mar 2025 13:29: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=1743168557; cv=none; b=KqXxjdFSD6Bn1i6GUnx5RUGr/yjWXX1oZ7mJiKCJT2Ues7GMC8kNlV0iqHcQw5g9tQcd516MXjSWJl+He+MjYJPuk7sx1DWiQSIkXfWlP7fj6MFZWuI6dSxyqzywv8OmM0OgKH2Ib+FSJAfDAh4byI1+QF02AkOmhaqtZer6N7A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168557; c=relaxed/simple; bh=2gDW9IOQ/NyyYQR/FZrQrYxoqLiDM7Is5aunFcwYsTw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CImf93FuO95bJ/5mvtCzmTLEYKcSctA4WGAygwiHWieWfOS7jOi4Lg7ZV+LNFzEjGWBV4Owh/s3ExOxt2XO01maqwQdsqsDOR0Dntwx71YsrVv5EkVHe0kLpOWW2/bUdUroMg+HHMrn1qg9qcwWRx1KIjpGHwpkIgOBifUb2rR0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=g68LkZ7u; 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="g68LkZ7u" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 09FD9C4CEE5; Fri, 28 Mar 2025 13:29:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168556; bh=2gDW9IOQ/NyyYQR/FZrQrYxoqLiDM7Is5aunFcwYsTw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g68LkZ7uXLHD0O04PausL6EMIIkjWGiKWCJ2xJsnDU88uAFBye57h/jFDGW3zxNZr tXV6wpzAx+7NnH1A+tNkpwBxw9cJP3aeQHgkF9EgI2l9naW1X7fic8J4ELl2NkSM+0 QalDe/kgopmX942rH828bQyM5J/GUAQYaH7kOJUk6KjbK7IePWRtIbSUA9g8nN0LBw uGPow0UqgkEaFE4ssVlm7gdHbrCzbLcoqgVwJHRSWSTVXfjIjs6L9bPO2DiuJp7/Uw xBF0Z/x264HtKbzqVAyXXTpK468BsE9IaBQZMiWNYKHvm7pAmRgu+1+ElerGtIk5qb svqRPD9sehTOA== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 46/49] x86/alternatives: Move declarations of vmlinux.lds.S defined section symbols to Date: Fri, 28 Mar 2025 14:27:01 +0100 Message-ID: <20250328132704.1901674-47-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" Move it from the middle of a .c file next to the similar declarations of __alt_instructions[] et al. Signed-off-by: Ingo Molnar --- arch/x86/include/asm/alternative.h | 6 ++++++ arch/x86/kernel/alternative.c | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alte= rnative.h index 4a37a8bd87fd..ef84739a77f5 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -82,6 +82,12 @@ struct alt_instr { =20 extern struct alt_instr __alt_instructions[], __alt_instructions_end[]; =20 +extern s32 __retpoline_sites[], __retpoline_sites_end[]; +extern s32 __return_sites[], __return_sites_end[]; +extern s32 __cfi_sites[], __cfi_sites_end[]; +extern s32 __ibt_endbr_seal[], __ibt_endbr_seal_end[]; +extern s32 __smp_locks[], __smp_locks_end[]; + /* * Debug flag that can be tested to see whether alternative * instructions were patched in already: diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 242c0b1f7e40..df718a4e88c2 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -149,12 +149,6 @@ static void add_nop(u8 *buf, unsigned int len) *buf =3D INT3_INSN_OPCODE; } =20 -extern s32 __retpoline_sites[], __retpoline_sites_end[]; -extern s32 __return_sites[], __return_sites_end[]; -extern s32 __cfi_sites[], __cfi_sites_end[]; -extern s32 __ibt_endbr_seal[], __ibt_endbr_seal_end[]; -extern s32 __smp_locks[], __smp_locks_end[]; - /* * Matches NOP and NOPL, not any of the other possible NOPs. */ --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 86CCE23372C for ; Fri, 28 Mar 2025 13:29: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=1743168558; cv=none; b=jHMjdU0gSSSCUIStOmRIixhc1PBS6rFBIWoEzDlVkM5w9l3vza1beXsvQyrlHLN7fdzvTfmtg12lWuPicDkagZ56SquhheAC/Pn85+MLPT/+nXpa7qlV3KtM2V1nfWYLRdpTo6Z2LgXdsHLorxH+7DMG/R+uGKtouSiTRsJMAv0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168558; c=relaxed/simple; bh=RtQa43M5Chutv/Mu+hA4RGh+5vaibCz9hJlkWvXMbbA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pZFJzrscNENqSrNO3HHPKyLlmlYeWFzEkiUe+SYqrJYx0FWc/w1HIxyhjRNH+eVp4ntVaQmMa8OWaZoqWjeTCw3kd3egPk8N0haRc7DJbcc8GstOKKOcy+g8oe+/aL+1yLDV533q1DItSbsOs8BayAqkixAjrrzeVlU6QLAaQCU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tmIp9oyJ; 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="tmIp9oyJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 75CE1C4CEE4; Fri, 28 Mar 2025 13:29:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168558; bh=RtQa43M5Chutv/Mu+hA4RGh+5vaibCz9hJlkWvXMbbA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tmIp9oyJk2zx71pJu8YFyPqgJ4zd75Yn4/zbn8+P6KBrLf6TamhKXbtYq3aa2TKnk ceiETZTefWh8+rdLMZLVxmTmfE/1wMv3EFIXRqap5Tiablm9Aox/cruHNjWg0PydGi WZD7XPlMbFaPyE5LTjwETqzRESfjGMbskioBAylsTAEHQ/l6RmG3p+zdcOqTFNbzmP MuCPDHzRMP4OYLTi5oRQD6X8eIEu61Wywt0oLmoNzzKesFZii+jUwn5F7bMMrSUc+O S4+ZO0RvcaGNKxHVavcm7JhPA2JLFS4ZZeJwBxQN53LhqEEpZqCJUSpla5gzks3rr4 Qq0W3gFV1AmOQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 47/49] x86/alternatives: Remove 'smp_text_poke_batch_flush()' Date: Fri, 28 Mar 2025 14:27:02 +0100 Message-ID: <20250328132704.1901674-48-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" It only has a single user left, merge it into smp_text_poke_batch_add() and remove the helper function. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index df718a4e88c2..6de97646b4d6 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2831,14 +2831,6 @@ void smp_text_poke_batch_finish(void) smp_text_poke_batch_process(); } =20 -static void smp_text_poke_batch_flush(void *addr) -{ - lockdep_assert_held(&text_mutex); - - if (text_poke_array.nr_entries =3D=3D TEXT_POKE_ARRAY_MAX || !text_poke_a= ddr_ordered(addr)) - smp_text_poke_batch_process(); -} - /** * smp_text_poke_batch_add() -- update instruction on live kernel on SMP, = batched * @addr: address to patch @@ -2854,7 +2846,8 @@ static void smp_text_poke_batch_flush(void *addr) */ void __ref smp_text_poke_batch_add(void *addr, const void *opcode, size_t = len, const void *emulate) { - smp_text_poke_batch_flush(addr); + if (text_poke_array.nr_entries =3D=3D TEXT_POKE_ARRAY_MAX || !text_poke_a= ddr_ordered(addr)) + smp_text_poke_batch_process(); __smp_text_poke_batch_add(addr, opcode, len, emulate); } =20 --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 590B923535A for ; Fri, 28 Mar 2025 13:29: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=1743168561; cv=none; b=kY55A3ZXyww5FID3yja/KI8hM4Ork70YAXpV+r5+tRgDRF1QH3ZZqVdPwbh3FeiMb9WrNNbup17VdhkTF5blL2fIO4FCjeoaY4mm8VYZvekEi6OsjraNAbfruJvEHrylJ7hzeu/eD/qjMfg8eoK8k12SKkTjM0J8JQVHvYyeGAE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168561; c=relaxed/simple; bh=jaYn7tBzB3JSleDRcXcYRL1mMA34lR0DbCUN5pyM02o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eKdPkGHnD6RirdnNpeKlqm5xjnAuE9AT1DuIQezK/FPBS0ldMkIiGR6HarLJzKfy/65td6tWdK0h1630HwIWCnAHKf8mSYPTM1Sq61F1yC/dBupMWruIYFLyn9t7QDgighdpJ91gQxxtbKFHZQ0XxTrXgDm7aJiRP/M333hTvRg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=X6IGMAks; 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="X6IGMAks" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1375C4CEE5; Fri, 28 Mar 2025 13:29:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168560; bh=jaYn7tBzB3JSleDRcXcYRL1mMA34lR0DbCUN5pyM02o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X6IGMAks17Mo+kSamOGz3q9MPsz2BKzxkEetcOTqm/ATTF1ZFec0g/9BzIUH4vv1a EFv/NsO4CVf3aW/9I3y1ZX8DfBJr4aaqIzdCgmDDHT9veOObAThHCdVaGCt/MPJOP+ wgz4orcBnIg06sq6R8SwvE6OTIzdX24yoPyh0CxmDA5hnPnTOpmLeB71VE0pAFnfwU hx8xAsWJpGTOYLG/2XWk9P0F4biYEIMzhVM7AoT1ScRsKJ/J3IFuO6LyeWfpMTp4KX FTLeBgBbQYTTDW2slVMkp8M5r7c01+lSt5jN8EKvcml9zzOzO2fAcpOgjPnyRESqxD tulYGmUu+jc2A== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 48/49] x86/alternatives: Update the comments in smp_text_poke_batch_process() Date: Fri, 28 Mar 2025 14:27:03 +0100 Message-ID: <20250328132704.1901674-49-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" - Capitalize 'INT3' consistently, - make it clear that 'sync cores' means an SMP sync to all CPUs, - fix typos and spelling. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 6de97646b4d6..a855db342c6a 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2561,24 +2561,24 @@ noinstr int smp_text_poke_int3_trap_handler(struct = pt_regs *regs) =20 /** * smp_text_poke_batch_process() -- update instructions on live kernel on = SMP - * @text_poke_array.vec: vector of instructions to patch + * @text_poke_array.vec: vector of instructions to patch * @text_poke_array.nr_entries: number of entries in the vector * - * Modify multi-byte instruction by using int3 breakpoint on SMP. - * We completely avoid stop_machine() here, and achieve the - * synchronization using int3 breakpoint. + * Modify multi-byte instructions by using INT3 breakpoints on SMP. + * We completely avoid using stop_machine() here, and achieve the + * synchronization using INT3 breakpoints and SMP cross-calls. * * The way it is done: * - For each entry in the vector: - * - add a int3 trap to the address that will be patched - * - sync cores + * - add an INT3 trap to the address that will be patched + * - SMP sync all CPUs * - For each entry in the vector: * - update all but the first byte of the patched range - * - sync cores + * - SMP sync all CPUs * - For each entry in the vector: - * - replace the first byte (int3) by the first byte of + * - replace the first byte (INT3) by the first byte of the * replacing opcode - * - sync cores + * - SMP sync all CPUs */ static void smp_text_poke_batch_process(void) { @@ -2606,13 +2606,13 @@ static void smp_text_poke_batch_process(void) cond_resched(); =20 /* - * Corresponding read barrier in int3 notifier for making sure the + * Corresponding read barrier in INT3 notifier for making sure the * text_poke_array.nr_entries and handler are correctly ordered wrt. patc= hing. */ smp_wmb(); =20 /* - * First step: add a int3 trap to the address that will be patched. + * First step: add a INT3 trap to the address that will be patched. */ for (i =3D 0; i < text_poke_array.nr_entries; i++) { text_poke_array.vec[i].old =3D *(u8 *)text_poke_addr(&text_poke_array.ve= c[i]); @@ -2685,7 +2685,7 @@ static void smp_text_poke_batch_process(void) } =20 /* - * Third step: replace the first byte (int3) by the first byte of + * Third step: replace the first byte (INT3) by the first byte of the * replacing opcode. */ for (do_sync =3D 0, i =3D 0; i < text_poke_array.nr_entries; i++) { --=20 2.45.2 From nobody Wed Dec 17 10:10:44 2025 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 6C7AF2356A3 for ; Fri, 28 Mar 2025 13:29: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=1743168563; cv=none; b=AZKMba5SGrpMOlJiwvaRQdn6woOZVu26VxrqGX/CPaV45Cs34lKfR6hvu//gqabxz6Vv6bIUXm5CvH4SXJCENmkK9woLhZVbKhpCBJUIjPLeQjhh88zElRbiPpeP1OzM1k1TV7y2m85qxx5g7lgTcBKku4BoNfHYykdGMhrn8CA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743168563; c=relaxed/simple; bh=WpqYCmjDIdupb8yXwuJg+5H+hsNUqhDNiN1/6wHf950=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AhULqFuI3PtCFmOj219PqRFkWf7CrzmWurN25wo9etuJSt5Fd8RQQIejW2fE4p0NwUkOE6q3OFkJNq7Xkp2obnPsBsmTtCHA4gcWkncNrxbohYGW0bIhsMKip6NH+lGi2xvfQkNb3pJdWMHw9nCLsoIv+3a5huUCbHSBN2dkcUY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tSEpKWhc; 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="tSEpKWhc" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 581AAC4CEE4; Fri, 28 Mar 2025 13:29:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743168563; bh=WpqYCmjDIdupb8yXwuJg+5H+hsNUqhDNiN1/6wHf950=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tSEpKWhcFRzT4Luj28SgY5cuzp0xj2CDZ/pD8RxTQvVetsWemdGsMUBrCnIOW0rwY CXXYqrAwxU4KbYhN8Ntjw2G4m4aI+kCQ18GqWUXRmkWkZ4aSbX7pNlFRFh3ftsgTK0 1klPu8GJDk0KZLhyGlbUy6NVVcAs9kSi2KSXampCSRoOpu7NzMFj1XtKMeY1QMVwZe GirZNvfh0g963hknGLW9PCCcnuyd+4yPQ43QGm16qdzkvSt1Xn88jYqaaeYa/ciblI SfdF67C/bUlQ0cVWcI8sy2c04kVHRgzCp0cXx4z3twPSMv8EhVyErIkZS3rw/6/zkm cc318XdkvUc4w== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 49/49] x86/alternatives: Rename 'apply_relocation()' to 'text_poke_apply_relocation()' Date: Fri, 28 Mar 2025 14:27:04 +0100 Message-ID: <20250328132704.1901674-50-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250328132704.1901674-1-mingo@kernel.org> References: <20250328132704.1901674-1-mingo@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" Join the text_poke_*() API namespace. Signed-off-by: Ingo Molnar --- arch/x86/include/asm/text-patching.h | 2 +- arch/x86/kernel/alternative.c | 6 +++--- arch/x86/kernel/callthunks.c | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/arch/x86/include/asm/text-patching.h b/arch/x86/include/asm/te= xt-patching.h index 53ac94743e5d..335f88b54ed0 100644 --- a/arch/x86/include/asm/text-patching.h +++ b/arch/x86/include/asm/text-patching.h @@ -15,7 +15,7 @@ =20 extern void text_poke_early(void *addr, const void *opcode, size_t len); =20 -extern void apply_relocation(u8 *buf, const u8 * const instr, size_t instr= len, u8 *repl, size_t repl_len); +extern void text_poke_apply_relocation(u8 *buf, const u8 * const instr, si= ze_t instrlen, u8 *repl, size_t repl_len); =20 /* * Clear and restore the kernel write-protection flag on the local CPU. diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index a855db342c6a..cd5b69b6eff8 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -340,7 +340,7 @@ static void __apply_relocation(u8 *buf, const u8 * cons= t instr, size_t instrlen, } } =20 -void apply_relocation(u8 *buf, const u8 * const instr, size_t instrlen, u8= *repl, size_t repl_len) +void text_poke_apply_relocation(u8 *buf, const u8 * const instr, size_t in= strlen, u8 *repl, size_t repl_len) { __apply_relocation(buf, instr, instrlen, repl, repl_len); optimize_nops(instr, buf, instrlen); @@ -496,7 +496,7 @@ void __init_or_module noinline apply_alternatives(struc= t alt_instr *start, for (; insn_buff_sz < a->instrlen; insn_buff_sz++) insn_buff[insn_buff_sz] =3D 0x90; =20 - apply_relocation(insn_buff, instr, a->instrlen, replacement, a->replacem= entlen); + text_poke_apply_relocation(insn_buff, instr, a->instrlen, replacement, a= ->replacementlen); =20 DUMP_BYTES(ALT, instr, a->instrlen, "%px: old_insn: ", instr); DUMP_BYTES(ALT, replacement, a->replacementlen, "%px: rpl_insn: ", rep= lacement); @@ -1981,7 +1981,7 @@ __visible noinline void __init __alt_reloc_selftest(v= oid *arg) static noinline void __init alt_reloc_selftest(void) { /* - * Tests apply_relocation(). + * Tests text_poke_apply_relocation(). * * This has a relative immediate (CALL) in a place other than the first * instruction and additionally on x86_64 we get a RIP-relative LEA: diff --git a/arch/x86/kernel/callthunks.c b/arch/x86/kernel/callthunks.c index 25ae54250112..e016c5780d42 100644 --- a/arch/x86/kernel/callthunks.c +++ b/arch/x86/kernel/callthunks.c @@ -186,7 +186,7 @@ static void *patch_dest(void *dest, bool direct) u8 *pad =3D dest - tsize; =20 memcpy(insn_buff, skl_call_thunk_template, tsize); - apply_relocation(insn_buff, pad, tsize, skl_call_thunk_template, tsize); + text_poke_apply_relocation(insn_buff, pad, tsize, skl_call_thunk_template= , tsize); =20 /* Already patched? */ if (!bcmp(pad, insn_buff, tsize)) @@ -295,7 +295,7 @@ static bool is_callthunk(void *addr) pad =3D (void *)(dest - tmpl_size); =20 memcpy(insn_buff, skl_call_thunk_template, tmpl_size); - apply_relocation(insn_buff, pad, tmpl_size, skl_call_thunk_template, tmpl= _size); + text_poke_apply_relocation(insn_buff, pad, tmpl_size, skl_call_thunk_temp= late, tmpl_size); =20 return !bcmp(pad, insn_buff, tmpl_size); } @@ -313,7 +313,7 @@ int x86_call_depth_emit_accounting(u8 **pprog, void *fu= nc, void *ip) return 0; =20 memcpy(insn_buff, skl_call_thunk_template, tmpl_size); - apply_relocation(insn_buff, ip, tmpl_size, skl_call_thunk_template, tmpl_= size); + text_poke_apply_relocation(insn_buff, ip, tmpl_size, skl_call_thunk_templ= ate, tmpl_size); =20 memcpy(*pprog, insn_buff, tmpl_size); *pprog +=3D tmpl_size; --=20 2.45.2