Skip to content

Add CodeQL and cargo-deny SAST workflows - #1

Merged
nihalpasham merged 1 commit into
mainfrom
add-sast-workflows
Apr 25, 2026
Merged

nihalpasham merged 1 commit into
mainfrom
add-sast-workflows

Conversation

@nihalpasham

Copy link
Copy Markdown
Collaborator

Summary

  • Add CodeQL workflow for Rust + Actions static analysis (push/PR/weekly)
  • Add cargo-deny workflow for advisory, license, ban, and source auditing (push/PR/weekly)
  • Add deny.toml configuration (permissive license allowlist, blocks unknown registries/git sources, allows pliron git dep)
  • Add .claude/ to .gitignore

Addresses MVSB-32099 (Initiate SAST) and MVSB-32100 (Execute SAST).

@github-advanced-security

Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

CodeQL for Rust + Actions analysis (push/PR/weekly), cargo-deny for
advisory, license, ban, and source auditing. Also adds .claude/ to
.gitignore.
@nihalpasham
nihalpasham merged commit e93ac1a into main Apr 25, 2026
4 checks passed
@nihalpasham
nihalpasham deleted the add-sast-workflows branch May 6, 2026 02:23
brandonros added a commit to brandonros/cuda-oxide that referenced this pull request May 12, 2026
… bug B

After moving a helper *inside* the `#[cuda_module]` mod (the workaround
for bug A), an intrinsic-wrapping helper still fails to codegen unless
marked `#[inline]`:

    Verification failed for 'llvm module':
    Symbol helper_no_inline__kernels__get_thread_idx not found

Same failure shape as bug A but with `kernels__` in the mangle —
confirming the migrant's natural fix-up path ("move it inside the mod")
doesn't close the bug. The second, undocumented requirement is
`#[inline]`. The in-tree
`cross_crate_kernel/kernel-lib/src/lib.rs:45-48` example relies on this
attribute for its `device_helper`, but the `#[cuda_module]` macro
README doesn't surface that requirement.

## Why this is committed as a known-failure rather than a fix

Adding `#[inline]` to the helper here flips the diagnostic from
"Symbol not found" at LLVM verification to a different failure at
mir-importer's type translator:

    Unsupported construct: Type translation not yet implemented for:
    RigidTy(FnPtr(... std::fmt::Formatter ... std::fmt::Error ...))

That's the `<_ as Display>::fmt` function pointer that
`core::fmt::Arguments` carries vtable-style — the same FnPtr we hit
during the original limitation-NVIDIA#1 work and that we now reproduce
independently in `panic_fmt_path`. Inlining the intrinsic-wrapping
helper pulls `thread::index_1d()`'s body into the kernel's own MIR,
where the importer trips on the FnPtr. The non-inline path quietly
avoids this by keeping the offending body in a separate function the
importer never visits.

So `#[inline]` is necessary but not sufficient — there's a latent
FnPtr collection issue in `cuda_device` intrinsics themselves. This
example surfaces both layers so they can be tracked together.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
brandonros added a commit to brandonros/cuda-oxide that referenced this pull request May 12, 2026
…FnPtr

Any kernel-reachable path that goes through `core::panicking::panic_fmt`
hits a `FnPtr` arm the mir-importer type translator doesn't handle:

    Unsupported construct: Type translation not yet implemented for:
    RigidTy(FnPtr(Binder { value: FnSig { inputs_and_output: [
      Ty { ... "std::ptr::NonNull" ... },
      Ty { ... Ref Mut "std::fmt::Formatter" ... },
      Ty { ... "std::result::Result" ... "std::fmt::Error" ... }
    ] } }))

That signature is the type-erased `<_ as Display>::fmt` slot that
`core::fmt::Arguments` uses for each formatting placeholder. The
following common Rust patterns all lower through it and fail today:

  - `assert!(cond, "msg")`
  - `panic!("msg")`
  - `unreachable!("msg")`
  - `.expect("msg")` on `Option` / `Result`
  - `.unwrap()` on `Option` / `Result`

## Why this matters / why it's committed separately

The original brief framed limitation NVIDIA#1 (`RigidTy(Str)`) as "fix one
arm, unlock every panic message and every `.unwrap`." We hit this
FnPtr error twice during this branch — once when the first version of
the `str_panic_path` repro used `assert!(c, "msg")`, and again when
`helper_no_inline`'s `#[inline]` workaround inlined a
`cuda_device::thread::index_1d()` body into the kernel's own MIR. Two
independent triggers converging on the same FnPtr suggests the issue
isn't panic-specific — it's the importer's type translator missing a
function-pointer arm.

This reproducer pins down the simplest, most idiomatic trigger
(`assert!` with a static-string message) so the bug has a stable name
and a stable failing build to bisect against. It's intentionally NOT
fixed: the fix likely needs either a `RigidTy::FnPtr` arm in
`translate_type` plus a story for how FnPtr values flow through the
dialect (currently no `MirFnPtrType`), OR a collection-side change
that strips Display-vtable arguments from panic call sites before the
importer sees them.

Closes the loop on the brief's "RigidTy(Str) unlocks every panic"
claim: it doesn't. Two layers, not one.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
brandonros added a commit to brandonros/cuda-oxide that referenced this pull request May 12, 2026
… bug B

After moving a helper *inside* the `#[cuda_module]` mod (the workaround
for bug A), an intrinsic-wrapping helper still fails to codegen unless
marked `#[inline]`:

    Verification failed for 'llvm module':
    Symbol helper_no_inline__kernels__get_thread_idx not found

Same failure shape as bug A but with `kernels__` in the mangle —
confirming the migrant's natural fix-up path ("move it inside the mod")
doesn't close the bug. The second, undocumented requirement is
`#[inline]`. The in-tree
`cross_crate_kernel/kernel-lib/src/lib.rs:45-48` example relies on this
attribute for its `device_helper`, but the `#[cuda_module]` macro
README doesn't surface that requirement.

## Why this is committed as a known-failure rather than a fix

Adding `#[inline]` to the helper here flips the diagnostic from
"Symbol not found" at LLVM verification to a different failure at
mir-importer's type translator:

    Unsupported construct: Type translation not yet implemented for:
    RigidTy(FnPtr(... std::fmt::Formatter ... std::fmt::Error ...))

That's the `<_ as Display>::fmt` function pointer that
`core::fmt::Arguments` carries vtable-style — the same FnPtr we hit
during the original limitation-NVIDIA#1 work and that we now reproduce
independently in `panic_fmt_path`. Inlining the intrinsic-wrapping
helper pulls `thread::index_1d()`'s body into the kernel's own MIR,
where the importer trips on the FnPtr. The non-inline path quietly
avoids this by keeping the offending body in a separate function the
importer never visits.

So `#[inline]` is necessary but not sufficient — there's a latent
FnPtr collection issue in `cuda_device` intrinsics themselves. This
example surfaces both layers so they can be tracked together.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
brandonros added a commit to brandonros/cuda-oxide that referenced this pull request May 12, 2026
…FnPtr

Any kernel-reachable path that goes through `core::panicking::panic_fmt`
hits a `FnPtr` arm the mir-importer type translator doesn't handle:

    Unsupported construct: Type translation not yet implemented for:
    RigidTy(FnPtr(Binder { value: FnSig { inputs_and_output: [
      Ty { ... "std::ptr::NonNull" ... },
      Ty { ... Ref Mut "std::fmt::Formatter" ... },
      Ty { ... "std::result::Result" ... "std::fmt::Error" ... }
    ] } }))

That signature is the type-erased `<_ as Display>::fmt` slot that
`core::fmt::Arguments` uses for each formatting placeholder. The
following common Rust patterns all lower through it and fail today:

  - `assert!(cond, "msg")`
  - `panic!("msg")`
  - `unreachable!("msg")`
  - `.expect("msg")` on `Option` / `Result`
  - `.unwrap()` on `Option` / `Result`

## Why this matters / why it's committed separately

