[Public] Hi Christian and Xinhui,
Thanks for your suggestion. The cause is I saw data corruption in several proprietary use cases. BUILD_BUG_ON will have build variation per gcc difference? Anyway, WARN_ON is fine to me, and I will send a new patch set soon to address this. Regards, Guchun From: Koenig, Christian <christian.koe...@amd.com> Sent: Friday, September 10, 2021 2:37 PM To: Pan, Xinhui <xinhui....@amd.com>; amd-gfx@lists.freedesktop.org; dri-de...@lists.freedesktop.org; Deucher, Alexander <alexander.deuc...@amd.com>; Chen, Guchun <guchun.c...@amd.com> Cc: Shi, Leslie <yuliang....@amd.com> Subject: Re: [PATCH] drm/ttm: add a BUG_ON in ttm_set_driver_manager when array bounds Yeah, that's a good point. If build_bug_on() doesn't works for some reason then we at least need to lower this to a WARN_ON. A BUG_ON() is only justified if we prevent strong data corruption with it or note a NULL pointer earlier on or similar. Regards, Christian. Am 10.09.21 um 06:36 schrieb Pan, Xinhui: [AMD Official Use Only] looks good to me. But maybe build_bug_on works too and more reasonable to detect such wrong usage. ________________________________ From: Chen, Guchun <guchun.c...@amd.com><mailto:guchun.c...@amd.com> Sent: Friday, September 10, 2021 12:30:14 PM To: amd-gfx@lists.freedesktop.org<mailto:amd-gfx@lists.freedesktop.org> <amd-gfx@lists.freedesktop.org><mailto:amd-gfx@lists.freedesktop.org>; dri-de...@lists.freedesktop.org<mailto:dri-de...@lists.freedesktop.org> <dri-de...@lists.freedesktop.org><mailto:dri-de...@lists.freedesktop.org>; Koenig, Christian <christian.koe...@amd.com><mailto:christian.koe...@amd.com>; Pan, Xinhui <xinhui....@amd.com><mailto:xinhui....@amd.com>; Deucher, Alexander <alexander.deuc...@amd.com><mailto:alexander.deuc...@amd.com> Cc: Chen, Guchun <guchun.c...@amd.com><mailto:guchun.c...@amd.com>; Shi, Leslie <yuliang....@amd.com><mailto:yuliang....@amd.com> Subject: [PATCH] drm/ttm: add a BUG_ON in ttm_set_driver_manager when array bounds Vendor will define their own memory types on top of TTM_PL_PRIV, but call ttm_set_driver_manager directly without checking mem_type value when setting up memory manager. So add such check to aware the case when array bounds. Signed-off-by: Leslie Shi <yuliang....@amd.com><mailto:yuliang....@amd.com> Signed-off-by: Guchun Chen <guchun.c...@amd.com><mailto:guchun.c...@amd.com> --- include/drm/ttm/ttm_device.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/drm/ttm/ttm_device.h b/include/drm/ttm/ttm_device.h index 7a0f561c57ee..24ad76ca8022 100644 --- a/include/drm/ttm/ttm_device.h +++ b/include/drm/ttm/ttm_device.h @@ -308,6 +308,7 @@ ttm_manager_type(struct ttm_device *bdev, int mem_type) static inline void ttm_set_driver_manager(struct ttm_device *bdev, int type, struct ttm_resource_manager *manager) { + BUG_ON(type >= TTM_NUM_MEM_TYPES); bdev->man_drv[type] = manager; } -- 2.17.1