Prev: [RFC][PATCH 0/2] kmemleak: Fix some false positives with special scan
Next: [PATCH 1/2] kmemleak: Fix some false positives with special scan
From: Hiroshi DOYU on 14 May 2010 03:20 From: Hiroshi DOYU <Hiroshi.DOYU(a)nokia.com> The pointer is converted to a physical address with attribution bits. The test can be done either with special scan or without special scan, which can be specified with the kernel module parameter, "use_special". This can be squashed into kmemleak-test.c if necessary. Signed-off-by: Hiroshi DOYU <Hiroshi.DOYU(a)nokia.com> --- mm/Makefile | 2 +- mm/kmemleak-special-test.c | 89 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+), 1 deletions(-) create mode 100644 mm/kmemleak-special-test.c diff --git a/mm/Makefile b/mm/Makefile index 6c2a73a..bad26d4 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -43,4 +43,4 @@ obj-$(CONFIG_CGROUP_MEM_RES_CTLR) += memcontrol.o page_cgroup.o obj-$(CONFIG_MEMORY_FAILURE) += memory-failure.o obj-$(CONFIG_HWPOISON_INJECT) += hwpoison-inject.o obj-$(CONFIG_DEBUG_KMEMLEAK) += kmemleak.o -obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o +obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o kmemleak-special-test.o diff --git a/mm/kmemleak-special-test.c b/mm/kmemleak-special-test.c new file mode 100644 index 0000000..602d595 --- /dev/null +++ b/mm/kmemleak-special-test.c @@ -0,0 +1,89 @@ +/* + * kmemleak: special test + * + * Copyright (C) 2010 Nokia Corporation + * + * Written by Hiroshi DOYU <Hiroshi.DOYU(a)nokia.com> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#define DEBUG + +#include <linux/module.h> +#include <linux/kmemleak.h> + +static bool use_special; +module_param(use_special, bool, 0644); +MODULE_PARM_DESC(use_special, "Enable special scan mode"); + +#define MAXELEMENT 8 +static u32 elements[MAXELEMENT]; + +static u32 custom_conversion(u32 orig) +{ + u32 addr = orig; + + addr &= ~1; + addr = (u32)phys_to_virt(addr); + + pr_debug("%s: %08x -> %08x\n", __func__, orig, addr); + + return addr; +} + +static int __init kmemleak_special_init(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(elements); i++) { + void *virt; + + virt = kmalloc(SZ_1K, GFP_KERNEL); + BUG_ON(!virt); + + /* fill out some markers */ + memset(virt, 0xa5, SZ_1K); + *(char *)virt = i; + + elements[i] = virt_to_phys(virt) | 1; + + pr_debug("%s(%d): store %d@%p -> %08x\n", + __func__, use_special, SZ_1K, virt, elements[i]); + } + + if (use_special) { + int err; + + + err = kmemleak_special_scan(elements, sizeof(elements), + custom_conversion); + WARN_ON(err); + } + + return 0; +} +module_init(kmemleak_special_init); + +static void __exit kmemleak_special_exit(void) +{ + int i; + + if (use_special) + kmemleak_no_special(elements); + + for (i = 0; i < ARRAY_SIZE(elements); i++) { + u32 val; + + val = elements[i]; + val &= ~1; + kfree(phys_to_virt(val)); + } +} +module_exit(kmemleak_special_exit); + +MODULE_DESCRIPTION("kmemleak: special test"); +MODULE_AUTHOR("Hiroshi DOYU <Hiroshi.DOYU(a)nokia.com>"); +MODULE_LICENSE("GPL v2"); -- 1.7.1.rc1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo(a)vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ |