Skip to contentSkip to conversation

kmemleak: Inform kmemleak about pid_hash

PATCH New Catalin Marinas 1 participant 1 message Jun 29, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kmemleak: Inform kmemleak about pid_hash

Kmemleak does not track alloc_bootmem calls but the pid_hash allocated in pidhash_init() would need to be scanned as it contains pointers to struct pid objects.

---

FYI, tracking all alloc/free_bootmem calls in kmemleak was raised in the past but this is not simple as alloc/reserve/free_bootmem aren't always used as alloc/free pairs and this may confuse kmemleak. There are also not many places where alloc_bootmem memory contains pointers to other objects to be worth scanning.

 kernel/pid.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
kernel/pid.c +7 -0
index 31310b5..5fa1db4 100644
@@ -36,6 +36,7 @@
 #include <linux/pid_namespace.h>
 #include <linux/init_task.h>
 #include <linux/syscalls.h>
+#include <linux/kmemleak.h>
 
 #define pid_hashfn(nr, ns)	\
 	hash_long((unsigned long)nr + (unsigned long)ns, pidhash_shift)
@@ -512,6 +513,12 @@ void __init pidhash_init(void)
 	pid_hash = alloc_bootmem(pidhash_size *	sizeof(*(pid_hash)));
 	if (!pid_hash)
 		panic("Could not alloc pidhash!\n");
+	/*
+	 * pid_hash contains references to allocated struct pid objects and it
+	 * must be scanned by kmemleak to avoid false positives.
+	 */
+	kmemleak_alloc(pid_hash, pidhash_size *	sizeof(*(pid_hash)), 0,
+		       GFP_KERNEL);
 	for (i = 0; i < pidhash_size; i++)
 		INIT_HLIST_HEAD(&pid_hash[i]);
 }