From nobody Tue Dec 30 08:00:14 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 557A4C072A2 for ; Fri, 17 Nov 2023 13:22:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346059AbjKQNWD (ORCPT ); Fri, 17 Nov 2023 08:22:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230383AbjKQNWC (ORCPT ); Fri, 17 Nov 2023 08:22:02 -0500 Received: from out30-99.freemail.mail.aliyun.com (out30-99.freemail.mail.aliyun.com [115.124.30.99]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C675CD4B for ; Fri, 17 Nov 2023 05:21:57 -0800 (PST) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R941e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045192;MF=cruzzhao@linux.alibaba.com;NM=1;PH=DS;RN=12;SR=0;TI=SMTPD_---0VwZt3bk_1700227309; Received: from localhost.localdomain(mailfrom:CruzZhao@linux.alibaba.com fp:SMTPD_---0VwZt3bk_1700227309) by smtp.aliyun-inc.com; Fri, 17 Nov 2023 21:21:55 +0800 From: Cruz Zhao To: mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, joel@joelfernandes.org Cc: linux-kernel@vger.kernel.org Subject: [PATCH] sched/core: put the cookie to uaddr when create cookie Date: Fri, 17 Nov 2023 21:21:48 +0800 Message-Id: <20231117132148.17844-1-CruzZhao@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 --- 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, e= num pid_type type, BUILD_BUG_ON(PR_SCHED_CORE_SCOPE_PROCESS_GROUP !=3D PIDTYPE_PGID); =20 if (type > PIDTYPE_PGID || cmd >=3D PR_SCHED_CORE_MAX || pid < 0 || - (cmd !=3D PR_SCHED_CORE_GET && uaddr)) + (cmd !=3D PR_SCHED_CORE_GET && cmd !=3D PR_SCHED_CORE_CREATE && uaddr= )) return -EINVAL; =20 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); =20 out: + if (cmd =3D=3D PR_SCHED_CORE_CREATE && !err && uaddr) { + ptr_to_hashval((void *)cookie, &id); + err =3D put_user(id, (u64 __user *)uaddr); + } sched_core_put_cookie(cookie); put_task_struct(task); return err; --=20 2.39.3