[PATCH 23/49] x86/alternatives: Simplify smp_text_poke_single() by using tp_vec and existing APIs

Ingo Molnar posted 49 patches 8 months, 3 weeks ago
There is a newer version of this series
[PATCH 23/49] x86/alternatives: Simplify smp_text_poke_single() by using tp_vec and existing APIs
Posted by Ingo Molnar 8 months, 3 weeks ago
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 <mingo@kernel.org>
---
 arch/x86/kernel/alternative.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index ffffec4597b7..70abc636b87c 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -2906,8 +2906,13 @@ void __ref smp_text_poke_batch_add(void *addr, const void *opcode, size_t len, c
  */
 void __ref smp_text_poke_single(void *addr, const void *opcode, size_t len, const void *emulate)
 {
-	struct smp_text_poke_loc tp;
+	struct smp_text_poke_loc *tp;
+
+	/* Batch-patching should not be mixed with single-patching: */
+	WARN_ON_ONCE(tp_vec_nr != 0);
+
+	tp = &tp_vec[tp_vec_nr++];
+	text_poke_int3_loc_init(tp, addr, opcode, len, emulate);
 
-	text_poke_int3_loc_init(&tp, addr, opcode, len, emulate);
-	smp_text_poke_batch_process(&tp, 1);
+	smp_text_poke_batch_finish();
 }
-- 
2.45.2
Re: [PATCH 23/49] x86/alternatives: Simplify smp_text_poke_single() by using tp_vec and existing APIs
Posted by Peter Zijlstra 8 months, 2 weeks ago
On Fri, Mar 28, 2025 at 02:26:38PM +0100, Ingo Molnar wrote:
> 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.

This should go before patch 20, otherwise you'll have this intermediate
state where we trip the WARN, no?

> Signed-off-by: Ingo Molnar <mingo@kernel.org>
> ---
>  arch/x86/kernel/alternative.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
> index ffffec4597b7..70abc636b87c 100644
> --- a/arch/x86/kernel/alternative.c
> +++ b/arch/x86/kernel/alternative.c
> @@ -2906,8 +2906,13 @@ void __ref smp_text_poke_batch_add(void *addr, const void *opcode, size_t len, c
>   */
>  void __ref smp_text_poke_single(void *addr, const void *opcode, size_t len, const void *emulate)
>  {
> -	struct smp_text_poke_loc tp;
> +	struct smp_text_poke_loc *tp;
> +
> +	/* Batch-patching should not be mixed with single-patching: */
> +	WARN_ON_ONCE(tp_vec_nr != 0);
> +
> +	tp = &tp_vec[tp_vec_nr++];
> +	text_poke_int3_loc_init(tp, addr, opcode, len, emulate);
>  
> -	text_poke_int3_loc_init(&tp, addr, opcode, len, emulate);
> -	smp_text_poke_batch_process(&tp, 1);
> +	smp_text_poke_batch_finish();
>  }
> -- 
> 2.45.2
>
Re: [PATCH 23/49] x86/alternatives: Simplify smp_text_poke_single() by using tp_vec and existing APIs
Posted by Ingo Molnar 8 months, 2 weeks ago
* Peter Zijlstra <peterz@infradead.org> wrote:

> On Fri, Mar 28, 2025 at 02:26:38PM +0100, Ingo Molnar wrote:
> > 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.
> 
> This should go before patch 20, otherwise you'll have this intermediate
> state where we trip the WARN, no?

Yeah, indeed - I've shuffled them around in the latest 
WIP.x86/alternatives.

Thanks,

	Ingo