<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Linux MMU Notifier: Internals and Heterogeneous Device Use Cases on GPUers</title><link>https://en.gpuers.cn/columns/mmu-notifier/</link><description>Recent content in Linux MMU Notifier: Internals and Heterogeneous Device Use Cases on GPUers</description><image><title>GPUers</title><url>https://en.gpuers.cn/img/og-cover-en.png</url><link>https://en.gpuers.cn/img/og-cover-en.png</link></image><generator>Hugo</generator><language>en-US</language><lastBuildDate>Mon, 23 Nov 2026 00:00:00 +0800</lastBuildDate><atom:link href="https://en.gpuers.cn/columns/mmu-notifier/index.xml" rel="self" type="application/rss+xml"/><item><title>CPU and Device Page-Table Invalidation Synchronization</title><link>https://en.gpuers.cn/columns/mmu-notifier/0003-001/</link><pubDate>Sat, 21 Nov 2026 00:00:00 +0800</pubDate><guid>https://en.gpuers.cn/columns/mmu-notifier/0003-001/</guid><description>A CPU, GPU, RDMA NIC, or virtual-machine MMU may maintain a mapping for the same user virtual-address range at the same time.</description><content:encoded><![CDATA[<p>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 <strong>derived mirror</strong> 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.</p>
<p>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.</p>
<h2 id="11-cpu-page-tables-and-device-mappings">1.1 CPU Page Tables and Device Mappings</h2>
<p>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:</p>
<ul>
<li>The CPU page table translates a user virtual address to a CPU physical page.</li>
<li>A GPU page table, or an IOMMU, performs the device-side translation.</li>
<li>A GPU page table does not choose the physical address independently. It obtains the address from the CPU page table, <code>hmm_range_fault()</code>, or another kernel page-acquisition interface.</li>
</ul>
<p>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.</p>
<p>Figure 1.1.1 shows the conflict caused by <code>munmap()</code>. 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.</p>

<figure class="align-center">
    <img loading="lazy" src="https://en.gpuers.cn/columns/mmu-notifier/0003-001/1.1-problem.en.png" width="2480" height="1440"
         alt="Synchronization between CPU page-table changes and device mappings">
    <figcaption><p>Figure 1.1.1. Synchronization between CPU page-table changes and device mappings</p></figcaption>
</figure>

<p>The object requiring synchronization is not the virtual address value itself but the <strong>translation result retained by the device</strong>. Even if the virtual address remains valid, moving it from page A to page B makes a device translation from VA to A incorrect.</p>
<h2 id="12-pinning-pages-and-dynamic-tracking">1.2 Pinning Pages and Dynamic Tracking</h2>
<p>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.</p>
<p class="table-caption">Table 1.2.1. Applicability of pinning and dynamic tracking</p>

<table>
	<thead>
			<tr>
					<th>Dimension</th>
					<th>Page pinning</th>
					<th>MMU notifier tracking</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>Page state</td>
					<td>Usually remains unchanged during the operation</td>
					<td>Allows swapping, migration, and reclaim</td>
			</tr>
			<tr>
					<td>Registration cost</td>
					<td>Often acquires pages and creates DMA mappings at registration</td>
					<td>Can register a range and acquire pages on demand</td>
			</tr>
			<tr>
					<td>Memory pressure</td>
					<td>Long-lived large pins prevent mm reclaim</td>
					<td>mm can reclaim while the device receives invalidation</td>
			</tr>
			<tr>
					<td>Access timing</td>
					<td>Driver explicitly controls the I/O lifetime</td>
					<td>Notifications and asynchronous device access require a synchronization protocol</td>
			</tr>
			<tr>
					<td>Typical use</td>
					<td>DMA with a defined lifetime</td>
					<td>SVM, ODP, KVM shadow page tables</td>
			</tr>
	</tbody>
