10 Commits
Author SHA1 Message Date
Yuming Jiangandlongjin d53fdc91a7 feat(ipc/sem): add semaphore support for dragonOS (#2172)
* refactor(ipc): extract generic SysV IPC permission module

* feat(ipc): implement System V semaphore syscalls

* test(ipc): add SysV semaphore dunitest suite

* style(ipc): satisfy kernel formatting checks

* style(ipc): translate SysV semaphore comments to English

* fix(ipc): make IPC_SET permission updates atomic

* fix(ipc): make semaphore set allocation fallible

* feat(ipc): implement SysV SEM_UNDO lifecycle

* fix(ipc): mark allocated IDs in release builds

* fix(ipc): prioritize const semaphore waiters

* fix(process): preserve reaped PID identity

* fix(process): preserve exec locking in prepared namespace publication

Signed-off-by: longjin <longjin@dragonos.org>

* fix(ipc): harden semaphore allocation and Linux syscall semantics

Signed-off-by: longjin <longjin@dragonos.org>

* test(fuse): handle background writeback in direct-drain assertions

Validate complete cached-page coverage before direct writes without assuming a fixed writeback partition. Cover tail-first writeback deterministically and close open files on failure to avoid contaminating later mount-isolation tests.

Signed-off-by: longjin <longjin@dragonos.org>

* fix(ipc): make bulk semaphore buffers fallible and prepare queue growth unlocked

Return ENOMEM for SETALL and GETALL buffer allocation failures. Prepare spare waiting-queue capacity only after a blocked operation needs growth, then revalidate and publish without allocating under the namespace lock. Preserve FIFO order and release replaced storage outside the lock. Add a 32000-element SETALL/GETALL regression.

Signed-off-by: longjin <longjin@dragonos.org>

* fix(ipc): prepare undo registry growth outside the namespace lock

Request spare capacity before publishing a first-time undo group. Allocate outside the manager lock, then revalidate the set and registration state before moving Weak entries into the prepared buffer. Keep replaced storage for unlocked disposal and preserve mark-after-insertion and duplicate prevention. Add coverage for competing growth and repeated registration.

Signed-off-by: longjin <longjin@dragonos.org>

* fix(ipc): scope semaphore undo cleanup and defer wakeups

Associate undo groups with each semaphore set so control operations no longer scan unrelated groups. Reuse published records for the registration fast path and preserve unlocked spare-capacity preparation.

Publish queued results under the namespace lock and drain an allocation-free completion batch after unlocking across semop, semctl and exit replay. Keep completed entries alive and detach links iteratively.

Add set-local undo and bulk removal regressions. Validate with make kernel, kernel workspace tests, 69 Linux host tests, 69 DragonOS guest tests and 20 complete guest repeats.

Signed-off-by: longjin <longjin@dragonos.org>

* fix(ipc): reclaim unused semaphore undo registry storage

Unlink retired groups using their existing records and release failed or canceled missing associations only when no published record or shared waiter remains. Preserve the original whole-group replay critical section.

Reclaim empty registries without allocation and shrink sparse registries through unlocked fallible preparation and locked revalidation. Keep allocation failure and competing growth outside syscall success semantics.

Add persistent-set undo churn and shrink revalidation coverage. Kernel and workspace builds, host capacity/failure checks, 70 Linux tests, 70 DragonOS tests and 20 full guest repeats passed.

Signed-off-by: longjin <longjin@dragonos.org>

* fix(ipc): skip empty unshare installs and cache the maximum ID index

Return no prepared install when unshare has no replacement state or undo detachment. Preserve validation and required SYSVSEM/NEWIPC work.

Track the highest used index in the existing IPC allocator, using its bitmap only when removing the maximum. Make semaphore information queries read the cache without scanning the object table.

Add allocator and syscall regressions. Validate kernel/workspace builds, four allocator tests, 50000 randomized allocator steps, installation failure injection, Linux and guest semaphore 72/72, 20 full guest repeats, and SHM 61 passed with four environment skips.

Signed-off-by: longjin <longjin@dragonos.org>

* fix(namespace): make prepared fs copies fallible

Signed-off-by: longjin <longjin@dragonos.org>

* fix(ipc): prepare semaphore storage outside the lock and unlink waiters directly

Signed-off-by: longjin <longjin@dragonos.org>

* fix(dunitest): use real deadlines when collecting child output

Signed-off-by: longjin <longjin@dragonos.org>

* fix(ipc): reuse live undo records and replay one set at a time

Signed-off-by: longjin <longjin@dragonos.org>

* fix(ipc): defer semaphore removal reclamation until after unlock

Signed-off-by: longjin <longjin@dragonos.org>

* fix(ipc): cache wait counts and retain zero undo records

Signed-off-by: longjin <longjin@dragonos.org>

* docs: remove sem undo implementation plan and design spec

Signed-off-by: longjin <longjin@dragonos.org>

* refactor(ipc): separate semaphore state, operations and undo lifecycle

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>

* perf(ipc): preindex semaphore scratch and reclaim undo record storage

Signed-off-by: longjin <longjin@dragonos.org>

* fix(ipc): correct semaphore ABI and index undo records

Signed-off-by: longjin <longjin@dragonos.org>

* fix(ipc): replay detached undo outside fs publication barrier

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>

* fix(ipc): skip semaphore queue scans when waiter state is unchanged

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>

* test(ipc): preserve creator group access after semaphore IPC_SET

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>

* perf(ipc): index semaphore set undo associations

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>

* fix(ci): match syscall boot markers literally

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>

---------

Signed-off-by: mistcoversmyeyes <mingjiangyu1@qq.com>
Signed-off-by: longjin <longjin@dragonos.org>
Co-authored-by: longjin <longjin@dragonos.org>
2026-09-07 11:16:17 +08:00
Yuming Jiang b2b8aace07 feat(agents): 统一的 agent 配置管理方案。 (#1670)
* feat(agents/skills): 为 agents 添加 skill-creator 技能

* feat(agents): 实现初版 Gvisor bug 修复 Skill

* docs(agents):添加 `.agent` 文件夹的文档

* chore(agents):使用软链接将 skills 文件夹链接到不同agent

* refactor: 调整 README 文档

* feat: 添加对 copilot 的 skills 引用支持

* feat(agents): 更新 “gvisor 分析”的 SKILL.md 文档并将示例拆分为单独文档

* feat: v0.2.0 gvisor 分析报告 skills

- 合并单测试用例分析和多测试用例分析的工作流

* docs(agents/gvisor-anly): 补充步骤七完整内容并更新示例

- 补充 SKILL.md 步骤七的详细内容(根因分析表格和修复方案的生成规则)
- 更新 EXAMPLES.md 中的处理流程,使其符合新的 7 步工作流
- 区分单个测试(跳过概览步骤)和多个测试(完整 7 步)的处理路径

Signed-off-by: mingjiangyu1 <mingjiangyu1@qq.com>
2026-02-11 11:24:30 +08:00
Yuming Jiangandlongjin 28b6ba7a21 feat: 在架构相关初始化的时候注册 tsc 时钟源。 (#1769)
- 添加 Tsc 时钟源实现。
- 优化时钟源重新选择的逻辑


Signed-off-by: mingjiangyu1 <mingjiangyu1@qq.com>
Co-authored-by: longjin <longjin@DragonOS.org>
2026-02-07 21:25:56 +08:00
Yuming Jiang dade7343ba fix(driver/tsc): 修复 pmtimer 拼写错误 (#1762)
Signed-off-by: mingjiangyu1 <mingjiangyu1@qq.com>
2026-02-03 11:31:08 +08:00
Yuming Jiangandlongjin 7543a33658 fix(ipc): 修复部分 shm_test 错误的测试用例 (#1674)
* fix(mm): 克隆地址空间时对于映射到 SysV 共享内存的 VMA 增加 shm map_count。

* fix(ipc): 使 shm 元数据与 Linux 对齐

- 补充 `ShmFlags::PERM_MASK` 用于获取 POSIX 权限位
    - 该掩码用于屏蔽掉非权限位的一次性标志,如 `IPC_CREAT`、`IPC_EXCL` 等。
- 使 KernelShm 能正确创建并初始化
    - 正确初始化 uid/gid/cuid/cgid,并使用 `PERM_MASK` 正确获取权限位。
    - shm_lpid 初始化为 0(因为 lpid 只记录最后一个执行 attach/detach 操作的进程 ID,而在创建时没有这样的进程)。
- 使 `shm_stat` 能够正确获取共享内存状态信息
    - 使 `shm_stat` 正确获取 shm_perm.mode。
    - 使 `shm_stat` 将 shm_{a,d,c}time 以秒为单位输出,

* fix(ipc/sys_shmget): 完善 sys_shmget 创建一个 key 已经存在的共享内存段时的错误处理

- 添加了对 size 参数的检查,确保如果 size 大于已存在段的大小,则返回错误。

* feat(ipc): 添加KernIpcPerm构造函数

* docs(ipc/shm): 优化 SysV Shm 模块部分注释,标记待实现的 ShmId 生成机制

- 统一称呼“Shm Segment”为“共享内存段”,避免混淆
- 使用 “attach” 和 “detach” 术语,避免使用中文翻译。
- 优化部分注释的表达,使其更清晰易懂
- 标记待实现的 ShmId 生成机制

* refactor(mm/ucontext): 优化 `InnerAddressSpace::munmap` 函数和其内部调用 `extract` 函数的注释

- 重构并优化 `InnerAddressSpace::munmap()` 函数的注释
    - 调整了部分代码的顺序以提升可读性
    - 优化了检查 related_vmas 循环中的注释和变量命名,使其更清晰易懂
    - 添加了循环 unmap related_vmas 的每次循环的操作的逻辑注释,帮助理解代码意图
- 优化 `LockedVMA::extract()` 函数注释,增加参数和返回值说明

* docs(mm/UserMappings): 优化 `remove_vma` 函数的注释

* refactor(mm/ucontext): 优化 LockedVMA::unmap() 临时变量命名

- 优化共享内存管理器的detach_shm函数注释,增加对副作用的说明
- 优化 unmap() 函数中变量的命名

* refactor(ipc/shm): 优化 KernIpcPerm 构造函数,简化权限信息传递

* docs(ipc/shm): 更新 KernelShm 结构体中 shm_lprid 字段的注释,明确操作者定义

* fmt

* docs(ipc/shm): 更新 KernelShm 构造函数中 lprid 填充为0 的注释

* fix(ipc): 修复 shm 路径 unwrap 崩溃

* fix(ipc): 处理 fork 中 shm 段删除竞态

* fix(ipc/shmget): sys_shmget 共享内存段状态不一致

- 添加根据 shm_id 获取实际共享内存段的错误处理,防止在 “检查” -> “获取” 过程中状态变化导致的不一致问题。

* fix(ipc/shm): 处理 shm 相关类型转换溢出

* 补充 try_clone 锁顺序说明

* clean: 清除未使用的 PosixShmPerm::new 函数

* ci: restart CI pipeline

---------

Co-authored-by: longjin <longjin@DragonOS.org>
2026-01-23 00:03:23 +08:00
Yuming Jiang 74649e00b1 fix(time/clocksource):修复 ClocksourceWatchdog 拼写错误 (#1628) 2026-01-11 18:35:59 +08:00
Yuming Jiang 58676c8e91 refactor(mm): 重命名 verify_area 为 access_ok 并改进文档 (#1597)
重命名理由:
- verify_area 暗示"已验证可访问",具有误导性
- access_ok 强调"快速范围检查",符合实际行为

文档改进:
- 明确说明这只是第一层检查,不保证真正可访问
- 添加粗体警告,防止误用为"已验证可访问"
- 补充典型用法示例,展示配合 copy_to_user 的正确模式

这将函数语义从"验证已完成"纠正为"可以尝试访问",
避免开发者误认为 Ok(()) 代表地址已映射或真正可访问。
2026-01-03 22:06:38 +08:00
Yuming Jiang 8a5c7606f6 feat(user/profile): 修正 PS1 环境变量使其与 bash 默认高亮一致 (#1432) 2025-12-03 22:44:39 +08:00
Yuming Jiangandlongjin 9420fe09cd fix(gvisor): 修复自动化开启/关闭 gvisor syscall测例打包的脚本 (#1405)
* fix(tools): 修复缺失 /tmp 目录导致 gvisor 测例运行错误的问题

- 在 `write_disk_image.sh` 中添加创建 /tmp 目录的命令。

Signed-off-by: yuming <mingjiangyu1@qq.com>

* ci: 优化启用/关闭gvisor测试的脚本

Signed-off-by: longjin <longjin@DragonOS.org>


---------

Signed-off-by: yuming <mingjiangyu1@qq.com>
Signed-off-by: longjin <longjin@DragonOS.org>
Co-authored-by: longjin <longjin@DragonOS.org>
2025-11-26 00:00:04 +08:00
Yuming Jiang 3f18af7c5a fix(syscall/vfs): fix SIG derivative when writing partial readable buffer (#1375)
* fix(mm/vfs): 修复 writev 无法正确处理部分 iov 为受保护内存空间的情况

- 引入 user_accessible_len() 以测量从给定地址 `address` 开始,能够被拷贝的最长连续字节长度(注:使用vma进行校验)
- 使 IoVecs::gather 返回 Result 并仅聚合可以被读取的 `buf` 部分(注意,一旦碰到不可访问的 iov,后面的iov都会被抛弃)
- 在 writev/pwritev 中传播新的 Result 以支持 gVisor 下的部分写入

* docs(vfs/syscall): 添加文件系统实现分散写入的 TODO 注释

- 添加了对于 IoVecs 发起的分散写入的处理方式目前处理方式的注释。
- 添加了实现分散写入依赖于文件系统对于 IoVecs 写入支持的注释。

* feat(test): 添加 pwritev 性能测试程序

* fix(syscall/user_access): 修复 潜在的死锁问题

* test(gvisor): 在自动测试中启用所有的 writev 测试


Signed-Off-By: mingjiangyu1 <mingjiangyu1@qq.com>
2025-11-22 00:00:57 +08:00