Skip to content

Commit de5097c

Browse files
Ingo MolnarIngo Molnar
authored andcommitted
[PATCH] mutex subsystem, more debugging code
more mutex debugging: check for held locks during memory freeing, task exit, enable sysrq printouts, etc. Signed-off-by: Ingo Molnar <[email protected]> Signed-off-by: Arjan van de Ven <[email protected]>
1 parent 408894e commit de5097c

File tree

7 files changed

+37
-0
lines changed

7 files changed

+37
-0
lines changed

arch/i386/mm/pageattr.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ void kernel_map_pages(struct page *page, int numpages, int enable)
222222
{
223223
if (PageHighMem(page))
224224
return;
225+
if (!enable)
226+
mutex_debug_check_no_locks_freed(page_address(page),
227+
page_address(page+numpages));
228+
225229
/* the return value is ignored - the calls cannot fail,
226230
* large pages are disabled at boot time.
227231
*/

drivers/char/sysrq.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,21 @@ static struct sysrq_key_op sysrq_mountro_op = {
153153

154154
/* END SYNC SYSRQ HANDLERS BLOCK */
155155

156+
#ifdef CONFIG_DEBUG_MUTEXES
157+
158+
static void
159+
sysrq_handle_showlocks(int key, struct pt_regs *pt_regs, struct tty_struct *tty)
160+
{
161+
mutex_debug_show_all_locks();
162+
}
163+
164+
static struct sysrq_key_op sysrq_showlocks_op = {
165+
.handler = sysrq_handle_showlocks,
166+
.help_msg = "show-all-locks(D)",
167+
.action_msg = "Show Locks Held",
168+
};
169+
170+
#endif
156171

157172
/* SHOW SYSRQ HANDLERS BLOCK */
158173

@@ -294,7 +309,11 @@ static struct sysrq_key_op *sysrq_key_table[SYSRQ_KEY_TABLE_LENGTH] = {
294309
#else
295310
/* c */ NULL,
296311
#endif
312+
#ifdef CONFIG_DEBUG_MUTEXES
313+
/* d */ &sysrq_showlocks_op,
314+
#else
297315
/* d */ NULL,
316+
#endif
298317
/* e */ &sysrq_term_op,
299318
/* f */ &sysrq_moom_op,
300319
/* g */ NULL,

include/linux/mm.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/rbtree.h>
1414
#include <linux/prio_tree.h>
1515
#include <linux/fs.h>
16+
#include <linux/mutex.h>
1617

1718
struct mempolicy;
1819
struct anon_vma;
@@ -1024,6 +1025,9 @@ static inline void vm_stat_account(struct mm_struct *mm,
10241025
static inline void
10251026
kernel_map_pages(struct page *page, int numpages, int enable)
10261027
{
1028+
if (!PageHighMem(page) && !enable)
1029+
mutex_debug_check_no_locks_freed(page_address(page),
1030+
page_address(page + numpages));
10271031
}
10281032
#endif
10291033

kernel/exit.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <linux/syscalls.h>
3030
#include <linux/signal.h>
3131
#include <linux/cn_proc.h>
32+
#include <linux/mutex.h>
3233

3334
#include <asm/uaccess.h>
3435
#include <asm/unistd.h>
@@ -869,6 +870,10 @@ fastcall NORET_TYPE void do_exit(long code)
869870
mpol_free(tsk->mempolicy);
870871
tsk->mempolicy = NULL;
871872
#endif
873+
/*
874+
* If DEBUG_MUTEXES is on, make sure we are holding no locks:
875+
*/
876+
mutex_debug_check_no_locks_held(tsk);
872877

873878
/* PF_DEAD causes final put_task_struct after we schedule. */
874879
preempt_disable();

kernel/sched.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4386,6 +4386,7 @@ void show_state(void)
43864386
} while_each_thread(g, p);
43874387

43884388
read_unlock(&tasklist_lock);
4389+
mutex_debug_show_all_locks();
43894390
}
43904391

43914392
/**

mm/page_alloc.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,9 @@ static void __free_pages_ok(struct page *page, unsigned int order)
415415
int reserved = 0;
416416

417417
arch_free_page(page, order);
418+
if (!PageHighMem(page))
419+
mutex_debug_check_no_locks_freed(page_address(page),
420+
page_address(page+(1<<order)));
418421

419422
#ifndef CONFIG_MMU
420423
for (i = 1 ; i < (1 << order) ; ++i)

mm/slab.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3071,6 +3071,7 @@ void kfree(const void *objp)
30713071
local_irq_save(flags);
30723072
kfree_debugcheck(objp);
30733073
c = page_get_cache(virt_to_page(objp));
3074+
mutex_debug_check_no_locks_freed(objp, objp+obj_reallen(c));
30743075
__cache_free(c, (void *)objp);
30753076
local_irq_restore(flags);
30763077
}

0 commit comments

Comments
 (0)