From: "Lazar, Lijo" <lijo.lazar@amd.com>
To: Alex Deucher <alexdeucher@gmail.com>
Cc: amd-gfx@lists.freedesktop.org, Hawking.Zhang@amd.com,
Alexander.Deucher@amd.com, Christian.Koenig@amd.com,
Jesse.Zhang@amd.com, Lancelot.Six@amd.com, "Yat Sin,
David" <David.YatSin@amd.com>
Subject: Re: [PATCH v4 04/11] drm/amdgpu: Add user save area params validation
Date: Tue, 27 Jan 2026 11:41:37 +0530 [thread overview]
Message-ID: <2c920279-0245-4b66-9604-7333b00b9983@amd.com> (raw)
In-Reply-To: <CADnq5_P243kbtXDgv0JqgjmB9taA+2uMUbYtR90aVzPU4APXUw@mail.gmail.com>
On 27-Jan-26 11:25 AM, Alex Deucher wrote:
> On Tue, Jan 27, 2026 at 12:35 AM Lazar, Lijo <lijo.lazar@amd.com> wrote:
>>
>>
>>
>> On 24-Jan-26 2:14 AM, Alex Deucher wrote:
>>> On Thu, Jan 22, 2026 at 5:52 AM Lijo Lazar <lijo.lazar@amd.com> wrote:
>>>>
>>>> Add an interface to validate user provided save area parameters. Address
>>>> validation is not done and expected to be done outside.
>>>>
>>>> Signed-off-by: Lijo Lazar <lijo.lazar@amd.com>
>>>> ---
>>>> drivers/gpu/drm/amd/amdgpu/amdgpu_cwsr.c | 44 ++++++++++++++++++++++++
>>>> drivers/gpu/drm/amd/amdgpu/amdgpu_cwsr.h | 11 ++++++
>>>> 2 files changed, 55 insertions(+)
>>>>
>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cwsr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cwsr.c
>>>> index 80020fd33ce6..32d9398cd1d1 100644
>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cwsr.c
>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cwsr.c
>>>> @@ -64,6 +64,15 @@ static inline bool amdgpu_cwsr_is_supported(struct amdgpu_device *adev)
>>>> return true;
>>>> }
>>>>
>>>> +uint32_t amdgpu_cwsr_size_needed(struct amdgpu_device *adev, int num_xcc)
>>>> +{
>>>> + if (!amdgpu_cwsr_is_enabled(adev))
>>>> + return 0;
>>>> +
>>>> + return num_xcc *
>>>> + (adev->cwsr_info->xcc_cwsr_sz + adev->cwsr_info->xcc_dbg_mem_sz);
>>>
>>> These could overflow if userspace passes in especially large values.
>>>
>>
>> Sorry, I didn't get that. cwsr_info contains driver calculated values.
>> This function returns the size required.
>
> Sorry, I mixed this up. See below.
>
>>
>> Thanks,
>> Lijo
>>
>>> Alex
>>>
>>>> +}
>>>> +
>>>> static void amdgpu_cwsr_init_isa_details(struct amdgpu_device *adev,
>>>> struct amdgpu_cwsr_info *cwsr_info)
>>>> {
>>>> @@ -425,6 +434,41 @@ int amdgpu_cwsr_alloc(struct amdgpu_device *adev, struct amdgpu_vm *vm,
>>>> return r;
>>>> }
>>>>
>>>> +int amdgpu_cwsr_validate_params(struct amdgpu_device *adev,
>>>> + struct amdgpu_cwsr_params *cwsr_params,
>>>> + int num_xcc)
>>>> +{
>>>> + struct amdgpu_cwsr_info *cwsr_info = adev->cwsr_info;
>>>> +
>>>> + if (!amdgpu_cwsr_is_enabled(adev))
>>>> + return -EOPNOTSUPP;
>>>> +
>>>> + if (!cwsr_params)
>>>> + return -EINVAL;
>>>> +
>>>> + /*
>>>> + * Only control stack and save area size details checked. Address validation needs to be
>>>> + * carried out separately.
>>>> + */
>>>> + if (cwsr_params->ctl_stack_sz !=
>>>> + (cwsr_info->xcc_ctl_stack_sz * num_xcc)) {
>>>> + dev_dbg(adev->dev,
>>>> + "queue ctl stack size 0x%x not equal to node ctl stack size 0x%x\n",
>>>> + cwsr_params->ctl_stack_sz,
>>>> + num_xcc * cwsr_info->xcc_ctl_stack_sz);
>>>> + return -EINVAL;
>>>> + }
>>>> +
>>>> + if (cwsr_params->cwsr_sz < (cwsr_info->xcc_cwsr_sz * num_xcc)) {
>>>> + dev_dbg(adev->dev,
>>>> + "queue cwsr size 0x%x not equal to node cwsr size 0x%x\n",
>>>> + cwsr_params->cwsr_sz, num_xcc * cwsr_info->xcc_cwsr_sz);
>>>> + return -EINVAL;
>>>> + }
>
> cwsr_params->cwsr_sz has no upper bound check. Can this cause an
> overflow elsewhere?
>
We could restrict to a max limit of 2 * cwsr size required. Adding
David/Lancelot as well.
Thanks,
Lijo
> Alex
>
>
> Alex
>
>>>> +
>>>> + return 0;
>>>> +}
>>>> +
>>>> void amdgpu_cwsr_free(struct amdgpu_device *adev, struct amdgpu_vm *vm,
>>>> struct amdgpu_cwsr_trap_obj **trap_obj)
>>>> {
>>>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cwsr.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_cwsr.h
>>>> index 3c80d057bbed..96b03a8ed99b 100644
>>>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cwsr.h
>>>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cwsr.h
>>>> @@ -56,6 +56,13 @@ struct amdgpu_cwsr_info {
>>>> uint32_t xcc_cwsr_sz;
>>>> };
>>>>
>>>> +struct amdgpu_cwsr_params {
>>>> + uint64_t ctx_save_area_address;
>>>> + /* cwsr size info */
>>>> + uint32_t ctl_stack_sz;
>>>> + uint32_t cwsr_sz;
>>>> +};
>>>> +
>>>> int amdgpu_cwsr_init(struct amdgpu_device *adev);
>>>> void amdgpu_cwsr_fini(struct amdgpu_device *adev);
>>>>
>>>> @@ -68,4 +75,8 @@ static inline bool amdgpu_cwsr_is_enabled(struct amdgpu_device *adev)
>>>> return adev->cwsr_info != NULL;
>>>> }
>>>>
>>>> +uint32_t amdgpu_cwsr_size_needed(struct amdgpu_device *adev, int num_xcc);
>>>> +int amdgpu_cwsr_validate_params(struct amdgpu_device *adev,
>>>> + struct amdgpu_cwsr_params *cwsr_params,
>>>> + int num_xcc);
>>>> #endif
>>>> --
>>>> 2.49.0
>>>>
>>
next prev parent reply other threads:[~2026-01-27 6:11 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-01-22 10:39 [PATCH v4 00/11] Add CWSR support to user queues Lijo Lazar
2026-01-22 10:39 ` [PATCH v4 01/11] drm/amdgpu: Add helper function to get xcc count Lijo Lazar
2026-01-22 10:39 ` [PATCH v4 02/11] drm/amdgpu: Add cwsr functions Lijo Lazar
2026-01-23 20:41 ` Alex Deucher
2026-01-22 10:39 ` [PATCH v4 03/11] drm/amdgpu: Fill cwsr save area details Lijo Lazar
2026-01-22 10:39 ` [PATCH v4 04/11] drm/amdgpu: Add user save area params validation Lijo Lazar
2026-01-23 20:44 ` Alex Deucher
2026-01-27 5:35 ` Lazar, Lijo
2026-01-27 5:55 ` Alex Deucher
2026-01-27 6:11 ` Lazar, Lijo [this message]
2026-01-28 12:30 ` Lancelot SIX
2026-01-28 16:06 ` Alex Deucher
2026-01-22 10:39 ` [PATCH v4 05/11] drm/amdgpu: Add cwsr to device init/fini sequence Lijo Lazar
2026-01-22 10:39 ` [PATCH v4 06/11] drm/amdgpu: Add first level cwsr handler to userq Lijo Lazar
2026-01-22 10:39 ` [PATCH v4 07/11] drm/amdgpu: Add user save area params to mqd input Lijo Lazar
2026-01-23 20:47 ` Alex Deucher
2026-01-22 10:39 ` [PATCH v4 08/11] drm/amdgpu: Add ioctl to get cwsr details Lijo Lazar
2026-01-23 20:48 ` Alex Deucher
2026-01-22 10:39 ` [PATCH v4 09/11] drm/amdgpu: Add ioctl support for cwsr params Lijo Lazar
2026-01-23 20:51 ` Alex Deucher
2026-01-27 5:44 ` Lazar, Lijo
2026-01-28 11:59 ` Lancelot SIX
2026-01-28 13:21 ` Lazar, Lijo
2026-01-22 10:39 ` [PATCH v4 10/11] drm/amdgpu: Add ioctl to set level2 handler Lijo Lazar
2026-01-23 20:52 ` Alex Deucher
2026-01-22 10:40 ` [PATCH v4 11/11] drm/amdgpu: Add interface to set debug trap flag Lijo Lazar
2026-01-23 20:53 ` Alex Deucher
2026-01-27 12:36 ` Lazar, Lijo
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=2c920279-0245-4b66-9604-7333b00b9983@amd.com \
--to=lijo.lazar@amd.com \
--cc=Alexander.Deucher@amd.com \
--cc=Christian.Koenig@amd.com \
--cc=David.YatSin@amd.com \
--cc=Hawking.Zhang@amd.com \
--cc=Jesse.Zhang@amd.com \
--cc=Lancelot.Six@amd.com \
--cc=alexdeucher@gmail.com \
--cc=amd-gfx@lists.freedesktop.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox