Re: [tip: perf/urgent] perf/aux: Fix tracking of auxiliary trace buffer allocation

From: Alexander Shishkin
Date: Fri Nov 15 2019 - 11:07:07 EST


"tip-bot2 for Thomas Richter" <tip-bot2@xxxxxxxxxxxxx> writes:

> /* now it's safe to free the pages */
> - atomic_long_sub(rb->aux_nr_pages, &mmap_user->locked_vm);
> - atomic64_sub(rb->aux_mmap_locked, &vma->vm_mm->pinned_vm);
> + if (!rb->aux_mmap_locked)
> + atomic_long_sub(rb->aux_nr_pages, &mmap_user->locked_vm);
> + else
> + atomic64_sub(rb->aux_mmap_locked, &vma->vm_mm->pinned_vm);

This only works correctly when rb->aux_mmap_locked is either equal to
rb->aux_nr_pages or zero. Otherwise, it leaks

rb->aux_nr_pages - rb->aux_mmap_locked

in the locked_vm permanently.

Regards,
--
Alex