[for-next,6/8] ftrace: Prevent RCU stall on PREEMPT_VOLUNTARY kernels

Message ID 20221214140209.346584113@goodmis.org
State New
Headers
Series tracing: Last minute fixes for 6.2 |

Commit Message

Steven Rostedt Dec. 14, 2022, 2:01 p.m. UTC
  From: "gpiccoli@igalia.com" <gpiccoli@igalia.com>

The function match_records() may take a while due to a large
number of string comparisons, so when in PREEMPT_VOLUNTARY
kernels we could face RCU stalls due to that.

Add a cond_resched() to prevent that.

Link: https://lkml.kernel.org/r/20221115204847.593616-1-gpiccoli@igalia.com

Cc: Mark Rutland <mark.rutland@arm.com>
Suggested-by: Steven Rostedt <rostedt@goodmis.org>
Acked-by: Paul E. McKenney <paulmck@kernel.org> # from RCU CPU stall warning perspective
Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 kernel/trace/ftrace.c | 1 +
 1 file changed, 1 insertion(+)
  

Comments

Guilherme G. Piccoli Dec. 14, 2022, 3:53 p.m. UTC | #1
On 14/12/2022 11:01, Steven Rostedt wrote:
> From: "gpiccoli@igalia.com" <gpiccoli@igalia.com>

Hi Steve, would be possible to use my full name here, like: Guilherme G.
Piccoli <gpiccoli@igalia.com> ?

Thanks,


Guilherme

> 
> The function match_records() may take a while due to a large
> number of string comparisons, so when in PREEMPT_VOLUNTARY
> kernels we could face RCU stalls due to that.
> 
> Add a cond_resched() to prevent that.
> 
> Link: https://lkml.kernel.org/r/20221115204847.593616-1-gpiccoli@igalia.com
> 
> Cc: Mark Rutland <mark.rutland@arm.com>
> Suggested-by: Steven Rostedt <rostedt@goodmis.org>
> Acked-by: Paul E. McKenney <paulmck@kernel.org> # from RCU CPU stall warning perspective
> Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
> Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> ---
>  kernel/trace/ftrace.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index d04552c0c275..b8e374a372e5 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -4204,6 +4204,7 @@ match_records(struct ftrace_hash *hash, char *func, int len, char *mod)
>  			}
>  			found = 1;
>  		}
> +		cond_resched();
>  	} while_for_each_ftrace_rec();
>   out_unlock:
>  	mutex_unlock(&ftrace_lock);
  
Steven Rostedt Dec. 14, 2022, 4:15 p.m. UTC | #2
On Wed, 14 Dec 2022 12:53:04 -0300
"Guilherme G. Piccoli" <gpiccoli@igalia.com> wrote:

> On 14/12/2022 11:01, Steven Rostedt wrote:
> > From: "gpiccoli@igalia.com" <gpiccoli@igalia.com>  
> 
> Hi Steve, would be possible to use my full name here, like: Guilherme G.
> Piccoli <gpiccoli@igalia.com> ?

Sure, I haven't pushed to the next repo yet.

I found the reason it didn't go into my patchwork, and did a resend via a
"redirect", and that must have changed the from address :-/

-- Steve
  
Steven Rostedt Dec. 14, 2022, 4:17 p.m. UTC | #3
On Wed, 14 Dec 2022 11:15:44 -0500
Steven Rostedt <rostedt@goodmis.org> wrote:

> On Wed, 14 Dec 2022 12:53:04 -0300
> "Guilherme G. Piccoli" <gpiccoli@igalia.com> wrote:
> 
> > On 14/12/2022 11:01, Steven Rostedt wrote:  
> > > From: "gpiccoli@igalia.com" <gpiccoli@igalia.com>    
> > 
> > Hi Steve, would be possible to use my full name here, like: Guilherme G.
> > Piccoli <gpiccoli@igalia.com> ?  
> 
> Sure, I haven't pushed to the next repo yet.
> 
> I found the reason it didn't go into my patchwork, and did a resend via a
> "redirect", and that must have changed the from address :-/
> 

Here's the new update:

-- Steve


From d0b24b4e91fcb8408c4979888547f86be514e337 Mon Sep 17 00:00:00 2001
From: "Guilherme G. Piccoli" <gpiccoli@igalia.com>
Date: Tue, 15 Nov 2022 17:48:47 -0300
Subject: [PATCH] ftrace: Prevent RCU stall on PREEMPT_VOLUNTARY kernels

The function match_records() may take a while due to a large
number of string comparisons, so when in PREEMPT_VOLUNTARY
kernels we could face RCU stalls due to that.

Add a cond_resched() to prevent that.

Link: https://lkml.kernel.org/r/20221115204847.593616-1-gpiccoli@igalia.com

Cc: Mark Rutland <mark.rutland@arm.com>
Suggested-by: Steven Rostedt <rostedt@goodmis.org>
Acked-by: Paul E. McKenney <paulmck@kernel.org> # from RCU CPU stall warning perspective
Signed-off-by: Guilherme G. Piccoli <gpiccoli@igalia.com>
Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org>
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 kernel/trace/ftrace.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index d04552c0c275..b8e374a372e5 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -4204,6 +4204,7 @@ match_records(struct ftrace_hash *hash, char *func, int len, char *mod)
 			}
 			found = 1;
 		}
+		cond_resched();
 	} while_for_each_ftrace_rec();
  out_unlock:
 	mutex_unlock(&ftrace_lock);
  
Guilherme G. Piccoli Dec. 14, 2022, 4:23 p.m. UTC | #4
On 14/12/2022 13:15, Steven Rostedt wrote:
> On Wed, 14 Dec 2022 12:53:04 -0300
> "Guilherme G. Piccoli" <gpiccoli@igalia.com> wrote:
> 
>> On 14/12/2022 11:01, Steven Rostedt wrote:
>>> From: "gpiccoli@igalia.com" <gpiccoli@igalia.com>  
>>
>> Hi Steve, would be possible to use my full name here, like: Guilherme G.
>> Piccoli <gpiccoli@igalia.com> ?
> 
> Sure, I haven't pushed to the next repo yet.
> 
> I found the reason it didn't go into my patchwork, and did a resend via a
> "redirect", and that must have changed the from address :-/
> 
> -- Steve

Perfect, thanks a lot for your prompt response!!
  

Patch

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index d04552c0c275..b8e374a372e5 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -4204,6 +4204,7 @@  match_records(struct ftrace_hash *hash, char *func, int len, char *mod)
 			}
 			found = 1;
 		}
+		cond_resched();
 	} while_for_each_ftrace_rec();
  out_unlock:
 	mutex_unlock(&ftrace_lock);