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

   ## Summary
   
   On x86_64 (intel64), a divide error (ISR0) or an x87 FPU error (ISR16) goes 
to `x86_64_fault_kill_isr()`. This handler sends SIGFPE to the running task and 
returns to the instruction that faulted. When the kernel itself faulted, no 
task can handle the signal: the CPU executes the same instruction again and 
again, and the system hangs without a message. One example is a divide by zero 
in the idle task at boot, which `qemu-intel64:nsh` and 
`qemu-intel64:knsh_romfs` with `CONFIG_RTC_HIRES` and the HPET timer show: the 
console stays empty after `Booting from ROM..`.
   
   This PR sends the kernel faults to the panic path of 
`x86_64_fault_panic_isr()`, which prints the exception and the register dump. A 
fault belongs to the kernel when the task is a kernel thread or the idle task, 
or, in a build with a user mode, when the CPU was in ring 0 (a system call or 
an interrupt handler). `x86_64_fault_user_isr()` makes the same decision for 
ISR6, ISR13 and ISR14, and arm64 and RISC-V make it for their user faults. A 
user task still gets SIGFPE.
   
   In the flat build all code runs in ring 0, so the CPL cannot tell a task 
from the kernel. There, only kernel threads and the idle task panic, and all 
other tasks get SIGFPE as before.
   
   ## Impact
   
   x86_64 intel64 only. A divide error or an x87 FPU error of the kernel now 
panics with a register dump instead of a silent hang. A user process in the 
kernel build and a task in the flat build get SIGFPE as before. Not a breaking 
change: no API change, and the flat build keeps SIGFPE for all tasks. No 
Kconfig change, no build file change.
   
   ## Testing
   
   QEMU 10.2.2 under KVM, GCC 12.3 in the NuttX CI image, make. "HPET" means 
`ARCH_INTEL64_HPET_ALARM` and `INTEL64_HPET` instead of the TSC deadline timer. 
A test program (as `hello`) divides by zero with a SIGFPE handler (`fpe`, the 
handler prints and calls `_exit()`) and without one (`fpedef`).
   
   | Config | Test | master | this PR |
   |---|---|---|---|
   | `nsh` (flat), HPET, `RTC`, `RTC_HIRES` | boot (divide by zero in the idle 
task) | no output, no prompt | `x86_64_fault_panic_isr: Exception 0 occurred`, 
assertion in `Idle_Task`, `CPL: 0`, register dump with `RSI: 0` |
   | `knsh_romfs` (kernel), HPET, `RTC`, `RTC_HIRES` | boot | no output, no 
prompt | the same panic report |
   | `nsh`, TSC deadline | `hello fpe`, `hello fpedef`, `ps` | `SIGFPE caught`; 
the default action ends `hello`; NSH runs on | the same |
   | `knsh_romfs`, HPET, `SCHED_IRQMONITOR`, `ARCH_PERF_EVENTS` | `cat 
/proc/irqs` (divide by zero in `up_perf_convert()` in a system call of NSH) | 
no output, the system hangs | panic report: task `/system/bin/init`, `CPL: 0` |
   | `nsh`, HPET, `SCHED_IRQMONITOR`, `ARCH_PERF_EVENTS` | `cat /proc/irqs` | 
the shell gets SIGFPE and ends, init starts a new `sh` | the same (flat build: 
task gets SIGFPE) |
   | `knsh_romfs`, TSC deadline | `/system/bin/hello fpe` | segmentation fault 
at `x86_64_sigdeliver` (a separate master bug: the signal trampoline keeps the 
user CS) | the same |
   
   With a test-only fix of that trampoline bug (the trampoline gets the kernel 
CS and SS), `knsh_romfs` `/system/bin/hello fpe` prints `SIGFPE caught` on 
master and on this PR: the user process still gets SIGFPE.
   
   x86_64 has no protected build. No CI test covers this: ostest does not 
divide by zero, and no x86_64 CI configuration runs a kernel fault.
   
   `tools/checkpatch.sh -c -u -m -g` passes.
   


-- 
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