09e7987121
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. |
||
---|---|---|
.. | ||
configs | ||
include | ||
scripts | ||
src | ||
Kconfig | ||
README.txt |
1. Download and install toolchain $ curl https://static.dev.sifive.com/dev-tools/riscv64-unknown-elf-gcc-8.3.0-2019.08.0-x86_64-linux-ubuntu14.tar.gz 2. Build and install qemu $ git clone https://github.com/qemu/qemu $ cd qemu $ ./configure --target-list=riscv32-softmmu,riscv64-softmmu $ make $ sudo make install 3.1. Configure and build NuttX for BUILD_FLAT $ mkdir ./nuttx; cd ./nuttx $ git clone https://github.com/apache/nuttx.git nuttx $ git clone https://github.com/apache/nuttx-apps.git apps $ cd nuttx $ make distclean $ ./tools/configure.sh rv-virt:nsh $ make V=1 -j7 3.2 Configure and build NuttX for BUILD_KERNEL $ mkdir ./nuttx; cd ./nuttx $ git clone https://github.com/apache/nuttx.git nuttx $ git clone https://github.com/apache/nuttx-apps.git apps $ cd nuttx $ make distclean $ ./tools/configure.sh rv-virt:knsh64 $ make V=1 -j7 $ make export V=1 $ cd ../apps $ ./tools/mkimport.sh -z -x ../nuttx/nuttx-export-*.tar.gz $ make import V=1 $ cd ../nuttx 4. Run the nuttx with qemu $ qemu-system-riscv32 -semihosting -M virt,aclint=on -cpu rv32 -smp 8 -bios none -kernel nuttx -nographic or $ qemu-system-riscv64 -semihosting -M virt,aclint=on -cpu rv64 -smp 8 -bios none -kernel nuttx -nographic NuttShell (NSH) NuttX-10.3.0-RC1 nsh> mount -t hostfs -o fs=. /host nsh> cat /host/AUTHORS This is a list of all the contributors that have submitted ICLA, SGA If you are not on this list and believe you should be, please inform us. ICLA ==== ... nsh> 4. Run the nuttx network with qemu $ qemu-system-riscv32 -semihosting -M virt,aclint=on -cpu rv32 -smp 8 \ -global virtio-mmio.force-legacy=false \ -netdev user,id=u1,hostfwd=tcp:127.0.0.1:10023-10.0.2.15:23,hostfwd=tcp:127.0.0.1:15001-10.0.2.15:5001 \ -device virtio-net-device,netdev=u1,bus=virtio-mmio-bus.0 \ -bios none -kernel nuttx -nographic or $ qemu-system-riscv64 -semihosting -M virt,aclint=on -cpu rv64 -smp 8 \ -global virtio-mmio.force-legacy=false \ -netdev user,id=u1,hostfwd=tcp:127.0.0.1:10023-10.0.2.15:23,hostfwd=tcp:127.0.0.1:15001-10.0.2.15:5001 \ -device virtio-net-device,netdev=u1,bus=virtio-mmio-bus.0 \ -bios none -kernel nuttx -nographic 5. TODO Support FPU Support RISC-V User mode