diff mbox series

[5.11,073/120] drm/ttm: Warn on pinning without holding a reference

Message ID 20210322121932.109281887@linuxfoundation.org
State New
Headers show
Series None | expand

Commit Message

Greg Kroah-Hartman March 22, 2021, 12:27 p.m. UTC
From: Daniel Vetter <daniel.vetter@ffwll.ch>

[ Upstream commit 57fcd550eb15bce14a7154736379dfd4ed60ae81 ]

Not technically a problem for ttm, but very likely a driver bug and
pretty big time confusing for reviewing code.

So warn about it, both at cleanup time (so we catch these for sure)
and at pin/unpin time (so we know who's the culprit).

Reviewed-by: Huang Rui <ray.huang@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>
Cc: Christian Koenig <christian.koenig@amd.com>
Cc: Huang Rui <ray.huang@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20201028113120.3641237-1-daniel.vetter@ffwll.ch
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/gpu/drm/ttm/ttm_bo.c | 2 +-
 include/drm/ttm/ttm_bo_api.h | 2 ++
 2 files changed, 3 insertions(+), 1 deletion(-)

Comments

Christian König March 25, 2021, 8:14 a.m. UTC | #1
Hi Greg,

sorry just realized this after users started to complain. This patch 
shouldn't been backported to 5.11 in the first place.

The warning itself is a good idea, but we also have patch for drivers 
and TTM in the pipeline for 5.12 so that the warning isn't triggered any 
more.

Without backporting all of that we now get a rain of warnings in 5.11.9.

My suggestion is to revert this patch from the 5.11 branch.

Thanks,
Christian.

Am 22.03.21 um 13:27 schrieb Greg Kroah-Hartman:
> From: Daniel Vetter <daniel.vetter@ffwll.ch>

>

> [ Upstream commit 57fcd550eb15bce14a7154736379dfd4ed60ae81 ]

>

> Not technically a problem for ttm, but very likely a driver bug and

> pretty big time confusing for reviewing code.

>

> So warn about it, both at cleanup time (so we catch these for sure)

> and at pin/unpin time (so we know who's the culprit).

>

> Reviewed-by: Huang Rui <ray.huang@amd.com>

> Reviewed-by: Christian König <christian.koenig@amd.com>

> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com>

> Cc: Christian Koenig <christian.koenig@amd.com>

> Cc: Huang Rui <ray.huang@amd.com>

> Link: https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatchwork.freedesktop.org%2Fpatch%2Fmsgid%2F20201028113120.3641237-1-daniel.vetter%40ffwll.ch&amp;data=04%7C01%7Cchristian.koenig%40amd.com%7C090c217ffc0f4823bbe508d8ed2ec6eb%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637520132480960479%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&amp;sdata=SJqFJ7QthSG4R%2B918EqjKliGwi1DJUORh6DtpHGTtn8%3D&amp;reserved=0

> Signed-off-by: Sasha Levin <sashal@kernel.org>

> ---

>   drivers/gpu/drm/ttm/ttm_bo.c | 2 +-

>   include/drm/ttm/ttm_bo_api.h | 2 ++

>   2 files changed, 3 insertions(+), 1 deletion(-)

>

> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c

> index 22073e77fdf9..a76eb2c14e8c 100644

> --- a/drivers/gpu/drm/ttm/ttm_bo.c

> +++ b/drivers/gpu/drm/ttm/ttm_bo.c

> @@ -514,7 +514,7 @@ static void ttm_bo_release(struct kref *kref)

>   		 * shrinkers, now that they are queued for

>   		 * destruction.

>   		 */

> -		if (bo->pin_count) {

> +		if (WARN_ON(bo->pin_count)) {

>   			bo->pin_count = 0;

>   			ttm_bo_del_from_lru(bo);

>   			ttm_bo_add_mem_to_lru(bo, &bo->mem);

> diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h

> index 2564e66e67d7..79b9367e0ffd 100644

> --- a/include/drm/ttm/ttm_bo_api.h

> +++ b/include/drm/ttm/ttm_bo_api.h

> @@ -600,6 +600,7 @@ static inline bool ttm_bo_uses_embedded_gem_object(struct ttm_buffer_object *bo)

>   static inline void ttm_bo_pin(struct ttm_buffer_object *bo)

>   {

>   	dma_resv_assert_held(bo->base.resv);

> +	WARN_ON_ONCE(!kref_read(&bo->kref));

>   	++bo->pin_count;

>   }

>   

> @@ -613,6 +614,7 @@ static inline void ttm_bo_unpin(struct ttm_buffer_object *bo)

>   {

>   	dma_resv_assert_held(bo->base.resv);

>   	WARN_ON_ONCE(!bo->pin_count);

> +	WARN_ON_ONCE(!kref_read(&bo->kref));

>   	--bo->pin_count;

>   }

>
Greg Kroah-Hartman March 25, 2021, 8:50 a.m. UTC | #2
On Thu, Mar 25, 2021 at 09:14:59AM +0100, Christian König wrote:
> Hi Greg,

> 

> sorry just realized this after users started to complain. This patch

> shouldn't been backported to 5.11 in the first place.

> 

> The warning itself is a good idea, but we also have patch for drivers and

> TTM in the pipeline for 5.12 so that the warning isn't triggered any more.

> 

> Without backporting all of that we now get a rain of warnings in 5.11.9.

> 

> My suggestion is to revert this patch from the 5.11 branch.


Thanks, will go do so right now and push out a new 5.11 release with
that in it to keep the noise down for you.

greg k-h
Christian König March 25, 2021, 8:51 a.m. UTC | #3
Am 25.03.21 um 09:50 schrieb Greg Kroah-Hartman:
> On Thu, Mar 25, 2021 at 09:14:59AM +0100, Christian König wrote:

>> Hi Greg,

>>

>> sorry just realized this after users started to complain. This patch

>> shouldn't been backported to 5.11 in the first place.

>>

>> The warning itself is a good idea, but we also have patch for drivers and

>> TTM in the pipeline for 5.12 so that the warning isn't triggered any more.

>>

>> Without backporting all of that we now get a rain of warnings in 5.11.9.

>>

>> My suggestion is to revert this patch from the 5.11 branch.

> Thanks, will go do so right now and push out a new 5.11 release with

> that in it to keep the noise down for you.


Thanks a lot for that! I got a bit swamped this morning because of mails 
and bug reports.

Christian.

>

> greg k-h
diff mbox series

Patch

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 22073e77fdf9..a76eb2c14e8c 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -514,7 +514,7 @@  static void ttm_bo_release(struct kref *kref)
 		 * shrinkers, now that they are queued for
 		 * destruction.
 		 */
-		if (bo->pin_count) {
+		if (WARN_ON(bo->pin_count)) {
 			bo->pin_count = 0;
 			ttm_bo_del_from_lru(bo);
 			ttm_bo_add_mem_to_lru(bo, &bo->mem);
diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
index 2564e66e67d7..79b9367e0ffd 100644
--- a/include/drm/ttm/ttm_bo_api.h
+++ b/include/drm/ttm/ttm_bo_api.h
@@ -600,6 +600,7 @@  static inline bool ttm_bo_uses_embedded_gem_object(struct ttm_buffer_object *bo)
 static inline void ttm_bo_pin(struct ttm_buffer_object *bo)
 {
 	dma_resv_assert_held(bo->base.resv);
+	WARN_ON_ONCE(!kref_read(&bo->kref));
 	++bo->pin_count;
 }
 
@@ -613,6 +614,7 @@  static inline void ttm_bo_unpin(struct ttm_buffer_object *bo)
 {
 	dma_resv_assert_held(bo->base.resv);
 	WARN_ON_ONCE(!bo->pin_count);
+	WARN_ON_ONCE(!kref_read(&bo->kref));
 	--bo->pin_count;
 }