public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/alternatives: Add cond_resched() to text_poke_bp_batch()
@ 2023-05-28 12:46 Steven Rostedt
  2023-05-29  2:52 ` Masami Hiramatsu
  2023-05-30 12:01 ` Peter Zijlstra
  0 siblings, 2 replies; 6+ messages in thread
From: Steven Rostedt @ 2023-05-28 12:46 UTC (permalink / raw)
  To: LKML, x86
  Cc: Masami Hiramatsu, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Peter Zijlstra

From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

Debugging in the kernel has started slowing down the kernel by a
noticeable amount. The ftrace start up tests are triggering the softlockup
watchdog on some boxes. This is caused by the start up tests that enable
function and function graph tracing several times. Sprinkling
cond_resched() just in the start up test code was not enough to stop the
softlockup from triggering. It would sometimes trigger in the
text_poke_bp_batch() code.

The text_poke_bp_batch() is run in schedulable context. Add
cond_resched() between each phase (adding the int3, updating the code, and
removing the int3). This keeps the softlockup from triggering in the start
up tests.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 arch/x86/kernel/alternative.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index f615e0cb6d93..e024eddd457f 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -1953,6 +1953,14 @@ static void text_poke_bp_batch(struct text_poke_loc *tp, unsigned int nr_entries
 	 */
 	atomic_set_release(&bp_desc.refs, 1);
 
+	/*
+	 * Function tracing can enable thousands of places that need to be
+	 * updated. This can take quite some time, and with full kernel debugging
+	 * enabled, this could cause the softlockup watchdog to trigger.
+	 * Add cond_resched() calls to each phase.
+	 */
+	cond_resched();
+
 	/*
 	 * Corresponding read barrier in int3 notifier for making sure the
 	 * nr_entries and handler are correctly ordered wrt. patching.
@@ -2030,6 +2038,7 @@ static void text_poke_bp_batch(struct text_poke_loc *tp, unsigned int nr_entries
 		 * better safe than sorry (plus there's not only Intel).
 		 */
 		text_poke_sync();
+		cond_resched();
 	}
 
 	/*
@@ -2049,8 +2058,10 @@ static void text_poke_bp_batch(struct text_poke_loc *tp, unsigned int nr_entries
 		do_sync++;
 	}
 
-	if (do_sync)
+	if (do_sync) {
 		text_poke_sync();
+		cond_resched();
+	}
 
 	/*
 	 * Remove and wait for refs to be zero.
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] x86/alternatives: Add cond_resched() to text_poke_bp_batch()
  2023-05-28 12:46 [PATCH] x86/alternatives: Add cond_resched() to text_poke_bp_batch() Steven Rostedt
@ 2023-05-29  2:52 ` Masami Hiramatsu
  2023-05-29  3:21   ` Steven Rostedt
  2023-05-30 12:01 ` Peter Zijlstra
  1 sibling, 1 reply; 6+ messages in thread
From: Masami Hiramatsu @ 2023-05-29  2:52 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: LKML, x86, Masami Hiramatsu, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, Peter Zijlstra

On Sun, 28 May 2023 08:46:52 -0400
Steven Rostedt <rostedt@goodmis.org> wrote:

> From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
> 
> Debugging in the kernel has started slowing down the kernel by a
> noticeable amount. The ftrace start up tests are triggering the softlockup
> watchdog on some boxes. This is caused by the start up tests that enable
> function and function graph tracing several times. Sprinkling
> cond_resched() just in the start up test code was not enough to stop the
> softlockup from triggering. It would sometimes trigger in the
> text_poke_bp_batch() code.
> 
> The text_poke_bp_batch() is run in schedulable context. Add
> cond_resched() between each phase (adding the int3, updating the code, and
> removing the int3). This keeps the softlockup from triggering in the start
> up tests.
> 
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> ---
>  arch/x86/kernel/alternative.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
> index f615e0cb6d93..e024eddd457f 100644
> --- a/arch/x86/kernel/alternative.c
> +++ b/arch/x86/kernel/alternative.c
> @@ -1953,6 +1953,14 @@ static void text_poke_bp_batch(struct text_poke_loc *tp, unsigned int nr_entries
>  	 */
>  	atomic_set_release(&bp_desc.refs, 1);
>  
> +	/*
> +	 * Function tracing can enable thousands of places that need to be
> +	 * updated. This can take quite some time, and with full kernel debugging
> +	 * enabled, this could cause the softlockup watchdog to trigger.
> +	 * Add cond_resched() calls to each phase.
> +	 */
> +	cond_resched();

Hmm, why don't you put this between the first step (put int3) and the
second step (put other bytes)? I guess those would takes more time.

Thank you,

> +
>  	/*
>  	 * Corresponding read barrier in int3 notifier for making sure the
>  	 * nr_entries and handler are correctly ordered wrt. patching.
> @@ -2030,6 +2038,7 @@ static void text_poke_bp_batch(struct text_poke_loc *tp, unsigned int nr_entries
>  		 * better safe than sorry (plus there's not only Intel).
>  		 */
>  		text_poke_sync();
> +		cond_resched();
>  	}
>  
>  	/*
> @@ -2049,8 +2058,10 @@ static void text_poke_bp_batch(struct text_poke_loc *tp, unsigned int nr_entries
>  		do_sync++;
>  	}
>  
> -	if (do_sync)
> +	if (do_sync) {
>  		text_poke_sync();
> +		cond_resched();
> +	}
>  
>  	/*
>  	 * Remove and wait for refs to be zero.
> -- 
> 2.39.2
> 


-- 
Masami Hiramatsu (Google) <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] x86/alternatives: Add cond_resched() to text_poke_bp_batch()
  2023-05-29  2:52 ` Masami Hiramatsu
@ 2023-05-29  3:21   ` Steven Rostedt
  0 siblings, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2023-05-29  3:21 UTC (permalink / raw)
  To: Masami Hiramatsu (Google)
  Cc: LKML, x86, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	Peter Zijlstra

On Mon, 29 May 2023 11:52:46 +0900
Masami Hiramatsu (Google) <mhiramat@kernel.org> wrote:

> > +	/*
> > +	 * Function tracing can enable thousands of places that need to be
> > +	 * updated. This can take quite some time, and with full kernel debugging
> > +	 * enabled, this could cause the softlockup watchdog to trigger.
> > +	 * Add cond_resched() calls to each phase.
> > +	 */
> > +	cond_resched();  
> 
> Hmm, why don't you put this between the first step (put int3) and the
> second step (put other bytes)? I guess those would takes more time.

Ah you're right. I still want this here to clear the 'need resched'
flag before we start the process, but I did miss one after the first
loop.

Thanks for the review!

-- Steve

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] x86/alternatives: Add cond_resched() to text_poke_bp_batch()
  2023-05-28 12:46 [PATCH] x86/alternatives: Add cond_resched() to text_poke_bp_batch() Steven Rostedt
  2023-05-29  2:52 ` Masami Hiramatsu
@ 2023-05-30 12:01 ` Peter Zijlstra
  2023-05-30 12:35   ` Steven Rostedt
  2023-05-31  9:08   ` Steven Rostedt
  1 sibling, 2 replies; 6+ messages in thread
From: Peter Zijlstra @ 2023-05-30 12:01 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: LKML, x86, Masami Hiramatsu, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov

