Skip to content

feat(cardwire-ebpf): send event on manual mode and make force_gpu works - #174

Merged
luytan merged 7 commits into
mainfrom
smart-mode-features-for-manual
Aug 9, 2026
Merged

feat(cardwire-ebpf): send event on manual mode and make force_gpu works#174
luytan merged 7 commits into
mainfrom
smart-mode-features-for-manual

Conversation

@luytan

@luytan luytan commented Aug 9, 2026

Copy link
Copy Markdown
Member

Description

Please include a summary of the changes and if applicable, a related issue.

If this PR introduce a new feature, explain your motivations

Fixes # (issue)

TODO

  • Copy-Paste this line

Checklist:

  • My code follows the style guidelines of this project (cargo fmt)
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the mdBook documentation
  • My changes generate no new warnings (clippy/clang)
  • New and existing unit tests pass locally with my changes (either use nix flake check or wait for the ci)

@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: abafaa17-807f-415e-b2c3-632e657724d9

📥 Commits

Reviewing files that changed from the base of the PR and between 54f7258 and c4f5519.

📒 Files selected for processing (2)
  • .github/workflows/cicd.yml
  • nix/ci-2gpu.nix

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added support for manual execution mode alongside smart mode.
    • Manual mode respects configured application-to-GPU mappings.
    • Added multi-GPU launch support with GPU-specific environment configuration.
    • Smart mode now explicitly unblocks the default integrated GPU.
  • Bug Fixes

    • Improved GPU access decisions and blocking state handling.
    • Improved display detection by excluding virtual and internal displays.
    • Simplified manual-mode processing by skipping unnecessary policy checks and application discovery.

Walkthrough

Execution events now carry smart or manual mode values. eBPF enforcement uses mode-specific GPU mapping behavior. The daemon applies the mode in evaluate_app. GPU state, display detection, integration tests, and VM CI targets were updated.

Changes

Mode-aware GPU enforcement

Layer / File(s) Summary
Execution event contract and propagation
crates/cardwire-ebpf/src/maps.rs, crates/cardwire-ebpf/src/main.rs, crates/cardwire-daemon/src/analyzer/models.rs
ExecEvent carries aligned mode data. The eBPF tracepoint emits smart mode as 3 and manual mode as 2. The analyzer passes the mode to evaluate_app.
Structured inode block state
crates/cardwire-ebpf/src/maps.rs, crates/cardwire-ebpf-userspace/src/lib.rs, crates/cardwire-daemon/src/interface/gpu.rs
The inode map stores GPU ID and block status. Unblocking retains the entry with an inactive block flag. Status checks require a matching GPU ID and active block status.
Mode-specific enforcement and analysis
crates/cardwire-ebpf/src/helpers.rs, crates/cardwire-daemon/src/analyzer/models.rs
Manual mode checks forced mappings for the current or parent process. Manual evaluate_app returns after environment overrides. Integrated mode follows blocked state.
Daemon GPU and display behavior
crates/cardwire-daemon/src/interface/mode.rs, crates/cardwire-daemon/src/interface/gpu.rs, crates/cardwire-daemon/src/core/gpu/display.rs
Smart mode unblocks the default integrated GPU. Display and activity detection exclude virtual, non-physical, internal, unknown, and writeback connector types.
GPU integration validation
nix/ci-2gpu.nix, nix/ci-3gpu.nix, nix/ci-15gpu.nix
Integration tests cover GPU defaults, overrides, launch variables, mode failures, and multi-GPU selection.

VM test matrix

