Linux Perf Users
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Namhyung Kim <namhyung@kernel.org>
Cc: Ian Rogers <irogers@google.com>,
	Kan Liang <kan.liang@linux.intel.com>,
	Jiri Olsa <jolsa@kernel.org>,
	Adrian Hunter <adrian.hunter@intel.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	linux-perf-users@vger.kernel.org, Song Liu <song@kernel.org>,
	bpf@vger.kernel.org, Alexei Starovoitov <ast@kernel.org>
Subject: Re: [PATCH] perf lock contention: Reject more than 10ms delays for safety
Date: Sat, 31 May 2025 08:45:11 -0300	[thread overview]
Message-ID: <aDrrxwPcSslAFnpb@x1> (raw)
In-Reply-To: <20250515181042.555189-1-namhyung@kernel.org>

On Thu, May 15, 2025 at 11:10:42AM -0700, Namhyung Kim wrote:
> Delaying kernel operations can be dangerous and the kernel may kill
> (non-sleepable) BPF programs running for long in the future.
> 
> Limit the max delay to 10ms and update the document about it.
> 
>   $ sudo ./perf lock con -abl -J 100000us@cgroup_mutex true
>   lock delay is too long: 100000us (> 10ms)
> 
>    Usage: perf lock contention [<options>]
> 
>       -J, --inject-delay <TIME@FUNC>
>                             Inject delays to specific locks
> 
> Suggested-by: Alexei Starovoitov <ast@kernel.org>
> Signed-off-by: Namhyung Kim <namhyung@kernel.org>



Thanks, applied to perf-tools-next,

- Arnaldo

> ---
>  tools/perf/Documentation/perf-lock.txt | 8 ++++++--
>  tools/perf/builtin-lock.c              | 5 +++++
>  2 files changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/Documentation/perf-lock.txt b/tools/perf/Documentation/perf-lock.txt
> index 2d9aecf630422aa6..c17b3e318169f9dc 100644
> --- a/tools/perf/Documentation/perf-lock.txt
> +++ b/tools/perf/Documentation/perf-lock.txt
> @@ -224,8 +224,12 @@ CONTENTION OPTIONS
>  	only with -b/--use-bpf.
>  
>  	The 'time' is specified in nsec but it can have a unit suffix.  Available
> -	units are "ms" and "us".  Note that it will busy-wait after it gets the
> -	lock.  Please use it at your own risk.
> +	units are "ms", "us" and "ns".  Currently it accepts up to 10ms of delays
> +	for safety reasons.
> +
> +	Note that it will busy-wait after it gets the lock. Delaying locks can
> +	have significant consequences including potential kernel crashes.  Please
> +	use it at your own risk.
>  
>  
>  SEE ALSO
> diff --git a/tools/perf/builtin-lock.c b/tools/perf/builtin-lock.c
> index 41f6f3d2b779b986..3b3ade7a39cad01f 100644
> --- a/tools/perf/builtin-lock.c
> +++ b/tools/perf/builtin-lock.c
> @@ -2537,6 +2537,11 @@ static bool add_lock_delay(char *spec)
>  		return false;
>  	}
>  
> +	if (duration > 10 * 1000 * 1000) {
> +		pr_err("lock delay is too long: %s (> 10ms)\n", spec);
> +		return false;
> +	}
> +
>  	tmp = realloc(delays, (nr_delays + 1) * sizeof(*delays));
>  	if (tmp == NULL) {
>  		pr_err("Memory allocation failure\n");
> -- 
> 2.49.0.1101.gccaa498523-goog

  parent reply	other threads:[~2025-05-31 11:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-15 18:10 [PATCH] perf lock contention: Reject more than 10ms delays for safety Namhyung Kim
2025-05-15 18:18 ` Ian Rogers
2025-05-31 11:45 ` Arnaldo Carvalho de Melo [this message]
2025-05-31 11:49 ` Arnaldo Carvalho de Melo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aDrrxwPcSslAFnpb@x1 \
    --to=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=irogers@google.com \
    --cc=jolsa@kernel.org \
    --cc=kan.liang@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=song@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox