From: Ma Wupeng mawupeng1@huawei.com
hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I4SK3S CVE: NA
------------------------------------------
With the patch, Memory reliable features can only be disabled via /proc/sys/vm/reliable_debug. Pervious features can be enabled via this interface and this may lead to tricky counting or limit problem.
Signed-off-by: Ma Wupeng mawupeng1@huawei.com Reviewed-by: Kefeng Wang wangkefeng.wang@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- Documentation/sysctl/vm.txt | 7 +++--- mm/mem_reliable.c | 45 ++++++++++++++----------------------- 2 files changed, 21 insertions(+), 31 deletions(-)
diff --git a/Documentation/sysctl/vm.txt b/Documentation/sysctl/vm.txt index b2a1e9ac4fb27..b3808f1236f89 100644 --- a/Documentation/sysctl/vm.txt +++ b/Documentation/sysctl/vm.txt @@ -928,7 +928,8 @@ configurations.
reliable_debug:
-reliable_debug is used to control memory reliable features. +reliable_debug is used to control memory reliable features and can only be +disabled via this interface.
Four bits are used to represent the following features - bit 0: memory reliable feature @@ -939,8 +940,8 @@ Four bits are used to represent the following features Bit 1~3 are valid if and only if the bit 0 is 1. If the first bit is 0, all other features will be closed no matter other bits's status.
-For example, you can enable reliable fallback feature by +For example, you can disable all features by
- $ echo 3 > /proc/sys/vm/reliable_debug + $ echo 0 > /proc/sys/vm/reliable_debug
============ End of Document ================================= diff --git a/mm/mem_reliable.c b/mm/mem_reliable.c index 7ce97184e08ec..d02159b0182fa 100644 --- a/mm/mem_reliable.c +++ b/mm/mem_reliable.c @@ -241,19 +241,16 @@ int reliable_limit_handler(struct ctl_table *table, int write, return ret; }
-static void mem_reliable_feature_set(int idx, bool enable); +static void mem_reliable_feature_disable(int idx);
#define CTRL_BITS_SHIFT MEM_RELIABLE_MAX #define CTRL_BITS_MASK ((1 << CTRL_BITS_SHIFT) - 1)
static unsigned long mem_reliable_ctrl_bits = CTRL_BITS_MASK;
-static void mem_reliable_ctrl_bit_set(int idx, bool enable) +static void mem_reliable_ctrl_bit_disabled(int idx) { - if (enable) - set_bit(idx, &mem_reliable_ctrl_bits); - else - clear_bit(idx, &mem_reliable_ctrl_bits); + clear_bit(idx, &mem_reliable_ctrl_bits); }
static bool mem_reliable_ctrl_bit_is_enabled(int idx) @@ -266,25 +263,16 @@ static void mem_reliable_parse_ctrl_bits(unsigned long ctrl_bits) bool status; int i;
- if (!mem_reliable_is_enabled()) { - static_branch_enable(&mem_reliable); - mem_reliable_ctrl_bit_set(MEM_RELIABLE_ALL, 1); - pr_info("memory reliable feature enabled.\n"); - } - for (i = MEM_RELIABLE_FALLBACK; i < MEM_RELIABLE_MAX; i++) { status = !!test_bit(i, &ctrl_bits);
- if (mem_reliable_ctrl_bit_is_enabled(i) ^ status) - mem_reliable_feature_set(i, status); + if (mem_reliable_ctrl_bit_is_enabled(i) && !status) + mem_reliable_feature_disable(i); } }
static void mem_reliable_disable_all(void) { - if (!mem_reliable_is_enabled()) - return; - mem_reliable_ctrl_bits = 0;
reliable_allow_fallback = false; @@ -306,7 +294,8 @@ int reliable_debug_handler(struct ctl_table *table, int write, old_ctrl_bits = mem_reliable_ctrl_bits; ret = proc_doulongvec_minmax(table, write, buffer, length, ppos); if (ret == 0 && write) { - if (mem_reliable_ctrl_bits > (1 << CTRL_BITS_SHIFT) - 1) { + if (!mem_reliable_is_enabled() || + (mem_reliable_ctrl_bits > (1 << CTRL_BITS_SHIFT) - 1)) { mem_reliable_ctrl_bits = old_ctrl_bits; mutex_unlock(&reliable_debug_mutex);
@@ -483,24 +472,24 @@ static int __init reliable_sysctl_init(void) } late_initcall(reliable_sysctl_init); #else -static void mem_reliable_ctrl_bit_set(int idx, bool enable) {} +static void mem_reliable_ctrl_bit_disabled(int idx) {} #endif
-static void mem_reliable_feature_set(int idx, bool enable) +static void mem_reliable_feature_disable(int idx) { char *str = NULL;
switch (idx) { case MEM_RELIABLE_FALLBACK: - reliable_allow_fallback = enable; + reliable_allow_fallback = false; str = "fallback"; break; case MEM_RELIABLE_SHM: - shmem_reliable = enable; + shmem_reliable = false; str = "shmem"; break; case MEM_RELIABLE_PAGECACHE: - pagecache_use_reliable_mem = enable; + pagecache_use_reliable_mem = false; str = "pagecache"; break; default: @@ -508,8 +497,8 @@ static void mem_reliable_feature_set(int idx, bool enable) return; }
- mem_reliable_ctrl_bit_set(idx, enable); - pr_info("%s is %s\n", str, enable ? "enabled" : "disabled"); + mem_reliable_ctrl_bit_disabled(idx); + pr_info("%s is disabled\n", str); }
void reliable_show_mem_info(void) @@ -556,13 +545,13 @@ static int __init setup_reliable_debug(char *str) for (; *str && *str != ','; str++) { switch (*str) { case 'F': - mem_reliable_feature_set(MEM_RELIABLE_FALLBACK, false); + mem_reliable_feature_disable(MEM_RELIABLE_FALLBACK); break; case 'S': - mem_reliable_feature_set(MEM_RELIABLE_SHM, false); + mem_reliable_feature_disable(MEM_RELIABLE_SHM); break; case 'P': - mem_reliable_feature_set(MEM_RELIABLE_PAGECACHE, false); + mem_reliable_feature_disable(MEM_RELIABLE_PAGECACHE); break; default: pr_err("reliable_debug option '%c' unknown. skipped\n",