⬢ DragonFlyBSD Kernel Audit
DF-4507 / static_proof.sh
← back to finding ↓ download raw
#!/bin/sh
# DF-4507 static proof: TTM page-pool reclamation is dead code on DragonFly.
# Run from the repo root (read-only; touches nothing).
# Every command's expected output is annotated below.

echo "=== [1] The only vm_lowmem references in the whole kernel tree ==="
echo "# (expect: only ttm_page_alloc.c REGISTER/DEREGISTER — no DECLARATION, no INVOKE)"
rg -n "vm_lowmem" sys/ | grep -v ttm_page_alloc.c || echo "NO OTHER REFS: vm_lowmem is never declared/invoked anywhere"
rg -n "vm_lowmem" sys/dev/drm/ttm/ttm_page_alloc.c

echo
echo "=== [2] Every EVENTHANDLER_INVOKE site in the kernel (none fire vm_lowmem) ==="
rg -n "EVENTHANDLER_INVOKE" sys/ --type c -o | sort -u | head -40
rg -c "EVENTHANDLER_INVOKE\(vm_lowmem" sys/ || echo "COUNT=0: EVENTHANDLER_INVOKE(vm_lowmem) does not exist"

echo
echo "=== [3] register_shrinker is never defined (only called from dead code) ==="
rg -n "register_shrinker" sys/
echo "# i915's call is inside '#if 0':"
sed -n '520,532p' sys/dev/drm/i915/i915_gem_shrinker.c
echo "# dma pool variant is preprocessed out:"
sed -n '34,38p' sys/dev/drm/ttm/ttm_page_alloc_dma.c
echo "# the shrinker shim defines types only — no registration API:"
cat sys/dev/drm/include/linux/shrinker.h | sed -n '30,49p'

echo
echo "=== [4] ttm_page_alloc.c itself is LIVE (no guard) and registers the callback ==="
sed -n '442,454p' sys/dev/drm/ttm/ttm_page_alloc.c

echo
echo "=== [5] The only LIVE reclamation path: put-path trim at options.max_size ==="
sed -n '709,721p' sys/dev/drm/ttm/ttm_page_alloc.c
echo "# max_size source (half the kernel zone, in pages):"
sed -n '351,355p' sys/dev/drm/ttm/ttm_memory.c

echo
echo "=== [6] Signature landmine if the event ever gets wired naively ==="
echo "# vm_lowmem handlers would be invoked as func(arg, <int>); the registered"
echo "# ttm_pool_shrink_scan expects (struct shrinker *, struct shrink_control *)"
echo "# and dereferences sc at line 398 (sc->gfp_mask = M_WAITOK) and 418:"
sed -n '385,424p' sys/dev/drm/ttm/ttm_page_alloc.c