From dd0716c2b87792ebea30864e7ad1df461d4c1525 Mon Sep 17 00:00:00 2001 From: Borislav Petkov Date: Thu, 16 May 2024 12:22:40 +0200 Subject: x86/boot: Add a fallthrough annotation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add implicit fallthrough checking to the decompressor code and fix this warning: arch/x86/boot/printf.c: In function ‘vsprintf’: arch/x86/boot/printf.c:248:10: warning: this statement may fall through [-Wimplicit-fallthrough=] 248 | flags |= SMALL; | ^ arch/x86/boot/printf.c:249:3: note: here 249 | case 'X': | ^~~~ This is a patch from three years ago which I found in my trees, thus the SUSE authorship still. Signed-off-by: Borislav Petkov Signed-off-by: Borislav Petkov (AMD) Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/r/20240516102240.16270-1-bp@kernel.org --- arch/x86/boot/Makefile | 1 + arch/x86/boot/printf.c | 1 + 2 files changed, 2 insertions(+) diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile index 3cece19b7473..343aef6d752f 100644 --- a/arch/x86/boot/Makefile +++ b/arch/x86/boot/Makefile @@ -69,6 +69,7 @@ KBUILD_CFLAGS := $(REALMODE_CFLAGS) -D_SETUP KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__ KBUILD_CFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=) KBUILD_CFLAGS += -fno-asynchronous-unwind-tables +KBUILD_CFLAGS += $(CONFIG_CC_IMPLICIT_FALLTHROUGH) GCOV_PROFILE := n UBSAN_SANITIZE := n diff --git a/arch/x86/boot/printf.c b/arch/x86/boot/printf.c index 1237beeb9540..c0ec1dc355ab 100644 --- a/arch/x86/boot/printf.c +++ b/arch/x86/boot/printf.c @@ -246,6 +246,7 @@ int vsprintf(char *buf, const char *fmt, va_list args) case 'x': flags |= SMALL; + fallthrough; case 'X': base = 16; break; -- cgit v1.2.3 From 82110ae235e0560d1f952f74f9fd991587b0e3a7 Mon Sep 17 00:00:00 2001 From: Nathan Chancellor Date: Thu, 16 May 2024 07:03:41 -0700 Subject: x86/boot: Address clang -Wimplicit-fallthrough in vsprintf() After enabling -Wimplicit-fallthrough for the x86 boot code, clang warns: arch/x86/boot/printf.c:257:3: warning: unannotated fall-through between switch labels [-Wimplicit-fallthrough] 257 | case 'u': | ^ Clang is a little more pedantic than GCC, which does not warn when falling through to a case that is just break or return. Clang's version is more in line with the kernel's own stance in deprecated.rst, which states that all switch/case blocks must end in either break, fallthrough, continue, goto, or return. Add the missing break to silence the warning. Fixes: dd0716c2b877 ("x86/boot: Add a fallthrough annotation") Reported-by: kernel test robot Signed-off-by: Nathan Chancellor Signed-off-by: Ingo Molnar Acked-by: Justin Stitt Link: https://lore.kernel.org/r/20240516-x86-boot-fix-clang-implicit-fallthrough-v1-1-04dc320ca07c@kernel.org Closes: https://lore.kernel.org/oe-kbuild-all/202405162054.ryP73vy1-lkp@intel.com/ --- arch/x86/boot/printf.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/x86/boot/printf.c b/arch/x86/boot/printf.c index c0ec1dc355ab..51dc14b714f6 100644 --- a/arch/x86/boot/printf.c +++ b/arch/x86/boot/printf.c @@ -254,6 +254,8 @@ int vsprintf(char *buf, const char *fmt, va_list args) case 'd': case 'i': flags |= SIGN; + break; + case 'u': break; -- cgit v1.2.3 From 9dba9c67e52dbe0978c0e86c994891eba480adf0 Mon Sep 17 00:00:00 2001 From: "Borislav Petkov (AMD)" Date: Wed, 15 May 2024 12:48:04 +0200 Subject: x86/alternatives: Use the correct length when optimizing NOPs Commit in Fixes moved the optimize_nops() call inside apply_relocation() and made it a second optimization pass after the relocations have been done. Since optimize_nops() works only on NOPs, that is fine and it'll simply jump over instructions which are not NOPs. However, it made that call with repl_len as the buffer length to optimize. However, it can happen that there are alternatives calls like this one: alternative("mfence; lfence", "", ALT_NOT(X86_FEATURE_APIC_MSRS_FENCE)); where the replacement length is 0. And using repl_len is wrong because apply_alternatives() expands the buffer size to the length of the source insn that is being patched, by padding it with one-byte NOPs: for (; insn_buff_sz < a->instrlen; insn_buff_sz++) insn_buff[insn_buff_sz] = 0x90; Long story short: pass the length of the original instruction(s) as the length of the temporary buffer which to optimize. Result: SMP alternatives: feat: 11*32+27, old: (lapic_next_deadline+0x9/0x50 (ffffffff81061829) len: 6), repl: (ffffffff89b1cc60, len: 0) flags: 0x1 SMP alternatives: ffffffff81061829: old_insn: 0f ae f0 0f ae e8 SMP alternatives: ffffffff81061829: final_insn: 90 90 90 90 90 90 => SMP alternatives: feat: 11*32+27, old: (lapic_next_deadline+0x9/0x50 (ffffffff81061839) len: 6), repl: (ffffffff89b1cc60, len: 0) flags: 0x1 SMP alternatives: ffffffff81061839: [0:6) optimized NOPs: 66 0f 1f 44 00 00 SMP alternatives: ffffffff81061839: old_insn: 0f ae f0 0f ae e8 SMP alternatives: ffffffff81061839: final_insn: 66 0f 1f 44 00 00 Fixes: da8f9cf7e721 ("x86/alternatives: Get rid of __optimize_nops()") Signed-off-by: Borislav Petkov (AMD) Signed-off-by: Ingo Molnar Link: https://lore.kernel.org/r/20240515104804.32004-1-bp@kernel.org --- arch/x86/kernel/alternative.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index 7555c15b7183..89de61243272 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -372,7 +372,7 @@ static void __apply_relocation(u8 *buf, const u8 * const instr, size_t instrlen, void apply_relocation(u8 *buf, const u8 * const instr, size_t instrlen, u8 *repl, size_t repl_len) { __apply_relocation(buf, instr, instrlen, repl, repl_len); - optimize_nops(instr, buf, repl_len); + optimize_nops(instr, buf, instrlen); } /* Low-level backend functions usable from alternative code replacements. */ -- cgit v1.2.3