All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] drm/ttm: Try to check if new ttm man out of bounds during compile
@ 2021-09-13  3:36 xinhui pan
  2021-09-13  6:35 ` Christian König
  0 siblings, 1 reply; 3+ messages in thread
From: xinhui pan @ 2021-09-13  3:36 UTC (permalink / raw)
  To: amd-gfx; +Cc: christian.koenig, daniel, dri-devel, Guchun.Chen, xinhui pan

Allow TTM know if vendor set new ttm mananger out of bounds by adding
build_bug_on.

Signed-off-by: xinhui pan <xinhui.pan@amd.com>
---
 drivers/gpu/drm/ttm/ttm_range_manager.c |  2 ++
 include/drm/ttm/ttm_device.h            |  3 +++
 include/drm/ttm/ttm_range_manager.h     | 10 ++++++++++
 3 files changed, 15 insertions(+)

diff --git a/drivers/gpu/drm/ttm/ttm_range_manager.c b/drivers/gpu/drm/ttm/ttm_range_manager.c
index 03395386e8a7..47e304719b88 100644
--- a/drivers/gpu/drm/ttm/ttm_range_manager.c
+++ b/drivers/gpu/drm/ttm/ttm_range_manager.c
@@ -127,6 +127,8 @@ static const struct ttm_resource_manager_func ttm_range_manager_func = {
 	.debug = ttm_range_man_debug
 };
 
+#undef ttm_range_man_init
+#undef ttm_range_man_fini
 /**
  * ttm_range_man_init
  *
diff --git a/include/drm/ttm/ttm_device.h b/include/drm/ttm/ttm_device.h
index 07d722950d5b..6f23724f5a06 100644
--- a/include/drm/ttm/ttm_device.h
+++ b/include/drm/ttm/ttm_device.h
@@ -285,12 +285,15 @@ int ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx,
 static inline struct ttm_resource_manager *
 ttm_manager_type(struct ttm_device *bdev, int mem_type)
 {
+	BUILD_BUG_ON(__builtin_constant_p(mem_type)
+		     && mem_type >= TTM_NUM_MEM_TYPES);
 	return bdev->man_drv[mem_type];
 }
 
 static inline void ttm_set_driver_manager(struct ttm_device *bdev, int type,
 					  struct ttm_resource_manager *manager)
 {
+	BUILD_BUG_ON(__builtin_constant_p(type) && type >= TTM_NUM_MEM_TYPES);
 	bdev->man_drv[type] = manager;
 }
 
diff --git a/include/drm/ttm/ttm_range_manager.h b/include/drm/ttm/ttm_range_manager.h
index 22b6fa42ac20..9250ade54e2c 100644
--- a/include/drm/ttm/ttm_range_manager.h
+++ b/include/drm/ttm/ttm_range_manager.h
@@ -38,5 +38,15 @@ int ttm_range_man_init(struct ttm_device *bdev,
 		       unsigned long p_size);
 int ttm_range_man_fini(struct ttm_device *bdev,
 		       unsigned type);
+#define ttm_range_man_init(bdev, type, use_tt, size) ({	\
+	BUILD_BUG_ON(__builtin_constant_p(type)		\
+			&& type >= TTM_NUM_MEM_TYPES);	\
+	ttm_range_man_init(bdev, type, use_tt, size);	\
+})
+#define ttm_range_man_fini(bdev, type) ({		\
+	BUILD_BUG_ON(__builtin_constant_p(type)		\
+			&& type >= TTM_NUM_MEM_TYPES);	\
+	ttm_range_man_fini(bdev, type);			\
+})
 
 #endif
-- 
2.25.1


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

* Re: [RFC PATCH] drm/ttm: Try to check if new ttm man out of bounds during compile
  2021-09-13  3:36 [RFC PATCH] drm/ttm: Try to check if new ttm man out of bounds during compile xinhui pan
@ 2021-09-13  6:35 ` Christian König
  2021-09-13  6:44   ` 回复: " Pan, Xinhui
  0 siblings, 1 reply; 3+ messages in thread
From: Christian König @ 2021-09-13  6:35 UTC (permalink / raw)
  To: xinhui pan, amd-gfx; +Cc: christian.koenig, daniel, dri-devel, Guchun.Chen



Am 13.09.21 um 05:36 schrieb xinhui pan:
> Allow TTM know if vendor set new ttm mananger out of bounds by adding
> build_bug_on.

I really like the part in the inline functions, but the wrappers around 
the ttm_range_man_init/fini look a bit awkward of hand.

Christian.

>
> Signed-off-by: xinhui pan <xinhui.pan@amd.com>
> ---
>   drivers/gpu/drm/ttm/ttm_range_manager.c |  2 ++
>   include/drm/ttm/ttm_device.h            |  3 +++
>   include/drm/ttm/ttm_range_manager.h     | 10 ++++++++++
>   3 files changed, 15 insertions(+)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_range_manager.c b/drivers/gpu/drm/ttm/ttm_range_manager.c
> index 03395386e8a7..47e304719b88 100644
> --- a/drivers/gpu/drm/ttm/ttm_range_manager.c
> +++ b/drivers/gpu/drm/ttm/ttm_range_manager.c
> @@ -127,6 +127,8 @@ static const struct ttm_resource_manager_func ttm_range_manager_func = {
>   	.debug = ttm_range_man_debug
>   };
>   
> +#undef ttm_range_man_init
> +#undef ttm_range_man_fini
>   /**
>    * ttm_range_man_init
>    *
> diff --git a/include/drm/ttm/ttm_device.h b/include/drm/ttm/ttm_device.h
> index 07d722950d5b..6f23724f5a06 100644
> --- a/include/drm/ttm/ttm_device.h
> +++ b/include/drm/ttm/ttm_device.h
> @@ -285,12 +285,15 @@ int ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx,
>   static inline struct ttm_resource_manager *
>   ttm_manager_type(struct ttm_device *bdev, int mem_type)
>   {
> +	BUILD_BUG_ON(__builtin_constant_p(mem_type)
> +		     && mem_type >= TTM_NUM_MEM_TYPES);
>   	return bdev->man_drv[mem_type];
>   }
>   
>   static inline void ttm_set_driver_manager(struct ttm_device *bdev, int type,
>   					  struct ttm_resource_manager *manager)
>   {
> +	BUILD_BUG_ON(__builtin_constant_p(type) && type >= TTM_NUM_MEM_TYPES);
>   	bdev->man_drv[type] = manager;
>   }
>   
> diff --git a/include/drm/ttm/ttm_range_manager.h b/include/drm/ttm/ttm_range_manager.h
> index 22b6fa42ac20..9250ade54e2c 100644
> --- a/include/drm/ttm/ttm_range_manager.h
> +++ b/include/drm/ttm/ttm_range_manager.h
> @@ -38,5 +38,15 @@ int ttm_range_man_init(struct ttm_device *bdev,
>   		       unsigned long p_size);
>   int ttm_range_man_fini(struct ttm_device *bdev,
>   		       unsigned type);
> +#define ttm_range_man_init(bdev, type, use_tt, size) ({	\
> +	BUILD_BUG_ON(__builtin_constant_p(type)		\
> +			&& type >= TTM_NUM_MEM_TYPES);	\
> +	ttm_range_man_init(bdev, type, use_tt, size);	\
> +})
> +#define ttm_range_man_fini(bdev, type) ({		\
> +	BUILD_BUG_ON(__builtin_constant_p(type)		\
> +			&& type >= TTM_NUM_MEM_TYPES);	\
> +	ttm_range_man_fini(bdev, type);			\
> +})
>   
>   #endif


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

* 回复: [RFC PATCH] drm/ttm: Try to check if new ttm man out of bounds during compile
  2021-09-13  6:35 ` Christian König
