Commit 0df14c1f authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo
Browse files

perf lock contention: Reject more than 10ms delays for safety



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: default avatarAlexei Starovoitov <ast@kernel.org>
Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Song Liu <song@kernel.org>
Link: https://lore.kernel.org/r/20250515181042.555189-1-namhyung@kernel.org


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 8c56bfe5
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -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
+5 −0
Original line number Diff line number Diff line
@@ -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");