A Lilu plugin that keeps NVMe TRIM (Dataset Management / deallocate) away from specific devices whose firmware does not survive it, while every other NVMe device keeps TRIM unchanged.
Target device: a 750 GB Intel Optane SSDPD21K750GAM. Its firmware drops off the
bus when it receives TRIM and takes the machine with it. If you wonder what it is,
read this: Bought a modified D4800X
Milestone M3. Discards are suppressed for every device that matches a rule in the
kext's Info.plist, at the point where a storage discard would become an NVMe
Dataset Management command; every other NVMe device reaches the original
implementation unchanged, byte for byte.
The interception points are read from the running IONVMeFamily slice's own
symbol table, by exact mangled name, with the slice base recovered from the image
itself. Nothing build-specific is compiled in, so an IONVMeFamily update that
keeps those symbols keeps the driver working, and there is no table of measured
offsets waiting to go stale in its place. The distances observed at run time are
published (NvmeHookLayout) for the record.
The suppression is measured, not assumed. Three counters are published per
device: seen (discards entering the filter), blocked (of those, the ones
short-circuited) and dsm (Dataset Management commands that left for that
device). On the matched device blocked tracks seen while dsm stays at zero,
and the volume keeps working: written, read back and verified across bulk deletes,
unmount/remount cycles and a sleep/wake cycle.
Verified on the control device first, which shares the target's media family, and
then on the target itself: the Optane was erased to a single APFS volume and put
through an hour of write/read-back/delete cycles, three unmount/remount cycles
and a sleep/wake, with blocked == seen and dsm at zero throughout — 394
discards swallowed, none reaching the hardware — and diskutil verifyVolume
clean at the end. DEBUG.md carries the implementation, the property table and
the way the hooks are resolved.
The hooks are resolved from a live IONVMeController: its vtable pointer leads to
the slice, and the slice's symbol table names the three functions. The driver
never reads the file system, and a slice whose symbols are gone makes it inert
instead of dangerous.
The devices to suppress are listed in this kext's Info.plist, under the
personality, and nowhere else — there are no device names in the source and no
boot argument that changes matching: loading the plugin means its rules apply.
<key>NvmeHookDevices</key>
<array>
<dict>
<key>Model</key>
<string>INTEL SSDPD21K750GAM</string>
<key>Serial</key>
<string>*</string>
</dict>
</array>- Several dicts may be listed; they are tried in order and the first match wins.
*in either field matches any value. The shipped rule pins the model and accepts any serial, so every drive of that model is covered; replace the*with that drive's serial to pin the single unit instead.- Matching is on the block storage device the discard belongs to, and the result is cached per device.
- Edit the list on the ESP copy of
NvmeHook.kextand reboot; OpenCore injects the bundle, so a change needs a restart.
NvmeHookDebug in the same dictionary decides how much the driver writes to the
IORegistry. It is false by default, and absent means false.
| value | what is published |
|---|---|
false |
NvmeHookVersion, NvmeHookPatches, NvmeHookConfig, NvmeHookHooks, NvmeHookTotal |
true |
the above plus the resolved hook addresses, the slice and symbol-table readings, the header-scan trace, the instance count, the bus scan, the worker state, the per-controller match report and the per-device match report with its own counter |
Diagnostic properties cost a registry write each, which is why they are opt-in;
the counters in NvmeHookTotal are always published because they are the proof
that suppression works. Changing the switch needs a reboot, like the rule list.
| boot-arg | effect |
|---|---|
-nvmehookoff |
do not load the plugin at all (checked by Lilu) |
-nvmehookdbg |
Lilu debug output for this plugin |
-nvmehookbeta |
allow loading on beta kernels |
-nvmehookoff is the kill switch: with it the machine behaves as if the driver
were not installed. It is also the switch that removes all protection, so it is
for recovery, not for daily use.
- macOS 11 through 26 (Darwin 20 through 25), x86_64.
- Lilu 1.7.x loaded as
as.vit9696.Lilu. - A Lilu source tree at build time (
Headers/andLibrary/plugin_start.cpp); a releasedLilu.kextships only the headers and is not enough.
Run on macOS; neither Xcode nor sudo is required, only the Command Line Tools:
git submodule update --init MacKernelSDK
sh Scripts/build-noxcode.sh # Lilu tree from $HOME/src/LiluThe script writes one output directory per run and records the newest kext in
build/latest-noxcode-build.txt. The version lives in VERSION= inside the
script and feeds both the binary and Info.plist.
Lilu and this plugin are installed on the ESP only, never on the system volume:
- Copy
NvmeHook.kexttoEFI/OC/Kexts/on the internal SATA disk's EFI partition. - Add one
Kernel > Addentry for it afterLilu.kextinEFI/OC/config.plist, keeping a backup of the plist next to itself and validating the result. - Reboot; the kext is injected by OpenCore.
Putting the kext in /Library/Extensions does not work: kmutil resolves
dependencies against kexts on disk, Lilu is not there, and the collection build
fails.
kextstat | grep -iE 'nvmehook|IONVMeFamily'
ioreg -n IOResources -l -w0 | grep -E 'NvmeHook(Version|Patches|Config|Resolve|Layout|Hooks|Total)'
ioreg -r -c IONVMeBlockStorageDevice -l -w0 | grep NvmeHookCountersNvmeHookResolve has to read resolved by symbols …; symbol path: ok. Anything
else carries the reason it failed — no Mach-O header below the vptr,
implausible slide, symbol table parsed but the names are missing — and means
nothing was patched. NvmeHookLayout prints the distances between the vtable
slot and each hook in the running image, plus the slice and its symbol count, for
the record.
The kernel log is not a usable record here: it is a ring buffer that ordinary
boot traffic overwrites within a minute. DEBUG.md explains the IORegistry
report, the counters and the debugging procedure.