On Sun, May 28, 2023 at 08:46:52AM -0400, Steven Rostedt wrote:
> From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
> 
> Debugging in the kernel has started slowing down the kernel by a
> noticeable amount. The ftrace start up tests are triggering the softlockup
> watchdog on some boxes. This is caused by the start up tests that enable
> function and function graph tracing several times. Sprinkling
> cond_resched() just in the start up test code was not enough to stop the
> softlockup from triggering. It would sometimes trigger in the
> text_poke_bp_batch() code.
> 
> The text_poke_bp_batch() is run in schedulable context. Add
> cond_resched() between each phase (adding the int3, updating the code, and
> removing the int3). This keeps the softlockup from triggering in the start
> up tests.
> 
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> ---
>  arch/x86/kernel/alternative.c | 13 ++++++++++++-
>  1 file changed, 12 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
> index f615e0cb6d93..e024eddd457f 100644
> --- a/arch/x86/kernel/alternative.c
> +++ b/arch/x86/kernel/alternative.c
> @@ -1953,6 +1953,14 @@ static void text_poke_bp_batch(struct text_poke_loc *tp, unsigned int nr_entries
>  	 */
>  	atomic_set_release(&bp_desc.refs, 1);
>  
> +	/*
> +	 * Function tracing can enable thousands of places that need to be
> +	 * updated. This can take quite some time, and with full kernel debugging
> +	 * enabled, this could cause the softlockup watchdog to trigger.
> +	 * Add cond_resched() calls to each phase.
> +	 */
> +	cond_resched();

But but but... you can only have TP_VEC_MAX pokes queued, which is 256
on normal setups.

Please explain how this leads to problems and why you need _3_
reschedule points here.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] x86/alternatives: Add cond_resched() to text_poke_bp_batch()
  2023-05-30 12:01 ` Peter Zijlstra
@ 2023-05-30 12:35   ` Steven Rostedt
  2023-05-31  9:08   ` Steven Rostedt
  1 sibling, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2023-05-30 12:35 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: LKML, x86, Masami Hiramatsu, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov

On Tue, 30 May 2023 14:01:48 +0200
Peter Zijlstra <peterz@infradead.org> wrote:

> On Sun, May 28, 2023 at 08:46:52AM -0400, Steven Rostedt wrote:
> > diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
> > index f615e0cb6d93..e024eddd457f 100644
> > --- a/arch/x86/kernel/alternative.c
> > +++ b/arch/x86/kernel/alternative.c
> > @@ -1953,6 +1953,14 @@ static void text_poke_bp_batch(struct text_poke_loc *tp, unsigned int nr_entries
> >  	 */
> >  	atomic_set_release(&bp_desc.refs, 1);
> >  
> > +	/*
> > +	 * Function tracing can enable thousands of places that need to be
> > +	 * updated. This can take quite some time, and with full kernel debugging
> > +	 * enabled, this could cause the softlockup watchdog to trigger.
> > +	 * Add cond_resched() calls to each phase.
> > +	 */
> > +	cond_resched();  
> 
> But but but... you can only have TP_VEC_MAX pokes queued, which is 256
> on normal setups.
> 
> Please explain how this leads to problems and why you need _3_
> reschedule points here.

Maybe this was me being overly paranoid (and thinking, it doesn't hurt).

I could try it with just adding one (to make sure it happens every
flush), and see if it doesn't trigger the softlock up.

-- Steve

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] x86/alternatives: Add cond_resched() to text_poke_bp_batch()
  2023-05-30 12:01 ` Peter Zijlstra
  2023-05-30 12:35   ` Steven Rostedt
@ 2023-05-31  9:08   ` Steven Rostedt
  1 sibling, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2023-05-31  9:08 UTC (permalink / raw)
  To: Peter Zijlstra
  Cc: LKML, x86, Masami Hiramatsu, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov

On Tue, 30 May 2023 14:01:48 +0200
Peter Zijlstra <peterz@infradead.org> wrote:


> > diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
> > index f615e0cb6d93..e024eddd457f 100644
> > --- a/arch/x86/kernel/alternative.c
> > +++ b/arch/x86/kernel/alternative.c
> > @@ -1953,6 +1953,14 @@ static void text_poke_bp_batch(struct text_poke_loc *tp, unsigned int nr_entries
> >  	 */
> >  	atomic_set_release(&bp_desc.refs, 1);
> >  
> > +	/*
> > +	 * Function tracing can enable thousands of places that need to be
> > +	 * updated. This can take quite some time, and with full kernel debugging
> > +	 * enabled, this could cause the softlockup watchdog to trigger.
> > +	 * Add cond_resched() calls to each phase.
> > +	 */
> > +	cond_resched();  
> 
> But but but... you can only have TP_VEC_MAX pokes queued, which is 256
> on normal setups.
> 
> Please explain how this leads to problems and why you need _3_
> reschedule points here.

I removed all but this first one and it works fine.

I'll resend with the update.

-- Steve

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-05-31  9:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-28 12:46 [PATCH] x86/alternatives: Add cond_resched() to text_poke_bp_batch() Steven Rostedt
2023-05-29  2:52 ` Masami Hiramatsu
2023-05-29  3:21   ` Steven Rostedt
2023-05-30 12:01 ` Peter Zijlstra
2023-05-30 12:35   ` Steven Rostedt
2023-05-31  9:08   ` Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox