From nobody Thu Dec 18 17:58:49 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 B351227D795 for ; Fri, 11 Apr 2025 05:41:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350076; cv=none; b=Phg3LZEbkIgGKj7orJWQqNsoeLUuXiKJK/1jubVdZoDlovtb3WWk2BqOQNT2Rp88qu3q/sgDPWP3ypWASaAU3+Lb1QS6IdPPSp523LkAR2XxqAB1KDyP22y7w5bpECtXZecH5qZFgBetLBq0nBKO9qn4IPny2lclEzgYF55HIp8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350076; c=relaxed/simple; bh=NO6FtaESPRYJpWa3pRYGQg6ozRF+SKuxjJZ4vEwmzXs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kN9KF0l9+1/Zc/98HVCQwh8SMhtZt/YSmsYmxo0PvY6EMn1wlBuu3lfaK1YX/LFn0HXLls5w1dJOhT2UYWP818njK/+ZoxE5Y/ahRSIl6G+T/v3W4pnVZO9oAL4kQy5ZlVhPLTAYbF/mk7uZzJhO29YTFlkqHyxtuNOqXKPcPiY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=j+fN8i83; 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="j+fN8i83" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8239AC4CEE5; Fri, 11 Apr 2025 05:41:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350074; bh=NO6FtaESPRYJpWa3pRYGQg6ozRF+SKuxjJZ4vEwmzXs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j+fN8i83+EiBWRYSIjcpxnd01I350XamVr7qFHr6qL+lWYjK+YBgxWdpKJjldmPS9 VLJym9W4TLlxWUHFz7tIwH3pt/tP2HgYpvQ6OtGJ09Nx0zB0ktFdUsaAVgga7WPUrs ZykWoJVP324IZlK9h5WBDo/RgDS/a8XSDXsNIvVDadcIo6iDqduX4Q02QURP/N8yWX QyzJwN/WoJRVhChw5WaJBt1AdaypGRE18zIhJpPM0sPb9RIDDylecNqC6Mlye4GXmO Fa6BoVQp1EuglR1ZLboWkpOWcqbzeu+qPbGNJxGpDvpITCJI86fOtkq0LTJbCKW+m9 nER0eSJlmYprg== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Eric Dumazet , Ingo Molnar , Brian Gerst , Kees Cook , Josh Poimboeuf Subject: [PATCH 01/53] x86/alternatives: Improve code-patching scalability by removing false sharing in poke_int3_handler() Date: Fri, 11 Apr 2025 07:40:13 +0200 Message-ID: <20250411054105.2341982-2-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-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" From: Eric Dumazet eBPF programs can be run 50,000,000 times per second on busy servers. Whenever /proc/sys/kernel/bpf_stats_enabled is turned off, hundreds of calls sites are patched from text_poke_bp_batch() and we see a huge loss of performance due to false sharing on bp_desc.refs lasting up to three seconds. 51.30% server_bin [kernel.kallsyms] [k] poke_int3_handl= er | |--46.45%--poke_int3_handler | exc_int3 | asm_exc_int3 | | | |--24.26%--cls_bpf_classify | | tcf_classify | | __dev_queue_xmit | | ip6_finish_output2 | | ip6_output | | ip6_xmit | | inet6_csk_xmit | | __tcp_transmit_skb Fix this by replacing bp_desc.refs with a per-cpu bp_refs. Before the patch, on a host with 240 cores (480 threads): $ sysctl -wq kernel.bpf_stats_enabled=3D0 text_poke_bp_batch(nr_entries=3D164) : Took 2655300 usec $ bpftool prog | grep run_time_ns ... 105: sched_cls name hn_egress tag 699fc5eea64144e3 gpl run_time_ns 3009063719 run_cnt 82757845 : average cost is 36 nsec per call After this patch: $ sysctl -wq kernel.bpf_stats_enabled=3D0 text_poke_bp_batch(nr_entries=3D164) : Took 702 usec $ bpftool prog | grep run_time_ns ... 105: sched_cls name hn_egress tag 699fc5eea64144e3 gpl run_time_ns 1928223019 run_cnt 67682728 : average cost is 28 nsec per call Ie. text-patching performance improved 3700x: from 2.65 seconds to 0.0007 seconds. Since the atomic_cond_read_acquire(refs, !VAL) spin-loop was not triggered even once in my tests, add an unlikely() annotation, because this appears to be the common case. [ mingo: Improved the changelog some more. ] Signed-off-by: Eric Dumazet Signed-off-by: Ingo Molnar Cc: Brian Gerst Cc: Juergen Gross Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Kees Cook Cc: Peter Zijlstra Cc: Josh Poimboeuf Link: https://lore.kernel.org/r/20250325043316.874518-1-edumazet@google.com --- arch/x86/kernel/alternative.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index bf82c6f7d690..85089c79a828 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2474,28 +2474,29 @@ struct text_poke_loc { struct bp_patching_desc { struct text_poke_loc *vec; int nr_entries; - atomic_t refs; }; =20 +static DEFINE_PER_CPU(atomic_t, bp_refs); + static struct bp_patching_desc bp_desc; =20 static __always_inline struct bp_patching_desc *try_get_desc(void) { - struct bp_patching_desc *desc =3D &bp_desc; + atomic_t *refs =3D this_cpu_ptr(&bp_refs); =20 - if (!raw_atomic_inc_not_zero(&desc->refs)) + if (!raw_atomic_inc_not_zero(refs)) return NULL; =20 - return desc; + return &bp_desc; } =20 static __always_inline void put_desc(void) { - struct bp_patching_desc *desc =3D &bp_desc; + atomic_t *refs =3D this_cpu_ptr(&bp_refs); =20 smp_mb__before_atomic(); - raw_atomic_dec(&desc->refs); + raw_atomic_dec(refs); } =20 static __always_inline void *text_poke_addr(struct text_poke_loc *tp) @@ -2528,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_desc.refs =3D 1 INT3 - * WMB RMB - * write INT3 if (bp_desc.refs !=3D 0) + * bp_refs =3D 1 INT3 + * WMB RMB + * write INT3 if (bp_refs !=3D 0) */ smp_rmb(); =20 @@ -2636,7 +2637,8 @@ static void text_poke_bp_batch(struct text_poke_loc *= tp, unsigned int nr_entries * Corresponds to the implicit memory barrier in try_get_desc() to * ensure reading a non-zero refcount provides up to date bp_desc data. */ - atomic_set_release(&bp_desc.refs, 1); + for_each_possible_cpu(i) + atomic_set_release(per_cpu_ptr(&bp_refs, i), 1); =20 /* * Function tracing can enable thousands of places that need to be @@ -2750,8 +2752,12 @@ static void text_poke_bp_batch(struct text_poke_loc = *tp, unsigned int nr_entries /* * Remove and wait for refs to be zero. */ - if (!atomic_dec_and_test(&bp_desc.refs)) - atomic_cond_read_acquire(&bp_desc.refs, !VAL); + for_each_possible_cpu(i) { + atomic_t *refs =3D per_cpu_ptr(&bp_refs, i); + + if (unlikely(!atomic_dec_and_test(refs))) + atomic_cond_read_acquire(refs, !VAL); + } } =20 static void text_poke_loc_init(struct text_poke_loc *tp, void *addr, --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 AB25427D79A for ; Fri, 11 Apr 2025 05:41: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=1744350077; cv=none; b=LP590Nyf1wIiKVAb9j9BXOuu/OZrgroFbAPNyAEil8mreg+2LalbcOJms0Q4bIgkB7z2YVGtI4OPJ+YB4AoVC/2RMZDeVUU6Rn27rs58jvAm3DswLKyJEYtxvikNdruB7jPf/xnbO1XvwTmWth1BsY4miZA834s7WBLowlewWFw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350077; c=relaxed/simple; bh=TFQXCq5fVPI5M6GJFklYGsXNadUsa2uuwbcNO4LhjnQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bFy+gJFakm7b0x7PSJUW/6HktwUf4BOCZ3mSA0lhpWBwMhcfnDXST6mtyzCIkWQItfa/DtnYYWoHlOmCBReX36646X+Zuej3CAATqLULd5TbvQDqfmxw/2961JBH1v3GXLLG9BxbrMYs3S5IGH033ov+zOXMnzfNWy11Xy02i8Y= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XMcngRIZ; 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="XMcngRIZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A78D1C4CEE9; Fri, 11 Apr 2025 05:41:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350077; bh=TFQXCq5fVPI5M6GJFklYGsXNadUsa2uuwbcNO4LhjnQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XMcngRIZheKT8ZpDDAPgU2+FA137q4aaqI/et48IBc6Eo59SBb4cBJVCGuWWxVTh8 E+pQORhwwar05uMtGbToONotmFUJjo3yP64nxWikLLwuvavoLAHh5tvGiyx3CoFSyt GPyA5fTr15yJP8aAc8XkAbwgJhBmRiKsAz/atL6HrwhESeS/jHt/k2Nr2NuC47vlFp ayVyNsEN1h1g/+SeNZ1WpTg9nQ7/l3tJdq/Ox+1zcfG0TNZlgE242E6wFHq+EeQ0s3 GsLXb7LM9NOVv8+agonviliSzi9cvmIBy26G4G3FKhd7USvxtfzihXqRO1xC3tSAUq Oq1JSWxOEz8kw== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar , Eric Dumazet , Brian Gerst , Josh Poimboeuf Subject: [PATCH 02/53] x86/alternatives: Document the text_poke_bp_batch() synchronization rules a bit more Date: Fri, 11 Apr 2025 07:40:14 +0200 Message-ID: <20250411054105.2341982-3-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-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" From: Peter Zijlstra Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Ingo Molnar Cc: Eric Dumazet Cc: Brian Gerst Cc: Juergen Gross Cc: H. Peter Anvin Cc: Linus Torvalds Cc: Josh Poimboeuf Link: https://lore.kernel.org/r/20250325103047.GH36322@noisy.programming.ki= cks-ass.net --- arch/x86/kernel/alternative.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 85089c79a828..5f448142aa99 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2751,6 +2751,13 @@ static void text_poke_bp_batch(struct text_poke_loc = *tp, unsigned int nr_entries =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 + * handlers and the below spin-wait will not happen. + * + * IOW. unless the replacement instruction is INT3, this case goes + * unused. */ for_each_possible_cpu(i) { atomic_t *refs =3D per_cpu_ptr(&bp_refs, i); --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 33B8C27D77E for ; Fri, 11 Apr 2025 05:41: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=1744350081; cv=none; b=VxzIMz4whHO7s1JmTSHjR6PHVvKEicdj0UhhnLBOqDLiUfatMh2xXOQSazAoAl+YErNlHEqbVTKVOPmjrmJtYZWehxrMIgdwGlV/34wBbPdmouANxID/21S+Ba7Ko6iAK4vFiVfgefxrfSipAOAGN+a4TwcBOn5/pfhWhP2L85c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350081; c=relaxed/simple; bh=rtowR0p5yc0zPA1Vl4ObrVmbHwWZEHknYKLd4kjcKNk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ioBGlUlnYeShDtdaiYyyBtMMEG+WPL5grh5S4a3p0uREz7DupOPNs4eFFrclRU9GuYgIJO0frHQQ6NgHBf557DJWcFx05tB3xPp85fw5UfJEibcIol8IPOatNACNfRinx71E9VUm6yd6EVUz94DB9/XXktXqKLssiv7nppvHlSA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IY5+qAAY; 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="IY5+qAAY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A55AAC4CEE5; Fri, 11 Apr 2025 05:41:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350079; bh=rtowR0p5yc0zPA1Vl4ObrVmbHwWZEHknYKLd4kjcKNk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IY5+qAAYDcVMHLMqg+70X2eDnPR9P52FZkiOxRnnSB1p1xSoj6rh2SSmXhx39fI26 lr1DNg0aX9v8dwlDkcr74M+WfnWI4f/fOhr5QtbfO1jbiG+fwgUq3q7nvsvklAh3YW xk3PBHm0wvjYoVwO9Md879dUtS5dNClV7fh6rYY5SWUDBlmn0pBHnA15P5HFmY+HTK De6K7vXJZo5I0HV+Fz8U50PDr9+MAOWLDDtR/5BySQ7OaAkyog7vztlh6x/qTPODE+ G/MVqwCpovgzZKRQA9MxWMEK8kmFCXCpH+SkGxjgTxH06oNvqWvl6OteOsocuKAkkO /HZZGDcR0Rdmw== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 03/53] x86/alternatives: Rename 'struct bp_patching_desc' to 'struct int3_patching_desc' Date: Fri, 11 Apr 2025 07:40:15 +0200 Message-ID: <20250411054105.2341982-4-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-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 Thu Dec 18 17:58:49 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 3972927EC68 for ; Fri, 11 Apr 2025 05:41: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=1744350082; cv=none; b=Oh8xWnjo9gvOlrHWygNrUqZndhmTTxRynvjg+JrWBAQW8yeKzcYqOSXIG99BQoJdvyWstrr6376tzd/EGoKsJAQl206cYxgmwjHT0THrQ8miL/IvdifAR6oQEQlph+cvdJBkrqyAKv3nj1RXfGSR5tnqtAVZzDoJf6NkaLSFUlQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350082; c=relaxed/simple; bh=eH4uwFqoC9JgVc1kv7VNnXR333bL5REyM/EgEQ04P/4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dxowmoPdyMlahnQc3VotVPnuZgVnVfm3yLphSfCD9tgv1bvZ4cYCik2wRUGP7gqT4OsfpgeO7gWPePzm6bhdtcP+nqe/E9KVYEQWQ5F2h0KlaW1SrLXnDMYyq6Vix2ED/6yZCTO6UCEX9qoYYhYB3CTnl5ctT+J1qLY5D6hEcQA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=LgX7uXqX; 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="LgX7uXqX" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0F4EEC4CEE9; Fri, 11 Apr 2025 05:41:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350082; bh=eH4uwFqoC9JgVc1kv7VNnXR333bL5REyM/EgEQ04P/4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LgX7uXqXRTOj42RdPRWlSHsGJndFDWvhf5eHkyfnleGF32ZsbgCOuV7tVu1Q0x0OE jBr4w6IUPFgFW2DinSCoYHQWX8dVCIfXLiX4mE24arUv7MwPDPhAH0wchKTV4QnXgH GFxK5uJMYjlqqtYcxA7HSqqI3A8eNI2ZRgqtxVmQaea4hYiABbpEDTjWfJbGXQ4sG5 s9GCYHPjaJHKRh0ZdSCvHRXodEhWrN8dv1eHh5Ch9EhmnlRQiyWDCBspB/B6/iwknq iW4EzC9Sd7X0+4rallopGqzAcK8mtRsKYvB+piZSiSxc9w2AWIxOdS9twuA+BC2et2 4qpaifQETAGSA== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 04/53] x86/alternatives: Rename 'bp_refs' to 'int3_refs' Date: Fri, 11 Apr 2025 07:40:16 +0200 Message-ID: <20250411054105.2341982-5-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-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 Thu Dec 18 17:58:49 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 7720927EC92 for ; Fri, 11 Apr 2025 05:41: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=1744350084; cv=none; b=tMAH5nCfdHhhP4WxJMYG9ry5nbMfKE/D5uPfmONJ85t9AVGSZhcu1N4a2GN1J5YX04Jdup0V3gfkUUNUheHS3zcKrnaHXzyD3mFV9OwG6onOTJT63kS1T3SFPlFPP+PSt4BGsIfx5dE7RcXFxr3R9xFZmaJ+DN/SgKNcjRr5IA4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350084; c=relaxed/simple; bh=7JfDcVoLgx2cHFr+F4A6UUUHRHLY28KYtLPQwaCZdD8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Kf9iXoEgj5l/rahUNR1eSGZ1vQxVo6ZyJjdzqYfKWZi6bNT2sY/okGmQZ1O0CC8VoDgfJX0tPK+DiRU+nbwxkB0yCURkG4EEr1Rqiuaseyr28XaA/3AhDqkNyqvZvcP2u4M/V6bqOtTeXtQPavZaNF4E4zrzQSyycSlzankhyVg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RQPCmPB7; 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="RQPCmPB7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6E27DC4CEE2; Fri, 11 Apr 2025 05:41:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350084; bh=7JfDcVoLgx2cHFr+F4A6UUUHRHLY28KYtLPQwaCZdD8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RQPCmPB7rxVqSiJYRCW264eCfrS/DwYfnoe5iMhi1pO8FXjVA7EBtYIDQhmEPyPOF v4/K+C15AAqnK2VHr+yA5TXHCfPAu3nEp98DK04ZxeLFGVWJjW3uKSvgEx9n3uNB60 sYU5qvCHWDhdK6lGkoVN0BWXn3QJJDc1vDztmrMI7fTcPdn1UK+Ze11emHw1M7/QoW khJmK2wDkx4WUPC11sI+rhvY5baiYkH2bU0qxjq/a+Lfv3a09SO1TdVZPuApSgGZQJ 10aIPMRTjRX+7r/hnqIfmCvUHrIXaEn3aiTmd3f4AxLT7dvQG73R5nJ0jxKx8R2DMI BU4+PmxBwrpaQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 05/53] x86/alternatives: Rename 'text_poke_bp_batch()' to 'smp_text_poke_batch_process()' Date: Fri, 11 Apr 2025 07:40:17 +0200 Message-ID: <20250411054105.2341982-6-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-1-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index cb9ac69694fb..7305c29bc8d1 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2467,7 +2467,7 @@ struct text_poke_loc { u8 len; u8 opcode; const u8 text[POKE_MAX_OPCODE_SIZE]; - /* see text_poke_bp_batch() */ + /* see smp_text_poke_batch_process() */ u8 old; }; =20 @@ -2540,7 +2540,7 @@ noinstr int poke_int3_handler(struct pt_regs *regs) return 0; =20 /* - * Discount the INT3. See text_poke_bp_batch(). + * Discount the INT3. See smp_text_poke_batch_process(). */ ip =3D (void *) regs->ip - INT3_INSN_SIZE; =20 @@ -2602,7 +2602,7 @@ static struct text_poke_loc tp_vec[TP_VEC_MAX]; static int tp_vec_nr; =20 /** - * text_poke_bp_batch() -- update instructions on live kernel on SMP + * smp_text_poke_batch_process() -- update instructions on live kernel on = SMP * @tp: vector of instructions to patch * @nr_entries: number of entries in the vector * @@ -2622,7 +2622,7 @@ static int tp_vec_nr; * replacing opcode * - sync cores */ -static void text_poke_bp_batch(struct text_poke_loc *tp, unsigned int nr_e= ntries) +static void smp_text_poke_batch_process(struct text_poke_loc *tp, unsigned= int nr_entries) { unsigned char int3 =3D INT3_INSN_OPCODE; unsigned int i; @@ -2866,7 +2866,7 @@ static bool tp_order_fail(void *addr) static void text_poke_flush(void *addr) { if (tp_vec_nr =3D=3D TP_VEC_MAX || tp_order_fail(addr)) { - text_poke_bp_batch(tp_vec, tp_vec_nr); + smp_text_poke_batch_process(tp_vec, tp_vec_nr); tp_vec_nr =3D 0; } } @@ -2902,5 +2902,5 @@ void __ref text_poke_bp(void *addr, const void *opcod= e, size_t len, const void * struct text_poke_loc tp; =20 text_poke_loc_init(&tp, addr, opcode, len, emulate); - text_poke_bp_batch(&tp, 1); + smp_text_poke_batch_process(&tp, 1); } --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 4834527F4D9 for ; Fri, 11 Apr 2025 05:41: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=1744350087; cv=none; b=CTI+LnH4P2oyIP/LMyAWV7qpBFuKL61LlaBTwBvSyDRetfpTd/zG9jRDb4CdnkA7cfFn13mTLGN96Nj4TnWIqsByp7uVTlUoqz8Kaa3cANjyO8rZhP9Xx1yzwfFq0cF8Pfdj7IxlPcrvEhyoFgATJQxlXqDXyBZiWQYOeZWLPaQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350087; c=relaxed/simple; bh=YDcAh8AaLBdt4MGFuGymYgJLwzdIfOqrt+w0YdFhNSQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=VBBP699AJNRyCiQCwbT3gfysj3TabrFMq/Y6oauIZ495C5DduoFeBUzY0nwLWpTCs71ZFOCf8v5Axlc8krr+jrrPbfWnnKf7NZ0oqLWDtAmNfaDoD/3Q5A+F8RcCUQGDfBcSaJX/Ag8pEMHY1cRs7X8ivqPlqWfi3eHsBjyeQaY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZmxkPiK7; 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="ZmxkPiK7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD5CEC4CEE5; Fri, 11 Apr 2025 05:41:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350086; bh=YDcAh8AaLBdt4MGFuGymYgJLwzdIfOqrt+w0YdFhNSQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZmxkPiK7nVIy70ZelS9By4ehK8FRMbJ+qBkjPTd4LPskNnd3glqB+GDjqtGUCb41W Tjqy35tBblgiwRk1oFTlvCHiG7FH/iBeRWB3IfnP194N4Fw8mzq/hnpskH5RA4mu99 5bDR+kHRkuaXvC3vZsEF/lM0o/9/bYl8+qkaVhBmF+1G8b4YwjOj+n5Shdy6iEU/gp nArwJ+otd9IvOMXgLPjcpFG7IUXDvgLpvxcKvHLrHHDRq2+nvJA6uo/hbXekFWDEU9 XV5choc5/4kqCgghwIJnZxyIRMcwUkjuAQJs+oFx9O4Px6oSkSaGGVJ665CuaRYpyF +tLy00vGAkj7g== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 06/53] x86/alternatives: Rename 'text_poke_bp()' to 'smp_text_poke_single()' Date: Fri, 11 Apr 2025 07:40:18 +0200 Message-ID: <20250411054105.2341982-7-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-1-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Signed-off-by: Ingo Molnar --- arch/x86/include/asm/text-patching.h | 2 +- arch/x86/kernel/alternative.c | 4 ++-- arch/x86/kernel/ftrace.c | 8 ++++---- arch/x86/kernel/jump_label.c | 2 +- arch/x86/kernel/kprobes/opt.c | 2 +- arch/x86/kernel/static_call.c | 2 +- arch/x86/net/bpf_jit_comp.c | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/arch/x86/include/asm/text-patching.h b/arch/x86/include/asm/te= xt-patching.h index ab9e143ec9fe..5189188b5e49 100644 --- a/arch/x86/include/asm/text-patching.h +++ b/arch/x86/include/asm/text-patching.h @@ -39,7 +39,7 @@ extern void *text_poke_copy(void *addr, const void *opcod= e, size_t len); extern void *text_poke_copy_locked(void *addr, const void *opcode, size_t = len, bool core_ok); extern void *text_poke_set(void *addr, int c, size_t len); extern int poke_int3_handler(struct pt_regs *regs); -extern void text_poke_bp(void *addr, const void *opcode, size_t len, const= void *emulate); +extern void smp_text_poke_single(void *addr, const void *opcode, size_t le= n, const void *emulate); =20 extern void text_poke_queue(void *addr, const void *opcode, size_t len, co= nst void *emulate); extern void text_poke_finish(void); diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 7305c29bc8d1..826c389b22eb 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2887,7 +2887,7 @@ void __ref text_poke_queue(void *addr, const void *op= code, size_t len, const voi } =20 /** - * text_poke_bp() -- update instructions on live kernel on SMP + * smp_text_poke_single() -- update instructions on live kernel on SMP * @addr: address to patch * @opcode: opcode of new instruction * @len: length to copy @@ -2897,7 +2897,7 @@ void __ref text_poke_queue(void *addr, const void *op= code, size_t len, const voi * dynamically allocated memory. This function should be used when it is * not possible to allocate memory. */ -void __ref text_poke_bp(void *addr, const void *opcode, size_t len, const = void *emulate) +void __ref smp_text_poke_single(void *addr, const void *opcode, size_t len= , const void *emulate) { struct text_poke_loc tp; =20 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c index cace6e8d7cc7..7175a0404def 100644 --- a/arch/x86/kernel/ftrace.c +++ b/arch/x86/kernel/ftrace.c @@ -186,11 +186,11 @@ int ftrace_update_ftrace_func(ftrace_func_t func) =20 ip =3D (unsigned long)(&ftrace_call); new =3D ftrace_call_replace(ip, (unsigned long)func); - text_poke_bp((void *)ip, new, MCOUNT_INSN_SIZE, NULL); + smp_text_poke_single((void *)ip, new, MCOUNT_INSN_SIZE, NULL); =20 ip =3D (unsigned long)(&ftrace_regs_call); new =3D ftrace_call_replace(ip, (unsigned long)func); - text_poke_bp((void *)ip, new, MCOUNT_INSN_SIZE, NULL); + smp_text_poke_single((void *)ip, new, MCOUNT_INSN_SIZE, NULL); =20 return 0; } @@ -492,7 +492,7 @@ void arch_ftrace_update_trampoline(struct ftrace_ops *o= ps) mutex_lock(&text_mutex); /* Do a safe modify in case the trampoline is executing */ new =3D ftrace_call_replace(ip, (unsigned long)func); - text_poke_bp((void *)ip, new, MCOUNT_INSN_SIZE, NULL); + smp_text_poke_single((void *)ip, new, MCOUNT_INSN_SIZE, NULL); mutex_unlock(&text_mutex); } =20 @@ -586,7 +586,7 @@ static int ftrace_mod_jmp(unsigned long ip, void *func) const char *new; =20 new =3D ftrace_jmp_replace(ip, (unsigned long)func); - text_poke_bp((void *)ip, new, MCOUNT_INSN_SIZE, NULL); + smp_text_poke_single((void *)ip, new, MCOUNT_INSN_SIZE, NULL); return 0; } =20 diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c index f5b8ef02d172..166e12037199 100644 --- a/arch/x86/kernel/jump_label.c +++ b/arch/x86/kernel/jump_label.c @@ -102,7 +102,7 @@ __jump_label_transform(struct jump_entry *entry, return; } =20 - text_poke_bp((void *)jump_entry_code(entry), jlp.code, jlp.size, NULL); + smp_text_poke_single((void *)jump_entry_code(entry), jlp.code, jlp.size, = NULL); } =20 static void __ref jump_label_transform(struct jump_entry *entry, diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c index 36d6809c6c9e..9307a40f4983 100644 --- a/arch/x86/kernel/kprobes/opt.c +++ b/arch/x86/kernel/kprobes/opt.c @@ -488,7 +488,7 @@ void arch_optimize_kprobes(struct list_head *oplist) insn_buff[0] =3D JMP32_INSN_OPCODE; *(s32 *)(&insn_buff[1]) =3D rel; =20 - text_poke_bp(op->kp.addr, insn_buff, JMP32_INSN_SIZE, NULL); + smp_text_poke_single(op->kp.addr, insn_buff, JMP32_INSN_SIZE, NULL); =20 list_del_init(&op->list); } diff --git a/arch/x86/kernel/static_call.c b/arch/x86/kernel/static_call.c index a59c72e77645..8164a7323c17 100644 --- a/arch/x86/kernel/static_call.c +++ b/arch/x86/kernel/static_call.c @@ -108,7 +108,7 @@ static void __ref __static_call_transform(void *insn, e= num insn_type type, if (system_state =3D=3D SYSTEM_BOOTING || modinit) return text_poke_early(insn, code, size); =20 - text_poke_bp(insn, code, size, emulate); + smp_text_poke_single(insn, code, size, emulate); } =20 static void __static_call_validate(u8 *insn, bool tail, bool tramp) diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c index 9e5fe2ba858f..e2b9991c3326 100644 --- a/arch/x86/net/bpf_jit_comp.c +++ b/arch/x86/net/bpf_jit_comp.c @@ -629,7 +629,7 @@ static int __bpf_arch_text_poke(void *ip, enum bpf_text= _poke_type t, goto out; ret =3D 1; if (memcmp(ip, new_insn, X86_PATCH_SIZE)) { - text_poke_bp(ip, new_insn, X86_PATCH_SIZE, NULL); + smp_text_poke_single(ip, new_insn, X86_PATCH_SIZE, NULL); ret =3D 0; } out: --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 3CB5627F4D5 for ; Fri, 11 Apr 2025 05:41: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=1744350089; cv=none; b=NI35HSw4z80KGnV2AatPU4Mh51qQs7a81HE0Foci2QAKFC+eGOXtJUAqIdmaDg/NJIxkV9AkAaYIwfuRfzzPHSvrOzxGGpskvb6nj3Qz8nhiqdHQojzhm4zkzYMzoidV6zBvZmLynrgKsqzSJD6Agjc0f4VFIVw2u9oP09myPDg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350089; c=relaxed/simple; bh=yGn827/rRWfL186zZgfsLQuLGVHOWwaC+FBYsTpnot0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aoT24nASFAuHu8cJQ64ooOrZtPLxLUmVz0YtbdZfLe7OMZlxJReK1HK67uh6PF79wU7DsDqOaBaH0TrHUTprf7aj1Tp2PrETU9BQQdc09ggQh5pcD/jujKB/xubd+pVoWNuZ+oYnmxWrqLrXpDRSgz/U+o8mdTdY6rKxhvK3eD4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=O90H+I/2; 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="O90H+I/2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32B29C4CEEB; Fri, 11 Apr 2025 05:41:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350089; bh=yGn827/rRWfL186zZgfsLQuLGVHOWwaC+FBYsTpnot0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O90H+I/2h0hLqsdCO8Ngb65mNFtNg8eMxw4d+Qkm9K/qnYT659hBc1MPNk/zLtV8/ xS74lUUg2J6ryOeWBGG9r/dUofHP3yRCCIv5FE9KslpIpEI53xJX2gq1LI8Wb15pDC SvOPClLyoedEgfWl8yPEAd+uIBwlaLxBqJbyxO3jLtPe6AHamMamL2kqKX/Iurik2j 5/d3eNnoZwYCLfgyn8B6mBiTOI9BuLUis2BtPVeu/2ji+OxE99YRw1XDk6iuGJ21L6 kxe5aiWE2CMgxQqMwbwYB+N1wqEdtjC0B88ASQ7BTsZ2LLkoS/dv0FzMbn2lWYiHxI m1a6rTqsgoaew== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 07/53] x86/alternatives: Rename 'poke_int3_handler()' to 'smp_text_poke_int3_handler()' Date: Fri, 11 Apr 2025 07:40:19 +0200 Message-ID: <20250411054105.2341982-8-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-1-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" All related functions in this subsystem already have a text_poke_int3_ prefix - add it to the trap handler as well. Signed-off-by: Ingo Molnar --- arch/x86/include/asm/text-patching.h | 2 +- arch/x86/kernel/alternative.c | 2 +- arch/x86/kernel/traps.c | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/text-patching.h b/arch/x86/include/asm/te= xt-patching.h index 5189188b5e49..93a6b7bc78bd 100644 --- a/arch/x86/include/asm/text-patching.h +++ b/arch/x86/include/asm/text-patching.h @@ -38,7 +38,7 @@ extern void *text_poke_copy(void *addr, const void *opcod= e, size_t len); #define text_poke_copy text_poke_copy extern void *text_poke_copy_locked(void *addr, const void *opcode, size_t = len, bool core_ok); extern void *text_poke_set(void *addr, int c, size_t len); -extern int poke_int3_handler(struct pt_regs *regs); +extern int smp_text_poke_int3_handler(struct pt_regs *regs); extern void smp_text_poke_single(void *addr, const void *opcode, size_t le= n, const void *emulate); =20 extern void text_poke_queue(void *addr, const void *opcode, size_t len, co= nst void *emulate); diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 826c389b22eb..44269d8bf492 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2515,7 +2515,7 @@ static __always_inline int patch_cmp(const void *key,= const void *elt) return 0; } =20 -noinstr int poke_int3_handler(struct pt_regs *regs) +noinstr int smp_text_poke_int3_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..d67407c623f3 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -882,16 +882,16 @@ static void do_int3_user(struct pt_regs *regs) DEFINE_IDTENTRY_RAW(exc_int3) { /* - * poke_int3_handler() is completely self contained code; it does (and + * smp_text_poke_int3_handler() is completely self contained code; it doe= s (and * must) *NOT* call out to anything, lest it hits upon yet another * INT3. */ - if (poke_int3_handler(regs)) + if (smp_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 smp_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 Thu Dec 18 17:58:49 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 09206280A2A for ; Fri, 11 Apr 2025 05:41: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=1744350092; cv=none; b=FMb5nYwjQzxcg7HZcX9gUjXwxJGfnPyCF/ke5B7xEu9nFNa9MuoknM5wYJGfhWyDd0sFvAMV4qhMCi0xnDsZXZYKPQmu0+gaZiVJSnPvInr+1hCnRvrxnTztC5zKtNGOGi+SvA2gMpL5ZPsE0FunmyrZqFhgyQtNcaCGddSuCJY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350092; c=relaxed/simple; bh=+3TFSMmZfapb3avr4NuLCplNFnlG3WK2pBGYdCTARa8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bZ9Cj17zasnLay9uqTKfihp5GEp6wjs0gprOpnytF7mGP1IIvKMdJxQ48Pglyzt7RApGr/6CqZ878sruthu+IFhQNV5aXMsdE5CzRgrT8CK+LBgzt0VTP4gl4CT7uBNj2K+o88/yP71tAqEAamv13BckwsBLxp95um92Eg1UxeE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=r/KVge6B; 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="r/KVge6B" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8F063C4CEE2; Fri, 11 Apr 2025 05:41:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350091; bh=+3TFSMmZfapb3avr4NuLCplNFnlG3WK2pBGYdCTARa8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r/KVge6BI1kxznqQMm+jRv27d6bqlc6NPtGw6Nkna2rtRCN6sh6pMJwp2VX26bBNM OoxnhF5QYzBvdPMYNplM+syfCKpcVgFJLlaUalISK7TKp1gsRcvabP6TNyeIPKiLB4 IsUpdPIKCsqQzL/yMQR6cqKdreujY9Ps1j1spSs9+InvHr3TEcmfUPCZT9+lU/VNyz 0BeuxBtzfsKSbSjCqk0G4GJ1Fm3jL/bZdShjQB3NLiXIQpeztbZORtPnq/0MiKn2j+ pciXE8xHnioa+pjdMhBtwf7MxdDuXX9/LlqCzd4ZJhmF294W/d2bEqmGml5ARzEEln EFEjD7KVoLOeA== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 08/53] x86/alternatives: Rename 'poking_mm' to 'text_poke_mm' Date: Fri, 11 Apr 2025 07:40:20 +0200 Message-ID: <20250411054105.2341982-9-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-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 93a6b7bc78bd..7a95c0820b3e 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 44269d8bf492..5afd453e4352 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 Thu Dec 18 17:58:49 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 5C2A4280A42 for ; Fri, 11 Apr 2025 05:41: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=1744350094; cv=none; b=LMbmOcV44lQBpNdEB/UaaP6MgSP32rMuNyrDl3RqGX3nK4MgQNBSdqGc4VXL4kLL6es++QttKZk0vWv3EbUFh3sZleFBlicH3MeN9liEelP+f7hyYOodixmZNsEbhKQv86Hkq5ZJXM+xmADRAHt/MZmwrqQyWPgdp8f5VGgMMpU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350094; c=relaxed/simple; bh=N5+8VWro4dAMeojhXBYAQkgI64QssYs5rPPdSnMjZLA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hsqu46nshw3TkUhmH2liKJUuS8DyaIAvK1G3A7MUDWzF51XzmybPuKau5h64G8LSciQydLhQzhN0IvT9DVXckgDp4Lx8RbMluzWOSEYM1CrSpc+VZrij7Tu2MKhpB58jSnq+OPzufZXnCHYUcbioPbyT62Ro7CoWJenvaK8QTcc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EQU66mGY; 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="EQU66mGY" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EDC34C4CEE5; Fri, 11 Apr 2025 05:41:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350093; bh=N5+8VWro4dAMeojhXBYAQkgI64QssYs5rPPdSnMjZLA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EQU66mGYZX3PRpdBzmh49S/xOqF47126gDvyS2gr1GOECjtNqP1tQg8LpkmjyfQsl cgY1DhDLMsIRh3UYRS688JhNzAwX+IpZ/HnO63IQyrAT6jSquZBzL5yFUarAvIY4bd JKiJNlZab5a9I+2Abu3JoMmRnzWVSihntYWNEwmsMMxy9yecldhEaIyui/qhnWoUKK iymq/vzb9tXrQ/a5uGV1VJn78mzZQXMlqmUSIM+Blojw8JAR5XeXlc8aSKtEVxHQvj bqyGr6pR9QtcC913gY1TrcxRxZM/qWnelXyRyvXSiGhmIEIHAzoHJALUZK8FCN0GFN lUBR9O1POdEUQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 09/53] x86/alternatives: Rename 'poking_addr' to 'text_poke_mm_addr' Date: Fri, 11 Apr 2025 07:40:21 +0200 Message-ID: <20250411054105.2341982-10-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-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 7a95c0820b3e..c8eac8cf4737 100644 --- a/arch/x86/include/asm/text-patching.h +++ b/arch/x86/include/asm/text-patching.h @@ -129,7 +129,7 @@ void *text_gen_insn(u8 opcode, const void *addr, const = void *dest) =20 extern int after_bootmem; extern __ro_after_init struct mm_struct *text_poke_mm; -extern __ro_after_init unsigned long poking_addr; +extern __ro_after_init unsigned long text_poke_mm_addr; =20 #ifndef CONFIG_UML_X86 static __always_inline diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 5afd453e4352..a64032b2f6ca 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2192,7 +2192,7 @@ static inline temp_mm_state_t use_temporary_mm(struct= mm_struct *mm) } =20 __ro_after_init struct mm_struct *text_poke_mm; -__ro_after_init unsigned long poking_addr; +__ro_after_init unsigned long text_poke_mm_addr; =20 static inline void unuse_temporary_mm(temp_mm_state_t prev_state) { @@ -2266,7 +2266,7 @@ static void *__text_poke(text_poke_f func, void *addr= , const void *src, size_t l /* * The lock is not really needed, but this allows to avoid open-coding. */ - ptep =3D get_locked_pte(text_poke_mm, poking_addr, &ptl); + ptep =3D get_locked_pte(text_poke_mm, text_poke_mm_addr, &ptl); =20 /* * This must not fail; preallocated in poking_init(). @@ -2276,11 +2276,11 @@ static void *__text_poke(text_poke_f func, void *ad= dr, const void *src, size_t l local_irq_save(flags); =20 pte =3D mk_pte(pages[0], pgprot); - set_pte_at(text_poke_mm, poking_addr, ptep, pte); + set_pte_at(text_poke_mm, text_poke_mm_addr, ptep, pte); =20 if (cross_page_boundary) { pte =3D mk_pte(pages[1], pgprot); - set_pte_at(text_poke_mm, poking_addr + PAGE_SIZE, ptep + 1, pte); + set_pte_at(text_poke_mm, text_poke_mm_addr + PAGE_SIZE, ptep + 1, pte); } =20 /* @@ -2290,7 +2290,7 @@ static void *__text_poke(text_poke_f func, void *addr= , const void *src, size_t l prev =3D use_temporary_mm(text_poke_mm); =20 kasan_disable_current(); - func((u8 *)poking_addr + offset_in_page(addr), src, len); + func((u8 *)text_poke_mm_addr + offset_in_page(addr), src, len); kasan_enable_current(); =20 /* @@ -2299,9 +2299,9 @@ static void *__text_poke(text_poke_f func, void *addr= , const void *src, size_t l */ barrier(); =20 - pte_clear(text_poke_mm, poking_addr, ptep); + pte_clear(text_poke_mm, text_poke_mm_addr, ptep); if (cross_page_boundary) - pte_clear(text_poke_mm, poking_addr + PAGE_SIZE, ptep + 1); + pte_clear(text_poke_mm, text_poke_mm_addr + PAGE_SIZE, ptep + 1); =20 /* * Loading the previous page-table hierarchy requires a serializing @@ -2314,7 +2314,7 @@ static void *__text_poke(text_poke_f func, void *addr= , const void *src, size_t l * Flushing the TLB might involve IPIs, which would require enabled * IRQs, but not if the mm is not used, as it is in this point. */ - flush_tlb_mm_range(text_poke_mm, poking_addr, poking_addr + + flush_tlb_mm_range(text_poke_mm, text_poke_mm_addr, text_poke_mm_addr + (cross_page_boundary ? 2 : 1) * PAGE_SIZE, PAGE_SHIFT, false); =20 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c index 84b52a1ebd48..f8c74d19bebb 100644 --- a/arch/x86/mm/init.c +++ b/arch/x86/mm/init.c @@ -835,20 +835,20 @@ void __init poking_init(void) * will be mapped at the same PMD. We need 2 pages, so find space for 3, * and adjust the address if the PMD ends after the first one. */ - poking_addr =3D TASK_UNMAPPED_BASE; + text_poke_mm_addr =3D TASK_UNMAPPED_BASE; if (IS_ENABLED(CONFIG_RANDOMIZE_BASE)) - poking_addr +=3D (kaslr_get_random_long("Poking") & PAGE_MASK) % + text_poke_mm_addr +=3D (kaslr_get_random_long("Poking") & PAGE_MASK) % (TASK_SIZE - TASK_UNMAPPED_BASE - 3 * PAGE_SIZE); =20 - if (((poking_addr + PAGE_SIZE) & ~PMD_MASK) =3D=3D 0) - poking_addr +=3D PAGE_SIZE; + if (((text_poke_mm_addr + PAGE_SIZE) & ~PMD_MASK) =3D=3D 0) + text_poke_mm_addr +=3D PAGE_SIZE; =20 /* * We need to trigger the allocation of the page-tables that will be * needed for poking now. Later, poking may be performed in an atomic * section, which might cause allocation to fail. */ - ptep =3D get_locked_pte(text_poke_mm, poking_addr, &ptl); + ptep =3D get_locked_pte(text_poke_mm, text_poke_mm_addr, &ptl); BUG_ON(!ptep); pte_unmap_unlock(ptep, ptl); } --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 6F322280A5B for ; Fri, 11 Apr 2025 05:41: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=1744350096; cv=none; b=W2BoIqKrRXCjWfNjwTuxvopqWYikQUIRmjuWftEiNIrcDoixpp3lji+UESFRzUuDBNBmr7lp971T5cFVAd/AVaO5Ah2PluNZGSAYnDGxkjx/6jihy1/MI7VYfqbSVJPupJbJCMBx9ajdfoV7u3iIdtOB9s9GwPl3oNTYZ8zJpEs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350096; c=relaxed/simple; bh=JkKUXZl8EWtFBzsfYNb9gWa0//YHq6hszNipmvkltlQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bCdmsFFUzcp+FWy7YqOFp8i4T71vDFk75cdbpVbAfCKph29BSSP+lL58VvCapmtrwVQxv7NWmFFWDBjj89m97bDPG+7qbV4Uhh3EbaQK9rqS0XVAT4QWSmj66Ep1R3mukLSotVJlr9XTMrQBgmJa8IFsDH+pfFfdPC4ELDrgRH0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ElGo1URe; 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="ElGo1URe" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5942DC4CEE2; Fri, 11 Apr 2025 05:41:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350096; bh=JkKUXZl8EWtFBzsfYNb9gWa0//YHq6hszNipmvkltlQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ElGo1UReYbRtumBcRdYn5aIPKGBg5k4OhRB6zu9WqiixDUl0sN9kKE+ny9FvOk2Ai GNxzD8Pz12dcqP2RpI4RxIy4WnLbHWZ1gCl7kXdK7ABFx2BiTAY/Fpf5o7Rgxx7oqr zw9b1y23M5+PSgp+BlhSQReMV01JATspTbksplh3/xzJn5gU7f9zXPbKabop2/VdO3 UNZQ01s+RzzFk9iUDypB1ddNsOfS6N+5CMr+eWQVgGwb5mREWczH+H/CruOV2h5H+c mFtGEuf+JrN42oDMeMtFDUuLOBF2DTYt1pZXlv7yWLM3AMLG/ZWQVZGBnLHqBGcflV c36aLRSz071Wg== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 10/53] x86/alternatives: Rename 'bp_desc' to 'int3_desc' Date: Fri, 11 Apr 2025 07:40:22 +0200 Message-ID: <20250411054105.2341982-11-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-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 a64032b2f6ca..2a630d1931ea 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2478,7 +2478,7 @@ struct int3_patching_desc { =20 static DEFINE_PER_CPU(atomic_t, int3_refs); =20 -static struct int3_patching_desc bp_desc; +static struct int3_patching_desc int3_desc; =20 static __always_inline struct int3_patching_desc *try_get_desc(void) @@ -2488,7 +2488,7 @@ struct int3_patching_desc *try_get_desc(void) if (!raw_atomic_inc_not_zero(refs)) return NULL; =20 - return &bp_desc; + return &int3_desc; } =20 static __always_inline void put_desc(void) @@ -2527,7 +2527,7 @@ noinstr int smp_text_poke_int3_handler(struct pt_regs= *regs) =20 /* * Having observed our INT3 instruction, we now must observe - * bp_desc with non-zero refcount: + * int3_desc with non-zero refcount: * * int3_refs =3D 1 INT3 * WMB RMB @@ -2630,12 +2630,12 @@ static void smp_text_poke_batch_process(struct text= _poke_loc *tp, unsigned int n =20 lockdep_assert_held(&text_mutex); =20 - bp_desc.vec =3D tp; - bp_desc.nr_entries =3D nr_entries; + int3_desc.vec =3D tp; + int3_desc.nr_entries =3D nr_entries; =20 /* * Corresponds to the implicit memory barrier in try_get_desc() to - * ensure reading a non-zero refcount provides up to date bp_desc data. + * ensure reading a non-zero refcount provides up to date int3_desc data. */ for_each_possible_cpu(i) atomic_set_release(per_cpu_ptr(&int3_refs, i), 1); --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 51A69280CE8 for ; Fri, 11 Apr 2025 05:41: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=1744350099; cv=none; b=YfRdj2E1hRDikIzkkSLs1UNPWnB3NskQzeEoxv9YVoQhuyQLBd06qsHNTfDb5Ro94bFTtb05xUGNNhb8RDWXNbcNyNvWAtgVX2ARrp/graO6KMlkvuQvo/znDYIAUJQvG5TTTJGkgEadHkmtzlZwQD1i/81fOk/O0NoCJVtCFPM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350099; c=relaxed/simple; bh=3mQOlLDjRBuCITwE6LPt/v5yxBFYbFUjrysRyHnj2gg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jzGysFpr1HyBjW6OO+18PEU/SDr45d7pJ6m1o0AK7SuTL7L5hOf6RtxTRtU2wLNuxjsg8ZnpOxPZN6uG384Mgo/yeQ7Nx4p/CfxBQ8e6FgR/OnJOI5bhvb0OrLo+x67M4cPGT2u2l2agudyONpVaraU9pAKwtXCJ3yK3/MxEvaI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=o1t0IbEt; 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="o1t0IbEt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B857EC4CEE5; Fri, 11 Apr 2025 05:41:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350098; bh=3mQOlLDjRBuCITwE6LPt/v5yxBFYbFUjrysRyHnj2gg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o1t0IbEttU4MHkZrCF8O0LJC3rx+ZptZA2U1Heo5r+4irGDw1t1vys9zY1UWRok3y 50PaMf1+TvUqjFsXfQ1W8i9wClBEkRKPBRvTkkhS8M+z+JFDYPoHZ0hSVHJ8OuarE+ ghhDZg3vamZIZ7eOwslLNzx88IfmPADw+ZKpVPUXBhGJgzBRfs5uUEt9DciwFEDvh5 cSwfEU2EcF3VkwBS6cj/XIdYwkoMMCNrxKw9OODjv33If9MT8W1+qs6pL8FyLTsB2W 7v0YpNtR4ZuPMcHcrDvwfxM9bOljRwiQCSVzrm5uBT+bFcRknHkpQ4ff4wJKGp9lb3 CuDtqKMFAu9+w== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 11/53] x86/alternatives: Remove duplicate 'text_poke_early()' prototype Date: Fri, 11 Apr 2025 07:40:23 +0200 Message-ID: <20250411054105.2341982-12-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-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 2a630d1931ea..dff53eb8c6dd 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 Thu Dec 18 17:58:49 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 3D107280CF9 for ; Fri, 11 Apr 2025 05:41: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=1744350101; cv=none; b=I2M9CeZuo0/0hpmRTJtQkjewe7sKa/H7rMR2mt4vP/UsOt70THFH6+G+uvE9hC1vf0KGT0peMy0zZjef3eoUY7DX0Qfne5MCEYEG91W0ySFOEjfNzTdLz4QiVFJXvOU9zhS2SKbzbzVk7HZ3qAjDZFafYwJxmgmA+XK8SfvXH9E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350101; c=relaxed/simple; bh=vUDBtPg+Mh3+eH/O9J1+/SzTJ1auFi1dBubNFPEun/k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C8QaWMWEm9MzMlW8DeAnDhT7JIqYJQVGjrOQEuEZg6tlQBbJ1BoVtE9H6su7HFEeK0NbA++AtldJ+v6QmZAxlt3TpEOPg9HIjs2e11hObbMInQdxh3kodCgJPgOhpo+SNuFhRsKcwaXtfVtNtPnTosw8KqJzexRka2e3TA3kneo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dj6+N2Yu; 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="dj6+N2Yu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2CE98C4CEE2; Fri, 11 Apr 2025 05:41:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350101; bh=vUDBtPg+Mh3+eH/O9J1+/SzTJ1auFi1dBubNFPEun/k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dj6+N2YuXyexDlgZtHIGregTb0OZ46WJ8escvBVgHZ5Q+CWcGWhILs2Rr0NVtY9Z/ BwNaWa0DWVkseb/NmlxQcQD2i/Duj6GIrHrkNunyuHLZUrCykynyc/LoWFedinblnY /FQuMjVe+p+57EdYcXMdRNb1SNT8ceo82ULY/hCbramDVBsTR3TQ7mvSMPqfdk2U9X wWT0gk3z0bBs38eZaitLQHA8qFA7iFF18MHIyuamd5J3X8jsvr9bu3atJTZtxc6/Tc h8OVWqPS/dV0oUxkyo8JgB81ssMA5EVwLI9iC6XjXJjWwp1FFZDiTHFT5vCV1tsHrp WOfv1MXqEhNuA== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 12/53] x86/alternatives: Update comments in int3_emulate_push() Date: Fri, 11 Apr 2025 07:40:24 +0200 Message-ID: <20250411054105.2341982-13-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-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 c8eac8cf4737..7e3527385708 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 Thu Dec 18 17:58:49 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 0412827CCF0 for ; Fri, 11 Apr 2025 05:41: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=1744350105; cv=none; b=ZyFl6sRjASu/PjojQX4gbAR2z1vYdlUcCgA6pnOjy8t9X7pQLld0Ap6n6eRO0C/JWwQgusMJmyjcEtOPzO6PF7sl33MZHdRmGrDwRG5ErKqHrUaGk5vOuDESYfJJBATyq050AjO6Lf6pjUjJgkL6j/dHtMRCiJUuq4HaSa4GmUk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350105; c=relaxed/simple; bh=seQnTfEoDsNmRjvcjJwSDRfCR8enSmCW4nymlK5IEiQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C4FE9Oz4TeeOp6bbQyyJEoGDNqZjElaYVZF3JqYF4tZJeOqv4DUUqlJH5oNLADnwCPKofE3eXFcUMexQvOwItD9SczWR7KrGUQGTgMux1R+QAyDoqAqRM/JoslNsqV6G8EgYoHnjavd7g2RRk1MrMtGb63RHUIh+PC3cx/pUS4I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=S8dfkSAM; 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="S8dfkSAM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87033C4CEE2; Fri, 11 Apr 2025 05:41:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350103; bh=seQnTfEoDsNmRjvcjJwSDRfCR8enSmCW4nymlK5IEiQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=S8dfkSAM+inOA6EWWMkr8Z4Aw2yPNxOEnzzHl0WSxnmpyMB9kZryzw25V6s4SHNfj 4JIeG99pMEAVT8a0vh/srtmP4ExvsEQH/OSvMOW61Lj+cvDkeHFkAiAR0lDembwShk 1IFR5uln91V4FvCG3wcuTbjbr+IEck7TLCKtJNxl4y+wYq5ZYqhA9Sho4X0d9gCJXG rjS8dTnJv3iGBP1MeRsx46JVHeGfiW3eL9MtCDWMqYl1FLCCaHMCA9Kf6xO1rGzLVi yOdjPt1wMM5faMAan8pp/6RDRQDvzMqsRJSTJAjvFFOeq940wVXBWNmBFoBsinKy1u ZylOErAuisc4Q== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 13/53] x86/alternatives: Remove the confusing, inaccurate & unnecessary 'temp_mm_state_t' abstraction Date: Fri, 11 Apr 2025 07:40:25 +0200 Message-ID: <20250411054105.2341982-14-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-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 dff53eb8c6dd..f3a04dfd0c37 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2139,10 +2139,6 @@ void __init_or_module text_poke_early(void *addr, co= nst void *opcode, } } =20 -typedef struct { - struct mm_struct *mm; -} temp_mm_state_t; - /* * Using a temporary mm allows to set temporary mappings that are not acce= ssible * by other CPUs. Such mappings are needed to perform sensitive memory wri= tes @@ -2156,9 +2152,9 @@ typedef struct { * loaded, thereby preventing interrupt handler bugs from overrid= ing * the kernel memory protection. */ -static inline temp_mm_state_t use_temporary_mm(struct mm_struct *mm) +static inline struct mm_struct *use_temporary_mm(struct mm_struct *temp_mm) { - temp_mm_state_t temp_state; + struct mm_struct *prev_mm; =20 lockdep_assert_irqs_disabled(); =20 @@ -2170,8 +2166,8 @@ static inline temp_mm_state_t use_temporary_mm(struct= mm_struct *mm) if (this_cpu_read(cpu_tlbstate_shared.is_lazy)) leave_mm(); =20 - temp_state.mm =3D this_cpu_read(cpu_tlbstate.loaded_mm); - switch_mm_irqs_off(NULL, mm, current); + prev_mm =3D this_cpu_read(cpu_tlbstate.loaded_mm); + switch_mm_irqs_off(NULL, temp_mm, current); =20 /* * If breakpoints are enabled, disable them while the temporary mm is @@ -2187,17 +2183,17 @@ static inline temp_mm_state_t use_temporary_mm(stru= ct mm_struct *mm) if (hw_breakpoint_active()) hw_breakpoint_disable(); =20 - return temp_state; + return prev_mm; } =20 __ro_after_init struct mm_struct *text_poke_mm; __ro_after_init unsigned long text_poke_mm_addr; =20 -static inline void unuse_temporary_mm(temp_mm_state_t prev_state) +static inline void unuse_temporary_mm(struct mm_struct *prev_mm) { lockdep_assert_irqs_disabled(); =20 - switch_mm_irqs_off(NULL, prev_state.mm, current); + switch_mm_irqs_off(NULL, prev_mm, current); =20 /* Clear the cpumask, to indicate no TLB flushing is needed anywhere */ cpumask_clear_cpu(raw_smp_processor_id(), mm_cpumask(text_poke_mm)); @@ -2228,7 +2224,7 @@ static void *__text_poke(text_poke_f func, void *addr= , const void *src, size_t l { bool cross_page_boundary =3D offset_in_page(addr) + len > PAGE_SIZE; struct page *pages[2] =3D {NULL}; - temp_mm_state_t prev; + struct mm_struct *prev_mm; unsigned long flags; pte_t pte, *ptep; spinlock_t *ptl; @@ -2286,7 +2282,7 @@ static void *__text_poke(text_poke_f func, void *addr= , const void *src, size_t l * Loading the temporary mm behaves as a compiler barrier, which * guarantees that the PTE will be set at the time memcpy() is done. */ - prev =3D use_temporary_mm(text_poke_mm); + prev_mm =3D use_temporary_mm(text_poke_mm); =20 kasan_disable_current(); func((u8 *)text_poke_mm_addr + offset_in_page(addr), src, len); @@ -2307,7 +2303,7 @@ static void *__text_poke(text_poke_f func, void *addr= , const void *src, size_t l * instruction that already allows the core to see the updated version. * Xen-PV is assumed to serialize execution in a similar manner. */ - unuse_temporary_mm(prev); + unuse_temporary_mm(prev_mm); =20 /* * Flushing the TLB might involve IPIs, which would require enabled --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 EA8F928152F for ; Fri, 11 Apr 2025 05:41:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350106; cv=none; b=Mo4PCD1Fee4bA03J5oghqKiz2dS8DWpDh9Gyf0ccm3U6ymRDIqUss5kXQp4kgCkHRkVOIs14T1GSYNukOtGt5SXU9H6V65+Cz5sZq6w1PZetXrC3L799reiGUFbA1JB+n0whevPPGp3ae0uhq0y887ucGE+RBbNUYDRTyM92a+s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350106; c=relaxed/simple; bh=Cg7s/jcyanOL3XRhNAy/hzbc+zENA4MFu8XemHbp8/4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s/tfx8C1puo7nNqMuOt14aG6Io4Z0azH4A/R71oWcuVvfsct40rQaAIJcqToh10tT78VlYcrh+iaJYrKrIgORkUq7WX6t8r5h4sy574uwK/Zxbrkx7aDPOUYi1d0Q8VI3RSx5h4pd8QLmGx5P1/NOsulg+aGyT6u/q1bJhA+idw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=oZ3x5irb; 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="oZ3x5irb" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E1A38C4CEE5; Fri, 11 Apr 2025 05:41:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350105; bh=Cg7s/jcyanOL3XRhNAy/hzbc+zENA4MFu8XemHbp8/4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=oZ3x5irbwyowc4ZtE59wkI8vXhrh7mZYQFgHtMU/hangVhACPHqbEQqoWikgNzQc9 A+lPJIvUMAG1z+gc1XNq0vvrjaAbtDEzn7q2Ixa6tyNUyvqbJAw9EQBnLnQjiRhHLD XwxL3tsHEVCdRv6We1hQuq7broVgkvvFbYKGMa4mPA5lB3B2lqWij7qTRjBoGrKcLO IGdTw2mleyAlyOKu0i2LYlzcvfWNJSsgFmVYOIr/eh3cXIwX+LF3/M2QQrhj2fKo1J MU7O8Br20lRAmT+hacIjv6EtzPCCYDrQg5kW1k7frqqKAc+29yKnjG3+eyVTS7nuzM XaQbrT7TEbkig== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 14/53] x86/alternatives: Rename 'text_poke_flush()' to 'smp_text_poke_batch_flush()' Date: Fri, 11 Apr 2025 07:40:26 +0200 Message-ID: <20250411054105.2341982-15-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-1-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This name is actually actively confusing, because the simple text_poke*() APIs use MM-switching based code patching, while text_poke_flush() is part of the INT3 based text_poke_int3_*() machinery that is an additional layer of functionality on top of regular text_poke*() functional= ity. Rename it to smp_text_poke_batch_flush() to make it clear which layer it belongs to. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index f3a04dfd0c37..35a89ead153c 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2858,7 +2858,7 @@ static bool tp_order_fail(void *addr) return false; } =20 -static void text_poke_flush(void *addr) +static void smp_text_poke_batch_flush(void *addr) { if (tp_vec_nr =3D=3D TP_VEC_MAX || tp_order_fail(addr)) { smp_text_poke_batch_process(tp_vec, tp_vec_nr); @@ -2868,14 +2868,14 @@ static void text_poke_flush(void *addr) =20 void text_poke_finish(void) { - text_poke_flush(NULL); + smp_text_poke_batch_flush(NULL); } =20 void __ref text_poke_queue(void *addr, const void *opcode, size_t len, con= st void *emulate) { struct text_poke_loc *tp; =20 - text_poke_flush(addr); + smp_text_poke_batch_flush(addr); =20 tp =3D &tp_vec[tp_vec_nr++]; text_poke_loc_init(tp, addr, opcode, len, emulate); --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 606FA281536 for ; Fri, 11 Apr 2025 05:41: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=1744350108; cv=none; b=svd3JUHcdNiCJg+Fd3WpvFPQau7dLoYCd+/Wjys+koWlYA909EL2sRGmIrBODrny2KeXK7sXZSUWEz5d5wswuNk9LpmG+zOZ6pMkizTvs8mX4iCVw/yWfVfEzD9ePgMfROn2xfKUmcsVr/Tn3YB6x7bd6CjbdocN65bIFCpowTo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350108; c=relaxed/simple; bh=CtYdubQzU/wKiIbjdpR3sYf3OATSeMckXnWIpeQyi98=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZQnH+SWkJPxoZjm2mZe/zbYmBFaUeNaDhj4Gv7adud1u21sUKfqBUwafaurM9zaGhXQu8aME3kuovX+QVxDjFOUABtfqKgvQeX8JMKrwICMzuRaJBLPi0eJaRreF9Unm1phHS7p6/KtzU1iYa5uTA7MAFi9sGKy0b+xjA3Mzwog= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pn5fSagN; 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="pn5fSagN" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BA98C4CEE2; Fri, 11 Apr 2025 05:41:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350108; bh=CtYdubQzU/wKiIbjdpR3sYf3OATSeMckXnWIpeQyi98=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pn5fSagN2qxOTTGne15Py8nlssPv548QtIhOGcrqnDzrLGmDriSVHd8GHzwZkRvLC LrVSkVbbMePDBUoAN25ABoHzFOV6UOKLHJ9rrUpadqKbVpiRnhi2hqO0LNY4+UzM1I BtXNezeqyLxNnd63xgATVnaJz+zjgGDHALVtxdLPoZHfKXg0+qK4sDL7oBrAx96oZI j0sX3mKw7ReJzK/++JcnZJ8IPbDNcvaJLxoo9QqrgXk8xhK+AO8iRp1+deE4wBEgpA tHlJcAyl9ErJFTXAeRBvJIq+aFoOVD96GHMtbxfuWYrkmsEmEZ6Tpg7wDzF219jHzD aY6N/j+D82uXQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 15/53] x86/alternatives: Rename 'text_poke_finish()' to 'smp_text_poke_batch_finish()' Date: Fri, 11 Apr 2025 07:40:27 +0200 Message-ID: <20250411054105.2341982-16-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-1-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This name is actively confusing as well, because the simple text_poke*() APIs use MM-switching based code patching, while text_poke_finish() is part of the INT3 based text_poke_int3_*() machinery that is an additional layer of functionality on top of regular text_poke*() functional= ity. Rename it to smp_text_poke_batch_finish() to make it clear which layer it belongs to. Signed-off-by: Ingo Molnar --- arch/x86/include/asm/text-patching.h | 2 +- arch/x86/kernel/alternative.c | 2 +- arch/x86/kernel/ftrace.c | 4 ++-- arch/x86/kernel/jump_label.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/text-patching.h b/arch/x86/include/asm/te= xt-patching.h index 7e3527385708..f27d29042f8c 100644 --- a/arch/x86/include/asm/text-patching.h +++ b/arch/x86/include/asm/text-patching.h @@ -42,7 +42,7 @@ extern int smp_text_poke_int3_handler(struct pt_regs *reg= s); extern void smp_text_poke_single(void *addr, const void *opcode, size_t le= n, const void *emulate); =20 extern void text_poke_queue(void *addr, const void *opcode, size_t len, co= nst void *emulate); -extern void text_poke_finish(void); +extern void smp_text_poke_batch_finish(void); =20 #define INT3_INSN_SIZE 1 #define INT3_INSN_OPCODE 0xCC diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 35a89ead153c..63561e81bfaf 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2866,7 +2866,7 @@ static void smp_text_poke_batch_flush(void *addr) } } =20 -void text_poke_finish(void) +void smp_text_poke_batch_finish(void) { smp_text_poke_batch_flush(NULL); } diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c index 7175a0404def..c35a928364b9 100644 --- a/arch/x86/kernel/ftrace.c +++ b/arch/x86/kernel/ftrace.c @@ -58,7 +58,7 @@ void ftrace_arch_code_modify_post_process(void) * module load, and we need to finish the text_poke_queue() * that they do, here. */ - text_poke_finish(); + smp_text_poke_batch_finish(); ftrace_poke_late =3D 0; mutex_unlock(&text_mutex); } @@ -250,7 +250,7 @@ void ftrace_replace_code(int enable) text_poke_queue((void *)rec->ip, new, MCOUNT_INSN_SIZE, NULL); ftrace_update_record(rec, enable); } - text_poke_finish(); + smp_text_poke_batch_finish(); } =20 void arch_ftrace_update_code(int command) diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c index 166e12037199..28be6eb6cb3d 100644 --- a/arch/x86/kernel/jump_label.c +++ b/arch/x86/kernel/jump_label.c @@ -143,6 +143,6 @@ bool arch_jump_label_transform_queue(struct jump_entry = *entry, void arch_jump_label_transform_apply(void) { mutex_lock(&text_mutex); - text_poke_finish(); + smp_text_poke_batch_finish(); mutex_unlock(&text_mutex); } --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 2307D2853FD for ; Fri, 11 Apr 2025 05:41: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=1744350111; cv=none; b=pZPwtjUN9vw/YzPeOPjmsDv6gvIFMQNA5itCa8W6OOYYH3InIiywGb6d/UKMnZxdyDNwDQuT+jqbZ9IjRP52SUnEqL4REMV83wfoV9Shzw9kgcufzrG5BwRG5ArGcGwMDhgM4Cipznu91/fdZPQ6ZeDLOiF5Mk1CYLUH2ct8HT4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350111; c=relaxed/simple; bh=CBCUwNluC97sqq7ctdVuJJUBnC49P33NBLd+/VXkG/4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c+n648v1AhGSYrl7TjcNPLwEBETFbCyyh//A7LE+dkdU2zQaHUzVGQzDAV2f/Trmo69xvt97X8Du+yHtK62ZvemQ799TQsxRx3x/qZWadbwUc4bI8xKMeApok4sp0rb6213bZbKyZmX30xE1nIODkHCph3HRFqYbl1vrLVa596k= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=gcMv30QH; 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="gcMv30QH" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB70DC4CEE2; Fri, 11 Apr 2025 05:41:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350110; bh=CBCUwNluC97sqq7ctdVuJJUBnC49P33NBLd+/VXkG/4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gcMv30QHt6FZ5HeU1jXziG3TVyVtgLR+1Trdyb9fL0qD2zD+hLol/0Ev9fktjcCNG wBjTf/dZHNvNGQc5Xji5nIt3bv5ISPkxJAByDgDnGw7eIZ0O5FJAvIsH+L36aMp/H9 RrqaCF+6so5NXmMaPlcnt1Tf82xK9xNkXBQIyGvNirz39OPiw76G0nKHvSDcfEXmdE iBgqVzKyvj1lmeqsgBnshZVY1JiVLYAeawtys4UADLJiaMA9MR0Cacplp4IQNno4aM YpCDMWZo7bTZPaqi7+wmtWnHl2mc+vM050SuF6GwtErO1hCYX10iS7/aIDhrCFKBkw t199mF4nuEgaA== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 16/53] x86/alternatives: Rename 'text_poke_queue()' to 'smp_text_poke_batch_add()' Date: Fri, 11 Apr 2025 07:40:28 +0200 Message-ID: <20250411054105.2341982-17-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-1-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This name is actively confusing as well, because the simple text_poke*() APIs use MM-switching based code patching, while text_poke_queue() is part of the INT3 based text_poke_int3_*() machinery that is an additional layer of functionality on top of regular text_poke*() functional= ity. Rename it to smp_text_poke_batch_add() to make it clear which layer it belongs to. Signed-off-by: Ingo Molnar --- arch/x86/include/asm/text-patching.h | 2 +- arch/x86/kernel/alternative.c | 2 +- arch/x86/kernel/ftrace.c | 6 +++--- arch/x86/kernel/jump_label.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/text-patching.h b/arch/x86/include/asm/te= xt-patching.h index f27d29042f8c..f3c9b70afb0c 100644 --- a/arch/x86/include/asm/text-patching.h +++ b/arch/x86/include/asm/text-patching.h @@ -41,7 +41,7 @@ extern void *text_poke_set(void *addr, int c, size_t len); extern int smp_text_poke_int3_handler(struct pt_regs *regs); extern void smp_text_poke_single(void *addr, const void *opcode, size_t le= n, const void *emulate); =20 -extern void text_poke_queue(void *addr, const void *opcode, size_t len, co= nst void *emulate); +extern void smp_text_poke_batch_add(void *addr, const void *opcode, size_t= len, const void *emulate); extern void smp_text_poke_batch_finish(void); =20 #define INT3_INSN_SIZE 1 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 63561e81bfaf..1c8316e8b7f1 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2871,7 +2871,7 @@ void smp_text_poke_batch_finish(void) smp_text_poke_batch_flush(NULL); } =20 -void __ref text_poke_queue(void *addr, const void *opcode, size_t len, con= st void *emulate) +void __ref smp_text_poke_batch_add(void *addr, const void *opcode, size_t = len, const void *emulate) { struct text_poke_loc *tp; =20 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c index c35a928364b9..0853ba3fd04a 100644 --- a/arch/x86/kernel/ftrace.c +++ b/arch/x86/kernel/ftrace.c @@ -55,7 +55,7 @@ void ftrace_arch_code_modify_post_process(void) { /* * ftrace_make_{call,nop}() may be called during - * module load, and we need to finish the text_poke_queue() + * module load, and we need to finish the smp_text_poke_batch_add() * that they do, here. */ smp_text_poke_batch_finish(); @@ -119,7 +119,7 @@ ftrace_modify_code_direct(unsigned long ip, const char = *old_code, =20 /* replace the text with the new text */ if (ftrace_poke_late) - text_poke_queue((void *)ip, new_code, MCOUNT_INSN_SIZE, NULL); + smp_text_poke_batch_add((void *)ip, new_code, MCOUNT_INSN_SIZE, NULL); else text_poke_early((void *)ip, new_code, MCOUNT_INSN_SIZE); return 0; @@ -247,7 +247,7 @@ void ftrace_replace_code(int enable) break; } =20 - text_poke_queue((void *)rec->ip, new, MCOUNT_INSN_SIZE, NULL); + smp_text_poke_batch_add((void *)rec->ip, new, MCOUNT_INSN_SIZE, NULL); ftrace_update_record(rec, enable); } smp_text_poke_batch_finish(); diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c index 28be6eb6cb3d..a7949a54a0ff 100644 --- a/arch/x86/kernel/jump_label.c +++ b/arch/x86/kernel/jump_label.c @@ -135,7 +135,7 @@ bool arch_jump_label_transform_queue(struct jump_entry = *entry, =20 mutex_lock(&text_mutex); jlp =3D __jump_label_patch(entry, type); - text_poke_queue((void *)jump_entry_code(entry), jlp.code, jlp.size, NULL); + smp_text_poke_batch_add((void *)jump_entry_code(entry), jlp.code, jlp.siz= e, NULL); mutex_unlock(&text_mutex); return true; } --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 1AF8628A3FF for ; Fri, 11 Apr 2025 05:41: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=1744350113; cv=none; b=lpGr4LjdOQayMl49huKGEhP521U/hi3mJwrVSb8iF13dJ6Q7HbeqzGrA9ldIErc3Lhs2hXpN5kqKlxOxWqmG6RdNj6556Z94BAHtlVlT2btttUWhBXGEYtGjGCqB2tjWAR+caKNPYRlH7mMlrHFWmRy+VowFFqegXbNad39mHCc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350113; c=relaxed/simple; bh=Ydt1QgZ0OJMPUJMz1VBZGyYSU8ydyyPAyASBpNkUvfg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NRqvgilcsARfeGuufsZES0u6w2Sde7iRlDu+tbUW2ldjIw+RFFejRc6+E8dcO9HpaI4WH87bjBRd5DRies9ZyBAbsUmGWAilF9l4mgWwTcvLf25zEqBL6AyOW6FTsNlbJiYgZvOMzAya47Y1ZyNUGzDrIGwcPkZ+/Xr7qtRReDc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NWvz111D; 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="NWvz111D" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 14134C4CEEA; Fri, 11 Apr 2025 05:41:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350113; bh=Ydt1QgZ0OJMPUJMz1VBZGyYSU8ydyyPAyASBpNkUvfg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NWvz111DRqFlfLM0C5MEmeWZGZ6IUbcG19lADOh7oHdw7sdNMpIoalLzTbXJxlfLQ WscTcdBEzEiGkjzHhMevzXW8HHYWTCuOjvyJdWL+NBQTyMNiQtmH0tOqcw+GPcYzk/ LeQ6phCNWVSxianbH58tkJ51fBZld8FkdOjRb8rlZrEarBtzlqVHOnW6xUfEek726L 6gQ9QwRbyPIliZToIOS+bJiSJMDDB3KKQ37jgG4In/W1fwLoyh1DduzXr+p1bUP6+U 0YcHGhCu9TyyCvYuek1KuA1RJ9PKAsi+iDazJwD+2ayAo9pT8kwRkXx4G1HHYa8jVR vjDHl6ijfK3qQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 17/53] x86/alternatives: Rename 'text_poke_loc_init()' to 'text_poke_int3_loc_init()' Date: Fri, 11 Apr 2025 07:40:29 +0200 Message-ID: <20250411054105.2341982-18-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-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 1c8316e8b7f1..e909f2859d0d 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2762,7 +2762,7 @@ static void smp_text_poke_batch_process(struct text_p= oke_loc *tp, unsigned int n } } =20 -static void text_poke_loc_init(struct text_poke_loc *tp, void *addr, +static void text_poke_int3_loc_init(struct text_poke_loc *tp, void *addr, const void *opcode, size_t len, const void *emulate) { struct insn insn; @@ -2878,7 +2878,7 @@ void __ref smp_text_poke_batch_add(void *addr, const = void *opcode, size_t len, c smp_text_poke_batch_flush(addr); =20 tp =3D &tp_vec[tp_vec_nr++]; - text_poke_loc_init(tp, addr, opcode, len, emulate); + text_poke_int3_loc_init(tp, addr, opcode, len, emulate); } =20 /** @@ -2896,6 +2896,6 @@ void __ref smp_text_poke_single(void *addr, const voi= d *opcode, size_t len, cons { struct text_poke_loc tp; =20 - text_poke_loc_init(&tp, addr, opcode, len, emulate); + text_poke_int3_loc_init(&tp, addr, opcode, len, emulate); smp_text_poke_batch_process(&tp, 1); } --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 75FFB28EA52 for ; Fri, 11 Apr 2025 05:41: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=1744350115; cv=none; b=CMukezobcLHgVa3AmnlM4xRwXGX1obCTWqAxZexNglIs45RDvaQmlE1aNVAQeHyOS4TPGbx2JzWG7MIZzOH4y+bu8ADwc5253Dr3t5O1r7nqlGjyQvp5KJwVQmrtxBq+cRe/hAD3pOQoemUK1+y7N4fQ1SFlTx/0homWpYxJV3k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350115; c=relaxed/simple; bh=2yK7MrqUmq0bK+hOiG8TcLoKYtO5neIrToE++cf+tug=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ery66Bc8KUv9xBX4DOwwluZalWc9r4eeeiwlCnrtUnekWLtH5bDZntTcqrP/7tKyOdLBRAbTU45xg4TdUe1bNWBObW78Dc7OAaje23YFC4pXLA1T0Gkx1tabfD8DQ+SjILr2kx8jV9TSXxOjeUnbZRAQzC8i0ToEskmjaeUyunQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=dKRANRXt; 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="dKRANRXt" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6F498C4CEE2; Fri, 11 Apr 2025 05:41:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350115; bh=2yK7MrqUmq0bK+hOiG8TcLoKYtO5neIrToE++cf+tug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dKRANRXtNayXHoT5eOBMvPPQaTyckzepgnuZnbSNq/RLHSYY3R7RhJt1soakL4Jmg pU8ioDwWuxuO0st7HpN5elVsnlU+RshUtfSwMJSBUFEUtLeX0cIb9B58YWm9AW36Y6 0/HzZMVwBFbMUmLqlxtDhEJ/UOHo6Bo6iCgBJZ7u8fZbcpnOmO+H7+j4PNH/dWFdeQ ZraghlBDgjOF9gtTEpoC1iJDxPz2tXjd4KBLjIGapadjEYTjJllIBV20+JtGhQbxWt J/qpFU0hN4BYj7g7YF/wUiZRiKs0G9GimJjSHWS6egRKepSQ89F3oxEt5aEhrEQCcQ vvGRbYQ/RV+Sw== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 18/53] x86/alternatives: Rename 'struct text_poke_loc' to 'struct smp_text_poke_loc' Date: Fri, 11 Apr 2025 07:40:30 +0200 Message-ID: <20250411054105.2341982-19-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-1-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Make it clear that this structure is part of the INT3 based SMP patching facility, not the regular text_poke*() MM-switch based facility. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index e909f2859d0d..8bd5842e626e 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2455,7 +2455,7 @@ void text_poke_sync(void) * this thing. When len =3D=3D 6 everything is prefixed with 0x0f and we m= ap * opcode to Jcc.d8, using len to distinguish. */ -struct text_poke_loc { +struct smp_text_poke_loc { /* addr :=3D _stext + rel_addr */ s32 rel_addr; s32 disp; @@ -2467,7 +2467,7 @@ struct text_poke_loc { }; =20 struct int3_patching_desc { - struct text_poke_loc *vec; + struct smp_text_poke_loc *vec; int nr_entries; }; =20 @@ -2494,14 +2494,14 @@ static __always_inline void put_desc(void) raw_atomic_dec(refs); } =20 -static __always_inline void *text_poke_addr(struct text_poke_loc *tp) +static __always_inline void *text_poke_addr(struct smp_text_poke_loc *tp) { return _stext + tp->rel_addr; } =20 static __always_inline int patch_cmp(const void *key, const void *elt) { - struct text_poke_loc *tp =3D (struct text_poke_loc *) elt; + struct smp_text_poke_loc *tp =3D (struct smp_text_poke_loc *) elt; =20 if (key < text_poke_addr(tp)) return -1; @@ -2513,7 +2513,7 @@ static __always_inline int patch_cmp(const void *key,= const void *elt) noinstr int smp_text_poke_int3_handler(struct pt_regs *regs) { struct int3_patching_desc *desc; - struct text_poke_loc *tp; + struct smp_text_poke_loc *tp; int ret =3D 0; void *ip; =20 @@ -2544,7 +2544,7 @@ noinstr int smp_text_poke_int3_handler(struct pt_regs= *regs) */ if (unlikely(desc->nr_entries > 1)) { tp =3D __inline_bsearch(ip, desc->vec, desc->nr_entries, - sizeof(struct text_poke_loc), + sizeof(struct smp_text_poke_loc), patch_cmp); if (!tp) goto out_put; @@ -2592,8 +2592,8 @@ noinstr int smp_text_poke_int3_handler(struct pt_regs= *regs) return ret; } =20 -#define TP_VEC_MAX (PAGE_SIZE / sizeof(struct text_poke_loc)) -static struct text_poke_loc tp_vec[TP_VEC_MAX]; +#define TP_VEC_MAX (PAGE_SIZE / sizeof(struct smp_text_poke_loc)) +static struct smp_text_poke_loc tp_vec[TP_VEC_MAX]; static int tp_vec_nr; =20 /** @@ -2617,7 +2617,7 @@ static int tp_vec_nr; * replacing opcode * - sync cores */ -static void smp_text_poke_batch_process(struct text_poke_loc *tp, unsigned= int nr_entries) +static void smp_text_poke_batch_process(struct smp_text_poke_loc *tp, unsi= gned int nr_entries) { unsigned char int3 =3D INT3_INSN_OPCODE; unsigned int i; @@ -2762,7 +2762,7 @@ static void smp_text_poke_batch_process(struct text_p= oke_loc *tp, unsigned int n } } =20 -static void text_poke_int3_loc_init(struct text_poke_loc *tp, void *addr, +static void text_poke_int3_loc_init(struct smp_text_poke_loc *tp, void *ad= dr, const void *opcode, size_t len, const void *emulate) { struct insn insn; @@ -2843,7 +2843,7 @@ static void text_poke_int3_loc_init(struct text_poke_= loc *tp, void *addr, */ static bool tp_order_fail(void *addr) { - struct text_poke_loc *tp; + struct smp_text_poke_loc *tp; =20 if (!tp_vec_nr) return false; @@ -2873,7 +2873,7 @@ void smp_text_poke_batch_finish(void) =20 void __ref smp_text_poke_batch_add(void *addr, const void *opcode, size_t = len, const void *emulate) { - struct text_poke_loc *tp; + struct smp_text_poke_loc *tp; =20 smp_text_poke_batch_flush(addr); =20 @@ -2894,7 +2894,7 @@ void __ref smp_text_poke_batch_add(void *addr, const = void *opcode, size_t len, c */ void __ref smp_text_poke_single(void *addr, const void *opcode, size_t len= , const void *emulate) { - struct text_poke_loc tp; + struct smp_text_poke_loc tp; =20 text_poke_int3_loc_init(&tp, addr, opcode, len, emulate); smp_text_poke_batch_process(&tp, 1); --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 D2D5928FFFB for ; Fri, 11 Apr 2025 05:41:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350117; cv=none; b=EptTtKhkQG8g2hOIMGnThIrwAEcznkIv3AQDQ2G2eRpKr7wq2jhEcLuE/ZBvTTwgPgI6bZB/cAt/JBPHNtJcAbv9vJ1dZ6INU2GvbBMp1eFjN9wRp0AH9LN6gnQ1fe4kywOKQehfTVSo943hnYhQE29TpsrbYpNMoXg2gru9lBc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350117; c=relaxed/simple; bh=fMWeKBd9lbhMMm3nKgIyEkTL3zQn1EXu1KKQ4Sg/rPQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SWQyXNO0fRVJNLUFa0HIS5Ft1S05OEvKsEHhYgtoufQBnyJ5DOsJ1kWFirUSSGD0NyyvRKIDwP9KAp+lkD26z0oBq/wnmDRTe2J/s1wLASfrjdD4E/hnf44SX1vsAjWduY/JHS6XhL9sRaT/GXmfZ11qL8jsJ6dR7AwDuuXpTL8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Z4bIExAn; 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="Z4bIExAn" Received: by smtp.kernel.org (Postfix) with ESMTPSA id CB775C4CEE2; Fri, 11 Apr 2025 05:41:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350117; bh=fMWeKBd9lbhMMm3nKgIyEkTL3zQn1EXu1KKQ4Sg/rPQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z4bIExAnr1y8yy+ucv83IImHU85/vva+/Y0aCacKWbdAcg3G9hXA/DDAhBRpQuUHv 7iRSIGgI5KTxBD3QNWriZDv0B4wag6jY3mHnFXKi6h4mMMy1nguHpn2f9D2hWW1Tvl 62eWcfBcR1X6qeg3Et8l6oMJC9GihX5DNgMvctcf5CdTiiaf7hkvbHshe2Ykl+FlBw Iz5OSpmosNZ/huimIaLf1BTytkfo4b40249myhH/rF4tnzS/i2N4Ax8DPW97jIRG9d 2uEbkhgUNL55m0ITwZAdhgEqcCVYj1ln0iSttLzdJOTIU7zGArUqzCGZqfVVuZ01Jl Uehn5QiVRrZog== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 19/53] x86/alternatives: Rename 'struct int3_patching_desc' to 'struct text_poke_int3_vec' Date: Fri, 11 Apr 2025 07:40:31 +0200 Message-ID: <20250411054105.2341982-20-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-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 8bd5842e626e..ca4599ef44f3 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2466,17 +2466,17 @@ struct smp_text_poke_loc { u8 old; }; =20 -struct int3_patching_desc { +struct text_poke_int3_vec { struct smp_text_poke_loc *vec; int nr_entries; }; =20 static DEFINE_PER_CPU(atomic_t, int3_refs); =20 -static struct int3_patching_desc int3_desc; +static struct text_poke_int3_vec int3_desc; =20 static __always_inline -struct int3_patching_desc *try_get_desc(void) +struct text_poke_int3_vec *try_get_desc(void) { atomic_t *refs =3D this_cpu_ptr(&int3_refs); =20 @@ -2512,7 +2512,7 @@ static __always_inline int patch_cmp(const void *key,= const void *elt) =20 noinstr int smp_text_poke_int3_handler(struct pt_regs *regs) { - struct int3_patching_desc *desc; + struct text_poke_int3_vec *desc; struct smp_text_poke_loc *tp; int ret =3D 0; void *ip; --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 3934C27D797 for ; Fri, 11 Apr 2025 05:42: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=1744350120; cv=none; b=px41ePt1bWO5UrJOO9o2zezn4t6xsKbQlkeT60Z7wK3f85T8w95oavIP6b79/MSfPCY+bQpaLTK6hCBX8k7JvUrhj55HS5q9k4fGez/Oqyeum4oHGGOf2EJof/hpFEKEFgd/fk16yCbf4sDpNjnXPTf3iSbqszsXYMib9ULJ9GI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350120; c=relaxed/simple; bh=1TfzjV65Vu98Mi2aJPbWFVq8Ym9PXjl/pxflZuUinfg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UGDYvAO6UbvNaP6ZMflIpXxz+MsUsIjk6RRyPpoxdqU1FzNgvrc5i31RRyy/r4Ru3UfCvKcoBNQvTGvJ2ugohQl0befnuhp3z2snxfZxfSrP9KbmGmM86mAGcO4VnK8AoXPQc8Y+S5ctosuTTiLuRMOX9ENvKAskaKy+leAeJRQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=I/bvONuz; 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="I/bvONuz" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32EACC4CEE2; Fri, 11 Apr 2025 05:41:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350120; bh=1TfzjV65Vu98Mi2aJPbWFVq8Ym9PXjl/pxflZuUinfg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I/bvONuz2pjRT8xXmuRhAcCA6HMAa/N9lGQy7zL7Rx0ZhYFSb/mdsEhiC5IJuoIGX zu0+sMln/7BU/0etZE5K5OrCtrUE8SSx8K6N5EtEYdaF2zCm/NWwut+6d6vI9plrDJ 1z2piMN03JpUmKUk08GH+Q5WHtX279BDEF+1WpjPWATBYZJr3rL9R4Ar6nDC1v5l36 sMqZNGn+SpUvwxcAGrbKCuAdh97s8PRtpvYbk7yNnUP6S3lMq0Q8BmIjgAjwxdy50Z zC1BOP4vBwOmFxAhg/E3BA5DwdqBRd/B4CYJt0OIYN72X0UgqS1UAleQIrI8gSZI8Q kvoazOijnndFQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 20/53] x86/alternatives: Rename 'int3_desc' to 'int3_vec' Date: Fri, 11 Apr 2025 07:40:32 +0200 Message-ID: <20250411054105.2341982-21-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-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 ca4599ef44f3..cb1723730f1e 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2473,7 +2473,7 @@ struct text_poke_int3_vec { =20 static DEFINE_PER_CPU(atomic_t, int3_refs); =20 -static struct text_poke_int3_vec int3_desc; +static struct text_poke_int3_vec int3_vec; =20 static __always_inline struct text_poke_int3_vec *try_get_desc(void) @@ -2483,7 +2483,7 @@ struct text_poke_int3_vec *try_get_desc(void) if (!raw_atomic_inc_not_zero(refs)) return NULL; =20 - return &int3_desc; + return &int3_vec; } =20 static __always_inline void put_desc(void) @@ -2522,7 +2522,7 @@ noinstr int smp_text_poke_int3_handler(struct pt_regs= *regs) =20 /* * Having observed our INT3 instruction, we now must observe - * int3_desc with non-zero refcount: + * int3_vec with non-zero refcount: * * int3_refs =3D 1 INT3 * WMB RMB @@ -2625,12 +2625,12 @@ static void smp_text_poke_batch_process(struct smp_= text_poke_loc *tp, unsigned i =20 lockdep_assert_held(&text_mutex); =20 - int3_desc.vec =3D tp; - int3_desc.nr_entries =3D nr_entries; + int3_vec.vec =3D tp; + int3_vec.nr_entries =3D nr_entries; =20 /* * Corresponds to the implicit memory barrier in try_get_desc() to - * ensure reading a non-zero refcount provides up to date int3_desc data. + * ensure reading a non-zero refcount provides up to date int3_vec data. */ for_each_possible_cpu(i) atomic_set_release(per_cpu_ptr(&int3_refs, i), 1); --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 91F1D293475 for ; Fri, 11 Apr 2025 05:42: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=1744350122; cv=none; b=XObjpJFjYjyQbJQ6vJu1br1JT48jQNB6zuqfw5tYoFvUXEPJk91gw03bBNBGqDclHLMf597Bu1a/0/tQK61rsdwEKvK3WcayflqkjoyVT25sP/tZM9D8G3D9V5mkSgOxbZ941KJjLtPbCkfM/yCwPnrrP4/i72nnx+L5LflTxGY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350122; c=relaxed/simple; bh=Cxr9+BpFDPItZf6/GxwLJEbbqAM3a68chIdZlEEpu00=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bLSZw9qnFEyzCtJq12dDBrzMKV+JuHZTlv6kiHBV+EcHE0ejOd3bQwfjPeKw04Ty6h2p+ikyhZuxD0oUtuvL22KUgIePwvfjXRkLPigBDenpUwXI8ArJqerB9NIbJ9y6ocxKXN1tNGGn8WzSKRDGjNf9XQaHC7Sv6vD8/6Hepmc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=u6nd6fa+; 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="u6nd6fa+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8BB89C4CEE2; Fri, 11 Apr 2025 05:42:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350122; bh=Cxr9+BpFDPItZf6/GxwLJEbbqAM3a68chIdZlEEpu00=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u6nd6fa+o/BuRWZyGJyfVp9kbi/mCQEJRrKFAOkwQBskOinGxBijBX+S2PQSWY/lr 0xKmn8Md5CnPcK8JmXe7XRgmMdMbNnfl0dFXqBAhphdc6wjFkeXDj43hf3Wx5pxzY7 bfxFOwnmIEuILatyWMsPZVrPHF5iG2y+hPj1zi/gR1yuPg2rger5W1+noZBYZwh1ei jxu6ByAz1UeiO5keBLWdL61T+oUh8+b1wIuHGEJEbnQgeF8vgwEFSxyi//k9dLJoOH Zi0SDE6jvXmo4e4MIdoAcXU3XLpM3ehBAggYZues3wU1g4nO1B3yah6bpcOKjIKTmY X1aesOnVSoq/g== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 21/53] x86/alternatives: Add text_mutex) assert to smp_text_poke_batch_flush() Date: Fri, 11 Apr 2025 07:40:33 +0200 Message-ID: <20250411054105.2341982-22-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-1-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It's possible to escape the text_mutex-held assert in smp_text_poke_batch_process() if the caller uses a properly batched and sorted series of patch requests, so add an explicit lockdep_assert_held() to make sure it's held by all callers. All text_poke_int3_*() APIs will call either smp_text_poke_batch_process() or smp_text_poke_batch_flush() internally. The text_mutex must be held, because tp_vec and tp_vec_nr et al are all globals, and the INT3 patching machinery itself relies on external serialization. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index cb1723730f1e..d3d250dcefca 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2860,6 +2860,8 @@ static bool tp_order_fail(void *addr) =20 static void smp_text_poke_batch_flush(void *addr) { + lockdep_assert_held(&text_mutex); + if (tp_vec_nr =3D=3D TP_VEC_MAX || tp_order_fail(addr)) { smp_text_poke_batch_process(tp_vec, tp_vec_nr); tp_vec_nr =3D 0; --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 52353293B72 for ; Fri, 11 Apr 2025 05:42:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350125; cv=none; b=mGGQqUb25+VB0Q2AFD40uR3cPIio3l7V0J1N3MVz65TCaX3By+3IYOOEJywVsJltXFHEFCJyBPGIRSjQNTUwXEOYioQ8g/nl/Kj9owcEMJgqieCisIL66CFEHf/nVR90dhqzYGKJKrf2RxqSRg1PPRj+XKAsrCPYm7jTOVgrtLY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350125; c=relaxed/simple; bh=5ve/rJJkqY9+wXdI0eiSUbGq+zG5vSV+XhyvzG//1yk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dkgxj5v+9xasgj6kkajRlrjQ9F3T+1Y/B32Cy5HAQWFnr4JGuxJng9Kv6nXHr9/XVt4rKVNdoACnf2uGIuMFXgiKULywUWlMEwfJMbPuILGCwK9Ba8mqWUw0YLDgk1ouplMRZL4d3L9QXNqyfyskjusJ5yH4LgfkCZS6nP6j1YE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aR2uGARw; 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="aR2uGARw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E50DEC4CEE2; Fri, 11 Apr 2025 05:42:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350124; bh=5ve/rJJkqY9+wXdI0eiSUbGq+zG5vSV+XhyvzG//1yk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aR2uGARwcn3CECP5GL0K9EJeifsbLMI+jSKJOoB5xEGPtgN0WdtQKyU7BbAW1fCqO zhZiHGf/Z4zmaTnf74IIV90pNS+JhfaKE5KlyhPjyy4kKJPY2HeMisGRNNiIAEbnDg IhVdBgSLb3+jVTmdew4F/M/pFIaLOA1LRGlF7fmtjYK1UbugTebmOz54AiavV3IsEI mr++I5X5CYrgqfnx0TY7lJl2karI4ccWygELDMIknGXAFmdb66/0RcLkLsjXqrXE5v lY1P+yNbg+wXg+uwNHYSwfaG2+obOFOgt5j9iSl+Z3OYP6gKYJRbr7nqfR23pIYeut PuYMdLGDRL8xw== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 22/53] x86/alternatives: Use non-inverted logic instead of 'tp_order_fail()' Date: Fri, 11 Apr 2025 07:40:34 +0200 Message-ID: <20250411054105.2341982-23-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-1-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" tp_order_fail() uses inverted logic: it returns true in case something is false, which is only a plus at the IOCCC. Instead rename it to regular parity as 'text_poke_addr_ordered()', and adjust the code accordingly. Also add a comment explaining how the address ordering should be understood. No change in functionality intended. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index d3d250dcefca..c9fd31d512b0 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2841,28 +2841,34 @@ static void text_poke_int3_loc_init(struct smp_text= _poke_loc *tp, void *addr, * We hard rely on the tp_vec being ordered; ensure this is so by flushing * early if needed. */ -static bool tp_order_fail(void *addr) +static bool text_poke_addr_ordered(void *addr) { struct smp_text_poke_loc *tp; =20 if (!tp_vec_nr) - return false; + return true; =20 if (!addr) /* force */ - return true; + return false; =20 - tp =3D &tp_vec[tp_vec_nr - 1]; + /* + * If the last current entry's address is higher than the + * new entry's address we'd like to add, then ordering + * is violated and we must first flush all pending patching + * requests: + */ + tp =3D &tp_vec[tp_vec_nr-1]; if ((unsigned long)text_poke_addr(tp) > (unsigned long)addr) - return true; + return false; =20 - return false; + return true; } =20 static void smp_text_poke_batch_flush(void *addr) { lockdep_assert_held(&text_mutex); =20 - if (tp_vec_nr =3D=3D TP_VEC_MAX || tp_order_fail(addr)) { + if (tp_vec_nr =3D=3D TP_VEC_MAX || !text_poke_addr_ordered(addr)) { smp_text_poke_batch_process(tp_vec, tp_vec_nr); tp_vec_nr =3D 0; } --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 55BAF28EA52 for ; Fri, 11 Apr 2025 05:42: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=1744350127; cv=none; b=ubxMSwNx81pgJNcys825XPq391OnmbSx1n/rKqAaGO48qG4HJwt+cME/E8btHl9mPnbEO+CPGTbTfLpXQQhFyQ3wdtJKY/DYc3dt6dVDxYKT9VxOJnSuDv0wJgrhCVG1mRUcihmNeDLohm1ZoCjlVoK/BIi0fCZrmjJD9Gd2MpM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350127; c=relaxed/simple; bh=A4zDuD9kFmef8lAoqWp7mMMwFBvTb+YDoARFkhayZF8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fGW2FHeKHe+JwFZ6+WUTaEcl6FTWsC9LCar1mw7OOdTGbeTmvVMCcR3AffiGSshOVQYCEZh4LQTx3rSa3TUyoZ2Zlxxag75olHj5hVQPjMVldJUS5BQcdYROTafv/xxl9bHMBvPdMNjlDsMTW2EpDIF5owTR6FLHCuuoq2tThks= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jBWuqb1L; 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="jBWuqb1L" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4BB98C4CEE9; Fri, 11 Apr 2025 05:42:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350127; bh=A4zDuD9kFmef8lAoqWp7mMMwFBvTb+YDoARFkhayZF8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jBWuqb1LuX6PLdUWfBWcP4aHDS6ER7p1qybbq7IF9L5HdVlepfhxlRL/K/g5Uqnu2 NwgpSmM7V7YJgjSxoPfMtHDoKaA66lk+00HFH9lA2ytlxj/gUuOE+YBj8vvPXx+Cyg 2f/A2e9qq8Z9IDZE/4lOAuql8UY7PSOcz7cWru5HyBMhOnoPYF/uQ/sH3AZl2vdDja lf9O8EdhTVFnr3R2FA/JQd9c8bQzB3AXWaNW4yn+mvTe6KCAfAYGEDsOU3gp2fMdrl OhL/VaI8kbiib5k0NtDgi7Duz/X95+TIOChJna3TH3RL+HxYP+5nfytDeuVSjlgPEN bwzBhR8BbTrrQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 23/53] x86/alternatives: Remove the 'addr == NULL means forced-flush' hack from smp_text_poke_batch_finish()/smp_text_poke_batch_flush()/text_poke_addr_ordered() Date: Fri, 11 Apr 2025 07:40:35 +0200 Message-ID: <20250411054105.2341982-24-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-1-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There's this weird hack used by smp_text_poke_batch_finish() to indicate a 'forced flush': smp_text_poke_batch_flush(NULL); Just open-code the vector-flush in a straightforward fashion: smp_text_poke_batch_process(tp_vec, tp_vec_nr); tp_vec_nr =3D 0; And get rid of !addr hack from text_poke_addr_ordered(). Leave a WARN_ON_ONCE(), just in case some external code learned to rely on this behavior. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index c9fd31d512b0..d4eb20aa8d7c 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2845,12 +2845,11 @@ static bool text_poke_addr_ordered(void *addr) { struct smp_text_poke_loc *tp; =20 + WARN_ON_ONCE(!addr); + if (!tp_vec_nr) return true; =20 - if (!addr) /* force */ - return false; - /* * If the last current entry's address is higher than the * new entry's address we'd like to add, then ordering @@ -2864,6 +2863,14 @@ static bool text_poke_addr_ordered(void *addr) return true; } =20 +void smp_text_poke_batch_finish(void) +{ + if (tp_vec_nr) { + smp_text_poke_batch_process(tp_vec, tp_vec_nr); + tp_vec_nr =3D 0; + } +} + static void smp_text_poke_batch_flush(void *addr) { lockdep_assert_held(&text_mutex); @@ -2874,11 +2881,6 @@ static void smp_text_poke_batch_flush(void *addr) } } =20 -void smp_text_poke_batch_finish(void) -{ - smp_text_poke_batch_flush(NULL); -} - void __ref smp_text_poke_batch_add(void *addr, const void *opcode, size_t = len, const void *emulate) { struct smp_text_poke_loc *tp; --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 AF23D296171 for ; Fri, 11 Apr 2025 05:42:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350129; cv=none; b=YN7ytdaULB2hFD4cDm5liUKMLyODkuPFPNrTSIxnx57nA6gsig2Ei7o/jAFh/yuhMzUn0jIW52KmyXJnq7o4BOEKHsclC62fYW0anbCogA11JQguvfGI+hpDJgsdzy3U1bBccfiSMo7wnrq07RRUFZBViPnkBk8t7pbjuzsjvqs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350129; c=relaxed/simple; bh=lyCApSzB3Dokghhd8Ey2R2XphdhSMxBO52IMlu4kvkc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MfAJCPXlHlLWOejV6P66FC3TKzh9oMbdyIhnoQ7UBuG5s/eLejsxIRsShkkeZN+JesVJIkEyZYeoxFRw0CHEmLOaHZ6dEQ1GUxvXnXytuDKqX8BA5cog9k9EzLIRBNRNZWes6CGOLdVyXr4nyl/RGZTH81M+36G0nZ2eASoZJ0Q= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=B9/Ca+yI; 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="B9/Ca+yI" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A7CEDC4CEE2; Fri, 11 Apr 2025 05:42:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350129; bh=lyCApSzB3Dokghhd8Ey2R2XphdhSMxBO52IMlu4kvkc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B9/Ca+yIO/vAdTeKVy6GNTc4noqRrS3JNtbg0rRdDUFbREyUA2fCEHUJB6bRXuBKu gOPpnb5Tqpo1/FFT9lX/hw4sE9XvSTDzJ/RyP5NTBxGoAvXWhhvL/2IO75eVhI51EL ZX8zi/mbjN/Ik4iLBxRGTbkzlVQm0NwshawaRyBUp2PAyyrMRJASq/MUpOYl8HKNys hQ26Nh6CajU584ECH5Aie82Mf6viGd1but7nw1Q0mqQHeBMrtH9KjJtHFeVneOVRh4 yiABXcm4NI8942mPT2xhbApbci4qzUkM/S6eruXIeTRG+0Hh1PYsL7FKRKzaorOjfn YMc9Rs27Ldl/g== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 24/53] x86/alternatives: Simplify smp_text_poke_single() by using tp_vec and existing APIs Date: Fri, 11 Apr 2025 07:40:36 +0200 Message-ID: <20250411054105.2341982-25-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-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 d4eb20aa8d7c..09c6be8900d3 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2904,8 +2904,13 @@ void __ref smp_text_poke_batch_add(void *addr, const= void *opcode, size_t len, c */ void __ref smp_text_poke_single(void *addr, const void *opcode, size_t len= , const void *emulate) { - struct smp_text_poke_loc tp; + struct smp_text_poke_loc *tp; + + /* Batch-patching should not be mixed with single-patching: */ + WARN_ON_ONCE(tp_vec_nr !=3D 0); + + tp =3D &tp_vec[tp_vec_nr++]; + text_poke_int3_loc_init(tp, addr, opcode, len, emulate); =20 - text_poke_int3_loc_init(&tp, addr, opcode, len, emulate); - smp_text_poke_batch_process(&tp, 1); + smp_text_poke_batch_finish(); } --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 20F2829617F for ; Fri, 11 Apr 2025 05:42: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=1744350132; cv=none; b=OkMSjfZxh1e+Ei8hoy17Nf2Az43lh2GQpIERn26sny2vNa4jSpa4Fq74R4jyKa8wzX6r88+4PtfC4zsfFQaiNkwfD5dDUJGbuxS36FNklWG96v65F50eTwJn9A6qJwMmw8j9UIjy1HYfSsxt8bM5Ey+/DNFLtNE1P+5NfuFqOjM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350132; c=relaxed/simple; bh=rmBlT3JpJLSXrIQpkHLjkV255q8JcC/6mq08ZERslzA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LP7/UJuNuwrRZmw1Yj32b6vClRS3ikRiTF7mmRfEZSdHJ2b0voCvX0ViEGg8LED8gX6i+48CUI7Hhwuxr/yC/e7KKf8sBJbDZTdyTOmW9ae5VKKD9XNVI+/SMUOE+MSdH6OmcxW2c579jZWXRTrYIJEtSCe67/pj8yyGCF1WYdo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=C2RMHBBM; 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="C2RMHBBM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0FFF4C4CEE5; Fri, 11 Apr 2025 05:42:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350132; bh=rmBlT3JpJLSXrIQpkHLjkV255q8JcC/6mq08ZERslzA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C2RMHBBMnozvjbIVy7ymXRYeAoHCdTxpZrU+L8QFhAogovZl2jDMfLd/48YV2LCrd AbPkWCtXv2i2yW3PwLBKgiYA23qnT5SlU2f5dxr/96nrBaw943FB0Lmd0ahvKRDe2Q 3+/71XSKBqnfEBoRfzDHr4SiWERu16Os5KVDnRh8ezCxqC3nYTPsUdT8TbtAFWtSRe Xm+6TWkoDnnHnEDJ99DHZ+rO1lzDgAOgT3/4pBLmHA6/p8rLocFVqg2RrpFMmC6D1k J/NvOlH6aJIzYP7nurRB3NA/6AIJrdYJFhEQexoEaT2b7ofdTMEEh74uwi83FnuKhU pF2ip6Hu+SxJw== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 25/53] x86/alternatives: Assert that smp_text_poke_int3_handler() can only ever handle 'tp_vec[]' based requests Date: Fri, 11 Apr 2025 07:40:37 +0200 Message-ID: <20250411054105.2341982-26-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-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 09c6be8900d3..aa369870dfce 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2510,6 +2510,10 @@ static __always_inline int patch_cmp(const void *key= , const void *elt) return 0; } =20 +#define TP_VEC_MAX (PAGE_SIZE / sizeof(struct smp_text_poke_loc)) +static struct smp_text_poke_loc tp_vec[TP_VEC_MAX]; +static int tp_vec_nr; + noinstr int smp_text_poke_int3_handler(struct pt_regs *regs) { struct text_poke_int3_vec *desc; @@ -2534,6 +2538,8 @@ noinstr int smp_text_poke_int3_handler(struct pt_regs= *regs) if (!desc) return 0; =20 + WARN_ON_ONCE(desc->vec !=3D tp_vec); + /* * Discount the INT3. See smp_text_poke_batch_process(). */ @@ -2592,10 +2598,6 @@ noinstr int smp_text_poke_int3_handler(struct pt_reg= s *regs) return ret; } =20 -#define TP_VEC_MAX (PAGE_SIZE / sizeof(struct smp_text_poke_loc)) -static struct smp_text_poke_loc tp_vec[TP_VEC_MAX]; -static int tp_vec_nr; - /** * smp_text_poke_batch_process() -- update instructions on live kernel on = SMP * @tp: vector of instructions to patch --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 74D8C2980C7 for ; Fri, 11 Apr 2025 05:42:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350134; cv=none; b=cWvLTa76IDzLA+LVGjbriMHg5p0O3pSNz7iaG4edt1XKpH4FZWOel7YiwHfvSmDAc5khNY2Ld3WUnL7W/gMHKkm/cvMebRJZn8Ucg8EFNqIX3Abg8FmuVnTNagDvYD7f605e1WhGQ2Ak61W+emQmkDf9CjAQPVF+AEkuo3CUerw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350134; c=relaxed/simple; bh=ksgKsThUr934SDiegLpXIFwyJxxeAEKWgbZq2X+31d4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o2ztJMw8sNR2NIV0ljVyE+hwTPAlNbrFvtjXVH7+1ySavLTm7qT42rzg5JcQn/BnFrh8L9WFuyhzBq5P5Jsy3lqK76hqwxHfS4bi9THmBAewlyigLpVQnjS42h+kkcWz67hIgA6zV/N2OniDhurW1IXrNNTWlI03WSCEm26TFQs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KroPtlNS; 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="KroPtlNS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6C648C4CEE2; Fri, 11 Apr 2025 05:42:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350134; bh=ksgKsThUr934SDiegLpXIFwyJxxeAEKWgbZq2X+31d4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KroPtlNSnjk3T0QrcLHrKVQsODTR8VdxddVkzwQUF1jOADMlLVMZ8zuDdHcRO01/m dcgu3BjSUpU4HbAtfaB+MX742Jy2LNYiIRyJuAcglNwdxWGmTHAp62rNdqTlMETWYj qNr+pJApemRR+x89nBVld8AFtf+5D9SKZ4cvbV+k+ejTzweED/v8OE/OTMfv6S/vIi koL9VMycb9o0AaksfwOLmiQ4/HFPe8t9NRI18td6ajau9WTJ0EhVVnEoKN/IUAFFqR 71bhl/8XJocC7o9QzsiY33ppVIU3PCrnvzy8dI73yBp8fYC+aA+iGQ9JONUNyDvuK1 LJjd3+lUYPFxg== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 26/53] x86/alternatives: Assert input parameters in smp_text_poke_batch_process() Date: Fri, 11 Apr 2025 07:40:38 +0200 Message-ID: <20250411054105.2341982-27-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-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 aa369870dfce..ee6ff7660563 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2627,6 +2627,9 @@ static void smp_text_poke_batch_process(struct smp_te= xt_poke_loc *tp, unsigned i =20 lockdep_assert_held(&text_mutex); =20 + WARN_ON_ONCE(tp !=3D tp_vec); + WARN_ON_ONCE(nr_entries !=3D tp_vec_nr); + int3_vec.vec =3D tp; int3_vec.nr_entries =3D nr_entries; =20 --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 D7F752980DD for ; Fri, 11 Apr 2025 05:42:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350136; cv=none; b=REo8vJyJWSS9tgQEQEzZLmZq4qo3WR6l3fFf9dLtdkPubRJToX2krDlKyCR5hQyc7LDq9YR7ZV7LzUPN3Ey2bHbPspx9cC5SGv0AVUa2Nzp3Lc4TvdI5a9GW3N9xpP/gEAgWTJ3EwDNbFkdVKabI8yLKkhS3lc1yQIwzWqMTZSE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350136; c=relaxed/simple; bh=62aMsQYVHPp7bHeNS3D+Wg81XfB0kzlWGa83pIbg3qY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZldHYrFqiJt8F/odS7q7HmRgMzePE/CIP0i/hecF387ZFN1d4ak/ehqgzSWaJ6kOVTcSI2Y6LiTujFJMeSlie0e/Hg4ybKBZQ5KTAc053tpY2/DXJaGagMUCe/WQe5N/bV6/hWttwcAmXAymtKLSmJEed5zeTnVM9Bsmzs1fdSI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ru8tlPD5; 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="Ru8tlPD5" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8554C4CEE2; Fri, 11 Apr 2025 05:42:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350136; bh=62aMsQYVHPp7bHeNS3D+Wg81XfB0kzlWGa83pIbg3qY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ru8tlPD5fg0IQEnUrNUe4fNZcRl4dg5cK1AvS0ebO96jH8SFPUl86JMxG418yUWFc Tjz1fXst2hM0hJNBWXi4cEa/4pL2BdJqrZBKEl0GUQtQ+w0/VCgziwMkA3ccT4O8a3 EX8IXb9CiQv/QCKv0qZfnxlHkGciLdusq+v/mN1qObbcKczs193DawsV9LpLaKdHaf d3AT3ke+ywRNrkH0+FMgaQzaHt7h/ntABUumc9CQ3HrmCwstT70u/lJ+BPlFtLpUXA 7tVzYDhT2eboJjc/1DNZLnCMmLwFeJgw8NIKlgBcL7gy0+ZFJaH6GmDF/+mgrsDcRh HNKHN8rwsAfhw== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 27/53] x86/alternatives: Introduce 'struct smp_text_poke_array' and move tp_vec and tp_vec_nr to it Date: Fri, 11 Apr 2025 07:40:39 +0200 Message-ID: <20250411054105.2341982-28-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-1-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" struct text_poke_array is an equivalent structure to these global variables: static struct smp_text_poke_loc tp_vec[TP_VEC_MAX]; static int tp_vec_nr; Note that we intentionally mirror much of the naming of 'struct text_poke_int3_vec', which will further highlight the unecessary layering going on in this code, and will ease its removal. No change in functionality. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 43 +++++++++++++++++++++++----------------= ---- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index ee6ff7660563..d1647aa46db5 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2467,14 +2467,21 @@ struct smp_text_poke_loc { }; =20 struct text_poke_int3_vec { - struct smp_text_poke_loc *vec; int nr_entries; + struct smp_text_poke_loc *vec; }; =20 static DEFINE_PER_CPU(atomic_t, int3_refs); =20 static struct text_poke_int3_vec int3_vec; =20 +#define TP_ARRAY_NR_ENTRIES_MAX (PAGE_SIZE / sizeof(struct smp_text_poke_l= oc)) + +static struct smp_text_poke_array { + int nr_entries; + struct smp_text_poke_loc vec[TP_ARRAY_NR_ENTRIES_MAX]; +} text_poke_array; + static __always_inline struct text_poke_int3_vec *try_get_desc(void) { @@ -2510,10 +2517,6 @@ static __always_inline int patch_cmp(const void *key= , const void *elt) return 0; } =20 -#define TP_VEC_MAX (PAGE_SIZE / sizeof(struct smp_text_poke_loc)) -static struct smp_text_poke_loc tp_vec[TP_VEC_MAX]; -static int tp_vec_nr; - noinstr int smp_text_poke_int3_handler(struct pt_regs *regs) { struct text_poke_int3_vec *desc; @@ -2538,7 +2541,7 @@ noinstr int smp_text_poke_int3_handler(struct pt_regs= *regs) if (!desc) return 0; =20 - WARN_ON_ONCE(desc->vec !=3D tp_vec); + WARN_ON_ONCE(desc->vec !=3D text_poke_array.vec); =20 /* * Discount the INT3. See smp_text_poke_batch_process(). @@ -2627,8 +2630,8 @@ static void smp_text_poke_batch_process(struct smp_te= xt_poke_loc *tp, unsigned i =20 lockdep_assert_held(&text_mutex); =20 - WARN_ON_ONCE(tp !=3D tp_vec); - WARN_ON_ONCE(nr_entries !=3D tp_vec_nr); + WARN_ON_ONCE(tp !=3D text_poke_array.vec); + WARN_ON_ONCE(nr_entries !=3D text_poke_array.nr_entries); =20 int3_vec.vec =3D tp; int3_vec.nr_entries =3D nr_entries; @@ -2843,7 +2846,7 @@ static void text_poke_int3_loc_init(struct smp_text_p= oke_loc *tp, void *addr, } =20 /* - * We hard rely on the tp_vec being ordered; ensure this is so by flushing + * We hard rely on the text_poke_array.vec being ordered; ensure this is s= o by flushing * early if needed. */ static bool text_poke_addr_ordered(void *addr) @@ -2852,7 +2855,7 @@ static bool text_poke_addr_ordered(void *addr) =20 WARN_ON_ONCE(!addr); =20 - if (!tp_vec_nr) + if (!text_poke_array.nr_entries) return true; =20 /* @@ -2861,7 +2864,7 @@ static bool text_poke_addr_ordered(void *addr) * is violated and we must first flush all pending patching * requests: */ - tp =3D &tp_vec[tp_vec_nr-1]; + tp =3D &text_poke_array.vec[text_poke_array.nr_entries-1]; if ((unsigned long)text_poke_addr(tp) > (unsigned long)addr) return false; =20 @@ -2870,9 +2873,9 @@ static bool text_poke_addr_ordered(void *addr) =20 void smp_text_poke_batch_finish(void) { - if (tp_vec_nr) { - smp_text_poke_batch_process(tp_vec, tp_vec_nr); - tp_vec_nr =3D 0; + if (text_poke_array.nr_entries) { + smp_text_poke_batch_process(text_poke_array.vec, text_poke_array.nr_entr= ies); + text_poke_array.nr_entries =3D 0; } } =20 @@ -2880,9 +2883,9 @@ static void smp_text_poke_batch_flush(void *addr) { lockdep_assert_held(&text_mutex); =20 - if (tp_vec_nr =3D=3D TP_VEC_MAX || !text_poke_addr_ordered(addr)) { - smp_text_poke_batch_process(tp_vec, tp_vec_nr); - tp_vec_nr =3D 0; + if (text_poke_array.nr_entries =3D=3D TP_ARRAY_NR_ENTRIES_MAX || !text_po= ke_addr_ordered(addr)) { + smp_text_poke_batch_process(text_poke_array.vec, text_poke_array.nr_entr= ies); + text_poke_array.nr_entries =3D 0; } } =20 @@ -2892,7 +2895,7 @@ void __ref smp_text_poke_batch_add(void *addr, const = void *opcode, size_t len, c =20 smp_text_poke_batch_flush(addr); =20 - tp =3D &tp_vec[tp_vec_nr++]; + tp =3D &text_poke_array.vec[text_poke_array.nr_entries++]; text_poke_int3_loc_init(tp, addr, opcode, len, emulate); } =20 @@ -2912,9 +2915,9 @@ void __ref smp_text_poke_single(void *addr, const voi= d *opcode, size_t len, cons struct smp_text_poke_loc *tp; =20 /* Batch-patching should not be mixed with single-patching: */ - WARN_ON_ONCE(tp_vec_nr !=3D 0); + WARN_ON_ONCE(text_poke_array.nr_entries !=3D 0); =20 - tp =3D &tp_vec[tp_vec_nr++]; + tp =3D &text_poke_array.vec[text_poke_array.nr_entries++]; text_poke_int3_loc_init(tp, addr, opcode, len, emulate); =20 smp_text_poke_batch_finish(); --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 9CDB4298990 for ; Fri, 11 Apr 2025 05:42: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=1744350139; cv=none; b=pPB8ssnIm4bu/oN1BJ+pscmBPNAQ3/qhLlBonuIHE5Z53ypQQMY/nhLLXmTwy6w54GoZbj/EteLte8ao5em2DILWou9Xray/sBMmVm++ZCP61IsHTFsOeSkoLiDQ+POFTK8A26DT01o2HrBxUOuIvi8Qd2RDEdlFPF1bKeN4tIE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350139; c=relaxed/simple; bh=zi+/HiEvwS3E0QajGfqQJ4f+3skWIus+SdC9r+0htYo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Iz6ni8UTv3RpbmsFHQews4ZIkrgug+uII8AevrwZee/sdZLdSdvocIToQ4QH95Pu5VQ0beRIUm2cBl5Qv063LqmnPUQY2FVgrc56gTdUepe8HzKmzHZN9ehhTcNdbKZOt5OuB18X9HNcE6yqQlCeODM8Wp/kpNnUGh9DnBdb8m4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=QXEQAQwi; 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="QXEQAQwi" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 35646C4CEE5; Fri, 11 Apr 2025 05:42:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350139; bh=zi+/HiEvwS3E0QajGfqQJ4f+3skWIus+SdC9r+0htYo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QXEQAQwiyzigsHPyAkVDnFJ+0mQG/VfVY2hlEwlLdAZd28lBReMLl2cjUdgBBJ1X6 fI/B5paRm5ZWR5KSvUQGCVu2EV+X/Qc4bBil7FdVi0IA6f9yCjNoUskoNbEvG3p7X+ 8VgiTA1vZBR75Oq0MQUzXNmUeiMSHv2YJ4wn2x18MOPXB35MWsUAwPa5VtsZgdF0rG 9gRokl61o1IhYJJShaYff23CvYSAh//PFZQQvyLe8D/3E3EhW22aJXdbJzwqTJueCE fMFQdyhGJjk7ZGTfYeDfoiHGJfnOA8Pd5tjP/rjjmu4xzR1G7WIho9a2FmuZyptYhX Y9E2VJWf/imZw== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 28/53] x86/alternatives: Remove the tp_vec indirection Date: Fri, 11 Apr 2025 07:40:40 +0200 Message-ID: <20250411054105.2341982-29-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-1-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" At this point we are always working out of an uptodate text_poke_array, there's no need for smp_text_poke_int3_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 d1647aa46db5..4da6a64dcb0a 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2466,15 +2466,6 @@ struct smp_text_poke_loc { u8 old; }; =20 -struct text_poke_int3_vec { - int nr_entries; - struct smp_text_poke_loc *vec; -}; - -static DEFINE_PER_CPU(atomic_t, int3_refs); - -static struct text_poke_int3_vec int3_vec; - #define TP_ARRAY_NR_ENTRIES_MAX (PAGE_SIZE / sizeof(struct smp_text_poke_l= oc)) =20 static struct smp_text_poke_array { @@ -2482,15 +2473,17 @@ static struct smp_text_poke_array { struct smp_text_poke_loc vec[TP_ARRAY_NR_ENTRIES_MAX]; } text_poke_array; =20 +static DEFINE_PER_CPU(atomic_t, int3_refs); + static __always_inline -struct text_poke_int3_vec *try_get_desc(void) +struct smp_text_poke_array *try_get_desc(void) { atomic_t *refs =3D this_cpu_ptr(&int3_refs); =20 if (!raw_atomic_inc_not_zero(refs)) return NULL; =20 - return &int3_vec; + return &text_poke_array; } =20 static __always_inline void put_desc(void) @@ -2519,7 +2512,7 @@ static __always_inline int patch_cmp(const void *key,= const void *elt) =20 noinstr int smp_text_poke_int3_handler(struct pt_regs *regs) { - struct text_poke_int3_vec *desc; + struct smp_text_poke_array *desc; struct smp_text_poke_loc *tp; int ret =3D 0; void *ip; @@ -2529,7 +2522,7 @@ noinstr int smp_text_poke_int3_handler(struct pt_regs= *regs) =20 /* * Having observed our INT3 instruction, we now must observe - * int3_vec with non-zero refcount: + * text_poke_array with non-zero refcount: * * int3_refs =3D 1 INT3 * WMB RMB @@ -2633,12 +2626,9 @@ static void smp_text_poke_batch_process(struct smp_t= ext_poke_loc *tp, unsigned i WARN_ON_ONCE(tp !=3D text_poke_array.vec); WARN_ON_ONCE(nr_entries !=3D text_poke_array.nr_entries); =20 - int3_vec.vec =3D tp; - int3_vec.nr_entries =3D nr_entries; - /* * Corresponds to the implicit memory barrier in try_get_desc() to - * ensure reading a non-zero refcount provides up to date int3_vec data. + * ensure reading a non-zero refcount provides up to date text_poke_array= data. */ for_each_possible_cpu(i) atomic_set_release(per_cpu_ptr(&int3_refs, i), 1); --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 97B17298992 for ; Fri, 11 Apr 2025 05:42:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350141; cv=none; b=cgw9ixVRaoipKzNRuB5oBlZXlJcSEzxeDfbNBonGs64dra1jiKyGUvNiikhO7wWGOmji0d/GgCfNIHKyZll7XL6xye9F/S8zMP3vjkwufpJ/iAvO3mvrB2/2n+bXxgsgX0kREE92k2f5WTNf/f2OszHW/5wHVCyIMvtu5wb0cCM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350141; c=relaxed/simple; bh=IbZURKeJ3vzy/tXLxxQltXi7cPQ66zkmzEzSAd4LpiU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=d99z3lmOCc3pZsap66EPwm6tZlI5FGIpafdvi4w7W2NNUyMdIdLVrPATsK5YT3WiIdfgMqbmfpV3103FcqbtAkswArl8dqJPTte5kxnMRMsv/VlKVfAyhbrf98Z9sEQKsPNUZVAPb2xXa0sQreQM/K6MSHKdQxB+d5EVXL1V7z4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=P5nNHFDk; 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="P5nNHFDk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 92B3BC4CEE2; Fri, 11 Apr 2025 05:42:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350141; bh=IbZURKeJ3vzy/tXLxxQltXi7cPQ66zkmzEzSAd4LpiU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P5nNHFDkrIQZkZt/r/DfNKPMuFbkpE+qmIQstnQVzUX4Ramexfdw4g5sm+mNPkh+c SlMK8enxczrg4wzCqLGeIVJLrhrqjTGBXVh+NRY+xTu1XeofrrEAo7C15MmikEP4L0 ruDpYdE4lvaR6OV6CpmLGtzhP3A9MoRe79KS2ALmtCzwjVfEFlFd9yZeltWdpEorE6 X2NY/a/lFb+JceCkRl9DRIH520Ulns7cwa8jSOlypd0kdKIMrFFYctHYaUrdWsYc3i BPhfThVTOu+F+Ar2lin+pBRDfzc+Eqf+82JCjvGtbCy3OdKoSj8U9VIJdzsokKFEz/ eiIOwm/9aHlmQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 29/53] x86/alternatives: Rename 'try_get_desc()' to 'try_get_text_poke_array()' Date: Fri, 11 Apr 2025 07:40:41 +0200 Message-ID: <20250411054105.2341982-30-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-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 4da6a64dcb0a..2bec5ba866ec 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2476,7 +2476,7 @@ static struct smp_text_poke_array { static DEFINE_PER_CPU(atomic_t, int3_refs); =20 static __always_inline -struct smp_text_poke_array *try_get_desc(void) +struct smp_text_poke_array *try_get_text_poke_array(void) { atomic_t *refs =3D this_cpu_ptr(&int3_refs); =20 @@ -2530,7 +2530,7 @@ noinstr int smp_text_poke_int3_handler(struct pt_regs= *regs) */ smp_rmb(); =20 - desc =3D try_get_desc(); + desc =3D try_get_text_poke_array(); if (!desc) return 0; =20 @@ -2627,7 +2627,7 @@ static void smp_text_poke_batch_process(struct smp_te= xt_poke_loc *tp, unsigned i WARN_ON_ONCE(nr_entries !=3D text_poke_array.nr_entries); =20 /* - * Corresponds to the implicit memory barrier in try_get_desc() to + * Corresponds to the implicit memory barrier in try_get_text_poke_array(= ) to * ensure reading a non-zero refcount provides up to date text_poke_array= data. */ for_each_possible_cpu(i) --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 61D6B2989BB for ; Fri, 11 Apr 2025 05:42: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=1744350144; cv=none; b=takTRhfCxGdwpHVXgH8aUKj7nFoNch0j2Kbd7MDjQDKsIz8pURkXIGDhCwEzRXz73FNr+RpWZ4eXS9PbVpONbAyVQVPu9W0Ku4MhShDOAFNEgI59v9YuwYSLspJ2L2Zz1RFD+gIG/KfciYtsLXVYDZ7/6CP2s3pAiMgQCC4DAHY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350144; c=relaxed/simple; bh=Mvjqf4G02sWBd7sPd73c+7EGfXBqP3D4JOuKEf5BPkc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aDZ556PnKNcNdn05uguEJhh1eTFwyNwWKMZcX1ZICohJx0QD18rRLEC8Q11RJKwA68Jf3eQMryqBUpqbYJA3k1goG0WXc1Zkj7uPRUucUhfJwvhr98jp+NVNriQ3WImzuYapFK6cD2s0J80m/gruRO9lK8+IaarF51ml74ysZNI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Sp3GnWHM; 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="Sp3GnWHM" Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED00CC4CEE9; Fri, 11 Apr 2025 05:42:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350143; bh=Mvjqf4G02sWBd7sPd73c+7EGfXBqP3D4JOuKEf5BPkc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Sp3GnWHM6i+44MxSALjghldzg+JU+rTqt2x5j5K/fHddi498UOUjHqyG6Q6P6CoZx Qp0lZCwTvV8P+pLa9GuFgdGQ4xDoiUcaUTuhHfu11gO9tr0Dl2oU2r9awEbd5HbiIO c0BKP//bbjElA8eO4Eva2xfFMkkFmz3LzUu8KSlSsyLnOHr4VA/CgaB9KYlwLx69HP Bsclhphud0k+PYo/x8FNqimSZ2ttrJO+yt3wFJn8VYOqz/WXMrwMunKfsE8yaEcwwi wouj5nwFo3TZdxldaoDQRjMlsCyp0kVGGgNKnT96wp/WBGpJ+ndGr8g4mfNtV/27xI 4E78PJzc5QOCQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 30/53] x86/alternatives: Rename 'put_desc()' to 'put_text_poke_array()' Date: Fri, 11 Apr 2025 07:40:42 +0200 Message-ID: <20250411054105.2341982-31-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-1-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Just like with try_get_text_poke_array(), this name better reflects what the underlying code is doing, there's no 'descriptor' indirection anymore. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 2bec5ba866ec..4ab9d227e306 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2486,7 +2486,7 @@ struct smp_text_poke_array *try_get_text_poke_array(v= oid) return &text_poke_array; } =20 -static __always_inline void put_desc(void) +static __always_inline void put_text_poke_array(void) { atomic_t *refs =3D this_cpu_ptr(&int3_refs); =20 @@ -2590,7 +2590,7 @@ noinstr int smp_text_poke_int3_handler(struct pt_regs= *regs) ret =3D 1; =20 out_put: - put_desc(); + put_text_poke_array(); return ret; } =20 --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 C7630298CAD for ; Fri, 11 Apr 2025 05:42: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=1744350146; cv=none; b=cIhOZfgN0QYzpTbWeWGYZMafswIpdMwGlyo9HyLMHb3ibxWZAHqfYLzBUmLNf+ML7pWS5yiiOuZC9/yQsEWyaCJqS2HFTJPWxi/xZdiJDqMwu++M5QTc0OtHw0+Svd2rMs5kSjq4b2MQ4oHB3ZHX0vU+eaqmgsgMBUkLxgHnhqE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350146; c=relaxed/simple; bh=WP0YunJFC2OWDdeHhznrBy/YZJ/p/c2BbJj5MQAcuSY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nHYgVkgukAgWxe4Uk0MjzxxJbacrvwFpzLo5oHmuJl/rCK0hrilLIOHkQWZvGa1+1rAqBJ8gc8nfMZJqzJIiWFcS871ttxr/jibCAWKytIB3IVOLyD7rsr86uaTsk096j1u8Wmk2Tzes+uGVAhQqoLRremM4RA8bAFhxn3DQkv0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kqHJDdrW; 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="kqHJDdrW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5954FC4CEE2; Fri, 11 Apr 2025 05:42:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350146; bh=WP0YunJFC2OWDdeHhznrBy/YZJ/p/c2BbJj5MQAcuSY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kqHJDdrWIRbB8rxsVg+9coG+4As0KL43dw8fDyUjUgGYLK1V7/KjZmidjwecFUhew OU3YQKgBue/Pgkb1j5eum1b1cXZxCRMIjJBtsvU+B8bSBKGd0IPoOMfzWMlTpbO6PG Rxxjrk5ImsJNdGbf3PQ8XsTahZbbzUZzdslRtikvHNKViTxtFANCAeJeTNLf1UHcFi R30pzh/63wBGUom6Lr/hmJ/MAHs6vKu6ND0I7OqU34l5R4earlnq9ZaISc5MMHpI4B RkrRPqoMOIaPydFVnMw84bNeymVoPtK8FbjWsrcG+2S3KmVlZ5bzG+TIE80dlN52Wd yDNcxPiUc+VIw== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 31/53] x86/alternatives: Simplify try_get_text_poke_array() Date: Fri, 11 Apr 2025 07:40:43 +0200 Message-ID: <20250411054105.2341982-32-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-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 4ab9d227e306..357d708a3d4f 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2475,15 +2475,14 @@ static struct smp_text_poke_array { =20 static DEFINE_PER_CPU(atomic_t, int3_refs); =20 -static __always_inline -struct smp_text_poke_array *try_get_text_poke_array(void) +static __always_inline bool try_get_text_poke_array(void) { atomic_t *refs =3D this_cpu_ptr(&int3_refs); =20 if (!raw_atomic_inc_not_zero(refs)) - return NULL; + return false; =20 - return &text_poke_array; + return true; } =20 static __always_inline void put_text_poke_array(void) @@ -2530,9 +2529,9 @@ noinstr int smp_text_poke_int3_handler(struct pt_regs= *regs) */ smp_rmb(); =20 - desc =3D try_get_text_poke_array(); - if (!desc) + if (!try_get_text_poke_array()) return 0; + desc =3D &text_poke_array; =20 WARN_ON_ONCE(desc->vec !=3D text_poke_array.vec); =20 --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 26E07298CC2 for ; Fri, 11 Apr 2025 05:42:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350149; cv=none; b=hxt1AGJ9y5AF6XiURcJIOIEfNdfn4e/CHWVqU9SUHIZd68Q1G3K/8LGO/DppE1yd85P6ydkhGkJ5tpsSfSgyr2XSU5EdXwM6QPQLcdwzLKhMmik4hOKqCf5N9JlkO1bXaoZ39yYQUw5VoF+rNdPK1vFUsgjpyQDtaNCfrw0kfBw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350149; c=relaxed/simple; bh=956PC3FXixsFDAeLSWwOk0G94ROVX8E2HD5NDUABTno=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IRXqdYMESe29RSvGSy+g7hWyd35cC0ZYY2ymisW8FrC4T8CahnEJgZr5KWMUAMZ16WaGHv9cndQ/GHmHiHfjd/Ypwk5xmA5Yzv7QOIfDgAyZaCEyAaiNObXbMlUNqHdLBpjwWvfHTCavtB4BopsHBHzm+tcE50ui5kc3goY1dCo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=AtqPnaFQ; 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="AtqPnaFQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B8093C4CEE9; Fri, 11 Apr 2025 05:42:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350148; bh=956PC3FXixsFDAeLSWwOk0G94ROVX8E2HD5NDUABTno=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AtqPnaFQHHe6cJQahbhz+mHGRI7aAEFL7HJ2UPsZJ3Ean3N0X24+/WPEHm7164uhB v0R4QYYBnh2x8IArCaVZK8T6qbvBZaQf/Yk5PvfmJGKrPoVp1o3FV/AyRncuhtJSfh SCkzasDpkS2dYYLTo5EClz7jL/gfXV7dB7APNaef5sn3RxtFulj/fj9eguThBdPz1R Lugzyr4IHhKJiIzIQz4UBGkGIBC1Wye+lBI16Y4ehXoGOCvPTnBALnUGUQIbmubULu 2ueGc3DpsSa15oNzKLsdSj3nOIvTm6ScwJ9sjviPiyPK5sanJ/VT7tXst6XH8YhcCc 4cfz1p/UxLb6w== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 32/53] x86/alternatives: Simplify smp_text_poke_int3_handler() Date: Fri, 11 Apr 2025 07:40:44 +0200 Message-ID: <20250411054105.2341982-33-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-1-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Remove the 'desc' local variable indirection and use text_poke_array directly. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 357d708a3d4f..f94a715d9b2b 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2511,7 +2511,6 @@ static __always_inline int patch_cmp(const void *key,= const void *elt) =20 noinstr int smp_text_poke_int3_handler(struct pt_regs *regs) { - struct smp_text_poke_array *desc; struct smp_text_poke_loc *tp; int ret =3D 0; void *ip; @@ -2531,9 +2530,6 @@ noinstr int smp_text_poke_int3_handler(struct pt_regs= *regs) =20 if (!try_get_text_poke_array()) return 0; - desc =3D &text_poke_array; - - WARN_ON_ONCE(desc->vec !=3D text_poke_array.vec); =20 /* * Discount the INT3. See smp_text_poke_batch_process(). @@ -2543,14 +2539,14 @@ noinstr int smp_text_poke_int3_handler(struct pt_re= gs *regs) /* * Skip the binary search if there is a single member in the vector. */ - if (unlikely(desc->nr_entries > 1)) { - tp =3D __inline_bsearch(ip, desc->vec, desc->nr_entries, + if (unlikely(text_poke_array.nr_entries > 1)) { + tp =3D __inline_bsearch(ip, text_poke_array.vec, text_poke_array.nr_entr= ies, sizeof(struct smp_text_poke_loc), patch_cmp); if (!tp) goto out_put; } else { - tp =3D desc->vec; + tp =3D text_poke_array.vec; if (text_poke_addr(tp) !=3D ip) goto out_put; } --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 27B85298CD7 for ; Fri, 11 Apr 2025 05:42: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=1744350151; cv=none; b=Qxs1rbguH7XGD2C7VX9cJiUlc71iXjHvVlJEs0Vp4a/75IMNW6rb4n5NaKw/xQlAwY5ORD2h3L29M3P3PO2rQknBJr1V/McuhPJ+XYnFD/qi7asv7pjrYc/UcGE91btooikJUlNoemZxT7E+xcjWCPPptuIyXrdkgnYxCgTJStY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350151; c=relaxed/simple; bh=mrD1rbGrQKN82oUVMkFYkr3GJMh92Eu93Tf8zWhbpEE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OnpdMud/WuQr1zcaBSREGmRH+k7OKi+iheBuWFUcID7TxZlYKGQfpix+3Dxdekt9cSn8LfiTydYCnYBvSvJmy/OXsiuTWP7ZTpcG87bSzfl1HXymqH6BtW/89jgUBRhMRb6B3fQVF8Q9r1HP6YSjFPnEmYqpA9Y+IH6KT+pZCps= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Ymbq4C3T; 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="Ymbq4C3T" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20F45C4CEE5; Fri, 11 Apr 2025 05:42:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350151; bh=mrD1rbGrQKN82oUVMkFYkr3GJMh92Eu93Tf8zWhbpEE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ymbq4C3TXAbCufiGsXN5PPR6HRdN+LtdwcoTQnmKx8D2LhTZ98ECMZjLMsYQjbYu8 e9imqLCJGpRZXZ+R7SOaEUcJekFEECdAJgQZ09fJNTOMnlGcTkl1Gh1WvaLWL/1uU5 vlf3L2t6rqLAZ30xW4VSk/XGuzE2ZzEojDuVgKD3t5IKJzdE/zmoMo1X/l2E/PowLE us7hLoOF6SQERFR6ZQhyA60zkRGONphAIEjZ90oo96QqRxUFGHwN/+h4ihNwQc+lFm qX/vN2t4OyfhiSbAOqDqo5dK/7vFb875Ym5TFc++yA313cA2vtrYkfjYSLw5EegbUt h9RpobN3Fn3wg== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 33/53] x86/alternatives: Simplify smp_text_poke_batch_process() Date: Fri, 11 Apr 2025 07:40:45 +0200 Message-ID: <20250411054105.2341982-34-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-1-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This function is now using the text_poke_array state exclusively, make that explicit by removing the redundant input parameters. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 43 ++++++++++++++++++++-------------------= ---- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index f94a715d9b2b..f5db49434020 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2591,8 +2591,8 @@ noinstr int smp_text_poke_int3_handler(struct pt_regs= *regs) =20 /** * smp_text_poke_batch_process() -- update instructions on live kernel on = SMP - * @tp: vector of instructions to patch - * @nr_entries: number of entries in the vector + * @text_poke_array.vec: vector of instructions to patch + * @text_poke_array.nr_entries: number of entries in the vector * * Modify multi-byte instruction by using int3 breakpoint on SMP. * We completely avoid stop_machine() here, and achieve the @@ -2610,7 +2610,7 @@ noinstr int smp_text_poke_int3_handler(struct pt_regs= *regs) * replacing opcode * - sync cores */ -static void smp_text_poke_batch_process(struct smp_text_poke_loc *tp, unsi= gned int nr_entries) +static void smp_text_poke_batch_process(void) { unsigned char int3 =3D INT3_INSN_OPCODE; unsigned int i; @@ -2618,9 +2618,6 @@ static void smp_text_poke_batch_process(struct smp_te= xt_poke_loc *tp, unsigned i =20 lockdep_assert_held(&text_mutex); =20 - WARN_ON_ONCE(tp !=3D text_poke_array.vec); - WARN_ON_ONCE(nr_entries !=3D text_poke_array.nr_entries); - /* * Corresponds to the implicit memory barrier in try_get_text_poke_array(= ) to * ensure reading a non-zero refcount provides up to date text_poke_array= data. @@ -2640,16 +2637,16 @@ static void smp_text_poke_batch_process(struct smp_= text_poke_loc *tp, unsigned i =20 /* * Corresponding read barrier in int3 notifier for making sure the - * nr_entries and handler are correctly ordered wrt. patching. + * text_poke_array.nr_entries and handler are correctly ordered wrt. patc= hing. */ smp_wmb(); =20 /* * First step: add a int3 trap to the address that will be patched. */ - for (i =3D 0; i < nr_entries; i++) { - tp[i].old =3D *(u8 *)text_poke_addr(&tp[i]); - text_poke(text_poke_addr(&tp[i]), &int3, INT3_INSN_SIZE); + for (i =3D 0; i < text_poke_array.nr_entries; i++) { + text_poke_array.vec[i].old =3D *(u8 *)text_poke_addr(&text_poke_array.ve= c[i]); + text_poke(text_poke_addr(&text_poke_array.vec[i]), &int3, INT3_INSN_SIZE= ); } =20 text_poke_sync(); @@ -2657,15 +2654,15 @@ static void smp_text_poke_batch_process(struct smp_= text_poke_loc *tp, unsigned i /* * Second step: update all but the first byte of the patched range. */ - for (do_sync =3D 0, i =3D 0; i < nr_entries; i++) { - u8 old[POKE_MAX_OPCODE_SIZE+1] =3D { tp[i].old, }; + for (do_sync =3D 0, i =3D 0; i < text_poke_array.nr_entries; i++) { + u8 old[POKE_MAX_OPCODE_SIZE+1] =3D { text_poke_array.vec[i].old, }; u8 _new[POKE_MAX_OPCODE_SIZE+1]; - const u8 *new =3D tp[i].text; - int len =3D tp[i].len; + const u8 *new =3D text_poke_array.vec[i].text; + int len =3D text_poke_array.vec[i].len; =20 if (len - INT3_INSN_SIZE > 0) { memcpy(old + INT3_INSN_SIZE, - text_poke_addr(&tp[i]) + INT3_INSN_SIZE, + text_poke_addr(&text_poke_array.vec[i]) + INT3_INSN_SIZE, len - INT3_INSN_SIZE); =20 if (len =3D=3D 6) { @@ -2674,7 +2671,7 @@ static void smp_text_poke_batch_process(struct smp_te= xt_poke_loc *tp, unsigned i new =3D _new; } =20 - text_poke(text_poke_addr(&tp[i]) + INT3_INSN_SIZE, + text_poke(text_poke_addr(&text_poke_array.vec[i]) + INT3_INSN_SIZE, new + INT3_INSN_SIZE, len - INT3_INSN_SIZE); =20 @@ -2705,7 +2702,7 @@ static void smp_text_poke_batch_process(struct smp_te= xt_poke_loc *tp, unsigned i * The old instruction is recorded so that the event can be * processed forwards or backwards. */ - perf_event_text_poke(text_poke_addr(&tp[i]), old, len, new, len); + perf_event_text_poke(text_poke_addr(&text_poke_array.vec[i]), old, len, = new, len); } =20 if (do_sync) { @@ -2721,16 +2718,16 @@ static void smp_text_poke_batch_process(struct smp_= text_poke_loc *tp, unsigned i * Third step: replace the first byte (int3) by the first byte of * replacing opcode. */ - for (do_sync =3D 0, i =3D 0; i < nr_entries; i++) { - u8 byte =3D tp[i].text[0]; + for (do_sync =3D 0, i =3D 0; i < text_poke_array.nr_entries; i++) { + u8 byte =3D text_poke_array.vec[i].text[0]; =20 - if (tp[i].len =3D=3D 6) + if (text_poke_array.vec[i].len =3D=3D 6) byte =3D 0x0f; =20 if (byte =3D=3D INT3_INSN_OPCODE) continue; =20 - text_poke(text_poke_addr(&tp[i]), &byte, INT3_INSN_SIZE); + text_poke(text_poke_addr(&text_poke_array.vec[i]), &byte, INT3_INSN_SIZE= ); do_sync++; } =20 @@ -2859,7 +2856,7 @@ static bool text_poke_addr_ordered(void *addr) void smp_text_poke_batch_finish(void) { if (text_poke_array.nr_entries) { - smp_text_poke_batch_process(text_poke_array.vec, text_poke_array.nr_entr= ies); + smp_text_poke_batch_process(); text_poke_array.nr_entries =3D 0; } } @@ -2869,7 +2866,7 @@ static void smp_text_poke_batch_flush(void *addr) lockdep_assert_held(&text_mutex); =20 if (text_poke_array.nr_entries =3D=3D TP_ARRAY_NR_ENTRIES_MAX || !text_po= ke_addr_ordered(addr)) { - smp_text_poke_batch_process(text_poke_array.vec, text_poke_array.nr_entr= ies); + smp_text_poke_batch_process(); text_poke_array.nr_entries =3D 0; } } --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 E665429AAF9 for ; Fri, 11 Apr 2025 05:42: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=1744350154; cv=none; b=OtLjbxECkKirPNRX1NpCuL3QuZvUeDI9i3QIwqjALQg9mWuyw0mYBO3bGQbGAoWmf6d20E25UUpjEJAAZ4Tu8Lf0lcZSkpFTaxIt3ZykieENHLanZE/lzidKHSNL+p+RgVu98IKFUEvqdfPojfn4nOjDr8SzX8N8JC5TLFxFsro= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350154; c=relaxed/simple; bh=q1y1UU8TtQ+UI5bgfeVUW4m4YLJuEiZphDRwAd5ABZ4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=q3lIIqu9Wwqm5vnQnkcsXiWmecFXehyMTGyaRs/kvKVR62lB5sLSFa6ACPl8TthufwNrzBYKiiL/zS06v46jakJ2U1ltcqxcM6i3BqCI8cgdBKzdIuxEJfSV2ZgkdeHzcBYOSIW/UN129PbkGenWp/uVA36y9qoj4L1MmA93r9U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IyrgE0Qx; 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="IyrgE0Qx" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D33EC4CEE2; Fri, 11 Apr 2025 05:42:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350153; bh=q1y1UU8TtQ+UI5bgfeVUW4m4YLJuEiZphDRwAd5ABZ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IyrgE0QxM/V0Wh0hopGfOI7aKzNm5tumHlayL8UPp7LxaMdkbF+8W6vNng/PntyX6 ZhPujfX0C/8zH0jJVM31VMMjWXpUrZfDXsMEX945uazMtp9oJlIHvpMREy3v7R4XMh O+r1UYgrJAJdN9VfjKuNBR7Q/cY0tNqKPh4mN0BrD3CGRdINFlZAWyV4m6bh5kX+U4 Wx+CeuxbX/S175YqOdgyJAN7J0KHWMnreswpeoXSkHcU3vezZlWcllNR84mreUbVHU YIm9TKJ1325TXg828WmstJQ9JUrq12Gk4+YDw3SzXJWUHMZXZVnqFAX8zQaGXDyIYy 7YyABrCDAUMmQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 34/53] x86/alternatives: Rename 'int3_refs' to 'text_poke_array_refs' Date: Fri, 11 Apr 2025 07:40:46 +0200 Message-ID: <20250411054105.2341982-35-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-1-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Make it clear that these reference counts lock access to text_poke_array. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index f5db49434020..08ac3c7ad6f8 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2473,11 +2473,11 @@ static struct smp_text_poke_array { struct smp_text_poke_loc vec[TP_ARRAY_NR_ENTRIES_MAX]; } text_poke_array; =20 -static DEFINE_PER_CPU(atomic_t, int3_refs); +static DEFINE_PER_CPU(atomic_t, text_poke_array_refs); =20 static __always_inline bool try_get_text_poke_array(void) { - atomic_t *refs =3D this_cpu_ptr(&int3_refs); + atomic_t *refs =3D this_cpu_ptr(&text_poke_array_refs); =20 if (!raw_atomic_inc_not_zero(refs)) return false; @@ -2487,7 +2487,7 @@ static __always_inline bool try_get_text_poke_array(v= oid) =20 static __always_inline void put_text_poke_array(void) { - atomic_t *refs =3D this_cpu_ptr(&int3_refs); + atomic_t *refs =3D this_cpu_ptr(&text_poke_array_refs); =20 smp_mb__before_atomic(); raw_atomic_dec(refs); @@ -2522,9 +2522,9 @@ noinstr int smp_text_poke_int3_handler(struct pt_regs= *regs) * Having observed our INT3 instruction, we now must observe * text_poke_array with non-zero refcount: * - * int3_refs =3D 1 INT3 + * text_poke_array_refs =3D 1 INT3 * WMB RMB - * write INT3 if (int3_refs !=3D 0) + * write INT3 if (text_poke_array_refs !=3D 0) */ smp_rmb(); =20 @@ -2623,7 +2623,7 @@ static void smp_text_poke_batch_process(void) * ensure reading a non-zero refcount provides up to date text_poke_array= data. */ for_each_possible_cpu(i) - atomic_set_release(per_cpu_ptr(&int3_refs, i), 1); + atomic_set_release(per_cpu_ptr(&text_poke_array_refs, i), 1); =20 /* * Function tracing can enable thousands of places that need to be @@ -2745,7 +2745,7 @@ static void smp_text_poke_batch_process(void) * unused. */ for_each_possible_cpu(i) { - atomic_t *refs =3D per_cpu_ptr(&int3_refs, i); + atomic_t *refs =3D per_cpu_ptr(&text_poke_array_refs, i); =20 if (unlikely(!atomic_dec_and_test(refs))) atomic_cond_read_acquire(refs, !VAL); --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 E937529AB0F for ; Fri, 11 Apr 2025 05:42:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350156; cv=none; b=JCGTivkqafS7ZD520kGRiVgDEF8JU8907YlVnlp4c/3iG4REH/NStd1pANHBR5VsU/F809BMrrxgYpzamOZH1db4gJklIGgaUWFzEUorR5I85jsjRX1Ev5aqDfUcmYH8+Qf3r6HFGTArhwYRZ0C1F4Aho30RBEMC9xCr+fIsN1Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350156; c=relaxed/simple; bh=lktWMWsyBreqWNLqEhBiEo/wBoVvh7RxDk06AUoYyn4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rKRTiGycerIS25FXi5/YaZrkAR5HFG2DrCr2g4u6ILuOhAYKCOq12Qm7+zVGinHW5mrkat8wl3XSGXLwXliHhR2c2crjxafWa8ZZAxdUaxrqh9wYmP4Zi09Ehf9kEVfwE/uXu9ZweP3BZwCgoEjlBcbfgf8moJC3sebKYdwKhGw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mJtiEEbF; 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="mJtiEEbF" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DC343C4CEE9; Fri, 11 Apr 2025 05:42:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350155; bh=lktWMWsyBreqWNLqEhBiEo/wBoVvh7RxDk06AUoYyn4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mJtiEEbFAFB4LHagFiVhAOaLhevNpyfWDVx5GK/6PcsPgzpI4rRMruaK8SSVpbZCi vV2XnOo87TOBomq0R9oSDau9/1xmwRocspQ2HfGENUT2V4HPt60RWbCo4Tjk98Ho1z SmeNrbc9RVJmgvHEeY/aCIeho2Z1SLNn83Q6eO88efaSzAdZhlZjni0N4RI8Oe0BB9 XKY2DSqHrkkFfM1ATUFT6fgySYatL83MsFWdvnd2EZ6/1fO1pNRHR6MJxj/Qdplhs1 oAjUNBf6ILN3n6/DcdN6PP7C+B+PMONr+YMFwSGivhX+6q/O7+q3TcHpZBPOWQXtyl 0iBbd52SsObPw== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 35/53] x86/alternatives: Move the text_poke_array manipulation into text_poke_int3_loc_init() and rename it to __smp_text_poke_batch_add() Date: Fri, 11 Apr 2025 07:40:47 +0200 Message-ID: <20250411054105.2341982-36-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-1-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This simplifies the code and code generation a bit: text data bss dec hex filename 14802 1029 4112 19943 4de7 alternative.o.before 14784 1029 4112 19925 4dd5 alternative.o.after Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 08ac3c7ad6f8..eb0da270043b 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2752,12 +2752,14 @@ static void smp_text_poke_batch_process(void) } } =20 -static void text_poke_int3_loc_init(struct smp_text_poke_loc *tp, void *ad= dr, - const void *opcode, size_t len, const void *emulate) +static void __smp_text_poke_batch_add(void *addr, const void *opcode, size= _t len, const void *emulate) { + struct smp_text_poke_loc *tp; struct insn insn; int ret, i =3D 0; =20 + tp =3D &text_poke_array.vec[text_poke_array.nr_entries++]; + if (len =3D=3D 6) i =3D 1; memcpy((void *)tp->text, opcode+i, len-i); @@ -2873,12 +2875,8 @@ static void smp_text_poke_batch_flush(void *addr) =20 void __ref smp_text_poke_batch_add(void *addr, const void *opcode, size_t = len, const void *emulate) { - struct smp_text_poke_loc *tp; - smp_text_poke_batch_flush(addr); - - tp =3D &text_poke_array.vec[text_poke_array.nr_entries++]; - text_poke_int3_loc_init(tp, addr, opcode, len, emulate); + __smp_text_poke_batch_add(addr, opcode, len, emulate); } =20 /** @@ -2894,13 +2892,9 @@ void __ref smp_text_poke_batch_add(void *addr, const= void *opcode, size_t len, c */ void __ref smp_text_poke_single(void *addr, const void *opcode, size_t len= , const void *emulate) { - struct smp_text_poke_loc *tp; - /* Batch-patching should not be mixed with single-patching: */ WARN_ON_ONCE(text_poke_array.nr_entries !=3D 0); =20 - tp =3D &text_poke_array.vec[text_poke_array.nr_entries++]; - text_poke_int3_loc_init(tp, addr, opcode, len, emulate); - + __smp_text_poke_batch_add(addr, opcode, len, emulate); smp_text_poke_batch_finish(); } --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 7E07627EC8F for ; Fri, 11 Apr 2025 05:42: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=1744350158; cv=none; b=W60BM63ui80rt9d+IYvqTFmrpRhH1wkH58R5LITrIaemGqrojUvAcmKJbumvPGQiwQovFPp6E3GXkLN35Ev+hk4yHjy++OGB//FxKZDEhBaJ/8S++BEgqyGQEYae4T4i0HlsZjU0rOi3NazB/AQypJ+IluoapXfBM9+SCBCdZl4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350158; c=relaxed/simple; bh=HGw5sBbPivY24BHzcOkn/hmosqOGzdaca6k0lHUME1g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=J2R9Thr0rCINg3s2BKUewp0VGBFzTHUsPojIT8JO/PkToS7bYlG2DGXJlb2iCgeXeyx9dL5bnnUiS5Up3H/Je0xY7YnletBl/RZyK+jXkLWmXIbk+tpJC8DaAKvGcCz28o0NEne4+kZRfN/JLO0FI/yMf0NNc9CxIvjK6XFM/V8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iBhwWFlJ; 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="iBhwWFlJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 49816C4CEE2; Fri, 11 Apr 2025 05:42:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350158; bh=HGw5sBbPivY24BHzcOkn/hmosqOGzdaca6k0lHUME1g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iBhwWFlJfnSoNcR5toAPMp+6QfVkaH4JOSapQItB5z7KD9o9h8S235PEifSPQVTzF f5HiLRuZlkQrPoNNWmRYJUjQzKIVqFBBq3Sj/FiMGxE0NtvkO8Piv0UR0lHszn24k+ KOhpKsAgNLP7ijS7sfUBgUzhrCTGiL0/hS86CrMw52Gfze4gpAsFdTcPi1CLbmtBL/ UldkNMDBYZmUzH0Ztp+G860b+Jk6Ts9gQiW9Q2BiKZZtk8neQjvvVvi8pCmnIbpQkZ xNxRbYj7vAhSC76lz0TnLfBgHpbSGICDt04XU+gewDjCZQPAIHZK1nWKIG+jn29/sv TsrHNJPYNncyw== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 36/53] x86/alternatives: Remove the mixed-patching restriction on smp_text_poke_single() Date: Fri, 11 Apr 2025 07:40:48 +0200 Message-ID: <20250411054105.2341982-37-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-1-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" At this point smp_text_poke_single(addr, opcode, len, emulate) is equivalen= t to: smp_text_poke_batch_add(addr, opcode, len, emulate); smp_text_poke_batch_finish(); So remove the restriction on mixing single-instruction patching with multi-instruction patching. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index eb0da270043b..f0bb2158f27b 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2892,9 +2892,6 @@ void __ref smp_text_poke_batch_add(void *addr, const = void *opcode, size_t len, c */ void __ref smp_text_poke_single(void *addr, const void *opcode, size_t len= , const void *emulate) { - /* Batch-patching should not be mixed with single-patching: */ - WARN_ON_ONCE(text_poke_array.nr_entries !=3D 0); - __smp_text_poke_batch_add(addr, opcode, len, emulate); smp_text_poke_batch_finish(); } --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 B2C7027EC83 for ; Fri, 11 Apr 2025 05:42:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350160; cv=none; b=ctC+QhxCQmT9kJqX6j2PRPykrPIBhVNYC0qT8AhuCi6XYqjKKl7oBl6MoPtLOtutNePnpCfYuCW/8SgSiGHWNCYKKkK3lWagRE29LIK5hcDkjzO0fc1hca9JMcWywXsnMlNfav/jRiVI/fqHtN5eolyQlYRXrSYh42GmmZWqiFs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350160; c=relaxed/simple; bh=8IVnwtasieQj9t3fVVSgTrFtPxkH9TpWV5p25obbWs4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GzaUtyZXCN4rNVDtqfovMJshY8YYOxw1HbqKfurc7YwHzT7iLmo9o/QwQfVfTgu7XZlxqGh+QbRRp5k25gFEHeTfvgMOt8N9guT08XRnj70rlrcZh7hpp5XVOlP9plZosCK3y5vTTk7vDVpjDso0lFqycUYZtJUMwRR9K/Bvjgc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kiEYpPBC; 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="kiEYpPBC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA712C4CEE2; Fri, 11 Apr 2025 05:42:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350160; bh=8IVnwtasieQj9t3fVVSgTrFtPxkH9TpWV5p25obbWs4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kiEYpPBCB0VDGMI/axO7VRnVP9psx9Wpz59ICjJQmqnuCYT3BSe0VRNn/7Hj00uBv ngwv1flW9MmQGVfsWmqhyj08Si/HIDqkAEsSLhQFSSdwWHPEVD1ZJvzs4bpUTq+rJz QyESsVTtw892nGmTtLOcI9AKkOWE2ZYQJqYiMKyQB8AzeqwxKJO7A1KCUjKYg01Vwp 4Y2viO9jYbbuftSLFg4ydEaGbNaGHOyC1X7/CLFOMJ75QL6e5nf/5c/lfuZW2VMl3g byVp3iSQayTEB8VfPSbkgavay4EZ71vGB7NvV4nYRzIMA37yk3ZdsFw439ZGyfLEhv 2dwKlWrlfb5UA== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 37/53] x86/alternatives: Document 'smp_text_poke_single()' Date: Fri, 11 Apr 2025 07:40:49 +0200 Message-ID: <20250411054105.2341982-38-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-1-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Extend the documentation to better describe its purpose. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index f0bb2158f27b..a9726cc96972 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2880,7 +2880,7 @@ void __ref smp_text_poke_batch_add(void *addr, const = void *opcode, size_t len, c } =20 /** - * smp_text_poke_single() -- update instructions on live kernel on SMP + * smp_text_poke_single() -- update instruction on live kernel on SMP imme= diately * @addr: address to patch * @opcode: opcode of new instruction * @len: length to copy @@ -2888,7 +2888,8 @@ void __ref smp_text_poke_batch_add(void *addr, const = void *opcode, size_t len, c * * Update a single instruction with the vector in the stack, avoiding * dynamically allocated memory. This function should be used when it is - * not possible to allocate memory. + * not possible to allocate memory for a vector. The single instruction + * is patched in immediately. */ void __ref smp_text_poke_single(void *addr, const void *opcode, size_t len= , const void *emulate) { --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 7CFA227F4C0 for ; Fri, 11 Apr 2025 05:42: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=1744350163; cv=none; b=kf1mbGkFIiJsu3b6l4SxaPxReiRXl+QSZtj5A+3u3nd1ggjv9N5SFIv2IYwBJPVifMH5f+Dyl4HfN4GfpMEcE8LGM0bbjj47bayBFNoCH+NeoibZz53XbuW0lishtPTaLz9mtTBhJdEo7k2lv7KkjddKtUc6JiV4xmPNx6UBCd8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350163; c=relaxed/simple; bh=ToLj5zu3BJSFtDe7BjL5JSTUEqkeAeZC5sBV0v/uvzE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s/asb9xURfGMnSWdUxx4tPZ1JtYO+JwjRIyb9Jw6ML/ULK9WX5c1ihepbTBO92b3ceoWGmu34StnIaTlgUSX/wu4zTDz1Pq2F0Sb6nz1XJBiGi8iZ/0j1GGZbLSpOBFcDu85VOPSo8j9PigtBDiatyel4H5tj7YuDuWCsZD0THw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rZ0p0cd6; 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="rZ0p0cd6" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 137D1C4CEE9; Fri, 11 Apr 2025 05:42:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350163; bh=ToLj5zu3BJSFtDe7BjL5JSTUEqkeAeZC5sBV0v/uvzE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rZ0p0cd69yZl1br6CmP6K2aCUzASnXg8SR1U1hBanpwz5Fdfhur0ycT4gNL4kqvY+ sl0U/eo1hvjmv1xpvtcKKgx9X4PnqZwUp4GphARIGbKIeS0gKO/0cbWIG9HqdoxcP3 F9uJeQhcZhXFPE1o+EGI3Oz+jNFhxj/SDUmIUPtXwOZHoFeIV081YJV78hCL6BYsvs g/McyurU4/nZ5kRxDo4R0Q41cz5fTz1wVj51d89WEbAWEfynBtjsLTWgWLf3ObFHkX pOIKnXcrB6Nq52e3TWsgsR8dHsP+jyetFypISYIgQAtNJTkDvuS1Ee67/PydsoWV6k 5G86uL9v4S6aQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 38/53] x86/alternatives: Add documentation for smp_text_poke_batch_add() Date: Fri, 11 Apr 2025 07:40:50 +0200 Message-ID: <20250411054105.2341982-39-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-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 a9726cc96972..b47ad0853589 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2873,6 +2873,19 @@ static void smp_text_poke_batch_flush(void *addr) } } =20 +/** + * smp_text_poke_batch_add() -- update instruction on live kernel on SMP, = batched + * @addr: address to patch + * @opcode: opcode of new instruction + * @len: length to copy + * @emulate: instruction to be emulated + * + * Add a new instruction to the current queue of to-be-patched instructions + * the kernel maintains. The patching request will not be executed immedia= tely, + * but becomes part of an array of patching requests, optimized for batched + * execution. All pending patching requests will be executed on the next + * smp_text_poke_batch_finish() call. + */ void __ref smp_text_poke_batch_add(void *addr, const void *opcode, size_t = len, const void *emulate) { smp_text_poke_batch_flush(addr); --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 9F06129B235 for ; Fri, 11 Apr 2025 05:42:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350165; cv=none; b=CyARsCrILVzk+zuIIuwP7ObLu9dpCOFGKGK4tQVHD+T1MIghZeWO69ejt6gAz/PFrvI2h+PXIq9opA4tXr8rHtyEBhQMI7oiK4pFsbTodiSJlxhLI+eebz5WAp7+NKQG8sVe5ZxbPoT7psgeeGMQ8VKkIi5QvlZYAroJ6thmwqA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350165; c=relaxed/simple; bh=lzWWYWlpG9TKB4p/7Blvc6fnd+/o4S0RiKyCG4pICyY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qa9BRflLxRFpJXAyV0il3D3ILeD0LndIhYSLxEOiSJiUm4sVx4+iHcy0Qipps6zRtjl7XjAfdYKZ6v5CTaQMJxF9iOMgMVev/ylAjBB8Ee38dwQM4l9GLMthUXw/bJ81Aaa6TXq8+4wYS+ppuNL5BozmFlBErn7d/IRmQrNNnNo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NHgrVPYW; 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="NHgrVPYW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70523C4CEE2; Fri, 11 Apr 2025 05:42:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350165; bh=lzWWYWlpG9TKB4p/7Blvc6fnd+/o4S0RiKyCG4pICyY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NHgrVPYWOK+ZiP6CtKTCvxT+I54h2YIXnzUQsmoHKd/+rOVgzgUARqi4QKqbexQ3Z gufbNq8sA8MfwPjcxXXueyILzPpYe70Q1wJkumPbxcmzrqAMWdG1rfRe5+X7jqAOoh 0f3orVOBXGyx6QCcO/cLkk4T2Psk31Ep3lszOYa2auRgCxwWC6WwrIL7OaMa2YTyYu 5OW37aAXEuQaLxjUvwX+ZX2v+HcHC8RtS1CpK88ABqzCFZ+pdBNW6ky8HjY+HLfx74 GqnM57W4DDYff92+TEW/f4lCHt2fyVs4qH96+pXSSQ86dwbWcvTDsnrHkCwdu6ia4l SgMnIFmqt6Rfg== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 39/53] x86/alternatives: Move text_poke_array completion from smp_text_poke_batch_finish() and smp_text_poke_batch_flush() to smp_text_poke_batch_process() Date: Fri, 11 Apr 2025 07:40:51 +0200 Message-ID: <20250411054105.2341982-40-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-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 b47ad0853589..556a82f576cd 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2750,6 +2750,9 @@ static void smp_text_poke_batch_process(void) if (unlikely(!atomic_dec_and_test(refs))) atomic_cond_read_acquire(refs, !VAL); } + + /* They are all completed: */ + text_poke_array.nr_entries =3D 0; } =20 static void __smp_text_poke_batch_add(void *addr, const void *opcode, size= _t len, const void *emulate) @@ -2857,20 +2860,16 @@ static bool text_poke_addr_ordered(void *addr) =20 void smp_text_poke_batch_finish(void) { - if (text_poke_array.nr_entries) { + if (text_poke_array.nr_entries) smp_text_poke_batch_process(); - text_poke_array.nr_entries =3D 0; - } } =20 static void smp_text_poke_batch_flush(void *addr) { lockdep_assert_held(&text_mutex); =20 - if (text_poke_array.nr_entries =3D=3D TP_ARRAY_NR_ENTRIES_MAX || !text_po= ke_addr_ordered(addr)) { + if (text_poke_array.nr_entries =3D=3D TP_ARRAY_NR_ENTRIES_MAX || !text_po= ke_addr_ordered(addr)) smp_text_poke_batch_process(); - text_poke_array.nr_entries =3D 0; - } } =20 /** --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 421AF29C32F for ; Fri, 11 Apr 2025 05:42:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350168; cv=none; b=I8Y8btqOZeuvxrV/9r969QuC9OgHl416bbnmOvHp6b5NYUuKOvMLh19/H1uBuxP84qpPeE67bTvO5Q/pXuXuOeyq4ApgJjSvx8zp7m1VAYBdv0VzmGcP7/X9KElSl5YUlbBQ7nyJsF69SuTyQYCPPoFpMbKzC9ZihPG273TbyAo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350168; c=relaxed/simple; bh=+Zusv4g+u/zW0IcYKf98daAfMcPmsjKjF92ucQMyf2o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KVp7VFXrDx96ttM7kWOoNCHZoSgoXSoPzX2YycldiEEuH2uEGkQcu2WK9GPBV/aZVnEi3x18z6Y5U322H3TncaR4Ghzn6ORy/dydLaTa1F7Hjie6oc6XLWpB/wNaeDAeycA17CGrP3+Zq+uN8fUIUZG3j7caoYsYU1E1IfrN+LY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mMH4fUfS; 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="mMH4fUfS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id D13B9C4CEE2; Fri, 11 Apr 2025 05:42:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350167; bh=+Zusv4g+u/zW0IcYKf98daAfMcPmsjKjF92ucQMyf2o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mMH4fUfSkD8KcDMKcNbtQQVK5tJzNO+p9jQvXQ+vYZzrMFOiI+zWsom46GFK3INjS Bvb+CTXAA00Fo9Ek7/VUK3QWrSD6DIg3Je3VdS5iDueNeNZrV59wy3NVWEw5OLRNu9 hqdk9ITTKhkotSpxrwl/1DcVhdUhtGR1cyTwzrYdDLeZ0cmzz1KDqCrRKDJuubqp5S kf5Xy4cI433zbqek+NSQlLUh1sD7N4TQjzFivNyv/lS/3iPt8MsREew7plbndv9/0d LrULnHtY5XiRHkTws7q10MRLQ9b6cjETSybY8R1taogqO+N7I+W6Nnv3doz8Ql0eUh e60vbxw/MxBSg== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 40/53] x86/alternatives: Rename 'text_poke_sync()' to 'smp_text_poke_sync_each_cpu()' Date: Fri, 11 Apr 2025 07:40:52 +0200 Message-ID: <20250411054105.2341982-41-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-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 f3c9b70afb0c..d9dbbe9d9667 100644 --- a/arch/x86/include/asm/text-patching.h +++ b/arch/x86/include/asm/text-patching.h @@ -32,7 +32,7 @@ extern void apply_relocation(u8 *buf, const u8 * const in= str, size_t instrlen, u * an inconsistent instruction while you patch. */ extern void *text_poke(void *addr, const void *opcode, size_t len); -extern void text_poke_sync(void); +extern void smp_text_poke_sync_each_cpu(void); extern void *text_poke_kgdb(void *addr, const void *opcode, size_t len); extern void *text_poke_copy(void *addr, const void *opcode, size_t len); #define text_poke_copy text_poke_copy diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 556a82f576cd..e4c51d81a72f 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2445,7 +2445,7 @@ static void do_sync_core(void *info) sync_core(); } =20 -void text_poke_sync(void) +void smp_text_poke_sync_each_cpu(void) { on_each_cpu(do_sync_core, NULL, 1); } @@ -2469,8 +2469,8 @@ struct smp_text_poke_loc { #define TP_ARRAY_NR_ENTRIES_MAX (PAGE_SIZE / sizeof(struct smp_text_poke_l= oc)) =20 static struct smp_text_poke_array { - int nr_entries; struct smp_text_poke_loc vec[TP_ARRAY_NR_ENTRIES_MAX]; + int nr_entries; } text_poke_array; =20 static DEFINE_PER_CPU(atomic_t, text_poke_array_refs); @@ -2649,7 +2649,7 @@ static void smp_text_poke_batch_process(void) text_poke(text_poke_addr(&text_poke_array.vec[i]), &int3, INT3_INSN_SIZE= ); } =20 - text_poke_sync(); + smp_text_poke_sync_each_cpu(); =20 /* * Second step: update all but the first byte of the patched range. @@ -2711,7 +2711,7 @@ static void smp_text_poke_batch_process(void) * not necessary and we'd be safe even without it. But * better safe than sorry (plus there's not only Intel). */ - text_poke_sync(); + smp_text_poke_sync_each_cpu(); } =20 /* @@ -2732,13 +2732,13 @@ static void smp_text_poke_batch_process(void) } =20 if (do_sync) - text_poke_sync(); + smp_text_poke_sync_each_cpu(); =20 /* * Remove and wait for refs to be zero. * * Notably, if after step-3 above the INT3 got removed, then the - * text_poke_sync() will have serialized against any running INT3 + * smp_text_poke_sync_each_cpu() will have serialized against any running= INT3 * handlers and the below spin-wait will not happen. * * IOW. unless the replacement instruction is INT3, this case goes diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c index 09608fd93687..47cb8eb138ba 100644 --- a/arch/x86/kernel/kprobes/core.c +++ b/arch/x86/kernel/kprobes/core.c @@ -808,7 +808,7 @@ void arch_arm_kprobe(struct kprobe *p) u8 int3 =3D INT3_INSN_OPCODE; =20 text_poke(p->addr, &int3, 1); - text_poke_sync(); + smp_text_poke_sync_each_cpu(); perf_event_text_poke(p->addr, &p->opcode, 1, &int3, 1); } =20 @@ -818,7 +818,7 @@ void arch_disarm_kprobe(struct kprobe *p) =20 perf_event_text_poke(p->addr, &int3, 1, &p->opcode, 1); text_poke(p->addr, &p->opcode, 1); - text_poke_sync(); + smp_text_poke_sync_each_cpu(); } =20 void arch_remove_kprobe(struct kprobe *p) diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c index 9307a40f4983..0aabd4c4e2c4 100644 --- a/arch/x86/kernel/kprobes/opt.c +++ b/arch/x86/kernel/kprobes/opt.c @@ -513,11 +513,11 @@ void arch_unoptimize_kprobe(struct optimized_kprobe *= op) JMP32_INSN_SIZE - INT3_INSN_SIZE); =20 text_poke(addr, new, INT3_INSN_SIZE); - text_poke_sync(); + smp_text_poke_sync_each_cpu(); text_poke(addr + INT3_INSN_SIZE, new + INT3_INSN_SIZE, JMP32_INSN_SIZE - INT3_INSN_SIZE); - text_poke_sync(); + smp_text_poke_sync_each_cpu(); =20 perf_event_text_poke(op->kp.addr, old, JMP32_INSN_SIZE, new, JMP32_INSN_S= IZE); } diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c index a7998f351701..231d6326d1fd 100644 --- a/arch/x86/kernel/module.c +++ b/arch/x86/kernel/module.c @@ -206,7 +206,7 @@ static int write_relocate_add(Elf64_Shdr *sechdrs, write, apply); =20 if (!early) { - text_poke_sync(); + smp_text_poke_sync_each_cpu(); mutex_unlock(&text_mutex); } =20 --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 44EDD29C339 for ; Fri, 11 Apr 2025 05:42: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=1744350170; cv=none; b=YnrBqPoTvNWwj8Iuxrop/HWBRUqCv802Qq8/fVV23m160nER16I2kwuv0wprbwCNwaEapO9u8Kz9jfZ9iCMyFT+QAtQjVU0PCzdM0Mg7SjDLDcqUHx3SaqA7yYpSLBf6aa6g6hwNph2SPOlGZLSRK+lQMulG0K5Yjp9Nx+3GU+Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350170; c=relaxed/simple; bh=c7hl833vaOXPDceZ4VYoTj+KEMlhRXA+jNoUUU6pIbE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C86TaLPqgE/IEuhmaB0aePcqfENsnRjQCPkxOXWI+D9LJSi6IYLxNCUD8L6hq1EK67RNm4MKHHc4br9IUhTJOEufE5m924wKEwxzXgYyCBGag1XhBCIKMiBWu+EA3WAx0MggplJ762EylHTMEFxGz+XopFSDwl8HGbhNEWOXadc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WvAWmSB4; 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="WvAWmSB4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 39E73C4CEE5; Fri, 11 Apr 2025 05:42:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350170; bh=c7hl833vaOXPDceZ4VYoTj+KEMlhRXA+jNoUUU6pIbE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WvAWmSB43lT8BPWWGWkoP00HBGDbKFbfWlXHO/ag55fe0HzLlJ6qPf2dBz8DhXtYR 47mdei15TvPEuHgflbjeeBn534Yc93Rh2f//JKiQ/JL3OryUZLBHG0jZamcWKuvpGs kE9UVe+AqyGRm2oBk/vs413yQSRfTmAokVa9r13o7/7RGF5hM+qVF3goG+X9wYFSLj 4Qn2Vplio+t80Zht4dZP7EIU4rTbqc5y+mTv/nURk9kX8diT3B9zYRn9KjAoCUtxsJ +UKQaygMQQMIyU3RwWvmLLVJbUCULstXE4q+fV5CxbtGkk17WUcjzyoHjLmK8YUscl aRU4zAIAl/ADA== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 41/53] x86/alternatives: Simplify text_poke_addr_ordered() Date: Fri, 11 Apr 2025 07:40:53 +0200 Message-ID: <20250411054105.2341982-42-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-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 e4c51d81a72f..a747b0885f9a 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2838,8 +2838,6 @@ static void __smp_text_poke_batch_add(void *addr, con= st void *opcode, size_t len */ static bool text_poke_addr_ordered(void *addr) { - struct smp_text_poke_loc *tp; - WARN_ON_ONCE(!addr); =20 if (!text_poke_array.nr_entries) @@ -2851,8 +2849,7 @@ static bool text_poke_addr_ordered(void *addr) * is violated and we must first flush all pending patching * requests: */ - tp =3D &text_poke_array.vec[text_poke_array.nr_entries-1]; - if ((unsigned long)text_poke_addr(tp) > (unsigned long)addr) + if (text_poke_addr(text_poke_array.vec + text_poke_array.nr_entries-1) > = addr) return false; =20 return true; --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 0266829C358 for ; Fri, 11 Apr 2025 05:42:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350173; cv=none; b=M2DIeECBixyQrotg+Xd5FuP9NHvqW9JN9pd1+4DFEgvXpF0Cm44+551M+V/+lIimDnfzPW3ZVu1iug++D10CPvWDPQWONcd/7w8PSelmEI+m7bZL6TOORujEk2T6nvO6WR39I8OWaGdkAJ7p8cV35dovkD2jLauPJsTjYtEkjAI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350173; c=relaxed/simple; bh=O2zkaR2kW2P6AgmlTPYVLnVaHIZDOoTZSfQFD0K2MAI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Sl2DX0JmRxRhZv31zCSE8gSKJzE8Br07v/U3OCtZy+q+L5maRJOZg7XNt+oL3nzmeZWNdNVrgIQr3EPKqPsZaFTe+2TcbD1lGwFfLof3cfGURJx1AGflRV3QlveklQaubd4fXQc0+Fug5LjmE9W+urU0u0sACUzEOkKBEocCzYU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=fzeuMb3o; 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="fzeuMb3o" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97C20C4CEE2; Fri, 11 Apr 2025 05:42:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350172; bh=O2zkaR2kW2P6AgmlTPYVLnVaHIZDOoTZSfQFD0K2MAI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fzeuMb3ofgXIUCY4TZLT0C6hYH0wIMi6zEt3ZlBsWEvfr4GaMuYfsz1Vv4cM20o81 FMT19HLaFjBengRs+oE9W9+23f34KuTjcti/qNa3VbBtc+1k7FfNVT9BQs5P1tYMR3 NzmYDNxsqgzq4ZbR8Wg4t3Hogkqw3IZIe/cyu0Nb0OfaSgWliihdnvsipIfDHzZ4ra p2SK+30TqCLFtqQhHLLuVr3nDwgkWQnVLWDUgXXs2GUkg0TBnPXLb0DvDkKUibRhZQ P1VDmmJiHfpq38+w9LkY0v9oA70923lwyc/KRHJTCb53y2BCdN1TgyndKtAiNGTkoP az6AOmYImeoCQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 42/53] x86/alternatives: Constify text_poke_addr() Date: Fri, 11 Apr 2025 07:40:54 +0200 Message-ID: <20250411054105.2341982-43-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-1-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This will also allow the simplification of patch_cmp(). Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index a747b0885f9a..14ca17dc36e8 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2493,7 +2493,7 @@ static __always_inline void put_text_poke_array(void) raw_atomic_dec(refs); } =20 -static __always_inline void *text_poke_addr(struct smp_text_poke_loc *tp) +static __always_inline void *text_poke_addr(const struct smp_text_poke_loc= *tp) { return _stext + tp->rel_addr; } --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 6449127F4E4 for ; Fri, 11 Apr 2025 05:42: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=1744350176; cv=none; b=lp5IgBNBVqKecl0gEoj34US3r+QRe0HfSKFkQYUGHyOeTYIMsdusOcyk+K0UC3QWvV+7bavXWYP0bpUcMQkWBzgScsC42OJmh0JLksXQmpeoT7MnD8XdWsb75xsiRl5eaaLa4RSVm9lHwC9kqdHiVfSQvFIsD31kXjh/BEJRHc4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350176; c=relaxed/simple; bh=6zdgSV9K8OdJ8/4BsSMe+UCengCTWOkuOFeCX5WC8VU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EQXGFSZBWcX+Pl/CEESQkUrSjDoOF8R2AJcKIOt9EnfSJ4gLUImtFy5RovH0+62HNOQJ2ubWeqi20OFdPIJJd7x4g7kf/s/Uv3WgFdHX8q2lIxwuVKLqfLy0Kk6TT55NLmJ63z62pcEcoFA+hqGG1adnNDfO74DEBmEm9185hqM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=PzISamqg; 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="PzISamqg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 08D76C4CEE9; Fri, 11 Apr 2025 05:42:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350174; bh=6zdgSV9K8OdJ8/4BsSMe+UCengCTWOkuOFeCX5WC8VU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PzISamqgxRCstxoLN0GELLHQzkrYfaviJmMg7Zhn7Ej320+fJ+KHzYCA4qhImhNHG yOFvhWr2+RIrXeiI2AKs/OOXiYnabjnErPtGAwWURsp4u1OEjZSumpSHgr56YIsMgz cio4BPjltomfR0rpqnwnP1AyWLAvqNdalaHkpkDup1eUgAEXIhACZWJIedW8zU4fyg ZgKWQlQj8UINj4TRuS4nufhdlzHms9ofRWMgqKSP9mhY641coLDop0miEPQbyHJxU5 PpBth1W1ZN8SefN/BtdKLmn0ZWnwrUYxDaIXjJgE6zXlh3QChtLt3RvELjbigTti7U zYccJFqYLCiWQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 43/53] x86/alternatives: Simplify and clean up patch_cmp() Date: Fri, 11 Apr 2025 07:40:55 +0200 Message-ID: <20250411054105.2341982-44-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-1-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" - No need to cast over to 'struct smp_text_poke_loc *', void * is just fine for a binary search, - Use the canonical (a, b) input parameter nomenclature of cmp_func_t functions and rename the input parameters from (tp, elt) to (tpl_a, tpl_b). Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 14ca17dc36e8..f278655f0950 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2498,13 +2498,11 @@ static __always_inline void *text_poke_addr(const s= truct smp_text_poke_loc *tp) return _stext + tp->rel_addr; } =20 -static __always_inline int patch_cmp(const void *key, const void *elt) +static __always_inline int patch_cmp(const void *tpl_a, const void *tpl_b) { - struct smp_text_poke_loc *tp =3D (struct smp_text_poke_loc *) elt; - - if (key < text_poke_addr(tp)) + if (tpl_a < text_poke_addr(tpl_b)) return -1; - if (key > text_poke_addr(tp)) + if (tpl_a > text_poke_addr(tpl_b)) return 1; return 0; } --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 D224A29CB37 for ; Fri, 11 Apr 2025 05:42:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350177; cv=none; b=U2ME3o/e4r//mmylipX89pmLwg/0IVrSMxAIREteWsEJDctjWW45OQ4XTqNq6lhV4B9nCLY5WeyMTTRzwDNWzgYk4PRWiTGWBCs5BxeMX0mYgvwqb57WxFrlyjd2TXVRPuBuO3BzuzdIWADxUkzU8uOEoFQLN8s8oHHTexbkaxw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350177; c=relaxed/simple; bh=wCp+fBmivejOSZgdsFJX2TiROPoQzwLCwR2oz4Urcog=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eA+C94vGt9XVI4ssKxb6QftEtuTy6Iuq76CrW3nLP3a2VfU7TnVrRI8O4qpPHhxcCXYvLZZJsb7E3tybh608zEa/5cA4jiI+WrgJhJ98xM7lubPH+5ZzlKDAxaIWRRWExtqekgAHB9qiT9UvhXUahpcOGJj901lYlT0HmsIgrUs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=q87hJNBw; 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="q87hJNBw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 62F1FC4CEE2; Fri, 11 Apr 2025 05:42:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350177; bh=wCp+fBmivejOSZgdsFJX2TiROPoQzwLCwR2oz4Urcog=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q87hJNBwO0IjPQFlLFkiQwBTWsSR1FKtNmovQPrNqaRusTjVENP2cMDdybJ2+aGn2 a6CI9S/fx33KX3PNefxqwbxYli1BD18tcGKpnukIFEJVy3Oo7iMFozpSasHpQehiuy S06jds+71WHW1WvU3y0ufK7SEVhnc10p88nhRt8fe60Jl87baMQkHAP7SYKTihKz+G SVmBt7/y7zEM+J5STcM2SHcw1K/6ffFc1GzrkJvjiYfoAl2Gf6aMsITijDGyEJ3Ayw 0/5G7lKdPGg9Vm1nWNhRH2PxskPa7HhwtqT/5TzTTDzbSb6VxQK4PT9EC72hkkr99b X6T1+1KrT1/1Q== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 44/53] x86/alternatives: Standardize on 'tpl' local variable names for 'struct smp_text_poke_loc *' Date: Fri, 11 Apr 2025 07:40:56 +0200 Message-ID: <20250411054105.2341982-45-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-1-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" There's no toilet paper in this code. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 54 +++++++++++++++++++++------------------= ---- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index f278655f0950..c5abcf95daea 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2493,9 +2493,9 @@ static __always_inline void put_text_poke_array(void) raw_atomic_dec(refs); } =20 -static __always_inline void *text_poke_addr(const struct smp_text_poke_loc= *tp) +static __always_inline void *text_poke_addr(const struct smp_text_poke_loc= *tpl) { - return _stext + tp->rel_addr; + return _stext + tpl->rel_addr; } =20 static __always_inline int patch_cmp(const void *tpl_a, const void *tpl_b) @@ -2509,7 +2509,7 @@ static __always_inline int patch_cmp(const void *tpl_= a, const void *tpl_b) =20 noinstr int smp_text_poke_int3_handler(struct pt_regs *regs) { - struct smp_text_poke_loc *tp; + struct smp_text_poke_loc *tpl; int ret =3D 0; void *ip; =20 @@ -2538,20 +2538,20 @@ noinstr int smp_text_poke_int3_handler(struct pt_re= gs *regs) * Skip the binary search if there is a single member in the vector. */ if (unlikely(text_poke_array.nr_entries > 1)) { - tp =3D __inline_bsearch(ip, text_poke_array.vec, text_poke_array.nr_entr= ies, + tpl =3D __inline_bsearch(ip, text_poke_array.vec, text_poke_array.nr_ent= ries, sizeof(struct smp_text_poke_loc), patch_cmp); - if (!tp) + if (!tpl) goto out_put; } else { - tp =3D text_poke_array.vec; - if (text_poke_addr(tp) !=3D ip) + tpl =3D text_poke_array.vec; + if (text_poke_addr(tpl) !=3D ip) goto out_put; } =20 - ip +=3D tp->len; + ip +=3D tpl->len; =20 - switch (tp->opcode) { + switch (tpl->opcode) { case INT3_INSN_OPCODE: /* * Someone poked an explicit INT3, they'll want to handle it, @@ -2564,16 +2564,16 @@ noinstr int smp_text_poke_int3_handler(struct pt_re= gs *regs) break; =20 case CALL_INSN_OPCODE: - int3_emulate_call(regs, (long)ip + tp->disp); + int3_emulate_call(regs, (long)ip + tpl->disp); break; =20 case JMP32_INSN_OPCODE: case JMP8_INSN_OPCODE: - int3_emulate_jmp(regs, (long)ip + tp->disp); + int3_emulate_jmp(regs, (long)ip + tpl->disp); break; =20 case 0x70 ... 0x7f: /* Jcc */ - int3_emulate_jcc(regs, tp->opcode & 0xf, (long)ip, tp->disp); + int3_emulate_jcc(regs, tpl->opcode & 0xf, (long)ip, tpl->disp); break; =20 default: @@ -2755,33 +2755,33 @@ static void smp_text_poke_batch_process(void) =20 static void __smp_text_poke_batch_add(void *addr, const void *opcode, size= _t len, const void *emulate) { - struct smp_text_poke_loc *tp; + struct smp_text_poke_loc *tpl; struct insn insn; int ret, i =3D 0; =20 - tp =3D &text_poke_array.vec[text_poke_array.nr_entries++]; + tpl =3D &text_poke_array.vec[text_poke_array.nr_entries++]; =20 if (len =3D=3D 6) i =3D 1; - memcpy((void *)tp->text, opcode+i, len-i); + memcpy((void *)tpl->text, opcode+i, len-i); if (!emulate) emulate =3D opcode; =20 ret =3D insn_decode_kernel(&insn, emulate); BUG_ON(ret < 0); =20 - tp->rel_addr =3D addr - (void *)_stext; - tp->len =3D len; - tp->opcode =3D insn.opcode.bytes[0]; + tpl->rel_addr =3D addr - (void *)_stext; + tpl->len =3D len; + tpl->opcode =3D insn.opcode.bytes[0]; =20 if (is_jcc32(&insn)) { /* * Map Jcc.d32 onto Jcc.d8 and use len to distinguish. */ - tp->opcode =3D insn.opcode.bytes[1] - 0x10; + tpl->opcode =3D insn.opcode.bytes[1] - 0x10; } =20 - switch (tp->opcode) { + switch (tpl->opcode) { case RET_INSN_OPCODE: case JMP32_INSN_OPCODE: case JMP8_INSN_OPCODE: @@ -2790,14 +2790,14 @@ static void __smp_text_poke_batch_add(void *addr, c= onst void *opcode, size_t len * next instruction can be padded with INT3. */ for (i =3D insn.length; i < len; i++) - BUG_ON(tp->text[i] !=3D INT3_INSN_OPCODE); + BUG_ON(tpl->text[i] !=3D INT3_INSN_OPCODE); break; =20 default: BUG_ON(len !=3D insn.length); } =20 - switch (tp->opcode) { + switch (tpl->opcode) { case INT3_INSN_OPCODE: case RET_INSN_OPCODE: break; @@ -2806,21 +2806,21 @@ static void __smp_text_poke_batch_add(void *addr, c= onst void *opcode, size_t len case JMP32_INSN_OPCODE: case JMP8_INSN_OPCODE: case 0x70 ... 0x7f: /* Jcc */ - tp->disp =3D insn.immediate.value; + tpl->disp =3D insn.immediate.value; break; =20 default: /* assume NOP */ switch (len) { case 2: /* NOP2 -- emulate as JMP8+0 */ BUG_ON(memcmp(emulate, x86_nops[len], len)); - tp->opcode =3D JMP8_INSN_OPCODE; - tp->disp =3D 0; + tpl->opcode =3D JMP8_INSN_OPCODE; + tpl->disp =3D 0; break; =20 case 5: /* NOP5 -- emulate as JMP32+0 */ BUG_ON(memcmp(emulate, x86_nops[len], len)); - tp->opcode =3D JMP32_INSN_OPCODE; - tp->disp =3D 0; + tpl->opcode =3D JMP32_INSN_OPCODE; + tpl->disp =3D 0; break; =20 default: /* unknown instruction */ --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 C8B4E29CB51 for ; Fri, 11 Apr 2025 05:42:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350179; cv=none; b=u3/xI6LT8GmndS4k30Yxo3vsJMX5HPlKAHLg7xXZ0apz2vVsrdr5RBVyKqIXSL/vv3YGNTc+O7Or//fStSEB2hUxDzalQ10v1C73lt0794Va8If7bik4wR1POMZpqkyPyQpfcWoGZIMxS+9SonrjcJmLMdcwVsEweB8UHAqMtyw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350179; c=relaxed/simple; bh=BMmunbnNc/HgIVTVEnaV2JEkO23hN5JxPbS53pz9BFw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LHRqhzdGbPOyajKjZu7Y3Od+d9J2km+RbB4vWJjIQrofkCibQRQBYrPb0Cmcdg0Jue7yQ8eNX2CJVMJ11lhrMQXTSjFQyqV2wrSHZguHDGDCIjYNzns/sYHYm1M1jisFHRUZActWobcEBuAw4vIeE4ugSbcwr9aSvRY2kQHpli4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=OofR8iPT; 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="OofR8iPT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BFB67C4CEE9; Fri, 11 Apr 2025 05:42:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350179; bh=BMmunbnNc/HgIVTVEnaV2JEkO23hN5JxPbS53pz9BFw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OofR8iPTEwY5Zplb+A5/HHxoVsj9tatZ0OKWvHJw3g+lkyMqjfDtPFAI+ZlrF5zSH NbFePhaxCHKglHBYWiDGNWadI6I67flnFB3N/LILOOa9AG8cNGjjnEKo6loeCrkttL A2rcrC9xPg2hrrvULUJQgF0BLNZUeo0z/E9XmwlSGuHc7RPCjTXElixCv1FnOtXryb XzqsIWKbB80cvwI20m3SbRMizxR2b1WgjSQ/YtXe2+ge+Vnq9M9xd/icM8qU8O910F wgHwcDh8JxUooYcBcgPWGUwoGXwwpX6jiUu9RXevLBn0nuKt6xRKjJ/zyxRrr3HAAC cpdAvy155tUCw== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 45/53] x86/alternatives: Rename 'TP_ARRAY_NR_ENTRIES_MAX' to 'TEXT_POKE_ARRAY_MAX' Date: Fri, 11 Apr 2025 07:40:57 +0200 Message-ID: <20250411054105.2341982-46-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-1-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Standardize on TEXT_POKE_ namespace for CPP constants too. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index c5abcf95daea..4b460dea4f4e 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2466,10 +2466,10 @@ struct smp_text_poke_loc { u8 old; }; =20 -#define TP_ARRAY_NR_ENTRIES_MAX (PAGE_SIZE / sizeof(struct smp_text_poke_l= oc)) +#define TEXT_POKE_ARRAY_MAX (PAGE_SIZE / sizeof(struct smp_text_poke_loc)) =20 static struct smp_text_poke_array { - struct smp_text_poke_loc vec[TP_ARRAY_NR_ENTRIES_MAX]; + struct smp_text_poke_loc vec[TEXT_POKE_ARRAY_MAX]; int nr_entries; } text_poke_array; =20 @@ -2863,7 +2863,7 @@ static void smp_text_poke_batch_flush(void *addr) { lockdep_assert_held(&text_mutex); =20 - if (text_poke_array.nr_entries =3D=3D TP_ARRAY_NR_ENTRIES_MAX || !text_po= ke_addr_ordered(addr)) + if (text_poke_array.nr_entries =3D=3D TEXT_POKE_ARRAY_MAX || !text_poke_a= ddr_ordered(addr)) smp_text_poke_batch_process(); } =20 --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 3A60727F4F2 for ; Fri, 11 Apr 2025 05:43: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=1744350182; cv=none; b=UJEan5p2X9A0nXxfJdztZ9D6yfSTBl0K6BudsC9PubnhIVZRCU+AbJZhJC2t8eWeo4uAaB8Lbad/ovVO9YCSbTU1uLqkS/R/5z1BPn0nuaACDHA0SPRspiXGOFUINSgblzs6ew93oRKT2vSK0dI9cBxBugmdElp8uRqlioojT8A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350182; c=relaxed/simple; bh=1e4YhLREtiY4dPdmIC26xRSMVltPv7w9IgK602p5zzo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NQpR4eJh5ZzE90ZANjwyjJqZ40NpOqKlR1MtF4QMgI82Jtg1hIrjeOej6yBXYRGRf2hL3C+sTsN9l/LvpHAzkeQBseUme0Th3aQ/8wTKi0K7DhHj+o7Ve4vw5UV9TTY8ElXjuXjiZehmcEk5JBcc8xcNwMIMROmMDl8pIVIR+Ns= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZoIOL/MP; 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="ZoIOL/MP" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28F5BC4CEE2; Fri, 11 Apr 2025 05:42:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350182; bh=1e4YhLREtiY4dPdmIC26xRSMVltPv7w9IgK602p5zzo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZoIOL/MPn28eV2g+gM//gt7TRRGkGAWJiM0XIGE50nf8C+WartAPKrgBAdDINPG+s yDs9dzTbMi8MoI1WloG9pyB6hCXPhDDU+uf0zD2lHv/MB5u7D4m6PXK0vMlQJKYrzd vfj49FLeqVDxeZ9dfrrIYjs4kineGHfyGiag+15BiZhfoDDIwh/AMCrsjfxqIB8AoK Fn04qFlJHd0W+BYFrVUgSaBYSGJmYjs9sYtXDlvrDBebA3SwQuUomfEzWz+MJh2BPY rbAQnYFvUqfAIM8PyzmuuBIlmYhAIxems7uRD1kaZ/jtYvlXnjVmVdnufUyyE1NR59 cq2IcmdVX5ugQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 46/53] x86/alternatives: Rename 'POKE_MAX_OPCODE_SIZE' to 'TEXT_POKE_MAX_OPCODE_SIZE' Date: Fri, 11 Apr 2025 07:40:58 +0200 Message-ID: <20250411054105.2341982-47-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-1-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Join the TEXT_POKE_ namespace. Signed-off-by: Ingo Molnar --- arch/x86/include/asm/text-patching.h | 4 ++-- arch/x86/kernel/alternative.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/text-patching.h b/arch/x86/include/asm/te= xt-patching.h index d9dbbe9d9667..a45ac8a223f3 100644 --- a/arch/x86/include/asm/text-patching.h +++ b/arch/x86/include/asm/text-patching.h @@ -11,7 +11,7 @@ * JUMP_LABEL_NOP_SIZE/RELATIVEJUMP_SIZE, which are 5. * Raise it if needed. */ -#define POKE_MAX_OPCODE_SIZE 5 +#define TEXT_POKE_MAX_OPCODE_SIZE 5 =20 extern void text_poke_early(void *addr, const void *opcode, size_t len); =20 @@ -82,7 +82,7 @@ static __always_inline int text_opcode_size(u8 opcode) } =20 union text_poke_insn { - u8 text[POKE_MAX_OPCODE_SIZE]; + u8 text[TEXT_POKE_MAX_OPCODE_SIZE]; struct { u8 opcode; s32 disp; diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 4b460dea4f4e..b8e0b1b2383f 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2461,7 +2461,7 @@ struct smp_text_poke_loc { s32 disp; u8 len; u8 opcode; - const u8 text[POKE_MAX_OPCODE_SIZE]; + const u8 text[TEXT_POKE_MAX_OPCODE_SIZE]; /* see smp_text_poke_batch_process() */ u8 old; }; @@ -2653,8 +2653,8 @@ static void smp_text_poke_batch_process(void) * Second step: update all but the first byte of the patched range. */ for (do_sync =3D 0, i =3D 0; i < text_poke_array.nr_entries; i++) { - u8 old[POKE_MAX_OPCODE_SIZE+1] =3D { text_poke_array.vec[i].old, }; - u8 _new[POKE_MAX_OPCODE_SIZE+1]; + u8 old[TEXT_POKE_MAX_OPCODE_SIZE+1] =3D { text_poke_array.vec[i].old, }; + u8 _new[TEXT_POKE_MAX_OPCODE_SIZE+1]; const u8 *new =3D text_poke_array.vec[i].text; int len =3D text_poke_array.vec[i].len; =20 --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 8EC5B29DB88 for ; Fri, 11 Apr 2025 05:43:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350184; cv=none; b=NMppSQXch8ChZnZontfE/LzqVR78sfmrjPuI7tcaskLgyJsf5VssZauXFF/D/TbZCjZUSC57svFwDT+LFdLBerNU0ldTZQK/5gPG4llZRKqRfnrd7u91vceI/BG04XzTf1f8dynYTEF6zCURxHW8OFA9SDrZoqhWl5ZizU0folM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350184; c=relaxed/simple; bh=CW+oLjMLLZx9Xmr4WIfZNc/V67kLp4BlPYfvRUYZM64=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MIr6R9TwD/KR9O/DPY3Pw1B0m723+47oTgcEUpGPFYWC/8wmCLu+sQZUKQSA2MjDLFkLKW60dYIfO5+OVXsaLYCKT7x8yWPHvnZ4QrNI1YwM1ZlKoGO/SO+6sLMAwXlpfmDrHq/pQMafqMMt71bvdkPXTCWCNV7A8oIEoJusB1s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NxiA5bVJ; 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="NxiA5bVJ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8800CC4CEE5; Fri, 11 Apr 2025 05:43:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350184; bh=CW+oLjMLLZx9Xmr4WIfZNc/V67kLp4BlPYfvRUYZM64=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NxiA5bVJhJFCTNUOvjGGvpsAxFjN3J7xqozxe1Mw7j9gkL2MMemVxYMjRJcfPl8PI sxl0WahQ+NLTgcI77tC7VrNkYXszBHuu7QaWxN7Es/WicJ2kw3ZoK9IEJGmGaHCDAY HSWSlYxBtmK0YR1Pggrv4/Umj2jMHFjO8XkAL56P/w4/o1EB2YsJt01S5o9utiDSNs o2wX8BxvuXjoUJGMfgYI1P8vACwGiGrZ7HHms4O6WFpFS4MfLxr+C8RCjSJQ+NTpM1 PCKagMSMl707LfeO9YAIHflmUzlP4Qo/52qUsUK3aH+cywuKNSp8da2SRUAQJEPMFN BuwqJf5asYSOA== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 47/53] x86/alternatives: Simplify the #include section Date: Fri, 11 Apr 2025 07:40:59 +0200 Message-ID: <20250411054105.2341982-48-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-1-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We accumulated lots of unnecessary header inclusions over the years, trim them. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 28 +++------------------------- 1 file changed, 3 insertions(+), 25 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index b8e0b1b2383f..eb3be5d3efef 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -1,36 +1,14 @@ // SPDX-License-Identifier: GPL-2.0-only #define pr_fmt(fmt) "SMP alternatives: " fmt =20 -#include -#include +#include #include -#include -#include -#include -#include -#include #include #include -#include -#include -#include -#include -#include -#include -#include + #include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include -#include -#include +#include =20 int __read_mostly alternatives_patched; =20 --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 EA5A529DB9B for ; Fri, 11 Apr 2025 05:43:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350187; cv=none; b=jelflJhd+uY5xqxraD8uT52hwiAYnNn2uPeSvSHv4wTawkOliGZBQ6OeO1jVgkifBhj/anRCAtSBwlKZacrcftnB2cF5OzW2FjqTlG6FMflRViHRQNMgpmw4ZgqFnT7nWAeEZUQfUss5K6WM1SJLwv3gtnYNF9fNWIpYywxByMg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350187; c=relaxed/simple; bh=Nu2LqFQAEtnU/2I6HvpLjldth4L30txPXLQCI1B17WM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KcB+TW+L5MCF076DKgNH5ZrnFRvHOoZojcdDUC28dwxlGYxsetuitX0ZlsUNAsn5hRc9XdYlKLEDSLhk8PFsb7exV9J5Mp5B/hjCUkB6VON4fzwE0BSwEmVdRvUYWV+2wvYt3VFpU10xRgwdbSGvahI+x7yow75EDfiEhsOSSHg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pYhqhbR9; 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="pYhqhbR9" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E2EAAC4CEE5; Fri, 11 Apr 2025 05:43:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350186; bh=Nu2LqFQAEtnU/2I6HvpLjldth4L30txPXLQCI1B17WM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pYhqhbR9nbpby6XjQMna6X8fTsQBcTx0cZciLPnHDatJVVhC3lzkQAO6wHwg1I1sB /Li5A6FduXC3Mn111etpoq9BqAJMtmmTBaL+1sl5Yw12ptKDzG88efJQ2qpCd0QG4L 2yttU6d9qeZHUjGCTliMMIBkVTh4T+AixarlOpmZKgPC1fChTiBugY59e1NFrEDbjw BEPk7iDBvTQuD2I6Tosp2Cw6vD4ackBp30KNiphg+hsapolIr1EQc4I2YAbcqLOqCo VBC2ECcYuWbvlBk6nDaguA1yjSnBlbOwAcpnupCA85WVBzmvIVlOWe30UfLLHhV5ol wOdKoJ79/0+UA== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 48/53] x86/alternatives: Move declarations of vmlinux.lds.S defined section symbols to Date: Fri, 11 Apr 2025 07:41:00 +0200 Message-ID: <20250411054105.2341982-49-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-1-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Move it from the middle of a .c file next to the similar declarations of __alt_instructions[] et al. Signed-off-by: Ingo Molnar --- arch/x86/include/asm/alternative.h | 6 ++++++ arch/x86/kernel/alternative.c | 6 ------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alte= rnative.h index 4a37a8bd87fd..ef84739a77f5 100644 --- a/arch/x86/include/asm/alternative.h +++ b/arch/x86/include/asm/alternative.h @@ -82,6 +82,12 @@ struct alt_instr { =20 extern struct alt_instr __alt_instructions[], __alt_instructions_end[]; =20 +extern s32 __retpoline_sites[], __retpoline_sites_end[]; +extern s32 __return_sites[], __return_sites_end[]; +extern s32 __cfi_sites[], __cfi_sites_end[]; +extern s32 __ibt_endbr_seal[], __ibt_endbr_seal_end[]; +extern s32 __smp_locks[], __smp_locks_end[]; + /* * Debug flag that can be tested to see whether alternative * instructions were patched in already: diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index eb3be5d3efef..cd828c236fd2 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -149,12 +149,6 @@ static void add_nop(u8 *buf, unsigned int len) *buf =3D INT3_INSN_OPCODE; } =20 -extern s32 __retpoline_sites[], __retpoline_sites_end[]; -extern s32 __return_sites[], __return_sites_end[]; -extern s32 __cfi_sites[], __cfi_sites_end[]; -extern s32 __ibt_endbr_seal[], __ibt_endbr_seal_end[]; -extern s32 __smp_locks[], __smp_locks_end[]; - /* * Matches NOP and NOPL, not any of the other possible NOPs. */ --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 4CF312BD58D for ; Fri, 11 Apr 2025 05:43:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350189; cv=none; b=cvX77srwDM9a2pUw3G71aEYz/lYml1il2s5Ayadg2Pj0CawIvRUxK5L3H6MxiIKNd8CX71qLfmR7HAbKVf9ekpQS+qJ/tnYPt1Nl2oui4MNfp4nxP+6IKvuMp7n5vWG26kCNPmnn8cmfg4igAwjHAeQwGSv16KwEvFMmBydoIsk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350189; c=relaxed/simple; bh=K68LeerggAQQqGdt2sTeYGoKvBpGLCia3hwfCbUThac=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iA68LlgKl8UWrYhuXEAXXQ28Fnn7Y3MNJQWhpyuIeIWQVR0UvHC/0bxnQFtnLoAFG5v+D8pT3rmzKpvSLNzhVneCiuErL1auOYZ355hMkZWH/B0iuAkDCdHoHAQzuqEIm5hr2ilkuiPEJhdBTyJUeqhIhShG1m28gJ79O8hYNPk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Kz1DUX2P; 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="Kz1DUX2P" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A96EC4CEE2; Fri, 11 Apr 2025 05:43:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350189; bh=K68LeerggAQQqGdt2sTeYGoKvBpGLCia3hwfCbUThac=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Kz1DUX2PcuVXr6ZWkQGgGjdsLBI4uv/twZZsB0janAbJt/cuac/QqxhY92VXgQ4Zw 3eTAuxppIF1PjImNt9wOCInkEIJEN/Z3+6sUKlLTYcZtf3DKhmSFZZe9bcgAdlRWed Ygv31hpayj81ZhZGFcBtooPSwmv6A9n/yOqKe6IOSs49TFbYzCrcUoc8mNN7M+xnbp Gw96lIf3W9+e0Z+ITsGUDEC1Qe21+8ywuMSzfsD4hkrjHlBOjxxoNcUBT1RbOSj/9z XkC8rK+iaaw0gblImxAhf0Y8mV3mBdr67eLV5Ot8v60JJ82cTR5gzg9nVVtBNuYeFt KMcHXsm6YDLOA== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 49/53] x86/alternatives: Remove 'smp_text_poke_batch_flush()' Date: Fri, 11 Apr 2025 07:41:01 +0200 Message-ID: <20250411054105.2341982-50-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-1-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" It only has a single user left, merge it into smp_text_poke_batch_add() and remove the helper function. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index cd828c236fd2..c0be0663425e 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2831,14 +2831,6 @@ void smp_text_poke_batch_finish(void) smp_text_poke_batch_process(); } =20 -static void smp_text_poke_batch_flush(void *addr) -{ - lockdep_assert_held(&text_mutex); - - if (text_poke_array.nr_entries =3D=3D TEXT_POKE_ARRAY_MAX || !text_poke_a= ddr_ordered(addr)) - smp_text_poke_batch_process(); -} - /** * smp_text_poke_batch_add() -- update instruction on live kernel on SMP, = batched * @addr: address to patch @@ -2854,7 +2846,8 @@ static void smp_text_poke_batch_flush(void *addr) */ void __ref smp_text_poke_batch_add(void *addr, const void *opcode, size_t = len, const void *emulate) { - smp_text_poke_batch_flush(addr); + if (text_poke_array.nr_entries =3D=3D TEXT_POKE_ARRAY_MAX || !text_poke_a= ddr_ordered(addr)) + smp_text_poke_batch_process(); __smp_text_poke_batch_add(addr, opcode, len, emulate); } =20 --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 B11DB2BD5A0 for ; Fri, 11 Apr 2025 05:43:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350191; cv=none; b=sruEU3UT+STtBxGosAZpbBg1Ox4aeQtOkxc6ZFzKwRijMeIPcu1bWxdW7ul9GCFRNo3in0bo+S2BJ7j+pGe6NxObPHMQaHZYH7a8FumSxsZBPgNgr1+HOWh5LL6bB6pbdN65FiBHQz3CjfMiqKjOsXlOZ+dghdz3NjZdCSaU7Po= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350191; c=relaxed/simple; bh=egCr3mkvet3/AXmCOBCu30nw3QjIoKNyGxc4UXsVQsE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=c1GDEiTbhiBl2gY4uFLWJ9FjIIAPP5ql0+/ko7SeT+KFGvMuyelyZQtgNNAnnjDkqtFZtSTk1dwUibpCpbvT6gz3znmeQURV8ZgMfLj5Mx/vFPyETIIE8rZul0tuWxlIBt3gbd2UsVnoZBeLGWy6BWtmVEn0iapdw0nOjw+Q9Yc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=awMgx7WE; 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="awMgx7WE" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4DF6C4CEE2; Fri, 11 Apr 2025 05:43:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350191; bh=egCr3mkvet3/AXmCOBCu30nw3QjIoKNyGxc4UXsVQsE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=awMgx7WEAuauQIn+TqQMWMJpMpZ3ir8lsSu+s71IofVRRRgimhgQRoeCmlr9+Zzqu equVfDQC71iGaRUtUnsqiWFBU5GCtLqv9Pw2dBR44BqRZ2m5dPyfa5Xvnv6sq5cCTS mVf3AfRG5p1xl3qCDP43QatEMhzav/MqV8bj8GMJCFA+c9m9ugbmI8JAfov39/ZSe5 bV9GVlcXx0jlJ+vqhonU281NW0IGfD2c3yTvIx4jikDBUlyS9xPBksvjH8Dq7W7NvW NUJITfJ73bdU6PBb295/Pz9tkOWLcFOMXqop6HYE97+WlFp7yONngwAqBLGF2RUu2i 3l/8EQi0y5HGQ== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 50/53] x86/alternatives: Update the comments in smp_text_poke_batch_process() Date: Fri, 11 Apr 2025 07:41:02 +0200 Message-ID: <20250411054105.2341982-51-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-1-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" - Capitalize 'INT3' consistently, - make it clear that 'sync cores' means an SMP sync to all CPUs, - fix typos and spelling. Signed-off-by: Ingo Molnar --- arch/x86/kernel/alternative.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index c0be0663425e..9ee6f879bce5 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2561,24 +2561,26 @@ noinstr int smp_text_poke_int3_handler(struct pt_re= gs *regs) =20 /** * smp_text_poke_batch_process() -- update instructions on live kernel on = SMP - * @text_poke_array.vec: vector of instructions to patch - * @text_poke_array.nr_entries: number of entries in the vector * - * Modify multi-byte instruction by using int3 breakpoint on SMP. - * We completely avoid stop_machine() here, and achieve the - * synchronization using int3 breakpoint. + * Input state: + * text_poke_array.vec: vector of instructions to patch + * text_poke_array.nr_entries: number of entries in the vector + * + * Modify multi-byte instructions by using INT3 breakpoints on SMP. + * We completely avoid using stop_machine() here, and achieve the + * synchronization using INT3 breakpoints and SMP cross-calls. * * The way it is done: * - For each entry in the vector: - * - add a int3 trap to the address that will be patched - * - sync cores + * - add an INT3 trap to the address that will be patched + * - SMP sync all CPUs * - For each entry in the vector: * - update all but the first byte of the patched range - * - sync cores + * - SMP sync all CPUs * - For each entry in the vector: - * - replace the first byte (int3) by the first byte of + * - replace the first byte (INT3) by the first byte of the * replacing opcode - * - sync cores + * - SMP sync all CPUs */ static void smp_text_poke_batch_process(void) { @@ -2606,13 +2608,13 @@ static void smp_text_poke_batch_process(void) cond_resched(); =20 /* - * Corresponding read barrier in int3 notifier for making sure the + * Corresponding read barrier in INT3 notifier for making sure the * text_poke_array.nr_entries and handler are correctly ordered wrt. patc= hing. */ smp_wmb(); =20 /* - * First step: add a int3 trap to the address that will be patched. + * First step: add a INT3 trap to the address that will be patched. */ for (i =3D 0; i < text_poke_array.nr_entries; i++) { text_poke_array.vec[i].old =3D *(u8 *)text_poke_addr(&text_poke_array.ve= c[i]); @@ -2685,7 +2687,7 @@ static void smp_text_poke_batch_process(void) } =20 /* - * Third step: replace the first byte (int3) by the first byte of + * Third step: replace the first byte (INT3) by the first byte of the * replacing opcode. */ for (do_sync =3D 0, i =3D 0; i < text_poke_array.nr_entries; i++) { --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 1141A2BD5B7 for ; Fri, 11 Apr 2025 05:43:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350194; cv=none; b=XLXfDUO7XHp1wkw5EwwwQDwCuAegvidAXQbOsSZKRs1jfMq4VwcuO8blxxorN+VXjjfoedJnRxrrXI+dtJbp0QJDjpxlfF1aJh3xNr5ASZXBcP8P0hvrzdIo1HpM6a9/mtBq/JPFeFB6LMy0HI+cMtNo8mDUglq3h8yP+XeCdjU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350194; c=relaxed/simple; bh=badTX7FT8IohDN00i2VjzI29ky2TF4awZx5U6VyzMFk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OMX0uecMIxv9gQBk58o3LC+Rpq9XrkUUs3nPAWYTHY4tY48OduOotcDUIp7kIw8d7ahe4yqGgKFg66cSsgMnGptINB97tQ2D6tQQ6P0LslNNYZIfyhBOXhVuRUJuEMAqAcOb+KHHObd4jkEP774uuasUbNB88JBXG8e3uvXYjcA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=HcDO9Pch; 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="HcDO9Pch" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0B7D3C4CEE5; Fri, 11 Apr 2025 05:43:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350193; bh=badTX7FT8IohDN00i2VjzI29ky2TF4awZx5U6VyzMFk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HcDO9PchsMf0EyHUg2b6ZODqgZPR8tFsEH+t8nw9rKERrxjjIlc2mor7xizqOtaCz zr4WwKDYzfgFiVhNRwkOSXRbrKAC77UKqy2lzAGHw6PAfTatEDAPMN255VgaIHo3vD yYidC/znKIv7N6gw4DljjJbuXZkuABc8j4+JJGO8q5rQf+HUxuROqxzaRUZKdzvLEn s4DFe0QvRQ9SZKvDUC7EjwJT1U7nDaXzn1zTXrlPn/Q4lH3M7FX9iITMN6rsY81hLW gVNgu7mc7/qPZqSknRd/a9VT8OV0sQRk2wCCNbtFjveK5lalwFPHMJQKsiSlDdM5Rs KBHzpo5pe6NTA== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 51/53] x86/alternatives: Rename 'apply_relocation()' to 'text_poke_apply_relocation()' Date: Fri, 11 Apr 2025 07:41:03 +0200 Message-ID: <20250411054105.2341982-52-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-1-mingo@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Join the text_poke_*() API namespace. Signed-off-by: Ingo Molnar --- arch/x86/include/asm/text-patching.h | 2 +- arch/x86/kernel/alternative.c | 6 +++--- arch/x86/kernel/callthunks.c | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/arch/x86/include/asm/text-patching.h b/arch/x86/include/asm/te= xt-patching.h index a45ac8a223f3..5337f1be18f6 100644 --- a/arch/x86/include/asm/text-patching.h +++ b/arch/x86/include/asm/text-patching.h @@ -15,7 +15,7 @@ =20 extern void text_poke_early(void *addr, const void *opcode, size_t len); =20 -extern void apply_relocation(u8 *buf, const u8 * const instr, size_t instr= len, u8 *repl, size_t repl_len); +extern void text_poke_apply_relocation(u8 *buf, const u8 * const instr, si= ze_t instrlen, u8 *repl, size_t repl_len); =20 /* * Clear and restore the kernel write-protection flag on the local CPU. diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 9ee6f879bce5..231b2acbe360 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -340,7 +340,7 @@ static void __apply_relocation(u8 *buf, const u8 * cons= t instr, size_t instrlen, } } =20 -void apply_relocation(u8 *buf, const u8 * const instr, size_t instrlen, u8= *repl, size_t repl_len) +void text_poke_apply_relocation(u8 *buf, const u8 * const instr, size_t in= strlen, u8 *repl, size_t repl_len) { __apply_relocation(buf, instr, instrlen, repl, repl_len); optimize_nops(instr, buf, instrlen); @@ -496,7 +496,7 @@ void __init_or_module noinline apply_alternatives(struc= t alt_instr *start, for (; insn_buff_sz < a->instrlen; insn_buff_sz++) insn_buff[insn_buff_sz] =3D 0x90; =20 - apply_relocation(insn_buff, instr, a->instrlen, replacement, a->replacem= entlen); + text_poke_apply_relocation(insn_buff, instr, a->instrlen, replacement, a= ->replacementlen); =20 DUMP_BYTES(ALT, instr, a->instrlen, "%px: old_insn: ", instr); DUMP_BYTES(ALT, replacement, a->replacementlen, "%px: rpl_insn: ", rep= lacement); @@ -1981,7 +1981,7 @@ __visible noinline void __init __alt_reloc_selftest(v= oid *arg) static noinline void __init alt_reloc_selftest(void) { /* - * Tests apply_relocation(). + * Tests text_poke_apply_relocation(). * * This has a relative immediate (CALL) in a place other than the first * instruction and additionally on x86_64 we get a RIP-relative LEA: diff --git a/arch/x86/kernel/callthunks.c b/arch/x86/kernel/callthunks.c index d86d7d6e750c..a951333c5995 100644 --- a/arch/x86/kernel/callthunks.c +++ b/arch/x86/kernel/callthunks.c @@ -185,7 +185,7 @@ static void *patch_dest(void *dest, bool direct) u8 *pad =3D dest - tsize; =20 memcpy(insn_buff, skl_call_thunk_template, tsize); - apply_relocation(insn_buff, pad, tsize, skl_call_thunk_template, tsize); + text_poke_apply_relocation(insn_buff, pad, tsize, skl_call_thunk_template= , tsize); =20 /* Already patched? */ if (!bcmp(pad, insn_buff, tsize)) @@ -294,7 +294,7 @@ static bool is_callthunk(void *addr) pad =3D (void *)(dest - tmpl_size); =20 memcpy(insn_buff, skl_call_thunk_template, tmpl_size); - apply_relocation(insn_buff, pad, tmpl_size, skl_call_thunk_template, tmpl= _size); + text_poke_apply_relocation(insn_buff, pad, tmpl_size, skl_call_thunk_temp= late, tmpl_size); =20 return !bcmp(pad, insn_buff, tmpl_size); } @@ -312,7 +312,7 @@ int x86_call_depth_emit_accounting(u8 **pprog, void *fu= nc, void *ip) return 0; =20 memcpy(insn_buff, skl_call_thunk_template, tmpl_size); - apply_relocation(insn_buff, ip, tmpl_size, skl_call_thunk_template, tmpl_= size); + text_poke_apply_relocation(insn_buff, ip, tmpl_size, skl_call_thunk_templ= ate, tmpl_size); =20 memcpy(*pprog, insn_buff, tmpl_size); *pprog +=3D tmpl_size; --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 75D782BE7AC for ; Fri, 11 Apr 2025 05:43:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350196; cv=none; b=srgswKZZY6hMTxbmT+IEo+iCc1Ea09ITkcpp3Ft1g0AUBcvWhQYvR4vkPfM8kCI4IQexeZppEwA/afrPAF0a2EVywpHLHJLxfHpH0VSgz4+/UxVNWIN6tAoFQ4DBqA3cRJzsqOi+VkUD4T4ZH1yPdP0T1+yV7uLfeSWTqE63GiA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350196; c=relaxed/simple; bh=EFn+5AyjrVdlK00O2v7ECfvpshL8IgYUH9Ij5AZDLac=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OI5g5+YcydTx1WOIIgPN5w2N9/cFSO9Xm+MnH4Nd3XC6+OfjJh1uH7NTjeo0GgrQXVKneiMSS17VIBnRfqVrybhdiigQnCd+MpER4uwxc7y5M6agU0Y30vlFQedfhoUITz4XJQ7jHGHDrVKtbsfcgiJOO2rZnJEQhYqqYuvex+w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=KuRLmuTj; 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="KuRLmuTj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 65E33C4CEE5; Fri, 11 Apr 2025 05:43:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350196; bh=EFn+5AyjrVdlK00O2v7ECfvpshL8IgYUH9Ij5AZDLac=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KuRLmuTj1Y5U/2VgaJkOtj/ToLebzAdyPU0s/vWeke84VGZIzhdYjT7Z3ow5kQYaE NDufGw7EDINZ2lfVnEvCGQrxhkh0e159jCGjJE0+9oL1xeD71l7dF7ue/J+bakJuxU TQ9McPRWSayEbBAhCi/LDXYptHoXpxAidq+CNMP7WOwWXaOvnkZ6Zr6YuxUC9C6rPi qdU4fl9VCgamD7Sf0rF8hOGWcxZonZh9PUwnyuHZSVwP7h2nKeJ3HR561KDhL24PBm +3xThuz1eCHdew6H/KWhPv7k94S8cARP/wrxiMBEuTSHiQZmj2GaYtW4I0AlyFHj6I enCvCgkLVSD5g== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Ingo Molnar Subject: [PATCH 52/53] x86/alternatives: Add comment about noinstr expectations Date: Fri, 11 Apr 2025 07:41:04 +0200 Message-ID: <20250411054105.2341982-53-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-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 | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 231b2acbe360..604dd608d281 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2447,6 +2447,11 @@ static struct smp_text_poke_array { =20 static DEFINE_PER_CPU(atomic_t, text_poke_array_refs); =20 +/* + * These four __always_inline annotations imply noinstr, necessary + * due to smp_text_poke_int3_handler() being noinstr: + */ + static __always_inline bool try_get_text_poke_array(void) { atomic_t *refs =3D this_cpu_ptr(&text_poke_array_refs); --=20 2.45.2 From nobody Thu Dec 18 17:58:49 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 6A096280A3D for ; Fri, 11 Apr 2025 05:43: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=1744350199; cv=none; b=FRxxn2WPycN5JWRJCKKOhCMIk7uRwV+rZrD00VISXVP/y8Pp9FoY7C8pH3btnCS1wjuJiX+dVPGkOKYkEUdT9wymq+e/3TG5+rVji4VcMEOTks8gZEgkL/Y3NRXb3xSawqAnk2MjRsty0ky0MAN1FOrtJ+eJLtiuV9PbeIncaus= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744350199; c=relaxed/simple; bh=UIdMzgbZmy/Hx3MCBOeO26dCBR19yi0+Lbwoq7DqXQQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QOoeH+CknRqvlcpM49Y4nmna+s3yA0mC9Z+8lixo08VCEa8QMqwoKcM4rOtDVb8r2yVSoTxkjvCjIMz2QnBWmljdvob3+GKvtDV2V/NpiYtvmpngwlGfomVjr3A8s5p52Bq65GlIqUOBw1f9vdxRwvzKvlTZHmzvOTv/x9ifXvU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=D6pKshpj; 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="D6pKshpj" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C9847C4CEE5; Fri, 11 Apr 2025 05:43:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1744350198; bh=UIdMzgbZmy/Hx3MCBOeO26dCBR19yi0+Lbwoq7DqXQQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D6pKshpjB/tan7xD5mLSJxsixIBlKk7k9TyyU4g4bJ0WYB+SmMVzY1SsPTSIjoNX/ B4BnIztTVRZ2ZAfHugqCCAkXGgEAMTQQj3+93qXhhBP4lWu2Yr3SCrR3NxKNExarwZ enBW8/IDhn5hF57zWLumae335uOqECi3A/e8uEENCP4CAh3hBlP0BuCCBVjEQezJYb AbYjXUofdG67XbDdawULmYrdqH3YnMlitpBS9OHXpMaQmP72xA82bBnRN+AEeg0Fs5 gzqoem86DvWQB84fuDuKu8JAOeVvNCgQ+is6rdDB7dTwnQ++MfglWjZT8upAFFoZHi BnAy+ZjSkXvsg== From: Ingo Molnar To: linux-kernel@vger.kernel.org Cc: Juergen Gross , "H . Peter Anvin" , Linus Torvalds , Peter Zijlstra , Borislav Petkov , Thomas Gleixner , Nikolay Borisov , Ingo Molnar Subject: [PATCH 53/53] x86/alternatives: Make smp_text_poke_batch_process() subsume smp_text_poke_batch_finish() Date: Fri, 11 Apr 2025 07:41:05 +0200 Message-ID: <20250411054105.2341982-54-mingo@kernel.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20250411054105.2341982-1-mingo@kernel.org> References: <20250411054105.2341982-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" From: Nikolay Borisov Simplify the alternatives interface some more by moving the poke_batch_finish check into poke_batch_process and renaming the latter. The net effect is one less function name to consider when reading the code. Signed-off-by: Nikolay Borisov Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/r/20250403153956.1913607-1-nik.borisov@suse.c= om --- arch/x86/kernel/alternative.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 604dd608d281..f785d2335812 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2434,7 +2434,7 @@ struct smp_text_poke_loc { u8 len; u8 opcode; const u8 text[TEXT_POKE_MAX_OPCODE_SIZE]; - /* see smp_text_poke_batch_process() */ + /* see smp_text_poke_batch_finish() */ u8 old; }; =20 @@ -2507,7 +2507,7 @@ noinstr int smp_text_poke_int3_handler(struct pt_regs= *regs) return 0; =20 /* - * Discount the INT3. See smp_text_poke_batch_process(). + * Discount the INT3. See smp_text_poke_batch_finish(). */ ip =3D (void *) regs->ip - INT3_INSN_SIZE; =20 @@ -2565,7 +2565,7 @@ noinstr int smp_text_poke_int3_handler(struct pt_regs= *regs) } =20 /** - * smp_text_poke_batch_process() -- update instructions on live kernel on = SMP + * smp_text_poke_batch_finish() -- update instructions on live kernel on S= MP * * Input state: * text_poke_array.vec: vector of instructions to patch @@ -2587,12 +2587,15 @@ noinstr int smp_text_poke_int3_handler(struct pt_re= gs *regs) * replacing opcode * - SMP sync all CPUs */ -static void smp_text_poke_batch_process(void) +void smp_text_poke_batch_finish(void) { unsigned char int3 =3D INT3_INSN_OPCODE; unsigned int i; int do_sync; =20 + if (!text_poke_array.nr_entries) + return; + lockdep_assert_held(&text_mutex); =20 /* @@ -2832,12 +2835,6 @@ static bool text_poke_addr_ordered(void *addr) return true; } =20 -void smp_text_poke_batch_finish(void) -{ - if (text_poke_array.nr_entries) - smp_text_poke_batch_process(); -} - /** * smp_text_poke_batch_add() -- update instruction on live kernel on SMP, = batched * @addr: address to patch @@ -2854,7 +2851,7 @@ void smp_text_poke_batch_finish(void) void __ref smp_text_poke_batch_add(void *addr, const void *opcode, size_t = len, const void *emulate) { if (text_poke_array.nr_entries =3D=3D TEXT_POKE_ARRAY_MAX || !text_poke_a= ddr_ordered(addr)) - smp_text_poke_batch_process(); + smp_text_poke_batch_finish(); __smp_text_poke_batch_add(addr, opcode, len, emulate); } =20 --=20 2.45.2