Skip to content

fix(vfs): wait for pipe space before file-to-pipe splice read#1920

Merged
fslongjin merged 5 commits into
DragonOS-Community:masterfrom
fslongjin:fix/splice-file-to-pipe-wait-order
May 19, 2026
Merged

fix(vfs): wait for pipe space before file-to-pipe splice read#1920
fslongjin merged 5 commits into
DragonOS-Community:masterfrom
fslongjin:fix/splice-file-to-pipe-wait-order

Conversation

@fslongjin
Copy link
Copy Markdown
Member

Summary

  • align file-to-pipe splice with Linux ordering by waiting for output pipe space before reading from the input file
  • add a pipe helper that preserves PIPE_BUF atomic write semantics for blocking splice writes
  • avoid advancing/reading from the input file before an interruptible pipe wait can complete

Validation

  • make kernel
  • make fmt
  • TCG guest: ./splice_test --gtest_filter=*Concurrent* passed, SpliceTest.FromPipeWithConcurrentIo completed in ~1s
  • TCG guest: ./splice_test --gtest_filter=*SmallCapacity*:*Concurrent* passed
  • TCG guest: ./gvisor-test-runner splice_test passed, 27/27 tests, SpliceTest.FromPipeWithConcurrentIo completed in ~3.4s, full splice_test in ~4.8s

Signed-off-by: longjin <longjin@dragonos.org>
@github-actions github-actions Bot added Bug fix A bug is fixed in this pull request test Unitest/User space test labels May 18, 2026
Copy link
Copy Markdown
Member Author

更新:在原有 file->pipe splice 等待顺序修复之外,补了一层 RwSem 等待者公平性修复,避免 madvise(MADV_DONTNEED) 这类短写锁循环在释放后立即重抢 address_space 写锁,导致已经排队的 splice/read 路径长期拿不到读锁。

本轮验证:

  • make kernel 通过
  • make fmt 通过(包含 kernel clippy)
  • make -C user/apps/tests/dunitest build-suites 通过
  • Linux 本地执行 splice_concurrent_io_test --gtest_filter=SpliceConcurrentIo.FileToPipeNotStarvedByMadvise 通过
  • DragonOS guest 中执行 gVisor splice_test 通过:27/27 passed,原卡住的 SpliceTest.FromPipeWithConcurrentIo 未再超时
  • DragonOS guest 中新增 dunitest normal/splice_concurrent_io 通过

备注:全量 make test-dunit 当前仍失败在仓库已有无关 dunitest/内核问题(例如 fdatasync 未实现、pid_namespace_forkudp_ipv6_send_semantics panic 等),但本次新增的 splice 并发回归用例已在该轮中通过。

@fslongjin fslongjin force-pushed the fix/splice-file-to-pipe-wait-order branch from 64d0261 to 324fbab Compare May 19, 2026 04:08
Copy link
Copy Markdown
Member Author

已修复 CI 中 epoll_test 的 panic。

根因:上一版 RwSem 公平性修改让 read() 在“锁当前可读、但队列里已有 waiter”的情况下也可能主动睡眠一次。EpollTest.DoubleEpollOneShot 路径里 sched_getparam -> UserBuffer::write_one -> user_accessible_len -> vm.read() 可能处在 preempt_count == 1 的上下文,原语义要求锁可读时不能 schedule;主动睡眠触发了 sched::schedule()preempt_count == 0 断言。

修正:

  • RwSem::read() / read_interruptible() 恢复为先 try_read(),只有真的被 writer/upgrader 阻塞时才进入等待队列。
  • RwSem::write() / write_interruptible() 仍在普通可睡眠上下文中避免插队已排队 waiter,以保留对 madvise 短写锁循环饿死 splice 读侧的修复;如果当前 preempt_count != 0,则不因 waiter 存在而主动睡眠。

本轮验证:

  • make kernel 通过
  • make fmt 通过(包含 kernel clippy)
  • 重新写入带 gVisor syscall tests 的镜像后,在 DragonOS guest 中执行:
    • epoll_test 通过:21 个测试,20 passed / 1 skipped,没有再 panic
    • splice_test 通过:27/27 passed,SpliceTest.FromPipeWithConcurrentIo 未超时

@fslongjin
Copy link
Copy Markdown
Member Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 324fbab12d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread kernel/src/filesystem/vfs/syscall/sys_splice.rs Outdated
Signed-off-by: longjin <longjin@dragonos.org>
@fslongjin fslongjin force-pushed the fix/splice-file-to-pipe-wait-order branch from 324fbab to 3734615 Compare May 19, 2026 05:51
@fslongjin
Copy link
Copy Markdown
Member Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3734615667

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread kernel/src/filesystem/vfs/syscall/sys_splice.rs Outdated
Signed-off-by: longjin <longjin@dragonos.org>
@fslongjin
Copy link
Copy Markdown
Member Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a15b34d476

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread kernel/src/filesystem/vfs/syscall/sys_splice.rs Outdated
Signed-off-by: longjin <longjin@dragonos.org>
@fslongjin
Copy link
Copy Markdown
Member Author

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: dee3c57d27

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread kernel/src/filesystem/vfs/syscall/sys_splice.rs Outdated
Signed-off-by: longjin <longjin@dragonos.org>
@fslongjin fslongjin merged commit 2562b9f into DragonOS-Community:master May 19, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug fix A bug is fixed in this pull request test Unitest/User space test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant