From: ZhangPeng zhangpeng362@huawei.com
hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8KESX CVE: NA
--------------------------------
Add enable_userswap boot option to enable userswap feature. Add static key userswap_enabled to indicate whether the feature is enabled.
Signed-off-by: ZhangPeng zhangpeng362@huawei.com --- include/linux/swapops.h | 4 ++++ mm/Makefile | 1 + mm/userswap.c | 17 +++++++++++++++++ 3 files changed, 22 insertions(+) create mode 100644 mm/userswap.c
diff --git a/include/linux/swapops.h b/include/linux/swapops.h index 6b4ed6bfb67c..4a7e53612fdb 100644 --- a/include/linux/swapops.h +++ b/include/linux/swapops.h @@ -456,8 +456,12 @@ static inline int pte_none_mostly(pte_t pte) }
#ifdef CONFIG_USERSWAP +extern struct static_key_false userswap_enabled; + static inline int is_userswap_entry(swp_entry_t entry) { + if (!static_branch_unlikely(&userswap_enabled)) + return 0; return unlikely(swp_type(entry) == SWP_USERSWAP_ENTRY); } #else diff --git a/mm/Makefile b/mm/Makefile index c51aca1d9ec7..642c6335596d 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -122,6 +122,7 @@ obj-$(CONFIG_CMA_DEBUGFS) += cma_debug.o obj-$(CONFIG_SECRETMEM) += secretmem.o obj-$(CONFIG_CMA_SYSFS) += cma_sysfs.o obj-$(CONFIG_USERFAULTFD) += userfaultfd.o +obj-$(CONFIG_USERSWAP) += userswap.o obj-$(CONFIG_IDLE_PAGE_TRACKING) += page_idle.o obj-$(CONFIG_DEBUG_PAGEALLOC) += debug_page_alloc.o obj-$(CONFIG_DEBUG_PAGE_REF) += debug_page_ref.o diff --git a/mm/userswap.c b/mm/userswap.c new file mode 100644 index 000000000000..a2f180b4457f --- /dev/null +++ b/mm/userswap.c @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) Huawei Technologies Co., Ltd. 2023. All rights reserved. + * + * userswap core file + */ + +#include "internal.h" + +DEFINE_STATIC_KEY_FALSE(userswap_enabled); + +static int __init enable_userswap_setup(char *str) +{ + static_branch_enable(&userswap_enabled); + return 1; +} +__setup("enable_userswap", enable_userswap_setup);