nuttx/sched/sched
Ville Juven 09e7987121 sched/addrenv: Fix system crash when process group has been deleted
There is currently a big problem in the address environment handling which
is that the address environment is released too soon when the process is
exiting. The current MMU mappings will always be the exiting process's, which means
the system needs them AT LEAST until the next context switch happens. If
the next thread is a kernel thread, the address environment is needed for
longer.

Kernel threads "lend" the address environment of the previous user process.
This is beneficial in two ways:
- The kernel processes do not need an allocated address environment
- When a context switch happens from user -> kernel or kernel -> kernel,
  the TLB does not need to be flushed. This must be done only when
  changing to a different user address environment.

Another issue is when a new process is created; the address environment
of the new process must be temporarily instantiated by up_addrenv_select().
However, the system scheduler does not know that the process has a different
address environment to its own and when / if a context restore happens, the
wrong MMU page directory is restored and the process will either crash or
do something horribly wrong.

The following changes are needed to fix the issues:
- Add mm_curr which is the current address environment of the process
- Add a reference counter to safeguard the address environment
- Whenever an address environment is mapped to MMU, its reference counter
  is incremented
- Whenever and address environment is unmapped from MMU, its reference
  counter is decremented, and tested. If no more references -> drop the
  address environment and release the memory as well
- To limit the context switch delay, the address environment is freed in
  a separate low priority clean-up thread (LPWORK)
- When a process temporarily instantiates another process's address
  environment, the scheduler will now know of this and will restore the
  correct mappings to MMU

