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

drm: add drm_gem_object_is_shared_for_memory_stats() helper

Add a helper so that drm drivers can consistently report
shared status via the fdinfo shared memory stats interface.

In addition to handle count, show buffers as shared if they
are shared via dma-buf as well (e.g., shared with v4l or some
other subsystem).

v2: switch to inline function

Link: https://lore.kernel.org/all/20231207180225.439482-1-alexander.deucher@amd.com/
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com> (v1)
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Reviewed-by: Christian König <christian.keonig@amd.com>
Signed-off-by: Christian König <christian.koenig@amd.com>

authored by

Alex Deucher and committed by
Christian König
b31f5eba 77d17c4c

+13
+13
include/drm/drm_gem.h
··· 553 553 554 554 int drm_gem_evict(struct drm_gem_object *obj); 555 555 556 + /** 557 + * drm_gem_object_is_shared_for_memory_stats - helper for shared memory stats 558 + * 559 + * This helper should only be used for fdinfo shared memory stats to determine 560 + * if a GEM object is shared. 561 + * 562 + * @obj: obj in question 563 + */ 564 + static inline bool drm_gem_object_is_shared_for_memory_stats(struct drm_gem_object *obj) 565 + { 566 + return (obj->handle_count > 1) || obj->dma_buf; 567 + } 568 + 556 569 #ifdef CONFIG_LOCKDEP 557 570 /** 558 571 * drm_gem_gpuva_set_lock() - Set the lock protecting accesses to the gpuva list.