Linux kernel -stable discussions
 help / color / mirror / Atom feed
* [PATCH] drm/ttm: Destroy the ttm_tt in ttm_bo_move_null() when it's no longer needed
@ 2026-11-24 19:09 Thomas Hellström
  2026-11-24 19:53 ` Matthew Brost
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Thomas Hellström @ 2026-11-24 19:09 UTC (permalink / raw)
  To: intel-xe
  Cc: Thomas Hellström, Natalie Vock, Arun Pravin, Matthew Auld,
	Matthew Brost, dri-devel, stable

The xe kmd uses ttm_bo_move_null() when moving an unpopulated bo to
VRAM. In that case the bo may still carry a ttm_tt that was created
for its deferred placement, and it is left dangling on a bo whose new
resource doesn't use a ttm_tt.

Make ttm_bo_move_null() destroy the bo's ttm_tt when @new_mem is NULL
or its memory type manager doesn't use a ttm_tt.

ttm_bo_tt_destroy() is internal to TTM and not exported. Rather than
exporting it, move ttm_bo_move_null() out to ttm_bo_util.c and
export that instead.

Patch and commit message was drafted using an LLM.

Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel GPUs")
Cc: Natalie Vock <nat@pixelcluster.dev>
Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Matthew Brost <matthew.brost@intel.com>
Cc: dri-devel@lists.freedesktop.org
Cc: <stable@vger.kernel.org> # v6.8+
Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
---
 drivers/gpu/drm/ttm/ttm_bo_util.c | 20 ++++++++++++++++++++
 include/drm/ttm/ttm_bo.h          | 15 ++-------------
 2 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index f9458a4d5a09..7f3459db596a 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -202,6 +202,26 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
 }
 EXPORT_SYMBOL(ttm_bo_move_memcpy);
 
+/**
+ * ttm_bo_move_null() - assign memory for a buffer object.
+ * @bo: The bo to assign the memory to.
+ * @new_mem: The memory to be assigned, or NULL.
+ *
+ * Free the current resource of @bo and assign @new_mem to it. If @new_mem is
+ * NULL or its memory type manager doesn't use a &struct ttm_tt, the bo's
+ * &struct ttm_tt, if any, is unpopulated and destroyed.
+ */
+void ttm_bo_move_null(struct ttm_buffer_object *bo,
+		      struct ttm_resource *new_mem)
+{
+	if (!new_mem || !ttm_manager_type(bo->bdev, new_mem->mem_type)->use_tt)
+		ttm_bo_tt_destroy(bo);
+
+	ttm_resource_free(bo, &bo->resource);
+	ttm_bo_assign_mem(bo, new_mem);
+}
+EXPORT_SYMBOL(ttm_bo_move_null);
+
 static void ttm_transfered_destroy(struct ttm_buffer_object *bo)
 {
 	struct ttm_transfer_obj *fbo;
diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h
index 32791c4db2a9..d525e04893ed 100644
--- a/include/drm/ttm/ttm_bo.h
+++ b/include/drm/ttm/ttm_bo.h
@@ -356,19 +356,8 @@ static inline void ttm_bo_assign_mem(struct ttm_buffer_object *bo,
 	bo->resource = new_mem;
 }
 
-/**
- * ttm_bo_move_null - assign memory for a buffer object.
- * @bo: The bo to assign the memory to
- * @new_mem: The memory to be assigned.
- *
- * Assign the memory from new_mem to the memory of the buffer object bo.
- */
-static inline void ttm_bo_move_null(struct ttm_buffer_object *bo,
-				    struct ttm_resource *new_mem)
-{
-	ttm_resource_free(bo, &bo->resource);
-	ttm_bo_assign_mem(bo, new_mem);
-}
+void ttm_bo_move_null(struct ttm_buffer_object *bo,
+		      struct ttm_resource *new_mem);
 
 /**
  * ttm_bo_unreserve
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] drm/ttm: Destroy the ttm_tt in ttm_bo_move_null() when it's no longer needed
  2026-11-24 19:09 [PATCH] drm/ttm: Destroy the ttm_tt in ttm_bo_move_null() when it's no longer needed Thomas Hellström
@ 2026-11-24 19:53 ` Matthew Brost
  2026-11-25  9:30   ` Thomas Hellström
  2026-11-25  9:55 ` Matthew Auld
  2026-12-04 14:54 ` Natalie Vock
  2 siblings, 1 reply; 5+ messages in thread
From: Matthew Brost @ 2026-11-24 19:53 UTC (permalink / raw)
  To: Thomas Hellström
  Cc: intel-xe, Natalie Vock, Arun Pravin, Matthew Auld, dri-devel,
	stable

On Tue, Nov 24, 2026 at 08:09:54PM +0100, Thomas Hellström wrote:
> The xe kmd uses ttm_bo_move_null() when moving an unpopulated bo to
> VRAM. In that case the bo may still carry a ttm_tt that was created

I'm wondering if other drivers which use TTM + support VRAM (amdgpu,
Nouveau) have a similar problem or this really just an issue in Xe.

Either way I think this is safe and correct for any driver.

> for its deferred placement, and it is left dangling on a bo whose new
> resource doesn't use a ttm_tt.
> 
> Make ttm_bo_move_null() destroy the bo's ttm_tt when @new_mem is NULL
> or its memory type manager doesn't use a ttm_tt.
> 
> ttm_bo_tt_destroy() is internal to TTM and not exported. Rather than
> exporting it, move ttm_bo_move_null() out to ttm_bo_util.c and
> export that instead.
> 
> Patch and commit message was drafted using an LLM.
> 
> Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel GPUs")
> Cc: Natalie Vock <nat@pixelcluster.dev>
> Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
> Cc: Matthew Auld <matthew.auld@intel.com>
> Cc: Matthew Brost <matthew.brost@intel.com>

Reviewed-by: Matthew Brost <matthew.brost@intel.com>

> Cc: dri-devel@lists.freedesktop.org
> Cc: <stable@vger.kernel.org> # v6.8+
> Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> ---
>  drivers/gpu/drm/ttm/ttm_bo_util.c | 20 ++++++++++++++++++++
>  include/drm/ttm/ttm_bo.h          | 15 ++-------------
>  2 files changed, 22 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
> index f9458a4d5a09..7f3459db596a 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_util.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
> @@ -202,6 +202,26 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
>  }
>  EXPORT_SYMBOL(ttm_bo_move_memcpy);
>  
> +/**
> + * ttm_bo_move_null() - assign memory for a buffer object.
> + * @bo: The bo to assign the memory to.
> + * @new_mem: The memory to be assigned, or NULL.
> + *
> + * Free the current resource of @bo and assign @new_mem to it. If @new_mem is
> + * NULL or its memory type manager doesn't use a &struct ttm_tt, the bo's
> + * &struct ttm_tt, if any, is unpopulated and destroyed.
> + */
> +void ttm_bo_move_null(struct ttm_buffer_object *bo,
> +		      struct ttm_resource *new_mem)
> +{
> +	if (!new_mem || !ttm_manager_type(bo->bdev, new_mem->mem_type)->use_tt)
> +		ttm_bo_tt_destroy(bo);
> +
> +	ttm_resource_free(bo, &bo->resource);
> +	ttm_bo_assign_mem(bo, new_mem);
> +}
> +EXPORT_SYMBOL(ttm_bo_move_null);
> +
>  static void ttm_transfered_destroy(struct ttm_buffer_object *bo)
>  {
>  	struct ttm_transfer_obj *fbo;
> diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h
> index 32791c4db2a9..d525e04893ed 100644
> --- a/include/drm/ttm/ttm_bo.h
> +++ b/include/drm/ttm/ttm_bo.h
> @@ -356,19 +356,8 @@ static inline void ttm_bo_assign_mem(struct ttm_buffer_object *bo,
>  	bo->resource = new_mem;
>  }
>  
> -/**
> - * ttm_bo_move_null - assign memory for a buffer object.
> - * @bo: The bo to assign the memory to
> - * @new_mem: The memory to be assigned.
> - *
> - * Assign the memory from new_mem to the memory of the buffer object bo.
> - */
> -static inline void ttm_bo_move_null(struct ttm_buffer_object *bo,
> -				    struct ttm_resource *new_mem)
> -{
> -	ttm_resource_free(bo, &bo->resource);
> -	ttm_bo_assign_mem(bo, new_mem);
> -}
> +void ttm_bo_move_null(struct ttm_buffer_object *bo,
> +		      struct ttm_resource *new_mem);
>  
>  /**
>   * ttm_bo_unreserve
> -- 
> 2.56.1
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] drm/ttm: Destroy the ttm_tt in ttm_bo_move_null() when it's no longer needed
  2026-11-24 19:53 ` Matthew Brost