</table>
<p>The cost of pinning is not simply an extra memory copy. It is a <strong>restriction on later mm decisions</strong>. 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.</p>
<p>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.</p>
<h2 id="13-basic-invalidation-sequence">1.3 Basic Invalidation Sequence</h2>
<p>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.</p>
<h3 id="131-page-lifetime-and-callback-ordering">1.3.1 Page Lifetime and Callback Ordering</h3>
<p>When a notification represents <code>MMU_NOTIFY_UNMAP</code>, 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.</p>
<p>For a page that is about to be freed, the safe order is:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">notification start
</span></span><span class="line"><span class="cl">  → stop the device from starting new accesses
</span></span><span class="line"><span class="cl">  → wait for accesses already issued to finish
</span></span><span class="line"><span class="cl">  → clear device page-table/IOMMU/DMA mappings and finish TLB invalidation
</span></span><span class="line"><span class="cl">  → callback return
</span></span><span class="line"><span class="cl">  → CPU page-table update and page release
</span></span></code></pre></div><p>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.</p>
<h3 id="132-event-semantics-and-device-actions">1.3.2 Event Semantics and Device Actions</h3>
<p>A page-table change does not necessarily mean that an address disappears permanently:</p>
<ul>
<li>After <code>munmap()</code>, the address mapping may cease to exist.</li>
<li>After swap or migration, the virtual address remains valid, but its PFN changes or its PTE is temporarily absent.</li>
<li><code>mprotect()</code> usually leaves the PFN unchanged but changes the access permissions enforced by the device.</li>
<li>A device-initiated migration may use <code>range-&gt;owner</code> to distinguish a self-generated event from an external invalidation.</li>
</ul>
<p>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.</p>
<h3 id="133-mapping-submission-window">1.3.3 Mapping Submission Window</h3>
<p>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:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">the driver reads the CPU page table and obtains page A
</span></span><span class="line"><span class="cl">CPU reclaim invalidates page A and issues a notification
</span></span><span class="line"><span class="cl">no mapping exists in the device page table yet, so there is nothing to revoke
</span></span><span class="line"><span class="cl">CPU modifies the page table and frees page A
</span></span><span class="line"><span class="cl">the driver writes the previously obtained PFN for A into the device page table
</span></span></code></pre></div><p>The invalidation was not lost. It arrived before the mapping existed. A callback alone cannot close this race, so <code>mmu_interval_notifier</code> 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.</p>
<h2 id="14-scope-of-mmu-notifier">1.4 Scope of MMU Notifier</h2>
<p>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.</p>
<p class="table-caption">Table 1.4.1. MMU notifier responsibility boundaries</p>

<table>
	<thead>
			<tr>
					<th>Component</th>
					<th>Responsible for</th>
					<th>Not responsible for</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>mm</td>
					<td>CPU page-table modification, range construction, subscriber notification</td>
					<td>Device page-table formats and device TLB invalidation commands</td>
			</tr>
			<tr>
					<td>MMU notifier core</td>
					<td>Subscription management, overlapping-range filtering, event and sequence delivery</td>
					<td>Reading device state or interpreting private driver mappings</td>
			</tr>
			<tr>
					<td>Device driver</td>
					<td>Stopping access, clearing hardware mappings, waiting for completion, rebuilding mappings</td>
					<td>Deciding when process mappings are unmapped or migrated</td>
			</tr>
			<tr>
					<td>HMM/ODP</td>
					<td>Page acquisition and fault assistance for devices</td>
					<td>Replacing notifier invalidation synchronization</td>
			</tr>
	</tbody>
</table>
<p>The remaining articles follow three layers:</p>
<ol>
<li>The notifier describes which event occurred.</li>
<li>mm defines when and with which data structures that event is dispatched.</li>
<li>The driver stops asynchronous access, revokes the hardware mapping, and safely rebuilds it.</li>
</ol>
<h2 id="15-typical-use-cases">1.5 Typical Use Cases</h2>
<p>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.</p>
<p class="table-caption">Table 1.5.1. Typical users and synchronized objects</p>

<table>
	<thead>
			<tr>
					<th>User</th>
					<th>Authoritative CPU state</th>
					<th>Derived device state</th>
					<th>Core invalidation action</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>KVM</td>
					<td>CPU page table for host user address (HVA)</td>
					<td>EPT/NPT or shadow page-table entries</td>
					<td>Clear GFN mappings and flush virtual-machine TLBs</td>
			</tr>
			<tr>
					<td>GPU SVM/userptr</td>
					<td>Process CPU page table</td>
					<td>GPU page table and DMA mappings</td>
					<td>Stop queues or wait for fences, then revoke GPU mappings</td>
			</tr>
			<tr>
					<td>RDMA ODP</td>
					<td>CPU page table for a registered range</td>
					<td>MTT, DMA addresses, and hardware caches</td>
					<td>Clear the hardware translation and then release DMA mappings</td>
			</tr>
			<tr>
					<td>VFIO/IOMMU</td>
					<td>CPU page table for a DMA range</td>
					<td>IOMMU mappings and DMA mappings</td>
					<td>Revoke IOMMU mappings and synchronize hardware</td>
			</tr>
	</tbody>
</table>
<p>The application article compares how these mechanisms are implemented without repeating the base notifier and sequence protocol definitions.</p>
<h2 id="16-summary">1.6 Summary</h2>
<p>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.</p>
<p>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.</p>
<p>The next article introduces the event and subscription APIs and explains when <code>mmu_notifier</code> or <code>mmu_interval_notifier</code> is appropriate.</p>
]]></content:encoded></item><item><title>Debugging, Performance, and Source Reference</title><link>https://en.gpuers.cn/columns/mmu-notifier/0003-008/</link><pubDate>Sat, 21 Nov 2026 00:00:00 +0800</pubDate><guid>https://en.gpuers.cn/columns/mmu-notifier/0003-008/</guid><description>An MMU notifier failure often does not end in one callback.</description><content:encoded><![CDATA[<p>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.</p>
<p>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.</p>
<h2 id="81-triage-and-entry-points">8.1 Triage and Entry Points</h2>
<p>MMU notifier failures can be grouped by their visible symptom.</p>
<p class="table-caption">Table 8.1.1. MMU notifier problem classes</p>

<table>
	<thead>
			<tr>
					<th>Symptom</th>
					<th>Possible cause</th>
					<th>First observation point</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>Device accesses a freed page, data corruption, or DMA isolation error</td>
					<td>Incomplete hardware stop, DMA unmapped too early, missed invalidation</td>
					<td>Callback, device PTE/MTT, DMA mapping</td>
			</tr>
			<tr>
					<td>Frequent retry after GPU/NIC fault</td>
					<td>Rapid sequence changes, oversized acquisition range, concurrent unmap</td>
					<td>Invalidation count, <code>-EBUSY</code>, retry ratio</td>
			</tr>
			<tr>
					<td>System stall or lockdep report</td>
					<td>Lock order, removal self-lock, reclaim waiting for callback</td>
					<td>Callback stack, mmap lock, driver lock, resv</td>
			</tr>
			<tr>
					<td>Old permission or PFN remains after update</td>
					<td>Wrong event handling or missed page-level permission change</td>
					<td><code>range-&gt;event</code>, VMA/PTE permissions, owner</td>
			</tr>
			<tr>
					<td>Callback never runs</td>
					<td>Range not covered, insertion failed, or object already removed</td>
					<td><code>mm</code>, range, interval tree, registration result</td>
			</tr>
	</tbody>
</table>
<p>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.</p>

<figure class="align-center">
    <img loading="lazy" src="https://en.gpuers.cn/columns/mmu-notifier/0003-008/8.1-triage.en.png" width="2800" height="1440"
         alt="MMU notifier fault triage">
    <figcaption><p>Figure 8.1.1. MMU notifier fault triage</p></figcaption>
</figure>

