Re: [PATCH 5/5] drm/exec, drm/xe, drm/amdgpu: Add an accessor for struct drm_exec::ticket

2026-04-01 Thread Thomas Hellström
Hi,

On Tue, 2026-03-31 at 11:46 +0200, Christian König wrote:
> On 3/31/26 11:20, Thomas Hellström wrote:
> > Drivers were accessing this drm_exec member directly.
> 
> I don't see a problem with that as long as we have documented that
> this is allowed.

It's more of forward-looking for the case I mentioned in the cover-
letter. If drm_exec becomes a subclass of a drm_transaction or
whatever, then this would likely be &exec->txn.ticket;

Could ofc postpone that to any such refactor, but since the patch is up
for review...

Thanks,
Thomas


> 
> Regards,
> Christian.
> 
> > Provide an accessor, drm_exec_ticket() to avoid that.
> > 
> > Signed-off-by: Thomas Hellström 
> > ---
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 4 ++--
> >  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c   | 6 +++---
> >  drivers/gpu/drm/xe/xe_validation.c   | 4 ++--
> >  include/drm/drm_exec.h   | 5 +
> >  4 files changed, 12 insertions(+), 7 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> > index 29b400cdd6d5..8a4fb9a62485 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> > @@ -2998,7 +2998,7 @@ int
> > amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct
> > dma_fence __rcu *
> >     /* Validate PDs, PTs and evicted DMABuf imports last.
> > Otherwise BO
> >  * validations above would invalidate DMABuf imports
> > again.
> >  */
> > -   ret = process_validate_vms(process_info, &exec.ticket);
> > +   ret = process_validate_vms(process_info,
> > drm_exec_ticket(exec));
> >     if (ret) {
> >     pr_debug("Validating VMs failed, ret: %d\n", ret);
> >     goto validate_map_fail;
> > @@ -3039,7 +3039,7 @@ int
> > amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct
> > dma_fence __rcu *
> >     goto validate_map_fail;
> >     }
> >  
> > -   ret = amdgpu_vm_handle_moved(adev, peer_vm,
> > &exec.ticket);
> > +   ret = amdgpu_vm_handle_moved(adev, peer_vm,
> > drm_exec_ticket(exec));
> >     if (ret) {
> >     dev_dbg(adev->dev,
> >     "Memory eviction: handle moved
> > failed, pid %8d. Try again.\n",
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> > index c4ee19603460..c725a7976c63 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> > @@ -1157,7 +1157,7 @@ static int amdgpu_cs_vm_handling(struct
> > amdgpu_cs_parser *p)
> >     return r;
> >     }
> >  
> > -   r = amdgpu_vm_handle_moved(adev, vm, &p->exec.ticket);
> > +   r = amdgpu_vm_handle_moved(adev, vm, drm_exec_ticket(&p-
> > >exec));
> >     if (r)
> >     return r;
> >  
> > @@ -1358,7 +1358,7 @@ static int amdgpu_cs_submit(struct
> > amdgpu_cs_parser *p,
> >     cs->out.handle = seq;
> >     leader->uf_sequence = seq;
> >  
> > -   amdgpu_vm_bo_trace_cs(&fpriv->vm, &p->exec.ticket);
> > +   amdgpu_vm_bo_trace_cs(&fpriv->vm, drm_exec_ticket(&p-
> > >exec));
> >     for (i = 0; i < p->gang_size; ++i) {
> >     amdgpu_job_free_resources(p->jobs[i]);
> >     trace_amdgpu_cs_ioctl(p->jobs[i]);
> > @@ -1793,7 +1793,7 @@ int amdgpu_cs_find_mapping(struct
> > amdgpu_cs_parser *parser,
> >     *map = mapping;
> >  
> >     /* Double check that the BO is reserved by this CS */
> > -   if (dma_resv_locking_ctx((*bo)->tbo.base.resv) != &parser-
> > >exec.ticket)
> > +   if (dma_resv_locking_ctx((*bo)->tbo.base.resv) !=
> > drm_exec_ticket(&parser->exec))
> >     return -EINVAL;
> >  
> >     /* Make sure VRAM is allocated contigiously */
> > diff --git a/drivers/gpu/drm/xe/xe_validation.c
> > b/drivers/gpu/drm/xe/xe_validation.c
> > index a611438eaafe..8dff4d0ec895 100644
> > --- a/drivers/gpu/drm/xe/xe_validation.c
> > +++ b/drivers/gpu/drm/xe/xe_validation.c
> > @@ -156,7 +156,7 @@ int xe_validation_ctx_init(struct
> > xe_validation_ctx *ctx, struct xe_validation_d
> >  
> >  #ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
> >  /*
> > - * This abuses both drm_exec and ww_mutex internals and should be
> > + * This abuses ww_mutex internals and should be
> >   * replaced by checking for -EDEADLK when we can make TTM
> >   * stop converting -EDEADLK to -ENOMEM.
> >   * An alternative is to not have exhaustive eviction with
> > @@ -164,7 +164,7 @@ int xe_validation_ctx_init(struct
> > xe_validation_ctx *ctx, struct xe_validation_d
> >   */
> >  static bool xe_validation_contention_injected(struct drm_exec
> > *exec)
> >  {
> > -   return !!exec->ticket.contending_lock;
> > +   return !!drm_exec_ticket(exec)->contending_lock;
> >  }
> >  
> >  #else
> > diff --git a/include/drm/drm_exec.h b/include/drm/drm_exec.h
> > index 5ed5be1f8244..50d056a87de0 100644
> > --- a/include/drm/drm_exec.h
> > +++ b/include

[PATCH 5/5] drm/exec, drm/xe, drm/amdgpu: Add an accessor for struct drm_exec::ticket

2026-04-01 Thread Thomas Hellström
Drivers were accessing this drm_exec member directly.
Provide an accessor, drm_exec_ticket() to avoid that.

Signed-off-by: Thomas Hellström 
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c   | 6 +++---
 drivers/gpu/drm/xe/xe_validation.c   | 4 ++--
 include/drm/drm_exec.h   | 5 +
 4 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index 29b400cdd6d5..8a4fb9a62485 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -2998,7 +2998,7 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, 
struct dma_fence __rcu *
/* Validate PDs, PTs and evicted DMABuf imports last. Otherwise BO
 * validations above would invalidate DMABuf imports again.
 */
-   ret = process_validate_vms(process_info, &exec.ticket);
+   ret = process_validate_vms(process_info, drm_exec_ticket(exec));
if (ret) {
pr_debug("Validating VMs failed, ret: %d\n", ret);
goto validate_map_fail;
@@ -3039,7 +3039,7 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, 
struct dma_fence __rcu *
goto validate_map_fail;
}
 
-   ret = amdgpu_vm_handle_moved(adev, peer_vm, &exec.ticket);
+   ret = amdgpu_vm_handle_moved(adev, peer_vm, 
drm_exec_ticket(exec));
if (ret) {
dev_dbg(adev->dev,
"Memory eviction: handle moved failed, pid %8d. 
Try again.\n",
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index c4ee19603460..c725a7976c63 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -1157,7 +1157,7 @@ static int amdgpu_cs_vm_handling(struct amdgpu_cs_parser 
*p)
return r;
}
 
-   r = amdgpu_vm_handle_moved(adev, vm, &p->exec.ticket);
+   r = amdgpu_vm_handle_moved(adev, vm, drm_exec_ticket(&p->exec));
if (r)
return r;
 
@@ -1358,7 +1358,7 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
cs->out.handle = seq;
leader->uf_sequence = seq;
 
-   amdgpu_vm_bo_trace_cs(&fpriv->vm, &p->exec.ticket);
+   amdgpu_vm_bo_trace_cs(&fpriv->vm, drm_exec_ticket(&p->exec));
for (i = 0; i < p->gang_size; ++i) {
amdgpu_job_free_resources(p->jobs[i]);
trace_amdgpu_cs_ioctl(p->jobs[i]);
@@ -1793,7 +1793,7 @@ int amdgpu_cs_find_mapping(struct amdgpu_cs_parser 
*parser,
*map = mapping;
 
/* Double check that the BO is reserved by this CS */
-   if (dma_resv_locking_ctx((*bo)->tbo.base.resv) != &parser->exec.ticket)
+   if (dma_resv_locking_ctx((*bo)->tbo.base.resv) != 
drm_exec_ticket(&parser->exec))
return -EINVAL;
 
/* Make sure VRAM is allocated contigiously */
diff --git a/drivers/gpu/drm/xe/xe_validation.c 
b/drivers/gpu/drm/xe/xe_validation.c
index a611438eaafe..8dff4d0ec895 100644
--- a/drivers/gpu/drm/xe/xe_validation.c
+++ b/drivers/gpu/drm/xe/xe_validation.c
@@ -156,7 +156,7 @@ int xe_validation_ctx_init(struct xe_validation_ctx *ctx, 
struct xe_validation_d
 
 #ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
 /*
- * This abuses both drm_exec and ww_mutex internals and should be
+ * This abuses ww_mutex internals and should be
  * replaced by checking for -EDEADLK when we can make TTM
  * stop converting -EDEADLK to -ENOMEM.
  * An alternative is to not have exhaustive eviction with
@@ -164,7 +164,7 @@ int xe_validation_ctx_init(struct xe_validation_ctx *ctx, 
struct xe_validation_d
  */
 static bool xe_validation_contention_injected(struct drm_exec *exec)
 {
-   return !!exec->ticket.contending_lock;
+   return !!drm_exec_ticket(exec)->contending_lock;
 }
 
 #else
diff --git a/include/drm/drm_exec.h b/include/drm/drm_exec.h
index 5ed5be1f8244..50d056a87de0 100644
--- a/include/drm/drm_exec.h
+++ b/include/drm/drm_exec.h
@@ -151,6 +151,11 @@ static inline bool drm_exec_is_contended(struct drm_exec 
*exec)
goto *__drm_exec_retry_ptr; \
} while (0)
 
+static inline struct ww_acquire_ctx *drm_exec_ticket(struct drm_exec *exec)
+{
+   return &exec->ticket;
+}
+
 void drm_exec_init(struct drm_exec *exec, u32 flags, unsigned nr);
 void drm_exec_fini(struct drm_exec *exec);
 bool drm_exec_cleanup(struct drm_exec *exec);
-- 
2.53.0



Re: [PATCH 5/5] drm/exec, drm/xe, drm/amdgpu: Add an accessor for struct drm_exec::ticket

2026-03-31 Thread kernel test robot
Hi Thomas,

kernel test robot noticed the following build errors:

[auto build test ERROR on drm-misc/drm-misc-next]
[also build test ERROR on next-20260330]
[cannot apply to drm-xe/drm-xe-next linus/master v7.0-rc6]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:
https://github.com/intel-lab-lkp/linux/commits/Thomas-Hellstr-m/drm-exec-Remove-the-index-parameter-from-drm_exec_for_each_locked_obj-_reverse/20260331-220349
base:   https://gitlab.freedesktop.org/drm/misc/kernel.git drm-misc-next
patch link:
https://lore.kernel.org/r/20260331092023.81616-6-thomas.hellstrom%40linux.intel.com
patch subject: [PATCH 5/5] drm/exec, drm/xe, drm/amdgpu: Add an accessor for 
struct drm_exec::ticket
config: x86_64-rhel-9.4 
(https://download.01.org/0day-ci/archive/20260401/[email protected]/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): 
(https://download.01.org/0day-ci/archive/20260401/[email protected]/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/[email protected]/

All errors (new ones prefixed by >>):

   drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c: In function 
'amdgpu_amdkfd_gpuvm_restore_process_bos':
>> drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c:3001:66: error: 
>> incompatible type for argument 1 of 'drm_exec_ticket'
3001 | ret = process_validate_vms(process_info, 
drm_exec_ticket(exec));
 |  ^~~~
 |  |
 |  
struct drm_exec
   In file included from drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c:30:
   include/drm/drm_exec.h:154:71: note: expected 'struct drm_exec *' but 
argument is of type 'struct drm_exec'
 154 | static inline struct ww_acquire_ctx *drm_exec_ticket(struct drm_exec 
*exec)
 |  
~^~~~
   drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c:3042:77: error: 
incompatible type for argument 1 of 'drm_exec_ticket'
3042 | ret = amdgpu_vm_handle_moved(adev, peer_vm, 
drm_exec_ticket(exec));
 |  
   ^~~~
 |  
   |
 |  
   struct drm_exec
   include/drm/drm_exec.h:154:71: note: expected 'struct drm_exec *' but 
argument is of type 'struct drm_exec'
 154 | static inline struct ww_acquire_ctx *drm_exec_ticket(struct drm_exec 
*exec)
 |  
~^~~~


vim +/drm_exec_ticket +3001 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c

  2897  
  2898  /** amdgpu_amdkfd_gpuvm_restore_process_bos - Restore all BOs for the 
given
  2899   *   KFD process identified by process_info
  2900   *
  2901   * @process_info: amdkfd_process_info of the KFD process
  2902   *
  2903   * After memory eviction, restore thread calls this function. The 
function
  2904   * should be called when the Process is still valid. BO restore 
involves -
  2905   *
  2906   * 1.  Release old eviction fence and create new one
  2907   * 2.  Get two copies of PD BO list from all the VMs. Keep one copy as 
pd_list.
  2908   * 3   Use the second PD list and kfd_bo_list to create a list 
(ctx.list) of
  2909   * BOs that need to be reserved.
  2910   * 4.  Reserve all the BOs
  2911   * 5.  Validate of PD and PT BOs.
  2912   * 6.  Validate all KFD BOs using kfd_bo_list and Map them and add new 
fence
  2913   * 7.  Add fence to all PD and PT BOs.
  2914   * 8.  Unreserve all BOs
  2915   */
  2916  int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct 
dma_fence __rcu **ef)
  2917  {
  2918  struct amdkfd_process_info *process_info = info;
  2919  struct amdgpu_vm *peer_vm;
  2920  struct kgd_mem *mem;
  2921  struct list_head duplicate_save;
  2922  struct amdgpu_sync sync_obj;
  2923  unsigned long failed_size = 0;
  2924  unsigned long total_size = 0;
  2925  struct drm_exec exec;
  2926  int ret;
  2927  
  2928  INIT_LIST_HEAD(&duplicate_save);
  2929  
  2930  mutex_lock(&process_info->lock);
  2931  
  2932  d

Re: [PATCH 5/5] drm/exec, drm/xe, drm/amdgpu: Add an accessor for struct drm_exec::ticket

2026-03-31 Thread kernel test robot
Hi Thomas,

kernel test robot noticed the following build errors:

[auto build test ERROR on drm-misc/drm-misc-next]
[also build test ERROR on next-20260330]
[cannot apply to drm-xe/drm-xe-next linus/master v7.0-rc6]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:
https://github.com/intel-lab-lkp/linux/commits/Thomas-Hellstr-m/drm-exec-Remove-the-index-parameter-from-drm_exec_for_each_locked_obj-_reverse/20260331-220349
base:   https://gitlab.freedesktop.org/drm/misc/kernel.git drm-misc-next
patch link:
https://lore.kernel.org/r/20260331092023.81616-6-thomas.hellstrom%40linux.intel.com
patch subject: [PATCH 5/5] drm/exec, drm/xe, drm/amdgpu: Add an accessor for 
struct drm_exec::ticket
config: riscv-randconfig-r073-20260401 
(https://download.01.org/0day-ci/archive/20260401/[email protected]/config)
compiler: clang version 23.0.0git (https://github.com/llvm/llvm-project 
2cd67b8b69f78e3f95918204320c3075a74ba16c)
smatch: v0.5.0-9004-gb810ac53
reproduce (this is a W=1 build): 
(https://download.01.org/0day-ci/archive/20260401/[email protected]/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/[email protected]/

All errors (new ones prefixed by >>):

>> drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c:3001:59: error: passing 
>> 'struct drm_exec' to parameter of incompatible type 'struct drm_exec *'; 
>> take the address with &
3001 | ret = process_validate_vms(process_info, 
drm_exec_ticket(exec));
 |  ^~~~
 |  &
   include/drm/drm_exec.h:154:71: note: passing argument to parameter 'exec' 
here
 154 | static inline struct ww_acquire_ctx *drm_exec_ticket(struct drm_exec 
*exec)
 |  
 ^
   drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c:3042:63: error: passing 
'struct drm_exec' to parameter of incompatible type 'struct drm_exec *'; take 
the address with &
3042 | ret = amdgpu_vm_handle_moved(adev, peer_vm, 
drm_exec_ticket(exec));
 |  
   ^~~~
 |  
   &
   include/drm/drm_exec.h:154:71: note: passing argument to parameter 'exec' 
here
 154 | static inline struct ww_acquire_ctx *drm_exec_ticket(struct drm_exec 
*exec)
 |  
 ^
   2 errors generated.


vim +3001 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c

  2897  
  2898  /** amdgpu_amdkfd_gpuvm_restore_process_bos - Restore all BOs for the 
given
  2899   *   KFD process identified by process_info
  2900   *
  2901   * @process_info: amdkfd_process_info of the KFD process
  2902   *
  2903   * After memory eviction, restore thread calls this function. The 
function
  2904   * should be called when the Process is still valid. BO restore 
involves -
  2905   *
  2906   * 1.  Release old eviction fence and create new one
  2907   * 2.  Get two copies of PD BO list from all the VMs. Keep one copy as 
pd_list.
  2908   * 3   Use the second PD list and kfd_bo_list to create a list 
(ctx.list) of
  2909   * BOs that need to be reserved.
  2910   * 4.  Reserve all the BOs
  2911   * 5.  Validate of PD and PT BOs.
  2912   * 6.  Validate all KFD BOs using kfd_bo_list and Map them and add new 
fence
  2913   * 7.  Add fence to all PD and PT BOs.
  2914   * 8.  Unreserve all BOs
  2915   */
  2916  int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct 
dma_fence __rcu **ef)
  2917  {
  2918  struct amdkfd_process_info *process_info = info;
  2919  struct amdgpu_vm *peer_vm;
  2920  struct kgd_mem *mem;
  2921  struct list_head duplicate_save;
  2922  struct amdgpu_sync sync_obj;
  2923  unsigned long failed_size = 0;
  2924  unsigned long total_size = 0;
  2925  struct drm_exec exec;
  2926  int ret;
  2927  
  2928  INIT_LIST_HEAD(&duplicate_save);
  2929  
  2930  mutex_lock(&process_info->lock);
  2931  
  2932  drm_exec_init(&exec, DRM_EXEC_IGNORE_DUPLICATES, 0);
  2933  drm_exec_until_all_locked(&exec) {
  2934  list_for_each_entry(peer_vm, 
&process_info->vm_list_head,
  2935

Re: [PATCH 5/5] drm/exec, drm/xe, drm/amdgpu: Add an accessor for struct drm_exec::ticket

2026-03-31 Thread kernel test robot
Hi Thomas,

kernel test robot noticed the following build errors:

[auto build test ERROR on drm-misc/drm-misc-next]
[also build test ERROR on next-20260331]
[cannot apply to drm-xe/drm-xe-next linus/master v6.16-rc1]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:
https://github.com/intel-lab-lkp/linux/commits/Thomas-Hellstr-m/drm-exec-Remove-the-index-parameter-from-drm_exec_for_each_locked_obj-_reverse/20260331-220349
base:   https://gitlab.freedesktop.org/drm/misc/kernel.git drm-misc-next
patch link:
https://lore.kernel.org/r/20260331092023.81616-6-thomas.hellstrom%40linux.intel.com
patch subject: [PATCH 5/5] drm/exec, drm/xe, drm/amdgpu: Add an accessor for 
struct drm_exec::ticket
config: x86_64-rhel-9.4 
(https://download.01.org/0day-ci/archive/20260331/[email protected]/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): 
(https://download.01.org/0day-ci/archive/20260331/[email protected]/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/[email protected]/

All errors (new ones prefixed by >>):

   drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c: In function 
'amdgpu_amdkfd_gpuvm_restore_process_bos':
>> drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c:3001:66: error: 
>> incompatible type for argument 1 of 'drm_exec_ticket'
3001 | ret = process_validate_vms(process_info, 
drm_exec_ticket(exec));
 |  ^~~~
 |  |
 |  
struct drm_exec
   In file included from drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c:30:
   include/drm/drm_exec.h:154:71: note: expected 'struct drm_exec *' but 
argument is of type 'struct drm_exec'
 154 | static inline struct ww_acquire_ctx *drm_exec_ticket(struct drm_exec 
*exec)
 |  
~^~~~
   drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c:3042:77: error: 
incompatible type for argument 1 of 'drm_exec_ticket'
3042 | ret = amdgpu_vm_handle_moved(adev, peer_vm, 
drm_exec_ticket(exec));
 |  
   ^~~~
 |  
   |
 |  
   struct drm_exec
   include/drm/drm_exec.h:154:71: note: expected 'struct drm_exec *' but 
argument is of type 'struct drm_exec'
 154 | static inline struct ww_acquire_ctx *drm_exec_ticket(struct drm_exec 
*exec)
 |  
~^~~~


vim +/drm_exec_ticket +3001 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c

  2897  
  2898  /** amdgpu_amdkfd_gpuvm_restore_process_bos - Restore all BOs for the 
given
  2899   *   KFD process identified by process_info
  2900   *
  2901   * @process_info: amdkfd_process_info of the KFD process
  2902   *
  2903   * After memory eviction, restore thread calls this function. The 
function
  2904   * should be called when the Process is still valid. BO restore 
involves -
  2905   *
  2906   * 1.  Release old eviction fence and create new one
  2907   * 2.  Get two copies of PD BO list from all the VMs. Keep one copy as 
pd_list.
  2908   * 3   Use the second PD list and kfd_bo_list to create a list 
(ctx.list) of
  2909   * BOs that need to be reserved.
  2910   * 4.  Reserve all the BOs
  2911   * 5.  Validate of PD and PT BOs.
  2912   * 6.  Validate all KFD BOs using kfd_bo_list and Map them and add new 
fence
  2913   * 7.  Add fence to all PD and PT BOs.
  2914   * 8.  Unreserve all BOs
  2915   */
  2916  int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, struct 
dma_fence __rcu **ef)
  2917  {
  2918  struct amdkfd_process_info *process_info = info;
  2919  struct amdgpu_vm *peer_vm;
  2920  struct kgd_mem *mem;
  2921  struct list_head duplicate_save;
  2922  struct amdgpu_sync sync_obj;
  2923  unsigned long failed_size = 0;
  2924  unsigned long total_size = 0;
  2925  struct drm_exec exec;
  2926  int ret;
  2927  
  2928  INIT_LIST_HEAD(&duplicate_save);
  2929  
  2930  mutex_lock(&process_info->lock);
  2931  
  2932  d

Re: [PATCH 5/5] drm/exec, drm/xe, drm/amdgpu: Add an accessor for struct drm_exec::ticket

2026-03-31 Thread Christian König
On 3/31/26 11:20, Thomas Hellström wrote:
> Drivers were accessing this drm_exec member directly.

I don't see a problem with that as long as we have documented that this is 
allowed.

Regards,
Christian.

> Provide an accessor, drm_exec_ticket() to avoid that.
> 
> Signed-off-by: Thomas Hellström 
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 4 ++--
>  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c   | 6 +++---
>  drivers/gpu/drm/xe/xe_validation.c   | 4 ++--
>  include/drm/drm_exec.h   | 5 +
>  4 files changed, 12 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> index 29b400cdd6d5..8a4fb9a62485 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
> @@ -2998,7 +2998,7 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, 
> struct dma_fence __rcu *
>   /* Validate PDs, PTs and evicted DMABuf imports last. Otherwise BO
>* validations above would invalidate DMABuf imports again.
>*/
> - ret = process_validate_vms(process_info, &exec.ticket);
> + ret = process_validate_vms(process_info, drm_exec_ticket(exec));
>   if (ret) {
>   pr_debug("Validating VMs failed, ret: %d\n", ret);
>   goto validate_map_fail;
> @@ -3039,7 +3039,7 @@ int amdgpu_amdkfd_gpuvm_restore_process_bos(void *info, 
> struct dma_fence __rcu *
>   goto validate_map_fail;
>   }
>  
> - ret = amdgpu_vm_handle_moved(adev, peer_vm, &exec.ticket);
> + ret = amdgpu_vm_handle_moved(adev, peer_vm, 
> drm_exec_ticket(exec));
>   if (ret) {
>   dev_dbg(adev->dev,
>   "Memory eviction: handle moved failed, pid %8d. 
> Try again.\n",
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c 
> b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> index c4ee19603460..c725a7976c63 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
> @@ -1157,7 +1157,7 @@ static int amdgpu_cs_vm_handling(struct 
> amdgpu_cs_parser *p)
>   return r;
>   }
>  
> - r = amdgpu_vm_handle_moved(adev, vm, &p->exec.ticket);
> + r = amdgpu_vm_handle_moved(adev, vm, drm_exec_ticket(&p->exec));
>   if (r)
>   return r;
>  
> @@ -1358,7 +1358,7 @@ static int amdgpu_cs_submit(struct amdgpu_cs_parser *p,
>   cs->out.handle = seq;
>   leader->uf_sequence = seq;
>  
> - amdgpu_vm_bo_trace_cs(&fpriv->vm, &p->exec.ticket);
> + amdgpu_vm_bo_trace_cs(&fpriv->vm, drm_exec_ticket(&p->exec));
>   for (i = 0; i < p->gang_size; ++i) {
>   amdgpu_job_free_resources(p->jobs[i]);
>   trace_amdgpu_cs_ioctl(p->jobs[i]);
> @@ -1793,7 +1793,7 @@ int amdgpu_cs_find_mapping(struct amdgpu_cs_parser 
> *parser,
>   *map = mapping;
>  
>   /* Double check that the BO is reserved by this CS */
> - if (dma_resv_locking_ctx((*bo)->tbo.base.resv) != &parser->exec.ticket)
> + if (dma_resv_locking_ctx((*bo)->tbo.base.resv) != 
> drm_exec_ticket(&parser->exec))
>   return -EINVAL;
>  
>   /* Make sure VRAM is allocated contigiously */
> diff --git a/drivers/gpu/drm/xe/xe_validation.c 
> b/drivers/gpu/drm/xe/xe_validation.c
> index a611438eaafe..8dff4d0ec895 100644
> --- a/drivers/gpu/drm/xe/xe_validation.c
> +++ b/drivers/gpu/drm/xe/xe_validation.c
> @@ -156,7 +156,7 @@ int xe_validation_ctx_init(struct xe_validation_ctx *ctx, 
> struct xe_validation_d
>  
>  #ifdef CONFIG_DEBUG_WW_MUTEX_SLOWPATH
>  /*
> - * This abuses both drm_exec and ww_mutex internals and should be
> + * This abuses ww_mutex internals and should be
>   * replaced by checking for -EDEADLK when we can make TTM
>   * stop converting -EDEADLK to -ENOMEM.
>   * An alternative is to not have exhaustive eviction with
> @@ -164,7 +164,7 @@ int xe_validation_ctx_init(struct xe_validation_ctx *ctx, 
> struct xe_validation_d
>   */
>  static bool xe_validation_contention_injected(struct drm_exec *exec)
>  {
> - return !!exec->ticket.contending_lock;
> + return !!drm_exec_ticket(exec)->contending_lock;
>  }
>  
>  #else
> diff --git a/include/drm/drm_exec.h b/include/drm/drm_exec.h
> index 5ed5be1f8244..50d056a87de0 100644
> --- a/include/drm/drm_exec.h
> +++ b/include/drm/drm_exec.h
> @@ -151,6 +151,11 @@ static inline bool drm_exec_is_contended(struct drm_exec 
> *exec)
>   goto *__drm_exec_retry_ptr; \
>   } while (0)
>  
> +static inline struct ww_acquire_ctx *drm_exec_ticket(struct drm_exec *exec)
> +{
> + return &exec->ticket;
> +}
> +
>  void drm_exec_init(struct drm_exec *exec, u32 flags, unsigned nr);
>  void drm_exec_fini(struct drm_exec *exec);
>  bool drm_exec_cleanup(struct drm_exec *exec);