Skip to content

Commit a6cf4e0

Browse files
urezkitorvalds
authored andcommitted
mm/vmap: add DEBUG_AUGMENT_LOWEST_MATCH_CHECK macro
This macro adds some debug code to check that vmap allocations are happened in ascending order. By default this option is set to 0 and not active. It requires recompilation of the kernel to activate it. Set to 1, compile the kernel. [[email protected]: v4] Link: http://lkml.kernel.org/r/[email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Uladzislau Rezki (Sony) <[email protected]> Reviewed-by: Roman Gushchin <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Joel Fernandes <[email protected]> Cc: Matthew Wilcox <[email protected]> Cc: Michal Hocko <[email protected]> Cc: Oleksiy Avramchenko <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: Tejun Heo <[email protected]> Cc: Thomas Garnier <[email protected]> Cc: Thomas Gleixner <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent bb850f4 commit a6cf4e0

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

mm/vmalloc.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ EXPORT_SYMBOL(vmalloc_to_pfn);
326326
/*** Global kva allocator ***/
327327

328328
#define DEBUG_AUGMENT_PROPAGATE_CHECK 0
329+
#define DEBUG_AUGMENT_LOWEST_MATCH_CHECK 0
329330

330331
#define VM_LAZY_FREE 0x02
331332
#define VM_VM_AREA 0x04
@@ -834,6 +835,44 @@ find_vmap_lowest_match(unsigned long size,
834835
return NULL;
835836
}
836837

838+
#if DEBUG_AUGMENT_LOWEST_MATCH_CHECK
839+
#include <linux/random.h>
840+
841+
static struct vmap_area *
842+
find_vmap_lowest_linear_match(unsigned long size,
843+
unsigned long align, unsigned long vstart)
844+
{
845+
struct vmap_area *va;
846+
847+
list_for_each_entry(va, &free_vmap_area_list, list) {
848+
if (!is_within_this_va(va, size, align, vstart))
849+
continue;
850+
851+
return va;
852+
}
853+
854+
return NULL;
855+
}
856+
857+
static void
858+
find_vmap_lowest_match_check(unsigned long size)
859+
{
860+
struct vmap_area *va_1, *va_2;
861+
unsigned long vstart;
862+
unsigned int rnd;
863+
864+
get_random_bytes(&rnd, sizeof(rnd));
865+
vstart = VMALLOC_START + rnd;
866+
867+
va_1 = find_vmap_lowest_match(size, 1, vstart);
868+
va_2 = find_vmap_lowest_linear_match(size, 1, vstart);
869+
870+
if (va_1 != va_2)
871+
pr_emerg("not lowest: t: 0x%p, l: 0x%p, v: 0x%lx\n",
872+
va_1, va_2, vstart);
873+
}
874+
#endif
875+
837876
enum fit_type {
838877
NOTHING_FIT = 0,
839878
FL_FIT_TYPE = 1, /* full fit */
@@ -976,6 +1015,10 @@ __alloc_vmap_area(unsigned long size, unsigned long align,
9761015
if (ret)
9771016
return vend;
9781017

1018+
#if DEBUG_AUGMENT_LOWEST_MATCH_CHECK
1019+
find_vmap_lowest_match_check(size);
1020+
#endif
1021+
9791022
return nva_start_addr;
9801023
}
9811024

0 commit comments

Comments
 (0)