FROMGIT: mm, page_poison: use static key more efficiently
Commit 11c9c7edae
("mm/page_poison.c: replace bool variable with static
key") changed page_poisoning_enabled() to a static key check. However,
the function is not inlined, so each check still involves a function call
with overhead not eliminated when page poisoning is disabled.
Analogically to how debug_pagealloc is handled, this patch converts
page_poisoning_enabled() back to boolean check, and introduces
page_poisoning_enabled_static() for fast paths. Both functions are
inlined.
The function kernel_poison_pages() is also called unconditionally and does
the static key check inside. Remove it from there and put it to callers.
Also split it to two functions kernel_poison_pages() and
kernel_unpoison_pages() instead of the confusing bool parameter.
Also optimize the check that enables page poisoning instead of
debug_pagealloc for architectures without proper debug_pagealloc support.
Move the check to init_mem_debugging_and_hardening() to enable a single
static key instead of having two static branches in
page_poisoning_enabled_static().
Link: https://lkml.kernel.org/r/20201113104033.22907-3-vbabka@suse.cz
Signed-off-by: Vlastimil Babka <vbabka@suse.cz>
Reviewed-by: David Hildenbrand <david@redhat.com>
Cc: Mike Rapoport <rppt@linux.ibm.com>
Cc: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Cc: Alexander Potapenko <glider@google.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Laura Abbott <labbott@kernel.org>
Cc: Mateusz Nosek <mateusznosek0@gmail.com>
Cc: Michal Hocko <mhocko@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
(cherry picked from commit 8db26a3d47354ce7271a8cab03cd65b9d3d610b9
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git akpm)
Bug: 182930667
Signed-off-by: Alexander Potapenko <glider@google.com>
Change-Id: Ifc3fdf5cd58f3b8346bf81480df3836811e7458b
This commit is contained in:

committed by
Todd Kjos

parent
0879d44ddd
commit
e871c7feeb
@@ -8,45 +8,17 @@
|
||||
#include <linux/ratelimit.h>
|
||||
#include <linux/kasan.h>
|
||||
|
||||
static DEFINE_STATIC_KEY_FALSE_RO(want_page_poisoning);
|
||||
bool _page_poisoning_enabled_early;
|
||||
EXPORT_SYMBOL(_page_poisoning_enabled_early);
|
||||
DEFINE_STATIC_KEY_FALSE(_page_poisoning_enabled);
|
||||
EXPORT_SYMBOL(_page_poisoning_enabled);
|
||||
|
||||
static int __init early_page_poison_param(char *buf)
|
||||
{
|
||||
int ret;
|
||||
bool tmp;
|
||||
|
||||
ret = strtobool(buf, &tmp);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
if (tmp)
|
||||
static_branch_enable(&want_page_poisoning);
|
||||
else
|
||||
static_branch_disable(&want_page_poisoning);
|
||||
|
||||
return 0;
|
||||
return kstrtobool(buf, &_page_poisoning_enabled_early);
|
||||
}
|
||||
early_param("page_poison", early_page_poison_param);
|
||||
|
||||
/**
|
||||
* page_poisoning_enabled - check if page poisoning is enabled
|
||||
*
|
||||
* Return true if page poisoning is enabled, or false if not.
|
||||
*/
|
||||
bool page_poisoning_enabled(void)
|
||||
{
|
||||
/*
|
||||
* Assumes that debug_pagealloc_enabled is set before
|
||||
* memblock_free_all.
|
||||
* Page poisoning is debug page alloc for some arches. If
|
||||
* either of those options are enabled, enable poisoning.
|
||||
*/
|
||||
return (static_branch_unlikely(&want_page_poisoning) ||
|
||||
(!IS_ENABLED(CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC) &&
|
||||
debug_pagealloc_enabled()));
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(page_poisoning_enabled);
|
||||
|
||||
static void poison_page(struct page *page)
|
||||
{
|
||||
void *addr = kmap_atomic(page);
|
||||
@@ -58,7 +30,7 @@ static void poison_page(struct page *page)
|
||||
kunmap_atomic(addr);
|
||||
}
|
||||
|
||||
static void poison_pages(struct page *page, int n)
|
||||
void __kernel_poison_pages(struct page *page, int n)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -117,7 +89,7 @@ static void unpoison_page(struct page *page)
|
||||
kunmap_atomic(addr);
|
||||
}
|
||||
|
||||
static void unpoison_pages(struct page *page, int n)
|
||||
void __kernel_unpoison_pages(struct page *page, int n)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -125,17 +97,6 @@ static void unpoison_pages(struct page *page, int n)
|
||||
unpoison_page(page + i);
|
||||
}
|
||||
|
||||
void kernel_poison_pages(struct page *page, int numpages, int enable)
|
||||
{
|
||||
if (!page_poisoning_enabled())
|
||||
return;
|
||||
|
||||
if (enable)
|
||||
unpoison_pages(page, numpages);
|
||||
else
|
||||
poison_pages(page, numpages);
|
||||
}
|
||||
|
||||
#ifndef CONFIG_ARCH_SUPPORTS_DEBUG_PAGEALLOC
|
||||
void __kernel_map_pages(struct page *page, int numpages, int enable)
|
||||
{
|
||||
|
Reference in New Issue
Block a user