An MMU notifier failure often does not end in one callback. A driver may miss an invalidation and submit an old PFN much later, or validate the sequence correctly but deadlock in a callback wait. Investigation therefore needs three time lines: CPU page-table events, notifier callbacks, and device mapping submission/revocation.

This concluding article begins with fault classification and observation, then provides source-reading guidance, API reference tables, and the final implementation checklist. Interface details follow current Linux mainline and should be reconciled with the selected kernel version when applied to a concrete driver.

8.1 Triage and Entry Points

MMU notifier failures can be grouped by their visible symptom.

Table 8.1.1. MMU notifier problem classes

SymptomPossible causeFirst observation point
Device accesses a freed page, data corruption, or DMA isolation errorIncomplete hardware stop, DMA unmapped too early, missed invalidationCallback, device PTE/MTT, DMA mapping
Frequent retry after GPU/NIC faultRapid sequence changes, oversized acquisition range, concurrent unmapInvalidation count, -EBUSY, retry ratio
System stall or lockdep reportLock order, removal self-lock, reclaim waiting for callbackCallback stack, mmap lock, driver lock, resv
Old permission or PFN remains after updateWrong event handling or missed page-level permission changerange->event, VMA/PTE permissions, owner
Callback never runsRange not covered, insertion failed, or object already removedmm, range, interval tree, registration result

Start by asking whether the event reached the subscriber. If it did not, inspect subscription lifetime and range coverage. If it arrived but hardware did not stop, inspect callback synchronization. Only after event and sequence are correct should the final submission window be examined.

MMU notifier fault triage

Figure 8.1.1. MMU notifier fault triage

8.2 Three Required Time Lines

A minimal trace must answer when CPU state changed, when the subscriber completed invalidation, and when the device submitted or revoked a mapping.

8.2.1 CPU Page-Table Timeline

For every range start/end, record:

  • a comparable mm or process identifier;
  • [start, end);
  • event;
  • BLOCKABLE;
  • owner;
  • return value, start time, and end time.

Tracepoints, ftrace, temporary Kprobe/eBPF probes, or a driver trace event can provide this data. High-frequency printk alone can alter timing and lock behavior.

8.2.2 Driver Invalidation Timeline

In the callback, record:

  • the notifier object and registered interval;
  • the event/range intersection;
  • cur_seq and the previous interval sequence;
  • device-stop start and completion;
  • PTE/MTT clearing, TLB invalidation, and DMA-unmap order;
  • callback result.

The full interval and event range are useful for diagnosing partial overlap, off-by-page calculations, and end-point errors.

8.2.3 Device Mapping Timeline

Record in the page-acquisition and submission path:

  • the sequence returned by read_begin();
  • HMM/fault return values;
  • times for DMA and GPU/IOMMU/MTT updates;
  • read_retry() result;
  • whether the update lock remained held through final submission;
  • the rollback range after failure.

Together, these time lines identify whether the stale mapping came from a missed callback, incomplete hardware stop, missing sequence update, early unlock, or incomplete rollback.

8.3 Debugging Tools and Constraints

8.3.1 lockdep

lockdep checks ordering among notifier callbacks, mmap locks, driver locks, DMA reservations, and fence waits. Focus on:

  • remove/unregister holding a lock required by the callback;
  • fence-signaling code acquiring a driver lock while an invalidation waits for that fence;
  • ordinary allocation entering reclaim from a callback or mmap path;
  • HMM acquisition forming a reverse order with device update or queue locks;
  • notifier core’s synthetic lockdep_map spanning an unpaired start/end region.

A report normally identifies a driver lock hierarchy problem rather than an error in notifier design.

8.3.2 KASAN and Page Isolation

KASAN is effective for notifier-object, range, and context use-after-free bugs, including:

  • freeing an embedded notifier before remove returns;
  • destroying a range tree or DMA array while a callback runs;
  • deleting a range during UNMAP while a fault worker retains a raw pointer;
  • releasing temporary PFN/DMA storage before -EBUSY retry cleanup completes.

Hardware access to a freed page may instead appear as an IOMMU/GPU fault or silent corruption. Correlate KASAN with IOMMU/GPU logs, reset reports, and event traces.

8.3.3 Tracepoint, Kprobe, and BPF

Use stable tracepoints for supported interfaces and Kprobe/eBPF for temporary internal checks. Group events by notifier identity and record a monotonic timestamp and CPU. Function names alone are insufficient; range, sequence, lock state, and result are needed to prove ordering.

Use the smallest useful reproducer, such as a single 4 KiB or 2 MiB userptr, and alternate:

GPU/RDMA read and write
munmap / mprotect
swap / NUMA migration
fault and remap
process exit and remove

Small, fixed ranges make it easier to correlate a CPU invalidation range with a device fault address.

8.4 Key Metrics

Performance counters do not replace correctness, but they locate pressure in a working implementation.

Table 8.4.1. Key MMU notifier metrics

MetricMeaningAbnormal signal
Invalidation countCPU changes that overlap a subscriptionFrequent small changes or an oversized notifier
Range-size distributionAddress extent revoked per callbackA few events clearing many unrelated mappings
Callback durationStop, TLB, and DMA-release timeSerial waits or slow device fences
-EBUSY ratioHMM/page-walk retry rateConcurrent invalidation, migration, or fault pressure
read_retry failure rateSequence changes before submissionLong acquisition window or oversized range
Blockable-failure rateNon-blocking callbacks that could not finishPoor non-blocking retry policy
Fence/queue stop timeHardware stop latencyLong-running queues lack preemption/eviction
DMA-unmap countNumber of mappings removedDuplicate mappings or incorrect range calculation

Record percentiles and group by event. Averages hide the long tail caused by fence waits and large TLB flushes.

Performance work must not trade away safety. Merging adjacent PTE/TLB operations or prefetching pages can improve latency, but actual hardware revocation cannot be deferred merely to shorten callback duration.

MMU notifier metrics and bottleneck diagnosis

Figure 8.4.1. MMU notifier metrics and bottleneck diagnosis

8.5 Source-Reading Order

Fix the kernel version first, then read in the order: public contract, notifier core, mm call sites, HMM, and device drivers.

Table 8.5.1. Source-reading path

StageFile or objectFocus
Public interfaceinclude/linux/mmu_notifier.hRange, events, callback tables, registration/removal, sequence APIs
Per-mm containermm/mmu_notifier.csubscriptions, list/interval tree, start/end, deferred updates
mm call sitesmm/memory.c, mm/mmap.c, mm/mprotect.c, migration filesEvent construction and start/end boundaries
HMMinclude/linux/hmm.h, mm/hmm.chmm_range, PFN flags, page walk, remote fault
KVMvirt/kvm/ and architecture-specific KVM MMU codeHVA→GFN, SPTE clearing, vCPU invalidation sequence
GPUamdgpu/KFD/Nouveau/XeQueue stop, GPU PTE, DMA mapping, fault recovery
RDMAdrivers/infiniband/core/umem_odp.c and hardware driversMTT, ODP fault, hardware-cache invalidation
IOMMU/VFIOIOMMU and VFIO mapping pathsDMA lifetime, IOMMU TLB, user mapping management

A minimal review asks:

  1. Where is the subscription object created, registered, and owned?
  2. Which lock protects the callback, and is it also the final submission lock?
  3. Which hardware states stop first, and which DMA mappings are released last?
  4. Does event handling distinguish UNMAP, MIGRATE, and PROTECTION?
  5. Does mapping construction execute read_begin/read_retry?
  6. Does the failure path release partial submissions?
  7. Do remove/unregister and object destruction satisfy the callback-termination order?

8.6 API and Structure Reference

The final reference lists the most common interfaces. Use the selected kernel’s headers for complete signatures and version differences.

Table 8.6.1. Registration, invalidation, and sequence APIs

APIPurposeConstraint
mmu_notifier_register()Register a whole-mm traditional notifierInitial container creation may need mmap write lock
mmu_notifier_unregister()Remove a traditional notifierWaits for callbacks; do not hold a callback lock
mmu_interval_notifier_insert()Insert a range subscriptionTree update can be deferred during invalidation
mmu_interval_notifier_remove()Remove a range subscriptionNo callback after successful return
mmu_interval_read_begin()Begin a sequence readMay wait while the interval is invalidating
mmu_interval_set_seq()Save cur_seq in invalidationUse the same lock as final checking
mmu_interval_check_retry()Early lock-free checkA false result is not a submission guarantee
mmu_interval_read_retry()Final pre-submission checkUse the same lock as invalidate
hmm_range_fault()Walk and, if requested, populate CPU page-table stateHold mmap read lock; retry -EBUSY

Table 8.6.2. Core structures

StructureCore fieldsPurpose
struct mmu_notifier_rangemm, start/end, event, flags, ownerOne CPU page-table change
struct mmu_notifierhlist, ops, mmWhole-address-space subscription
struct mmu_interval_notifierinterval_tree, ops, mm, invalidate_seqRange subscription with read-side retry
struct mmu_notifier_subscriptionslist, itree, invalidate_seq, wq, deferred_listPer-mm subscription and invalidation state
struct hmm_rangenotifier, notifier_seq, start/end, hmm_pfns, flags, ownerHMM query input and PFN output
MMU notifier APIs and object relations

Figure 8.6.1. MMU notifier APIs and object relations

8.7 Series Summary

MMU notifier handles a derived-mapping consistency problem. CPU mm owns the authoritative user address space; KVM, GPU, RDMA, and IOMMU users retain mappings derived from it. On a CPU page-table change, devices stop access and revoke derived state before CPU pages can be released or migrated.

The series has three levels:

Table 8.7.1. Series content map

LevelArticlesCentral question
Events and modelsArticles 1–2Why mappings invalidate; how events and subscriptions express invalidation
Synchronization and implementationArticles 3–4How sequences protect submission and how mm manages and dispatches subscriptions
Use and engineering practiceArticles 5–8HMM/device faults, applications, driver constraints, debugging, and reference

The implementation loop is:

subscription covers the mapping lifetime
→ callback follows BLOCKABLE rules
→ hardware stops and old mapping is revoked
→ HMM/fault acquisition uses the sequence protocol
→ the same lock validates and submits the new mapping
→ the failure path performs complete rollback

The key is not any single API. Event, sequence, lock, and hardware state must all be correct. If one is missing, the driver may look correct in software while the device still holds an old address or permission.