Skip to content

Skip force-igpu Vfio dance when no NVIDIA GPU is present - #12504

Open
paulogeyer wants to merge 3 commits into
omacom:quattrofrom
paulogeyer:fix/12496-force-igpu
Open

paulogeyer wants to merge 3 commits into
omacom:quattrofrom
paulogeyer:fix/12496-force-igpu

Conversation

@paulogeyer

@paulogeyer paulogeyer commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

default/systemd/system-sleep/force-igpu ran whenever supergfxctl existed and Integrated mode was configured. On machines without an NVIDIA dGPU, post still tried to switch to Vfio, timed out every resume, and could leave the restore marker behind.

Exit early unless a PCI display controller with vendor 0x10de is present. Hybrid behavior is unchanged when NVIDIA is present.

Fixes #12496

Test plan

  • Harness: mock supergfxctl + empty PCI → stock post fails, patched post exits 0
  • Harness: fake NVIDIA PCI → patched script enters the dance again
  • Optional: real resume on Intel-only and hybrid NVIDIA machines

The sleep hook ran whenever supergfxctl existed and Integrated mode was
configured. On machines without an NVIDIA dGPU, post still tried to
switch to Vfio, timed out every resume, and could leave the restore
marker behind.

Exit early unless a PCI display controller with vendor 0x10de is present.
Hybrid/G14 behavior is unchanged when NVIDIA is present.

Fixes omacom#12496
@llstrk

llstrk commented Sep 25, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Verified: the change fixes #12496 on machines without an NVIDIA GPU. It also stops the hook on the hybrid NVIDIA laptops the hook was written for. In Integrated mode supergfxd removes the dGPU from the PCI device list, so the new check exits at pre and the post-resume Vfio/Integrated sequence does not run.

The PCI check misses the dGPU that supergfxd has removed

has_nvidia_gpu || exit 0 runs before the case, so it gates both pre and post. It looks only at devices currently listed under /sys/bus/pci/devices.

