Skip to contentSkip to conversation

sched/core: put the cookie to uaddr when create cookie

PATCH New Cruz Zhao 1 participant 1 message Nov 17, 2023 Scheduler

lore
Share & tools
lore

Cruz Zhao

author
#0 lore raw

PATCH 1/1 sched/core: put the cookie to uaddr when create cookie

For the control process, it's necessary to get the cookie of the task when create a cookie with command PR_SCHED_CORE_CREATE. In current design, we have to use command PR_SCHED_CORE_GET after we create a cookie, with one more syscall.

To optimize this process, we allow user to pass a userspace address, and we put the cookie to the uaddr when we create the cookie successfully. If the uaddr is NULL, the logic is the same as before.

Note that put_user() will return -EFAULT if error, which is different from any error return value of sched_core_share_pid().

---
 kernel/sched/core_sched.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
kernel/sched/core_sched.c +5 -1
index a57fd8f27498..96bd159844b7 100644
@@ -142,7 +142,7 @@ int sched_core_share_pid(unsigned int cmd, pid_t pid, enum pid_type type,
 	BUILD_BUG_ON(PR_SCHED_CORE_SCOPE_PROCESS_GROUP != PIDTYPE_PGID);
 
 	if (type > PIDTYPE_PGID || cmd >= PR_SCHED_CORE_MAX || pid < 0 ||
-	    (cmd != PR_SCHED_CORE_GET && uaddr))
+	    (cmd != PR_SCHED_CORE_GET && cmd != PR_SCHED_CORE_CREATE && uaddr))
 		return -EINVAL;
 
 	rcu_read_lock();
@@ -229,6 +229,10 @@ int sched_core_share_pid(unsigned int cmd, pid_t pid, enum pid_type type,
 	read_unlock(&tasklist_lock);
 
 out:
+	if (cmd == PR_SCHED_CORE_CREATE && !err && uaddr) {
+		ptr_to_hashval((void *)cookie, &id);
+		err = put_user(id, (u64 __user *)uaddr);
+	}
 	sched_core_put_cookie(cookie);
 	put_task_struct(task);
 	return err;
Signature · 1 line
2.39.3