提交 ce7f20d0 编写于 作者: L Lin Yujun 提交者: Zheng Zengkai

Re-add padlen to the structure alt_instr

hulk inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I5QC2M
CVE: NA

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

After optimize_nops() is optimized, redundant padlen is
deleted, and ALT_ENTRY_SIZE is reduced to 12. However,
the ALT_ENTRY_SIZE used by previously compiled .ko is
still 13. As a result, an error is reported when the
previously compiled .ko is inserted:

kernel BUG at arch/x86/kernel/alternative.c:444!
invalid opcode: 000 [#1] SMP PTI

Add 'padlen' back and change ALT_ENTRY_SIZE back to 13
to solve the problem.

Fixes: e68db6f780c6 ("x86/alternatives: Optimize optimize_nops()")
Signed-off-by: NLin Yujun <linyujun809@huawei.com>
Reviewed-by: NZhang Jianhua <chris.zjh@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 055190f0
...@@ -65,6 +65,7 @@ struct alt_instr { ...@@ -65,6 +65,7 @@ struct alt_instr {
u16 cpuid; /* cpuid bit set for replacement */ u16 cpuid; /* cpuid bit set for replacement */
u8 instrlen; /* length of original instruction */ u8 instrlen; /* length of original instruction */
u8 replacementlen; /* length of new instruction */ u8 replacementlen; /* length of new instruction */
u8 padlen; /* length of build-time padding */
} __packed; } __packed;
/* /*
...@@ -105,6 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end) ...@@ -105,6 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
#define alt_end_marker "663" #define alt_end_marker "663"
#define alt_slen "662b-661b" #define alt_slen "662b-661b"
#define alt_pad_len alt_end_marker"b-662b"
#define alt_total_slen alt_end_marker"b-661b" #define alt_total_slen alt_end_marker"b-661b"
#define alt_rlen(num) e_replacement(num)"f-"b_replacement(num)"f" #define alt_rlen(num) e_replacement(num)"f-"b_replacement(num)"f"
...@@ -151,7 +153,8 @@ static inline int alternatives_text_reserved(void *start, void *end) ...@@ -151,7 +153,8 @@ static inline int alternatives_text_reserved(void *start, void *end)
" .long " b_replacement(num)"f - .\n" /* new instruction */ \ " .long " b_replacement(num)"f - .\n" /* new instruction */ \
" .word " __stringify(feature) "\n" /* feature bit */ \ " .word " __stringify(feature) "\n" /* feature bit */ \
" .byte " alt_total_slen "\n" /* source len */ \ " .byte " alt_total_slen "\n" /* source len */ \
" .byte " alt_rlen(num) "\n" /* replacement len */ " .byte " alt_rlen(num) "\n" /* replacement len */ \
" .byte " alt_pad_len "\n" /* pad len */
#define ALTINSTR_REPLACEMENT(newinstr, feature, num) /* replacement */ \ #define ALTINSTR_REPLACEMENT(newinstr, feature, num) /* replacement */ \
"# ALT: replacement " #num "\n" \ "# ALT: replacement " #num "\n" \
...@@ -311,12 +314,13 @@ static inline int alternatives_text_reserved(void *start, void *end) ...@@ -311,12 +314,13 @@ static inline int alternatives_text_reserved(void *start, void *end)
* enough information for the alternatives patching code to patch an * enough information for the alternatives patching code to patch an
* instruction. See apply_alternatives(). * instruction. See apply_alternatives().
*/ */
.macro altinstruction_entry orig alt feature orig_len alt_len .macro altinstruction_entry orig alt feature orig_len alt_len pad_len
.long \orig - . .long \orig - .
.long \alt - . .long \alt - .
.word \feature .word \feature
.byte \orig_len .byte \orig_len
.byte \alt_len .byte \alt_len
.byte \pad_len
.endm .endm
/* /*
...@@ -333,7 +337,7 @@ static inline int alternatives_text_reserved(void *start, void *end) ...@@ -333,7 +337,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
142: 142:
.pushsection .altinstructions,"a" .pushsection .altinstructions,"a"
altinstruction_entry 140b,143f,\feature,142b-140b,144f-143f altinstruction_entry 140b,143f,\feature,142b-140b,144f-143f,142b-141b
.popsection .popsection
.pushsection .altinstr_replacement,"ax" .pushsection .altinstr_replacement,"ax"
...@@ -370,8 +374,8 @@ static inline int alternatives_text_reserved(void *start, void *end) ...@@ -370,8 +374,8 @@ static inline int alternatives_text_reserved(void *start, void *end)
142: 142:
.pushsection .altinstructions,"a" .pushsection .altinstructions,"a"
altinstruction_entry 140b,143f,\feature1,142b-140b,144f-143f altinstruction_entry 140b,143f,\feature1,142b-140b,144f-143f,142b-141b
altinstruction_entry 140b,144f,\feature2,142b-140b,145f-144f altinstruction_entry 140b,144f,\feature2,142b-140b,145f-144f,142b-141b
.popsection .popsection
.pushsection .altinstr_replacement,"ax" .pushsection .altinstr_replacement,"ax"
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#define JUMP_ORIG_OFFSET 0 #define JUMP_ORIG_OFFSET 0
#define JUMP_NEW_OFFSET 4 #define JUMP_NEW_OFFSET 4
#define ALT_ENTRY_SIZE 12 #define ALT_ENTRY_SIZE 13
#define ALT_ORIG_OFFSET 0 #define ALT_ORIG_OFFSET 0
#define ALT_NEW_OFFSET 4 #define ALT_NEW_OFFSET 4
#define ALT_FEATURE_OFFSET 8 #define ALT_FEATURE_OFFSET 8
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册