Re: [PATCH drm-misc-next v2 6/7] drm/gpuvm: generalize dma_resv/extobj handling and GEM validation

2023-09-06 Thread kernel test robot
Hi Danilo,

kernel test robot noticed the following build warnings:

[auto build test WARNING on 6bd3d8da51ca1ec97c724016466606aec7739b9f]

url:
https://github.com/intel-lab-lkp/linux/commits/Danilo-Krummrich/drm-gpuva_mgr-allow-building-as-module/20230907-054931
base:   6bd3d8da51ca1ec97c724016466606aec7739b9f
patch link:https://lore.kernel.org/r/20230906214723.4393-7-dakr%40redhat.com
patch subject: [PATCH drm-misc-next v2 6/7] drm/gpuvm: generalize 
dma_resv/extobj handling and GEM validation
config: riscv-defconfig 
(https://download.01.org/0day-ci/archive/20230907/202309070844.arxmnmra-...@intel.com/config)
compiler: riscv64-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): 
(https://download.01.org/0day-ci/archive/20230907/202309070844.arxmnmra-...@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot 
| Closes: 
https://lore.kernel.org/oe-kbuild-all/202309070844.arxmnmra-...@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/gpu/drm/drm_gpuva_mgr.c:998: warning: Function parameter or member 
>> 'exec' not described in 'drm_gpuvm_resv_add_fence'


vim +998 drivers/gpu/drm/drm_gpuva_mgr.c

   983  
   984  /**
   985   * drm_gpuvm_resv_add_fence - add fence to private and all extobj
   986   * dma-resv
   987   * @gpuvm: the _gpuvm to add a fence to
   988   * @fence: fence to add
   989   * @private_usage: private dma-resv usage
   990   * @extobj_usage: extobj dma-resv usage
   991   */
   992  void
   993  drm_gpuvm_resv_add_fence(struct drm_gpuvm *gpuvm,
   994   struct drm_exec *exec,
   995   struct dma_fence *fence,
   996   enum dma_resv_usage private_usage,
   997   enum dma_resv_usage extobj_usage)
 > 998  {
   999  struct drm_gem_object *obj;
  1000  unsigned long index;
  1001  
  1002  drm_exec_for_each_locked_object(exec, index, obj) {
  1003  dma_resv_assert_held(obj->resv);
  1004  dma_resv_add_fence(obj->resv, fence,
  1005 drm_gpuvm_is_extobj(gpuvm, 
obj) ?
  1006 private_usage : 
extobj_usage);
  1007  }
  1008  }
  1009  EXPORT_SYMBOL_GPL(drm_gpuvm_resv_add_fence);
  1010  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki


[PATCH drm-misc-next v2 6/7] drm/gpuvm: generalize dma_resv/extobj handling and GEM validation

2023-09-06 Thread Danilo Krummrich
So far the DRM GPUVA manager offers common infrastructure to track GPU VA
allocations and mappings, generically connect GPU VA mappings to their
backing buffers and perform more complex mapping operations on the GPU VA
space.

However, there are more design patterns commonly used by drivers, which
can potentially be generalized in order to make the DRM GPUVA manager
represent a basic GPU-VM implementation. In this context, this patch aims
at generalizing the following elements.

1) Provide a common dma-resv for GEM objects not being used outside of
   this GPU-VM.

2) Provide tracking of external GEM objects (GEM objects which are
   shared with other GPU-VMs).

3) Provide functions to efficiently lock all GEM objects dma-resv the
   GPU-VM contains mappings of.

4) Provide tracking of evicted GEM objects the GPU-VM contains mappings
   of, such that validation of evicted GEM objects is accelerated.

5) Provide some convinience functions for common patterns.

Rather than being designed as a "framework", the target is to make all
features appear as a collection of optional helper functions, such that
drivers are free to make use of the DRM GPUVA managers basic
functionality and opt-in for other features without setting any feature
flags, just by making use of the corresponding functions.

Suggested-by: Matthew Brost 
Signed-off-by: Danilo Krummrich 
---
 drivers/gpu/drm/drm_gpuva_mgr.c | 335 +++-
 include/drm/drm_gpuva_mgr.h | 235 +-
 2 files changed, 564 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/drm_gpuva_mgr.c b/drivers/gpu/drm/drm_gpuva_mgr.c
