]> git.baikalelectronics.ru Git - kernel.git/commitdiff
drm/ttm: Try to check if new ttm man out of bounds during compile
authorxinhui pan <xinhui.pan@amd.com>
Mon, 13 Sep 2021 08:09:50 +0000 (16:09 +0800)
committerChristian König <christian.koenig@amd.com>
Mon, 13 Sep 2021 08:14:28 +0000 (10:14 +0200)
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>
drivers/gpu/drm/ttm/ttm_range_manager.c
include/drm/ttm/ttm_device.h
include/drm/ttm/ttm_range_manager.h

index f4b08a8705b320687fc8aa9d2db02e5b7a8013d9..67d68a4a8640681f88af64102468ca1ed2bf25ac 100644 (file)
@@ -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)
 {
@@ -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
@@ -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);
@@ -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);
index 3cc1d9b7613194d791212bfcfe9e27a697ab749d..cbe03d45e88343d562f29cf63e3997257bca50c5 100644 (file)
@@ -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;
 }
 
index 22b6fa42ac20fd2724a4d48bdfb9c40a6548942b..7963b957e9ef20a6e755ca71190f82ac72de7867 100644 (file)
@@ -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>
 
 /**
@@ -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