Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp3142490rwl; Tue, 27 Dec 2022 05:05:08 -0800 (PST) X-Google-Smtp-Source: AMrXdXtbDMxxLnCmH9UGjPbPpXxWsw4FqmoWdJvY+TnvfmYqqTtr6Jz5x8F1Q7tc8foEI6gfUAah X-Received: by 2002:a17:906:9688:b0:7c1:1c7:3bad with SMTP id w8-20020a170906968800b007c101c73badmr17766515ejx.36.1672146308137; Tue, 27 Dec 2022 05:05:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672146308; cv=none; d=google.com; s=arc-20160816; b=TCzL0ilKwZeFQL6/h8BBs3NUyFVpqvmkc14oeZmUyY8VvDeE/cgcdwiUQI0DKTOY/F qwOmqmn3+TcRh2O5spBccTzRbibsC9ahuXLpcmMvUSel9TxH52Cstecn+Jc1NUQDtvDa jU6WR0ysLDDBcWJVcsRRgdBz6XZ4LavtuFmkqvAQXpEl6HR4trzbnXhnqY4ciJ94BRig zK+aKbOc897hdIPC/9rdLzTq6mrUhNnXw06paWuZdH53PXbdyw6LZDui/uWJpbhwiK/x 0Jrca1qPnJhrayayxX1Pd0hyHsldzTCJ1x7IOieOXSB4zDGAPVTSiArOwO4NoXliiC5u 7kUA== 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=+l2d/cdq1bCnwK0D6HgfIjn8zg4u9A5dEqaR/jxT4do=; b=JkVvQ70IhzUbEp8CMFvpJG96JklCyWpW6dvMbTwjBYswcTy0GMyrPFExVIGrtEnAFY okdzmfP1ImueluMJYg7SjF2h5vtlz3VFMFwRM4NuatFZhloAO0k0DYWMWQL/2jcHetez zNkbvKsMfDFkcEbOuX6c2snDoRrMW72jIcE5z0xy6pm+UlYf1zuyNKetKqMu7DHdBxJS KwBDdg8ui2MROTSfNeX+S5o1Ccl4j9HvYuZD6uA5DUs7+Df66ICAmTX6yZLhys5/YQfE IP6B/iGusIShkDJXO5Ujo8pfdr6W80r9x3xyrnkd2peicHvHbdY+uu0/mDg1RSzfgI6p nBrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=GpmzF1bR; 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 wu9-20020a170906eec900b0084c6438e6c3si2866479ejb.889.2022.12.27.05.04.52; Tue, 27 Dec 2022 05:05:08 -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=GpmzF1bR; 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 S232182AbiL0MQb (ORCPT + 66 others); Tue, 27 Dec 2022 07:16:31 -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: 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: 99babd04b25054717d21840298b0b46046b42cd9 Gitweb: https://git.kernel.org/tip/99babd04b25054717d21840298b0b46046b42cd9 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@efficios.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/selftests/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 = 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() == i); assert(rseq_current_cpu_raw() == i); assert(rseq_cpu_start() == i); + node = rseq_fallback_current_node(); + assert(rseq_current_node_id() == node); CPU_CLR(i, &test_affinity); } } diff --git a/tools/testing/selftests/rseq/rseq-abi.h b/tools/testing/selftests/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; /* + * 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); } +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 = 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" +#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); /* + * 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; } +static inline bool rseq_node_id_available(void) +{ + return (int) rseq_feature_size >= rseq_offsetofend(struct rseq_abi, node_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);