Skip to contentSkip to conversation

Patch "drm/amdkfd: Create file descriptor after client is added to smi_clients list" has been added to the 5.17-stable tree

PATCH [email protected] 1 participant 1 message Apr 11, 2022

Subsystems (3)
lore
Share & tools
lore

[email protected]

author Applied
#0 lore raw

This is a note to let you know that I've just added the patch titled

drm/amdkfd: Create file descriptor after client is added to smi_clients list

to the 5.17-stable tree which can be found at:
http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
drm-amdkfd-create-file-descriptor-after-client-is-added-to-smi_clients-list.patch
and it can be found in the queue-5.17 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree, please let <[email protected]> know about it.

From e79a2398e1b2d47060474dca291542368183bc0f Mon Sep 17 00:00:00 2001
From: Lee Jones <[email protected]>
Date: Thu, 31 Mar 2022 13:21:17 +0100
Subject: drm/amdkfd: Create file descriptor after client is added to smi_clients list
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

From: Lee Jones <[email protected]>

commit e79a2398e1b2d47060474dca291542368183bc0f upstream.

This ensures userspace cannot prematurely clean-up the client before it is fully initialised which has been proven to cause issues in the past.

---
 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
@@ -268,15 +268,6 @@ int kfd_smi_event_open(struct kfd_dev *d
 		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;
@@ -286,5 +277,20 @@ int kfd_smi_event_open(struct kfd_dev *d
 	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;
 }

Patches currently in stable-queue which might be from [email protected] are

queue-5.17/drm-amdkfd-create-file-descriptor-after-client-is-added-to-smi_clients-list.patch