@ 2021-09-13  6:44   ` Pan, Xinhui
  0 siblings, 0 replies; 3+ messages in thread
From: Pan, Xinhui @ 2021-09-13  6:44 UTC (permalink / raw)
  To: Christian König, amd-gfx
  Cc: Koenig, Christian, daniel, dri-devel, Chen, Guchun

[AMD Official Use Only]

ttm_range_man_init/fini are exported. Someone else might use it by find_symbol.
I just want to not break things.

Developer usually compile the whole kernel. So add a checked version of ttm_range_man_init/fini by the wrappers.

________________________________________
发件人: Christian König <ckoenig.leichtzumerken@gmail.com>
发送时间: 2021年9月13日 14:35
收件人: Pan, Xinhui; amd-gfx@lists.freedesktop.org
抄送: Koenig, Christian; daniel@ffwll.ch; dri-devel@lists.freedesktop.org; Chen, Guchun
主题: Re: [RFC PATCH] drm/ttm: Try to check if new ttm man out of bounds during compile



Am 13.09.21 um 05:36 schrieb xinhui pan:
> Allow TTM know if vendor set new ttm mananger out of bounds by adding
> build_bug_on.

I really like the part in the inline functions, but the wrappers around
the ttm_range_man_init/fini look a bit awkward of hand.

Christian.

>
> Signed-off-by: xinhui pan <xinhui.pan@amd.com>
> ---
>   drivers/gpu/drm/ttm/ttm_range_manager.c |  2 ++
>   include/drm/ttm/ttm_device.h            |  3 +++
>   include/drm/ttm/ttm_range_manager.h     | 10 ++++++++++
>   3 files changed, 15 insertions(+)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_range_manager.c b/drivers/gpu/drm/ttm/ttm_range_manager.c
> index 03395386e8a7..47e304719b88 100644
> --- a/drivers/gpu/drm/ttm/ttm_range_manager.c
> +++ b/drivers/gpu/drm/ttm/ttm_range_manager.c
> @@ -127,6 +127,8 @@ static const struct ttm_resource_manager_func ttm_range_manager_func = {
>       .debug = ttm_range_man_debug
>   };
>
> +#undef ttm_range_man_init
> +#undef ttm_range_man_fini
>   /**
>    * ttm_range_man_init
>    *
> diff --git a/include/drm/ttm/ttm_device.h b/include/drm/ttm/ttm_device.h
> index 07d722950d5b..6f23724f5a06 100644
> --- a/include/drm/ttm/ttm_device.h
> +++ b/include/drm/ttm/ttm_device.h
> @@ -285,12 +285,15 @@ int ttm_device_swapout(struct ttm_device *bdev, struct ttm_operation_ctx *ctx,
>   static inline struct ttm_resource_manager *
>   ttm_manager_type(struct ttm_device *bdev, int mem_type)
>   {
> +     BUILD_BUG_ON(__builtin_constant_p(mem_type)
> +                  && mem_type >= TTM_NUM_MEM_TYPES);
>       return bdev->man_drv[mem_type];
>   }
>
>   static inline void ttm_set_driver_manager(struct ttm_device *bdev, int type,
>                                         struct ttm_resource_manager *manager)
>   {
> +     BUILD_BUG_ON(__builtin_constant_p(type) && type >= TTM_NUM_MEM_TYPES);
>       bdev->man_drv[type] = manager;
>   }
>
> diff --git a/include/drm/ttm/ttm_range_manager.h b/include/drm/ttm/ttm_range_manager.h
> index 22b6fa42ac20..9250ade54e2c 100644
> --- a/include/drm/ttm/ttm_range_manager.h
> +++ b/include/drm/ttm/ttm_range_manager.h
> @@ -38,5 +38,15 @@ int ttm_range_man_init(struct ttm_device *bdev,
>                      unsigned long p_size);
>   int ttm_range_man_fini(struct ttm_device *bdev,
>                      unsigned type);
> +#define ttm_range_man_init(bdev, type, use_tt, size) ({      \
> +     BUILD_BUG_ON(__builtin_constant_p(type)         \
> +                     && type >= TTM_NUM_MEM_TYPES);  \
> +     ttm_range_man_init(bdev, type, use_tt, size);   \
> +})
> +#define ttm_range_man_fini(bdev, type) ({            \
> +     BUILD_BUG_ON(__builtin_constant_p(type)         \
> +                     && type >= TTM_NUM_MEM_TYPES);  \
> +     ttm_range_man_fini(bdev, type);                 \
> +})
>
>   #endif


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

end of thread, other threads:[~2021-09-13  6:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-13  3:36 [RFC PATCH] drm/ttm: Try to check if new ttm man out of bounds during compile xinhui pan
2021-09-13  6:35 ` Christian König
2021-09-13  6:44   ` 回复: " Pan, Xinhui

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.