@ 2026-11-25  9:30   ` Thomas Hellström
  0 siblings, 0 replies; 5+ messages in thread
From: Thomas Hellström @ 2026-11-25  9:30 UTC (permalink / raw)
  To: Matthew Brost
  Cc: intel-xe, Natalie Vock, Arun Pravin, Matthew Auld, dri-devel,
	stable

On Tue, 2026-11-24 at 11:53 -0800, Matthew Brost wrote:
> On Tue, Nov 24, 2026 at 08:09:54PM +0100, Thomas Hellström wrote:
> > The xe kmd uses ttm_bo_move_null() when moving an unpopulated bo to
> > VRAM. In that case the bo may still carry a ttm_tt that was created
> 
> I'm wondering if other drivers which use TTM + support VRAM (amdgpu,
> Nouveau) have a similar problem or this really just an issue in Xe.

IIRC there's no other driver that takes this path to deferred memory.
From my understanding, AMD takes the route over TT, actually populating
the ttm_tt first.

/Thomas


> 
> Either way I think this is safe and correct for any driver.
> 
> > for its deferred placement, and it is left dangling on a bo whose
> > new
> > resource doesn't use a ttm_tt.
> > 
> > Make ttm_bo_move_null() destroy the bo's ttm_tt when @new_mem is
> > NULL
> > or its memory type manager doesn't use a ttm_tt.
> > 
> > ttm_bo_tt_destroy() is internal to TTM and not exported. Rather
> > than
> > exporting it, move ttm_bo_move_null() out to ttm_bo_util.c and
> > export that instead.
> > 
> > Patch and commit message was drafted using an LLM.
> > 
> > Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel
> > GPUs")
> > Cc: Natalie Vock <nat@pixelcluster.dev>
> > Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
> > Cc: Matthew Auld <matthew.auld@intel.com>
> > Cc: Matthew Brost <matthew.brost@intel.com>
> 
> Reviewed-by: Matthew Brost <matthew.brost@intel.com>
> 
> > Cc: dri-devel@lists.freedesktop.org
> > Cc: <stable@vger.kernel.org> # v6.8+
> > Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>
> > ---
> >  drivers/gpu/drm/ttm/ttm_bo_util.c | 20 ++++++++++++++++++++
> >  include/drm/ttm/ttm_bo.h          | 15 ++-------------
> >  2 files changed, 22 insertions(+), 13 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c
> > b/drivers/gpu/drm/ttm/ttm_bo_util.c
> > index f9458a4d5a09..7f3459db596a 100644
> > --- a/drivers/gpu/drm/ttm/ttm_bo_util.c
> > +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
> > @@ -202,6 +202,26 @@ int ttm_bo_move_memcpy(struct
> > ttm_buffer_object *bo,
> >  }
> >  EXPORT_SYMBOL(ttm_bo_move_memcpy);
> >  
> > +/**
> > + * ttm_bo_move_null() - assign memory for a buffer object.
> > + * @bo: The bo to assign the memory to.
> > + * @new_mem: The memory to be assigned, or NULL.
> > + *
> > + * Free the current resource of @bo and assign @new_mem to it. If
> > @new_mem is
> > + * NULL or its memory type manager doesn't use a &struct ttm_tt,
> > the bo's
> > + * &struct ttm_tt, if any, is unpopulated and destroyed.
> > + */
> > +void ttm_bo_move_null(struct ttm_buffer_object *bo,
> > +		      struct ttm_resource *new_mem)
> > +{
> > +	if (!new_mem || !ttm_manager_type(bo->bdev, new_mem-
> > >mem_type)->use_tt)
> > +		ttm_bo_tt_destroy(bo);
> > +
> > +	ttm_resource_free(bo, &bo->resource);
> > +	ttm_bo_assign_mem(bo, new_mem);
> > +}
> > +EXPORT_SYMBOL(ttm_bo_move_null);
> > +
> >  static void ttm_transfered_destroy(struct ttm_buffer_object *bo)
> >  {
> >  	struct ttm_transfer_obj *fbo;
> > diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h
> > index 32791c4db2a9..d525e04893ed 100644
> > --- a/include/drm/ttm/ttm_bo.h
> > +++ b/include/drm/ttm/ttm_bo.h
> > @@ -356,19 +356,8 @@ static inline void ttm_bo_assign_mem(struct
> > ttm_buffer_object *bo,
> >  	bo->resource = new_mem;
> >  }
> >  
> > -/**
> > - * ttm_bo_move_null - assign memory for a buffer object.
> > - * @bo: The bo to assign the memory to
> > - * @new_mem: The memory to be assigned.
> > - *
> > - * Assign the memory from new_mem to the memory of the buffer
> > object bo.
> > - */
> > -static inline void ttm_bo_move_null(struct ttm_buffer_object *bo,
> > -				    struct ttm_resource *new_mem)
> > -{
> > -	ttm_resource_free(bo, &bo->resource);
> > -	ttm_bo_assign_mem(bo, new_mem);
> > -}
> > +void ttm_bo_move_null(struct ttm_buffer_object *bo,
> > +		      struct ttm_resource *new_mem);
> >  
> >  /**
> >   * ttm_bo_unreserve
> > -- 
> > 2.56.1
> > 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] drm/ttm: Destroy the ttm_tt in ttm_bo_move_null() when it's no longer needed
  2026-11-24 19:09 [PATCH] drm/ttm: Destroy the ttm_tt in ttm_bo_move_null() when it's no longer needed Thomas Hellström
  2026-11-24 19:53 ` Matthew Brost
