Commit Graph

2184 Commits

Author SHA1 Message Date
ligd
0a88799bab sched: fix task_delete crash in SMP case
A testcase as following:

child_task()
{
  sleep(3);
}

main_task()
{
  while (1)
    {
      ret = task_create("child_task", child_task, );
      sleep(1);

      task_delete(ret);
    }
}

Root casuse:
task_delete hasn's cover the condition that the deleted-task
is justing running on the other CPU.

Fix:
Let the nxsched_remove_readytorun() do the real work

Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-01-18 14:11:18 +09:00
zhangyuan21
acd108a5ed pthread: fixed pthread_cancel and pthread_exit crash in SMP mode
1. When pthread exit, set the default cancellability state to NONCANCELABLE state.
2. Make sure modify tcb->flags is atomic operations.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-01-18 11:57:40 +08:00
zhangyuan21
9fd30c7f63 sched/pthread: check pthread group and flags before join
Prevent users from using the wrong pid and causing system crash.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-01-18 11:57:40 +08:00
Ville Juven
6a026382f0 group_leave: Don't instantiate address environment prior to destroying it
This is just unnecessary, a process cannot be destroyed by another
process in any case, every time this is executed the active address
environment is the process getting destroyed.

Even in the hypothetical case this was possible, the system would
crash at once if a context switch happens between "select()" and
"restore()", which is possible as the granule allocator is protected by
a semaphore (which is a synchronization point).
2023-01-18 11:02:19 +08:00
ligd
c0aaaa94e1 assert: used %p to logout the pointer
Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-01-17 09:46:40 -03:00
ligd
19f87e88b9 assert: fix build break.
misc/assert.c: In function 'show_tasks':
Error: misc/assert.c:411:10: error: format '%p' expects argument of type 'void *', but argument 3 has type 'uintptr_t' {aka 'long unsigned int'} [-Werror=format=]
  411 |   _alert("  ----   ---"
      |          ^~~~~~~~~~~~~~
......
  424 |          , up_get_intstackbase()
      |            ~~~~~~~~~~~~~~~~~~~~~
      |            |
      |            uintptr_t {aka long unsigned int}

Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-01-17 09:46:40 -03:00
ligd
c821088734 pthread: fix pthread exit error when set DETACHED
Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-01-17 11:09:36 +08:00
ligd
940de60892 assert: add stackbase dump
Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-01-17 11:04:12 +08:00
ligd
4de9317373 assert: add uname info to assert message
Signed-off-by: ligd <liguiding1@xiaomi.com>
2023-01-17 11:04:12 +08:00
Gustavo Henrique Nihei
a3e253b4a3 mm: Enable a dedicated kernel heap on BUILD_FLAT via MM_KERNEL_HEAP
Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2023-01-17 10:30:00 +08:00
zhangyuan21
63039b80e1 sched/wqueue: do work_cancel when worker is not null
Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2023-01-16 13:37:00 +08:00
Jukka Laitinen
a2a10c87e3 mm/shm: Switch to use process' common virtual memory region allocator
- Also remove the nuttx private shm.h file nuttx/mm/shm.h, which became redundant
- Also remove the gran allocator initialization/release in binfmt since common
  vpage allocator is initialized in group_create/group_leave

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2023-01-13 02:20:13 +08:00
Jukka Laitinen
2236facca9 mm/map: Add a common virtual memory region allocator
Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2023-01-13 02:20:13 +08:00
Xiang Xiao
ef65d443ad sem: Remove PRIOINHERIT_FLAGS_ENABLE and use SEM_PRIO_INHERIT instead
and refine the code to prepare the support of new flags

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-01-11 17:35:28 +02:00
chao an
fdc3c44cc4 sched/group: fix task info heap-use-after-free
tg_info is still in use after task_uninit_info(), unifies
lib_stream_* with life cycle of task info to avoid this issue.

| ==1940861==ERROR: AddressSanitizer: heap-use-after-free on address 0xf47032e0 at pc 0x5676dc4f bp 0xf2f38c68 sp 0xf2f38c58
|
|#10 0xf7abec89 in __asan::__asan_report_load2 (addr=4100993760) at ../../../../src/libsanitizer/asan/asan_rtl.cpp:119
|#11 0x5677356a in nxsem_destroy (sem=0xf47032e0) at semaphore/sem_destroy.c:73
|#12 0x56773695 in sem_destroy (sem=0xf47032e0) at semaphore/sem_destroy.c:120
|#13 0x5676faa2 in nxmutex_destroy (mutex=0xf47032e0) at include/nuttx/mutex.h:126
|#14 0x567a3430 in lib_stream_release (group=0xf4901ba0) at stdio/lib_libstream.c:98
|#15 0x5676da75 in group_release (group=0xf4901ba0) at group/group_leave.c:162
|#16 0x5676e51c in group_leave (tcb=0xf5377740) at group/group_leave.c:360
|#17 0x569fe79b in nxtask_exithook (tcb=0xf5377740, status=0) at task/task_exithook.c:455
|#18 0x569f90b9 in _exit (status=0) at task/exit.c:82
|#19 0x56742680 in exit (status=0) at stdlib/lib_exit.c:61
|#20 0x56a69c78 in iperf_showusage (progname=0xf2f28838 "iperf", exitcode=0) at iperf_main.c:91
|#21 0x56a6a6ec in iperf_main (argc=1, argv=0xf2f28830) at iperf_main.c:140
|#22 0x5679c148 in nxtask_startup (entrypt=0x56a69c78 <iperf_main>, argc=1, argv=0xf2f28830) at sched/task_startup.c:70
|#23 0x56767f58 in nxtask_start () at task/task_start.c:134

Signed-off-by: chao an <anchao@xiaomi.com>
2023-01-11 01:53:59 +08:00
Jukka Laitinen
7f8bec7070 Add mm/mm_map virtual memory mapping list
The task_group specific list can be used to store information about
mmappings.

For a driver or filesystem performing mmap can also enable munmap by
adding an item to this list using mm_map_add(). The item is then
returned in the corresponding munmap call.

Signed-off-by: Jukka Laitinen <jukkax@ssrc.tii.ae>
2023-01-10 18:34:25 +08:00
anjiahao
9a32cf7a1a assert:add a last type to call notifier
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
2023-01-05 22:58:00 +08:00
Xiang Xiao
98ab55ef68 drivers/note: Replace the scritical section with spin_xxx_wo_note
to avoid to generate the unexpected schedule information

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-01-04 00:21:18 +02:00
yinshengkai
81448b5021 sched/irq: add spin_unlock_irqsave/irqrestore_wo_note
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2023-01-02 22:29:01 +08:00
yinshengkai
ca5fcc58c2 sched: move SCHED_INSTRUMENTATION_xxx to note Kconfig
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2022-12-30 15:50:30 -03:00
田昕
96a45e2c75 sched/misc:add linux-like reboot notifier list
Signed-off-by: 田昕 <tianxin7@xiaomi.com>
2022-12-29 19:18:42 +08:00
Xiang Xiao
d5f729ed25 sched/assert: Dump the global state only when it's a fatal error
and merge assert_end into _assert

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-12-29 11:50:31 +09:00
Xiang Xiao
d1497a8d08 sched/assert: Don't call up_check_tcbstack for the kernel stack
since up_check_tcbstack only check the userspace stack color

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-12-29 11:50:31 +09:00
Xiang Xiao
5f99e482b5 sched/assert: Don't call running_task more than once
and fix some minor style issue

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-12-29 11:50:31 +09:00
Masayuki Ishikawa
6992a8f4cc sched: group: Fix memory corruption in group_leave.c
Summary:
- I noticed that nxplayer (HTTP audio streaming) + command execution
  via telnet sometimes causes memory corruption.
  See https://github.com/apache/nuttx/pull/7947 for the detail.
- This commit fixes this issue by calling lib_stream_release() before
  lib_stream_release() in group_leave.c

Impact:
- Should be none

Testing:
- Tested with spresense:wifi_smp

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2022-12-29 10:33:47 +08:00
Xiang Xiao
2e59d832fc sched/misc: Rename panic.c to panic_notifier.c
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-12-28 21:42:38 +02:00
dongjiuzhu1
9244b5a737 signal: Support sigaction:sa_user, siginfo_t:si_user with user info
When the signal sent by the sender is blocked in the target task,
if the target task has an action registered with sa_flags SA_KENELHAND,
it will directly respond to the action in the context of the sender.
When the action is executed, it will have the parameters set by the
target task with sigaction:sa_user.

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2022-12-28 23:05:58 +08:00
dongjiuzhu1
3927d878e4 signal/nxsig_pengingset: move nxsig_pendingset to common header
Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
2022-12-28 23:05:58 +08:00
zhangyuan21
45394eb6dc arch: save user context in assert common code
This is the work continue with #7875

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2022-12-24 13:02:56 +08:00
Ville Juven
172b209f2d sched/assert: Re-implement assert() into user space
_assert is a kernel procedure, entered via system call to make the core
dump in privileged mode.

Running exit() from this context is not OK as it runs the registered
exit functions and flushes streams, which must not be done
from privileged mode as it is a security hole.

Thus, implement assert() into user space (again) and remove the exit()
call from the kernel procedure.
2022-12-22 21:07:47 +08:00
Ville Juven
b0b352f784 sched/assert: Fix printing argv when address environments are in use
Instantiate the correct address environment when reading the process's
argument vector. Otherwise doing this will crash the system every time,
causing a recursive assert loop.

Also try to do a bit of sanity checking before attempting to read the
process's memory, it might be in a bad state in which case this will
fail anyway.
2022-12-22 20:35:57 +08:00
Ville Juven
3be81e649f libc/stdio: Flush streams in userspace when process exits
This fixes a long standing issue, where the kernel does flushing of file
streams, although it should not handle such streams at all.
2022-12-22 20:16:11 +08:00
Ville Juven
2ed51d026c fs/streams: Move the file streams from the group structure into TLS
This is preparation for flushing streams from user space, like it should
be done.

- Move tg_streamlist (group, kernel space) ->
       ta_streamlist (TLS, user space)
- Access stream list via tg_info in kernel
- Access stream list via TLS in user space
- Remove / rename nxsched_get_streams -> lib_getstreams
- Remove system call for nxsched_get_streams
2022-12-22 20:16:11 +08:00
yinshengkai
1a8cbc0b99 sched/assert: modify assert message
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2022-12-22 20:08:27 +08:00
Petro Karashchenko
b107e4f417 nuttx: unify MIN, MAX and ABS macro definition across the code
Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2022-12-21 09:31:28 +08:00
Xiang Xiao
fd0d6a9bf5 compiler.h: Add _ between format|printf|syslog|scanf|strftime and like
align with other macro naming style

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-12-21 01:05:19 +02:00
zhangyuan21
8b5078fc36 sched/semaphore: check sem flags before enable priority inheritance
Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2022-12-20 11:50:42 +08:00
zhangyuan21
0113865bb0 sched/pthread: Delay pjoininfo allocation time
Create pjoininfo until pthread_exit/pthread_canel/pthread_join get called.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2022-12-20 10:26:02 +08:00
zhangyuan21
3462061624 task: show thread main entry when display thread name
Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2022-12-17 14:53:59 +08:00
zhangyuan21
3d2ffed8ae Revert "pthread: Change the default name from <pthread> to <0xyyyyyyyy>"
This reverts commit 092d23b25d.

Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2022-12-17 14:53:59 +08:00
zhangyuan21
37789e75aa task_setup: set sigprocmask directly to improve performance
signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2022-12-17 13:52:15 +08:00
zhangyuan21
453a1a7332 arch: move stack and task dump to common code
Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2022-12-17 01:59:35 +08:00
zhangyuan21
632d87ee71 arch: remove up_release_pending function
Signed-off-by: zhangyuan21 <zhangyuan21@xiaomi.com>
2022-12-16 21:29:57 +08:00
yinshengkai
552cf4b549 merge sched_note_spinxx into sched_note_spincommon
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2022-12-16 17:03:53 +08:00
Ville Juven
920956b20f sched/sched_releasetcb: Fix code style issue from prior patch 2022-12-15 20:28:52 +08:00
Petro Karashchenko
5b4e12774c sched: remove unnecessary type cast
fix code style issues

Signed-off-by: Petro Karashchenko <petro.karashchenko@gmail.com>
2022-12-15 09:44:32 +08:00
Ville Juven
1a67dc7c68 sched/release_tcb: Do not release stack for user processes here
The user stack is dependent on the user address environment. As the
process exits, this address environment is destroyed anyway, so the
stack does not need to be released separately.

There is also an issue with this when the process exits via exit(). The
problem is that the task group is released prior to this "up_release_stack()"
call along with the address environment, and trying to free the memory
either causes an immediate crash (no valid addrenv), or frees memory into
another process' heap (addrenv from a different process).

Signed-off-by: Ville Juven <ville.juven@unikie.com>
2022-12-14 17:54:28 +08:00
田昕
0382b63f5d move common assert logic together.
Signed-off-by: 田昕 <tianxin7@xiaomi.com>
2022-12-12 17:05:02 +08:00
yinshengkai
09814831b8 sched: move sched_note.c to drivers/note
Signed-off-by: yinshengkai <yinshengkai@xiaomi.com>
2022-12-09 23:36:11 +08:00
Ville Juven
864bcf556e sched/nx_bringup: Set the initial stack size in kernel build as well
After #7364 this now works, so use it for the init process. It makes sense
as the init process typically requires a big stack (due to init scripts).
2022-12-09 22:15:48 +08:00