mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Geyslan Gregório" <gg@condado.dev>
To: Hui Peng <benquike@gmail.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Arnaldo Carvalho de Melo <acme@kernel.org>,
	Namhyung Kim <namhyung@kernel.org>
Cc: "Geyslan Gregório" <gg@condado.dev>,
	"Mark Rutland" <mark.rutland@arm.com>,
	"Alexander Shishkin" <alexander.shishkin@linux.intel.com>,
	"Jiri Olsa" <jolsa@kernel.org>, "Ian Rogers" <irogers@google.com>,
	"Adrian Hunter" <adrian.hunter@intel.com>,
	"James Clark" <james.clark@linaro.org>,
	linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] perf/core: fix user->locked_vm leak on secondary mmap()
Date: Wed, 14 Oct 2026 20:07:00 -0300	[thread overview]
Message-ID: <20261014230740.754550-1-gg@condado.dev> (raw)
In-Reply-To: <20260921003306.426050-1-benquike@gmail.com>

On Mon, 21 Sep 2026 00:33:06 +0000, Hui Peng wrote:
> Fix this by only calling perf_mmap_account() when allocating a new ring
> buffer in perf_mmap_rb() or a new AUX buffer in perf_mmap_aux().

Same thing I found reading perf_mmap_rb(), and I tested your patch. It
applies to current mainline (0fcb05b72344) and I confirmed the leak and
the fix there.

Instead of reading it off an EPERM I measured user->locked_vm directly:
io_uring buffer registration charges the same counter against
RLIMIT_MEMLOCK, so the largest buffer that still registers gives the page
count. x86_64 defconfig under KVM, 2 and 4 vCPUs, each case on its own
uid. Mapping a buffer three more times and unmapping all of them, pages
left charged after the last munmap(), before -> after:

  ring, one process           195 -> 0
  ring, fd handed to workers   195 -> 0
  AUX area                     192 -> 0

The charge follows the event fd, not the mm, so a supervisor that opens
per-CPU events and lets a worker map them leaks the buffer size on every
worker restart.

Your reproducer covers the ring buffer, so I ran the AUX path too. With
no PT/SPE/CoreSight here I used a throwaway test-only PMU (just
setup_aux/free_aux, enough to drive the accounting); same leak, same fix.

Tested-by: Geyslan Gregório <gg@condado.dev>

Worth noting this is independent of Lorenzo's "track the perf mlock gift
separately" [1]: that keeps perf from starving the other locked_vm users,
this kills the per-buffer double charge. Both are needed.

The reproducer and test harness were LLM-assisted; the measurements and
this report are mine.

[1] https://lore.kernel.org/all/20261003-perf-locked-vm-fix-v1-1-d214dcaf0d76@kernel.org/

Thanks,
Geyslan

      parent reply	other threads:[~2026-10-14 23:08 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-19 22:17 [PATCH] perf/core: fix locked_vm leak on alias mmap() and cross-MM pinned_vm underflow Hui Peng
2026-09-21  0:33 ` [PATCH v2] perf/core: fix user->locked_vm leak on secondary mmap() Hui Peng
2026-09-21 15:10   ` krzk
2026-09-21 15:13   ` krzk
2026-10-14 23:07   ` Geyslan Gregório [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261014230740.754550-1-gg@condado.dev \
    --to=gg@condado.dev \
    --cc=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=benquike@gmail.com \
    --cc=irogers@google.com \
    --cc=james.clark@linaro.org \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-perf-users@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mingo@redhat.com \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®