casaroli opened a new pull request, #20821: URL: https://github.com/apache/nuttx/pull/20821
## Summary #20801 defines `up_tls_info()` as a read of `TPIDR_EL0` for all code, also for the kernel. `include/nuttx/tls.h` then makes `tls_get_info()` use it in the kernel too. In a protected or a kernel build, user code can write `TPIDR_EL0` (`msr tpidr_el0, x0` is allowed at EL0). So the kernel writes errno to an address that user code selects: a system call that fails writes errno through the TLS info that `TPIDR_EL0` points to. With `CONFIG_TLS_NCLEANUP` > 0, `tls_cleanup_push()` in the kernel (`poll()`, `epoll_wait()`, TCP, UDP, netlink) also writes a callback and its argument there. This PR defines `up_tls_info()` only for user code and for the flat build, in `arch/arm64/include/arch.h`, where `include/nuttx/arch.h` says it belongs. The kernel of a protected or a kernel build uses `tls_get_info()` again, which finds the TLS info from the TCB, as before #20801. User code still reads `TPIDR_EL0`, so code on a `makecontext()` stack still finds its TLS info. The flat build does not change: there the kernel and the applications are one image. ## Impact arm64, protected and kernel builds: the kernel no longer uses `TPIDR_EL0`. Flat builds: no change. ## Testing QEMU 11 with HVF on an Apple M4, `qemu-armv8a:knsh`. The test program points `TPIDR_EL0` to a copy of its TLS info, calls `open()` on a file that does not exist, and puts `TPIDR_EL0` back. Then it checks where errno went. | Test | master | This PR | |---|---|---| | errno of a failing `open()` | `kernel wrote errno through the user TPIDR_EL0 YES` (errno of the thread 0, the copy changed) | `kernel wrote errno through the user TPIDR_EL0 NO` (errno of the thread 2) | | `makecontext()` stack: `printf()`, errno, environment, context switch, signal handler | PASS | PASS | | ucontext test (`getcontext`, `makecontext`, `swapcontext`, `uc_link`, FP registers) | PASS | PASS | | errno per thread, 4 threads | PASS | PASS | | `ostest` on `qemu-armv8a:knsh` and `qemu-armv8a:nsh` | `Exiting with status 0` | `Exiting with status 0` | Build: `fvp-armv8r:pnsh` (protected). With this PR the kernel image has `tls_get_info()` and the user image does not use it. `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]
