You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "pussuw (via GitHub)" <gi...@apache.org> on 2024/09/10 12:46:10 UTC
[PR] arm64/task/pthread_start: Fix rare issue with context register location [nuttx]
pussuw opened a new pull request, #13366:
URL: https://github.com/apache/nuttx/pull/13366
## Summary
There is a tiny possibility that when a process is started a trap is taken which causes a context switch. This moves the kernel stack unexpectedly and the task start logic no longer works.
Fix this by recording the initial context location, and use that to trampoline into the user process with interrupts disabled. This ensures the context stays intact AND the kernel stack is fully unwound before the user process starts.
## Impact
Fixes a rare crash when a task / process is starting
## Testing
- qemu-armv8a:knsh
- downstream imx9 target with kernel mode
--
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] arm64/task/pthread_start: Fix rare issue with context register location [nuttx]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on PR #13366:
URL: https://github.com/apache/nuttx/pull/13366#issuecomment-2341325845
> There is a tiny possibility that when a process is started a trap is taken which causes a context switch. This moves the kernel stack unexpectedly and the task start logic no longer works.
but why not initialize PSTATE to disable all interrupts and re-enable it after the initialization code enter the safe place.
--
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] arm64/task/pthread_start: Fix rare issue with context register location [nuttx]
Posted by "acassis (via GitHub)" <gi...@apache.org>.
acassis merged PR #13366:
URL: https://github.com/apache/nuttx/pull/13366
--
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] arm64/task/pthread_start: Fix rare issue with context register location [nuttx]
Posted by "pussuw (via GitHub)" <gi...@apache.org>.
pussuw commented on PR #13366:
URL: https://github.com/apache/nuttx/pull/13366#issuecomment-2341363888
> > There is a tiny possibility that when a process is started a trap is taken which causes a context switch. This moves the kernel stack unexpectedly and the task start logic no longer works.
>
> but why not initialize PSTATE to disable all interrupts and re-enable it after the initialization code enter the safe place?
The task start logic after arm64_initialstate first executes nxtask_start() with kernel privileges https://github.com/apache/nuttx/blob/master/sched/task/task_start.c and then executes the "up_task_start" trampoline code. I see no reason to defer interrupts before entering up_task_start.
The initial state logic reserves space for FPU on the top of the kernel stack, and space for the integer registers just below that.
What I want is to use the existing arm64_exit_exception logic to:
- Load the userspace context into the kernel stack, where the integer registers originally were
- Fully unwind the kernel stack when dropping to user space
The logic in this patch achieves both, and works for pthreads as well. I decided to replace the old kernel private system call logic because that way did not fully unwind the kernel stack, which is exactly what I want to do.
I would also like to replace the RISC-V equivalent functions, but due to a possible regression I decided not to do so.
--
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