@ 2026-11-25  9:55 ` Matthew Auld
  2026-12-04 14:54 ` Natalie Vock
  2 siblings, 0 replies; 5+ messages in thread
From: Matthew Auld @ 2026-11-25  9:55 UTC (permalink / raw)
  To: Thomas Hellström, intel-xe
  Cc: Natalie Vock, Arun Pravin, Matthew Brost, dri-devel, stable

On 24/11/2026 19:09, Thomas Hellström wrote:
> The xe kmd uses ttm_bo_move_null() when moving an unpopulated bo to
> VRAM. In that case the bo may still carry a ttm_tt that was created
> for its deferred placement, and it is left dangling on a bo whose new
> resource doesn't use a ttm_tt.
> 
> Make ttm_bo_move_null() destroy the bo's ttm_tt when @new_mem is NULL
> or its memory type manager doesn't use a ttm_tt.
> 
> ttm_bo_tt_destroy() is internal to TTM and not exported. Rather than
> exporting it, move ttm_bo_move_null() out to ttm_bo_util.c and
> export that instead.
> 
> Patch and commit message was drafted using an LLM.
> 
> Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel GPUs")
> Cc: Natalie Vock <nat@pixelcluster.dev>
> Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
> Cc: Matthew Auld <matthew.auld@intel.com>
> Cc: Matthew Brost <matthew.brost@intel.com>
> Cc: dri-devel@lists.freedesktop.org
> Cc: <stable@vger.kernel.org> # v6.8+
> Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>

