From nobody Mon Jun 8 07:26:02 2026 Received: from va-1-115.ptr.blmpb.com (va-1-115.ptr.blmpb.com [209.127.230.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E4BF03644C7 for ; Wed, 3 Jun 2026 03:53:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.127.230.115 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780458812; cv=none; b=uZ63PDEut9SDJEm4B4L29/1Ov6tcL/bslFqeSQKYlb5140jIbSwaq4gkGfdSYuPzDV+KFegWOd3xpp/EyFVeyNZYc1INfQbjj+rNWtEmeNZ6Qwngc4LHidavzl9NaphzJ6Cn8m60cemURYjascfR4RmU8DV9w7/q2s03kUvZ16g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780458812; c=relaxed/simple; bh=95xDVeybNcG6tmK9Jp/z5LPix8iadiAjPpk+Caghi9M=; h=From:To:Subject:Date:Message-Id:Cc:Mime-Version:Content-Type; b=jZfDZdrWfr/QL0hKW0BfXNPdo5og40+trarcM1dJq1oSud7srkCSMUqo8uXQpvCgrQ8XCKLDll91aVPvN3oiRvSQ6DsL7bEdYNCAGUFeRVI+Q/5v6ISYjvJfyBA3LwkEcjqlJmAbt4Swy5pobowPEciCT5XUddQ3VolWt1LbOmQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=m/4apiLh; arc=none smtp.client-ip=209.127.230.115 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="m/4apiLh" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1780458799; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=MFxN0eDM0EQaQEYZXyVgMg7gWvqW/BKj9d9daCeXaw0=; b=m/4apiLh1GrGhafkU21bbWjkzvF8qCRLwW7pZmNI28uGTSmn5exS/IZHZfJjsj2HaI0ObU 6MHg/1O/coMf4mUYJw3U1unMQpq01+aZsoDiD2im7ELL+jzT9CqWexwXW/5PIG2SgxajTt rcKYjWWl53pCv4Ko0HDIEifcZhbes7DmB7xBXRBR5ELzY2Ej5QKjPmp3MeTDJqNyOiXF3C hiUictbg59u6pbnh0d6P3BBXmbZW4SFH3EXdRUuX2c83Pm3RtVe8gV0XfYVgcSyoaMrF1Q lMWT7oz9emTXuKXbJT7LSsF4Jyy81m1jekA/FIcuGzGwQWSWFVSi1jPDJCXqUA== From: "Rui Qi" X-Original-From: Rui Qi To: , , , Subject: [PATCH] riscv: fix frame pointer in call_on_irq_stack for RV32 Date: Wed, 3 Jun 2026 11:53:05 +0800 X-Lms-Return-Path: Message-Id: <20260603035305.564823-1-qirui.001@bytedance.com> Content-Transfer-Encoding: quoted-printable Cc: "Rui Qi" , , Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.20.1 Content-Type: text/plain; charset="utf-8" The frame pointer (s0/fp) in call_on_irq_stack is set using STACKFRAME_SIZE_ON_STACK, which equals ALIGN(sizeof(struct stackframe), STACK_ALIGN). On RV64, sizeof(struct stackframe) is 16 and the aligned size is also 16, so there is no difference. However, on RV32, sizeof(struct stackframe) is 8 while STACKFRAME_SIZE_ON_STACK is 16 due to 8 bytes of alignment padding. The stack unwinder does 'frame =3D (struct stackframe *)fp - 1', which reads from 'fp - sizeof(struct stackframe)'. On RV32, with fp set to sp + STACKFRAME_SIZE_ON_STACK (sp + 16), the unwinder reads from sp + 8, which falls in the alignment padding rather than where the saved fp/ra are actually stored (sp + 0 and sp + 4). Fix this by introducing STACKFRAME_SIZE (the unaligned sizeof) and using it for frame pointer setup and restoration, while keeping STACKFRAME_SIZE_ON_STACK for the stack pointer allocation/deallocation which must remain 16-byte aligned. Signed-off-by: Rui Qi --- arch/riscv/kernel/asm-offsets.c | 1 + arch/riscv/kernel/entry.S | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/riscv/kernel/asm-offsets.c b/arch/riscv/kernel/asm-offset= s.c index af827448a609..c1b5f7eb03fd 100644 --- a/arch/riscv/kernel/asm-offsets.c +++ b/arch/riscv/kernel/asm-offsets.c @@ -500,6 +500,7 @@ void asm_offsets(void) OFFSET(SBI_HART_BOOT_TASK_PTR_OFFSET, sbi_hart_boot_data, task_ptr); OFFSET(SBI_HART_BOOT_STACK_PTR_OFFSET, sbi_hart_boot_data, stack_ptr); =20 + DEFINE(STACKFRAME_SIZE, sizeof(struct stackframe)); DEFINE(STACKFRAME_SIZE_ON_STACK, ALIGN(sizeof(struct stackframe), STACK_A= LIGN)); OFFSET(STACKFRAME_FP, stackframe, fp); OFFSET(STACKFRAME_RA, stackframe, ra); diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S index d011fb51c59a..e8b654e2b7b5 100644 --- a/arch/riscv/kernel/entry.S +++ b/arch/riscv/kernel/entry.S @@ -383,7 +383,7 @@ SYM_FUNC_START(call_on_irq_stack) addi sp, sp, -STACKFRAME_SIZE_ON_STACK REG_S ra, STACKFRAME_RA(sp) REG_S s0, STACKFRAME_FP(sp) - addi s0, sp, STACKFRAME_SIZE_ON_STACK + addi s0, sp, STACKFRAME_SIZE =20 /* Switch to the per-CPU shadow call stack */ scs_save_current @@ -399,7 +399,7 @@ SYM_FUNC_START(call_on_irq_stack) scs_load_current =20 /* Switch back to the thread stack and restore ra and s0 */ - addi sp, s0, -STACKFRAME_SIZE_ON_STACK + addi sp, s0, -STACKFRAME_SIZE REG_L ra, STACKFRAME_RA(sp) REG_L s0, STACKFRAME_FP(sp) addi sp, sp, STACKFRAME_SIZE_ON_STACK --=20 2.20.1