From 55308a20138c3ea39a0882265f255c5b0f931f20 Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Wed, 3 Sep 2003 11:12:33 -0700 Subject: [PATCH] [PATCH] more slab page checking Add checks for kfree() of a page which was allocated with __alloc_pages(), and for free_pages() of a page which was allocated with kmalloc(). --- include/linux/page-flags.h | 2 ++ mm/page_alloc.c | 1 + mm/slab.c | 3 ++- 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index d4fd6bb3ca431..006fde0295d54 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -191,6 +191,8 @@ extern void get_full_page_state(struct page_state *ret); #define PageSlab(page) test_bit(PG_slab, &(page)->flags) #define SetPageSlab(page) set_bit(PG_slab, &(page)->flags) #define ClearPageSlab(page) clear_bit(PG_slab, &(page)->flags) +#define TestClearPageSlab(page) test_and_clear_bit(PG_slab, &(page)->flags) +#define TestSetPageSlab(page) test_and_set_bit(PG_slab, &(page)->flags) #ifdef CONFIG_HIGHMEM #define PageHighMem(page) test_bit(PG_highmem, &(page)->flags) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 453f291437ab6..2ac25b6c141f0 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -220,6 +220,7 @@ static inline void free_pages_check(const char *function, struct page *page) 1 << PG_locked | 1 << PG_active | 1 << PG_reclaim | + 1 << PG_slab | 1 << PG_writeback ))) bad_page(function, page); if (PageDirty(page)) diff --git a/mm/slab.c b/mm/slab.c index 6093193d0456f..f54d4e83c7f3c 100644 --- a/mm/slab.c +++ b/mm/slab.c @@ -787,7 +787,8 @@ static inline void kmem_freepages (kmem_cache_t *cachep, void *addr) * vm_scan(). Shouldn't be a worry. */ while (i--) { - ClearPageSlab(page); + if (!TestClearPageSlab(page)) + BUG(); page++; } sub_page_state(nr_slab, nr_freed); -- 2.53.0