feat(ipc/sem): add semaphore support for dragonOS - #2172
feat(ipc/sem): add semaphore support for dragonOS#2172mistcoversmyeyes wants to merge 34 commits into
Conversation
e0bc761 to
a266b20
Compare
d9c382f to
fbdee92
Compare
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fbdee927ce
ℹ️ 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".
fslongjin
left a comment
There was a problem hiding this comment.
Request changes: this PR establishes a useful base for System V semaphore support, but it does not yet satisfy the Linux 6.6 compatibility and concurrency-safety contract stated in #2142.
The blocking issues are:
- IPC_SET permission updates can partially commit on an error, changing the owner even though the syscall returns EINVAL; the shared helper also affects SHM.
- SEM_UNDO is rejected with ENOSYS and the new test codifies that incompatibility, while Linux maintains per-process/shared undo state and replays it at process exit.
- A single namespace-wide spinlock protects the registry and every semaphore set, so unrelated sets are serialized; the lock also covers allocation-heavy queue simulation and scheduler wakeups.
- User-controlled semaphore-set allocation is infallible and can reach the kernel panic allocation handler instead of returning ENOMEM.
- SEM_STAT and SEM_STAT_ANY mask their direct table index, causing out-of-range indices to alias valid objects.
The basic syscall wiring, atomic multi-operation simulation, timeout/removal paths, and test breadth are valuable. However, the issues above are architectural or user-visible Linux semantic mismatches rather than optional refinements. Please address them, add the corresponding regression tests, and rerun the guest suite. The current Integration Test check also reports 5666 passed, 1 failed, and 180 skipped; I am not attributing that failure to this PR without further evidence, but the PR description should not claim that Integration Test passed while the check remains red.
| .iter() | ||
| .any(|op| (op.sem_flg as u32) & SemFlags::SEM_UNDO.bits() != 0) | ||
| { | ||
| return Err(SystemError::ENOSYS); |
There was a problem hiding this comment.
[P1] Rejecting every SEM_UNDO operation with ENOSYS is not Linux-compatible System V semaphore behavior. Linux 6.6 maintains sem_undo/semadj state, shares the undo list for CLONE_SYSVSEM, clears adjustments on SETVAL/SETALL/IPC_RMID, and replays them from exit_sem() when a task exits. This is essential crash-recovery behavior: without it, a lock holder exiting can leave peers blocked indefinitely. Please implement the full lifecycle before treating #2142 as complete; the new test should verify Linux behavior instead of expecting ENOSYS.
There was a problem hiding this comment.
Confirmed. Full SEM_UNDO lifecycle support is required for Linux 6.6 compatibility, including shared undo state for CLONE_SYSVSEM, semadj updates and limits, cleanup on SETVAL/SETALL/IPC_RMID, and replay on task exit. I am implementing this now and will replace the current ENOSYS test with lifecycle coverage. Keeping this thread open until the implementation and tests are complete.
| /// SysV SHM manager (phase one: per-namespace SHM only) | ||
| pub shm: SpinLock<ShmManager>, | ||
| /// SysV semaphore manager | ||
| pub sem: SpinLock<SemManager>, |
There was a problem hiding this comment.
[P1] A namespace-wide spinlock is too broad for semaphore-set state. Every operation on every set, including update_queue(), is serialized here; queue simulation allocates a HashMap, may rescan waiters quadratically, and calls Waker::wake() while this lock is held. A user can therefore stall unrelated semaphore sets in the same namespace. Please keep the manager lock limited to ID/key/quota lookup, store stable Arc<KernelSemSet> objects with per-set locking, use a non-allocating operation fast path, and collect wakeups for execution after releasing the set lock, following Linux's registry/array locking and wake_q separation.
There was a problem hiding this comment.
Please keep the manager lock limited to ID/key/quota lookup, store stable
Arc<KernelSemSet>objects with per-set locking, use a non-allocating operation fast path, and collect wakeups for execution after releasing the set lock.
I am currently evaluating the necessity and designing the manager/per-set lock separation. No implementation changes for this lock split have started yet.
I am also coordinating this with the latest semaphore queue work. The design will preserve the unlocked queue-growth preparation and fallible-allocation semantics from b3f637c7, rather than duplicate or replace that work. I will post the finalized scope before touching the locking code so we can avoid overlapping changes.
|
While reviewing the queue-rescan concern, I found a separate Linux 6.6 compatibility issue in the current unified waiter queue. Linux classifies queued requests into const operations (the entire operation group has no altering operation) and alter operations when they are enqueued: ipc/sem.c#L2127-L2153. Its update path handles wait-for-zero requests before scanning pending alter requests: ipc/sem.c#L1029-L1039. After a queued alter operation succeeds, Linux immediately checks wait-for-zero requests made satisfiable by that change before continuing with further alter operations: ipc/sem.c#L974-L992. The current DragonOS implementation stores both classes in one Proposed minimal design for this PR:
This fixes the observable ordering difference without attempting to eliminate the irreducible worst-case rescan for complex multi-operation groups. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a2d659b25f
ℹ️ 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".
| let (waiter, waker) = Waiter::new_pair(); | ||
| let timer = | ||
| deadline_ticks.map(|deadline| Timer::new(TimeoutWaker::new(waker.clone()), deadline)); |
There was a problem hiding this comment.
当 semop 可立即完成时,这里仍会无条件为 Waker 分配 Arc;带非零超时的 semtimedop 还会额外分配 TimeoutWaker 和 Timer。这使无竞争的信号量快路径以及无效 ID、越界或权限失败等错误路径都承担不必要的堆分配开销;应仅在 simulate_semop 返回 Blocked 且确实需要睡眠后创建这些对象。
AGENTS.md reference: AGENTS.md:L10-L10
Useful? React with 👍 / 👎.
|
There are currently conflicts. Please rebase your code onto the latest |
Signed-off-by: longjin <longjin@dragonos.org>
cfa9335 to
73467d1
Compare
Signed-off-by: longjin <longjin@dragonos.org>
|
@codex review |
Signed-off-by: longjin <longjin@dragonos.org>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 277351ed23
ℹ️ 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".
Signed-off-by: longjin <longjin@dragonos.org>
|
@codex review |
|
Codex Review: Didn't find any major issues. Hooray! 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". |
Signed-off-by: longjin <longjin@dragonos.org>
Split semaphore ABI, namespace management, atomic execution and wait queues into focused modules. Centralize terminal publication without rescanning known queues, and represent undo retirement with an explicit phase. Preserve syscall paths, locking and deferred reclamation. Move existing tests with their owning modules and add atomic-attempt regression coverage. Signed-off-by: longjin <longjin@dragonos.org>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 303064c738
ℹ️ 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".
Signed-off-by: longjin <longjin@dragonos.org>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a455a7301a
ℹ️ 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".
Signed-off-by: longjin <longjin@dragonos.org>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 55a48ef282
ℹ️ 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".
Preserve the old IPC namespace and actor across namespace publication, then release the fs reference guard before replay. Validate copied SETALL values before checking for concurrent removal. Signed-off-by: longjin <longjin@dragonos.org>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 506bf42a68
ℹ️ 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".
Track both committed semaphore values and shared undo adjustments in the existing completion result. Preserve the result through the immediate undo path and use it for immediate scans and queued retries. Debt-only changes must still retry waiters because they can turn a blocked shared SEM_UNDO operation into ERANGE. Add user-space coverage for immediate and queued debt-only changes. Signed-off-by: longjin <longjin@dragonos.org>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0424b7f82f
ℹ️ 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".
Cover creator and current group membership through both primary and supplementary groups after changing gid. Check read/write access, unrelated-group denial, and the separate owner-only IPC_SET/IPC_RMID boundary. Linux 6.6 ipcperms checks both cgid and gid, so retain the existing kernel behavior. Signed-off-by: longjin <longjin@dragonos.org>
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3e3843d074
ℹ️ 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".
Keep dense association storage and its group-identity index together. Prepare both buffers outside the manager lock, recheck capacity before publication, and repair moved slots on constant-time expected removal. Preserve Weak identity lifetimes, deferred RMID cleanup, geometric growth and best-effort unlocked reclamation. Extend registry regression coverage for removal, deduplication and concurrent capacity changes. Signed-off-by: longjin <longjin@dragonos.org>
The rcS marker contains brackets that were incorrectly interpreted as a regex character class, causing the monitor to misclassify a system that had already entered userspace. Add host tests executing the actual predicate against literal, binary, CRLF, missing and misleading log inputs. Keep existing timeout and failure policies unchanged. Signed-off-by: longjin <longjin@dragonos.org>
|
CI investigation and fix: a473663 corrects a proven boot-monitor bug in the failed Integration Test run. The serial log had already printed the rcS marker, but grep treated its brackets as a regular-expression character class and failed to recognize it. The monitor now matches the literal markers. Six tests execute the actual shell predicate; three failed before the change and all six pass afterward. Timeout and failure policies are unchanged. The later upload error (no test cases found) was secondary: that run stopped before the test runner started. The monitor correction is not evidence that the underlying pre-test startup stall is fixed. Its exact internal cause has not been established from the available log. I have rerun the failed job at the same SHA as a control; it is currently running the syscall-test step. The new head also has fresh CI runs. Locally, the repository's network startup policy returned successfully after installing its configuration and mounting /run, but that does not exclude an intermittent cold-boot issue. The semaphore-index change in fa5cdf9 separately passed the kernel build, library tests, actual-source fault/capacity/index probes and 87 DragonOS SysVSem tests plus 20 full-suite repetitions. Three-role adversarial review passed. No tests were skipped or timeouts extended to turn CI green. |
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. 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". |
Related
Summary
semget,semctl,semop, andsemtimedop.Scope
SEM_UNDOis out of scope and currently returnsENOSYS.Acceptance
ENOSYS.semopandsemtimedopshare consistent operation semantics.IPC_RMID.Testing