-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
amdgpu: add kernelModule.patches option #321663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| # TODO there should probably be a generic mechanism to patch any in-kernel module like this | ||
| { | ||
| stdenv, | ||
| kernel, # The kernel to patch | ||
| patches ? [ ], | ||
| }: | ||
|
|
||
| stdenv.mkDerivation { | ||
| pname = "amdgpu-kernel-module-customised"; | ||
| inherit (kernel) | ||
| src | ||
| version | ||
| postPatch | ||
| nativeBuildInputs | ||
| modDirVersion | ||
| ; | ||
| patches = kernel.patches or [ ] ++ patches; | ||
|
|
||
| modulePath = "drivers/gpu/drm/amd/amdgpu"; | ||
|
|
||
| buildPhase = '' | ||
| BUILT_KERNEL=${kernel.dev}/lib/modules/$modDirVersion/build | ||
|
|
||
| cp $BUILT_KERNEL/Module.symvers $BUILT_KERNEL/.config ${kernel.dev}/vmlinux ./ | ||
|
|
||
| make "-j$NIX_BUILD_CORES" modules_prepare | ||
| make "-j$NIX_BUILD_CORES" M=$modulePath modules | ||
| ''; | ||
|
|
||
| installPhase = '' | ||
| make \ | ||
| INSTALL_MOD_PATH="$out" \ | ||
| XZ="xz -T$NIX_BUILD_CORES" \ | ||
| M="$modulePath" \ | ||
| modules_install | ||
| ''; | ||
|
|
||
| meta = { | ||
| description = "AMDGPU kernel module"; | ||
| inherit (kernel.meta) license; | ||
| }; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,11 +17,6 @@ in | |
| which is only available in the `radeon` driver | ||
| ''; | ||
|
|
||
| initrd.enable = lib.mkEnableOption '' | ||
| loading `amdgpu` kernelModule in stage 1. | ||
| Can fix lower resolution in boot screen during initramfs phase | ||
| ''; | ||
|
|
||
| overdrive = { | ||
| enable = lib.mkEnableOption ''`amdgpu` overdrive mode for overclocking''; | ||
|
|
||
|
|
@@ -39,10 +34,58 @@ in | |
| }; | ||
| }; | ||
|
|
||
| kernelModule = { | ||
| inInitrd = lib.mkEnableOption '' | ||
|
||
| installing the `amdgpu` kernelModule into the initrd; making it | ||
| available in stage 1 of the boot process. | ||
|
|
||
| This allows for an earlier modeset to apply the preferred resolution in | ||
| the beginning of the initramfs phase rather than after it. | ||
| ''; | ||
|
|
||
| patches = lib.mkOption { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| type = with lib.types; listOf path; | ||
| default = [ ]; | ||
| description = '' | ||
| Patches to apply to the kernel for the `amdgpu` kernel module build. | ||
|
|
||
| This is intended for applying small patches concerning only the | ||
| `amdgpu` module's internals without needing to rebuild the entire | ||
| kernel. | ||
|
|
||
| The patches are applied to the entire kernel tree but only the | ||
| `amdgpu` module will actually be built and used. You should therefore | ||
| not touch anything outside of `drivers/gpu/drm/amd/amdgpu` using the | ||
| patches as those modifications will not be present in the actual | ||
| kernel you will be running which might cause undefined and likely | ||
| erroneous behaviour. | ||
| Use {option}`boot.kernelPatches` instead for such cases. | ||
|
|
||
| A reboot is required for the patched module to be loaded. | ||
| ''; | ||
| example = lib.literalExpression '' | ||
| [ | ||
| (pkgs.fetchpatch2 { | ||
| url = "https://lore.kernel.org/lkml/20240610-amdgpu-min-backlight-quirk-v1-1-8459895a5b2a@weissschuh.net/raw"; | ||
| hash = ""; | ||
| }) | ||
| ] | ||
| ''; | ||
| }; | ||
| }; | ||
|
|
||
| opencl.enable = lib.mkEnableOption ''OpenCL support using ROCM runtime library''; | ||
| # cfg.amdvlk option is defined in ./amdvlk.nix module | ||
| }; | ||
|
|
||
| imports = [ | ||
| # This can be removed post 24.11; it was only ever in unstable | ||
| (lib.mkRenamedOptionModule | ||
| [ "hardware" "amdgpu" "initrd" "enable" ] | ||
| [ "hardware" "amdgpu" "kernelModule" "inInitrd" ] | ||
| ) | ||
| ]; | ||
|
|
||
| config = { | ||
| boot.kernelParams = | ||
| lib.optionals cfg.legacySupport.enable [ | ||
|
|
@@ -55,7 +98,14 @@ in | |
| "amdgpu.ppfeaturemask=${cfg.overdrive.ppfeaturemask}" | ||
| ]; | ||
|
|
||
| boot.initrd.kernelModules = lib.optionals cfg.initrd.enable [ "amdgpu" ]; | ||
| boot.initrd.kernelModules = lib.optionals cfg.kernelModule.inInitrd [ "amdgpu" ]; | ||
|
|
||
| boot.extraModulePackages = lib.mkIf (cfg.kernelModule.patches != [ ]) [ | ||
| (pkgs.callPackage ./amdgpu-kernel-module.nix { | ||
| inherit (config.boot.kernelPackages) kernel; | ||
| inherit (cfg.kernelModule) patches; | ||
| }) | ||
| ]; | ||
|
|
||
| hardware.graphics = lib.mkIf cfg.opencl.enable { | ||
| enable = lib.mkDefault true; | ||
|
|
@@ -67,6 +117,9 @@ in | |
| }; | ||
|
|
||
| meta = { | ||
| maintainers = with lib.maintainers; [ johnrtitor ]; | ||
| maintainers = with lib.maintainers; [ | ||
| johnrtitor | ||
| atemu | ||
| ]; | ||
| }; | ||
| } | ||
There was a problem hiding this comment.
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
amdgpumodule?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.
There was a problem hiding this comment.
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:
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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"?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.