diff --git a/mm/kfence/core.c b/mm/kfence/core.c index 66076d8742b7..d25202766fbb 100644 --- a/mm/kfence/core.c +++ b/mm/kfence/core.c @@ -510,6 +510,7 @@ static bool __init kfence_init_pool(void) unsigned long addr = (unsigned long)__kfence_pool; struct page *pages; int i; + char *p; if (!__kfence_pool) return false; @@ -592,6 +593,16 @@ err: * fails for the first page, and therefore expect addr==__kfence_pool in * most failure cases. */ + for (p = (char *)addr; p < __kfence_pool + KFENCE_POOL_SIZE; p += PAGE_SIZE) { + struct page *page = virt_to_page(p); + + if (!PageSlab(page)) + continue; +#ifdef CONFIG_MEMCG + page->memcg_data = 0; +#endif + __ClearPageSlab(page); + } memblock_free_late(__pa(addr), KFENCE_POOL_SIZE - (addr - (unsigned long)__kfence_pool)); __kfence_pool = NULL; return false;