Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp601762rwb; Thu, 22 Sep 2022 04:11:41 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7q1OvOaP6imA4ThzitVZq6jAIgZ1q1Vk35hgXppTkzqex3yFmIY2KdorCzAVD5b1HtqvsU X-Received: by 2002:a05:6402:5489:b0:43b:b935:db37 with SMTP id fg9-20020a056402548900b0043bb935db37mr2787355edb.347.1663845100859; Thu, 22 Sep 2022 04:11:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663845100; cv=none; d=google.com; s=arc-20160816; b=kJUfpqp5uf7hWoDn3Vr2iHy08pThauWBTGp4l65ujea0WtJtfRvJunmeWVT+jUbIMw ud7gwmoYdQER6V5pKlU/8BYvBf5bOY9dE/x96UUyO6gtE12wBg0Df8+ELa9576kKL/6+ w2923a48EcfVEhMLjZGNW/fmdrNKPsOIR1iaGmSGf6VCCLQutGpT7t4snAMVeVKjBS/n r3QlO/9Yfxbc0Fv4gR9bAV/e2CmqJvnSj3kq0Z4AgMvfrUUTvp97eKwS14IiqY5aM93y TyUxnTNK5m4gcyzV/67KqWVL7GtZMF1X5ELb6Wp9dcnMOju8cDdX859r0f2aaq0/AUIF J12w== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=JS89KcyTJ89l9xIEnQ8WAZrnXAHkPhxK4radPvQL1YM=; b=uy9e8kYjiJy4xnG50VmBdiIBiVqVQJUlwWLQgpGEhaMK/dfQE2oBn7pjNB7Ndflwet A/JJ8gQ2KgJX7h75ZZw/NMxOwq4kxeumWWIkOtaUs8L+7GXOygOngombJWiVo0anChUI eR9wxoXAiwGSyXzdt/5s2vGsWPZx3Wm+5oHY5BmjdDDw/P8saex65zagdBXnWGP+fjbj KDD6Pg8N7ekuQIo1n8tx4rKqS7DczLIRLvzei1qHNnP68z7DOW6/xh5/YNn6uYVmIaZ4 uzTsDlLQltXyH6yq4GDyBwTFa120lF2vEmOiO0dqohzIW4GNH4LhRxcsBz2iRcXcGKyP vdfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=mAEHpdA8; 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=NONE dis=NONE) header.from=efficios.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sg11-20020a170907a40b00b0077751bae5absi5646772ejc.534.2022.09.22.04.11.12; Thu, 22 Sep 2022 04:11:40 -0700 (PDT) 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=@efficios.com header.s=smtpout1 header.b=mAEHpdA8; 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=NONE dis=NONE) header.from=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230070AbiIVLFw (ORCPT + 99 others); Thu, 22 Sep 2022 07:05:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40090 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230124AbiIVLFX (ORCPT ); Thu, 22 Sep 2022 07:05:23 -0400 Received: from smtpout.efficios.com (smtpout.efficios.com [IPv6:2607:5300:203:5aae::31e5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5929D5774; Thu, 22 Sep 2022 04:05:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1663844385; bh=V6ifN+Z2o32dRDK/qtc0ACzB5XZyKPg7n5MP45xnYvs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mAEHpdA8SUNY4mLBFqOS5l/P1ElKgbZJIN0BMXJAkOqYsMoKJgfFM8xXN72qtLUqp mpzU/ydZLQMX4VAQ2rH4YWDUQ1vS3aMCOdNrAzqM8QhhkV3Dhb07Q/pyUYuQkXn0d6 tPh5VCmzismoft78jzhijBqzoQJfdIAlTqyotTeX4Pvq2TymYgFwb1iiEWitZQu0Xs 5/pWjGbC+03Z0fpDuXensXeD+zki6dtIXPKHAFo0HdL0w9fYjY8y8m3Q5wz+HYMuu7 xEBPE0lnJsDZQAE+oqKVvW32f/7/xUQPBKji4X2YOYPGUf7N706fx7OOpz5CroJc2D LToRXCFiJWg0A== Received: from localhost.localdomain (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4MYC3P3SPdzNNF; Thu, 22 Sep 2022 06:59:45 -0400 (EDT) From: Mathieu Desnoyers To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Thomas Gleixner , "Paul E . McKenney" , Boqun Feng , "H . Peter Anvin" , Paul Turner , linux-api@vger.kernel.org, Christian Brauner , Florian Weimer , David.Laight@ACULAB.COM, carlos@redhat.com, Peter Oskolkov , Alexander Mikhalitsyn , Mathieu Desnoyers Subject: [PATCH v4 10/25] rseq: Extend struct rseq with per memory space vcpu id Date: Thu, 22 Sep 2022 06:59:25 -0400 Message-Id: <20220922105941.237830-11-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220922105941.237830-1-mathieu.desnoyers@efficios.com> References: <20220922105941.237830-1-mathieu.desnoyers@efficios.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 If a memory space has fewer threads than cores, or is limited to run on few cores concurrently through sched affinity or cgroup cpusets, the virtual cpu 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 --- 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 1cb90a435c5c..77a136586ac6 100644 --- a/include/uapi/linux/rseq.h +++ b/include/uapi/linux/rseq.h @@ -139,6 +139,15 @@ struct rseq { */ __u32 node_id; + /* + * Restartable sequences vm_vcpu_id 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 virtual CPU ID + * (allocated uniquely within a memory space). + */ + __u32 vm_vcpu_id; + /* * Flexible array member at end of structure, after last feature field. */ diff --git a/kernel/rseq.c b/kernel/rseq.c index cb7d8a5afc82..1e37662df433 100644 --- a/kernel/rseq.c +++ b/kernel/rseq.c @@ -89,12 +89,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 vm_vcpu_id = task_mm_vcpu_id(t); + WARN_ON_ONCE((int) vm_vcpu_id < 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(vm_vcpu_id, &rseq->vm_vcpu_id, efault_end); /* * Additional feature fields added after ORIG_RSEQ_SIZE * need to be conditionally updated only if @@ -112,7 +115,8 @@ static int rseq_update_cpu_node_id(struct task_struct *t) 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, + vm_vcpu_id = 0; /* * Reset cpu_id_start to its initial state (0). @@ -131,6 +135,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 vm_vcpu_id to its initial state (0). + */ + if (put_user(vm_vcpu_id, &t->rseq->vm_vcpu_id)) + return -EFAULT; /* * Additional feature fields added after ORIG_RSEQ_SIZE * need to be conditionally reset only if -- 2.25.1