Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Namhyung 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: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Namhyung Kim and committed by
Arnaldo Carvalho de Melo
0df14c1f 8c56bfe5

+11 -2
+6 -2
tools/perf/Documentation/perf-lock.txt
··· 224 224 only with -b/--use-bpf. 225 225 226 226 The 'time' is specified in nsec but it can have a unit suffix. Available 227 - units are "ms" and "us". Note that it will busy-wait after it gets the 228 - lock. Please use it at your own risk. 227 + units are "ms", "us" and "ns". Currently it accepts up to 10ms of delays 228 + for safety reasons. 229 + 230 + Note that it will busy-wait after it gets the lock. Delaying locks can 231 + have significant consequences including potential kernel crashes. Please 232 + use it at your own risk. 229 233 230 234 231 235 SEE ALSO
+5
tools/perf/builtin-lock.c
··· 2537 2537 return false; 2538 2538 } 2539 2539 2540 + if (duration > 10 * 1000 * 1000) { 2541 + pr_err("lock delay is too long: %s (> 10ms)\n", spec); 2542 + return false; 2543 + } 2544 + 2540 2545 tmp = realloc(delays, (nr_delays + 1) * sizeof(*delays)); 2541 2546 if (tmp == NULL) { 2542 2547 pr_err("Memory allocation failure\n");