From patchwork Fri Feb 9 06:40:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christoph_M=C3=BCllner?= X-Patchwork-Id: 13550911 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 805EFC4829D for ; Fri, 9 Feb 2024 06:41:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=41WbWy56qoz8AT9a2MkqQnpnibv2RKF+eKZr6gFp3ws=; b=ZxTkm3J6IOAjE7 3YIfYBFk7TqDEa1P6xzrr8RaJrs8sHwxlnZ2GseoXWGIhJa/TF+Cv34rjnlc2dfZ1P5321ryopWzk +wY2igDa+8WzLsTSvr8vudtdQ+QEcyh1tl+Xjd2YT6JN8W+CxkVKL8MpGi0WMlz5t0QmLPx22DjSa CtNv3FBH+tx/YNZfsBYKt7NcX44oYqzKBIgZICngtcqKiF1OzepWtE11CDBuLm2lKQthEn63Ix0pS u8Qu8HaEZAM3h2nKy0LX9OQ07B/ZYfxXPMwLP8uHes0qkINuXvmCo+EiVWE3Fcc4qMfkwe6icjQ3E c+ityXuKMjEWSmCMkPVQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rYKZV-0000000GFsp-41I3; Fri, 09 Feb 2024 06:41:13 +0000 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rYKZR-0000000GFn0-3kFf for linux-riscv@lists.infradead.org; Fri, 09 Feb 2024 06:41:11 +0000 Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-a389a3b9601so76826466b.1 for ; Thu, 08 Feb 2024 22:41:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1707460866; x=1708065666; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=L/ygjtZTVjHU12+LM3KMSNgL31cpnfsr1+pYQSNIAAg=; b=Shaq7AgjX4SwmTDQM1CubeVd+AfmEmPVhpcTTiPy0ChHOF9ZTRVIHuZVWeiXa7KeGp hs4EohrVXmquLv3Ud3R3S6I1evbkAGNpjSQyjpl5Zs522B6koB5eWRN2knvrfZSADykZ xBbNA9Bc/z53bOC5Z+QtHljDV0K9JEvdLP/oWJlHvX/o2czK2dVPpbmONxPimfv5v9ja 3ixBYpyEnoAOI1h8esOmq1I0eO6pXqABNH6cMtNLDyNO7ZlK4Dbq8A250XxH2f7cHUos KjT08pJzjE8IsL1E/HNs6bqNt9/ykatjAQ9/5zGmrDodEr0v9O1A8ET0k5mL1AA9JxWF wonQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707460866; x=1708065666; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=L/ygjtZTVjHU12+LM3KMSNgL31cpnfsr1+pYQSNIAAg=; b=lorvI1r2chIie9FfYyb6P6bEF0YWExUFqcqhCXfe3Uxm79vTEWbbqK4rMaXYr7Jqrl KgDf0Xp687T8jkzvd5dplncAKmb83sSgnsR8tktQ0diqzSiY6QwSD4t2yIW44zk8QLuk VXvIvDBHvneD211mEz9Amd5407ZygJNViBdOBpOxZJD3/Hb0Dl9TJH6D/+415GjzkRBW KrbkVq7r6UX2GyFtya8udK8J0+M9GbaLHarj+Zad15Es7RCY0t39BDixgo9qiK3utcOv uvCahbwHVwRdWAzsnySW59eAksoJTOsW0qhfzn/rlR27uECeVKMpGNDaoyqHh/BU+40r fcQA== X-Gm-Message-State: AOJu0YzRtV4x0EusUF9K1CbpQqSvNlSAJquLSjPQkAYeQ0rWhe+DDk3c KoYkzqWdl6pJ8zR2ZoNO3m1Ew3P0C7EUzgQO6BT/Z/AyK1htVpq19HRGmIZhfz4ioCl9GYl+OqV u/ok= X-Google-Smtp-Source: AGHT+IEIwRiGBGnLEqNZprft3iYD6FyLivJVlJ5DvcYSMjlUi+u/u4Zmw+cdsozGJ8bDIbGbqO9viw== X-Received: by 2002:a17:907:363:b0:a3b:e115:7b69 with SMTP id rs3-20020a170907036300b00a3be1157b69mr404470ejb.69.1707460866164; Thu, 08 Feb 2024 22:41:06 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWVssZFqFbfzrmw5N+m8jAa5zM7KTVmwqDhtj5haZxxQzg6uOIC2be48nkwLf0iu0niHguJ551L7u5EteLMF9srBcTAPbhPmlhN9lnjkUU2tTUIeTzif6I3w0++uwCEmChFy3wD+RbH1zBIgET/4eJv8GvYZpGHrClhravWVN/9G12TzOT6pSxV2Hf5e3nv7flcEKay3n/VtUfCFZG3bPN9ruH01WA4pLxi6TRTHdY1GWH33+HGoG4MpOKRjax3mVebVc09T8VWGX+znRRJccUOB6llHqPneJV3KtYH+dT4o/DHN4NIJfia2h3/sHl4L3kSb/tSovFkIYLWSDk7SfUqW4Chj3MUJXUmE0sf9MQYAdtfAN6/1fja+8Igov9hgoncDu7N6JrTf1HelAqwly0GYbt9mqEuV8OdU8VwuMxP9M/G6jFA4wa/KHnI64loSqYdktUMjvLgZ7rx2qlfJXN6Zd3aOJyvy7H5eCPyX4h6MwZ4bSZg8NP1kggYVgQlsNU1N6PAwAccqf+KBuVmusiVRDgI+H0kqOURQEVwFR6RGGBHW+HSr7CQwAxFTrLx054movAmNnanQ2a79ApvJwsN3r/dgbUoFqDGx06ftfb/L8PW2DBt5m8p9uCyAVppafDCV6fPkCjNoRaVSmiVJ3sH76fTIAlBb876kIN/CSV8gNL/Ffh4rtqvRfEz6leUCCjBpy0vXgkAx4sCA7iptzDDd8TasbVhCvk8WJkPDXMHVafgfSo/lKt24X5klr1yI0qYMQawiJ5TkcuJOiLbzBMsWBu8vz6ANKnF7FSpPfnOyRduMkg26SjeQOmb1c/q857B+B6Y2Rw1lUEIifHLy+pGHEaQaYYnqCNjq+3DZmZd6g== Received: from beast.fritz.box (62-178-148-172.cable.dynamic.surfer.at. [62.178.148.172]) by smtp.gmail.com with ESMTPSA id vb9-20020a170907d04900b00a370a76d3a0sm441180ejc.123.2024.02.08.22.41.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 22:41:05 -0800 (PST) From: =?utf-8?q?Christoph_M=C3=BCllner?= To: linux-riscv@lists.infradead.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Jonas Oberhauser , Peter Zijlstra , Palmer Dabbelt , Paul Walmsley , Albert Ou , Andrew Morton , Shuah Khan , Jonathan Corbet , Anup Patel , Philipp Tomsich , Andrew Jones , Guo Ren , Daniel Henrique Barboza , Conor Dooley , =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , Alan Stern , Will Deacon , Daniel Lustig , Brendan Sweeney , Andrew Waterman , Brendan Sweeney , Andrea Parri , Hans Boehm Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [RFC PATCH v2 6/6] RISC-V: selftests: Add DTSO tests Date: Fri, 9 Feb 2024 07:40:50 +0100 Message-ID: <20240209064050.2746540-7-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240209064050.2746540-1-christoph.muellner@vrull.eu> References: <20240209064050.2746540-1-christoph.muellner@vrull.eu> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240208_224110_048832_47B5ECE6 X-CRM114-Status: GOOD ( 21.98 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org This patch tests the dynamic memory consistency model prctl() behaviour on RISC-V. It does not depend on CONFIG_RISCV_ISA_SSDTSO or the availability of Ssdtso, but will test other aspects if these are not given. Signed-off-by: Christoph Müllner --- tools/testing/selftests/riscv/Makefile | 2 +- tools/testing/selftests/riscv/dtso/.gitignore | 1 + tools/testing/selftests/riscv/dtso/Makefile | 11 +++ tools/testing/selftests/riscv/dtso/dtso.c | 82 +++++++++++++++++++ 4 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/riscv/dtso/.gitignore create mode 100644 tools/testing/selftests/riscv/dtso/Makefile create mode 100644 tools/testing/selftests/riscv/dtso/dtso.c diff --git a/tools/testing/selftests/riscv/Makefile b/tools/testing/selftests/riscv/Makefile index 4a9ff515a3a0..1421c21841f9 100644 --- a/tools/testing/selftests/riscv/Makefile +++ b/tools/testing/selftests/riscv/Makefile @@ -5,7 +5,7 @@ ARCH ?= $(shell uname -m 2>/dev/null || echo not) ifneq (,$(filter $(ARCH),riscv)) -RISCV_SUBTARGETS ?= hwprobe vector mm +RISCV_SUBTARGETS ?= dtso hwprobe vector mm else RISCV_SUBTARGETS := endif diff --git a/tools/testing/selftests/riscv/dtso/.gitignore b/tools/testing/selftests/riscv/dtso/.gitignore new file mode 100644 index 000000000000..217d01679115 --- /dev/null +++ b/tools/testing/selftests/riscv/dtso/.gitignore @@ -0,0 +1 @@ +dtso diff --git a/tools/testing/selftests/riscv/dtso/Makefile b/tools/testing/selftests/riscv/dtso/Makefile new file mode 100644 index 000000000000..a1ffbdd3da85 --- /dev/null +++ b/tools/testing/selftests/riscv/dtso/Makefile @@ -0,0 +1,11 @@ +# SPDX-License-Identifier: GPL-2.0 +# Copyright (C) 2023 VRULL + +CFLAGS += -I$(top_srcdir)/tools/include + +TEST_GEN_PROGS := dtso + +include ../../lib.mk + +$(OUTPUT)/dtso: dtso.c ../hwprobe/sys_hwprobe.S + $(CC) -static -o$@ $(CFLAGS) $(LDFLAGS) $^ diff --git a/tools/testing/selftests/riscv/dtso/dtso.c b/tools/testing/selftests/riscv/dtso/dtso.c new file mode 100644 index 000000000000..c8a7b25adefd --- /dev/null +++ b/tools/testing/selftests/riscv/dtso/dtso.c @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* dtso - used for functional tests of memory consistency model switching + * at run-time. + * + * Copyright (c) 2023 Christoph Muellner + */ + +#include +#include +#include + +#include "../hwprobe/hwprobe.h" +#include "../../kselftest_harness.h" + +/* + * We have the following cases: + * 1) DTSO support disabed in the kernel config: + * - Ssdtso is not detected + * - {G,S}ET_MEMORY_CONSISTENCY_MODEL fails with EINVAL + * 2) DTSO support enabled and Ssdtso not available: + * - Ssdtso is not detected + * - {G,S}ET_MEMORY_CONSISTENCY_MODEL works for WMO and fails for TSO with EINVAL: + * 3) DTSO support enabled and Ssdtso available + * - Ssdtso is detected + * - {G,S}ET_MEMORY_CONSISTENCY_MODEL works for WMO and TSO + */ + +TEST(dtso) +{ + struct riscv_hwprobe pair; + int ret; + bool ssdtso_configured; + bool ssdtso_available; + + ret = prctl(PR_GET_MEMORY_CONSISTENCY_MODEL); + if (ret < 0) { + ASSERT_EQ(errno, EINVAL); + ssdtso_configured = false; + } else { + ASSERT_TRUE(ret == PR_MEMORY_CONSISTENCY_MODEL_RISCV_WMO || + ret == PR_MEMORY_CONSISTENCY_MODEL_RISCV_TSO); + ssdtso_configured = true; + } + + pair.key = RISCV_HWPROBE_KEY_IMA_EXT_0; + ret = riscv_hwprobe(&pair, 1, 0, NULL, 0); + ASSERT_GE(ret, 0); + ASSERT_EQ(pair.key, RISCV_HWPROBE_KEY_IMA_EXT_0); + ssdtso_available = !!(pair.value & RISCV_HWPROBE_EXT_SSDTSO); + + if (ssdtso_configured) { + /* Read out current model. */ + ret = prctl(PR_GET_MEMORY_CONSISTENCY_MODEL); + ASSERT_TRUE(ret == PR_MEMORY_CONSISTENCY_MODEL_RISCV_WMO || + ret == PR_MEMORY_CONSISTENCY_MODEL_RISCV_TSO); + + if (ssdtso_available) { + /* Switch to TSO. */ + ret = prctl(PR_SET_MEMORY_CONSISTENCY_MODEL, + PR_MEMORY_CONSISTENCY_MODEL_RISCV_TSO); + ASSERT_EQ(ret, 0); + ret = prctl(PR_GET_MEMORY_CONSISTENCY_MODEL); + ASSERT_TRUE(ret == PR_MEMORY_CONSISTENCY_MODEL_RISCV_TSO); + + /* Try switching back to WMO (must fail). */ + ret = prctl(PR_SET_MEMORY_CONSISTENCY_MODEL, + PR_MEMORY_CONSISTENCY_MODEL_RISCV_WMO); + ASSERT_LT(ret, 0); + ret = prctl(PR_GET_MEMORY_CONSISTENCY_MODEL); + ASSERT_TRUE(ret == PR_MEMORY_CONSISTENCY_MODEL_RISCV_TSO); + } else { + /* Set the same model, that's currently active. */ + ret = prctl(PR_SET_MEMORY_CONSISTENCY_MODEL, ret); + ASSERT_EQ(ret, 0); + } + } else { + ASSERT_EQ(ssdtso_available, false); + ksft_test_result_skip("Ssdtso not configured\n"); + } +} + +TEST_HARNESS_MAIN