Re: [PATCH] LoongArch: Fix off-by-one in bt_address() exception vector check

From: Huacai Chen

Date: Wed Nov 18 2026 - 02:36:50 EST


Hi, Tiezhu,

What's your opinion?

Huacai

On Mon, Nov 16, 2026 at 3:31 AM hanbings <hanbings@xxxxxxxxxxx> 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@xxxxxxxxxxxxxxx
> Signed-off-by: hanbings <hanbings@xxxxxxxxxxx>
> ---
> 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
>
>