提交 2262320a 编写于 作者: N Nathan Chancellor 提交者: Zheng Zengkai

MIPS: tlbex: Explicitly compare _PAGE_NO_EXEC against 0

stable inclusion
from stable-v5.10.138
commit 059f47b3a433b768135618b6a947084ed9876550
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I60QFD

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=059f47b3a433b768135618b6a947084ed9876550

--------------------------------

[ Upstream commit 74de14fe ]

When CONFIG_XPA is enabled, Clang warns:

  arch/mips/mm/tlbex.c:629:24: error: converting the result of '<<' to a boolean; did you mean '(1 << _PAGE_NO_EXEC_SHIFT) != 0'? [-Werror,-Wint-in-bool-context]
          if (cpu_has_rixi && !!_PAGE_NO_EXEC) {
                              ^
  arch/mips/include/asm/pgtable-bits.h:174:28: note: expanded from macro '_PAGE_NO_EXEC'
  # define _PAGE_NO_EXEC          (1 << _PAGE_NO_EXEC_SHIFT)
                                     ^
  arch/mips/mm/tlbex.c:2568:24: error: converting the result of '<<' to a boolean; did you mean '(1 << _PAGE_NO_EXEC_SHIFT) != 0'? [-Werror,-Wint-in-bool-context]
          if (!cpu_has_rixi || !_PAGE_NO_EXEC) {
                                ^
  arch/mips/include/asm/pgtable-bits.h:174:28: note: expanded from macro '_PAGE_NO_EXEC'
  # define _PAGE_NO_EXEC          (1 << _PAGE_NO_EXEC_SHIFT)
                                     ^
  2 errors generated.

_PAGE_NO_EXEC can be '0' or '1 << _PAGE_NO_EXEC_SHIFT' depending on the
build and runtime configuration, which is what the negation operators
are trying to convey. To silence the warning, explicitly compare against
0 so the result of the '<<' operator is not implicitly converted to a
boolean.

According to its documentation, GCC enables -Wint-in-bool-context with
-Wall but this warning is not visible when building the same
configuration with GCC. It appears GCC only warns when compiling C++,
not C, although the documentation makes no note of this:
https://godbolt.org/z/x39q3brxfReported-by: NSudip Mukherjee (Codethink) <sudipm.mukherjee@gmail.com>
Signed-off-by: NNathan Chancellor <nathan@kernel.org>
Signed-off-by: NThomas Bogendoerfer <tsbogend@alpha.franken.de>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
Reviewed-by: NWei Li <liwei391@huawei.com>
上级 fb2253f9
...@@ -633,7 +633,7 @@ static __maybe_unused void build_convert_pte_to_entrylo(u32 **p, ...@@ -633,7 +633,7 @@ static __maybe_unused void build_convert_pte_to_entrylo(u32 **p,
return; return;
} }
if (cpu_has_rixi && !!_PAGE_NO_EXEC) { if (cpu_has_rixi && _PAGE_NO_EXEC != 0) {
if (fill_includes_sw_bits) { if (fill_includes_sw_bits) {
UASM_i_ROTR(p, reg, reg, ilog2(_PAGE_GLOBAL)); UASM_i_ROTR(p, reg, reg, ilog2(_PAGE_GLOBAL));
} else { } else {
...@@ -2572,7 +2572,7 @@ static void check_pabits(void) ...@@ -2572,7 +2572,7 @@ static void check_pabits(void)
unsigned long entry; unsigned long entry;
unsigned pabits, fillbits; unsigned pabits, fillbits;
if (!cpu_has_rixi || !_PAGE_NO_EXEC) { if (!cpu_has_rixi || _PAGE_NO_EXEC == 0) {
/* /*
* We'll only be making use of the fact that we can rotate bits * We'll only be making use of the fact that we can rotate bits
* into the fill if the CPU supports RIXI, so don't bother * into the fill if the CPU supports RIXI, so don't bother
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册