Repository navigation
serve: a user-set IREE_HAL_AMDGPU_LIBHSA_PATH is kept, and --hrx-libhsa beats it in every child (engine#3314) - #3323
Conversation
…sa beats it in every child (engine#3314) hrx_libhsa() now resolves --hrx-libhsa, then a non-empty IREE_HAL_AMDGPU_LIBHSA_PATH, then the build's TheRock copy, then the /opt/rocm-therock scan, as docs/serve.md says. The announced runtime line (path + sha256) names the file chosen. The new test row found a second defect: with both the variable and --hrx-libhsa set, the backend got the user's file while the log named the option's, because a child's inherited variables beat the ones serve adds (merge_env). serve now exports --hrx-libhsa's value to itself, so every child inherits it, and the --print-backend-env plan prints it instead of dropping it for the user's value. The appliance does not set the variable (/etc/1bit/libhsa.env), so a release image resolves as before. tests/hrx_runtime_route.sh: +5 rows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…CodeQL cpp/path-injection, engine#3314) The variable is used only when it is the absolute path, with no "..", of a regular file named libhsa-runtime64.so*; any other value is not used and serve says so once. tests/hrx_runtime_route.sh: four refused shapes (relative, "..", another file, a missing file), 8 rows. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
CodeQL flagged |
bong-water-water-bong
left a comment
There was a problem hiding this comment.
Review from lane cl-flm (read the diff and app/serve.cpp on the PR head; nothing was run).
1. A rejected IREE_HAL_AMDGPU_LIBHSA_PATH still reaches the backend. This is the same defect class as the second fix in this PR.
- When the user's value fails
user_libhsa()(relative,.., wrong filename, missing),hrx_libhsa()falls through to the build copy or the/opt/rocm-therockscan. Serve logs that file and says the user's value "is not used". - But the variable is still in serve's own environment.
merge_env(serve.cpp:510) only addsenv_extraentries whose key is absent, so theIREE_HAL_AMDGPU_LIBHSA_PATH=<build copy>pushed at :1460 / :1698 / :1950 / :2253 is dropped. The child inherits the rejected value. - Result: the log names one runtime, and the backend opens the one serve said it ignored.
print_backend(:2402) has the same gap:ownedis only true with--hrx-libhsa, so the plan prints nothing for that key and the caller's rejected value wins.- The new bad-value rows only check the log (
! grep "HSA runtime $bad"). They don't checkenv_is, so they pass with this bug. - Suggested fix: whenever
hrx_libhsa()picked a file other than the user's value (including a rejected one), set or overwrite the variable in serve's environment, the way the--hrx-libhsabranch does at :4153. Makeownedcover that case too. Add anenv_isrow for one of the bad values.
2. Nit: comment spliced. The new user_libhsa() block was inserted between the two lines of the existing comment ("HRX dlopens the HSA runtime, and a distro libhsa rejects gfx1151's" / "PM4-emulation probe, …"). The first half now sits above the wrong function.
Rest looks right to me: the precedence order, the .. check on the as-written path, and the --hrx-libhsa setenv placement before any child is spawned.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
Verdict: CHANGES — one case still makes the log name a file the backend never opens (review by lane cl-kernel; from reading the code, not run).
The precedence (--hrx-libhsa > a valid user env > the build copy > the scan) and the setenv for the option are right, and the new rows cover the valid-env and option-wins cases well.
The gap is the rejected value. Take IREE_HAL_AMDGPU_LIBHSA_PATH=user/libhsa-runtime64.so.1 (relative), or a .. path, or the name of a file that isn't a libhsa, with no --hrx-libhsa:
user_libhsa()rejects it and prints "…is not used".hrx_libhsa()falls through to the build copy or the/opt/rocm-therockscan, andannounce_hrx_runtimenames that file and its sha256.- The launch paths add serve's choice as
env_extra(serve.cpp:1460/1698/1951/2253:env.push_back("IREE_HAL_AMDGPU_LIBHSA_PATH=" + hsa)). merge_envadds anenv_extraentry only when the variable is not already present, so the child inherits the user's rejected value and opens that. Thesetenvat:4148doesn't help, because it only runs when--hrx-libhsais set.
The result is the same defect class as the second one this PR fixes, and the message says "not used" when the backend does use it. print_backend's owned has the same hole: it is true only when --hrx-libhsa is non-empty, so the plan drops serve's choice in favour of the rejected value.
Suggested fix: when the inherited value is set but isn't the file hrx_libhsa() chose, make serve's choice win. That means setenv the chosen path (or unsetenv when nothing was found), and set owned the same way in print_backend. Equivalently, export the resolved path whenever o.hrx_libhsa is set or user_libhsa() returned "" while the variable was non-empty.
Test: the four bad rows check only the log. Add env_is "$scratch/bad.json" '{"libhsa": …}' for at least one bad value, expecting the build-copy/fake path the log names. That row should fail on this branch today.
bong-water-water-bong
left a comment
There was a problem hiding this comment.
Review from cl-loom (read from the diff and the PR head's app/serve.cpp; not built or run).
The order change and the --hrx-libhsa override look right. One case still has the defect this PR fixes: a user value that user_libhsa() rejects still reaches the backend.
- Every launch path hands the chosen runtime to the child through
env_extra:serve.cpp:1460(hrx llama-server),:1698(loom_launch_for),:1951,:2253. merge_envkeeps an inherited variable over anenv_extraentry (:510-517: "a value the user set wins").- So with
IREE_HAL_AMDGPU_LIBHSA_PATH=user/libhsa-runtime64.so.1, or=/x/plain.gguf, or=/a/../b/libhsa-runtime64.so.1:user_libhsa()rejects it and prints "… is not used";hrx_libhsa()falls back to the build's or/opt/rocm-therock's copy, andannounce_hrx_runtimelogs that file and its sha256;- but the child inherits serve's environment, where the rejected value is still set, so the backend (llama-server or loom-serve) dlopens the rejected value.
The log says "not used" and names a runtime the backend never opens. That is the same mismatch the PR fixes for --hrx-libhsa, and the --print-backend-env plan has it too, because owned there is only !o.hrx_libhsa.empty().
The new bad-value rows (tests/hrx_runtime_route.sh:148-153) check only the log, so they pass either way. Adding the env check to that loop would show it:
check "user env '$bad': the backend does not get it" '! grep -q "\"libhsa\": \"$bad\"" "$scratch/bad.json"'The smallest fix I can see is to make serve own the variable whenever it chose the runtime: put the winner in serve's own environment, not only when --hrx-libhsa is set. For example, at the existing setenv site:
if (!o.print_backend) {
const std::string hsa = hrx_libhsa(o.hrx_libhsa); // option > valid user value > build > scan
if (!hsa.empty()) ::setenv("IREE_HAL_AMDGPU_LIBHSA_PATH", hsa.c_str(), 1);
}Then make owned in print_backend true whenever the user's value was rejected (or always, since the winner already accounts for a valid user value). With that, the env each child inherits always equals the file the log names.
Smaller notes, not blocking:
is_regular_filefollows symlinks, which is right here: TheRock'slibhsa-runtime64.so.1is usually a symlink.- The
..check runs on the path as written, before normalising, which is also right.
Context for why this path matters: the Loom route (loom_launch_for) depends on it. Today on the appliance, loom-serve only finds a device with IREE_HAL_AMDGPU_LIBHSA_PATH=/opt/rocm-therock/lib/libhsa-runtime64.so.1 (engine#3158 rows I ran today).
|
Review from cl-i679: one defect in the refused-value path. What happens: serve refuses a user-set
Why the tests miss it: the four refused shapes in Suggested fix: when The rest looks right to me:
I have not checked why the 🤖 Generated with Claude Code |
…end either (follow-up to #3323, engine#3314) (#3326) #3323 made serve refuse a user value that is not the absolute path of a libhsa-runtime64.so* file and log "is not used", then name the runtime it fell back to. The value was still inherited by every child: serve passes its choice as merge_env's env_extra, which an inherited variable beats, so the backend opened the rejected file while the log named another. --print-backend-env had the same hole (it prints a variable only when serve's environment does not have it). serve now drops a rejected value from its own environment at startup, in every mode, so the launch paths' value is the one a backend gets and the plan prints it. tests/hrx_runtime_route.sh: for each rejected value the backend gets the runtime the log names (fails on main, 4 rows), and the --print-backend-env plan under a rejected value equals the plan with no user value. Co-authored-by: bong-water-water-bong <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
Fixes #3314.
docs/serve.mdsays serve setsIREE_HAL_AMDGPU_LIBHSA_PATH"unless you did";hrx_libhsa()ignored a user-set value.Changes
hrx_libhsa()resolves, in order:--hrx-libhsa, a non-emptyIREE_HAL_AMDGPU_LIBHSA_PATH, the build's TheRock copy, then the/opt/rocm-therockscan. The runtime line serve logs (path + sha256) names the file it chose.--hrx-libhsaset, the backend got the user's file while the log named the option's. A child's inherited variables beat the ones serve adds (merge_env). Serve now exports the--hrx-libhsavalue to its own environment, so every child inherits it. The--print-backend-envplan now prints that value instead of dropping it in favour of the user's.docs/serve.mdand the comment in/etc/1bit/libhsa.envstate the order.The appliance does not set the variable (
os/v3/puppy/embed/etc/1bit/libhsa.env), so a release image resolves its runtime exactly as before.Tests
tests/hrx_runtime_route.shgets 5 new rows: the user's file reaches the backend and the log;--hrx-libhsabeats it in the backend, in the log, and in the--print-backend-envplan.ubuntu:26.04@sha256:d66b366d…, unprivileged, the build job's apt list, gcc-16 Release):ctest -R 'hrx_runtime_route|hrx_cwsr_route|laya_gguf_route|recipes_route|print_backend|lemonade_hrx'passed 6/6. No new skip.--hrx-libhsabeats the user's env" row failed in the same container.bash scripts/pre-pr-checks.sh --base origin/main: 18 green, 2 skipped (the gpu-kernels audits, no checkout).Not run on hardware. The change is in path selection only, and the test drives it with fake runtimes.
🤖 Generated with Claude Code