From patchwork Thu Nov 3 20:03:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathieu Desnoyers X-Patchwork-Id: 15177 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp754204wru; Thu, 3 Nov 2022 13:31:27 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5PSIAZAjGdyjc3N6hBLJaGRlbwdhiGIt3rbkiBpfoKN6SSVewoyGFRe5JPFunOfDhXNXE3 X-Received: by 2002:a17:902:c40f:b0:186:b221:f378 with SMTP id k15-20020a170902c40f00b00186b221f378mr32222328plk.69.1667507487416; Thu, 03 Nov 2022 13:31:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667507487; cv=none; d=google.com; s=arc-20160816; b=aJ005BdIOn0Z3AfXlCQtu5/QUFPrpbBT2LjVAohR3U7EjbOUvsglINBPYIAtUR7T4E YoyaLtnEx4uKgqlRfhBKMR7Wcim0g7Fj6KsdR0rM2LsT8hhutj5PB4AMXoiD6D+g+eGN uzM8HckBpLfvhtZf1u0LmeqQA2Wol7wk1DYenAcbySK1Sled7kzoJzgeE3EpN8F3OaCJ KUp5rQWTcsbSh3Pk9/BXEcORssGW81zM3n7gtgjGaGYlOw2I4JPDmnRxJJlrxKfxa4mf pG38ZU0LhP3Wy5y9IYD/RfoDojlHE1trVCmV2x3NbgRY8adrUMe9KCJ/RdD1OZSv0rhT xYoA== 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=5UyzflobDECZvrAiurZyt1TvuXnRxypiu7Lqw0ZDnBE=; b=tjt6487QRQu4c+8xH3KjRS1jLt2m91h3zuEzu8FNgj05MG+a3a5NegYq04LogiA3RV WMei/HP+MeeYuvwmoylR/tJKo/QhkboweU/wugZjaSC95gfWOpZgeLAgYT4PJoU/s656 ZjynTiPtNtUEK6t1+MhQosBJ6bvVrNtPFv4DOVI0+DiLPlb4iB0qDkO8uu5irViIXVpL eJFPBJgAOs4WsiITJDAUFWpYm7U+L1I5Yy9Ohcx0/NupBI8L0owZVC8FXEKHlPTyUV0d eV2rWUJIB/7+tjfnSegiGcXnhk1cNB0xNszydCZhqPNDi1qddTyP3q2Km6LY3UzL76bo 346w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=smtpout1 header.b=LfCK7Zs4; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p5-20020a056a000b4500b0056caa27df70si2319726pfo.87.2022.11.03.13.31.09; Thu, 03 Nov 2022 13:31:27 -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=LfCK7Zs4; 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 S231618AbiKCUGg (ORCPT + 99 others); Thu, 3 Nov 2022 16:06:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231421AbiKCUFQ (ORCPT ); Thu, 3 Nov 2022 16:05:16 -0400 Received: from smtpout.efficios.com (smtpout.efficios.com [167.114.26.122]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B59F20341; Thu, 3 Nov 2022 13:05:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=efficios.com; s=smtpout1; t=1667505902; bh=yUWQ+0QsvWbby05bgjnK8z/Lmpm+aIQsimFMVF+aIIQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LfCK7Zs4irX7WcB0BGzSCU8wKRydekcNwk3rwNhyS+OpKJ5tA5oS4a9dUNH7iXumm nHlMhtmqN44YeiagUaQ1AZpMaWWXpYeIJ4TYU7UbtZ3dShHDpQ8DcdMzlpH1LYGqYO E+eXVA1/5XBIZd09XGoffnvMDNMz96tacPSHnAizrR9OYbZLNzVwr6K9nrV8aLo+vD 5Y6BtaeM64DX0VJSbJ+KOXQ0WmF3qaLqsFfDaNxSmm3woqaZQ6HCOvjn9KxOIMeIrh iJt/NpYWUKg6M+f0Z8W2jwyfr1myIyDwiVUCgSWn0lsVv/FG9VW25+xEFHxEbsd5E9 7+B3sZgH4vxkA== Received: from localhost.localdomain (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) by smtpout.efficios.com (Postfix) with ESMTPSA id 4N3F9B4SLMzg4m; Thu, 3 Nov 2022 16:05:02 -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 , Chris Kennelly , Mathieu Desnoyers Subject: [PATCH v5 19/24] selftests/rseq: Implement basic percpu ops vm_vcpu_id test Date: Thu, 3 Nov 2022 16:03:54 -0400 Message-Id: <20221103200359.328736-20-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221103200359.328736-1-mathieu.desnoyers@efficios.com> References: <20221103200359.328736-1-mathieu.desnoyers@efficios.com> MIME-Version: 1.0 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748508331168872175?= X-GMAIL-MSGID: =?utf-8?q?1748508331168872175?= Adapt to the rseq.h API changes introduced by commits "selftests/rseq: : Template memory ordering and percpu access mode". Build a new basic_percpu_ops_vm_vcpu_id_test to test the new "vm_vcpu_id" rseq field. Signed-off-by: Mathieu Desnoyers --- tools/testing/selftests/rseq/.gitignore | 1 + tools/testing/selftests/rseq/Makefile | 5 +- .../selftests/rseq/basic_percpu_ops_test.c | 46 ++++++++++++++++--- 3 files changed, 44 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/rseq/.gitignore b/tools/testing/selftests/rseq/.gitignore index 5910888ebfe1..5a7e5acc628c 100644 --- a/tools/testing/selftests/rseq/.gitignore +++ b/tools/testing/selftests/rseq/.gitignore @@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only basic_percpu_ops_test +basic_percpu_ops_vm_vcpu_id_test basic_test basic_rseq_op_test param_test diff --git a/tools/testing/selftests/rseq/Makefile b/tools/testing/selftests/rseq/Makefile index 215e1067f037..4210c135e621 100644 --- a/tools/testing/selftests/rseq/Makefile +++ b/tools/testing/selftests/rseq/Makefile @@ -12,7 +12,7 @@ LDLIBS += -lpthread -ldl # still track changes to header files and depend on shared object. OVERRIDE_TARGETS = 1 -TEST_GEN_PROGS = basic_test basic_percpu_ops_test param_test \ +TEST_GEN_PROGS = basic_test basic_percpu_ops_test basic_percpu_ops_vm_vcpu_id_test param_test \ param_test_benchmark param_test_compare_twice TEST_GEN_PROGS_EXTENDED = librseq.so @@ -29,6 +29,9 @@ $(OUTPUT)/librseq.so: rseq.c rseq.h rseq-*.h $(OUTPUT)/%: %.c $(TEST_GEN_PROGS_EXTENDED) rseq.h rseq-*.h $(CC) $(CFLAGS) $< $(LDLIBS) -lrseq -o $@ +$(OUTPUT)/basic_percpu_ops_vm_vcpu_id_test: basic_percpu_ops_test.c $(TEST_GEN_PROGS_EXTENDED) rseq.h rseq-*.h + $(CC) $(CFLAGS) -DBUILDOPT_RSEQ_PERCPU_VM_VCPU_ID $< $(LDLIBS) -lrseq -o $@ + $(OUTPUT)/param_test_benchmark: param_test.c $(TEST_GEN_PROGS_EXTENDED) \ rseq.h rseq-*.h $(CC) $(CFLAGS) -DBENCHMARK $< $(LDLIBS) -lrseq -o $@ diff --git a/tools/testing/selftests/rseq/basic_percpu_ops_test.c b/tools/testing/selftests/rseq/basic_percpu_ops_test.c index 517756afc2a4..719ff9910e23 100644 --- a/tools/testing/selftests/rseq/basic_percpu_ops_test.c +++ b/tools/testing/selftests/rseq/basic_percpu_ops_test.c @@ -12,6 +12,32 @@ #include "../kselftest.h" #include "rseq.h" +#ifdef BUILDOPT_RSEQ_PERCPU_VM_VCPU_ID +# define RSEQ_PERCPU RSEQ_PERCPU_VM_VCPU_ID +static +int get_current_cpu_id(void) +{ + return rseq_current_vm_vcpu_id(); +} +static +bool rseq_validate_cpu_id(void) +{ + return rseq_vm_vcpu_id_available(); +} +#else +# define RSEQ_PERCPU RSEQ_PERCPU_CPU_ID +static +int get_current_cpu_id(void) +{ + return rseq_cpu_start(); +} +static +bool rseq_validate_cpu_id(void) +{ + return rseq_current_cpu_raw() >= 0; +} +#endif + struct percpu_lock_entry { intptr_t v; } __attribute__((aligned(128))); @@ -51,9 +77,9 @@ int rseq_this_cpu_lock(struct percpu_lock *lock) for (;;) { int ret; - cpu = rseq_cpu_start(); - ret = rseq_cmpeqv_storev(&lock->c[cpu].v, - 0, 1, cpu); + cpu = get_current_cpu_id(); + ret = rseq_cmpeqv_storev(RSEQ_MO_RELAXED, RSEQ_PERCPU, + &lock->c[cpu].v, 0, 1, cpu); if (rseq_likely(!ret)) break; /* Retry if comparison fails or rseq aborts. */ @@ -141,13 +167,14 @@ void this_cpu_list_push(struct percpu_list *list, intptr_t *targetptr, newval, expect; int ret; - cpu = rseq_cpu_start(); + cpu = get_current_cpu_id(); /* Load list->c[cpu].head with single-copy atomicity. */ expect = (intptr_t)RSEQ_READ_ONCE(list->c[cpu].head); newval = (intptr_t)node; targetptr = (intptr_t *)&list->c[cpu].head; node->next = (struct percpu_list_node *)expect; - ret = rseq_cmpeqv_storev(targetptr, expect, newval, cpu); + ret = rseq_cmpeqv_storev(RSEQ_MO_RELAXED, RSEQ_PERCPU, + targetptr, expect, newval, cpu); if (rseq_likely(!ret)) break; /* Retry if comparison fails or rseq aborts. */ @@ -170,12 +197,13 @@ struct percpu_list_node *this_cpu_list_pop(struct percpu_list *list, long offset; int ret, cpu; - cpu = rseq_cpu_start(); + cpu = get_current_cpu_id(); targetptr = (intptr_t *)&list->c[cpu].head; expectnot = (intptr_t)NULL; offset = offsetof(struct percpu_list_node, next); load = (intptr_t *)&head; - ret = rseq_cmpnev_storeoffp_load(targetptr, expectnot, + ret = rseq_cmpnev_storeoffp_load(RSEQ_MO_RELAXED, RSEQ_PERCPU, + targetptr, expectnot, offset, load, cpu); if (rseq_likely(!ret)) { if (_cpu) @@ -295,6 +323,10 @@ int main(int argc, char **argv) errno, strerror(errno)); goto error; } + if (!rseq_validate_cpu_id()) { + fprintf(stderr, "Error: cpu id getter unavailable\n"); + goto error; + } printf("spinlock\n"); test_percpu_spinlock(); printf("percpu_list\n");