drm/amdgpu: restrict the hw sched jobs number to power of two
authorKevin Wang <kevin1.wang@amd.com>
Sun, 19 Jan 2020 09:20:43 +0000 (17:20 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 1 Jul 2020 05:59:23 +0000 (01:59 -0400)
the module parameter sched_hw_submission is probably from user mode,
and the kernel need to check whether it is legal.

1. align hw sched jobs to power of 2 and set minimum number is 2.
2. use kernel api is_power_of_2() to simplify driver code.

Signed-off-by: Kevin Wang <kevin1.wang@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c

index b8f9c7d..2858c09 100644 (file)
@@ -1166,6 +1166,16 @@ static int amdgpu_device_check_arguments(struct amdgpu_device *adev)
                amdgpu_vm_fragment_size = -1;
        }
 
+       if (amdgpu_sched_hw_submission < 2) {
+               dev_warn(adev->dev, "sched hw submission jobs (%d) must be at least 2\n",
+                        amdgpu_sched_hw_submission);
+               amdgpu_sched_hw_submission = 2;
+       } else if (!is_power_of_2(amdgpu_sched_hw_submission)) {
+               dev_warn(adev->dev, "sched hw submission jobs (%d) must be a power of 2\n",
+                        amdgpu_sched_hw_submission);
+               amdgpu_sched_hw_submission = roundup_pow_of_two(amdgpu_sched_hw_submission);
+       }
+
        amdgpu_device_check_smu_prv_buffer_size(adev);
 
        amdgpu_device_check_vm_size(adev);
index 60b323d..8d84975 100644 (file)
@@ -450,8 +450,7 @@ int amdgpu_fence_driver_init_ring(struct amdgpu_ring *ring,
        if (!adev)
                return -EINVAL;
 
-       /* Check that num_hw_submission is a power of two */
-       if ((num_hw_submission & (num_hw_submission - 1)) != 0)
+       if (!is_power_of_2(num_hw_submission))
                return -EINVAL;
 
        ring->fence_drv.cpu_addr = NULL;