From nobody Wed Sep 17 01:25:27 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 E6F73C4708E for ; Tue, 27 Dec 2022 12:16:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232191AbiL0MQd (ORCPT ); Tue, 27 Dec 2022 07:16:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231614AbiL0MOm (ORCPT ); Tue, 27 Dec 2022 07:14:42 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 157741097; Tue, 27 Dec 2022 04:13:56 -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=1672143232; 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=+l2d/cdq1bCnwK0D6HgfIjn8zg4u9A5dEqaR/jxT4do=; b=GpmzF1bRgjUbCBpwshD8Pu4Q/IdnmZ1zRDRSgXefGHmrGQLPw7qurglUSAf2gFukOqQhkW HdI0W+YwNGd7sPn88pja1N5e0ST8YBWUkrXX3kz9dm/aFl2s6FgRgltphFIG3r1Q7KsZHb 52h/LePBwOmZHtvNjy+bUMupdIax4CzM9IKEuTqe1x9X5tb9GfXVsb6MYq96qQOs8+MXh9 Eneu3FP7RVjeGnQ9fJNlab041V0Acq3N9WiANNlDrS7jm7CfuotRJ1eqRFgsSW5HvV0YTM J2xQtNaMEJ4Nkr3PIWftD2tZxZz8KC1v7T5vLZ24vOBjY29enyuQd1qHjqZ2kA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1672143232; 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=+l2d/cdq1bCnwK0D6HgfIjn8zg4u9A5dEqaR/jxT4do=; b=Yrj+kLAL2417OmKkegZvau6zufhq0iySNaNk1xPQCX3thbAszDkkSEcsFGGXrx9Dbt6k89 LTdl8dEBhWRTR2AQ== 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] selftests/rseq: Implement rseq numa node id field selftest Cc: Mathieu Desnoyers , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20221122203932.231377-7-mathieu.desnoyers@efficios.com> References: <20221122203932.231377-7-mathieu.desnoyers@efficios.com> MIME-Version: 1.0 Message-ID: <167214323192.4906.419354459348579509.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: quoted-printable 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: 99babd04b25054717d21840298b0b46046b42cd9 Gitweb: https://git.kernel.org/tip/99babd04b25054717d21840298b0b4604= 6b42cd9 Author: Mathieu Desnoyers AuthorDate: Tue, 22 Nov 2022 15:39:08 -05:00 Committer: Peter Zijlstra CommitterDate: Tue, 27 Dec 2022 12:52:11 +01:00 selftests/rseq: Implement rseq numa node id field selftest Test the NUMA node id extension rseq field. Compare it against the value returned by the getcpu(2) system call while pinned on a specific core. Signed-off-by: Mathieu Desnoyers Signed-off-by: Peter Zijlstra (Intel) Link: https://lore.kernel.org/r/20221122203932.231377-7-mathieu.desnoyers@e= fficios.com --- tools/testing/selftests/rseq/basic_test.c | 4 +++- tools/testing/selftests/rseq/rseq-abi.h | 8 ++++++- tools/testing/selftests/rseq/rseq.c | 18 ++++++++++++++- tools/testing/selftests/rseq/rseq.h | 28 ++++++++++++++++++++++- 4 files changed, 58 insertions(+) diff --git a/tools/testing/selftests/rseq/basic_test.c b/tools/testing/self= tests/rseq/basic_test.c index d8efbfb..295eea1 100644 --- a/tools/testing/selftests/rseq/basic_test.c +++ b/tools/testing/selftests/rseq/basic_test.c @@ -22,6 +22,8 @@ void test_cpu_pointer(void) CPU_ZERO(&test_affinity); for (i =3D 0; i < CPU_SETSIZE; i++) { if (CPU_ISSET(i, &affinity)) { + int node; + CPU_SET(i, &test_affinity); sched_setaffinity(0, sizeof(test_affinity), &test_affinity); @@ -29,6 +31,8 @@ void test_cpu_pointer(void) assert(rseq_current_cpu() =3D=3D i); assert(rseq_current_cpu_raw() =3D=3D i); assert(rseq_cpu_start() =3D=3D i); + node =3D rseq_fallback_current_node(); + assert(rseq_current_node_id() =3D=3D node); CPU_CLR(i, &test_affinity); } } diff --git a/tools/testing/selftests/rseq/rseq-abi.h b/tools/testing/selfte= sts/rseq/rseq-abi.h index 00ac846..a1faa91 100644 --- a/tools/testing/selftests/rseq/rseq-abi.h +++ b/tools/testing/selftests/rseq/rseq-abi.h @@ -148,6 +148,14 @@ struct rseq_abi { __u32 flags; =20 /* + * Restartable sequences node_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 NUMA node ID. + */ + __u32 node_id; + + /* * Flexible array member at end of structure, after last feature field. */ char end[]; diff --git a/tools/testing/selftests/rseq/rseq.c b/tools/testing/selftests/= rseq/rseq.c index 1e8e326..4e4aa00 100644 --- a/tools/testing/selftests/rseq/rseq.c +++ b/tools/testing/selftests/rseq/rseq.c @@ -79,6 +79,11 @@ static int sys_rseq(struct rseq_abi *rseq_abi, uint32_t = rseq_len, return syscall(__NR_rseq, rseq_abi, rseq_len, flags, sig); } =20 +static int sys_getcpu(unsigned *cpu, unsigned *node) +{ + return syscall(__NR_getcpu, cpu, node, NULL); +} + int rseq_available(void) { int rc; @@ -201,3 +206,16 @@ int32_t rseq_fallback_current_cpu(void) } return cpu; } + +int32_t rseq_fallback_current_node(void) +{ + uint32_t cpu_id, node_id; + int ret; + + ret =3D sys_getcpu(&cpu_id, &node_id); + if (ret) { + perror("sys_getcpu()"); + return ret; + } + return (int32_t) node_id; +} diff --git a/tools/testing/selftests/rseq/rseq.h b/tools/testing/selftests/= rseq/rseq.h index 95adc1e..fd17d0e 100644 --- a/tools/testing/selftests/rseq/rseq.h +++ b/tools/testing/selftests/rseq/rseq.h @@ -20,6 +20,15 @@ #include "rseq-abi.h" #include "compiler.h" =20 +#ifndef rseq_sizeof_field +#define rseq_sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER)) +#endif + +#ifndef rseq_offsetofend +#define rseq_offsetofend(TYPE, MEMBER) \ + (offsetof(TYPE, MEMBER) + rseq_sizeof_field(TYPE, MEMBER)) +#endif + /* * Empty code injection macros, override when testing. * It is important to consider that the ASM injection macros need to be @@ -129,6 +138,11 @@ int rseq_unregister_current_thread(void); int32_t rseq_fallback_current_cpu(void); =20 /* + * Restartable sequence fallback for reading the current node number. + */ +int32_t rseq_fallback_current_node(void); + +/* * Values returned can be either the current CPU number, -1 (rseq is * uninitialized), or -2 (rseq initialization has failed). */ @@ -163,6 +177,20 @@ static inline uint32_t rseq_current_cpu(void) return cpu; } =20 +static inline bool rseq_node_id_available(void) +{ + return (int) rseq_feature_size >=3D rseq_offsetofend(struct rseq_abi, nod= e_id); +} + +/* + * Current NUMA node number. + */ +static inline uint32_t rseq_current_node_id(void) +{ + assert(rseq_node_id_available()); + return RSEQ_ACCESS_ONCE(rseq_get_abi()->node_id); +} + static inline void rseq_clear_rseq_cs(void) { RSEQ_WRITE_ONCE(rseq_get_abi()->rseq_cs.arch.ptr, 0);