If 'regs' points to a local stack variable, prepare_frametrace() stores
all registers to the stack. This confuses objtool as it expects them to
be restored from the stack later.
The stores don't affect stack tracing, so use unwind hints to hide them
from objtool.
Fixes the following warnings:
arch/loongarch/kernel/traps.o: warning: objtool: show_stack+0xe0: stack state mismatch: reg1[22]=-1+0 reg2[22]=-2-160
arch/loongarch/kernel/traps.o: warning: objtool: show_stack+0xe0: stack state mismatch: reg1[23]=-1+0 reg2[23]=-2-152
Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
Fixes: cb8a2ef0848c ("LoongArch: Add ORC stack unwinder support")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202503280703.OARM8SrY-lkp@intel.com/
Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
---
arch/loongarch/include/asm/stacktrace.h | 3 +++
arch/loongarch/include/asm/unwind_hints.h | 10 +++++++++-
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/arch/loongarch/include/asm/stacktrace.h b/arch/loongarch/include/asm/stacktrace.h
index f23adb15f418..fc8b64773794 100644
--- a/arch/loongarch/include/asm/stacktrace.h
+++ b/arch/loongarch/include/asm/stacktrace.h
@@ -8,6 +8,7 @@
#include <asm/asm.h>
#include <asm/ptrace.h>
#include <asm/loongarch.h>
+#include <asm/unwind_hints.h>
#include <linux/stringify.h>
enum stack_type {
@@ -43,6 +44,7 @@ int get_stack_info(unsigned long stack, struct task_struct *task, struct stack_i
static __always_inline void prepare_frametrace(struct pt_regs *regs)
{
__asm__ __volatile__(
+ UNWIND_HINT_SAVE
/* Save $ra */
STORE_ONE_REG(1)
/* Use $ra to save PC */
@@ -80,6 +82,7 @@ static __always_inline void prepare_frametrace(struct pt_regs *regs)
STORE_ONE_REG(29)
STORE_ONE_REG(30)
STORE_ONE_REG(31)
+ UNWIND_HINT_RESTORE
: "=m" (regs->csr_era)
: "r" (regs->regs)
: "memory");
diff --git a/arch/loongarch/include/asm/unwind_hints.h b/arch/loongarch/include/asm/unwind_hints.h
index a01086ad9dde..2c68bc72736c 100644
--- a/arch/loongarch/include/asm/unwind_hints.h
+++ b/arch/loongarch/include/asm/unwind_hints.h
@@ -23,6 +23,14 @@
UNWIND_HINT sp_reg=ORC_REG_SP type=UNWIND_HINT_TYPE_CALL
.endm
-#endif /* __ASSEMBLY__ */
+#else /* !__ASSEMBLY__ */
+
+#define UNWIND_HINT_SAVE \
+ UNWIND_HINT(UNWIND_HINT_TYPE_SAVE, 0, 0, 0)
+
+#define UNWIND_HINT_RESTORE \
+ UNWIND_HINT(UNWIND_HINT_TYPE_RESTORE, 0, 0, 0)
+
+#endif /* !__ASSEMBLY__ */
#endif /* _ASM_LOONGARCH_UNWIND_HINTS_H */
--
2.48.1
* Josh Poimboeuf <jpoimboe@kernel.org> wrote:
> If 'regs' points to a local stack variable, prepare_frametrace() stores
> all registers to the stack. This confuses objtool as it expects them to
> be restored from the stack later.
>
> The stores don't affect stack tracing, so use unwind hints to hide them
> from objtool.
>
> Fixes the following warnings:
>
> arch/loongarch/kernel/traps.o: warning: objtool: show_stack+0xe0: stack state mismatch: reg1[22]=-1+0 reg2[22]=-2-160
> arch/loongarch/kernel/traps.o: warning: objtool: show_stack+0xe0: stack state mismatch: reg1[23]=-1+0 reg2[23]=-2-152
>
> Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
> Fixes: cb8a2ef0848c ("LoongArch: Add ORC stack unwinder support")
> Reported-by: kernel test robot <lkp@intel.com>
> Closes: https://lore.kernel.org/oe-kbuild-all/202503280703.OARM8SrY-lkp@intel.com/
> Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
Note, I skipped this fix from tip:objtool/urgent for the time being,
because Tiezhu Yang indicated that he'd be reviewing and testing this
patch.
Thanks,
Ingo
On 04/01/2025 03:08 PM, Ingo Molnar wrote:
>
> * Josh Poimboeuf <jpoimboe@kernel.org> wrote:
>
>> If 'regs' points to a local stack variable, prepare_frametrace() stores
>> all registers to the stack. This confuses objtool as it expects them to
>> be restored from the stack later.
>>
>> The stores don't affect stack tracing, so use unwind hints to hide them
>> from objtool.
>>
>> Fixes the following warnings:
>>
>> arch/loongarch/kernel/traps.o: warning: objtool: show_stack+0xe0: stack state mismatch: reg1[22]=-1+0 reg2[22]=-2-160
>> arch/loongarch/kernel/traps.o: warning: objtool: show_stack+0xe0: stack state mismatch: reg1[23]=-1+0 reg2[23]=-2-152
>>
>> Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
>> Fixes: cb8a2ef0848c ("LoongArch: Add ORC stack unwinder support")
>> Reported-by: kernel test robot <lkp@intel.com>
>> Closes: https://lore.kernel.org/oe-kbuild-all/202503280703.OARM8SrY-lkp@intel.com/
>> Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
>
> Note, I skipped this fix from tip:objtool/urgent for the time being,
> because Tiezhu Yang indicated that he'd be reviewing and testing this
> patch.
Tested-by: Tiezhu Yang <yangtiezhu@loongson.cn>
* Tiezhu Yang <yangtiezhu@loongson.cn> wrote:
> On 04/01/2025 03:08 PM, Ingo Molnar wrote:
> >
> > * Josh Poimboeuf <jpoimboe@kernel.org> wrote:
> >
> > > If 'regs' points to a local stack variable, prepare_frametrace() stores
> > > all registers to the stack. This confuses objtool as it expects them to
> > > be restored from the stack later.
> > >
> > > The stores don't affect stack tracing, so use unwind hints to hide them
> > > from objtool.
> > >
> > > Fixes the following warnings:
> > >
> > > arch/loongarch/kernel/traps.o: warning: objtool: show_stack+0xe0: stack state mismatch: reg1[22]=-1+0 reg2[22]=-2-160
> > > arch/loongarch/kernel/traps.o: warning: objtool: show_stack+0xe0: stack state mismatch: reg1[23]=-1+0 reg2[23]=-2-152
> > >
> > > Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
> > > Fixes: cb8a2ef0848c ("LoongArch: Add ORC stack unwinder support")
> > > Reported-by: kernel test robot <lkp@intel.com>
> > > Closes: https://lore.kernel.org/oe-kbuild-all/202503280703.OARM8SrY-lkp@intel.com/
> > > Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
> >
> > Note, I skipped this fix from tip:objtool/urgent for the time being,
> > because Tiezhu Yang indicated that he'd be reviewing and testing this
> > patch.
>
> Tested-by: Tiezhu Yang <yangtiezhu@loongson.cn>
Thank you! Is it fine with you if I send this fix with tonight's
objtool/urgent pull request to Linus?
Thanks,
Ingo
On 04/01/2025 04:10 PM, Ingo Molnar wrote:
>
> * Tiezhu Yang <yangtiezhu@loongson.cn> wrote:
>
>> On 04/01/2025 03:08 PM, Ingo Molnar wrote:
>>>
>>> * Josh Poimboeuf <jpoimboe@kernel.org> wrote:
>>>
>>>> If 'regs' points to a local stack variable, prepare_frametrace() stores
>>>> all registers to the stack. This confuses objtool as it expects them to
>>>> be restored from the stack later.
>>>>
>>>> The stores don't affect stack tracing, so use unwind hints to hide them
>>>> from objtool.
>>>>
>>>> Fixes the following warnings:
>>>>
>>>> arch/loongarch/kernel/traps.o: warning: objtool: show_stack+0xe0: stack state mismatch: reg1[22]=-1+0 reg2[22]=-2-160
>>>> arch/loongarch/kernel/traps.o: warning: objtool: show_stack+0xe0: stack state mismatch: reg1[23]=-1+0 reg2[23]=-2-152
>>>>
>>>> Cc: Tiezhu Yang <yangtiezhu@loongson.cn>
>>>> Fixes: cb8a2ef0848c ("LoongArch: Add ORC stack unwinder support")
>>>> Reported-by: kernel test robot <lkp@intel.com>
>>>> Closes: https://lore.kernel.org/oe-kbuild-all/202503280703.OARM8SrY-lkp@intel.com/
>>>> Signed-off-by: Josh Poimboeuf <jpoimboe@kernel.org>
>>>
>>> Note, I skipped this fix from tip:objtool/urgent for the time being,
>>> because Tiezhu Yang indicated that he'd be reviewing and testing this
>>> patch.
>>
>> Tested-by: Tiezhu Yang <yangtiezhu@loongson.cn>
>
> Thank you! Is it fine with you if I send this fix with tonight's
> objtool/urgent pull request to Linus?
Yes, no problem, thank you for doing this.
© 2016 - 2025 Red Hat, Inc.