From nobody Wed Dec 17 08:44:59 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 B82051D54E9 for ; Thu, 27 Mar 2025 20:54: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=1743108843; cv=none; b=eOYbhG3EEA/89QK0mU9rY0ir0t3hz4aPSxeuy6WQA0+GdiF9YXAsL2LQCpBVHMgEnwmR8d0TJR4H+olVV/hJSkbK6FRkhHEhza9mh5umoyuwPP1Xa4L0FrSPWVJ9WIt8OW63lfDviU2tKQBwKorblXZwsVNeBzGIKt/kmp7R27A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108843; c=relaxed/simple; bh=rtowR0p5yc0zPA1Vl4ObrVmbHwWZEHknYKLd4kjcKNk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=i9mjPhrF0m/b8KhdgaCPoPWs7Z2oDmIFe3jSMtmI78gqdcC2sKbEUK8RWvX0GEC4Roxav/u4PDTPfH8vK/kghhX0M6Js1X/I5vceLBfSt4XHlCACR7YDOM1R2zNT7Jg27dUXp4Jhm11Yo19dhxmYWp36OGzR3pX84saZhGt3ZnU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=O8CklMC1; 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="O8CklMC1" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 40520C4CEE8; Thu, 27 Mar 2025 20:54:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108843; bh=rtowR0p5yc0zPA1Vl4ObrVmbHwWZEHknYKLd4kjcKNk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O8CklMC1LC+KzeHnUENabx2quX8R5IHZc5o9/lgNBEaWwp6I2rmQwzVSBRE+bA5fT O/CvmkPLCEJPloQbj8WlmQDqc2kzt4gSpsUS4vrcYCYCt3stQCyVkv9045hFwlqH+t uGRBSFoVcOwXAN3p9+yP0CYBrjSN6s1ZIBcQKK2sd9sR0M/WNx898ut8oo5CpwKkxq Ygm1kp7uV75SR9JuFKITyzs3zvSQAA8bH6UZzNrKv1z0vUh66O+/wwEHkpiBu06LeM YesLFvkkbD5WwfFBr/NudyVofoR6JJCApmdlq3krhVljAcxyfKsRS8Nf2Oxj+pBRod 34dy76yWCWeEw== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 01/41] x86/alternatives: Rename 'struct bp_patching_desc' to 'struct int3_patching_desc' Date: Thu, 27 Mar 2025 21:53:14 +0100 Message-ID: <20250327205355.378659-2-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 08:44:59 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 126C41D9694 for ; Thu, 27 Mar 2025 20:54:05 +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=1743108846; cv=none; b=U4bJtFYFgF3Bvd1X64hOuTZdcrvOa1qFhM8FFzDQZIw1R2Yi+91olrPyH0y/d3Yt9J0EtSS3OEtWMNRYhe8OFDOC3dJF2/R5qGXeWeT+N+ab47XbF26YGJW19haVFIuDAtnpA6m0DnyXRVrx5hmE5Zanqte1ZTYOyvEtKc06HJQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108846; c=relaxed/simple; bh=eH4uwFqoC9JgVc1kv7VNnXR333bL5REyM/EgEQ04P/4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cxEG2S3zEPjQP8OPX9dj7rIZCgNQ+9Vzs1H9Y2lgu0B8AibbmTsT049/yn9JllIMEaNCBlarpezpm9IbIHtjcksqR8/l1rtV5B3CAtR+Pgk2HDqrDu8lPjkJu7ebs2eGJWxsCouNCD9v+U9dH3cIpDc0kzd4UUyPaCTx8yzbORQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hM63PF2K; 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="hM63PF2K" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D94DC4CEEF; Thu, 27 Mar 2025 20:54:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108845; bh=eH4uwFqoC9JgVc1kv7VNnXR333bL5REyM/EgEQ04P/4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hM63PF2KQ7bPoJZGkf42XcyZbbUs/tFu+ag/3/v7ETzjzdu86tm65Zhkk9TwcLVsj mPhpxO34WxHwh06co+HdkeGymJGxWSSf8MyGSWYFHKfZhwYImyqraa32mk22Ey8LJN 7u21Ozam58cO8ilmd1rABfM/ky7mIDh8Hj9jUqNCHJVMOCC5L5yjocfYNJVVgQ8eNT UhlUEE6Th9ILQdCIHJDb3Pcm3bnZRIVaq5Y6OG3Xd9QBgNrUl2nAceVXll9NigGXjV elfTlx3CpMSG8OcUr7BOrRugVo8Z9k57IGxeFmBZG81HV6K/m5OWaVJ8R2SfaLtdcr IJEhaiOmwOUJQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 02/41] x86/alternatives: Rename 'bp_refs' to 'int3_refs' Date: Thu, 27 Mar 2025 21:53:15 +0100 Message-ID: <20250327205355.378659-3-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 08:44:59 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 6F3B41DC19F for ; Thu, 27 Mar 2025 20:54: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=1743108848; cv=none; b=K9ureQ22jn7xUMi5igmoJu3yB/db05CFhA6mFHD3HukNRRABUhXfAMLT5U0zBdOybAXQFsO2DQf+rqiNg3FnfLUYY3FHYEByh5qd9bdlLTuz8bEltUnVl0FYELqYbjREE48DSsrAfI3/IpEfFmHGwGwNRI2I8Pt336HHxBzjDrE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108848; c=relaxed/simple; bh=zFMYNqC2tRZgktx72IknhXRNiWbs7PKD/NbUgJ+kXso=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZWl7B5EZhaHe92y9z6sf+Sdlm6peoi5twgFHmBdiATwdiT3gaKT48PLLIEYAkGE5lSeRzSoZ2/DNgfUDGYDn57knPSpbaGFc7ICjrti3pyImvjf9TzKMSo91LSIu+eajLhVvl7vJkujQwIxtoTS5nYuTR+Uj0lpTHg6q8xEnTeQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ek9ZsdA3; 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="Ek9ZsdA3" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 05213C4CEDD; Thu, 27 Mar 2025 20:54:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108847; bh=zFMYNqC2tRZgktx72IknhXRNiWbs7PKD/NbUgJ+kXso=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ek9ZsdA35lbHXYiRY5xgIUTy0qjbL4QvMWX06TIVhSX6j6IFhUxSulgW6oAN5RW8q wj8sWERmRhXPlKV4SykzPO/uzm246YrQ8aL7iYOKNVLK25Zw+7TBMGwh8TMFSdvC9P L3Wt/q8neAu8QwdB39nzqxCvZ1T/NqYBQyhLF0kyKKFb0g67+g9QEwYjFOjy3Tz2N9 OohEBNY1vH61/bZ11leMYADwQ+gXgUke7WnLLg7r6rVsHuu2vrNLVyral9SkfLeHAP BhDWqNNCU35yPnZg0kjKBSl43xwqNtLoB3qQIpL+QDH8thTbvpEro7PP8LUYd9kMG+ jkNYY2IpxAfcQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 03/41] x86/alternatives: Rename 'text_poke_bp_batch()' to 'text_poke_int3_batch()' Date: Thu, 27 Mar 2025 21:53:16 +0100 Message-ID: <20250327205355.378659-4-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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..b0fa770b7460 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 text_poke_int3_batch() */ 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 text_poke_int3_batch(). */ 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 + * text_poke_int3_batch() -- 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 text_poke_int3_batch(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); + text_poke_int3_batch(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); + text_poke_int3_batch(&tp, 1); } --=20 2.45.2 From nobody Wed Dec 17 08:44:59 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 C17761DC19F for ; Thu, 27 Mar 2025 20:54:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108851; cv=none; b=GK18Zght3nUhFBg6/vo7PUozGt4nbZNM5KJ48D51PhzhVBSaOsiLUUtWcbr6xSBJoYoNuIuGtInisXcfc3H3ulnteKRCeiIsXvAPXNyKtEaWPLWdqPIjh1OWVMx7FsfoLO0ia2wU1Qa4QU+V+vuFR4Jpd+/PueZFyY15q+OXJOw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108851; c=relaxed/simple; bh=iHbffRJTfO2boKACLnGSrGageot4RkwbYElW5JK8Wpg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KyVKC32I8LO45h2VeuSIF+Mh40LoDZRyfVFJuVdN33VqVNbaNGQ6Zu2ymWtGI+97cKug1durGE9qUI3+YRh+/FYeGJ3ixkRa9+1YEYSfyf4hD6+g+MjfxOCBY757QDeGIv2VOarPBHhFIuFL5ylfGR6Svl74juDLGpkKxlXCnnY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GXCm1gJ8; 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="GXCm1gJ8" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6266EC4CEEA; Thu, 27 Mar 2025 20:54:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108850; bh=iHbffRJTfO2boKACLnGSrGageot4RkwbYElW5JK8Wpg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GXCm1gJ8dq9xyFZwiwS3t4nKDCe0oOJtaHXio7GQuN/R+f/COiIzCPvJeEK4PO7TD j8xQ7pFZ6djIhT3Dus2UXJ9wbXexdkHpBBi0Gt9l57yAX6u0nlk2XrFrg9azfHzdcG FHys7iJV0eDTQomRgVorQtm79OGcYvv13jpWd1vsafRi+ptwJT6TYQ7U3HapDwWCuO Z3F09XWKFw1y7NEbcqkSdvA7c80OVqhEGbV2ADh3mxpshYeTZx8e3woArORydfpB8Y 4mgIa/zcNRB4RGkA7WtTUmtRj+U9TaV4xHzHqJh0zCJE+TRPQc6etbkCzHqhcYCBCf 9YviF+lfuW5Og== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 04/41] x86/alternatives: Rename 'text_poke_bp()' to 'text_poke_int3()' Date: Thu, 27 Mar 2025 21:53:17 +0100 Message-ID: <20250327205355.378659-5-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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..944b2aad4351 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 text_poke_int3(void *addr, const void *opcode, size_t len, con= st 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 b0fa770b7460..661cb6b1fbc3 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 + * text_poke_int3() -- 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 text_poke_int3(void *addr, const void *opcode, size_t len, cons= t void *emulate) { struct text_poke_loc tp; =20 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c index cace6e8d7cc7..4e284ff674f1 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); + text_poke_int3((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); + text_poke_int3((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); + text_poke_int3((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); + text_poke_int3((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..94e2dcc94d9d 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); + text_poke_int3((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..e13d4a2d9244 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); + text_poke_int3(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..3331a7c90b9a 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); + text_poke_int3(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..1e2a4b7a6b73 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); + text_poke_int3(ip, new_insn, X86_PATCH_SIZE, NULL); ret =3D 0; } out: --=20 2.45.2 From nobody Wed Dec 17 08:44:59 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 CDC3D1D61B1 for ; Thu, 27 Mar 2025 20:54: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=1743108852; cv=none; b=Lfincnhp1gVfSz9Jynmfoa+Isic0WNwuWSUfmi9ZB7loTzsos6R6wvRtThv5S4SxwTmM1MU1wsqmLKbOXe2qB26riCPvWP+bIwghtL21And6/Z9SW2Odh8ORA87aXYh+px1TZY+6lf3QfXulcdA0sV3awqqOnnGcT6BD/Z5CXW8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108852; c=relaxed/simple; bh=11k590VP3/2pKNqreW1J4GJIFV7KwjrehK3Zi7KY10c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UoQbrO2B0E6s4ovrVPfKu0ib1FNddhC2F64ivXgyaoMDIfwDMyDrQnYPkIZFzjqx99bfNumD3XzgYjat/V6ZeglSsag3KDaorKk1VP9lY5VKEoGMVaXL/Syybzhjbpqdhngy10bfWYbx21uax0kqoa9rfLS8zlrDVP0ZGnA0gT0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pzRQvrmt; 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="pzRQvrmt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C150CC4CEE8; Thu, 27 Mar 2025 20:54:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108852; bh=11k590VP3/2pKNqreW1J4GJIFV7KwjrehK3Zi7KY10c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pzRQvrmtri109Bvka24iIEl7D/vO4qnVzizHUqCgAd16z8LpJ9/KpOFMpaVFHylX9 ckCzsdtjiMHdL3J/p/i5S3IZ5jk+HBjy5fNKEQzxd4KlmOczVARkddMZTXzMM1sRfZ ZUAgZCu9wqbtVS5Q5Ou2vZXgoGoxjjxI0uSZ/cx7IY7C5gsQOZXJpnGM3GeymlkoGT HNf8aE37H2q4xkQu78Sc1UxSd2fPTHBLvXu/gE6VOYSdemVTrVErqfaUXb8bGfCUs6 BJp1WwETYOizrqFsLW0dBaBpNII1+/01WLwQoNJGZ9fOSZBx0+lEoGUksmwsDsrUGs 4h0JomTByg2KQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 05/41] x86/alternatives: Rename 'poke_int3_handler()' to 'text_poke_int3_handler()' Date: Thu, 27 Mar 2025 21:53:18 +0100 Message-ID: <20250327205355.378659-6-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 944b2aad4351..fbca0bd725b6 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 text_poke_int3_handler(struct pt_regs *regs); extern void text_poke_int3(void *addr, const void *opcode, size_t len, con= st 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 661cb6b1fbc3..5d410c97d451 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 text_poke_int3_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..b4c7bfb06ea1 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 + * text_poke_int3_handler() is completely self contained code; it does (a= nd * must) *NOT* call out to anything, lest it hits upon yet another * INT3. */ - if (poke_int3_handler(regs)) + if (text_poke_int3_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 text_poke_int3_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 08:44:59 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 977631DE4E6 for ; Thu, 27 Mar 2025 20:54:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108856; cv=none; b=P0nvN4JzP0wkg9YMY7ZiaSNAgfCUMz36FZdGe2xQv7zvP0KCuPGsGubkgdsyDXCRXIxYxM6emBVANIUGp8oFl+UbKYB+wCgbm2ayJ6T/ioTfJcpTpuKS2jztX5VBKluOhrW84PkHJW3x1nsG6lUoz/Q2jKO3mjXC9PX9if6RiaM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108856; c=relaxed/simple; bh=Za83jEeJe5sEnXkLkjmf0uI5lYD0YSWcEN8BPWeB1YA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BursO/wq7m47/NNpuFpevMCuqSHofVLSNnQTlFeZfBE96V/CD9M3YxyAE76oz8i2JVA8TTWK65mB8BFUYb3PNToEMqxJYmQsJQzhQbk/up9DidXwo134lhgt6qGcQrW0zEvrYk3GH7t6N+z6yZ+dpS2nqskIqipsj+H8GF+72Ds= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bAWmBtly; 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="bAWmBtly" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E69BC4CEDD; Thu, 27 Mar 2025 20:54:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108855; bh=Za83jEeJe5sEnXkLkjmf0uI5lYD0YSWcEN8BPWeB1YA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bAWmBtlyYYVO//fD4hy0uAg+0IMhHuSVjvbygCpD4sRsUcFEDjc8BMyatrofcYyqQ YRh2ZwQk9FJX+0tfr5Rk1zIuFLNM0r6TZw8xebTxxkGh4m9HUUJjh5zZ9jyDMPZJBa k/pPAIKPXv4X5aJUex6pA8Lk8vBNjYb7G5d9ytXXF21OlN0iQr4/C1GhW/kke8DtzT 2ADnX8ZLye+1DO4buYmaDjO7CvOKM7+3zz6PNQ5Jbsbx2HprdBkSxET7mkZ7nfAHGY Siad0ZK17+e45VCBsKdhMZ4Vpkoch4etPRq8eteLbQ8xaXfo0wS89X1sIc9LgKLRry klH/zNVrY31ww== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 06/41] x86/alternatives: Rename 'poking_mm' to 'text_poke_mm' Date: Thu, 27 Mar 2025 21:53:19 +0100 Message-ID: <20250327205355.378659-7-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 fbca0bd725b6..e41ea3040680 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 5d410c97d451..f4baeeaa6c0c 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 08:44:59 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 99C271DE8A7 for ; Thu, 27 Mar 2025 20:54: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=1743108857; cv=none; b=o5CiTzEspikHrtP7ecigDeU+9cqXm1u/Mb5+5fjs37k9UyvWGPPYgQsHB2uFVSiJTOb2cdwAxIYashZx8en4Ue07kFph5T4aM3Mg0k99jbKPuCerp60RjMm7UXWrYlW8eFK77Qrd8v5zyb93VY9JMZ0/PLDNqsGopSxeb1ZMk7g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108857; c=relaxed/simple; bh=+yld2kPw3Y0nsfuTsZpxBfmxj6LEFhkqSvSMpKQ2p4c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ur0L9DRTZi+WeLCRFn865ViOK7YXAXp2yYrOdEyE8xwkgx6ThmRv048dI9Y27v0zkoSHddH+waJTIrnO8T+MwDZDXX3EKOVZUxkSqbsflPBJ/4WvJxL7Ji4IR8SCRR729b/FByjsnPe48rLEesj36JMmER0hzskTyK4ij2Lz39w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jF9Hg5up; 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="jF9Hg5up" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8C170C4AF0B; Thu, 27 Mar 2025 20:54:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108857; bh=+yld2kPw3Y0nsfuTsZpxBfmxj6LEFhkqSvSMpKQ2p4c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jF9Hg5upi8SnWDkNd7UuOK5i19+z14+zKHj5lroNd5x1Euy8e6Bon8bzTnHWG7SM7 q9N3Xb5lCsCQsJSl1YEk7AV8wakwGeZTIAX+wN1C2ArZQKtRwTIp0wUwF+dcJ6wjoM JSRNGgZZwp1ZSIBPAhEDNpXmCpm0EnL36aIAzDinQCwkFXn5DdTzQpGgcqHCiidJ9l fqEv0tHl/8PoFHuQqPhvaTCYY+OoTBHnkf6C032JB17oYVTuF0KuwYDmw3BtYSxERl iAM683HYklZflnI9mB/O6YW8bMc9QgG4ndiuqsj6UlNcAyi84jA0jHHmMQR3YSvTTp KqER0v979q2Bw== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 07/41] x86/alternatives: Rename 'text_poke_addr' to 'text_poke_int3_addr' Date: Thu, 27 Mar 2025 21:53:20 +0100 Message-ID: <20250327205355.378659-8-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index f4baeeaa6c0c..100b606d7dde 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2499,7 +2499,7 @@ 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_int3_addr(struct text_poke_loc *tp) { return _stext + tp->rel_addr; } @@ -2508,9 +2508,9 @@ static __always_inline int patch_cmp(const void *key,= const void *elt) { struct text_poke_loc *tp =3D (struct text_poke_loc *) elt; =20 - if (key < text_poke_addr(tp)) + if (key < text_poke_int3_addr(tp)) return -1; - if (key > text_poke_addr(tp)) + if (key > text_poke_int3_addr(tp)) return 1; return 0; } @@ -2555,7 +2555,7 @@ noinstr int text_poke_int3_handler(struct pt_regs *re= gs) goto out_put; } else { tp =3D desc->vec; - if (text_poke_addr(tp) !=3D ip) + if (text_poke_int3_addr(tp) !=3D ip) goto out_put; } =20 @@ -2660,8 +2660,8 @@ static void text_poke_int3_batch(struct text_poke_loc= *tp, unsigned int nr_entri * 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); + tp[i].old =3D *(u8 *)text_poke_int3_addr(&tp[i]); + text_poke(text_poke_int3_addr(&tp[i]), &int3, INT3_INSN_SIZE); } =20 text_poke_sync(); @@ -2677,7 +2677,7 @@ static void text_poke_int3_batch(struct text_poke_loc= *tp, unsigned int nr_entri =20 if (len - INT3_INSN_SIZE > 0) { memcpy(old + INT3_INSN_SIZE, - text_poke_addr(&tp[i]) + INT3_INSN_SIZE, + text_poke_int3_addr(&tp[i]) + INT3_INSN_SIZE, len - INT3_INSN_SIZE); =20 if (len =3D=3D 6) { @@ -2686,7 +2686,7 @@ static void text_poke_int3_batch(struct text_poke_loc= *tp, unsigned int nr_entri new =3D _new; } =20 - text_poke(text_poke_addr(&tp[i]) + INT3_INSN_SIZE, + text_poke(text_poke_int3_addr(&tp[i]) + INT3_INSN_SIZE, new + INT3_INSN_SIZE, len - INT3_INSN_SIZE); =20 @@ -2717,7 +2717,7 @@ static void text_poke_int3_batch(struct text_poke_loc= *tp, unsigned int nr_entri * 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_int3_addr(&tp[i]), old, len, new, len); } =20 if (do_sync) { @@ -2742,7 +2742,7 @@ static void text_poke_int3_batch(struct text_poke_loc= *tp, unsigned int nr_entri if (byte =3D=3D INT3_INSN_OPCODE) continue; =20 - text_poke(text_poke_addr(&tp[i]), &byte, INT3_INSN_SIZE); + text_poke(text_poke_int3_addr(&tp[i]), &byte, INT3_INSN_SIZE); do_sync++; } =20 @@ -2857,7 +2857,7 @@ static bool tp_order_fail(void *addr) return true; =20 tp =3D &tp_vec[tp_vec_nr - 1]; - if ((unsigned long)text_poke_addr(tp) > (unsigned long)addr) + if ((unsigned long)text_poke_int3_addr(tp) > (unsigned long)addr) return true; =20 return false; --=20 2.45.2 From nobody Wed Dec 17 08:44:59 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 608FA1DF97E for ; Thu, 27 Mar 2025 20:54: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=1743108860; cv=none; b=A/7G9sytaXZFI4mYsYXJuGBOrlDRcDw/YClEW717bEVVM5IgfHDY9RDbcZ2qI8gBTNUdZSzV74p0ye3vcziww5orm0bocJwPirP8B307JT8TsGFpfvfTSAFJ2IgVJUDXxR37xz6LXbroDqHmAQgDQUGnMx4MuXrJ7vTKvN/ZhQg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108860; c=relaxed/simple; bh=6N46DpgWpCLPSbQwq/u3iFuEU5/btRcI+rWFwvFU2so=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oMTHpYbfqKGQ367AucxpI3oALcMTs3N4HeaFlITeP3S9HjhexdA2vyvzCXKfpVSl4Ri0PozLgWSPxZufS/nuy5YoxghzwXfDaTrwNVFUVJDSpGWEG9vq+PKdjPX3D0M+MUjo5i7L4vY6ndHhiDDVREBpnv54IO8owi5AEf3Vd6I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LZqtjtsU; 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="LZqtjtsU" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EB9B5C4CEE8; Thu, 27 Mar 2025 20:54:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108859; bh=6N46DpgWpCLPSbQwq/u3iFuEU5/btRcI+rWFwvFU2so=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LZqtjtsUkcUv0YLDjxlydYZ2hzEK0uifMSgvTJzesfIZm74lPrAGqinEquu25V8y+ +UZ8zhz500h+mToxHbkzGBMUoX7u43FNVnDjAKiYaf85jy3Xk74sy495ajMVEMufrC yEHmcMhwOuF5aWAzJxORGeJteSRk5Q1jzGa2AdoL91ldntYksYvyBlD2kFkiMJRsRG 8At8Dki5vmrRJcvt3RNVfyR7IiGIzPhZBCy3umU0fKSZdIuB6WK8Zs0pquRyARI7m7 ru+dWgLA4GWk6VSyyIhrFnEq8EK35IKEYu19G3lq5QR5pCPd5+3v0NwU5pWnCmfKT9 6gpsI880G9vgg== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 08/41] x86/alternatives: Rename 'poking_addr' to 'text_poke_addr' Date: Thu, 27 Mar 2025 21:53:21 +0100 Message-ID: <20250327205355.378659-9-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 e41ea3040680..9f6f011f5696 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_addr; =20 #ifndef CONFIG_UML_X86 static __always_inline diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 100b606d7dde..8c4bfb6d9a95 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_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_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_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_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_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_addr, ptep); if (cross_page_boundary) - pte_clear(text_poke_mm, poking_addr + PAGE_SIZE, ptep + 1); + pte_clear(text_poke_mm, text_poke_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_addr, text_poke_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..031741912981 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_addr =3D TASK_UNMAPPED_BASE; if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) - poking_addr +=3D (kaslr_get_random_long("Poking") & PAGE_MASK) % + text_poke_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_addr + PAGE_SIZE) & ~PMD_MASK) =3D=3D 0) + text_poke_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_addr, &ptl); BUG_ON(!ptep); pte_unmap_unlock(ptep, ptl); } --=20 2.45.2 From nobody Wed Dec 17 08:44:59 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 57E991E1DF9 for ; Thu, 27 Mar 2025 20:54: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=1743108862; cv=none; b=R8/IAmvPI9yzX0SnomAleFoSkYUdKH8RhzNpzpuhaCMbmeId+ifzfJH4z3rrK1bhBDH0Sxy9aOgrhlxE3Nztn2PQmq/zVRfEOPJkGEm66jtGRtTX+rq7ErHvSoaaAEUe6zrUay5sYFBC4FClrqd9AffKLYX9kCNxA5CkLEn74zU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108862; c=relaxed/simple; bh=Mf5NDjQds/8951zPAHI8EXZwxWU5Ec1f5rgl3VV1i1U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=P59lIl64UXCqHON2akNTkJwak6pFi7eg+sAB/KZaLd1p+LhTc2neDFGphTGIZrYLfXQ1ioAVSVhm/3hW6omlQs6BvSpFrjtU3qfb+mQz5VN48bY+u6/Z6cZZTPNSw2U1xVyeRxOICoSLmeu2k7fUZcGLYNbc5AnZX39yP7V87to= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=eTfB9VvA; 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="eTfB9VvA" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52C70C4CEEB; Thu, 27 Mar 2025 20:54:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108862; bh=Mf5NDjQds/8951zPAHI8EXZwxWU5Ec1f5rgl3VV1i1U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eTfB9VvA0nKP7vIA0V57z6mIbkx+OyY4eNQ/t0C+9i5G/sGpon8nD88tXBAIp+U8O kHIHzXyaSfJWO6tZWL4n2Oj8wIGEisJ6ssE+QN/2EW2FbWBcquGC2o8zQaAt7xRPSf I0zGCX2+dAth6ievCYGi6LiJWEem3qE2tpiyom4ASe9QJS9uLeYw9IHcCmJvGQy9BM 8B/CuqwwqZqCIpAEi0rQCeuo7VXgG7qbiF9Efg9sFq9y5Rx3qi2Ouo1ID12sO0PyAn pHAfOcl5L10wq88b5uCFE5SCIcbICFzuXc/4EQfPqenDyB/kgjHBhkTzKqHd/PF1wY 2qdcRUvlpYkpQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 09/41] x86/alternatives: Rename 'bp_desc' to 'int3_desc' Date: Thu, 27 Mar 2025 21:53:22 +0100 Message-ID: <20250327205355.378659-10-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 8c4bfb6d9a95..44b8e2826808 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 text_poke_int3_handler(struct pt_regs *re= gs) =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 text_poke_int3_batch(struct text_poke_l= oc *tp, unsigned int nr_entri =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 08:44:59 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 B757D1D61B1 for ; Thu, 27 Mar 2025 20:54: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=1743108864; cv=none; b=c1uojjyCmGu5H+6WJJoMOLTWJ8/5FoTHQYhwkqWWuPIrO/0A4nxbjtHdOnO5jc6zN6dn/GlrRpPwbEFualOGStjpbwI1Q1vgWOXAnoS+vJYi4DxnobhvR1bYuvIJGlk+JEZKiYKmAc9T06Kbu6pBp/uKN1coWWCg6QsgMOiSK7M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108864; c=relaxed/simple; bh=ZQOoyR3wsGdwSEhqaaiJ6uePJiLwWRAzr9gDlLkjMDY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q31qn2qlpuedOMVRLSOe6Bgk20/5MfjLpCLyzj3KXt0XaKfG/q/Xt4wYcHJYugPH1B4KbIpnK3aCw9P9EBFX8EDnHJvACUAsIatphzRMBWAeLSrDnytSdeu5eujJtEM5fnca/phkdsTyxDlYIaVnU/1f4B1NU3r2Y2ZMw1YvTrU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Jmqn+48C; 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="Jmqn+48C" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AAB61C4CEE8; Thu, 27 Mar 2025 20:54:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108864; bh=ZQOoyR3wsGdwSEhqaaiJ6uePJiLwWRAzr9gDlLkjMDY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Jmqn+48CeAz0hAVFuogVf2G5gr1iYmEqgUKjFgaF43urgrNIxApe+VycHhpsfm7qc ULsrIoEdD8T9xaFZSeRIbe3xurj5xGTscCMuuHuU/I38d5VaqnCQHJNbCFqNb0j6nS /uwsaVkN4hkZ5SVWgXuGb/r88XfPWQlMw64wymy+8b7gk30BoAiqWjwIpTzgYYUeD8 zr8PqSw7qL2TiDvjY/ipvvt1e9rH7tuaTVIl+V2ZgQ5ep1eoYsE1sqhBhTWUCu8KKK S5ICImgyOjigmAPWppGI09Y+AEXEorF18TUaqOwV+YxtYQEiZpEx6RDoNzK777TovT qxxs0b7N4YKMA== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 10/41] x86/alternatives: Remove duplicate 'text_poke_early()' prototype Date: Thu, 27 Mar 2025 21:53:23 +0100 Message-ID: <20250327205355.378659-11-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 44b8e2826808..7d14c8abd3aa 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 08:44:59 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 83F3A1DA2E5 for ; Thu, 27 Mar 2025 20:54:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108867; cv=none; b=Pp/HrIfCgact8sUOquHi5aYwDRnVlhiHwOQuvNqXo/3ycPZgjOi+w33XE8rHjE7SuXGB+QOTEP65VupBRfJFxA50xucPNnUX21kOBOqpLjLJkiv9Y2CCA8NpL9p75zf49y+Hq8hIOAaTClxB1umX9AoY5DOc3J6LgSvXR3c/Czg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108867; c=relaxed/simple; bh=+29BZwd36zi833w/mFjDZURDTxD//gjk8dm4eS5sx0A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=n1br0Yk6cEE1Sa9oZH0N5CpCgr8DEJUHIsZjUYWZQ38DofMczyJSruKyIwtHYl4IBdUQpU+x+8GBHlZt2098rhac5mZBERzln2Z5+E5eMm0Ha/nMXGFnV0EP//W941vRJjBeGEVo9ImHSt6GyB6pEpD1JhzuRLvb6AUD8rP5Vzk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GD/XFozt; 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="GD/XFozt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 19033C4CEEA; Thu, 27 Mar 2025 20:54:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108867; bh=+29BZwd36zi833w/mFjDZURDTxD//gjk8dm4eS5sx0A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GD/XFoztk0/cYpZ3HUHvaMGliBhFyQJOL8Ov+xQtVH6oyv7kNDDldf4GmFBWxitch 2xhPF1824qt9SRFsrv5f5q2xJ5HnBDyVJJyNh7S55+S/1DS+THZQHs+Feg9RB8nROG elFKlNFclTXf0ihMdByqoYZGWjzokgY5W35qhwEuRFBs1XDE+vJETTGsmbvIRFFPWM u5vBF03w2Jw7bMQq5ZJVUvkGrHYoqccSBFaFNP0QHQGItItkJ/xTtN6hTpWCih53rY GE/0DbUBUMXPh8IQ460Zeqr8irPptzPXdp6PS7S0wza63YJr5ITjC47uwSPNRqDEDu djfKkKEXe28Kw== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 11/41] x86/alternatives: Update comments in int3_emulate_push() Date: Thu, 27 Mar 2025 21:53:24 +0100 Message-ID: <20250327205355.378659-12-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 9f6f011f5696..c2dbb0e4d80d 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 08:44:59 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 78C0B1DE89A for ; Thu, 27 Mar 2025 20:54: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=1743108869; cv=none; b=R0oOXET3wzZhnJHUmAYs8kjPOWmz4/j35eKwofUxLy6RyedVOVPiJnb4AfjKokUw47tXggYagOWUoM34IDWqB4JezPZqKK0I0E3DT2F1WVVhxhDOjt5CuFd3z8yzx4lO7avmyB3g7OVT2dLM2ePe19VnCJyqBtZegXYjiLccIQI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108869; c=relaxed/simple; bh=A3v7IO8MRmxIxGpCftVasykegOu8TrEKYmjKX1aqWSY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hiTdMQgvtyd79xaKtdsnfAreRL7PA703zeXuZt5LL1k4njFQxABkPec5TSYOxNeTUYq7iN9lS/DxSyc1IqmYJheUJXmBNvSP9i1jMAr6rGqOf4lkpDl9hcjgKHNKJVY9kCV/ngv+QxijbT+q880QDXc2BbN6OVaQWmf63wmYxKY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=tGQ/K5uT; 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="tGQ/K5uT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 72A07C4CEE8; Thu, 27 Mar 2025 20:54:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108869; bh=A3v7IO8MRmxIxGpCftVasykegOu8TrEKYmjKX1aqWSY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tGQ/K5uTD4ubJ75IJiILJjxjydR9j80kEZiBvhdQnF613eXJnBZsznGGZy1kDPDIc I1zMKTsJBX85V4qP1NZWAYgl9RJg3HhTQnwqLrFG1mQWZD0VQyl+JGGXDeNt8NOxxL bhAyk/u+9VB/TA1zRLWJ0sqbCZWJ1bGJT8ckReS/xDsKq5+Pvx7uusp8rUatex9AhP qlQKdOzWPSUB6EP9aVwMKSdESkNTHAf5U+FTcfs88qZpwbCAuPUUOoNJnbSGO8kdNl rkPbEnWB8PpdPDOwe+yDY+ZoeIOqEpEl9IlYlRclSQSD3ynjMv2XBzNQVPrPs4eyWq Gyx05zuucD3jw== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 12/41] x86/alternatives: Remove the confusing, inaccurate & unnecessary 'temp_mm_state_t' abstraction Date: Thu, 27 Mar 2025 21:53:25 +0100 Message-ID: <20250327205355.378659-13-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 7d14c8abd3aa..557ee2546177 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_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_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 08:44:59 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 CEF6D1DC070 for ; Thu, 27 Mar 2025 20:54: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=1743108871; cv=none; b=FBrX9yDgAZ/Bn/8AhTK6VjzKHsJ77Aq7VwpdF7BPZshh6uKS+nyx3wwMfzUKC/0RED8qTQpA8Ky8p32jyEdx/suZ52TRpnQ5uoxSBR/z0lfqFWpGtMesxm35bmr+L6Tja46JMYvfslab9QoBJisXA25nsSfNC7PODX68/nqOrdM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108871; c=relaxed/simple; bh=OB80uW+3JA4RNb7/H8uPhUtnOGne8GtsV2w1ve8kN0E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bbmrb0e6WN3ar+SjY1+/AwvymlK+BhdZAmLmcmeINWlk5xtI06ITW1Arwhsh83T56hMZ2xBPWJbmsKzHNqXqHOVe80/PW0fiX7zJmKZY1dfWWgU4IYU2kyPIeYLX0KTE5aIkhoNOiKVT58FCqeZa0RVgKabU4NbAcevq6kPgxdc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=nZGm+yxj; 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="nZGm+yxj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC01EC4CEDD; Thu, 27 Mar 2025 20:54:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108871; bh=OB80uW+3JA4RNb7/H8uPhUtnOGne8GtsV2w1ve8kN0E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nZGm+yxjrVy4QZ/eGJckC6kCFmHwmJZxKzEiAlHE3q9MjUANd5p7Zvt2w5V2iEfqq Y8MtW5kAVrL7iWaWVgMAmKCIhSX5doruhF4zjvYstZotm08GfHBGuIzLS4EPJty4/m oT6VgXW9b2P4razjGc0N/9RFGKdRK6jckSg/DEMg86pyPf2d48ASy2/jxIT4RzeTR3 6fDl9cOw7c/ASxdUJVXgLeur/5nSTXJZMht3DZ203uqgjyDtCfGPdfkMI0rezF2aY5 cUKmfJNhaROQev5OuSxbNXbtR2oOQkmaI1ISevVbNZICPR0NASpJNQP5iCNRUh9IpB +zQNdDeEBJvKQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 13/41] x86/alternatives: Rename 'text_poke_flush()' to 'text_poke_int3_flush()' Date: Thu, 27 Mar 2025 21:53:26 +0100 Message-ID: <20250327205355.378659-14-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 text_poke_int3_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 557ee2546177..bf8080a68f66 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 text_poke_int3_flush(void *addr) { if (tp_vec_nr =3D=3D TP_VEC_MAX || tp_order_fail(addr)) { text_poke_int3_batch(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); + text_poke_int3_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); + text_poke_int3_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 08:44:59 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 945F91EB5C3 for ; Thu, 27 Mar 2025 20:54: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=1743108874; cv=none; b=gFDx7FNTtmIdHcj4Nh8h8w8bZ+Q0TAt0Bopm1GEm3SRmxHe1OfjDOClAJ35RJEx7iU2NNaCMh4Nf9v4dnUitsdxTsv6xjOPI/jW1buvBMOCKwB6g5bFLKNFFR9vPyNhWvT/p+PvefnmDTRzNy4PGBl8xzFEx/SRmw8Z+njEel1M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108874; c=relaxed/simple; bh=8eNzgbPU9418HKn6ZODmEq9IQh57gGCtuZbwYKe4FDo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=irWGtSh2Y5hh8wXhTnVAt3Dl+icpaGrjJxFW8X2DdAI0Nuj/5kB0/WnD/gWuxGUOHt7ZIYWvq3tKEbWIAnsCzFcA0apcVNxWYCUTTTIiPa6ZNbYCDR6TsmvXBOewJnSUhICr1NXMsk48mf6c8B9NJuydbzSXzkXSWAzQYS1Phyc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hq0IEeSy; 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="hq0IEeSy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31C51C4CEDD; Thu, 27 Mar 2025 20:54:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108874; bh=8eNzgbPU9418HKn6ZODmEq9IQh57gGCtuZbwYKe4FDo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hq0IEeSyIYHz1MN1i4ysIyqaBsu5MbfWsoVkR+leb4Xiq3ub4t7iZDBmVGW5Rn+RT s6uu2U2UEFhl0IexMtbooVncfOh75hmtWkhx7+nqfRM1g1JP7Empj8oOZ4pUtD4dZt yyxjoVACgKEy5GyKPCWSTILV6y/wZXRbO5QOwOVw0Q64fvi9m/gz9Y1tGs3pM1gDkq pozZStH9wz35IrkCDvy0wN1DXmCx2CfL1N/GrvtdmHY43Pbz0Uzyei8seGxsJqcHWj hkmVe0Ln2EYQFSP/kYpec+UKMGAjb07w9IxaIdy+oZ4QISS75OresbldJTgIPG0hok lOoTdy07wP5ng== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 14/41] x86/alternatives: Rename 'text_poke_finish()' to 'text_poke_int3_finish()' Date: Thu, 27 Mar 2025 21:53:27 +0100 Message-ID: <20250327205355.378659-15-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 text_poke_int3_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 c2dbb0e4d80d..43c5f3aecf02 100644 --- a/arch/x86/include/asm/text-patching.h +++ b/arch/x86/include/asm/text-patching.h @@ -42,7 +42,7 @@ extern int text_poke_int3_handler(struct pt_regs *regs); extern void text_poke_int3(void *addr, const void *opcode, size_t len, con= st 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 text_poke_int3_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 bf8080a68f66..cc86c1399a7b 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2866,7 +2866,7 @@ static void text_poke_int3_flush(void *addr) } } =20 -void text_poke_finish(void) +void text_poke_int3_finish(void) { text_poke_int3_flush(NULL); } diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c index 4e284ff674f1..7ab5657078a4 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(); + text_poke_int3_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(); + text_poke_int3_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 94e2dcc94d9d..5a1adf229fcf 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(); + text_poke_int3_finish(); mutex_unlock(&text_mutex); } --=20 2.45.2 From nobody Wed Dec 17 08:44:59 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 F404B1EEA36 for ; Thu, 27 Mar 2025 20:54: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=1743108877; cv=none; b=DP0I03WqDo6oEy8FDgxOeRUVKydctDijZzMf2zdiYgDhDOTZxw1KPj4qMew0Puu5edj/IRTuuMLf/fKsMdKnnwa5g+A9Zvbd/uX+lhk6qOo7x1/Uk3YserIs1vp1exarBG9u/4rsQnR7tEiOiBZlDndEkKV7Mb5XPlRjNlaJdnQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108877; c=relaxed/simple; bh=Rcm7aODbPt6k9TQCqfcINk0B2Wgiw5pPYjpzJmh42nQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A0BuRObU74fFeKDxZlmtATT74pcQdb/MoLxpLhLLhhpHSMuyZNgDBdnC+oJcYW3tzKMrTgqQxhfXex3CYPo10fI5AZVQDqFXJBAtZ+J/M+GSrZjaKyHJpFWtS5z+KASXPnKlFRTB+UB5EZwl6EE0HLn/3TIxqQguNzgDXHhQ7V4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=sbsRmzQC; 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="sbsRmzQC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8BC77C4CEE8; Thu, 27 Mar 2025 20:54:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108876; bh=Rcm7aODbPt6k9TQCqfcINk0B2Wgiw5pPYjpzJmh42nQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sbsRmzQCHWvhZwPqeuOkD9/tXEaPe7WEBIS4EB7bT+wmr3sztpGT7cMTWiJuFCJZ9 sIu9WCgnd60+MvETnGy4rE3R3IJ8kBwee98f9mSaDTOvrSH2OnzYgmOcfyWW3VKccy a9ap20ZjMk8N3515iSQJBchvcRJeQzZzNgVSiauS1pUn3o2Vv/pX4wLVjw1Hagokid ZflYEYhsBpaBOH1J5zgccEnDXwbNcrNXt7g+FEWeI7EmR9eVbukvLgWk/tC7+IC4ep x8mmeMeGsZlF1oFWcTko4nrsQSsdrCV3OXMVmULwAHpBP6bNDVGR9HXyCTJwainfeP NwauHikSl+gzA== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 15/41] x86/alternatives: Rename 'text_poke_queue()' to 'text_poke_int3_queue()' Date: Thu, 27 Mar 2025 21:53:28 +0100 Message-ID: <20250327205355.378659-16-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 text_poke_int3_queue() 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 43c5f3aecf02..7deb06aec467 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 text_poke_int3_handler(struct pt_regs *regs); extern void text_poke_int3(void *addr, const void *opcode, size_t len, con= st void *emulate); =20 -extern void text_poke_queue(void *addr, const void *opcode, size_t len, co= nst void *emulate); +extern void text_poke_int3_queue(void *addr, const void *opcode, size_t le= n, const void *emulate); extern void text_poke_int3_finish(void); =20 #define INT3_INSN_SIZE 1 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index cc86c1399a7b..89ab3a11f26e 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2871,7 +2871,7 @@ void text_poke_int3_finish(void) text_poke_int3_flush(NULL); } =20 -void __ref text_poke_queue(void *addr, const void *opcode, size_t len, con= st void *emulate) +void __ref text_poke_int3_queue(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 7ab5657078a4..ff3cdd08f28f 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 text_poke_int3_queue() * that they do, here. */ text_poke_int3_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); + text_poke_int3_queue((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); + text_poke_int3_queue((void *)rec->ip, new, MCOUNT_INSN_SIZE, NULL); ftrace_update_record(rec, enable); } text_poke_int3_finish(); diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c index 5a1adf229fcf..f72738e6d7d4 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); + text_poke_int3_queue((void *)jump_entry_code(entry), jlp.code, jlp.size, = NULL); mutex_unlock(&text_mutex); return true; } --=20 2.45.2 From nobody Wed Dec 17 08:44:59 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 5D8BD1EF37E for ; Thu, 27 Mar 2025 20:54:38 +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=1743108879; cv=none; b=AU3L9FGSvC8l7cwZ3CXAtjIzaUD0eYib88K9kHL2uzFqQ4vwJSBcw7dwCc5RezArTD+vaf0H5wcEJ84Q7h8kRrg/12ne0Exxa2wCTXt0gdETx4VOH+J4c0uk0IbZKMroguhe7zFHK5feDiQ1XOX5YmgjufW2l/CWQ37sCBpdz3s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108879; c=relaxed/simple; bh=ZCzaJ1GzYCi9QGyPAJ+YZiVJfInW5nTy7FWebxnvhwQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aGux09d6K4QsHGePPpaHfEIxUBMSe+1S2uiC5sClgnrc5P54L6keCQyXDKkbn9KIj2qIR4H5sr8sJVB7GskX5TLcfNWhSPuSrb0q4oqgQoN0h3hQDJz0cY6poZFyDF4caM4V6Y+byDQbxa5miVRq8M5Y9PuTMN0Ifeox7dCcz3A= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FE/LWrR9; 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="FE/LWrR9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8565C4CEEA; Thu, 27 Mar 2025 20:54:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108878; bh=ZCzaJ1GzYCi9QGyPAJ+YZiVJfInW5nTy7FWebxnvhwQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FE/LWrR9pEHtzm6KkuM8cvjp4k4NwbPJSQsoOF2emmmkSbd1VfiHR7MPNkdPIGkpl YAy+AJU0HIiQpWDR/q7gMS7cwAx91Zttd0KCJU7HJb6UbummiIxySCrUNvcYBOGMVv A5V71dziBgAsMSjfD3QxgPOLDteBZITn6B49pH9RVXIFx6AB6w1JJIckW5BRDibe/4 BbQemHr9nCdXNvM+FKs8X9O+bgpuMtT/baVXrzZVHmNIe8I5c8j/tAv6NGWMCBpx6G SDxJHNT3oPk/jDHNAxHkTmiqnV6z49RaFq5EjvLID+3r3oCwx7+v0o+BvASdaWGzwY DC/ocGFS3khUA== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 16/41] x86/alternatives: Rename 'text_poke_loc_init()' to 'text_poke_int3_loc_init()' Date: Thu, 27 Mar 2025 21:53:29 +0100 Message-ID: <20250327205355.378659-17-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 89ab3a11f26e..64355aa25402 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2762,7 +2762,7 @@ static void text_poke_int3_batch(struct text_poke_loc= *tp, unsigned int nr_entri } } =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 text_poke_int3_queue(void *addr, const voi= d *opcode, size_t len, cons text_poke_int3_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 text_poke_int3(void *addr, const void *opc= ode, size_t len, const void { 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); text_poke_int3_batch(&tp, 1); } --=20 2.45.2 From nobody Wed Dec 17 08:44:59 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 BBEA61DDA3D for ; Thu, 27 Mar 2025 20:54: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=1743108882; cv=none; b=CSUOyvqXyARNnFL3ECxhI6LoihU0OK2YYwYqTSvOEy4PAc6qkAxf6sq7vgTEhb2fNxEDenstJqZW05rOenAq0Dq0riWsLHeZOupFyTS0hTAIhABGuXpOekmak4fax8fVFou0Zdw0IbbjcvRGNHKtRMYTajKe/S+8Xh18/QrHcxk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108882; c=relaxed/simple; bh=py9hVGE7uEo18V6K/13DP1+9IePOV54O177MZwqQcAU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Lr6+BMJksJ9j+EXjJnqyPTvXpZsqu6ndAqvxwr8Yu4+Wnu9m0f++H3eQ/22BsG53OlcanzgLyBNbNy4mVDPMo8sRTo7HhCUqzamcf+Yr/feOwHNb2ruLn1QBTu8BmpxhKB/h//wzLaqBuXEjytlYp6LJbGYp7UxH4Uj3lSo3fKw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=VAC7xaBY; 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="VAC7xaBY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4FD43C4CEEB; Thu, 27 Mar 2025 20:54:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108881; bh=py9hVGE7uEo18V6K/13DP1+9IePOV54O177MZwqQcAU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VAC7xaBYAF0eDTa82rXU5sJxVbzfnL9ih8L+rVZGBZfcNKYosp/xsEvqdmEuA62TV 5hNCmCPafAi/5A+eqv2HqUp/anzf0OCiScL+xsZOkfaO3vvF1h+XK48GJpn1QU7w5b sVuH9oiTQF3LPSClUIpprFz4usl23ExCS0jVgOXr+DWoUnHbbljYskBhCD9XDNe1JZ 8vyvtZaFKQsvSLMbKSNeb/f0XRUaS2vHDhi3YmLpUP/sf/K9m4/3IfrU1jwkeCKTFZ 5c4ud4PYbZpGBRVGQ5kNOsJGdkBj9HuLTb3ZKjGqVRkCF6fKN1801Ff2gsjbL42Q+n OPUwXLaX2IWKQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 17/41] x86/alternatives: Rename 'struct text_poke_loc' to 'struct text_poke_int3_loc' Date: Thu, 27 Mar 2025 21:53:30 +0100 Message-ID: <20250327205355.378659-18-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 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 64355aa25402..62aead1bd671 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 text_poke_int3_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 text_poke_int3_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_int3_addr(struct text_poke_loc *tp) +static __always_inline void *text_poke_int3_addr(struct text_poke_int3_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 text_poke_int3_loc *tp =3D (struct text_poke_int3_loc *) elt; =20 if (key < text_poke_int3_addr(tp)) return -1; @@ -2513,7 +2513,7 @@ static __always_inline int patch_cmp(const void *key,= const void *elt) noinstr int text_poke_int3_handler(struct pt_regs *regs) { struct int3_patching_desc *desc; - struct text_poke_loc *tp; + struct text_poke_int3_loc *tp; int ret =3D 0; void *ip; =20 @@ -2544,7 +2544,7 @@ noinstr int text_poke_int3_handler(struct pt_regs *re= gs) */ if (unlikely(desc->nr_entries > 1)) { tp =3D __inline_bsearch(ip, desc->vec, desc->nr_entries, - sizeof(struct text_poke_loc), + sizeof(struct text_poke_int3_loc), patch_cmp); if (!tp) goto out_put; @@ -2592,8 +2592,8 @@ noinstr int text_poke_int3_handler(struct pt_regs *re= gs) 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 text_poke_int3_loc)) +static struct text_poke_int3_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 text_poke_int3_batch(struct text_poke_loc *tp, unsigned int nr= _entries) +static void text_poke_int3_batch(struct text_poke_int3_loc *tp, unsigned i= nt nr_entries) { unsigned char int3 =3D INT3_INSN_OPCODE; unsigned int i; @@ -2762,7 +2762,7 @@ static void text_poke_int3_batch(struct text_poke_loc= *tp, unsigned int nr_entri } } =20 -static void text_poke_int3_loc_init(struct text_poke_loc *tp, void *addr, +static void text_poke_int3_loc_init(struct text_poke_int3_loc *tp, void *a= ddr, 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 text_poke_int3_loc *tp; =20 if (!tp_vec_nr) return false; @@ -2873,7 +2873,7 @@ void text_poke_int3_finish(void) =20 void __ref text_poke_int3_queue(void *addr, const void *opcode, size_t len= , const void *emulate) { - struct text_poke_loc *tp; + struct text_poke_int3_loc *tp; =20 text_poke_int3_flush(addr); =20 @@ -2894,7 +2894,7 @@ void __ref text_poke_int3_queue(void *addr, const voi= d *opcode, size_t len, cons */ void __ref text_poke_int3(void *addr, const void *opcode, size_t len, cons= t void *emulate) { - struct text_poke_loc tp; + struct text_poke_int3_loc tp; =20 text_poke_int3_loc_init(&tp, addr, opcode, len, emulate); text_poke_int3_batch(&tp, 1); --=20 2.45.2 From nobody Wed Dec 17 08:44:59 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 1F85E1F1303 for ; Thu, 27 Mar 2025 20:54:43 +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=1743108884; cv=none; b=c5w+syqd2/63p2IMdO1agKGGJhnzOQWvRQ2K/D8dNNe83xIVLb4coJHsv5DovxJClgI25LqDCZ9MDlAih1IKE6AMrHqxZIKiCWWKP9b9eixYckZ6uDw8ZImP10XmhwCWJ3c6BU0PnJzzKvtHq2huQRfIGN8shb47RQluA/MPnFg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108884; c=relaxed/simple; bh=DTKzPUx/8uXv0sHiySN+14mvolGDMo9UYku+RfJ/RL0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Y+fu3MU+9D3MvOAdFlocNJIt1HtMm0dF2MOWZ7aXeDZ8Jwo2z7htI2i3EoTSgG7LMx5S+HqRlydtL2mbANOFxfrZaHwQK5RxaXufbFY/I4Qos63Q54osjUDpgKA62AazidVieZ+E/kXliNVZzrnpo127bEEVMnhCSIK0CUY502s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iCUplbT4; 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="iCUplbT4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AD4EAC4CEED; Thu, 27 Mar 2025 20:54:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108883; bh=DTKzPUx/8uXv0sHiySN+14mvolGDMo9UYku+RfJ/RL0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iCUplbT4H109ZdwWADHUYErja3QlUzv3M6ohr/9bqj+PRI6iciGcjXSdFT/zdZcsY +YeXWpNW+ExAeL42NVkn9bts0y4GVjBcAYhMey66MvqODPNZV9buElCYuGhUNiP+c4 wj00t6oNvwOtKqcsB03YtK/Hqqi+ri50KNMf/hZzsqXfFL5UQZXfgWTMpi0NhDrReu 6nrFQUE3NOCf5iryZ9KFSs+ClVsqs8gajr9ZNZYgeXx+q0R68LAO6RMPsHuMD877Pa lPzBWgxrYv3CXxKtBLGlpf56sS5wCSh949bYGT2fPLNKqO7fAdFeK2ymXHeUNeRoh0 zxQud2nO8Qjqg== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 18/41] x86/alternatives: Rename 'struct int3_patching_desc' to 'struct text_poke_int3_vec' Date: Thu, 27 Mar 2025 21:53:31 +0100 Message-ID: <20250327205355.378659-19-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 62aead1bd671..84c26d037f05 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2466,17 +2466,17 @@ struct text_poke_int3_loc { u8 old; }; =20 -struct int3_patching_desc { +struct text_poke_int3_vec { struct text_poke_int3_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 text_poke_int3_handler(struct pt_regs *regs) { - struct int3_patching_desc *desc; + struct text_poke_int3_vec *desc; struct text_poke_int3_loc *tp; int ret =3D 0; void *ip; --=20 2.45.2 From nobody Wed Dec 17 08:44:59 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 21EA41F3BBC for ; Thu, 27 Mar 2025 20:54: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=1743108886; cv=none; b=kCfjO5v7MLJ8qL25xhgns4EUjhmq36/9HozQYZ3YcHRbBLNtlORDq6iKgtO8AendLhnHBc8qVF8QED9qAmvxeS1N5MtYV4dUFZhUzQd2rTvtI+DND+IjLGZ8VOhog1beCHseKQ99LUgTCyTBhrLRkpKt4K8htLOfnduQY48PbAU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108886; c=relaxed/simple; bh=syPrkXLItsYp6RWBVz0g6CH8g+YTRH/Y7vTvm+v/eu0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U23ULrMFo58sUAlIqUyeH5dQMA2NgcQrc5WwKRhK4FBpxh6pL0KZE8Ge8Xb3z6y27vYecrPv/YHw+dKS61GtovhHl1RsGR+ukL5Xs1H70HLQtKATV46r7U5HJRzgXc7EJv0F8Uu8fwhNIiZeBVFemOoTBz5uvvmJBzpyXoEjg0Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=vDf38+p/; 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="vDf38+p/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 164DFC4CEE8; Thu, 27 Mar 2025 20:54:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108886; bh=syPrkXLItsYp6RWBVz0g6CH8g+YTRH/Y7vTvm+v/eu0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vDf38+p/tVm/LXOnZcXHTClqzztx375uXPrmMZzUTOPTuYi1hS4zjU6EdIkS3gaV5 utJt8fdQ2KKzINp4nNlTRivmGInWS47hT/LgzoSyfk7FKA3gkukgom10HibqObJp05 yDURPtKn//TgXQIV7ClHr3A5U0q1zbxqzSvbIykYqO2D7NRc31x9tAuAc3DlRXi+Pm nQdaK9xGAV0ja7fevlisEqkzPrmnWFgBatXJj4GOQjNo1Y1ui9+FlONY0FhufziAoG EqocA6OgkjkK/dKRhS+wYb4hQJ9WlFNYVju/fYuEuM29O6MbfGLcDK+2d0Mk6/wmGQ qmuG9h6vv2V6A== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 19/41] x86/alternatives: Rename 'int3_desc' to 'int3_vec' Date: Thu, 27 Mar 2025 21:53:32 +0100 Message-ID: <20250327205355.378659-20-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 84c26d037f05..a10e1b9db7b4 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 text_poke_int3_handler(struct pt_regs *re= gs) =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 text_poke_int3_batch(struct text_poke_i= nt3_loc *tp, unsigned int nr_ =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 08:44:59 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 F03EF1DDC2E for ; Thu, 27 Mar 2025 20:54:48 +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=1743108889; cv=none; b=FGD0VUfgRNOLvjHhz1X/YOvgNojYnminJA6Gi4+IDye9hP81Xk1uJAJDq+vqUVfqMg0anH0DN+9moU/Kk2Z3gz1DSyy6H8BS0y/3Avfr/UDgdV8jbjUdubPGqTtJIaYhPv3K4meXwH2OdR8z+CZxmipvX2tYjtlFXHlbMvWKtxk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108889; c=relaxed/simple; bh=9GBZ9hxohiO2X7F9sa1OcOUm4FTwL2gytiXlhodCkRs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gyi2aY1I7z65IWTDsdZq2qMj2zSXCpeyj/fWmSfRosWG27vm2qmdIDay/PzdV/zJXPiYltL9SjYtC531SLyXcdh6+u/ABhX7stRtN8mmxdz9XVA0ic+o6uM9CYxeknNoXXOV69Gp2G/EGQinLhfxunz9xwo4ix5Nirz2lhAMS4I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Gi7f/hK7; 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="Gi7f/hK7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 76F8AC4CEDD; Thu, 27 Mar 2025 20:54:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108888; bh=9GBZ9hxohiO2X7F9sa1OcOUm4FTwL2gytiXlhodCkRs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Gi7f/hK7Fnp1PyOyaExFPyHmbZWKDyQ+VBjsFtlsxCYghkFVIsLzYEVRAlEAxrjc/ o1G86acv0lswardIJz0yd1FrhrUhyVU0ft5G02+Trm+3wuesBz9ie1ZUHTKl0ugtHa 53gvX+BPnlJKzqdLaje/Gd7Piy7pQI6G/ffIa/6Gli1p4tuuvfMGAPBoaWmzR3lcHP /4S1bSddj9PeVQ7hYxUuemwj+wQfeuMzhdDGXMu9Nw1HPRzVb10D2BhWdLffLEy56x c5oQtOvgVZyQJC9ZPQbzo41j7FKtdN6IGLl/ABNhjTehOGuxpoJ9ZDqZZYeDVhGLCv lzboDRWWIBxJg== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 20/41] x86/alternatives: Add text_mutex) assert to text_poke_int3_flush() Date: Thu, 27 Mar 2025 21:53:33 +0100 Message-ID: <20250327205355.378659-21-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 text_poke_int3_batch() 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 text_poke_int3_batch() or text_poke_int3_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 a10e1b9db7b4..f75806d699be 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 text_poke_int3_flush(void *addr) { + lockdep_assert_held(&text_mutex); + if (tp_vec_nr =3D=3D TP_VEC_MAX || tp_order_fail(addr)) { text_poke_int3_batch(tp_vec, tp_vec_nr); tp_vec_nr =3D 0; --=20 2.45.2 From nobody Wed Dec 17 08:44:59 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 4F62E1F463D for ; Thu, 27 Mar 2025 20:54: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=1743108891; cv=none; b=FYB0qix/h755BbWmki8dpx/ArXWiucOG0ur7QzmrCY3exzE34SXu5jRN3eRHL+uwdKtbJ9uaMk8Qa02zQ8kN+2/bAOThkG4k9B76IdfglIhftIDZuggi8umpFTEiDUhtb5ocUT3EZwkawmSH+BnVX0SVLMazARRthd2jLZeOu+8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108891; c=relaxed/simple; bh=ooCiG1pF4040CksZrN8oejXD/ZlBQakpeu4sxsiC2Xk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=U5IesxSwf+He8O/clruvceqhutIFnwpi15BjUi+ncojeliNXEbbojfVgEQDLxInNLAw3CLgT2xtQoLPj2RZrkxTgo0cIb8VVZe+u7yd3qzhzSnLSUX/IvKGQ74um6i5LzLc1PW3+47FEGWsntZ92aN2os9eFHR7Ewp9H1+V0rpg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UKjk42dl; 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="UKjk42dl" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D56F1C4CEE8; Thu, 27 Mar 2025 20:54:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108890; bh=ooCiG1pF4040CksZrN8oejXD/ZlBQakpeu4sxsiC2Xk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UKjk42dlf/O6lPFJE+q1Bx8MPVfGdL2T9ziIpRG8pRknsN3Fb4coYRBgcoAsC5FRK YOq4T1VdCOL5QEmrlmRzAyl2cSIAQ6h2t2kEp+DG8TdwW4McvH1UxxhqcFIW8L/jkn yQc/TtuDBqAcWKbWtDm+DqKmfqfWkyh4VJJXGvZWuTN7Bnvxigkys4gsC5g+rIeIdA WRrJR1tgfX4MXs6H2PYr8SdRPsfJtpeDqEJ00hY+cTcrXIL9dOdHuUKadIjGhOJFBx d62BtkOMLhZFIvN/RgufVpE6o0cpQL3XfolAAUlDsBjCOWagNYL10Cb7+tKhK4QjEK ul7RhU5WKwrVw== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 21/41] x86/alternatives: Assert that text_poke_int3_handler() can only ever handle 'tp_vec[]' based requests Date: Thu, 27 Mar 2025 21:53:34 +0100 Message-ID: <20250327205355.378659-22-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 f75806d699be..883c2146ce54 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 text_poke_int3_loc)) +static struct text_poke_int3_loc tp_vec[TP_VEC_MAX]; +static int tp_vec_nr; + noinstr int text_poke_int3_handler(struct pt_regs *regs) { struct text_poke_int3_vec *desc; @@ -2534,6 +2538,8 @@ noinstr int text_poke_int3_handler(struct pt_regs *re= gs) if (!desc) return 0; =20 + WARN_ON_ONCE(desc->vec !=3D tp_vec); + /* * Discount the INT3. See text_poke_int3_batch(). */ @@ -2592,10 +2598,6 @@ noinstr int text_poke_int3_handler(struct pt_regs *r= egs) return ret; } =20 -#define TP_VEC_MAX (PAGE_SIZE / sizeof(struct text_poke_int3_loc)) -static struct text_poke_int3_loc tp_vec[TP_VEC_MAX]; -static int tp_vec_nr; - /** * text_poke_int3_batch() -- update instructions on live kernel on SMP * @tp: vector of instructions to patch --=20 2.45.2 From nobody Wed Dec 17 08:44:59 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 A849C1F4CA1 for ; Thu, 27 Mar 2025 20:54: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=1743108893; cv=none; b=erbB2KbCrPbGGnUBnKSy0r1OhiaqidD7luO7yTBi91Eq31a7HY0muceXN87n6ZccDPcUe7JisyI6xsDvBlcK3adBGFlkPDLzc4/MG/RWkxVonEDSsYrTaXFK68445YuLUxxVzWXN6qpCG1mjbhub3iWiASDFLRlZ+s5ZAPhlXx8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108893; c=relaxed/simple; bh=2DZAbxn4eU3D1we1tIjKqz9zqdYULwjE7sxoLgezx0E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=R5NP2lVk/ULUCLvvqN87gRx8i9oopU0YQWjBn2jFQc9ZHtv+Jz9sS7oeVwZHEmH6BeVUjsBLPoZxuSbX/oLtXMIZdV82LgEr3TZ9Tg88GTgMquGAz0PAvXJzu7dH9TUjPuGRF+wS8rHtrVcUVWGWxeytnII8sqNBLrmb7wLWAkk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Rih2p4VE; 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="Rih2p4VE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42CC2C4CEED; Thu, 27 Mar 2025 20:54:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108893; bh=2DZAbxn4eU3D1we1tIjKqz9zqdYULwjE7sxoLgezx0E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Rih2p4VEKvnrKSd6+tHE0tUFZHHdaTMfNjqPgVYuVA4T3bZ5lbrVXMUfyv81ruU5A xef4Nvux13Tx/iJefMe6kkl8MoMmdpfx7ae0dUEIhSaGyBV69eDSRPMdTkHN9XMRfE zVgi+31xd3MPoVdd6PLWg+3t9R3rRD+QeGzom6P9V1+Pv2QN/oRKfgdLRbwA/x+K5Y hfIFfVYNsNfvofVzV3ybIQAPbPrX1rm+lKuuQaybCiJv/0fsxICSpVxdWOeE8/araH zk3ugLv0PSECx/VwpgfK2EGjew8lLOTyU5hQ/MIRr/xEuYABhyl5E+e1fY7ZVaP3pm J37ccbgESYGOQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 22/41] x86/alternatives: Use non-inverted logic instead of 'tp_order_fail()' Date: Thu, 27 Mar 2025 21:53:35 +0100 Message-ID: <20250327205355.378659-23-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 'tp_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 883c2146ce54..938e8e70a379 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 text_pok= e_int3_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 tp_addr_ordered(void *addr) { struct text_poke_int3_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_int3_addr(tp) > (unsigned long)addr) - return true; + return false; =20 - return false; + return true; } =20 static void text_poke_int3_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 || !tp_addr_ordered(addr)) { text_poke_int3_batch(tp_vec, tp_vec_nr); tp_vec_nr =3D 0; } --=20 2.45.2 From nobody Wed Dec 17 08:44:59 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 ACD381F4C89 for ; Thu, 27 Mar 2025 20:54: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=1743108895; cv=none; b=r2hY4JgO85Dm3uJnvIG6eiV6uqYW2h1zEfLmSJwEkycMD4LrMPL5gHzZY3CJBGIZAbfOeljCb3XkfdfSSoGu8k78RV1jyjD5jJg3VYmPtnQS2Pu8zGFmMnU4snVD4coPQ+MNntLuOD5wcEjSjwI8KTNic+iM/sn9xSBoKZ1nWXQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108895; c=relaxed/simple; bh=8u0r22WAfYVwDqds3fWK7E47NzAdr3UN05v7fNA7zFw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=T9yBthZeWItHkKsSNcjeeGYHJqXlQM6j026SIlfJar7xoH9yXzLgSyFFoNvBUSzraHDRffUY6nOaG0O1ae8qteXa4A4UrULgoBLJBb3WXF0/0dlWv6f+yOF82az0c2p5vK7/QW9hfMHtcfGTf8dTVXnfaTDtjPUJmm9XC12BhiA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ev95ktBb; 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="Ev95ktBb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A33AAC4CEDD; Thu, 27 Mar 2025 20:54:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108895; bh=8u0r22WAfYVwDqds3fWK7E47NzAdr3UN05v7fNA7zFw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ev95ktBbyRQIvMgep4vrl8HRXE1UMzTeYtjd/CPPwloZz4tOCksU+KseN5q1KMD64 EwjEM8OsQYM6ce8nY/5V7cfwDvHpfxTDoMH2AXDeL3/zuptjfjWwM0zJ4y7AYVli8U /dHKEZduYeNHjdF6W9X9tcB4Sgv356+2ysvRBlYiSI7xkMUzIPHzF1mQ2FiRozPstP J9XWr0pYYszgsEbk1yxRiUGlyMepC1U2xVMBx/lB1xvORaXfUJo/MojAx/w+oGS4Dx LZG3cisj4ihYxbfWn3qQmtrjksO29opAK3Ah1Q9BShdcMVrtsi6zqM8VuJIx8RxdU/ ve3nvtiY0LGIA== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 23/41] x86/alternatives: Remove the 'addr == NULL means forced-flush' hack from text_poke_int3_finish()/text_poke_int3_flush()/tp_addr_ordered() Date: Thu, 27 Mar 2025 21:53:36 +0100 Message-ID: <20250327205355.378659-24-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 text_poke_int3_finish() to indicate a 'forced flush': text_poke_int3_flush(NULL); Just open-code the vector-flush in a straightforward fashion: text_poke_int3_batch(tp_vec, tp_vec_nr); tp_vec_nr =3D 0; And get rid of !addr hack from tp_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 938e8e70a379..906fb45b9e65 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2847,12 +2847,11 @@ static bool tp_addr_ordered(void *addr) { struct text_poke_int3_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 tp_addr_ordered(void *addr) return true; } =20 +void text_poke_int3_finish(void) +{ + if (tp_vec_nr) { + text_poke_int3_batch(tp_vec, tp_vec_nr); + tp_vec_nr =3D 0; + } +} + static void text_poke_int3_flush(void *addr) { lockdep_assert_held(&text_mutex); @@ -2876,11 +2883,6 @@ static void text_poke_int3_flush(void *addr) } } =20 -void text_poke_int3_finish(void) -{ - text_poke_int3_flush(NULL); -} - void __ref text_poke_int3_queue(void *addr, const void *opcode, size_t len= , const void *emulate) { struct text_poke_int3_loc *tp; --=20 2.45.2 From nobody Wed Dec 17 08:44:59 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 20E991F583A for ; Thu, 27 Mar 2025 20:54: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=1743108898; cv=none; b=FmT/a/NbuOKehypQ7tkwmxyyyLBuzAjJEXG7u+CbGc69jcqBEXC2S4amrbgTlO7LQWkLxmnm6gigFTEv/alIjWFLUUgPPlPFCKJarC92bgd4OpG/pQnOhsoPX/fSU7RoixjsXkCQDk73PO6YCAWtU+AxhnxqGK73U1umew6xdN4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108898; c=relaxed/simple; bh=p0Ih10xOVpTCmZXQkmnpEk3Kh0N4Zc+CdM0kPdasQnA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=etsN4gFwRoFyDPcnSPmd+j+t4fZW3x3zWaSNbyGWrCu/YnNgWFwit+h67C7UYKZnGOKAJ6TPatOIMYV8pBGJHtMo7baTZfdYEmrqf7aH3tt5ZmxtKHOvUk0FFMAbevKG0NPdjC24tk99xOfU2JukCk1QZzgTv37KmUUp973LBN4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aDzSPLI/; 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="aDzSPLI/" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0CA9CC4CEEA; Thu, 27 Mar 2025 20:54:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108898; bh=p0Ih10xOVpTCmZXQkmnpEk3Kh0N4Zc+CdM0kPdasQnA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aDzSPLI/gpvlEfLA6Y8aQDgpDLZ862/e3DIg8wblfcOog6QMuNL8MXVKgxm2hxYbC OVhOchZs0R8zzluNUuKg/7BmlBEgoYI+IkgeEKA8w381QpXZYWGoZ0G9ThpA31gJEW dmH/ytH5v7tMo4FX114ShHWNg/wboFsypRLyqJIHjwVysQaBCrAvSB2WfFRmcn7zxH BhiGxi73WaOMI5gAu/4FVDp/GLEp0Li/09bxs+U8sou7L0vvaRLzBvzpEKazDADKO4 T3JJbGdhXX4PLVbJBjfhg/ZhPCjt24La+GmSnfEyo2r0027X5g0bWL5MexOuf7luRw 2drL6YKT5K4Qg== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 24/41] x86/alternatives: Simplify text_poke_int3() by using tp_vec and existing APIs Date: Thu, 27 Mar 2025 21:53:37 +0100 Message-ID: <20250327205355.378659-25-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 906fb45b9e65..4f23f6b4d51d 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2906,8 +2906,13 @@ void __ref text_poke_int3_queue(void *addr, const vo= id *opcode, size_t len, cons */ void __ref text_poke_int3(void *addr, const void *opcode, size_t len, cons= t void *emulate) { - struct text_poke_int3_loc tp; + struct text_poke_int3_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); - text_poke_int3_batch(&tp, 1); + text_poke_int3_finish(); } --=20 2.45.2 From nobody Wed Dec 17 08:44:59 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 76A6D1F7554 for ; Thu, 27 Mar 2025 20:55:00 +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=1743108900; cv=none; b=PEW8B87AOHLWQCJdsAJGz6CneLA44Q8WlXSIRcHtaXGG8qwpkzoMSbmuZK+tqhVtF9m8LZqgwQ66eAPJ1Du1LOtjBUqdLblWYVTc7QFr7ycMRjJSm3f2i3aQKvxzXSf3HvD+gUiUwdPuF+o/qO9vInUQdWv9k+VIzKb2lwYB6jY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108900; c=relaxed/simple; bh=eW/8xw42s/o29z5huZ2CHNrtEu9TIFBu/E2GltPYfx8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TEyoyE6qnaW2Kg5D0FYz9gSGgWavMswZGuxwF8LX6yblKg8zmq7Fbqtxn86SzlI6/+joCnQ6jhUYV9oE1hLUw59QnfaKPcUQxKOc/f2N07/xGj6kV7bEFphxURMef05tQids4aac2PVDlBrmlLLVEIxQOqBYNXfj53owEcDdcvo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qTUklnma; 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="qTUklnma" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6D10DC4CEE8; Thu, 27 Mar 2025 20:54:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108900; bh=eW/8xw42s/o29z5huZ2CHNrtEu9TIFBu/E2GltPYfx8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qTUklnmaK7a1yadaXFYAKq70RUz3OkmvE94vFVDV5BZ5AiF12ySh1OfYrSggD+cFx hH2//iyJ0pfzh/u+q45F1VQFDr6FXreIpxmDJW+EDy+VziVzEAIFFA8TzjnBOrTk9+ Yv0Ce4c36PwyBpdoqhWIcJb0KHLSU/pRK/MmpxY/NPljxF1pgOq19tputXkqzbHQlb cUUqbDLjh2szFTxdzabCQUyq9Ilu6diw2ZTrh+GEQpFzDLqxIxL975RIpgKVytArtH MhgZk1Nns+JKNJ3D3xFNeEWx2M6XqcAxboYo5oD71rELVOFezmAgmQ5o7BuFiIpaln YeOAxn9yYjz+w== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 25/41] x86/alternatives: Assert input parameters in text_poke_int3_batch() Date: Thu, 27 Mar 2025 21:53:38 +0100 Message-ID: <20250327205355.378659-26-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 4f23f6b4d51d..393d796e797d 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2627,6 +2627,9 @@ static void text_poke_int3_batch(struct text_poke_int= 3_loc *tp, unsigned int nr_ =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 08:44:59 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 DB8C41F8741 for ; Thu, 27 Mar 2025 20:55: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=1743108902; cv=none; b=IKeIRQqBpvUIBbY5Rp977hxBKuvpWoysGDCTBCtcKbLwyZGevBSJH5RehNOAOlOogUUEARLOx7MS+/Vyx3zRdzD7QqhbrWemMYXuKsJDmCMOFfP0PA1kpolto+I8E3AJN9FwkQoOm5Hjd8ZSBbjauTSmYjN/wX/scArK5GQxjHQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108902; c=relaxed/simple; bh=bdiwBSo9W6RD9K2588a9gOGZgIRFv+BS8HeSGoR5mdQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WyU1VFc2C0zy+BNY46zhwi34Jn9qPHGuut+9WYgz8Pd8N+6t/M7Bh4EPtN7ny1gDPJ1e5Buvb8jwiZRzucHE3FC63ZqqK+sZe3ul94mT+OGVssaFr7aP36drAFiNKha/pfibth+hA2Jna3QRjuAMLT1Rc5uiaX2zfhNBev18/bg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KbjK632f; 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="KbjK632f" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CBC1DC4CEE8; Thu, 27 Mar 2025 20:55:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108902; bh=bdiwBSo9W6RD9K2588a9gOGZgIRFv+BS8HeSGoR5mdQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KbjK632fDcy2usClEHmIdVo7Qhwyzm0SWBV2e6aDHbitgBQBCBazaRgC6z6s/Yo2P EmCWbLp0kLZXci88+m5QznMazQt2qMEQWLvA3/xlHLQXdRrw8kXE1zkHHOlZ6bX7z/ hlEYyeHBc8w7J+X1/L/HpwLAHm9h+tFoKJGUy40MzUumD+ldm0sfur9TRs7GA3ZMDQ Go4y/LvbyZrjh1Omt/3o78qwm8LFpaqORc+QNLqfLlSTtlVQdacd2If5iVF1I8akVT hdxrz0Md+Xpe9N68JZRv0XoCgY4/BDU4V41l+VDIzS3D4naHtPcqhqP2omqfJLhE6C iF924132OWQfw== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 26/41] x86/alternatives: Introduce 'struct text_poke_int3_array' and move tp_vec and tp_vec_nr to it Date: Thu, 27 Mar 2025 21:53:39 +0100 Message-ID: <20250327205355.378659-27-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 text_poke_int3_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 393d796e797d..cf3bcaa97957 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2467,14 +2467,21 @@ struct text_poke_int3_loc { }; =20 struct text_poke_int3_vec { - struct text_poke_int3_loc *vec; int nr_entries; + struct text_poke_int3_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 text_poke_int3_= loc)) + +static struct text_poke_int3_array { + int nr_entries; + struct text_poke_int3_loc vec[TP_ARRAY_NR_ENTRIES_MAX]; +} tp_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 text_poke_int3_loc)) -static struct text_poke_int3_loc tp_vec[TP_VEC_MAX]; -static int tp_vec_nr; - noinstr int text_poke_int3_handler(struct pt_regs *regs) { struct text_poke_int3_vec *desc; @@ -2538,7 +2541,7 @@ noinstr int text_poke_int3_handler(struct pt_regs *re= gs) if (!desc) return 0; =20 - WARN_ON_ONCE(desc->vec !=3D tp_vec); + WARN_ON_ONCE(desc->vec !=3D tp_array.vec); =20 /* * Discount the INT3. See text_poke_int3_batch(). @@ -2627,8 +2630,8 @@ static void text_poke_int3_batch(struct text_poke_int= 3_loc *tp, unsigned int nr_ =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 tp_array.vec); + WARN_ON_ONCE(nr_entries !=3D tp_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 text_poke_= int3_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 tp_array.vec being ordered; ensure this is so by fl= ushing * early if needed. */ static bool tp_addr_ordered(void *addr) @@ -2852,7 +2855,7 @@ static bool tp_addr_ordered(void *addr) =20 WARN_ON_ONCE(!addr); =20 - if (!tp_vec_nr) + if (!tp_array.nr_entries) return true; =20 /* @@ -2861,7 +2864,7 @@ static bool tp_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 &tp_array.vec[tp_array.nr_entries-1]; if ((unsigned long)text_poke_int3_addr(tp) > (unsigned long)addr) return false; =20 @@ -2870,9 +2873,9 @@ static bool tp_addr_ordered(void *addr) =20 void text_poke_int3_finish(void) { - if (tp_vec_nr) { - text_poke_int3_batch(tp_vec, tp_vec_nr); - tp_vec_nr =3D 0; + if (tp_array.nr_entries) { + text_poke_int3_batch(tp_array.vec, tp_array.nr_entries); + tp_array.nr_entries =3D 0; } } =20 @@ -2880,9 +2883,9 @@ static void text_poke_int3_flush(void *addr) { lockdep_assert_held(&text_mutex); =20 - if (tp_vec_nr =3D=3D TP_VEC_MAX || !tp_addr_ordered(addr)) { - text_poke_int3_batch(tp_vec, tp_vec_nr); - tp_vec_nr =3D 0; + if (tp_array.nr_entries =3D=3D TP_ARRAY_NR_ENTRIES_MAX || !tp_addr_ordere= d(addr)) { + text_poke_int3_batch(tp_array.vec, tp_array.nr_entries); + tp_array.nr_entries =3D 0; } } =20 @@ -2892,7 +2895,7 @@ void __ref text_poke_int3_queue(void *addr, const voi= d *opcode, size_t len, cons =20 text_poke_int3_flush(addr); =20 - tp =3D &tp_vec[tp_vec_nr++]; + tp =3D &tp_array.vec[tp_array.nr_entries++]; text_poke_int3_loc_init(tp, addr, opcode, len, emulate); } =20 @@ -2912,9 +2915,9 @@ void __ref text_poke_int3(void *addr, const void *opc= ode, size_t len, const void struct text_poke_int3_loc *tp; =20 /* Batch-patching should not be mixed with single-patching: */ - WARN_ON_ONCE(tp_vec_nr !=3D 0); + WARN_ON_ONCE(tp_array.nr_entries !=3D 0); =20 - tp =3D &tp_vec[tp_vec_nr++]; + tp =3D &tp_array.vec[tp_array.nr_entries++]; text_poke_int3_loc_init(tp, addr, opcode, len, emulate); =20 text_poke_int3_finish(); --=20 2.45.2 From nobody Wed Dec 17 08:44:59 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 678A31F8726 for ; Thu, 27 Mar 2025 20:55:05 +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=1743108905; cv=none; b=m8zfAtp/QHcfBNjylkjey3AzOzs7HR5QoZYPFM6/eocJXu+TIpHPs5J82NHv2L8xgk0CY0vyFCD+4Y4cdFCSHG4atQfSnJgm1vn9I4vRpEq6f1sxaxoOEpGBGHAmroZha5pSVgfxFhtHWvT47Ns7MMQp5veNveF90vcxEVolh9g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108905; c=relaxed/simple; bh=5xR7PRjLVC0Rruw4fQdXxcv3j63d8tKbS7U0OIHAEdc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JAmrkQtl+iCeZ4dmq/8QkEXhSE48H6BNaG1aj2M6yRholuMOC6nX///3ybWi0zyF4zyNCYdgS65r5I7gw1yj0my7E5dNGDMfVJ/+bKLCFsDWEJxFzRbE8CwsGEo36LD9JeFRnxDLNZZJuQvCb7uKncmq/VuGpZL4kWtyBGps4k0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PFnzJJ+W; 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="PFnzJJ+W" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 388A7C4CEEE; Thu, 27 Mar 2025 20:55:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108905; bh=5xR7PRjLVC0Rruw4fQdXxcv3j63d8tKbS7U0OIHAEdc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PFnzJJ+WXfUIrXgkkfWjx9SDH++Rr66vRKKz4J7q39s0eahecIeWcIP45mHAJyG1E HCUvyCmySIkTdDV1w1rLmZRxZ9AUGJuu56resBA/jlICip9K6EJhlgKTg1LLgjp3+K RdTl3IZ9WJzioREzug3fr8+ZbeemZ3MSGJOxtsvzFAU0nsxmaJqaY2A0AGnO7YVLnb UJY5wlPcU9x6mspVCOu9pkkgqOfDiVSPLxDwHYX91QhLAPCnMpJ1PQCjp4GVw/Wx8I j1GDWExVLK+uHxC21UuX5wgDemOXIcSYypGQdUhXnO3l6htLZtpOxRGGdRlq8d45Mv cRijaSx1lPEVA== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 27/41] x86/alternatives: Remove the tp_vec indirection Date: Thu, 27 Mar 2025 21:53:40 +0100 Message-ID: <20250327205355.378659-28-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 tp_array, there's no need for text_poke_int3_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 cf3bcaa97957..3baef1827f3c 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2466,15 +2466,6 @@ struct text_poke_int3_loc { u8 old; }; =20 -struct text_poke_int3_vec { - int nr_entries; - struct text_poke_int3_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 text_poke_int3_= loc)) =20 static struct text_poke_int3_array { @@ -2482,15 +2473,17 @@ static struct text_poke_int3_array { struct text_poke_int3_loc vec[TP_ARRAY_NR_ENTRIES_MAX]; } tp_array; =20 +static DEFINE_PER_CPU(atomic_t, int3_refs); + static __always_inline -struct text_poke_int3_vec *try_get_desc(void) +struct text_poke_int3_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 &tp_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 text_poke_int3_handler(struct pt_regs *regs) { - struct text_poke_int3_vec *desc; + struct text_poke_int3_array *desc; struct text_poke_int3_loc *tp; int ret =3D 0; void *ip; @@ -2529,7 +2522,7 @@ noinstr int text_poke_int3_handler(struct pt_regs *re= gs) =20 /* * Having observed our INT3 instruction, we now must observe - * int3_vec with non-zero refcount: + * tp_array with non-zero refcount: * * int3_refs =3D 1 INT3 * WMB RMB @@ -2633,12 +2626,9 @@ static void text_poke_int3_batch(struct text_poke_in= t3_loc *tp, unsigned int nr_ WARN_ON_ONCE(tp !=3D tp_array.vec); WARN_ON_ONCE(nr_entries !=3D tp_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 tp_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 08:44:59 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 4952D1F8908 for ; Thu, 27 Mar 2025 20:55: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=1743108908; cv=none; b=MuZoGM5mR8xG8Lr2QSTd7YMoIlUqsquafailycpA3fg381PxqKZmuX3LF40Fp+QU4Gr//RMht5OaGnhab+W5p6N9tmnXGO9nuQHW6mkHQimwN4jpx3mKUr5p+eW9BSWfTtnfWbGjOSDWtJtyoGKJ7cd/LdMirBoxY5KPoUgXCKI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108908; c=relaxed/simple; bh=QMoqbm619+cOnBL7LihbZxCj1fqr6rQXTP8fguEZuoA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rc2E+9IhuOcMKf+CNrNeJF03XQ/2+/x+EBtKjIaYT3dOwX4VCK3dY79hvZL8R0FX4dZtaJLnknPlOfg0kLrsApl+Ij1MmklymWw4YwB+FtrXG45FiP341+GEeBtg0je/3EGORy8Os0fjbQc2DeLmUqjNk26MpNfdrk2i2Bb/3dE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hWm3rxVg; 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="hWm3rxVg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A8D18C4CEEE; Thu, 27 Mar 2025 20:55:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108907; bh=QMoqbm619+cOnBL7LihbZxCj1fqr6rQXTP8fguEZuoA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hWm3rxVgWeJTd10oVyFZMMZrHgpbmW+4A8j6D7Puu0V4hC5LgTr1UDwUlnB3SFzu4 4pjU2ivsMqab+ADydjcwsGsirkX5QGpQOwdooZUvkumuaXAxhbnaMonGikTRqbnuoR +/bS1+8Uegbv9AriN/nEaRZfsN7dPrH9SSavM9pj0vgCLy+dJ5wlSEloyglIgdXdMB oJ8rxw4sXSdpYgFWYArOOLh+MT/QCKl5hVAktzJEOQFCXzr7f7APJKw9jQkmt8zHID MY0fnBMfQO87Zo+QJBk1WSuqyimVXlTCxV96OZgdnYrxhe3RTSoUnKK4Pky+P2kLFX EqRDG8XQAbr7g== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 28/41] x86/alternatives: Rename 'try_get_desc()' to 'try_get_tp_array()' Date: Thu, 27 Mar 2025 21:53:41 +0100 Message-ID: <20250327205355.378659-29-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 3baef1827f3c..4b5ab9002e07 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2476,7 +2476,7 @@ static struct text_poke_int3_array { static DEFINE_PER_CPU(atomic_t, int3_refs); =20 static __always_inline -struct text_poke_int3_array *try_get_desc(void) +struct text_poke_int3_array *try_get_tp_array(void) { atomic_t *refs =3D this_cpu_ptr(&int3_refs); =20 @@ -2530,7 +2530,7 @@ noinstr int text_poke_int3_handler(struct pt_regs *re= gs) */ smp_rmb(); =20 - desc =3D try_get_desc(); + desc =3D try_get_tp_array(); if (!desc) return 0; =20 @@ -2627,7 +2627,7 @@ static void text_poke_int3_batch(struct text_poke_int= 3_loc *tp, unsigned int nr_ WARN_ON_ONCE(nr_entries !=3D tp_array.nr_entries); =20 /* - * Corresponds to the implicit memory barrier in try_get_desc() to + * Corresponds to the implicit memory barrier in try_get_tp_array() to * ensure reading a non-zero refcount provides up to date tp_array data. */ for_each_possible_cpu(i) --=20 2.45.2 From nobody Wed Dec 17 08:44:59 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 4575A1FCF6B for ; Thu, 27 Mar 2025 20:55:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108910; cv=none; b=TtyIs1cW8g1mWc2w74tgR+JTmrF+7bDQ769FslJX2kqT3WwaqB/bJIkP9XX03cgs515LniFg703q8YOdEs47e/ri5EN+CpIpGNBZVd+P632PyDcqEttJuPnWwyCfEMC/osXc4prTnma+CWuQ6H+rMoevmcO+g9kRwMDDFOWCWVw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108910; c=relaxed/simple; bh=DgovOuuyafFnae2SeX+P/RmrowYrTqPQkxMedo3u53s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ev3XQqOtCIEdKQ3phiVOuyco8X2F1VtgurT/d4Apo7C7a5kbvRIT5lhxpek+0CXzuco3JMWW2gk5zdsRojWCMeyv5y73ffIl0Amk+eUqmnbvORdT0P8C9W2J6Cxt6IPEmdKNg7hMlz0GyK1AHO+ozAIpY7Zq7zDhB1MFxxu0mB4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=UpxEleeB; 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="UpxEleeB" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2E8E7C4CEF6; Thu, 27 Mar 2025 20:55:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108910; bh=DgovOuuyafFnae2SeX+P/RmrowYrTqPQkxMedo3u53s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UpxEleeBQ3RSJluK2UdswiaqGVfcS5u0OPyqEN+at7Ri6uY0AwcdR95VjdNcPRXws BQfP1x0ySQvyayPNy6pLmyHVzfcPoRXNxpOLF1HnuFn+e2miXeryjx0yXCpkfSyKh9 SHlSRyFyXEpxxcZrx3HmsKuFgB/xGS8Wl9hAUrKEa36ifpDsr5zUYZ+Rdb2dbngUk5 wCngQD3Bm7nGj6+SoHz7Fp7C6LE9F5XiD6owc0Jt00X6Unhnnirv4wQypd2TDfdWuu C+zUW2m8MtMxcfEMn3D98IT4Ke4EStRr2o56mgt53fcgKg3kQkbncp19tfhKkQgiaJ Ep0qFcjmbF0/g== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 29/41] x86/alternatives: Rename 'put_desc()' to 'put_tp_array()' Date: Thu, 27 Mar 2025 21:53:42 +0100 Message-ID: <20250327205355.378659-30-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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_tp_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 4b5ab9002e07..0b11f53d6e6d 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2486,7 +2486,7 @@ struct text_poke_int3_array *try_get_tp_array(void) return &tp_array; } =20 -static __always_inline void put_desc(void) +static __always_inline void put_tp_array(void) { atomic_t *refs =3D this_cpu_ptr(&int3_refs); =20 @@ -2590,7 +2590,7 @@ noinstr int text_poke_int3_handler(struct pt_regs *re= gs) ret =3D 1; =20 out_put: - put_desc(); + put_tp_array(); return ret; } =20 --=20 2.45.2 From nobody Wed Dec 17 08:44:59 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 08BDC1FE478 for ; Thu, 27 Mar 2025 20:55: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=1743108913; cv=none; b=Nl4ZjUDIBq+/12ZB6GRBd/thJrx/oyPzINVeciIEkjyCJL3vGGsfKJ6qpvt6/plzvQOHDCWusYMD1VbbhkQ5Crq/EiB4aCBgHIboEfRipiw47pEH6nlgec8BKCpphL2in77UX5FajxjPcp+GX8YGKNh2Sn1qz71Ax/zxhM1sUIs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108913; c=relaxed/simple; bh=aQn1IMuNWEzPzCM2QlviwU5M5BXYHAYMr6gHofPyD/U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mbNzxpNGpOA+zSsqlXS3tJz06gfcxFDxPHb4AuzCOEuWuP+KFoWw+CCQiXIteH3vanZnB4kmQqVuO3iT4AAQQ7clqNlMyjzswVIvPBQjjhp0fmK2vzM48AKhUQjpX4DXQfTUnnGNf3VJ+4/l9SwfIYpWPBTUO76N8KEbHLeYPDk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mniHxcTO; 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="mniHxcTO" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 94DE1C4CEE8; Thu, 27 Mar 2025 20:55:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108912; bh=aQn1IMuNWEzPzCM2QlviwU5M5BXYHAYMr6gHofPyD/U=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mniHxcTOHD9MJreBwlnXOktb90Qdd3uhJ4x8H9zfARNdsQOUGJ/q4w6UOFsqr95am LUDycNG1YHPAE6WiOzwVpo0bfrOu5+uMG/CGhoWSpqM2uFKmfqPhj6PDpHY7fbFwLT X+swV4UWf4gJEbPNS3r15+oa26y/ESpHjlUK7qyP3HbSPQxEZCFyuUonmp4DHJvtgM aSBIUf2D0DgRf5xpZZ9W8u15aIMmC/VgZOBdtuxxDr2Qz/PGpGnZUOLVq8AHIaredf O+e8OizBkac2hNv8lggxuL6hAevQq15zhmqWPKdGzFRNLyVTGaN93PCBgu7JYCcS6W 1wSihEI+3hR4A== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 30/41] x86/alternatives: Simplify try_get_tp_array() Date: Thu, 27 Mar 2025 21:53:43 +0100 Message-ID: <20250327205355.378659-31-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 0b11f53d6e6d..244119066672 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2475,15 +2475,14 @@ static struct text_poke_int3_array { =20 static DEFINE_PER_CPU(atomic_t, int3_refs); =20 -static __always_inline -struct text_poke_int3_array *try_get_tp_array(void) +static bool try_get_tp_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 &tp_array; + return true; } =20 static __always_inline void put_tp_array(void) @@ -2530,9 +2529,9 @@ noinstr int text_poke_int3_handler(struct pt_regs *re= gs) */ smp_rmb(); =20 - desc =3D try_get_tp_array(); - if (!desc) + if (!try_get_tp_array()) return 0; + desc =3D &tp_array; =20 WARN_ON_ONCE(desc->vec !=3D tp_array.vec); =20 --=20 2.45.2 From nobody Wed Dec 17 08:44:59 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 693441FECC1 for ; Thu, 27 Mar 2025 20:55:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108915; cv=none; b=CqjyAe6524i14O2wvy8KMuAhaTIyIcbgLCjg14FJd2//lNKflAgWqiwbrlEt5dLiGq4k/qiiAz7yOdHoQP0IvUp5vCGoQAgqkQUorJA/FFtsUSd+pXq16uf5ZOIWxD4jrkl4+5toC3JTcguH0mOfDtuqSWeRakrsE0IRlPy6Mk0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108915; c=relaxed/simple; bh=U010mwqqgTBeBus61i+2bfeywY135xwU5UXbS6BSstM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X4yLEqd0AudmC41r8FHAwRCcng/93K56BCftyqidAo1leTQX4Kogy875qDre5QHe+WseppoZDo96OpFUPrHQuW7i/MpvbLLWV8eI4SiMDuOxBPhVhr/hceKJy62hFeAShE2iHmDloMhbrZjzWhtRwYVW2mWHO+9Az5aSWYJ16E4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=FFEecOr4; 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="FFEecOr4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3618C4CEEB; Thu, 27 Mar 2025 20:55:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108914; bh=U010mwqqgTBeBus61i+2bfeywY135xwU5UXbS6BSstM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FFEecOr4bWgZTRx7Kor/dy46f8GNEJKYgy7kgc5WHZ4iJ5h0RTUCCBVm4c6hucoaS pI1ktmE25UVDTVq+YoDbKkTIvvoDIo11v0rgdCiKCYsTrAnnR4DGMQuz/fzmjC2Ug6 LHfv9gTjPwpYZQDPAQe3e2oPAz37rp2OcTSFha0PvUFgB0t+zLhOQveuMeEKYwePB0 vr2wrhd4frd3owxYLzrYGJFS3nvb98QhcGA6qFfDfufQsaEMEcBMSTaBJV2Ye0rzws lDD34ftmA7aMhLJostwhPOeqK8FvS0mjrfPszhxjyFmOCfbMHEkyNztsVBf1u0Jwyl zMEZUZxKSMcbQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 31/41] x86/alternatives: Simplify text_poke_int3_handler() Date: Thu, 27 Mar 2025 21:53:44 +0100 Message-ID: <20250327205355.378659-32-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 tp_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 244119066672..9402826e2903 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 text_poke_int3_handler(struct pt_regs *regs) { - struct text_poke_int3_array *desc; struct text_poke_int3_loc *tp; int ret =3D 0; void *ip; @@ -2531,9 +2530,6 @@ noinstr int text_poke_int3_handler(struct pt_regs *re= gs) =20 if (!try_get_tp_array()) return 0; - desc =3D &tp_array; - - WARN_ON_ONCE(desc->vec !=3D tp_array.vec); =20 /* * Discount the INT3. See text_poke_int3_batch(). @@ -2543,14 +2539,14 @@ noinstr int text_poke_int3_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(tp_array.nr_entries > 1)) { + tp =3D __inline_bsearch(ip, tp_array.vec, tp_array.nr_entries, sizeof(struct text_poke_int3_loc), patch_cmp); if (!tp) goto out_put; } else { - tp =3D desc->vec; + tp =3D tp_array.vec; if (text_poke_int3_addr(tp) !=3D ip) goto out_put; } --=20 2.45.2 From nobody Wed Dec 17 08:44:59 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 D626A1FF1A1 for ; Thu, 27 Mar 2025 20:55: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=1743108918; cv=none; b=JYylLJP3pX2cQ78nCBkOHKDSIxZJ4sFIt2ITj0ghJWNjxRlchLKjU+yhcwYfPXvk+J4MdkrhV1iuYJ4gPeFMccvpNm2srs/vxg/DtPTk6bX3wMxsiBNt5wthYfS+N1EsWaniuYKNxge+HGK+r59qIfKXvf1cUg8OlU5qLCFZwFU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108918; c=relaxed/simple; bh=4zd+rCZ5QeklxftUChVjGc316W9QQBg9XQs4mwfg6cM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aRlin5tg87RFDH6yha/3DPus68EaoOgmOsepiTQ+yOKDpuKmgq+CXCepXPrcLsqDH0Kjxq1IzRPFtbgkK/HViEblUPdBonHFeXr/cdpTZl83gHDt6Wx+kInT+Q8HUJN3atj8v/W85DvfCEfWsVWpOWxy2iMHH6Hpob7LKCUjvB8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PM4UHPdw; 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="PM4UHPdw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5E1CCC4CEE8; Thu, 27 Mar 2025 20:55:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108917; bh=4zd+rCZ5QeklxftUChVjGc316W9QQBg9XQs4mwfg6cM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PM4UHPdwhFAbtoRzU/ilvTqDWwxAc1t8OV0Jh9jDaTHDWGJjp0Q68vNrYTahSbQjP TAt7/ayg7hjlfshFoQI2CGMkyql7dHm/PRP3Au9HB6SHYPP5vakEPpNddIWv4ZOMOe PWu1CnlEB8ObVKkOIoqBR0p1murA1M30R52pLZoTOrPYpWS8l3+5vHjsiRC3cygUn/ VkVN0etsFnJQuOgNLpAIYBasLJsJMpX9g/OdZV+Pu6nOhi3vnqZjeKwa6lo+xaHkgN 9EqMlDGx8gZsJ08kTOwklP5P/LbVwE1Ptz9C46MvnWNW3ypQvZIVYvAmLs91YFSisX CW/g9NVWO+7pg== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 32/41] x86/alternatives: Simplify text_poke_int3_batch() Date: Thu, 27 Mar 2025 21:53:45 +0100 Message-ID: <20250327205355.378659-33-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 tp_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 9402826e2903..40e86b41bb86 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2591,8 +2591,8 @@ noinstr int text_poke_int3_handler(struct pt_regs *re= gs) =20 /** * text_poke_int3_batch() -- update instructions on live kernel on SMP - * @tp: vector of instructions to patch - * @nr_entries: number of entries in the vector + * @tp_array.vec: vector of instructions to patch + * @tp_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 text_poke_int3_handler(struct pt_regs *re= gs) * replacing opcode * - sync cores */ -static void text_poke_int3_batch(struct text_poke_int3_loc *tp, unsigned i= nt nr_entries) +static void text_poke_int3_batch(void) { unsigned char int3 =3D INT3_INSN_OPCODE; unsigned int i; @@ -2618,9 +2618,6 @@ static void text_poke_int3_batch(struct text_poke_int= 3_loc *tp, unsigned int nr_ =20 lockdep_assert_held(&text_mutex); =20 - WARN_ON_ONCE(tp !=3D tp_array.vec); - WARN_ON_ONCE(nr_entries !=3D tp_array.nr_entries); - /* * Corresponds to the implicit memory barrier in try_get_tp_array() to * ensure reading a non-zero refcount provides up to date tp_array data. @@ -2640,16 +2637,16 @@ static void text_poke_int3_batch(struct text_poke_i= nt3_loc *tp, unsigned int nr_ =20 /* * Corresponding read barrier in int3 notifier for making sure the - * nr_entries and handler are correctly ordered wrt. patching. + * tp_array.nr_entries and handler are correctly ordered wrt. patching. */ 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_int3_addr(&tp[i]); - text_poke(text_poke_int3_addr(&tp[i]), &int3, INT3_INSN_SIZE); + for (i =3D 0; i < tp_array.nr_entries; i++) { + tp_array.vec[i].old =3D *(u8 *)text_poke_int3_addr(&tp_array.vec[i]); + text_poke(text_poke_int3_addr(&tp_array.vec[i]), &int3, INT3_INSN_SIZE); } =20 text_poke_sync(); @@ -2657,15 +2654,15 @@ static void text_poke_int3_batch(struct text_poke_i= nt3_loc *tp, unsigned int nr_ /* * 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 < tp_array.nr_entries; i++) { + u8 old[POKE_MAX_OPCODE_SIZE+1] =3D { tp_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 tp_array.vec[i].text; + int len =3D tp_array.vec[i].len; =20 if (len - INT3_INSN_SIZE > 0) { memcpy(old + INT3_INSN_SIZE, - text_poke_int3_addr(&tp[i]) + INT3_INSN_SIZE, + text_poke_int3_addr(&tp_array.vec[i]) + INT3_INSN_SIZE, len - INT3_INSN_SIZE); =20 if (len =3D=3D 6) { @@ -2674,7 +2671,7 @@ static void text_poke_int3_batch(struct text_poke_int= 3_loc *tp, unsigned int nr_ new =3D _new; } =20 - text_poke(text_poke_int3_addr(&tp[i]) + INT3_INSN_SIZE, + text_poke(text_poke_int3_addr(&tp_array.vec[i]) + INT3_INSN_SIZE, new + INT3_INSN_SIZE, len - INT3_INSN_SIZE); =20 @@ -2705,7 +2702,7 @@ static void text_poke_int3_batch(struct text_poke_int= 3_loc *tp, unsigned int nr_ * The old instruction is recorded so that the event can be * processed forwards or backwards. */ - perf_event_text_poke(text_poke_int3_addr(&tp[i]), old, len, new, len); + perf_event_text_poke(text_poke_int3_addr(&tp_array.vec[i]), old, len, ne= w, len); } =20 if (do_sync) { @@ -2721,16 +2718,16 @@ static void text_poke_int3_batch(struct text_poke_i= nt3_loc *tp, unsigned int nr_ * 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 < tp_array.nr_entries; i++) { + u8 byte =3D tp_array.vec[i].text[0]; =20 - if (tp[i].len =3D=3D 6) + if (tp_array.vec[i].len =3D=3D 6) byte =3D 0x0f; =20 if (byte =3D=3D INT3_INSN_OPCODE) continue; =20 - text_poke(text_poke_int3_addr(&tp[i]), &byte, INT3_INSN_SIZE); + text_poke(text_poke_int3_addr(&tp_array.vec[i]), &byte, INT3_INSN_SIZE); do_sync++; } =20 @@ -2859,7 +2856,7 @@ static bool tp_addr_ordered(void *addr) void text_poke_int3_finish(void) { if (tp_array.nr_entries) { - text_poke_int3_batch(tp_array.vec, tp_array.nr_entries); + text_poke_int3_batch(); tp_array.nr_entries =3D 0; } } @@ -2869,7 +2866,7 @@ static void text_poke_int3_flush(void *addr) lockdep_assert_held(&text_mutex); =20 if (tp_array.nr_entries =3D=3D TP_ARRAY_NR_ENTRIES_MAX || !tp_addr_ordere= d(addr)) { - text_poke_int3_batch(tp_array.vec, tp_array.nr_entries); + text_poke_int3_batch(); tp_array.nr_entries =3D 0; } } --=20 2.45.2 From nobody Wed Dec 17 08:44:59 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 216CD1FF1D6 for ; Thu, 27 Mar 2025 20:55: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=1743108920; cv=none; b=d8hWDK4QSGZuyJghbwa8XEOo6XTbufRQqFoQuzLjov558tfPSwheaPQqd0zdc4TwLjQJqDGBe2QG5r8czW8gnJCXWTIt+G/CQ38u6CavruqpPfU3m/Y+YjaqFz0S6UDAchjDJxOV/aQtKwCsLYyc33lO33dv6inJ0acIJstINzM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108920; c=relaxed/simple; bh=ONkCbb0X17pJcuDecoMQku1CkhbCOHuD9g7WoFvQdLI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=uF1TzLYqI9m9fLB1uOjBlaLePyfyk9rkfcXoD65Z21GE6ye2kzkZi/ZzYeItXupdh/FQMMhsPViLAtx6272cseKMG+jOUphi1v8dhViOf0me/BWQ42OpvQtKjMkbt6kO5y1uanRYQE6q+45/AfIMUtB3Z6wijndFh8k6cjVcFGc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OIH8WHxu; 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="OIH8WHxu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA06FC4CEEA; Thu, 27 Mar 2025 20:55:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108919; bh=ONkCbb0X17pJcuDecoMQku1CkhbCOHuD9g7WoFvQdLI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OIH8WHxu54I04RN3wXOUMG9VJpAgpHEehd7a38Jtk7UUIEcgFoZ8md/RhiHfglbYh Liy5Vr0S92RBSMucYqjsHeoaPbZkAUSFXB3BMwx73JzVtHSMODmZB5Czov0vG7dcB6 cIg8RTalz2+XJUKFwCtYJCgXXc1cDsVRwrLm4sr3k7ya92uTWpXqhfWY/g/9OL8FqW eRnki22AzZXj6+NMf6Lm42AFEMm1nAB4SlvPLK30A2q00Xq56Je6cUB8B74sXnsYrW qnVNihFiE46BpV2fU4/RpKZyxL/YC8ajRNV4Jlu8vfTachB+9khTjEwhVmNN45YsoT VANIVXKFTxSmw== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 33/41] x86/alternatives: Rename 'text_poke_int3_batch()' to 'text_poke_int3_batch_process()' Date: Thu, 27 Mar 2025 21:53:46 +0100 Message-ID: <20250327205355.378659-34-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 in the name that this is the function that does the actual batch processing (patching). 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 40e86b41bb86..6c3850527bd5 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2462,7 +2462,7 @@ struct text_poke_int3_loc { u8 len; u8 opcode; const u8 text[POKE_MAX_OPCODE_SIZE]; - /* see text_poke_int3_batch() */ + /* see text_poke_int3_batch_process() */ u8 old; }; =20 @@ -2532,7 +2532,7 @@ noinstr int text_poke_int3_handler(struct pt_regs *re= gs) return 0; =20 /* - * Discount the INT3. See text_poke_int3_batch(). + * Discount the INT3. See text_poke_int3_batch_process(). */ ip =3D (void *) regs->ip - INT3_INSN_SIZE; =20 @@ -2590,7 +2590,7 @@ noinstr int text_poke_int3_handler(struct pt_regs *re= gs) } =20 /** - * text_poke_int3_batch() -- update instructions on live kernel on SMP + * text_poke_int3_batch_process() -- update instructions on live kernel on= SMP * @tp_array.vec: vector of instructions to patch * @tp_array.nr_entries: number of entries in the vector * @@ -2610,7 +2610,7 @@ noinstr int text_poke_int3_handler(struct pt_regs *re= gs) * replacing opcode * - sync cores */ -static void text_poke_int3_batch(void) +static void text_poke_int3_batch_process(void) { unsigned char int3 =3D INT3_INSN_OPCODE; unsigned int i; @@ -2856,7 +2856,7 @@ static bool tp_addr_ordered(void *addr) void text_poke_int3_finish(void) { if (tp_array.nr_entries) { - text_poke_int3_batch(); + text_poke_int3_batch_process(); tp_array.nr_entries =3D 0; } } @@ -2866,7 +2866,7 @@ static void text_poke_int3_flush(void *addr) lockdep_assert_held(&text_mutex); =20 if (tp_array.nr_entries =3D=3D TP_ARRAY_NR_ENTRIES_MAX || !tp_addr_ordere= d(addr)) { - text_poke_int3_batch(); + text_poke_int3_batch_process(); tp_array.nr_entries =3D 0; } } --=20 2.45.2 From nobody Wed Dec 17 08:44:59 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 2844D1FFC49 for ; Thu, 27 Mar 2025 20:55: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=1743108922; cv=none; b=i42Q9fY3R4sXmslNkgL1oRtZjllADTg6CuOt/A/VBpPLoS3CoFI+woU5ImC/X5DSkYqeFYX2O54uu1Rh+y72FKAMoXt+VUUmd3ycgFpq4T22fNlf0DB2dF3teyz0m8FuHCmubD75kapDH/5pM6772Lw4hSMoo5BsKHeSs0vtOr0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108922; c=relaxed/simple; bh=+zk0eyrSgNMye3/IquBat7SMnI+wWDUbA9GFx8uB25M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CK8ZCM+/1AqSSteQx8etCkSWlrkLTl68+edycejBZw/UQ9uVCGS+lP8ZbWSoPr2xrMF7RKmJ9MY7Tm8C2Pd1gkCm2/c/fRyMGVDgkUD9AAUhC+45SB581DIEBMVUChytqXqnl4o4kXrUBoxN+lxD5PWCvAmku4Ifow/B1ls9+9k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jDMaLTgs; 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="jDMaLTgs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 222B0C4CEDD; Thu, 27 Mar 2025 20:55:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108922; bh=+zk0eyrSgNMye3/IquBat7SMnI+wWDUbA9GFx8uB25M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jDMaLTgsajV6qKqbDeNpuebV3GicPgQO2pxsenbGhKPJoa5MZjPuccdgHc/l0fTIw mxDMn9+USvtmySrjodBuVF9Es7a0OGzv4+EED8PN8pJrglUVzIZ9jpcIOk8fojZ49M MqDGkuPzGTBJJDLSuFIVeR8OcKKyj3lOduRgD8ufX+ueVIpXI8juNMMnzUCn8b8oJ7 UqpWtarp4yphltNFIVm0KT60u2DdNd3QhakxxoOX7czR0Uz9D7UDq3ejg2/A/qPlNi rNDjm1dmTY+3SrAHumN/JHOn8RFEM/WqGmOW/MhL6vspQH916Ch9HKmt29n8TEOSnG b2E1IqkKw8RRQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 34/41] x86/alternatives: Rename 'int3_refs' to 'tp_array_refs' Date: Thu, 27 Mar 2025 21:53:47 +0100 Message-ID: <20250327205355.378659-35-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 tp_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 6c3850527bd5..3ab40b0f5245 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2473,11 +2473,11 @@ static struct text_poke_int3_array { struct text_poke_int3_loc vec[TP_ARRAY_NR_ENTRIES_MAX]; } tp_array; =20 -static DEFINE_PER_CPU(atomic_t, int3_refs); +static DEFINE_PER_CPU(atomic_t, tp_array_refs); =20 static bool try_get_tp_array(void) { - atomic_t *refs =3D this_cpu_ptr(&int3_refs); + atomic_t *refs =3D this_cpu_ptr(&tp_array_refs); =20 if (!raw_atomic_inc_not_zero(refs)) return false; @@ -2487,7 +2487,7 @@ static bool try_get_tp_array(void) =20 static __always_inline void put_tp_array(void) { - atomic_t *refs =3D this_cpu_ptr(&int3_refs); + atomic_t *refs =3D this_cpu_ptr(&tp_array_refs); =20 smp_mb__before_atomic(); raw_atomic_dec(refs); @@ -2522,9 +2522,9 @@ noinstr int text_poke_int3_handler(struct pt_regs *re= gs) * Having observed our INT3 instruction, we now must observe * tp_array with non-zero refcount: * - * int3_refs =3D 1 INT3 + * tp_array_refs =3D 1 INT3 * WMB RMB - * write INT3 if (int3_refs !=3D 0) + * write INT3 if (tp_array_refs !=3D 0) */ smp_rmb(); =20 @@ -2623,7 +2623,7 @@ static void text_poke_int3_batch_process(void) * ensure reading a non-zero refcount provides up to date tp_array data. */ for_each_possible_cpu(i) - atomic_set_release(per_cpu_ptr(&int3_refs, i), 1); + atomic_set_release(per_cpu_ptr(&tp_array_refs, i), 1); =20 /* * Function tracing can enable thousands of places that need to be @@ -2745,7 +2745,7 @@ static void text_poke_int3_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(&tp_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 08:44:59 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 867911DEFFE for ; Thu, 27 Mar 2025 20:55: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=1743108924; cv=none; b=OAHdGgEVbUycM+YJnigrXmJzz4+t/yORTArMV+9vNAnH2hrXRtpp7/B8VdOE5Uz5SRfCGl1BswVZR6uBl6h7qsNlr9rQRqyIiTkC5xlYeFZBEUN1k2j25e10nyPnjInDlo8XSGEJ5n4XOujUxAomby22TsSCsNk3ni1a4J8n8xU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108924; c=relaxed/simple; bh=qY3C88Lx9VqUBrjdw5WfnBOZxPia3jDyA6h+eQRXizw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J0E8jDQtyP3bckj5iodkCTzMCsXms6eaGVVIhwdsJfotHaIX8OVHhOTy6JCSkO1eZRougxQTsuN+3dgcpVyekXDlMhYdq0MGbpLQeKAsH0pgoISKM7KvhGf42DOXpbt8ZxBS4DTnzHuNHP/aGD+kh5MGl0oQv2wyI3/TEBu2fyU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=MUUsMFSM; 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="MUUsMFSM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7E7EAC4CEE8; Thu, 27 Mar 2025 20:55:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108924; bh=qY3C88Lx9VqUBrjdw5WfnBOZxPia3jDyA6h+eQRXizw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MUUsMFSM+ig41Oj0aKGoITrfewFfH6/TJL0+jrMTpPQFRBeSDkMnx5xPNRxUfyPHO nTtk3E+rv/wrLgTUjcYpkewO5KH3SewrjXM0Ic65IcrX5bZepFFl6iRyyHtiZtp7Xx 5ia+kVEl/puT7oZussppiTLxlFDTqd2avObt/5opFJybeqi782BkaYvDh+i70CD8Js sL37V/aCODEdX0sIutddhMGbGhWsipu91PZDWHT8TQ2HCPtvJLgjI1l2g3uMYoYjzh hbx+Ja0l3RyqrkclTCzyEGC8vpFXmh0Dj+ALE2kAVOSs6bsaosJyxx4bcCFqtRTFX0 pz9f2XS0jxIQQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 35/41] x86/alternatives: Move the tp_array manipulation into text_poke_int3_loc_init() and rename it to text_poke_int3_loc_add() Date: Thu, 27 Mar 2025 21:53:48 +0100 Message-ID: <20250327205355.378659-36-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 3ab40b0f5245..e1cc3e109feb 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2752,12 +2752,14 @@ static void text_poke_int3_batch_process(void) } } =20 -static void text_poke_int3_loc_init(struct text_poke_int3_loc *tp, void *a= ddr, - const void *opcode, size_t len, const void *emulate) +static void text_poke_int3_loc_add(void *addr, const void *opcode, size_t = len, const void *emulate) { + struct text_poke_int3_loc *tp; struct insn insn; int ret, i =3D 0; =20 + tp =3D &tp_array.vec[tp_array.nr_entries++]; + if (len =3D=3D 6) i =3D 1; memcpy((void *)tp->text, opcode+i, len-i); @@ -2873,12 +2875,9 @@ static void text_poke_int3_flush(void *addr) =20 void __ref text_poke_int3_queue(void *addr, const void *opcode, size_t len= , const void *emulate) { - struct text_poke_int3_loc *tp; - text_poke_int3_flush(addr); =20 - tp =3D &tp_array.vec[tp_array.nr_entries++]; - text_poke_int3_loc_init(tp, addr, opcode, len, emulate); + text_poke_int3_loc_add(addr, opcode, len, emulate); } =20 /** @@ -2894,13 +2893,10 @@ void __ref text_poke_int3_queue(void *addr, const v= oid *opcode, size_t len, cons */ void __ref text_poke_int3(void *addr, const void *opcode, size_t len, cons= t void *emulate) { - struct text_poke_int3_loc *tp; - /* Batch-patching should not be mixed with single-patching: */ WARN_ON_ONCE(tp_array.nr_entries !=3D 0); =20 - tp =3D &tp_array.vec[tp_array.nr_entries++]; - text_poke_int3_loc_init(tp, addr, opcode, len, emulate); + text_poke_int3_loc_add(addr, opcode, len, emulate); =20 text_poke_int3_finish(); } --=20 2.45.2 From nobody Wed Dec 17 08:44:59 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 56ABE1E1DED for ; Thu, 27 Mar 2025 20:55: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=1743108927; cv=none; b=djmHJlRmwYW3obOnMNZPGTYrXqoL3W+lvKa/BT51nZN8ylr/FkIOGfDW5FLwQ1sURun+InUsZ9YFnDrc7jmeTXVZTr5xwG/WasfhZXVhhygly38b5aMKb7va0iCt3dpQjlO85FyM4Yr/lYunOAniz696qh52VenSaO4nqHrrcb4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108927; c=relaxed/simple; bh=7ALMOuG7jWpUDlRjq+Q/UOkbY2mXJBUhKxrusBFu4c8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oZYJ3KJ3ByrJYTwRLsgQNCzWWzET6+roSFuSVsUFveNKporPsPag7Y8FyUPIRxmaISG7js/NGuTH8hLbPfyKlJpFRCmEd2SJVumWuC9u666EMT2QD49Ys8VEfrffj+CZpWsCS2V8CL+e+U6sbS1fA3DG5sp9yPCQyId8K2xvQSA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XIrwVTo7; 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="XIrwVTo7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D645AC4CEDD; Thu, 27 Mar 2025 20:55:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108926; bh=7ALMOuG7jWpUDlRjq+Q/UOkbY2mXJBUhKxrusBFu4c8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XIrwVTo7JFihxY0SJr9/wguPGqmXiAnB93a0eQ7SsGeU+fJC5vfSwo7nOM/bzc1DA YhLdpo8v7HZC39hSo1iFxoOlpJsQS5fttNbtD0xrmseBZrRkAERMQhAyxqXUPnYbQl zmi6hV0/0XWI0nvOu6ttGGOBWcxz4Xa2PZy4zdpO7epIeHjC6qOBkEVc23AG74R+Ai vc7IS0YLxunAJTUMhMUFzQVgu8GM97fskaZNHEiA+mDy46+hO5Hq+FKG9HUPXBoSRu /2jTw+LjTkBdkKkENUlzcWIK/+qkcvG80KCkCmmWPROE22bCSTytsDjSv90X6OYVLq Uj8OpnkCnh3BA== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 36/41] x86/alternatives: Remove the mixed-patching restriction on text_poke_int3() Date: Thu, 27 Mar 2025 21:53:49 +0100 Message-ID: <20250327205355.378659-37-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 text_poke_int3(addr, opcode, len, emulate) is equivalent to: text_poke_int3_queue(addr, opcode, len, emulate); text_poke_int3_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 e1cc3e109feb..2807d35c7676 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2893,9 +2893,6 @@ void __ref text_poke_int3_queue(void *addr, const voi= d *opcode, size_t len, cons */ void __ref text_poke_int3(void *addr, const void *opcode, size_t len, cons= t void *emulate) { - /* Batch-patching should not be mixed with single-patching: */ - WARN_ON_ONCE(tp_array.nr_entries !=3D 0); - text_poke_int3_loc_add(addr, opcode, len, emulate); =20 text_poke_int3_finish(); --=20 2.45.2 From nobody Wed Dec 17 08:44:59 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 A1AD220010C for ; Thu, 27 Mar 2025 20:55: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=1743108929; cv=none; b=PLrMH/QD8AZnlbrsdVg8SCj9vZt2KnAuzwI73iOsQXadclIzwfLcBCo5kaGwl8kjwZPTzxNxXrvYt2VznIq26sni6ipurCAL9y0jqkhkQwbG00oizt9x3EhuUGMoxwKukanhY8wT4D5n4FQdCjnlifCO8xAjCN3M0GMHGCW0scQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108929; c=relaxed/simple; bh=eLbTYSgijLpKFTpkDcIYsE290Y5rBuicH2nkZPZA5QE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VtOm+N+okDsNNPvP4h6O8RzMWqri5GjkWiDxyZNItYV0PCR1lYsHQI4OahqYQsCLqrmTev0KOcPdCf4Pb0fYtUgEgdA2i80StxZowu+AC054ll2UedNGp25D1AFqbxccDtJC39TgEq0KcoZOsBZioR+dEbaNlwEzU6Hx4nw3SpQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=j777JcAd; 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="j777JcAd" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3AAD6C4CEEA; Thu, 27 Mar 2025 20:55:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108929; bh=eLbTYSgijLpKFTpkDcIYsE290Y5rBuicH2nkZPZA5QE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j777JcAdjK8rAUBX9vWJJ5jISV8BAD6TO4wCV/MJj9/FjU3LSh6/Pqa6vGFsoD3Vh eORzYsR/YdQ2rVaiABqz7o/GFGg/qYwnot7jrFs4ki3rCG3h7uaWx+Cylz+a9uqUOH dIb0rAbF+aq0zTXz6Mv/z9QCYOGPtklHhgb2QE8xRSwmZ0Lj1dWnrtUSg4lbvzKgD0 W2BpC2PLgjW7zaJLaYR+K5gh65fS46pTYEErRjm5rDlpS7/6U+0+YNcBOqm/Rx8iCO t34iEuRLD0kMNhWZ8cwu8ZK1SJOxM4MCssCduyMGLhuHXIYQgePBHHjeWaFjlexhLb bpp//Eh3giU5w== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 37/41] x86/alternatives: Rename 'text_poke_int3()' to 'text_poke_int3_now()' Date: Thu, 27 Mar 2025 21:53:50 +0100 Message-ID: <20250327205355.378659-38-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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" In the current name it's not obvious that the main difference between text_poke_int3() and text_poke_int3_queue() is that text_poke_int3() patches the kernel immediately. Make this more apparent by renaming it to text_poke_int3_now(). Also extend the documentation to better describe its purpose. Signed-off-by: Ingo Molnar --- arch/x86/include/asm/text-patching.h | 2 +- arch/x86/kernel/alternative.c | 7 ++++--- 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, 13 insertions(+), 12 deletions(-) diff --git a/arch/x86/include/asm/text-patching.h b/arch/x86/include/asm/te= xt-patching.h index 7deb06aec467..611957617278 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 text_poke_int3_handler(struct pt_regs *regs); -extern void text_poke_int3(void *addr, const void *opcode, size_t len, con= st void *emulate); +extern void text_poke_int3_now(void *addr, const void *opcode, size_t len,= const void *emulate); =20 extern void text_poke_int3_queue(void *addr, const void *opcode, size_t le= n, const void *emulate); extern void text_poke_int3_finish(void); diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 2807d35c7676..6e2fab1768e2 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2881,7 +2881,7 @@ void __ref text_poke_int3_queue(void *addr, const voi= d *opcode, size_t len, cons } =20 /** - * text_poke_int3() -- update instructions on live kernel on SMP + * text_poke_int3_now() -- update instruction on live kernel on SMP immedi= ately * @addr: address to patch * @opcode: opcode of new instruction * @len: length to copy @@ -2889,9 +2889,10 @@ void __ref text_poke_int3_queue(void *addr, const vo= id *opcode, size_t len, cons * * 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 text_poke_int3(void *addr, const void *opcode, size_t len, cons= t void *emulate) +void __ref text_poke_int3_now(void *addr, const void *opcode, size_t len, = const void *emulate) { text_poke_int3_loc_add(addr, opcode, len, emulate); =20 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c index ff3cdd08f28f..40b1c218ee86 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_int3((void *)ip, new, MCOUNT_INSN_SIZE, NULL); + text_poke_int3_now((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_int3((void *)ip, new, MCOUNT_INSN_SIZE, NULL); + text_poke_int3_now((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_int3((void *)ip, new, MCOUNT_INSN_SIZE, NULL); + text_poke_int3_now((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_int3((void *)ip, new, MCOUNT_INSN_SIZE, NULL); + text_poke_int3_now((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 f72738e6d7d4..e5b58c81dfaf 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_int3((void *)jump_entry_code(entry), jlp.code, jlp.size, NULL); + text_poke_int3_now((void *)jump_entry_code(entry), jlp.code, jlp.size, NU= LL); } =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 e13d4a2d9244..54bc5e7c6886 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_int3(op->kp.addr, insn_buff, JMP32_INSN_SIZE, NULL); + text_poke_int3_now(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 3331a7c90b9a..146cc27848df 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_int3(insn, code, size, emulate); + text_poke_int3_now(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 1e2a4b7a6b73..8d08c8ff3e50 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_int3(ip, new_insn, X86_PATCH_SIZE, NULL); + text_poke_int3_now(ip, new_insn, X86_PATCH_SIZE, NULL); ret =3D 0; } out: --=20 2.45.2 From nobody Wed Dec 17 08:44:59 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 019491E1E03 for ; Thu, 27 Mar 2025 20:55: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=1743108932; cv=none; b=DpNKvWig3Kw5X68xz0eUIHiw/osdTNqSVR5E6mR70L7ssFZOLJdUf2/l6Yq4dXsLC47UpfQK9iZ6jDNNA3YLR0ao5c3giKk1vhH8AFk7cGdLaHTK+8Zsaq4Cokt8GHbuxdi6pSJ9aPCHhN0SORb5nF/5rc35sya8YZ+rk7cdo8Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108932; c=relaxed/simple; bh=HoQveO0faaYUoFjWPwusKNMrw5MJAE1bF14xLtyj8eY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g72sMevrQD7JaERUuNg/BX3PutSfyHy2f8tZhorsl4LtmgOKceHGyUPJMtfG3DUZUbyV0ZQk4EtUBNhm5vfULZxT+uukZYo+2otVkB9OMsG90rkfBdbGovs8GcXVIEauxumjutgbKiC24vH3IWlaryn2AOLmdmjt+yuDE7u8RJk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gWba+j92; 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="gWba+j92" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 93DEDC4CEED; Thu, 27 Mar 2025 20:55:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108931; bh=HoQveO0faaYUoFjWPwusKNMrw5MJAE1bF14xLtyj8eY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gWba+j92Od66vSce4cx0+yMFEra62orchrfe1wJgiN5oko4vysfWprWVHVFWc0bGT AsThOnXwMJ/RudFMrEEURR9HBo6r2BJ4Ox3cCnsHAY61cr9LW5qYL9OFQQ/FxnJc7H 3YGyamFZdYOy0h6xDA9x4sE6zVaruZOSkmqX8DMMj0R+h9tEZ3ABF4mlzEltrfIdss pjfrHGpEpOX7VKWuZbBPlfSIJ/nsyesj5esL7uThTAYCCu0aL3aBXO+GYocqG1ygG3 aOm5EzJtp265msOsdNjSEx1Pv37NMrzz5MTy/5V89JcLhJ6EcNiw7E8byIHG51xHYD czSAVjVB9htlQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 38/41] x86/alternatives: Add documentation for text_poke_int3_queue() Date: Thu, 27 Mar 2025 21:53:51 +0100 Message-ID: <20250327205355.378659-39-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 6e2fab1768e2..ba322a29aefd 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2873,6 +2873,19 @@ static void text_poke_int3_flush(void *addr) } } =20 +/** + * text_poke_int3_queue() -- update instruction on live kernel on SMP, bat= ched + * @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 + * text_poke_int3_finish() call. + */ void __ref text_poke_int3_queue(void *addr, const void *opcode, size_t len= , const void *emulate) { text_poke_int3_flush(addr); --=20 2.45.2 From nobody Wed Dec 17 08:44:59 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 F157E20102A for ; Thu, 27 Mar 2025 20:55:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108934; cv=none; b=CAn5xzy2Weh1wpUOn/GWc8afj1WD4rD172o8eg5fjqx9GnC18WfW4VIfArX1coSJ2E/VAtP9Yb8IoJq2tZpwCZpNjzj6VyZZOBvmL09syEe8eoNsbgV/ewc5v+4UmE0ilUbaXNbi5kMKQUe7XBByU9YisPxUw7ji2NtiIRCj4sw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108934; c=relaxed/simple; bh=UjD1AYfZXQ3g8Nnd8gn7w8mDASasb2fkP86nzz+63xg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AM6e3FBB1Ed63D+jE+eZC3a2A0Tq7VYZZ5cym0MGzPFrSuzSxYMD5QUxsCepDXAVz09QcOq+QwRqKlqN4tpSU4WFUBltWxuQBqAxRpPLqCcKucnYpgRyNJk+TkXVhlu5CRSV3LiRnxWWkm1w9WI5uF+ec9ISyZiEJbxBu/KoX1Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=JoY7SGc7; 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="JoY7SGc7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF392C4CEEA; Thu, 27 Mar 2025 20:55:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108933; bh=UjD1AYfZXQ3g8Nnd8gn7w8mDASasb2fkP86nzz+63xg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JoY7SGc7vjsPpmdxhAVyf0VOZOPDfNeGnNsMdHxeOiT9+FuTHNg8LaczKMSTxWuPk 7Fmtu7hie5qsbiEb4hKtQXe4kReoP0T/q/zq8sFTPQ1D75Qo5tCJ+i08pufy2CdWd7 x289Oop8/7QKi2Uxl79CiMrmylD5bMLGGKh2j62hgK6jWM9AdlUuISvbkj77iZAGTV Ai2btru7uaUs1GrYUqA2AV/25A8O1vxN7lM/mYGH7thT8xXdD3IkDPrw0hBycwVOzp bnPM5VJ1vhkjQEK8zIjebvvLDNhmeSUVDMOITp73iq/BHZ5nzUE2gRJhvoZi0IBqOu FoBbWjcnqMdjg== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 39/41] x86/alternatives: Move tp_array completion from text_poke_int3_finish() and text_poke_int3_flush() to text_poke_int3_batch_process() Date: Thu, 27 Mar 2025 21:53:52 +0100 Message-ID: <20250327205355.378659-40-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 ba322a29aefd..1b523496a2f6 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2750,6 +2750,9 @@ static void text_poke_int3_batch_process(void) if (unlikely(!atomic_dec_and_test(refs))) atomic_cond_read_acquire(refs, !VAL); } + + /* They are all completed: */ + tp_array.nr_entries =3D 0; } =20 static void text_poke_int3_loc_add(void *addr, const void *opcode, size_t = len, const void *emulate) @@ -2857,20 +2860,16 @@ static bool tp_addr_ordered(void *addr) =20 void text_poke_int3_finish(void) { - if (tp_array.nr_entries) { + if (tp_array.nr_entries) text_poke_int3_batch_process(); - tp_array.nr_entries =3D 0; - } } =20 static void text_poke_int3_flush(void *addr) { lockdep_assert_held(&text_mutex); =20 - if (tp_array.nr_entries =3D=3D TP_ARRAY_NR_ENTRIES_MAX || !tp_addr_ordere= d(addr)) { + if (tp_array.nr_entries =3D=3D TP_ARRAY_NR_ENTRIES_MAX || !tp_addr_ordere= d(addr)) text_poke_int3_batch_process(); - tp_array.nr_entries =3D 0; - } } =20 /** --=20 2.45.2 From nobody Wed Dec 17 08:44:59 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 5C752201260 for ; Thu, 27 Mar 2025 20:55: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=1743108936; cv=none; b=p0AnZ1M/eu+KsQISaek0lWLHIlEct9c7UWtfnw4Y6nMWOW56Ruh2+NcELfFARVGThJlA9UERehoKjHmxXP9r7ewYybUwguK/hjRR50LiYyqUJETGbFt4wArDiWuP93rsL6V041fqDZS+qD/ZUFQIessJZvFWoLup/Ibv8YSlXMk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108936; c=relaxed/simple; bh=wRb65iHgs3gw2lvD+qtC5MU5+7GuZzV78UYKyZwK4oM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=N8orZ/bpj7NyI6Vri1Fc36eQW8RXudZ52AkzRK5DLAAE/p76yRuMY0u+pFNon7SJ97ood5DyuzuEJ6ye5vioXOK8iaNZfhjQXPN862R/sd2NLhPOYNXTnSJN/Kr52DaqBNy7bohcWcyu3O/3eMRiMU74ozuSAL+AD23DxQ/DmAE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DIjya98v; 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="DIjya98v" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5640FC4CEDD; Thu, 27 Mar 2025 20:55:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108936; bh=wRb65iHgs3gw2lvD+qtC5MU5+7GuZzV78UYKyZwK4oM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DIjya98vF3cjhYtjFLRdDFLNMI0mqMXKGbdY+sLlra/0mYema/qh82bXww7qPXChG X9VhghQ4z+UhGK++/01ch33Naez9CxNWItMLX+49YYzKw+w62wLQXDbyQw1nZyUzL+ o4ZCLIVot07Ft4ZtZGJDSUN55yvnkjyvw9KsydRYKex0O/ACWZ/QLhJHd1nGa6tS7g 27TcCfMO6JBdrWwyskNB7pJQ7iVnaF4tNHMIb9YbchpsHEEWYg9xrmCcTLL1glerNR 0eZmdvH4TI8wSeU6gffZsCwT/MudijgPy2mQFM30gguHYRXo/Zz8DxuiOSrv/KBh7r uwzrVfypC1n5Q== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 40/41] x86/alternatives: Rename 'text_poke_sync()' to 'text_poke_sync_each_cpu()' Date: Thu, 27 Mar 2025 21:53:53 +0100 Message-ID: <20250327205355.378659-41-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 611957617278..ff30aa1d0c47 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 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 1b523496a2f6..32d3707d7963 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 text_poke_sync_each_cpu(void) { on_each_cpu(do_sync_core, NULL, 1); } @@ -2469,8 +2469,8 @@ struct text_poke_int3_loc { #define TP_ARRAY_NR_ENTRIES_MAX (PAGE_SIZE / sizeof(struct text_poke_int3_= loc)) =20 static struct text_poke_int3_array { - int nr_entries; struct text_poke_int3_loc vec[TP_ARRAY_NR_ENTRIES_MAX]; + int nr_entries; } tp_array; =20 static DEFINE_PER_CPU(atomic_t, tp_array_refs); @@ -2649,7 +2649,7 @@ static void text_poke_int3_batch_process(void) text_poke(text_poke_int3_addr(&tp_array.vec[i]), &int3, INT3_INSN_SIZE); } =20 - text_poke_sync(); + text_poke_sync_each_cpu(); =20 /* * Second step: update all but the first byte of the patched range. @@ -2711,7 +2711,7 @@ static void text_poke_int3_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(); + text_poke_sync_each_cpu(); } =20 /* @@ -2732,13 +2732,13 @@ static void text_poke_int3_batch_process(void) } =20 if (do_sync) - text_poke_sync(); + 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 + * 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..5e35c95524dc 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(); + 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(); + 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 54bc5e7c6886..5efa7b50bbb3 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(); + text_poke_sync_each_cpu(); text_poke(addr + INT3_INSN_SIZE, new + INT3_INSN_SIZE, JMP32_INSN_SIZE - INT3_INSN_SIZE); - text_poke_sync(); + 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..1c598c90e24d 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(); + text_poke_sync_each_cpu(); mutex_unlock(&text_mutex); } =20 --=20 2.45.2 From nobody Wed Dec 17 08:44:59 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 3084020126B for ; Thu, 27 Mar 2025 20:55:38 +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=1743108939; cv=none; b=oUiavxm6XV/ufWswySdoSmnjbMuNu/ow0kjtM2Guzz4sWHEfZehgSMyZrQFGn22a2IJuSHGAyTNAAFK7omU5TzxBjJPXZOOyQ8tQaxen5+xJZwZjGDAmBmNVLdD2tW9G7XhYe3x6Y8/mU/sHrwiBPCThmw0AIFb88f/2uF/D9bk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1743108939; c=relaxed/simple; bh=0GUOSXJuYhO7n4hvtyZ3fk4YLaL5zvqwT4xfK0SfvHQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mqIsHTJWUamH9dKKRxxXFRqGZI3qf/ONdfOKPC33cFJxD2Y5TryPD8NDXxcbNSWK+Hxh96N3rijJ8vWKktBaXmUIAmqhhzoQvN/tUeJutfYHOHWNtkz65hlfgx9ax4EtYOk+Ys8D88NU5hgzWStV7c8tguSDfKMYWtS3xpLVqmE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bAvncNBN; 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="bAvncNBN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B1BB4C4CEE8; Thu, 27 Mar 2025 20:55:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1743108938; bh=0GUOSXJuYhO7n4hvtyZ3fk4YLaL5zvqwT4xfK0SfvHQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bAvncNBNq9VwnE/UJI1luNP2nXXgizMWNhpdLIVc4zZ0q8APYe0kZmyn3emw+Dfnv TpdIr+p4+VQeANCHMcROHBjf5xhurmqnOFtJu4XDM7Ma9bTpnPPzwUq0Og5KxDLemG sXuvsE07PyhIGh8IEwL1oEyqn8eLEywsvCMWrT85nkcspw0fYPufIQVdEnZEZyLIdz 1Lj2E5aQ2ApI6nNV9i5+WmESzNc1b3H0wSRTPXAPBO05woWs1Chk6VtXNJnCwVrH4+ VffwsA+4EKrccE/YFovrlPGuCWD7V9yWN8wdvXd38uX17+ddb3QVAjrfMHH6N8/7K9 EmOynwKl54FsA== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner Subject: [PATCH 41/41] x86/alternatives: Simplify tp_addr_ordered() Date: Thu, 27 Mar 2025 21:53:54 +0100 Message-ID: <20250327205355.378659-42-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250327205355.378659-1-mingo@kernel.org> References: <20250327205355.378659-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 32d3707d7963..7367c829a4fb 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2838,8 +2838,6 @@ static void text_poke_int3_loc_add(void *addr, const = void *opcode, size_t len, c */ static bool tp_addr_ordered(void *addr) { - struct text_poke_int3_loc *tp; - WARN_ON_ONCE(!addr); =20 if (!tp_array.nr_entries) @@ -2851,8 +2849,7 @@ static bool tp_addr_ordered(void *addr) * is violated and we must first flush all pending patching * requests: */ - tp =3D &tp_array.vec[tp_array.nr_entries-1]; - if ((unsigned long)text_poke_int3_addr(tp) > (unsigned long)addr) + if (text_poke_int3_addr(tp_array.vec + tp_array.nr_entries-1) > addr) return false; =20 return true; --=20 2.45.2