Skip to content

Commit

Permalink
mm/cma: make kmemleak ignore CMA regions
Browse files Browse the repository at this point in the history
kmemleak will add allocations as objects to a pool.  The memory allocated
for each object in this pool is periodically searched for pointers to
other allocated objects.  This only works for memory that is mapped into
the kernel's virtual address space, which happens not to be the case for
most CMA regions.

Furthermore, CMA regions are typically used to store data transferred to
or from a device and therefore don't contain pointers to other objects.

Without this, the kernel crashes on the first execution of the
scan_gray_list() because it tries to access highmem.  Perhaps a more
appropriate fix would be to reject any object that can't map to a kernel
virtual address?

[[email protected]: add comment]
[[email protected]: fix comment, per Catalin]
[[email protected]: include linux/io.h for phys_to_virt()]
Signed-off-by: Thierry Reding <[email protected]>
Cc: Michal Nazarewicz <[email protected]>
Cc: Marek Szyprowski <[email protected]>
Cc: Joonsoo Kim <[email protected]>
Cc: "Aneesh Kumar K.V" <[email protected]>
Cc: Catalin Marinas <[email protected]>
Signed-off-by: Stephen Rothwell <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
thierryreding authored and torvalds committed Dec 13, 2014
1 parent dee2f8a commit 620951e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions mm/cma.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <linux/log2.h>
#include <linux/cma.h>
#include <linux/highmem.h>
#include <linux/io.h>

struct cma {
unsigned long base_pfn;
Expand Down Expand Up @@ -324,6 +325,11 @@ int __init cma_declare_contiguous(phys_addr_t base,
}
}

/*
* kmemleak scans/reads tracked objects for pointers to other
* objects but this address isn't mapped and accessible
*/
kmemleak_ignore(phys_to_virt(addr));
base = addr;
}

Expand Down

0 comments on commit 620951e

Please sign in to comment.