https://github.com/thorio/pat-dealloc
Stupid kernel module and userspace helper to free PAT memtypes
https://github.com/thorio/pat-dealloc
command-line-tool linux-kernel x86-pat
Last synced: 2 months ago
JSON representation
Stupid kernel module and userspace helper to free PAT memtypes
- Host: GitHub
- URL: https://github.com/thorio/pat-dealloc
- Owner: thorio
- License: gpl-3.0
- Created: 2024-04-01T16:24:43.000Z (about 2 years ago)
- Default Branch: develop
- Last Pushed: 2025-01-05T16:55:00.000Z (over 1 year ago)
- Last Synced: 2025-12-08T01:40:46.883Z (6 months ago)
- Topics: command-line-tool, linux-kernel, x86-pat
- Language: Rust
- Homepage:
- Size: 72.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# pat-dealloc


[](https://aur.archlinux.org/packages/pat-dealloc-dkms)
A kernel module and helper utility to remove PAT entries. May cause issues if used incorrectly, so proceed with caution.
Intended as a less dodgy workaround for this issue: https://gitlab.freedesktop.org/drm/amd/-/issues/2794
Also my first kernel module and first (sort of) useful thing written in C.
## Usage
### WARNING
The kernel module **DOES NOT CARE** what you give it: as long as it parses it will try to `memtype_free` the address range(s) you supply, even if that memory is still in use by a driver. Doing this while anything is actively using that memory *might* result in memory corruption. **USE AT YOUR OWN RISK**.
Best to unload/stop relevant drivers before running this.
### Standalone
Write a string like this `0x000000f81c650000-0x000000f81c651000` to `/dev/pat_dealloc` in a single write call, without a newline. The module will stupidly attempt to free the given range, check kernel logs.
### With the helper
Run `pat-dealloc raw --start 0x000000f81c650000 --end 0x000000f81c651000` to accomplish the same as the example above.
Alternatively, run `pat-dealloc pci --address 0000:01:00.0` to free all reserved PAT entries for the given PCI device.
You can append `--load` to either of these to automatically load the kernel module for you.
## Building
You will need rust set up and linux headers installed. The makefile was written for arch and might need tweaking on other distros (PRs welcome).
You will also need to re-compile the module for every new kernel you run, which can be automated with [dkms](https://wiki.archlinux.org/title/Dynamic_Kernel_Module_Support) or similar.
`cargo build` to compile the userspace helper. `./target/debug/pat-dealloc` as root to run it.
`cd` into `module` and run `make` to compile the kernel module. Then `insmod pat_dealloc.ko` as root.