Repository navigation
fix(ipc): make the SysV SHM manager lock a mutex - #2720
Merged
fslongjin merged 3 commits intoNov 27, 2026
Merged
Conversation
AsakuraMizu
force-pushed
the
fix/shm-lock-tmpfs-inode
branch
from
November 25, 2026 13:53
50cc955 to
0fd0482
Compare
Signed-off-by: longjin <longjin@dragonos.org>
Signed-off-by: longjin <longjin@dragonos.org>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2719
背景
shmctl在持有 IPC 命名空间的shm(SpinLock<ShmManager>)时会取睡眠锁:SHM_LOCK/SHM_UNLOCK经set_locked()取 tmpfs inode 的Mutex,SHM_INFO经resident_pages()取 inode 和 page cache 的Mutex,SHM_UNLOCK释放 memlock 计费时取SYSV_SHM_MEMLOCK_ACCOUNT。这些锁被别的任务持有时,schedule()里的preempt_count() == 0断言失败,内核 panic。根因
ipcns.shm是自旋锁,而ShmManager在锁内调用的 backing 和 memlock 计费代码会睡眠。修复方案
把
ipcns.shm改为Mutex。这把锁只在shmget、shmat、shmctl和 VMA 的 open/close 里取,这些地方都可以睡眠;close_vma()销毁段时本来就会取睡眠锁。Linux 中对应的shm_ids(ns).rwsem也是睡眠锁。验证
新增 dunitest 测例
normal/sysv_shm_lock_fault(加入whitelist.txt):三个线程反复写入一个 64 KiB 段的映射并MADV_DONTNEED,主线程分别反复做SHM_LOCK/SHM_UNLOCK和SHM_INFO,检查返回值。src/sched/mod.rs:1219,left: 1, right: 0)。SHM_LOCK/SHM_UNLOCK手动验证过,修复前 panic,修复后正常。现有normal/sysv_shm_semantics、normal/internal_shmem通过。