A CPU, GPU, RDMA NIC, or virtual-machine MMU may maintain a mapping for the same user virtual-address range at the same time. Linux mm still owns the CPU page table, but a device usually has a separate page table, IOMMU mapping, or hardware translation cache, which is essentially a derived mirror of the CPU page table. Once a device asynchronously retains and uses this mirror, the device must stop using the old physical page and revoke the derived mapping before that page is freed or reused.

The MMU notifier mechanism is the synchronization notification interface that Linux mm provides for these users. This article explains why it exists and defines what it can and cannot guarantee. Subsequent articles cover events, data structures, sequence validation, and driver implementation.

1.1 CPU Page Tables and Device Mappings

A user process has one virtual address space, but the CPU need not be its only execution agent. When a GPU accesses a user buffer, two independent translation relations exist:

  • The CPU page table translates a user virtual address to a CPU physical page.
  • A GPU page table, or an IOMMU, performs the device-side translation.
  • A GPU page table does not choose the physical address independently. It obtains the address from the CPU page table, hmm_range_fault(), or another kernel page-acquisition interface.

Identical virtual addresses do not make the two page tables naturally synchronized. A CPU page-table update does not change the GPU page table automatically, so the GPU may retain a valid entry for an old PFN. RDMA, KVM, and VFIO have the same problem, although their derived mappings are memory translation tables, EPT/NPT entries, or IOMMU page tables.

Figure 1.1.1 shows the conflict caused by munmap(). The CPU is removing an address mapping while the device page table still describes the old physical page. If the CPU reclaims and reallocates that page, a later DMA or GPU access through the stale mapping targets a page that no longer belongs to the process.

Synchronization between CPU page-table changes and device mappings

Figure 1.1.1. Synchronization between CPU page-table changes and device mappings

The object requiring synchronization is not the virtual address value itself but the translation result retained by the device. Even if the virtual address remains valid, moving it from page A to page B makes a device translation from VA to A incorrect.

1.2 Pinning Pages and Dynamic Tracking

Traditional device DMA may acquire user pages and pin them to prevent swapping or migration during an operation. This remains useful for short-lived, known-range I/O that requires stable physical pages, but it is not a universal solution.

Table 1.2.1. Applicability of pinning and dynamic tracking

DimensionPage pinningMMU notifier tracking
Page stateUsually remains unchanged during the operationAllows swapping, migration, and reclaim
Registration costOften acquires pages and creates DMA mappings at registrationCan register a range and acquire pages on demand
Memory pressureLong-lived large pins prevent mm reclaimmm can reclaim while the device receives invalidation
Access timingDriver explicitly controls the I/O lifetimeNotifications and asynchronous device access require a synchronization protocol
Typical useDMA with a defined lifetimeSVM, ODP, KVM shadow page tables

The cost of pinning is not simply an extra memory copy. It is a restriction on later mm decisions. If a GPU or NIC pins a large amount of user memory for a long period, mm cannot swap those pages or move them among NUMA nodes or memory domains. SVM, ODP, and virtual-machine memory have longer lifetimes, larger address ranges, and less predictable access patterns, so they need a mechanism that allows pages to remain part of normal system memory management.

An MMU notifier does not eliminate pinning. If a device has already started DMA or submitted GPU work, the driver still needs a fence, DMA reservation, or another synchronization mechanism that lets the callback wait for that access to finish. The notifier solves the synchronization point for a pending CPU page-table change; it does not make arbitrary asynchronous device work disappear before the callback returns.

1.3 Basic Invalidation Sequence

The MMU notifier lies between mm and a subscribing device. A page-table-changing path initializes an invalidation range, notifies subscribers, modifies the CPU page table, flushes the TLB, and finishes the notification. A device driver must satisfy the resulting constraints.

1.3.1 Page Lifetime and Callback Ordering

When a notification represents MMU_NOTIFY_UNMAP, migration, swap, a protection change, or a device-exclusive transition, the subscriber must update or revoke the corresponding device mapping. The important point is not whether the callback was invoked, but whether the device can still access the range when the callback returns.

For a page that is about to be freed, the safe order is:

notification start
  → stop the device from starting new accesses
  → wait for accesses already issued to finish
  → clear device page-table/IOMMU/DMA mappings and finish TLB invalidation
  → callback return
  → CPU page-table update and page release

If a callback only marks a software object invalid without waiting for hardware use to finish, hardware may still read or write the old address after the CPU frees the page.

1.3.2 Event Semantics and Device Actions

A page-table change does not necessarily mean that an address disappears permanently:

  • After munmap(), the address mapping may cease to exist.
  • After swap or migration, the virtual address remains valid, but its PFN changes or its PTE is temporarily absent.
  • mprotect() usually leaves the PFN unchanged but changes the access permissions enforced by the device.
  • A device-initiated migration may use range->owner to distinguish a self-generated event from an external invalidation.

An MMU notifier is therefore not a broadcast interface that reacquires every page for every callback. The event type determines whether the driver can update only permissions, whether it must destroy range state, and whether the mapping may later be rebuilt.

1.3.3 Mapping Submission Window

A notification can revoke entries that already exist in a device page table, but it cannot revoke a mapping result that has not yet been submitted. Consider this sequence:

the driver reads the CPU page table and obtains page A
CPU reclaim invalidates page A and issues a notification
no mapping exists in the device page table yet, so there is nothing to revoke
CPU modifies the page table and frees page A
the driver writes the previously obtained PFN for A into the device page table

The invalidation was not lost. It arrived before the mapping existed. A callback alone cannot close this race, so mmu_interval_notifier provides a sequence-and-retry protocol that lets a driver verify that page acquisition has not been invalidated before it submits a mapping. Chapter 3 covers this protocol.

1.4 Scope of MMU Notifier

An MMU notifier provides a generic page-table-change event mechanism; it does not implement all memory management for a concrete device. Table 1.4.1 summarizes the responsibility boundaries.

Table 1.4.1. MMU notifier responsibility boundaries

ComponentResponsible forNot responsible for
mmCPU page-table modification, range construction, subscriber notificationDevice page-table formats and device TLB invalidation commands
MMU notifier coreSubscription management, overlapping-range filtering, event and sequence deliveryReading device state or interpreting private driver mappings
Device driverStopping access, clearing hardware mappings, waiting for completion, rebuilding mappingsDeciding when process mappings are unmapped or migrated
HMM/ODPPage acquisition and fault assistance for devicesReplacing notifier invalidation synchronization

The remaining articles follow three layers:

  1. The notifier describes which event occurred.
  2. mm defines when and with which data structures that event is dispatched.
  3. The driver stops asynchronous access, revokes the hardware mapping, and safely rebuilds it.

1.5 Typical Use Cases

Although many subsystems use MMU notifiers, they share the same basic shape: a device holds a mapping derived from a process address space, and the device must revoke that mapping when the CPU page table changes.

Table 1.5.1. Typical users and synchronized objects

UserAuthoritative CPU stateDerived device stateCore invalidation action
KVMCPU page table for host user address (HVA)EPT/NPT or shadow page-table entriesClear GFN mappings and flush virtual-machine TLBs
GPU SVM/userptrProcess CPU page tableGPU page table and DMA mappingsStop queues or wait for fences, then revoke GPU mappings
RDMA ODPCPU page table for a registered rangeMTT, DMA addresses, and hardware cachesClear the hardware translation and then release DMA mappings
VFIO/IOMMUCPU page table for a DMA rangeIOMMU mappings and DMA mappingsRevoke IOMMU mappings and synchronize hardware

The application article compares how these mechanisms are implemented without repeating the base notifier and sequence protocol definitions.

1.6 Summary

MMU notifiers exist because CPU mm and devices maintain independent mappings. The CPU page table is the authoritative state of a user address space, while a device mapping is a derived cache. When the CPU reclaims, migrates, or changes permissions for a page, the device cannot continue using the old mapping.

Pinning prevents mm from changing pages during an operation. An MMU notifier allows mm to change pages while notifying the device in time. The mechanisms can be combined. Notification alone is still insufficient unless it is joined with a driver lock, a device fence or DMA completion mechanism, and the required hardware stop sequence.

The next article introduces the event and subscription APIs and explains when mmu_notifier or mmu_interval_notifier is appropriate.