* [PATCH] LoongArch: Fix off-by-one in bt_address() exception vector check
@ 2026-11-15 19:31 hanbings
2026-11-18 7:36 ` Huacai Chen
0 siblings, 1 reply; 3+ messages in thread
From: hanbings @ 2026-11-15 19:31 UTC (permalink / raw)
To: Huacai Chen, loongarch; +Cc: WANG Xuerui, Tiezhu Yang, linux-kernel
EXCCODE_INT_END names the last valid interrupt exception code, not an
exclusive upper bound. Since INT_AVEC is 14:
EXCCODE_INT_NUM = INT_AVEC + 1 = 15
EXCCODE_INT_END = EXCCODE_INT_START + EXCCODE_INT_NUM - 1 = 78
trap_init() installs handle_vint for vectors 64 through 78 inclusive,
and the switch in bt_address() also maps types up to EXCCODE_INT_END
inclusive. But the range check uses:
ra < eentry + EXCCODE_INT_END * VECSIZE
which stops at the start of vector 78, so an address in the last
interrupt vector is never translated. For example, eentry + 78 *
VECSIZE + 0x154 is rejected instead of being mapped to handle_vint +
0x154.
The off-by-one has existed since the ORC unwinder was added; at that
time EXCCODE_INT_END was 77, so vector 77 was excluded. After AVEC
support made vector 78 the last interrupt vector, vector 78 is the one
that is excluded. Before commit 4cd641a79e69 ("LoongArch: Remove
unnecessary checks for ORC unwinder"), this silently ended the unwind.
Since that commit, bt_address() returns 0 and unwind_next_frame()
logs:
cannot find unwind pc at ...
Fixes: cb8a2ef0848c ("LoongArch: Add ORC stack unwinder support")
Cc: stable@vger.kernel.org
Signed-off-by: hanbings <hanbings@hanbings.io>
---
arch/loongarch/kernel/unwind_orc.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/loongarch/kernel/unwind_orc.c b/arch/loongarch/kernel/unwind_orc.c
index 9cfb5bb19..784edf6a7 100644
--- a/arch/loongarch/kernel/unwind_orc.c
+++ b/arch/loongarch/kernel/unwind_orc.c
@@ -366,7 +366,7 @@ static inline unsigned long bt_address(unsigned long ra)
}
#endif
- if (ra >= eentry && ra < eentry + EXCCODE_INT_END * VECSIZE) {
+ if (ra >= eentry && ra < eentry + (EXCCODE_INT_END + 1) * VECSIZE) {
unsigned long func;
unsigned long type = (ra - eentry) / VECSIZE;
unsigned long offset = (ra - eentry) % VECSIZE;
base-commit: 422e532809572ba1043192bf6a0c653bc68b3140
--
2.54.0
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] LoongArch: Fix off-by-one in bt_address() exception vector check
2026-11-15 19:31 [PATCH] LoongArch: Fix off-by-one in bt_address() exception vector check hanbings
@ 2026-11-18 7:36 ` Huacai Chen
2026-11-18 8:23 ` Tiezhu Yang
0 siblings, 1 reply; 3+ messages in thread
From: Huacai Chen @ 2026-11-18 7:36 UTC (permalink / raw)
To: hanbings; +Cc: loongarch, WANG Xuerui, Tiezhu Yang, linux-kernel
Hi, Tiezhu,
What's your opinion?
Huacai
On Mon, Nov 16, 2026 at 3:31 AM hanbings <hanbings@hanbings.io> wrote:
>
> EXCCODE_INT_END names the last valid interrupt exception code, not an
> exclusive upper bound. Since INT_AVEC is 14:
>
> EXCCODE_INT_NUM = INT_AVEC + 1 = 15
> EXCCODE_INT_END = EXCCODE_INT_START + EXCCODE_INT_NUM - 1 = 78
>
> trap_init() installs handle_vint for vectors 64 through 78 inclusive,
> and the switch in bt_address() also maps types up to EXCCODE_INT_END
> inclusive. But the range check uses:
>
> ra < eentry + EXCCODE_INT_END * VECSIZE
>
> which stops at the start of vector 78, so an address in the last
> interrupt vector is never translated. For example, eentry + 78 *
> VECSIZE + 0x154 is rejected instead of being mapped to handle_vint +
> 0x154.
>
> The off-by-one has existed since the ORC unwinder was added; at that
> time EXCCODE_INT_END was 77, so vector 77 was excluded. After AVEC
> support made vector 78 the last interrupt vector, vector 78 is the one
> that is excluded. Before commit 4cd641a79e69 ("LoongArch: Remove
> unnecessary checks for ORC unwinder"), this silently ended the unwind.
> Since that commit, bt_address() returns 0 and unwind_next_frame()
> logs:
>
> cannot find unwind pc at ...
>
> Fixes: cb8a2ef0848c ("LoongArch: Add ORC stack unwinder support")
> Cc: stable@vger.kernel.org
> Signed-off-by: hanbings <hanbings@hanbings.io>
> ---
> arch/loongarch/kernel/unwind_orc.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/loongarch/kernel/unwind_orc.c b/arch/loongarch/kernel/unwind_orc.c
> index 9cfb5bb19..784edf6a7 100644
> --- a/arch/loongarch/kernel/unwind_orc.c
> +++ b/arch/loongarch/kernel/unwind_orc.c
> @@ -366,7 +366,7 @@ static inline unsigned long bt_address(unsigned long ra)
> }
> #endif
>
> - if (ra >= eentry && ra < eentry + EXCCODE_INT_END * VECSIZE) {
> + if (ra >= eentry && ra < eentry + (EXCCODE_INT_END + 1) * VECSIZE) {
> unsigned long func;
> unsigned long type = (ra - eentry) / VECSIZE;
> unsigned long offset = (ra - eentry) % VECSIZE;
>
> base-commit: 422e532809572ba1043192bf6a0c653bc68b3140
> --
> 2.54.0
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-18 8:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-15 19:31 [PATCH] LoongArch: Fix off-by-one in bt_address() exception vector check hanbings
2026-11-18 7:36 ` Huacai Chen
2026-11-18 8:23 ` 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®