daniel-p-carvalho opened a new pull request, #20450:
URL: https://github.com/apache/nuttx/pull/20450

   ## Summary
   
   `arch/mips/pic32mz: record the running task on interrupt exit.`
   
   Since 19b4911d7f ("arch: remove up_current_regs in common code"),
   `pic32mz_decodeirq()` saves the interrupted context into
   `g_running_tasks[this_cpu()]->xcp.regs` on entry, but nothing in the
   PIC32MZ interrupt path updates `g_running_tasks[]` after a context switch.
   The only writers are `nx_start()` (Idle task) and `up_exit()` (NULL). As a
   result:
   
   * While the system runs, every interrupt copies the interrupted context into
     the Idle task's TCB, whichever task was really interrupted.
   * After any task or thread exits, `up_exit()` sets `g_running_tasks[]` to
     NULL and it stays NULL: no context is saved on interrupt entry any more,
     and the next context switch restores stale registers. The crash dump path
     also uses `g_running_tasks[]`, so the resulting exception usually faults
     again inside `PANIC()` and prints nothing useful.
   
   The fix sets `g_running_tasks[this_cpu()]` to `this_task()` before
   `pic32mz_decodeirq()` returns, as the ARM and RISC-V interrupt handlers do.
   
   This was found while porting NuttX to the PIC32MZ-W1 (draft PR #20448):
   the system crashed as soon as the network initialization thread
   (`CONFIG_NETINIT_THREAD`) exited.
   
   `arch/mips/src/pic32mx/pic32mx_decodeirq.c`,
   `arch/mips/src/mips32/mips_doirq.c` and
   `arch/mips/src/jz4780/jz4780_decodeirq.c` follow the same pattern and look
   affected too. They are not changed here because I have no hardware to test
   them; see the issue linked below.
   
   ## Impact
   
   * PIC32MZ (EC, EF and W1): context save/restore is correct after a task or
     thread exits, and crash dumps work.
   * No Kconfig, API or board changes.
   
   ## Testing
   
   * checkpatch: `./tools/checkpatch.sh -c -u -m -g upstream/master..HEAD`
     passes.
   * Build (Pinguino p32-gcc 4.9.2, as in CI): `pic32mz-starterkit:nsh`,
     `chipkit-wifire:nsh`, `flipnclick-pic32mz:nsh`,
     `flipnclick-pic32mz:nxlines`. No new warnings.
   * Hardware: PIC32MZ-W1 (WFI32E01PE, B0 silicon) board from the port in
     #20448, with networking enabled (`CONFIG_NETINIT_THREAD=y`).
     * Before: right after `netinit_thread: Exit` the board took a "Reserved
       instruction" or "Bus error (instruction fetch)" exception with EPC in
       rodata or at 0, and the PANIC dump faulted again.
     * After: the netinit thread exits cleanly, NSH, telnetd and ping keep
       working. A deliberate bus error (`mw 0x0` in NSH) now gives a complete
       crash dump (registers, stack dump and task list).
   * Not tested on PIC32MZ EC/EF hardware.
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to