<h2 id="82-three-required-time-lines">8.2 Three Required Time Lines</h2>
<p>A minimal trace must answer when CPU state changed, when the subscriber completed invalidation, and when the device submitted or revoked a mapping.</p>
<h3 id="821-cpu-page-table-timeline">8.2.1 CPU Page-Table Timeline</h3>
<p>For every range start/end, record:</p>
<ul>
<li>a comparable <code>mm</code> or process identifier;</li>
<li><code>[start, end)</code>;</li>
<li><code>event</code>;</li>
<li><code>BLOCKABLE</code>;</li>
<li><code>owner</code>;</li>
<li>return value, start time, and end time.</li>
</ul>
<p>Tracepoints, ftrace, temporary Kprobe/eBPF probes, or a driver trace event can provide this data. High-frequency <code>printk</code> alone can alter timing and lock behavior.</p>
<h3 id="822-driver-invalidation-timeline">8.2.2 Driver Invalidation Timeline</h3>
<p>In the callback, record:</p>
<ul>
<li>the notifier object and registered interval;</li>
<li>the event/range intersection;</li>
<li><code>cur_seq</code> and the previous interval sequence;</li>
<li>device-stop start and completion;</li>
<li>PTE/MTT clearing, TLB invalidation, and DMA-unmap order;</li>
<li>callback result.</li>
</ul>
<p>The full interval and event range are useful for diagnosing partial overlap, off-by-page calculations, and end-point errors.</p>
<h3 id="823-device-mapping-timeline">8.2.3 Device Mapping Timeline</h3>
<p>Record in the page-acquisition and submission path:</p>
<ul>
<li>the sequence returned by <code>read_begin()</code>;</li>
<li>HMM/fault return values;</li>
<li>times for DMA and GPU/IOMMU/MTT updates;</li>
<li><code>read_retry()</code> result;</li>
<li>whether the update lock remained held through final submission;</li>
<li>the rollback range after failure.</li>
</ul>
<p>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.</p>
<h2 id="83-debugging-tools-and-constraints">8.3 Debugging Tools and Constraints</h2>
<h3 id="831-lockdep">8.3.1 lockdep</h3>
<p><code>lockdep</code> checks ordering among notifier callbacks, mmap locks, driver locks, DMA reservations, and fence waits. Focus on:</p>
<ul>
<li>remove/unregister holding a lock required by the callback;</li>
<li>fence-signaling code acquiring a driver lock while an invalidation waits for that fence;</li>
<li>ordinary allocation entering reclaim from a callback or mmap path;</li>
<li>HMM acquisition forming a reverse order with device update or queue locks;</li>
<li>notifier core&rsquo;s synthetic <code>lockdep_map</code> spanning an unpaired start/end region.</li>
</ul>
<p>A report normally identifies a driver lock hierarchy problem rather than an error in notifier design.</p>
<h3 id="832-kasan-and-page-isolation">8.3.2 KASAN and Page Isolation</h3>
<p>KASAN is effective for notifier-object, range, and context use-after-free bugs, including:</p>
<ul>
<li>freeing an embedded notifier before remove returns;</li>
<li>destroying a range tree or DMA array while a callback runs;</li>
<li>deleting a range during <code>UNMAP</code> while a fault worker retains a raw pointer;</li>
<li>releasing temporary PFN/DMA storage before <code>-EBUSY</code> retry cleanup completes.</li>
</ul>
<p>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.</p>
<h3 id="833-tracepoint-kprobe-and-bpf">8.3.3 Tracepoint, Kprobe, and BPF</h3>
<p>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.</p>
<p>Use the smallest useful reproducer, such as a single 4 KiB or 2 MiB userptr, and alternate:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">GPU/RDMA read and write
</span></span><span class="line"><span class="cl">munmap / mprotect
</span></span><span class="line"><span class="cl">swap / NUMA migration
</span></span><span class="line"><span class="cl">fault and remap
</span></span><span class="line"><span class="cl">process exit and remove
</span></span></code></pre></div><p>Small, fixed ranges make it easier to correlate a CPU invalidation range with a device fault address.</p>
<h2 id="84-key-metrics">8.4 Key Metrics</h2>
<p>Performance counters do not replace correctness, but they locate pressure in a working implementation.</p>
<p class="table-caption">Table 8.4.1. Key MMU notifier metrics</p>

