perf/core: fix mlock accounting in perf_mmap()
Subsystems (2)
PATCH v3 1/1 perf/core: fix mlock accounting in perf_mmap()
Eecreasing sysctl_perf_event_mlock between two consecutive perf_mmap()s of a perf ring buffer may lead to an integer underflow in locked memory accounting. This may lead to the undesired behaviors, such as failures in BPF map creation.
Address this by adjusting the accounting logic to take into account the possibility that the amount of already locked memory may exceed the current limit.
--- kernel/events/core.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
kernel/events/core.c +9 -1
@@ -5917,7 +5917,15 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma)*/ user_lock_limit *=num_online_cpus (); - user_locked =atomic_long_read (&user->locked_vm) + user_extra; + user_locked =atomic_long_read (&user->locked_vm); + +/* +* sysctl_perf_event_mlock may have changed, so that +* user->locked_vm > user_lock_limit +*/ +if (user_locked > user_lock_limit) + user_locked = user_lock_limit; + user_locked += user_extra;if (user_locked > user_lock_limit) {/*
Signature · 1 line
2.17.1
Quoted 1 line · Song Liu
Eecreasing
sysctl_perf_event_mlockbetween two consecutive perf_mmap()s of
Typo: "Decreasing".
Quoted 8 lines
a perf ring buffer may lead to an integer underflow in locked memory accounting. This may lead to the undesired behaviors, such as failures in BPF map creation.
Address this by adjusting the accounting logic to take into account the possibility that the amount of already locked memory may exceed the current limit.
Quoted 7 lines
Fixes c4b75479741c ("perf/core: Make the mlock accounting simple again")Signed-off-by Song Liu <[email protected]>Suggested-by Alexander Shishkin <[email protected]>Cc Alexander Shishkin <[email protected]>Cc Arnaldo Carvalho de Melo <[email protected]>Cc Jiri Olsa <[email protected]>Cc Peter Zijlstra <[email protected]>
Other than that,
Thanks,
--
Alex
Thanks Alex!
Quoted 7 lines · Alexander Shishkin
Quoted 1 line · Song Liu
Eecreasing
sysctl_perf_event_mlockbetween two consecutive perf_mmap()s ofTypo: "Decreasing".
Peter, could you please fix this typo when you apply the patch? I guess it is not necessary to spam the list with a v4 just for this typo.
Thanks,
Song
Quoted 24 lines
Quoted 9 lines
a perf ring buffer may lead to an integer underflow in locked memory accounting. This may lead to the undesired behaviors, such as failures in BPF map creation.
Address this by adjusting the accounting logic to take into account the possibility that the amount of already locked memory may exceed the current limit.
Quoted 7 lines
Fixes c4b75479741c ("perf/core: Make the mlock accounting simple again")Signed-off-by Song Liu <[email protected]>Suggested-by Alexander Shishkin <[email protected]>Cc Alexander Shishkin <[email protected]>Cc Arnaldo Carvalho de Melo <[email protected]>Cc Jiri Olsa <[email protected]>Cc Peter Zijlstra <[email protected]>Other than that,
Thanks,
--
Alex
Peter Zijlstra
maintainerQuoted 4 lines · Song Liu
Thanks Alex!
Quoted 2 lines · Alexander Shishkin
Quoted 8 lines
Quoted 5 lines
Quoted 1 line · Song Liu
Eecreasing
sysctl_perf_event_mlockbetween two consecutive perf_mmap()s ofTypo: "Decreasing".
Peter, could you please fix this typo when you apply the patch? I guess it is not necessary to spam the list with a v4 just for this typo.
Done!
[tip: perf/urgent] perf/core: Fix mlock accounting in perf_mmap()
In reply to Song LiuThe following commit has been merged into the perf/urgent branch of tip:
The following commit has been merged into the perf/urgent branch of tip:
Commit-ID: 003461559ef7a9bd0239bae35a22ad8924d6e9ad Gitweb: https://git.kernel.org/tip/003461559ef7a9bd0239bae35a22ad8924d6e9ad Author: Song Liu <[email protected]> AuthorDate: Thu, 23 Jan 2020 10:11:46 -08:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Tue, 28 Jan 2020 21:20:18 +01:00
perf/core: Fix mlock accounting in perf_mmap()
Decreasing sysctl_perf_event_mlock between two consecutive perf_mmap()s of a perf ring buffer may lead to an integer underflow in locked memory accounting. This may lead to the undesired behaviors, such as failures in BPF map creation.
Address this by adjusting the accounting logic to take into account the possibility that the amount of already locked memory may exceed the current limit.
--- kernel/events/core.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
kernel/events/core.c +9 -1
@@ -5916,7 +5916,15 @@ accounting:*/ user_lock_limit *=num_online_cpus (); - user_locked =atomic_long_read (&user->locked_vm) + user_extra; + user_locked =atomic_long_read (&user->locked_vm); + +/* +* sysctl_perf_event_mlock may have changed, so that +* user->locked_vm > user_lock_limit +*/ +if (user_locked > user_lock_limit) + user_locked = user_lock_limit; + user_locked += user_extra;if (user_locked > user_lock_limit) {/*