From patchwork Tue Dec 27 12:13:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 36866 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1361386wrt; Tue, 27 Dec 2022 04:17:07 -0800 (PST) X-Google-Smtp-Source: AMrXdXvoDpw7NoqEPdU6nAyI2n/dEzxenE4pAu/C9wU+PpVa7ClXQ6nImwqj6KVjRLrAZASUf3CK X-Received: by 2002:a05:6402:241b:b0:45c:b772:5f41 with SMTP id t27-20020a056402241b00b0045cb7725f41mr20623044eda.6.1672143427555; Tue, 27 Dec 2022 04:17:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672143427; cv=none; d=google.com; s=arc-20160816; b=j/cncZIX7GSQyFqEnxF1j5WBR+8TL/SWHxi0EBWRD2VIGX999L7/9kTElgC6hOS5rj wKK/MhPQ6bsjWvcMFXxPwg3n24cC+bFIZ3t9UnSGNxLlsBakGd7KTk1rbh1uslfXIv8T o+Wqi4eujpnarmZJTkwZBHR22l9Zv6iiOAyS7WdOsyVuLEGx5eDPovJFElUbTrggt4FS WRvckYch7S7a1Sua1LfVb30D9xLeGMswIP6cR3e39yGTWPCHLdAKZxDj/32He3xQuYBi iJyy1Aup4NQDj/5UdmWG3ceIXFCXLH5/G1fuLrjpsJh6G+ZfFVjyMzYrowienzD8PbQD 84tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=4TfBq1x+gmsL+8qg80jLPOcg/ef3xJeXazRbhO7StmM=; b=GmRC9j6uy8jFXDBWr1bLD29dpAyDNpHqvBP+Xx6agtlDE1b7dMCip/wSaXsWnGZrKP ihVZChLeA/Z+o9r1EfFjf+tiWsICivzHXsHxyLnwF9u0bGgC3uoKmKid3xyUdNwgGY62 VqcnyIq55+eeeobEEdANNCCx4vI6Ac2LXXdg6LyZ8J0SyMtIrjmdvwtgv9Hs2KOQaCoF byyH/oGX/WKgYyj49N1BUAxxrxwLQj6D3okpsQ976QFX7Dvyg2ZhhBSgF1tVyYqXGz7C 144MzkBi5oJiKbKrp9Ia5O54zrQwpEpe+mjJ9Fpg/n9BoNYNDls9bqc93t0n+/eQ8eIX zX7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fyut8b7h; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cx5-20020a05640222a500b00470140406e3si10147681edb.98.2022.12.27.04.16.41; Tue, 27 Dec 2022 04:17:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=fyut8b7h; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232070AbiL0MQA (ORCPT + 99 others); Tue, 27 Dec 2022 07:16:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232118AbiL0MOl (ORCPT ); Tue, 27 Dec 2022 07:14:41 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4266EAE; Tue, 27 Dec 2022 04:13:54 -0800 (PST) Date: Tue, 27 Dec 2022 12:13:51 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1672143231; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4TfBq1x+gmsL+8qg80jLPOcg/ef3xJeXazRbhO7StmM=; b=fyut8b7hlECCqetXG4gH18U8HS1PzXnk8zsUB3ApQHBWvS6Q1HOvIpal4ppxt0L751M8R3 vKaV0nauFevnayLZ3pE4FQ7UMEOFIXyr8Bg3b72lwPt1K6YHK7Rje/euMBiWRm5/OVcGFL iv27S3ihbZVXtMSK6f4Ru55ihe+x/LwPLc55frpNAnbo7Ovl8ZKVdm7KHi2vX5kqjylBZk PojxURW2tZW+FDYb4sTv9NFgL6QHXi39g2s3eXUdhfxsFJwa14z8mKE6Gl17Nm1t27PqoW WtKn9jY/bEjh/QouXrqFMJzd7HU4Co5QxbeS4VTp5I2J7phLv6xqio6yCekaNA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1672143231; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4TfBq1x+gmsL+8qg80jLPOcg/ef3xJeXazRbhO7StmM=; b=CsEYAFFfSvgXgtrNMbZxGmy332oX4TgjxrEz+Z506drVyxPcp/zik9iYLfWJgeL4Mc73yb 0Q8D8aArYixO0NCQ== From: "tip-bot2 for Mathieu Desnoyers" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] rseq: Extend struct rseq with per-memory-map concurrency ID Cc: Mathieu Desnoyers , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20221122203932.231377-9-mathieu.desnoyers@efficios.com> References: <20221122203932.231377-9-mathieu.desnoyers@efficios.com> MIME-Version: 1.0 Message-ID: <167214323153.4906.14464853919693066880.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750230287559109756?= X-GMAIL-MSGID: =?utf-8?q?1753369466250409899?= The following commit has been merged into the sched/core branch of tip: Commit-ID: f7b01bb0b57f994a44ea6368536b59062b796381 Gitweb: https://git.kernel.org/tip/f7b01bb0b57f994a44ea6368536b59062b796381 Author: Mathieu Desnoyers AuthorDate: Tue, 22 Nov 2022 15:39:10 -05:00 Committer: Peter Zijlstra CommitterDate: Tue, 27 Dec 2022 12:52:12 +01:00 rseq: Extend struct rseq with per-memory-map concurrency ID If a memory map has fewer threads than there are cores on the system, or is limited to run on few cores concurrently through sched affinity or cgroup cpusets, the concurrency IDs will be values close to 0, thus allowing efficient use of user-space memory for per-cpu data structures. Signed-off-by: Mathieu Desnoyers Signed-off-by: Peter Zijlstra (Intel) Link: https://lore.kernel.org/r/20221122203932.231377-9-mathieu.desnoyers@efficios.com --- include/uapi/linux/rseq.h | 9 +++++++++ kernel/rseq.c | 11 ++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/rseq.h b/include/uapi/linux/rseq.h index 1cb90a4..c233aae 100644 --- a/include/uapi/linux/rseq.h +++ b/include/uapi/linux/rseq.h @@ -140,6 +140,15 @@ struct rseq { __u32 node_id; /* + * Restartable sequences mm_cid field. Updated by the kernel. Read by + * user-space with single-copy atomicity semantics. This field should + * only be read by the thread which registered this data structure. + * Aligned on 32-bit. Contains the current thread's concurrency ID + * (allocated uniquely within a memory map). + */ + __u32 mm_cid; + + /* * Flexible array member at end of structure, after last feature field. */ char end[]; diff --git a/kernel/rseq.c b/kernel/rseq.c index 193cfcc..9de6e35 100644 --- a/kernel/rseq.c +++ b/kernel/rseq.c @@ -90,12 +90,15 @@ static int rseq_update_cpu_node_id(struct task_struct *t) struct rseq __user *rseq = t->rseq; u32 cpu_id = raw_smp_processor_id(); u32 node_id = cpu_to_node(cpu_id); + u32 mm_cid = task_mm_cid(t); + WARN_ON_ONCE((int) mm_cid < 0); if (!user_write_access_begin(rseq, t->rseq_len)) goto efault; unsafe_put_user(cpu_id, &rseq->cpu_id_start, efault_end); unsafe_put_user(cpu_id, &rseq->cpu_id, efault_end); unsafe_put_user(node_id, &rseq->node_id, efault_end); + unsafe_put_user(mm_cid, &rseq->mm_cid, efault_end); /* * Additional feature fields added after ORIG_RSEQ_SIZE * need to be conditionally updated only if @@ -113,7 +116,8 @@ efault: static int rseq_reset_rseq_cpu_node_id(struct task_struct *t) { - u32 cpu_id_start = 0, cpu_id = RSEQ_CPU_ID_UNINITIALIZED, node_id = 0; + u32 cpu_id_start = 0, cpu_id = RSEQ_CPU_ID_UNINITIALIZED, node_id = 0, + mm_cid = 0; /* * Reset cpu_id_start to its initial state (0). @@ -133,6 +137,11 @@ static int rseq_reset_rseq_cpu_node_id(struct task_struct *t) if (put_user(node_id, &t->rseq->node_id)) return -EFAULT; /* + * Reset mm_cid to its initial state (0). + */ + if (put_user(mm_cid, &t->rseq->mm_cid)) + return -EFAULT; + /* * Additional feature fields added after ORIG_RSEQ_SIZE * need to be conditionally reset only if * t->rseq_len != ORIG_RSEQ_SIZE.