Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/i915: Document locking guidelines

To ensure cross-driver locking compatibility, document the expected
guidelines for implementing the GEM locking in i915. Note that this
is a description of how things should end up after being reworked,
and does not reflect the current state of things.

v2: Use rst note:: tag (Rodrigo)

Signed-off-by: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Abdiel Janulgue <abdiel.janulgue@linux.intel.com>
Cc: CQ Tang <cq.tang@intel.com>
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Acked-by: Dave Airlie <airlied@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190830105053.17491-1-joonas.lahtinen@linux.intel.com

+46
+46
Documentation/gpu/i915.rst
··· 329 329 refer to GPU-addresses so that the kernel can edit the buffer correctly. 330 330 This process is dubbed relocation. 331 331 332 + Locking Guidelines 333 + ------------------ 334 + 335 + .. note:: 336 + This is a description of how the locking should be after 337 + refactoring is done. Does not necessarily reflect what the locking 338 + looks like while WIP. 339 + 340 + #. All locking rules and interface contracts with cross-driver interfaces 341 + (dma-buf, dma_fence) need to be followed. 342 + 343 + #. No struct_mutex anywhere in the code 344 + 345 + #. dma_resv will be the outermost lock (when needed) and ww_acquire_ctx 346 + is to be hoisted at highest level and passed down within i915_gem_ctx 347 + in the call chain 348 + 349 + #. While holding lru/memory manager (buddy, drm_mm, whatever) locks 350 + system memory allocations are not allowed 351 + 352 + * Enforce this by priming lockdep (with fs_reclaim). If we 353 + allocate memory while holding these looks we get a rehash 354 + of the shrinker vs. struct_mutex saga, and that would be 355 + real bad. 356 + 357 + #. Do not nest different lru/memory manager locks within each other. 358 + Take them in turn to update memory allocations, relying on the object’s 359 + dma_resv ww_mutex to serialize against other operations. 360 + 361 + #. The suggestion for lru/memory managers locks is that they are small 362 + enough to be spinlocks. 363 + 364 + #. All features need to come with exhaustive kernel selftests and/or 365 + IGT tests when appropriate 366 + 367 + #. All LMEM uAPI paths need to be fully restartable (_interruptible() 368 + for all locks/waits/sleeps) 369 + 370 + * Error handling validation through signal injection. 371 + Still the best strategy we have for validating GEM uAPI 372 + corner cases. 373 + Must be excessively used in the IGT, and we need to check 374 + that we really have full path coverage of all error cases. 375 + 376 + * -EDEADLK handling with ww_mutex 377 + 332 378 GEM BO Management Implementation Details 333 379 ---------------------------------------- 334 380