On Thu, Jun 18, 2026 at 04:09:02PM +0800, Honglei Huang wrote:
> From: Honglei Huang <[email protected]>
> 
> The core mechanism of drm_gpusvm is HMM, which is fundamentally an
> MM side subsystem. A drm_device, enters the picture on the device side at
> DMA mapping / GPU bind.
> 
> So move struct drm_device from struct drm_gpusvm in drm_gpusvm. Let
> drm_gpusvm keep its core neutral and leave device side decisions to
> the driver. Make drm_gpusvm a pure MM level object.
> 
>   - Move the drm_device from struct drm_gpusvm. drm_device now stored in
>     drm_gpusvm_pages.
>   - Drop the drm parameter from drm_gpusvm_init()
>   - Update the xe call sites in xe_svm_init() and other callers.
> 
> drm_device does not disappear from the framework, it is
> relocated onto each drm_gpusvm_pages where DMA actually happens.
> 
> Suggested-by: Matthew Brost <[email protected]>

Reviewed-by: Matthew Brost <[email protected]>

> Signed-off-by: Honglei Huang <[email protected]>
> ---
>  drivers/gpu/drm/drm_gpusvm.c | 8 ++++----
>  drivers/gpu/drm/xe/xe_svm.c  | 4 ++--
>  drivers/gpu/drm/xe/xe_svm.h  | 2 +-
>  include/drm/drm_gpusvm.h     | 4 +---
>  4 files changed, 8 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_gpusvm.c b/drivers/gpu/drm/drm_gpusvm.c
> index 842bfb37a36..9d5badb038a 100644
> --- a/drivers/gpu/drm/drm_gpusvm.c
> +++ b/drivers/gpu/drm/drm_gpusvm.c
> @@ -433,7 +433,6 @@ static const struct mmu_interval_notifier_ops 
> drm_gpusvm_notifier_ops = {
>   * drm_gpusvm_init() - Initialize the GPU SVM.
>   * @gpusvm: Pointer to the GPU SVM structure.
>   * @name: Name of the GPU SVM.
> - * @drm: Pointer to the DRM device structure.
>   * @mm: Pointer to the mm_struct for the address space.
>   * @mm_start: Start address of GPU SVM.
>   * @mm_range: Range of the GPU SVM.
> @@ -447,7 +446,9 @@ static const struct mmu_interval_notifier_ops 
> drm_gpusvm_notifier_ops = {
>   * This function initializes the GPU SVM.
>   *
>   * Note: If only using the simple drm_gpusvm_pages API (get/unmap/free),
> - * then only @gpusvm, @name, and @drm are expected. However, the same base
> + * then only @gpusvm and @name are expected. The @drm drm_device for dma
> + * mappings is bound per-pages via drm_gpusvm_init_pages() before the first
> + * drm_gpusvm_get_pages() call. However, the same base
>   * @gpusvm can also be used with both modes together in which case the full
>   * setup is needed, where the core drm_gpusvm_pages API will simply never use
>   * the other fields.
> @@ -455,7 +456,7 @@ static const struct mmu_interval_notifier_ops 
> drm_gpusvm_notifier_ops = {
>   * Return: 0 on success, a negative error code on failure.
>   */
>  int drm_gpusvm_init(struct drm_gpusvm *gpusvm,
> -                 const char *name, struct drm_device *drm,
> +                 const char *name,
>                   struct mm_struct *mm,
>                   unsigned long mm_start, unsigned long mm_range,
>                   unsigned long notifier_size,
> @@ -473,7 +474,6 @@ int drm_gpusvm_init(struct drm_gpusvm *gpusvm,
>       }
>  
>       gpusvm->name = name;
> -     gpusvm->drm = drm;
>       gpusvm->mm = mm;
>       gpusvm->mm_start = mm_start;
>       gpusvm->mm_range = mm_range;
> diff --git a/drivers/gpu/drm/xe/xe_svm.c b/drivers/gpu/drm/xe/xe_svm.c
> index 77af0a8de63..7c4e40809e6 100644
> --- a/drivers/gpu/drm/xe/xe_svm.c
> +++ b/drivers/gpu/drm/xe/xe_svm.c
> @@ -906,7 +906,7 @@ int xe_svm_init(struct xe_vm *vm)
>                       return err;
>               }
>  
> -             err = drm_gpusvm_init(&vm->svm.gpusvm, "Xe SVM", &vm->xe->drm,
> +             err = drm_gpusvm_init(&vm->svm.gpusvm, "Xe SVM",
>                                     current->mm, 0, vm->size,
>                                     xe_modparam.svm_notifier_size * SZ_1M,
>                                     &gpusvm_ops, fault_chunk_sizes,
> @@ -920,7 +920,7 @@ int xe_svm_init(struct xe_vm *vm)
>               }
>       } else {
>               err = drm_gpusvm_init(&vm->svm.gpusvm, "Xe SVM (simple)",
> -                                   &vm->xe->drm, NULL, 0, 0, 0, NULL,
> +                                   NULL, 0, 0, 0, NULL,
>                                     NULL, 0);
>       }
>  
> diff --git a/drivers/gpu/drm/xe/xe_svm.h b/drivers/gpu/drm/xe/xe_svm.h
> index 1423ab2f1d6..63ea991e2cb 100644
> --- a/drivers/gpu/drm/xe/xe_svm.h
> +++ b/drivers/gpu/drm/xe/xe_svm.h
> @@ -235,7 +235,7 @@ static inline
>  int xe_svm_init(struct xe_vm *vm)
>  {
>  #if IS_ENABLED(CONFIG_DRM_GPUSVM)
> -     return drm_gpusvm_init(&vm->svm.gpusvm, "Xe SVM (simple)", &vm->xe->drm,
> +     return drm_gpusvm_init(&vm->svm.gpusvm, "Xe SVM (simple)",
>                              NULL, 0, 0, 0, NULL, NULL, 0);
>  #else
>       return 0;
> diff --git a/include/drm/drm_gpusvm.h b/include/drm/drm_gpusvm.h
> index 5edfa7d0c36..f40b52e3ae7 100644
> --- a/include/drm/drm_gpusvm.h
> +++ b/include/drm/drm_gpusvm.h
> @@ -195,7 +195,6 @@ struct drm_gpusvm_range {
>   * struct drm_gpusvm - GPU SVM structure
>   *
>   * @name: Name of the GPU SVM
> - * @drm: Pointer to the DRM device structure
>   * @mm: Pointer to the mm_struct for the address space
>   * @mm_start: Start address of GPU SVM
>   * @mm_range: Range of the GPU SVM
> @@ -219,7 +218,6 @@ struct drm_gpusvm_range {
>   */
>  struct drm_gpusvm {
>       const char *name;
> -     struct drm_device *drm;
>       struct mm_struct *mm;
>       unsigned long mm_start;
>       unsigned long mm_range;
> @@ -271,7 +269,7 @@ struct drm_gpusvm_ctx {
>  };
>  
>  int drm_gpusvm_init(struct drm_gpusvm *gpusvm,
> -                 const char *name, struct drm_device *drm,
> +                 const char *name,
>                   struct mm_struct *mm,
>                   unsigned long mm_start, unsigned long mm_range,
>                   unsigned long notifier_size,
> -- 
> 2.34.1
> 

Reply via email to