Skip to content

feat(starry-nix): activate nixpkgs on StarryOS (with sandboxed nix)#1520

Open
silicalet wants to merge 78 commits into
rcore-os:devfrom
silicalet:003-starryos-nixpkgs
Open

feat(starry-nix): activate nixpkgs on StarryOS (with sandboxed nix)#1520
silicalet wants to merge 78 commits into
rcore-os:devfrom
silicalet:003-starryos-nixpkgs

Conversation

@silicalet

@silicalet silicalet commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

依赖

⚠️ 在pr1125(002-starryos-nix-smoke)的基础上进一步的PR。 本分支基于 002,包含 002 的所有 commit。
由于 systemd/cgroup v2尚不完善,我暂时无法独立完成模拟星绽OS使Starry支持NixOS的终极目标,
故当前只能先支持nixpkgs,等于给starry在apk/apt之后再添加一种包管理方式

问题

002 完成了 no-sandbox nix smoke(NIX_NOSANDBOX_COMPLETE),但 nixpkgs 源码构建路径一直被注释掉。本 PR 激活 nixpkgs 测试路径,在 StarryOS 上通过 nix-build /opt/nixpkgs -A hello 从 binary cache 获取并验证 hello 程序。

改动

Nix 应用测试(apps/starry/nix/

  • test_nix.sh:激活 nix-nixpkgs 阶段(原被注释),在 nix-nosandbox 之后运行
  • nix-nixpkgs.sh:简化测试逻辑为 nix-build /opt/nixpkgs -A hello(binary cache),替代原来在 guest 内编译 C 源码的 stdenv.mkDerivation 方式。该方式已通过 podman CI 容器验证,总运行时间 ~230s
  • nix-nosandbox.sh:修复 builder 创建 /nix/var/nix/profiles/per-user/root 目录失败不会导致 false PASS
  • nix.sh:更新注释,反映 sandbox=false 保留原因(默认路径无需 sandbox,非内核缺失)
  • prebuild.sh
    • 切换到官方 Nix 2.34.0 二进制闭包(SHA256 固定,分架构),替代之前的 apk add nix
    • 注入 pinned nixpkgs 源码树到 /opt/nixpkgs(release-26.05 commit 714a5f8c,SHA256 固定)
    • resize_rootfs(): 将 ext4 镜像从默认 3G 扩展到 8G,容纳 nix store(~393M)+ nixpkgs source(~322M)+ NAR download overhead
    • 注入 test-nix-builder-init 诊断二进制到 /usr/bin/starry-test-suit/
    • 修复 aarch64 prebuild 架构检测(原来 hardcode qemu-x86_64-static)
  • qemu-x86_64.toml / qemu-aarch64.toml
    • success_regex 增加 NIX_NIXPKGS_TEST_PASSED
    • QEMU 内存从 512M 提升到 8G(x86_64)/ 2G(aarch64)
    • 超时从 1200s 调整为 1800s(x86_64)/ 1200s(aarch64)
  • README.md:更新以反映 nixpkgs phase 已激活、Nix 2.34.0 官方闭包、nixpkgs pin 信息、文件结构变化
  • 新增 qemu-x86_64-shell.toml:交互式 shell 配置,8 SMP,用于手动调试
  • 新增 qemu-x86_64-test-builder-init.toml:builder-init 回归测试专用配置

内核修复

  • close_range fd-table 死锁修复os/StarryOS/kernel/src/syscall/fs/fd_ops.rs):
    sys_close_range 在持有 FD_TABLE 写锁时调用 release_locks_on_close,后者通过
    fd_tables_contain_filefd_table_file_refs 再次获取 FD_TABLE,形成自死锁。
    修复:收集被关闭 fd、先 drop(fd_table) 再释放锁。此问题是 system 聚合套件挂死的根因,
    任何 shell 管道都会触发 dup2 → 死锁。
  • nix nar restore 路径修复os/arceos/modules/axfs-ng/src/fs_core/context.rs):
    resolve_path 支持 nix nar restore 所需的路径约束
  • clone flagos/StarryOS/kernel/src/syscall/task/clone.rs):补上缺失的 clone flag
  • build configqemu-smp1/build-x86_64-unknown-none.toml):system 聚合套件启用 ax-fs-ng/open-noatime

内核回归测试(test-suit/starryos/qemu-smp1/system/

新增 7 个 C 回归测试,作为 qemu-smp1/system 聚合套件子项:

测试 覆盖子系统 验证点
test-nix-builder-init fork/exec/prctl/dup2/PTY/setsid/close_range/setrlimit/umask 精确复现 Nix builder 初始化的 12 步 syscall 序列
test-brk-mmap-interaction brk/mmap/mprotect/madvise 347 行:brk 与 mmap 交互、MADV_DONTNEED 后 brk 行为、OOM 压力
test-rlimit-inheritance prlimit64/fork fork 后子进程继承 RLIMIT_STACK 并检测 EFAULT
bugfix-nix-openat2-resolve openat2/RESOLVE_BENEATH StarryOS fix 前后的 openat2 resolve 行为
test-close-range close_range 补全 CLOSE_RANGE_CLOEXEC + 已被关闭 fd 的 dup3
test-pty-master-close PTY 扩展现有 PTY 测试:Nix sentinel → 长日志 → stderr master poll 送达 → slave 输出完整性

内核诊断

  • os/StarryOS/kernel/src/task/ops.rs / os/arceos/modules/axtask/src/run_queue.rs
    添加 do_exitexit_current is_init 的 console 诊断(用于 NIXPKGS-001 根因定位)

原理

  • 官方 Nix 2.34.0 二进制闭包替代 apk add nix:避免 Alpine apk 的 Nix 版本落后和依赖问题
  • Pinned nixpkgs 源码注入 /opt/nixpkgs:避免 guest 内 fetchTarball 的 git-cache 导入造成的
    89,704-entry 文件树元数据性能瓶颈(NIXPKGS-001 调研结论:耗时为纯文件系统 VFS metadata path,非 ext4/block 层)
  • nix-build -A hello(binary cache):从 cache.nixos.org / mirrors.cernet.edu.cn 镜像拉取预编译的 hello,
    无需本地编译 stdenv,消除了 300s 超时问题
  • sandbox = false 保留:默认路径已是 binary substitution,无需 sandbox;boot.isContainer 模式也无需
    mount namespace 隔离

验证

ghcr.io/rcore-os/tgoskits-container:latest Podman 容器中:

# nix app test(nosandbox + nixpkgs 两阶段)
cargo xtask starry app qemu -t nix --arch x86_64
  → NIX_NOSANDBOX_TEST_PASSED ✅
  → NIX_NIXPKGS_TEST_PASSED ✅  (Hello, world!)

# system 聚合套件(含新增 7 个内核回归测试)
cargo xtask starry test qemu --arch x86_64 -c qemu-smp1/system
  → PASS system

影响面

  • 内核改动集中在 close_range fd-table 锁顺序修复 + nix nar restore 路径约束
  • 新测试仅影响 test-suit/starryos/qemu-smp1/system/apps/starry/nix/
  • prebuild.sh 切换到官方 Nix 闭包 + nixpkgs 源码注入,不依赖 guest 内 apk/nix-channel 网络

已知限制

  • sandbox nix-build 暂缓nix.sh--option sandbox true)仍被注释,不在 CI gate 中。
    StarryOS 已支持所有 7 种 namespace flag(PR namespace实现 #981),sandbox 路径理论上可用,但需端到端验证

  • aarch64 nixpkgs:未在此 PR 中验证(仅 x86_64 通过 podman CI)

    追加说明:Nix sandbox 与 test-suit 更新 (2026-7-15)

    本 PR 后续又补齐了 Nix sandbox 相关验证,因此上面部分早期描述中关于 qemu-smp1/system、sandbox 暂缓、仅 x86_64 验证等信息,以本追加说明为准。

    Standalone Nix sandbox 验证

    新增并启用 test-suit/starryos/qemu/nix-sandbox/

    • x86_64 / aarch64 均运行最小 nix-build --no-substitute --option sandbox true
    • 使用唯一 token 验证当前 builder 的 started/done marker 和输出内容,避免 false pass
    • 检查 Nix 日志中没有 sandbox auto-disable
    • 失败时通过 NIX_SANDBOX_ERROR / NIX_SANDBOX_TEST_FAILED 明确传递给 test-suit runner
    • GitHub-hosted aarch64 CI 较慢,因此 standalone sandbox case 的 QEMU timeout 与 guest 内部预算已同步调整为 180s

    Nix sandbox debug regression suite

    新增 test-suit/starryos/qemu/nix-sandbox-debug/,用于覆盖 Nix sandbox 依赖的 Linux 语义阻塞点。该 suite 不直接跑 Nix sandbox builder,而是在 sandbox=off 下验证内核语义,便于定位 StarryOS regression。

    覆盖内容包括:

    • mountinfo / per-namespace mounts / remount flags
    • bind/rbind mount 与 mount propagation
    • pivot_root 及 pivot_root namespace 隔离
    • cgroup namespace
    • /proc/sys/user/max_*_namespaces
    • /proc/<pid>/environ
    • /proc/<pid>/root/proc/<pid>/cwd
    • Nix builder exec/init/clone-parent/namespace-exec/first-divergence focused cases

    qemu/system 路径更新

    原文中的 qemu-smp1/system 已过时。当前 StarryOS test-suit 已统一到 qemu wrapper,系统级内核回归测试应使用:

    cargo xtask starry test qemu --arch x86_64 -c qemu/system
    cargo xtask starry test qemu --arch aarch64 -c qemu/system
    
    apps/starry/nix/README.md 已同步更新该路径。
    
    ### Nix app test 当前内容
    
    apps/starry/nix/test_nix.sh 当前包含三段:
    
    1. nix-nosandbox:builtins.toFile store-path write
    2. nix-sandbox:最小本地 derivation,--no-substitute --option sandbox true
    3. nix-nixpkgs:导入 /opt/nixpkgs,realize 并执行 hello
    
    其中 nixpkgs phase 默认允许 binary substitution,用于验证 nixpkgs 作为包管理器可用;它不声明完整本地源码构建 stdenv。
    
    ### 已补充验证
    
    已完成的本地/Podman 验证包括:
    
    cargo xtask starry app qemu -t nix --arch x86_64
    # PASS: NIX_APP_TESTS_PASSED
    
    cargo xtask starry test qemu --arch x86_64 -c qemu/nix-sandbox
    cargo xtask starry test qemu --arch aarch64 -c qemu/nix-sandbox
    # PASS: NIX_SANDBOX_TEST_PASSED / STARRY_GROUPED_TESTS_PASSED
    
    cargo xtask starry test qemu --arch x86_64 -c qemu/nix-sandbox-debug
    # PASS: NIX_SANDBOX_DEBUG_TESTS_PASSED
    
    cargo test -p axbuild nix_sandbox_cases_enforce_bounded_truthful_completion -- --nocapture
    cargo xtask clippy --package axbuild
    cargo fmt
    git diff --check
    
    最新提交 fix(starry-nix): relax sandbox CI timeout 是针对 PR CI 中 aarch64 standalone sandbox 的 90s 内部预算过紧问题;该问题表现为 builder 已经 started/done,但 wrapper 先以 exit 124 判定 timeout。
    

追加说明:review 后的 test-suit/axbuild 修正(2026-07-17)

根据 review 反馈,nix-sandbox-debug 不再作为 standalone sandbox/debug contract 维护,而是作为普通系统语义回归用例迁入 test-suit/starryos/qemu/system/。本轮同步移除了 PR 分支新增的 axbuild contract 测试改动,scripts/axbuild/src/starry/test/tests/ 保持上游版本;迁移仅依赖现有数据驱动 test-suit 机制。

本轮本地 Podman CI 复现时还修正了两个运行问题:

  • test-suit/starryos/qemu/system/test-mountinfo 的 CMake target 改为 nix-sandbox-test-mountinfo,避免和既有 syscall-test-mountinfotest-mountinfo target 重名。
  • apps/starry/nix/qemu-x86_64.toml 改为 uefi = true / to_bin = true,与 std/PIC Starry x86_64 镜像的 UEFI handoff 保持一致,避免 QEMU 直接 -kernel 加载 PIE ELF 时报 Error loading uncompressed kernel without PVH ELF Note

最新本地验证使用 ghcr.io/rcore-os/tgoskits-container:latest,并挂载 .ci-cache

cargo xtask starry test qemu --arch x86_64 -c qemu/system
# PASS system

cargo xtask starry app qemu -t nix --arch x86_64
# PASS: NIX_APP_TESTS_PASSED

追加说明:上游同步与 review 修正(2026-07-24)

合并最新 upstream/dev 后,本分支进一步按已合入的上游实现收敛:

  • 移除 003 分支中重复且覆盖较弱的 test-mountinfo,用上游 PR feat(starry): complete mount tree semantics #1644 的 syscall-test-mountinfo 作为 mountinfo 回归测试;Podman QEMU 验证为 42/42 checks passed。
  • 移除已由上游实现覆盖的 clone/clone3 与 close_range 重复测试片段。
  • 将 axbuild 测试预期同步到统一后的 qemu/system 布局,并新增检查,禁止 grouped system 子用例使用绝对 CMake install DESTINATION。
  • 按 review 意见修复 test-cgroup-ns 和 test-max-ns-entries:使用 RUNTIME DESTINATION usr/bin/starry-test-suit,确保通过 DESTDIR 安装到 guest overlay。

本轮使用 ghcr.io/rcore-os/tgoskits-container:latest,并挂载 .ci-cache/cargo.ci-cache/rustup.ci-cache/tmp,验证结果:

qemu/test-cgroup-ns: PASS (TEST_CGROUP_NS_PASSED)
qemu/test-max-ns-entries: PASS (TEST_MAX_NS_ENTRIES_PASSED)
qemu/syscall-test-mountinfo: PASS (42/42)
cargo test -p axbuild starry_system_grouped_cases_use_overlay_relative_install_destinations: PASS
cargo xtask clippy --package axbuild: PASS
cargo fmt --all -- --check: PASS

对应签名提交:c9651cab9

LoongArch CI 架构过滤修正

后续 CI 发现 test-nix-clone-parent 在 LoongArch grouped system 构建阶段失败。该测试使用
x86_64 专用的 rax/r12/r13 寄存器、syscall 指令和 =a 汇编约束,因此不能在
LoongArch 上编译。

本轮通过现有 starry_arch_filtered_executable helper 将该测试限制为 x86_64;其他架构
仍生成明确的 skip 二进制,保持 grouped system 子用例可发现且不会误编译 x86_64 源码。

Podman 容器继续挂载 .ci-cache/cargo.ci-cache/rustup.ci-cache/tmp,验证结果:

cargo xtask starry test qemu --arch loongarch64 -c qemu/system/test-nix-clone-parent
# PASS system(显式 skip)

cargo xtask starry test qemu --arch x86_64 -c qemu/system/test-nix-clone-parent
# TEST_NIX_CLONE_PARENT_PASSED
# PASS system

对应签名提交:7ebf5739f

@mai-team-app mai-team-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

审查总结

本 PR 在 StarryOS 上激活 nixpkgs 测试路径(nix-build /opt/nixpkgs -A hello),同时包含:

  • close_range/dup3 fd-table 自死锁修复:收集已关闭 fd、先 drop(fd_table)release_locks_on_close,修复 shell 管道挂死
  • openat2 RESOLVE_BENEATH 支持:实现 resolve_parent_beneath_no_symlinks 满足 nix nar restore 路径约束
  • Mount namespace 重构Weak<Self>Arc<Self> children,新增 MountNamespaceclone_treeunshare_mount_namespace
  • clone flag:补上 CLONE_NEWNS|CLONE_FS 互斥检查、RLIMIT 继承、pid_ns init tracking
  • do_exit 增强:PID namespace init SIGKILL 清理 + flock 锁释放
  • Nix app 测试apps/starry/nix/ 完整 app 套件
  • 7 个内核回归测试:作为 qemu-smp1/system 子项

验证结果

  • cargo fmt --check ✅ 通过
  • cargo clippy --manifest-path components/axfs-ng-vfs/Cargo.toml --all-features -- -D warnings ✅ 通过
  • cargo clippy --manifest-path os/arceos/modules/axfs-ng/Cargo.toml --all-features -- -D warnings ✅ 通过
  • cargo clippy --manifest-path os/arceos/modules/axtask/Cargo.toml --all-features -- -D warnings ✅ 通过

CI 状态

所有 24+ 个 CI check runs 均为 conclusion: "skipped"(fork PR CI 策略)。mergeable_state"unstable"。作者在 podman 容器中验证了 cargo xtask starry app qemu -t nix --arch x86_64cargo xtask starry test qemu --arch x86_64 -c qemu-smp1/system,但 CI 覆盖完全缺失。

重复/重叠分析

  • PR #1125(同作者,002-starryos-nix-smoke):本 PR 明确依赖 #1125。两者均为 open 状态,#1125 有 52 条 review comments、10 条 issue comments、mergeable_state: "blocked"。本 PR 分支包含 #1125 的所有 commit。两者是序列依赖关系,非重复。
  • base 分支检查components/axfs-ng-vfs/src/mount.rsos/arceos/modules/axfs-ng/src/fs_core/context.rs 的改动在 base 分支无等效实现。
  • 搜索相关 open PR:未发现与 close_rangemount namespacenix app test 直接重叠的其他 open PR。

阻塞问题

1. 预编译二进制文件检入仓库(安全/可复现性)

apps/starry/nix/test-nix-builder-init 是一个 47KB 的 ELF 二进制文件,直接检入源码仓库。虽然其源代码存在于 test-suit/starryos/qemu-smp1/system/test-nix-builder-init/src/main.c(通过 CMake 编译),但仓库中的预编译二进制存在以下问题:

  • 安全性:二进制 blob 无法审查,无法验证是否与源码一致
  • 可复现性:无法从该二进制反推构建环境
  • 架构特定:该二进制仅适用于 x86_64

修复方向:移除仓库中的预编译二进制,让 prebuild.sh 从源码构建(利用已有的 CMake 构建产物或单独编译)。

2. README 与实际测试行为不一致

apps/starry/nix/README.md 描述 nixpkgs phase 为 "stdenv.mkDerivation source build of a minimal C hello program",并声称 "the target derivation's buildPhase (the hello.chello compile step) still runs locally on StarryOS"。

但实际的 nix-nixpkgs.sh 仅执行 nix-build /opt/nixpkgs -A hello,通过 binary cache 获取预编译的 hello 包,不进行本地 C 编译。README 的描述与代码行为不符。

修复方向:更新 README 中 nixpkgs phase 的描述,准确反映 binary cache 路径,移除关于本地编译 buildPhase 的错误说明。

3. 所有 CI 检查被跳过

本 PR 有 150 个 commit、90 个变更文件、+5387/-322 行,涉及 close_range 锁修复、mount namespace 重构、openat2 resolve 语义变更等内核关键路径。所有 CI check runs 均为 skippedmergeable_state"unstable"

作者在 podman 容器中的验证是好的补充,但不能替代 CI 的跨架构覆盖(aarch64 nixpkgs 测试未验证)。

修复方向:需要触发 CI 运行(例如通过 maintainer 在目标仓库分支上触发),或至少在 PR body 中提供 aarch64 的等效验证证据。

4. 依赖未合并的 PR #1125

PR body 明确声明 "请先合并 #1125(002-starryos-nix-smoke)再合并此 PR"。#1125 有 52 条 review comments、mergeable_state: "blocked",其 review 讨论尚未解决。本 PR 包含 #1125 的所有 commit,使得代码审查无法清晰分离两个 PR 的变更边界。

修复方向:等 #1125 合并后再重新审查本 PR,或将本 PR 的 base 改为 #1125 的 head(而不是 dev),使 diff 仅包含本 PR 的增量变更。


非阻塞建议

Mount namespace 内存模型

components/axfs-ng-vfs/src/mount.rschildrenHashMap<ReferenceKey, Weak<Self>> 改为 HashMap<ReferenceKey, Arc<Self>>,这意味着每个 mount namespace 拥有独立的 mount tree 副本(通过 clone_tree 递归克隆)。建议在代码或 commit message 中说明:

  • 每个 namespace 的 mount tree 克隆的内存开销预估
  • 为何选择 Arc 而非继续使用 Weak(与 namespace 隔离语义的关系)

mount_namespace_contains 性能

MountNamespace::contains_mountpoint 每次调用都会通过 children() 克隆所有 Arc 引用并遍历整个 mount tree。如果 is_mount_busy 等热路径频繁调用此方法,可能需要考虑优化。

诊断打印

os/StarryOS/kernel/src/task/ops.rsos/arceos/modules/axtask/src/run_queue.rs 中的 ax_println! / console::write_bytes 诊断输出([DIAG] do_exit[DIAG] exit_current)建议在稳定后移除或改为 trace 级别日志,避免在正常 CI 输出中产生噪音。

clone flag 互斥检查注释

os/StarryOS/kernel/src/syscall/task/clone.rsCLONE_NEWNS | CLONE_FS 互斥检查是正确的(Linux 也拒绝此组合),建议在注释中说明 Linux 语义:CLONE_NEWNS 要求独立的 fs_struct(否则 mount namespace 隔离不完整),因此与 CLONE_FS 互斥。

Powered by deepseek-v4-pro

"(?m)^NIX_NOSANDBOX_TEST_FAILED\\s*$",
"(?m)^NIX_NIXPKGS_TEST_FAILED\\s*$",
]
timeout = 1800

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

非阻塞:超时从 1200s 提升到 1800s。考虑到 nix-build -A hello 通过 binary cache 获取预编译包(~230s),1800s 超时远大于正常路径。建议在 README 或 PR body 中说明 1800s 的合理性(网络波动?aarch64 更慢?),避免超时掩盖真实的死锁/挂死问题。

Comment thread os/arceos/modules/axtask/src/run_queue.rs Outdated

@ZR233 ZR233 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

复审当前 head 8b0c5e505190836808147032375221a393cfc3d1

本地轻量检查:git diff --check origin/dev...HEAD 通过;bash -n apps/starry/nix/prebuild.sh apps/starry/nix/test_nix.sh apps/starry/nix/nix-nosandbox.sh apps/starry/nix/nix-nixpkgs.sh apps/starry/nix/nix.sh 通过。

仍需修改后再合入:

  1. 本 PR 明确依赖 #1125,但 #1125 当前仍是 REQUEST_CHANGES,并且本 PR 分支包含 #1125 的提交,diff 边界无法清晰审查。请等 #1125 合并后 rebase,或把 base 明确改到 #1125 head 只审本 PR 增量。
  2. apps/starry/nix/test-nix-builder-init 是直接提交的 x86_64 ELF blob,需要移除并改为从源码/已有测试产物生成。
  3. README/PR body 与实际 nixpkgs 测试行为不一致:脚本是 nix-build /opt/nixpkgs -A hello 且允许 binary cache,不是文档描述的最小本地 C source build。
  4. 当前 CI run 28834694265 还有多个 pending job,且 app-level nixpkgs/aarch64 流程不属于常规 CI 覆盖;合入前需要 current-head 终态 CI 和对应 app 证据。

所以本轮继续 request changes。

Comment thread apps/starry/nix/test-nix-builder-init Outdated
Comment thread apps/starry/nix/README.md Outdated

@mai-team-app mai-team-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

审查总结

本 PR 在 StarryOS 上激活 nixpkgs 测试路径(nix-build /opt/nixpkgs -A hello),同时包含 close_range fd-table 自死锁修复、openat2 RESOLVE_BENEATH 支持、mount namespace 重构、clone flag 补全、7 个内核回归测试以及 Nix app 测试套件。

本地验证结果:

  • cargo fmt --check ✅ 通过
  • cargo clippy --manifest-path components/axfs-ng-vfs/Cargo.toml --all-features -- -D warnings ✅ 通过
  • cargo clippy --manifest-path os/arceos/modules/axfs-ng/Cargo.toml --all-features -- -D warnings ✅ 通过
  • cargo clippy --manifest-path os/arceos/modules/axtask/Cargo.toml --all-features -- -D warnings ✅ 通过

本轮复审确认:ZR233 在 head 8b0c5e5 提出的 4 个阻塞问题全部未解决。继续 request changes。

CI 状态

当前 head 8b0c5e505190836808147032375221a393cfc3d1 的所有 24 个 check runs 均为 conclusion: "skipped"(fork PR CI 策略不自动运行)。92 个变更文件、152 个 commit,涉及 close_range 锁修复、mount namespace 重构、openat2 resolve 语义变更等内核关键路径,缺乏 CI 覆盖。mergeable_state"blocked"

重复/重叠分析

  • PR #1125(同作者,002-starryos-nix-smoke):本 PR 明确依赖 #1125,分支包含 #1125 的所有 commit。#1125 当前仍为 state: openmergeable_state: "blocked",58 条 review comments。两者为序列依赖关系,非重复。
  • base 分支检查apps/starry/nix/ 下所有文件在 base 分支不存在(全新内容)。components/axfs-ng-vfs/src/mount.rsos/arceos/modules/axfs-ng/src/fs_core/context.rs 的改动在 base 分支无等效实现。
  • 搜索相关 open PR:未发现与 close_range、mount namespace、nix app test 直接重叠的其他 open PR。

阻塞问题

1. 依赖未合并的 PR #1125(阻塞)

PR body 明确声明"请先合并 #1125(002-starryos-nix-smoke)再合并此 PR"。#1125 当前仍为 mergeable_state: "blocked",58 条 review comments,已有 REQUEST_CHANGES。本 PR 分支包含 #1125 的全部 commit,diff 边界无法清晰审查,merge queue 也会阻塞。

修复方向:等 #1125 合并后 rebase 本 PR,或将 base 明确设为 #1125 的 head,仅审查本 PR 的增量变更。

2. 预编译 x86_64 ELF 二进制文件检入源码仓库(阻塞)

apps/starry/nix/test-nix-builder-init 是直接提交的 x86_64 ELF 静态 PIE 可执行文件。源码仓库中不应包含不可审查、不可复现、架构固定的预编译二进制 blob。虽然 test-suit/starryos/qemu-smp1/system/test-nix-builder-init/src/main.c 中存在对应的 C 源码和 CMake 构建路径,但 blob 本身仍是合入障碍。

修复方向:移除仓库中的预编译二进制,在 prebuild.sh 中从源码构建或复用 CMake 构建产物后注入。

3. README 与实际测试行为不一致(阻塞)

apps/starry/nix/README.md 多处(line 18、51、82、107)描述 nixpkgs phase 为 stdenv.mkDerivation source build,声称"buildPhase (the hello.chello compile step) still runs locally on StarryOS"。但实际的 nix-nixpkgs.sh 仅执行 nix-build /opt/nixpkgs -A hello,通过 binary cache 获取预编译的 hello 包,不进行本地 C 编译。文档描述与代码行为不符。

修复方向:更新 README 和 PR body 中 nixpkgs phase 的描述,准确反映 binary cache 路径(nixpkgs import/eval + hello derivation realization/execution),移除关于本地编译 buildPhase 的错误说明。如果预期未来会激活本地 source build,应明确标注为待实现目标而非已完成功能。

4. 所有 CI 检查被跳过(阻塞)

本 PR 有 152 个 commit、92 个变更文件,涉及 close_range 锁修复、mount namespace 重构、openat2 resolve 语义变更等内核关键路径。所有 24 个 CI check runs 均为 skipped(fork PR 策略)。作者在 podman 容器中的验证是好的补充,但不能替代 CI 的跨架构覆盖(aarch64 nixpkgs 测试未验证)。

修复方向:需要通过 maintainer 在目标仓库分支触发 CI 运行,或至少在 PR body 中提供 aarch64 的等效验证证据。


非阻塞建议

  • 超时值说明:x86_64 超时从 1200s 调整为 1800s,建议在 README 或 commit message 中说明 1800s 的合理性(正常路径 ~230s,1800s 预留了网络波动、aarch64 更慢等场景)。
  • [DIAG] do_exit / [DIAG] exit_current 诊断打印:建议在稳定性验证完成后移除此诊断或改为 trace 级别日志,避免 CI 输出噪音。
  • Mount namespace Arc<Self> children 内存模型:建议在代码注释或 commit message 中说明每个 namespace mount tree 克隆的内存开销预估,以及为何选择 Arc 而非 Weak
  • clone flag 互斥检查CLONE_NEWNS | CLONE_FS 互斥检查正确(Linux 同样拒绝),建议在注释中说明 Linux 语义。

Powered by deepseek-v4-pro

@mai-team-app mai-team-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

审查总结

本 PR 在 StarryOS 上激活 nixpkgs 测试路径(nix-build /opt/nixpkgs -A hello),同时包含 close_range fd-table 自死锁修复、openat2 RESOLVE_BENEATH 支持、mount namespace 重构、clone flag 补全、7 个内核回归测试以及 Nix app 测试套件。当前 head f99c6d6 为 merge 最新 dev 后的版本。

本地验证结果

  • cargo fmt --check ✅ 通过
  • cargo clippy --manifest-path components/axfs-ng-vfs/Cargo.toml --all-features -- -D warnings ✅ 通过
  • cargo clippy --manifest-path os/arceos/modules/axfs-ng/Cargo.toml --all-features -- -D warnings ✅ 通过
  • cargo clippy --manifest-path os/arceos/modules/axtask/Cargo.toml --all-features -- -D warnings ✅ 通过
  • cargo clippy --manifest-path os/StarryOS/kernel/Cargo.toml --all-features -- -D warnings ✅ 通过

CI 状态

当前 head f99c6d6 的所有 24 个 check runs 均为 conclusion: "skipped"(fork PR CI 策略)。92 个变更文件、153 个 commit,涉及 close_range 锁修复、mount namespace 重构、openat2 resolve 语义变更等内核关键路径,缺乏 CI 覆盖。mergeable_state"blocked"

重复/重叠分析

  • PR #1125(同作者,002-starryos-nix-smoke):本 PR 明确依赖 #1125。当前 #1125 仍为 state: openmergeable_state: "blocked",58 条 review comments。两者为序列依赖关系,非重复。
  • base 分支检查apps/starry/nix/ 下所有文件在 base 分支不存在(全新内容)。内核改动在 base 分支无等效实现。
  • 搜索相关 open PR:未发现与 close_range、mount namespace、nix app test 直接重叠的其他 open PR。

前序 review 审查

前序 3 次 review(bot、ZR233、bot)在 commit 8b0c5e5 均提交 REQUEST_CHANGES,指出 4 个阻塞问题。当前 head f99c6d6 仅 merge 了 dev 的最新提交,未解决任何一个之前指出的阻塞问题


阻塞问题

1. 依赖未合并的 PR #1125(阻塞)

PR body 明确声明"请先合并 #1125(002-starryos-nix-smoke)再合并此 PR"。#1125 当前仍为 mergeable_state: "blocked",58 条 review comments,已有多次 REQUEST_CHANGES。本 PR 分支包含 #1125 的全部 commit,diff 边界无法清晰审查,merge queue 也会阻塞。

修复方向:等 #1125 合并后 rebase 本 PR,或将 base 明确设为 #1125 的 head,仅审查本 PR 的增量变更。

2. 预编译 x86_64 ELF 二进制文件检入源码仓库(阻塞)

apps/starry/nix/test-nix-builder-init 是直接提交的 x86_64 ELF 静态可执行文件(ELF magic 7f 45 4c 46 确认)。源码仓库中不应包含不可审查、不可复现、架构固定的预编译二进制 blob。虽然 test-suit/starryos/qemu-smp1/system/test-nix-builder-init/src/main.c 中存在对应的 C 源码和 CMake 构建路径,但 blob 本身仍是合入障碍。

修复方向:移除仓库中的预编译二进制,在 prebuild.sh 中从源码构建或复用 CMake 构建产物后注入。

3. README 与实际测试行为不一致(阻塞)

apps/starry/nix/README.md 多处(line 18、24、33、51、78、82、107)描述 nixpkgs phase 为 stdenv.mkDerivation source build,声称"buildPhase (the hello.chello compile step) still runs locally on StarryOS"。但实际的 nix-nixpkgs.sh 仅执行 nix-build /opt/nixpkgs -A hello,通过 binary cache 获取预编译的 hello 包,不进行本地 C 编译。文档描述与代码行为不符,会误导后续维护者和使用者。

修复方向:更新 README 和 PR body 中 nixpkgs phase 的描述,准确反映 binary cache 路径(nixpkgs import/eval + hello derivation realization/execution),移除关于本地编译 buildPhase 的错误说明。如果预期未来会激活本地 source build,应明确标注为待实现目标而非已完成功能。

4. 所有 CI 检查被跳过(阻塞)

本 PR 有 153 个 commit、92 个变更文件,涉及 close_range 锁修复、mount namespace 重构、openat2 resolve 语义变更等内核关键路径。所有 24 个 CI check runs 均为 skipped(fork PR 策略)。作者在 podman 容器中的验证是好的补充,但不能替代 CI 的跨架构覆盖(aarch64 nixpkgs 测试未验证)。

修复方向:需要通过 maintainer 在目标仓库分支触发 CI 运行,或至少在 PR body 中提供 aarch64 的等效验证证据。


非阻塞建议

  • [DIAG] do_exit / [DIAG] exit_current 诊断打印:建议在稳定性验证完成后移除此诊断或改为 trace 级别日志,避免 CI 输出噪音。
  • Mount namespace Arc<Self> children 内存模型:建议在代码注释或 commit message 中说明每个 namespace mount tree 克隆的内存开销预估。
  • clone flag 互斥检查CLONE_NEWNS | CLONE_FS 互斥检查正确,建议在注释中说明 Linux 语义。

Powered by deepseek-v4-pro

Comment thread apps/starry/nix/README.md Outdated
@silicalet
silicalet marked this pull request as draft July 7, 2026 05:50

@ZR233 ZR233 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

复审当前 draft head f99c6d6224d605e311d1f35ac22a2687ac510771,上一轮阻塞点仍然有效。

本地确认:git diff --check origin/dev...HEAD 通过,git merge-tree --write-tree origin/dev HEAD 可生成 merge tree,当前 CI 也是 28 success / 28 expected skipped。但这几个合入阻塞仍未解决:

  1. 本 PR 仍包含 #1125 级别的大量基础改动,diff 边界不是“nixpkgs source build”自身的增量。请等 #1125 合入后 rebase 到最新 dev,或明确把 base 改到 #1125 head 后只审本 PR 增量。
  2. apps/starry/nix/test-nix-builder-init 仍是直接提交的 x86_64 static PIE ELF blob(约 47KB)。仓库里不应提交不可审查、架构固定的预编译二进制;请改为从 test-suit/starryos/qemu-smp1/system/test-nix-builder-init/src/main.c 或已有构建产物生成/注入。
  3. README 仍声称 nixpkgs 路径是 stdenv.mkDerivation source build,且 hello.c -> hellobuildPhase 在 StarryOS 本地执行;但 nix-nixpkgs.sh 实际执行的是 nix-build /opt/nixpkgs -A hello,并允许 binary cache,没有禁止替换 hello 本身。请把文档/PR body 改成实际覆盖的 nixpkgs import/eval + derivation realization 行为,或改脚本使目标 derivation 确实本地构建并给出证据。
  4. 这是 draft 且变更面涉及 close_range、mount namespace、openat2、brk/mmap、PTY 等内核关键路径;在拆清 base/移除 blob/同步文档后,还需要补当前 head 的 app-level nixpkgs/aarch64 证据。

@silicalet
silicalet force-pushed the 003-starryos-nixpkgs branch 2 times, most recently from 1b8dbe8 to 019201b Compare July 7, 2026 11:36
silicalet added 4 commits July 7, 2026 21:18
Rebased onto upstream/dev (PR rcore-os#1125 merged).

003-specific nixpkgs additions:
- nix-nixpkgs.sh: pkgs.stdenv.mkDerivation source build (binary cache allowed)
- prebuild.sh: official Nix 2.34.0 binary closure + pinned nixpkgs source
- test-nix-builder-init: builder-init regression binary
- qemu-x86_64-shell.toml / qemu-x86_64-test-builder-init.toml: debug configs
- README: nixpkgs phase documentation + aarch64 verification
- test_nix.sh: nosandbox + nixpkgs two-phase test
…n tests

- Add standalone nix-sandbox test case (x86_64 + aarch64 TOMLs)
  with inline shell script: apk install nix, configure sandbox=true,
  run nix-build on minimal derivation, verify sandbox was active.
- Add nix-debug grouped test suite (10 existing syscall tests)
- Add test-pty-fork-echo regression test (8 cases A-H):
  systematically tests PTY communication across fork, unshare(NEWNS),
  clone(5 ns flags), clone+mount/proc, clone(CLONE_PARENT).
- Cases A-E, G pass. Cases F, H fail — root cause identified:
  StarryOS clone() returns EINVAL for CLONE_PARENT flag.
  Nix uses CLONE_PARENT for sandbox builder spawning.
- Add strace-nixpkgs test case

Diagnosis: silicalet/003-sandbox-clone-parent-root-cause.md
- Remove CLONE_PARENT from exit_signal mutual exclusion check in clone.rs
  and clone3.rs validate(). Linux semantics: CLONE_PARENT IS allowed with
  a non-zero exit_signal; only CLONE_THREAD is incompatible.
- Add mutual exclusion between CLONE_THREAD and CLONE_PARENT, matching
  Linux behavior where both flags together return EINVAL.
- The actual CLONE_PARENT logic (fork from grandparent, exit signal to
  grandparent) was already correctly implemented.
- Simplifies nix-sandbox TOML diagnostic section.
@silicalet
silicalet force-pushed the 003-starryos-nixpkgs branch from fbb3e74 to 3e43f0d Compare July 7, 2026 13:22
@silicalet silicalet changed the title feat(starry-nix): activate nixpkgs source build on StarryOS feat(starry-nix): activate nixpkgs on StarryOS Jul 8, 2026
silicalet added 2 commits July 8, 2026 09:59
…amic mounts

- Add Mountpoint::walk_tree() in axfs-ng-vfs for mount-tree traversal
- Add MountNamespace::walk_tree() wrapper in axfs-ng
- Create proc_mountinfo.rs module with render_mountinfo()/render_mounts()
- Wire /proc/<pid>/mountinfo with per-process FsContext access
- Replace static /proc/<pid>/mounts with dynamic per-namespace rendering
- Store mount flags (MS_NODEV/MS_NOSUID/MS_NOEXEC/etc.) on all mount paths
- Fix mount_id to be independent of device (global counter)
- Add peer_group_id for shared/slave/unbindable mount propagation
- Use DeviceId::major()/minor() for mountinfo major:minor field
- Add nix-sandbox-debug test suite with 4 C regression tests
- Untrack nix-debug tests from git (local-only debug suite)
- Add CgroupNamespace struct in axnsproxy (new_root/clone_ns/id)
- Add cgroup_ns field to NsProxy with unshare_cgroup/set_ns_cgroup
- Add NsFd::Cgroup variant in nsfd.rs
- Wire CLONE_NEWCGROUP in sys_unshare (was no-op) and sys_setns
- Remove EINVAL for clone(CLONE_NEWCGROUP); add unshare_cgroup in do_clone
- Add /proc/<pid>/ns/cgroup entry in NsDir
- Wire try_open_nsfd for cgroup -> NsFd::Cgroup
- Add 7 /proc/sys/user/max_*_namespaces entries (user/mnt/pid/net/uts/ipc/cgroup)
- Add test-cgroup-ns and test-max-ns-entries to nix-sandbox-debug suite

@ZR233 ZR233 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

复审当前 draft head 3e43f0d440884217eb487bc5ab988f5b01d0db88,仍需要修改后再继续评估。

这轮先更正前次上下文:#1125 已显示 merged,因此上一轮“依赖未合并 #1125”的阻塞不再作为当前结论依据;当前 origin/dev...origin/pr/1520 也只剩本 PR 的增量 commit,merge-tree 可生成 merge tree。

当前仍有这些阻塞项:

  1. CI 已经失败:Check formatting / run_hostcargo fmt --all -- --check 中失败,具体 diff 位于 os/StarryOS/kernel/src/syscall/fs/mount.rs:410 附近;本地 git diff --check origin/dev...origin/pr/1520 也报 test-suit/starryos/qemu-smp1/nix-debug/test-pty-fork-echo/src/main.c:575: new blank line at EOF.。需要先修复格式/whitespace,让基础检查恢复为绿。
  2. apps/starry/nix/test-nix-builder-init 仍是直接提交的 x86_64 static PIE ELF blob(约 47 KiB),不可审查且架构固定。请移除二进制文件,改为从已有 C 源码构建/注入或复用测试构建产物。
  3. README 与实际测试行为仍不一致:文档多处描述 stdenv.mkDerivation source build 和 hello.c -> hello 本地 buildPhase,但当前脚本执行的是 nix-build /opt/nixpkgs -A hello 并允许 binary cache。需要把 README/PR body 同步到实际覆盖范围,或者改测试使目标 derivation 确实本地构建并提供 current-head 证据。
  4. PR 仍是 draft,且变更涉及 mount namespace / pivot_root / clone flags / Nix app 等关键路径;在上面三点修完后,还需要补当前 head 的 app-level Nix 运行证据(至少 x86_64,若声明 aarch64 支持则也需要 aarch64)。

已验证:

  • git merge-tree --write-tree origin/dev origin/pr/1520 可生成 merge tree,无合并冲突。
  • 当前 CI 的失败不是环境误报,而是格式检查直接失败。

Comment thread os/StarryOS/kernel/src/syscall/fs/mount.rs Outdated
Comment thread apps/starry/nix/test-nix-builder-init Outdated
Comment thread apps/starry/nix/README.md Outdated
- Add envp field to ProcessImage/ProcessData, wire through execve/clone/entry
- Add /proc/<pid>/environ entry (NUL-separated env vars from proc_data.envp)
- Add /proc/<pid>/root symlink (reads from proc_data.root_path)
- Add /proc/<pid>/cwd symlink (reads from proc_data.cwd_path)
- Add root_path/cwd_path fields to ProcessData, sync on chdir/chroot/fchdir
  (avoids deadlock: readlink holds FS_CONTEXT lock via with_fs, so symlink
  closures must not re-lock FS_CONTEXT — store path strings in ProcessData
  like exe_path, update in sys_chdir/sys_chroot/sys_fchdir)
- Add test-proc-environ and test-proc-root-cwd to nix-sandbox-debug suite

@ZR233 ZR233 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

当前 head 392e15f 还不能合入。主要 blocker:

  • 与最新 origin/devgit merge-tree --write-tree origin/dev HEAD 时仍在 os/StarryOS/kernel/src/pseudofs/proc.rs 发生内容冲突。
  • 当前 CI 不是绿的:run 28913835238 中 Starry QEMU 多架构失败/取消,Run clippy / run_host 也被取消;其中 x86_64 job 85777025991 已经跑到新增的 qemu-smp1/nix-sandbox,并在 nosandbox 预检 120s 超时后输出 unexpected EOF reading a line。这说明 sandbox/debug case 实际进入了默认 matrix,和 README/PR 描述里的“sandbox 不进 CI/仍为可选”不一致。
  • 之前指出的 x86_64 ELF blob 以及 nixpkgs source build 文档与 nix-build /opt/nixpkgs -A hello(允许 binary cache)之间的不一致仍未解决,已有 inline comment 仍适用。
  • PR 还修改了仓库级 AGENTS.md 加本地 Speckit active plan,这和本功能无关,应移除。

如果想先合入可通过的部分,建议把已完成的非 sandbox/nixpkgs 路径收窄到能稳定通过的 PR;未完成的 sandbox/debug cases 请移出默认 CI 发现路径,或让它们在当前 head 通过,并在 PR 描述里明确已完成/未完成项。

Comment thread AGENTS.md Outdated
Comment thread test-suit/starryos/qemu/nix-sandbox/qemu-x86_64.toml Outdated
silicalet added 3 commits July 8, 2026 14:48
- Split Mountpoint::detach() into detach() (entry, propagates to shared
  peer group members) and detach_from_parent() (internal helper, pure
  parent-children unlink with no propagation). Splitting prevents
  re-entrant cycles since shared peers form a clique — each peer's
  peers list contains every other peer including self.
- Delegate Location::unmount() tree-detach step to Mountpoint::detach()
  so regular umount (not just umount2(MNT_DETACH)) propagates the
  unmount to peer group members, matching Linux UMOUNT_PROPAGATE
  semantics.
- Add two Rust unit tests in mount.rs:
    * detach_propagates_to_shared_peer_group_members
    * detach_private_mount_does_not_propagate
- Add test-mount-propagation C regression test to nix-sandbox-debug:
  mount tmpfs -> make-shared -> bind onto plain dir -> umount source ->
  verify peer disappears from /proc/self/mountinfo.
- Update nix-sandbox-debug qemu-x86_64.toml runner to include the new
  test binary (9/9 tests pass).
- Bump flake.lock.

Note: cross-namespace peer-group propagation requires clone_tree() to
establish bidirectional peer links between original and cloned shared
mounts; clone_shallow() currently copies peer_group_id and propagation
type but not the peers list. That is a separate follow-up outside
Phase 6 scope.
- Add test-pivot-root C regression test exercising the StarryOS
  sys_pivot_root workaround path: absolute new_root/put_old paths
  (kernel does string-based validation), fork-based so the parent
  survives the chroot_fs_refs propagation, probe-file based
  verification (mountinfo-after check skipped because /proc is not
  mounted in the new root). Tests the relaxed is_root_of_mount path.
- Update qemu-x86_64.toml runner loop to include test-pivot-root as
  the LAST entry: pivot_root's chroot_fs_refs propagation repoints
  every task whose root or cwd matched the old root, including the
  runner shell, so subsequent test binaries would fail to exec.
- Document the nix-sandbox-debug regression suite in
  apps/starry/nix/README.md: covered semantics table (10 tests),
  why pivot-root runs last, how to run the suite, runner success
  marker. Cross-references Phase 3-6 fixes.
- Suite verification: 10/10 PASS in CI container on x86_64 (~6s).
- Phase 9 polish gates (run separately): cargo fmt --all --check
  exit 0; cargo xtask clippy on axfs-ng-vfs (2/2), ax-fs-ng (5/5),
  axnsproxy (1/1), starry-kernel (17/17 incl. vsock feature) all
  PASS. Rust unit tests for shared-peer-group propagation 10/10
  PASS.
# Conflicts:
#	os/StarryOS/kernel/src/pseudofs/proc.rs

@ZR233 ZR233 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

复审 a154d179(draft):与 dev 的合并可生成 merge tree,git diff --check origin/dev...HEAD 通过;上一轮的格式意见已不再适用。但当前 head 仍不能合入。

  1. 已有未解决意见仍成立:apps/starry/nix/test-nix-builder-init 是直接提交的 x86_64 static-PIE ELF;仓库应改为从同 PR 的 C 源码/测试产物构建并注入。AGENTS.md 的 Speckit active-plan 也属于本地开发状态,应移出。
  2. README 仍称目标 hello 的 buildPhase 在 StarryOS 本地执行,但 nix-nixpkgs 既配置了 substituters,又没有 --no-substitute;Nix 默认会在可用时使用二进制替代物。因此当前覆盖应如 PR body 所述为 nixpkgs import/eval、derivation realization 与运行,或改为强制且证明确实发生的本地构建。
  3. dev 已将 Starry test wrapper 统一为 test-suit/starryos/qemu/,但本 PR 仍把 Nix sandbox/strace/system 测试放在 qemu-smp1/。当前 head 执行 cargo xtask starry test qemu --arch x86_64 --list 只发现 qemu/qemu/{system,tty-console-input-burst},没有任何 Nix case;PR body 所述的 -c qemu-smp1/system 因此不能作为当前 runner 的验证命令。请迁移到当前布局或同时更新发现/构建逻辑,并在 current head 跑出精确 case。

我也尝试了 cargo xtask starry app qemu -t nix --arch x86_64:流程完成 rootfs 扩容、Nix 2.34.0 与 pinned nixpkgs 的哈希校验,但在向 ext4 逐文件注入完整 nixpkgs tree 时仍未进入 QEMU;为避免长时间占用环境已中止,不能作为通过证据。当前 head 的 Starry QEMU CI 作业也均因并发取消而非成功完成,仍需提供 current-head 的可复现 QEMU 结果。

重复/重叠检查:#1125 已合并;未发现另一个开放 PR 覆盖同一 Nix/nixpkgs 功能。

Comment thread test-suit/starryos/qemu/nix-sandbox/qemu-x86_64.toml Outdated
# Conflicts:
#	os/StarryOS/kernel/src/file/net.rs
#	os/StarryOS/kernel/src/pseudofs/dev/tty/terminal/ldisc.rs
#	test-suit/starryos/qemu/system/bugfix-nix-openat2-resolve/src/main.c
#	test-suit/starryos/qemu/system/test-pty-master-close/src/main.c
#	test-suit/starryos/qemu/system/test-sio-set-ifflags/src/main.c

@mai-team-app mai-team-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

本 PR 将 StarryOS 的 Nix/nixpkgs 应用流程与 system 测试路径扩展到挂载命名空间、传播、pivot_root、mountinfo、cgroup namespace 等内核行为,并调整 axbuild 的 QEMU 分组发现与运行逻辑。改动并非隔离:它影响测试发现/编译这一共享契约,以及 Starry 用户态 syscall/Linux ABI 语义。

本地验证:git diff --check origin/dev...HEAD、相关 Nix 脚本 bash -n 和 reviewer helper 单元测试通过;但 cargo test -p axbuild --lib starry::test::tests::system_case_tests -- --nocapture 在编译 axbuild 的测试目标时失败(E0425,见行内评论),所以相关测试尚未执行。当前 head 的组织 CI 有大量 skipped/cancelled job,且至少一个失败结论;未将其笼统归因于本 PR,但本地可复现的编译失败已足以阻塞。

已检查既有评论:此前关于预编译 blob、Nix 文档语义、CI 覆盖和拆分范围的意见是合理的;当前 head 已不再包含此前指出的 blob,其他历史讨论仍作为上下文。此前 propagation 权限位置的担忧经与 origin/dev 对比确认是 base 已有行为,不作为本轮 finding。

未发现与 mount namespace/Nix 路径直接重复的开放 PR;PR #1125 为依赖/历史上下文而非本轮新增 finding。

剩余阻塞问题:axbuild 测试代码引用了当前树中不存在的 helper,必须先修复并重新运行相关 axbuild 测试。除此之外,完整的 QEMU system/nix 运行在本环境未执行,修复后仍建议以对应 CI/容器流程复验。

Powered by gpt-5.6-terra

request.build_info_override = Some(crate::starry::build::StarryBuildInfo {
max_cpu_num: Some(1),
..crate::starry::build::default_starry_build_info()
..crate::starry::build::default_starry_build_info_for_target("x86_64-unknown-none")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

这里调用的 default_starry_build_info_for_target 在当前 scripts/axbuild/src/starry/build.rs 中不存在(只定义了 default_starry_build_info)。因此 cargo test -p axbuild --lib ... 在编译测试目标时就报 E0425;下面 line 277 还有同一个调用。请改用现有构造函数,或在 build 模块中恢复/实现这个 target-aware helper,并重新运行 axbuild 的相关测试。

@mai-team-app mai-team-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

本 PR 将 StarryOS 的 Nix/nixpkgs app 流程与 mount namespace、挂载传播、pivot_root/proc/*/mountinfo 等内核/VFS 语义一并扩展;这不是隔离改动,会影响 Starry QEMU 测试矩阵和挂载命名空间契约。

阻塞项

  1. axfs-ng-vfs 的新增 mount-tree 单测发生 SIGSEGV(见内联评论)。本地 cargo clippy --manifest-path components/axfs-ng-vfs/Cargo.toml --all-features -- -D warnings 通过,但 cargo test --manifest-path components/axfs-ng-vfs/Cargo.toml --all-features 以 signal 11 退出;单线程 RUST_BACKTRACE=1 ... -- --nocapture --test-threads=1 也稳定在该测试崩溃。
  2. 当前 head 的组织 CI Test starry loongarch64 qemu / run_container 失败:run 29931214002、job 88962912499,执行 target/debug/tg-xtask starry test qemu --arch loongarch64 后退出 1。该矩阵覆盖本 PR 修改的 Starry 内核/VFS 路径,现有信息无法证明失败无关;请取得或复现失败日志、修复对应 case,并在当前 head 上重跑通过。

审查与验证

  • 已完整阅读项目代码质量、feature-development 和 Starry syscall 指南;本 PR 同时新增 Nix app 能力并改变用户可见的 Linux ABI/挂载命名空间语义,均适用。
  • git diff --check origin/dev...HEADcargo fmt --check --all、全部 Nix shell 脚本 bash -n 均通过。
  • 复查了历史评审:早期关于预编译 blob、文档与依赖 PR 的问题在当前 diff 已不再成立;本轮只保留当前 head 可复现的测试/CI 阻塞项。
  • 测试位于 test-suit/starryos/qemu/system/<subcase>/,CMake 布局和 grouped runner 的失败传播已检查;新增 app 流程仍有较大运行时覆盖面,待上述阻塞项修复后应重新执行相应 QEMU 验证。
  • 重叠分析:搜索了 mount namespace / nixpkgs / close_range 相关 open PR;未发现当前实现的直接重复项。历史 #1125 依赖已不再是当前分支的独立合入前置条件。

请先修复内联单测崩溃和当前 head 的 Starry CI 失败,再请求复审。

Powered by gpt-5.6-terra

}

#[test]
fn clone_tree_rebuilds_slave_master_directionality() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

阻塞(回归测试):cargo test --manifest-path components/axfs-ng-vfs/Cargo.toml --all-features 在这个新增的 clone_tree_rebuilds_slave_master_directionality 测试中以 SIGSEGV 退出;单线程 --nocapture 重跑也稳定在此处崩溃。该测试直接覆盖本 PR 新增的 clone/propagation graph 重建逻辑,说明该路径仍有内存或拓扑错误。请先定位并修复崩溃,再提交能跑完该 crate 全部测试的结果。

@mai-team-app mai-team-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

本 PR 将 StarryOS 的 Nix app 工作流扩展到 nixpkgs 阶段,并重构 VFS mount tree/传播、mount namespace、mountinfo 及相关 Linux ABI;同时新增 grouped system 回归测试。该功能属于跨 crate 且改变用户可见 mount/namespace syscall 语义的高风险功能,已按 code-quality.mdfeature-development.mdstarry/syscall.md 审阅。

现有 qemu/system 子用例的 CMake 布局符合当前 grouped-system runner 的发现规则;与 #1125 为顺序依赖而非重复实现,base 中已有早期 namespace/mount 基础。此前关于预编译 blob、文档语义和格式的问题在当前 head 的变更范围中不再适用/已更新。仍有此处的阻塞正确性问题。

验证:

  • cargo fmt --check:通过;git diff --check origin/dev...HEAD:通过。
  • cargo clippy --manifest-path components/axfs-ng-vfs/Cargo.toml --all-features -- -D warnings:通过。
  • cargo test --manifest-path components/axfs-ng-vfs/Cargo.toml --all-features:失败,SIGSEGV;已用单测筛选复现。
  • 当前 head 的组织 CI 有 65 个 check run;部分矩阵已成功或按 runner 条件跳过,但仍有进行中的工作,且本地 VFS 单测失败由本 PR 的 changed surface 直接触发,不能被 CI 状态抵消。

此前评审意见已核对:当前阻塞项是本次在 current head 可重复的新增 VFS 回归测试崩溃;未关闭任何未证实已修复的讨论。请先修复后重新运行 focused 及完整 VFS all-features 测试。除该阻塞项外,本轮未发现需要单列的新增问题。

Powered by gpt-5.6-terra

let bound = Mountpoint::bind(&root_loc, bind_target, false);
assert_eq!(bound.source(), "/dev/vda");

let cloned = root.clone_tree();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

阻塞(正确性):这里新增的 clone_tree() 回归路径当前会直接崩溃。运行 cargo test --manifest-path components/axfs-ng-vfs/Cargo.toml --all-features mount::tests::bind_and_namespace_clone_preserve_mount_source -- --exact --nocapture 时,唯一执行的本测试以 SIGSEGV 退出;完整 VFS all-features 测试也在此处失败。该路径用于 CLONE_NEWNS 的 mount tree 复制,不能在有宿主段错误的状态合入。请定位并修复 clone tree 中的无效所有权/拓扑访问,保留该回归测试并提供 focused 与完整 VFS 测试均通过的结果。

propagate_new_child previously iterated only the source parent's direct
peers and slaves, so a new child under a shared mount A reached B
(slave of A) but never reached C when C was a slave of B or slave of
A's peer. Linux requires transitive forwarding along slave chains, and
the gap left `/proc/*/mountinfo` and mount(2) visibility inconsistent
for topologies set up via namespace clone.

Replace the flat iteration with a DFS over the propagation graph keyed
by `mount_id` (peer groups are cliques, so a visited set is mandatory).
This mirrors `collect_receiving_parents` in unmount.rs and reuses the
existing `propagation_targets()` helper.

Regression coverage:
- Rust unit test `propagate_new_child_reaches_slave_of_slave` (fails
  on the previous implementation, passes after the fix).
- C test `test_clone_ns_transitive_slave_propagation` in
  test-unshare-mount-ns: parent namespace owns src(shared) -> slave,
  child unshares CLONE_NEWNS, parent mounts under src, child verifies
  the propagated mount reaches the cloned slave-of-peer — only
  reachable by walking past the cloned shared peer.

@mai-team-app mai-team-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

审查结论

本 PR 将 Nix/nixpkgs QEMU app 流程、统一 qemu/system 回归用例、mount namespace/传播与 pivot_root、动态 mountinfo,以及多种 namespace 接线一并引入。app 与内核 ABI、VFS 共享状态均会受影响,不能视为隔离的文档或测试改动。

发现 1 个阻塞性 Linux ABI 问题(见行内评论):CLONE_NEWCGROUP 现在会成功创建并切换一个 namespace ID,但没有实现 cgroup hierarchy 的 namespace 视图虚拟化。请在修复后再请求审查。

关键 syscall ABI 核对(Linux 6.x 文档)

Syscall 结论 对应标准 依据
clone 存在问题(F-001) clone(2)cgroup_namespaces(7) CLONE_NEWCGROUP 只产生 ID,未改变 cgroup 视图。
clone3 存在问题(F-001) clone3(2)cgroup_namespaces(7) 复用同一 clone namespace 处理路径。
unshare 存在问题(F-001) unshare(2)cgroup_namespaces(7) unshare(CLONE_NEWCGROUP) 暴露了不完整语义。
setns 存在问题(F-001) setns(2)cgroup_namespaces(7) 切换的仅是 ID,非 namespace-private cgroup view。
mount 本轮未发现独立阻塞项 mount(2) 核对 bind/传播/重挂载新增路径及 system 用例布局。
umount2 本轮未发现独立阻塞项 umount2(2) 核对 normal/detach/expire 分支和传播 unmount 计划。
pivot_root 本轮未发现独立阻塞项 pivot_root(2) 核对新 root/put_old 关系与 namespace 回归用例。

测试与验证

  • git diff --check origin/dev...HEAD 通过;helper 已确认工作区 HEAD 为 a09084ab13b9884ec120922af28240dcf09dd123
  • cargo fmt --all -- --check 因本环境下载 pinned nightly toolchain 的组件后提前结束,未得到可用的本地格式结论;组织 CI 的 Check formatting / run_host 在当前 head 成功。
  • current-head 组织 CI run 29976090455:65 个 checks 中 success=15、skipped=32、cancelled=17、failure=1。格式检查成功,但 workflow 仍为 failure,且本 PR 的 nix app/QEMU 与新的 cgroup 语义没有获得足以替代行为审查的成功证据。该 failure 未作为本评论的独立归因结论。
  • 新增 system C 子用例均采用 system/<subcase>/CMakeLists.txt + src/ 并由根 CMake glob 发现,安装到 usr/bin/starry-test-suit;布局与 runner 一致。test-cgroup-ns 只验证 nsfd inode 的变化,不能验证 F-001。

既有评论与重叠分析

已重新检查旧评论:先前关于提交 ELF blob、README 将 substitution 误称本地 source build、以及旧 qemu-smp1 布局的问题在当前 head 已不再直接适用;当前测试已迁入 qemu/system,Nix 文档/脚本也已反映实际阶段。此前提出的“拆分大 PR”仍值得执行:当前仍为 70 个文件、7702 行新增的跨层改动。

base 中不存在本 PR 的 mount namespace/cgroup namespace 实现。相关开放 PR #1642 明确声明从本 PR 拆出的 cgroup namespace 范围,和这里的 CLONE_NEWCGROUP 改动重叠;应避免两边分别演进同一 ABI,修复语义后请选择一个明确的合入路径。

除 F-001 外,本轮未保留其他活动 finding。

Powered by gpt-5.6-terra

///
/// Cgroup namespaces virtualize the view of the cgroup hierarchy:
/// processes in a new cgroup namespace see their current cgroup as the
/// root of the hierarchy in `/proc/<pid>/cgroup`. This type carries

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

阻塞(cgroup namespace 语义不完整):这里的 CgroupNamespace 只分配并暴露一个 ID;注释也明确说明 hierarchy “managed elsewhere”。当前内核中 cgroup_ns 仅用于 /proc/*/ns/cgroup、nsfd 和 setns 赋值,未参与 /proc/<pid>/cgroup、cgroupfs 或 mountinfo 的视图转换。因此 unshare(CLONE_NEWCGROUP) 后子进程仍会看到与父进程相同的 cgroup hierarchy,和 cgroup_namespaces(7) 所定义的可观察语义不符;新增测试只比较 namespace inode,覆盖不到这个缺口。请实现 namespace-aware 的 cgroup 路径//proc/<pid>/cgroup 渲染并增加父子视图差异的回归测试,或在完整支持前拒绝该 flag。

@ZR233 ZR233 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

本轮复审基于 current head a09084ab13b9884ec120922af28240dcf09dd123。结论仍为 Request changes

仍然阻塞合并的问题

  1. #1644 存在硬重叠,当前 PR 已重新合入拆出的 mount-tree 工作。 #1644 的说明明确写明它从 #1520 拆出,覆盖 mount tree、propagation、namespace clone、mountinfo 及对应 syscall/test;而本 head 又通过多次 merge 把同一组文件和实现带回 #1520#1644 仍处于 open 且 head 继续演进,因此这不是可接受的“相关 PR”,而是两个开放 PR 同时拥有同一实现与测试的重复所有权。请先明确唯一落点:要么让 #1520 基于 #1644 并移除重复提交,要么关闭/合并 #1644 后再更新本 PR,避免两条分支独立修正同一套传播图。

  2. mount-tree 的最低层 host regression 在 current head 稳定崩溃。 cargo test --manifest-path components/axfs-ng-vfs/Cargo.toml --all-features 以 SIGSEGV 结束;以下三个定向用例也都单独以 SIGSEGV 结束:

    • mount::tests::bind_and_namespace_clone_preserve_mount_source
    • mount::tests::clone_tree_rebuilds_slave_master_directionality
    • mount::tests::clone_tree_reconnects_shared_clone_to_source_peer_group

    因此目前不能把新加入的 bind/source preservation、slave/master directionality 和 shared peer reconnection 视为已验证。

  3. Nix sandbox 的 axbuild contract test 仍无法编译。 cargo test -p axbuild nix_sandbox -- --nocaptureqemu_run_tests.rs:247:277 报 E0425:default_starry_build_info_for_target 不存在,测试尚未开始执行。这是上轮阻塞项在新 head 上的直接复现。

  4. host-side prebuild 仍包含环境侵入式 apt-get 路径。 该脚本会修改审阅机/CI host,并假设 Debian/Ubuntu 包管理环境;当前线程对应代码仍未移除或隔离。请改为容器/声明式依赖,或在 runner 明确提供且不修改 host 的工具链。

  5. cgroup namespace 仍只有“namespace inode 不同”的外壳。 当前 CgroupNamespace 没有改变 /proc/<pid>/cgroup、cgroupfs 或 mountinfo 的 namespace-root 视图;unshare(CLONE_NEWCGROUP) 后仍暴露同一层级。现有测试只比较 namespace inode,不能证明 Linux cgroup namespace 的可观察语义。

syscall / ABI 复核

syscall 参考 current-head 判断
mount mount(2) 阻塞:实现与 #1644 重复,传播/clone host tests SIGSEGV
umount2 umount(2) 阻塞:依赖同一 mount graph,最低层回归未通过
pivot_root pivot_root(2) 未发现独立新问题,但其 namespace/mount 依赖尚未通过上述验证
unshare unshare(2) 阻塞:CLONE_NEWCGROUP 只改变 inode,未实现 namespace-root 可见语义;参考 cgroup_namespaces(7)
setns setns(2) 同上,cgroup namespace 状态切换缺少可观察层级语义验证
clone clone(2) mount/cgroup namespace clone 依赖上述未通过路径
clone3 clone(2) clone 共用 namespace 语义,当前证据不足
close_range close_range(2) 未发现本轮新增阻塞,但聚合测试被 axbuild 编译错误挡住
openat2 openat2(2) RESOLVE 路径未发现新的静态问题;current-head contract test 未能执行

本地验证与合并检查

  • cargo fmt --all --check
  • cargo xtask clippy --package axfs-ng-vfs(2/2)
  • ❌ axfs-ng-vfs all-features 与上述三个定向测试:SIGSEGV
  • ❌ axbuild nix_sandbox 定向测试:E0425,未进入测试
  • ✅ GitHub 当前显示 mergeable
  • ❌ 重复/重叠检查:#1644 为硬阻塞
  • ⚠️ 未获得 current-head 的完整 GitHub check-run 列表,本结论不以空状态面替代 CI 证据

请先收敛 #1520/#1644 的所有权,修复最低层 SIGSEGV 与 axbuild 编译失败,并补齐 cgroup namespace 的可观察语义及旧红/新绿回归后再请求复审。

@mai-team-app mai-team-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

本 PR 将 StarryOS 的 Nix/nixpkgs QEMU 应用流程与大量 mount namespace、mount propagation、mount/umount2/pivot_root、clone/unshare/cgroup namespace 的 Linux ABI 变更一并引入,并把回归覆盖放到 test-suit/starryos/qemu/system。这不是 release 版本升级 PR。

审核结论

存在一个可稳定复现的阻塞性测试崩溃,当前不能合入。

验证

  • git diff --check origin/dev...HEAD:通过。
  • cargo fmt --all -- --check:通过。
  • cargo test --manifest-path components/axfs-ng-vfs/Cargo.toml --all-features:失败;启动 31 个测试后测试进程以 SIGSEGV/exit 101 退出。
  • 聚焦命令 cargo test --manifest-path components/axfs-ng-vfs/Cargo.toml --all-features mount::tests::bind_and_namespace_clone_preserve_mount_source -- --exact --nocapture --test-threads=1:同样稳定触发 SIGSEGV
  • 当前 head 的组织仓库 check-runs 为 0,commit status 为 pending 且没有 statuses,因此没有可替代本地失败结果的已通过 CI。

影响与范围

改动并不隔离:新的 namespace-local mount tree、传播关系和 unmount plan 会影响现有 mount(2)umount2(2)pivot_root(2)unshare(2)clone(2)/clone3(2)/proc/*/mountinfo 可见行为。此次新增的 system C 测试位于正确的 qemu/system/<subcase>/CMakeLists.txt + src/ 布局,根 CMake 的 glob 会发现它们;不过当前 VFS crate 的基础单测已经崩溃,不能视为覆盖有效。

syscall/ABI 核对

已按 Starry syscall 指南检查直接受影响入口:mount(2)umount2(2)pivot_root(2)unshare(2)clone(2)clone3(2)setns(2)。实现意图分别涉及 Linux mount propagation、mount topology、namespace 创建/切换与错误返回;对应参考为 mount(2)umount2(2)pivot_root(2)unshare(2)clone(2)setns(2)。由于新增 mount-tree crate 测试本身发生 SIGSEGV,以上入口的完整行为兼容性尚无法确认;先修复崩溃并重新运行 crate/QEMU 回归是继续审查的前提。

历史、重叠与剩余风险

已阅读之前的 review/PR 讨论。此前关于预编译 blob、Nix 文档与实际 binary-substitution 行为、以及依赖 #1125 的问题是合理历史上下文;当前 head 已移除该 blob,并将 README 描述更新为允许 substitution 的 nixpkgs realization,因此本轮没有重复这些旧 finding。PR body 仍说明它与 #1125 有序列依赖,且 base 分支未包含等价的 mount namespace 实现;搜索 mount namespace/mountinfo/close_range/nix 的开放 PR 后,未发现能替代本 PR 当前 mount-topology 改动的直接重复项。

修复 SIGSEGV 后,请至少提供完整 axfs-ng-vfs 测试、受影响 qemu/system case 的 current-head 运行结果,并补充可审查的多架构/CI 证据。

Powered by gpt-5.6-terra

}

#[test]
fn bind_and_namespace_clone_preserve_mount_source() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

【阻塞 / 正确性】这个新增用例本身会让测试进程崩溃:cargo test --manifest-path components/axfs-ng-vfs/Cargo.toml --all-features mount::tests::bind_and_namespace_clone_preserve_mount_source -- --exact --nocapture --test-threads=1SIGSEGV(exit 101)退出,完整 crate 测试也在启动 31 个用例后以相同方式失败。请先定位 mock reference/目录构造或 mount clone 路径中的无效内存/生命周期问题,修复后保留可正常完成的回归用例,并提供完整 crate 测试通过结果。

@silicalet

Copy link
Copy Markdown
Contributor Author

cgroup疑似有另一个pr在搞,我计划只实现到能满足nix的需要即可

# Conflicts:
#	components/axfs-ng-vfs/src/mount/mod.rs
#	flake.lock
#	os/StarryOS/kernel/src/syscall/fs/mount.rs
#	test-suit/starryos/qemu/system/test-mount-bind/src/main.c
#	test-suit/starryos/qemu/system/test-mount-propagation/src/main.c
#	test-suit/starryos/qemu/system/test-per-ns-mounts/src/main.c
#	test-suit/starryos/qemu/system/test-pivot-root-namespace/src/main.c
#	test-suit/starryos/qemu/system/test-pivot-root/src/main.c
#	test-suit/starryos/qemu/system/test-remount-flags/src/main.c
#	test-suit/starryos/qemu/system/test-unshare-mount-ns/src/main.c

@mai-team-app mai-team-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

本 PR 将 StarryOS 的 Nix/nixpkgs 应用流程、cgroup namespace 与多项 namespace/mount/syscall 回归测试合入统一的 qemu/system suite。影响面包含 namespace ABI、/proc 展示以及 grouped-C 测试安装/发现契约,不能视为隔离改动。

发现两个阻塞问题:新增的 cgroup namespace 与 namespace-limit 回归测试使用绝对 CMake 安装目录,绕过 runner 的 DESTDIR=<guest overlay>;因此它们会写入构建主机而不会进入 QEMU guest,新增覆盖实际上不执行。

验证:

  • git diff --check origin/dev...HEAD 通过。
  • cargo fmt --all -- --checkcargo test --manifest-path os/StarryOS/axnsproxy/Cargo.tomlcargo clippy --manifest-path os/StarryOS/axnsproxy/Cargo.toml --all-features -- -D warnings 通过。
  • 以 grouped-C runner 相同的 CMake/DESTDIR 安装新增子项,确认其余相对 DESTINATION 的二进制进入 overlay,而两处绝对 DESTINATION 写入宿主机 /usr/bin
  • 当前 head 的组织 CI:59 个 check run 中 13 成功、1 失败、16 cancelled、29 skipped;失败/取消的 Starry QEMU 相关检查尚未提供可证明与本变更无关的结论,未将其作为本次独立 finding。

已查看历史 review/comments:此前关于预编译 blob、文档和格式的具体问题不再对应当前 diff;现有合理意见仍要求新增 system 覆盖必须由 runner 真正发现。本 PR body 所称的 cgroup 相关开放 PR 与检索到的相关 PR 存在重叠风险;本结论基于当前 diff 中可复现的安装缺陷。

请先修正以下内联问题并在 guest 中验证这两个测试确实由 /usr/bin/starry-test-suit/* 执行。

Powered by gpt-5.6-terra

add_executable(test-cgroup-ns src/main.c)
target_link_libraries(test-cgroup-ns c)

install(TARGETS test-cgroup-ns DESTINATION /usr/bin/starry-test-suit)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

阻塞:这里的绝对 DESTINATION /usr/bin/... 绕过了 grouped-C 安装阶段设置的 DESTDIR=<guest overlay>。我用相同的 CMAKE_INSTALL_PREFIX=/DESTDIR 安装验证时,这个目标实际写到了构建主机 /usr/bin/starry-test-suit/test-cgroup-ns,而不是 overlay;QEMU 的 system wrapper 只扫描 guest 内 /usr/bin/starry-test-suit/*,因此此回归测试不会被发现或执行。请改为相对路径 usr/bin/starry-test-suit(与其余 system 子项一致),并让 discovery 测试拒绝绝对 DESTINATION。

add_executable(test-max-ns-entries src/main.c)
target_link_libraries(test-max-ns-entries c)

install(TARGETS test-max-ns-entries DESTINATION /usr/bin/starry-test-suit)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

阻塞:此处也不能使用绝对安装目录。grouped-C runner 用 DESTDIR=<overlay> 收集 guest 文件;实测本目标被安装到宿主机 /usr/bin/starry-test-suit/test-max-ns-entries,没有出现在 overlay,因此 QEMU 不会执行该新增回归测试。请改成相对 RUNTIME DESTINATION usr/bin/starry-test-suit,保持与 system suite 其他子项相同的安装契约。

@mai-team-app mai-team-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

本 PR 将 Starry Nix 应用扩展为 sandbox/nixpkgs 三阶段执行,并同时接入 cgroup namespace、devpts、namespace/procfs 以及多项 qemu/system 回归测试;因此并非 isolated 的应用脚本调整,而是会影响 StarryOS 的 clone/unshare/setns、/proc 与 cgroup 可见性契约。

阻塞问题

  1. cgroup namespace 的核心可见性语义尚未实现(见内联评论)。当前实现只改变 namespace ID,/proc/<pid>/cgroup 仍固定返回 0::/,所以 Nix 的能力探测可能通过,但真实依赖 cgroup namespace 视图隔离的程序会得到错误结果。新增测试仅验证 namespace inode,不能捕获该问题。

  2. 与 open PR #1642 重复:#1642 明确从本 PR 拆出了同一 cgroup namespace 实现,涵盖 CgroupNamespace、clone/unshare/setns、/proc/<pid>/ns/cgroup、namespace limit 文件及相同两项 system 测试。请只保留一个实现:从本 PR 移除该部分并明确依赖 #1642,或关闭/替换 #1642 后将唯一实现作为独立、可验证的变更提交;其余 Nix 改动应重基到清晰依赖链。

审查与验证

  • 已完整阅读代码质量、功能开发和 Starry syscall 领域指南;本 PR 为跨越用户可见 syscall/ABI 与应用工作流的高风险功能扩展,PR 描述虽给出 Nix 场景和命令,但 cgroup namespace 的语义/隔离设计材料与可覆盖核心行为的测试不足。
  • 已检查默认分支实现、当前 diff、既有 review/讨论和关联 open PR;先前关于拆分小 PR、可审查范围的建议仍然适用。#1642 是明确的重复/冲突风险;未将它视为可忽略的标题匹配。
  • git diff --check origin/dev...HEAD、所有 Nix shell 脚本 bash -n 通过;新增 grouped C 子目录布局符合当前 qemu/system/<subcase>/CMakeLists.txt + src/ 结构。未发现 [patch.crates-io]
  • 本地 cargo fmt --checkcargo test --manifest-path scripts/axbuild/Cargo.toml --lib starry::app::tests::qemu --no-default-features 因 rustup 下载 pinned nightly 组件时重命名 partial 文件失败而无法执行(非代码诊断)。
  • 当前 head 的组织 CI run 30058310042 已结束且结论为 failure;格式、sync-lint、spin-lint 已成功,但许多矩阵 job 被 skipped/cancelled,不能作为 Nix app 与新增 QEMU/system 行为通过的证据。CI 不是本评论唯一阻塞依据,但修复后需提供当前 head 的实际 QEMU 运行证据,尤其是文档声明的 cargo xtask starry app qemu -t nix --arch <arch> 和相关 qemu/system 用例。

在上述问题解决前不建议合入。

Powered by gpt-5.6-terra


/// Per-process cgroup namespace.
///
/// Cgroup namespaces virtualize the view of the cgroup hierarchy:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

阻塞:这里的实现只生成 namespace ID,但没有实现 cgroup namespace 的核心视图隔离。/proc/<pid>/cgroup 仍在 pseudofs/proc.rs 无条件返回 0::/,既不保存创建 namespace 时的 cgroup 根,也不按 setns 后的 namespace 重写路径;因此 CLONE_NEWCGROUP 只会让 /proc/self/ns/cgroup 的 inode 变化。现有 test-cgroup-ns 也只断言 inode,覆盖不到这个行为。请把 cgroup 根/路径映射接入 proc/cgroupfs 并增加可失败的 /proc/self/cgroup 可见性测试;如果本 PR 只想满足 Nix 探测,请不要把该 flag 宣传为已完成的 namespace 实现。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

是这么着的,但是我发现有别的pr在搞cgroup, 因此不打算实现这个,除了cgroup其他拆出来的pr都已经合入。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

cgroup拆出pr应该是1642

@mai-team-app mai-team-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

本 PR 将 Nix/nixpkgs QEMU app 流程、若干 system 回归用例与 StarryOS namespace/cgroup 相关 syscall 路径一并扩展;其中 cgroup namespace 是用户可见的 Linux ABI 新能力,按 feature-development.md 属于高风险共享内核语义。本轮发现其实现仍只有 namespace 标识符,不能满足所声明的隔离契约,因此暂不能合入。

阻塞问题

  • CLONE_NEWCGROUP/unshare/setns 已被改为成功,但没有实现 cgroup namespace 的根和可见性重写。Linux cgroup_namespaces(7) 要求创建时所在 cgroup 成为 namespace 内的 /;当前 /proc/<pid>/cgroup 固定输出 0::/,cgroupfs 仍从全局 root_id() 建树,均没有使用 NsProxy::cgroup_ns。现有新增测试只验证 /proc/self/ns/cgroup inode 变化,无法捕获该行为缺失。请实现 namespace root 在 proc/cgroupfs 中的路径/可见性转换并增加直接 ABI 回归测试;若当前范围只需要占位,应继续对该 flag 返回不支持。

审查与验证

  • 已阅读 base 的 AGENTS.md、代码质量/功能开发/Starry syscall 指南及 Starry app/test-suite 规则。该 PR 改变 cloneunsharesetns 与 proc/cgroup 可观察语义,syscall 指南适用;上述问题正是其要求的 namespace 共享与可观察结果不一致。
  • 已核对 base:devCLONE_NEWCGROUP 明确未实现;未发现等价 base 实现。相关 open PR 搜索未找到可替代本实现的 cgroup namespace PR;#1125 是此 Nix 工作的前序/重叠历史上下文而非此 finding 的修复。
  • 本地通过:cargo fmt --checkcargo test -p axnsproxycargo clippy -p axnsproxy --all-targets -- -D warningsbash -n apps/starry/nix/{prebuild,nix,nix-nixpkgs,nix-nosandbox,test_nix}.shgit diff --check origin/dev...HEAD
  • 当前 head 的组织 CI 有成功、跳过、取消以及一个 ArceOS loongarch64 失败项;本轮未将该失败归因于本 PR。无论 CI 状态如何,上述 cgroup ABI 缺失可由静态调用链和现有测试覆盖缺口直接确认。
  • 已查看历史 review/comments:此前关于预编译 blob、README 与实际 nixpkgs 行为、格式等评论对应文件/状态已有变化;本轮未重复这些已过时或不再适用的阻塞点。除本文问题外,Nix app 与 system 测试的布局符合 app/test-suite 分层,仍建议在修复后运行文档中的实际 QEMU app 与 qemu/system 回归流程验证。

现有问题未解决前,请保持该 review thread 开放。

Powered by gpt-5.6-terra

///
/// Cgroup namespaces virtualize the view of the cgroup hierarchy:
/// processes in a new cgroup namespace see their current cgroup as the
/// root of the hierarchy in `/proc/<pid>/cgroup`. This type carries

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

阻塞(Linux cgroup namespace 语义):这里新增的 namespace 只有 ID;注释也明确层级“由其他地方管理”。但本 PR 同时让 clone/unshare/setns(CLONE_NEWCGROUP) 成功并暴露 /proc/*/ns/cgroup。Linux 的 cgroup namespace 必须把创建时所在 cgroup 虚拟为该 namespace 的 //proc/<pid>/cgroup(以及 cgroupfs 的可见层级)都必须按这个根重写。当前 pseudofs/proc.rs 仍把所有进程固定渲染为 0::/pseudofs/cgroup.rs 仍从全局 root_id() 建树,二者均未读取 NsProxy::cgroup_ns;现有测试只比较 namespace inode,因而在没有任何 cgroup 隔离时也会通过。请保存 namespace root 并在 proc/cgroupfs 路径中应用它,补直接 ABI 回归测试;否则应继续返回不支持,而不是把该 flag 宣称为可用。

@mai-team-app mai-team-app Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

本 PR 将 Starry Nix 应用流程、多个内核 namespace/挂载相关 ABI 变更及 qemu/system 回归用例合在一起;目标是让 Nix/nixpkgs 流程可运行。该变更不是 release 版本升级,feature-development.md 适用:它属于跨层、共享的高风险能力,但当前仍有重复实现,不能合入。

阻塞问题

  • cgroup namespace 改动与开放 PR #1642 重复。#1642 明确说明它从本 PR 拆出,并覆盖同一 CgroupNamespaceCLONE_NEWCGROUP/setns、proc namespace 项及 test-cgroup-nstest-max-ns-entries。请先保留一个原子 PR(建议完成 #1642),再让本 PR rebase 到最新 dev 并删除已覆盖的实现和测试;否则两个 PR 会重复改变同一 Linux ABI,带来合并与后续维护冲突。

验证与审查范围

  • 已完整核对代码质量、功能开发和 Starry syscall 指南;新 C 用例位于当前 qemu/system/<subcase>/ 的可发现布局,聚合 CMake 会纳入对应目录,失败传播由现有 grouped runner 处理。
  • 本地:git diff --check origin/dev...HEAD、Nix shell 脚本 bash -n 通过;review helper 的 7 个自测通过,且已验证 workspace HEAD 为 b17713ffc0973292ed9e0b24aa8cb7d13ae4e1e5cargo fmt --check 在本环境尝试安装 pinned nightly 时仅完成工具链同步/下载即退出,未获得本地格式结论;组织 CI 的 Check formatting / run_host 已成功。
  • 当前组织 CI 共 61 个 check runs:27 成功、30 跳过、3 取消、1 失败;失败项是 Test starry loongarch64 qemu / run_container,属于本 PR 修改的 Starry 内核/测试范围,因此不能作为无关失败忽略。即使重复问题修复,也需要对该 current-head 失败重新验证。
  • 已检查既有审查意见:历史的预编译 ELF 和旧 README/nixpkgs 描述问题已不再位于当前变更文件;此前关于拆分过大改动的意见仍与本次发现一致。#1644 是 mount 语义的独立拆分;#1642 则与当前 cgroup namespace 代码直接重叠。

除上述阻塞项外,本轮未增加其他独立 finding。

Powered by gpt-5.6-terra

@@ -0,0 +1,41 @@
use alloc::sync::Arc;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

阻塞|重复实现。 这里开始的 cgroup namespace 实现及对应测试已经被拆分到开放的 #1642#1642 的说明也明确写明其从本 PR 拆出,并覆盖 CgroupNamespaceCLONE_NEWCGROUP/setns、proc namespace 条目及 test-cgroup-nstest-max-ns-entries。两个 PR 同时保留会重复修改同一 Linux ABI,并在合并时产生冲突。请先保留并完成一个原子 PR(建议 #1642);本 PR rebase 后删除已由它覆盖的实现和测试,只保留 Nix 集成所需的增量。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

何意味,1642就是我提的,已经标明了两个pr的关系

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants