Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp3098961rwl; Tue, 27 Dec 2022 04:27:31 -0800 (PST) X-Google-Smtp-Source: AMrXdXsIB96FC4pYH+xEZmy66u/Yza3xYodU/sKgyrhMqYG/DIcYuWULF+DMyZrROq7YOVglLc3D X-Received: by 2002:a17:90b:4b48:b0:218:7148:580d with SMTP id mi8-20020a17090b4b4800b002187148580dmr25504197pjb.7.1672144051238; Tue, 27 Dec 2022 04:27:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672144051; cv=none; d=google.com; s=arc-20160816; b=WykwijxtyjRwRr5sFS6vL7b031xIcj1W6JBAvWf1hDI0Jw/zOd0xw1CHAVt+2awEhq 74r5sAVDftb/e+zMfhGJoZ7dcaDFMy1+gXtvti+JBklc0pgUPu7J2qJQznTkJAXUv+pg ANwXMSMSTJ7l9CESNtYF+x3RPM58Omb0Wxw7qQ3tOmhRrV31B5SoHAUWGu+Wtvht8aXd BZjPxNgsmcRQtLvtBKO6hkHEzXcD3AvNuXSNTdI1kDKI/AyhOQOzJm//GpzDgNAFfn4H 7qjvefzl4U1xlHIr3whD81FJfQ3IYYZfqN+HISDjie6rGgf/Jg+sE8afl+f0Z1e9Ke0+ ohEA== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oo15-20020a17090b1c8f00b0021a05416404si14685401pjb.67.2022.12.27.04.27.22; Tue, 27 Dec 2022 04:27:31 -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 + 66 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 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 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.