feat(vfs): implement close_range syscall - #2200
Conversation
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4ceb912b9a
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5d92b33dc0
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5d92b33dc0
ℹ️ 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".
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6c261a6c53
ℹ️ 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".
| (Some(highest), Some((first, last))) | ||
| if highest >= first as usize && highest <= last as usize => |
There was a problem hiding this comment.
当 CLOSE_RANGE_UNSHARE 使用有限区间且 last 之上仍有打开的 fd 时,此条件退回到 highest,使 populate_clone() 仍复制 [first, last] 中的文件,随后又逐个执行 finish_close()。新的证据是该分支仅在最高 fd 落入区间时才应用穿孔,而 Linux 6.6 会将有限范围同样作为 dup_fd() 的 punch range,在保留高位 fd 的同时跳过区间内引用;当前实现因此会产生 Linux 不会触发的 FUSE FLUSH 等可观察回调和额外复制开销。应让填充阶段直接跳过整个 punch range,而不是只通过截断尾部 copy_len 实现穿孔。
AGENTS.md reference: AGENTS.md:L9-L9
Useful? React with 👍 / 👎.
| if flags.contains(CloseRangeFlags::CLOEXEC) { | ||
| set_cloexec_in_table(&new_table, first, last); | ||
| } else { | ||
| close_range_in_table(&new_table, first, last); |
There was a problem hiding this comment.
当调用方与其他任务通过 CLONE_FILES 共享 fd 表,且普通 CLOSE_RANGE_UNSHARE 在关闭回调或 sched_yield() 中让出 CPU 时,这里会在新表尚未安装到当前 PCB 的情况下扫描并关闭它;共享任务可在此期间修改仍挂在当前 PCB 上的旧表,而最终替换会让这些范围外更新突然从当前任务视图消失,procfs 观察者也会在操作期间看到错误的表身份。Linux 6.6 在复制后先切换 current->files,再对新表执行范围操作;这里也应先安装新表并释放 PCB 锁,再运行可能阻塞的关闭流程。
AGENTS.md reference: AGENTS.md:L9-L9
Useful? React with 👍 / 👎.
Add Linux-compatible close_range(2) handling for close, CLOEXEC, and UNSHARE operations with the expected u32 ABI and validation order. Introduce a fallible two-phase fd-table clone so allocation failures cannot mutate the shared table or trigger close side effects. Scan close ranges with bounded work, perform file finalization outside fd-table locks, preserve reserved descriptors, and retain the correct POSIX lock owner semantics. Add deterministic no-skip coverage for range validation, raw argument truncation, shared and private tables, sparse descriptors, lowered RLIMIT_NOFILE, next-fd reuse, and record-lock ownership. Validated with x86_64 kernel format/check/clippy/build, a RISC-V kernel check, host Linux tests, and DragonOS guest tests. Signed-off-by: longjin <longjin@dragonos.org>
Separate the cloned fd-table layout size from the installed File population bound. Tail punch-hole clones now stop copying at the last descriptor that must be retained instead of cloning up to the minimum 1024-slot layout and then closing those files. This avoids redundant Arc clones, range scans, and observable flush_for_close callbacks while preserving the minimum table capacity, reserved-fd behavior, next_fd recomputation, and ordinary clone semantics. Add a focused clone-plan regression test for a 64-fd retained prefix in a 1024-slot layout. Validated with kernel format, check, clippy, make kernel, host close_range tests, and three independent adversarial reviews. Signed-off-by: longjin <longjin@dragonos.org>
Separate files-table lifetime references from PCB attachment ownership so procfs, BPF, and in-flight syscall observers cannot be mistaken for CLONE_FILES users. Introduce a lightweight FileDescriptorTable identity with an atomic task-user count and an RAII FdTableAttachment for PCB slots. Route private replacement, CLONE_FILES sharing, exec, close_range, fork cleanup, and exit through the attachment lifecycle while keeping final table destruction outside basic and fd-table locks. Use coherent table-and-sharing snapshots for exec and close_range, preserve the fallible close_range clone transaction, and add a focused ownership regression test proving observer Arcs do not affect sharing decisions. Signed-off-by: longjin <longjin@dragonos.org>
Track task attachments independently from transient Arc observers so close_range and exec only unshare genuinely shared descriptor tables. Keep table lifetime ownership separate from task-sharing identity and preserve POSIX lock ownership for private tables. Reuse the fallible descriptor-table clone path across close_range, fork, and exec. Preserve the allocation-before-population transaction boundary, use conditional rescheduling during range scans, and keep old table teardown outside process and fdtable locks. Harden exec after the point of no return by preparing fallible signal state early and terminating through the normal fatal-exec path when later image installation fails. Add close_range ownership and exec isolation regression coverage. Signed-off-by: longjin <longjin@dragonos.org>
6c261a6 to
8db4f2d
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Retire replaced sighand references outside task_lock through a fallible RCU callback admission path so shared-sighand exec no longer waits for a global grace period during normal operation. Reserve both pending and ready callback capacity before publication to keep grace-period advancement allocation-free. Preserve the removed Arc on allocation failure and use a no-allocation yielding grace-period fallback instead of turning post-PONR memory pressure into a kernel panic. Add RCU selftests for fallible deferred drop and no-allocation grace-period progress, plus deterministic successful and post-PONR shared-sighand exec isolation coverage. Validated with kernel build, formatting, nightly clippy, DragonOS guest exec ABI tests, and multi-agent adversarial review. Signed-off-by: longjin <longjin@dragonos.org>
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
Summary
close_range(2)support for close,CLOSE_RANGE_CLOEXEC, andCLOSE_RANGE_UNSHAREMotivation
DragonOS already exposed syscall number 436 on each architecture but had no VFS handler. Applications using
close_range(2)therefore receivedENOSYS, and the existing fd-table clone path did not provide the fallible transaction boundary required byCLOSE_RANGE_UNSHARE.This implementation follows Linux 6.6 semantics without introducing a new VFS trait, global lock, bitmap subsystem, or userspace-style close loop.
Implementation
FD_CLOEXEC, omit in-progress reservations, allocate a new POSIX lock owner, and recomputenext_fdValidation