Repository navigation
fix(rocm): let the hsaco disk cache trust a container volume root - #3530
Conversation
Implementation Review SummaryIntent
Findings Addressed
Remaining Items
Verification
Notes: the descent, root split and entry-ref code is a faithful copy of |
Security and performance reviewNo CRITICAL or HIGH findings, so no commits from this pass. Checked: the trusted-root split on the path as given (shortest matching prefix), the LOW (no fix, none reachable by another uid today):
Verification: |
The ROCm kernel cache refused any directory under a group- or other-writable component, so on a Kubernetes volume root (root-owned 0777, or group-writable through fsGroup) it was always off and every pod start recompiled its kernels. This applies the two rules of #3503 to it. - Rule 1: a component only its group can write passes when that group is the gid handed over by the new set_hsaco_cache_trusted_group bridge setter, which ensure_hsaco_cache_trust calls at startup of mlxcel and mlxcel-server with the effective gid only when private_group proves it private. - Rule 2: MLXCEL_CACHE_TRUSTED_ROOT is split on the cache path as given; the new hsaco_cache_dir_trust.h (a copy of the CUDA ptx_cache_trust.h, since a ROCm build never sees the CUDA overlay) descends below it with openat(O_NOFOLLOW), keeps the directory above <arch> so later architectures open from it, and pins the <arch> descriptor so entries are read and published, and nested directories created, through it. The sibling-rename residual and Rule 1's blindness to pod-spec groups carry over and are documented. The host test gains rocm_hsaco_cache_test_trust.inc for both rules, and the TTFT harness takes --backend rocm. Refs #3527
Five runs per cell of mlxcel-server with Qwen3-4B-4bit on Strix Halo: both rules of #3527 turn a refused ROCm kernel cache into a second-start hit, shown by the cache files (published on every cold run, untouched on every warm run), and main refuses the same directories. The model JIT-compiles one module there, so no time saving was measurable. Root-owned roots could not be made on the host (no sudo, docker or newuidmap). Refs #3527
With MLX_HSACO_CACHE_DIR equal to MLXCEL_CACHE_TRUSTED_ROOT the kept parent is the root's own descriptor. The host test now checks that entries are read and published through the pinned <arch> after it is swapped, and that a second architecture opens from the root. The benchmark record states what was observed (one published module) and adds the mlxcel generate start-up check. Refs #3527
Off Linux the cfg-gated block drops out and the function body was only `if !cfg!(feature = "rocm") { return; }`, which clippy's needless_return rejects under `-D warnings`. The PR's clippy job runs on Linux only, so this would first fail in the nightly macOS `make verify` and for anyone running the documented lint locally on Apple Silicon.
The feature check now sits inside the Linux block, so behavior is unchanged on every platform. Checked with a standalone crate of the same shape: the old form fails `cargo clippy -- -D warnings` on macOS, the new form passes with and without the feature, and with the gate emulated as `unix`.
Refs #3527
With MLX_HSACO_CACHE_DIR equal to MLXCEL_CACHE_TRUSTED_ROOT each <arch> sits directly in the root, so the sibling-rename window reopens for every architecture until it is first resolved. The header and the env-var row say so, and the header notes that the cache path is normalized lexically, as in the CUDA copy. Raised as LOW in review. Refs #3527
d887133 to
2feeca7
Compare
Bilingual reports for the eight PRs of epic #3488: #3508 (graceful drain), #3509 (CUDA PTX cache trust), #3530 (ROCm hsaco cache trust), #3540 (NVRTC redistributable headers), #3543 (CUDA container image), #3549 (Helm chart), #3550 (GHCR image publishing) and #3554 (chart OCI publishing and docs). Each report names what the PR record leaves unvalidated: a real GHCR push, a GPU pod on a cluster, the amd64 and debug images. The HuggingFace cache follow-up is #3570.
Summary
The ROCm kernel (hsaco) disk cache refused any directory under a group- or other-writable component, so on a Kubernetes volume root (root-owned
0777, or group-writable throughfsGroup) it was always off and every pod start compiled its kernels again. This applies the two rules of #3503 (merged in #3509) to it, POSIX only.set_hsaco_cache_trusted_group.mlxcel_core::ensure_hsaco_cache_trust()calls it at startup ofmlxcelandmlxcel-serverwith the effective gid, only whenprivate_groupproves it private. The ROCm header resolves its directory itself, so this is a separate startup call next toensure_persistent_ptx_cache.MLXCEL_CACHE_TRUSTED_ROOTis split on the cache path as given, before anything is resolved, created or repaired. Every component below the root is opened withopenat(O_NOFOLLOW)and created0700if missing. Each must be owned by the current user (root does not count) with no group or other write. The directory above<arch>is opened once per process and kept, so a second GPU architecture is opened from it instead of descending from the root again. The<arch>descriptor is pinned, and entries are read, published (openat,renameat,unlinkat) and nested directories created through it. An unusable value printsmlxcel: MLXCEL_CACHE_TRUSTED_ROOT ignored: <reason>once and the walk applies.hsaco_cache_dir_trust.h, a copy of the CUDAptx_cache_trust.hadapted to this cache. It is not shared because a ROCm build never sees the CUDA overlay, and onlyoverlays/core(upstream-provenance files) reaches every build. CUDA code is untouched. The Windows branch keeps its signatures and is unchanged.MLX_HSACO_CACHE_DIRequal to the trusted root, each<arch>sits directly in the root, so that window stays open until each architecture is first used.For the owner
docs/installation.mdwas edited beyond the twoenvironment-variables.mdrows the issue names. The ROCm "Kernel disk cache" section said a group-writable explicit directory is always refused, which is no longer true. One paragraph was added there, which may touch the same file as feat(docker): Add CUDA container image with mlxcel and mlxcel-server #3484.newuidmapon the host. Rule 2 never judges the root's owner, and the walk treats root and the current user alike, so the mode is what decides. The root-owned cases (02775with the trusted gid, a root-owned component below the trusted root) are covered by the host test.Changes during review
ensure_hsaco_cache_trustkeeps itsrocmcheck inside the Linux block, so a macOS clippy run does not reject the body asneedless_return(found by review, checked with a standalone crate; the halo clippy run predates this reshape).Test plan
scripts/mlxcelverse/rocm_hsaco_cache_test.sh(macOS clang and Debian gcc 14,-Werror). Newrocm_hsaco_cache_test_trust.inccovers both rules: a symlink planted at the first component below the root, a root-owned component below it, entries read and published through the pinned descriptor after the path is swapped, a second architecture from the kept parent, and a root that is the direct parent of<arch>. Eight deliberate rule breaks each fail it.scripts/mlxcelverse/cuda_runtime_dir_test.sh,make verify-rocm-overlay, env-var and native-env checkers,cargo clippy --release --features rocm -p mlxcel-core --lib -- -D warningson halo.mlxcel-serverwith Qwen3-4B-4bit, five runs per cell. On the second start, under a0777root with the opt-in and under a2775root of the private gid, the server read the three published cache files and changed none.mainand the branch without the opt-in refused with one line and cached nothing.mlxcel generatewas checked the same way. Timing showed no difference because this model JIT-compiles one module. Record:docs/benchmark_results/hsaco-cache-trust-gfx1151-2026-11-29.md.lib.rschange, a multi-architecture GPU host, and a real Kubernetes pod.Closes #3527