Drop ProtectClock= from the unit — it hides /dev/nvidia* and NVML can't init - #14
Merged
ricky-chaoju merged 1 commit intoSep 2, 2026
Conversation
Under the systemd unit nvmlInit() failed with "Failed to initialize NVML: Unknown Error" while the same binary worked from a root shell. Bisecting the hardening directives with systemd-run --wait --pipe -p <directive> /usr/local/bin/nvfd list on Ubuntu 22.04.5 / systemd 249 / driver 595.84 (RTX 6000 Ada) passed every directive except ProtectClock=yes. systemd.exec(5): ProtectClock=yes implies DeviceAllow=char-rtc r, and "adding [DeviceAllow=] turns on DevicePolicy=closed by default". With a closed device policy the daemon cannot open /dev/nvidiactl or /dev/nvidia<N>, so NVML cannot reach the driver. Removing ProtectClock= costs nothing the daemon needs (it never touches the clock) and restores device access. Keeping ProtectClock= alongside explicit DeviceAllow= entries for the NVIDIA nodes would work too, but the set of nodes varies by GPU count and driver (nvidia-uvm has a dynamic major), so the simpler rule is preferred.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi — thanks for nvfd, it's exactly the tool I was looking for after giving up on the Coolbits/X route. I hit a wall getting the service to start, though, and I think it will bite anyone on a reasonably recent systemd, so here's the fix.
What happens
systemctl start nvfdfails every time withuntil the start limit gives up, while
sudo nvfd listandsudo nvfd statusfrom a shell work fine. Same binary, same root user, so it had to be the unit's sandboxing.Finding it
I ran
nvfd listunder each hardening directive from the unit on its own withsystemd-run:Fourteen of the fifteen pass.
ProtectClock=yesis the only one that fails. Then, with all fourteen others applied together andProtectClock=left out,nvfd listruns and enumerates the GPU.The reason is in
systemd.exec(5):ProtectClock=yesimpliesDeviceAllow=char-rtc r, and adding anyDeviceAllow=switches the unit toDevicePolicy=closed. From that point the service only sees the devices on the allow-list, so/dev/nvidiactland/dev/nvidia0aren't there and NVML can't reach the driver. The "Unknown Error" is NVML's way of saying it couldn't open the device node.The change
Just remove
ProtectClock=and leave a comment in the unit saying why it mustn't come back. The daemon never touches the clock, so nothing is lost. I did consider keeping it and adding explicitDeviceAllow=lines for the NVIDIA nodes instead, but the set of nodes depends on GPU count and driver (nvidia-uvmhas a dynamic major), and a wrong guess there fails in exactly this silent way, so the simpler rule felt safer.Tested on Ubuntu 22.04.5, systemd 249, driver 595.84, RTX 6000 Ada. Happy to adjust if you'd prefer the allow-list approach.