Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Skip to content
Commit 696f804e authored by Catalin Marinas's avatar Catalin Marinas Committed by Gerrit - the friendly Code Review server
Browse files

mm: kmemleak: allow safe memory scanning during kmemleak disabling



The kmemleak scanning thread can run for minutes.  Callbacks like
kmemleak_free() are allowed during this time, the race being taken care of
by the object->lock spinlock.  Such lock also prevents a memory block from
being freed or unmapped while it is being scanned by blocking the
kmemleak_free() -> ...  -> __delete_object() function until the lock is
released in scan_object().

When a kmemleak error occurs (e.g.  it fails to allocate its metadata),
kmemleak_enabled is set and __delete_object() is no longer called on freed
objects.  If kmemleak_scan is running at the same time, kmemleak_free() no
longer waits for the object scanning to complete, allowing the
corresponding memory block to be freed or unmapped (in the case of
vfree()).  This leads to kmemleak_scan potentially triggering a page
fault.

This patch separates the kmemleak_free() enabling/disabling from the
overall kmemleak_enabled nob so that we can defer the disabling of the
object freeing tracking until the scanning thread completed.  The
kmemleak_free_part() is deliberately ignored by this patch since this is
only called during boot before the scanning thread started.

Change-Id: Idec67be116b23ee9aa56419e8f7c9e17df0086f2
Signed-off-by: default avatarCatalin Marinas <catalin.marinas@arm.com>
Reported-by: default avatarVignesh Radhakrishnan <vigneshr@codeaurora.org>
Tested-by: default avatarVignesh Radhakrishnan <vigneshr@codeaurora.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Git-commit: d613b66e1df80fddfff8e3eaa704243a955158db
Git-repo: git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git


Signed-off-by: default avatarVignesh Radhakrishnan <vigneshr@codeaurora.org>
parent 43afbd02
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment