From: "Christian König" <christian.koenig@amd.com>
To: "Ma, Jun" <majun@amd.com>, Ma Jun <Jun.Ma2@amd.com>,
amd-gfx@lists.freedesktop.org, Alexander.Deucher@amd.com
Subject: Re: [PATCH] drm/amdgpu: Fix out-of-bounds write warning
Date: Fri, 26 Apr 2024 09:38:33 +0200 [thread overview]
Message-ID: <2b0b8031-7a01-45ab-8f1c-1e528618975c@amd.com> (raw)
In-Reply-To: <95431aa1-1567-42d1-8e18-df7406cf4b45@amd.com>
Am 26.04.24 um 05:24 schrieb Ma, Jun:
> On 4/25/2024 8:39 PM, Christian König wrote:
>> Am 25.04.24 um 12:00 schrieb Ma Jun:
>>> Check the ring type value to fix the out-of-bounds
>>> write warning
>>>
>>> Signed-off-by: Ma Jun <Jun.Ma2@amd.com>
>>> ---
>>> drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c | 5 +++++
>>> 1 file changed, 5 insertions(+)
>>>
>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
>>> index 06f0a6534a94..1e0b5bb47bc9 100644
>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.c
>>> @@ -353,6 +353,11 @@ int amdgpu_ring_init(struct amdgpu_device *adev, struct amdgpu_ring *ring,
>>> ring->hw_prio = hw_prio;
>>>
>>> if (!ring->no_scheduler) {
>>> + if (ring->funcs->type >= AMDGPU_HW_IP_NUM) {
>>> + dev_warn(adev->dev, "ring type %d has no scheduler\n", ring->funcs->type);
>>> + return 0;
>>> + }
>>> +
>> That check should probably be at the beginning of the function since
>> trying to initialize a ring with an invalid type should be rejected
>> immediately.
>>
> This check is used to skip the gpu_sched setting for the rings
> which don't have scheduler, such as KIQ, MES, UMSCH_MM.
> Without this check, there could be an potential out-of-bounds writing
> when ring->no__scheduler is not set correctly.
Ah! In this case that that is not really clean.
Probably best approach is to change the "if (!ring->no_scheduler)" instead.
Maybe even move this code here into amdgpu_ctx.c:
hw_ip = ring->funcs->type;
num_sched = &adev->gpu_sched[hw_ip][hw_prio].num_scheds;
adev->gpu_sched[hw_ip][hw_prio].sched[(*num_sched)++] =
&ring->sched;
And then add something like hw_ip <= AMDGPU_HW_IP_NUM.
Background is that it is perfectly valid to have a scheduler for the MES
for example.
Regards,
Christian.
>
> Regards,
> Ma Jun
>
>> Regards,
>> Christian.
>>
>>> hw_ip = ring->funcs->type;
>>> num_sched = &adev->gpu_sched[hw_ip][hw_prio].num_scheds;
>>> adev->gpu_sched[hw_ip][hw_prio].sched[(*num_sched)++] =
prev parent reply other threads:[~2024-04-26 7:38 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-25 10:00 [PATCH] drm/amdgpu: Fix out-of-bounds write warning Ma Jun
2024-04-25 10:00 ` [PATCH v2 1/2] drm/amdgpu: Fix uninitialized variable warning in amdgpu_afmt_acr Ma Jun
2024-04-25 13:14 ` Alex Deucher
2024-04-25 10:00 ` [PATCH v2 2/2] drm/amdgpu: Fix the uninitialized variable warning Ma Jun
2024-04-25 10:10 ` Lazar, Lijo
2024-04-26 3:08 ` Ma, Jun
2024-04-25 13:12 ` Alex Deucher
2024-04-25 12:39 ` [PATCH] drm/amdgpu: Fix out-of-bounds write warning Christian König
2024-04-26 3:24 ` Ma, Jun
2024-04-26 7:38 ` Christian König [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2b0b8031-7a01-45ab-8f1c-1e528618975c@amd.com \
--to=christian.koenig@amd.com \
--cc=Alexander.Deucher@amd.com \
--cc=Jun.Ma2@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=majun@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.