The original brief framed limitation NVIDIA#1 (`RigidTy(Str)`) as "fix one
arm, unlock every panic message and every `.unwrap`." We hit this
FnPtr error twice during this branch — once when the first version of
the `str_panic_path` repro used `assert!(c, "msg")`, and again when
`helper_no_inline`'s `#[inline]` workaround inlined a
`cuda_device::thread::index_1d()` body into the kernel's own MIR. Two
independent triggers converging on the same FnPtr suggests the issue
isn't panic-specific — it's the importer's type translator missing a
function-pointer arm.

This reproducer pins down the simplest, most idiomatic trigger
(`assert!` with a static-string message) so the bug has a stable name
and a stable failing build to bisect against. It's intentionally NOT
fixed: the fix likely needs either a `RigidTy::FnPtr` arm in
`translate_type` plus a story for how FnPtr values flow through the
dialect (currently no `MirFnPtrType`), OR a collection-side change
that strips Display-vtable arguments from panic call sites before the
importer sees them.

Closes the loop on the brief's "RigidTy(Str) unlocks every panic"
claim: it doesn't. Two layers, not one.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
brandonros added a commit to brandonros/cuda-oxide that referenced this pull request May 12, 2026
… bug B

After moving a helper *inside* the `#[cuda_module]` mod (the workaround
for bug A), an intrinsic-wrapping helper still fails to codegen unless
marked `#[inline]`:

    Verification failed for 'llvm module':
    Symbol helper_no_inline__kernels__get_thread_idx not found

Same failure shape as bug A but with `kernels__` in the mangle —
confirming the migrant's natural fix-up path ("move it inside the mod")
doesn't close the bug. The second, undocumented requirement is
`#[inline]`. The in-tree
`cross_crate_kernel/kernel-lib/src/lib.rs:45-48` example relies on this
attribute for its `device_helper`, but the `#[cuda_module]` macro
README doesn't surface that requirement.

## Why this is committed as a known-failure rather than a fix

Adding `#[inline]` to the helper here flips the diagnostic from
"Symbol not found" at LLVM verification to a different failure at
mir-importer's type translator:

    Unsupported construct: Type translation not yet implemented for:
    RigidTy(FnPtr(... std::fmt::Formatter ... std::fmt::Error ...))

That's the `<_ as Display>::fmt` function pointer that
`core::fmt::Arguments` carries vtable-style — the same FnPtr we hit
during the original limitation-NVIDIA#1 work and that we now reproduce
independently in `panic_fmt_path`. Inlining the intrinsic-wrapping
helper pulls `thread::index_1d()`'s body into the kernel's own MIR,
where the importer trips on the FnPtr. The non-inline path quietly
avoids this by keeping the offending body in a separate function the
importer never visits.

So `#[inline]` is necessary but not sufficient — there's a latent
FnPtr collection issue in `cuda_device` intrinsics themselves. This
example surfaces both layers so they can be tracked together.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
brandonros added a commit to brandonros/cuda-oxide that referenced this pull request May 12, 2026
…FnPtr

Any kernel-reachable path that goes through `core::panicking::panic_fmt`
hits a `FnPtr` arm the mir-importer type translator doesn't handle:

    Unsupported construct: Type translation not yet implemented for:
    RigidTy(FnPtr(Binder { value: FnSig { inputs_and_output: [
      Ty { ... "std::ptr::NonNull" ... },
      Ty { ... Ref Mut "std::fmt::Formatter" ... },
      Ty { ... "std::result::Result" ... "std::fmt::Error" ... }
    ] } }))

That signature is the type-erased `<_ as Display>::fmt` slot that
`core::fmt::Arguments` uses for each formatting placeholder. The
following common Rust patterns all lower through it and fail today:

  - `assert!(cond, "msg")`
  - `panic!("msg")`
  - `unreachable!("msg")`
  - `.expect("msg")` on `Option` / `Result`
  - `.unwrap()` on `Option` / `Result`

## Why this matters / why it's committed separately