<table>
	<thead>
			<tr>
					<th>Metric</th>
					<th>Meaning</th>
					<th>Abnormal signal</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>Invalidation count</td>
					<td>CPU changes that overlap a subscription</td>
					<td>Frequent small changes or an oversized notifier</td>
			</tr>
			<tr>
					<td>Range-size distribution</td>
					<td>Address extent revoked per callback</td>
					<td>A few events clearing many unrelated mappings</td>
			</tr>
			<tr>
					<td>Callback duration</td>
					<td>Stop, TLB, and DMA-release time</td>
					<td>Serial waits or slow device fences</td>
			</tr>
			<tr>
					<td><code>-EBUSY</code> ratio</td>
					<td>HMM/page-walk retry rate</td>
					<td>Concurrent invalidation, migration, or fault pressure</td>
			</tr>
			<tr>
					<td><code>read_retry</code> failure rate</td>
					<td>Sequence changes before submission</td>
					<td>Long acquisition window or oversized range</td>
			</tr>
			<tr>
					<td>Blockable-failure rate</td>
					<td>Non-blocking callbacks that could not finish</td>
					<td>Poor non-blocking retry policy</td>
			</tr>
			<tr>
					<td>Fence/queue stop time</td>
					<td>Hardware stop latency</td>
					<td>Long-running queues lack preemption/eviction</td>
			</tr>
			<tr>
					<td>DMA-unmap count</td>
					<td>Number of mappings removed</td>
					<td>Duplicate mappings or incorrect range calculation</td>
			</tr>
	</tbody>
</table>
<p>Record percentiles and group by <code>event</code>. Averages hide the long tail caused by fence waits and large TLB flushes.</p>
<p>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.</p>

<figure class="align-center">
    <img loading="lazy" src="https://en.gpuers.cn/columns/mmu-notifier/0003-008/8.2-metrics.en.png" width="2900" height="1440"
         alt="MMU notifier metrics and bottleneck diagnosis">
    <figcaption><p>Figure 8.4.1. MMU notifier metrics and bottleneck diagnosis</p></figcaption>
</figure>

<h2 id="85-source-reading-order">8.5 Source-Reading Order</h2>
<p>Fix the kernel version first, then read in the order: public contract, notifier core, mm call sites, HMM, and device drivers.</p>
<p class="table-caption">Table 8.5.1. Source-reading path</p>

<table>
	<thead>
			<tr>
					<th>Stage</th>
					<th>File or object</th>
					<th>Focus</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>Public interface</td>
					<td><code>include/linux/mmu_notifier.h</code></td>
					<td>Range, events, callback tables, registration/removal, sequence APIs</td>
			</tr>
			<tr>
					<td>Per-mm container</td>
					<td><code>mm/mmu_notifier.c</code></td>
					<td><code>subscriptions</code>, list/interval tree, start/end, deferred updates</td>
			</tr>
			<tr>
					<td>mm call sites</td>
					<td><code>mm/memory.c</code>, <code>mm/mmap.c</code>, <code>mm/mprotect.c</code>, migration files</td>
					<td>Event construction and start/end boundaries</td>
			</tr>
			<tr>
					<td>HMM</td>
					<td><code>include/linux/hmm.h</code>, <code>mm/hmm.c</code></td>
					<td><code>hmm_range</code>, PFN flags, page walk, remote fault</td>
			</tr>
			<tr>
					<td>KVM</td>
					<td><code>virt/kvm/</code> and architecture-specific KVM MMU code</td>
					<td>HVA→GFN, SPTE clearing, vCPU invalidation sequence</td>
			</tr>
			<tr>
					<td>GPU</td>
					<td>amdgpu/KFD/Nouveau/Xe</td>
					<td>Queue stop, GPU PTE, DMA mapping, fault recovery</td>
			</tr>
			<tr>
					<td>RDMA</td>
					<td><code>drivers/infiniband/core/umem_odp.c</code> and hardware drivers</td>
					<td>MTT, ODP fault, hardware-cache invalidation</td>
			</tr>
			<tr>
					<td>IOMMU/VFIO</td>
					<td>IOMMU and VFIO mapping paths</td>
					<td>DMA lifetime, IOMMU TLB, user mapping management</td>
			</tr>
	</tbody>
</table>
<p>A minimal review asks:</p>
<ol>
<li>Where is the subscription object created, registered, and owned?</li>
<li>Which lock protects the callback, and is it also the final submission lock?</li>
<li>Which hardware states stop first, and which DMA mappings are released last?</li>
<li>Does event handling distinguish <code>UNMAP</code>, <code>MIGRATE</code>, and <code>PROTECTION</code>?</li>
<li>Does mapping construction execute <code>read_begin/read_retry</code>?</li>
<li>Does the failure path release partial submissions?</li>
<li>Do remove/unregister and object destruction satisfy the callback-termination order?</li>
</ol>
<h2 id="86-api-and-structure-reference">8.6 API and Structure Reference</h2>
<p>The final reference lists the most common interfaces. Use the selected kernel&rsquo;s headers for complete signatures and version differences.</p>
<p class="table-caption">Table 8.6.1. Registration, invalidation, and sequence APIs</p>

<table>
	<thead>
			<tr>
					<th>API</th>
					<th>Purpose</th>
					<th>Constraint</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td><code>mmu_notifier_register()</code></td>
					<td>Register a whole-<code>mm</code> traditional notifier</td>
					<td>Initial container creation may need mmap write lock</td>
			</tr>
			<tr>
					<td><code>mmu_notifier_unregister()</code></td>
					<td>Remove a traditional notifier</td>
					<td>Waits for callbacks; do not hold a callback lock</td>
			</tr>
			<tr>
					<td><code>mmu_interval_notifier_insert()</code></td>
					<td>Insert a range subscription</td>
					<td>Tree update can be deferred during invalidation</td>
			</tr>
			<tr>
					<td><code>mmu_interval_notifier_remove()</code></td>
					<td>Remove a range subscription</td>
					<td>No callback after successful return</td>
			</tr>
			<tr>
					<td><code>mmu_interval_read_begin()</code></td>
					<td>Begin a sequence read</td>
					<td>May wait while the interval is invalidating</td>
			</tr>
			<tr>
					<td><code>mmu_interval_set_seq()</code></td>
					<td>Save <code>cur_seq</code> in invalidation</td>
					<td>Use the same lock as final checking</td>
			</tr>
			<tr>
					<td><code>mmu_interval_check_retry()</code></td>
					<td>Early lock-free check</td>
					<td>A false result is not a submission guarantee</td>
			</tr>
			<tr>
					<td><code>mmu_interval_read_retry()</code></td>
					<td>Final pre-submission check</td>
					<td>Use the same lock as <code>invalidate</code></td>
			</tr>
			<tr>
					<td><code>hmm_range_fault()</code></td>
					<td>Walk and, if requested, populate CPU page-table state</td>
					<td>Hold mmap read lock; retry <code>-EBUSY</code></td>
			</tr>
	</tbody>
</table>
<p class="table-caption">Table 8.6.2. Core structures</p>

<table>
	<thead>
			<tr>
					<th>Structure</th>
					<th>Core fields</th>
					<th>Purpose</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td><code>struct mmu_notifier_range</code></td>
					<td><code>mm</code>, <code>start/end</code>, <code>event</code>, <code>flags</code>, <code>owner</code></td>
					<td>One CPU page-table change</td>
			</tr>
			<tr>
					<td><code>struct mmu_notifier</code></td>
					<td><code>hlist</code>, <code>ops</code>, <code>mm</code></td>
					<td>Whole-address-space subscription</td>
			</tr>
			<tr>
					<td><code>struct mmu_interval_notifier</code></td>
					<td><code>interval_tree</code>, <code>ops</code>, <code>mm</code>, <code>invalidate_seq</code></td>
					<td>Range subscription with read-side retry</td>
			</tr>
			<tr>
					<td><code>struct mmu_notifier_subscriptions</code></td>
					<td><code>list</code>, <code>itree</code>, <code>invalidate_seq</code>, <code>wq</code>, <code>deferred_list</code></td>
					<td>Per-mm subscription and invalidation state</td>
			</tr>
			<tr>
					<td><code>struct hmm_range</code></td>
					<td><code>notifier</code>, <code>notifier_seq</code>, <code>start/end</code>, <code>hmm_pfns</code>, flags, owner</td>
					<td>HMM query input and PFN output</td>
			</tr>
	</tbody>
</table>

<figure class="align-center">
    <img loading="lazy" src="https://en.gpuers.cn/columns/mmu-notifier/0003-008/8.3-object-map.en.png" width="2920" height="1520"
         alt="MMU notifier APIs and object relations">
    <figcaption><p>Figure 8.6.1. MMU notifier APIs and object relations</p></figcaption>
</figure>

<h2 id="87-series-summary">8.7 Series Summary</h2>
<p>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.</p>
<p>The series has three levels:</p>
<p class="table-caption">Table 8.7.1. Series content map</p>

<table>
	<thead>
			<tr>
					<th>Level</th>
					<th>Articles</th>
					<th>Central question</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>Events and models</td>
					<td>Articles 1–2</td>
					<td>Why mappings invalidate; how events and subscriptions express invalidation</td>
			</tr>
			<tr>
					<td>Synchronization and implementation</td>
					<td>Articles 3–4</td>
					<td>How sequences protect submission and how mm manages and dispatches subscriptions</td>
			</tr>
			<tr>
					<td>Use and engineering practice</td>
					<td>Articles 5–8</td>
					<td>HMM/device faults, applications, driver constraints, debugging, and reference</td>
			</tr>
	</tbody>
</table>
<p>The implementation loop is:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">subscription covers the mapping lifetime
</span></span><span class="line"><span class="cl">→ callback follows BLOCKABLE rules
</span></span><span class="line"><span class="cl">→ hardware stops and old mapping is revoked
</span></span><span class="line"><span class="cl">→ HMM/fault acquisition uses the sequence protocol
</span></span><span class="line"><span class="cl">→ the same lock validates and submits the new mapping
</span></span><span class="line"><span class="cl">→ the failure path performs complete rollback
</span></span></code></pre></div><p>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.</p>
]]></content:encoded></item><item><title>HMM and Device Page Faults</title><link>https://en.gpuers.cn/columns/mmu-notifier/0003-005/</link><pubDate>Sat, 21 Nov 2026 00:00:00 +0800</pubDate><guid>https://en.gpuers.cn/columns/mmu-notifier/0003-005/</guid><description>mmuintervalnotifier synchronizes invalidation after CPU page-table changes, while hmmrangefault() lets a device fault read or populate the CPU mapping.</description><content:encoded><![CDATA[<p><code>mmu_interval_notifier</code> synchronizes invalidation after CPU page-table changes, while <code>hmm_range_fault()</code> lets a device fault read or populate the CPU mapping. Heterogeneous Memory Management (HMM) combines the two: a device faults on a process virtual address, the kernel walks the CPU page table and returns PFNs, and the driver creates a device mapping after sequence validation.</p>
<p>HMM does not describe a GPU page-table format and does not stop hardware, issue device TLB invalidation, or create DMA mappings on behalf of a driver. It provides the CPU-mm page result, a page-fault entry point, and device-private-page semantics. This article focuses on <code>struct hmm_range</code>, the input/output contract of <code>hmm_range_fault()</code>, and the complete device-fault path through mapping submission.</p>
]]></content:encoded></item><item><title>MMU Notifier Driver Implementation Constraints</title><link>https://en.gpuers.cn/columns/mmu-notifier/0003-007/</link><pubDate>Sat, 21 Nov 2026 00:00:00 +0800</pubDate><guid>https://en.gpuers.cn/columns/mmu-notifier/0003-007/</guid><description>The preceding articles described events, kernel paths, and sequence synchronization.</description><content:encoded>&lt;p>The preceding articles described events, kernel paths, and sequence synchronization. For a driver, correctness depends on two facts at callback return: the hardware has stopped using old mappings, and mapping submission is serialized with invalidation through the same lock.&lt;/p>
&lt;p>This article organizes those requirements from a driver perspective. It focuses on where the APIs must be placed, which work cannot be deferred asynchronously, and how a partial mapping is rolled back after an error.&lt;/p>
</content:encoded></item><item><title>MMU Notifier Events and Subscription Models</title><link>https://en.gpuers.cn/columns/mmu-notifier/0003-002/</link><pubDate>Sat, 21 Nov 2026 00:00:00 +0800</pubDate><guid>https://en.gpuers.cn/columns/mmu-notifier/0003-002/</guid><description>An MMU notifier can be viewed as an observer mechanism that CPU mm exposes to users of secondary page tables.</description><content:encoded><![CDATA[<p>An MMU notifier can be viewed as an observer mechanism that CPU mm exposes to users of secondary page tables. The difficult part is not the subscription list itself. It is determining when an event occurs, which information it carries, and what a subscriber must complete before returning from the callback.</p>
<p>When the CPU page table changes, Linux mm sends the change to users holding derived mappings. An MMU notifier carries three classes of information: the affected <code>mm</code>, the address range, and the meaning of the change. Subscribers use that information to stop device access, revoke mappings, and complete hardware synchronization.</p>
<p>This article establishes the interface model used by the rest of the series: first the event description, then the two subscription objects and their callbacks, and finally the selection rules.</p>
]]></content:encoded></item><item><title>MMU Notifier Kernel Implementation Paths</title><link>https://en.gpuers.cn/columns/mmu-notifier/0003-004/</link><pubDate>Sat, 21 Nov 2026 00:00:00 +0800</pubDate><guid>https://en.gpuers.cn/columns/mmu-notifier/0003-004/</guid><description>Chapter 2 introduced events, subscription objects, and callbacks. Chapter 3 explained the interval sequence protocol.</description><content:encoded><![CDATA[<p>Chapter 2 introduced events, subscription objects, and callbacks. Chapter 3 explained the interval sequence protocol. This article returns to Linux mm internals and examines how notifier core manages subscriptions, dispatches invalidations, and connects events from <code>munmap()</code>, protection changes, and migration to driver callbacks.</p>
<p>It focuses on notifier core and mm call sites. Device-specific stopping, DMA waits, and IOMMU teardown are covered in the application and driver-constraint articles.</p>
]]></content:encoded></item><item><title>mmu_interval_notifier Sequence Synchronization</title><link>https://en.gpuers.cn/columns/mmu-notifier/0003-003/</link><pubDate>Sat, 21 Nov 2026 00:00:00 +0800</pubDate><guid>https://en.gpuers.cn/columns/mmu-notifier/0003-003/</guid><description>Chapter 2 explained how a notifier callback revokes mappings already present in a device page table.</description><content:encoded><![CDATA[<p>Chapter 2 explained how a notifier callback revokes mappings already present in a device page table. One race remains uncovered: a driver has read the CPU page table but has not yet written the result into the device page table. If invalidation arrives in that window, the device contains no entry for the callback to revoke, and the driver may later submit an obsolete PFN.</p>
<p><code>mmu_interval_notifier</code> records such invalidations with sequence numbers. The driver obtains a sequence before reading and compares it before submission. If the sequence changed, it discards the result and retries. This mechanism complements rather than replaces synchronous invalidation.</p>
]]></content:encoded></item><item><title>Typical MMU Notifier Applications</title><link>https://en.gpuers.cn/columns/mmu-notifier/0003-006/</link><pubDate>Sat, 21 Nov 2026 00:00:00 +0800</pubDate><guid>https://en.gpuers.cn/columns/mmu-notifier/0003-006/</guid><description>MMU notifier users maintain different derived mappings.</description><content:encoded>&lt;p>MMU notifier users maintain different derived mappings. KVM maintains EPT/NPT or shadow page tables, GPU drivers maintain device page tables and DMA mappings, and RDMA drivers maintain MTTs, DMA addresses, and hardware caches. They receive the same CPU page-table invalidation events but execute different hardware actions.&lt;/p>
&lt;p>This article compares KVM, GPU SVM/userptr, RDMA ODP, and VFIO/IOMMU through one common model rather than reproducing each driver line by line.&lt;/p>
</content:encoded></item></channel></rss>