mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] sched/core: put the cookie to uaddr when create cookie
@ 2023-11-17 13:21 Cruz Zhao
  0 siblings, 0 replies; only message in thread
From: Cruz Zhao @ 2023-11-17 13:21 UTC (permalink / raw)
  To: mingo, peterz, juri.lelli, vincent.guittot, dietmar.eggemann,
	rostedt, bsegall, mgorman, bristot, vschneid, joel
  Cc: linux-kernel

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().

Signed-off-by: Cruz Zhao <CruzZhao@linux.alibaba.com>
---
 kernel/sched/core_sched.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/kernel/sched/core_sched.c b/kernel/sched/core_sched.c
index a57fd8f27498..96bd159844b7 100644
--- a/kernel/sched/core_sched.c
+++ b/kernel/sched/core_sched.c
@@ -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;
-- 
2.39.3


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-11-17 13:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-17 13:21 [PATCH] sched/core: put the cookie to uaddr when create cookie Cruz Zhao

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®