You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "fdcavalcanti (via GitHub)" <gi...@apache.org> on 2025/02/11 12:28:09 UTC

[PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

fdcavalcanti opened a new pull request, #15815:
URL: https://github.com/apache/nuttx/pull/15815

   ## Summary
   
   This PR adds support for backtrace on RISC-V on certain build settings explained below.
   Up to this point, it was not printing anything useful during crashes.
   
   ## Impact
   
   Adds backtrace for task and IRQs when the RISC-V system crashes.
   
   ## Testing
   
   Tested on Espressif RISC-V devices and rv-virt.
   All tests are based on:
   
   - defconfig: rv-virt:nsh
   - CONFIG_SCHED_BACKTRACE=y
   - CONFIG_FRAME_POINTER=y
   - CONFIG_DEBUG_SYMBOLS=y
   
   The test is executed as follows: build, run ostest and test the backtrace in two different ways:
   
   - Task exception: simply do `*p = 0`; inside a simple test program.
   - IRQ exception: set up an interrupt handler and trigger the IRQ. Inside the interrupt routine, do `*p = 0;`.
   
   The backtrace is verified manually using `tools/btdecode.sh`.
   
   ### Test Scenario 1
   
   - CONFIG_SMP=n
   - CONFIG_ARCH_INTERRUPTSTACK=2048
   
   Command: `qemu-system-riscv32 -semihosting -M virt,aclint=on -cpu rv32 -bios none -kernel nuttx -nographic`
   
   - backtrace: PASS
   - ostest: PASS
   
   ### Test Scenario 2
   
   - CONFIG_SMP=y
   - CONFIG_SMP_NCPUS=2
   - CONFIG_ARCH_INTERRUPTSTACK=2048
   
   Command: `qemu-system-riscv32 -semihosting -M virt,aclint=on -cpu rv32 -smp 2 -bios none -kernel nuttx -nographic`
   
   - backtrace: PASS
   - ostest: PASS
   
   ### Test Scenario 3
   
   - CONFIG_SMP=n
   - CONFIG_ARCH_INTERRUPTSTACK=0
   - CONFIG_INIT_STACKSIZE=4096
   
   Command: `qemu-system-riscv32 -semihosting -M virt,aclint=on -cpu rv32 -bios none -kernel nuttx -nographic`
   In this case, `CONFIG_INIT_STACKSIZE` must be increased since we don't have the interrupt stack.
   
   - backtrace: PASS
   - ostest: PASS


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "nuttxpr (via GitHub)" <gi...@apache.org>.
nuttxpr commented on PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#issuecomment-2650709774

   [**\[Experimental Bot, please feedback here\]**](https://github.com/search?q=repo%3Aapache%2Fnuttx+13552&type=issues)
   
   
   
   Yes, this PR description meets the NuttX requirements. It clearly explains the change, its impact, and provides sufficient testing information to evaluate the functionality.  The use of specific scenarios and pass/fail results is particularly helpful.  It could be slightly improved by including snippets of the before/after backtrace output (even abbreviated) to demonstrate the actual change.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "fdcavalcanti (via GitHub)" <gi...@apache.org>.
fdcavalcanti commented on PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#issuecomment-2662754587

   > > About breaking this up in smaller PRs. Here's the first one #15835 .
   > 
   > it's enough to split the big change into the indeepent patch.
   
   Please check if this separation is enough. I can open a new PR if it makes more sense.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "jlaitine (via GitHub)" <gi...@apache.org>.
jlaitine commented on PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#issuecomment-2693953335

   Hi @tmedicci, the commit b4174952843c2ffd9776d02bd4357b118e2c55b9 seems to crash on me on the mpfs platfrom (64-bit risc-v), due to misaligned stack pointer access at "REGSTORE   ra, 12(sp)" and/or "REGLOAD    ra, 12(sp)".
   
   Could you check if this was tested on 64-bit risc-v systems and could those be aligned at 16-byte boundaries?
   
   Thanks!
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "acassis (via GitHub)" <gi...@apache.org>.
acassis commented on PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#issuecomment-2694570301

   @jlaitine @tmedicci should we revert it?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#discussion_r1953232657


##########
arch/risc-v/src/common/riscv_doirq.c:
##########
@@ -88,13 +88,24 @@ uintreg_t *riscv_doirq(int irq, uintreg_t *regs)
       (*running_task)->xcp.regs = regs;
     }
 
-  /* Nested interrupts are not supported */
+  /* Current regs non-zero indicates that we are processing an interrupt;
+   * current_regs is also used to manage interrupt level context switches.
+   *
+   * Nested interrupts are not supported. But an exception may occur while
+   * processing an interrupt. In this case, current_regs will be non-NULL.
+   */
 
-  DEBUGASSERT(!up_interrupt_context());
+  DEBUGASSERT(((irq > RISCV_MAX_EXCEPTION) && !up_interrupt_context()) ||

Review Comment:
   It's a general improvement to allow syscall in irq handler, why do we make it couple with panic?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "lupyuen (via GitHub)" <gi...@apache.org>.
lupyuen commented on PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#issuecomment-2650751700

   @nuttxpr test milkv_duos:nsh


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "jlaitine (via GitHub)" <gi...@apache.org>.
jlaitine commented on PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#issuecomment-2696575545

   I guess I will just test the attached patch on qemu rv32 and on mpfs, and create a PR if it works.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#discussion_r1956516266


##########
arch/risc-v/src/common/riscv_exception_common.S:
##########
@@ -207,25 +207,46 @@ handle_irq:
   .cfi_offset x2, 8               /* Toolchain not support macro, is REG_X2 * 4 */
   .cfi_offset ra, 0               /* Toolchain not support macro, is REG_EPC * 4 */
 
+  REGLOAD    ra, REG_EPC(sp)
+  REGLOAD    s0, REG_X8(sp)

Review Comment:
   I just said that this chnage can support the recusive irq dispatch, which is useful by self. The correct patch sequence is that:
   
   1. Move the stack limit check to backtrace
   2. Create stack frame gdb expected manually 
   3. Support irq_dispatch recusively
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#issuecomment-2656686990

   > About breaking this up in smaller PRs. Here's the first one #15835 .
   
   it's enough to split the big change into the indeepent patch.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "fdcavalcanti (via GitHub)" <gi...@apache.org>.
fdcavalcanti commented on PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#issuecomment-2651507703

   I have added a backtrace example output on the PR description.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#discussion_r1953242553


##########
arch/risc-v/src/common/riscv_exception_common.S:
##########
@@ -207,25 +207,46 @@ handle_irq:
   .cfi_offset x2, 8               /* Toolchain not support macro, is REG_X2 * 4 */
   .cfi_offset ra, 0               /* Toolchain not support macro, is REG_EPC * 4 */
 
+  REGLOAD    ra, REG_EPC(sp)
+  REGLOAD    s0, REG_X8(sp)

Review Comment:
   the change here make the backtrace can go through multiple interrupt stack frame, should be splitted to new patch and give a detailed comment in commit message and code, otherwise few people can understand why waste time to push/pop the register which already saved and may remove them to improve the speed. Actually, it may better to guard by CONFIG_BACKTRACE.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "fdcavalcanti (via GitHub)" <gi...@apache.org>.
fdcavalcanti commented on code in PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#discussion_r1956410518


##########
arch/risc-v/src/common/riscv_exception_common.S:
##########
@@ -207,25 +207,46 @@ handle_irq:
   .cfi_offset x2, 8               /* Toolchain not support macro, is REG_X2 * 4 */
   .cfi_offset ra, 0               /* Toolchain not support macro, is REG_EPC * 4 */
 
+  REGLOAD    ra, REG_EPC(sp)
+  REGLOAD    s0, REG_X8(sp)

Review Comment:
   So I tested this in some scenarios.
   Added only this change to master branch and also removed this change from this PR branch.
   Both cases give us bad results.
   
   Here's the master branch + this modification. We get the backtrace stuck in a loop printing the same content.
   ```
   sched_dumpstack: backtrace| 3: 0x800009cc 0x80000688 0x80000630 0x8000016a 0x800009cc 0x80000688 0x80000630 0x8000016a
   [repeat indefinitely]
   ```
   Which is:
   ```
   $ ./tools/btdecode.sh riscv-none-elf-addr2line bt
   Backtrace for task 3:
   0x800009cc: irq_dispatch at irq_dispatch.c:160
   0x80000688: riscv_doirq at riscv_doirq.c:102
   0x80000630: riscv_dispatch_irq at qemu_rv_irq_dispatch.c:140
   0x8000016a: return_from_exception at riscv_exception_common.S:243
   0x800009cc: irq_dispatch at irq_dispatch.c:160
   0x80000688: riscv_doirq at riscv_doirq.c:102
   0x80000630: riscv_dispatch_irq at qemu_rv_irq_dispatch.c:140
   0x8000016a: return_from_exception at riscv_exception_common.S:243
   ```
   
   Now if I **remove** this section from this PR's branch, we get the same endless repeating loop.
   ```
   sched_dumpstack: backtrace| 3: 0x8001a374 0x8001a374 0x8001a374 0x8001a374 0x8001a374 0x8001a374 0x8001a374 0x8001a374
   [repeat indefinetly]
   ```
   Which is:
   ```
   0x8001a374: assert_on_interrupt_handler at backtrace_qemu_main.c:112
   ```
   
   So we can't have this as a standalone patch, won't work. We need to keep this all together.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#discussion_r1958097550


##########
arch/risc-v/src/common/riscv_macros.S:
##########
@@ -342,7 +342,27 @@
 #if CONFIG_ARCH_INTERRUPTSTACK > 15
 #if !defined(CONFIG_SMP) && !defined(CONFIG_ARCH_USE_S_MODE)
 .macro  setintstack tmp0, tmp1
-  la    sp, g_intstacktop
+
+  /* Load g_intstacktop (the start of the interrupt stack) */

Review Comment:
   should this change belong to the second patch to support the nest irq handle?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "jlaitine (via GitHub)" <gi...@apache.org>.
jlaitine commented on PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#issuecomment-2696414230

   > > @jlaitine @tmedicci should we revert it?
   > 
   > No need to revert it for mpfs yet, I can check tomorrow if there is some simple.fix for it. I just didn't immediately see why it uses the offset of 12 bytes there.
   
   I gave the patch another look; I don't quite understand what is being done here:
   
     addi       sp, sp, -16
     REGSTORE   ra, 12(sp)
     REGSTORE   s0, 8(sp)
     add         s0, sp, 16
   
   I see that one wants to store ra and s0 to stack. But where does the offsets come from? For two registers on rv32 you'd need 2 * INT_REG_SIZE, that is 8 bytes, so for that it would be addi sp,sp,-8, REGSTORE ra, 8(sp), REGSTORE s0, 4(sp), add s0,sp, 8  and so worth. So offsets for those registers would be 8,4 for rv32 and 16,8 for rv64.
   
   I made a quick check that just fixing the alignment for "REGSTORE ra, 12(sp)" -> "REGSTORE ra, 16(sp)" (and  for the corresponding regload as well) fixes the booting issue.
   
   But could you @tmedicci  , @fdcavalcanti explain why the offset of 12 has been used here, and hence on rv32 4 bytes of "gap" left in stack here? Should this just always spend 16 bytes for these registers or perhaps use the INT_REG_SIZE to properly calculate the stack usage and offsets here?
   
   It is quite straightforward to just  fix this to boot also on platforms which require strict 8-byte stack alignment, but I'd need to understand the original code first, where does the offsets of 12,8 come in here?
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "tmedicci (via GitHub)" <gi...@apache.org>.
tmedicci commented on code in PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#discussion_r1954425944


##########
arch/risc-v/src/common/riscv_doirq.c:
##########
@@ -88,13 +88,24 @@ uintreg_t *riscv_doirq(int irq, uintreg_t *regs)
       (*running_task)->xcp.regs = regs;
     }
 
-  /* Nested interrupts are not supported */
+  /* Current regs non-zero indicates that we are processing an interrupt;
+   * current_regs is also used to manage interrupt level context switches.
+   *
+   * Nested interrupts are not supported. But an exception may occur while
+   * processing an interrupt. In this case, current_regs will be non-NULL.
+   */
 
-  DEBUGASSERT(!up_interrupt_context());
+  DEBUGASSERT(((irq > RISCV_MAX_EXCEPTION) && !up_interrupt_context()) ||

Review Comment:
   How could the backtrace dump work successfully (if `CONFIG_DEBUG_ASSERTIONS=y`) without it?
   
   It would assert there (instead of on the right place, which `riscv_exception`).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#discussion_r1950782741


##########
arch/risc-v/src/common/riscv_backtrace.c:
##########
@@ -150,17 +163,10 @@ int up_backtrace(struct tcb_s *tcb, void **buffer, int size, int skip)
     {
       if (up_interrupt_context())
         {
-#if CONFIG_ARCH_INTERRUPTSTACK > 15
-          ret = backtrace((uintptr_t *)g_intstackalloc,

Review Comment:
   but we need dump the backtrace on interrupt stack too



##########
arch/risc-v/src/common/riscv_exception_common.S:
##########
@@ -207,25 +207,46 @@ handle_irq:
   .cfi_offset x2, 8               /* Toolchain not support macro, is REG_X2 * 4 */
   .cfi_offset ra, 0               /* Toolchain not support macro, is REG_EPC * 4 */
 
+  REGLOAD    ra, REG_EPC(sp)
+  REGLOAD    s0, REG_X8(sp)

Review Comment:
   why need save ra/s0



##########
arch/risc-v/src/common/riscv_doirq.c:
##########
@@ -88,13 +88,24 @@ uintreg_t *riscv_doirq(int irq, uintreg_t *regs)
       (*running_task)->xcp.regs = regs;
     }
 
-  /* Nested interrupts are not supported */
+  /* Current regs non-zero indicates that we are processing an interrupt;
+   * current_regs is also used to manage interrupt level context switches.
+   *
+   * Nested interrupts are not supported. But an exception may occur while
+   * processing an interrupt. In this case, current_regs will be non-NULL.
+   */
 
-  DEBUGASSERT(!up_interrupt_context());
+  DEBUGASSERT(((irq > RISCV_MAX_EXCEPTION) && !up_interrupt_context()) ||

Review Comment:
   this patch contain unrelated change, please split to the small and independ patch for easy review.



##########
arch/risc-v/src/common/riscv_exception_common.S:
##########
@@ -207,25 +207,46 @@ handle_irq:
   .cfi_offset x2, 8               /* Toolchain not support macro, is REG_X2 * 4 */
   .cfi_offset ra, 0               /* Toolchain not support macro, is REG_EPC * 4 */
 
+  REGLOAD    ra, REG_EPC(sp)
+  REGLOAD    s0, REG_X8(sp)
+
 #if CONFIG_ARCH_INTERRUPTSTACK > 15
 
   /* Switch to interrupt stack */
 
   setintstack t0, t1
 
+  addi       sp, sp, -16
+  REGSTORE   ra, 12(sp)
+  REGSTORE   s0, 8(sp)
+  add	       s0, sp, 16
+
   /* Call interrupt handler in C */
 
   jal        x1, riscv_dispatch_irq
 
+  REGLOAD    ra, 12(sp)
+  REGLOAD    s0, 8(sp)
+  add	sp,sp,16

Review Comment:
   align the second argument at line 222, 230, 238, 248



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "fdcavalcanti (via GitHub)" <gi...@apache.org>.
fdcavalcanti commented on code in PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#discussion_r1951225283


##########
arch/risc-v/src/common/riscv_exception_common.S:
##########
@@ -207,25 +207,46 @@ handle_irq:
   .cfi_offset x2, 8               /* Toolchain not support macro, is REG_X2 * 4 */
   .cfi_offset ra, 0               /* Toolchain not support macro, is REG_EPC * 4 */
 
+  REGLOAD    ra, REG_EPC(sp)
+  REGLOAD    s0, REG_X8(sp)

Review Comment:
   On 210 we load from stack the EPC of the function that caused the exception as RA, because we create a frame below using this value. We need to link the exception routine to the code that created it, so we can have backtrace.
   Then on 211 we restore the fp/s0 value since it was used previously on line 140 (`csrr       s0, CSR_STATUS`).
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "nuttxpr (via GitHub)" <gi...@apache.org>.
nuttxpr commented on PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#issuecomment-2662867580

   [**\[Experimental Bot, please feedback here\]**](https://github.com/search?q=repo%3Aapache%2Fnuttx+15779&type=issues)
   
   Build and Test Successful (milkv_duos:nsh)
   https://gitlab.com/lupyuen/nuttx-build-log/-/snippets/4807555
   ```text
   $ git clone https://github.com/fdcavalcanti/nuttx nuttx --branch feature/risc-v_int_backtrace_review
   $ git clone https://github.com/apache/nuttx-apps apps --branch master
   $ pushd nuttx
   $ git reset --hard HEAD
   HEAD is now at 5cf2e434d6 arch/risc-v: improve nested interrupt assertion on riscv_doirq
   $ popd
   $ pushd apps
   $ git reset --hard HEAD
   HEAD is now at db8542d2b interpreters/python: fix patch to set `_PyRuntime` attribute
   $ popd
   NuttX Source: https://github.com/apache/nuttx/tree/5cf2e434d685cb75f4b67c57837184909b1f763d
   NuttX Apps: https://github.com/apache/nuttx-apps/tree/db8542d2b12a93c39a154ef5d100daecceeb9863
   $ cd nuttx
   $ tools/configure.sh milkv_duos:nsh
   $ make -j
   $ make -j export
   $ pushd ../apps
   $ ./tools/mkimport.sh -z -x ../nuttx/nuttx-export-12.1.0.tar.gz
   $ make -j import
   $ popd
   $ genromfs -f initrd -d ../apps/bin -V NuttXBootVol
   $ head -c 65536 /dev/zero
   $ cat nuttx.bin /tmp/nuttx.pad initrd
   $ scp Image tftpserver:/tftpboot/Image-sg2000
   $ ssh tftpserver ls -l /tftpboot/Image-sg2000
   $ cd /home/luppy/nuttx-build-farm
   $ ssh tftpserver
   OpenSBI v0.9
   nsh> uname -a
   NuttX 12.1.0 5cf2e434d6 Feb 17 2025 19:38:55 risc-v milkv_duos
   nsh> ostest
   arena       81000    81000
   ordblks         2        3
   mxordblk    7cff8    78ff8
   uordblks     2660     4570
   fordblks    7e9a0    7ca90
   user_main: Exiting
   ostest_main: Exiting with status 0
   nsh> Now running https://github.com/lupyuen/nuttx-build-farm/blob/main/oz64-power.sh off
   ----- Power off Oz64
   []
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "lupyuen (via GitHub)" <gi...@apache.org>.
lupyuen commented on PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#issuecomment-2662855930

   @nuttxpr test milkv_duos:nsh


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "fdcavalcanti (via GitHub)" <gi...@apache.org>.
fdcavalcanti commented on PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#issuecomment-2656541376

   About breaking this up in smaller PRs.
   Here's the first one #15835 .


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "fdcavalcanti (via GitHub)" <gi...@apache.org>.
fdcavalcanti commented on code in PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#discussion_r1956053929


##########
arch/risc-v/src/common/riscv_exception_common.S:
##########
@@ -207,25 +207,46 @@ handle_irq:
   .cfi_offset x2, 8               /* Toolchain not support macro, is REG_X2 * 4 */
   .cfi_offset ra, 0               /* Toolchain not support macro, is REG_EPC * 4 */
 
+  REGLOAD    ra, REG_EPC(sp)
+  REGLOAD    s0, REG_X8(sp)

Review Comment:
   I think wrapping with CONFIG_SCHED_BACKTRACE gives good indication of its purpose.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "fdcavalcanti (via GitHub)" <gi...@apache.org>.
fdcavalcanti commented on code in PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#discussion_r1950818774


##########
arch/risc-v/src/common/riscv_backtrace.c:
##########
@@ -150,17 +163,10 @@ int up_backtrace(struct tcb_s *tcb, void **buffer, int size, int skip)
     {
       if (up_interrupt_context())
         {
-#if CONFIG_ARCH_INTERRUPTSTACK > 15
-          ret = backtrace((uintptr_t *)g_intstackalloc,

Review Comment:
   This check has been moved inside `backtrace` function



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "fdcavalcanti (via GitHub)" <gi...@apache.org>.
fdcavalcanti commented on code in PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#discussion_r1950818774


##########
arch/risc-v/src/common/riscv_backtrace.c:
##########
@@ -150,17 +163,10 @@ int up_backtrace(struct tcb_s *tcb, void **buffer, int size, int skip)
     {
       if (up_interrupt_context())
         {
-#if CONFIG_ARCH_INTERRUPTSTACK > 15
-          ret = backtrace((uintptr_t *)g_intstackalloc,

Review Comment:
   This check has been moved to the `backtrace` function



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "tmedicci (via GitHub)" <gi...@apache.org>.
tmedicci commented on code in PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#discussion_r1953004237


##########
arch/risc-v/src/common/riscv_doirq.c:
##########
@@ -88,13 +88,24 @@ uintreg_t *riscv_doirq(int irq, uintreg_t *regs)
       (*running_task)->xcp.regs = regs;
     }
 
-  /* Nested interrupts are not supported */
+  /* Current regs non-zero indicates that we are processing an interrupt;
+   * current_regs is also used to manage interrupt level context switches.
+   *
+   * Nested interrupts are not supported. But an exception may occur while
+   * processing an interrupt. In this case, current_regs will be non-NULL.
+   */
 
-  DEBUGASSERT(!up_interrupt_context());
+  DEBUGASSERT(((irq > RISCV_MAX_EXCEPTION) && !up_interrupt_context()) ||

Review Comment:
   Hi @xiaoxiang781216, 
   
   I don't think those changes can be split into smaller commits. This PR implements the backtrace dump when an exception occurs during IRQ handling.
   
   This code is necessary, otherwise it wouldn't achieve the panic function that dumps the backtrace (which require `irq_dispatch` to run). Without it, we wouldn't be able to check if the call frame is able to restore the backtrace across the IRQ handle. 
   
   2 and 3 aren't independent changes.
   
   @fdcavalcanti , can you test if 1) can be split into another PR?
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "fdcavalcanti (via GitHub)" <gi...@apache.org>.
fdcavalcanti commented on code in PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#discussion_r1951229324


##########
arch/risc-v/src/common/riscv_doirq.c:
##########
@@ -88,13 +88,24 @@ uintreg_t *riscv_doirq(int irq, uintreg_t *regs)
       (*running_task)->xcp.regs = regs;
     }
 
-  /* Nested interrupts are not supported */
+  /* Current regs non-zero indicates that we are processing an interrupt;
+   * current_regs is also used to manage interrupt level context switches.
+   *
+   * Nested interrupts are not supported. But an exception may occur while
+   * processing an interrupt. In this case, current_regs will be non-NULL.
+   */
 
-  DEBUGASSERT(!up_interrupt_context());
+  DEBUGASSERT(((irq > RISCV_MAX_EXCEPTION) && !up_interrupt_context()) ||

Review Comment:
   We need this patch otherwise we won't call irq_dispatch.
   Not sure what you mean by that.



##########
arch/risc-v/src/common/riscv_exception_common.S:
##########
@@ -207,25 +207,46 @@ handle_irq:
   .cfi_offset x2, 8               /* Toolchain not support macro, is REG_X2 * 4 */
   .cfi_offset ra, 0               /* Toolchain not support macro, is REG_EPC * 4 */
 
+  REGLOAD    ra, REG_EPC(sp)
+  REGLOAD    s0, REG_X8(sp)
+
 #if CONFIG_ARCH_INTERRUPTSTACK > 15
 
   /* Switch to interrupt stack */
 
   setintstack t0, t1
 
+  addi       sp, sp, -16
+  REGSTORE   ra, 12(sp)
+  REGSTORE   s0, 8(sp)
+  add	       s0, sp, 16
+
   /* Call interrupt handler in C */
 
   jal        x1, riscv_dispatch_irq
 
+  REGLOAD    ra, 12(sp)
+  REGLOAD    s0, 8(sp)
+  add	sp,sp,16

Review Comment:
   Will fix it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "acassis (via GitHub)" <gi...@apache.org>.
acassis merged PR #15815:
URL: https://github.com/apache/nuttx/pull/15815


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "cederom (via GitHub)" <gi...@apache.org>.
cederom commented on PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#issuecomment-2694619820

   > @acassis: @jlaitine @tmedicci should we revert it?
   
   Maybe @fdcavalcanti could provide a fix if the implementation is already here and useful but broken? :-)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#discussion_r1953232657


##########
arch/risc-v/src/common/riscv_doirq.c:
##########
@@ -88,13 +88,24 @@ uintreg_t *riscv_doirq(int irq, uintreg_t *regs)
       (*running_task)->xcp.regs = regs;
     }
 
-  /* Nested interrupts are not supported */
+  /* Current regs non-zero indicates that we are processing an interrupt;
+   * current_regs is also used to manage interrupt level context switches.
+   *
+   * Nested interrupts are not supported. But an exception may occur while
+   * processing an interrupt. In this case, current_regs will be non-NULL.
+   */
 
-  DEBUGASSERT(!up_interrupt_context());
+  DEBUGASSERT(((irq > RISCV_MAX_EXCEPTION) && !up_interrupt_context()) ||

Review Comment:
   It's a general improvement to allow syscall in irq handler and worth to make it into an indpendent patch, and let's panic improvement depends on it. 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "tmedicci (via GitHub)" <gi...@apache.org>.
tmedicci commented on code in PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#discussion_r1953267656


##########
arch/risc-v/src/common/riscv_doirq.c:
##########
@@ -88,13 +88,24 @@ uintreg_t *riscv_doirq(int irq, uintreg_t *regs)
       (*running_task)->xcp.regs = regs;
     }
 
-  /* Nested interrupts are not supported */
+  /* Current regs non-zero indicates that we are processing an interrupt;
+   * current_regs is also used to manage interrupt level context switches.
+   *
+   * Nested interrupts are not supported. But an exception may occur while
+   * processing an interrupt. In this case, current_regs will be non-NULL.
+   */
 
-  DEBUGASSERT(!up_interrupt_context());
+  DEBUGASSERT(((irq > RISCV_MAX_EXCEPTION) && !up_interrupt_context()) ||

Review Comment:
   Please note that, on RISC-V, exceptions are treated by the irq handler (and that's why it needs to be adjusted accordingly to allow treating an exception - like store prohibited - during an interrupt handler).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "fdcavalcanti (via GitHub)" <gi...@apache.org>.
fdcavalcanti commented on code in PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#discussion_r1958202017


##########
arch/risc-v/src/common/riscv_macros.S:
##########
@@ -342,7 +342,27 @@
 #if CONFIG_ARCH_INTERRUPTSTACK > 15
 #if !defined(CONFIG_SMP) && !defined(CONFIG_ARCH_USE_S_MODE)
 .macro  setintstack tmp0, tmp1
-  la    sp, g_intstacktop
+
+  /* Load g_intstacktop (the start of the interrupt stack) */

Review Comment:
   If I do that the first patch gets unstable when an exception occurs inside IRQ (non-stop stack dump). Don't think we should do that.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "cederom (via GitHub)" <gi...@apache.org>.
cederom commented on PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#issuecomment-2694606797

   Whoops :-( I think @lupyuen just adds support for RISCV64 ESWIN EIC7700X SoC in https://github.com/apache/nuttx/pull/15921 that might be used to verify this kind of stuff on real world hardware?
   
   What RV64 boards are well implemented and can be used for real world verification?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#issuecomment-2694746185

   @fdcavalcanti do you try backtrace in gdb with:
   https://github.com/apache/nuttx/pull/15815/files#diff-80d4dc3d0f030ae4ec0a9f70272e80da59a093522bd30c7213eb027543c86b03R206-R208
   but wihtout:
   https://github.com/apache/nuttx/pull/15815/files#diff-80d4dc3d0f030ae4ec0a9f70272e80da59a093522bd30c7213eb027543c86b03R210-R214
   https://github.com/apache/nuttx/pull/15815/files#diff-80d4dc3d0f030ae4ec0a9f70272e80da59a093522bd30c7213eb027543c86b03R221-R224
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "jlaitine (via GitHub)" <gi...@apache.org>.
jlaitine commented on PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#issuecomment-2694647608

   > @jlaitine @tmedicci should we revert it?
   
   No need to revert it for mpfs yet, I can check tomorrow if there is some simple.fix for it. I just didn't immediately see why it uses the offset of 12 bytes there.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#discussion_r1956093642


##########
arch/risc-v/src/common/riscv_exception_common.S:
##########
@@ -207,25 +207,46 @@ handle_irq:
   .cfi_offset x2, 8               /* Toolchain not support macro, is REG_X2 * 4 */
   .cfi_offset ra, 0               /* Toolchain not support macro, is REG_EPC * 4 */
 
+  REGLOAD    ra, REG_EPC(sp)
+  REGLOAD    s0, REG_X8(sp)

Review Comment:
   yes, but even that it's an indpendent change from supporting the interrupt reentry



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#discussion_r1953722165


##########
arch/risc-v/src/common/riscv_doirq.c:
##########
@@ -88,13 +88,24 @@ uintreg_t *riscv_doirq(int irq, uintreg_t *regs)
       (*running_task)->xcp.regs = regs;
     }
 
-  /* Nested interrupts are not supported */
+  /* Current regs non-zero indicates that we are processing an interrupt;
+   * current_regs is also used to manage interrupt level context switches.
+   *
+   * Nested interrupts are not supported. But an exception may occur while
+   * processing an interrupt. In this case, current_regs will be non-NULL.
+   */
 
-  DEBUGASSERT(!up_interrupt_context());
+  DEBUGASSERT(((irq > RISCV_MAX_EXCEPTION) && !up_interrupt_context()) ||

Review Comment:
   yes, but this is a general improvement,  why bundle in the change of backtrace? it is still useful even without backtrace improvement.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "fdcavalcanti (via GitHub)" <gi...@apache.org>.
fdcavalcanti commented on code in PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#discussion_r1953025438


##########
arch/risc-v/src/common/riscv_doirq.c:
##########
@@ -88,13 +88,24 @@ uintreg_t *riscv_doirq(int irq, uintreg_t *regs)
       (*running_task)->xcp.regs = regs;
     }
 
-  /* Nested interrupts are not supported */
+  /* Current regs non-zero indicates that we are processing an interrupt;
+   * current_regs is also used to manage interrupt level context switches.
+   *
+   * Nested interrupts are not supported. But an exception may occur while
+   * processing an interrupt. In this case, current_regs will be non-NULL.
+   */
 
-  DEBUGASSERT(!up_interrupt_context());
+  DEBUGASSERT(((irq > RISCV_MAX_EXCEPTION) && !up_interrupt_context()) ||

Review Comment:
   Currently running tests.
   So far, I believe we can have 1) as a separate PR.
   It looks like 2 and 3 must be together.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "tmedicci (via GitHub)" <gi...@apache.org>.
tmedicci commented on code in PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#discussion_r1953265966


##########
arch/risc-v/src/common/riscv_doirq.c:
##########
@@ -88,13 +88,24 @@ uintreg_t *riscv_doirq(int irq, uintreg_t *regs)
       (*running_task)->xcp.regs = regs;
     }
 
-  /* Nested interrupts are not supported */
+  /* Current regs non-zero indicates that we are processing an interrupt;
+   * current_regs is also used to manage interrupt level context switches.
+   *
+   * Nested interrupts are not supported. But an exception may occur while
+   * processing an interrupt. In this case, current_regs will be non-NULL.
+   */
 
-  DEBUGASSERT(!up_interrupt_context());
+  DEBUGASSERT(((irq > RISCV_MAX_EXCEPTION) && !up_interrupt_context()) ||

Review Comment:
   @xiaoxiang781216 , we are not implementing anything related to the syscall in irq handler.
   
   We are just allowing the exception being treated by the `irq_dispatch` when handling an interrupt. 
   The [`riscv_exception_attach`](https://github.com/apache/incubator-nuttx/blob/3a4b8edf2c77563033c0d0dd3b38100e51da6495/arch/risc-v/src/common/riscv_exception.c#L256) registers the handlers for each exception. Note that exceptions like `RISCV_IRQ_IINSTRUCTION` are treated by [`riscv_exception`](https://github.com/apache/incubator-nuttx/blob/3a4b8edf2c77563033c0d0dd3b38100e51da6495/arch/risc-v/src/common/riscv_exception.c#L93), which dumps the stack and the backtrace. This `DEBUGASSERTION` was changed just to allow it to occur during an interrupt handler.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#discussion_r1951898478


##########
arch/risc-v/src/common/riscv_doirq.c:
##########
@@ -88,13 +88,24 @@ uintreg_t *riscv_doirq(int irq, uintreg_t *regs)
       (*running_task)->xcp.regs = regs;
     }
 
-  /* Nested interrupts are not supported */
+  /* Current regs non-zero indicates that we are processing an interrupt;
+   * current_regs is also used to manage interrupt level context switches.
+   *
+   * Nested interrupts are not supported. But an exception may occur while
+   * processing an interrupt. In this case, current_regs will be non-NULL.
+   */
 
-  DEBUGASSERT(!up_interrupt_context());
+  DEBUGASSERT(((irq > RISCV_MAX_EXCEPTION) && !up_interrupt_context()) ||

Review Comment:
   The patch contain some trick but independent change, it's better to split into the seperated pr to help the reviewer understand why this change is needed, for example:
   
   1. Merge the stack baundary check into backtrace
   2. Create a call frame in assembly code to help debugger restore the backtrace across the irq handle
   3. The change here and setintstack improvement isn't directly related to backtrace if I understand correctly, so could split too.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] risc-v/backtrace: Support backtrace dump during IRQ [nuttx]

Posted by "nuttxpr (via GitHub)" <gi...@apache.org>.
nuttxpr commented on PR #15815:
URL: https://github.com/apache/nuttx/pull/15815#issuecomment-2650783082

   [**\[Experimental Bot, please feedback here\]**](https://github.com/search?q=repo%3Aapache%2Fnuttx+15779&type=issues)
   
   Build and Test Successful (milkv_duos:nsh)
   https://gitlab.com/lupyuen/nuttx-build-log/-/snippets/4805229
   ```text
   $ git clone https://github.com/fdcavalcanti/nuttx nuttx --branch feature/risc-v_int_backtrace_review
   $ git clone https://github.com/apache/nuttx-apps apps --branch master
   $ pushd nuttx
   $ git reset --hard HEAD
   HEAD is now at 8aac8a457a risc-v/backtrace: Support backtrace dump during IRQ
   $ popd
   $ pushd apps
   $ git reset --hard HEAD
   HEAD is now at fb0c1e10d system/uorb: require that LIBC_FLOATINGPOINT be enabled for DEBUG_UORB
   $ popd
   NuttX Source: https://github.com/apache/nuttx/tree/8aac8a457a835f042498e497d1e0d38f299791bf
   NuttX Apps: https://github.com/apache/nuttx-apps/tree/fb0c1e10ded2a6fb9f066b9893662cbcc86e4646
   $ cd nuttx
   $ tools/configure.sh milkv_duos:nsh
   $ make -j
   $ make -j export
   $ pushd ../apps
   $ ./tools/mkimport.sh -z -x ../nuttx/nuttx-export-12.1.0.tar.gz
   $ make -j import
   $ popd
   $ genromfs -f initrd -d ../apps/bin -V NuttXBootVol
   $ head -c 65536 /dev/zero
   $ cat nuttx.bin /tmp/nuttx.pad initrd
   $ scp Image tftpserver:/tftpboot/Image-sg2000
   $ ssh tftpserver ls -l /tftpboot/Image-sg2000
   $ cd /home/luppy/nuttx-build-farm
   $ ssh tftpserver
   OpenSBI v0.9
   nsh> uname -a
   NuttX 12.1.0 8aac8a457a Feb 11 2025 21:06:37 risc-v milkv_duos
   nsh> ostest
   arena       81000    81000
   ordblks         2        3
   mxordblk    7cff8    78ff8
   uordblks     2660     4570
   fordblks    7e9a0    7ca90
   user_main: Exiting
   ostest_main: Exiting with status 0
   nsh> Now running https://github.com/lupyuen/nuttx-build-farm/blob/main/oz64-power.sh off
   ----- Power off Oz64
   []
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org