Why is this not causing more noticeable issues ? The problem only happens
under the aforementioned special conditions, and if a context switch or
IRQ occurs during this time.
2023-02-08 02:51:23 +08:00
..
Make.defs fs/streams: Move the file streams from the group structure into TLS 2022-12-22 20:16:11 +08:00
sched_addblocked.c sched: semaphore wait list optimize 2022-09-28 18:08:37 +08:00
sched_addprioritized.c sched: remove unnecessary type cast 2022-12-15 09:44:32 +08:00
sched_addreadytorun.c sched: remove unnecessary type cast 2022-12-15 09:44:32 +08:00
sched_backtrace.c sched: Guard backtrace related code correctly 2022-10-11 00:01:35 +02:00
sched_cpuload_oneshot.c sched: Simplify the cpuload process 2022-08-18 22:11:29 +03:00
sched_cpuload_period.c sched: Simplify the cpuload process 2022-08-18 22:11:29 +03:00
sched_cpuload.c sched: Simplify the cpuload process 2022-08-18 22:11:29 +03:00
sched_cpupause.c sched: Author Gregory Nutt: update licenses to Apache 2021-02-09 01:21:53 -08:00
sched_cpuselect.c nuttx/sched: use pid to check idle task 2022-10-31 17:53:08 +09:00
sched_critmonitor.c sched_critmonitor: remove check zero in sched_critmonitor 2022-07-22 10:15:06 +03:00
sched_foreach.c sched: Remove pidhash_s and move ticks to tcb_s 2021-10-16 06:19:17 -03:00
sched_get_stackinfo.c sched: Refine tls_info_s and task_info_s 2021-07-02 10:33:34 -05:00
sched_getaffinity.c sched: Author Gregory Nutt: update licenses to Apache 2021-02-09 01:21:53 -08:00
sched_getcpu.c
sched_getfiles.c Run nxstyle against all .c and .h files modified by this PR. 2020-05-09 14:19:08 -03:00
sched_getparam.c Don't include assert.h from public header file 2021-06-03 08:36:03 -07:00
sched_getscheduler.c sched: Author Gregory Nutt: update licenses to Apache 2021-02-09 01:21:53 -08:00
sched_gettcb.c drivers/note: Replace the scritical section with spin_xxx_wo_note 2023-01-04 00:21:18 +02:00
sched_idletask.c nuttx/sched: use pid to check idle task 2022-10-31 17:53:08 +09:00
sched_lock.c sched: Remove the unnecessary "FAR dq_queue_t *" cast 2022-08-31 08:50:57 +09:00
sched_lockcount.c sched: Author Gregory Nutt: update licenses to Apache 2021-02-09 01:21:53 -08:00
sched_mergepending.c sched: remove unnecessary type cast 2022-12-15 09:44:32 +08:00
sched_mergeprioritized.c Remove the unnessary empty line after label 2022-09-30 17:54:56 +02:00
sched_processtimer.c sched: Remove the unnecessary weak_function 2022-08-30 09:42:24 +02:00
sched_releasetcb.c sched/addrenv: Fix system crash when process group has been deleted 2023-02-08 02:51:23 +08:00
sched_removeblocked.c sched: semaphore wait list optimize 2022-09-28 18:08:37 +08:00
sched_removereadytorun.c sched: fix task_delete crash in SMP case 2023-01-18 14:11:18 +09:00
sched_reprioritize.c sched/semaphore: fix priority boost restoration for priority inheritance 2022-10-03 15:14:24 -03:00
sched_reprioritizertr.c nuttx/sched: move reprioritize process to public function 2022-11-22 15:29:00 +09:00
sched_resumescheduler.c SMP: fix crash when switch to new task which is still running 2022-09-17 17:37:47 +09:00
sched_roundrobin.c nuttx: Use MIN/MAX definitions from "sys/param.h" 2023-02-01 23:47:44 +08:00
sched_rrgetinterval.c sched: Author Gregory Nutt: update licenses to Apache 2021-02-09 01:21:53 -08:00
sched_self.c Run nxstyle against all .c and .h files modified by this PR. 2020-05-09 14:19:08 -03:00
sched_setaffinity.c sched: sched: Remove sched_lock/unlock from nxsched_set_affinity() 2021-01-20 21:52:58 -08:00
sched_setparam.c sched: Author Gregory Nutt: update licenses to Apache 2021-02-09 01:21:53 -08:00
sched_setpriority.c sched: remove unnecessary type cast 2022-12-15 09:44:32 +08:00
sched_setscheduler.c sched/getpid: replace syscall getpid/tid/ppid() to kernel version 2023-02-02 10:33:01 +08:00
sched_sporadic.c nuttx: Use MIN/MAX definitions from "sys/param.h" 2023-02-01 23:47:44 +08:00
sched_suspend.c nuttx/sched: merge up_block_task and up_unblock_task 2022-11-22 22:59:08 +08:00
sched_suspendscheduler.c sched: Author Gregory Nutt: update licenses to Apache 2021-02-09 01:21:53 -08:00
sched_sysinfo.c nuttx/sched/sched: fix runtime error UBSan(division by zero) 2022-10-16 12:43:31 +08:00
sched_thistask.c arch, include, sched : Refactor ARCH_GLOBAL_IRQDISABLE related code 2020-09-03 10:20:20 +08:00
sched_timerexpiration.c nuttx: Use MIN/MAX definitions from "sys/param.h" 2023-02-01 23:47:44 +08:00
sched_unlock.c arch: remove up_release_pending function 2022-12-16 21:29:57 +08:00
sched_verifytcb.c Fix various typos 2022-07-08 02:15:54 +08:00
sched_wait.c sched: remove the unused function nx_wait and nx_waitid 2022-10-28 21:19:46 +02:00
sched_waitid.c sched: remove the unused function nx_wait and nx_waitid 2022-10-28 21:19:46 +02:00
sched_waitpid.c sched/waitpid: rename nx_waitpid() to nxsched_waitpid() 2023-02-01 20:40:41 +08:00
sched_yield.c sched: Author Gregory Nutt: update licenses to Apache 2021-02-09 01:21:53 -08:00
sched.h nuttx/sched: move reprioritize process to public function 2022-11-22 15:29:00 +09:00