Repository navigation
fix(tty): register fasync after dropping the irqsave flags lock - #2722
Merged
fslongjin merged 3 commits intoNov 27, 2026
Merged
Conversation
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 #2721
背景
tty 的
fcntl(F_SETFL, O_ASYNC)在TtyCoreData::add_fasync()里持有flags.read_irqsave()时调fasync_items.add(),后者取Mutex<Vec<FAsyncItem>>。同一 tty 的另一次add/remove正持有这把互斥锁时,schedule()里的preempt_count() == 0断言失败,内核 panic。根因
flags读锁用来和tty_vhangup()设置HUPPING、递增hangup_generation的写锁配对,保证挂断之后不会再登记 fasync;但这个守卫一直活到fasync_items.add()之后,把睡眠锁包进了关中断的临界区。修复方案
在读锁内检查挂断状态后放锁,再
add();之后重新读一次hangup_generation,若已变化则撤回这次登记并返回ENOTTY。tty_vhangup()先递增 generation 再clear()登记表,两者都经过同一把互斥锁,因此复查仍是旧值时,挂断的clear()一定在这次add()之后,会把它清掉。验证
新增 dunitest 测例
normal/tty_fasync_concurrency(加入whitelist.txt):同一个 pty 从端打开 8 次,8 个线程各自对一个 fd 反复切换O_ASYNC,检查每次fcntl都成功。src/sched/mod.rs:1219,left: 1, right: 0)。normal/tty_pty_hangup、normal/fcntl_signal、normal/file_owner_notifications也通过。