index da7a6e1aabe0..db4ef4fadc4b 100644
--- a/drivers/gpu/drm/drm_gpuva_mgr.c
+++ b/drivers/gpu/drm/drm_gpuva_mgr.c
@@ -678,6 +678,10 @@ drm_gpuvm_init(struct drm_gpuvm *gpuvm, struct drm_device 
*drm,
gpuvm->rb.tree = RB_ROOT_CACHED;
INIT_LIST_HEAD(>rb.list);
 
+   INIT_LIST_HEAD(>extobj.list);
+   INIT_LIST_HEAD(>evict.list);
+   spin_lock_init(>evict.lock);
+
drm_gpuva_check_overflow(start_offset, range);
gpuvm->mm_start = start_offset;
gpuvm->mm_range = range;
@@ -719,10 +723,291 @@ drm_gpuvm_destroy(struct drm_gpuvm *gpuvm)
WARN(!RB_EMPTY_ROOT(>rb.tree.rb_root),
 "GPUVA tree is not empty, potentially leaking memory.\n");
 
+   WARN(!list_empty(>extobj.list), "Extobj list should be 
empty.\n");
+   WARN(!list_empty(>evict.list), "Evict list should be empty.\n");
+
drm_gem_private_object_fini(>d_obj);
 }
 EXPORT_SYMBOL_GPL(drm_gpuvm_destroy);
 
+/**
+ * drm_gpuvm_prepare_objects() - prepare all assoiciated BOs
+ * @gpuvm: the _gpuvm
+ * @exec: the _exec locking context
+ * @num_fences: the amount of _fences to reserve
+ *
+ * Calls drm_exec_prepare_obj() for all _gem_objects the given
+ * _gpuvm contains mappings of.
+ *
+ * Using this function directly, it is the drivers responsibility to call
+ * drm_exec_init() and drm_exec_fini() accordingly.
+ *
+ * Returns: 0 on success, negative error code on failure.
+ */
+int
+drm_gpuvm_prepare_objects(struct drm_gpuvm *gpuvm,
+ struct drm_exec *exec,
+ unsigned int num_fences)
+{
+   struct drm_gpuvm_bo *vm_bo;
+   int ret;
+
+   list_for_each_entry(vm_bo, >extobj.list, list.entry.extobj) {
+   struct drm_gem_object *obj = vm_bo->obj;
+
+   ret = drm_exec_prepare_obj(exec, obj, num_fences);
+   if (ret)
+   return ret;
+   }
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(drm_gpuvm_prepare_objects);
+
+/**
+ * drm_gpuvm_prepare_range() - prepare all BOs mapped within a given range
+ * @gpuvm: the _gpuvm
+ * @exec: the _exec locking context
+ * @addr: the start address within the VA space
+ * @range: the range to iterate within the VA space
+ * @num_fences: the amount of _fences to reserve
+ *
+ * Calls drm_exec_prepare_obj() for all _gem_objects mapped between @addr
+ * and @addr + @range.
+ *
+ * Returns: 0 on success, negative error code on failure.
+ */
+int
+drm_gpuvm_prepare_range(struct drm_gpuvm *gpuvm, struct drm_exec *exec,
+   u64 addr, u64 range, unsigned int num_fences)
+{
+   struct drm_gpuva *va;
+   u64 end = addr + range;
+   int ret;
+
+   drm_gpuvm_for_each_va_range(va, gpuvm, addr, end) {
+   struct drm_gem_object *obj = va->gem.obj;
+
+   ret = drm_exec_prepare_obj(exec, obj, num_fences);
+   if (ret)
+   return ret;
+   }
+
+   return 0;
+}
+EXPORT_SYMBOL_GPL(drm_gpuvm_prepare_range);
+
+/**
+ * drm_gpuvm_exec_lock() - lock all dma-resv of all assoiciated BOs
+ * @vm_exec: the _gpuvm_exec abstraction
+ * @num_fences: the amount of _fences to reserve
+ * @interruptible: sleep interruptible if waiting
+ *
+ * Acquires all dma-resv locks of all _gem_objects the given
+ * _gpuvm contains mappings of.
+ *
+ * Addionally, when calling this