From patchwork Fri Nov 17 13:21:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: cruzzhao X-Patchwork-Id: 166177 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp522952vqn; Fri, 17 Nov 2023 05:22:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IER2KwoGVowxXJTv0MZDft1tCU+PkjjzJEyjUPq5ocQtYOEdTQ8k2fsWEblGZYYbVzwV806 X-Received: by 2002:a17:90b:4f48:b0:27d:2ce9:d6d5 with SMTP id pj8-20020a17090b4f4800b0027d2ce9d6d5mr7358956pjb.12.1700227335854; Fri, 17 Nov 2023 05:22:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700227335; cv=none; d=google.com; s=arc-20160816; b=rKGkxCvsqtwYWryYuaWNP3a36z3op/ejMRlm7tka3uAIu/csmKCEIufIprzammK2t6 X9XesJixMraYpSTapOaq8WaBJfSL+pAjVj56RDN4hCnJmTcuEAQcIupb7wOEQcUecoUN 23LSXsibyk35rBgEN1q+BsGQsdPQjn9SgB6OO9kGmaUc0B5nSJDXwiQnAlHpzHCi7TGX Vlc+W0lbqWRQdcg2Fvn/oDkUk/JhZLOE6Ugi9RFzVakaLi8rvhEzTeKu+Zgd68l9XEhl F4H8S4A/gvDi1m4RVlusSBOXG+J+BVjUSnGtz9K8kIQAymNEmuptHTE8qf/ezJ32PmW1 WoBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=KfJwRfz6QV22kS9GOIM5qBzuK4LOJabxO+0CFKWiOY4=; fh=QlmRtWuTYJDhaxF0GCu0nvK7RUqeTMNKD6hMg0kv7eo=; b=caB+/T3w+9T7h2WakL4dAbe+ZxslRzBFHWWRglzcRPNht3N59Xjv3sYIhv8HsCqhFj VQiCRCigRaYaWZpJGZb+hW/KKKDcJlS6/sjiBbSuvCo1AP9CfABtcFlWJFBnz3aIKqv9 SsTXR5285kMrbMPiqajGyHXCoKFgnCNMS6SiMv4x6vn6ipsm7dLT8DpIL+pS27cdwC0d E0S5ZZP8aO6EOBirM3s1QFzQXg7zWo8ELATaDrc2RXMz1eS0Lr2Q9UVANHTxb4LD3tNM BezQqMQCAXC47qS3Ftv0Uc8LQBjnDYqPWbvwhoj66T+yA4UmvbB4rBcYIXSkpKY4Rn7s 7ENw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id qb10-20020a17090b280a00b00283a171f265si110159pjb.139.2023.11.17.05.22.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 05:22:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id F0E9582A38E7; Fri, 17 Nov 2023 05:22:14 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346013AbjKQNWD (ORCPT + 30 others); 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 X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 17 Nov 2023 05:22:15 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782817579160998245 X-GMAIL-MSGID: 1782817579160998245 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, 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;