Skip to contentSkip to conversation

Fix unintentional integer overflow

PATCH-next Advait Dhamorikar 6 participants 9 messages Oct 4, 2024 – Oct 8, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Fix shift-count-overflow when creating mask.
The expression's value may not be what the
programmer intended, because the expression is
evaluated using a narrower integer type.

Fixes f0b19b84d391 ("drm/amdgpu: add amdgpu_jpeg_sched_mask debugfs")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1 -1
index 95e2796919fc..7df402c45f40 100644
@@ -388,7 +388,7 @@ static int amdgpu_debugfs_jpeg_sched_mask_get(void *data, u64 *val)
 		for (j = 0; j < adev->jpeg.num_jpeg_rings; ++j) {
 			ring = &adev->jpeg.inst[i].ring_dec[j];
 			if (ring->sched.ready)
-				mask |= 1 << ((i * adev->jpeg.num_jpeg_rings) + j);
+				mask |= (u64)1 << ((i * adev->jpeg.num_jpeg_rings) + j);
 		}
 	}
 	*val = mask;
Signature · 1 line
2.34.1
#1 lore raw

All occurrences of this error fix should have been together in a single patch both in _get and _set callbacks corresponding to f0b19b84d391, please avoid separate patch for each occurrence.

Sorry Alex, I missed to note this yesterday.

Regards,
Sathish

Quoted 24 lines · Advait Dhamorikar

Fix shift-count-overflow when creating mask. The expression's value may not be what the programmer intended, because the expression is evaluated using a narrower integer type.

Fixes f0b19b84d391 ("drm/amdgpu: add amdgpu_jpeg_sched_mask debugfs")
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1 -1
index 95e2796919fc..7df402c45f40 100644
@@ -388,7 +388,7 @@ static int amdgpu_debugfs_jpeg_sched_mask_get(void *data, u64 *val)
  		for (j = 0; j < adev->jpeg.num_jpeg_rings; ++j) {
  			ring = &adev->jpeg.inst[i].ring_dec[j];
  			if (ring->sched.ready)
-				mask |= 1 << ((i * adev->jpeg.num_jpeg_rings) + j);
+				mask |= (u64)1 << ((i * adev->jpeg.num_jpeg_rings) + j);
  		}
  	}
  	*val = mask;
#2 lore raw
Quoted 8 lines · Sathishkumar

All occurrences of this error fix should have been together in a single patch both in _get and _set callbacks corresponding to f0b19b84d391, please avoid separate patch for each occurrence.

Sorry Alex, I missed to note this yesterday.

Regards,
Sathish

Sathish,

Please don't post on top when responding to kernel emails and patches. It makes it difficult to follow the discussions

Quoted 14 lines · Advait Dhamorikar
Quoted 11 lines

Fix shift-count-overflow when creating mask. The expression's value may not be what the programmer intended, because the expression is evaluated using a narrower integer type.

Fixes f0b19b84d391 ("drm/amdgpu: add amdgpu_jpeg_sched_mask debugfs")
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 13 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c static int amdgpu_debugfs_jpeg_sched_mask_get(void *data, u64 *val) · line 394

Quoted 13 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1 -1
index 95e2796919fc..7df402c45f40 100644
@@ -388,7 +388,7 @@ static int amdgpu_debugfs_jpeg_sched_mask_get(void *data, u64 *val)
  		for (j = 0; j < adev->jpeg.num_jpeg_rings; ++j) {
  			ring = &adev->jpeg.inst[i].ring_dec[j];
  			if (ring->sched.ready)
-				mask |= 1 << ((i * adev->jpeg.num_jpeg_rings) + j);
+				mask |= (u64)1 << ((i * adev->jpeg.num_jpeg_rings) + j);
  		}
  	}
  	*val = mask;

thanks,
-- Shuah

#3 lore raw
In reply to Sundararaju, Sathishkumar
Quoted 5 lines · Sathishkumar

