Verify Gamma & Degamma LUT sizes in amdgpu_dm_atomic_check
Subsystems (3)
PATCH 1/1 Verify Gamma & Degamma LUT sizes in amdgpu_dm_atomic_check
From: Mark Yacoub <[email protected]>
For each CRTC state, check the size of Gamma and Degamma LUTs so unexpected and larger sizes wouldn't slip through.
TEST: IGT:kms_color::pipe-invalid-gamma-lut-sizes
--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 3 ++ .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h | 1 + .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 40 ++++++++++++++++--- 3 files changed, 38 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +3 -0
@@ -9402,6 +9402,9 @@ static int amdgpu_dm_atomic_check(struct drm_device *dev, dm_old_crtc_state->dsc_force_changed == false)continue ; +if ((ret =amdgpu_dm_verify_lut_sizes (new_crtc_state))) + goto fail; +if (!new_crtc_state->enable)continue ;
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +1 -0
@@ -541,6 +541,7 @@ void amdgpu_dm_trigger_timing_sync(struct drm_device *dev);#define MAX_COLOR_LEGACY_LUT_ENTRIES 256void amdgpu_dm_init_color_mod (void ); +int amdgpu_dm_verify_lut_sizes (const struct drm_crtc_state *crtc_state);int amdgpu_dm_update_crtc_color_mgmt (struct dm_crtc_state *crtc);int amdgpu_dm_update_plane_color_mgmt (struct dm_crtc_state *crtc,struct dc_plane_state *dc_plane_state);
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +34 -6
@@ -284,6 +284,37 @@ static int __set_input_tf(struct dc_transfer_func *func,return res ?0 : -ENOMEM ; } +/** +* Verifies that the Degamma and Gamma LUTs attached to the |crtc_state| are of +* the expected size. +* Returns 0 on success. +*/ +int amdgpu_dm_verify_lut_sizes (const struct drm_crtc_state *crtc_state) +{ +const struct drm_color_lut *lut =NULL ; +uint32_t size =0 ; + + lut =__extract_blob_lut (crtc_state->degamma_lut, &size); +if (lut && size !=MAX_COLOR_LUT_ENTRIES ) { +DRM_DEBUG_DRIVER ( +"Invalid Degamma LUT size. Should be %u but got %u.\n" , +MAX_COLOR_LUT_ENTRIES , size); +return -EINVAL ; + } + + lut =__extract_blob_lut (crtc_state->gamma_lut, &size); +if (lut && size !=MAX_COLOR_LUT_ENTRIES && + size !=MAX_COLOR_LEGACY_LUT_ENTRIES ) { +DRM_DEBUG_DRIVER ( +"Invalid Gamma LUT size. Should be %u (or %u for legacy) but got %u.\n" , +MAX_COLOR_LUT_ENTRIES ,MAX_COLOR_LEGACY_LUT_ENTRIES , + size); +return -EINVAL ; + } + +return 0 ; +} +/** * amdgpu_dm_update_crtc_color_mgmt: Maps DRM color management to DC stream. * @crtc: amdgpu_dm crtc state
@@ -317,14 +348,11 @@ int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc)bool is_legacy;int r; - degamma_lut =__extract_blob_lut (crtc->base.degamma_lut, °amma_size); -if (degamma_lut && degamma_size !=MAX_COLOR_LUT_ENTRIES ) -return -EINVAL ; +if ((r =amdgpu_dm_verify_lut_sizes (&crtc->base))) +return r; + degamma_lut =__extract_blob_lut (crtc->base.degamma_lut, °amma_size); regamma_lut =__extract_blob_lut (crtc->base.gamma_lut, ®amma_size); -if (regamma_lut && regamma_size !=MAX_COLOR_LUT_ENTRIES && - regamma_size !=MAX_COLOR_LEGACY_LUT_ENTRIES ) -return -EINVAL ; has_degamma = degamma_lut && !__is_lut_linear (degamma_lut, degamma_size);
Signature · 1 line
2.32.0.rc1.229.g3e70b5a671-goog
Ignore this patch, in favor of (
https://patchwork.freedesktop.org/series/91023/), which appends the commit title with drm/amd/display.
Quoted 120 lines · Mark Yacoub
From: Mark Yacoub <[email protected]>
For each CRTC state, check the size of Gamma and Degamma LUTs so unexpected and larger sizes wouldn't slip through.
TEST: IGT:kms_color::pipe-invalid-gamma-lut-sizes
Signed-off-by Mark Yacoub <[email protected]>--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 3 ++ .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h | 1 + .../amd/display/amdgpu_dm/amdgpu_dm_color.c | 40 ++++++++++++++++--- 3 files changed, 38 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +3
-0@@ -9402,6 +9402,9 @@ static int amdgpu_dm_atomic_check(struct drm_device *dev, dm_old_crtc_state->dsc_force_changed == false) continue; +if ((ret =amdgpu_dm_verify_lut_sizes (new_crtc_state))) + goto fail; +if (!new_crtc_state->enable)continue ;drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +1
-0@@ -541,6 +541,7 @@ void amdgpu_dm_trigger_timing_sync(struct drm_device *dev);#define MAX_COLOR_LEGACY_LUT_ENTRIES 256void amdgpu_dm_init_color_mod (void ); +int amdgpu_dm_verify_lut_sizes (const struct drm_crtc_state *crtc_state);int amdgpu_dm_update_crtc_color_mgmt (struct dm_crtc_state *crtc); int amdgpu_dm_update_plane_color_mgmt(struct dm_crtc_state *crtc,struct
dc_plane_state*dc_plane_state);drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +2
-0@@ -284,6 +284,37 @@ static int __set_input_tf(struct dc_transfer_func *func, return res ? 0 : -ENOMEM; } +/** +* Verifies that the Degamma and Gamma LUTs attached to the |crtc_state| are of
+ * the expected size.
+ * Returns 0 on success.
+ */drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +9
-0+int amdgpu_dm_verify_lut_sizes (const struct drm_crtc_state *crtc_state) +{ +const struct drm_color_lut *lut =NULL ; +uint32_t size =0 ; + + lut =__extract_blob_lut (crtc_state->degamma_lut, &size); +if (lut && size !=MAX_COLOR_LUT_ENTRIES ) { + DRM_DEBUG_DRIVER( + "Invalid Degamma LUT size. Should be %u but got%u.\n",
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +9
-0+ MAX_COLOR_LUT_ENTRIES, size); +return -EINVAL ; + } + + lut =__extract_blob_lut (crtc_state->gamma_lut, &size); +if (lut && size !=MAX_COLOR_LUT_ENTRIES && + size !=MAX_COLOR_LEGACY_LUT_ENTRIES ) { + DRM_DEBUG_DRIVER( + "Invalid Gamma LUT size. Should be %u (or %u forlegacy) but got %u.\n",
+MAX_COLOR_LUT_ENTRIES,MAX_COLOR_LEGACY_LUT_ENTRIES,drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +7
-0+ size); +return -EINVAL ; + } + +return 0 ; +} +/** * amdgpu_dm_update_crtc_color_mgmt: Maps DRM color management to DC stream.
* @crtc:amdgpu_dmcrtc statedrivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +3
-3@@ -317,14 +348,11 @@ int amdgpu_dm_update_crtc_color_mgmt(struct dm_crtc_state *crtc)bool is_legacy;int r; - degamma_lut =__extract_blob_lut (crtc->base.degamma_lut, °amma_size); -if (degamma_lut && degamma_size !=MAX_COLOR_LUT_ENTRIES ) -return -EINVAL ; +if ((r =amdgpu_dm_verify_lut_sizes (&crtc->base))) +return r; + degamma_lut =__extract_blob_lut (crtc->base.degamma_lut, °amma_size); regamma_lut = __extract_blob_lut(crtc->base.gamma_lut,
®amma_size);drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c +0
-4-if (regamma_lut && regamma_size !=MAX_COLOR_LUT_ENTRIES && - regamma_size !=MAX_COLOR_LEGACY_LUT_ENTRIES ) -return -EINVAL ; has_degamma = degamma_lut && !__is_lut_linear (degamma_lut, degamma_size); --2.32.0.rc1.229.g3e70b5a671-goog
kernel test robot
build botThank you for the patch! Perhaps something to improve:
Hi Mark,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on tegra-drm/drm/tegra/for-next] [also build test WARNING on linus/master v5.13-rc4 next-20210604] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Mark-Yacoub/Verify-Gamma-Degamma-LUT-sizes-in-amdgpu_dm_atomic_check/20210605-010052 base: git://anongit.freedesktop.org/tegra/linux.git drm/tegra/for-next config: arc-allyesconfig (attached as .config) compiler: arceb-elf-gcc (GCC) 9.3.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/69d2510b404de1ebb3ee54e37daff71f1df02a29
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Mark-Yacoub/Verify-Gamma-Degamma-LUT-sizes-in-amdgpu_dm_atomic_check/20210605-010052 git checkout 69d2510b404de1ebb3ee54e37daff71f1df02a29
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arc
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm_color.c:288: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst
* Verifies that the Degamma and Gamma LUTs attached to the |crtc_state| are of
vim +288 drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm_color.c
286
287 /**
> 288 * Verifies that the Degamma and Gamma LUTs attached to the |crtc_state| are of
289 * the expected size.
290 * Returns 0 on success.
291 */
292 int amdgpu_dm_verify_lut_sizes(const struct drm_crtc_state *crtc_state)
293 {
294 const struct drm_color_lut *lut = NULL;
295 uint32_t size = 0;
296
297 lut = __extract_blob_lut(crtc_state->degamma_lut, &size);
298 if (lut && size != MAX_COLOR_LUT_ENTRIES) {
299 DRM_DEBUG_DRIVER(
300 "Invalid Degamma LUT size. Should be %u but got %u.\n",
301 MAX_COLOR_LUT_ENTRIES, size);
302 return -EINVAL;
303 }
304
305 lut = __extract_blob_lut(crtc_state->gamma_lut, &size);
306 if (lut && size != MAX_COLOR_LUT_ENTRIES &&
307 size != MAX_COLOR_LEGACY_LUT_ENTRIES) {
308 DRM_DEBUG_DRIVER(
309 "Invalid Gamma LUT size. Should be %u (or %u for legacy) but got %u.\n",
310 MAX_COLOR_LUT_ENTRIES, MAX_COLOR_LEGACY_LUT_ENTRIES,
311 size);
312 return -EINVAL;
313 }
314
315 return 0;
316 }
317
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
kernel test robot
build botThank you for the patch! Perhaps something to improve:
Hi Mark,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on tegra-drm/drm/tegra/for-next] [also build test WARNING on linus/master v5.13-rc4 next-20210604] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Mark-Yacoub/Verify-Gamma-Degamma-LUT-sizes-in-amdgpu_dm_atomic_check/20210605-010052 base: git://anongit.freedesktop.org/tegra/linux.git drm/tegra/for-next config: x86_64-randconfig-a014-20210604 (attached as .config) compiler: clang version 13.0.0 (https://github.com/llvm/llvm-project 5c0d1b2f902aa6a9cf47cc7e42c5b83bb2217cf9)
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# https://github.com/0day-ci/linux/commit/69d2510b404de1ebb3ee54e37daff71f1df02a29
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Mark-Yacoub/Verify-Gamma-Degamma-LUT-sizes-in-amdgpu_dm_atomic_check/20210605-010052 git checkout 69d2510b404de1ebb3ee54e37daff71f1df02a29
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm_color.c:288: warning: This comment starts with '/**', but isn't a kernel-doc comment. Refer Documentation/doc-guide/kernel-doc.rst
* Verifies that the Degamma and Gamma LUTs attached to the |crtc_state| are of
vim +288 drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm_color.c
286
287 /**
> 288 * Verifies that the Degamma and Gamma LUTs attached to the |crtc_state| are of
289 * the expected size.
290 * Returns 0 on success.
291 */
292 int amdgpu_dm_verify_lut_sizes(const struct drm_crtc_state *crtc_state)
293 {
294 const struct drm_color_lut *lut = NULL;
295 uint32_t size = 0;
296
297 lut = __extract_blob_lut(crtc_state->degamma_lut, &size);
298 if (lut && size != MAX_COLOR_LUT_ENTRIES) {
299 DRM_DEBUG_DRIVER(
300 "Invalid Degamma LUT size. Should be %u but got %u.\n",
301 MAX_COLOR_LUT_ENTRIES, size);
302 return -EINVAL;
303 }
304
305 lut = __extract_blob_lut(crtc_state->gamma_lut, &size);
306 if (lut && size != MAX_COLOR_LUT_ENTRIES &&
307 size != MAX_COLOR_LEGACY_LUT_ENTRIES) {
308 DRM_DEBUG_DRIVER(
309 "Invalid Gamma LUT size. Should be %u (or %u for legacy) but got %u.\n",
310 MAX_COLOR_LUT_ENTRIES, MAX_COLOR_LEGACY_LUT_ENTRIES,
311 size);
312 return -EINVAL;
313 }
314
315 return 0;
316 }
317
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org