You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "pussuw (via GitHub)" <gi...@apache.org> on 2023/10/04 15:22:09 UTC

[PR] CONFIG_BUILD_KERNEL: PANIC() if someone tries to kill the init process [nuttx]

pussuw opened a new pull request, #10857:
URL: https://github.com/apache/nuttx/pull/10857

   ## Summary
   As everything is inherited from the init process, there is no way it can be allowed to be killed.
   
   Mark the init process's group ID and PANIC() at once if someone tries to kill it / calls exit() from it.
   
   This is more of a debug feature, under normal conditions such a thing can never happen.
   ## Impact
   CONFIG_BUILD_KERNEL=y only
   ## Testing
   icicle + CONFIG_BUILD_KERNEL=y
   


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

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


Re: [PR] CONFIG_BUILD_KERNEL: PANIC() if someone tries to kill the init process [nuttx]

Posted by "pussuw (via GitHub)" <gi...@apache.org>.
pussuw closed pull request #10857: CONFIG_BUILD_KERNEL: PANIC() if someone tries to kill the init process
URL: https://github.com/apache/nuttx/pull/10857


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

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


Re: [PR] CONFIG_BUILD_KERNEL: PANIC() if someone tries to kill the init process [nuttx]

Posted by "pussuw (via GitHub)" <gi...@apache.org>.
pussuw commented on PR #10857:
URL: https://github.com/apache/nuttx/pull/10857#issuecomment-1747361547

   Btw, the crash occurs if another process is running, so some kind of bug exists in this case:
   
   ```
   ville@workpc:~/wpc_toolchain/workspace/nuttx-bare/nuttx$ qemu-system-riscv64 -semihosting -M virt,aclint=on -cpu rv64 -smp 8 -bios none -kernel nuttx -nographic
   ABC
   NuttShell (NSH) NuttX-10.4.0
   nsh> /system/bin/hello -t &
   /system/bin/hello [0:100]
   nsh> Hello world!
   exit
   [    5.843000] _assert: Current Version: NuttX  10.4.0 071fb18501-dirty Oct  4 2023 20:32:52 risc-v
   [    5.843000] _assert: Assertion failed : at file: common/riscv_doirq.c:79 task: /system/bin/init 0xc000004a
   [    5.843000] up_dump_register: EPC: 0000000080001e5a
   [    5.843000] up_dump_register: A0: 0000000080201730 A1: 000000000000004f A2: 0000000000000000 A3: 0000000000000000
   [    5.843000] up_dump_register: A4: 00000000802090c0 A5: 000000008020a540 A6: 0000000000000000 A7: 0000000000000003
   [    5.843000] up_dump_register: T0: 00000000802012f0 T1: 0000000000002000 T2: 0000000000002000 T3: 00000000c0202040
   [    5.843000] up_dump_register: T4: 00000000c0202038 T5: 00000000000000ff T6: 000000000000000f
   [    5.843000] up_dump_register: S0: 0000000000000000 S1: 0000000080202098 S2: 0000000080209900 S3: 0000000000000000
   [    5.843000] up_dump_register: S4: 0000000080017ff0 S5: 0000000000044100 S6: 0000000080202098 S7: 000000000000004f
   [    5.843000] up_dump_register: S8: 0000000000000000 S9: 0000000000000000 S10: 0000000000000000 S11: 0000000000000000
   [    5.843000] up_dump_register: SP: 0000000080201130 FP: 0000000000000000 TP: 0000000000000000 RA: 0000000080001e5a
   [    5.843000] dump_stack: IRQ Stack:
   [    5.843000] dump_stack:   base: 0x802002b0
   [    5.843000] dump_stack:   size: 00004096
   [    5.843000] dump_stack:     sp: 0x80201130
   [    5.843000] stack_dump: 0x80201120: 80201130 00000000 80001f72 00000000 deadbeef deadbeef deadbeef deadbeef
   [    5.843000] stack_dump: 0x80201140: deadbeef deadbeef deadbeef deadbeef 80209900 00000000 80201730 00000000
   [    5.843000] stack_dump: 0x80201160: 00000000 00000000 80017ff0 00000000 0000004f 00000000 7474754e 00000058
   [    5.843000] stack_dump: 0x80201180: 802098b8 00000000 8000301c 00000000 deadbeef deadbeef deadbeef ffffffff
   [    5.843000] stack_dump: 0x802011a0: deadbeef deadbeef 00000000 2e303100 00302e34 00000000 802020a0 00000000
   [    5.843000] stack_dump: 0x802011c0: 37304120 31626631 31303538 7269642d 4f207974 20207463 30322034 32203332
   [    5.843000] stack_dump: 0x802011e0: 32333a30 0032353a 80201328 00000000 0000006e 73697200 00762d63 00000000
   [    5.843000] stack_dump: 0x80201200: 80209da0 00000000 80003dbe 00000000 00000000 00000000 00000000 00000000
   [    5.843000] stack_dump: 0x80201220: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
   [    5.843000] stack_dump: 0x80201240: 00000000 00000000 80201328 00000000 0000006e 00000000 80202098 00000000
   [    5.843000] stack_dump: 0x80201260: 80200fe0 00000000 80007516 00000000 00000001 00000000 80000ca8 00000000
   [    5.843000] stack_dump: 0x80201280: 8020af90 00000000 00000000 00000000 00000005 00000000 800009c2 00000000
   [    5.843000] dump_stack: Kernel Stack:
   [    5.843000] dump_stack:   base: 0
   [    5.843000] dump_stack:   size: 00003072
   [    5.843000] dump_stack: User Stack:
   [    5.843000] dump_stack:   base: 0
   [    5.843000] dump_stack:   size: 00000000
   [    5.843000] dump_tasks:    PID GROUP PRI POLICY   TYPE    NPX STATE   EVENT      SIGMASK          STACKBASE  STACKSIZE      USED   FILLED    COMMAND
   [    5.843000] dump_tasks:   ----   --- --- -------- ------- --- ------- ---------- ---------------- 0x802002b0      4096      4088    99.8%!   irq
   [    5.843000] dump_task:       0     0   0 FIFO     Kthread N-- Ready              0000000000000000 0x80207010      3056      1760    57.5%    Idle_Task
   [    5.843000] dump_task:       1     1 100 RR       Kthread --- Running            0000000000000000 0x8020a050      1968       704    35.7%    lpwork 0x80201df0 0x80201e18
   [    5.843000] dump_task:       3     3 100 RR       Task    --- Waiting Semaphore  0000000000000000 0xc0202040      1984       392    19.7%    /system/bin/hello -t
   
   ```


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

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