All occurrences of this error fix should have been together in a single patch both in _get and _set callbacks corresponding to f0b19b84d391, please avoid separate patch for each occurrence.

Sorry Alex, I missed to note this yesterday.

I've dropped the patch. Please pick it up once it's fixed up appropriately.

Thanks,

Alex

Quoted 32 lines

Regards,
Sathish

On 10/4/2024 1:46 PM, Advait Dhamorikar wrote:

Fix shift-count-overflow when creating mask.
The expression's value may not be what the
programmer intended, because the expression is
evaluated using a narrower integer type.

Fixes f0b19b84d391 ("drm/amdgpu: add amdgpu_jpeg_sched_mask debugfs")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1 -1
index 95e2796919fc..7df402c45f40 100644
@@ -388,7 +388,7 @@ static int amdgpu_debugfs_jpeg_sched_mask_get(void *data, u64 *val)
  for (j = 0; j < adev->jpeg.num_jpeg_rings; ++j) {
  ring = &adev->jpeg.inst[i].ring_dec[j];
  if (ring->sched.ready)
- mask |= 1 << ((i * adev->jpeg.num_jpeg_rings) + j);
+ mask |= (u64)1 << ((i * adev->jpeg.num_jpeg_rings) + j);
  }
  }
  *val = mask;
#4 lore raw
Quoted 7 lines · Alex Deucher
Quoted 4 lines · Sathishkumar

All occurrences of this error fix should have been together in a single patch both in _get and _set callbacks corresponding to f0b19b84d391, please avoid separate patch for each occurrence.

Sorry Alex, I missed to note this yesterday.

I've dropped the patch. Please pick it up once it's fixed up appropriately.

Thanks Alex.

Hi Advait,
Please collate the changes together with Lijo's suggestion as well, "1ULL <<" instead of typecast, there are 3 occurrences of the error in f0b19b84d391.

Regards,
Sathish

Quoted 36 lines

Thanks,

Alex

Quoted 31 lines

Regards,
Sathish

On 10/4/2024 1:46 PM, Advait Dhamorikar wrote:

Fix shift-count-overflow when creating mask.
The expression's value may not be what the
programmer intended, because the expression is
evaluated using a narrower integer type.

Fixes f0b19b84d391 ("drm/amdgpu: add amdgpu_jpeg_sched_mask debugfs")
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1 -1
index 95e2796919fc..7df402c45f40 100644
@@ -388,7 +388,7 @@ static int amdgpu_debugfs_jpeg_sched_mask_get(void *data, u64 *val)
   for (j = 0; j < adev->jpeg.num_jpeg_rings; ++j) {
   ring = &adev->jpeg.inst[i].ring_dec[j];
   if (ring->sched.ready)
- mask |= 1 << ((i * adev->jpeg.num_jpeg_rings) + j);
+ mask |= (u64)1 << ((i * adev->jpeg.num_jpeg_rings) + j);
   }
   }
   *val = mask;
#5 lore raw

Hi Sathish,

Quoted 3 lines

Please collate the changes together with Lijo's suggestion as well, "1ULL <<" instead of typecast, there are 3 occurrences of the error in f0b19b84d391.

I could only observe two instances of this error in f0b19b84d391 at:
'mask = (1 << (adev->jpeg.num_jpeg_inst * adev->jpeg.num_jpeg_rings)) - 1; and mask |= 1 << ((i * adev->jpeg.num_jpeg_rings) + j);`

There are a few instances where we can use 1U instead of int as harvest_config uses unsigned int (adev->jpeg.harvest_config & (1 << i)
However I think they should be fixed in a separate patch?

Thanks and regards,
Advait

Quoted 57 lines · Sathishkumar
Quoted 7 lines · Alex Deucher
Quoted 4 lines · Sathishkumar

All occurrences of this error fix should have been together in a single patch both in _get and _set callbacks corresponding to f0b19b84d391, please avoid separate patch for each occurrence.

Sorry Alex, I missed to note this yesterday.

I've dropped the patch. Please pick it up once it's fixed up appropriately.

Thanks Alex.

Hi Advait,
Please collate the changes together with Lijo's suggestion as well, "1ULL <<" instead of typecast, there are 3 occurrences of the error in f0b19b84d391.

Regards,
Sathish

Quoted 36 lines

Thanks,

Alex

Quoted 31 lines

Regards,
Sathish

On 10/4/2024 1:46 PM, Advait Dhamorikar wrote:

Fix shift-count-overflow when creating mask.
The expression's value may not be what the
programmer intended, because the expression is
evaluated using a narrower integer type.

Fixes f0b19b84d391 ("drm/amdgpu: add amdgpu_jpeg_sched_mask debugfs")
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1 -1
index 95e2796919fc..7df402c45f40 100644
@@ -388,7 +388,7 @@ static int amdgpu_debugfs_jpeg_sched_mask_get(void *data, u64 *val)
   for (j = 0; j < adev->jpeg.num_jpeg_rings; ++j) {
   ring = &adev->jpeg.inst[i].ring_dec[j];
   if (ring->sched.ready)
- mask |= 1 << ((i * adev->jpeg.num_jpeg_rings) + j);
+ mask |= (u64)1 << ((i * adev->jpeg.num_jpeg_rings) + j);
   }
   }
   *val = mask;
#6 lore raw

Am 05.10.24 um 09:05 schrieb Advait Dhamorikar:

Quoted 5 lines

Hi Sathish,

Quoted 3 lines

Please collate the changes together with Lijo's suggestion as well, "1ULL <<" instead of typecast, there are 3 occurrences of the error in f0b19b84d391.

Quoted 8 lines

I could only observe two instances of this error in f0b19b84d391 at:
'mask = (1 << (adev->jpeg.num_jpeg_inst * adev->jpeg.num_jpeg_rings)) - 1; and mask |= 1 << ((i * adev->jpeg.num_jpeg_rings) + j);`

There are a few instances where we can use 1U instead of int as harvest_config uses unsigned int (adev->jpeg.harvest_config & (1 << i)
However I think they should be fixed in a separate patch?

No, all of this are numerical problems where not taken into account the size of the destination type.

Saying that all of that are basically just style cleanups which doesn't need to be back-ported in any way, so please drop the Fixes: tag.

And you should probably change the subject line to something like "drm/amdgpu: cleanup shift coding style".

Regards,
Christian.

Quoted 57 lines

Thanks and regards,
Advait

Quoted 52 lines · Sathishkumar
Quoted 6 lines · Alex Deucher
Quoted 3 lines · Sathishkumar

All occurrences of this error fix should have been together in a single patch both in _get and _set callbacks corresponding to f0b19b84d391, please avoid separate patch for each occurrence.

Sorry Alex, I missed to note this yesterday.

I've dropped the patch. Please pick it up once it's fixed up appropriately.

Thanks Alex.

Hi Advait,
Please collate the changes together with Lijo's suggestion as well, "1ULL <<" instead of typecast, there are 3 occurrences of the error in f0b19b84d391.

Regards,
Sathish

Quoted 34 lines

Thanks,

Alex

Quoted 30 lines

Regards,
Sathish

On 10/4/2024 1:46 PM, Advait Dhamorikar wrote:

Fix shift-count-overflow when creating mask.
The expression's value may not be what the
programmer intended, because the expression is
evaluated using a narrower integer type.

Fixes f0b19b84d391 ("drm/amdgpu: add amdgpu_jpeg_sched_mask debugfs")
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1 -1
index 95e2796919fc..7df402c45f40 100644
@@ -388,7 +388,7 @@ static int amdgpu_debugfs_jpeg_sched_mask_get(void *data, u64 *val)
    for (j = 0; j < adev->jpeg.num_jpeg_rings; ++j) {
    ring = &adev->jpeg.inst[i].ring_dec[j];
    if (ring->sched.ready)
- mask |= 1 << ((i * adev->jpeg.num_jpeg_rings) + j);
+ mask |= (u64)1 << ((i * adev->jpeg.num_jpeg_rings) + j);
    }
    }
    *val = mask;
