xiaoxiang781216 edited a comment on pull request #5731:
URL: https://github.com/apache/incubator-nuttx/pull/5731#issuecomment-1080599016


   > Can someone please explain to me how this change is supposed to work with 
MMU and address environments ? Am I misunderstanding something ? The xcp.regs 
are now allocated from the user task's stack memory, prior to this change they 
were in the kernel's memory space.
   > 
   > Please note the following example
   > 
   > ```
   > 
   >           struct tcb_s *nexttcb = this_task();
   > 
   > #ifdef CONFIG_ARCH_ADDRENV
   >           /* Make sure that the address environment for the previously
   >            * running task is closed down gracefully (data caches dump,
   >            * MMU flushed) and set up the address environment for the new
   >            * thread at the head of the ready-to-run list.
   >            */
   > 
   >           (void)group_addrenv(nexttcb);
   > #endif
   >           /* Reset scheduler parameters */
   > 
   >           nxsched_resume_scheduler(nexttcb);
   > 
   >           /* Then switch contexts */
   > 
   >           riscv_switchcontext(&rtcb->xcp.regs, nexttcb->xcp.regs);
   > ```
   > 
   > If rtcb->xpc.regs points to the old task's stack, which resides in its 
address environment, how can we perform a register save there ?
   > 
   
   since rtcb->xcp.regs itself is still in the kernel space, 
riscv_switchcontext can update rtcb->xcp.regs to the new context on the stack:
   
https://github.com/apache/incubator-nuttx/blob/master/arch/risc-v/src/common/riscv_swint.c#L247-L254
   
   > The old implementation saved the task context in the kernel space memory, 
which is why it is safe to change the address environment as the memory for 
xcp.regs[] exists in the kernel space and is always mapped ?
   
   The problem we can see is that up_schedule_sigaction may touch the stack of 
non current thread directly:
   
   - 
https://github.com/apache/incubator-nuttx/pull/5731/files#diff-6959df667f4307ac5bd81dbd07981927ab5612fe0590f0dfca26665bcde96ec6R307-R318
   
   - 
https://github.com/apache/incubator-nuttx/pull/5731/files#diff-6959df667f4307ac5bd81dbd07981927ab5612fe0590f0dfca26665bcde96ec6R399-R415
   
   We haven't found other places will touch the memory pointed by xcp.regs of 
the non current thread, if you find some please point out.
    
   Since RISCV kernel mode isn't mainlined yet, @anchao will test the same 
change(#5645) on ARM.
   


-- 
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-unsubscr...@nuttx.apache.org

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


Reply via email to