Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp462695imn; Fri, 29 Jul 2022 12:23:21 -0700 (PDT) X-Google-Smtp-Source: AGRyM1t7x+V59DTM/6ilfeGD4Da6TG9KtPme5BQJx9JTOd2DEiPWdgmHu9lkfvQI8/GzTiAs13q+ X-Received: by 2002:aa7:c1d0:0:b0:43c:f89f:a134 with SMTP id d16-20020aa7c1d0000000b0043cf89fa134mr4857941edp.4.1659122601642; Fri, 29 Jul 2022 12:23:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659122601; cv=none; d=google.com; s=arc-20160816; b=0SBULuobokI12f0CALCC8JTMT89UJ0VC6yRivQVZT9K58AfwDDZM8KCEKAnIC1fnuK TYnOKLT7sbnc38Yv7JTjMDakAYNJwyXI/6EyAiS7664qis1zx4Sob406x35t/MrWOQci qmCl31R8PlIR8C1muugUZ7RhytJKq9qdtyMZ8M+LeA+dcObrip6e3R6sOeNF8qGUa0eq Tm91+JBbdsujysSsZJEXrO5LFLHChcWih6o7RbKM3cu7U9L2y8gFbj73Sd+1IpkLQTWY ZQVB2VT1iniVBniq/R/sjeZrnLbAPc17g2RoQkuYYFQPd+b8gEFIVRnG8NuWnT6lxdek COUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature:dkim-filter; bh=O6oX4tqm54q4o/zImsHHSCyS1HipqEmhYnQTSLOU7vM=; b=QSujeb8IQHhccd+T4Xltjhy44L4ZxcMBIKSj1bjWT4GrpAxDInYMr+rJ4jYqlzBohK N+yJsGDpfrApNw8W2Lf1YUvg/IERkkbDk4zEx9poyr2MZ2FPj/lQJoVhnkjblePFTujA 96maNmcqSse5bnxPr0rvhMOB8XB6caNKxOXFTWeZyANRKSmJv6ecD7b8jQgqOJNPdw5j jE0AAlCJhJMw9AcsQgH9cIEuImXwJCv6U7otrXWlH8MazPHoycw+Z2gDMyJOykS/sU7D bdOUn4ucJ+uR0/d9tznGdJMnmlkzmJ7Nz9o1k4yVVcAOr8jAJTPOdHR1uERNS1vR5+hw CqVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=WBSo43I3; 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 dz18-20020a0564021d5200b0043bbf8748d4si4504148edb.431.2022.07.29.12.22.54; Fri, 29 Jul 2022 12:23:21 -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=default header.b=WBSo43I3; 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 S238460AbiG2TDF (ORCPT + 99 others); Fri, 29 Jul 2022 15:03:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238461AbiG2TCp (ORCPT ); Fri, 29 Jul 2022 15:02:45 -0400 Received: from mail.efficios.com (mail.efficios.com [167.114.26.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 20B0B66108; Fri, 29 Jul 2022 12:02:45 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id DF657318F0D; Fri, 29 Jul 2022 15:02:42 -0400 (EDT) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id QJSUBYdRK_jN; Fri, 29 Jul 2022 15:02:42 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 78E2F318D75; Fri, 29 Jul 2022 15:02:42 -0400 (EDT) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 78E2F318D75 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1659121362; bh=O6oX4tqm54q4o/zImsHHSCyS1HipqEmhYnQTSLOU7vM=; h=From:To:Date:Message-Id; b=WBSo43I3fzFvtiPNfSZ1nVfarX3dKD4vdOSdIUGFyMERoLUn++xdwZxbtq63V2263 yljpX9YFlwBPbNm0vpEl6//kUmdsxCWVRV2uDGJdi6QPLgMZ92xyV2umKDGQrZ4AFh XyU/yfT0SpSJTdQb75OyBg6OGhXW75bDK8z5SA4rySvHWNTGwJxn1ABxLyqcv8d+CP EshzOj1ioAB/BrQqH815a0wuInAcn6wFN+JeNO/cpzGZS7s7+kJehmFBB3R7dIINZZ X27f/tncRH2aadhQJTzdSPDPgsQeTHIBKoppMdAcWOpwr+AFnBrNfP8Zf5x7dartvE b/A12N/X60Cig== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id t1Mq1S7JASDh; Fri, 29 Jul 2022 15:02:42 -0400 (EDT) Received: from localhost.localdomain (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) by mail.efficios.com (Postfix) with ESMTPSA id 2E877318DBD; Fri, 29 Jul 2022 15:02:42 -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 , Mathieu Desnoyers Subject: [PATCH v3 05/23] selftests/rseq: Implement rseq numa node id field selftest Date: Fri, 29 Jul 2022 15:02:07 -0400 Message-Id: <20220729190225.12726-6-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220729190225.12726-1-mathieu.desnoyers@efficios.com> References: <20220729190225.12726-1-mathieu.desnoyers@efficios.com> 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 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 --- 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 d8efbfb89193..295eea16466f 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 00ac846d85b0..a1faa9162d52 100644 --- a/tools/testing/selftests/rseq/rseq-abi.h +++ b/tools/testing/selftests/rseq/rseq-abi.h @@ -147,6 +147,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. */ diff --git a/tools/testing/selftests/rseq/rseq.c b/tools/testing/selftests/rseq/rseq.c index 20ea536d1012..0a96c3c779cd 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; @@ -199,3 +204,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 95adc1e1b0db..fd17d0e54a1b 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 @@ -128,6 +137,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); -- 2.17.1