perf lock contention: Reject more than 10ms delays for safety
Subsystems (2)
Namhyung Kim
maintainerPATCH 1/1 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
--- tools/perf/Documentation/perf-lock.txt | 8 ++++++-- tools/perf/builtin-lock.c | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-)
tools/perf/Documentation/perf-lock.txt +6 -2
@@ -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
tools/perf/builtin-lock.c +5 -0
@@ -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" );
Signature · 1 line
2.49.0.1101.gccaa498523-goog
Ian Rogers
reviewerNit, in the subject line for clarity perhaps rather than "perf lock contention:" call it "perf lock contention/delay" or "perf lock delay".
Quoted 45 lines · Namhyung Kim
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 locksSuggested-by Alexei Starovoitov <[email protected]>Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/Documentation/perf-lock.txt | 8 ++++++-- tools/perf/builtin-lock.c | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-)tools/perf/Documentation/perf-lock.txt +6
-2@@ -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 ALSOtools/perf/builtin-lock.c +0
-0
tools/perf/builtin-lock.c static bool add_lock_delay(char *spec) · line 2540
Quoted 4 lines
tools/perf/builtin-lock.c +1
-0@@ -2537,6 +2537,11 @@ static bool add_lock_delay(char *spec)return false; } +if (duration >10 *1000 *1000 ) {
nit: It's unfortunate the variable name isn't carrying the time unit. For example, this could be:
```
if (duration_ns > 10 * NSEC_PER_SEC) {
```which should hopefully make it clearer what the time units are and that they aren't messed up.
Thanks,
Ian
Quoted 10 lines
tools/perf/builtin-lock.c +4
-1+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
Quoted 8 lines · Namhyung Kim
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)
Quoted 7 lines
Usage: perf lock contention [<options>]
-J, --inject-delay <TIME@FUNC>
Inject delays to specific locksSuggested-by Alexei Starovoitov <[email protected]>Signed-off-by Namhyung Kim <[email protected]>
Thanks, applied to perf-tools-next,
- Arnaldo
Quoted 42 lines
--- tools/perf/Documentation/perf-lock.txt | 8 ++++++-- tools/perf/builtin-lock.c | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-)tools/perf/Documentation/perf-lock.txt +6
-2@@ -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 ALSOtools/perf/builtin-lock.c +5
-0@@ -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" );Signature · 1 line
2.49.0.1101.gccaa498523-goog
Arnaldo Carvalho de Melo
maintainerQuoted 44 lines · Namhyung Kim
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 locksSuggested-by Alexei Starovoitov <[email protected]>Signed-off-by Namhyung Kim <[email protected]>--- tools/perf/Documentation/perf-lock.txt | 8 ++++++-- tools/perf/builtin-lock.c | 5 +++++ 2 files changed, 11 insertions(+), 2 deletions(-)tools/perf/Documentation/perf-lock.txt +6
-2@@ -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 ALSOtools/perf/builtin-lock.c +0
-0
tools/perf/builtin-lock.c static bool add_lock_delay(char *spec) · line 2544
Quoted 8 lines
tools/perf/builtin-lock.c +5
-0@@ -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; + } +
Please consider to replace those 1000 * 1000 her and in other places with NSEC_PER_MSEC in a followup patch for the next merge window.
- Arnaldo
Quoted 5 lines
tools/perf/builtin-lock.c +0
-0tmp =realloc (delays, (nr_delays +1 ) *sizeof (*delays));if (tmp ==NULL ) {pr_err ("Memory allocation failure\n" );Signature · 1 line
2.49.0.1101.gccaa498523-goog