Skip to content
This repository has been archived by the owner on Nov 21, 2022. It is now read-only.

Commit

Permalink
drm/amdkfd: Create file descriptor after client is added to smi_clien…
Browse files Browse the repository at this point in the history
…ts 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.

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]>
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Lee Jones <[email protected]>
Reviewed-by: Felix Kuehling <[email protected]>
Signed-off-by: Felix Kuehling <[email protected]>
Signed-off-by: Alex Deucher <[email protected]>
  • Loading branch information
Lee Jones authored and alexdeucher committed Apr 1, 2022
1 parent cf8cc38 commit e454226
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions drivers/gpu/drm/amd/amdkfd/kfd_smi_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}

0 comments on commit e454226

Please sign in to comment.