Skip to content

perf: Convert mmap() related reference counts to refcount_t

Peter Zijlstra lkml 1 version Applied

Status from this message: The following commit has been merged into the perf/core branch of tip:

Get series with b4
b4 am [email protected]

Versions newest first

  1. v3 Latest15 patches 23 repliesApplied

Changes in v3 from the cover letter

- replaced patches 4,5 with fine grained steps

Patches in v3 Applied

#Subject and filesSizeRepliesApplied
1/15perf: Remove redundant condition for AUX buffer sizekernel/events/core.c+1 -11 reply
2/15perf: Split out mlock limit handlingkernel/events/core.c+38 -371 reply
3/15perf: Split out VM accountingkernel/events/core.c+9 -41 reply
4/15perf: Move perf_mmap_calc_limits() into both rb and aux brancheskernel/events/core.c+18 -81 reply
5/15perf: Merge consecutive conditionals in perf_mmap()kernel/events/core.c+19 -221 reply
6/15perf: Move common code into both rb and aux brancheskernel/events/core.c+15 -103 replies
7/15perf: Remove redundant aux_unlock labelkernel/events/core.c+8 -91 reply
8/15perf: Use guard() for aux_mutex in perf_mmap()kernel/events/core.c+1 -51 reply
9/15perf: Reflow to get rid of aux_success labelkernel/events/core.c+18 -192 replies
10/15perf: Split out the AUX buffer allocationkernel/events/core.c+77 -671 reply
11/15perf: Make RB allocation branch self sufficientkernel/events/core.c+1 -51 reply
12/15perf: Split out the RB allocationkernel/events/core.c+73 -721 reply
13/15perf: Use scoped_guard() for mmap_mutex in perf_mmap()kernel/events/core.c+14 -184 replies
14/15perf: Identify the 0->1 transition for event::mmap_countkernel/events/core.c+1 -12 replies
15/15perf: Convert mmap() refcounts to refcount_tinclude/linux/perf_event.h kernel/events/core.c kernel/events/internal.h +1 more+24 -241 reply

Reviews trailers per patch

All 15 patches have a Reviewed-by or Acked-by.

PatchLorenzo StoakesThomas Gleixner
1/15R-b
2/15R-b
3/15R-b
4/15R-b
5/15R-b
6/15R-b
7/15R-b
8/15R-b
9/15R-b
10/15R-b Originally-by
11/15R-b
12/15R-b Originally-by
13/15R-b
14/15R-b
15/15R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v3 thread

Cover letter [PATCH v3 00/15] perf: Convert mmap() related reference counts to refcount_t

Took over the series from Thomas; much thanks to him for cleaning this up.

The recently fixed reference count leaks could have been detected by using refcount_t and refcount_t would have mitigated the potential overflow at least.

It turned out that converting the code as is does not work as the allocation code ends up doing a refcount_inc() for the first allocation, which causes refcount_t sanity checks to emit a UAF warning.

The reason is that the code is sharing functionality at the wrong level and ends up being overly complicated for no reason. That's what inevitable led to the refcount leak problems.

Address this by splitting the ringbuffer and the AUX buffer mapping and allocation parts out into seperate functions, which handle the reference counts in a sane way.

That not only simplifies the code and makes it halfways comprehensible, but also allows to convert the mmap() related reference counts to refcount_t.

It survives lightweight testing with perf and passes the perf/mmap selftest.

Also available at:

git://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git perf/core

---
v2: https://lkml.kernel.org/r/[email protected]

Changes vs v2:
- replaced patches 4,5 with fine grained steps