Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp2165091rwi; Thu, 3 Nov 2022 13:32:08 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5+0c1H8raZqzxbhvCAmayCIC8zSFVEDc216fjMl40CIrLfOxH2Yf8bG5RNSh0w12282Utg X-Received: by 2002:a05:6a00:1947:b0:565:c337:c53b with SMTP id s7-20020a056a00194700b00565c337c53bmr32203167pfk.10.1667507528717; Thu, 03 Nov 2022 13:32:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667507528; cv=none; d=google.com; s=arc-20160816; b=duFahR2aQax2yYDm/gn7Zi3lmh0KY5Y9e/oPUai60lgMhsd2feNFQVp3rRkyII499G 49ztOZ/r7DmZpEkY4EeIfKUJWNN1gQE7WcqF1EaU74t0F0ihONC2JSvVNMvH23YIO49T nJh3ZjNPWKfzyLku09Z2F1J0SQ+tHUxkluT8BLyCPgB/rs8F1C7WaiaXbK87v+qX+Mtp ys8/yxn7i/wxlXtRhdoaBaePIw7Uov1U+vOPMHq0lCXdOYE9+dWZPNRcb5idpuNFsqvd 5rH2/EvcRDrb7u22EvAw8YMrA97799y+teYTiITZ1srGgv7dm72egsSzeD5XY42ixHfV vM3w== 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 Return-Path: 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.51; Thu, 03 Nov 2022 13:32:08 -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 + 97 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 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 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"); -- 2.25.1