drm/amd/pm: And destination bounds checking to struct copy
Subsystems (3)
PATCH 1/1 drm/amd/pm: And destination bounds checking to struct copy
In preparation for FORTIFY_SOURCE performing compile-time and run-time field bounds checking for memcpy(), memmove(), and memset(), avoid intentionally writing across neighboring fields.
The "Board Parameters" members of the structs:
struct atom_smc_dpm_info_v4_5 struct atom_smc_dpm_info_v4_6 struct atom_smc_dpm_info_v4_7 struct atom_smc_dpm_info_v4_10
are written to the corresponding members of the corresponding PPTable_t variables, but they lack destination size bounds checking, which means the compiler cannot verify at compile time that this is an intended and safe memcpy().
Since the header files are effectively immutable[1] and a struct_group() cannot be used, nor a common struct referenced by both sides of the memcpy() arguments, add a new helper, memcpy_trailing(), to perform the bounds checking at compile time. Replace the open-coded memcpy()s with memcpy_trailing() which includes enough context for the bounds checking.
"objdump -d" shows no object code changes.
[1] https://lore.kernel.org/lkml/[email protected]
---
Alex, I dropped your prior Acked-by, since the implementation is very different. If you're still happy with it, I can add it back. :)
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 25 +++++++++++++++++++ .../gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c | 6 ++--- .../gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c | 8 +++--- .../drm/amd/pm/swsmu/smu13/aldebaran_ppt.c | 5 ++-- 4 files changed, 33 insertions(+), 11 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +25 -0
@@ -1446,4 +1446,29 @@ static inline int amdgpu_in_reset(struct amdgpu_device *adev) {return atomic_read (&adev->in_gpu_reset); } + +/** +* memcpy_trailing - Copy the end of one structure into the middle of another +* +* @dst: Pointer to destination struct +* @first_dst_member: The member name in @dst where the overwrite begins +* @last_dst_member: The member name in @dst where the overwrite ends after +* @src: Pointer to the source struct +* @first_src_member: The member name in @src where the copy begins +* +*/ +#define memcpy_trailing (dst, first_dst_member, last_dst_member, \ + src, first_src_member) \ +({ \ + size_t __src_offset = offsetof(typeof(*(src)), first_src_member); \ + size_t __src_size = sizeof(*(src)) - __src_offset; \ + size_t __dst_offset = offsetof(typeof(*(dst)), first_dst_member); \ + size_t __dst_size = offsetofend(typeof(*(dst)), last_dst_member) - \ + __dst_offset; \ + BUILD_BUG_ON(__src_size != __dst_size); \ + __builtin_memcpy((u8 *)(dst) + __dst_offset, \ + (u8 *)(src) + __src_offset, \ + __dst_size); \ +}) +#endif
drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c +2 -4
@@ -465,10 +465,8 @@ static int arcturus_append_powerplay_table(struct smu_context *smu)if ((smc_dpm_table->table_header.format_revision ==4 ) && (smc_dpm_table->table_header.content_revision ==6 )) -memcpy (&smc_pptable->MaxVoltageStepGfx, - &smc_dpm_table->maxvoltagestepgfx, -sizeof (*smc_dpm_table) - offsetof(struct atom_smc_dpm_info_v4_6 , maxvoltagestepgfx)); - +memcpy_trailing (smc_pptable, MaxVoltageStepGfx, BoardReserved, + smc_dpm_table, maxvoltagestepgfx);return 0 ; }
drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c +4 -4
@@ -431,16 +431,16 @@ static int navi10_append_powerplay_table(struct smu_context *smu)switch (smc_dpm_table->table_header.content_revision) {case 5 :/* nv10 and nv14 */ -memcpy (smc_pptable->I2cControllers, smc_dpm_table->I2cControllers, -sizeof (*smc_dpm_table) -sizeof (smc_dpm_table->table_header)); +memcpy_trailing (smc_pptable, I2cControllers, BoardReserved, + smc_dpm_table, I2cControllers);break ;case 7 :/* nv12 */ ret =amdgpu_atombios_get_data_table (adev, index,NULL ,NULL ,NULL , (uint8_t **)&smc_dpm_table_v4_7);if (ret)return ret; -memcpy (smc_pptable->I2cControllers, smc_dpm_table_v4_7->I2cControllers, -sizeof (*smc_dpm_table_v4_7) -sizeof (smc_dpm_table_v4_7->table_header)); +memcpy_trailing (smc_pptable, I2cControllers, BoardReserved, + smc_dpm_table_v4_7, I2cControllers);break ;default : dev_err(smu->adev->dev, "smc_dpm_info with unsupported content revision %d!\n",
drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c +2 -3
@@ -409,9 +409,8 @@ static int aldebaran_append_powerplay_table(struct smu_context *smu)if ((smc_dpm_table->table_header.format_revision ==4 ) && (smc_dpm_table->table_header.content_revision ==10 )) -memcpy (&smc_pptable->GfxMaxCurrent, - &smc_dpm_table->GfxMaxCurrent, -sizeof (*smc_dpm_table) - offsetof(struct atom_smc_dpm_info_v4_10 , GfxMaxCurrent)); +memcpy_trailing (smc_pptable, GfxMaxCurrent, reserved, + smc_dpm_table, GfxMaxCurrent);return 0 ; }
Signature · 1 line
2.30.2
Quoted 39 lines · Kees Cook
In preparation for
FORTIFY_SOURCEperforming compile-time and run-time field bounds checking formemcpy(),memmove(), andmemset(), avoid intentionally writing across neighboring fields.The "Board Parameters" members of the structs:
struct atom_smc_dpm_info_v4_5 struct atom_smc_dpm_info_v4_6 struct atom_smc_dpm_info_v4_7 struct atom_smc_dpm_info_v4_10are written to the corresponding members of the corresponding
PPTable_tvariables, but they lack destination size bounds checking, which means the compiler cannot verify at compile time that this is an intended and safememcpy().Since the header files are effectively immutable[1] and a
struct_group()cannot be used, nor a common struct referenced by both sides of thememcpy()arguments, add a new helper,memcpy_trailing(), to perform the bounds checking at compile time. Replace the open-coded memcpy()s withmemcpy_trailing()which includes enough context for the bounds checking."objdump -d" shows no object code changes.
[1] https://lore.kernel.org/lkml/[email protected]
Cc Lijo Lazar <[email protected]>Cc "Christian König" <[email protected]>Cc "Pan, Xinhui" <[email protected]>Cc David Airlie <[email protected]>Cc Daniel Vetter <[email protected]>Cc Hawking Zhang <[email protected]>Cc Feifei Xu <[email protected]>Cc Likun Gao <[email protected]>Cc Jiawei Gu <[email protected]>Cc Evan Quan <[email protected]>Signed-off-by Kees Cook <[email protected]>
Quoted 3 lines
---
Alex, I dropped your prior Acked-by, since the implementation is very different. If you're still happy with it, I can add it back. :)
This looks reasonable to me:
Quoted 102 lines
--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 25 +++++++++++++++++++ .../gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c | 6 ++--- .../gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c | 8 +++--- .../drm/amd/pm/swsmu/smu13/aldebaran_ppt.c | 5 ++-- 4 files changed, 33 insertions(+), 11 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +25
-0@@ -1446,4 +1446,29 @@ static inline int amdgpu_in_reset(struct amdgpu_device *adev) {return atomic_read (&adev->in_gpu_reset); } + +/** +* memcpy_trailing - Copy the end of one structure into the middle of another +* +* @dst: Pointer to destination struct +* @first_dst_member: The member name in @dst where the overwrite begins +* @last_dst_member: The member name in @dst where the overwrite ends after +* @src: Pointer to the source struct +* @first_src_member: The member name in @src where the copy begins +* +*/ +#define memcpy_trailing (dst, first_dst_member, last_dst_member, \ + src, first_src_member) \ +({ \ + size_t __src_offset = offsetof(typeof(*(src)), first_src_member); \ + size_t __src_size = sizeof(*(src)) - __src_offset; \ + size_t __dst_offset = offsetof(typeof(*(dst)), first_dst_member); \ + size_t __dst_size = offsetofend(typeof(*(dst)), last_dst_member) - \ + __dst_offset; \ + BUILD_BUG_ON(__src_size != __dst_size); \ + __builtin_memcpy((u8 *)(dst) + __dst_offset, \ + (u8 *)(src) + __src_offset, \ + __dst_size); \ +}) +#endif drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c +2
-4@@ -465,10 +465,8 @@ static int arcturus_append_powerplay_table(struct smu_context *smu)if ((smc_dpm_table->table_header.format_revision ==4 ) && (smc_dpm_table->table_header.content_revision ==6 )) -memcpy (&smc_pptable->MaxVoltageStepGfx, - &smc_dpm_table->maxvoltagestepgfx, -sizeof (*smc_dpm_table) - offsetof(struct atom_smc_dpm_info_v4_6 , maxvoltagestepgfx)); - +memcpy_trailing (smc_pptable, MaxVoltageStepGfx, BoardReserved, + smc_dpm_table, maxvoltagestepgfx);return 0 ; }drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c +4
-4@@ -431,16 +431,16 @@ static int navi10_append_powerplay_table(struct smu_context *smu)switch (smc_dpm_table->table_header.content_revision) {case 5 :/* nv10 and nv14 */ -memcpy (smc_pptable->I2cControllers, smc_dpm_table->I2cControllers, -sizeof (*smc_dpm_table) -sizeof (smc_dpm_table->table_header)); +memcpy_trailing (smc_pptable, I2cControllers, BoardReserved, + smc_dpm_table, I2cControllers);break ;case 7 :/* nv12 */ ret =amdgpu_atombios_get_data_table (adev, index,NULL ,NULL ,NULL , (uint8_t **)&smc_dpm_table_v4_7);if (ret)return ret; -memcpy (smc_pptable->I2cControllers, smc_dpm_table_v4_7->I2cControllers, -sizeof (*smc_dpm_table_v4_7) -sizeof (smc_dpm_table_v4_7->table_header)); +memcpy_trailing (smc_pptable, I2cControllers, BoardReserved, + smc_dpm_table_v4_7, I2cControllers);break ;default : dev_err(smu->adev->dev, "smc_dpm_info with unsupported content revision %d!\n",drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c +2
-4@@ -409,9 +409,8 @@ static int aldebaran_append_powerplay_table(struct smu_context *smu)if ((smc_dpm_table->table_header.format_revision ==4 ) && (smc_dpm_table->table_header.content_revision ==10 )) -memcpy (&smc_pptable->GfxMaxCurrent, - &smc_dpm_table->GfxMaxCurrent, -sizeof (*smc_dpm_table) - offsetof(struct atom_smc_dpm_info_v4_10 , GfxMaxCurrent)); +memcpy_trailing (smc_pptable, GfxMaxCurrent, reserved, + smc_dpm_table, GfxMaxCurrent);return 0 ; } --2.30.2
Thanks Kees!
Thanks,
Lijo
Quoted 141 lines · Kees Cook
In preparation for
FORTIFY_SOURCEperforming compile-time and run-time field bounds checking formemcpy(),memmove(), andmemset(), avoid intentionally writing across neighboring fields.The "Board Parameters" members of the structs:
struct atom_smc_dpm_info_v4_5 struct atom_smc_dpm_info_v4_6 struct atom_smc_dpm_info_v4_7 struct atom_smc_dpm_info_v4_10are written to the corresponding members of the corresponding
PPTable_tvariables, but they lack destination size bounds checking, which means the compiler cannot verify at compile time that this is an intended and safememcpy().Since the header files are effectively immutable[1] and a
struct_group()cannot be used, nor a common struct referenced by both sides of thememcpy()arguments, add a new helper,memcpy_trailing(), to perform the bounds checking at compile time. Replace the open-coded memcpy()s withmemcpy_trailing()which includes enough context for the bounds checking."objdump -d" shows no object code changes.
Cc Lijo Lazar <[email protected]>Cc "Christian König" <[email protected]>Cc "Pan, Xinhui" <[email protected]>Cc David Airlie <[email protected]>Cc Daniel Vetter <[email protected]>Cc Hawking Zhang <[email protected]>Cc Feifei Xu <[email protected]>Cc Likun Gao <[email protected]>Cc Jiawei Gu <[email protected]>Cc Evan Quan <[email protected]>Signed-off-by Kees Cook <[email protected]>---
Alex, I dropped your prior Acked-by, since the implementation is very different. If you're still happy with it, I can add it back. :)--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 25 +++++++++++++++++++ .../gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c | 6 ++--- .../gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c | 8 +++--- .../drm/amd/pm/swsmu/smu13/aldebaran_ppt.c | 5 ++-- 4 files changed, 33 insertions(+), 11 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +25
-0@@ -1446,4 +1446,29 @@ static inline int amdgpu_in_reset(struct amdgpu_device *adev) {return atomic_read (&adev->in_gpu_reset); } + +/** +* memcpy_trailing - Copy the end of one structure into the middle of another +* +* @dst: Pointer to destination struct +* @first_dst_member: The member name in @dst where the overwrite begins +* @last_dst_member: The member name in @dst where the overwrite ends after +* @src: Pointer to the source struct +* @first_src_member: The member name in @src where the copy begins +* +*/ +#define memcpy_trailing (dst, first_dst_member, last_dst_member, \ + src, first_src_member) \ +({ \ + size_t __src_offset = offsetof(typeof(*(src)), first_src_member); \ + size_t __src_size = sizeof(*(src)) - __src_offset; \ + size_t __dst_offset = offsetof(typeof(*(dst)), first_dst_member); \ + size_t __dst_size = offsetofend(typeof(*(dst)), last_dst_member) - \ + __dst_offset; \ + BUILD_BUG_ON(__src_size != __dst_size); \ + __builtin_memcpy((u8 *)(dst) + __dst_offset, \ + (u8 *)(src) + __src_offset, \ + __dst_size); \ +}) +#endif drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c +2
-4@@ -465,10 +465,8 @@ static int arcturus_append_powerplay_table(struct smu_context *smu)if ((smc_dpm_table->table_header.format_revision ==4 ) && (smc_dpm_table->table_header.content_revision ==6 )) -memcpy (&smc_pptable->MaxVoltageStepGfx, - &smc_dpm_table->maxvoltagestepgfx, -sizeof (*smc_dpm_table) - offsetof(struct atom_smc_dpm_info_v4_6 , maxvoltagestepgfx)); - +memcpy_trailing (smc_pptable, MaxVoltageStepGfx, BoardReserved, + smc_dpm_table, maxvoltagestepgfx);return 0 ; }drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c +4
-4@@ -431,16 +431,16 @@ static int navi10_append_powerplay_table(struct smu_context *smu)switch (smc_dpm_table->table_header.content_revision) {case 5 :/* nv10 and nv14 */ -memcpy (smc_pptable->I2cControllers, smc_dpm_table->I2cControllers, -sizeof (*smc_dpm_table) -sizeof (smc_dpm_table->table_header)); +memcpy_trailing (smc_pptable, I2cControllers, BoardReserved, + smc_dpm_table, I2cControllers);break ;case 7 :/* nv12 */ ret =amdgpu_atombios_get_data_table (adev, index,NULL ,NULL ,NULL , (uint8_t **)&smc_dpm_table_v4_7);if (ret)return ret; -memcpy (smc_pptable->I2cControllers, smc_dpm_table_v4_7->I2cControllers, -sizeof (*smc_dpm_table_v4_7) -sizeof (smc_dpm_table_v4_7->table_header)); +memcpy_trailing (smc_pptable, I2cControllers, BoardReserved, + smc_dpm_table_v4_7, I2cControllers);break ;default : dev_err(smu->adev->dev, "smc_dpm_info with unsupported content revision %d!\n",drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c +2
-3@@ -409,9 +409,8 @@ static int aldebaran_append_powerplay_table(struct smu_context *smu)if ((smc_dpm_table->table_header.format_revision ==4 ) && (smc_dpm_table->table_header.content_revision ==10 )) -memcpy (&smc_pptable->GfxMaxCurrent, - &smc_dpm_table->GfxMaxCurrent, -sizeof (*smc_dpm_table) - offsetof(struct atom_smc_dpm_info_v4_10 , GfxMaxCurrent)); +memcpy_trailing (smc_pptable, GfxMaxCurrent, reserved, + smc_dpm_table, GfxMaxCurrent);return 0 ; }
Christian König
maintainerAm 19.08.21 um 22:14 schrieb Kees Cook:
Quoted 59 lines
In preparation for
FORTIFY_SOURCEperforming compile-time and run-time field bounds checking formemcpy(),memmove(), andmemset(), avoid intentionally writing across neighboring fields.The "Board Parameters" members of the structs:
struct atom_smc_dpm_info_v4_5 struct atom_smc_dpm_info_v4_6 struct atom_smc_dpm_info_v4_7 struct atom_smc_dpm_info_v4_10are written to the corresponding members of the corresponding
PPTable_tvariables, but they lack destination size bounds checking, which means the compiler cannot verify at compile time that this is an intended and safememcpy().Since the header files are effectively immutable[1] and a
struct_group()cannot be used, nor a common struct referenced by both sides of thememcpy()arguments, add a new helper,memcpy_trailing(), to perform the bounds checking at compile time. Replace the open-coded memcpy()s withmemcpy_trailing()which includes enough context for the bounds checking."objdump -d" shows no object code changes.
Cc Lijo Lazar <[email protected]>Cc "Christian König" <[email protected]>Cc "Pan, Xinhui" <[email protected]>Cc David Airlie <[email protected]>Cc Daniel Vetter <[email protected]>Cc Hawking Zhang <[email protected]>Cc Feifei Xu <[email protected]>Cc Likun Gao <[email protected]>Cc Jiawei Gu <[email protected]>Cc Evan Quan <[email protected]>Signed-off-by Kees Cook <[email protected]>---
Alex, I dropped your prior Acked-by, since the implementation is very different. If you're still happy with it, I can add it back. :)--- drivers/gpu/drm/amd/amdgpu/amdgpu.h | 25 +++++++++++++++++++ .../gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c | 6 ++--- .../gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c | 8 +++--- .../drm/amd/pm/swsmu/smu13/aldebaran_ppt.c | 5 ++-- 4 files changed, 33 insertions(+), 11 deletions(-)drivers/gpu/drm/amd/amdgpu/amdgpu.h +3
-0@@ -1446,4 +1446,29 @@ static inline int amdgpu_in_reset(struct amdgpu_device *adev) {return atomic_read (&adev->in_gpu_reset); } + +/** +* memcpy_trailing - Copy the end of one structure into the middle of another
drivers/gpu/drm/amd/amdgpu/amdgpu.h static inline int amdgpu_in_reset(struct amdgpu_device *adev) · line 1461
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +10
-0+* +* @dst: Pointer to destination struct +* @first_dst_member: The member name in @dst where the overwrite begins +* @last_dst_member: The member name in @dst where the overwrite ends after +* @src: Pointer to the source struct +* @first_src_member: The member name in @src where the copy begins +* +*/ +#define memcpy_trailing (dst, first_dst_member, last_dst_member, \ + src, first_src_member) \
Please don't add a function like this into amdgpu.h, especially when it is only used by the SMU code.
And please give it an amdgpu_ prefix so that we are not confusing it with a core function.
Apart from that looks good to me.
Thanks,
Christian.
Quoted 71 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +12
-0+({ \ +size_t __src_offset = offsetof(typeof (*(src )), first_src_member); \ +size_t __src_size =sizeof (*(src)) - __src_offset; \ +size_t __dst_offset = offsetof(typeof (*(dst )), first_dst_member); \ +size_t __dst_size =offsetofend (typeof (*(dst)), last_dst_member) - \ + __dst_offset; \ +BUILD_BUG_ON (__src_size != __dst_size); \ +__builtin_memcpy ((u8 *)(dst) + __dst_offset, \ + (u8 *)(src) + __src_offset, \ + __dst_size); \ +}) +#endif drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c +2
-4@@ -465,10 +465,8 @@ static int arcturus_append_powerplay_table(struct smu_context *smu)if ((smc_dpm_table->table_header.format_revision ==4 ) && (smc_dpm_table->table_header.content_revision ==6 )) -memcpy (&smc_pptable->MaxVoltageStepGfx, - &smc_dpm_table->maxvoltagestepgfx, -sizeof (*smc_dpm_table) - offsetof(struct atom_smc_dpm_info_v4_6 , maxvoltagestepgfx)); - +memcpy_trailing (smc_pptable, MaxVoltageStepGfx, BoardReserved, + smc_dpm_table, maxvoltagestepgfx);return 0 ; }drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c +4
-4@@ -431,16 +431,16 @@ static int navi10_append_powerplay_table(struct smu_context *smu)switch (smc_dpm_table->table_header.content_revision) {case 5 :/* nv10 and nv14 */ -memcpy (smc_pptable->I2cControllers, smc_dpm_table->I2cControllers, -sizeof (*smc_dpm_table) -sizeof (smc_dpm_table->table_header)); +memcpy_trailing (smc_pptable, I2cControllers, BoardReserved, + smc_dpm_table, I2cControllers);break ;case 7 :/* nv12 */ ret =amdgpu_atombios_get_data_table (adev, index,NULL ,NULL ,NULL , (uint8_t **)&smc_dpm_table_v4_7);if (ret)return ret; -memcpy (smc_pptable->I2cControllers, smc_dpm_table_v4_7->I2cControllers, -sizeof (*smc_dpm_table_v4_7) -sizeof (smc_dpm_table_v4_7->table_header)); +memcpy_trailing (smc_pptable, I2cControllers, BoardReserved, + smc_dpm_table_v4_7, I2cControllers);break ;default : dev_err(smu->adev->dev, "smc_dpm_info with unsupported content revision %d!\n",drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c +2
-3@@ -409,9 +409,8 @@ static int aldebaran_append_powerplay_table(struct smu_context *smu)if ((smc_dpm_table->table_header.format_revision ==4 ) && (smc_dpm_table->table_header.content_revision ==10 )) -memcpy (&smc_pptable->GfxMaxCurrent, - &smc_dpm_table->GfxMaxCurrent, -sizeof (*smc_dpm_table) - offsetof(struct atom_smc_dpm_info_v4_10 , GfxMaxCurrent)); +memcpy_trailing (smc_pptable, GfxMaxCurrent, reserved, + smc_dpm_table, GfxMaxCurrent);return 0 ; }
Quoted 20 lines · Christian König
Am 19.08.21 um 22:14 schrieb Kees Cook:
Quoted 17 lines
[...]
drivers/gpu/drm/amd/amdgpu/amdgpu.h +8
-0@@ -1446,4 +1446,29 @@ static inline int amdgpu_in_reset(struct amdgpu_device *adev) {return atomic_read (&adev->in_gpu_reset); } + +/** +* memcpy_trailing - Copy the end of one structure into the middle of another +* +* @dst: Pointer to destination struct +* @first_dst_member: The member name in @dst where the overwrite begins +* @last_dst_member: The member name in @dst where the overwrite ends after +* @src: Pointer to the source struct
Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h static inline int amdgpu_in_reset(struct amdgpu_device *adev) · line 1461
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +5
-0+* @first_src_member: The member name in @src where the copy begins +* +*/ +#define memcpy_trailing (dst, first_dst_member, last_dst_member, \ + src, first_src_member) \Please don't add a function like this into
amdgpu.h, especially when it is only used by the SMU code.
Sure, I'm happy to move it. It wasn't clear to me which headers were considered "immutable". Which header should I put this in?
Quoted 2 lines
And please give it an
amdgpu_prefix so that we are not confusing it with a core function.
Sure, I will include that.
Quoted 1 line
Apart from that looks good to me.
Thanks!
-Kees
Christian König
maintainerAm 23.08.21 um 16:23 schrieb Kees Cook:
Quoted 28 lines · Christian König
Quoted 18 lines
Am 19.08.21 um 22:14 schrieb Kees Cook:
Quoted 16 lines
[...]
drivers/gpu/drm/amd/amdgpu/amdgpu.h +7
-0@@ -1446,4 +1446,29 @@ static inline int amdgpu_in_reset(struct amdgpu_device *adev) {return atomic_read (&adev->in_gpu_reset); } + +/** +* memcpy_trailing - Copy the end of one structure into the middle of another +* +* @dst: Pointer to destination struct +* @first_dst_member: The member name in @dst where the overwrite begins +* @last_dst_member: The member name in @dst where the overwrite ends after Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h static inline int amdgpu_in_reset(struct amdgpu_device *adev) · line 1461
Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +6
-0+* @src: Pointer to the source struct +* @first_src_member: The member name in @src where the copy begins +* +*/ +#define memcpy_trailing (dst, first_dst_member, last_dst_member, \ + src, first_src_member) \Please don't add a function like this into
amdgpu.h, especially when it is only used by the SMU code.
Quoted 1 line
Sure, I'm happy to move it. It wasn't clear to me which headers were considered "immutable". Which header should I put this in?
I think amdgpu_smuio.h, but I'm not 100% sure. Alex do you have a better idea?
We don't want to put anything new into amdgpu.h any more since this is basically only a legacy leftover.
Thanks,
Christian.
Quoted 9 lines
Quoted 3 lines
And please give it an
amdgpu_prefix so that we are not confusing it with a core function.Sure, I will include that.
Quoted 1 line
Apart from that looks good to me.
Thanks!
-Kees
Deucher, Alexander
maintainer[Public]
Quoted 59 lines
-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Monday, August 23, 2021 3:02 PM
To: Kees Cook <[email protected]>; Lazar, Lijo <[email protected]>
Cc: Pan, Xinhui <[email protected]>; David Airlie <[email protected]>; Daniel Vetter <[email protected]>; Zhang, Hawking <[email protected]>; Xu, Feifei <[email protected]>; Gao, Likun <[email protected]>; Gu, JiaWei (Will) <[email protected]>; Quan, Evan <[email protected]>; [email protected]; dri- [email protected]; Deucher, Alexander <[email protected]>; Tuikov, Luben <[email protected]>; Grodzovsky, Andrey <[email protected]>; Li, Dennis <[email protected]>; Sundararaju, Sathishkumar <[email protected]>; Kim, Jonathan <[email protected]>; Wang, Kevin(Yang) <[email protected]>; Nieto, David M <[email protected]>; Feng, Kenneth <[email protected]>; Lee Jones <[email protected]>; Clements, John <[email protected]>; [email protected]; [email protected]
Subject: Re: [PATCH] drm/amd/pm: And destination bounds checking to struct copyAm 23.08.21 um 16:23 schrieb Kees Cook:
Quoted 2 lines
On August 22, 2021 11:28:54 PM PDT, "Christian König"
Quoted 9 lines · <[email protected]> wrote:
Quoted 9 lines
Am 19.08.21 um 22:14 schrieb Kees Cook:
drivers/gpu/drm/amd/amdgpu/amdgpu.h static inline int amdgpu_in_reset(struct
Quoted 7 lines
[...]
drivers/gpu/drm/amd/amdgpu/amdgpu.h +0
-0@@ -1446,4 +1446,29 @@ static inline int amdgpu_in_reset(struct
amdgpu_device*adev)Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h static inline int amdgpu_in_reset(struct amdgpu_device *adev)
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +7
-0{return atomic_read (&adev->in_gpu_reset); } + +/** +* memcpy_trailing - Copy the end of one structure into the middle +of another +* +* @dst: Pointer to destination struct +* @first_dst_member: The member name in @dst where the overwrite
Quoted 2 lines
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h static inline int amdgpu_in_reset(struct · line 1457
Quoted 2 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +2
-0+begins + * @last_dst_member: The member name in @dst where theoverwrite
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h static inline int amdgpu_in_reset(struct · line 1460
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3
-0+ends after + * @src: Pointer to the source struct + * @first_src_member: The member name in @src where the copybegins
Quoted 3 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h static inline int amdgpu_in_reset(struct amdgpu_device *adev)
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h +3
-0+* +*/ +#define memcpy_trailing(dst, first_dst_member, last_dst_member,\
Quoted 9 lines
Quoted 4 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu.h static inline int amdgpu_in_reset(struct amdgpu_device *adev) · line 1461
Quoted 1 line
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1
-0+ src, first_src_member) \Please don't add a function like this into
amdgpu.h, especially when it is only used by the SMU code.Sure, I'm happy to move it. It wasn't clear to me which headers were
considered "immutable". Which header should I put this in?
I think
amdgpu_smuio.h, but I'm not 100% sure. Alex do you have a better idea?
No, that's for the SMUIO callbacks for the IP block. Please use drivers/gpu/drm/amd/pm/inc/amdgpu_smu.h
Alex
Quoted 15 lines
We don't want to put anything new into
amdgpu.hany more since this is basically only a legacy leftover.Thanks,
Christian.Quoted 9 lines
Quoted 3 lines
And please give it an
amdgpu_prefix so that we are not confusing it with a core function.Sure, I will include that.
Quoted 1 line
Apart from that looks good to me.
Thanks!
-Kees