Reviewed-by: Matthew Auld <matthew.auld@intel.com>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] drm/ttm: Destroy the ttm_tt in ttm_bo_move_null() when it's no longer needed
  2026-11-24 19:09 [PATCH] drm/ttm: Destroy the ttm_tt in ttm_bo_move_null() when it's no longer needed Thomas Hellström
  2026-11-24 19:53 ` Matthew Brost
  2026-11-25  9:55 ` Matthew Auld
@ 2026-12-04 14:54 ` Natalie Vock
  2 siblings, 0 replies; 5+ messages in thread
From: Natalie Vock @ 2026-12-04 14:54 UTC (permalink / raw)
  To: intel-xe, Thomas Hellström
  Cc: Thomas Hellström, Arun Pravin, Matthew Auld, Matthew Brost,
	dri-devel, stable

On Tuesday, 24 November 2026 20:09 Thomas Hellström wrote:
> The xe kmd uses ttm_bo_move_null() when moving an unpopulated bo to
> VRAM. In that case the bo may still carry a ttm_tt that was created
> for its deferred placement, and it is left dangling on a bo whose new
> resource doesn't use a ttm_tt.
> 
> Make ttm_bo_move_null() destroy the bo's ttm_tt when @new_mem is NULL
> or its memory type manager doesn't use a ttm_tt.
> 
> ttm_bo_tt_destroy() is internal to TTM and not exported. Rather than
> exporting it, move ttm_bo_move_null() out to ttm_bo_util.c and
> export that instead.
> 
> Patch and commit message was drafted using an LLM.
> 
> Fixes: dd08ebf6c352 ("drm/xe: Introduce a new DRM driver for Intel GPUs")
> Cc: Natalie Vock <nat@pixelcluster.dev>
> Cc: Arun Pravin <arunpravin.paneerselvam@amd.com>
> Cc: Matthew Auld <matthew.auld@intel.com>
> Cc: Matthew Brost <matthew.brost@intel.com>
> Cc: dri-devel@lists.freedesktop.org
> Cc: <stable@vger.kernel.org> # v6.8+
> Signed-off-by: Thomas Hellström <thomas.hellstrom@linux.intel.com>

Reviewed-by: Natalie Vock <nat@pixelcluster.dev>

> ---
>  drivers/gpu/drm/ttm/ttm_bo_util.c | 20 ++++++++++++++++++++
>  include/drm/ttm/ttm_bo.h          | 15 ++-------------
>  2 files changed, 22 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
> index f9458a4d5a09..7f3459db596a 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_util.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
> @@ -202,6 +202,26 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
>  }
>  EXPORT_SYMBOL(ttm_bo_move_memcpy);
>  
> +/**
> + * ttm_bo_move_null() - assign memory for a buffer object.
> + * @bo: The bo to assign the memory to.
> + * @new_mem: The memory to be assigned, or NULL.
> + *
> + * Free the current resource of @bo and assign @new_mem to it. If @new_mem is
> + * NULL or its memory type manager doesn't use a &struct ttm_tt, the bo's
> + * &struct ttm_tt, if any, is unpopulated and destroyed.
> + */
> +void ttm_bo_move_null(struct ttm_buffer_object *bo,
> +		      struct ttm_resource *new_mem)
> +{
> +	if (!new_mem || !ttm_manager_type(bo->bdev, new_mem->mem_type)->use_tt)
> +		ttm_bo_tt_destroy(bo);
> +
> +	ttm_resource_free(bo, &bo->resource);
> +	ttm_bo_assign_mem(bo, new_mem);
> +}
> +EXPORT_SYMBOL(ttm_bo_move_null);
> +
>  static void ttm_transfered_destroy(struct ttm_buffer_object *bo)
>  {
>  	struct ttm_transfer_obj *fbo;
> diff --git a/include/drm/ttm/ttm_bo.h b/include/drm/ttm/ttm_bo.h
> index 32791c4db2a9..d525e04893ed 100644
> --- a/include/drm/ttm/ttm_bo.h
> +++ b/include/drm/ttm/ttm_bo.h
> @@ -356,19 +356,8 @@ static inline void ttm_bo_assign_mem(struct ttm_buffer_object *bo,
>  	bo->resource = new_mem;
>  }
>  
> -/**
> - * ttm_bo_move_null - assign memory for a buffer object.
> - * @bo: The bo to assign the memory to
> - * @new_mem: The memory to be assigned.
> - *
> - * Assign the memory from new_mem to the memory of the buffer object bo.
> - */
> -static inline void ttm_bo_move_null(struct ttm_buffer_object *bo,
> -				    struct ttm_resource *new_mem)
> -{
> -	ttm_resource_free(bo, &bo->resource);
> -	ttm_bo_assign_mem(bo, new_mem);
> -}
> +void ttm_bo_move_null(struct ttm_buffer_object *bo,
> +		      struct ttm_resource *new_mem);
>  
>  /**
>   * ttm_bo_unreserve
> 





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-12-04 14:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 19:09 [PATCH] drm/ttm: Destroy the ttm_tt in ttm_bo_move_null() when it's no longer needed Thomas Hellström
2026-11-24 19:53 ` Matthew Brost
2026-11-25  9:30   ` Thomas Hellström
2026-11-25  9:55 ` Matthew Auld
2026-12-04 14:54 ` Natalie Vock

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox