Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG REPORT] Deadlock and other reachable panic caused by lots of syscall fork #1079

Open
Marsman1996 opened this issue Dec 11, 2024 · 0 comments
Labels
bug-report 这是一个bug报告(如果确认是一个bug,请管理人员添加`bug` label) needs-triage 这个问题可能需要分类处理。如果已经完成分类,请移除它。

Comments

@Marsman1996
Copy link
Contributor

Marsman1996 commented Dec 11, 2024

描述错误/Describe the bug
There is a deadlock and several reachable panic when program calls syscall fork multiple times.

Deadlock at src/libs/rwlock.rs:260-262.

match self.try_write() {
Some(guard) => return guard,
None => spin_loop(),

Panic at src/mm/allocator/slab.rs:44

self.zone
.allocate(layout)
.expect("Should succeed after refill")
.as_ptr()

and src/namespaces/pid_namespace.rs:113

if tid == 0 {
nr = pid_ns
.id_alloctor
.write()
.alloc()
.expect("PID allocation failed.");

请填写您的电脑的信息/Environment

  • OS Version:Debian GNU/Linux 11
  • DragonOS Version:72423f9
  • DADK Version:dadk 0.2.0
  • Rust Version:rustc 1.84.0-nightly (fbab78289 2024-11-04)

重现步骤/To Reproduce

  1. Compile a program which calls system call fork multiple times
#include <unistd.h>

int main() {
  for (int i = 0; i < 1000; i++)
    fork();
}
  1. Run the compiled program

期望行为/Expected behavior
DragonOS should not panic or fall into deadlock.

屏幕截图/Log
Scree log:

root@DragonOS:/$ /bin/deadlock
[ ERROR ] (src/debug/panic/mod.rs:15)	 Kernel Panic Occurred.
Location:
	File: src/mm/allocator/slab.rs
	Line: 44, Column: 22
Message:
	Should succeed after refill: OutOfMemory
Rust Panic Backtrace:
Current PCB:
	ProcessControlBlock { pid: Pid(9), tgid: Pid(9), thread_pid: RwLock { lock: 0, data: UnsafeCell { .. } }, basic: RwLock { lock: 0, data: U}
/bin/deadlock: Process terminated
root@DragonOS:/$ [ ERROR ] (src/debug/panic/mod.rs:15)	 Kernel Panic Occurred.
Location:
	File: src/mm/allocator/slab.rs
	Line: 44, Column: 22
Message:
	Should succeed aft[ ERROR ] (src/debug/panic/mod.rs:15)	 Kernel Panic Occurred.
Location:
	File: src/mm/allocator/slab.rs
	Line: 4[ ERROR ] (src/debug/panic/mod.rs:15)	 Kernel Panic Occur[ ERROR ] (src/debug/panic/mod.rs:15)	 Kernel Panic Occurred.
Location:
	File: src/namespaces/pid_namespace.rs
	Line: 113, Column: 22
Message:
	PID allocation failed.
Rust Panic Backtrace:
Current PCB:
	ProcessControlBlock { pid: Pid(4724), tgid: Pid(4724), thread_pid: RwLock { lock: 0, data: UnsafeCell { .. } }, basic: RwLock { lock: 0, d}

The GDB log:

(gdb) bt
#0  core::sync::atomic::AtomicUsize::fetch_update<fn(usize) -> core::option::Option<usize>> (self=0xffff800018a62800, 
    set_order=core::sync::atomic::Ordering::Acquire, fetch_order=core::sync::atomic::Ordering::Relaxed, f=<optimized out>)
    at /root/.rustup/toolchains/nightly-2024-11-05-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/sync/atomic.rs:2908
#1  alloc::sync::Weak<dragonos_kernel::process::ProcessControlBlock, alloc::alloc::Global>::upgrade<dragonos_kernel::process::ProcessControlBlock, alloc::alloc::Global> (self=<optimized out>) at /root/.rustup/toolchains/nightly-2024-11-05-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/alloc/src/sync.rs:3001
#2  dragonos_kernel::process::ProcessControlBlock::arch_current_pcb () at src/arch/x86_64/process/mod.rs:286
#3  dragonos_kernel::process::ProcessManager::current_pcb () at src/process/mod.rs:166
#4  0x0000000200000000 in ?? ()
#5  0x0000000000000000 in ?? ()
(gdb) n
dragonos_kernel::process::ProcessManager::current_pcb () at src/process/mod.rs:167
167         }
(gdb) 
dragonos_kernel::libs::rwlock::RwLock<ida::IdAllocator>::try_write<ida::IdAllocator> (self=0xffff80001eb35910) at src/libs/rwlock.rs:211
211             let r = self.inner_try_write();
(gdb) 
213                 ProcessManager::preempt_enable();
(gdb) 
216             return r;
(gdb) 
dragonos_kernel::libs::rwlock::RwLock<ida::IdAllocator>::write<ida::IdAllocator> (self=0xffff80001eb35910) at src/libs/rwlock.rs:260
260                 match self.try_write() {
(gdb) 
262                     None => spin_loop(),
(gdb) 
260                 match self.try_write() {
(gdb) 
262                     None => spin_loop(),
(gdb) bt
#0  dragonos_kernel::libs::rwlock::RwLock<ida::IdAllocator>::write<ida::IdAllocator> (self=0xffff80001eb35910) at src/libs/rwlock.rs:262
#1  dragonos_kernel::namespaces::pid_namespace::PidStrcut::alloc_pid (ns=..., set_tid=...) at src/namespaces/pid_namespace.rs:111
#2  0x0000000000000000 in ?? ()
@Marsman1996 Marsman1996 added the bug-report 这是一个bug报告(如果确认是一个bug,请管理人员添加`bug` label) label Dec 11, 2024
@dragonosbot dragonosbot added the needs-triage 这个问题可能需要分类处理。如果已经完成分类,请移除它。 label Dec 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug-report 这是一个bug报告(如果确认是一个bug,请管理人员添加`bug` label) needs-triage 这个问题可能需要分类处理。如果已经完成分类,请移除它。
Projects
None yet
Development

No branches or pull requests

2 participants