In supergfxctl 5.2.7 (the version in Omarchy's package recipe), entering Integrated mode runs UnbindRemoveGpu. That applies at boot, from Hybrid, and in the Vfio to Integrated step of this hook's own sequence. UnbindRemoveGpu writes 1 to each dGPU function's sysfs remove node (src/actions.rs, src/pci_device.rs). With the "hotplug_type": "None" config that omarchy-toggle-hybrid-gpu writes, this removal is how the dGPU gets powered off. supergfxd's own Integrated to Vfio transition starts with RescanPci to make the device visible again.

Consecutive sleep cycles after booting in Integrated mode, assuming the hook's header premise that the dGPU reappears on wake:

cycle   dGPU listed at pre?   base                          this PR
1       no (removed at boot)  marker, Vfio -> Integrated    exits at check: no marker, no sequence
2       yes (back after wake) marker, Vfio -> Integrated    marker, Vfio -> Integrated (removes dGPU again)
3       no                    marker, Vfio -> Integrated    exits at check: no marker, no sequence

The hibernate branch of pre, which switches to Vfio before hibernating, is skipped the same way whenever the dGPU is not listed.

Impact: on the hybrid NVIDIA laptops the hook targets, the dGPU is left powered after about every other resume. That is the behavior the hook exists to prevent. The skipped pre and post paths follow from the hook and supergfxctl source. Wake re-enumeration is the hook's documented premise and was not observed on hardware.

Suggested change: detect the dGPU in a way that survives the Integrated-mode removal, and keep the Intel-only case a no-op. Optional approaches:

  • Ask the daemon: supergfxctl --vendor reports the vendor that supergfxd detected at startup (it rescans PCI first). It keeps Nvidia after the removal and prints Unknown when there is no dGPU. It needs supergfxd reachable over D-Bus at sleep time, so bound it with timeout like the existing calls and decide how a failure should be handled.
  • Keep the sysfs scan but move it to where presence matters: in post after the existing sleep 4 re-enumeration delay (clear the marker and exit 0 when no NVIDIA display function is listed), and in the hibernate branch of pre. Marker creation then no longer depends on the removed state.

Optional test improvement: the test plan's "fake NVIDIA PCI" case lists the device at pre time, which is not the state supergfxd leaves in Integrated mode. A case with the device unlisted at pre and listed again after wake would cover this path.

Verified:

  • On a machine with no NVIDIA display controller, both phases exit 0 without writing the marker or calling supergfxctl. The base version reproduces the report: post exits 1 with Could not confirm the GPU transition to Vfio mode and leaves the marker behind.
  • The checks match the kernel's sysfs formats (vendor as 0x%04x, class as 0x%06x). 0x03* covers VGA, 3D and other display controllers, a non-display NVIDIA function such as HDA audio is ignored, and an empty glob returns cleanly.
  • When the NVIDIA device is listed at pre, behavior matches the base.

Review information

Test scope: source review of the hook at the PR head and base, its installer and migration, supergfxctl 5.2.7 source, and Linux v7.2 PCI removal code. One isolated command-only run executed base and head copies of the hook against a synthetic PCI tree and a supergfxctl stub modeled on the 5.2.7 transitions. No real suspend, resume or hibernate, supergfxd daemon, or GPU hardware was used. The supergfxctl --vendor behavior is from source only.

AI process: Opus 5.5 Medium coordination and synthesis, independent Opus 5.5 Xhigh and GPT 6 Sol Xhigh technical assessments, Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@omarchybot omarchybot added the bug Something isn't working label Sep 27, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Thanks for tracking this down. The bug in #12496 is real and this pull request does fix it, but the new gate also turns the hook off on the hybrid laptops it exists for, so it needs a different check before it can land.

What was checked. I ran the hook at base (60663faf8) and at this head (42185887c) on a disposable Omarchy worker with no NVIDIA device. I used a stub supergfxctl, ran as root, and ran the repository's tests. Codex Medium reviewed it separately and reached the same main finding from supergfxctl's source; independence is not guaranteed.

The bug reproduces and is fixed. With the marker set and a supergfxctl that never reports Vfio, post at base exits 1 after 14 seconds with "Could not confirm the GPU transition to Vfio mode". At this head it exits 0 straight away.

The regression. When supergfxd is in Integrated mode, it takes the dGPU off the PCI bus. At boot and on every Hybrid → Integrated switch it runs UnbindRemoveGpu, which writes 1 to the device's sysfs remove file (src/actions.rs and src/pci_device.rs upstream). That happens with hotplug_type: None too. So on a G14 in Integrated mode, /sys/bus/pci/devices has no 0x10de display controller when pre runs. has_nvidia_gpu fails, and the hook exits at force-igpu:29 before it writes the restore marker. From sysfs, that machine looks exactly like the worker. Running the same cases on the worker:

  • pre hibernate: base writes the marker and switches to Vfio. This head does neither, so the step that keeps hibernate resume from failing with -EIO is skipped.
  • pre suspend then post suspend: base runs Vfio → Integrated after resume. This head does nothing, so the dGPU stays on after resume, which is the original G14 problem.

Codex also pointed out that the post gate runs before the 4-second re-enumeration delay, so a dGPU that is still coming back can suppress the restore even when the marker exists.

Tests. ./test/cli passes. test/shell.d/hybrid-gpu-test.sh and hw-hybrid-gpu-test.sh pass. test/shell.d/system-sleep-ownership-migration-test.sh fails at this head on "force-igpu does not securely record Integrated restore intent during pre-suspend", and the same test passes 23 of 23 with the base hook. The fixture stubs supergfxctl but not sysfs, so the hook now exits early on any test machine without an NVIDIA GPU. This pull request has no CI run.

A narrower gate. Ask supergfxd instead of sysfs, the way bin/omarchy-hw-hybrid-gpu already does. Upstream get_supported_modes (src/controller.rs) returns only [Integrated] when it found no dGPU vendor and the machine has no ASUS dGPU-disable support. That is the T480s in #12496. On a hybrid it lists Hybrid and Vfio, because the daemon keeps the dGPU it detected at startup. So a bounded supergfxctl -s that exits only when the answer is exactly [Integrated] fixes this issue. A timeout or error should not count as "no dGPU". That half still needs confirming on a hybrid, ideally by someone with a G14 running Integrated mode.

AMD-dGPU hybrids lose the hook under this gate as well, since the toggle is not NVIDIA-specific. A gate that asks supergfxd avoids that too. The mode change to 755 is harmless, because both install paths set 0755 themselves.

#11843 also edits force-igpu (recovering from Vfio). It is a different bug and does not compete with this one, but the two will need rebasing against each other.

This waits on the author: a gate that holds on hybrids in Integrated mode, and a test that does not depend on the host's GPU.

@jandrusk

Copy link
Copy Markdown

Thanks for this — #12496 is real and still present on quattro.

One blocking issue before merge: the PCI 0x10de gate turns the hook off on the hybrid laptops it exists for. In Integrated mode, supergfxd has already unbound/removed the NVIDIA device from sysfs (UnbindRemoveGpu), so has_nvidia_gpu returns false on a G14 exactly like a T480s. That skips writing the restore marker and skips the hibernate Vfio step.

Narrower gate (same idea as omarchy-hw-hybrid-gpu): ask supergfxd what it supports, and only exit early when the answer is exactly [Integrated]:

supported=$(/usr/bin/timeout --kill-after=1s 3s /usr/bin/supergfxctl -s 2>/dev/null) || supported=""
# timeout/error must NOT count as "no dGPU"
if [[ $supported == "[Integrated]" ]]; then
  exit 0
fi

Also keep the NVIDIA check out of the post path when the restore marker already exists (or run it after the 4s re-enumeration delay). Happy to re-review once that lands.

In Integrated mode supergfxd removes the NVIDIA dGPU from sysfs, so the
0x10de probe skipped the hook on the hybrid laptops it exists for. Ask
supergfxd for its supported modes in pre only; a timeout/error keeps the
hook armed, and post relies on the restore marker alone.
@paulogeyer

Copy link
Copy Markdown
Contributor Author

Thanks @jandrusk, you're right: in Integrated mode the dGPU is already gone from sysfs, so the PCI probe disabled the hook on the G14s it's for.

Pushed a fix:

  • Dropped the 0x10de sysfs probe.
  • In pre only, the hook now exits early (and clears any stale restore marker) when supergfxctl -s prints exactly [Integrated]. A timeout or error does not count as "no dGPU", so the hook stays armed.
  • post doesn't run the check at all; it still relies on the restore marker.

Tested with a stub harness (fake supergfxctl, no root, no real suspend):

  • Intel-only skips on suspend and hibernate, and a stale marker is cleared.
  • Hybrid with the dGPU removed from sysfs arms on suspend and switches to Vfio on hibernate.
  • An -s timeout or error keeps the hook armed.
  • post restores and clears the marker without calling -s.

It hasn't been tested on a real G14 in Integrated mode yet, so a run there would be welcome.

The hook is a root-owned copy that omarchy-toggle-hybrid-gpu and migration 1788662350 publish once, so the new gate never reached a machine that already had the hook, including the T480s in omacom#12496. Replace the copy only when it is exactly one of the two versions quattro shipped, so an administrator's edits survive.

Co-Authored-By: Codex Medium <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@omarchybot omarchybot added the verified Omarchy Triage has verified that this issue is ready for final review label Oct 14, 2026
@omarchybot

Copy link
Copy Markdown
Collaborator

Thanks for the rework. The new gate fixes #12496 without the hybrid regression, and I pushed one commit so the fix also reaches machines that already have the hook installed.

What was checked. I installed the real supergfxctl 5.2.7 (Omarchy's package) on a disposable Omarchy worker. The worker has no dGPU, so it is the T480s case, and supergfxd answers -s with [Integrated]. I set /etc/supergfxd.conf to Integrated with Omarchy's config and ran the hook as root:

The hybrid side can't be run on a worker, so it rests on supergfxctl's source. get_supported_modes (src/controller.rs:99-105) returns only [Integrated] when supergfxd found no dGPU vendor and there is no ASUS dgpu_disable. DiscreetGpu::new rescans PCI before it looks (src/pci_device.rs:544-546), so a G14 whose dGPU was removed in Integrated mode still lists Hybrid and Vfio, even after supergfxd restarts. A run on a real G14 in Integrated mode would still be welcome.

What I pushed (eabe187): migrations/1791984619.sh. The hook in /usr/lib/systemd/system-sleep/ is a root-owned copy that omarchy-toggle-hybrid-gpu and migration 1788662350 publish once, so changing the template alone would leave every machine that already has it failing on resume, the one in #12496 included. The migration replaces the installed hook only when it is exactly one of the two versions quattro shipped. It stages the new copy and renames it into place, so an administrator's edits survive and a failed run leaves the old hook intact. On the worker I ran it as root against both shipped versions, an edited hook, a symlink, a missing hook and a failed copy, and then ran a full suspend cycle with the installed hook.

Tests. ./test/cli passes. system-sleep-ownership-migration-test.sh passes 23 of 23, along with hybrid-gpu-test.sh, hw-hybrid-gpu-test.sh and unowned-system-paths-test.sh. The full shell suite has 4 of 245 files failing: ascii-test, branding-about-animation-test, locate-test and omarchy-kernel-migration-test. All four fail the same way with this change reverted. The last two pass once current quattro is merged in, and the first two fail on quattro itself. The suite's supergfxctl stub prints nothing for -s, so it exercises the armed path but not the new skip.

Second opinion. Codex Medium reviewed this over three rounds. It found that the template change alone never reached installed machines, which is why the migration was added. It also found that the migration's first version wrote over the hook in place, so it now stages and renames. Its last round, on eabe187, found nothing open. It agreed with the reading of supergfxctl above; independence is not guaranteed.

This now waits on the maintainer: the fix is verified, but the shell suite is not green on this branch for the unrelated reasons above.

@omarchybot omarchybot removed the verified Omarchy Triage has verified that this issue is ready for final review label Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

system-sleep force-igpu fails on every resume on machines without an NVIDIA dGPU

4 participants