@@ -257,3 +257,79 @@ fences in the kernel. This means:
257257 userspace is allowed to use userspace fencing or long running compute
258258 workloads. This also means no implicit fencing for shared buffers in these
259259 cases.
260+
261+ Recoverable Hardware Page Faults Implications
262+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
263+
264+ Modern hardware supports recoverable page faults, which has a lot of
265+ implications for DMA fences.
266+
267+ First, a pending page fault obviously holds up the work that's running on the
268+ accelerator and a memory allocation is usually required to resolve the fault.
269+ But memory allocations are not allowed to gate completion of DMA fences, which
270+ means any workload using recoverable page faults cannot use DMA fences for
271+ synchronization. Synchronization fences controlled by userspace must be used
272+ instead.
273+
274+ On GPUs this poses a problem, because current desktop compositor protocols on
275+ Linux rely on DMA fences, which means without an entirely new userspace stack
276+ built on top of userspace fences, they cannot benefit from recoverable page
277+ faults. Specifically this means implicit synchronization will not be possible.
278+ The exception is when page faults are only used as migration hints and never to
279+ on-demand fill a memory request. For now this means recoverable page
280+ faults on GPUs are limited to pure compute workloads.
281+
282+ Furthermore GPUs usually have shared resources between the 3D rendering and
283+ compute side, like compute units or command submission engines. If both a 3D
284+ job with a DMA fence and a compute workload using recoverable page faults are
285+ pending they could deadlock:
286+
287+ - The 3D workload might need to wait for the compute job to finish and release
288+ hardware resources first.
289+
290+ - The compute workload might be stuck in a page fault, because the memory
291+ allocation is waiting for the DMA fence of the 3D workload to complete.
292+
293+ There are a few options to prevent this problem, one of which drivers need to
294+ ensure:
295+
296+ - Compute workloads can always be preempted, even when a page fault is pending
297+ and not yet repaired. Not all hardware supports this.
298+
299+ - DMA fence workloads and workloads which need page fault handling have
300+ independent hardware resources to guarantee forward progress. This could be
301+ achieved through e.g. through dedicated engines and minimal compute unit
302+ reservations for DMA fence workloads.
303+
304+ - The reservation approach could be further refined by only reserving the
305+ hardware resources for DMA fence workloads when they are in-flight. This must
306+ cover the time from when the DMA fence is visible to other threads up to
307+ moment when fence is completed through dma_fence_signal().
308+
309+ - As a last resort, if the hardware provides no useful reservation mechanics,
310+ all workloads must be flushed from the GPU when switching between jobs
311+ requiring DMA fences or jobs requiring page fault handling: This means all DMA
312+ fences must complete before a compute job with page fault handling can be
313+ inserted into the scheduler queue. And vice versa, before a DMA fence can be
314+ made visible anywhere in the system, all compute workloads must be preempted
315+ to guarantee all pending GPU page faults are flushed.
316+
317+ - Only a fairly theoretical option would be to untangle these dependencies when
318+ allocating memory to repair hardware page faults, either through separate
319+ memory blocks or runtime tracking of the full dependency graph of all DMA
320+ fences. This results very wide impact on the kernel, since resolving the page
321+ on the CPU side can itself involve a page fault. It is much more feasible and
322+ robust to limit the impact of handling hardware page faults to the specific
323+ driver.
324+
325+ Note that workloads that run on independent hardware like copy engines or other
326+ GPUs do not have any impact. This allows us to keep using DMA fences internally
327+ in the kernel even for resolving hardware page faults, e.g. by using copy
328+ engines to clear or copy memory needed to resolve the page fault.
329+
330+ In some ways this page fault problem is a special case of the `Infinite DMA
331+ Fences ` discussions: Infinite fences from compute workloads are allowed to
332+ depend on DMA fences, but not the other way around. And not even the page fault
333+ problem is new, because some other CPU thread in userspace might
334+ hit a page fault which holds up a userspace fence - supporting page faults on
335+ GPUs doesn't anything fundamentally new.
0 commit comments