Layer / File(s) Summary
VM matrix and package outputs
.github/workflows/cicd.yml, flake.nix
CI runs separate 2-GPU, 3-GPU, and 15-GPU VM checks. Flake outputs expose each check as a package.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant EBPF as eBPF tracepoint
  participant Event as ExecEvent
  participant Analyzer as CardwireAnalyzer
  participant Enforcement as is_inode_blocked
  participant Launch as GPU launch
  EBPF->>Event: Emit process ID and mode
  Event->>Analyzer: Deliver execution event
  Analyzer->>Analyzer: Apply environment overrides
  Enforcement->>Enforcement: Check inode state and forced GPU mappings
  Launch->>Launch: Set CARDWIRE_FORCE_GPU and DRI_PRIME
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description repeats the template and does not summarize the changes, explain motivation, identify an issue, or complete the checklist. Add a change summary, feature motivation, issue reference or explicit none, and update the TODO and checklist items.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main changes: manual-mode event sending and functional force_gpu behavior.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/cardwire-ebpf/src/helpers.rs`:
- Around line 60-80: Update the manual-mode branch around the `MANUAL` check to
consult `CW_ALLOWED_PID` for the current PID and its PPID before performing the
`CW_FORCED_PID` lookup. If either process is explicitly allowed, preserve the
allow-and-exit behavior used by smart mode; otherwise retain the existing
forced-GPU matching and default blocking logic.

In `@crates/cardwire-ebpf/src/maps.rs`:
- Around line 76-78: The ExecEvent definitions in
crates/cardwire-ebpf/src/maps.rs:76-78,
crates/cardwire-ebpf/src/main.rs:469-473, and
crates/cardwire-daemon/src/analyzer/models.rs:22-24 must use #[repr(C)] with a
reserved [u8; 3] field so the wire layout remains 8 bytes; initialize reserved
before each ring_buf.write(event) in the eBPF producer.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 95ca5ef6-7af1-4e3f-adf9-d4cc4348b9dc

📥 Commits

Reviewing files that changed from the base of the PR and between 2964bbd and 7e59ca9.

📒 Files selected for processing (4)
  • crates/cardwire-daemon/src/analyzer/models.rs
  • crates/cardwire-ebpf/src/helpers.rs
  • crates/cardwire-ebpf/src/main.rs
  • crates/cardwire-ebpf/src/maps.rs

Comment thread crates/cardwire-ebpf/src/helpers.rs Outdated
Comment thread crates/cardwire-ebpf/src/maps.rs

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/cicd.yml:
- Line 142: Update the actions/checkout step in the vm-test job to set
persist-credentials to false, ensuring the checkout token is not retained in
.git/config; leave credential provisioning to any future step that explicitly
requires Git authentication.

In `@nix/ci-2gpu.nix`:
- Around line 82-88: Update the “Test Dynamic Analysis ENV Flags” subtest to
replace the shell builtin `:` with an actual executable child process for each
CARDWIRE_ALLOW and CARDWIRE_FORCE_DGPU case. Ensure the child receives the
override environment and delays its `/dev/dri/renderD129` access until dynamic
analysis has completed, while preserving the existing succeed/fail expectations
for values 1 and 0.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 1ed3697e-4c62-437c-9c9f-fbcd2d129a99

📥 Commits

Reviewing files that changed from the base of the PR and between 7e59ca9 and 54f7258.

📒 Files selected for processing (13)
  • .github/workflows/cicd.yml
  • crates/cardwire-daemon/src/analyzer/models.rs
  • crates/cardwire-daemon/src/core/gpu/display.rs
  • crates/cardwire-daemon/src/interface/gpu.rs
  • crates/cardwire-daemon/src/interface/mode.rs
  • crates/cardwire-ebpf-userspace/src/lib.rs
  • crates/cardwire-ebpf/src/helpers.rs
  • crates/cardwire-ebpf/src/main.rs
  • crates/cardwire-ebpf/src/maps.rs
  • flake.nix
  • nix/ci-15gpu.nix
  • nix/ci-2gpu.nix
  • nix/ci-3gpu.nix

Comment thread .github/workflows/cicd.yml
Comment thread nix/ci-2gpu.nix Outdated
@luytan
luytan merged commit bd9514f into main Aug 9, 2026
9 checks passed
@luytan
luytan deleted the smart-mode-features-for-manual branch August 9, 2026 12:12
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.

1 participant