Re: [PR] CONFIG_BUILD_KERNEL: PANIC() if someone tries to kill the init process [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #10857:
URL: https://github.com/apache/nuttx/pull/10857#discussion_r1346245539


##########
sched/task/task_exithook.c:
##########
@@ -465,7 +465,15 @@ void nxtask_exithook(FAR struct tcb_s *tcb, int status)
    * status (no zombies here!)
    */
 
-  group_leave(tcb);
+  if (group_leave(tcb) == 0)
+    {
+      /* Group is dead now, PANIC() if this is the init task */
+
+      if (nxsched_is_inittask(tcb))

Review Comment:
   > I was wondering about this use case but I'm not sure whether it works in kernel mode or not. At least in Linux the system panics at once if init is killed.
   
   Since nsh consume resource, it is good to exit after finishing the initialization for the memory. You can event launch it again with CONFIG_TTY_LAUNCH:
   https://github.com/apache/nuttx/blob/071fb18501a4198b21693bc089142039bb9dc1be/drivers/serial/serial.c#L1727-L1778



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

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


Re: [PR] CONFIG_BUILD_KERNEL: PANIC() if someone tries to kill the init process [nuttx]

Posted by "pussuw (via GitHub)" <gi...@apache.org>.
pussuw commented on PR #10857:
URL: https://github.com/apache/nuttx/pull/10857#issuecomment-1747366834

   > is it a kernel mode bug? we never see this in the flat mode.
   
   Yes I think so. It works fine in flat mode for me as well.


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

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


Re: [PR] CONFIG_BUILD_KERNEL: PANIC() if someone tries to kill the init process [nuttx]

Posted by "pussuw (via GitHub)" <gi...@apache.org>.
pussuw commented on code in PR #10857:
URL: https://github.com/apache/nuttx/pull/10857#discussion_r1346195434


##########
sched/task/task_exithook.c:
##########
@@ -465,7 +465,15 @@ void nxtask_exithook(FAR struct tcb_s *tcb, int status)
    * status (no zombies here!)
    */
 
-  group_leave(tcb);
+  if (group_leave(tcb) == 0)
+    {
+      /* Group is dead now, PANIC() if this is the init task */
+
+      if (nxsched_is_inittask(tcb))

Review Comment:
   ```
   ville@workpc:~/wpc_toolchain/workspace/nuttx-bare/nuttx$ qemu-system-riscv64 -semihosting -M virt,aclint=on -cpu rv64 -smp 8 -bios none -kernel nuttx -nographic
   ABC
   NuttShell (NSH) NuttX-10.4.0
   nsh> exit
   [    1.640000] riscv_exception: EXCEPTION: Load access fault. MCAUSE: 0000000000000005, EPC: 000000008000531a, MTVAL: 0000000000000008
   [    1.640000] riscv_exception: PANIC!!! Exception = 0000000000000005
   [    1.640000] _assert: Current Version: NuttX  10.4.0 3b71bad8c7 Oct  4 2023 19:56:45 risc-v
   [    1.640000] _assert: Assertion failed panic: at file: common/riscv_exception.c:85 task: /system/bin/init 0xc000004a
   [    1.640000] up_dump_register: EPC: 000000008000531a
   [    1.640000] up_dump_register: A0: 0000000080209650 A1: 0000000080209460 A2: 00000000802095c0 A3: 0000000000000000
   [    1.640000] up_dump_register: A4: 0000000000007fff A5: 0000000000000000 A6: 0000000080206c38 A7: fffffffffffffff8
   [    1.640000] up_dump_register: T0: 0000000080006c34 T1: 0000000000000007 T2: 00000000000001ff T3: 0000000080209838
   [    1.640000] up_dump_register: T4: 0000000080209830 T5: 0000000000000009 T6: 000000000000002a
   [    1.640000] up_dump_register: S0: 0000000080209650 S1: 0000000080209470 S2: 00000000802094a0 S3: 0000000000000000
   [    1.640000] up_dump_register: S4: 0000000000000000 S5: 0000000000000000 S6: ffffffffffffffff S7: 000000000000000b
   [    1.640000] up_dump_register: S8: 000000000000000a S9: 0000000000000000 S10: 0000000000000000 S11: 0000000000000000
   [    1.640000] up_dump_register: SP: 00000000802091f0 FP: 0000000080209650 TP: 0000000000000000 RA: 0000000080005130
   [    1.640000] dump_stack: Kernel Stack:
   [    1.640000] dump_stack:   base: 0x80208860
   [    1.640000] dump_stack:   size: 00003072
   [    1.640000] dump_stack:     sp: 0x802091f0
   [    1.640000] stack_dump: 0x802091e0: 80209650 00000000 800050c0 00000000 00000001 00000000 80209650 00000000
   [    1.640000] stack_dump: 0x80209200: 00000000 00000000 8000450a 00000000 c02002e8 00000000 c0200858 00000000
   [    1.640000] stack_dump: 0x80209220: 00000000 00000000 80006c40 00000000 c0202b40 00000000 800013a4 00000000
   [    1.640000] stack_dump: 0x80209240: c0000d16 00000000 8000019a 00000000 8000138c 00000000 c0000d16 00000000
   [    1.640000] stack_dump: 0x80209260: 80209250 00000000 00000000 00000000 00000000 00000000 800072da 00000000
   [    1.640000] stack_dump: 0x80209280: c00011a6 00000000 000001ff 00000000 00000000 00000000 c0200858 00000000
   [    1.640000] stack_dump: 0x802092a0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
   [    1.640000] stack_dump: 0x802092c0: 00007fff 00000000 00000001 00000000 c0200118 00000000 fffffff8 ffffffff
   [    1.640000] stack_dump: 0x802092e0: 00000001 00000000 00000000 00000000 00000000 00000000 00000000 00000000
   [    1.640000] stack_dump: 0x80209300: ffffffff ffffffff 0000000b 00000000 0000000a 00000000 00000000 00000000
   [    1.640000] stack_dump: 0x80209320: 00000000 00000000 00000000 00000000 802090e0 00000000 802090d8 00000000
   [    1.640000] stack_dump: 0x80209340: 00000009 00000000 0000002a 00000000 00042120 00000000 00000000 00000000
   [    1.640000] stack_dump: 0x80209360: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
   [    1.640000] stack_dump: 0x80209380: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
   [    1.640000] stack_dump: 0x802093a0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
   [    1.640000] stack_dump: 0x802093c0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
   [    1.640000] stack_dump: 0x802093e0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
   [    1.640000] stack_dump: 0x80209400: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
   [    1.640000] stack_dump: 0x80209420: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
   [    1.640000] stack_dump: 0x80209440: 00000000 00000000 800044c8 00000000 00000000 00000000 00000000 00000000
   [    1.640000] dump_tasks:    PID GROUP PRI POLICY   TYPE    NPX STATE   EVENT      SIGMASK          STACKBASE  STACKSIZE      USED   FILLED    COMMAND
   [    1.640000] dump_tasks:   ----   --- --- -------- ------- --- ------- ---------- ---------------- 0x802002b0      2048      2040    99.6%!   irq
   [    1.640000] dump_task:       0     0   0 FIFO     Kthread N-- Ready              0000000000000000 0x80206010      3056      1520    49.7%    Idle_Task
   [    1.640000] dump_task:       1     1 100 RR       Kthread --- Waiting Semaphore  0000000000000000 0x8020a050      1968       704    35.7%    lpwork 0x802015f0 0x80201618
   [    1.640000] dump_task:       2    -1 100 RR       Task    N-- Running            0000000000000000 0xc0202040      3008       768    25.5%    /system/bin/init
   
   ```
   
   Just tried it, and the system crashes at once. Perhaps there is some bug that needs to be fixed. IRQ stack usage seems a bit high but that can be due to the assert dump.



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

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


Re: [PR] CONFIG_BUILD_KERNEL: PANIC() if someone tries to kill the init process [nuttx]

Posted by "pussuw (via GitHub)" <gi...@apache.org>.
pussuw commented on code in PR #10857:
URL: https://github.com/apache/nuttx/pull/10857#discussion_r1346219402


##########
sched/task/task_exithook.c:
##########
@@ -465,7 +465,15 @@ void nxtask_exithook(FAR struct tcb_s *tcb, int status)
    * status (no zombies here!)
    */
 
-  group_leave(tcb);
+  if (group_leave(tcb) == 0)
+    {
+      /* Group is dead now, PANIC() if this is the init task */
+
+      if (nxsched_is_inittask(tcb))

Review Comment:
   Seems like calling exit() for nsh works just fine. There is a bug in my implementation here which causes the crash.
   
   Abandoning.



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

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


Re: [PR] CONFIG_BUILD_KERNEL: PANIC() if someone tries to kill the init process [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #10857:
URL: https://github.com/apache/nuttx/pull/10857#discussion_r1346147862


##########
sched/task/task_exithook.c:
##########
@@ -465,7 +465,15 @@ void nxtask_exithook(FAR struct tcb_s *tcb, int status)
    * status (no zombies here!)
    */
 
-  group_leave(tcb);
+  if (group_leave(tcb) == 0)
+    {
+      /* Group is dead now, PANIC() if this is the init task */
+
+      if (nxsched_is_inittask(tcb))

Review Comment:
   but what happen if init process exit? it may useful to exit init(nsh) process after it launch all needed service.



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

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


Re: [PR] CONFIG_BUILD_KERNEL: PANIC() if someone tries to kill the init process [nuttx]

Posted by "pussuw (via GitHub)" <gi...@apache.org>.
pussuw commented on code in PR #10857:
URL: https://github.com/apache/nuttx/pull/10857#discussion_r1346186050


##########
sched/task/task_exithook.c:
##########
@@ -465,7 +465,15 @@ void nxtask_exithook(FAR struct tcb_s *tcb, int status)
    * status (no zombies here!)
    */
 
-  group_leave(tcb);
+  if (group_leave(tcb) == 0)
+    {
+      /* Group is dead now, PANIC() if this is the init task */
+
+      if (nxsched_is_inittask(tcb))

Review Comment:
   I was wondering about this use case but I'm not sure whether it works in kernel mode or not.



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

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


Re: [PR] CONFIG_BUILD_KERNEL: PANIC() if someone tries to kill the init process [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on PR #10857:
URL: https://github.com/apache/nuttx/pull/10857#issuecomment-1747365481

   is it a kernel mode bug? we never see this in the flat mode.


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

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


Re: [PR] CONFIG_BUILD_KERNEL: PANIC() if someone tries to kill the init process [nuttx]

Posted by "pussuw (via GitHub)" <gi...@apache.org>.
pussuw commented on code in PR #10857:
URL: https://github.com/apache/nuttx/pull/10857#discussion_r1346186050


##########
sched/task/task_exithook.c:
##########
@@ -465,7 +465,15 @@ void nxtask_exithook(FAR struct tcb_s *tcb, int status)
    * status (no zombies here!)
    */
 
-  group_leave(tcb);
+  if (group_leave(tcb) == 0)
+    {
+      /* Group is dead now, PANIC() if this is the init task */
+
+      if (nxsched_is_inittask(tcb))

Review Comment:
   I was wondering about this use case but I'm not sure whether it works in kernel mode or not. At least in Linux the system panics at once if init is killed.



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

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