Skip to content

amdgpu: add kernelModule.patches option#321663

Draft
Atemu wants to merge 3 commits intoNixOS:masterfrom
Atemu:amdgpu-patches
Draft

amdgpu: add kernelModule.patches option#321663
Atemu wants to merge 3 commits intoNixOS:masterfrom
Atemu:amdgpu-patches

Conversation

@Atemu
Copy link
Copy Markdown
Member

@Atemu Atemu commented Jun 22, 2024

Description of changes

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@Atemu Atemu requested a review from JohnRTitor June 22, 2024 04:08
@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` labels Jun 22, 2024
@ofborg ofborg bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Jun 22, 2024
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not really keen on the idea, which problems would it solve specifically for amdgpu module?

If anything like this to be introduced, I think it should be standardised and available for all modules. Perhaps @K900 wants to take a look here as well.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had two issues that I needed to patch the amdgpu module for so far:

  1. SteamVR needs to be able to create a high-priority queue but you can't give it CAP_SYS_NICE because we run Steam inside of a userns. I must patch the amdgpu kernel module to allow any process to create such a queue (and potentially DOS the system but idc).
  2. The Framework 16 Laptop has a quirk and the display brightness does not go as low as it should and the lowest is too bright for dim environments. Until FW releases a firmware fix for this (which would be the proper fix), the module must be patched to add the quirk.

I'd also like this to be a standard option but I think that can come later. No need to perfect it in the V1.

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.

I really, really don't want to be setting this precedent.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I could certainly see this being a footgun, I don't really see any great danger here; could you elaborate?

I was also planning on making the unprivileged high-priority queue patch into a stand-alone option and providing some hacks in the Steam module to make the SteamVR setup experience smoother.

https://github.com/Atemu/nixos-config/blob/93b9546d1698286367bdb8826a3d827d5527128c/modules/gaming/module.nix#L116-L126

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.

I think a generic mechanism would be nice, is there any way to unstall this?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 on the generic mechanism.

I think a challenge here could be to make it easy to configure for users (i.e. boot.kernelModules."amdgpu".patches = [...]), as we would somehow need to map module names to module paths within the kernel source tree.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Building a good interface here would be hard as some modules that are conceptually one unit may be constituted of multiple individual module files.

That's at least part of the reason why I limited my work to AMDGPU first. I'd prefer if we just merged this as iteration 1 and came up with a good design for a generic mechanism in iteration 2.

I know it's hard but we need to put a limit on our perfectionism sometimes ;)

@K900 could you share your doubts about "setting this precedent"?

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.

Mostly my concern is that we're giving users a tool that's very sharp and very easy to hold wrong, and the failure mode is not great.

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.

Also, the initial goal of this, that being the capability issues, should really be fixed somewhere at a higher level (possibly in bwrap itself even?)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the initial goal of this, that being the capability issues, should really be fixed somewhere at a higher level (possibly in bwrap itself even?)

See #217119

In short:
Applications inside of user namespaces can never have effective file capabilities. This is just a design decision of the kernel. There have been numerous attempts to move away from capabilities specifically for high priority DRM contexts (which is what SteamVR needs) but none of them have made it into the kernel yet.

@K900
Copy link
Copy Markdown
Contributor

K900 commented Jun 22, 2024

Agreed. This could be some sort of a generic mechanism if we really want it to exist.

Atemu added a commit to Atemu/nixos-config that referenced this pull request Jul 10, 2024
Port of NixOS/nixpkgs#321663 because I need this NOW.
@wegank wegank added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jan 2, 2025
@stale stale bot removed the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Jan 5, 2025
Copy link
Copy Markdown
Member

@JohnRTitor JohnRTitor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I think about it, it might be good to merge this PR as an initial option and then try to look for a general solution.

LGTM approved, if you are still working on it, could you rebase it?

@wegank wegank added 12.approvals: 1 This PR was reviewed and approved by one person. 2.status: merge conflict This PR has merge conflicts with the target branch labels Jun 9, 2025
@ofborg ofborg bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Jun 23, 2025
Comment on lines 37 to 38
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel like kernelModule.inInitrd is a good name for this option. But I also don't have a better idea than just going back to initrd.enable

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed.

Copy link
Copy Markdown
Member

@JohnRTitor JohnRTitor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you have rebased the PR, and @Atemu has been inactive, I assume you want to adopt this PR? That's fine with me. Or you can also clone this branch and open a new PR.

the beginning of the initramfs phase rather than after it.
'';

patches = lib.mkOption {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hardware.amdgpu.modulePatches can be used while keeping the current structure.

@Scrumplex Scrumplex marked this pull request as draft June 24, 2025 16:56
@nixpkgs-ci nixpkgs-ci bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Dec 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants