Skip to contentSkip to conversation

x86/alternatives: check replacementlen <= instrlen at build time

PATCH In review Jan Beulich 1 participant 2 messages Nov 27, 2009 – Dec 2, 2009 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/alternatives: check replacementlen <= instrlen at build time

Having run into the run-(boot-)time check a couple of times lately, I finally took time to find a build-time check so that one doesn't need to analyze the register/stack dump and resolve this (through manual lookup in vmlinux) to the offending construct. The assembler will emit a message like "Error: value of <num> too large for field of 1 bytes at <offset>", which while not pointing out the source location still makes analysis quite a bit easier.

---
 arch/x86/include/asm/alternative.h     |    1 +
 1 files changed, 1 insertion(+)
arch/x86/include/asm/alternative.h +1 -0
@@ -84,6 +84,7 @@ static inline void alternatives_smp_swit
       "	 .byte " __stringify(feature) "\n"	/* feature bit     */	\
       "	 .byte 662b-661b\n"			/* sourcelen       */	\
       "	 .byte 664f-663f\n"			/* replacementlen  */	\
+      "	 .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */	\
       ".previous\n"							\
       ".section .altinstr_replacement, \"ax\"\n"			\
       "663:\n\t" newinstr "\n664:\n"		/* replacement     */	\
#1 lore raw

[tip:x86/asm] x86/alternatives: Check replacementlen <= instrlen at build time

Commit-ID:  01be50a308be466e122c3a8b3d535f1b673ecbd2
Gitweb:     http://git.kernel.org/tip/01be50a308be466e122c3a8b3d535f1b673ecbd2
Author:     Jan Beulich <[email protected]>
AuthorDate: Fri, 27 Nov 2009 15:04:58 +0000
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 2 Dec 2009 11:39:45 +0100

x86/alternatives: Check replacementlen <= instrlen at build time

Having run into the run-(boot-)time check a couple of times lately, I finally took time to find a build-time check so that one doesn't need to analyze the register/stack dump and resolve this (through manual lookup in vmlinux) to the offending construct.

The assembler will emit a message like "Error: value of <num> too large for field of 1 bytes at <offset>", which while not pointing out the source location still makes analysis quite a bit easier.

LKML-Reference: <[email protected]>

---
 arch/x86/include/asm/alternative.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
arch/x86/include/asm/alternative.h +1 -0
index c240efc..69b74a7 100644
@@ -84,6 +84,7 @@ static inline void alternatives_smp_switch(int smp) {}
       "	 .byte " __stringify(feature) "\n"	/* feature bit     */	\
       "	 .byte 662b-661b\n"			/* sourcelen       */	\
       "	 .byte 664f-663f\n"			/* replacementlen  */	\
+      "	 .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */	\
       ".previous\n"							\
       ".section .altinstr_replacement, \"ax\"\n"			\
       "663:\n\t" newinstr "\n664:\n"		/* replacement     */	\