drm/ttm: Try to check if new ttm man out of bounds during compile
Subsystems (3)
RFC PATCH 1/1 drm/ttm: Try to check if new ttm man out of bounds during compile
Allow TTM know if vendor set new ttm mananger out of bounds by adding build_bug_on.
--- 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(+)
drivers/gpu/drm/ttm/ttm_range_manager.c +2 -0
@@ -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 *
include/drm/ttm/ttm_device.h +3 -0
@@ -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; }
include/drm/ttm/ttm_range_manager.h +10 -0
@@ -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
Signature · 1 line
2.25.1
Am 13.09.21 um 05:36 schrieb xinhui pan:
Quoted 2 lines
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.
Quoted 61 lines
Signed-off-by xinhui pan <[email protected]>--- 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(+)drivers/gpu/drm/ttm/ttm_range_manager.c +2
-0@@ -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 * include/drm/ttm/ttm_device.h +3
-0@@ -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; }include/drm/ttm/ttm_range_manager.h +10
-0@@ -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
[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 <[email protected]>
发送时间: 2021年9月13日 14:35
收件人: Pan, Xinhui; [email protected]
抄送: Koenig, Christian; [email protected]; [email protected]; 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:
Quoted 2 lines
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.
Quoted 61 lines
Signed-off-by xinhui pan <[email protected]>--- 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(+)drivers/gpu/drm/ttm/ttm_range_manager.c +2
-0@@ -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 * include/drm/ttm/ttm_device.h +3
-0@@ -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; }include/drm/ttm/ttm_range_manager.h +10
-0@@ -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