The original brief framed limitation NVIDIA#1 (`RigidTy(Str)`) as "fix one
arm, unlock every panic message and every `.unwrap`." We hit this
FnPtr error twice during this branch — once when the first version of
the `str_panic_path` repro used `assert!(c, "msg")`, and again when
`helper_no_inline`'s `#[inline]` workaround inlined a
`cuda_device::thread::index_1d()` body into the kernel's own MIR. Two
independent triggers converging on the same FnPtr suggests the issue
isn't panic-specific — it's the importer's type translator missing a
function-pointer arm.

This reproducer pins down the simplest, most idiomatic trigger
(`assert!` with a static-string message) so the bug has a stable name
and a stable failing build to bisect against. It's intentionally NOT
fixed: the fix likely needs either a `RigidTy::FnPtr` arm in
`translate_type` plus a story for how FnPtr values flow through the
dialect (currently no `MirFnPtrType`), OR a collection-side change
that strips Display-vtable arguments from panic call sites before the
importer sees them.

Closes the loop on the brief's "RigidTy(Str) unlocks every panic"
claim: it doesn't. Two layers, not one.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
brandonros added a commit to brandonros/cuda-oxide that referenced this pull request May 13, 2026
… bug B

After moving a helper *inside* the `#[cuda_module]` mod (the workaround
for bug A), an intrinsic-wrapping helper still fails to codegen unless
marked `#[inline]`:

    Verification failed for 'llvm module':
    Symbol helper_no_inline__kernels__get_thread_idx not found

Same failure shape as bug A but with `kernels__` in the mangle —
confirming the migrant's natural fix-up path ("move it inside the mod")
doesn't close the bug. The second, undocumented requirement is
`#[inline]`. The in-tree
`cross_crate_kernel/kernel-lib/src/lib.rs:45-48` example relies on this
attribute for its `device_helper`, but the `#[cuda_module]` macro
README doesn't surface that requirement.

## Why this is committed as a known-failure rather than a fix

Adding `#[inline]` to the helper here flips the diagnostic from
"Symbol not found" at LLVM verification to a different failure at
mir-importer's type translator:

    Unsupported construct: Type translation not yet implemented for:
    RigidTy(FnPtr(... std::fmt::Formatter ... std::fmt::Error ...))

That's the `<_ as Display>::fmt` function pointer that
`core::fmt::Arguments` carries vtable-style — the same FnPtr we hit
during the original limitation-NVIDIA#1 work and that we now reproduce
independently in `panic_fmt_path`. Inlining the intrinsic-wrapping
helper pulls `thread::index_1d()`'s body into the kernel's own MIR,
where the importer trips on the FnPtr. The non-inline path quietly
avoids this by keeping the offending body in a separate function the
importer never visits.

So `#[inline]` is necessary but not sufficient — there's a latent
FnPtr collection issue in `cuda_device` intrinsics themselves. This
example surfaces both layers so they can be tracked together.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
brandonros added a commit to brandonros/cuda-oxide that referenced this pull request May 13, 2026
…FnPtr

Any kernel-reachable path that goes through `core::panicking::panic_fmt`
hits a `FnPtr` arm the mir-importer type translator doesn't handle:

    Unsupported construct: Type translation not yet implemented for:
    RigidTy(FnPtr(Binder { value: FnSig { inputs_and_output: [
      Ty { ... "std::ptr::NonNull" ... },
      Ty { ... Ref Mut "std::fmt::Formatter" ... },
      Ty { ... "std::result::Result" ... "std::fmt::Error" ... }
    ] } }))

That signature is the type-erased `<_ as Display>::fmt` slot that
`core::fmt::Arguments` uses for each formatting placeholder. The
following common Rust patterns all lower through it and fail today:

  - `assert!(cond, "msg")`
  - `panic!("msg")`
  - `unreachable!("msg")`
  - `.expect("msg")` on `Option` / `Result`
  - `.unwrap()` on `Option` / `Result`

## Why this matters / why it's committed separately

