Repository navigation
ci: run lance-linalg's tests under AddressSanitizer nightly - #8878
Conversation
1044ea5 to
765955a
Compare
|
Revised after another review pass, which found the justification overstated and two steps dead. "a write past the end is bounds-checked nowhere" was false, and the code says so: The The protoc step is gone too. |
765955a to
ec9d4de
Compare
|
A fourth pass asked a question I had not: the job claims it makes an overflow "fail with a file and a line", and nothing had ever exercised the failure path. So I planted a deliberate out-of-bounds store on a fork branch and looked at what the log actually says. It was detected and unusable. Bare hex addresses and module offsets, no function names, no line numbers: ubuntu-24.04 ships The same exercise found a coverage limit I have added to the body rather than papered over. My first attempt planted the store in Also from that pass: Two suggestions from it I am declining, with reasons. Notifications: no job in this workflow has any, and adding issue-filing on failure would need |
ec9d4de to
4e924c3
Compare
|
One correction from another pass, on a claim that was backwards rather than merely loose. The Also folded two copies of the nightly-toolchain explanation into one; the header pointed at |
4e924c3 to
ce0e570
Compare
|
One false claim removed. The The difference is deliberate and now says so: enabling |
|
Three review passes on this job have now come back with nothing, and the last two went at it by measuring rather than reading, so the evidence is worth leaving here. Round 8 compiled a probe against the job's exact flags to confirm the Round 9 attacked the case that would matter most and is easiest to miss: whether the job can go green without testing anything. A compile error inside a One incidental finding, not worth a change: |
There was a problem hiding this comment.
After the base refresh and version-independent toolchain comment, the Rust-side sanitizer job remains a useful, scoped check for internal pointer-arithmetic errors.
The author-retained limit is unchanged: native C kernels are not instrumented, including the AVX-512 dist-table path selected on capable hosts. Default features leave the f16/bf16 paths in Rust. No further change is requested for this pull request.
## What this changes `qemu-pre-haswell` already builds `lance-linalg`'s lib tests in release mode. This adds one step that runs that same binary a second time, on the runner's own CPU instead of under qemu, by overriding the cargo runner to `env` for that step only. The build step and the new run move above the QEMU setup steps, and the job's `name:` changes because it now does two things. ## Why: no PR job runs the dispatched SIMD kernels in an optimized build The job emulates a Nehalem, and every runtime feature gate in `lance-linalg` tests for `avx`, `avx2`, `fma`, or an `avx512*` feature. A Nehalem has none of them, so `SIMD_SUPPORT` resolves to `None` and every dispatch takes its fallback arm. That is correct for a SIGILL check, but no job a pull request runs executes the dispatched kernels in an optimized build: the jobs that run tests use the `ci` profile, which inherits `dev`. The nightly `compat-sequence` job builds a release wheel and builds and searches an IVF_PQ index over float32 vectors, but it runs once a night, gates no pull request, and checks recall rather than comparing kernels against a reference. Running the binary that is already on disk closes that gap, and it closes it for free. What it catches is a kernel that computes a wrong result only under optimized code generation, which `lance-linalg`'s comparisons against the scalar reference flag. A memory error inside a kernel is not guaranteed to crash in either profile; that is what the sanitizer job in #8878 is for. ## Cost Nothing beyond the test run itself. Measured locally: after `cargo test --release -p lance-linalg --lib --no-run`, changing only the runner env var and running again reports every crate `Fresh` and recompiles nothing. The runner override is not an input to cargo's build fingerprint. The job's existing 60 minute budget already covers a from-scratch release build. ## What the native run does not cover Worth stating so the next reader does not assume more than is there. The binary is built with the job's `RUSTFLAGS: "-C target-cpu=x86-64-v2"`, and env `RUSTFLAGS` replaces the per-target `rustflags` in `.cargo/config.toml` wholesale. So `#[cfg(target_feature = "avx2")]` code is compiled out of it, and only the runtime-dispatched kernels are reachable, since `#[target_feature(enable = "avx2")]` is additive per function. Both runs use default features, so `fp16kernels` is off. Which dispatch tier the native run takes depends on the runner's CPU, and GitHub does not contract a CPU model. `test_x86_runtime_feature_report` writes the detected features to stderr, so the job log records what actually happened rather than leaving it to be inferred. ## Why the new step sits before the QEMU build A step runs only if the ones before it succeeded, and the QEMU steps include building QEMU 8.2.10 from source on a cache miss. With the build and the native run first, a QEMU failure cannot take the native signal down with it. Nothing in the QEMU setup is a prerequisite for the cargo build: `--no-run` never invokes the runner, and `lance-linalg`'s `build.rs` needs only a C compiler. The move does not disturb the two ordering constraints in the job. `Swatinem/rust-cache` still precedes the first cargo invocation, and `Restore QEMU 8.2.10` still precedes both steps that read its `cache-hit` output. ## The rename, and the one line of Rust The job id `qemu-pre-haswell` is unchanged, so the `rust-cache` key, which is derived from `github.job`, is unaffected. Only the display name changes. `rust/lance-linalg/src/distance/dot_f16.rs` referred to the job by its display name, which the rename would have left pointing at a string that exists nowhere in the repository. It now names the job id, matching what `rust/lance-linalg/src/simd/i32.rs` already does. ## Test plan An x86_64 run with `RUSTFLAGS="-C target-cpu=x86-64-v2"` and the pass-through runner, the closest local equivalent of the native step, confirms three things at once: the v2 baseline builds, `env` works as a cargo runner, and `test_x86_runtime_feature_report` is visible without `--nocapture`. The resulting step order was checked against both ordering constraints above. The AVX2 and AVX-512 arms were compiled but not executed locally, since the host is aarch64 and an x86_64 build under Rosetta reports neither feature; they first execute when this job runs on a real x86 runner. ## A gap this leaves open No job runs `lance-linalg` in an optimized profile with `--features fp16kernels`. Turning it on compiles C, which would cost a rebuild and undo the zero-cost property above, so it belongs in its own change. Co-authored-by: Xuanwo <[email protected]>
What this changes
A
linalg-asanjob innightly_run.ymlrunscargo test -p lance-linalg --testsunder-Zsanitizer=address.The public entry points already validate the lengths a caller passes:
sum_4bit_dist_tableassertsdists.len() >= n, andhamming_batch_u64asserts the output length with a comment explaining why it is not adebug_assert. What nothing checks is the pointer arithmetic the kernels then do inside those bounds._mm256_storeu_si256(dists.as_mut_ptr().add(16), ...)in the AVX2 dist-table kernels and*results_ptr.add(1)through.add(3)inhamming_batch_avx2are raw stores at offsets the kernel computes itself, so an off-by-one in a chunk count writes past the buffer while every entry assert still passes.It lands in
nightly_run.ymlrather thanrust.ymlbecause-Zsanitizerneeds a nightly toolchain, and the only nightly this repo uses is indaily-code-coverage.yml, which isscheduleplusworkflow_dispatch. The pin is the same one that file uses, so there is one nightly date in the repo rather than two.Three details in the job are load-bearing and each is there for a reason a reader would otherwise have to rediscover.
RUSTUP_TOOLCHAINrather thanrustup default. A rustup override file outranks the default toolchain, andrust-toolchain.tomlpins a stable release, sorustup default nightly-...followed bycargo testruns the sanitizer flag into a stable compiler and stops aterror: the option 'Z' is only accepted on the nightly compiler.daily-code-coverage.ymlsolves the same problem the other way, withcargo +nightly-....RUSTFLAGSrepeats the baseline from.cargo/config.toml. Setting the variable replaces that file's per-targetrustflagswholesale rather than appending, so leaving it at just the sanitizer flag would instrument a build no release ships, and would compile out the arms gated ontarget_feature = "avx2". One of those is where the batch call that writes into a heap buffer lives (cosine_batch_avx512intovec![0.0; batch.len() / dimension]), which is the case a sanitizer detects best.--target x86_64-unknown-linux-gnukeeps the sanitizer off build scripts and proc macros, which run on the host.There is no protoc step, unlike every other Rust job here.
lance-linalg's dependency closure contains noprost-buildortonic-build, dev-dependencies included, and the job runs green without it.Test plan
On aarch64-apple-darwin, with one deliberate 2-byte store planted past the 32-slot output of
sum_dist_table_32bytes_batch_neon, ASan reportsheap-buffer-overflow, WRITE of size 2atdist_table.rswith the chain up throughsum_4bit_dist_table_uninitto the test. The same binary without the sanitizer dies with a bareSIGTRAPand no location, so what this job adds on that mutation is the location rather than the detection.It has run for real on Linux, four times, on a fork branch with the
github.repositoryguard dropped since that guard is what stops it running anywhere but here.Two clean runs: 33305364459 and, after dropping the protoc step, 33312991796. Both green, about a minute and a half to build and three to four minutes to run.
Then two runs with a deliberate out-of-bounds store planted in a kernel, to check the claim that this job names a file and a line. That is where the
ASAN_SYMBOLIZER_PATHstep comes from. Without it the report was detected but useless:ubuntu-24.04 ships
llvm-symbolizeronly under a versioned name, and ASan looks for the unversioned one onPATH. With the step, the same overflow reports:So the failing test names itself in the stack, which is why the run does not need
--test-threads=1to attribute a report.That exercise also turned up a coverage limit worth stating. I first planted the store in
sum_dist_table_32bytes_batch_avx2and the job stayed green: on a runner with AVX-512BW,sum_4bit_dist_table_uninitselects the AVX-512 C kernel, so the Rust AVX2 one never executes. The hacc entry point has no AVX-512 kernel, which is why the planted store there did fire. So on an AVX-512 runner this job covers the hacc AVX2 kernel, the scalar paths and everything else in the crate, but not the AVX2 dist_table kernel that a smaller host would take.One gap remains: the C is not instrumented.
dist_table.ccompiles without-fsanitize=address, so the AVX-512 dist_table kernel is not covered. I triedCFLAGS=-fsanitize=addressand it broke a host link inlance-arrow's build script, so it is left out rather than half-applied.Scope note
--testsselects the lib's unit tests and every integration target, sotests/panic_location.rsruns under the sanitizer too, and a target added later is included without editing this job.