nuttx/boards/arm
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
..
a1x/pcduino-a10 Remove OK macro from the code base 2023-02-02 13:58:16 +01:00
am335x/beaglebone-black Remove OK macro from the code base 2023-02-02 13:58:16 +01:00
c5471/c5471evm boards: Remove CONFIG_NETDEVICES=y from board defconfig 2022-10-01 19:12:15 +02:00
cxd56xx Remove OK macro from the code base 2023-02-02 13:58:16 +01:00
dm320/ntosd-dm320 Remove OK macro from the code base 2023-02-02 13:58:16 +01:00
efm32 arch/arm/toolchain: migrate the toolchain define to arch/arm/Kconfig 2022-09-16 14:47:27 +08:00
eoss3/quickfeather boards/arm: remove -funwind-tables from boards Make.defs 2022-11-05 20:36:35 +08:00
gd32f4/gd32f450zk-eval Add i2c driver for gd32f450 MCU 2022-12-17 17:12:26 +08:00
imx6/sabre-6quad sched/addrenv: Fix system crash when process group has been deleted 2023-02-08 02:51:23 +08:00
imxrt nuttx: Use MIN/MAX definitions from "sys/param.h" 2023-02-01 23:47:44 +08:00
kinetis Remove OK macro from the code base 2023-02-02 13:58:16 +01:00
kl Remove the unnecessary NULL fields in global instance definition of file_operations 2023-01-04 00:32:13 +02:00
lc823450/lc823450-xgevk boards/iperf: device name will vary across different NICs 2022-11-20 19:44:32 +08:00
lpc17xx_40xx Remove OK macro from the code base 2023-02-02 13:58:16 +01:00
lpc31xx boards: Update all boards config after updating NSH_CMDPARMS 2023-01-23 03:04:51 +08:00
lpc43xx Remove the unnecessary cast for main_t, NULL and argv 2022-10-18 08:51:45 +02:00
lpc54xx/lpcxpresso-lpc54628 boards: adapt LVGL v8 defconfig 2023-01-01 10:15:08 -03:00
lpc214x Replace nxsem API when used as a lock with nxmutex API 2022-10-17 15:59:46 +09:00
lpc2378/olimex-lpc2378 boards/arm: Remove "LDFLAGS += -g" whichi is already added by Toolchain.defs 2022-05-16 11:17:08 +03:00
max326xx/max32660-evsys Move warning option from Make.defs to Toolchain.defs 2022-05-15 15:40:35 +03:00
moxart/moxa boards: Fix the CI build errors for telnetd 2022-11-07 16:06:00 +01:00
nrf52 Remove the unnecessary "return;" at the end of function 2022-11-27 22:23:50 +01:00
nrf53/nrf5340-audio-dk boards: initial support for nrf5340-audio-dk - NSH boots on the app core 2022-09-18 21:49:32 +08:00
nuc1xx/nutiny-nuc120 sched/spawn: Rename task_spawnattr_[get|set]stack[size|addr] to posix_spawnattr_[get|set]stack[size|addr] 2022-11-01 09:51:18 +09:00
phy62xx/phy6222 nuttx/sched: merge up_block_task and up_unblock_task 2022-11-22 22:59:08 +08:00
rp2040 rp2040/raspberrypi-pico-w: update submodule to avoid invaild firmware 2023-02-07 04:40:38 +08:00
s32k1xx Remove OK macro from the code base 2023-02-02 13:58:16 +01:00
s32k3xx boards: Update all boards config after updating NSH_CMDPARMS 2023-01-23 03:04:51 +08:00
sam34 Remove OK macro from the code base 2023-02-02 13:58:16 +01:00
sama5 sched/addrenv: Fix system crash when process group has been deleted 2023-02-08 02:51:23 +08:00
samd2l2 sched/spawn: Rename task_spawnattr_[get|set]stack[size|addr] to posix_spawnattr_[get|set]stack[size|addr] 2022-11-01 09:51:18 +09:00
samd5e5 Remove OK macro from the code base 2023-02-02 13:58:16 +01:00
samv7 arch/arm/samv7: add ARCH_RAMVECTORS support 2022-12-17 13:57:03 +08:00
stm32 boards/stm32f4disco: add timer driver support 2023-02-08 02:43:13 +08:00
stm32f0l0g0 Remove OK macro from the code base 2023-02-02 13:58:16 +01:00
stm32f7 Add initial support to Meadow F7Micro board 2023-01-26 18:05:21 +08:00
stm32h7 Remove OK macro from the code base 2023-02-02 13:58:16 +01:00
stm32l4 boards: Update all boards config after updating NSH_CMDPARMS 2023-01-23 03:04:51 +08:00
stm32l5 boards: Update all boards config after updating NSH_CMDPARMS 2023-01-23 03:04:51 +08:00
stm32u5 b-u585i-iot02a: Don't need to disable CONFIG_ARCH_LEDS 2023-01-23 03:04:51 +08:00
stm32wb boards/stm32wb/flipperzero: adding LCD support 2022-10-31 09:40:13 +08:00
stm32wl5/nucleo-wl55jc nucleo-wl55jc: remove duplicated peripheral placed manually 2023-01-23 03:04:51 +08:00
str71x/olimex-strp711 Replace nxsem API when used as a lock with nxmutex API 2022-10-17 15:59:46 +09:00
tiva Added SocketCAN driver implementation to the tiva chip, modified the EK-TC1294XL launchpad board to use the new SocketCAN API 2023-01-31 14:07:23 +08:00
tlsr82/tlsr8278adk80d tlsr82/backtrace: tc32 backtrace bug fix 2023-02-04 18:25:58 -03:00
tms570 armv7-r/tms570: fix build break 2022-09-22 02:22:18 +08:00
xmc4 arch/arm/toolchain: migrate the toolchain define to arch/arm/Kconfig 2022-09-16 14:47:27 +08:00