The original brief framed limitation NVIDIA#1 (`RigidTy(Str)`) as "fix one
arm, unlock every panic message and every `.unwrap`." We hit this
FnPtr error twice during this branch — once when the first version of
the `str_panic_path` repro used `assert!(c, "msg")`, and again when
`helper_no_inline`'s `#[inline]` workaround inlined a
`cuda_device::thread::index_1d()` body into the kernel's own MIR. Two
independent triggers converging on the same FnPtr suggests the issue
isn't panic-specific — it's the importer's type translator missing a
function-pointer arm.

This reproducer pins down the simplest, most idiomatic trigger
(`assert!` with a static-string message) so the bug has a stable name
and a stable failing build to bisect against. It's intentionally NOT
fixed: the fix likely needs either a `RigidTy::FnPtr` arm in
`translate_type` plus a story for how FnPtr values flow through the
dialect (currently no `MirFnPtrType`), OR a collection-side change
that strips Display-vtable arguments from panic call sites before the
importer sees them.

Closes the loop on the brief's "RigidTy(Str) unlocks every panic"
claim: it doesn't. Two layers, not one.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
meefs pushed a commit to meefs/cuda-oxide that referenced this pull request Sep 30, 2026
elibol pushed a commit to cryos/cuda-rust that referenced this pull request Oct 2, 2026
- Root README.md becomes the umbrella hub: one paragraph per component,
  a table for picking between the SIMT and Tile models, and a per-component
  license table. Modelled on NVIDIA/cuda-python's root README.
- cuda-oxide's existing README moves to cuda-oxide/README.md unchanged.
- docs/index.md is the published landing page. Its toctree links out to the
  component books by absolute URL, which is how cuda-python gets one
  navigation sidebar across independently built sites.
- docs/build_all_docs.sh builds the umbrella page, then each component book,
  and stitches the output into build/html/{,cuda-oxide/,cutile/}. Neither
  book moves. This produces the URL layout issue NVIDIA#2 asks for without
  relocating any sources or conflicting with NVIDIA#1.
- .gitignore no longer ignores /docs/. It was ignored for out-of-band design
  notes; only the build output is ignored now.

All three Sphinx builds pass under `-W --keep-going`.

URLs use https://nvlabs.github.io/cuda-rust/ as a placeholder; the public
umbrella repository does not exist yet.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Rob Parolin <[email protected]>
pifu-zh added a commit to pifu-zh/cuda-oxide that referenced this pull request Oct 25, 2026
…aw macro ntid + stack lifetime

Investigation chain (each step evidence-backed):
1. C probe of the shim stream surface (create/async memcpy both ways/
   stream launch/sync, vecadd kernel): 1024/1024 — shim exonerated.
2. gdb on the 'hang': not a hang at all but SIGSEGV inside
   hipModuleLaunchKernel — the kernarg array was SHORTER than the kernel's
   metadata param list: the sync raw cuda_launch! macro (unlike the async
   macro and the typed launchers) never appended the ntid_x/y/z kernargs;
   ROCm walks the metadata past the array end. First fix: append in all
   three expand_cuda_launch branches.
3. Post-fix: closures Tests 2-4 went all-zero on the sync raw path only.
   Root cause: the appended ntid locals were declared INSIDE the gating if,
   but the packet stores raw stack pointers — the slots were reused by the
   launch call's own frame, so the driver copied garbage blockDim and every
   in-kernel bounds guard rejected. Second fix: hoist the locals to block
   scope (assign+push inside the gate).
4. Remaining failure isolated to Test 9 (non-move reference captures):
   closure struct embeds HOST stack pointers; upstream's macro comment
   documents the GPU dereferences them via HMM — unavailable on
   gfx1030/ROCm (HSA fault at a host-stack address). Classified
   HARDWARE/RUNTIME-limited with the move-capture alternative verified.

End state: host_closure Tests 1-8 + 10-13 (12 closure shapes x 4 launch
paths incl. both async paths) all pass on the GPU; pytest 15/15 regression.
Matrix async + closure-ABI rows FULL; catalogue gains the HMM entry and
closes open item NVIDIA#1.

Signed-off-by: pifu-zh <[email protected]>
nihalpasham pushed a commit that referenced this pull request Nov 9, 2026
…handshakes (#1716)

## What This PR Does

Replaces fixed 30ms `thread::sleep` delays with deterministic
synchronization in two concurrency/retry unit tests:

1. **`ETXTBSY` Version-Probe Retry Test (`cuda-artifact-finalizer`)**
2. **Single-Flight LTOIR Cache Lock Test (`cuda-host`)**

---

### 1. Deterministic Retry & Lock Contention Hooks

Previously, both tests slept for 30ms to approximate thread ordering,
which could either fail spuriously on loaded runners or pass without
exercising the retry/lock path:

```text
BEFORE:
  ptx.rs:         background thread sleeps 30ms, then drops write fd
  ltoir_cache.rs: winner sleeps 30ms hoping 7 other threads contend on lock

AFTER:
  ptx.rs:         `BUSY_RETRY_WAIT` hook drops write fd inside retry #1
                  (plus a second test asserting all 8 doubling delays: 2ms..256ms)
  ltoir_cache.rs: `KEY_LOCK_ARRIVALS` condvar holds the build until all 8 threads
                  reach `acquire_key_lock`
```

* Guarantees that `PtxAssembler::from_path` observes
`ExecutableFileBusy` at least once before succeeding.
* Guarantees that all 8 threads miss the cache fast path and contend on
the per-key lockfile before the build publishes.

---

## Verification

* **Tests & CI Gates**:
  * `cargo test -p cuda-artifact-finalizer -p cuda-host --lib`: **PASS**
* `cargo clippy -p cuda-artifact-finalizer -p cuda-host --all-targets --
-D warnings`: **PASS**
  * `cargo oxide fmt --check`: **PASS**

Part of #1680

Signed-off-by: Vyncint Ng <[email protected]>
nihalpasham pushed a commit that referenced this pull request Nov 9, 2026
## What This PR Does

Fixes `cargo oxide setup` in standalone projects so it builds the
project's `cuda-oxide` dependency once instead of attempting to compile
the user's crate as the codegen backend:

1. **Build-Free Setup Context & Standalone Refresh
(`crates/cargo-oxide/src/commands/`)**
2. **Cache-Preserving Refresh Planning
(`crates/cargo-oxide/src/backend.rs`)**

---

### 1. Standalone `cargo oxide setup` Resolution and Refresh

Previously, `Commands::Setup` called `resolve_context()`, which eagerly
built the backend once and set `ctx.codegen_crate = cwd` outside the
workspace. `setup()` then tried to build `ctx.codegen_crate` as
`rustc-codegen-cuda`, compiling the user's project and failing:

```text
BEFORE (standalone project):
  cargo oxide setup
  ──► resolve_context() builds backend #1, sets codegen_crate = <user-project>
  ──► setup() runs build_backend_from_source(<user-project>) ──► fails ("no library targets found")

AFTER:
  cargo oxide setup
  ──► resolve_setup_context() locates backend without building
  ──► workspace:  SetupPlan::BuildAndPublish (builds local backend once, publishes to cache)
  ──► standalone: SetupPlan::RefreshFromDependency (rebuilds from project's cuda-oxide dependency)
  ──► pinned:     SetupPlan::RefusePinned (refuses when CUDA_OXIDE_BACKEND or config pin is set)
```

* `refresh_plan` resolves `Cargo.lock` and checks toolchain
compatibility before clearing `~/.cargo/cuda-oxide/`, so lockless path
dependencies and refused toolchains never wipe a valid shared cache.

---

## Verification

* **Tests & CI Gates**:
  * `cargo test -p cargo-oxide`: **PASS** (287 passed)
  * `cargo clippy -p cargo-oxide --all-targets -- -D warnings`: **PASS**
* `RUSTDOCFLAGS="-D warnings" cargo doc -p cargo-oxide --no-deps`:
**PASS**

Closes #1688

---------

Signed-off-by: Praveen Perera <[email protected]>
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.

2 participants