2020-10-13 16:56:04 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* test_free_pages.c: Check that free_pages() doesn't leak memory
|
|
|
|
* Copyright (c) 2020 Oracle
|
|
|
|
* Author: Matthew Wilcox <willy@infradead.org>
|
|
|
|
*/
|
|
|
|
|
2020-12-15 21:43:01 -07:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2020-10-13 16:56:04 -07:00
|
|
|
#include <linux/gfp.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
|
|
|
|
static void test_free_pages(gfp_t gfp)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 1000 * 1000; i++) {
|
|
|
|
unsigned long addr = __get_free_pages(gfp, 3);
|
2022-06-30 01:41:20 -07:00
|
|
|
struct page *page = virt_to_page((void *)addr);
|
2020-10-13 16:56:04 -07:00
|
|
|
|
|
|
|
/* Simulate page cache getting a speculative reference */
|
|
|
|
get_page(page);
|
|
|
|
free_pages(addr, 3);
|
|
|
|
put_page(page);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int m_in(void)
|
|
|
|
{
|
2020-12-15 21:43:01 -07:00
|
|
|
pr_info("Testing with GFP_KERNEL\n");
|
2020-10-13 16:56:04 -07:00
|
|
|
test_free_pages(GFP_KERNEL);
|
2020-12-15 21:43:01 -07:00
|
|
|
pr_info("Testing with GFP_KERNEL | __GFP_COMP\n");
|
2020-10-13 16:56:04 -07:00
|
|
|
test_free_pages(GFP_KERNEL | __GFP_COMP);
|
2020-12-15 21:43:01 -07:00
|
|
|
pr_info("Test completed\n");
|
2020-10-13 16:56:04 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void m_ex(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(m_in);
|
|
|
|
module_exit(m_ex);
|
|
|
|
MODULE_AUTHOR("Matthew Wilcox <willy@infradead.org>");
|
2024-06-19 13:59:15 -07:00
|
|
|
MODULE_DESCRIPTION("Check that free_pages() doesn't leak memory");
|
2020-10-13 16:56:04 -07:00
|
|
|
MODULE_LICENSE("GPL");
|