回复: [RFC PATCH] drm/ttm: Try to check if new ttm man out of bounds during compile

Pan, Xinhui Xinhui.Pan at amd.com
Mon Sep 13 06:44:01 UTC 2021


[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 at gmail.com>
发送时间: 2021年9月13日 14:35
收件人: Pan, Xinhui; amd-gfx at lists.freedesktop.org
抄送: Koenig, Christian; daniel at ffwll.ch; dri-devel at 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 at 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



More information about the dri-devel mailing list