drm/amdkfd: Create file descriptor after client is added to smi_clients list
Subsystems (3)
PATCH v2 1/1 drm/amdkfd: Create file descriptor after client is added to smi_clients list
This ensures userspace cannot prematurely clean-up the client before it is fully initialised which has been proven to cause issues in the past.
---
CAVEAT: This patch is completely untested
I can't seem to find a configuration strategy to compile test this allyesconfig and allmodconfig do not appear sufficient
v2: Also remove Client from RCU list in error path
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c | 24 +++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-)
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c +15 -9
@@ -247,15 +247,6 @@ int kfd_smi_event_open(struct kfd_dev *dev, uint32_t *fd)return ret; } - ret =anon_inode_getfd (kfd_smi_name, &kfd_smi_ev_fops, (void *)client, -O_RDWR ); -if (ret <0 ) { -kfifo_free (&client->fifo); -kfree (client); -return ret; - } - *fd = ret; -init_waitqueue_head (&client->wait_queue);spin_lock_init (&client->lock); client->events =0 ;
@@ -265,5 +256,20 @@ int kfd_smi_event_open(struct kfd_dev *dev, uint32_t *fd)list_add_rcu (&client->list, &dev->smi_clients);spin_unlock (&dev->smi_lock); + ret =anon_inode_getfd (kfd_smi_name, &kfd_smi_ev_fops, (void *)client, +O_RDWR ); +if (ret <0 ) { +spin_lock (&dev->smi_lock); +list_del_rcu (&client->list); +spin_unlock (&dev->smi_lock); + +synchronize_rcu (); + +kfifo_free (&client->fifo); +kfree (client); +return ret; + } + *fd = ret; +return 0 ; }
Signature · 1 line
2.35.1.1021.g381101b075-goog
Am 2022-03-31 um 08:21 schrieb Lee Jones:
Quoted 4 lines
This ensures userspace cannot prematurely clean-up the client before it is fully initialised which has been proven to cause issues in the past.
Quoted 9 lines
Cc Felix Kuehling <[email protected]>Cc Alex Deucher <[email protected]>Cc "Christian König" <[email protected]>Cc "Pan, Xinhui" <[email protected]>Cc David Airlie <[email protected]>Cc Daniel Vetter <[email protected]>Signed-off-by Lee Jones <[email protected]>
I will apply to patch to amd-staging-drm-next.
Quoted 5 lines
---
CAVEAT: This patch is completely untested
I can't seem to find a configuration strategy to compile test this allyesconfig and allmodconfig do not appear sufficient
That's very strange. It should get compiled if CONFIG_HSA_AMD is enabled. I will at least compile-test it before I submit.
Regards,
Felix
Quoted 47 lines
v2: Also remove Client from RCU list in error path
drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c | 24 +++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-)drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c +15
-9@@ -247,15 +247,6 @@ int kfd_smi_event_open(struct kfd_dev *dev, uint32_t *fd)return ret; } - ret =anon_inode_getfd (kfd_smi_name, &kfd_smi_ev_fops, (void *)client, -O_RDWR ); -if (ret <0 ) { -kfifo_free (&client->fifo); -kfree (client); -return ret; - } - *fd = ret; -init_waitqueue_head (&client->wait_queue);spin_lock_init (&client->lock); client->events =0 ;@@ -265,5 +256,20 @@ int kfd_smi_event_open(struct kfd_dev *dev, uint32_t *fd)list_add_rcu (&client->list, &dev->smi_clients);spin_unlock (&dev->smi_lock); + ret =anon_inode_getfd (kfd_smi_name, &kfd_smi_ev_fops, (void *)client, +O_RDWR ); +if (ret <0 ) { +spin_lock (&dev->smi_lock); +list_del_rcu (&client->list); +spin_unlock (&dev->smi_lock); + +synchronize_rcu (); + +kfifo_free (&client->fifo); +kfree (client); +return ret; + } + *fd = ret; +return 0 ; }
Quoted 20 lines · Felix Kuehling
Am 2022-03-31 um 08:21 schrieb Lee Jones:
Quoted 4 lines
This ensures userspace cannot prematurely clean-up the client before it is fully initialised which has been proven to cause issues in the past.
Quoted 9 lines
Cc Felix Kuehling <[email protected]>Cc Alex Deucher <[email protected]>Cc "Christian König" <[email protected]>Cc "Pan, Xinhui" <[email protected]>Cc David Airlie <[email protected]>Cc Daniel Vetter <[email protected]>Signed-off-by Lee Jones <[email protected]>Reviewed-by Felix Kuehling <[email protected]>I will apply to patch to amd-staging-drm-next.
Quoted 8 lines
Quoted 5 lines
---
CAVEAT: This patch is completely untested
I can't seem to find a configuration strategy to compile test this allyesconfig and allmodconfig do not appear sufficientThat's very strange. It should get compiled if
CONFIG_HSA_AMDis enabled.
Okay, I figured it out.
Apparently you can't give 'drivers/gpu/drm/amd' as a build param.
'drivers/gpu/drm' works as I expect however.
Quoted 1 line
I will at least compile-test it before I submit.
Great, thank you.
Signature · 4 lines
Lee Jones [李琼斯] Principal Technical Lead - Developer Services Linaro.org │ Open source software for Arm SoCs Follow Linaro: Facebook | Twitter | Blog