#7 lore raw

Hi Christian,

I am not sure if I correctly understood what you meant, just to clarify

When you say this

Quoted 8 lines

No, all of this are numerical problems where not taken into account the size of the destination type.

Saying that all of that are basically just style cleanups which doesn't need to be back-ported in any way, so please drop the Fixes: tag.

And you should probably change the subject line to something like "drm/amdgpu: cleanup shift coding style".

Are you just talking about this message?

Quoted 4 lines
Quoted 4 lines

There are a few instances where we can use 1U instead of int as harvest_config uses unsigned int (adev->jpeg.harvest_config & (1 << i)
However I think they should be fixed in a separate patch?

Or is it intended for the complete previous "Fix unintentional overflow" patch as well?
And I should just send a v3 with the two changes?

Thanks and regards,
Advait

Quoted 86 lines · Christian König

Am 05.10.24 um 09:05 schrieb Advait Dhamorikar:

Quoted 5 lines

Hi Sathish,

Quoted 3 lines

Please collate the changes together with Lijo's suggestion as well, "1ULL <<" instead of typecast, there are 3 occurrences of the error in f0b19b84d391.

Quoted 8 lines

I could only observe two instances of this error in f0b19b84d391 at:
'mask = (1 << (adev->jpeg.num_jpeg_inst * adev->jpeg.num_jpeg_rings)) - 1; and mask |= 1 << ((i * adev->jpeg.num_jpeg_rings) + j);`

There are a few instances where we can use 1U instead of int as harvest_config uses unsigned int (adev->jpeg.harvest_config & (1 << i)
However I think they should be fixed in a separate patch?

No, all of this are numerical problems where not taken into account the size of the destination type.

Saying that all of that are basically just style cleanups which doesn't need to be back-ported in any way, so please drop the Fixes: tag.

And you should probably change the subject line to something like "drm/amdgpu: cleanup shift coding style".

Regards,
Christian.

Quoted 57 lines

Thanks and regards,
Advait

Quoted 52 lines · Sathishkumar
Quoted 6 lines · Alex Deucher
Quoted 3 lines · Sathishkumar

All occurrences of this error fix should have been together in a single patch both in _get and _set callbacks corresponding to f0b19b84d391, please avoid separate patch for each occurrence.

Sorry Alex, I missed to note this yesterday.

I've dropped the patch. Please pick it up once it's fixed up appropriately.

Thanks Alex.

Hi Advait,
Please collate the changes together with Lijo's suggestion as well, "1ULL <<" instead of typecast, there are 3 occurrences of the error in f0b19b84d391.

Regards,
Sathish

Quoted 34 lines

Thanks,

Alex

Quoted 30 lines

Regards,
Sathish

On 10/4/2024 1:46 PM, Advait Dhamorikar wrote:

Fix shift-count-overflow when creating mask.
The expression's value may not be what the
programmer intended, because the expression is
evaluated using a narrower integer type.

Fixes f0b19b84d391 ("drm/amdgpu: add amdgpu_jpeg_sched_mask debugfs")
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 2 +-
   1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1 -1
index 95e2796919fc..7df402c45f40 100644
@@ -388,7 +388,7 @@ static int amdgpu_debugfs_jpeg_sched_mask_get(void *data, u64 *val)
    for (j = 0; j < adev->jpeg.num_jpeg_rings; ++j) {
    ring = &adev->jpeg.inst[i].ring_dec[j];
    if (ring->sched.ready)
- mask |= 1 << ((i * adev->jpeg.num_jpeg_rings) + j);
+ mask |= (u64)1 << ((i * adev->jpeg.num_jpeg_rings) + j);
    }
    }
    *val = mask;
maintainer
#8 lore raw

Am 08.10.24 um 05:38 schrieb Advait Dhamorikar:

Quoted 11 lines

Hi Christian,

I am not sure if I correctly understood what you meant, just to clarify

When you say this

Quoted 6 lines

No, all of this are numerical problems where not taken into account the size of the destination type.
Saying that all of that are basically just style cleanups which doesn't need to be back-ported in any way, so please drop the Fixes: tag. And you should probably change the subject line to something like "drm/amdgpu: cleanup shift coding style".

Quoted 7 lines

Are you just talking about this message?

Quoted 4 lines
Quoted 4 lines

There are a few instances where we can use 1U instead of int as harvest_config uses unsigned int (adev->jpeg.harvest_config & (1 << i)
However I think they should be fixed in a separate patch?

Or is it intended for the complete previous "Fix unintentional overflow" patch as well?

My comment applies to all patches.

Those patches are not really fixing anything because the shift values come from some BIOS table and if I remember correctly for example the harvest config only contains two meaningful bits.

Fixing the warnings is nice to have, but not really necessary for correctness. So the patches shouldn't be back-ported and don't need any Fixes tags.

Regards,
Christian.

Quoted 88 lines

And I should just send a v3 with the two changes?

Thanks and regards,
Advait

Quoted 81 lines · Christian König

Am 05.10.24 um 09:05 schrieb Advait Dhamorikar:

Quoted 5 lines

Hi Sathish,

Quoted 3 lines

Please collate the changes together with Lijo's suggestion as well, "1ULL <<" instead of typecast, there are 3 occurrences of the error in f0b19b84d391.

Quoted 8 lines

I could only observe two instances of this error in f0b19b84d391 at:
'mask = (1 << (adev->jpeg.num_jpeg_inst * adev->jpeg.num_jpeg_rings)) - 1; and mask |= 1 << ((i * adev->jpeg.num_jpeg_rings) + j);`

There are a few instances where we can use 1U instead of int as harvest_config uses unsigned int (adev->jpeg.harvest_config & (1 << i)
However I think they should be fixed in a separate patch?

No, all of this are numerical problems where not taken into account the size of the destination type.

Saying that all of that are basically just style cleanups which doesn't need to be back-ported in any way, so please drop the Fixes: tag.

And you should probably change the subject line to something like "drm/amdgpu: cleanup shift coding style".

Regards,
Christian.

Quoted 55 lines

Thanks and regards,
Advait

Quoted 51 lines · Sathishkumar
Quoted 6 lines · Alex Deucher
Quoted 3 lines · Sathishkumar

All occurrences of this error fix should have been together in a single patch both in _get and _set callbacks corresponding to f0b19b84d391, please avoid separate patch for each occurrence.

Sorry Alex, I missed to note this yesterday.

I've dropped the patch. Please pick it up once it's fixed up appropriately.

Thanks Alex.

Hi Advait,
Please collate the changes together with Lijo's suggestion as well, "1ULL <<" instead of typecast, there are 3 occurrences of the error in f0b19b84d391.

Regards,
Sathish

Quoted 34 lines

Thanks,

Alex

Quoted 30 lines

Regards,
Sathish

On 10/4/2024 1:46 PM, Advait Dhamorikar wrote:

Fix shift-count-overflow when creating mask.
The expression's value may not be what the
programmer intended, because the expression is
evaluated using a narrower integer type.

Fixes f0b19b84d391 ("drm/amdgpu: add amdgpu_jpeg_sched_mask debugfs")
---
    drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c | 2 +-
    1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_jpeg.c +1 -1
index 95e2796919fc..7df402c45f40 100644
@@ -388,7 +388,7 @@ static int amdgpu_debugfs_jpeg_sched_mask_get(void *data, u64 *val)
     for (j = 0; j < adev->jpeg.num_jpeg_rings; ++j) {
     ring = &adev->jpeg.inst[i].ring_dec[j];
     if (ring->sched.ready)
- mask |= 1 << ((i * adev->jpeg.num_jpeg_rings) + j);
+ mask |= (u64)1 << ((i * adev->jpeg.num_jpeg_rings) + j);
     }
     }
     *val = mask;