* [PATCH v2 0/3] Fix objtool warning about do_syscall() on LoongArch
@ 2024-08-05 3:26 Tiezhu Yang
2024-08-05 3:26 ` [PATCH v2 1/3] objtool/LoongArch: Decode secondary stack instruction Tiezhu Yang
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Tiezhu Yang @ 2024-08-05 3:26 UTC (permalink / raw)
To: Josh Poimboeuf, Peter Zijlstra, Huacai Chen; +Cc: loongarch, linux-kernel
With this series, there is no objtool warning about do_syscall() and
there is handle_syscall() which is the previous frame of do_syscall()
in the call trace when running "echo l > /proc/sysrq-trigger", tested
with the following two configs:
(1) CONFIG_RANDOMIZE_KSTACK_OFFSET=y &&
CONFIG_RANDOMIZE_KSTACK_OFFSET_DEFAULT=n
(2) CONFIG_RANDOMIZE_KSTACK_OFFSET=y &&
CONFIG_RANDOMIZE_KSTACK_OFFSET_DEFAULT=y
Tiezhu Yang (3):
objtool/LoongArch: Decode secondary stack instruction
objtool: Handle secondary stack related instructions
LoongArch: Remove STACK_FRAME_NON_STANDARD(do_syscall)
arch/loongarch/kernel/syscall.c | 4 ----
tools/arch/loongarch/include/asm/inst.h | 12 ++++++++++
tools/objtool/arch/loongarch/decode.c | 29 ++++++++++++++++++++++++-
tools/objtool/check.c | 22 +++++++++++++++++++
tools/objtool/include/objtool/elf.h | 1 +
5 files changed, 63 insertions(+), 5 deletions(-)
--
2.42.0
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH v2 1/3] objtool/LoongArch: Decode secondary stack instruction 2024-08-05 3:26 [PATCH v2 0/3] Fix objtool warning about do_syscall() on LoongArch Tiezhu Yang @ 2024-08-05 3:26 ` Tiezhu Yang 2024-08-05 3:26 ` [PATCH v2 2/3] objtool: Handle secondary stack related instructions Tiezhu Yang 2024-08-05 3:27 ` [PATCH v2 3/3] LoongArch: Remove STACK_FRAME_NON_STANDARD(do_syscall) Tiezhu Yang 2 siblings, 0 replies; 7+ messages in thread From: Tiezhu Yang @ 2024-08-05 3:26 UTC (permalink / raw) To: Josh Poimboeuf, Peter Zijlstra, Huacai Chen; +Cc: loongarch, linux-kernel After commit a0f7085f6a63 ("LoongArch: Add RANDOMIZE_KSTACK_OFFSET support"), there is a new instruction "sub.d $sp, $sp, $t0" for the secondary stack in do_syscall(), then there exists a objtool warning "do_syscall+0x11c: return with modified stack frame" and there is no handle_syscall() which is the previous frame of do_syscall() in the call trace when executing the command "echo l > /proc/sysrq-trigger". In order to solve the above issues, the first step is to decode the secondary stack instruction "sub.d $sp, $sp, $t0". Cc: stable@vger.kernel.org # 6.9+ Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> --- tools/arch/loongarch/include/asm/inst.h | 12 ++++++++++++ tools/objtool/arch/loongarch/decode.c | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/tools/arch/loongarch/include/asm/inst.h b/tools/arch/loongarch/include/asm/inst.h index c25b5853181d..935b596642e2 100644 --- a/tools/arch/loongarch/include/asm/inst.h +++ b/tools/arch/loongarch/include/asm/inst.h @@ -51,6 +51,10 @@ enum reg2i16_op { bgeu_op = 0x1b, }; +enum reg3_op { + subd_op = 0x23, +}; + struct reg0i15_format { unsigned int immediate : 15; unsigned int opcode : 17; @@ -96,6 +100,13 @@ struct reg2i16_format { unsigned int opcode : 6; }; +struct reg3_format { + unsigned int rd : 5; + unsigned int rj : 5; + unsigned int rk : 5; + unsigned int opcode : 17; +}; + union loongarch_instruction { unsigned int word; struct reg0i15_format reg0i15_format; @@ -105,6 +116,7 @@ union loongarch_instruction { struct reg2i12_format reg2i12_format; struct reg2i14_format reg2i14_format; struct reg2i16_format reg2i16_format; + struct reg3_format reg3_format; }; #define LOONGARCH_INSN_SIZE sizeof(union loongarch_instruction) diff --git a/tools/objtool/arch/loongarch/decode.c b/tools/objtool/arch/loongarch/decode.c index aee479d2191c..db4dd05cdb49 100644 --- a/tools/objtool/arch/loongarch/decode.c +++ b/tools/objtool/arch/loongarch/decode.c @@ -272,6 +272,25 @@ static bool decode_insn_reg2i16_fomat(union loongarch_instruction inst, return true; } +static bool decode_insn_reg3_fomat(union loongarch_instruction inst, + struct instruction *insn) +{ + switch (inst.reg3_format.opcode) { + case subd_op: + if ((inst.reg3_format.rd == CFI_SP) && (inst.reg3_format.rj == CFI_SP)) { + /* + * sub.d sp,sp,t0 + * this is a rare case for the secondary stack. + */ + } + break; + default: + return false; + } + + return true; +} + int arch_decode_instruction(struct objtool_file *file, const struct section *sec, unsigned long offset, unsigned int maxlen, struct instruction *insn) @@ -303,6 +322,8 @@ int arch_decode_instruction(struct objtool_file *file, const struct section *sec return 0; if (decode_insn_reg2i16_fomat(inst, insn)) return 0; + if (decode_insn_reg3_fomat(inst, insn)) + return 0; if (inst.word == 0) insn->type = INSN_NOP; -- 2.42.0 ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 2/3] objtool: Handle secondary stack related instructions 2024-08-05 3:26 [PATCH v2 0/3] Fix objtool warning about do_syscall() on LoongArch Tiezhu Yang 2024-08-05 3:26 ` [PATCH v2 1/3] objtool/LoongArch: Decode secondary stack instruction Tiezhu Yang @ 2024-08-05 3:26 ` Tiezhu Yang 2024-08-05 6:37 ` Tiezhu Yang ` (2 more replies) 2024-08-05 3:27 ` [PATCH v2 3/3] LoongArch: Remove STACK_FRAME_NON_STANDARD(do_syscall) Tiezhu Yang 2 siblings, 3 replies; 7+ messages in thread From: Tiezhu Yang @ 2024-08-05 3:26 UTC (permalink / raw) To: Josh Poimboeuf, Peter Zijlstra, Huacai Chen; +Cc: loongarch, linux-kernel After commit a0f7085f6a63 ("LoongArch: Add RANDOMIZE_KSTACK_OFFSET support"), there is a new instruction "sub.d $sp, $sp, $t0" for the secondary stack in do_syscall(), then there exists a objtool warning "do_syscall+0x11c: return with modified stack frame" and there is no handle_syscall() which is the previous frame of do_syscall() in the call trace when executing the command "echo l > /proc/sysrq-trigger". objdump shows something like this: 0000000000000000 <do_syscall>: 0: 02ff8063 addi.d $sp, $sp, -32 4: 29c04076 st.d $fp, $sp, 16 8: 29c02077 st.d $s0, $sp, 8 c: 29c06061 st.d $ra, $sp, 24 10: 02c08076 addi.d $fp, $sp, 32 ... 74: 0011b063 sub.d $sp, $sp, $t0 ... a8: 4c000181 jirl $ra, $t0, 0 ... dc: 02ff82c3 addi.d $sp, $fp, -32 e0: 28c06061 ld.d $ra, $sp, 24 e4: 28c04076 ld.d $fp, $sp, 16 e8: 28c02077 ld.d $s0, $sp, 8 ec: 02c08063 addi.d $sp, $sp, 32 f0: 4c000020 jirl $zero, $ra, 0 The instruction "sub.d $sp, $sp, $t0" changes the stack bottom and the new stack size is a random value, in order to find the return address of do_syscall() which is stored in the original stack frame after executing "jirl $ra, $t0, 0", it should use fp which points to the original stack top. This is a rare case, add a member "secondary_stack" in the struct symbol as a label to avoid affecting the current normal case, then set it as true only if there exists the secondary stack instruction "sub.d $sp, $sp, $t0", at last check this label for the other special secondary stack instructions about fp to change the cfa base and cfa offset during the period of secondary stack in update_cfi_state(). Tested with the following two configs: (1) CONFIG_RANDOMIZE_KSTACK_OFFSET=y && CONFIG_RANDOMIZE_KSTACK_OFFSET_DEFAULT=n (2) CONFIG_RANDOMIZE_KSTACK_OFFSET=y && CONFIG_RANDOMIZE_KSTACK_OFFSET_DEFAULT=y Cc: stable@vger.kernel.org # 6.9+ Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> --- tools/objtool/arch/loongarch/decode.c | 8 +++++++- tools/objtool/check.c | 22 ++++++++++++++++++++++ tools/objtool/include/objtool/elf.h | 1 + 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/tools/objtool/arch/loongarch/decode.c b/tools/objtool/arch/loongarch/decode.c index db4dd05cdb49..4085714ffd18 100644 --- a/tools/objtool/arch/loongarch/decode.c +++ b/tools/objtool/arch/loongarch/decode.c @@ -122,7 +122,7 @@ static bool decode_insn_reg2i12_fomat(union loongarch_instruction inst, switch (inst.reg2i12_format.opcode) { case addid_op: if ((inst.reg2i12_format.rd == CFI_SP) || (inst.reg2i12_format.rj == CFI_SP)) { - /* addi.d sp,sp,si12 or addi.d fp,sp,si12 */ + /* addi.d sp,sp,si12 or addi.d fp,sp,si12 or addi.d sp,fp,si12 */ insn->immediate = sign_extend64(inst.reg2i12_format.immediate, 11); ADD_OP(op) { op->src.type = OP_SRC_ADD; @@ -275,6 +275,8 @@ static bool decode_insn_reg2i16_fomat(union loongarch_instruction inst, static bool decode_insn_reg3_fomat(union loongarch_instruction inst, struct instruction *insn) { + struct symbol *func; + switch (inst.reg3_format.opcode) { case subd_op: if ((inst.reg3_format.rd == CFI_SP) && (inst.reg3_format.rj == CFI_SP)) { @@ -282,6 +284,10 @@ static bool decode_insn_reg3_fomat(union loongarch_instruction inst, * sub.d sp,sp,t0 * this is a rare case for the secondary stack. */ + func = find_func_containing(insn->sec, insn->offset); + if (!func) + return false; + func->secondary_stack = true; } break; default: diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 01237d167223..c7b9942fee29 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2993,6 +2993,28 @@ static int update_cfi_state(struct instruction *insn, break; } + if (op->dest.reg == CFI_BP && op->src.reg == CFI_SP) { + /* addi.d fp,sp,imm for the secondary stack on LoongArch */ + if (cfa->base == CFI_SP && cfa->offset == op->src.offset) { + if (insn->sym->secondary_stack) { + cfa->base = CFI_BP; + cfa->offset = 0; + } + } + break; + } + + if (op->dest.reg == CFI_SP && op->src.reg == CFI_BP) { + /* addi.d sp,fp,imm for the secondary stack on LoongArch */ + if (cfa->base == CFI_FP && cfa->offset == 0) { + if (insn->sym->secondary_stack) { + cfa->base = CFI_SP; + cfa->offset = -op->src.offset; + } + } + break; + } + if (op->dest.reg == CFI_SP && op->src.reg == CFI_BP) { /* lea disp(%rbp), %rsp */ diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h index 2b8a69de4db8..586916e0d441 100644 --- a/tools/objtool/include/objtool/elf.h +++ b/tools/objtool/include/objtool/elf.h @@ -68,6 +68,7 @@ struct symbol { u8 warned : 1; u8 embedded_insn : 1; u8 local_label : 1; + u8 secondary_stack : 1; struct list_head pv_target; struct reloc *relocs; }; -- 2.42.0 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 2/3] objtool: Handle secondary stack related instructions 2024-08-05 3:26 ` [PATCH v2 2/3] objtool: Handle secondary stack related instructions Tiezhu Yang @ 2024-08-05 6:37 ` Tiezhu Yang 2024-08-05 9:03 ` kernel test robot 2024-08-05 10:15 ` Jinyang He 2 siblings, 0 replies; 7+ messages in thread From: Tiezhu Yang @ 2024-08-05 6:37 UTC (permalink / raw) To: Josh Poimboeuf, Peter Zijlstra, Huacai Chen; +Cc: loongarch, linux-kernel On 08/05/2024 11:26 AM, Tiezhu Yang wrote: > After commit a0f7085f6a63 ("LoongArch: Add RANDOMIZE_KSTACK_OFFSET > support"), there is a new instruction "sub.d $sp, $sp, $t0" for the > secondary stack in do_syscall(), then there exists a objtool warning > "do_syscall+0x11c: return with modified stack frame" and there is no > handle_syscall() which is the previous frame of do_syscall() in the > call trace when executing the command "echo l > /proc/sysrq-trigger". ... > diff --git a/tools/objtool/check.c b/tools/objtool/check.c > index 01237d167223..c7b9942fee29 100644 > --- a/tools/objtool/check.c > +++ b/tools/objtool/check.c > @@ -2993,6 +2993,28 @@ static int update_cfi_state(struct instruction *insn, > break; > } > > + if (op->dest.reg == CFI_BP && op->src.reg == CFI_SP) { > + /* addi.d fp,sp,imm for the secondary stack on LoongArch */ > + if (cfa->base == CFI_SP && cfa->offset == op->src.offset) { > + if (insn->sym->secondary_stack) { > + cfa->base = CFI_BP; > + cfa->offset = 0; > + } > + } > + break; > + } > + > + if (op->dest.reg == CFI_SP && op->src.reg == CFI_BP) { > + /* addi.d sp,fp,imm for the secondary stack on LoongArch */ > + if (cfa->base == CFI_FP && cfa->offset == 0) { Here should be CFI_BP instead of CFI_FP which is only defined for LoongArch. > + if (insn->sym->secondary_stack) { > + cfa->base = CFI_SP; > + cfa->offset = -op->src.offset; > + } > + } > + break; > + } > + > if (op->dest.reg == CFI_SP && op->src.reg == CFI_BP) { > > /* lea disp(%rbp), %rsp */ Oh, sorry, I forgot to test this change on x86. Here is the test info on x86: the cfa->base is CFI_BP or CFI_BP_INDIRECT and the cfa->offset is not 0 if (op->dest.reg == CFI_SP && op->src.reg == CFI_BP), thus it can check the following condition if(cfa->base == CFI_BP && cfa->offset == 0) to distinguish x86 and LoongArch. So the correct change should be something like this to make sure it works well for both x86 and LoongArch: diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 01237d167223..0832d20c95d2 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -2993,10 +2993,28 @@ static int update_cfi_state(struct instruction *insn, break; } - if (op->dest.reg == CFI_SP && op->src.reg == CFI_BP) { + if (op->dest.reg == CFI_BP && op->src.reg == CFI_SP) { + /* addi.d fp,sp,imm for the secondary stack on LoongArch */ + if (cfa->base == CFI_SP && cfa->offset == op->src.offset) { + if (insn->sym->secondary_stack) { + cfa->base = CFI_BP; + cfa->offset = 0; + } + } + break; + } - /* lea disp(%rbp), %rsp */ - cfi->stack_size = -(op->src.offset + regs[CFI_BP].offset); + if (op->dest.reg == CFI_SP && op->src.reg == CFI_BP) { + /* addi.d sp,fp,imm for the secondary stack on LoongArch */ + if (cfa->base == CFI_BP && cfa->offset == 0) { + if (insn->sym->secondary_stack) { + cfa->base = CFI_SP; + cfa->offset = -op->src.offset; + } + } else { + /* lea disp(%rbp), %rsp */ + cfi->stack_size = -(op->src.offset + regs[CFI_BP].offset); + } break; } I will wait for some days to get more review comments and then send v3 later. Thanks, Tiezhu ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 2/3] objtool: Handle secondary stack related instructions 2024-08-05 3:26 ` [PATCH v2 2/3] objtool: Handle secondary stack related instructions Tiezhu Yang 2024-08-05 6:37 ` Tiezhu Yang @ 2024-08-05 9:03 ` kernel test robot 2024-08-05 10:15 ` Jinyang He 2 siblings, 0 replies; 7+ messages in thread From: kernel test robot @ 2024-08-05 9:03 UTC (permalink / raw) To: Tiezhu Yang, Josh Poimboeuf, Peter Zijlstra, Huacai Chen Cc: oe-kbuild-all, loongarch, linux-kernel Hi Tiezhu, kernel test robot noticed the following build errors: [auto build test ERROR on linus/master] [also build test ERROR on v6.11-rc2 next-20240802] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Tiezhu-Yang/objtool-LoongArch-Decode-secondary-stack-instruction/20240805-113316 base: linus/master patch link: https://lore.kernel.org/r/20240805032700.16038-3-yangtiezhu%40loongson.cn patch subject: [PATCH v2 2/3] objtool: Handle secondary stack related instructions config: x86_64-allmodconfig (https://download.01.org/0day-ci/archive/20240805/202408051602.NqvBpTsv-lkp@intel.com/config) compiler: clang version 18.1.5 (https://github.com/llvm/llvm-project 617a15a9eac96088ae5e9134248d8236e34b91b1) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240805/202408051602.NqvBpTsv-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202408051602.NqvBpTsv-lkp@intel.com/ All errors (new ones prefixed by >>): scripts/genksyms/parse.y: warning: 9 shift/reduce conflicts [-Wconflicts-sr] scripts/genksyms/parse.y: warning: 5 reduce/reduce conflicts [-Wconflicts-rr] scripts/genksyms/parse.y: note: rerun with option '-Wcounterexamples' to generate conflict counterexamples >> check.c:3009:22: error: use of undeclared identifier 'CFI_FP' 3009 | if (cfa->base == CFI_FP && cfa->offset == 0) { | ^ 1 error generated. make[5]: *** [tools/build/Makefile.build:105: tools/objtool/check.o] Error 1 make[5]: *** Waiting for unfinished jobs.... make[4]: *** [Makefile:70: tools/objtool/objtool-in.o] Error 2 make[3]: *** [Makefile:72: objtool] Error 2 make[2]: *** [Makefile:1360: tools/objtool] Error 2 make[2]: Target 'prepare' not remade because of errors. make[1]: *** [Makefile:224: __sub-make] Error 2 make[1]: Target 'prepare' not remade because of errors. make: *** [Makefile:224: __sub-make] Error 2 make: Target 'prepare' not remade because of errors. -- 0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v2 2/3] objtool: Handle secondary stack related instructions 2024-08-05 3:26 ` [PATCH v2 2/3] objtool: Handle secondary stack related instructions Tiezhu Yang 2024-08-05 6:37 ` Tiezhu Yang 2024-08-05 9:03 ` kernel test robot @ 2024-08-05 10:15 ` Jinyang He 2 siblings, 0 replies; 7+ messages in thread From: Jinyang He @ 2024-08-05 10:15 UTC (permalink / raw) To: Tiezhu Yang, Josh Poimboeuf, Peter Zijlstra, Huacai Chen Cc: loongarch, linux-kernel On 2024-08-05 11:26, Tiezhu Yang wrote: > After commit a0f7085f6a63 ("LoongArch: Add RANDOMIZE_KSTACK_OFFSET > support"), there is a new instruction "sub.d $sp, $sp, $t0" for the > secondary stack in do_syscall(), then there exists a objtool warning > "do_syscall+0x11c: return with modified stack frame" and there is no > handle_syscall() which is the previous frame of do_syscall() in the > call trace when executing the command "echo l > /proc/sysrq-trigger". > > objdump shows something like this: > > 0000000000000000 <do_syscall>: > 0: 02ff8063 addi.d $sp, $sp, -32 > 4: 29c04076 st.d $fp, $sp, 16 > 8: 29c02077 st.d $s0, $sp, 8 > c: 29c06061 st.d $ra, $sp, 24 > 10: 02c08076 addi.d $fp, $sp, 32 > ... > 74: 0011b063 sub.d $sp, $sp, $t0 > ... > a8: 4c000181 jirl $ra, $t0, 0 > ... > dc: 02ff82c3 addi.d $sp, $fp, -32 > e0: 28c06061 ld.d $ra, $sp, 24 > e4: 28c04076 ld.d $fp, $sp, 16 > e8: 28c02077 ld.d $s0, $sp, 8 > ec: 02c08063 addi.d $sp, $sp, 32 > f0: 4c000020 jirl $zero, $ra, 0 > > The instruction "sub.d $sp, $sp, $t0" changes the stack bottom > and the new stack size is a random value, in order to find the > return address of do_syscall() which is stored in the original > stack frame after executing "jirl $ra, $t0, 0", it should use > fp which points to the original stack top. > > This is a rare case, add a member "secondary_stack" in the struct > symbol as a label to avoid affecting the current normal case, then > set it as true only if there exists the secondary stack instruction > "sub.d $sp, $sp, $t0", at last check this label for the other special > secondary stack instructions about fp to change the cfa base and cfa > offset during the period of secondary stack in update_cfi_state(). > > Tested with the following two configs: > (1) CONFIG_RANDOMIZE_KSTACK_OFFSET=y && > CONFIG_RANDOMIZE_KSTACK_OFFSET_DEFAULT=n > (2) CONFIG_RANDOMIZE_KSTACK_OFFSET=y && > CONFIG_RANDOMIZE_KSTACK_OFFSET_DEFAULT=y > > Cc: stable@vger.kernel.org # 6.9+ > Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> > --- > tools/objtool/arch/loongarch/decode.c | 8 +++++++- > tools/objtool/check.c | 22 ++++++++++++++++++++++ > tools/objtool/include/objtool/elf.h | 1 + > 3 files changed, 30 insertions(+), 1 deletion(-) > > diff --git a/tools/objtool/arch/loongarch/decode.c b/tools/objtool/arch/loongarch/decode.c > index db4dd05cdb49..4085714ffd18 100644 > --- a/tools/objtool/arch/loongarch/decode.c > +++ b/tools/objtool/arch/loongarch/decode.c > @@ -122,7 +122,7 @@ static bool decode_insn_reg2i12_fomat(union loongarch_instruction inst, > switch (inst.reg2i12_format.opcode) { > case addid_op: > if ((inst.reg2i12_format.rd == CFI_SP) || (inst.reg2i12_format.rj == CFI_SP)) { > - /* addi.d sp,sp,si12 or addi.d fp,sp,si12 */ > + /* addi.d sp,sp,si12 or addi.d fp,sp,si12 or addi.d sp,fp,si12 */ > insn->immediate = sign_extend64(inst.reg2i12_format.immediate, 11); > ADD_OP(op) { > op->src.type = OP_SRC_ADD; > @@ -275,6 +275,8 @@ static bool decode_insn_reg2i16_fomat(union loongarch_instruction inst, > static bool decode_insn_reg3_fomat(union loongarch_instruction inst, > struct instruction *insn) > { > + struct symbol *func; > + > switch (inst.reg3_format.opcode) { > case subd_op: > if ((inst.reg3_format.rd == CFI_SP) && (inst.reg3_format.rj == CFI_SP)) { > @@ -282,6 +284,10 @@ static bool decode_insn_reg3_fomat(union loongarch_instruction inst, > * sub.d sp,sp,t0 > * this is a rare case for the secondary stack. > */ > + func = find_func_containing(insn->sec, insn->offset); > + if (!func) > + return false; > + func->secondary_stack = true; > } > break; > default: > diff --git a/tools/objtool/check.c b/tools/objtool/check.c > index 01237d167223..c7b9942fee29 100644 > --- a/tools/objtool/check.c > +++ b/tools/objtool/check.c > @@ -2993,6 +2993,28 @@ static int update_cfi_state(struct instruction *insn, > break; > } > > + if (op->dest.reg == CFI_BP && op->src.reg == CFI_SP) { > + /* addi.d fp,sp,imm for the secondary stack on LoongArch */ > + if (cfa->base == CFI_SP && cfa->offset == op->src.offset) { > + if (insn->sym->secondary_stack) { > + cfa->base = CFI_BP; > + cfa->offset = 0; > + } > + } > + break; > + } > + > + if (op->dest.reg == CFI_SP && op->src.reg == CFI_BP) { > + /* addi.d sp,fp,imm for the secondary stack on LoongArch */ > + if (cfa->base == CFI_FP && cfa->offset == 0) { > + if (insn->sym->secondary_stack) { > + cfa->base = CFI_SP; > + cfa->offset = -op->src.offset; > + } > + } > + break; > + } > + > if (op->dest.reg == CFI_SP && op->src.reg == CFI_BP) { > > /* lea disp(%rbp), %rsp */ > diff --git a/tools/objtool/include/objtool/elf.h b/tools/objtool/include/objtool/elf.h > index 2b8a69de4db8..586916e0d441 100644 > --- a/tools/objtool/include/objtool/elf.h > +++ b/tools/objtool/include/objtool/elf.h > @@ -68,6 +68,7 @@ struct symbol { > u8 warned : 1; > u8 embedded_insn : 1; > u8 local_label : 1; > + u8 secondary_stack : 1; > struct list_head pv_target; > struct reloc *relocs; > }; LGTM although I think we should make update_cfi_state() arch-specific. It also fix many warning when use Clang, thanks. Jinyang ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v2 3/3] LoongArch: Remove STACK_FRAME_NON_STANDARD(do_syscall) 2024-08-05 3:26 [PATCH v2 0/3] Fix objtool warning about do_syscall() on LoongArch Tiezhu Yang 2024-08-05 3:26 ` [PATCH v2 1/3] objtool/LoongArch: Decode secondary stack instruction Tiezhu Yang 2024-08-05 3:26 ` [PATCH v2 2/3] objtool: Handle secondary stack related instructions Tiezhu Yang @ 2024-08-05 3:27 ` Tiezhu Yang 2 siblings, 0 replies; 7+ messages in thread From: Tiezhu Yang @ 2024-08-05 3:27 UTC (permalink / raw) To: Josh Poimboeuf, Peter Zijlstra, Huacai Chen; +Cc: loongarch, linux-kernel For now, it can remove STACK_FRAME_NON_STANDARD(do_syscall) because there is no objtool warning "do_syscall+0x11c: return with modified stack frame", then there is handle_syscall() which is the previous frame of do_syscall() in the call trace when executing the command "echo l > /proc/sysrq-trigger". Fixes: a0f7085f6a63 ("LoongArch: Add RANDOMIZE_KSTACK_OFFSET support") Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> --- arch/loongarch/kernel/syscall.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/arch/loongarch/kernel/syscall.c b/arch/loongarch/kernel/syscall.c index ba5d0930a74f..168bd97540f8 100644 --- a/arch/loongarch/kernel/syscall.c +++ b/arch/loongarch/kernel/syscall.c @@ -79,7 +79,3 @@ void noinstr __no_stack_protector do_syscall(struct pt_regs *regs) syscall_exit_to_user_mode(regs); } - -#ifdef CONFIG_RANDOMIZE_KSTACK_OFFSET -STACK_FRAME_NON_STANDARD(do_syscall); -#endif -- 2.42.0 ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-08-05 10:15 UTC | newest] Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2024-08-05 3:26 [PATCH v2 0/3] Fix objtool warning about do_syscall() on LoongArch Tiezhu Yang 2024-08-05 3:26 ` [PATCH v2 1/3] objtool/LoongArch: Decode secondary stack instruction Tiezhu Yang 2024-08-05 3:26 ` [PATCH v2 2/3] objtool: Handle secondary stack related instructions Tiezhu Yang 2024-08-05 6:37 ` Tiezhu Yang 2024-08-05 9:03 ` kernel test robot 2024-08-05 10:15 ` Jinyang He 2024-08-05 3:27 ` [PATCH v2 3/3] LoongArch: Remove STACK_FRAME_NON_STANDARD(do_syscall) Tiezhu Yang
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®