mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] drm/amdgpu: Fix potential integer overflow in scheduler mask calculations
@ 2024-12-15 12:28 Karol Przybylski
  2024-12-16 18:47 ` Alex Deucher
  0 siblings, 1 reply; 2+ messages in thread
From: Karol Przybylski @ 2024-12-15 12:28 UTC (permalink / raw)
  To: alexander.deucher, christian.koenig, Xinhui.Pan, airlied, simona,
	srinivasan.shanmugam, Hawking.Zhang, Jack.Xiao, lijo.lazar,
	Jesse.zhang, tao.zhou1
  Cc: Karol Przybylski, amd-gfx, dri-devel, linux-kernel

The use of 1 << i in scheduler mask calculations can result in an
unintentional integer overflow due to the expression being
evaluated as a 32-bit signed integer.

This patch replaces 1 << i with 1ULL << i to ensure the operation
is performed as a 64-bit unsigned integer, preventing overflow

Discovered in coverity scan, CID 1636393, 1636175, 1636007, 1635853

Fixes: c5c63d9cb5d3b drm/amdgpu: add amdgpu_gfx_sched_mask and amdgpu_compute_sched_mask debugfs
Signed-off-by: Karol Przybylski <karprzy7@gmail.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
index 69a6b6dba0a5..8fb6c5f6a060 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
@@ -2050,7 +2050,7 @@ static int amdgpu_debugfs_gfx_sched_mask_set(void *data, u64 val)
 	if (!adev)
 		return -ENODEV;
 
-	mask = (1 << adev->gfx.num_gfx_rings) - 1;
+	mask = (1ULL << adev->gfx.num_gfx_rings) - 1;
 	if ((val & mask) == 0)
 		return -EINVAL;
 
@@ -2078,7 +2078,7 @@ static int amdgpu_debugfs_gfx_sched_mask_get(void *data, u64 *val)
 	for (i = 0; i < adev->gfx.num_gfx_rings; ++i) {
 		ring = &adev->gfx.gfx_ring[i];
 		if (ring->sched.ready)
-			mask |= 1 << i;
+			mask |= 1ULL << i;
 	}
 
 	*val = mask;
@@ -2120,7 +2120,7 @@ static int amdgpu_debugfs_compute_sched_mask_set(void *data, u64 val)
 	if (!adev)
 		return -ENODEV;
 
-	mask = (1 << adev->gfx.num_compute_rings) - 1;
+	mask = (1ULL << adev->gfx.num_compute_rings) - 1;
 	if ((val & mask) == 0)
 		return -EINVAL;
 
@@ -2149,7 +2149,7 @@ static int amdgpu_debugfs_compute_sched_mask_get(void *data, u64 *val)
 	for (i = 0; i < adev->gfx.num_compute_rings; ++i) {
 		ring = &adev->gfx.compute_ring[i];
 		if (ring->sched.ready)
-			mask |= 1 << i;
+			mask |= 1ULL << i;
 	}
 
 	*val = mask;
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] drm/amdgpu: Fix potential integer overflow in scheduler mask calculations
  2024-12-15 12:28 [PATCH] drm/amdgpu: Fix potential integer overflow in scheduler mask calculations Karol Przybylski
@ 2024-12-16 18:47 ` Alex Deucher
  0 siblings, 0 replies; 2+ messages in thread
From: Alex Deucher @ 2024-12-16 18:47 UTC (permalink / raw)
  To: Karol Przybylski
  Cc: alexander.deucher, christian.koenig, Xinhui.Pan, airlied, simona,
	srinivasan.shanmugam, Hawking.Zhang, Jack.Xiao, lijo.lazar,
	Jesse.zhang, tao.zhou1, amd-gfx, dri-devel, linux-kernel

Applied.  Thanks!

On Sun, Dec 15, 2024 at 7:38 AM Karol Przybylski <karprzy7@gmail.com> wrote:
>
> The use of 1 << i in scheduler mask calculations can result in an
> unintentional integer overflow due to the expression being
> evaluated as a 32-bit signed integer.
>
> This patch replaces 1 << i with 1ULL << i to ensure the operation
> is performed as a 64-bit unsigned integer, preventing overflow
>
> Discovered in coverity scan, CID 1636393, 1636175, 1636007, 1635853
>
> Fixes: c5c63d9cb5d3b drm/amdgpu: add amdgpu_gfx_sched_mask and amdgpu_compute_sched_mask debugfs
> Signed-off-by: Karol Przybylski <karprzy7@gmail.com>
> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
> index 69a6b6dba0a5..8fb6c5f6a060 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gfx.c
> @@ -2050,7 +2050,7 @@ static int amdgpu_debugfs_gfx_sched_mask_set(void *data, u64 val)
>         if (!adev)
>                 return -ENODEV;
>
> -       mask = (1 << adev->gfx.num_gfx_rings) - 1;
> +       mask = (1ULL << adev->gfx.num_gfx_rings) - 1;
>         if ((val & mask) == 0)
>                 return -EINVAL;
>
> @@ -2078,7 +2078,7 @@ static int amdgpu_debugfs_gfx_sched_mask_get(void *data, u64 *val)
>         for (i = 0; i < adev->gfx.num_gfx_rings; ++i) {
>                 ring = &adev->gfx.gfx_ring[i];
>                 if (ring->sched.ready)
> -                       mask |= 1 << i;
> +                       mask |= 1ULL << i;
>         }
>
>         *val = mask;
> @@ -2120,7 +2120,7 @@ static int amdgpu_debugfs_compute_sched_mask_set(void *data, u64 val)
>         if (!adev)
>                 return -ENODEV;
>
> -       mask = (1 << adev->gfx.num_compute_rings) - 1;
> +       mask = (1ULL << adev->gfx.num_compute_rings) - 1;
>         if ((val & mask) == 0)
>                 return -EINVAL;
>
> @@ -2149,7 +2149,7 @@ static int amdgpu_debugfs_compute_sched_mask_get(void *data, u64 *val)
>         for (i = 0; i < adev->gfx.num_compute_rings; ++i) {
>                 ring = &adev->gfx.compute_ring[i];
>                 if (ring->sched.ready)
> -                       mask |= 1 << i;
> +                       mask |= 1ULL << i;
>         }
>
>         *val = mask;
> --
> 2.34.1
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-12-16 18:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-15 12:28 [PATCH] drm/amdgpu: Fix potential integer overflow in scheduler mask calculations Karol Przybylski
2024-12-16 18:47 ` Alex Deucher

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®