* [PATCH] drm/amdkfd: Replace kmalloc + copy_from_user with memdup_user
@ 2025-09-09 15:11 Thorsten Blum
2025-09-09 15:35 ` Alex Deucher
0 siblings, 1 reply; 4+ messages in thread
From: Thorsten Blum @ 2025-09-09 15:11 UTC (permalink / raw)
To: Felix Kuehling, Alex Deucher, Christian König, David Airlie,
Simona Vetter
Cc: Thorsten Blum, amd-gfx, dri-devel, linux-kernel
Replace kmalloc() followed by copy_from_user() with memdup_user() to
improve and simplify kfd_criu_restore_queue().
No functional changes intended.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
.../amd/amdkfd/kfd_process_queue_manager.c | 22 +++++--------------
1 file changed, 6 insertions(+), 16 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
index 7fbb5c274ccc..70c17a12cadf 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
@@ -1004,13 +1004,9 @@ int kfd_criu_restore_queue(struct kfd_process *p,
if (*priv_data_offset + sizeof(*q_data) > max_priv_data_size)
return -EINVAL;
- q_data = kmalloc(sizeof(*q_data), GFP_KERNEL);
- if (!q_data)
- return -ENOMEM;
-
- ret = copy_from_user(q_data, user_priv_ptr + *priv_data_offset, sizeof(*q_data));
- if (ret) {
- ret = -EFAULT;
+ q_data = memdup_user(user_priv_ptr + *priv_data_offset, sizeof(*q_data));
+ if (IS_ERR(q_data)) {
+ ret = PTR_ERR(q_data);
goto exit;
}
@@ -1022,15 +1018,9 @@ int kfd_criu_restore_queue(struct kfd_process *p,
goto exit;
}
- q_extra_data = kmalloc(q_extra_data_size, GFP_KERNEL);
- if (!q_extra_data) {
- ret = -ENOMEM;
- goto exit;
- }
-
- ret = copy_from_user(q_extra_data, user_priv_ptr + *priv_data_offset, q_extra_data_size);
- if (ret) {
- ret = -EFAULT;
+ q_extra_data = memdup_user(user_priv_ptr + *priv_data_offset, q_extra_data_size);
+ if (IS_ERR(q_extra_data)) {
+ ret = PTR_ERR(q_extra_data);
goto exit;
}
--
2.51.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] drm/amdkfd: Replace kmalloc + copy_from_user with memdup_user
2025-09-09 15:11 [PATCH] drm/amdkfd: Replace kmalloc + copy_from_user with memdup_user Thorsten Blum
@ 2025-09-09 15:35 ` Alex Deucher
2025-09-12 12:48 ` Thorsten Blum
0 siblings, 1 reply; 4+ messages in thread
From: Alex Deucher @ 2025-09-09 15:35 UTC (permalink / raw)
To: Thorsten Blum
Cc: Felix Kuehling, Alex Deucher, Christian König, David Airlie,
Simona Vetter, amd-gfx, dri-devel, linux-kernel
Applied. Thanks!
Alex
On Tue, Sep 9, 2025 at 11:29 AM Thorsten Blum <thorsten.blum@linux.dev> wrote:
>
> Replace kmalloc() followed by copy_from_user() with memdup_user() to
> improve and simplify kfd_criu_restore_queue().
>
> No functional changes intended.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
> .../amd/amdkfd/kfd_process_queue_manager.c | 22 +++++--------------
> 1 file changed, 6 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
> index 7fbb5c274ccc..70c17a12cadf 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c
> @@ -1004,13 +1004,9 @@ int kfd_criu_restore_queue(struct kfd_process *p,
> if (*priv_data_offset + sizeof(*q_data) > max_priv_data_size)
> return -EINVAL;
>
> - q_data = kmalloc(sizeof(*q_data), GFP_KERNEL);
> - if (!q_data)
> - return -ENOMEM;
> -
> - ret = copy_from_user(q_data, user_priv_ptr + *priv_data_offset, sizeof(*q_data));
> - if (ret) {
> - ret = -EFAULT;
> + q_data = memdup_user(user_priv_ptr + *priv_data_offset, sizeof(*q_data));
> + if (IS_ERR(q_data)) {
> + ret = PTR_ERR(q_data);
> goto exit;
> }
>
> @@ -1022,15 +1018,9 @@ int kfd_criu_restore_queue(struct kfd_process *p,
> goto exit;
> }
>
> - q_extra_data = kmalloc(q_extra_data_size, GFP_KERNEL);
> - if (!q_extra_data) {
> - ret = -ENOMEM;
> - goto exit;
> - }
> -
> - ret = copy_from_user(q_extra_data, user_priv_ptr + *priv_data_offset, q_extra_data_size);
> - if (ret) {
> - ret = -EFAULT;
> + q_extra_data = memdup_user(user_priv_ptr + *priv_data_offset, q_extra_data_size);
> + if (IS_ERR(q_extra_data)) {
> + ret = PTR_ERR(q_extra_data);
> goto exit;
> }
>
> --
> 2.51.0
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] drm/amdkfd: Replace kmalloc + copy_from_user with memdup_user
2025-09-09 15:35 ` Alex Deucher
@ 2025-09-12 12:48 ` Thorsten Blum
2025-09-12 13:06 ` Alex Deucher
0 siblings, 1 reply; 4+ messages in thread
From: Thorsten Blum @ 2025-09-12 12:48 UTC (permalink / raw)
To: Alex Deucher
Cc: Felix Kuehling, Alex Deucher, Christian König, David Airlie,
Simona Vetter, amd-gfx, dri-devel, linux-kernel
Hi Alex,
On 9. Sep 2025, at 17:35, Alex Deucher wrote:
> Applied. Thanks!
>
> On Tue, Sep 9, 2025 at 11:29 AM Thorsten Blum <thorsten.blum@linux.dev> wrote:
>>
>> Replace kmalloc() followed by copy_from_user() with memdup_user() to
>> improve and simplify kfd_criu_restore_queue().
>>
>> No functional changes intended.
>>
>> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
>> ---
I just learned that calling kfree() on an error pointer doesn't work, so
this patch should probably be reverted/not applied.
Thanks,
Thorsten
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] drm/amdkfd: Replace kmalloc + copy_from_user with memdup_user
2025-09-12 12:48 ` Thorsten Blum
@ 2025-09-12 13:06 ` Alex Deucher
0 siblings, 0 replies; 4+ messages in thread
From: Alex Deucher @ 2025-09-12 13:06 UTC (permalink / raw)
To: Thorsten Blum
Cc: Felix Kuehling, Alex Deucher, Christian König, David Airlie,
Simona Vetter, amd-gfx, dri-devel, linux-kernel
On Fri, Sep 12, 2025 at 8:48 AM Thorsten Blum <thorsten.blum@linux.dev> wrote:
>
> Hi Alex,
>
> On 9. Sep 2025, at 17:35, Alex Deucher wrote:
> > Applied. Thanks!
> >
> > On Tue, Sep 9, 2025 at 11:29 AM Thorsten Blum <thorsten.blum@linux.dev> wrote:
> >>
> >> Replace kmalloc() followed by copy_from_user() with memdup_user() to
> >> improve and simplify kfd_criu_restore_queue().
> >>
> >> No functional changes intended.
> >>
> >> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> >> ---
>
> I just learned that calling kfree() on an error pointer doesn't work, so
> this patch should probably be reverted/not applied.
Thanks for the heads up.
Alex
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-09-12 13:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-09 15:11 [PATCH] drm/amdkfd: Replace kmalloc + copy_from_user with memdup_user Thorsten Blum
2025-09-09 15:35 ` Alex Deucher
2025-09-12 12:48 ` Thorsten Blum
2025-09-12 13:06 ` Alex Deucher
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.