Skip to content

Commit

Permalink
drm/ttm: Try to check if new ttm man out of bounds during compile
Browse files Browse the repository at this point in the history
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>
Reviewed-by: Christian König <christian.koenig@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20210913080950.180752-1-xinhui.pan@amd.com
Signed-off-by: Christian König <christian.koenig@amd.com>
  • Loading branch information
xinhui pan authored and Christian König committed Sep 13, 2021
1 parent d4cb82a commit 617d5b3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
8 changes: 4 additions & 4 deletions drivers/gpu/drm/ttm/ttm_range_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ static const struct ttm_resource_manager_func ttm_range_manager_func = {
* Initialise a generic range manager for the selected memory type.
* The range manager is installed for this device in the type slot.
*/
int ttm_range_man_init(struct ttm_device *bdev,
int ttm_range_man_init_nocheck(struct ttm_device *bdev,
unsigned type, bool use_tt,
unsigned long p_size)
{
Expand All @@ -163,7 +163,7 @@ int ttm_range_man_init(struct ttm_device *bdev,
ttm_resource_manager_set_used(man, true);
return 0;
}
EXPORT_SYMBOL(ttm_range_man_init);
EXPORT_SYMBOL(ttm_range_man_init_nocheck);

/**
* ttm_range_man_fini
Expand All @@ -173,7 +173,7 @@ EXPORT_SYMBOL(ttm_range_man_init);
*
* Remove the generic range manager from a slot and tear it down.
*/
int ttm_range_man_fini(struct ttm_device *bdev,
int ttm_range_man_fini_nocheck(struct ttm_device *bdev,
unsigned type)
{
struct ttm_resource_manager *man = ttm_manager_type(bdev, type);
Expand All @@ -200,4 +200,4 @@ int ttm_range_man_fini(struct ttm_device *bdev,
kfree(rman);
return 0;
}
EXPORT_SYMBOL(ttm_range_man_fini);
EXPORT_SYMBOL(ttm_range_man_fini_nocheck);
3 changes: 3 additions & 0 deletions include/drm/ttm/ttm_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,12 +291,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;
}

Expand Down
18 changes: 16 additions & 2 deletions include/drm/ttm/ttm_range_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#define _TTM_RANGE_MANAGER_H_

#include <drm/ttm/ttm_resource.h>
#include <drm/ttm/ttm_device.h>
#include <drm/drm_mm.h>

/**
Expand Down Expand Up @@ -33,10 +34,23 @@ to_ttm_range_mgr_node(struct ttm_resource *res)
return container_of(res, struct ttm_range_mgr_node, base);
}

int ttm_range_man_init(struct ttm_device *bdev,
int ttm_range_man_init_nocheck(struct ttm_device *bdev,
unsigned type, bool use_tt,
unsigned long p_size);
int ttm_range_man_fini(struct ttm_device *bdev,
int ttm_range_man_fini_nocheck(struct ttm_device *bdev,
unsigned type);
static __always_inline int ttm_range_man_init(struct ttm_device *bdev,
unsigned int type, bool use_tt,
unsigned long p_size)
{
BUILD_BUG_ON(__builtin_constant_p(type) && type >= TTM_NUM_MEM_TYPES);
return ttm_range_man_init_nocheck(bdev, type, use_tt, p_size);
}

static __always_inline int ttm_range_man_fini(struct ttm_device *bdev,
unsigned int type)
{
BUILD_BUG_ON(__builtin_constant_p(type) && type >= TTM_NUM_MEM_TYPES);
return ttm_range_man_fini_nocheck(bdev, type);
}
#endif

0 comments on commit 617d5b3

Please sign in to comment.