From patchwork Sat May 4 12:28:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931267 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=jZQHEAZg; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWn6M6lKhz1xnT for ; Sat, 4 May 2024 22:29:15 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=jZQHEAZg; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWn6M0nDZz30V3 for ; Sat, 4 May 2024 22:29:15 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=jZQHEAZg; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42f; helo=mail-pf1-x42f.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn621LRfz30Ss for ; Sat, 4 May 2024 22:28:57 +1000 (AEST) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6f3e3d789cdso485649b3a.1 for ; Sat, 04 May 2024 05:28:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825735; x=1715430535; darn=lists.ozlabs.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=I25dR1hp7l0QjjFDNAfUmrV/isLz0uJLZYj3XaBOpYk=; b=jZQHEAZgKDIADYpuoInYGlM8y0n5WK+cNWKaykBL4+ScxvUXd8vDcemCrf45hZ7qz+ sHCyNELzCUsrdBT1N6eO0ScCPVZ36bgoMbIoetQ669OOPN4O+vfmSTHx9hKz3EQ4hyWJ L29TW3JQXqsJQUfy5JVWh2jq41HC2ncxTzRUVkV+dWOM2QeKztAJK2FN7dPZPz5SKsGK 7pdwE8+RqtBRrCpoUSxs6C05yeNB1WHdkQ73UELX9IebiX/jsw2VOyffi03oGDv2mLyy Gjt97GVKX90GFQqt6CvFYgD7QlpQoIEc43fM1j36gdlytVfTEAdOBCfRo5u50oKuxON6 owBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825735; x=1715430535; 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=I25dR1hp7l0QjjFDNAfUmrV/isLz0uJLZYj3XaBOpYk=; b=lwoGyGPJ6MRPuZo3cD2wnzBVLKxSQ98NrQt8VXZCjYflwSvyeuPwlqRJG/qiRyFPpe lWCjSujAQ0phDxf1dw8GoMCVoh0613TkTm79x/Cn35UZIeApiC84U16zZXxvmH1NNITh /QYhwMrQ0I8bWqCgNfvnakk45vGF8Mpqr4Mq9q7V8zwAXHzfoJIe8nf5xv1y8H96rnI/ LXvavm3LPWIpOChh7ifOuswMUNx6o8c56clwKJ7RSYORfgwRz7+RrEbzyA8qlLJIBWDc 9aWDrBg0UXQGlnJTdig7R1dUAKfhSMwjZJvdrtyPM6NiMyz2z2rIlEAZCNzNW2O4rM2D tp1A== X-Forwarded-Encrypted: i=1; AJvYcCXo/pAyH2BDSeuntlKkV3Wyszxh9gfIMtkSJco19bFqeDx6lo4BeJPlGTK9dA0HKb7mhBsoueslwsglsmM2KwWQZ1+jCpjKlkMsIGUOyQ== X-Gm-Message-State: AOJu0Yy3f1FURg45CXSE+VGxxHwMcO6PbXYAj41A0dnD4T0AOtL0ET7C bWrfR1BKXQGYuiVWr+RNzI6kbbFYhTcpUBV3/uVj0AEQSwx1wPor X-Google-Smtp-Source: AGHT+IGaFaM98B+g3awhLTc0POSb1Mkk5D3cQDh3d7Qwnrc2vPOZNBOGQtUtLg4E7fAYXpIWmzWJXA== X-Received: by 2002:a05:6a00:18a0:b0:6f4:1799:c714 with SMTP id x32-20020a056a0018a000b006f41799c714mr7186679pfh.12.1714825735365; Sat, 04 May 2024 05:28:55 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.28.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:28:54 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 01/31] doc: update unittests doc Date: Sat, 4 May 2024 22:28:07 +1000 Message-ID: <20240504122841.1177683-2-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" This adds a few minor fixes. Signed-off-by: Nicholas Piggin Reviewed-by: Andrew Jones --- docs/unittests.txt | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/unittests.txt b/docs/unittests.txt index 3192a60ec..7cf2c55ad 100644 --- a/docs/unittests.txt +++ b/docs/unittests.txt @@ -15,8 +15,8 @@ unittests.cfg format # is the comment symbol, all following contents of the line is ignored. -Each unit test is defined with a [unit-test-name] line, followed by -a set of parameters that control how the test case is run. The name is +Each unit test is defined with a [unit-test-name] line, followed by a +set of parameters that control how the test case is run. The name is arbitrary and appears in the status reporting output. Parameters appear on their own lines under the test name, and have a @@ -62,8 +62,8 @@ groups groups = ... Used to group the test cases for the `run_tests.sh -g ...` run group -option. Adding a test to the nodefault group will cause it to not be -run by default. +option. The group name is arbitrary, aside from the nodefault group +which makes the test to not be run by default. accel ----- @@ -82,8 +82,10 @@ Optional timeout in seconds, after which the test will be killed and fail. check ----- -check = =< +check = = Check a file for a particular value before running a test. The check line can contain multiple files to check separated by a space, but each check parameter needs to be of the form = + +The path and value can not contain space, =, or shell wildcard characters. From patchwork Sat May 4 12:28:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931269 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=DgZ0+Ooy; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWn840YX1z1yb7 for ; Sat, 4 May 2024 22:30:43 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=DgZ0+Ooy; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWn832gnvz30Tj for ; Sat, 4 May 2024 22:30:43 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=DgZ0+Ooy; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::436; helo=mail-pf1-x436.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn6568xNz30Kd for ; Sat, 4 May 2024 22:29:01 +1000 (AEST) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-6f45f1179c3so179796b3a.3 for ; Sat, 04 May 2024 05:29:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825739; x=1715430539; darn=lists.ozlabs.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=XRZJRuRRFLhuP09XIFiRVicmhI/6wcE/f1lbmYTsJ8g=; b=DgZ0+OoyTccoanFFr1ye6PAbuiQzrBXapu/SuwnwtZ+j1XJfNRSjX3xXCDSJoBkdvL ci6pCUy6aF4hFiw0OOOlkM7LK0y97TCIZa/74c9HpXrPTTcTvehuN/Ot0GNNfsNIA1Ji Jn0VLHwxK9itogLRkZpQEgNkA/AwSOmp1b9PZQzrR+pJG+eZFcLv+gsR/K11u6OU5f4V oHwgEDPGxmLJFSoUx0npD3tOcLReMUO4sfqvAmxj+I+vbxAkh+/1EleLxD/smjBbY/bZ VwiVSpCLsFG0kgGreRGbZcHqxHEXzEYuumVGE49ruw+ZLOKX+er0tK1jEPhjcKdXa3il Ry3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825739; x=1715430539; 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=XRZJRuRRFLhuP09XIFiRVicmhI/6wcE/f1lbmYTsJ8g=; b=lo92ryBzzjlu83VFiELu9WrPZvQUAw4wE3MOqc3EYd9kz23iujtpRktulkAPs9pjlP 7vO5+rQysdBwnkjRjpxWeOjITd2Qj6dcHWJpCVBX+ALwAw7xvFaNjX169PasP4APGLF1 +uZG3eTt1+mIjK4OdIE+JJczhJ+c8w4aQJkn23xUobqQEkn5P0swfUR8V5MFG4h5BdeA +Yw0Vaj5G0qyzu/V7mtAuGW6zzAj1ZkR2wspwFLfzchJ3dsknCRf2/OZt/DRHCDEE+7s WCTpWsbWh2/EwMTndtKRdFE3T4l7QbixyqL97+vu+oLUW1+oLhLUvqCTZY95qBQNgfVq 66cA== X-Forwarded-Encrypted: i=1; AJvYcCV2TExqOZe8kRApiJQeLUz8tzgvSEA5SYxEOYtCz4h1cebDIPmT57Z/OpXn42L9QNBwRxcTkf8mKuOzcLz/iVk4gu1OM+iQCThLHToIGA== X-Gm-Message-State: AOJu0YxIwjQ7+pIp606uGp7xq6AiKppNY59BJLWkg+TK0cvIIZGu7iY5 iHTfEkNUNSNRyN5ltB82xZyqda0tpepd2Ejd3sp1ucd6W2td5Es1 X-Google-Smtp-Source: AGHT+IFTNbNHpMpZNjRXGh0JKa5s+AXqP40FKU9v2kc69wA5Y0uIM7vdJmn5XaSEQllotSM8lvtZ3g== X-Received: by 2002:a05:6a00:2da6:b0:6ed:e1c:1034 with SMTP id fb38-20020a056a002da600b006ed0e1c1034mr5646333pfb.34.1714825739079; Sat, 04 May 2024 05:28:59 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.28.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:28:58 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 02/31] report: Add known failure reporting option Date: Sat, 4 May 2024 22:28:08 +1000 Message-ID: <20240504122841.1177683-3-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" There are times we would like to test a function that is known to fail in some conditions due to a bug in implementation (QEMU, KVM, or even hardware). It would be nice to count these as known failures and not report a summary failure. xfail is not the same thing, xfail means failure is required and a pass causes the test to fail. So add kfail for known failures. Mark the failing ppc64 h_cede_tm and spapr_vpa tests as kfail. Signed-off-by: Nicholas Piggin Reviewed-by: Thomas Huth --- lib/libcflat.h | 2 ++ lib/report.c | 33 +++++++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/lib/libcflat.h b/lib/libcflat.h index 700f43527..ae3c2c6d0 100644 --- a/lib/libcflat.h +++ b/lib/libcflat.h @@ -100,6 +100,8 @@ extern void report(bool pass, const char *msg_fmt, ...) __attribute__((format(printf, 2, 3), nonnull(2))); extern void report_xfail(bool xfail, bool pass, const char *msg_fmt, ...) __attribute__((format(printf, 3, 4), nonnull(3))); +extern void report_kfail(bool kfail, bool pass, const char *msg_fmt, ...) + __attribute__((format(printf, 3, 4), nonnull(3))); extern void report_abort(const char *msg_fmt, ...) __attribute__((format(printf, 1, 2))) __attribute__((noreturn)); diff --git a/lib/report.c b/lib/report.c index 8e9bff5b8..7f3c4f059 100644 --- a/lib/report.c +++ b/lib/report.c @@ -13,7 +13,7 @@ #include "libcflat.h" #include "asm/spinlock.h" -static unsigned int tests, failures, xfailures, skipped; +static unsigned int tests, failures, xfailures, kfailures, skipped; static char prefixes[256]; static struct spinlock lock; @@ -81,11 +81,12 @@ void report_prefix_pop(void) } static void va_report(const char *msg_fmt, - bool pass, bool xfail, bool skip, va_list va) + bool pass, bool xfail, bool kfail, bool skip, va_list va) { const char *prefix = skip ? "SKIP" : xfail ? (pass ? "XPASS" : "XFAIL") - : (pass ? "PASS" : "FAIL"); + : kfail ? (pass ? "PASS" : "KFAIL") + : (pass ? "PASS" : "FAIL"); spin_lock(&lock); @@ -98,6 +99,8 @@ static void va_report(const char *msg_fmt, skipped++; else if (xfail && !pass) xfailures++; + else if (kfail && !pass) + kfailures++; else if (xfail || !pass) failures++; @@ -108,7 +111,7 @@ void report(bool pass, const char *msg_fmt, ...) { va_list va; va_start(va, msg_fmt); - va_report(msg_fmt, pass, false, false, va); + va_report(msg_fmt, pass, false, false, false, va); va_end(va); } @@ -117,7 +120,7 @@ void report_pass(const char *msg_fmt, ...) va_list va; va_start(va, msg_fmt); - va_report(msg_fmt, true, false, false, va); + va_report(msg_fmt, true, false, false, false, va); va_end(va); } @@ -126,7 +129,7 @@ void report_fail(const char *msg_fmt, ...) va_list va; va_start(va, msg_fmt); - va_report(msg_fmt, false, false, false, va); + va_report(msg_fmt, false, false, false, false, va); va_end(va); } @@ -134,7 +137,19 @@ void report_xfail(bool xfail, bool pass, const char *msg_fmt, ...) { va_list va; va_start(va, msg_fmt); - va_report(msg_fmt, pass, xfail, false, va); + va_report(msg_fmt, pass, xfail, false, false, va); + va_end(va); +} + +/* + * kfail is known failure. If kfail is true then test will succeed + * regardless of pass. + */ +void report_kfail(bool kfail, bool pass, const char *msg_fmt, ...) +{ + va_list va; + va_start(va, msg_fmt); + va_report(msg_fmt, pass, false, kfail, false, va); va_end(va); } @@ -142,7 +157,7 @@ void report_skip(const char *msg_fmt, ...) { va_list va; va_start(va, msg_fmt); - va_report(msg_fmt, false, false, true, va); + va_report(msg_fmt, false, false, false, true, va); va_end(va); } @@ -168,6 +183,8 @@ int report_summary(void) printf("SUMMARY: %d tests", tests); if (failures) printf(", %d unexpected failures", failures); + if (kfailures) + printf(", %d known failures", kfailures); if (xfailures) printf(", %d expected failures", xfailures); if (skipped) From patchwork Sat May 4 12:28:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931271 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=cyId0vM1; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWn8y35f0z1yb7 for ; Sat, 4 May 2024 22:31:30 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=cyId0vM1; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWn8y1kdRz3d8M for ; Sat, 4 May 2024 22:31:30 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=cyId0vM1; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42f; helo=mail-pf1-x42f.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn683n8Fz30V2 for ; Sat, 4 May 2024 22:29:04 +1000 (AEST) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6f453d2c5a1so532101b3a.2 for ; Sat, 04 May 2024 05:29:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825743; x=1715430543; darn=lists.ozlabs.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=nFe1uWytdimmtEZbjI3zC2F1410iNZlNbtoiOiPVBV0=; b=cyId0vM1jLFGPXwxM457mPJRe9bQVb8su8CikPzaciiVWDgca0F8c3QFg8oOyG7sCv dX7HhRZ/4leJFO/q989iFXLZwTCMtN2rSa58OZF3zH8Q4hVh8PXWSyknTpObUUn+Ucn2 MpzCoaHMpDTMKR9uwwOn8AIxsm/pfGWCyN5E8JIdMc+X0tD3BrHcfMbIEcDmCJ3FONoc auuAPOduFN3+LCrzv4kIcTFKmlEf3BrjHTnWS/fc+WDGvoWiK09awe4J4vqDNuhlSZvU y7jKV1OF7Rc06NrZWNJ3yDcFgHj9pl/T7Lle+CsP2EkBnVgFnye0BYyG/1bFvb/cRHMn Dj5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825743; x=1715430543; 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=nFe1uWytdimmtEZbjI3zC2F1410iNZlNbtoiOiPVBV0=; b=CD7xbqkV9w/5wgnbJuC6Fw+Y4/cHgo6KOTO5Bwy5+L9T0VrVN6vg4TVhWHeq/CmCps xOlh3HJUU4sprOVqvXAG3Ajf8uhaqIKjWIgsKBd6dyEgAQrutwe1BzpA+LQNsT12V/Hu B3o+teemn3SGSHkLxd7mufGK44XajQTV81YCrKfcp4vKdg2L0QhZfZrL4XjxnW8WueH7 0t9Fu7hzwiuMA/AI6BrecuTMQCHmKl1TaRuh7k8WuVhTKQhQ1B/+kfecvPQnNOt6+yoA 7p4lscx5/gQhW6AXDe6WeQl37s1TsqCg4kIwsiddf8T/BQ/dPjSxaB+80CPldI4ew9Pv G1wA== X-Forwarded-Encrypted: i=1; AJvYcCW0jYA6bp3BXdwbgLIDVJM6zZ9JymXUCw+MZ+5hpJavOY/Dntu2gipNO1C1FAZwnfXho5gFDlG6F12VXBYAd2ILMOcdq5o/XPXy2M2jtQ== X-Gm-Message-State: AOJu0YwOM6EnY8evwKRI5G1IxacjJMOhpgVZqfJLt9b6jYt8vaDe3+5k I92m7FMv/IID2DasdFbsjY+uADHrVBJzDgrtR+vVgR2AKtcUiE0P X-Google-Smtp-Source: AGHT+IFU5PoRxx+mTNW7TKy4wefEqAB9Vnc58pFz6n9Y7PrQ01UGoWnU/ypMDlEI1b/QoE5Vxl0sIw== X-Received: by 2002:a05:6a20:9187:b0:1a7:5e8f:8707 with SMTP id v7-20020a056a20918700b001a75e8f8707mr7337295pzd.26.1714825742844; Sat, 04 May 2024 05:29:02 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.28.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:29:02 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 03/31] powerpc: Mark known failing tests as kfail Date: Sat, 4 May 2024 22:28:09 +1000 Message-ID: <20240504122841.1177683-4-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Mark the failing h_cede_tm and spapr_vpa tests as kfail. Signed-off-by: Nicholas Piggin --- powerpc/spapr_vpa.c | 3 ++- powerpc/tm.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/powerpc/spapr_vpa.c b/powerpc/spapr_vpa.c index c2075e157..46fa0485c 100644 --- a/powerpc/spapr_vpa.c +++ b/powerpc/spapr_vpa.c @@ -150,7 +150,8 @@ static void test_vpa(void) report_fail("Could not deregister after registration"); disp_count1 = be32_to_cpu(vpa->vp_dispatch_count); - report(disp_count1 % 2 == 1, "Dispatch count is odd after deregister"); + /* TCG known fail, could be wrong test, must verify against PowerVM */ + report_kfail(true, disp_count1 % 2 == 1, "Dispatch count is odd after deregister"); report_prefix_pop(); } diff --git a/powerpc/tm.c b/powerpc/tm.c index 6b1ceeb6e..d9e7f455d 100644 --- a/powerpc/tm.c +++ b/powerpc/tm.c @@ -133,7 +133,8 @@ int main(int argc, char **argv) report_skip("TM is not available"); goto done; } - report(cpus_with_tm == nr_cpus, + /* KVM does not report TM in secondary threads in POWER9 */ + report_kfail(true, cpus_with_tm == nr_cpus, "TM available in all 'ibm,pa-features' properties"); all = argc == 1 || !strcmp(argv[1], "all"); From patchwork Sat May 4 12:28:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931272 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=NHFjD0FP; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWn9w0nn4z1yb7 for ; Sat, 4 May 2024 22:32:20 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=NHFjD0FP; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWn9v4V7Pz3cfg for ; Sat, 4 May 2024 22:32:19 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=NHFjD0FP; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42e; helo=mail-pf1-x42e.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn6D2kfJz30VD for ; Sat, 4 May 2024 22:29:08 +1000 (AEST) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6f44881ad9eso418451b3a.3 for ; Sat, 04 May 2024 05:29:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825747; x=1715430547; darn=lists.ozlabs.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=Nbmc3N7ayQQTSkTEYRPQXziyE3JeoYhuY3oQWrhsIyA=; b=NHFjD0FPv0/FKXfnxpkP2+6MB8kJgsAYFzUdQwDxsS/Ll2kbMtxvcDPGwQ8gb/zIcz 9iK3+QSKcPUO91Y7ayxMuXlaRlHam0Qc5lH1TrR9yMniBNgGi+ZFUXlsIRU1B0xXYABS l3CEewpW3y/Rofsn1MoWyn+eQV/en04m7eUDC7jtC6awPjd4OrMLx3atC9BDu8rCDPtG gt+QrAwn+bReDVO5SNkACMVfEeuY2tTWiMeiRrR/TsK/FSW7OiC9oiALdgj2CPAfLO7I n+583/u905+1mrE7p/rFRp94xPrhQNRuTGOr2j8TNDAzi61rZ7qYQteYl7EEVF9jYRer uX9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825747; x=1715430547; 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=Nbmc3N7ayQQTSkTEYRPQXziyE3JeoYhuY3oQWrhsIyA=; b=BUI0aev45AxSS7VkkM4FRsYoTB1Pt2jaRjkkKu1UBIzdhJNSdPhVdyQK7BO3h7rgZ3 FMMkzJH6rbdG8Ef2FEkZsZotOXaglOeyIpBvQxEXoPvjmRPsWfId+rs3vDxhXYfS1GyY 998Oqt7pxetKpo7ozSaQlIET6hoAqsRPLi1QfNdO7mgNvF84zTNc6EAmAcGx9YpfqP0W Zow1LYBAmYyWFOMNjAr412f4UArweJtc5TIA8vHfvhTZOpePwB6IrdPK/PGBt9/EYlqG Q2vQEoQ/kObnrPHR9GlCDF+J/zbWyskzL0IofKUVCGk5uHTrDcksbiug9OL86srgPUMR Joww== X-Forwarded-Encrypted: i=1; AJvYcCWjfemsrS23txqFvDziw9SxtAVyPdo5HaZjSppmg+ynDG8mnOJqBJd+FPd9/k/pIFzqA6EsUiiYxVxS1CqaCe0cNxCmDzAdXzvmSM5g2A== X-Gm-Message-State: AOJu0YynMO3zMRxtC5q1kkHVYTF2ubCoLVunkvJK1f7bVML3ha2WzOH9 wUqIzByrTXPA8+21Q2VS19p066QqRfr4ekPUgHvHzYKWMaVKhcBA X-Google-Smtp-Source: AGHT+IEZFDAiDCpXRWqjZJD9ozdG8fcKWo3qQoDgM90MYAfLLB66dy82b1Qj+GOfJf6+77IQHdV5SA== X-Received: by 2002:a05:6a00:4f83:b0:6ee:1c9d:b471 with SMTP id ld3-20020a056a004f8300b006ee1c9db471mr5947858pfb.25.1714825746767; Sat, 04 May 2024 05:29:06 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.29.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:29:06 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 04/31] powerpc: Update unittests for latest QEMU version Date: Sat, 4 May 2024 22:28:10 +1000 Message-ID: <20240504122841.1177683-5-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" The latest QEMU fixes some known bugs in migration which allow some migration tests to be re-enabled on tcg. Signed-off-by: Nicholas Piggin --- powerpc/unittests.cfg | 5 ----- 1 file changed, 5 deletions(-) diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index 432c81d58..699736926 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -20,9 +20,6 @@ groups = selftest [selftest-migration] file = selftest-migration.elf groups = selftest migration -# TODO: Remove accel=kvm once the following TCG migration fix has been merged: -# https://lore.kernel.org/qemu-devel/20240219061731.232570-1-npiggin@gmail.com/ -accel = kvm [selftest-migration-skip] file = selftest-migration.elf @@ -30,10 +27,8 @@ machine = pseries groups = selftest migration extra_params = -append "skip" -# This fails due to a QEMU TCG bug so KVM-only until QEMU is fixed upstream [migration-memory] file = memory-verify.elf -accel = kvm machine = pseries groups = migration From patchwork Sat May 4 12:28:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931273 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=XdniKYVg; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWnBj1H8bz1yb7 for ; Sat, 4 May 2024 22:33:01 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=XdniKYVg; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWnBh7220z3dWF for ; Sat, 4 May 2024 22:33:00 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=XdniKYVg; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::d2f; helo=mail-io1-xd2f.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-io1-xd2f.google.com (mail-io1-xd2f.google.com [IPv6:2607:f8b0:4864:20::d2f]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn6L27dzz30Tk for ; Sat, 4 May 2024 22:29:14 +1000 (AEST) Received: by mail-io1-xd2f.google.com with SMTP id ca18e2360f4ac-7de9261da9bso30006239f.0 for ; Sat, 04 May 2024 05:29:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825751; x=1715430551; darn=lists.ozlabs.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=KDnOGDpVvVheVrCqOGJBqJmhnJQNu0kipM/AOYWeWwg=; b=XdniKYVg3hymPljihRfJCsBVhl588Mezs3Otw3rgWXVh0NYuszaqUSSaqX2desl2Wy PyCq2p8GomI8lNC9wCxZDDHl5SIXvFsX5AW058VNjeWpLolEqy9+dJUnMIDy4PXvDLOe XGdNs9vTH/N9tPGVoyF9V/orrvvjoH7rI2kEZMF4rocPihEybpcnuztUYWydOfSR6I+n TnTIpK+MeNE82zz5ds2HtezQuuGw3JWmp+WN5uBy168dCKJ7bTc/UIAiQbaINytU11W8 yuC8KX5G8S9gSWP5LS7R5qhkBucoZMVqz52DNw+xrOBIpXe1/SAFFdNrH+BFwA6elf9G owYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825751; x=1715430551; 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=KDnOGDpVvVheVrCqOGJBqJmhnJQNu0kipM/AOYWeWwg=; b=wsY350+O5bdFXhHC7S+5CwT272y2gjmC5b+d+LteaUf2ikISBFlrSsZ3MAr3t0Bqky zCDvMdoLfONK9NQmV55wtgKBfvXC8CXYQMSet31NT4bSntVr68bVVfuwArmyriX4ZdnD 7/3zJBO11234rTs6wkZr4mOAhAKrB9SJ9M0tiDKyeOoNmZFw6kuOPN5/H9goCYnHhJXZ ZSbuvjE3ymI3KOz6Cl3n9NNZ/C5aajY4ctlKbqLhouJrBL8iOF+nR5U7yaDiEfVVaDri WcOfTJ5c4u4w1RYKv7vTTwSIrHd3F9bhM24vf+bezWzyPXcsiDQ7FJpcmxo2vFXT3F7a Eeug== X-Forwarded-Encrypted: i=1; AJvYcCUrefnZB21Sqj18kxJAOFfsoNPJMZxGKOsfd9OrZ5UQQQ8u2a6JsaExGVIznlJLV2+h1OXbENQAnoaACMBJIK9bH7h7LzyKQTCZ71lnUw== X-Gm-Message-State: AOJu0YwAVhTTL9vqHlyL9fCKMaUzIVYJLO9BCHRGwt/ZN4F1+JStYPh0 fl+J5TIo0hfvDxHgROvzuxnv0IZxxjNmATN4vjJgMkl8SFJwkxj0eIGVgQ== X-Google-Smtp-Source: AGHT+IEjKBEFtlOjs/PDAHpR/1uXDtDMh4TUbg2Wk3YFPjvyd38uKj508ho6Po8qc7yXp6YSjjSxaA== X-Received: by 2002:a05:6e02:216b:b0:36b:2438:8805 with SMTP id s11-20020a056e02216b00b0036b24388805mr6822079ilv.12.1714825751029; Sat, 04 May 2024 05:29:11 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.29.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:29:10 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 05/31] powerpc/sprs: Specify SPRs with data rather than code Date: Sat, 4 May 2024 22:28:11 +1000 Message-ID: <20240504122841.1177683-6-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" A significant rework that builds an array of 'struct spr', where each element describes an SPR. This makes various metadata about the SPR like name and access type easier to carry and use. Hypervisor privileged registers are described despite not being used at the moment for completeness, but also the code might one day be reused for a hypervisor-privileged test. Acked-by: Thomas Huth Signed-off-by: Nicholas Piggin --- lib/powerpc/asm/reg.h | 2 + powerpc/sprs.c | 650 +++++++++++++++++++++++++++++------------- 2 files changed, 460 insertions(+), 192 deletions(-) diff --git a/lib/powerpc/asm/reg.h b/lib/powerpc/asm/reg.h index 6810c1d82..1f991288e 100644 --- a/lib/powerpc/asm/reg.h +++ b/lib/powerpc/asm/reg.h @@ -5,6 +5,8 @@ #define UL(x) _AC(x, UL) +#define SPR_SRR0 0x01a +#define SPR_SRR1 0x01b #define SPR_TB 0x10c #define SPR_SPRG0 0x110 #define SPR_SPRG1 0x111 diff --git a/powerpc/sprs.c b/powerpc/sprs.c index a19d80a1a..a6588ca63 100644 --- a/powerpc/sprs.c +++ b/powerpc/sprs.c @@ -30,229 +30,458 @@ #include #include -uint64_t before[1024], after[1024]; - -/* Common SPRs for all PowerPC CPUs */ -static void set_sprs_common(uint64_t val) +/* "Indirect" mfspr/mtspr which accept a non-constant spr number */ +static uint64_t __mfspr(unsigned spr) { - mtspr(9, val); /* CTR */ - // mtspr(273, val); /* SPRG1 */ /* Used by our exception handler */ - mtspr(274, val); /* SPRG2 */ - mtspr(275, val); /* SPRG3 */ + uint64_t tmp; + uint64_t ret; + + asm volatile( +" bcl 20, 31, 1f \n" +"1: mflr %0 \n" +" addi %0, %0, (2f-1b) \n" +" add %0, %0, %2 \n" +" mtctr %0 \n" +" bctr \n" +"2: \n" +".LSPR=0 \n" +".rept 1024 \n" +" mfspr %1, .LSPR \n" +" b 3f \n" +" .LSPR=.LSPR+1 \n" +".endr \n" +"3: \n" + : "=&r"(tmp), + "=r"(ret) + : "r"(spr*8) /* 8 bytes per 'mfspr ; b' block */ + : "lr", "ctr"); + + return ret; } -/* SPRs from PowerPC Operating Environment Architecture, Book III, Vers. 2.01 */ -static void set_sprs_book3s_201(uint64_t val) +static void __mtspr(unsigned spr, uint64_t val) { - mtspr(18, val); /* DSISR */ - mtspr(19, val); /* DAR */ - mtspr(152, val); /* CTRL */ - mtspr(256, val); /* VRSAVE */ - mtspr(786, val); /* MMCRA */ - mtspr(795, val); /* MMCR0 */ - mtspr(798, val); /* MMCR1 */ + uint64_t tmp; + + asm volatile( +" bcl 20, 31, 1f \n" +"1: mflr %0 \n" +" addi %0, %0, (2f-1b) \n" +" add %0, %0, %2 \n" +" mtctr %0 \n" +" bctr \n" +"2: \n" +".LSPR=0 \n" +".rept 1024 \n" +" mtspr .LSPR, %1 \n" +" b 3f \n" +" .LSPR=.LSPR+1 \n" +".endr \n" +"3: \n" + : "=&r"(tmp) + : "r"(val), + "r"(spr*8) /* 8 bytes per 'mfspr ; b' block */ + : "lr", "ctr", "xer"); } +static uint64_t before[1024], after[1024]; + +#define SPR_PR_READ 0x0001 +#define SPR_PR_WRITE 0x0002 +#define SPR_OS_READ 0x0010 +#define SPR_OS_WRITE 0x0020 +#define SPR_HV_READ 0x0100 +#define SPR_HV_WRITE 0x0200 + +#define RW 0x333 +#define RO 0x111 +#define WO 0x222 +#define OS_RW 0x330 +#define OS_RO 0x110 +#define OS_WO 0x220 +#define HV_RW 0x300 +#define HV_RO 0x100 +#define HV_WO 0x200 + +#define SPR_ASYNC 0x1000 /* May be updated asynchronously */ +#define SPR_INT 0x2000 /* May be updated by synchronous interrupt */ +#define SPR_HARNESS 0x4000 /* Test harness uses the register */ + +struct spr { + const char *name; + uint8_t width; + uint16_t access; + uint16_t type; +}; + +/* SPRs common denominator back to PowerPC Operating Environment Architecture */ +static const struct spr sprs_common[1024] = { + [1] = { "XER", 64, RW, SPR_HARNESS, }, /* Used by compiler */ + [8] = { "LR", 64, RW, SPR_HARNESS, }, /* Compiler, mfspr/mtspr */ + [9] = { "CTR", 64, RW, SPR_HARNESS, }, /* Compiler, mfspr/mtspr */ + [18] = { "DSISR", 32, OS_RW, SPR_INT, }, + [19] = { "DAR", 64, OS_RW, SPR_INT, }, + [26] = { "SRR0", 64, OS_RW, SPR_INT, }, + [27] = { "SRR1", 64, OS_RW, SPR_INT, }, +[268] = { "TB", 64, RO , SPR_ASYNC, }, +[269] = { "TBU", 32, RO, SPR_ASYNC, }, +[272] = { "SPRG0", 64, OS_RW, SPR_HARNESS, }, /* Interrupt stacr */ +[273] = { "SPRG1", 64, OS_RW, SPR_HARNESS, }, /* Interrupt Scratch */ +[274] = { "SPRG2", 64, OS_RW, }, +[275] = { "SPRG3", 64, OS_RW, }, +[287] = { "PVR", 32, OS_RO, }, +}; + +/* SPRs from PowerPC Operating Environment Architecture, Book III, Vers. 2.01 */ +static const struct spr sprs_201[1024] = { + [22] = { "DEC", 32, OS_RW, SPR_ASYNC, }, + [25] = { "SDR1", 64, HV_RW | OS_RO, }, + [29] = { "ACCR", 64, OS_RW, }, +[136] = { "CTRL", 32, RO, }, +[152] = { "CTRL", 32, OS_WO, }, +[259] = { "SPRG3", 64, RO, }, +/* ASR, EAR omitted */ +[284] = { "TBL", 32, HV_WO, }, +[285] = { "TBU", 32, HV_WO, }, +[310] = { "HDEC", 32, HV_RW, SPR_ASYNC, }, +[1013]= { "DABR", 64, HV_RW | OS_RO, }, +[1023]= { "PIR", 32, OS_RO, SPR_ASYNC, }, /* Can't be virtualised, appears to be async */ +}; + +static const struct spr sprs_970_pmu[1024] = { +/* POWER4+ PMU, should confirm with PPC970 */ +[770] = { "MMCRA", 64, RO, }, +[771] = { "PMC1", 32, RO, }, +[772] = { "PMC2", 32, RO, }, +[773] = { "PMC3", 32, RO, }, +[774] = { "PMC4", 32, RO, }, +[775] = { "PMC5", 32, RO, }, +[776] = { "PMC6", 32, RO, }, +[777] = { "PMC7", 32, RO, }, +[778] = { "PMC8", 32, RO, }, +[779] = { "MMCR0", 64, RO, }, +[780] = { "SIAR", 64, RO, }, +[781] = { "SDAR", 64, RO, }, +[782] = { "MMCR1", 64, RO, }, +[786] = { "MMCRA", 64, OS_RW, }, +[787] = { "PMC1", 32, OS_RW, }, +[788] = { "PMC2", 32, OS_RW, }, +[789] = { "PMC3", 32, OS_RW, }, +[790] = { "PMC4", 32, OS_RW, }, +[791] = { "PMC5", 32, OS_RW, }, +[792] = { "PMC6", 32, OS_RW, }, +[793] = { "PMC7", 32, OS_RW, }, +[794] = { "PMC8", 32, OS_RW, }, +[795] = { "MMCR0", 64, OS_RW, }, +[796] = { "SIAR", 64, OS_RW, }, +[797] = { "SDAR", 64, OS_RW, }, +[798] = { "MMCR1", 64, OS_RW, }, +}; + +/* These are common SPRs from 2.07S onward (POWER CPUs that support KVM HV) */ +static const struct spr sprs_power_common[1024] = { + [3] = { "DSCR", 64, RW, }, + [13] = { "AMR", 64, RW, }, + [17] = { "DSCR", 64, OS_RW, }, + [28] = { "CFAR", 64, OS_RW, SPR_ASYNC, }, /* Effectively async */ + [29] = { "AMR", 64, OS_RW, }, + [61] = { "IAMR", 64, OS_RW, }, +[136] = { "CTRL", 32, RO, }, +[152] = { "CTRL", 32, OS_WO, }, +[153] = { "FSCR", 64, OS_RW, }, +[157] = { "UAMOR", 64, OS_RW, }, +[159] = { "PSPB", 32, OS_RW, }, +[176] = { "DPDES", 64, HV_RW | OS_RO, }, +[180] = { "DAWR0", 64, HV_RW, }, +[186] = { "RPR", 64, HV_RW, }, +[187] = { "CIABR", 64, HV_RW, }, +[188] = { "DAWRX0", 32, HV_RW, }, +[190] = { "HFSCR", 64, HV_RW, }, +[256] = { "VRSAVE", 32, RW, }, +[259] = { "SPRG3", 64, RO, }, +[284] = { "TBL", 32, HV_WO, }, +[285] = { "TBU", 32, HV_WO, }, +[286] = { "TBU40", 64, HV_WO, }, +[304] = { "HSPRG0", 64, HV_RW, }, +[305] = { "HSPRG1", 64, HV_RW, }, +[306] = { "HDSISR", 32, HV_RW, SPR_INT, }, +[307] = { "HDAR", 64, HV_RW, SPR_INT, }, +[308] = { "SPURR", 64, HV_RW | OS_RO, SPR_ASYNC, }, +[309] = { "PURR", 64, HV_RW | OS_RO, SPR_ASYNC, }, +[313] = { "HRMOR", 64, HV_RW, }, +[314] = { "HSRR0", 64, HV_RW, SPR_INT, }, +[315] = { "HSRR1", 64, HV_RW, SPR_INT, }, +[318] = { "LPCR", 64, HV_RW, }, +[319] = { "LPIDR", 32, HV_RW, }, +[336] = { "HMER", 64, HV_RW, }, +[337] = { "HMEER", 64, HV_RW, }, +[338] = { "PCR", 64, HV_RW, }, +[349] = { "AMOR", 64, HV_RW, }, +[446] = { "TIR", 64, OS_RO, }, +[800] = { "BESCRS", 64, RW, }, +[801] = { "BESCRSU", 32, RW, }, +[802] = { "BESCRR", 64, RW, }, +[803] = { "BESCRRU", 32, RW, }, +[804] = { "EBBHR", 64, RW, }, +[805] = { "EBBRR", 64, RW, }, +[806] = { "BESCR", 64, RW, }, +[815] = { "TAR", 64, RW, }, +[848] = { "IC", 64, HV_RW | OS_RO, SPR_ASYNC, }, +[849] = { "VTB", 64, HV_RW | OS_RO, SPR_ASYNC, }, +[896] = { "PPR", 64, RW, }, +[898] = { "PPR32", 32, RW, }, +[1023]= { "PIR", 32, OS_RO, SPR_ASYNC, }, /* Can't be virtualised, appears to be async */ +}; + +static const struct spr sprs_tm[1024] = { +#if 0 + /* XXX: leave these out until enabling TM facility (and more testing) */ +[128] = { "TFHAR", 64, RW, }, +[129] = { "TFIAR", 64, RW, }, +[130] = { "TEXASR", 64, RW, }, +[131] = { "TEXASRU", 32, RW, }, +#endif +}; + /* SPRs from PowerISA 2.07 Book III-S */ -static void set_sprs_book3s_207(uint64_t val) -{ - mtspr(3, val); /* DSCR */ - mtspr(13, val); /* AMR */ - mtspr(17, val); /* DSCR */ - mtspr(18, val); /* DSISR */ - mtspr(19, val); /* DAR */ - mtspr(29, val); /* AMR */ - mtspr(61, val); /* IAMR */ - // mtspr(152, val); /* CTRL */ /* TODO: Needs a fix in KVM */ - mtspr(153, val); /* FSCR */ - mtspr(157, val); /* UAMOR */ - mtspr(159, val); /* PSPB */ - mtspr(256, val); /* VRSAVE */ - // mtspr(272, val); /* SPRG0 */ /* Used by our exception handler */ - mtspr(769, val); /* MMCR2 */ - mtspr(770, val); /* MMCRA */ - mtspr(771, val); /* PMC1 */ - mtspr(772, val); /* PMC2 */ - mtspr(773, val); /* PMC3 */ - mtspr(774, val); /* PMC4 */ - mtspr(775, val); /* PMC5 */ - mtspr(776, val); /* PMC6 */ - mtspr(779, (val & 0xfffffffffbab3fffULL) | 0xfa0b2070); /* MMCR0 */ - mtspr(784, val); /* SIER */ - mtspr(785, val); /* MMCR2 */ - mtspr(786, val); /* MMCRA */ - mtspr(787, val); /* PMC1 */ - mtspr(788, val); /* PMC2 */ - mtspr(789, val); /* PMC3 */ - mtspr(790, val); /* PMC4 */ - mtspr(791, val); /* PMC5 */ - mtspr(792, val); /* PMC6 */ - mtspr(795, (val & 0xfffffffffbab3fffULL) | 0xfa0b2070); /* MMCR0 */ - mtspr(796, val); /* SIAR */ - mtspr(797, val); /* SDAR */ - mtspr(798, val); /* MMCR1 */ - mtspr(800, val); /* BESCRS */ - mtspr(801, val); /* BESCCRSU */ - mtspr(802, val); /* BESCRR */ - mtspr(803, val); /* BESCRRU */ - mtspr(804, val); /* EBBHR */ - mtspr(805, val); /* EBBRR */ - mtspr(806, val); /* BESCR */ - mtspr(815, val); /* TAR */ -} +static const struct spr sprs_207[1024] = { + [22] = { "DEC", 32, OS_RW, SPR_ASYNC, }, + [25] = { "SDR1", 64, HV_RW, }, +[177] = { "DHDES", 64, HV_RW, }, +[283] = { "CIR", 32, OS_RO, }, +[310] = { "HDEC", 32, HV_RW, SPR_ASYNC, }, +[312] = { "RMOR", 64, HV_RW, }, +[339] = { "HEIR", 32, HV_RW, SPR_INT, }, +}; /* SPRs from PowerISA 3.00 Book III */ -static void set_sprs_book3s_300(uint64_t val) -{ - set_sprs_book3s_207(val); - mtspr(48, val); /* PIDR */ - mtspr(144, val); /* TIDR */ - mtspr(823, val); /* PSSCR */ -} +static const struct spr sprs_300[1024] = { + [22] = { "DEC", 64, OS_RW, SPR_ASYNC, }, + [48] = { "PIDR", 32, OS_RW, }, +[144] = { "TIDR", 64, OS_RW, }, +[283] = { "CIR", 32, OS_RO, }, +[310] = { "HDEC", 64, HV_RW, SPR_ASYNC, }, +[339] = { "HEIR", 32, HV_RW, SPR_INT, }, +[464] = { "PTCR", 64, HV_RW, }, +[816] = { "ASDR", 64, HV_RW, SPR_INT, }, +[823] = { "PSSCR", 64, OS_RW, }, +[855] = { "PSSCR", 64, HV_RW, }, +}; -/* SPRs from Power ISA Version 3.1B */ -static void set_sprs_book3s_31(uint64_t val) -{ - set_sprs_book3s_207(val); - mtspr(48, val); /* PIDR */ - /* 3.1 removes TIDR */ - mtspr(823, val); /* PSSCR */ -} +/* SPRs from PowerISA 3.1B Book III */ +static const struct spr sprs_31[1024] = { + [22] = { "DEC", 64, OS_RW, SPR_ASYNC, }, + [48] = { "PIDR", 32, OS_RW, }, +[181] = { "DAWR1", 64, HV_RW, }, +[189] = { "DAWRX1", 32, HV_RW, }, +[310] = { "HDEC", 64, HV_RW, SPR_ASYNC, }, +[339] = { "HEIR", 64, HV_RW, SPR_INT, }, +[455] = { "HDEXCR", 32, RO, }, +[464] = { "PTCR", 64, HV_RW, }, +[468] = { "HASHKEYR", 64, OS_RW, }, +[469] = { "HASHPKEYR", 64, HV_RW, }, +[471] = { "HDEXCR", 64, HV_RW, }, +[812] = { "DEXCR", 32, RO, }, +[816] = { "ASDR", 64, HV_RW, SPR_INT, }, +[823] = { "PSSCR", 64, OS_RW, }, +[828] = { "DEXCR", 64, OS_RW, }, +[855] = { "PSSCR", 64, HV_RW, }, +}; -static void set_sprs(uint64_t val) +/* SPRs POWER9, POWER10 User Manual */ +static const struct spr sprs_power9_10[1024] = { +[276] = { "SPRC", 64, HV_RW, }, +[277] = { "SPRD", 64, HV_RW, }, +[317] = { "TFMR", 64, HV_RW, }, +[799] = { "IMC", 64, HV_RW, }, +[850] = { "LDBAR", 64, HV_RO, }, +[851] = { "MMCRC", 32, HV_RW, }, +[853] = { "PMSR", 32, HV_RO, }, +[861] = { "L2QOSR", 64, HV_WO, }, +[881] = { "TRIG1", 64, OS_WO, }, +[882] = { "TRIG2", 64, OS_WO, }, +[884] = { "PMCR", 64, HV_RW, }, +[885] = { "RWMR", 64, HV_RW, }, +[895] = { "WORT", 64, OS_RW, }, /* UM says 18-bits! */ +[921] = { "TSCR", 32, HV_RW, }, +[922] = { "TTR", 64, HV_RW, }, +[1006]= { "TRACE", 64, WO, }, +[1008]= { "HID", 64, HV_RW, }, +}; + +/* This covers POWER8 and POWER9 PMUs */ +static const struct spr sprs_power_common_pmu[1024] = { +[768] = { "SIER", 64, RO, }, +[769] = { "MMCR2", 64, RW, }, +[770] = { "MMCRA", 64, RW, }, +[771] = { "PMC1", 32, RW, }, +[772] = { "PMC2", 32, RW, }, +[773] = { "PMC3", 32, RW, }, +[774] = { "PMC4", 32, RW, }, +[775] = { "PMC5", 32, RW, }, +[776] = { "PMC6", 32, RW, }, +[779] = { "MMCR0", 64, RW, }, +[780] = { "SIAR", 64, RO, }, +[781] = { "SDAR", 64, RO, }, +[782] = { "MMCR1", 64, RO, }, +[784] = { "SIER", 64, OS_RW, }, +[785] = { "MMCR2", 64, OS_RW, }, +[786] = { "MMCRA", 64, OS_RW, }, +[787] = { "PMC1", 32, OS_RW, }, +[788] = { "PMC2", 32, OS_RW, }, +[789] = { "PMC3", 32, OS_RW, }, +[790] = { "PMC4", 32, OS_RW, }, +[791] = { "PMC5", 32, OS_RW, }, +[792] = { "PMC6", 32, OS_RW, }, +[795] = { "MMCR0", 64, OS_RW, }, +[796] = { "SIAR", 64, OS_RW, }, +[797] = { "SDAR", 64, OS_RW, }, +[798] = { "MMCR1", 64, OS_RW, }, +}; + +static const struct spr sprs_power10_pmu[1024] = { +[736] = { "SIER2", 64, RO, }, +[737] = { "SIER3", 64, RO, }, +[738] = { "MMCR3", 64, RO, }, +[752] = { "SIER2", 64, OS_RW, }, +[753] = { "SIER3", 64, OS_RW, }, +[754] = { "MMCR3", 64, OS_RW, }, +}; + +static struct spr sprs[1024]; + +static void setup_sprs(void) { - set_sprs_common(val); + int i; + + for (i = 0; i < 1024; i++) { + if (sprs_common[i].name) { + memcpy(&sprs[i], &sprs_common[i], sizeof(struct spr)); + } + } switch (mfspr(SPR_PVR) & PVR_VERSION_MASK) { case PVR_VER_970: case PVR_VER_970FX: case PVR_VER_970MP: - set_sprs_book3s_201(val); + for (i = 0; i < 1024; i++) { + if (sprs_201[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_201[i], sizeof(struct spr)); + } + if (sprs_970_pmu[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_power_common_pmu[i], sizeof(struct spr)); + } + } break; + case PVR_VER_POWER8E: case PVR_VER_POWER8NVL: case PVR_VER_POWER8: - set_sprs_book3s_207(val); + for (i = 0; i < 1024; i++) { + if (sprs_power_common[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_power_common[i], sizeof(struct spr)); + } + if (sprs_207[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_207[i], sizeof(struct spr)); + } + if (sprs_tm[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_tm[i], sizeof(struct spr)); + } + if (sprs_power_common_pmu[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_power_common_pmu[i], sizeof(struct spr)); + } + } break; + case PVR_VER_POWER9: - set_sprs_book3s_300(val); + for (i = 0; i < 1024; i++) { + if (sprs_power_common[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_power_common[i], sizeof(struct spr)); + } + if (sprs_300[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_300[i], sizeof(struct spr)); + } + if (sprs_tm[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_tm[i], sizeof(struct spr)); + } + if (sprs_power9_10[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_power9_10[i], sizeof(struct spr)); + } + if (sprs_power_common_pmu[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_power_common_pmu[i], sizeof(struct spr)); + } + } break; + case PVR_VER_POWER10: - set_sprs_book3s_31(val); + for (i = 0; i < 1024; i++) { + if (sprs_power_common[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_power_common[i], sizeof(struct spr)); + } + if (sprs_31[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_31[i], sizeof(struct spr)); + } + if (sprs_power9_10[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_power9_10[i], sizeof(struct spr)); + } + if (sprs_power_common_pmu[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_power_common_pmu[i], sizeof(struct spr)); + } + if (sprs_power10_pmu[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_power10_pmu[i], sizeof(struct spr)); + } + } break; + default: - puts("Warning: Unknown processor version!\n"); + memcpy(sprs, sprs_common, sizeof(sprs)); + puts("Warning: Unknown processor version, falling back to common SPRs!\n"); + break; } } -static void get_sprs_common(uint64_t *v) -{ - v[9] = mfspr(9); /* CTR */ - // v[273] = mfspr(273); /* SPRG1 */ /* Used by our exception handler */ - v[274] = mfspr(274); /* SPRG2 */ - v[275] = mfspr(275); /* SPRG3 */ -} - -static void get_sprs_book3s_201(uint64_t *v) -{ - v[18] = mfspr(18); /* DSISR */ - v[19] = mfspr(19); /* DAR */ - v[136] = mfspr(136); /* CTRL */ - v[256] = mfspr(256); /* VRSAVE */ - v[786] = mfspr(786); /* MMCRA */ - v[795] = mfspr(795); /* MMCR0 */ - v[798] = mfspr(798); /* MMCR1 */ -} - -static void get_sprs_book3s_207(uint64_t *v) -{ - v[3] = mfspr(3); /* DSCR */ - v[13] = mfspr(13); /* AMR */ - v[17] = mfspr(17); /* DSCR */ - v[18] = mfspr(18); /* DSISR */ - v[19] = mfspr(19); /* DAR */ - v[29] = mfspr(29); /* AMR */ - v[61] = mfspr(61); /* IAMR */ - // v[136] = mfspr(136); /* CTRL */ /* TODO: Needs a fix in KVM */ - v[153] = mfspr(153); /* FSCR */ - v[157] = mfspr(157); /* UAMOR */ - v[159] = mfspr(159); /* PSPB */ - v[256] = mfspr(256); /* VRSAVE */ - v[259] = mfspr(259); /* SPRG3 (read only) */ - // v[272] = mfspr(272); /* SPRG0 */ /* Used by our exception handler */ - v[769] = mfspr(769); /* MMCR2 */ - v[770] = mfspr(770); /* MMCRA */ - v[771] = mfspr(771); /* PMC1 */ - v[772] = mfspr(772); /* PMC2 */ - v[773] = mfspr(773); /* PMC3 */ - v[774] = mfspr(774); /* PMC4 */ - v[775] = mfspr(775); /* PMC5 */ - v[776] = mfspr(776); /* PMC6 */ - v[779] = mfspr(779); /* MMCR0 */ - v[780] = mfspr(780); /* SIAR (read only) */ - v[781] = mfspr(781); /* SDAR (read only) */ - v[782] = mfspr(782); /* MMCR1 (read only) */ - v[784] = mfspr(784); /* SIER */ - v[785] = mfspr(785); /* MMCR2 */ - v[786] = mfspr(786); /* MMCRA */ - v[787] = mfspr(787); /* PMC1 */ - v[788] = mfspr(788); /* PMC2 */ - v[789] = mfspr(789); /* PMC3 */ - v[790] = mfspr(790); /* PMC4 */ - v[791] = mfspr(791); /* PMC5 */ - v[792] = mfspr(792); /* PMC6 */ - v[795] = mfspr(795); /* MMCR0 */ - v[796] = mfspr(796); /* SIAR */ - v[797] = mfspr(797); /* SDAR */ - v[798] = mfspr(798); /* MMCR1 */ - v[800] = mfspr(800); /* BESCRS */ - v[801] = mfspr(801); /* BESCCRSU */ - v[802] = mfspr(802); /* BESCRR */ - v[803] = mfspr(803); /* BESCRRU */ - v[804] = mfspr(804); /* EBBHR */ - v[805] = mfspr(805); /* EBBRR */ - v[806] = mfspr(806); /* BESCR */ - v[815] = mfspr(815); /* TAR */ -} - -static void get_sprs_book3s_300(uint64_t *v) +static void get_sprs(uint64_t *v) { - get_sprs_book3s_207(v); - v[48] = mfspr(48); /* PIDR */ - v[144] = mfspr(144); /* TIDR */ - v[823] = mfspr(823); /* PSSCR */ -} + int i; -static void get_sprs_book3s_31(uint64_t *v) -{ - get_sprs_book3s_207(v); - v[48] = mfspr(48); /* PIDR */ - v[823] = mfspr(823); /* PSSCR */ + for (i = 0; i < 1024; i++) { + if (!(sprs[i].access & SPR_OS_READ)) + continue; + v[i] = __mfspr(i); + } } -static void get_sprs(uint64_t *v) +static void set_sprs(uint64_t val) { - uint32_t pvr = mfspr(287); /* Processor Version Register */ - - get_sprs_common(v); + int i; - switch (pvr >> 16) { - case 0x39: /* PPC970 */ - case 0x3C: /* PPC970FX */ - case 0x44: /* PPC970MP */ - get_sprs_book3s_201(v); - break; - case 0x4b: /* POWER8E */ - case 0x4c: /* POWER8NVL */ - case 0x4d: /* POWER8 */ - get_sprs_book3s_207(v); - break; - case 0x4e: /* POWER9 */ - get_sprs_book3s_300(v); - break; - case 0x80: /* POWER10 */ - get_sprs_book3s_31(v); - break; + for (i = 0; i < 1024; i++) { + if (!(sprs[i].access & SPR_OS_WRITE)) + continue; + if (sprs[i].type & SPR_HARNESS) + continue; + if (!strcmp(sprs[i].name, "MMCR0")) { + /* XXX: could use a comment or better abstraction! */ + __mtspr(i, (val & 0xfffffffffbab3fffULL) | 0xfa0b2070); + } else { + __mtspr(i, val); + } } } @@ -289,7 +518,9 @@ int main(int argc, char **argv) } } - printf("Settings SPRs to %#lx...\n", pat); + setup_sprs(); + + printf("Setting SPRs to 0x%lx...\n", pat); set_sprs(pat); memset(before, 0, sizeof(before)); @@ -299,18 +530,53 @@ int main(int argc, char **argv) if (pause) { migrate_once(); + /* Reload regs changed by getchar/putchar hcalls */ + before[SPR_SRR0] = mfspr(SPR_SRR0); + before[SPR_SRR1] = mfspr(SPR_SRR1); + + /* WORT seems to go to 0 after KVM switch, perhaps CPU idle */ + if (sprs[895].name) + before[895] = mfspr(895); } else { msleep(2000); + + /* Reload regs changed by dec interrupt */ + before[SPR_SRR0] = mfspr(SPR_SRR0); + before[SPR_SRR1] = mfspr(SPR_SRR1); + before[SPR_SPRG1] = mfspr(SPR_SPRG1); + + /* WORT seems to go to 0 after KVM switch, perhaps CPU idle */ + if (sprs[895].name) + before[895] = mfspr(895); } get_sprs(after); puts("Checking SPRs...\n"); for (i = 0; i < 1024; i++) { - if (before[i] != 0 || after[i] != 0) - report(before[i] == after[i], - "SPR %d:\t%#018lx <==> %#018lx", i, before[i], - after[i]); + bool pass = true; + + if (!(sprs[i].access & SPR_OS_READ)) + continue; + + if (sprs[i].width == 32) { + if (before[i] >> 32) + pass = false; + } + if (!(sprs[i].type & (SPR_HARNESS|SPR_ASYNC)) && (before[i] != after[i])) + pass = false; + + if (sprs[i].width == 32 && !(before[i] >> 32) && !(after[i] >> 32)) { + /* known failure KVM migration of CTRL */ + report_kfail(true && i == 136, + "%-10s(%4d):\t 0x%08lx <==> 0x%08lx", + sprs[i].name, i, + before[i], after[i]); + } else { + report(pass, "%-10s(%4d):\t0x%016lx <==> 0x%016lx", + sprs[i].name, i, + before[i], after[i]); + } } return report_summary(); From patchwork Sat May 4 12:28:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931274 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=CCw0Ljne; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWnCd0B2Kz1yb7 for ; Sat, 4 May 2024 22:33:48 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=CCw0Ljne; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWnCc4Slyz3cMQ for ; Sat, 4 May 2024 22:33:48 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=CCw0Ljne; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42a; helo=mail-pf1-x42a.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn6N67QSz30Vk for ; Sat, 4 May 2024 22:29:16 +1000 (AEST) Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6ed9fc77bbfso424742b3a.1 for ; Sat, 04 May 2024 05:29:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825754; x=1715430554; darn=lists.ozlabs.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=hLJ4F+YKrXLreQDqYuCgCaOGHgxIONW/HHGxnZQi+UY=; b=CCw0LjneX0jMniZP/7g0paTjkJZUptye+W8gnd/Ce30aHdxAn77wgaFyRxJ6RzfxJB DUc5jyaLovBANbf/aCVxtiu9/+kRRIDiRWCtJIlEI4aX0of6PVCaSbgYZauCq/TniNiI rmQyLqVSKmAjLknLY9ebv47eWy8C81iyvCJZML6ZY3IIc8bb7p+qjHXtaXP6VTZi99EP 1/XvZdvuVzgM9oDgRwftLn2mxJBojiOe/NssRARQ8fFwV54ssZZt/Ruq4UqLBFlcNWup xfh8ZFXcLHUcHyJXW6VapQW4IlypeTLwxW8X75n4ml5A891RhlYkf57q9gebzLFOQydo CMjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825754; x=1715430554; 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=hLJ4F+YKrXLreQDqYuCgCaOGHgxIONW/HHGxnZQi+UY=; b=ouC1N23id3hjliwqv7Tf4/TIEtPutm40i3o1P1eAw49mKFv9HSPh615jjdonDlBKHB Z1V0oepVyMgLoXjcm2U9308yoljvl97lonYv1BqiNChC7Hl2sI99HtAm5uk0MxqE0tgP FVSOkheVf6KCkbbVJplUf7r15Sr8WUqVuTAl/6F8nUYTsP2sie5invCwfEfVEfo57wA3 RmvzS2kU7f4cVIxzp0UAn1C0ZUpARTTVEgfkx3r1SA9Qx4nADhwrpqRU1qorG7QXxW6g 330YlmmSRItrIBgNGHVvH9a4hgvl8dMtF9BGxrWSDcBucTcwYqs/4qKypcsQD1jWNkfi JQ3w== X-Forwarded-Encrypted: i=1; AJvYcCUpbv6AVRQ70vBGvqLS5usPXvWvoGsXfqr5dqmu/iIS7zsKGlxSxu3ZZSeqshQCMdHFRLUZ/aExvEZkz4GQYTQVnqsZ26J3PlIqWfQTrA== X-Gm-Message-State: AOJu0Yxsnl9svqm558xrnNS5pEBy5A7DAbJ6y7/LXpbRtl8GSSjPGEHu OavgTVIempmEOQrmeGZCQE+rgctGrATz9cilrmT5GnnPT4m2dBFv X-Google-Smtp-Source: AGHT+IHLAKw3BD6hW5ivGm/rKmAEyFICvMjClcsYl5pfoB1uSKJ1pCOvw+uWJkH4jaFuzAcKq99lJQ== X-Received: by 2002:a05:6a00:1903:b0:6f0:b81f:af5b with SMTP id y3-20020a056a00190300b006f0b81faf5bmr6119136pfi.34.1714825754399; Sat, 04 May 2024 05:29:14 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.29.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:29:14 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 06/31] powerpc/sprs: Avoid taking PMU interrupts caused by register fuzzing Date: Sat, 4 May 2024 22:28:12 +1000 Message-ID: <20240504122841.1177683-7-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Storing certain values in MMCR0 can cause PMU interrupts when msleep enables MSR[EE], and this crashes the test. Freeze the PMU counters and clear any PMU exception before calling msleep. Reviewed-by: Thomas Huth Signed-off-by: Nicholas Piggin --- lib/powerpc/asm/reg.h | 4 ++++ powerpc/sprs.c | 17 +++++++++++------ 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/powerpc/asm/reg.h b/lib/powerpc/asm/reg.h index 1f991288e..c80b32059 100644 --- a/lib/powerpc/asm/reg.h +++ b/lib/powerpc/asm/reg.h @@ -24,6 +24,10 @@ #define PVR_VER_POWER10 UL(0x00800000) #define SPR_HSRR0 0x13a #define SPR_HSRR1 0x13b +#define SPR_MMCR0 0x31b +#define MMCR0_FC UL(0x80000000) +#define MMCR0_PMAE UL(0x04000000) +#define MMCR0_PMAO UL(0x00000080) /* Machine State Register definitions: */ #define MSR_EE_BIT 15 /* External Interrupts Enable */ diff --git a/powerpc/sprs.c b/powerpc/sprs.c index a6588ca63..c25dac1f6 100644 --- a/powerpc/sprs.c +++ b/powerpc/sprs.c @@ -476,12 +476,7 @@ static void set_sprs(uint64_t val) continue; if (sprs[i].type & SPR_HARNESS) continue; - if (!strcmp(sprs[i].name, "MMCR0")) { - /* XXX: could use a comment or better abstraction! */ - __mtspr(i, (val & 0xfffffffffbab3fffULL) | 0xfa0b2070); - } else { - __mtspr(i, val); - } + __mtspr(i, val); } } @@ -538,6 +533,16 @@ int main(int argc, char **argv) if (sprs[895].name) before[895] = mfspr(895); } else { + /* + * msleep will enable MSR[EE] and take a decrementer + * interrupt. Must account for changed registers and + * prevent taking unhandled interrupts. + */ + /* Prevent PMU interrupt */ + mtspr(SPR_MMCR0, (mfspr(SPR_MMCR0) | MMCR0_FC) & + ~(MMCR0_PMAO | MMCR0_PMAE)); + before[SPR_MMCR0] = mfspr(SPR_MMCR0); + before[779] = mfspr(SPR_MMCR0); msleep(2000); /* Reload regs changed by dec interrupt */ From patchwork Sat May 4 12:28:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931275 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=ibDglOUS; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWnDQ3XL9z1yb7 for ; Sat, 4 May 2024 22:34:30 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=ibDglOUS; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWnDP5C8jz3cT3 for ; Sat, 4 May 2024 22:34:29 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=ibDglOUS; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42a; helo=mail-pf1-x42a.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn6R4zqqz30WP for ; Sat, 4 May 2024 22:29:19 +1000 (AEST) Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6ee13f19e7eso479364b3a.1 for ; Sat, 04 May 2024 05:29:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825758; x=1715430558; darn=lists.ozlabs.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=uGMJSfkN2PfJHtxLiOclIw2fyyzbggN8HHskSwcg0zA=; b=ibDglOUS5wike1/kezZY+Mi1rSp+4SXIiT7fcRqZCQF8OwtpEMCufkyKq5UvpxOcue TyRF922DdpMe5GtSP2ksf8aEdjuQ0GkR7pJ20B4IIUGXJbOpv6YpJzIqprk2Dfr5I1Tq V5PQqzouZkrL2qTWniYjKwHyt8+RiIa9ae/b+Kc9D+8MX7O4jZVBWsa2ZJ/4Kb3bxpmM q/nRtizldbaE+hXHVsn7cCzjDUZ/SaeK7FM1aLXky/znA47iP8skM9rtUOP0shUsJlDG EMdoZpeUK8Yx/tCEZMWZYxt0HWcAqThlWKo8Qn5KCnN0MjjCD95L2ZznuVuh2qwSJdkx jduA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825758; x=1715430558; 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=uGMJSfkN2PfJHtxLiOclIw2fyyzbggN8HHskSwcg0zA=; b=P9AvWb8lGviZzfFZYOOcll8Ax29BE3RkhlU/VmtxXZrFlMfcJioaB14EWcICy1qfdb svD/3FiDmpw8SdFOxkS8NEPtkuwMQIbG5+bDm3JechB4rJ0t4f+MlhWaYpWAjZViC+/y 9FH5cFugeAT4J1hztcSy9tQS7iDdk43NltWc2AUGJGwB36WbNZS0H/b5mfiNPc79sJPs eCRwKafVdsN6Mf3ukpyji3StFkoCubYCHlIUnofLHAWuRMYHYQu+ettqnukaOLdcijoE YA3xsOoOq1uPfi5p0tkQKvdoej16reHu5Ivj7eO6BX+SKyY0FQPWdcaRCaQPxdPDng6N Z17Q== X-Forwarded-Encrypted: i=1; AJvYcCVdzFFaODdBRmPt5D6uyhQPrWvinRNwZBcGSf2ISKi8A6bJua3mU00J4ZatLfHfm2yo72vtN3vR8heC4zUg5Fy6Vujoz4HCFfd+YB2wpg== X-Gm-Message-State: AOJu0YwguQlNiE7mHodQa8qdPJiE5pHNyAeg9kpWgZXgD9Ge1m/878MO THpoa6oB1K4IfubOBShlI7Y192KqqWJNXBJqvyE/3VDk0Np+dyqh X-Google-Smtp-Source: AGHT+IF4Gwv3VCJ87TdHGNnmmkZNl82UF42Fzg7O1j26MYNkfF8j7hnGLUzlLI5XVds3TNEaAqZ0bg== X-Received: by 2002:a05:6a00:4e4e:b0:6f4:5531:7ce4 with SMTP id gu14-20020a056a004e4e00b006f455317ce4mr2694549pfb.33.1714825757985; Sat, 04 May 2024 05:29:17 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.29.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:29:17 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 07/31] scripts: allow machine option to be specified in unittests.cfg Date: Sat, 4 May 2024 22:28:13 +1000 Message-ID: <20240504122841.1177683-8-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" This allows different machines with different requirements to be supported by run_tests.sh, similarly to how different accelerators are handled. Acked-by: Thomas Huth Acked-by: Andrew Jones Signed-off-by: Nicholas Piggin --- docs/unittests.txt | 7 +++++++ scripts/common.bash | 8 ++++++-- scripts/runtime.bash | 16 ++++++++++++---- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/docs/unittests.txt b/docs/unittests.txt index 7cf2c55ad..6449efd78 100644 --- a/docs/unittests.txt +++ b/docs/unittests.txt @@ -42,6 +42,13 @@ For / directories that support multiple architectures, this restricts the test to the specified arch. By default, the test will run on any architecture. +machine +------- +For those architectures that support multiple machine types, this restricts +the test to the specified machine. By default, the test will run on +any machine type. (Note, the machine can be specified with the MACHINE= +environment variable, and defaults to the architecture's default.) + smp --- smp = diff --git a/scripts/common.bash b/scripts/common.bash index 5e9ad53e2..3aa557c8c 100644 --- a/scripts/common.bash +++ b/scripts/common.bash @@ -10,6 +10,7 @@ function for_each_unittest() local opts local groups local arch + local machine local check local accel local timeout @@ -21,7 +22,7 @@ function for_each_unittest() if [[ "$line" =~ ^\[(.*)\]$ ]]; then rematch=${BASH_REMATCH[1]} if [ -n "${testname}" ]; then - $(arch_cmd) "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout" + $(arch_cmd) "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$machine" "$check" "$accel" "$timeout" fi testname=$rematch smp=1 @@ -29,6 +30,7 @@ function for_each_unittest() opts="" groups="" arch="" + machine="" check="" accel="" timeout="" @@ -58,6 +60,8 @@ function for_each_unittest() groups=${BASH_REMATCH[1]} elif [[ $line =~ ^arch\ *=\ *(.*)$ ]]; then arch=${BASH_REMATCH[1]} + elif [[ $line =~ ^machine\ *=\ *(.*)$ ]]; then + machine=${BASH_REMATCH[1]} elif [[ $line =~ ^check\ *=\ *(.*)$ ]]; then check=${BASH_REMATCH[1]} elif [[ $line =~ ^accel\ *=\ *(.*)$ ]]; then @@ -67,7 +71,7 @@ function for_each_unittest() fi done if [ -n "${testname}" ]; then - $(arch_cmd) "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout" + $(arch_cmd) "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$machine" "$check" "$accel" "$timeout" fi exec {fd}<&- } diff --git a/scripts/runtime.bash b/scripts/runtime.bash index 177b62166..0c96d6ea2 100644 --- a/scripts/runtime.bash +++ b/scripts/runtime.bash @@ -32,7 +32,7 @@ premature_failure() get_cmdline() { local kernel=$1 - echo "TESTNAME=$testname TIMEOUT=$timeout ACCEL=$accel $RUNTIME_arch_run $kernel -smp $smp $opts" + echo "TESTNAME=$testname TIMEOUT=$timeout MACHINE=$machine ACCEL=$accel $RUNTIME_arch_run $kernel -smp $smp $opts" } skip_nodefault() @@ -80,9 +80,10 @@ function run() local kernel="$4" local opts="$5" local arch="$6" - local check="${CHECK:-$7}" - local accel="$8" - local timeout="${9:-$TIMEOUT}" # unittests.cfg overrides the default + local machine="$7" + local check="${CHECK:-$8}" + local accel="$9" + local timeout="${10:-$TIMEOUT}" # unittests.cfg overrides the default if [ "${CONFIG_EFI}" == "y" ]; then kernel=${kernel/%.flat/.efi} @@ -116,6 +117,13 @@ function run() return 2 fi + if [ -n "$machine" ] && [ -n "$MACHINE" ] && [ "$machine" != "$MACHINE" ]; then + print_result "SKIP" $testname "" "$machine only" + return 2 + elif [ -n "$MACHINE" ]; then + machine="$MACHINE" + fi + if [ -n "$accel" ] && [ -n "$ACCEL" ] && [ "$accel" != "$ACCEL" ]; then print_result "SKIP" $testname "" "$accel only, but ACCEL=$ACCEL" return 2 From patchwork Sat May 4 12:28:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931276 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=QvKNcIvV; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWnFC304mz1ybC for ; Sat, 4 May 2024 22:35:11 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=QvKNcIvV; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWnFB6cFcz3fp5 for ; Sat, 4 May 2024 22:35:10 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=QvKNcIvV; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42a; helo=mail-pf1-x42a.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn6W2jZRz30Ty for ; Sat, 4 May 2024 22:29:23 +1000 (AEST) Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6f447976de7so456803b3a.1 for ; Sat, 04 May 2024 05:29:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825762; x=1715430562; darn=lists.ozlabs.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=Z2oN58zMGF7viCDdv81NUvK9SW9hozVqH9VBnYqZITI=; b=QvKNcIvVVN4pI0yGHj0BcQV3KIaLPWZXwTF67MyfYPsvi6jCB25PyoDP3bEd5odZoJ ghTxVx1bQhwPGCNDuo3lJ2nJB9wXo4Y18d2gNNoPuAdFN3CWEq7YZJkQ547/FwuCttlk vZv7aK2UAEG47o9TN/oQ+Ucm2U5ySfbOBJ1HfBbDeAIBIwt4EfbnMDT/73ubgToJXpb4 44tq8ob8B7qmsFm8BIEN/jWcGS8C+5rkrzNJ59tjYr6lepkWfdUTyfYZBSrerQ/2hDuI Ye4azxEer2YTWOvI/3HSRwT8FtxQYlehSPi3DCNkJO2nXh2MI40bDKgAvEdxE0b6NVe7 VzKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825762; x=1715430562; 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=Z2oN58zMGF7viCDdv81NUvK9SW9hozVqH9VBnYqZITI=; b=vKGPLEiGtgByLtVmL6RXWOOftOMHa/fXzwYRE/z/O5tTzLpoK8TqImT8umLk92a4Fc VUU8lM0RTbdsE936hY0UAhJNatf82N+LRXUM24pveb77XVntCa0z8/KEUYEpzpQ0B7Q7 L2UQMGQ0D9Flg18buy/v83FYK7wpbxpDmAututJtGFxkySYLhJNQuAkNt/ZQH5FRekTK k5ofWmtlGGptV/CdK5eTbtxyV/fyHU8zOpTRi0oraWH7OksJnYqG3Lm9rQI7J0A8F2Sz TsviGMcDzTe/VvpjoLqC/KWkd1e00bMJgwMaaVvK8++MP97N/wsbFkZvv3niOFx6zgeJ e0Ew== X-Forwarded-Encrypted: i=1; AJvYcCV0RvhrEZRh8QjIcMmsKO9SXdMhelDR0nAI3kyQEm6zEy+ImL+CNSp7+tnnnrx/hLlASxo17WvdxVWjWwR6lKYgsZRP6WYLOD3jsnxHyw== X-Gm-Message-State: AOJu0Yz6CcjRvcwdOhAfw+9seeOYXWOEljhfHUlWY+jZmc89EJtuHgmu Uu2hVss2vWRmXU257ghXqInDMd2IsdFyC3+KdEtBJZrBR+yQXWTO X-Google-Smtp-Source: AGHT+IFpF2KbAJADbX+vvZ9NgIXRALb0JcOtlo9568C/7j2tvWKU/CYfftgPnveWWLcunWzlgXYF+A== X-Received: by 2002:a05:6a20:8410:b0:1ae:3f11:328e with SMTP id c16-20020a056a20841000b001ae3f11328emr5818088pzd.20.1714825761811; Sat, 04 May 2024 05:29:21 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.29.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:29:21 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 08/31] scripts: Accommodate powerpc powernv machine differences Date: Sat, 4 May 2024 22:28:14 +1000 Message-ID: <20240504122841.1177683-9-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" The QEMU powerpc powernv machine has minor differences that must be accommodated for in output parsing: - Summary parsing must search more lines of output for the summary line, to accommodate OPAL message on shutdown. - Premature failure testing must tolerate case differences in kernel load error message. Acked-by: Thomas Huth Signed-off-by: Nicholas Piggin --- powerpc/unittests.cfg | 1 + scripts/runtime.bash | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index 699736926..f562de9f4 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -4,6 +4,7 @@ # powerpc specifics: # # file = .elf # powerpc uses .elf files +# machine = pseries|powernv ############################################################################## # diff --git a/scripts/runtime.bash b/scripts/runtime.bash index 0c96d6ea2..4b9c7d6b7 100644 --- a/scripts/runtime.bash +++ b/scripts/runtime.bash @@ -9,7 +9,7 @@ FAIL() { echo -ne "\e[31mFAIL\e[0m"; } extract_summary() { local cr=$'\r' - tail -3 | grep '^SUMMARY: ' | sed 's/^SUMMARY: /(/;s/'"$cr"'\{0,1\}$/)/' + tail -5 | grep '^SUMMARY: ' | sed 's/^SUMMARY: /(/;s/'"$cr"'\{0,1\}$/)/' } # We assume that QEMU is going to work if it tried to load the kernel @@ -20,7 +20,9 @@ premature_failure() log="$(eval "$(get_cmdline _NO_FILE_4Uhere_)" 2>&1)" echo "$log" | grep "_NO_FILE_4Uhere_" | - grep -q -e "could not \(load\|open\) kernel" -e "error loading" -e "failed to load" && + grep -q -e "[Cc]ould not \(load\|open\) kernel" \ + -e "error loading" \ + -e "failed to load" && return 1 RUNTIME_log_stderr <<< "$log" From patchwork Sat May 4 12:28:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931277 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=YnF4duor; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWnG01PBkz1ybC for ; Sat, 4 May 2024 22:35:52 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=YnF4duor; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWnG003QTz3dWj for ; Sat, 4 May 2024 22:35:52 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=YnF4duor; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::529; helo=mail-pg1-x529.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn6c0ZHKz3bYR for ; Sat, 4 May 2024 22:29:27 +1000 (AEST) Received: by mail-pg1-x529.google.com with SMTP id 41be03b00d2f7-6123726725eso400383a12.3 for ; Sat, 04 May 2024 05:29:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825765; x=1715430565; darn=lists.ozlabs.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=r9wVHOUiFuog5OIFLP44RsGdYC/kxyjt4DqnIsx+VeE=; b=YnF4duorSEXNaG7StK89jkeHGTPV+KuR6J6nTVKYrmgVce+cmjiA0/LTDL6dqrgI/C bglKL5oVkuplKLl7Cl7zvxi1O26NkkUU5vapyTnD5Xheye4xdyz3GYettWrfamPIF7vj jqiO6ELcpo4hH+4znB2wInEYK3TEB9rCr1rMz1LRJMcJ52ZdzNBzTSbpivK9gUL30cQ+ ag5jLnof7MF2Qka3JVGet/THpe9+XHsyL12P5gyCLCwtYfxrgWOXubZwNg+wulSmUFSW tON31VQNz2h0rlV++IRcn4ZF1oiXnKNuuxGxohKLrAuI/yUcbVCu2CuZ5pD0gHR8S4Rl kjMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825765; x=1715430565; 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=r9wVHOUiFuog5OIFLP44RsGdYC/kxyjt4DqnIsx+VeE=; b=rbz7gWyZStfDT+xuq6MQujoj4hzfEFslfmLhdbXo6Xa9FevqfsDrx0/3ytIsWuJqam SFiEeu2ruOHiIdoCA3nVvwpOeJ/VWg3iRog4S6JVnXr/M68oeTEastvabaKE4oOgOGRp yqUp196C7CcHIed1VbWtvT2L6SBAXvyz/NObs9tNDm/igNOL4TXPeduEdIKFbKrkrLaX WHZHbq75PuFQelG0+SYODsY7af3gzJVuIcUWlGeZigtC0VPY1Rnfo6KOyEU+U4znpciN ymdCOwZD8bwlTYLcbpHtWqoze88WZcr1n8kfC5vfDiFfQh/Pa3zcpiySsULlX+LfYjQR PFhw== X-Forwarded-Encrypted: i=1; AJvYcCUZuIWVj1hKKRWNbcpIjqPtztJwTGdVUiEK8D/Lay0XQDP5ran4UKnJx4AWR3tHW7hbu7uBuh6sY19IZ41D9J6UPqW7kf7J8DmVjKpnPg== X-Gm-Message-State: AOJu0Yw4TBiLNg7IwrtlPTAnEaxsYiwBTsn4EpAuqXm6jzwA90Qh5bMc FxMzVPZ0R2g7Uf4yM9oZPCO51+oMF2uXlf6S2vUdcI9V+0F2HCYy X-Google-Smtp-Source: AGHT+IHfA4Xb8JsllR28KiImteg6H/Wy/clgxIKsTc6YYcfNx6r4yuSxYU7d9gfndPDLjG90pAWLiA== X-Received: by 2002:a05:6a20:9c97:b0:1af:9ee6:25c4 with SMTP id mj23-20020a056a209c9700b001af9ee625c4mr506833pzb.42.1714825765537; Sat, 04 May 2024 05:29:25 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.29.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:29:25 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 09/31] powerpc: Support powernv machine with QEMU TCG Date: Sat, 4 May 2024 22:28:15 +1000 Message-ID: <20240504122841.1177683-10-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , =?utf-8?q?C=C3=A9dric_Le_Goater?= , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Add support for QEMU's powernv machine. This uses standard firmware (skiboot) rather than a minimal firmware shim. Reviewed-by: Cédric Le Goater Signed-off-by: Nicholas Piggin --- lib/powerpc/asm/processor.h | 23 +++++++++++ lib/powerpc/asm/reg.h | 4 ++ lib/powerpc/hcall.c | 4 +- lib/powerpc/io.c | 27 ++++++++++++- lib/powerpc/io.h | 6 +++ lib/powerpc/processor.c | 37 ++++++++++++++++++ lib/powerpc/setup.c | 14 +++++-- lib/ppc64/asm/opal.h | 15 ++++++++ lib/ppc64/opal-calls.S | 50 ++++++++++++++++++++++++ lib/ppc64/opal.c | 76 +++++++++++++++++++++++++++++++++++++ powerpc/Makefile.ppc64 | 2 + powerpc/cstart64.S | 7 ++++ powerpc/run | 42 ++++++++++++++++---- powerpc/unittests.cfg | 10 ++++- 14 files changed, 301 insertions(+), 16 deletions(-) create mode 100644 lib/ppc64/asm/opal.h create mode 100644 lib/ppc64/opal-calls.S create mode 100644 lib/ppc64/opal.c diff --git a/lib/powerpc/asm/processor.h b/lib/powerpc/asm/processor.h index e415f9235..9d8061962 100644 --- a/lib/powerpc/asm/processor.h +++ b/lib/powerpc/asm/processor.h @@ -10,6 +10,8 @@ void handle_exception(int trap, void (*func)(struct pt_regs *, void *), void *); void do_handle_exception(struct pt_regs *regs); #endif /* __ASSEMBLY__ */ +extern bool cpu_has_hv; + static inline uint64_t mfspr(int nr) { uint64_t ret; @@ -38,4 +40,25 @@ static inline void mtmsr(uint64_t msr) asm volatile ("mtmsrd %[msr]" :: [msr] "r" (msr) : "memory"); } +/* + * This returns true on PowerNV / OPAL machines which run in hypervisor + * mode. False on pseries / PAPR machines that run in guest mode. + */ +static inline bool machine_is_powernv(void) +{ + return cpu_has_hv; +} + +/* + * This returns true on pseries / PAPR / KVM machines which run under a + * hypervisor or QEMU pseries machine. False for PowerNV / OPAL. + */ +static inline bool machine_is_pseries(void) +{ + return !machine_is_powernv(); +} + +void enable_mcheck(void); +void disable_mcheck(void); + #endif /* _ASMPOWERPC_PROCESSOR_H_ */ diff --git a/lib/powerpc/asm/reg.h b/lib/powerpc/asm/reg.h index c80b32059..782e75527 100644 --- a/lib/powerpc/asm/reg.h +++ b/lib/powerpc/asm/reg.h @@ -30,7 +30,11 @@ #define MMCR0_PMAO UL(0x00000080) /* Machine State Register definitions: */ +#define MSR_LE_BIT 0 #define MSR_EE_BIT 15 /* External Interrupts Enable */ +#define MSR_HV_BIT 60 /* Hypervisor mode */ #define MSR_SF_BIT 63 /* 64-bit mode */ +#define MSR_ME UL(0x1000) + #endif diff --git a/lib/powerpc/hcall.c b/lib/powerpc/hcall.c index b4d39ac65..45f201315 100644 --- a/lib/powerpc/hcall.c +++ b/lib/powerpc/hcall.c @@ -25,7 +25,7 @@ int hcall_have_broken_sc1(void) return r3 == (unsigned long)H_PRIVILEGE; } -void putchar(int c) +void papr_putchar(int c) { unsigned long vty = 0; /* 0 == default */ unsigned long nr_chars = 1; @@ -34,7 +34,7 @@ void putchar(int c) hcall(H_PUT_TERM_CHAR, vty, nr_chars, chars); } -int __getchar(void) +int __papr_getchar(void) { register unsigned long r3 asm("r3") = H_GET_TERM_CHAR; register unsigned long r4 asm("r4") = 0; /* 0 == default vty */ diff --git a/lib/powerpc/io.c b/lib/powerpc/io.c index a381688bc..ab7bb843c 100644 --- a/lib/powerpc/io.c +++ b/lib/powerpc/io.c @@ -9,13 +9,33 @@ #include #include #include +#include #include "io.h" static struct spinlock print_lock; +void putchar(int c) +{ + if (machine_is_powernv()) + opal_putchar(c); + else + papr_putchar(c); +} + +int __getchar(void) +{ + if (machine_is_powernv()) + return __opal_getchar(); + else + return __papr_getchar(); +} + void io_init(void) { - rtas_init(); + if (machine_is_powernv()) + assert(!opal_init()); + else + rtas_init(); } void puts(const char *s) @@ -38,7 +58,10 @@ void exit(int code) // FIXME: change this print-exit/rtas-poweroff to chr_testdev_exit(), // maybe by plugging chr-testdev into a spapr-vty. printf("\nEXIT: STATUS=%d\n", ((code) << 1) | 1); - rtas_power_off(); + if (machine_is_powernv()) + opal_power_off(); + else + rtas_power_off(); halt(code); __builtin_unreachable(); } diff --git a/lib/powerpc/io.h b/lib/powerpc/io.h index d4f21ba15..943bf142b 100644 --- a/lib/powerpc/io.h +++ b/lib/powerpc/io.h @@ -8,6 +8,12 @@ #define _POWERPC_IO_H_ extern void io_init(void); +extern int opal_init(void); +extern void opal_power_off(void); extern void putchar(int c); +extern void opal_putchar(int c); +extern void papr_putchar(int c); +extern int __opal_getchar(void); +extern int __papr_getchar(void); #endif diff --git a/lib/powerpc/processor.c b/lib/powerpc/processor.c index 114584024..1b4bb0d61 100644 --- a/lib/powerpc/processor.c +++ b/lib/powerpc/processor.c @@ -84,6 +84,16 @@ void sleep_tb(uint64_t cycles) { uint64_t start, end, now; + if (!machine_is_pseries()) { + /* + * P9/10 Could use 'stop' to sleep here which would be + * interesting. stop with ESL=0 should be simple enough, ESL=1 + * would require SRESET based wakeup which is more involved. + */ + delay(cycles); + return; + } + start = now = get_tb(); end = start + cycles; @@ -120,3 +130,30 @@ void usleep(uint64_t us) { sleep_tb((us * tb_hz) / 1000000); } + +static void rfid_msr(uint64_t msr) +{ + uint64_t tmp; + + asm volatile( + "mtsrr1 %1 \n\ + bl 0f \n\ + 0: \n\ + mflr %0 \n\ + addi %0,%0,1f-0b \n\ + mtsrr0 %0 \n\ + rfid \n\ + 1: \n" + : "=r"(tmp) : "r"(msr) : "lr"); +} + +void enable_mcheck(void) +{ + /* This is a no-op on pseries */ + rfid_msr(mfmsr() | MSR_ME); +} + +void disable_mcheck(void) +{ + rfid_msr(mfmsr() & ~MSR_ME); +} diff --git a/lib/powerpc/setup.c b/lib/powerpc/setup.c index d98f66fae..89e5157f2 100644 --- a/lib/powerpc/setup.c +++ b/lib/powerpc/setup.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include "io.h" @@ -85,6 +86,8 @@ static void cpu_set(int fdtnode, u64 regval, void *info) } } +bool cpu_has_hv; + static void cpu_init(void) { struct cpu_set_params params; @@ -98,12 +101,13 @@ static void cpu_init(void) tb_hz = params.tb_hz; /* Interrupt Endianness */ - + if (machine_is_pseries()) { #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ - hcall(H_SET_MODE, 1, 4, 0, 0); + hcall(H_SET_MODE, 1, 4, 0, 0); #else - hcall(H_SET_MODE, 0, 4, 0, 0); + hcall(H_SET_MODE, 0, 4, 0, 0); #endif + } } static void mem_init(phys_addr_t freemem_start) @@ -159,6 +163,10 @@ void setup(const void *fdt) u32 fdt_size; int ret; + cpu_has_hv = !!(mfmsr() & (1ULL << MSR_HV_BIT)); + + enable_mcheck(); + /* * Before calling mem_init we need to move the fdt and initrd * to safe locations. We move them to construct the memory diff --git a/lib/ppc64/asm/opal.h b/lib/ppc64/asm/opal.h new file mode 100644 index 000000000..de64e2c8d --- /dev/null +++ b/lib/ppc64/asm/opal.h @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef _ASMPPC64_OPAL_H_ +#define _ASMPPC64_OPAL_H_ + +#define OPAL_SUCCESS 0 + +#define OPAL_CONSOLE_WRITE 1 +#define OPAL_CONSOLE_READ 2 +#define OPAL_CEC_POWER_DOWN 5 +#define OPAL_POLL_EVENTS 10 +#define OPAL_REINIT_CPUS 70 +# define OPAL_REINIT_CPUS_HILE_BE (1 << 0) +# define OPAL_REINIT_CPUS_HILE_LE (1 << 1) + +#endif diff --git a/lib/ppc64/opal-calls.S b/lib/ppc64/opal-calls.S new file mode 100644 index 000000000..8cb4c3e91 --- /dev/null +++ b/lib/ppc64/opal-calls.S @@ -0,0 +1,50 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (c) 2016 IBM Corporation. + */ + +#include + + .text + .globl opal_call +opal_call: + mr r0,r3 + mr r3,r4 + mr r4,r5 + mr r5,r6 + mr r6,r7 + mflr r11 + std r11,16(r1) + mfcr r12 + stw r12,8(r1) + std r2,-8(r1) /* use redzone */ + + /* Set opal return address */ + LOAD_REG_ADDR(r11, opal_return) + mtlr r11 + mfmsr r12 + std r12,-16(r1) /* use redzone */ + + /* switch to BE when we enter OPAL */ + li r11,(1 << MSR_LE_BIT) + ori r11,r11,(1 << MSR_EE_BIT) + andc r12,r12,r11 + mtspr SPR_HSRR1,r12 + + /* load the opal call entry point and base */ + LOAD_REG_ADDR(r11, opal) + ld r12,8(r11) + ld r2,0(r11) + mtspr SPR_HSRR0,r12 + hrfid + +opal_return: + FIXUP_ENDIAN + ld r12,-16(r1) /* use redzone */ + mtmsrd r12 + ld r2,-8(r1) /* use redzone */ + lwz r11,8(r1); + ld r12,16(r1) + mtcr r11; + mtlr r12 + blr diff --git a/lib/ppc64/opal.c b/lib/ppc64/opal.c new file mode 100644 index 000000000..63fe42ae6 --- /dev/null +++ b/lib/ppc64/opal.c @@ -0,0 +1,76 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * OPAL call helpers + */ +#include +#include +#include +#include +#include +#include "../powerpc/io.h" + +struct opal { + uint64_t base; + uint64_t entry; +} opal; + +extern int64_t opal_call(int64_t token, int64_t arg1, int64_t arg2, int64_t arg3); + +int opal_init(void) +{ + const struct fdt_property *prop; + int node, len; + + node = fdt_path_offset(dt_fdt(), "/ibm,opal"); + if (node < 0) + return -1; + + prop = fdt_get_property(dt_fdt(), node, "opal-base-address", &len); + if (!prop) + return -1; + opal.base = fdt64_to_cpu(*(uint64_t *)prop->data); + + prop = fdt_get_property(dt_fdt(), node, "opal-entry-address", &len); + if (!prop) + return -1; + opal.entry = fdt64_to_cpu(*(uint64_t *)prop->data); + +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + if (opal_call(OPAL_REINIT_CPUS, OPAL_REINIT_CPUS_HILE_LE, 0, 0) != OPAL_SUCCESS) + return -1; +#endif + + return 0; +} + +extern void opal_power_off(void) +{ + opal_call(OPAL_CEC_POWER_DOWN, 0, 0, 0); + while (true) + opal_call(OPAL_POLL_EVENTS, 0, 0, 0); +} + +void opal_putchar(int c) +{ + unsigned long vty = 0; /* 0 == default */ + unsigned long nr_chars = cpu_to_be64(1); + char ch = c; + + opal_call(OPAL_CONSOLE_WRITE, (int64_t)vty, (int64_t)&nr_chars, (int64_t)&ch); +} + +int __opal_getchar(void) +{ + unsigned long vty = 0; /* 0 == default */ + unsigned long nr_chars = cpu_to_be64(1); + char ch; + int rc; + + rc = opal_call(OPAL_CONSOLE_READ, (int64_t)vty, (int64_t)&nr_chars, (int64_t)&ch); + if (rc != OPAL_SUCCESS) + return -1; + if (nr_chars == 0) + return -1; + + return ch; +} diff --git a/powerpc/Makefile.ppc64 b/powerpc/Makefile.ppc64 index eb682c226..a18a9628f 100644 --- a/powerpc/Makefile.ppc64 +++ b/powerpc/Makefile.ppc64 @@ -18,6 +18,8 @@ reloc.o = $(TEST_DIR)/reloc64.o OBJDIRS += lib/ppc64 cflatobjs += lib/ppc64/stack.o +cflatobjs += lib/ppc64/opal.o +cflatobjs += lib/ppc64/opal-calls.o # ppc64 specific tests tests = $(TEST_DIR)/spapr_vpa.elf diff --git a/powerpc/cstart64.S b/powerpc/cstart64.S index 07d297f61..405cb0561 100644 --- a/powerpc/cstart64.S +++ b/powerpc/cstart64.S @@ -97,6 +97,13 @@ start: sync isync + /* powernv machine does not check broken_sc1 */ + mfmsr r3 + li r4,1 + sldi r4,r4,MSR_HV_BIT + and. r3,r3,r4 + bne 1f + /* patch sc1 if needed */ bl hcall_have_broken_sc1 cmpwi r3, 0 diff --git a/powerpc/run b/powerpc/run index 5cdb94194..172f32a46 100755 --- a/powerpc/run +++ b/powerpc/run @@ -1,5 +1,14 @@ #!/usr/bin/env bash +get_qemu_machine () +{ + if [ "$MACHINE" ]; then + echo $MACHINE + else + echo pseries + fi +} + if [ -z "$KUT_STANDALONE" ]; then if [ ! -f config.mak ]; then echo "run ./configure && make first. See ./configure -h" @@ -11,24 +20,41 @@ fi set_qemu_accelerator || exit $? +MACHINE=$(get_qemu_machine) || + exit $? + +if [[ "$MACHINE" == "powernv"* ]] && [ "$ACCEL" = "kvm" ]; then + echo "PowerNV machine does not support KVM. ACCEL=tcg must be specified." + exit 2 +fi + qemu=$(search_qemu_binary) || exit $? -if ! $qemu -machine '?' 2>&1 | grep 'pseries' > /dev/null; then - echo "$qemu doesn't support pSeries ('-machine pseries'). Exiting." +if ! $qemu -machine '?' 2>&1 | grep $MACHINE > /dev/null; then + echo "$qemu doesn't support '-machine $MACHINE'. Exiting." exit 2 fi -M='-machine pseries' +M="-machine $MACHINE" M+=",accel=$ACCEL$ACCEL_PROPS" +B="" +D="" + +if [[ "$MACHINE" == "pseries"* ]] ; then + if [[ "$ACCEL" == "tcg" ]] ; then + M+=",cap-cfpc=broken,cap-sbbc=broken,cap-ibs=broken,cap-ccf-assist=off" + elif [[ "$ACCEL" == "kvm" ]] ; then + M+=",cap-ccf-assist=off" + fi + B+="-bios $FIRMWARE" +fi -if [[ "$ACCEL" == "tcg" ]] ; then - M+=",cap-cfpc=broken,cap-sbbc=broken,cap-ibs=broken,cap-ccf-assist=off" -elif [[ "$ACCEL" == "kvm" ]] ; then - M+=",cap-ccf-assist=off" +if [[ "$MACHINE" == "powernv"* ]] ; then + D+="-device ipmi-bmc-sim,id=bmc0 -device isa-ipmi-bt,bmc=bmc0,irq=10" fi -command="$qemu -nodefaults $M -bios $FIRMWARE" +command="$qemu -nodefaults $M $B $D" command+=" -display none -serial stdio -kernel" command="$(migration_cmd) $(timeout_cmd) $command" diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index f562de9f4..4c0c6ddea 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -15,11 +15,12 @@ [selftest-setup] file = selftest.elf smp = 2 -extra_params = -m 256 -append 'setup smp=2 mem=256' +extra_params = -m 1g -append 'setup smp=2 mem=1024' groups = selftest [selftest-migration] file = selftest-migration.elf +machine = pseries groups = selftest migration [selftest-migration-skip] @@ -35,24 +36,29 @@ groups = migration [spapr_hcall] file = spapr_hcall.elf +machine = pseries [spapr_vpa] file = spapr_vpa.elf +machine = pseries [rtas-get-time-of-day] file = rtas.elf +machine = pseries timeout = 5 extra_params = -append "get-time-of-day date=$(date +%s)" groups = rtas [rtas-get-time-of-day-base] file = rtas.elf +machine = pseries timeout = 5 extra_params = -rtc base="2006-06-17" -append "get-time-of-day date=$(date --date="2006-06-17 UTC" +%s)" groups = rtas [rtas-set-time-of-day] file = rtas.elf +machine = pseries extra_params = -append "set-time-of-day" timeout = 5 groups = rtas @@ -62,6 +68,7 @@ file = emulator.elf [h_cede_tm] file = tm.elf +machine = pseries accel = kvm smp = 2,threads=2 extra_params = -machine cap-htm=on -append "h_cede_tm" @@ -72,5 +79,6 @@ file = sprs.elf [sprs-migration] file = sprs.elf +machine = pseries extra_params = -append '-w' groups = migration From patchwork Sat May 4 12:28:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931278 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=jkWOuQcK; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWnGw3qqZz1ybC for ; Sat, 4 May 2024 22:36:40 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=jkWOuQcK; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWnGv6qwWz3fQb for ; Sat, 4 May 2024 22:36:39 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=jkWOuQcK; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::433; helo=mail-pf1-x433.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn6h0KlNz30Vx for ; Sat, 4 May 2024 22:29:31 +1000 (AEST) Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6f44881ad9eso418564b3a.3 for ; Sat, 04 May 2024 05:29:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825770; x=1715430570; darn=lists.ozlabs.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=bnIgLQ4CEo3lVw3vLtU4xy1hTDqKssgefGwIrsqFLjM=; b=jkWOuQcKPjEmksCXFe9h8VhGjyXc4LrjxxeJPrfqzE9Q2i5i0H77mxn8NesJ47bbkw gTlH4Md+MrHBbYzCGsYSQDdusTvg30436Ale/sE4qA+dpxzFP/5mfSwlC7GsAMrFGZbl VmFR4xxatQvT86Ba2r9XKEC178Vz92PvLyfN0bdfAMumGL2fXvx1IqM5AR0RipSCNX8y vbN5kOR8zEctJddE52SFUpkfWbeHZfDIzoF5h3puOxQQUEpcZWpAa1Y4+WVXSqisvxV3 8MZ4zjY/F49dI0c1ZjnDkZWPjZFmW4mO+S0p6T4S+/TcBny037wn+xMpO056BUs1Slug 8k4Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825770; x=1715430570; 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=bnIgLQ4CEo3lVw3vLtU4xy1hTDqKssgefGwIrsqFLjM=; b=YJIqCF+Mx+Q+2ePPj7Y0G1FxxvT99BkkZW4o9rReyYFyFn+3HRlbP+PUno2dttVZwW k6rE7mtDY+Yic7Bm5tgoutgE3A5Z8pg7p6r65kpGPge33kBVVmgY6c6vZA3mqqVYQRZe 0bD+e+1jMF/vJwO+F3zf+Z3JRzvvl6H7Y9BbVp6MWAQFBWuzEDPOJa1GiP7XfTkICbK0 P0u5Mw9cFm9hnVBTnQ2boKJqgR/YeTACXDXYOHkcJNZRsgwq8LhnVQluzumKsCCoqdbK 6ut5L7QIyKyRMjGAFUivtlrOGHFUuffGreatn+dtNTpZ6x9PT5LIjdqPpUZjh7Exl3tu Nbyg== X-Forwarded-Encrypted: i=1; AJvYcCXddbjXkPknOX+kKKHvu9b9HlI35AS4yrbMMCe3tyNm76kEUQx0I/0Wkg81rrBhfj94dRbP0c45AIXyc2p7/utU+DMKGNH8LJqFPTS7eQ== X-Gm-Message-State: AOJu0YxcJPGAVVJUNeFa5sGJv0aRVtR+jWhSZGTP4xSUCnHUNEgUqWQM sXtj/YD+FIuJRf53PjmmxzFbmTGpGp19GRLFDafcFJuhtExW+8bO X-Google-Smtp-Source: AGHT+IHHrgaDs7cGEwfT9gLtgcGbdkXTEI61OdN8dRApxZSbjCEp8wy5hJY3mc5TL2hAOJ/4+IokuA== X-Received: by 2002:a05:6a00:3c81:b0:6ed:5f64:2ff4 with SMTP id lm1-20020a056a003c8100b006ed5f642ff4mr5933260pfb.14.1714825769608; Sat, 04 May 2024 05:29:29 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.29.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:29:28 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 10/31] powerpc: Fix emulator illegal instruction test for powernv Date: Sat, 4 May 2024 22:28:16 +1000 Message-ID: <20240504122841.1177683-11-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Illegal instructions cause 0xe40 (HEAI) interrupts rather than program interrupts. Acked-by: Thomas Huth Signed-off-by: Nicholas Piggin --- lib/powerpc/asm/processor.h | 1 + lib/powerpc/setup.c | 13 +++++++++++++ powerpc/emulator.c | 16 ++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/lib/powerpc/asm/processor.h b/lib/powerpc/asm/processor.h index 9d8061962..cf1b9d8ff 100644 --- a/lib/powerpc/asm/processor.h +++ b/lib/powerpc/asm/processor.h @@ -11,6 +11,7 @@ void do_handle_exception(struct pt_regs *regs); #endif /* __ASSEMBLY__ */ extern bool cpu_has_hv; +extern bool cpu_has_heai; static inline uint64_t mfspr(int nr) { diff --git a/lib/powerpc/setup.c b/lib/powerpc/setup.c index 89e5157f2..3c81aee9e 100644 --- a/lib/powerpc/setup.c +++ b/lib/powerpc/setup.c @@ -87,6 +87,7 @@ static void cpu_set(int fdtnode, u64 regval, void *info) } bool cpu_has_hv; +bool cpu_has_heai; static void cpu_init(void) { @@ -108,6 +109,18 @@ static void cpu_init(void) hcall(H_SET_MODE, 0, 4, 0, 0); #endif } + + switch (mfspr(SPR_PVR) & PVR_VERSION_MASK) { + case PVR_VER_POWER10: + case PVR_VER_POWER9: + case PVR_VER_POWER8E: + case PVR_VER_POWER8NVL: + case PVR_VER_POWER8: + cpu_has_heai = true; + break; + default: + break; + } } static void mem_init(phys_addr_t freemem_start) diff --git a/powerpc/emulator.c b/powerpc/emulator.c index 39dd59645..af5174944 100644 --- a/powerpc/emulator.c +++ b/powerpc/emulator.c @@ -31,6 +31,20 @@ static void program_check_handler(struct pt_regs *regs, void *opaque) regs->nip += 4; } +static void heai_handler(struct pt_regs *regs, void *opaque) +{ + int *data = opaque; + + if (verbose) { + printf("Detected invalid instruction %#018lx: %08x\n", + regs->nip, *(uint32_t*)regs->nip); + } + + *data = 8; /* Illegal instruction */ + + regs->nip += 4; +} + static void alignment_handler(struct pt_regs *regs, void *opaque) { int *data = opaque; @@ -363,6 +377,8 @@ int main(int argc, char **argv) int i; handle_exception(0x700, program_check_handler, (void *)&is_invalid); + if (cpu_has_heai) + handle_exception(0xe40, heai_handler, (void *)&is_invalid); handle_exception(0x600, alignment_handler, (void *)&alignment); for (i = 1; i < argc; i++) { From patchwork Sat May 4 12:28:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931279 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=L8/bppBG; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWnHh5JvKz1ybC for ; Sat, 4 May 2024 22:37:20 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=L8/bppBG; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWnHh3y3mz3fSC for ; Sat, 4 May 2024 22:37:20 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=L8/bppBG; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::433; helo=mail-pf1-x433.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn6k6sdmz3c05 for ; Sat, 4 May 2024 22:29:34 +1000 (AEST) Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-6edb76d83d0so510995b3a.0 for ; Sat, 04 May 2024 05:29:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825773; x=1715430573; darn=lists.ozlabs.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=KL3WN/bxkH6E8862NdjfyN9j8TIYfGdUkTmziJ3+E+4=; b=L8/bppBGDedqWORw6n6X+0PeoYlsHX/Cvyee04UkQNFT2rMRj6hh8iU/tX3vaT7Ers T7e52xZkQo3AeSNL0He3qJP95ZN0A4Sj8qWUf/p9EmcdfFeWADpsLvv8Enf39ctfmE10 pujPElNMasViiBUss1192VAYjge3ESbCyCzcKVa9i/gIy/df4skbHJ3q82lrRwMPmmzT uODP+yYQUXi+mZWhfDWWDLGc5IY6ooFPVhyIyS/U49hysJQQHtBTQSXIJxAjQPgNjQQ0 8Go5nHGQQf6baKt021KrekPHTB/dgE8S7swU6Dxwh9LPcjnxCB3xFqM9v7QQR+FwFkrW Jo3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825773; x=1715430573; 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=KL3WN/bxkH6E8862NdjfyN9j8TIYfGdUkTmziJ3+E+4=; b=YlJvzKyiLPKG+2XwMkNXOHtC+cd6Jq1Vx+TAID8pzm0oDelLkcXhmn7515QDacI+G7 ZORbb8AusAuhccgQq+3PxfgmKY/PS7ixqB/j+oEjSBV/UnfX9nQRa+JDX79NPLFzSrZX ate8ztFYrEPAfRmGgDAGfmB18XP+0Z3YDTNjKjnDf1tvs+pwnZfQ6LBBgKvHSst0FyOv p3+mv/AhP06y5G27B+EqO8Rg6ZCEzFRjEZkISesnZGiOBmwYe+a6HTfbr/5pPJTzJMKa X8oIuYye1kd6nGDDEXo0XUAs/9XP6rwdjNecRjLXj6AshoSSeUJ5H6zDeGVwYQ7tRRmd In+A== X-Forwarded-Encrypted: i=1; AJvYcCXJXfhQjsZ/b4wWIrtyEbw13d1Tt7+M7dKxnsli3WnHGt43kOlEtFQc7Lbs5xzyx1VVc/zemBG8JhybIKZnhPcGAP+PiwQxNgnpLNhZaQ== X-Gm-Message-State: AOJu0YwOqV0g1I9KqoDrA4Aez67s3RIcwLOWrqTxaVpLN8aZ0nOObKAX joaR5jVKuymagiN/p5Qsou6Wz45v8SJa3kbJTMnrdMDGsos8vEe3 X-Google-Smtp-Source: AGHT+IHBmXjDuf4tcSq4Go5iahY4Ba3kc5TDtYi/Y0fd6Oj+KY7AD/7pfPGXye/+vZmLqeCSyja2UQ== X-Received: by 2002:a05:6a20:12cb:b0:1aa:340e:237e with SMTP id v11-20020a056a2012cb00b001aa340e237emr6790296pzg.59.1714825773410; Sat, 04 May 2024 05:29:33 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.29.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:29:32 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 11/31] powerpc/sprs: Test hypervisor registers on powernv machine Date: Sat, 4 May 2024 22:28:17 +1000 Message-ID: <20240504122841.1177683-12-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" This enables HV privilege registers to be tested with the powernv machine. Acked-by: Thomas Huth Signed-off-by: Nicholas Piggin --- powerpc/sprs.c | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/powerpc/sprs.c b/powerpc/sprs.c index c25dac1f6..de9e87a21 100644 --- a/powerpc/sprs.c +++ b/powerpc/sprs.c @@ -199,16 +199,16 @@ static const struct spr sprs_power_common[1024] = { [190] = { "HFSCR", 64, HV_RW, }, [256] = { "VRSAVE", 32, RW, }, [259] = { "SPRG3", 64, RO, }, -[284] = { "TBL", 32, HV_WO, }, -[285] = { "TBU", 32, HV_WO, }, -[286] = { "TBU40", 64, HV_WO, }, +[284] = { "TBL", 32, HV_WO, }, /* Things can go a bit wonky with */ +[285] = { "TBU", 32, HV_WO, }, /* Timebase changing. Should save */ +[286] = { "TBU40", 64, HV_WO, }, /* and restore it. */ [304] = { "HSPRG0", 64, HV_RW, }, [305] = { "HSPRG1", 64, HV_RW, }, [306] = { "HDSISR", 32, HV_RW, SPR_INT, }, [307] = { "HDAR", 64, HV_RW, SPR_INT, }, [308] = { "SPURR", 64, HV_RW | OS_RO, SPR_ASYNC, }, [309] = { "PURR", 64, HV_RW | OS_RO, SPR_ASYNC, }, -[313] = { "HRMOR", 64, HV_RW, }, +[313] = { "HRMOR", 64, HV_RW, SPR_HARNESS, }, /* Harness can't cope with HRMOR changing */ [314] = { "HSRR0", 64, HV_RW, SPR_INT, }, [315] = { "HSRR1", 64, HV_RW, SPR_INT, }, [318] = { "LPCR", 64, HV_RW, }, @@ -306,7 +306,7 @@ static const struct spr sprs_power9_10[1024] = { [921] = { "TSCR", 32, HV_RW, }, [922] = { "TTR", 64, HV_RW, }, [1006]= { "TRACE", 64, WO, }, -[1008]= { "HID", 64, HV_RW, }, +[1008]= { "HID", 64, HV_RW, SPR_HARNESS, }, /* HILE would be unhelpful to change */ }; /* This covers POWER8 and POWER9 PMUs */ @@ -350,6 +350,22 @@ static const struct spr sprs_power10_pmu[1024] = { static struct spr sprs[1024]; +static bool spr_read_perms(int spr) +{ + if (cpu_has_hv) + return !!(sprs[spr].access & SPR_HV_READ); + else + return !!(sprs[spr].access & SPR_OS_READ); +} + +static bool spr_write_perms(int spr) +{ + if (cpu_has_hv) + return !!(sprs[spr].access & SPR_HV_WRITE); + else + return !!(sprs[spr].access & SPR_OS_WRITE); +} + static void setup_sprs(void) { int i; @@ -461,7 +477,7 @@ static void get_sprs(uint64_t *v) int i; for (i = 0; i < 1024; i++) { - if (!(sprs[i].access & SPR_OS_READ)) + if (!spr_read_perms(i)) continue; v[i] = __mfspr(i); } @@ -472,8 +488,9 @@ static void set_sprs(uint64_t val) int i; for (i = 0; i < 1024; i++) { - if (!(sprs[i].access & SPR_OS_WRITE)) + if (!spr_write_perms(i)) continue; + if (sprs[i].type & SPR_HARNESS) continue; __mtspr(i, val); @@ -561,7 +578,7 @@ int main(int argc, char **argv) for (i = 0; i < 1024; i++) { bool pass = true; - if (!(sprs[i].access & SPR_OS_READ)) + if (!spr_read_perms(i)) continue; if (sprs[i].width == 32) { From patchwork Sat May 4 12:28:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931280 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=d/+PbpqB; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWnJT4BNdz1ybC for ; Sat, 4 May 2024 22:38:01 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=d/+PbpqB; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWnJT1SS9z3dDh for ; Sat, 4 May 2024 22:38:01 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=d/+PbpqB; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42e; helo=mail-pf1-x42e.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn6q1vL7z3cFN for ; Sat, 4 May 2024 22:29:39 +1000 (AEST) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6f44b5e7f07so392082b3a.2 for ; Sat, 04 May 2024 05:29:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825778; x=1715430578; darn=lists.ozlabs.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=kavMBo8KNcRmoPwTE1Oe8y9GeM+kd+Ho3+bW4koygvQ=; b=d/+PbpqBpSHeIkADKjdy6H5TfEthBrOyuokQKIiFAyeESMBCzHOGbBrPrBsV8HxXJX usfP94STVg/r9yaZJ9Qz1DIzHNg0RYebGuzqeE0fJhFJ8VjZ1uVzBYWE5eTlYNik6JGK gq7bEA9qF448s3J7Cbf1Teow7aVHL4JbE9thogwI3aSH5d65lCRO8+YNcQshPTPSvl83 7nMR+VuZbPFMTbmOkKEY7vKHVxP+4k1lb2lkOOJYEvbGp8prsNo29o4jB9Brkoa2tI+p bYyQd3WlKQ/rOYo7KyqXhwz9sj3xrgMZiMPwKww0cr/wako02LTEDivzRlwK4ZbFy8b5 HJEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825778; x=1715430578; 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=kavMBo8KNcRmoPwTE1Oe8y9GeM+kd+Ho3+bW4koygvQ=; b=oPTgMT6/HYQBuSBkTxZDvXNs0gffLz9xOh2QXLl7gtZyNPYLjSsj7au09+3Axp9t1G XA2y6/QURo6W7X8kQ+WKzuA2VJdLXGGNYcFm3cQqHlsOI2Ly5NIsTnO6l83fOOoJk1bO qUXpkECFDdRpEF0+Btb3tiF2Tfzs5BEypZVwolCwB+tdQbQLvfH74HK9BvicQz1jeBXe QekHRHv9L7eBhwP+97cySOz0Lsian3mRWpnOLFNcw2B5Y8L1DLESXZ15LGCuKAM3buTP pEL4xRukJzi6sIdcF3ihzpVR3/87Y3VIQ890lRrug5z7npUs7b7Er2iLp1faY9ujVFIP 64hQ== X-Forwarded-Encrypted: i=1; AJvYcCWXZMVxrr776p9BA/sNcb16flidLtHWYlbhdrp4xlzxV/eNQUqlm/lUKKMOI+QCbqSZofYEF2KkgISHEdyEEjCG1ppdcFFOAPhTm37n8Q== X-Gm-Message-State: AOJu0YySqp9SaSIbX2ELBwaYDyBoroBSiiwT9YZKMVSwdMc5J+qrJY9h 7eKaIS0Wbhq+xUlordCQH+ZXhqEN8AKWX+JvFPc7/4s3Z1CDsp0KoSDrWQ== X-Google-Smtp-Source: AGHT+IFwIkt93HtQtERrEdSM/+DbYu5bMQSPIbkZnBHOORjt3BcqhvAcQVz2yhravkyyNcodVzppMw== X-Received: by 2002:a05:6a00:1904:b0:6ed:d5f5:869 with SMTP id y4-20020a056a00190400b006edd5f50869mr5871153pfi.3.1714825777622; Sat, 04 May 2024 05:29:37 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.29.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:29:37 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 12/31] powerpc: general interrupt tests Date: Sat, 4 May 2024 22:28:18 +1000 Message-ID: <20240504122841.1177683-13-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Add basic testing of various kinds of interrupts, machine check, page fault, illegal, decrementer, trace, syscall, etc. This has a known failure on QEMU TCG pseries machines where MSR[ME] can be incorrectly set to 0. Signed-off-by: Nicholas Piggin Acked-by: Thomas Huth --- lib/powerpc/asm/processor.h | 4 + lib/powerpc/asm/reg.h | 17 ++ lib/powerpc/setup.c | 11 + lib/ppc64/asm/ptrace.h | 16 ++ powerpc/Makefile.common | 3 +- powerpc/interrupts.c | 414 ++++++++++++++++++++++++++++++++++++ powerpc/unittests.cfg | 3 + 7 files changed, 467 insertions(+), 1 deletion(-) create mode 100644 powerpc/interrupts.c diff --git a/lib/powerpc/asm/processor.h b/lib/powerpc/asm/processor.h index cf1b9d8ff..eed37d1f4 100644 --- a/lib/powerpc/asm/processor.h +++ b/lib/powerpc/asm/processor.h @@ -11,7 +11,11 @@ void do_handle_exception(struct pt_regs *regs); #endif /* __ASSEMBLY__ */ extern bool cpu_has_hv; +extern bool cpu_has_power_mce; +extern bool cpu_has_siar; extern bool cpu_has_heai; +extern bool cpu_has_prefix; +extern bool cpu_has_sc_lev; static inline uint64_t mfspr(int nr) { diff --git a/lib/powerpc/asm/reg.h b/lib/powerpc/asm/reg.h index 782e75527..d6097f48f 100644 --- a/lib/powerpc/asm/reg.h +++ b/lib/powerpc/asm/reg.h @@ -5,8 +5,15 @@ #define UL(x) _AC(x, UL) +#define SPR_DSISR 0x012 +#define SPR_DAR 0x013 +#define SPR_DEC 0x016 #define SPR_SRR0 0x01a #define SPR_SRR1 0x01b +#define SRR1_PREFIX UL(0x20000000) +#define SPR_FSCR 0x099 +#define FSCR_PREFIX UL(0x2000) +#define SPR_HFSCR 0x0be #define SPR_TB 0x10c #define SPR_SPRG0 0x110 #define SPR_SPRG1 0x111 @@ -22,12 +29,17 @@ #define PVR_VER_POWER8 UL(0x004d0000) #define PVR_VER_POWER9 UL(0x004e0000) #define PVR_VER_POWER10 UL(0x00800000) +#define SPR_HDEC 0x136 #define SPR_HSRR0 0x13a #define SPR_HSRR1 0x13b +#define SPR_LPCR 0x13e +#define LPCR_HDICE UL(0x1) +#define SPR_HEIR 0x153 #define SPR_MMCR0 0x31b #define MMCR0_FC UL(0x80000000) #define MMCR0_PMAE UL(0x04000000) #define MMCR0_PMAO UL(0x00000080) +#define SPR_SIAR 0x31c /* Machine State Register definitions: */ #define MSR_LE_BIT 0 @@ -35,6 +47,11 @@ #define MSR_HV_BIT 60 /* Hypervisor mode */ #define MSR_SF_BIT 63 /* 64-bit mode */ +#define MSR_DR UL(0x0010) +#define MSR_IR UL(0x0020) +#define MSR_BE UL(0x0200) /* Branch Trace Enable */ +#define MSR_SE UL(0x0400) /* Single Step Enable */ +#define MSR_EE UL(0x8000) #define MSR_ME UL(0x1000) #endif diff --git a/lib/powerpc/setup.c b/lib/powerpc/setup.c index 3c81aee9e..9b665f59c 100644 --- a/lib/powerpc/setup.c +++ b/lib/powerpc/setup.c @@ -87,7 +87,11 @@ static void cpu_set(int fdtnode, u64 regval, void *info) } bool cpu_has_hv; +bool cpu_has_power_mce; /* POWER CPU machine checks */ +bool cpu_has_siar; bool cpu_has_heai; +bool cpu_has_prefix; +bool cpu_has_sc_lev; /* sc interrupt has LEV field in SRR1 */ static void cpu_init(void) { @@ -112,15 +116,22 @@ static void cpu_init(void) switch (mfspr(SPR_PVR) & PVR_VERSION_MASK) { case PVR_VER_POWER10: + cpu_has_prefix = true; + cpu_has_sc_lev = true; case PVR_VER_POWER9: case PVR_VER_POWER8E: case PVR_VER_POWER8NVL: case PVR_VER_POWER8: + cpu_has_power_mce = true; cpu_has_heai = true; + cpu_has_siar = true; break; default: break; } + + if (!cpu_has_hv) /* HEIR is HV register */ + cpu_has_heai = false; } static void mem_init(phys_addr_t freemem_start) diff --git a/lib/ppc64/asm/ptrace.h b/lib/ppc64/asm/ptrace.h index 12de7499b..db263a59e 100644 --- a/lib/ppc64/asm/ptrace.h +++ b/lib/ppc64/asm/ptrace.h @@ -5,6 +5,9 @@ #define STACK_FRAME_OVERHEAD 112 /* size of minimum stack frame */ #ifndef __ASSEMBLY__ + +#include + struct pt_regs { unsigned long gpr[32]; unsigned long nip; @@ -17,6 +20,19 @@ struct pt_regs { unsigned long _pad; /* stack must be 16-byte aligned */ }; +static inline bool regs_is_prefix(volatile struct pt_regs *regs) +{ + return regs->msr & SRR1_PREFIX; +} + +static inline void regs_advance_insn(struct pt_regs *regs) +{ + if (regs_is_prefix(regs)) + regs->nip += 8; + else + regs->nip += 4; +} + #define STACK_INT_FRAME_SIZE (sizeof(struct pt_regs) + \ STACK_FRAME_OVERHEAD + KERNEL_REDZONE_SIZE) diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common index 1e181da69..68165fc25 100644 --- a/powerpc/Makefile.common +++ b/powerpc/Makefile.common @@ -12,7 +12,8 @@ tests-common = \ $(TEST_DIR)/rtas.elf \ $(TEST_DIR)/emulator.elf \ $(TEST_DIR)/tm.elf \ - $(TEST_DIR)/sprs.elf + $(TEST_DIR)/sprs.elf \ + $(TEST_DIR)/interrupts.elf tests-all = $(tests-common) $(tests) all: directories $(TEST_DIR)/boot_rom.bin $(tests-all) diff --git a/powerpc/interrupts.c b/powerpc/interrupts.c new file mode 100644 index 000000000..552c48ef2 --- /dev/null +++ b/powerpc/interrupts.c @@ -0,0 +1,414 @@ +/* SPDX-License-Identifier: LGPL-2.0-only */ +/* + * Test interrupts + * + * Copyright 2024 Nicholas Piggin, IBM Corp. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static volatile bool got_interrupt; +static volatile struct pt_regs recorded_regs; + +static void mce_handler(struct pt_regs *regs, void *opaque) +{ + bool *is_fetch = opaque; + + got_interrupt = true; + memcpy((void *)&recorded_regs, regs, sizeof(struct pt_regs)); + if (*is_fetch) + regs->nip = regs->link; + else + regs_advance_insn(regs); +} + +static void fault_handler(struct pt_regs *regs, void *opaque) +{ + memcpy((void *)&recorded_regs, regs, sizeof(struct pt_regs)); + if (regs->trap == 0x400 || regs->trap == 0x480) + regs->nip = regs->link; + else + regs_advance_insn(regs); +} + +static void test_mce(void) +{ + unsigned long addr = -4ULL; + uint8_t tmp; + bool is_fetch; + + report_prefix_push("mce"); + + handle_exception(0x200, mce_handler, &is_fetch); + handle_exception(0x300, fault_handler, NULL); + handle_exception(0x380, fault_handler, NULL); + handle_exception(0x400, fault_handler, NULL); + handle_exception(0x480, fault_handler, NULL); + + if (machine_is_powernv()) { + enable_mcheck(); + } else { + report(mfmsr() & MSR_ME, "pseries machine has MSR[ME]=1"); + if (!(mfmsr() & MSR_ME)) { /* try to fix it */ + enable_mcheck(); + } + if (mfmsr() & MSR_ME) { + disable_mcheck(); + report(mfmsr() & MSR_ME, "pseries is unable to change MSR[ME]"); + if (!(mfmsr() & MSR_ME)) { /* try to fix it */ + enable_mcheck(); + } + } + } + + is_fetch = false; + asm volatile("lbz %0,0(%1)" : "=r"(tmp) : "r"(addr)); + + report(got_interrupt, "MCE on access to invalid real address"); + if (got_interrupt) { + report(mfspr(SPR_DAR) == addr, "MCE sets DAR correctly"); + if (cpu_has_power_mce) + report(recorded_regs.msr & (1ULL << 21), "d-side MCE sets SRR1[42]"); + got_interrupt = false; + } + + is_fetch = true; + asm volatile("mtctr %0 ; bctrl" :: "r"(addr) : "ctr", "lr"); + report(got_interrupt, "MCE on fetch from invalid real address"); + if (got_interrupt) { + report(recorded_regs.nip == addr, "MCE sets SRR0 correctly"); + if (cpu_has_power_mce) + report(!(recorded_regs.msr & (1ULL << 21)), "i-side MCE clears SRR1[42]"); + got_interrupt = false; + } + + handle_exception(0x200, NULL, NULL); + handle_exception(0x300, NULL, NULL); + handle_exception(0x380, NULL, NULL); + handle_exception(0x400, NULL, NULL); + handle_exception(0x480, NULL, NULL); + + report_prefix_pop(); +} + +static void dseg_handler(struct pt_regs *regs, void *data) +{ + got_interrupt = true; + memcpy((void *)&recorded_regs, regs, sizeof(struct pt_regs)); + regs_advance_insn(regs); + regs->msr &= ~MSR_DR; +} + +static void test_dseg(void) +{ + uint64_t msr, tmp; + + report_prefix_push("data segment"); + + /* Some HV start in radix mode and need 0x300 */ + handle_exception(0x300, &dseg_handler, NULL); + handle_exception(0x380, &dseg_handler, NULL); + + asm volatile( +" mfmsr %0 \n \ + ori %0,%0,%2 \n \ + mtmsrd %0 \n \ + lbz %1,0(0) " + : "=r"(msr), "=r"(tmp) : "i"(MSR_DR): "memory"); + + report(got_interrupt, "interrupt on NULL dereference"); + got_interrupt = false; + + handle_exception(0x300, NULL, NULL); + handle_exception(0x380, NULL, NULL); + + report_prefix_pop(); +} + +static void dec_handler(struct pt_regs *regs, void *data) +{ + got_interrupt = true; + memcpy((void *)&recorded_regs, regs, sizeof(struct pt_regs)); + regs->msr &= ~MSR_EE; +} + +static void test_dec(void) +{ + uint64_t msr; + uint64_t tb; + + report_prefix_push("decrementer"); + + handle_exception(0x900, &dec_handler, NULL); + + asm volatile( +" mtdec %1 \n \ + mfmsr %0 \n \ + ori %0,%0,%2 \n \ + mtmsrd %0,1 " + : "=r"(msr) : "r"(10000), "i"(MSR_EE): "memory"); + + tb = get_tb(); + while (!got_interrupt) { + if (get_tb() - tb > tb_hz * 5) + break; /* timeout 5s */ + } + + report(got_interrupt, "interrupt on decrementer underflow"); + got_interrupt = false; + + handle_exception(0x900, NULL, NULL); + + if (!machine_is_powernv()) + goto done; /* Skip HV tests */ + + handle_exception(0x980, &dec_handler, NULL); + + mtspr(SPR_LPCR, mfspr(SPR_LPCR) | LPCR_HDICE); + asm volatile( +" mtspr 0x136,%1 \n \ + mtdec %3 \n \ + mfmsr %0 \n \ + ori %0,%0,%2 \n \ + mtmsrd %0,1 " + : "=r"(msr) : "r"(10000), "i"(MSR_EE), "r"(0x7fffffff): "memory"); + + tb = get_tb(); + while (!got_interrupt) { + if (get_tb() - tb > tb_hz * 5) + break; /* timeout 5s */ + } + + mtspr(SPR_LPCR, mfspr(SPR_LPCR) & ~LPCR_HDICE); + + report(got_interrupt, "interrupt on hdecrementer underflow"); + got_interrupt = false; + + handle_exception(0x980, NULL, NULL); + +done: + report_prefix_pop(); +} + + +static volatile uint64_t recorded_heir; + +static void heai_handler(struct pt_regs *regs, void *data) +{ + got_interrupt = true; + memcpy((void *)&recorded_regs, regs, sizeof(struct pt_regs)); + regs_advance_insn(regs); + if (cpu_has_heai) + recorded_heir = mfspr(SPR_HEIR); +} + +static void program_handler(struct pt_regs *regs, void *data) +{ + got_interrupt = true; + memcpy((void *)&recorded_regs, regs, sizeof(struct pt_regs)); + regs_advance_insn(regs); +} + +/* + * This tests invalid instruction handling. powernv (HV) should take an + * HEAI interrupt with the HEIR SPR set to the instruction image. pseries + * (guest) should take a program interrupt. CPUs which support prefix + * should report prefix instruction in (H)SRR1[34]. + */ +static void test_illegal(void) +{ + report_prefix_push("illegal instruction"); + + if (machine_is_powernv()) { + handle_exception(0xe40, &heai_handler, NULL); + } else { + handle_exception(0x700, &program_handler, NULL); + } + + asm volatile(".long 0x12345678" ::: "memory"); + report(got_interrupt, "interrupt on invalid instruction"); + got_interrupt = false; + if (cpu_has_heai) + report(recorded_heir == 0x12345678, "HEIR: 0x%08lx", recorded_heir); + report(!regs_is_prefix(&recorded_regs), "(H)SRR1 prefix bit clear"); + + if (cpu_has_prefix) { + asm volatile(".balign 8 ; .long 0x04000123; .long 0x00badc0d"); + report(got_interrupt, "interrupt on invalid prefix instruction"); + got_interrupt = false; + if (cpu_has_heai) + report(recorded_heir == 0x0400012300badc0d, "HEIR: 0x%08lx", recorded_heir); + report(regs_is_prefix(&recorded_regs), "(H)SRR1 prefix bit set"); + } + + handle_exception(0xe40, NULL, NULL); + handle_exception(0x700, NULL, NULL); + + report_prefix_pop(); +} + +static void sc_handler(struct pt_regs *regs, void *data) +{ + got_interrupt = true; + memcpy((void *)&recorded_regs, regs, sizeof(struct pt_regs)); +} + +static void test_sc(void) +{ + report_prefix_push("syscall"); + + handle_exception(0xc00, &sc_handler, NULL); + + asm volatile("sc 0" ::: "memory"); + + report(got_interrupt, "interrupt on sc 0 instruction"); + got_interrupt = false; + if (cpu_has_sc_lev) + report(((recorded_regs.msr >> 20) & 0x3) == 0, "SRR1 set LEV=0"); + if (machine_is_powernv()) { + asm volatile("sc 1" ::: "memory"); + + report(got_interrupt, "interrupt on sc 1 instruction"); + got_interrupt = false; + if (cpu_has_sc_lev) + report(((recorded_regs.msr >> 20) & 0x3) == 1, "SRR1 set LEV=1"); + } + + handle_exception(0xc00, NULL, NULL); + + report_prefix_pop(); +} + + +static void trace_handler(struct pt_regs *regs, void *data) +{ + got_interrupt = true; + memcpy((void *)&recorded_regs, regs, sizeof(struct pt_regs)); + regs->msr &= ~(MSR_SE | MSR_BE); +} + +static void program_trace_handler(struct pt_regs *regs, void *data) +{ + regs->msr &= ~(MSR_SE | MSR_BE); + regs->nip += 4; +} + +extern char trace_insn[]; +extern char trace_insn2[]; +extern char trace_insn3[]; +extern char trace_rfid[]; + +static void test_trace(void) +{ + unsigned long msr; + + report_prefix_push("trace"); + + handle_exception(0xd00, &trace_handler, NULL); + + msr = mfmsr() | MSR_SE; + asm volatile( + " mtmsr %0 \n" + ".global trace_insn \n" + "trace_insn: \n" + " nop \n" + : : "r"(msr) : "memory"); + + report(got_interrupt, "interrupt on single step"); + got_interrupt = false; + report(recorded_regs.nip == (unsigned long)trace_insn + 4, + "single step interrupt at the correct address"); + if (cpu_has_siar) + report(mfspr(SPR_SIAR) == (unsigned long)trace_insn, + "single step recorded SIAR at the correct address"); + + msr = mfmsr() | MSR_SE; + asm volatile( + " mtmsr %0 \n" + ".global trace_insn2 \n" + "trace_insn2: \n" + " b 1f \n" + " nop \n" + "1: \n" + : : "r"(msr) : "memory"); + + report(got_interrupt, "interrupt on single step branch"); + got_interrupt = false; + report(recorded_regs.nip == (unsigned long)trace_insn2 + 8, + "single step interrupt at the correct address"); + if (cpu_has_siar) + report(mfspr(SPR_SIAR) == (unsigned long)trace_insn2, + "single step recorded SIAR at the correct address"); + + msr = mfmsr() | MSR_BE; + asm volatile( + " mtmsr %0 \n" + ".global trace_insn3 \n" + "trace_insn3: \n" + " nop \n" + " b 1f \n" + " nop \n" + "1: \n" + : : "r"(msr) : "memory"); + + report(got_interrupt, "interrupt on branch trace"); + got_interrupt = false; + report(recorded_regs.nip == (unsigned long)trace_insn3 + 12, + "branch trace interrupt at the correct address"); + if (cpu_has_siar) + report(mfspr(SPR_SIAR) == (unsigned long)trace_insn3 + 4, + "branch trace recorded SIAR at the correct address"); + + handle_exception(0x700, &program_trace_handler, NULL); + msr = mfmsr() | MSR_SE; + asm volatile( + " mtmsr %0 \n" + " trap \n" + : : "r"(msr) : "memory"); + + report(!got_interrupt, "no interrupt on single step trap"); + got_interrupt = false; + handle_exception(0x700, NULL, NULL); + + msr = mfmsr() | MSR_SE; + mtspr(SPR_SRR0, (unsigned long)trace_rfid); + mtspr(SPR_SRR1, mfmsr()); + asm volatile( + " mtmsr %0 \n" + " rfid \n" + ".global trace_rfid \n" + "trace_rfid: \n" + : : "r"(msr) : "memory"); + + report(!got_interrupt, "no interrupt on single step rfid"); + got_interrupt = false; + handle_exception(0xd00, NULL, NULL); + + report_prefix_pop(); +} + + +int main(int argc, char **argv) +{ + report_prefix_push("interrupts"); + + if (cpu_has_power_mce) + test_mce(); + test_dseg(); + test_illegal(); + test_dec(); + test_sc(); + test_trace(); + + report_prefix_pop(); + + return report_summary(); +} diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index 4c0c6ddea..03d7b60e5 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -66,6 +66,9 @@ groups = rtas [emulator] file = emulator.elf +[interrupts] +file = interrupts.elf + [h_cede_tm] file = tm.elf machine = pseries From patchwork Sat May 4 12:28:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931281 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=CFtsUkGh; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWnKP2bWxz1ybC for ; Sat, 4 May 2024 22:38:49 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=CFtsUkGh; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWnKP1DyPz3dJ5 for ; Sat, 4 May 2024 22:38:49 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=CFtsUkGh; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::436; helo=mail-pf1-x436.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn6v0nXyz3cP7 for ; Sat, 4 May 2024 22:29:43 +1000 (AEST) Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-6f43ee95078so437687b3a.1 for ; Sat, 04 May 2024 05:29:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825781; x=1715430581; darn=lists.ozlabs.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=f4yJRII8fMy/F3bi6dE4gOA3IVVXz2IcrfhDD/wKV2o=; b=CFtsUkGhMV3Z2beCHJFoeC2pElxBXkj9LCaOzh8FcbZ80H+BkQtoMtOF7Bhp5J3xQI jlnN3N8NVv0MsdyvFp7Vvu+BmJjHRAfZHzYqGUt8r/YUC8RQjyGZ8pmkeR9TNsaOvdzw Od9qA0RbZGTkY1z0gSm9voFjPqz2iF0MEpZcWiaA+ffGo3jEA0VeNdfMpeEGbgME5ugs P96I//sdN0HDpcwvNYEfyASoY7msR0yN94DCqW068FYin4ZD12w+kWZ/S5zceV1OQC7y elzyoDjDnNE9zu5mX/+h5CeRsAcYW6TJNvxKZCUL5e0/u97kWa7kDxrwthTYNJVTl4a8 KGTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825781; x=1715430581; 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=f4yJRII8fMy/F3bi6dE4gOA3IVVXz2IcrfhDD/wKV2o=; b=JYW5dRsSM6bL2MrJwlx0O6Uz0YxZtpfGx8ezHM2QZiXXzXNHmS/XfKNZaeFuBw0u2N Ogjv3asPLX618r1R782aOQbFmEmE77tM146c6Arpvlnpkj386lmRruRc8nu83fuZLQ8v p56gCPOPE7FjVJzhPKST1g64ttPwDA2aGw6VX7jk4Hz83GncEqgyICcpJtaBmyFJixVe iBripG15b8qcXFWjaSA7UmZgp6SAR41/OVUT9sSzUYj11pYGII9s+PCd6yDBqnIimZIM V05TBO4oIwloFMNyD/630PHP4ao6doKYvw4w8DEmde8pwhrnb4FYc9EHWhc+SCGlTrL7 Y1xg== X-Forwarded-Encrypted: i=1; AJvYcCWfF2LkCJWvBUPm0No9CgpW8r/k1Gr10aR8PEzRQsAz6zFnHRLsn95h9Vc9FMv4sHtjwRbSWUBDnlZYIIWy/V4dP4VR36/BqWZYJW2UUQ== X-Gm-Message-State: AOJu0YyF3Y3LXYLVqB7eHVQu7gj50KgmFcD8hWL1hHL7RZ6bU1k6AmMP Fe+4EOS/5+ml/YFOR5yyVo5PSOt8CmgTtT94z8udgnC8ro/9ZtF1 X-Google-Smtp-Source: AGHT+IEVY84AEN6CkjA2mwQYQV9LLTUK8/xjcAaI/p883Mc0ey+jvDCcJWFOC5KONl0A8jAnUAwjbQ== X-Received: by 2002:a05:6a00:23d1:b0:6ec:f282:f4ea with SMTP id g17-20020a056a0023d100b006ecf282f4eamr5430472pfc.34.1714825781511; Sat, 04 May 2024 05:29:41 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.29.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:29:40 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 13/31] powerpc: Add rtas stop-self support Date: Sat, 4 May 2024 22:28:19 +1000 Message-ID: <20240504122841.1177683-14-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" In preparation for improved SMP support, add stop-self support to the harness. This is non-trivial because it requires an unlocked rtas call: a CPU can't be holding a spin lock when it goes offline or it will deadlock other CPUs. rtas permits stop-self to be called without serialising all other rtas operations. Reviewed-by: Thomas Huth Signed-off-by: Nicholas Piggin --- lib/powerpc/asm/rtas.h | 2 ++ lib/powerpc/rtas.c | 78 +++++++++++++++++++++++++++++++++--------- 2 files changed, 64 insertions(+), 16 deletions(-) diff --git a/lib/powerpc/asm/rtas.h b/lib/powerpc/asm/rtas.h index 6fb407a18..364bf9355 100644 --- a/lib/powerpc/asm/rtas.h +++ b/lib/powerpc/asm/rtas.h @@ -23,8 +23,10 @@ struct rtas_args { extern void rtas_init(void); extern int rtas_token(const char *service, uint32_t *token); extern int rtas_call(int token, int nargs, int nret, int *outputs, ...); +extern int rtas_call_unlocked(struct rtas_args *args, int token, int nargs, int nret, int *outputs, ...); extern void rtas_power_off(void); +extern void rtas_stop_self(void); #endif /* __ASSEMBLY__ */ #define RTAS_MSR_MASK 0xfffffffffffffffe diff --git a/lib/powerpc/rtas.c b/lib/powerpc/rtas.c index 41c0a243e..b477a38e0 100644 --- a/lib/powerpc/rtas.c +++ b/lib/powerpc/rtas.c @@ -87,40 +87,86 @@ int rtas_token(const char *service, uint32_t *token) return 0; } -int rtas_call(int token, int nargs, int nret, int *outputs, ...) +static void __rtas_call(struct rtas_args *args) { - va_list list; - int ret, i; + enter_rtas(__pa(args)); +} - spin_lock(&rtas_lock); +static int rtas_call_unlocked_va(struct rtas_args *args, + int token, int nargs, int nret, int *outputs, + va_list list) +{ + int ret, i; - rtas_args.token = cpu_to_be32(token); - rtas_args.nargs = cpu_to_be32(nargs); - rtas_args.nret = cpu_to_be32(nret); - rtas_args.rets = &rtas_args.args[nargs]; + args->token = cpu_to_be32(token); + args->nargs = cpu_to_be32(nargs); + args->nret = cpu_to_be32(nret); + args->rets = &args->args[nargs]; - va_start(list, outputs); for (i = 0; i < nargs; ++i) - rtas_args.args[i] = cpu_to_be32(va_arg(list, u32)); - va_end(list); + args->args[i] = cpu_to_be32(va_arg(list, u32)); for (i = 0; i < nret; ++i) - rtas_args.rets[i] = 0; + args->rets[i] = 0; - enter_rtas(__pa(&rtas_args)); + __rtas_call(args); if (nret > 1 && outputs != NULL) for (i = 0; i < nret - 1; ++i) - outputs[i] = be32_to_cpu(rtas_args.rets[i + 1]); + outputs[i] = be32_to_cpu(args->rets[i + 1]); + + ret = nret > 0 ? be32_to_cpu(args->rets[0]) : 0; + + return ret; +} + +int rtas_call_unlocked(struct rtas_args *args, int token, int nargs, int nret, int *outputs, ...) +{ + va_list list; + int ret; - ret = nret > 0 ? be32_to_cpu(rtas_args.rets[0]) : 0; + va_start(list, outputs); + ret = rtas_call_unlocked_va(args, token, nargs, nret, outputs, list); + va_end(list); + + return ret; +} + +int rtas_call(int token, int nargs, int nret, int *outputs, ...) +{ + va_list list; + int ret; + + spin_lock(&rtas_lock); + + va_start(list, outputs); + ret = rtas_call_unlocked_va(&rtas_args, token, nargs, nret, outputs, list); + va_end(list); spin_unlock(&rtas_lock); + return ret; } +void rtas_stop_self(void) +{ + struct rtas_args args; + uint32_t token; + int ret; + + ret = rtas_token("stop-self", &token); + if (ret) { + puts("RTAS stop-self not available\n"); + return; + } + + ret = rtas_call_unlocked(&args, token, 0, 1, NULL); + printf("RTAS stop-self returned %d\n", ret); +} + void rtas_power_off(void) { + struct rtas_args args; uint32_t token; int ret; @@ -130,6 +176,6 @@ void rtas_power_off(void) return; } - ret = rtas_call(token, 2, 1, NULL, -1, -1); + ret = rtas_call_unlocked(&args, token, 2, 1, NULL, -1, -1); printf("RTAS power-off returned %d\n", ret); } From patchwork Sat May 4 12:28:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931282 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=JO6TxM2E; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWnLB582Rz1ybC for ; Sat, 4 May 2024 22:39:30 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=JO6TxM2E; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWnLB0vBkz3ccX for ; Sat, 4 May 2024 22:39:30 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=JO6TxM2E; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::432; helo=mail-pf1-x432.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn6z4cWLz3cSN for ; Sat, 4 May 2024 22:29:47 +1000 (AEST) Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-6f467fb2e66so83694b3a.1 for ; Sat, 04 May 2024 05:29:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825785; x=1715430585; darn=lists.ozlabs.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=JCnyyrhUMJlPFe7cyug7bxp4Z8jcIGiZmkD9LBikPH8=; b=JO6TxM2ENW+rOre+Hzd6nOgtAVKwgDYrhBgeKwTKAl+CJs4MkwHy284LfKbr5rryrJ Ehq1JGpHIHID7QE5CAycb79xu/IytpQtsPMDuDlQVqWClgayIxiaMBUCC4FN1LG3wm4a mXjDj9ItahLAdZkHdZ03YuI7EUqha6xq1CMyWE3lWdQpcoafRE+t/N/2H/N+WJJfLI27 KwADA66kRdy7LXCPbHqHcDURyFvqp2t+c8aa4JBBQqYQW32a61OaRl0kXjl3pAyAledw 5fC3n6fOSg+dQs50u+uNWAercD1Vvuj4I5B9NN7Hcj6it+GMHRCPJBh2Hv0egf7cZ/7H UMrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825785; x=1715430585; 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=JCnyyrhUMJlPFe7cyug7bxp4Z8jcIGiZmkD9LBikPH8=; b=QtiBP9Sqr1GxbN1AODSxt7Ijo3a7u2bEX/CpOR/Cd1pFfLkJDgMnUrndXEBM2p4TXc MsG8bDDGvS/tuUJwNxg/SugmNAzCJ/QMd70WV5DfHyT++bdjzrS5g+HA2ghZGwsV5pFz nBm/mQgo/nw10Fsg6SiuVMn2vF0rpW3DOJRhZXd7BI94s5niTd8g8WmM9vgQxUBpq9o6 McZhhwNFrWpj/1lbY8hXiQImNAmN7xcQzXb7riXPWwRXDuUWBHv90cEWO8MuVZwwQJRs y/IUMp2hag+MlnCk/OMl3EK0CmxVgKZfkvFvh7TVu12dpWugZwOzB+fJOY2UZlOkAwEK Yy3A== X-Forwarded-Encrypted: i=1; AJvYcCUpFNAIPcOO/r2jrtKotAMJ0n9ZbtkMnq2FQtuN0kuvT+sd9UtDLvdLm74MJPT3JdM223UCnM7nxLWTH4JPGj63lMbYWVffC63f9b08Dw== X-Gm-Message-State: AOJu0YwsdzOR6uXKf8FIA1sBIef2yiSQ6cNcY3f14H25ZZcgLT0S7bkG wsUm1wCpJXB+/B/vyAM1AfTDikbEh+5uFMrlOR1JTjY91e8Sl/y9UPBX5g== X-Google-Smtp-Source: AGHT+IHpmwlZ1Ova538YiLDhjk47+Mf6xmDk20bCNSb9DMpIy00uqVcKZrw5LeJQK/2vW1ivif+7wA== X-Received: by 2002:a05:6a00:22c2:b0:6f0:c214:7974 with SMTP id f2-20020a056a0022c200b006f0c2147974mr5985175pfj.12.1714825785325; Sat, 04 May 2024 05:29:45 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.29.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:29:44 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 14/31] powerpc: Remove broken SMP exception stack setup Date: Sat, 4 May 2024 22:28:20 +1000 Message-ID: <20240504122841.1177683-15-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" The exception stack setup does not work correctly for SMP, because it is the boot processor that calls cpu_set() which sets SPRG2 to the exception stack, not the target CPU itself. So secondaries never got their SPRG2 set to a valid exception stack. Remove the SMP code and just set an exception stack for the boot processor. Make the stack 64kB while we're here, to match the size of the regular stack. Signed-off-by: Nicholas Piggin Reviewed-by: Thomas Huth --- lib/powerpc/setup.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/powerpc/setup.c b/lib/powerpc/setup.c index 9b665f59c..58be93f08 100644 --- a/lib/powerpc/setup.c +++ b/lib/powerpc/setup.c @@ -42,10 +42,6 @@ struct cpu_set_params { uint64_t tb_hz; }; -#define EXCEPTION_STACK_SIZE (32*1024) /* 32kB */ - -static char exception_stack[NR_CPUS][EXCEPTION_STACK_SIZE]; - static void cpu_set(int fdtnode, u64 regval, void *info) { static bool read_common_info = false; @@ -56,10 +52,6 @@ static void cpu_set(int fdtnode, u64 regval, void *info) cpus[cpu] = regval; - /* set exception stack address for this CPU (in SPGR0) */ - asm volatile ("mtsprg0 %[addr]" :: - [addr] "r" (exception_stack[cpu + 1])); - if (!read_common_info) { const struct fdt_property *prop; u32 *data; @@ -180,6 +172,10 @@ static void mem_init(phys_addr_t freemem_start) ? __icache_bytes : __dcache_bytes); } +#define EXCEPTION_STACK_SIZE SZ_64K + +static char boot_exception_stack[EXCEPTION_STACK_SIZE]; + void setup(const void *fdt) { void *freemem = &stacktop; @@ -189,6 +185,10 @@ void setup(const void *fdt) cpu_has_hv = !!(mfmsr() & (1ULL << MSR_HV_BIT)); + /* set exception stack address for this CPU (in SPGR0) */ + asm volatile ("mtsprg0 %[addr]" :: + [addr] "r" (boot_exception_stack + EXCEPTION_STACK_SIZE - 64)); + enable_mcheck(); /* From patchwork Sat May 4 12:28:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931283 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Js3MNsk4; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWnLz07qQz1yb7 for ; Sat, 4 May 2024 22:40:11 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Js3MNsk4; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWnLy5tn6z3g8B for ; Sat, 4 May 2024 22:40:10 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=Js3MNsk4; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42b; helo=mail-pf1-x42b.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn7326VZz30VV for ; Sat, 4 May 2024 22:29:51 +1000 (AEST) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-6f44390e328so524549b3a.2 for ; Sat, 04 May 2024 05:29:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825789; x=1715430589; darn=lists.ozlabs.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=fDXzWLE/DUs3GDPPxGlpa8evNqGRj/CtlxJusPx/GlU=; b=Js3MNsk4uxa2KFd4Np29cFpWWAW8jFXBHmR4p5R0HB4LS93hRm8Yk9dmocgdq4IpxH BNuSjyHX3q9CaZU2XA/8DVig0x6nj9BtLYKg0xdldOpSSeFCBl/ChMoEf913sj2MIpaV /LFytxB1YsUr8AeJGVP9CF09e6Ue1HAttE/GQzJRRqHOQ6apQiKkWwYN2Abhf99RCFnJ hSGeIq4F8DmJra1XskIzO7EQhoLZ9s2M7tQmTEVv+lb/S0x+js3nm6bKH36W7L4HSPJq G0ig9rBIeEzDveCYul8nfSsOp1uVLt3uZLwzXVI6tjXGOSExmyxU8qtCvCKJ9aiwVgIW TI2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825789; x=1715430589; 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=fDXzWLE/DUs3GDPPxGlpa8evNqGRj/CtlxJusPx/GlU=; b=j8VQFX1NxQag4zflPwl0RhtCMcLItSvPgK37PCFbENFp0Hugu6aHmSHJv1JtUoB71S bwFOmA5mN6ZbLI+uPqYiNAoYvdvMwl2Dtu9gKSfMZBeM6FaeSy8FMBpMGswUrLTKtovS ZTDfWdGP/yzmGu28IlpeL/qvrtYnvl4wT2GAkT7zBcIbeRXZk6cnj9Q2NNivsp8K5R5e vkn5vZfEo3C681OYdBX+hg5cPrbFq8zbRaMpPgMONWEB+Cyn8LHngWayC5RXFS1YkJ1f HosU2ZWNe0A2NsVa4OwYJrKjDcAvRm+zjxJuUyqpT/a0JDbQtz5pcY1ZaS0piICAbwgj G4zA== X-Forwarded-Encrypted: i=1; AJvYcCUOI38Q9XuddQU3MLolAX9yypX5CtPi7nr29UVi/MztBfkCVJ1wfGHVnD6634/CtcZ8S8ZgCaXNV2CbSqWLYe522xk2sn1d5jCMGrjnMw== X-Gm-Message-State: AOJu0YwLB3W2d4nSw5Vx6klbc4zUdUQCmJphyY1aOA6nlg/mXs1GqGxI WRCfPiRTjDy0ibnLlVuvrEegVeKeQLopusnHZu9GmzEAKtNm715d X-Google-Smtp-Source: AGHT+IHnQ2zuv/B+C0SD3NBohPwkG9C/rQDC8UTekLkLibupZ9dNhnjts9LIMNCchzomoGQJps/l9g== X-Received: by 2002:a05:6a00:4b4d:b0:6f3:ee81:13b5 with SMTP id kr13-20020a056a004b4d00b006f3ee8113b5mr7759237pfb.17.1714825788886; Sat, 04 May 2024 05:29:48 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.29.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:29:48 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 15/31] powerpc: Enable page alloc operations Date: Sat, 4 May 2024 22:28:21 +1000 Message-ID: <20240504122841.1177683-16-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" These will be used for stack allocation for secondary CPUs. Signed-off-by: Nicholas Piggin Reviewed-by: Thomas Huth --- lib/powerpc/setup.c | 8 ++++++++ powerpc/Makefile.common | 1 + 2 files changed, 9 insertions(+) diff --git a/lib/powerpc/setup.c b/lib/powerpc/setup.c index 58be93f08..73ca2f931 100644 --- a/lib/powerpc/setup.c +++ b/lib/powerpc/setup.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -133,6 +134,7 @@ static void mem_init(phys_addr_t freemem_start) .start = (phys_addr_t)-1, }; int nr_regs, i; + phys_addr_t base, top; nr_regs = dt_get_memory_params(regs, NR_MEM_REGIONS); assert(nr_regs > 0); @@ -170,6 +172,12 @@ static void mem_init(phys_addr_t freemem_start) phys_alloc_init(freemem_start, primary.end - freemem_start); phys_alloc_set_minimum_alignment(__icache_bytes > __dcache_bytes ? __icache_bytes : __dcache_bytes); + + phys_alloc_get_unused(&base, &top); + base = PAGE_ALIGN(base); + top &= PAGE_MASK; + page_alloc_init_area(0, base >> PAGE_SHIFT, top >> PAGE_SHIFT); + page_alloc_ops_enable(); } #define EXCEPTION_STACK_SIZE SZ_64K diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common index 68165fc25..6374418d2 100644 --- a/powerpc/Makefile.common +++ b/powerpc/Makefile.common @@ -38,6 +38,7 @@ cflatobjs += lib/util.o cflatobjs += lib/getchar.o cflatobjs += lib/alloc_phys.o cflatobjs += lib/alloc.o +cflatobjs += lib/alloc_page.o cflatobjs += lib/devicetree.o cflatobjs += lib/migrate.o cflatobjs += lib/powerpc/io.o From patchwork Sat May 4 12:28:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931285 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=PCJSV/ZX; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWnNY1MXrz1xnT for ; Sat, 4 May 2024 22:41:32 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=PCJSV/ZX; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWnNW6sC0z3gG2 for ; Sat, 4 May 2024 22:41:31 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=PCJSV/ZX; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2001:4860:4864:20::2e; helo=mail-oa1-x2e.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-oa1-x2e.google.com (mail-oa1-x2e.google.com [IPv6:2001:4860:4864:20::2e]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn7D216pz3bqP for ; Sat, 4 May 2024 22:30:00 +1000 (AEST) Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-23f041357ccso105448fac.3 for ; Sat, 04 May 2024 05:30:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825793; x=1715430593; darn=lists.ozlabs.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=QzolWM0KBX532JEr7qFaNuNRi8gLED13xIyQFP+nUXw=; b=PCJSV/ZXO4GMvE/73bjBU+0CD1PiSugcV9ksm7kuYgme9l2O0cOS5dB9/yvoPIYCTu fhNXjxEFiDYLnjlh4E4CpwwmVF0jdMREqslgpI5wYDzyL32ciRv6CbJGsm43HlYL7kZg xH9n1YT3Mk4SvK0inKp2ksmvqBsfwYkiNy+llbp6KJGu7IBpvWckOEv7064xLR/MF2gB DGTNZtLvNbM9d9DORCBu1/Qo4LN5Z+zrYQcQl0gEZOBPViwUXvlVv1gAjGi014ImbJ+x i06ZPqTO2gYzPvu2PzQ+j2eQGzSvKu6eM+Eq2mtc3ADNlSo9h0tgmSg73l/pGLrWDvdX Ngqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825793; x=1715430593; 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=QzolWM0KBX532JEr7qFaNuNRi8gLED13xIyQFP+nUXw=; b=eXnDwnStnXjaR4gIcJDgRSJPMMWBaC9NbeaLuwQaKTSNaKqWGseC992S6H0FPuuNja M7M2awacWqSjwXNd8ISPMsvhqx1/LRbMjcuUKu32ext/QWtCsgqwGDcPXXmjXFIh9Xu0 rNtR4Wn3ccXejYOVRwlnN6NNu7AL8QzalfBaS8xE9RT7RpFAFz5BtciV2KxWZZDnQxXO hAAMNfndAZhv0NBjGQuKv0QL/jwwPAAVN7TfJY8PKWqCE/U6WrEPGn4r2yXjnFBtZHab PZSJrECnyP5IVjbzEBHhsxz+CdOqPq3ufiusVhNd21gKilcaljV12t6RhAFypKsjui/f uswA== X-Forwarded-Encrypted: i=1; AJvYcCVy/1+OO0/VQVLxDC5ksmIErqxcoY9QJfryfAgDpGjuN1mf934InG/NkGqHX1Oy2cxu+7rpjsXeO/PPW/1Dbxr98En3ZQ0Zc99jd4edvQ== X-Gm-Message-State: AOJu0YwYXjka91p1Qt6OZI+chHrpwXMHsGTXpedD02lqFyow7CxEBpil nGHw1tRAJbICgXuM+nsgCcXe9ASjkVcG++jdmdDiw9DEfhHrD8xmx9VKLQ== X-Google-Smtp-Source: AGHT+IE8QC7TJFKIZP9hPD5VLW8/XQeIffn4e1dqGWdkXE90+KKRvi5WtGQbTqAAo+EomwthuJjD0w== X-Received: by 2002:a05:6870:9e46:b0:22e:93a0:fcbb with SMTP id pt6-20020a0568709e4600b0022e93a0fcbbmr6675249oab.34.1714825792656; Sat, 04 May 2024 05:29:52 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.29.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:29:52 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 16/31] powerpc: add SMP and IPI support Date: Sat, 4 May 2024 22:28:22 +1000 Message-ID: <20240504122841.1177683-17-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" powerpc SMP support is very primitive and does not set up a first-class runtime environment for secondary CPUs. This reworks SMP support, and provides a complete C and harness environment for the secondaries, including interrupt handling, as well as IPI support. Signed-off-by: Nicholas Piggin Acked-by: Thomas Huth --- lib/powerpc/asm/processor.h | 23 +++ lib/powerpc/asm/reg.h | 1 + lib/powerpc/asm/setup.h | 2 - lib/powerpc/asm/smp.h | 44 +++-- lib/powerpc/io.c | 15 +- lib/powerpc/processor.c | 7 +- lib/powerpc/setup.c | 90 +++++++--- lib/powerpc/smp.c | 337 ++++++++++++++++++++++++++++++---- lib/ppc64/asm-offsets.c | 9 + lib/ppc64/asm/atomic.h | 6 + lib/ppc64/asm/barrier.h | 2 + lib/ppc64/asm/opal.h | 7 + powerpc/Makefile.common | 1 + powerpc/cstart64.S | 50 +++++- powerpc/selftest.c | 4 +- powerpc/smp.c | 348 ++++++++++++++++++++++++++++++++++++ powerpc/tm.c | 5 +- powerpc/unittests.cfg | 8 + 18 files changed, 875 insertions(+), 84 deletions(-) create mode 100644 lib/ppc64/asm/atomic.h create mode 100644 powerpc/smp.c diff --git a/lib/powerpc/asm/processor.h b/lib/powerpc/asm/processor.h index eed37d1f4..a3859b5d4 100644 --- a/lib/powerpc/asm/processor.h +++ b/lib/powerpc/asm/processor.h @@ -16,6 +16,7 @@ extern bool cpu_has_siar; extern bool cpu_has_heai; extern bool cpu_has_prefix; extern bool cpu_has_sc_lev; +extern bool cpu_has_pause_short; static inline uint64_t mfspr(int nr) { @@ -45,6 +46,28 @@ static inline void mtmsr(uint64_t msr) asm volatile ("mtmsrd %[msr]" :: [msr] "r" (msr) : "memory"); } +static inline void local_irq_enable(void) +{ + unsigned long msr; + + asm volatile( +" mfmsr %0 \n \ + ori %0,%0,%1 \n \ + mtmsrd %0,1 " + : "=r"(msr) : "i"(MSR_EE): "memory"); +} + +static inline void local_irq_disable(void) +{ + unsigned long msr; + + asm volatile( +" mfmsr %0 \n \ + andc %0,%0,%1 \n \ + mtmsrd %0,1 " + : "=r"(msr) : "r"(MSR_EE): "memory"); +} + /* * This returns true on PowerNV / OPAL machines which run in hypervisor * mode. False on pseries / PAPR machines that run in guest mode. diff --git a/lib/powerpc/asm/reg.h b/lib/powerpc/asm/reg.h index d6097f48f..d2ca964c4 100644 --- a/lib/powerpc/asm/reg.h +++ b/lib/powerpc/asm/reg.h @@ -19,6 +19,7 @@ #define SPR_SPRG1 0x111 #define SPR_SPRG2 0x112 #define SPR_SPRG3 0x113 +#define SPR_TBU40 0x11e #define SPR_PVR 0x11f #define PVR_VERSION_MASK UL(0xffff0000) #define PVR_VER_970 UL(0x00390000) diff --git a/lib/powerpc/asm/setup.h b/lib/powerpc/asm/setup.h index cc7cf5e25..9ca318ce6 100644 --- a/lib/powerpc/asm/setup.h +++ b/lib/powerpc/asm/setup.h @@ -8,8 +8,6 @@ #include #define NR_CPUS 8 /* arbitrarily set for now */ -extern u32 cpus[NR_CPUS]; -extern int nr_cpus; extern uint64_t tb_hz; diff --git a/lib/powerpc/asm/smp.h b/lib/powerpc/asm/smp.h index 21940b4bc..c45988bfa 100644 --- a/lib/powerpc/asm/smp.h +++ b/lib/powerpc/asm/smp.h @@ -2,21 +2,45 @@ #define _ASMPOWERPC_SMP_H_ #include +#include -extern int nr_threads; +typedef void (*secondary_entry_fn)(int cpu_id); -struct start_threads { - int nr_threads; - int nr_started; +struct cpu { + unsigned long server_no; + unsigned long stack; + unsigned long exception_stack; + secondary_entry_fn entry; }; -typedef void (*secondary_entry_fn)(void); +extern int nr_cpus_present; +extern int nr_cpus_online; +extern struct cpu cpus[]; -extern void halt(void); +register struct cpu *__current_cpu asm("r13"); +static inline struct cpu *current_cpu(void) +{ + return __current_cpu; +} -extern int start_thread(int cpu_id, secondary_entry_fn entry, uint32_t r3); -extern struct start_threads start_cpu(int cpu_node, secondary_entry_fn entry, - uint32_t r3); -extern bool start_all_cpus(secondary_entry_fn entry, uint32_t r3); +static inline int smp_processor_id(void) +{ + return current_cpu()->server_no; +} + +void cpu_init(struct cpu *cpu, int cpu_id); + +extern void halt(int cpu_id); + +extern bool start_all_cpus(secondary_entry_fn entry); +extern void stop_all_cpus(void); + +struct pt_regs; +void register_ipi(void (*fn)(struct pt_regs *, void *), void *data); +void unregister_ipi(void); +void cpu_init_ipis(void); +void local_ipi_enable(void); +void local_ipi_disable(void); +void send_ipi(int cpu_id); #endif /* _ASMPOWERPC_SMP_H_ */ diff --git a/lib/powerpc/io.c b/lib/powerpc/io.c index ab7bb843c..cb7f2f050 100644 --- a/lib/powerpc/io.c +++ b/lib/powerpc/io.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "io.h" static struct spinlock print_lock; @@ -55,13 +56,17 @@ extern void halt(int code); void exit(int code) { + static int exited = 0; + // FIXME: change this print-exit/rtas-poweroff to chr_testdev_exit(), // maybe by plugging chr-testdev into a spapr-vty. - printf("\nEXIT: STATUS=%d\n", ((code) << 1) | 1); - if (machine_is_powernv()) - opal_power_off(); - else - rtas_power_off(); + if (atomic_fetch_inc(&exited) == 0) { + printf("\nEXIT: STATUS=%d\n", ((code) << 1) | 1); + if (machine_is_powernv()) + opal_power_off(); + else + rtas_power_off(); + } halt(code); __builtin_unreachable(); } diff --git a/lib/powerpc/processor.c b/lib/powerpc/processor.c index 1b4bb0d61..a6ce3c905 100644 --- a/lib/powerpc/processor.c +++ b/lib/powerpc/processor.c @@ -13,6 +13,7 @@ #include #include #include +#include static struct { void (*func)(struct pt_regs *, void *data); @@ -44,6 +45,8 @@ void do_handle_exception(struct pt_regs *regs) { unsigned char v; + __current_cpu = (struct cpu *)mfspr(SPR_SPRG0); + v = regs->trap >> 5; if (v < 128 && handlers[v].func) { @@ -51,8 +54,8 @@ void do_handle_exception(struct pt_regs *regs) return; } - printf("Unhandled cpu exception %#lx at NIA:0x%016lx MSR:0x%016lx\n", - regs->trap, regs->nip, regs->msr); + printf("Unhandled CPU%d exception %#lx at NIA:0x%016lx MSR:0x%016lx\n", + smp_processor_id(), regs->trap, regs->nip, regs->msr); dump_frame_stack((void *)regs->nip, (void *)regs->gpr[1]); abort(); } diff --git a/lib/powerpc/setup.c b/lib/powerpc/setup.c index 73ca2f931..622b99e5d 100644 --- a/lib/powerpc/setup.c +++ b/lib/powerpc/setup.c @@ -2,7 +2,7 @@ * Initialize machine setup information and I/O. * * After running setup() unit tests may query how many cpus they have - * (nr_cpus), how much memory they have (PHYSICAL_END - PHYSICAL_START), + * (nr_cpus_present), how much memory they have (PHYSICAL_END - PHYSICAL_START), * may use dynamic memory allocation (malloc, etc.), printf, and exit. * Finally, argc and argv are also ready to be passed to main(). * @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -29,8 +30,8 @@ extern unsigned long stacktop; char *initrd; u32 initrd_size; -u32 cpus[NR_CPUS] = { [0 ... NR_CPUS-1] = (~0U) }; -int nr_cpus; +u32 cpu_to_hwid[NR_CPUS] = { [0 ... NR_CPUS-1] = (~0U) }; +int nr_cpus_present; uint64_t tb_hz; struct mem_region mem_regions[NR_MEM_REGIONS]; @@ -45,13 +46,32 @@ struct cpu_set_params { static void cpu_set(int fdtnode, u64 regval, void *info) { + const struct fdt_property *prop; + u32 *threads; static bool read_common_info = false; struct cpu_set_params *params = info; - int cpu = nr_cpus++; - - assert_msg(cpu < NR_CPUS, "Number cpus exceeds maximum supported (%d).", NR_CPUS); - - cpus[cpu] = regval; + int nr_threads; + int len, i; + + /* Get the id array of threads on this node */ + prop = fdt_get_property(dt_fdt(), fdtnode, + "ibm,ppc-interrupt-server#s", &len); + assert(prop); + + nr_threads = len >> 2; /* Divide by 4 since 4 bytes per thread */ + threads = (u32 *)prop->data; /* Array of valid ids */ + + for (i = 0; i < nr_threads; i++) { + if (nr_cpus_present >= NR_CPUS) { + static bool warned = false; + if (!warned) { + printf("Warning: Number of present CPUs exceeds maximum supported (%d).\n", NR_CPUS); + warned = true; + } + break; + } + cpu_to_hwid[nr_cpus_present++] = fdt32_to_cpu(threads[i]); + } if (!read_common_info) { const struct fdt_property *prop; @@ -85,32 +105,25 @@ bool cpu_has_siar; bool cpu_has_heai; bool cpu_has_prefix; bool cpu_has_sc_lev; /* sc interrupt has LEV field in SRR1 */ +bool cpu_has_pause_short; -static void cpu_init(void) +static void cpu_init_params(void) { struct cpu_set_params params; int ret; - nr_cpus = 0; + nr_cpus_present = 0; ret = dt_for_each_cpu_node(cpu_set, ¶ms); assert(ret == 0); __icache_bytes = params.icache_bytes; __dcache_bytes = params.dcache_bytes; tb_hz = params.tb_hz; - /* Interrupt Endianness */ - if (machine_is_pseries()) { -#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ - hcall(H_SET_MODE, 1, 4, 0, 0); -#else - hcall(H_SET_MODE, 0, 4, 0, 0); -#endif - } - switch (mfspr(SPR_PVR) & PVR_VERSION_MASK) { case PVR_VER_POWER10: cpu_has_prefix = true; cpu_has_sc_lev = true; + cpu_has_pause_short = true; case PVR_VER_POWER9: case PVR_VER_POWER8E: case PVR_VER_POWER8NVL: @@ -183,19 +196,37 @@ static void mem_init(phys_addr_t freemem_start) #define EXCEPTION_STACK_SIZE SZ_64K static char boot_exception_stack[EXCEPTION_STACK_SIZE]; +struct cpu cpus[NR_CPUS]; + +void cpu_init(struct cpu *cpu, int cpu_id) +{ + cpu->server_no = cpu_id; + + cpu->stack = (unsigned long)memalign(SZ_4K, SZ_64K); + cpu->stack += SZ_64K - 64; + cpu->exception_stack = (unsigned long)memalign(SZ_4K, SZ_64K); + cpu->exception_stack += SZ_64K - 64; +} void setup(const void *fdt) { void *freemem = &stacktop; const char *bootargs, *tmp; + struct cpu *cpu; u32 fdt_size; int ret; cpu_has_hv = !!(mfmsr() & (1ULL << MSR_HV_BIT)); - /* set exception stack address for this CPU (in SPGR0) */ - asm volatile ("mtsprg0 %[addr]" :: - [addr] "r" (boot_exception_stack + EXCEPTION_STACK_SIZE - 64)); + memset(cpus, 0xff, sizeof(cpus)); + + cpu = &cpus[0]; + cpu->server_no = fdt_boot_cpuid_phys(fdt); + cpu->exception_stack = (unsigned long)boot_exception_stack; + cpu->exception_stack += EXCEPTION_STACK_SIZE - 64; + + mtspr(SPR_SPRG0, (unsigned long)cpu); + __current_cpu = cpu; enable_mcheck(); @@ -238,8 +269,19 @@ void setup(const void *fdt) assert(STACK_INT_FRAME_SIZE % 16 == 0); - /* call init functions */ - cpu_init(); + /* set parameters from dt */ + cpu_init_params(); + + /* Interrupt Endianness */ + if (machine_is_pseries()) { +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + hcall(H_SET_MODE, 1, 4, 0, 0); +#else + hcall(H_SET_MODE, 0, 4, 0, 0); +#endif + } + + cpu_init_ipis(); /* cpu_init must be called before mem_init */ mem_init(PAGE_ALIGN((unsigned long)freemem)); diff --git a/lib/powerpc/smp.c b/lib/powerpc/smp.c index 3e211eba8..27b169841 100644 --- a/lib/powerpc/smp.c +++ b/lib/powerpc/smp.c @@ -6,58 +6,253 @@ * This work is licensed under the terms of the GNU LGPL, version 2. */ +#include #include +#include +#include +#include #include #include +#include +#include #include #include -int nr_threads; - struct secondary_entry_data { secondary_entry_fn entry; - uint64_t r3; - int nr_started; }; +int nr_cpus_online = 1; + +static void stop_self(int cpu_id) +{ + if (machine_is_powernv()) { + if (opal_call(OPAL_RETURN_CPU, 0, 0, 0) != OPAL_SUCCESS) { + printf("OPAL_RETURN_CPU failed\n"); + } + } else { + rtas_stop_self(); + } + + printf("failed to stop cpu %d\n", cpu_id); + assert(0); +} + +void main_secondary(struct cpu *cpu); +void main_secondary(struct cpu *cpu) +{ + mtspr(SPR_SPRG0, (unsigned long)cpu); + __current_cpu = cpu; + + enable_mcheck(); + + cpu_init_ipis(); + + atomic_fetch_inc(&nr_cpus_online); + + cpu->entry(cpu->server_no); + + mb(); + atomic_fetch_dec(&nr_cpus_online); + + stop_self(cpu->server_no); +} + +enum OpalThreadStatus { + OPAL_THREAD_INACTIVE = 0x0, + OPAL_THREAD_STARTED = 0x1, + OPAL_THREAD_UNAVAILABLE = 0x2 /* opal-v3 */ +}; + +#define H_EOI 0x64 +#define H_CPPR 0x68 +#define H_IPI 0x6c +#define H_XIRR 0x74 + +static void (*ipi_fn)(struct pt_regs *regs, void *data); + +static void dbell_handler(struct pt_regs *regs, void *data) +{ + /* sync */ + ipi_fn(regs, data); +} + +static void extint_handler(struct pt_regs *regs, void *data) +{ + int32_t xirr; + int32_t xisr; + int64_t rc; + + asm volatile("mr r3,%1 ; sc 1 ; mr %0,r4" : "=r"(xirr) : "r"(H_XIRR)); + xisr = xirr & 0xffffff; + + if (xisr == 2) { /* IPI */ + rc = hcall(H_IPI, smp_processor_id(), 0xff); + assert(rc == H_SUCCESS); + } + + xirr |= (5 << 24); + rc = hcall(H_EOI, xirr); + assert(rc == H_SUCCESS); + + /* lower IPI */ + ipi_fn(regs, data); +} + +void cpu_init_ipis(void) +{ + if (machine_is_powernv()) { + /* skiboot can leave some messages set */ + unsigned long rb = (5 << (63-36)); + asm volatile("msgclr %0" :: "r"(rb) : "memory"); + } +} + +void local_ipi_enable(void) +{ + if (machine_is_pseries()) { + hcall(H_CPPR, 5); + } +} + +void local_ipi_disable(void) +{ + if (machine_is_pseries()) { + hcall(H_CPPR, 0); + } +} + +void register_ipi(void (*fn)(struct pt_regs *, void *), void *data) +{ + ipi_fn = fn; + if (machine_is_powernv()) { + handle_exception(0xe80, &dbell_handler, data); + } else { + handle_exception(0x500, &extint_handler, data); + } +} + +void unregister_ipi(void) +{ + if (machine_is_powernv()) { + handle_exception(0xe80, NULL, NULL); + } else { + handle_exception(0x500, NULL, NULL); + } +} + +void send_ipi(int cpu_id) +{ + if (machine_is_powernv()) { + unsigned long rb = (5 << (63-36)) | cpu_id; + asm volatile("lwsync" ::: "memory"); + asm volatile("msgsnd %0" :: "r"(rb) : "memory"); + } else { + hcall(H_IPI, cpu_id, 4); + } +} + +static int nr_started = 1; + +extern void start_secondary(uint64_t server_no); /* asm entry point */ + +static bool cpu_is_running(int cpu_id) +{ + if (machine_is_powernv()) { + int64_t ret; + uint8_t status; + + ret = opal_call(OPAL_QUERY_CPU_STATUS, cpu_id, (unsigned long)&status, 0); + if (ret != OPAL_SUCCESS) { + printf("OPAL_QUERY_CPU_STATUS failed for cpu %d\n", cpu_id); + return false; + } + return (status != OPAL_THREAD_INACTIVE); + } else { + uint32_t query_token; + int outputs[1], ret; + + ret = rtas_token("query-cpu-stopped-state", &query_token); + if (ret != 0) { + printf("rtas token query-cpu-stopped-state failed\n"); + return false; + } + + ret = rtas_call(query_token, 1, 2, outputs, cpu_id); + if (ret) { + printf("query-cpu-stopped-state failed for cpu %d\n", cpu_id); + return ret; + } + if (outputs[0]) /* cpu not in stopped state */ + return true; + return false; + } +} + /* * Start stopped thread cpu_id at entry * Returns: <0 on failure to start stopped cpu * 0 on success * >0 on cpu not in stopped state */ -int start_thread(int cpu_id, secondary_entry_fn entry, uint32_t r3) +static int start_thread(int cpu_id, secondary_entry_fn entry) { - uint32_t query_token, start_token; - int outputs[1], ret; + struct cpu *cpu; + uint64_t tb; - ret = rtas_token("query-cpu-stopped-state", &query_token); - assert(ret == 0); - ret = rtas_token("start-cpu", &start_token); - assert(ret == 0); + if (nr_started >= NR_CPUS) { + /* Reached limit */ + return -1; + } + + if (cpu_id == smp_processor_id()) { + /* Boot CPU already started */ + return -1; + } + + tb = get_tb(); + while (cpu_is_running(cpu_id)) { + if (get_tb() - tb > 3*tb_hz) { + printf("Unable to start running CPU:%d\n", cpu_id); + return 1; + } + } + + cpu = &cpus[nr_started]; + nr_started++; + + cpu_init(cpu, cpu_id); + cpu->entry = entry; + + if (machine_is_powernv()) { + if (opal_call(OPAL_START_CPU, cpu_id, (unsigned long)start_secondary, 0) != OPAL_SUCCESS) { + printf("failed to start cpu %d\n", cpu_id); + return -1; + } + } else { + uint32_t start_token; + int ret; - ret = rtas_call(query_token, 1, 2, outputs, cpu_id); - if (ret) { - printf("query-cpu-stopped-state failed for cpu %d\n", cpu_id); - } else if (!outputs[0]) { /* cpu in stopped state */ - ret = rtas_call(start_token, 3, 1, NULL, cpu_id, entry, r3); - if (ret) + ret = rtas_token("start-cpu", &start_token); + assert(ret == 0); + + ret = rtas_call(start_token, 3, 1, NULL, cpu_id, start_secondary, cpu_id); + if (ret) { printf("failed to start cpu %d\n", cpu_id); - } else { /* cpu not in stopped state */ - ret = outputs[0]; + return ret; + } } - return ret; + return 0; } /* * Start all stopped threads (vcpus) on cpu_node * Returns: Number of stopped cpus which were successfully started */ -struct start_threads start_cpu(int cpu_node, secondary_entry_fn entry, - uint32_t r3) +static void start_core(int cpu_node, secondary_entry_fn entry) { - int len, i, nr_threads, nr_started = 0; + int len, i, nr_threads; const struct fdt_property *prop; u32 *threads; @@ -67,23 +262,18 @@ struct start_threads start_cpu(int cpu_node, secondary_entry_fn entry, assert(prop); nr_threads = len >> 2; /* Divide by 4 since 4 bytes per thread */ - threads = (u32 *)prop->data; /* Array of valid ids */ - for (i = 0; i < nr_threads; i++) { - if (!start_thread(fdt32_to_cpu(threads[i]), entry, r3)) - nr_started++; - } + threads = (u32 *)prop->data; /* Array of valid ids */ - return (struct start_threads) { nr_threads, nr_started }; + for (i = 0; i < nr_threads; i++) + start_thread(fdt32_to_cpu(threads[i]), entry); } static void start_each_secondary(int fdtnode, u64 regval __unused, void *info) { struct secondary_entry_data *datap = info; - struct start_threads ret = start_cpu(fdtnode, datap->entry, datap->r3); - nr_threads += ret.nr_threads; - datap->nr_started += ret.nr_started; + start_core(fdtnode, datap->entry); } /* @@ -92,14 +282,89 @@ static void start_each_secondary(int fdtnode, u64 regval __unused, void *info) * Returns: TRUE on success * FALSE on failure */ -bool start_all_cpus(secondary_entry_fn entry, uint32_t r3) +bool start_all_cpus(secondary_entry_fn entry) { - struct secondary_entry_data data = { entry, r3, 0 }; + struct secondary_entry_data data = { entry }; + uint64_t tb; int ret; + assert(nr_cpus_online == 1); + assert(nr_started == 1); ret = dt_for_each_cpu_node(start_each_secondary, &data); assert(ret == 0); + assert(nr_started == nr_cpus_present); + + tb = get_tb(); + while (nr_cpus_online < nr_cpus_present) { + if (get_tb() - tb > 3*tb_hz) { + printf("failed to start all secondaries\n"); + assert(0); + } + cpu_relax(); + } + + return 1; +} + +/* + * Start stopped thread cpu_id at entry + * Returns: <0 on failure to start stopped cpu + * 0 on success + * >0 on cpu not in stopped state + */ +static int wait_thread(int cpu_id) +{ + uint64_t tb; + + /* Skip the caller */ + if (cpu_id == smp_processor_id()) { + return 0; + } + + tb = get_tb(); + while (cpu_is_running(cpu_id)) { + if (get_tb() - tb > 3*tb_hz) { + printf("Timeout waiting to stop CPU:%d\n", cpu_id); + return 1; + } + } + + return 0; +} + +/* + * Wait for running threads (vcpus) on cpu_node to stop + */ +static void wait_core(int cpu_node) +{ + int len, i, nr_threads; + const struct fdt_property *prop; + u32 *threads; + + /* Get the id array of threads on this cpu_node */ + prop = fdt_get_property(dt_fdt(), cpu_node, + "ibm,ppc-interrupt-server#s", &len); + assert(prop); + + nr_threads = len >> 2; /* Divide by 4 since 4 bytes per thread */ + + threads = (u32 *)prop->data; /* Array of valid ids */ + + for (i = 0; i < nr_threads; i++) + wait_thread(fdt32_to_cpu(threads[i])); +} + +static void wait_each_secondary(int fdtnode, u64 regval __unused, void *info) +{ + wait_core(fdtnode); +} + +void stop_all_cpus(void) +{ + while (nr_cpus_online > 1) + cpu_relax(); - /* We expect that we come in with one thread already started */ - return data.nr_started == nr_threads - 1; + dt_for_each_cpu_node(wait_each_secondary, NULL); + mb(); + nr_started = 1; } diff --git a/lib/ppc64/asm-offsets.c b/lib/ppc64/asm-offsets.c index 7843a20b4..ba1a045df 100644 --- a/lib/ppc64/asm-offsets.c +++ b/lib/ppc64/asm-offsets.c @@ -6,6 +6,8 @@ #include #include #include +#include +#include int main(void) { @@ -50,5 +52,12 @@ int main(void) DEFINE(_XER, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, xer)); DEFINE(_CCR, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, ccr)); DEFINE(_TRAP, STACK_FRAME_OVERHEAD+offsetof(struct pt_regs, trap)); + + DEFINE(SIZEOF_STRUCT_CPU, sizeof(struct cpu)); + DEFINE(CPU_SERVER_NO, offsetof(struct cpu, server_no)); + DEFINE(CPU_STACK, offsetof(struct cpu, stack)); + DEFINE(CPU_EXCEPTION_STACK, offsetof(struct cpu, exception_stack)); + DEFINE(MAX_CPUS, NR_CPUS); + return 0; } diff --git a/lib/ppc64/asm/atomic.h b/lib/ppc64/asm/atomic.h new file mode 100644 index 000000000..0f461b9ce --- /dev/null +++ b/lib/ppc64/asm/atomic.h @@ -0,0 +1,6 @@ +#ifndef _POWERPC_ATOMIC_H_ +#define _POWERPC_ATOMIC_H_ + +#include "asm-generic/atomic.h" + +#endif /* _POWERPC_ATOMIC_H_ */ diff --git a/lib/ppc64/asm/barrier.h b/lib/ppc64/asm/barrier.h index 76f6efa78..d2df29520 100644 --- a/lib/ppc64/asm/barrier.h +++ b/lib/ppc64/asm/barrier.h @@ -1,6 +1,8 @@ #ifndef _ASMPPC64_BARRIER_H_ #define _ASMPPC64_BARRIER_H_ +#define pause_short() asm volatile(".long 0x7c40003c" ::: "memory") + #define mb() asm volatile("sync":::"memory") #define rmb() asm volatile("sync":::"memory") #define wmb() asm volatile("sync":::"memory") diff --git a/lib/ppc64/asm/opal.h b/lib/ppc64/asm/opal.h index de64e2c8d..6c3e9ffe2 100644 --- a/lib/ppc64/asm/opal.h +++ b/lib/ppc64/asm/opal.h @@ -2,14 +2,21 @@ #ifndef _ASMPPC64_OPAL_H_ #define _ASMPPC64_OPAL_H_ +#include + #define OPAL_SUCCESS 0 #define OPAL_CONSOLE_WRITE 1 #define OPAL_CONSOLE_READ 2 #define OPAL_CEC_POWER_DOWN 5 #define OPAL_POLL_EVENTS 10 +#define OPAL_START_CPU 41 +#define OPAL_QUERY_CPU_STATUS 42 +#define OPAL_RETURN_CPU 69 #define OPAL_REINIT_CPUS 70 # define OPAL_REINIT_CPUS_HILE_BE (1 << 0) # define OPAL_REINIT_CPUS_HILE_LE (1 << 1) +int64_t opal_call(int64_t token, int64_t arg1, int64_t arg2, int64_t arg3); + #endif diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common index 6374418d2..b98f71c2f 100644 --- a/powerpc/Makefile.common +++ b/powerpc/Makefile.common @@ -12,6 +12,7 @@ tests-common = \ $(TEST_DIR)/rtas.elf \ $(TEST_DIR)/emulator.elf \ $(TEST_DIR)/tm.elf \ + $(TEST_DIR)/smp.elf \ $(TEST_DIR)/sprs.elf \ $(TEST_DIR)/interrupts.elf diff --git a/powerpc/cstart64.S b/powerpc/cstart64.S index 405cb0561..b4eb70696 100644 --- a/powerpc/cstart64.S +++ b/powerpc/cstart64.S @@ -125,6 +125,50 @@ start: bl exit b halt +/* + * start_secondary is the secondary entry point. r3 contains the cpu id + */ +.globl start_secondary +start_secondary: + FIXUP_ENDIAN + /* Switch to 64-bit mode */ + mfmsr r1 + li r2,1 + sldi r2,r2,MSR_SF_BIT + or r1,r1,r2 + mtmsrd r1 + + bl 0f +0: mflr r31 + subi r31, r31, 0b - start /* QEMU's kernel load address */ + + ld r2, (p_toc - start)(r31) + + LOAD_REG_ADDR(r9, cpus) + li r8,0 + li r7,0 +1: add r6,r9,r7 + ld r6,CPU_SERVER_NO(r6) + cmpd r6,r3 + beq 2f + addi r7,r7,SIZEOF_STRUCT_CPU + addi r8,r8,1 + cmpdi r8,MAX_CPUS + bne 1b + b . + +2: add r3,r9,r7 + ld r1,CPU_STACK(r3) + + /* Zero backpointers in initial stack frame so backtrace() stops */ + li r0,0 + std r0,0(r1) + std r0,16(r1) + + bl main_secondary + bl exit + b halt + .align 3 p_stack: .llong stackptr p_toc: .llong tocptr @@ -257,7 +301,8 @@ do_handle_exception_return: . = \vec mtsprg1 r1 /* save r1 */ - mfsprg0 r1 /* get exception stack address */ + mfsprg0 r1 /* get struct cpu address */ + ld r1,CPU_EXCEPTION_STACK(r1) /* get exception stack address */ subi r1,r1, INT_FRAME_SIZE /* save r0 and ctr to call generic handler */ @@ -273,7 +318,8 @@ do_handle_exception_return: . = \vec mtsprg1 r1 /* save r1 */ - mfsprg0 r1 /* get exception stack address */ + mfsprg0 r1 /* get struct cpu address */ + ld r1,CPU_EXCEPTION_STACK(r1) /* get exception stack address */ subi r1,r1, INT_FRAME_SIZE /* save r0 and ctr to call generic handler */ diff --git a/powerpc/selftest.c b/powerpc/selftest.c index 7acff7104..8d1a2c767 100644 --- a/powerpc/selftest.c +++ b/powerpc/selftest.c @@ -8,6 +8,7 @@ #include #include #include +#include static void check_setup(int argc, char **argv) { @@ -34,7 +35,8 @@ static void check_setup(int argc, char **argv) } else if (strcmp(argv[i], "smp") == 0) { - report(nr_cpus == (int)val, "nr_cpus = %d", nr_cpus); + report(nr_cpus_present == (int)val, + "nr_cpus_present = %d", nr_cpus_present); ++nr_tests; } diff --git a/powerpc/smp.c b/powerpc/smp.c new file mode 100644 index 000000000..644cf1c75 --- /dev/null +++ b/powerpc/smp.c @@ -0,0 +1,348 @@ +/* SPDX-License-Identifier: LGPL-2.0-only */ +/* + * SMP and IPI Tests + * + * Copyright 2024 Nicholas Piggin, IBM Corp. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static volatile bool start_test_running = true; +static volatile int nr_cpus_started; + +static void start_fn(int cpu_id) +{ + atomic_fetch_inc(&nr_cpus_started); + while (start_test_running) + cpu_relax(); + atomic_fetch_dec(&nr_cpus_started); +} + +static void test_start_cpus(int argc, char **argv) +{ + uint64_t tb; + + if (argc > 2) + report_abort("Unsupported argument: '%s'", argv[2]); + + nr_cpus_started = 1; + if (!start_all_cpus(start_fn)) + report_abort("Failed to start secondary cpus"); + + tb = get_tb(); + while (nr_cpus_started < nr_cpus_present) { + cpu_relax(); + if (get_tb() - tb > tb_hz * 5) + report_abort("Failed to start all secondaries"); + } + + if (nr_cpus_started != nr_cpus_online) + report_abort("Started CPUs does not match online"); + + barrier(); + start_test_running = false; + barrier(); + + tb = get_tb(); + while (nr_cpus_started > 1) { + cpu_relax(); + if (get_tb() - tb > tb_hz * 5) + report_abort("Failed to stop all secondaries"); + } + + stop_all_cpus(); + + report(true, "start cpus"); +} + +static volatile int nr_cpus_ipi = 0; + +static void ipi_handler(struct pt_regs *regs, void *data) +{ + atomic_fetch_inc(&nr_cpus_ipi); +} + +static volatile bool ipi_test_running = true; + +static void ipi_fn(int cpu_id) +{ + local_ipi_enable(); + + mtspr(SPR_DEC, 0x7fffffff); + local_irq_enable(); + while (ipi_test_running) + cpu_relax(); + local_irq_disable(); + + local_ipi_disable(); +} + +static void test_ipi_cpus(int argc, char **argv) +{ + uint64_t tb; + int i; + + if (argc > 2) + report_abort("Unsupported argument: '%s'", argv[2]); + + if (nr_cpus_present < 2) { + report_skip("Requires SMP (2 or more CPUs)"); + return; + } + + register_ipi(ipi_handler, NULL); + + if (!start_all_cpus(ipi_fn)) + report_abort("Failed to start secondary cpus"); + + for (i = 1; i < nr_cpus_online; i++) + send_ipi(cpus[i].server_no); + + tb = get_tb(); + while (nr_cpus_ipi < nr_cpus_online - 1) { + cpu_relax(); + if (get_tb() - tb > tb_hz * 5) + report_abort("Secondaries failed to respond to IPIs"); + } + + send_ipi(cpus[1].server_no); + + tb = get_tb(); + while (nr_cpus_ipi < nr_cpus_online) { + cpu_relax(); + if (get_tb() - tb > tb_hz * 5) + report_abort("Secondaries failed to respond to IPIs"); + } + + ipi_test_running = false; + + stop_all_cpus(); + + assert(nr_cpus_ipi == nr_cpus_present); + + unregister_ipi(); + + report(true, "IPI cpus"); +} + +static uint64_t time; +static bool time_went_backward; + +static void check_and_record_time(void) +{ + uint64_t tb; + uint64_t t; + uint64_t old; + + t = time; +again: + barrier(); + tb = get_tb(); + asm volatile("1: ldarx %0,0,%1 ; cmpd %0,%2 ; bne 2f ; stdcx. %3,0,%1 ; bne- 1b; 2:" : "=&r"(old) : "r"(&time), "r"(t), "r"(tb) : "memory", "cr0"); + assert(tb >= t); + if (old != t) { + t = old; + goto again; + } + if (old > tb) + time_went_backward = true; +} + +static void update_time(int64_t tb_offset) +{ + uint64_t new_tb; + + new_tb = get_tb() + tb_offset; + mtspr(SPR_TBU40, new_tb); + if ((get_tb() & 0xFFFFFF) < (new_tb & 0xFFFFFF)) { + new_tb += 0x1000000; + mtspr(SPR_TBU40, new_tb); + } +} + +static void time_sync_fn(int cpu_id) +{ + uint64_t start = get_tb(); + + while (!time_went_backward && get_tb() - start < tb_hz*2) { + check_and_record_time(); + cpu_relax(); + } + + while (!time_went_backward && get_tb() - start < tb_hz*2) { + check_and_record_time(); + udelay(1); + } + + if (machine_is_powernv()) { + while (!time_went_backward && get_tb() - start < tb_hz*2) { + check_and_record_time(); + update_time(0x1234000000); + cpu_relax(); + update_time(-0x1234000000); + } + } +} + +static void test_time_sync(int argc, char **argv) +{ + if (argc > 2) + report_abort("Unsupported argument: '%s'", argv[2]); + + if (nr_cpus_present < 2) { + report_skip("Requires SMP (2 or more CPUs)"); + return; + } + + time_went_backward = false; + + if (!start_all_cpus(time_sync_fn)) + report_abort("Failed to start secondary cpus"); + + time_sync_fn(-1); + + stop_all_cpus(); + + report(!time_went_backward, "time sync"); +} + +static volatile bool relax_test_running = true; + +static int relax_loop_count[NR_CPUS]; + +static void relax_fn(int cpu_id) +{ + volatile int i = 0; + + while (relax_test_running) { + cpu_relax(); + i++; + } + + relax_loop_count[cpu_id] = i; +} + +#define ITERS 1000000 + +static void test_relax(int argc, char **argv) +{ + volatile int i; + int count; + + if (argc > 2) + report_abort("Unsupported argument: '%s'", argv[2]); + + if (nr_cpus_present < 2) { + report_skip("Requires SMP (2 or more CPUs)"); + return; + } + + if (!start_all_cpus(relax_fn)) + report_abort("Failed to start secondary cpus"); + + for (i = 0; i < ITERS; i++) + ; + + relax_test_running = false; + + stop_all_cpus(); + + count = 0; + for (i = 0; i < NR_CPUS; i++) + count += relax_loop_count[i]; + if (count == 0) + count = 1; + + report(true, "busy-loops on CPU:%d vs cpu_relax-loops on others %ld%%", smp_processor_id(), (long)ITERS * 100 / count); +} + +static volatile bool pause_test_running = true; + +static int pause_loop_count[NR_CPUS]; + +static void pause_fn(int cpu_id) +{ + volatile int i = 0; + + while (pause_test_running) { + pause_short(); + i++; + } + + pause_loop_count[cpu_id] = i; +} + +#define ITERS 1000000 + +static void test_pause(int argc, char **argv) +{ + volatile int i; + int count; + + if (argc > 2) + report_abort("Unsupported argument: '%s'", argv[2]); + + if (!cpu_has_pause_short) + return; + + if (nr_cpus_present < 2) { + report_skip("Requires SMP (2 or more CPUs)"); + return; + } + + if (!start_all_cpus(pause_fn)) + report_abort("Failed to start secondary cpus"); + + for (i = 0; i < ITERS; i++) + ; + + pause_test_running = false; + + stop_all_cpus(); + + count = 0; + for (i = 0; i < NR_CPUS; i++) + count += pause_loop_count[i]; + + report(true, "busy-loops on CPU:%d vs pause_short-loops on others %ld%%", smp_processor_id(), (long)ITERS * 100 / count); +} + +struct { + const char *name; + void (*func)(int argc, char **argv); +} hctests[] = { + { "start_cpus", test_start_cpus }, + { "ipi_cpus", test_ipi_cpus }, + { "time_sync", test_time_sync }, + { "cpu_relax", test_relax }, + { "pause", test_pause }, + { NULL, NULL } +}; + +int main(int argc, char **argv) +{ + bool all; + int i; + + all = argc == 1 || !strcmp(argv[1], "all"); + + report_prefix_push("smp"); + + for (i = 0; hctests[i].name != NULL; i++) { + if (all || strcmp(argv[1], hctests[i].name) == 0) { + report_prefix_push(hctests[i].name); + hctests[i].func(argc, argv); + report_prefix_pop(); + } + } + + report_prefix_pop(); + return report_summary(); +} diff --git a/powerpc/tm.c b/powerpc/tm.c index d9e7f455d..507eaf492 100644 --- a/powerpc/tm.c +++ b/powerpc/tm.c @@ -89,7 +89,7 @@ static void test_h_cede_tm(int argc, char **argv) if (argc > 2) report_abort("Unsupported argument: '%s'", argv[2]); - if (!start_all_cpus(halt, 0)) + if (!start_all_cpus(halt)) report_abort("Failed to start secondary cpus"); if (!enable_tm()) @@ -133,8 +133,9 @@ int main(int argc, char **argv) report_skip("TM is not available"); goto done; } + /* kvm-unit-tests can limit number of CPUs present */ /* KVM does not report TM in secondary threads in POWER9 */ - report_kfail(true, cpus_with_tm == nr_cpus, + report_kfail(true, cpus_with_tm >= nr_cpus_present, "TM available in all 'ibm,pa-features' properties"); all = argc == 1 || !strcmp(argv[1], "all"); diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index 03d7b60e5..aa707e0f3 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -69,6 +69,14 @@ file = emulator.elf [interrupts] file = interrupts.elf +[smp] +file = smp.elf +smp = 2 + +[smp-smt] +file = smp.elf +smp = 8,threads=4 + [h_cede_tm] file = tm.elf machine = pseries From patchwork Sat May 4 12:28:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931284 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=huaWFRpL; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWnMl6nPkz1xnT for ; Sat, 4 May 2024 22:40:51 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=huaWFRpL; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWnMl46z6z3gBX for ; Sat, 4 May 2024 22:40:51 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=huaWFRpL; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42d; helo=mail-pf1-x42d.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn7B6Vwkz30WD for ; Sat, 4 May 2024 22:29:58 +1000 (AEST) Received: by mail-pf1-x42d.google.com with SMTP id d2e1a72fcca58-6f4496af4cdso474142b3a.0 for ; Sat, 04 May 2024 05:29:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825796; x=1715430596; darn=lists.ozlabs.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=FibUaZR7a7YpmE3r8aur9Iczi126UDYou5egcERbaPU=; b=huaWFRpLgaf8GB5SOPrkGMDon5Z4DlraVctkt8nflBGvX6+foeO14O/G1sBb9VHwp8 gciTne6ea6LcRyJ3rCWosb4aKeKkjtpk7bELvtjIMVq2NrSVBnrDZna7qUG2v2u11ZbH giJ+o+/mdR34RPij2s86cHAN2ML9ew2nBoSk9yUxaFmp2rTizGxeEqj8dJOvCwcamJE8 eX4RFxFrW7UaAfXvspwmN1+SCy8n4He1QpD9YUpACKvAvVnKCmEMb066uuWiSVPN7eH/ XMhe0PpF9/6B8PC/pK2Ap/VKsFIxANRbm2y8ENdojDGHjT0wq5GNWrnAc9q0NvMpG+x9 meTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825796; x=1715430596; 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=FibUaZR7a7YpmE3r8aur9Iczi126UDYou5egcERbaPU=; b=qbufRzdKrZbX40B2xU1Qj/QI3sf+hPP2KRIk1cJJ8jpPyABqJBpvpeU3O33UkXre/j T3f3FTUBSxOnnjftv7yw4T+Xkm2cpSmAAAwuT40LhrKNw9hnlwoAFnu96nhxHp2wwCbn bNaSAtpg5olZcu/Uncj1NofGk+uN+H2pW47PXZ2WoD5Rwocn92V9Eizo7eLdRm4nOSX2 pqIddmLuuafllRRl7h7s8gbVIMuxA3Lookvdh14YeAyc5rMz4wZajN+ft7Oct4UDzqv6 L2Tqf36rK+V2ws4F4rWcqH+OK90qXGqHbXxTSrZKsLz2lHIxT4+Fw6JQH3gwwvisBLIC iHBg== X-Forwarded-Encrypted: i=1; AJvYcCXtbrlJIPkL89cItpSoG1t/g1wtYeA2OAoTT8Xhqj2hY46keY3ZYWkLeGDi/xXnA2AAHJ/XQMICBwXbADVosWe84FqO9sKKy7pUEhpE6A== X-Gm-Message-State: AOJu0Yyzs5BYAIycAQjxpJohEQyfXf/YypvlGlu0yj3OpMuZeKtzkz0b YC1kun1AWakR9NmKzzm0ttAowi1ijXIxEhV2e6taYliOF4Kea+ytQX3y9Q== X-Google-Smtp-Source: AGHT+IFg9G2Bb7q3NP5uRAnJ4+QwVnW2uvirGMpGnluQF6UbjZr9y1Mkv1rM0MtalmE/Lrd9dZQD6g== X-Received: by 2002:a05:6a00:4b4d:b0:6f4:4723:98ad with SMTP id kr13-20020a056a004b4d00b006f4472398admr6462655pfb.16.1714825796206; Sat, 04 May 2024 05:29:56 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.29.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:29:55 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 17/31] powerpc: Add cpu_relax Date: Sat, 4 May 2024 22:28:23 +1000 Message-ID: <20240504122841.1177683-18-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Add a cpu_relax variant that uses SMT priority nop instructions like Linux. This was split out of the SMP patch because it affects the sprs test case. Signed-off-by: Nicholas Piggin Reviewed-by: Thomas Huth --- lib/ppc64/asm/barrier.h | 1 + powerpc/sprs.c | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/ppc64/asm/barrier.h b/lib/ppc64/asm/barrier.h index d2df29520..475434b6a 100644 --- a/lib/ppc64/asm/barrier.h +++ b/lib/ppc64/asm/barrier.h @@ -1,6 +1,7 @@ #ifndef _ASMPPC64_BARRIER_H_ #define _ASMPPC64_BARRIER_H_ +#define cpu_relax() asm volatile("or 1,1,1 ; or 2,2,2" ::: "memory") #define pause_short() asm volatile(".long 0x7c40003c" ::: "memory") #define mb() asm volatile("sync":::"memory") diff --git a/powerpc/sprs.c b/powerpc/sprs.c index de9e87a21..c5844985a 100644 --- a/powerpc/sprs.c +++ b/powerpc/sprs.c @@ -228,8 +228,8 @@ static const struct spr sprs_power_common[1024] = { [815] = { "TAR", 64, RW, }, [848] = { "IC", 64, HV_RW | OS_RO, SPR_ASYNC, }, [849] = { "VTB", 64, HV_RW | OS_RO, SPR_ASYNC, }, -[896] = { "PPR", 64, RW, }, -[898] = { "PPR32", 32, RW, }, +[896] = { "PPR", 64, RW, SPR_ASYNC, }, /* PPR(32) is changed by cpu_relax(), appears to be async */ +[898] = { "PPR32", 32, RW, SPR_ASYNC, }, [1023]= { "PIR", 32, OS_RO, SPR_ASYNC, }, /* Can't be virtualised, appears to be async */ }; From patchwork Sat May 4 12:28:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931286 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=hyns2iVK; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWnPS3cfTz1xnT for ; Sat, 4 May 2024 22:42:20 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=hyns2iVK; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWnPS28yrz3ftS for ; Sat, 4 May 2024 22:42:20 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=hyns2iVK; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2001:4860:4864:20::2c; helo=mail-oa1-x2c.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-oa1-x2c.google.com (mail-oa1-x2c.google.com [IPv6:2001:4860:4864:20::2c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn7H0DTmz30Tf for ; Sat, 4 May 2024 22:30:02 +1000 (AEST) Received: by mail-oa1-x2c.google.com with SMTP id 586e51a60fabf-2343ae31a9bso288498fac.1 for ; Sat, 04 May 2024 05:30:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825800; x=1715430600; darn=lists.ozlabs.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=Z4h54USUHBKAJcfNGm1VvT3BcXAZlUGZA4uOX+ggTWE=; b=hyns2iVKNteHdUKE8L1CfDbmpcBP/fmbNCuW3sCPK9J6Whw4OrZ4YvTJvyL0IXT2T7 gJBtclGgU+ViQ0yqrzJY+jTFuFTSA0zGrdhJUtqc6QyMO1QSClUFz3IMbQ+p7dRv3K6z Ei5foj+1A7VcV9b0UDuQNphcjJh+gmBNNPQuMHGyKWv+AzMI4o5lc3S4TQAnjgFEOmiA CCQb02O0lIlhU6h6zNhdw6pnvabY9o+XM7TFW8fKHWI3uF5rqMz8VtvZoVV7z2KLD4pZ V/JIQgjyPJZs+IlEr2inOCbmqaI/jpntzabU25POE2eefofiHNUkyf544SAIILk+JKIK TfGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825800; x=1715430600; 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=Z4h54USUHBKAJcfNGm1VvT3BcXAZlUGZA4uOX+ggTWE=; b=P8mhDdn36s1JRSzmxYYQZY1Bqsa47MYeqdL8Kqt+Ac5kSVhnC+5L2Px6I/+hV56swS u1uY/7MZCplAmG+6K8PHH65OkilGk+SeUDSeNINSn9quMTuFxr4Wwkvp55goNKC7rz2g gR4KPxZLZjxCjP7mE6iXbIxNkK5tx394ACS0vhC6JCqntPfKHneliKq9lzIRVq0fEp4u NJ78mx/eyl+mGeMVK545PEVl1JrlmJfbDj1cpSewesPtkNhD1V9K6TmoTtDts3Xf1TYT SA3vBkKhK2qjvMdiqJwYwPM+0KVOLWMWXlMVPUm3bEtKGfzyBUKF+exOENPdrc17thUY zgKg== X-Forwarded-Encrypted: i=1; AJvYcCUeB8RSOALLGTvToBzNrvA30No7tJm+Q2FCxuNKW8t18Pg9v7jOFdQy77kgPJMj420hG6c5qyjbVNS43JVTyd+3Pt2R0BjPlFzaZmXmaQ== X-Gm-Message-State: AOJu0YzYSh0eG3Nkpr/zFgoRlHLTheb0nyn2sBWsFajaIWRdYC5RAUyY j3w5OCkxTKYrHdoB+b13XNJShyyoQ+bAPQNcLD5K+6f/cY2EoiD/ X-Google-Smtp-Source: AGHT+IEvzIyj5q/YWunpbhcGD2rfjuIoMmYhPDFOu5tKaJohsYhSC3wKPUC/yABZy9c9/DJ3fHCG+g== X-Received: by 2002:a05:6871:5213:b0:23c:e7b:9208 with SMTP id ht19-20020a056871521300b0023c0e7b9208mr7091453oac.17.1714825800287; Sat, 04 May 2024 05:30:00 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.29.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:30:00 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 18/31] powerpc: Permit ACCEL=tcg,thread=single Date: Sat, 4 May 2024 22:28:24 +1000 Message-ID: <20240504122841.1177683-19-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Modify run script to permit single vs mttcg threading, add a thread=single smp case to unittests.cfg. Signed-off-by: Nicholas Piggin Reviewed-by: Thomas Huth --- powerpc/run | 4 ++-- powerpc/unittests.cfg | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/powerpc/run b/powerpc/run index 172f32a46..27abf1ef6 100755 --- a/powerpc/run +++ b/powerpc/run @@ -36,8 +36,8 @@ if ! $qemu -machine '?' 2>&1 | grep $MACHINE > /dev/null; then exit 2 fi +A="-accel $ACCEL$ACCEL_PROPS" M="-machine $MACHINE" -M+=",accel=$ACCEL$ACCEL_PROPS" B="" D="" @@ -54,7 +54,7 @@ if [[ "$MACHINE" == "powernv"* ]] ; then D+="-device ipmi-bmc-sim,id=bmc0 -device isa-ipmi-bt,bmc=bmc0,irq=10" fi -command="$qemu -nodefaults $M $B $D" +command="$qemu -nodefaults $A $M $B $D" command+=" -display none -serial stdio -kernel" command="$(migration_cmd) $(timeout_cmd) $command" diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index aa707e0f3..5c458996b 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -77,6 +77,12 @@ smp = 2 file = smp.elf smp = 8,threads=4 +# mttcg is the default most places, so add a thread=single test +[smp-thread-single] +file = smp.elf +smp = 8,threads=4 +accel = tcg,thread=single + [h_cede_tm] file = tm.elf machine = pseries From patchwork Sat May 4 12:28:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931287 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=dJUdjfs3; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWnQF2ccYz1xnT for ; Sat, 4 May 2024 22:43:01 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=dJUdjfs3; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWnQF1FBHz3fw5 for ; Sat, 4 May 2024 22:43:01 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=dJUdjfs3; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42f; helo=mail-pf1-x42f.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn7K5ynFz30VN for ; Sat, 4 May 2024 22:30:05 +1000 (AEST) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6f44390e328so524623b3a.2 for ; Sat, 04 May 2024 05:30:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825804; x=1715430604; darn=lists.ozlabs.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=1J1rerHtz2/IUl9CIlFdWIoy05A/oeTKAK2mDsoOQ0I=; b=dJUdjfs3aKFAMLpCcvgMWSKe77IcjUiLHpwU6QhB+A1D4wW4KT3zYFiLdCeYIFKOMa c3ol2fTk7/XgMy81OloM2gtNEdOBmR7DXGJTUgYFy192QGFPy+sPiSZTmOwLKxhIkODC asjqO0+Js7uK8KiSaiWf4Xiin1JKOmchaZCP+tag8HzTFXITQTpqa85oazECxnEfkwGI 3S9aTjFKEil4l1sQ7ni98YFYM9cXoSgV67B3eRInSuIieSKUr37Wgp80YCH5Gc1/OHoK 9wBFq5rPyxk7adcQqgkMJVaYDvv/Y1pHWi3gvkMl69jKvfOSCjMAEBqTOAQNg/cyHXW7 QgzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825804; x=1715430604; 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=1J1rerHtz2/IUl9CIlFdWIoy05A/oeTKAK2mDsoOQ0I=; b=PP6of3ygYcNigWWOXZFZ+OwXo6ogMikCEQxHaKIfQ7F6SmRtANIJfjCBJnPpysjcXk RpihLvv/OuUjnETz7jfL2CgplsDtBVDnrGtPLL33UC8Zb1gq8OrmXAn8w0gOjJecP4to NU62irpqlWCPKk0LswmY2fSXEkmfoNBLW+x0UOybBxo5CDfaIhdyJiUlsBW/o38CM3Af aTziN3VzzIMDt6nQCzv8TI1MfKIR+LXVw04r98spuoLDIcV26akfka1V6DxXq5E9FUGf SxAWAgXZN8yDP4DikKmvGagQ/RZ4ZXrmVfATNFnDNUCa+cWN0cUdaCJaUlkp6kmTVSh8 YAcA== X-Forwarded-Encrypted: i=1; AJvYcCXJMmGwOWxHfOGMx1tVjD+UZuUir0FQjUQ1ONx22iks+VsvXIH1rEZZ+kH2UMcNa4JvH9lQ41pFluhix/QgUGR7lPS4Ksawv/OIGv0sgA== X-Gm-Message-State: AOJu0YyJz/+Ta94bD9Wja1oAgSaayV7tq3X0I4FU/zt2XkJZidZiBu9f q2FAjgkOxOYyWQrL7Wp+HiWD4q8pRQDVAAUqxk9mh6bKfLwB+MAhgm8bIw== X-Google-Smtp-Source: AGHT+IE705BbaLHg0dkpi38AsyXDqDVglxsJuuZBWB5uM1M5vnAAvSQE55y3EV0uFEDzYsyhbYKW+A== X-Received: by 2002:a05:6a00:1799:b0:6ed:4aaa:3cbf with SMTP id s25-20020a056a00179900b006ed4aaa3cbfmr6768331pfg.3.1714825804126; Sat, 04 May 2024 05:30:04 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.30.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:30:03 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 19/31] powerpc: Avoid using larx/stcx. in spinlocks when only one CPU is running Date: Sat, 4 May 2024 22:28:25 +1000 Message-ID: <20240504122841.1177683-20-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" The test harness uses spinlocks if they are implemented with larx/stcx. it can prevent some test scenarios such as testing migration of a reservation. Signed-off-by: Nicholas Piggin --- lib/powerpc/asm/smp.h | 1 + lib/powerpc/smp.c | 5 +++++ lib/powerpc/spinlock.c | 29 +++++++++++++++++++++++++++++ lib/ppc64/asm/spinlock.h | 7 ++++++- powerpc/Makefile.common | 1 + 5 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 lib/powerpc/spinlock.c diff --git a/lib/powerpc/asm/smp.h b/lib/powerpc/asm/smp.h index c45988bfa..66188b9dd 100644 --- a/lib/powerpc/asm/smp.h +++ b/lib/powerpc/asm/smp.h @@ -15,6 +15,7 @@ struct cpu { extern int nr_cpus_present; extern int nr_cpus_online; +extern bool multithreaded; extern struct cpu cpus[]; register struct cpu *__current_cpu asm("r13"); diff --git a/lib/powerpc/smp.c b/lib/powerpc/smp.c index 27b169841..73c0ef214 100644 --- a/lib/powerpc/smp.c +++ b/lib/powerpc/smp.c @@ -276,6 +276,8 @@ static void start_each_secondary(int fdtnode, u64 regval __unused, void *info) start_core(fdtnode, datap->entry); } +bool multithreaded = false; + /* * Start all stopped cpus on the guest at entry with register 3 set to r3 * We expect that we come in with only one thread currently started @@ -290,6 +292,7 @@ bool start_all_cpus(secondary_entry_fn entry) assert(nr_cpus_online == 1); assert(nr_started == 1); + multithreaded = true; ret = dt_for_each_cpu_node(start_each_secondary, &data); assert(ret == 0); assert(nr_started == nr_cpus_present); @@ -361,10 +364,12 @@ static void wait_each_secondary(int fdtnode, u64 regval __unused, void *info) void stop_all_cpus(void) { + assert(multithreaded); while (nr_cpus_online > 1) cpu_relax(); dt_for_each_cpu_node(wait_each_secondary, NULL); mb(); nr_started = 1; + multithreaded = false; } diff --git a/lib/powerpc/spinlock.c b/lib/powerpc/spinlock.c new file mode 100644 index 000000000..623a1f2c1 --- /dev/null +++ b/lib/powerpc/spinlock.c @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: LGPL-2.0 */ +#include +#include + +/* + * Skip the atomic when single-threaded, which helps avoid larx/stcx. in + * the harness when testing tricky larx/stcx. sequences (e.g., migration + * vs reservation). + */ +void spin_lock(struct spinlock *lock) +{ + if (!multithreaded) { + assert(lock->v == 0); + lock->v = 1; + } else { + while (__sync_lock_test_and_set(&lock->v, 1)) + ; + } +} + +void spin_unlock(struct spinlock *lock) +{ + assert(lock->v == 1); + if (!multithreaded) { + lock->v = 0; + } else { + __sync_lock_release(&lock->v); + } +} diff --git a/lib/ppc64/asm/spinlock.h b/lib/ppc64/asm/spinlock.h index f59eed191..b952386da 100644 --- a/lib/ppc64/asm/spinlock.h +++ b/lib/ppc64/asm/spinlock.h @@ -1,6 +1,11 @@ #ifndef _ASMPPC64_SPINLOCK_H_ #define _ASMPPC64_SPINLOCK_H_ -#include +struct spinlock { + unsigned int v; +}; + +void spin_lock(struct spinlock *lock); +void spin_unlock(struct spinlock *lock); #endif /* _ASMPPC64_SPINLOCK_H_ */ diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common index b98f71c2f..1ee9c25d6 100644 --- a/powerpc/Makefile.common +++ b/powerpc/Makefile.common @@ -49,6 +49,7 @@ cflatobjs += lib/powerpc/rtas.o cflatobjs += lib/powerpc/processor.o cflatobjs += lib/powerpc/handlers.o cflatobjs += lib/powerpc/smp.o +cflatobjs += lib/powerpc/spinlock.o OBJDIRS += lib/powerpc From patchwork Sat May 4 12:28:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931288 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=bK8ErWJa; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWnR15prhz1xnT for ; Sat, 4 May 2024 22:43:41 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=bK8ErWJa; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWnR14Pm7z3fRP for ; Sat, 4 May 2024 22:43:41 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=bK8ErWJa; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::432; helo=mail-pf1-x432.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn7P3LF8z3cWq for ; Sat, 4 May 2024 22:30:09 +1000 (AEST) Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-6f4302187c0so2229767b3a.1 for ; Sat, 04 May 2024 05:30:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825808; x=1715430608; darn=lists.ozlabs.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=mvlqWTm5R6hH1aJHvySsaUaw6d4VUJ6a487Wd4qHA3w=; b=bK8ErWJajUZwROjyc0u/MEHPI9AKpYFsoD+toixJvR8RU+g5+yPEUx7ooBKJ942Ixm HN3emNMxP9e3WQjInyVsoAJG2/wY/cPIq2x39cdHZ8xrN1jisyZqp3CeNEZ64qGAv+ke puxr1neOZJdhGt1IU5Q95ikUQBwaDY9SvCNENH+l1OwvsYaZU5QqW1vm0s3sdTdF6XCE o+SpKGnQEsVuprizIDR4kCd7OaXXTlZPgoeJIranU/jAez9I5fBkYQvZEsgTweohGq8b k2kWp7NuMWL+kVWmDFiYP8mJqI0yTVJhD3V4ZYsDXWYboh0/QrY3sGUvbECBfuCvmy86 2nQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825808; x=1715430608; 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=mvlqWTm5R6hH1aJHvySsaUaw6d4VUJ6a487Wd4qHA3w=; b=k9JQLIwkl1CrUSPGvVZuSiu+I/0vQb/PLoZJEeivBN9W0x6iJUUimtkQxIhb/rVeiy KtearM7qYSisusDINJRLPejJB4TUhKdS5xj9jgJA+F2m0iguxRCONrGzOeU1KioNS0FO glJ6ICqX0ShKpRyjvyNVPUyBTHvyQTerW0ZbPOZHuwyqV4oXKz0IezLwQ3Uck/lulz29 BHTDYiHd3CTJN9CRX94YI+6gd4yD0Gw2qaY34WuRAobUcKyr5D7K8YA8QNYdLrfQMVrS Bgu1TiLvzr3Azzrl7AihTbjNYO9My7LegLPQ0LD+RbvumiXiLVIkGsoJ5k2C9MUsvHYo HJcA== X-Forwarded-Encrypted: i=1; AJvYcCX5HRhiV2dS6sK9/QO/7vwsOo4dQ7NZ6+NppLYtSus7mUM6Fncn0jdnE/Il61nXpLvDILbpjuTd9KDPpRSnmsjn48swWs4Ic2Vb10h2ow== X-Gm-Message-State: AOJu0YyM2QMSCbnvSGhRx5r+SF4+6VNWaLVYw/j6uaTWhugQwPmsDmpC eL9dmraycv5L5TdRa/ZLpSXpNX1u0EL0he+NrQq0Web/T6wjmMef X-Google-Smtp-Source: AGHT+IGtGsf5x/pEdQUlJKVmIg6cVX+m/JLMV6X990354Hcrk/iR00AB92q+lWqDkq9PpcE6KITNrA== X-Received: by 2002:a05:6a20:da83:b0:1af:81fd:63be with SMTP id iy3-20020a056a20da8300b001af81fd63bemr7138409pzb.13.1714825807773; Sat, 04 May 2024 05:30:07 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.30.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:30:07 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 20/31] powerpc: Add atomics tests Date: Sat, 4 May 2024 22:28:26 +1000 Message-ID: <20240504122841.1177683-21-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Signed-off-by: Nicholas Piggin --- powerpc/Makefile.common | 1 + powerpc/atomics.c | 375 ++++++++++++++++++++++++++++++++++++++++ powerpc/unittests.cfg | 9 + 3 files changed, 385 insertions(+) create mode 100644 powerpc/atomics.c diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common index 1ee9c25d6..420103c87 100644 --- a/powerpc/Makefile.common +++ b/powerpc/Makefile.common @@ -11,6 +11,7 @@ tests-common = \ $(TEST_DIR)/spapr_hcall.elf \ $(TEST_DIR)/rtas.elf \ $(TEST_DIR)/emulator.elf \ + $(TEST_DIR)/atomics.elf \ $(TEST_DIR)/tm.elf \ $(TEST_DIR)/smp.elf \ $(TEST_DIR)/sprs.elf \ diff --git a/powerpc/atomics.c b/powerpc/atomics.c new file mode 100644 index 000000000..975711fc8 --- /dev/null +++ b/powerpc/atomics.c @@ -0,0 +1,375 @@ +/* SPDX-License-Identifier: LGPL-2.0-only */ +/* + * Test some powerpc instructions + * + * Copyright 2024 Nicholas Piggin, IBM Corp. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static bool do_migrate; +static bool do_record; + +#define RSV_SIZE 128 + +static uint8_t granule[RSV_SIZE] __attribute((__aligned__(RSV_SIZE))); + +static void spin_lock(unsigned int *lock) +{ + unsigned int old; + + asm volatile ("1:" + "lwarx %0,0,%2;" + "cmpwi %0,0;" + "bne 1b;" + "stwcx. %1,0,%2;" + "bne- 1b;" + "lwsync;" + : "=&r"(old) : "r"(1), "r"(lock) : "cr0", "memory"); +} + +static void spin_unlock(unsigned int *lock) +{ + asm volatile("lwsync;" + "stw %1,%0;" + : "+m"(*lock) : "r"(0) : "memory"); +} + +static volatile bool got_interrupt; +static volatile struct pt_regs recorded_regs; + +static void interrupt_handler(struct pt_regs *regs, void *opaque) +{ + assert(!got_interrupt); + got_interrupt = true; + memcpy((void *)&recorded_regs, regs, sizeof(struct pt_regs)); + regs_advance_insn(regs); +} + +static void test_lwarx_stwcx(int argc, char *argv[]) +{ + unsigned int *var = (unsigned int *)granule; + unsigned int old; + unsigned int result; + + *var = 0; + asm volatile ("1:" + "lwarx %0,0,%2;" + "stwcx. %1,0,%2;" + "bne- 1b;" + : "=&r"(old) : "r"(1), "r"(var) : "cr0", "memory"); + report(old == 0 && *var == 1, "simple update"); + + *var = 0; + asm volatile ("li %0,0;" + "stwcx. %1,0,%2;" + "stwcx. %1,0,%2;" + "bne- 1f;" + "li %0,1;" + "1:" + : "=&r"(result) + : "r"(1), "r"(var) : "cr0", "memory"); + report(result == 0 && *var == 0, "failed stwcx. (no reservation)"); + + *var = 0; + asm volatile ("li %0,0;" + "lwarx %1,0,%4;" + "stw %3,0(%4);" + "stwcx. %2,0,%4;" + "bne- 1f;" + "li %0,1;" + "1:" + : "=&r"(result), "=&r"(old) + : "r"(1), "r"(2), "r"(var) : "cr0", "memory"); + /* This is implementation specific, so don't fail */ + if (result == 0 && *var == 2) + report(true, "failed stwcx. (intervening store)"); + else + report(true, "succeeded stwcx. (intervening store)"); + + handle_exception(0x600, interrupt_handler, NULL); + handle_exception(0x700, interrupt_handler, NULL); + + /* Implementations may not necessarily invoke the alignment interrupt */ + old = 10; + *var = 0; + asm volatile ( + "lwarx %0,0,%1;" + : "+&r"(old) : "r"((char *)var + 1)); + report(old == 10 && got_interrupt && recorded_regs.trap == 0x600, "unaligned lwarx causes fault"); + got_interrupt = false; + + /* + * Unaligned stwcx. is more difficult to test, at least under QEMU, + * the store does not proceed if there is no matching reservation, so + * the alignment handler does not get invoked. This is okay according + * to the Power ISA (unalignment does not necessarily invoke the + * alignment interrupt). But POWER CPUs do cause alignment interrupt. + */ + *var = 0; + asm volatile ( + "lwarx %0,0,%2;" + "stwcx. %1,0,%3;" + : "=&r"(old) : "r"(1), "r"(var), "r"((char *)var+1) : "cr0", "memory"); + /* unaligned larx/stcx. is not required by the ISA to cause an exception, in TCG the stcx does not. */ + report_kfail(true, old == 0 && *var == 0 && got_interrupt && recorded_regs.trap == 0x600, "unaligned stwcx. causes fault"); + got_interrupt = false; + + handle_exception(0x600, NULL, NULL); + +} + +static void test_lqarx_stqcx(int argc, char *argv[]) +{ + union { + __int128_t var; + struct { +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + unsigned long var1; + unsigned long var2; +#else + unsigned long var2; + unsigned long var1; +#endif + }; + } var __attribute__((aligned(16))); + register unsigned long new1 asm("r8"); + register unsigned long new2 asm("r9"); + register unsigned long old1 asm("r10"); + register unsigned long old2 asm("r11"); + unsigned int result; + + var.var1 = 1; + var.var2 = 2; + + (void)new2; + (void)old2; + + old1 = 0; + old2 = 0; + new1 = 3; + new2 = 4; + asm volatile ("1:" + "lqarx %0,0,%4;" + "stqcx. %2,0,%4;" + "bne- 1b;" + : "=&r"(old1), "=&r"(old2) + : "r"(new1), "r"(new2), "r"(&var) + : "cr0", "memory"); + + report(old1 == 2 && old2 == 1 && var.var1 == 4 && var.var2 == 3, + "simple update"); + + var.var1 = 1; + var.var2 = 2; + new1 = 3; + new2 = 4; + asm volatile ("li %0,0;" + "stqcx. %1,0,%3;" + "stqcx. %1,0,%3;" + "bne- 1f;" + "li %0,1;" + "1:" + : "=&r"(result) + : "r"(new1), "r"(new2), "r"(&var) + : "cr0", "memory"); + report(result == 0 && var.var1 == 1 && var.var2 == 2, + "failed stqcx. (no reservation)"); + + var.var1 = 1; + var.var2 = 2; + new1 = 3; + new2 = 4; + asm volatile ("li %0,0;" + "lqarx %1,0,%6;" + "std %5,0(%6);" + "stqcx. %3,0,%6;" + "bne- 1f;" + "li %0,1;" + "1:" + : "=&r"(result), "=&r"(old1), "=&r"(old2) + : "r"(new1), "r"(new2), "r"(0), "r"(&var) + : "cr0", "memory"); + /* This is implementation specific, so don't fail */ + if (result == 0 && (var.var1 == 0 || var.var2 == 0)) + report(true, "failed stqcx. (intervening store)"); + else + report(true, "succeeded stqcx. (intervening store)"); +} + +static void test_migrate_reserve(int argc, char *argv[]) +{ + unsigned int *var = (unsigned int *)granule; + unsigned int old; + int i; + int succeed = 0; + + if (!do_migrate) + return; + + for (i = 0; i < 10; i++) { + *var = 0x12345; + asm volatile ("lwarx %0,0,%1" : "=&r"(old) : "r"(var) : "memory"); + migrate_quiet(); + asm volatile ("stwcx. %0,0,%1" : : "r"(0xf00d), "r"(var) : "cr0", "memory"); + if (*var == 0xf00d) + succeed++; + } + + if (do_record) { + /* + * Running under TCG record-replay, reservations must not + * be lost by migration + */ + report(succeed > 0, "migrated reservation is not lost"); + } else { + report(succeed == 0, "migrated reservation is lost"); + } + + report_prefix_pop(); +} + +#define ITERS 10000000 +static int test_counter = 0; +static void test_inc_perf(int argc, char *argv[]) +{ + int i; + uint64_t tb1, tb2; + + tb1 = get_tb(); + for (i = 0; i < ITERS; i++) + __atomic_fetch_add(&test_counter, 1, __ATOMIC_RELAXED); + tb2 = get_tb(); + report(true, "atomic add takes %ldns", (tb2 - tb1) * 1000000000 / ITERS / tb_hz); + + tb1 = get_tb(); + for (i = 0; i < ITERS; i++) + __atomic_fetch_add(&test_counter, 1, __ATOMIC_SEQ_CST); + tb2 = get_tb(); + report(true, "sequentially conssistent atomic add takes %ldns", (tb2 - tb1) * 1000000000 / ITERS / tb_hz); +} + +static long smp_inc_counter = 0; +static int smp_inc_started; + +static void smp_inc_fn(int cpu_id) +{ + long i; + + atomic_fetch_inc(&smp_inc_started); + while (smp_inc_started < nr_cpus_present) + cpu_relax(); + + for (i = 0; i < ITERS; i++) + atomic_fetch_inc(&smp_inc_counter); + atomic_fetch_dec(&smp_inc_started); +} + +static void test_smp_inc(int argc, char **argv) +{ + if (nr_cpus_present < 2) + return; + + if (!start_all_cpus(smp_inc_fn)) + report_abort("Failed to start secondary cpus"); + + while (smp_inc_started < nr_cpus_present - 1) + cpu_relax(); + smp_inc_fn(smp_processor_id()); + while (smp_inc_started > 0) + cpu_relax(); + + stop_all_cpus(); + + report(smp_inc_counter == nr_cpus_present * ITERS, "counter lost no increments"); +} + +static long smp_lock_counter __attribute__((aligned(128))) = 0; +static unsigned int smp_lock __attribute__((aligned(128))); +static int smp_lock_started; + +static void smp_lock_fn(int cpu_id) +{ + long i; + + atomic_fetch_inc(&smp_lock_started); + while (smp_lock_started < nr_cpus_present) + cpu_relax(); + + for (i = 0; i < ITERS; i++) { + spin_lock(&smp_lock); + smp_lock_counter++; + spin_unlock(&smp_lock); + } + atomic_fetch_dec(&smp_lock_started); +} + +static void test_smp_lock(int argc, char **argv) +{ + if (nr_cpus_present < 2) + return; + + if (!start_all_cpus(smp_lock_fn)) + report_abort("Failed to start secondary cpus"); + + while (smp_lock_started < nr_cpus_present - 1) + cpu_relax(); + smp_lock_fn(smp_processor_id()); + while (smp_lock_started > 0) + cpu_relax(); + + stop_all_cpus(); + + report(smp_lock_counter == nr_cpus_present * ITERS, "counter lost no increments"); +} + +struct { + const char *name; + void (*func)(int argc, char **argv); +} hctests[] = { + { "lwarx/stwcx", test_lwarx_stwcx }, + { "lqarx/stqcx", test_lqarx_stqcx }, + { "migration", test_migrate_reserve }, + { "performance", test_inc_perf }, + { "SMP-atomic", test_smp_inc }, + { "SMP-lock", test_smp_lock }, + { NULL, NULL } +}; + +int main(int argc, char **argv) +{ + int i; + int all; + + all = argc == 1 || !strcmp(argv[1], "all"); + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-r") == 0) { + do_record = true; + } + if (strcmp(argv[i], "-m") == 0) { + do_migrate = true; + } + } + + report_prefix_push("atomics"); + + for (i = 0; hctests[i].name != NULL; i++) { + if (all || strcmp(argv[1], hctests[i].name) == 0) { + report_prefix_push(hctests[i].name); + hctests[i].func(argc, argv); + report_prefix_pop(); + } + } + + report_prefix_pop(); + + return report_summary(); +} diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index 5c458996b..a4210ab2a 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -83,6 +83,15 @@ file = smp.elf smp = 8,threads=4 accel = tcg,thread=single +[atomics] +file = atomics.elf + +[atomics-migration] +file = atomics.elf +machine = pseries +extra_params = -append "migration -m" +groups = migration + [h_cede_tm] file = tm.elf machine = pseries From patchwork Sat May 4 12:28:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931289 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=X3xzGhLI; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWnRq3Ppgz1xnT for ; Sat, 4 May 2024 22:44:23 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=X3xzGhLI; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWnRq1k5Mz3vmV for ; Sat, 4 May 2024 22:44:23 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=X3xzGhLI; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42c; helo=mail-pf1-x42c.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn7V20mTz3c5J for ; Sat, 4 May 2024 22:30:14 +1000 (AEST) Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-6edb76d83d0so511303b3a.0 for ; Sat, 04 May 2024 05:30:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825812; x=1715430612; darn=lists.ozlabs.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=Ex+SxNXbtxHc+7eehoPisO4bpsSQtf/mN9p+UJCwI0U=; b=X3xzGhLIHVmVRI6dZMjBP9g6QnZjQxypW+lcxiC68ELx6FkU8nptZjaiHdNpTxCWS4 6cnupDzNr6HXa7AIFbqXAz6rFiias6rU0dDCWiqJGnIdT+jocR7hBknpYqQsJYgLy3YI PWWqpBNJ9xDYSXucauRB/BvMtKF73rUcDgJSEwwJElAi046mBknZUqD+BI95A0ZJGr9G hsTstVwOhVbpBBWqD2f13PaHUbsNdFOoSYf9jIEc6ZU5QFbt5Mthujs2DHt3ob89pw7i L+f3/V1GYpXpxiDS81XjC4vpANX/PPfuSdRZ9r/zck8YFd0xbQgsWXCik4jTzN4vYgWn hLVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825812; x=1715430612; 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=Ex+SxNXbtxHc+7eehoPisO4bpsSQtf/mN9p+UJCwI0U=; b=jdz7vA6xMH5FzKhBfteKtGT3Q++oR2k3/PDwsa5HJQzroC3TImkaaayQBwxAg+Rna4 BRkurkwp7BowtEaZU2fucYZx/EA3QABaihYYfkLX+mPgQz7qqXVEGaxKmvHLs0cDAj0g 6tP8q6bhUCKdxYi/q2ideL5ABzniAHqmnTsCX8mXXVEm2NAJFmF7m8zFX2VSzYN/hsVs 9Yc9n/F2EW6Qp4g3LMFQNzbKAeuKikJTsLiEOTh+790sryu2qMKmv6R8XGgWcdGIMja7 dCo49Lkp6F9h6+uipfTje/+jmHqw6P8QW0bEw91w52uI4xpYclTG2pepbR6KjCMdi1eU Av7A== X-Forwarded-Encrypted: i=1; AJvYcCWJ6tQfUOrqiUid/cfEw+QwWyukz8izeObx+cHFweV2K5UsvocG/m8/g1QUCOtoXTNlJtY+O9Dtb7nUyXYJkRu+kgSQhPngKk2L2WC/zg== X-Gm-Message-State: AOJu0YxcIyrvsDBOuppLFbrfTQOoz+8fHMw2zoW00HiJDLzVvOWhYeeh kixWZbTe0B+RnDI2rJNb4uhizSUYYf1xeTJ7hWYBs8SIAwChtEjd X-Google-Smtp-Source: AGHT+IG0fFbbW3YKxQSYIB6Odvi+DEnlXT1BnkYx0IAJxuiZdpGcSJo4tew9A3NZcIpQMVmwkeKy0w== X-Received: by 2002:a05:6a00:1704:b0:6f3:854c:dee0 with SMTP id h4-20020a056a00170400b006f3854cdee0mr6747466pfc.21.1714825811715; Sat, 04 May 2024 05:30:11 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.30.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:30:11 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 21/31] powerpc: Add timebase tests Date: Sat, 4 May 2024 22:28:27 +1000 Message-ID: <20240504122841.1177683-22-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" This has a known failure on QEMU TCG machines where the decrementer interrupt is not lowered when the DEC wraps from -ve to +ve. Signed-off-by: Nicholas Piggin --- lib/powerpc/asm/reg.h | 1 + powerpc/Makefile.common | 1 + powerpc/timebase.c | 331 ++++++++++++++++++++++++++++++++++++++++ powerpc/unittests.cfg | 8 + 4 files changed, 341 insertions(+) create mode 100644 powerpc/timebase.c diff --git a/lib/powerpc/asm/reg.h b/lib/powerpc/asm/reg.h index d2ca964c4..12f9e8ac6 100644 --- a/lib/powerpc/asm/reg.h +++ b/lib/powerpc/asm/reg.h @@ -35,6 +35,7 @@ #define SPR_HSRR1 0x13b #define SPR_LPCR 0x13e #define LPCR_HDICE UL(0x1) +#define LPCR_LD UL(0x20000) #define SPR_HEIR 0x153 #define SPR_MMCR0 0x31b #define MMCR0_FC UL(0x80000000) diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common index 420103c87..b273033d1 100644 --- a/powerpc/Makefile.common +++ b/powerpc/Makefile.common @@ -15,6 +15,7 @@ tests-common = \ $(TEST_DIR)/tm.elf \ $(TEST_DIR)/smp.elf \ $(TEST_DIR)/sprs.elf \ + $(TEST_DIR)/timebase.elf \ $(TEST_DIR)/interrupts.elf tests-all = $(tests-common) $(tests) diff --git a/powerpc/timebase.c b/powerpc/timebase.c new file mode 100644 index 000000000..02a4e33c0 --- /dev/null +++ b/powerpc/timebase.c @@ -0,0 +1,331 @@ +/* SPDX-License-Identifier: LGPL-2.0-only */ +/* + * Test Timebase + * + * Copyright 2024 Nicholas Piggin, IBM Corp. + * + * This contains tests of timebase facility, TB, DEC, etc. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int dec_bits = 0; + +static void cpu_dec_bits(int fdtnode, u64 regval __unused, void *arg __unused) +{ + const struct fdt_property *prop; + int plen; + + prop = fdt_get_property(dt_fdt(), fdtnode, "ibm,dec-bits", &plen); + if (!prop) { + dec_bits = 32; + return; + } + + /* Sanity check for the property layout (first two bytes are header) */ + assert(plen == 4); + + dec_bits = fdt32_to_cpu(*(uint32_t *)prop->data); +} + +/* Check amount of CPUs nodes that have the TM flag */ +static int find_dec_bits(void) +{ + int ret; + + ret = dt_for_each_cpu_node(cpu_dec_bits, NULL); + if (ret < 0) + return ret; + + return dec_bits; +} + + +static bool do_migrate = false; +static volatile bool got_interrupt; +static volatile struct pt_regs recorded_regs; + +static uint64_t dec_max; +static uint64_t dec_min; + +static void test_tb(int argc, char **argv) +{ + uint64_t tb; + + tb = get_tb(); + if (do_migrate) + migrate(); + report(get_tb() >= tb, "timebase is incrementing"); +} + +static void dec_stop_handler(struct pt_regs *regs, void *data) +{ + mtspr(SPR_DEC, dec_max); +} + +static void dec_handler(struct pt_regs *regs, void *data) +{ + got_interrupt = true; + memcpy((void *)&recorded_regs, regs, sizeof(struct pt_regs)); + regs->msr &= ~MSR_EE; +} + +static void test_dec(int argc, char **argv) +{ + uint64_t tb1, tb2, dec; + int i; + + handle_exception(0x900, &dec_handler, NULL); + + for (i = 0; i < 100; i++) { + tb1 = get_tb(); + mtspr(SPR_DEC, dec_max); + dec = mfspr(SPR_DEC); + tb2 = get_tb(); + if (tb2 - tb1 < dec_max - dec) + break; + } + /* POWER CPUs can have a slight (few ticks) variation here */ + report_kfail(true, tb2 - tb1 >= dec_max - dec, "decrementer remains within TB after mtDEC"); + + tb1 = get_tb(); + mtspr(SPR_DEC, dec_max); + mdelay(1000); + dec = mfspr(SPR_DEC); + tb2 = get_tb(); + report(tb2 - tb1 >= dec_max - dec, "decrementer remains within TB after 1s"); + + mtspr(SPR_DEC, dec_max); + local_irq_enable(); + local_irq_disable(); + if (mfspr(SPR_DEC) <= dec_max) { + report(!got_interrupt, "no interrupt on decrementer positive"); + } + got_interrupt = false; + + mtspr(SPR_DEC, 1); + mdelay(100); /* Give the timer a chance to run */ + if (do_migrate) + migrate(); + local_irq_enable(); + local_irq_disable(); + report(got_interrupt, "interrupt on decrementer underflow"); + got_interrupt = false; + + if (do_migrate) + migrate(); + local_irq_enable(); + local_irq_disable(); + report(got_interrupt, "interrupt on decrementer still underflown"); + got_interrupt = false; + + mtspr(SPR_DEC, 0); + mdelay(100); /* Give the timer a chance to run */ + if (do_migrate) + migrate(); + local_irq_enable(); + local_irq_disable(); + report(got_interrupt, "DEC deal with set to 0"); + got_interrupt = false; + + /* Test for level-triggered decrementer */ + mtspr(SPR_DEC, -1ULL); + if (do_migrate) + migrate(); + local_irq_enable(); + local_irq_disable(); + report(got_interrupt, "interrupt on decrementer write MSB"); + got_interrupt = false; + + mtspr(SPR_DEC, dec_max); + local_irq_enable(); + if (do_migrate) + migrate(); + mtspr(SPR_DEC, -1); + local_irq_disable(); + report(got_interrupt, "interrupt on decrementer write MSB with irqs on"); + got_interrupt = false; + + mtspr(SPR_DEC, dec_min + 1); + mdelay(100); + local_irq_enable(); + local_irq_disable(); + /* TCG does not model this correctly */ + report_kfail(true, !got_interrupt, "no interrupt after wrap to positive"); + got_interrupt = false; + + handle_exception(0x900, NULL, NULL); +} + +static void test_hdec(int argc, char **argv) +{ + uint64_t tb1, tb2, hdec; + + if (!machine_is_powernv()) { + report_skip("skipping on !powernv machine"); + return; + } + + handle_exception(0x900, &dec_stop_handler, NULL); + handle_exception(0x980, &dec_handler, NULL); + + mtspr(SPR_HDEC, dec_max); + mtspr(SPR_LPCR, mfspr(SPR_LPCR) | LPCR_HDICE); + + tb1 = get_tb(); + mtspr(SPR_HDEC, dec_max); + hdec = mfspr(SPR_HDEC); + tb2 = get_tb(); + report(tb2 - tb1 >= dec_max - hdec, "hdecrementer remains within TB"); + + tb1 = get_tb(); + mtspr(SPR_HDEC, dec_max); + mdelay(1000); + hdec = mfspr(SPR_HDEC); + tb2 = get_tb(); + report(tb2 - tb1 >= dec_max - hdec, "hdecrementer remains within TB after 1s"); + + mtspr(SPR_HDEC, dec_max); + local_irq_enable(); + local_irq_disable(); + if (mfspr(SPR_HDEC) <= dec_max) { + report(!got_interrupt, "no interrupt on decrementer positive"); + } + got_interrupt = false; + + mtspr(SPR_HDEC, 1); + mdelay(100); /* Give the timer a chance to run */ + if (do_migrate) + migrate(); + /* HDEC is edge triggered so ensure it still fires */ + mtspr(SPR_HDEC, dec_max); + local_irq_enable(); + local_irq_disable(); + report(got_interrupt, "interrupt on hdecrementer underflow"); + got_interrupt = false; + + if (do_migrate) + migrate(); + local_irq_enable(); + local_irq_disable(); + report(!got_interrupt, "no interrupt on hdecrementer still underflown"); + got_interrupt = false; + + mtspr(SPR_HDEC, -1ULL); + if (do_migrate) + migrate(); + local_irq_enable(); + local_irq_disable(); + report(got_interrupt, "no interrupt on hdecrementer underflown write MSB"); + got_interrupt = false; + + mtspr(SPR_HDEC, 0); + mdelay(100); /* Give the timer a chance to run */ + if (do_migrate) + migrate(); + /* HDEC is edge triggered so ensure it still fires */ + mtspr(SPR_HDEC, dec_max); + local_irq_enable(); + local_irq_disable(); + report(got_interrupt, "HDEC deal with set to 0"); + got_interrupt = false; + + mtspr(SPR_HDEC, dec_max); + local_irq_enable(); + if (do_migrate) + migrate(); + mtspr(SPR_HDEC, -1ULL); + local_irq_disable(); + report(got_interrupt, "interrupt on hdecrementer write MSB with irqs on"); + got_interrupt = false; + + mtspr(SPR_HDEC, dec_max); + got_interrupt = false; + mtspr(SPR_HDEC, dec_min + 1); + if (do_migrate) + migrate(); + mdelay(100); + local_irq_enable(); + local_irq_disable(); + report(got_interrupt, "got interrupt after wrap to positive"); + got_interrupt = false; + + mtspr(SPR_HDEC, -1ULL); + local_irq_enable(); + local_irq_disable(); + got_interrupt = false; + mtspr(SPR_HDEC, dec_min + 1000000); + if (do_migrate) + migrate(); + mdelay(100); + mtspr(SPR_HDEC, -1ULL); + local_irq_enable(); + local_irq_disable(); + report(got_interrupt, "edge re-armed after wrap to positive"); + got_interrupt = false; + + mtspr(SPR_LPCR, mfspr(SPR_LPCR) & ~LPCR_HDICE); + + handle_exception(0x900, NULL, NULL); + handle_exception(0x980, NULL, NULL); +} + +struct { + const char *name; + void (*func)(int argc, char **argv); +} hctests[] = { + { "tb", test_tb }, + { "dec", test_dec }, + { "hdec", test_hdec }, + { NULL, NULL } +}; + +int main(int argc, char **argv) +{ + bool all; + int i; + + all = argc == 1 || !strcmp(argv[1], "all"); + + for (i = 1; i < argc; i++) { + if (!strcmp(argv[i], "-w")) { + do_migrate = true; + if (!all && argc == 2) + all = true; + } + } + + find_dec_bits(); + dec_max = (1ULL << (dec_bits - 1)) - 1; + dec_min = (1ULL << (dec_bits - 1)); + + if (machine_is_powernv() && dec_bits > 32) { + mtspr(SPR_LPCR, mfspr(SPR_LPCR) | LPCR_LD); + } + + report_prefix_push("timebase"); + + for (i = 0; hctests[i].name != NULL; i++) { + if (all || strcmp(argv[1], hctests[i].name) == 0) { + report_prefix_push(hctests[i].name); + hctests[i].func(argc, argv); + report_prefix_pop(); + } + } + + report_prefix_pop(); + + if (machine_is_powernv() && dec_bits > 32) { + mtspr(SPR_LPCR, mfspr(SPR_LPCR) & ~LPCR_LD); + } + + return report_summary(); +} diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index a4210ab2a..39e6dea3c 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -92,6 +92,14 @@ machine = pseries extra_params = -append "migration -m" groups = migration +[timebase] +file = timebase.elf + +[timebase-icount] +file = timebase.elf +accel = tcg +extra_params = -icount shift=5 + [h_cede_tm] file = tm.elf machine = pseries From patchwork Sat May 4 12:28:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931290 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=mxDeIuHV; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWnSp4VY0z1yb7 for ; Sat, 4 May 2024 22:45:14 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=mxDeIuHV; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWnSp34rlz3fTB for ; Sat, 4 May 2024 22:45:14 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=mxDeIuHV; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42a; helo=mail-pf1-x42a.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn7Y3plPz3cY1 for ; Sat, 4 May 2024 22:30:17 +1000 (AEST) Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6f4521ad6c0so442441b3a.0 for ; Sat, 04 May 2024 05:30:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825816; x=1715430616; darn=lists.ozlabs.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=/CKMERDi15KOz6GwJ7PbGSAZH1z1AoRDwALd66J3X8U=; b=mxDeIuHVBqpSwcd0PuNLDczBGqMHncGpeyEjTMNywctCU+Dhj5TXDP+7SE7GV0CQAN 5jFp1YLJ8v+EuGpU2Xln2kH3sJAR+JfFUgnbs7UZmP3/frh0PLqsV4w+WmCspvBXNxmh Opd77sJYGSRf01MHSdKONXbtcbs9WCzu92X0d7aI2d+Jql81jGPmg7E8oZZ1c+aQfGuE TO/tVbbueWAo5XWcJNX/OpucxqXg9ZAaCJBHEA3VMxBVJ/logJXgor3652m3TiC3LnrA Hs1Vvu6072ZPT7CITQTXN7GHyk7+If1kos/d7dreURKNk4Ul9GNw8rjeX8xcZn1LZC7y C+Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825816; x=1715430616; 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=/CKMERDi15KOz6GwJ7PbGSAZH1z1AoRDwALd66J3X8U=; b=qubgi6F6QDBeNQswOgVYG0IVKx41xciCbsQdkZSaunyaaHvk8UXZ2+wzZaG1Wbv8Vp VwTbV2upuqOjX4P3h2B8AlFg2qK1rP3YOehSuyfy6MiCAVwo49aMOyxpIJgUYx8olLmW +6Y8Db1al1r/d7IPuPGWTcMxPp5867bo/NcVXucaXVVoxXKYG8oZHxae8L0mcJSHtgSm UkhIstbJCz5MfbSKXsKwze2OIpJTG950ATFF1w6fVQ+1uMCzFn95g/jIdivnP9Ellh4z Sa3zs/iGHycEV/AgX7veYiYLeVTmLQMvKR+IDW+sFuPw9pq2tsY2vlW7WJcmt6H8WEiv g3wg== X-Forwarded-Encrypted: i=1; AJvYcCX7cF6Zq2wkVvKihNTX0XpzwrtYU+V3qT9bxomJn7gfdhLQ0HzrVxhoCAEFv9RvFaf6DbwnxejfH3asmaeQKo6KdbmbIi1jV5eLK7LBkw== X-Gm-Message-State: AOJu0YzCJfAFDcIz9HK2QO84StBdbsotwfzE/0RKz4xBRMUrtIhsDbRr SIT78Rm9dk7CgZInatLTcv61ElcJ2dfwi7Nb/D9RbQ0ARsA0d0Hj X-Google-Smtp-Source: AGHT+IGqAyt5fEzNhy0VWtCsC0GkSnROEX8VBW2bdBI+OO+V5N+PWXeQIXiDsYCyQl7jnFg4ZKN/hA== X-Received: by 2002:a05:6a00:4b46:b0:6ec:ff28:df5 with SMTP id kr6-20020a056a004b4600b006ecff280df5mr6006369pfb.27.1714825815510; Sat, 04 May 2024 05:30:15 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.30.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:30:15 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 22/31] powerpc: Add MMU support Date: Sat, 4 May 2024 22:28:28 +1000 Message-ID: <20240504122841.1177683-23-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Add support for radix MMU, 4kB and 64kB pages. This also adds MMU interrupt test cases, and runs the interrupts test entirely with MMU enabled if it is available (aside from machine check tests). Acked-by: Andrew Jones (configure changes) Signed-off-by: Nicholas Piggin --- configure | 39 +++-- lib/powerpc/asm/hcall.h | 6 + lib/powerpc/asm/processor.h | 1 + lib/powerpc/asm/reg.h | 3 + lib/powerpc/asm/smp.h | 2 + lib/powerpc/processor.c | 9 ++ lib/powerpc/setup.c | 8 +- lib/ppc64/asm/mmu.h | 11 ++ lib/ppc64/asm/page.h | 66 +++++++- lib/ppc64/asm/pgtable-hwdef.h | 66 ++++++++ lib/ppc64/asm/pgtable.h | 125 +++++++++++++++ lib/ppc64/mmu.c | 281 +++++++++++++++++++++++++++++++++ lib/ppc64/opal-calls.S | 4 +- powerpc/Makefile.common | 4 +- powerpc/Makefile.ppc64 | 1 + powerpc/interrupts.c | 96 ++++++++++-- powerpc/mmu.c | 283 ++++++++++++++++++++++++++++++++++ powerpc/unittests.cfg | 4 + 18 files changed, 980 insertions(+), 29 deletions(-) create mode 100644 lib/ppc64/asm/mmu.h create mode 100644 lib/ppc64/asm/pgtable-hwdef.h create mode 100644 lib/ppc64/asm/pgtable.h create mode 100644 lib/ppc64/mmu.c create mode 100644 powerpc/mmu.c diff --git a/configure b/configure index 0e0a28825..d744ec4dc 100755 --- a/configure +++ b/configure @@ -245,25 +245,33 @@ fi if [ -z "$page_size" ]; then if [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then page_size="4096" + elif [ "$arch" = "ppc64" ]; then + page_size="65536" fi else - if [ "$arch" != "arm64" ]; then - echo "--page-size is not supported for $arch" - usage - fi - if [ "${page_size: -1}" = "K" ] || [ "${page_size: -1}" = "k" ]; then page_size=$(( ${page_size%?} * 1024 )) fi - if [ "$page_size" != "4096" ] && [ "$page_size" != "16384" ] && - [ "$page_size" != "65536" ]; then - echo "arm64 doesn't support page size of $page_size" + + if [ "$arch" = "arm64" ]; then + if [ "$page_size" != "4096" ] && [ "$page_size" != "16384" ] && + [ "$page_size" != "65536" ]; then + echo "arm64 doesn't support page size of $page_size" + usage + fi + if [ "$efi" = 'y' ] && [ "$page_size" != "4096" ]; then + echo "efi must use 4K pages" + exit 1 + fi + elif [ "$arch" = "ppc64" ]; then + if [ "$page_size" != "4096" ] && [ "$page_size" != "65536" ]; then + echo "ppc64 doesn't support page size of $page_size" + usage + fi + else + echo "--page-size is not supported for $arch" usage fi - if [ "$efi" = 'y' ] && [ "$page_size" != "4096" ]; then - echo "efi must use 4K pages" - exit 1 - fi fi [ -z "$processor" ] && processor="$arch" @@ -472,6 +480,13 @@ cat <> lib/config.h #define CONFIG_UART_EARLY_BASE ${arm_uart_early_addr} #define CONFIG_ERRATA_FORCE ${errata_force} + +EOF +fi + +if [ "$arch" = "arm" ] || [ "$arch" = "arm64" ] || [ "$arch" = "ppc64" ]; then +cat <> lib/config.h + #define CONFIG_PAGE_SIZE _AC(${page_size}, UL) EOF diff --git a/lib/powerpc/asm/hcall.h b/lib/powerpc/asm/hcall.h index e0f5009e3..3b44dd204 100644 --- a/lib/powerpc/asm/hcall.h +++ b/lib/powerpc/asm/hcall.h @@ -24,6 +24,12 @@ #define H_PUT_TERM_CHAR 0x58 #define H_RANDOM 0x300 #define H_SET_MODE 0x31C +#define H_REGISTER_PROCESS_TABLE 0x37C + +#define PTBL_NEW 0x18 +#define PTBL_UNREGISTER 0x10 +#define PTBL_RADIX 0x04 +#define PTBL_GTSE 0x01 #define KVMPPC_HCALL_BASE 0xf000 #define KVMPPC_H_RTAS (KVMPPC_HCALL_BASE + 0x0) diff --git a/lib/powerpc/asm/processor.h b/lib/powerpc/asm/processor.h index a3859b5d4..d348239c5 100644 --- a/lib/powerpc/asm/processor.h +++ b/lib/powerpc/asm/processor.h @@ -14,6 +14,7 @@ extern bool cpu_has_hv; extern bool cpu_has_power_mce; extern bool cpu_has_siar; extern bool cpu_has_heai; +extern bool cpu_has_radix; extern bool cpu_has_prefix; extern bool cpu_has_sc_lev; extern bool cpu_has_pause_short; diff --git a/lib/powerpc/asm/reg.h b/lib/powerpc/asm/reg.h index 12f9e8ac6..b2fab4313 100644 --- a/lib/powerpc/asm/reg.h +++ b/lib/powerpc/asm/reg.h @@ -11,6 +11,7 @@ #define SPR_SRR0 0x01a #define SPR_SRR1 0x01b #define SRR1_PREFIX UL(0x20000000) +#define SPR_PIDR 0x030 #define SPR_FSCR 0x099 #define FSCR_PREFIX UL(0x2000) #define SPR_HFSCR 0x0be @@ -36,7 +37,9 @@ #define SPR_LPCR 0x13e #define LPCR_HDICE UL(0x1) #define LPCR_LD UL(0x20000) +#define SPR_LPIDR 0x13f #define SPR_HEIR 0x153 +#define SPR_PTCR 0x1d0 #define SPR_MMCR0 0x31b #define MMCR0_FC UL(0x80000000) #define MMCR0_PMAE UL(0x04000000) diff --git a/lib/powerpc/asm/smp.h b/lib/powerpc/asm/smp.h index 66188b9dd..3d7d3d08f 100644 --- a/lib/powerpc/asm/smp.h +++ b/lib/powerpc/asm/smp.h @@ -3,6 +3,7 @@ #include #include +#include typedef void (*secondary_entry_fn)(int cpu_id); @@ -11,6 +12,7 @@ struct cpu { unsigned long stack; unsigned long exception_stack; secondary_entry_fn entry; + pgd_t *pgtable; }; extern int nr_cpus_present; diff --git a/lib/powerpc/processor.c b/lib/powerpc/processor.c index a6ce3c905..09f6bb9d8 100644 --- a/lib/powerpc/processor.c +++ b/lib/powerpc/processor.c @@ -13,6 +13,7 @@ #include #include #include +#include #include static struct { @@ -47,6 +48,14 @@ void do_handle_exception(struct pt_regs *regs) __current_cpu = (struct cpu *)mfspr(SPR_SPRG0); + /* + * We run with AIL=0, so interrupts taken with MMU disabled. + * Enable here. + */ + assert(!(mfmsr() & (MSR_IR|MSR_DR))); + if (mmu_enabled()) + mtmsr(mfmsr() | (MSR_IR|MSR_DR)); + v = regs->trap >> 5; if (v < 128 && handlers[v].func) { diff --git a/lib/powerpc/setup.c b/lib/powerpc/setup.c index 622b99e5d..53ecbb830 100644 --- a/lib/powerpc/setup.c +++ b/lib/powerpc/setup.c @@ -103,6 +103,7 @@ bool cpu_has_hv; bool cpu_has_power_mce; /* POWER CPU machine checks */ bool cpu_has_siar; bool cpu_has_heai; +bool cpu_has_radix; bool cpu_has_prefix; bool cpu_has_sc_lev; /* sc interrupt has LEV field in SRR1 */ bool cpu_has_pause_short; @@ -125,6 +126,7 @@ static void cpu_init_params(void) cpu_has_sc_lev = true; cpu_has_pause_short = true; case PVR_VER_POWER9: + cpu_has_radix = true; case PVR_VER_POWER8E: case PVR_VER_POWER8NVL: case PVR_VER_POWER8: @@ -202,10 +204,11 @@ void cpu_init(struct cpu *cpu, int cpu_id) { cpu->server_no = cpu_id; - cpu->stack = (unsigned long)memalign(SZ_4K, SZ_64K); + cpu->stack = (unsigned long)memalign_pages(SZ_4K, SZ_64K); cpu->stack += SZ_64K - 64; - cpu->exception_stack = (unsigned long)memalign(SZ_4K, SZ_64K); + cpu->exception_stack = (unsigned long)memalign_pages(SZ_4K, SZ_64K); cpu->exception_stack += SZ_64K - 64; + cpu->pgtable = NULL; } void setup(const void *fdt) @@ -224,6 +227,7 @@ void setup(const void *fdt) cpu->server_no = fdt_boot_cpuid_phys(fdt); cpu->exception_stack = (unsigned long)boot_exception_stack; cpu->exception_stack += EXCEPTION_STACK_SIZE - 64; + cpu->pgtable = NULL; mtspr(SPR_SPRG0, (unsigned long)cpu); __current_cpu = cpu; diff --git a/lib/ppc64/asm/mmu.h b/lib/ppc64/asm/mmu.h new file mode 100644 index 000000000..fadeee4bc --- /dev/null +++ b/lib/ppc64/asm/mmu.h @@ -0,0 +1,11 @@ +#ifndef _ASMPOWERPC_MMU_H_ +#define _ASMPOWERPC_MMU_H_ + +#include + +bool vm_available(void); +bool mmu_enabled(void); +void mmu_enable(pgd_t *pgtable); +void mmu_disable(void); + +#endif diff --git a/lib/ppc64/asm/page.h b/lib/ppc64/asm/page.h index 1a8b62711..c497d86b9 100644 --- a/lib/ppc64/asm/page.h +++ b/lib/ppc64/asm/page.h @@ -1 +1,65 @@ -#include +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ASMPPC64_PAGE_H_ +#define _ASMPPC64_PAGE_H_ +/* + * Adapted from + * lib/arm64/asm/page.h and Linux kernel defines. + * + * Copyright (C) 2017, Red Hat Inc, Andrew Jones + */ + +#include +#include +#include + +#define VA_BITS 52 + +#define PAGE_SIZE CONFIG_PAGE_SIZE +#if PAGE_SIZE == SZ_64K +#define PAGE_SHIFT 16 +#elif PAGE_SIZE == SZ_4K +#define PAGE_SHIFT 12 +#else +#error Unsupported PAGE_SIZE +#endif +#define PAGE_MASK (~(PAGE_SIZE-1)) + +#ifndef __ASSEMBLY__ + +#define PAGE_ALIGN(addr) ALIGN(addr, PAGE_SIZE) + +typedef u64 pteval_t; +typedef u64 pmdval_t; +typedef u64 pudval_t; +typedef u64 pgdval_t; +typedef struct { pteval_t pte; } pte_t; +typedef struct { pmdval_t pmd; } pmd_t; +typedef struct { pudval_t pud; } pud_t; +typedef struct { pgdval_t pgd; } pgd_t; +typedef struct { pteval_t pgprot; } pgprot_t; + +#define pte_val(x) ((x).pte) +#define pmd_val(x) ((x).pmd) +#define pud_val(x) ((x).pud) +#define pgd_val(x) ((x).pgd) +#define pgprot_val(x) ((x).pgprot) + +#define __pte(x) ((pte_t) { (x) } ) +#define __pmd(x) ((pmd_t) { (x) } ) +#define __pud(x) ((pud_t) { (x) } ) +#define __pgd(x) ((pgd_t) { (x) } ) +#define __pgprot(x) ((pgprot_t) { (x) } ) + +#define __va(x) ((void *)__phys_to_virt((phys_addr_t)(x))) +#define __pa(x) __virt_to_phys((unsigned long)(x)) + +#define virt_to_pfn(kaddr) (__pa(kaddr) >> PAGE_SHIFT) +#define pfn_to_virt(pfn) __va((pfn) << PAGE_SHIFT) + +extern phys_addr_t __virt_to_phys(unsigned long addr); +extern unsigned long __phys_to_virt(phys_addr_t addr); + +extern void *__ioremap(phys_addr_t phys_addr, size_t size); + +#endif /* !__ASSEMBLY__ */ +#endif /* _ASMPPC64_PAGE_H_ */ diff --git a/lib/ppc64/asm/pgtable-hwdef.h b/lib/ppc64/asm/pgtable-hwdef.h new file mode 100644 index 000000000..7cb2c7476 --- /dev/null +++ b/lib/ppc64/asm/pgtable-hwdef.h @@ -0,0 +1,66 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ASMPPC64_PGTABLE_HWDEF_H_ +#define _ASMPPC64_PGTABLE_HWDEF_H_ +/* + * Copyright (C) 2024, IBM Inc, Nicholas Piggin + * + * Derived from Linux kernel MMU code. + */ + +#include + +#define UL(x) _AC(x, UL) + +/* + * Book3S-64 Radix page table + */ +#define PGDIR_SHIFT 39 +#define PUD_SHIFT 30 +#define PMD_SHIFT 21 + +#define PTRS_PER_PGD (SZ_64K / 8) +#define PTRS_PER_PUD (SZ_4K / 8) +#define PTRS_PER_PMD (SZ_4K / 8) +#if PAGE_SIZE == SZ_4K +#define PTRS_PER_PTE (SZ_4K / 8) +#else /* 64K */ +#define PTRS_PER_PTE (256 / 8) +#endif + +#define PGDIR_SIZE (UL(1) << PGDIR_SHIFT) +#define PGDIR_MASK (~(PGDIR_SIZE-1)) + +#define PUD_SIZE (UL(1) << PUD_SHIFT) +#define PUD_MASK (~(PUD_SIZE-1)) + +#define PMD_SIZE (UL(1) << PMD_SHIFT) +#define PMD_MASK (~(PMD_SIZE-1)) + +#define _PAGE_VALID 0x8000000000000000UL +#define _PAGE_PTE 0x4000000000000000UL + +#define _PAGE_EXEC 0x00001 /* execute permission */ +#define _PAGE_WRITE 0x00002 /* write access allowed */ +#define _PAGE_READ 0x00004 /* read access allowed */ +#define _PAGE_PRIVILEGED 0x00008 /* kernel access only */ +#define _PAGE_SAO 0x00010 /* Strong access order */ +#define _PAGE_NON_IDEMPOTENT 0x00020 /* non idempotent memory */ +#define _PAGE_TOLERANT 0x00030 /* tolerant memory, cache inhibited */ +#define _PAGE_DIRTY 0x00080 /* C: page changed */ +#define _PAGE_ACCESSED 0x00100 /* R: page referenced */ + +/* + * Software bits + */ +#define _PAGE_SW0 0x2000000000000000UL +#define _PAGE_SW1 0x00800UL +#define _PAGE_SW2 0x00400UL +#define _PAGE_SW3 0x00200UL + +/* + * Highest possible physical address. + */ +#define PHYS_MASK_SHIFT (48) +#define PHYS_MASK ((UL(1) << PHYS_MASK_SHIFT) - 1) + +#endif /* _ASMPPC64_PGTABLE_HWDEF_H_ */ diff --git a/lib/ppc64/asm/pgtable.h b/lib/ppc64/asm/pgtable.h new file mode 100644 index 000000000..a6ee0d4cd --- /dev/null +++ b/lib/ppc64/asm/pgtable.h @@ -0,0 +1,125 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ASMARM64_PGTABLE_H_ +#define _ASMARM64_PGTABLE_H_ +/* + * Copyright (C) 2024, IBM Inc, Nicholas Piggin + * + * Derived from Linux kernel MMU code. + */ +#include +#include +#include +#include +#include +#include + +#include + +/* + * We can convert va <=> pa page table addresses with simple casts + * because we always allocate their pages with alloc_page(), and + * alloc_page() always returns identity mapped pages. + */ +#define pgtable_va(x) ((void *)(unsigned long)(x)) +#define pgtable_pa(x) ((unsigned long)(x)) + +#define pgd_none(pgd) (!pgd_val(pgd)) +#define pud_none(pud) (!pud_val(pud)) +#define pmd_none(pmd) (!pmd_val(pmd)) +#define pte_none(pte) (!pte_val(pte)) + +#define pgd_valid(pgd) (pgd_val(pgd) & cpu_to_be64(_PAGE_VALID)) +#define pud_valid(pud) (pud_val(pud) & cpu_to_be64(_PAGE_VALID)) +#define pmd_valid(pmd) (pmd_val(pmd) & cpu_to_be64(_PAGE_VALID)) +#define pte_valid(pte) (pte_val(pte) & cpu_to_be64(_PAGE_VALID)) + +#define pmd_huge(pmd) false + +static inline pud_t *pgd_page_vaddr(pgd_t pgd) +{ + return pgtable_va(be64_to_cpu(pgd_val(pgd)) & PHYS_MASK & ~0xfffULL); +} + +static inline pmd_t *pud_page_vaddr(pud_t pud) +{ + return pgtable_va(be64_to_cpu(pud_val(pud)) & PHYS_MASK & ~0xfffULL); +} + +static inline pte_t *pmd_page_vaddr(pmd_t pmd) +{ + return pgtable_va(be64_to_cpu(pmd_val(pmd)) & PHYS_MASK & ~0xfffULL); +} + +#define pgd_index(addr) (((addr) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1)) +#define pgd_offset(pt, addr) ((pt) + pgd_index(addr)) +#define pud_index(addr) (((addr) >> PUD_SHIFT) & (PTRS_PER_PUD - 1)) +#define pud_offset(pgd, addr) (pgd_page_vaddr(*(pgd)) + pud_index(addr)) +#define pmd_index(addr) (((addr) >> PMD_SHIFT) & (PTRS_PER_PMD - 1)) +#define pmd_offset(pud, addr) (pud_page_vaddr(*(pud)) + pmd_index(addr)) +#define pte_index(addr) (((addr) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)) +#define pte_offset(pmd, addr) (pmd_page_vaddr(*(pmd)) + pte_index(addr)) + +#define pgd_free(pgd) free(pgd) +static inline pgd_t *pgd_alloc_one(void) +{ + size_t sz = PTRS_PER_PGD * sizeof(pgd_t); + pgd_t *pgd = memalign_pages(sz, sz); + memset(pgd, 0, sz); + return pgd; +} + +#define pud_free(pud) free(pud) +static inline pud_t *pud_alloc_one(void) +{ + size_t sz = PTRS_PER_PGD * sizeof(pud_t); + pud_t *pud = memalign_pages(sz, sz); + memset(pud, 0, sz); + return pud; +} +static inline pud_t *pud_alloc(pgd_t *pgd, unsigned long addr) +{ + if (pgd_none(*pgd)) { + pgd_t entry; + pgd_val(entry) = cpu_to_be64(pgtable_pa(pud_alloc_one()) | _PAGE_VALID | (12 - 3) /* 4k pud page */); + WRITE_ONCE(*pgd, entry); + } + return pud_offset(pgd, addr); +} + +#define pmd_free(pmd) free(pmd) +static inline pmd_t *pmd_alloc_one(void) +{ + size_t sz = PTRS_PER_PMD * sizeof(pmd_t); + pmd_t *pmd = memalign_pages(sz, sz); + memset(pmd, 0, sz); + return pmd; +} +static inline pmd_t *pmd_alloc(pud_t *pud, unsigned long addr) +{ + if (pud_none(*pud)) { + pud_t entry; + pud_val(entry) = cpu_to_be64(pgtable_pa(pmd_alloc_one()) | _PAGE_VALID | (12 - 3) /* 4k pmd page */); + WRITE_ONCE(*pud, entry); + } + return pmd_offset(pud, addr); +} + +#define pte_free(pte) free(pte) +static inline pte_t *pte_alloc_one(void) +{ + size_t sz = PTRS_PER_PTE * sizeof(pte_t); + pte_t *pte = memalign_pages(sz, sz); + memset(pte, 0, sz); + return pte; +} +static inline pte_t *pte_alloc(pmd_t *pmd, unsigned long addr) +{ + if (pmd_none(*pmd)) { + pmd_t entry; + pmd_val(entry) = cpu_to_be64(pgtable_pa(pte_alloc_one()) | _PAGE_VALID | (21 - PAGE_SHIFT) /* 4k/256B pte page */); + WRITE_ONCE(*pmd, entry); + } + return pte_offset(pmd, addr); +} + +#endif /* _ASMPPC64_PGTABLE_H_ */ diff --git a/lib/ppc64/mmu.c b/lib/ppc64/mmu.c new file mode 100644 index 000000000..5307cd862 --- /dev/null +++ b/lib/ppc64/mmu.c @@ -0,0 +1,281 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Radix MMU support + * + * Copyright (C) 2024, IBM Inc, Nicholas Piggin + * + * Derived from Linux kernel MMU code. + */ +#include +#include +#include +#include +#include +#include +#include + +#include "alloc_page.h" +#include "vmalloc.h" +#include +#include + +#include + +static pgd_t *identity_pgd; + +bool vm_available(void) +{ + return cpu_has_radix; +} + +bool mmu_enabled(void) +{ + return current_cpu()->pgtable != NULL; +} + +void mmu_enable(pgd_t *pgtable) +{ + struct cpu *cpu = current_cpu(); + + if (!pgtable) + pgtable = identity_pgd; + + cpu->pgtable = pgtable; + + mtmsr(mfmsr() | (MSR_IR|MSR_DR)); +} + +void mmu_disable(void) +{ + struct cpu *cpu = current_cpu(); + + cpu->pgtable = NULL; + + mtmsr(mfmsr() & ~(MSR_IR|MSR_DR)); +} + +static inline void tlbie(unsigned long rb, unsigned long rs, int ric, int prs, int r) +{ + asm volatile(".machine push ; .machine power9; ptesync ; tlbie %0,%1,%2,%3,%4 ; eieio ; tlbsync ; ptesync ; .machine pop" :: "r"(rb), "r"(rs), "i"(ric), "i"(prs), "i"(r) : "memory"); +} + +static void flush_tlb_page(uintptr_t vaddr) +{ + unsigned long rb; + unsigned long ap; + + /* AP should come from dt (for pseries, at least) */ + if (PAGE_SIZE == SZ_4K) + ap = 0; + else if (PAGE_SIZE == SZ_64K) + ap = 5; + else if (PAGE_SIZE == SZ_2M) + ap = 1; + else if (PAGE_SIZE == SZ_1G) + ap = 2; + else + assert(0); + + rb = vaddr & ~((1UL << 12) - 1); + rb |= ap << 5; + + tlbie(rb, 0, 0, 1, 1); +} + +static pteval_t *get_pte(pgd_t *pgtable, uintptr_t vaddr) +{ + pgd_t *pgd = pgd_offset(pgtable, vaddr); + pud_t *pud = pud_alloc(pgd, vaddr); + pmd_t *pmd = pmd_alloc(pud, vaddr); + pte_t *pte = pte_alloc(pmd, vaddr); + + return &pte_val(*pte); +} + +static pteval_t *install_pte(pgd_t *pgtable, uintptr_t vaddr, pteval_t pte) +{ + pteval_t *p_pte = get_pte(pgtable, vaddr); + + if (READ_ONCE(*p_pte) & cpu_to_be64(_PAGE_VALID)) { + WRITE_ONCE(*p_pte, 0); + flush_tlb_page(vaddr); + } + + WRITE_ONCE(*p_pte, cpu_to_be64(pte)); + + return p_pte; +} + +static pteval_t *install_page_prot(pgd_t *pgtable, phys_addr_t phys, + uintptr_t vaddr, pgprot_t prot) +{ + pteval_t pte = phys; + pte |= _PAGE_VALID | _PAGE_PTE; + pte |= pgprot_val(prot); + return install_pte(pgtable, vaddr, pte); +} + +pteval_t *install_page(pgd_t *pgtable, phys_addr_t phys, void *virt) +{ + if (!pgtable) + pgtable = identity_pgd; + + return install_page_prot(pgtable, phys, (uintptr_t)virt, + __pgprot(_PAGE_VALID | _PAGE_PTE | + _PAGE_READ | _PAGE_WRITE | + _PAGE_EXEC | _PAGE_ACCESSED | + _PAGE_DIRTY)); +} + +static pteval_t *follow_pte(pgd_t *pgtable, uintptr_t vaddr) +{ + pgd_t *pgd; + pud_t *pud; + pmd_t *pmd; + pte_t *pte; + + pgd = pgd_offset(pgtable, vaddr); + if (!pgd_valid(*pgd)) + return NULL; + + pud = pud_offset(pgd, vaddr); + if (!pud_valid(*pud)) + return NULL; + + pmd = pmd_offset(pud, vaddr); + if (!pmd_valid(*pmd)) + return NULL; + if (pmd_huge(*pmd)) + return &pmd_val(*pmd); + + pte = pte_offset(pmd, vaddr); + if (!pte_valid(*pte)) + return NULL; + + return &pte_val(*pte); +} + +phys_addr_t virt_to_pte_phys(pgd_t *pgtable, void *virt) +{ + phys_addr_t mask; + pteval_t *pteval; + + if (!pgtable) + pgtable = identity_pgd; + + pteval = follow_pte(pgtable, (uintptr_t)virt); + if (!pteval) { + install_page(pgtable, (phys_addr_t)(unsigned long)virt, virt); + return (phys_addr_t)(unsigned long)virt; + } + + if (pmd_huge(__pmd(*pteval))) + mask = PMD_MASK; + else + mask = PAGE_MASK; + + return (be64_to_cpu(*pteval) & PHYS_MASK & mask) | + ((phys_addr_t)(unsigned long)virt & ~mask); +} + +struct partition_table_entry { + uint64_t dw0; + uint64_t dw1; +}; + +static struct partition_table_entry *partition_table; + +struct process_table_entry { + uint64_t dw0; + uint64_t dw1; +}; + +static struct process_table_entry *process_table; + +void *setup_mmu(phys_addr_t phys_end, void *unused) +{ + phys_addr_t addr; + uint64_t dw0, dw1; + + if (identity_pgd) + goto enable; + + assert_msg(cpu_has_radix, "MMU support requires radix MMU."); + + /* 32G address is reserved for vmalloc, cap phys_end at 31G */ + if (phys_end > (31ul << 30)) { + /* print warning */ + phys_end = 31ul << 30; + } + + init_alloc_vpage((void *)(32ul << 30)); + + process_table = memalign_pages(SZ_4K, SZ_4K); + memset(process_table, 0, SZ_4K); + + identity_pgd = pgd_alloc_one(); + + dw0 = (unsigned long)identity_pgd; + dw0 |= 16UL - 3; /* 64K pgd size */ + dw0 |= (0x2UL << 61) | (0x5UL << 5); /* 52-bit virt */ + process_table[1].dw0 = cpu_to_be64(dw0); + + if (machine_is_pseries()) { + int ret; + + ret = hcall(H_REGISTER_PROCESS_TABLE, PTBL_NEW | PTBL_RADIX | PTBL_GTSE, process_table, 0, 0 /* 4K size */); + assert_msg(!ret, "H_REGISTER_PROCESS_TABLE failed! err=%d\n", ret); + } else if (machine_is_powernv()) { + partition_table = memalign_pages(SZ_4K, SZ_4K); + memset(partition_table, 0, SZ_4K); + + /* Reuse dw0 for partition table */ + dw0 |= 1ULL << 63; /* Host radix */ + dw1 = (unsigned long)process_table; /* 4K size */ + partition_table[0].dw0 = cpu_to_be64(dw0); + partition_table[0].dw1 = cpu_to_be64(dw1); + + } else { + /* Only pseries and powernv support radix so far */ + assert(0); + } + + for (addr = 0; addr < phys_end; addr += PAGE_SIZE) + install_page(identity_pgd, addr, __va(addr)); + +enable: + if (machine_is_powernv()) { + mtspr(SPR_PTCR, (unsigned long)partition_table); /* 4KB size */ + + mtspr(SPR_LPIDR, 0); + /* Set LPCR[UPRT] and LPCR[HR] for radix */ + mtspr(SPR_LPCR, mfspr(SPR_LPCR) | (1ULL << 22) | (1ULL << 20)); + } + + /* PID=1 is used because PID=0 is also mapped in quadrant 3 */ + mtspr(SPR_PIDR, 1); + + mmu_enable(identity_pgd); + + return identity_pgd; +} + +phys_addr_t __virt_to_phys(unsigned long addr) +{ + if (mmu_enabled()) { + pgd_t *pgtable = current_cpu()->pgtable; + return virt_to_pte_phys(pgtable, (void *)addr); + } + return addr; +} + +unsigned long __phys_to_virt(phys_addr_t addr) +{ + /* + * We don't guarantee that phys_to_virt(virt_to_phys(vaddr)) == vaddr, but + * the default page tables do identity map all physical addresses, which + * means phys_to_virt(virt_to_phys((void *)paddr)) == paddr. + */ + assert(!mmu_enabled() || __virt_to_phys(addr) == addr); + return addr; +} diff --git a/lib/ppc64/opal-calls.S b/lib/ppc64/opal-calls.S index 8cb4c3e91..bc9c51f84 100644 --- a/lib/ppc64/opal-calls.S +++ b/lib/ppc64/opal-calls.S @@ -25,8 +25,8 @@ opal_call: mfmsr r12 std r12,-16(r1) /* use redzone */ - /* switch to BE when we enter OPAL */ - li r11,(1 << MSR_LE_BIT) + /* switch to BE and real-mode when we enter OPAL */ + li r11,(1 << MSR_LE_BIT) | MSR_IR | MSR_DR ori r11,r11,(1 << MSR_EE_BIT) andc r12,r12,r11 mtspr SPR_HSRR1,r12 diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common index b273033d1..7378b1137 100644 --- a/powerpc/Makefile.common +++ b/powerpc/Makefile.common @@ -16,7 +16,8 @@ tests-common = \ $(TEST_DIR)/smp.elf \ $(TEST_DIR)/sprs.elf \ $(TEST_DIR)/timebase.elf \ - $(TEST_DIR)/interrupts.elf + $(TEST_DIR)/interrupts.elf \ + $(TEST_DIR)/mmu.elf tests-all = $(tests-common) $(tests) all: directories $(TEST_DIR)/boot_rom.bin $(tests-all) @@ -42,6 +43,7 @@ cflatobjs += lib/getchar.o cflatobjs += lib/alloc_phys.o cflatobjs += lib/alloc.o cflatobjs += lib/alloc_page.o +cflatobjs += lib/vmalloc.o cflatobjs += lib/devicetree.o cflatobjs += lib/migrate.o cflatobjs += lib/powerpc/io.o diff --git a/powerpc/Makefile.ppc64 b/powerpc/Makefile.ppc64 index a18a9628f..2466471f9 100644 --- a/powerpc/Makefile.ppc64 +++ b/powerpc/Makefile.ppc64 @@ -18,6 +18,7 @@ reloc.o = $(TEST_DIR)/reloc64.o OBJDIRS += lib/ppc64 cflatobjs += lib/ppc64/stack.o +cflatobjs += lib/ppc64/mmu.o cflatobjs += lib/ppc64/opal.o cflatobjs += lib/ppc64/opal-calls.o diff --git a/powerpc/interrupts.c b/powerpc/interrupts.c index 552c48ef2..6bed26e41 100644 --- a/powerpc/interrupts.c +++ b/powerpc/interrupts.c @@ -14,6 +14,9 @@ #include #include #include +#include +#include "alloc_phys.h" +#include "vmalloc.h" static volatile bool got_interrupt; static volatile struct pt_regs recorded_regs; @@ -44,6 +47,7 @@ static void test_mce(void) unsigned long addr = -4ULL; uint8_t tmp; bool is_fetch; + bool mmu = mmu_enabled(); report_prefix_push("mce"); @@ -53,6 +57,9 @@ static void test_mce(void) handle_exception(0x400, fault_handler, NULL); handle_exception(0x480, fault_handler, NULL); + if (mmu) + mmu_disable(); + if (machine_is_powernv()) { enable_mcheck(); } else { @@ -71,7 +78,6 @@ static void test_mce(void) is_fetch = false; asm volatile("lbz %0,0(%1)" : "=r"(tmp) : "r"(addr)); - report(got_interrupt, "MCE on access to invalid real address"); if (got_interrupt) { report(mfspr(SPR_DAR) == addr, "MCE sets DAR correctly"); @@ -90,6 +96,9 @@ static void test_mce(void) got_interrupt = false; } + if (mmu) + mmu_enable(NULL); + handle_exception(0x200, NULL, NULL); handle_exception(0x300, NULL, NULL); handle_exception(0x380, NULL, NULL); @@ -99,29 +108,36 @@ static void test_mce(void) report_prefix_pop(); } -static void dseg_handler(struct pt_regs *regs, void *data) +static void dside_handler(struct pt_regs *regs, void *data) { got_interrupt = true; memcpy((void *)&recorded_regs, regs, sizeof(struct pt_regs)); regs_advance_insn(regs); - regs->msr &= ~MSR_DR; } -static void test_dseg(void) +static void iside_handler(struct pt_regs *regs, void *data) +{ + got_interrupt = true; + memcpy((void *)&recorded_regs, regs, sizeof(struct pt_regs)); + regs->nip = regs->link; +} + +static void test_dseg_nommu(void) { uint64_t msr, tmp; - report_prefix_push("data segment"); + report_prefix_push("dseg"); /* Some HV start in radix mode and need 0x300 */ - handle_exception(0x300, &dseg_handler, NULL); - handle_exception(0x380, &dseg_handler, NULL); + handle_exception(0x300, &dside_handler, NULL); + handle_exception(0x380, &dside_handler, NULL); asm volatile( " mfmsr %0 \n \ - ori %0,%0,%2 \n \ - mtmsrd %0 \n \ - lbz %1,0(0) " + ori %1,%0,%2 \n \ + mtmsrd %1 \n \ + lbz %1,0(0) \n \ + mtmsrd %0 " : "=r"(msr), "=r"(tmp) : "i"(MSR_DR): "memory"); report(got_interrupt, "interrupt on NULL dereference"); @@ -133,6 +149,61 @@ static void test_dseg(void) report_prefix_pop(); } +static void test_mmu(void) +{ + uint64_t tmp, addr; + phys_addr_t base, top; + + if (!mmu_enabled()) { + test_dseg_nommu(); + return; + } + + phys_alloc_get_unused(&base, &top); + + report_prefix_push("dsi"); + addr = top + PAGE_SIZE; + handle_exception(0x300, &dside_handler, NULL); + asm volatile("lbz %0,0(%1)" : "=r"(tmp) : "r"(addr)); + report(got_interrupt, "dsi on out of range dereference"); + report(mfspr(SPR_DAR) == addr, "DAR set correctly"); + report(mfspr(SPR_DSISR) & (1ULL << 30), "DSISR set correctly"); + got_interrupt = false; + handle_exception(0x300, NULL, NULL); + report_prefix_pop(); + + report_prefix_push("dseg"); + addr = -4ULL; + handle_exception(0x380, &dside_handler, NULL); + asm volatile("lbz %0,0(%1)" : "=r"(tmp) : "r"(addr)); + report(got_interrupt, "dseg on out of range dereference"); + report(mfspr(SPR_DAR) == addr, "DAR set correctly"); + got_interrupt = false; + handle_exception(0x380, NULL, NULL); + report_prefix_pop(); + + report_prefix_push("isi"); + addr = top + PAGE_SIZE; + handle_exception(0x400, &iside_handler, NULL); + asm volatile("mtctr %0 ; bctrl" :: "r"(addr) : "ctr", "lr"); + report(got_interrupt, "isi on out of range fetch"); + report(recorded_regs.nip == addr, "SRR0 set correctly"); + report(recorded_regs.msr & (1ULL << 30), "SRR1 set correctly"); + got_interrupt = false; + handle_exception(0x400, NULL, NULL); + report_prefix_pop(); + + report_prefix_push("iseg"); + addr = -4ULL; + handle_exception(0x480, &iside_handler, NULL); + asm volatile("mtctr %0 ; bctrl" :: "r"(addr) : "ctr", "lr"); + report(got_interrupt, "isi on out of range fetch"); + report(recorded_regs.nip == addr, "SRR0 set correctly"); + got_interrupt = false; + handle_exception(0x480, NULL, NULL); + report_prefix_pop(); +} + static void dec_handler(struct pt_regs *regs, void *data) { got_interrupt = true; @@ -400,9 +471,12 @@ int main(int argc, char **argv) { report_prefix_push("interrupts"); + if (vm_available()) + setup_vm(); + if (cpu_has_power_mce) test_mce(); - test_dseg(); + test_mmu(); test_illegal(); test_dec(); test_sc(); diff --git a/powerpc/mmu.c b/powerpc/mmu.c new file mode 100644 index 000000000..fef790506 --- /dev/null +++ b/powerpc/mmu.c @@ -0,0 +1,283 @@ +/* SPDX-License-Identifier: LGPL-2.0-only */ +/* + * MMU Tests + * + * Copyright 2024 Nicholas Piggin, IBM Corp. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static inline void tlbie(unsigned long rb, unsigned long rs, int ric, int prs, int r) +{ + asm volatile(".machine push ; .machine power9; ptesync ; tlbie %0,%1,%2,%3,%4 ; eieio ; tlbsync ; ptesync ; .machine pop" :: "r"(rb), "r"(rs), "i"(ric), "i"(prs), "i"(r) : "memory"); +} + +static inline void tlbiel(unsigned long rb, unsigned long rs, int ric, int prs, int r) +{ + asm volatile(".machine push ; .machine power9; ptesync ; tlbiel %0,%1,%2,%3,%4 ; ptesync ; .machine pop" :: "r"(rb), "r"(rs), "i"(ric), "i"(prs), "i"(r) : "memory"); +} + +static inline void flush_tlb_page_global(uintptr_t vaddr) +{ + unsigned long rb; + unsigned long rs = (1ULL << 32); /* pid */ + unsigned long ap; + + /* AP should come from dt (for pseries, at least) */ + if (PAGE_SIZE == SZ_4K) + ap = 0; + else if (PAGE_SIZE == SZ_64K) + ap = 5; + else if (PAGE_SIZE == SZ_2M) + ap = 1; + else if (PAGE_SIZE == SZ_1G) + ap = 2; + else + assert(0); + + rb = vaddr & ~((1UL << 12) - 1); + rb |= ap << 5; + + tlbie(rb, rs, 0, 1, 1); +} + +static inline void flush_tlb_page_local(uintptr_t vaddr) +{ + unsigned long rb; + unsigned long rs = (1ULL << 32); /* pid */ + unsigned long ap; + + /* AP should come from dt (for pseries, at least) */ + if (PAGE_SIZE == SZ_4K) + ap = 0; + else if (PAGE_SIZE == SZ_64K) + ap = 5; + else if (PAGE_SIZE == SZ_2M) + ap = 1; + else if (PAGE_SIZE == SZ_1G) + ap = 2; + else + assert(0); + + rb = vaddr & ~((1UL << 12) - 1); + rb |= ap << 5; + + tlbiel(rb, rs, 0, 1, 1); +} + +static volatile bool tlbie_test_running = true; +static volatile bool tlbie_test_failed = false; +static int tlbie_fn_started; + +static void *memory; + +static void trap_handler(struct pt_regs *regs, void *opaque) +{ + tlbie_test_failed = true; + regs_advance_insn(regs); +} + +static void tlbie_fn(int cpu_id) +{ + volatile char *m = memory; + + setup_mmu(0, NULL); + + atomic_fetch_inc(&tlbie_fn_started); + while (tlbie_test_running) { + unsigned long tmp; + + /* + * This is intended to execuse a QEMU TCG bug by forming a + * large TB which can prevent async work from running while the + * TB executes, so it could miss a broadcast TLB invalidation + * and pick up a stale translation. + */ + asm volatile (".rept 256 ; lbz %0,0(%1) ; tdnei %0,0 ; .endr" : "=&r"(tmp) : "r"(m)); + } +} + +#define ITERS 10000000 + +static void test_tlbie(int argc, char **argv) +{ + void *m[2]; + phys_addr_t p[2]; + pteval_t pteval[2]; + pteval_t *ptep; + int i; + + if (argc > 2) + report_abort("Unsupported argument: '%s'", argv[2]); + + if (nr_cpus_present < 2) { + report_skip("Requires SMP (2 or more CPUs)"); + return; + } + + handle_exception(0x700, &trap_handler, NULL); + + m[0] = alloc_page(); + p[0] = virt_to_phys(m[0]); + memset(m[0], 0, PAGE_SIZE); + m[1] = alloc_page(); + p[1] = virt_to_phys(m[1]); + memset(m[1], 0, PAGE_SIZE); + + memory = alloc_vpages(1); + ptep = install_page(NULL, p[0], memory); + pteval[0] = *ptep; + assert(ptep == install_page(NULL, p[1], memory)); + pteval[1] = *ptep; + assert(ptep == install_page(NULL, p[0], memory)); + assert(pteval[0] == *ptep); + flush_tlb_page_global((unsigned long)memory); + + if (!start_all_cpus(tlbie_fn)) + report_abort("Failed to start secondary cpus"); + + while (tlbie_fn_started < nr_cpus_present - 1) { + cpu_relax(); + } + + for (i = 0; i < ITERS; i++) { + *ptep = pteval[1]; + flush_tlb_page_global((unsigned long)memory); + *(long *)m[0] = -1; + barrier(); + *(long *)m[0] = 0; + barrier(); + *ptep = pteval[0]; + flush_tlb_page_global((unsigned long)memory); + *(long *)m[1] = -1; + barrier(); + *(long *)m[1] = 0; + barrier(); + if (tlbie_test_failed) + break; + } + + tlbie_test_running = false; + + stop_all_cpus(); + + handle_exception(0x700, NULL, NULL); + + /* TCG has a known race invalidating other CPUs */ + report_kfail(true, !tlbie_test_failed, "tlbie"); +} + +#define THIS_ITERS 100000 + +static void test_tlbie_this_cpu(int argc, char **argv) +{ + void *m[2]; + phys_addr_t p[2]; + pteval_t pteval[2]; + pteval_t *ptep; + int i; + bool success; + + if (argc > 2) + report_abort("Unsupported argument: '%s'", argv[2]); + + m[0] = alloc_page(); + p[0] = virt_to_phys(m[0]); + memset(m[0], 0, PAGE_SIZE); + m[1] = alloc_page(); + p[1] = virt_to_phys(m[1]); + memset(m[1], 0, PAGE_SIZE); + + memory = alloc_vpages(1); + ptep = install_page(NULL, p[0], memory); + pteval[0] = *ptep; + assert(ptep == install_page(NULL, p[1], memory)); + pteval[1] = *ptep; + assert(ptep == install_page(NULL, p[0], memory)); + assert(pteval[0] == *ptep); + flush_tlb_page_global((unsigned long)memory); + + *(long *)m[0] = 0; + *(long *)m[1] = -1; + + success = true; + for (i = 0; i < THIS_ITERS; i++) { + if (*(long *)memory != 0) { + success = false; + break; + } + *ptep = pteval[1]; + flush_tlb_page_local((unsigned long)memory); + if (*(long *)memory != -1) { + success = false; + break; + } + *ptep = pteval[0]; + flush_tlb_page_local((unsigned long)memory); + } + report(success, "tlbiel"); + + success = true; + flush_tlb_page_global((unsigned long)memory); + for (i = 0; i < THIS_ITERS; i++) { + if (*(long *)memory != 0) { + success = false; + break; + } + *ptep = pteval[1]; + flush_tlb_page_global((unsigned long)memory); + if (*(long *)memory != -1) { + success = false; + break; + } + *ptep = pteval[0]; + flush_tlb_page_global((unsigned long)memory); + } + report(success, "tlbie"); +} + + +struct { + const char *name; + void (*func)(int argc, char **argv); +} hctests[] = { + { "tlbi-this-cpu", test_tlbie_this_cpu }, + { "tlbi-other-cpu", test_tlbie }, + { NULL, NULL } +}; + +int main(int argc, char **argv) +{ + bool all; + int i; + + if (!vm_available()) { + report_skip("MMU is only supported for radix"); + return 0; + } + + setup_vm(); + + all = argc == 1 || !strcmp(argv[1], "all"); + + report_prefix_push("mmu"); + + for (i = 0; hctests[i].name != NULL; i++) { + if (all || strcmp(argv[1], hctests[i].name) == 0) { + report_prefix_push(hctests[i].name); + hctests[i].func(argc, argv); + report_prefix_pop(); + } + } + + report_prefix_pop(); + return report_summary(); +} diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index 39e6dea3c..286e11782 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -69,6 +69,10 @@ file = emulator.elf [interrupts] file = interrupts.elf +[mmu] +file = mmu.elf +smp = $MAX_SMP + [smp] file = smp.elf smp = 2 From patchwork Sat May 4 12:28:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931291 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=iLtkBHeZ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWnTn0cW7z1yb7 for ; Sat, 4 May 2024 22:46:04 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=iLtkBHeZ; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWnTm5pRgz3g26 for ; Sat, 4 May 2024 22:46:04 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=iLtkBHeZ; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::c31; helo=mail-oo1-xc31.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-oo1-xc31.google.com (mail-oo1-xc31.google.com [IPv6:2607:f8b0:4864:20::c31]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn7h38Ssz3cT2 for ; Sat, 4 May 2024 22:30:24 +1000 (AEST) Received: by mail-oo1-xc31.google.com with SMTP id 006d021491bc7-5aa362cc2ccso398265eaf.3 for ; Sat, 04 May 2024 05:30:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825821; x=1715430621; darn=lists.ozlabs.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=8Ev3MpJK+g2Tv7erZ4N92Jbmsn4hd/SpLK5/bTsHc98=; b=iLtkBHeZaBUVLi6krYGToQH0f/9o0PowYMY4Z3yR+YOS3nY0VzyAd4S/0F1l7DG+Hk 9uEfQiIQAYpXigfqir4ye6TyxWNo2Pgk0q7G0O7g051RHC3Drn5JN8+UDCBKghiVxwsC du1cQdw3G0k1bIfWVXsLqMz7qZojPjof0175KqJDatvkNXEhkbCirBtn5i5AvICJAkUJ r3hWbn3JK/jdilbchcq76uLeC7spid8WwxueHqhLHbovSTgXhdsclCiPtAt0BZzDf+KF Kr+kWMcHSJLaMBpxyn/P1Pytqcuzmh/S7C9c8dV8jQC3xtv/sHjpv8TtWFdwLWrw1opu n0UA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825821; x=1715430621; 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=8Ev3MpJK+g2Tv7erZ4N92Jbmsn4hd/SpLK5/bTsHc98=; b=kaNZ7pcEUyJYzeI26URBRtrl3HpDQaZQkoD3TCxNuTIA/gtjkDruIO0noIka0iTjTT ZU1uqDLc6xFx5VtJFEqMNmwJU/A3zkw8ykuJJA30Cu585A1ZfdTvjnpo8yRN8Isp3DgY 3x6CM0TnePYFnCgvq8AQkEZ8cCxMhWkudYgD9yD3impPvTdvQHs6yYjJ8N54iCl+z5iX 42orQNP5gbFYEkQDHgjAPgIyeZSDTm7Ul0Wobo7bQESycG6UVLN54C4LLur0xr6Pbro4 9ZGbiL7ydxhmQOicTRtXtW6ZSnbRLSJkBe0VB8hI0m5F03lsN+1Jjau0ywExk8ghhQa1 q67Q== X-Forwarded-Encrypted: i=1; AJvYcCXjzoUG+Z7gi+0zUgO8TsykLgFGy1Ojw6Flw2ifO6VD6C3qEo/2W4i44LHsshjKs75G571Zx+dKP0IqdyBZ/OghZJQZ5dsUbDrrkg9SmQ== X-Gm-Message-State: AOJu0YwSLKIXFCccPWT4AI13b5EQZJq/Eyg04yvqnGF8XB2xTiBH1k1F cSFxdXMpJmIG0TjRnbACK+d/xsuv4IgMTmQar5pQ7t1491mO2sny X-Google-Smtp-Source: AGHT+IGXK9FNNpuv9Y86irFXe62k+b4lm3bpmrwgI75eg9XgfuOVju3ss2aGbqNi5oKlxkQRfiVoHA== X-Received: by 2002:a05:6870:958d:b0:23e:8a6b:6acf with SMTP id k13-20020a056870958d00b0023e8a6b6acfmr3925485oao.32.1714825821168; Sat, 04 May 2024 05:30:21 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.30.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:30:20 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 23/31] common/sieve: Use vmalloc.h for setup_mmu definition Date: Sat, 4 May 2024 22:28:29 +1000 Message-ID: <20240504122841.1177683-24-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , linux-s390@vger.kernel.org, =?utf-8?q?Nico_B=C3=B6hr?= , Janosch Frank , kvm@vger.kernel.org, David Hildenbrand , Nicholas Piggin , Andrew Jones , Paolo Bonzini , Claudio Imbrenda , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" There is no good reason to put setup_vm in libcflat.h when it's defined in vmalloc.h. Cc: Paolo Bonzini Cc: Thomas Huth Cc: Janosch Frank Cc: Claudio Imbrenda Cc: Nico Böhr Cc: David Hildenbrand Cc: kvm@vger.kernel.org Cc: linux-s390@vger.kernel.org Acked-by: Andrew Jones Signed-off-by: Nicholas Piggin Reviewed-by: Thomas Huth --- common/sieve.c | 1 + lib/libcflat.h | 2 -- lib/s390x/io.c | 1 + lib/s390x/uv.h | 1 + lib/x86/vm.h | 1 + s390x/mvpg.c | 1 + s390x/selftest.c | 1 + x86/pmu.c | 1 + x86/pmu_lbr.c | 1 + x86/vmexit.c | 1 + x86/vmware_backdoors.c | 1 + 11 files changed, 10 insertions(+), 2 deletions(-) diff --git a/common/sieve.c b/common/sieve.c index 8150f2d98..8fe05ef13 100644 --- a/common/sieve.c +++ b/common/sieve.c @@ -1,5 +1,6 @@ #include "alloc.h" #include "libcflat.h" +#include "vmalloc.h" static int sieve(char* data, int size) { diff --git a/lib/libcflat.h b/lib/libcflat.h index ae3c2c6d0..16a838808 100644 --- a/lib/libcflat.h +++ b/lib/libcflat.h @@ -154,8 +154,6 @@ do { \ void binstr(unsigned long x, char out[BINSTR_SZ]); void print_binstr(unsigned long x); -extern void setup_vm(void); - #endif /* !__ASSEMBLY__ */ #define SZ_256 (1 << 8) diff --git a/lib/s390x/io.c b/lib/s390x/io.c index fb7b7ddaa..2b28ccaa0 100644 --- a/lib/s390x/io.c +++ b/lib/s390x/io.c @@ -10,6 +10,7 @@ */ #include #include +#include #include #include #include diff --git a/lib/s390x/uv.h b/lib/s390x/uv.h index 286933caa..00a370410 100644 --- a/lib/s390x/uv.h +++ b/lib/s390x/uv.h @@ -4,6 +4,7 @@ #include #include +#include bool uv_os_is_guest(void); bool uv_os_is_host(void); diff --git a/lib/x86/vm.h b/lib/x86/vm.h index 4b714bad7..cf39787aa 100644 --- a/lib/x86/vm.h +++ b/lib/x86/vm.h @@ -2,6 +2,7 @@ #define _X86_VM_H_ #include "processor.h" +#include "vmalloc.h" #include "asm/page.h" #include "asm/io.h" #include "asm/bitops.h" diff --git a/s390x/mvpg.c b/s390x/mvpg.c index 62d42e364..10909fb7a 100644 --- a/s390x/mvpg.c +++ b/s390x/mvpg.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include diff --git a/s390x/selftest.c b/s390x/selftest.c index 92ed4e5d3..3eaae9b06 100644 --- a/s390x/selftest.c +++ b/s390x/selftest.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include diff --git a/x86/pmu.c b/x86/pmu.c index 47a1a602a..7062c1ad9 100644 --- a/x86/pmu.c +++ b/x86/pmu.c @@ -6,6 +6,7 @@ #include "x86/apic.h" #include "x86/desc.h" #include "x86/isr.h" +#include "vmalloc.h" #include "alloc.h" #include "libcflat.h" diff --git a/x86/pmu_lbr.c b/x86/pmu_lbr.c index 40b63fa3d..c6f010847 100644 --- a/x86/pmu_lbr.c +++ b/x86/pmu_lbr.c @@ -2,6 +2,7 @@ #include "x86/processor.h" #include "x86/pmu.h" #include "x86/desc.h" +#include "vmalloc.h" #define N 1000000 diff --git a/x86/vmexit.c b/x86/vmexit.c index eb5d3023a..48a38f60f 100644 --- a/x86/vmexit.c +++ b/x86/vmexit.c @@ -1,6 +1,7 @@ #include "libcflat.h" #include "acpi.h" #include "smp.h" +#include "vmalloc.h" #include "pci.h" #include "x86/vm.h" #include "x86/desc.h" diff --git a/x86/vmware_backdoors.c b/x86/vmware_backdoors.c index bc1002056..f8cf7ecb1 100644 --- a/x86/vmware_backdoors.c +++ b/x86/vmware_backdoors.c @@ -6,6 +6,7 @@ #include "x86/desc.h" #include "x86/isr.h" #include "alloc.h" +#include "vmalloc.h" #include "setjmp.h" #include "usermode.h" #include "fault_test.h" From patchwork Sat May 4 12:28:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931292 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=gaibDEkx; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWnVY59MQz1yb7 for ; Sat, 4 May 2024 22:46:45 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=gaibDEkx; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWnVY3pk7z77xn for ; Sat, 4 May 2024 22:46:45 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=gaibDEkx; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42b; helo=mail-pf1-x42b.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn7k4Ryvz3cYw for ; Sat, 4 May 2024 22:30:26 +1000 (AEST) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-6f44b5e7f07so392421b3a.2 for ; Sat, 04 May 2024 05:30:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825825; x=1715430625; darn=lists.ozlabs.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=KVFESOjcVNNLos51ELml5v9t1FTREA6sVge5yqZTLzY=; b=gaibDEkx2nnH7Ahgnb51ehO4LtvQ04sMCEt5B9oGaqHJJNDGEgH9i//CrLjwVirSf1 nfHGFTuaJCYRwaBPwp7LbBVUp9VhLgKCUPwD60jpU2pS/rRG8hDI+D6c9bqWzs9q+b3Q bW10By13Ex/d/9fRyhiyBUZPcMyNmqyDInzDerjhaioAtFSBb4kSyDJxCMHu5cqKZ8Ar 2XJfAdrIyAfPAV4k6mOFJEaziiyiN95PNk9DZ6ZrkMdxN183Gw3VGnaUlSYODOz3nyum KEJONv0/kymTr2wNJePJ1Yy3WYSE+KxWmqYmjNrVRFRinrrEpZpsdIFuW8u+Ave++gZM JVew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825825; x=1715430625; 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=KVFESOjcVNNLos51ELml5v9t1FTREA6sVge5yqZTLzY=; b=sCY9ZkeonqEC7C3gnTb1plrlxCWaP3Q9R/ZFdaCO0mBWSFAYoqIOk6Zee/eWRD2HoE V1jFtdgl2/CU2SGLvqhXIsXt+dUiS42pDK75/ly7FIspGD281yxIw7kiIRJiNljM8rbv PkHSr7MM1bPNlrN29dQOMdlmjXeC41Aci1KyntKpUvUc/vA2UnRZhb/F4JCLNU900Zbp sQVZ5hckpOP+VBhN7sxkI4oMmHn85Ej7w/itKnfRkYq9oRwxq4+cBfe6YWHDt3EUYWbx KrgME21ZLdcshIKkVa8Zae5QdIHpWR3GrfxUNpjxfXHmWKOOtZbp2DaxrCObXUs/zQk4 2eLg== X-Forwarded-Encrypted: i=1; AJvYcCXvpaHQEqHqOqDYoqr7WHNvBSSDDGj1/vFxdL0Z8QkzlN03KunCbVTc5w2evF7LudYIqQz1rO0IuzfG5V5wxiu+ohhaQC/IbmrF8f+OsA== X-Gm-Message-State: AOJu0YzrJyHozqYBdrNINnxX0sAqgGPnP30m4SVUVqd7PcMs5BVbFGv+ rrILGVzGD3iVi1oogy3FrEo95eTEZRkfUR2z8Rykk89nyNIMSL5/ X-Google-Smtp-Source: AGHT+IFNPB2LJzAL2EtaSCfApNzeDsWtfIPNo5BFF8lVC4OEt9gdTEGRt1GpzrnYCaDmZ9s+o8lryg== X-Received: by 2002:a05:6a00:3982:b0:6ea:7b29:3ab7 with SMTP id fi2-20020a056a00398200b006ea7b293ab7mr5992043pfb.23.1714825825102; Sat, 04 May 2024 05:30:25 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.30.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:30:24 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 24/31] common/sieve: Support machines without MMU Date: Sat, 4 May 2024 22:28:30 +1000 Message-ID: <20240504122841.1177683-25-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones , Paolo Bonzini , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Not all powerpc CPUs provide MMU support. Define vm_available() that is true by default but archs can override it. Use this to run VM tests. Cc: Paolo Bonzini Cc: Thomas Huth Cc: kvm@vger.kernel.org Reviewed-by: Andrew Jones Signed-off-by: Nicholas Piggin Reviewed-by: Thomas Huth --- common/sieve.c | 14 ++++++++------ lib/ppc64/asm/mmu.h | 1 - lib/ppc64/mmu.c | 2 +- lib/vmalloc.c | 7 +++++++ lib/vmalloc.h | 2 ++ 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/common/sieve.c b/common/sieve.c index 8fe05ef13..db084691a 100644 --- a/common/sieve.c +++ b/common/sieve.c @@ -40,12 +40,14 @@ int main(void) printf("starting sieve\n"); test_sieve("static", static_data, STATIC_SIZE); - setup_vm(); - test_sieve("mapped", static_data, STATIC_SIZE); - for (i = 0; i < 3; ++i) { - v = malloc(VSIZE); - test_sieve("virtual", v, VSIZE); - free(v); + if (vm_available()) { + setup_vm(); + test_sieve("mapped", static_data, STATIC_SIZE); + for (i = 0; i < 3; ++i) { + v = malloc(VSIZE); + test_sieve("virtual", v, VSIZE); + free(v); + } } return 0; diff --git a/lib/ppc64/asm/mmu.h b/lib/ppc64/asm/mmu.h index fadeee4bc..eaff0f1f7 100644 --- a/lib/ppc64/asm/mmu.h +++ b/lib/ppc64/asm/mmu.h @@ -3,7 +3,6 @@ #include -bool vm_available(void); bool mmu_enabled(void); void mmu_enable(pgd_t *pgtable); void mmu_disable(void); diff --git a/lib/ppc64/mmu.c b/lib/ppc64/mmu.c index 5307cd862..84be31752 100644 --- a/lib/ppc64/mmu.c +++ b/lib/ppc64/mmu.c @@ -23,7 +23,7 @@ static pgd_t *identity_pgd; -bool vm_available(void) +bool vm_available(void) /* weak override */ { return cpu_has_radix; } diff --git a/lib/vmalloc.c b/lib/vmalloc.c index 572682576..cf2ef7a70 100644 --- a/lib/vmalloc.c +++ b/lib/vmalloc.c @@ -206,10 +206,17 @@ void init_alloc_vpage(void *top) spin_unlock(&lock); } +bool __attribute__((__weak__)) vm_available(void) +{ + return true; +} + void __setup_vm(void *opaque) { phys_addr_t base, top; + assert_msg(vm_available(), "Virtual memory not available. Must check vm_available() before calling setup_vm()"); + if (alloc_ops == &vmalloc_ops) return; diff --git a/lib/vmalloc.h b/lib/vmalloc.h index 0269fdde9..e81be39f4 100644 --- a/lib/vmalloc.h +++ b/lib/vmalloc.h @@ -17,6 +17,8 @@ extern void setup_vm(void); /* As above, plus passes an opaque value to setup_mmu(). */ extern void __setup_vm(void *opaque); +/* common/ tests must check availability before calling setup_vm() */ +extern bool vm_available(void); /* Set up paging */ extern void *setup_mmu(phys_addr_t top, void *opaque); /* Walk the page table and resolve the virtual address to a physical address */ From patchwork Sat May 4 12:28:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931293 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=WtAnBB0k; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWnWL418jz1yb7 for ; Sat, 4 May 2024 22:47:26 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=WtAnBB0k; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWnWL2hw9z781Q for ; Sat, 4 May 2024 22:47:26 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=WtAnBB0k; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::531; helo=mail-pg1-x531.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn7p6nsWz30Tw for ; Sat, 4 May 2024 22:30:30 +1000 (AEST) Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-61c4ebd0c99so320313a12.0 for ; Sat, 04 May 2024 05:30:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825829; x=1715430629; darn=lists.ozlabs.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=5NGJB2kU/PZBgZRxhGgnfzeZa2zBkfZth+TZPJCBD2U=; b=WtAnBB0kiLZuWpP0/8Bin+PipuCch8EzVxneiJPJj7xs8udF/KR1wRzdRT93PtfcjE +I0IbcB02XSaSoMVXALTD9V++VNYvt4TbxYCna+YqqImQiE3NF67dIQpgrPa55Z5S8lp buy1ZEeISwHr0d03YPRg1i9+jU4Ci8kEHaDJHazeri7C4DTSnlOKMnOMNEyNGqN5t0Nh 4cajmpTQeh3TTq/TxHbR4B0PPVrIdwRxQWZ96JSRbI+9I2ToMWUf5Ttni81M7sL8WDg9 jg0JQF4gDjPqiDl+5qjTa/ZdQSR2Dk755c9tHetLU3dfKHSKMfZvqffrvQJbnxaiUx7E KLGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825829; x=1715430629; 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=5NGJB2kU/PZBgZRxhGgnfzeZa2zBkfZth+TZPJCBD2U=; b=RJ6x0pzI8FcDzt/wZKWgT5NmJpwHMaaLXue2BSOMtgnb1qZUpNd2eV4uHU5QmW9bV+ E3fwYIfT95WDeejWMpvIrXw0UG3YtsUX1ifL39dFG9SgoDKasAh7phEa6NlquTuotrT+ EW+gKeA/cs/p8WWOYraC9ivzH9zwhbJbwAUircKMdTvpIG9trMUwWiEOFBjUlkW4a6R8 kZSsE02pOG4QGzvLI+Inoj2ja81HNxl6Sj3eNSV1Zf0kMorr8UBfwPSEQohk3FYnrbYE IPStuUG/Y0HXvNYmupOTKiBGEMk6TxmB8g2rFcqBZwST8TtW8tWro9UvD7TIRII0unfg aCKg== X-Forwarded-Encrypted: i=1; AJvYcCVp0vlu8lzJntxOz3sXp9lSUvX+w0YAa4x5vPFr8QtIxTwZHX1PAZmGmyFBopElVCMJ7EYWGduALJAxGYUXY89uwLGMlfUnNVXOCdB40w== X-Gm-Message-State: AOJu0YxABt4dZNd29F/2pvn5mUFnVxbMOe/adwia/D+vuz3CBQaOawnV c9W45awRjcfZknTMM9uLnRrtWCVXv1bNh/1ABXN+cdrfNyAOisFyE4cpAg== X-Google-Smtp-Source: AGHT+IEoUYJSmTBuUD/jk1CLYptkUeIzK0xq1aBA4WJ3bd83Z7S3fr1cnVqSRKmY/XCfM4wCkaZB+A== X-Received: by 2002:a05:6a20:3948:b0:1a7:8610:bb62 with SMTP id r8-20020a056a20394800b001a78610bb62mr7155624pzg.51.1714825828863; Sat, 04 May 2024 05:30:28 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.30.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:30:28 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 25/31] powerpc: Add sieve.c common test Date: Sat, 4 May 2024 22:28:31 +1000 Message-ID: <20240504122841.1177683-26-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Now that sieve copes with lack of MMU support, it can be run by powerpc. Signed-off-by: Nicholas Piggin Reviewed-by: Thomas Huth --- powerpc/Makefile.common | 1 + powerpc/sieve.c | 1 + powerpc/unittests.cfg | 3 +++ 3 files changed, 5 insertions(+) create mode 120000 powerpc/sieve.c diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common index 7378b1137..b2e89e4fd 100644 --- a/powerpc/Makefile.common +++ b/powerpc/Makefile.common @@ -8,6 +8,7 @@ tests-common = \ $(TEST_DIR)/selftest.elf \ $(TEST_DIR)/selftest-migration.elf \ $(TEST_DIR)/memory-verify.elf \ + $(TEST_DIR)/sieve.elf \ $(TEST_DIR)/spapr_hcall.elf \ $(TEST_DIR)/rtas.elf \ $(TEST_DIR)/emulator.elf \ diff --git a/powerpc/sieve.c b/powerpc/sieve.c new file mode 120000 index 000000000..fe299f309 --- /dev/null +++ b/powerpc/sieve.c @@ -0,0 +1 @@ +../common/sieve.c \ No newline at end of file diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index 286e11782..c7cda819d 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -120,3 +120,6 @@ file = sprs.elf machine = pseries extra_params = -append '-w' groups = migration + +[sieve] +file = sieve.elf From patchwork Sat May 4 12:28:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931294 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=LBMFwbCL; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWnX75TP8z1yb7 for ; Sat, 4 May 2024 22:48:07 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=LBMFwbCL; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWnX70jykz3g6G for ; Sat, 4 May 2024 22:48:07 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=LBMFwbCL; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::c2b; helo=mail-oo1-xc2b.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-oo1-xc2b.google.com (mail-oo1-xc2b.google.com [IPv6:2607:f8b0:4864:20::c2b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn7v2l3zz30VY for ; Sat, 4 May 2024 22:30:35 +1000 (AEST) Received: by mail-oo1-xc2b.google.com with SMTP id 006d021491bc7-5aa22ebd048so528880eaf.1 for ; Sat, 04 May 2024 05:30:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825832; x=1715430632; darn=lists.ozlabs.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=Jh8YEW5eRGXlO4vG/BDXDxg6Csm+R2ATJflCGfFbswc=; b=LBMFwbCLdxbPLIQ4Lraa43/FGUgN+GRGtUD2WMvghw5N/EFWKzTlRFkLldv/4INtha /4xHD3E94O1V6BllNwFPS5lVjo3T4u0bfQgRY3Uoe8MbqUgS9UerSl5lXu5DKLGNLQUc ltltp9rbzgxkYOOSkjcrY/4yrQogvmlBviVKbu8/qayZ1LgeP75i4EtAj0I+iSnGzOQf vnMelbZfP+77SavFY8Qe9ZmbR76CGd8hBvIgdZDUhg7UmJbKKfqy5CvFxsaV++JIGKOv IcHZfSTCAUBe3wctJFoXFBj6SjR4dXv2FqvkaidSHW1dhFuViOSCdqmm5tLfrsa/f7K2 ucLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825832; x=1715430632; 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=Jh8YEW5eRGXlO4vG/BDXDxg6Csm+R2ATJflCGfFbswc=; b=CflNKV76xa/9lmNozHTG2jzzp+hVgNODEv5LhooO3Xobpx1kdqnnJ7pJZIeTcb/ANP VCYMMVnNKIs6hrepaHMmU65IgmSXDvBnnU3Z5Hkzd+aLrzIjk2h64WOMPIKzrszD2bJ6 3PcGomNI+aaXv/NNfK8rXrMnmvUS0JEmN9vdt0E0aOGcVIzGStKWjVQ0zovIMdeHY5xp LGsXf26YmhfLpLFAK9L7Q8bjFTvSWPewDTCkNadfGbVspPxdqMIJ8bvNHoSCtMiKItl5 FSAu/16+p+WknL2xr2qLlU6k8+p8AzhMAPd2+SnWPkAymhSnpiVyfCpK3tlTg0ADqkZR ZHwA== X-Forwarded-Encrypted: i=1; AJvYcCVKkGvrXaaDdiNUpLypi+mFK0k1d2VkGIBX7vQmb7vZwATPUvQpyZB1Ih7ZLz+OdJWxhagESAxTghhrRHFnWJmUlKWNDTOuBnUEDgFP2A== X-Gm-Message-State: AOJu0Yx6/en8BdJXhJZxCFpvTB3efLuwubgx3Q61L0cgZGB4GcRg85fo ssiYjwxUsWP/LY3mLpH4pBwgg3Ez/7PGTWuAQXUhhP7rLc+8Iu9yJ6odBg== X-Google-Smtp-Source: AGHT+IESdyMEBnGtgUCUGCH7k2LmTJDL32vjDF5qwK3xaFqWHhbPdZWcsnCHU2+jidoGCotIv3vmBg== X-Received: by 2002:a05:6870:214c:b0:23c:1f8f:5b95 with SMTP id g12-20020a056870214c00b0023c1f8f5b95mr6177240oae.56.1714825832512; Sat, 04 May 2024 05:30:32 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.30.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:30:32 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 26/31] powerpc: add usermode support Date: Sat, 4 May 2024 22:28:32 +1000 Message-ID: <20240504122841.1177683-27-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" The biggest difficulty for user mode is MMU support. Otherwise it is a simple matter of setting and clearing MSR[PR] with rfid and sc respectively. Some common harness operations will fail in usermode, so some workarounds are reqiured (e.g., puts() can't be used directly). A usermode privileged instruction interrupt test is added. Signed-off-by: Nicholas Piggin Reviewed-by: Thomas Huth --- lib/powerpc/asm/processor.h | 9 +++++++++ lib/powerpc/asm/reg.h | 1 + lib/powerpc/asm/smp.h | 1 + lib/powerpc/io.c | 7 +++++++ lib/powerpc/processor.c | 38 +++++++++++++++++++++++++++++++++++++ lib/powerpc/rtas.c | 3 +++ lib/powerpc/setup.c | 8 ++++++-- lib/powerpc/spinlock.c | 4 ++++ lib/ppc64/mmu.c | 2 ++ powerpc/interrupts.c | 28 +++++++++++++++++++++++++++ 10 files changed, 99 insertions(+), 2 deletions(-) diff --git a/lib/powerpc/asm/processor.h b/lib/powerpc/asm/processor.h index d348239c5..749155696 100644 --- a/lib/powerpc/asm/processor.h +++ b/lib/powerpc/asm/processor.h @@ -19,6 +19,8 @@ extern bool cpu_has_prefix; extern bool cpu_has_sc_lev; extern bool cpu_has_pause_short; +bool in_usermode(void); + static inline uint64_t mfspr(int nr) { uint64_t ret; @@ -51,6 +53,8 @@ static inline void local_irq_enable(void) { unsigned long msr; + assert(!in_usermode()); + asm volatile( " mfmsr %0 \n \ ori %0,%0,%1 \n \ @@ -62,6 +66,8 @@ static inline void local_irq_disable(void) { unsigned long msr; + assert(!in_usermode()); + asm volatile( " mfmsr %0 \n \ andc %0,%0,%1 \n \ @@ -90,4 +96,7 @@ static inline bool machine_is_pseries(void) void enable_mcheck(void); void disable_mcheck(void); +void enter_usermode(void); +void exit_usermode(void); + #endif /* _ASMPOWERPC_PROCESSOR_H_ */ diff --git a/lib/powerpc/asm/reg.h b/lib/powerpc/asm/reg.h index b2fab4313..69ef21adb 100644 --- a/lib/powerpc/asm/reg.h +++ b/lib/powerpc/asm/reg.h @@ -58,5 +58,6 @@ #define MSR_SE UL(0x0400) /* Single Step Enable */ #define MSR_EE UL(0x8000) #define MSR_ME UL(0x1000) +#define MSR_PR UL(0x4000) #endif diff --git a/lib/powerpc/asm/smp.h b/lib/powerpc/asm/smp.h index 3d7d3d08f..e591f6ab0 100644 --- a/lib/powerpc/asm/smp.h +++ b/lib/powerpc/asm/smp.h @@ -11,6 +11,7 @@ struct cpu { unsigned long server_no; unsigned long stack; unsigned long exception_stack; + bool in_user; secondary_entry_fn entry; pgd_t *pgtable; }; diff --git a/lib/powerpc/io.c b/lib/powerpc/io.c index cb7f2f050..5c2810884 100644 --- a/lib/powerpc/io.c +++ b/lib/powerpc/io.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "io.h" static struct spinlock print_lock; @@ -41,10 +42,16 @@ void io_init(void) void puts(const char *s) { + bool user = in_usermode(); + + if (user) + exit_usermode(); spin_lock(&print_lock); while (*s) putchar(*s++); spin_unlock(&print_lock); + if (user) + enter_usermode(); } /* diff --git a/lib/powerpc/processor.c b/lib/powerpc/processor.c index 09f6bb9d8..6c3000d5c 100644 --- a/lib/powerpc/processor.c +++ b/lib/powerpc/processor.c @@ -47,6 +47,8 @@ void do_handle_exception(struct pt_regs *regs) unsigned char v; __current_cpu = (struct cpu *)mfspr(SPR_SPRG0); + if (in_usermode()) + current_cpu()->in_user = false; /* * We run with AIL=0, so interrupts taken with MMU disabled. @@ -60,6 +62,8 @@ void do_handle_exception(struct pt_regs *regs) if (v < 128 && handlers[v].func) { handlers[v].func(regs, handlers[v].data); + if (regs->msr & MSR_PR) + current_cpu()->in_user = true; return; } @@ -169,3 +173,37 @@ void disable_mcheck(void) { rfid_msr(mfmsr() & ~MSR_ME); } + +bool in_usermode(void) +{ + return current_cpu()->in_user; +} + +static void usermode_sc_handler(struct pt_regs *regs, void *data) +{ + regs->msr &= ~(MSR_PR|MSR_EE); + /* Interrupt return handler will keep in_user clear */ +} + +void enter_usermode(void) +{ + assert_msg(!in_usermode(), "enter_usermode called with in_usermode"); + /* mfmsr would fault in usermode anyway */ + assert_msg(!(mfmsr() & MSR_PR), "enter_usermode called from user mode"); + assert_msg(!(mfmsr() & MSR_EE), "enter_usermode called with interrupts enabled"); + assert_msg((mfmsr() & (MSR_IR|MSR_DR)) == (MSR_IR|MSR_DR), + "enter_usermode called with virtual memory disabled"); + + handle_exception(0xc00, usermode_sc_handler, NULL); + rfid_msr(mfmsr() | (MSR_PR|MSR_IR|MSR_DR|MSR_EE)); + current_cpu()->in_user = true; +} + +void exit_usermode(void) +{ + assert_msg(in_usermode(), "enter_usermode called with !in_usermode"); + asm volatile("sc 0" ::: "memory"); + handle_exception(0xc00, NULL, NULL); + assert(!in_usermode()); + assert(!(mfmsr() & MSR_PR)); +} diff --git a/lib/powerpc/rtas.c b/lib/powerpc/rtas.c index b477a38e0..9c1e0affc 100644 --- a/lib/powerpc/rtas.c +++ b/lib/powerpc/rtas.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -137,6 +138,8 @@ int rtas_call(int token, int nargs, int nret, int *outputs, ...) va_list list; int ret; + assert_msg(!in_usermode(), "May not make RTAS call from user mode\n"); + spin_lock(&rtas_lock); va_start(list, outputs); diff --git a/lib/powerpc/setup.c b/lib/powerpc/setup.c index 53ecbb830..a4ff678ce 100644 --- a/lib/powerpc/setup.c +++ b/lib/powerpc/setup.c @@ -209,8 +209,11 @@ void cpu_init(struct cpu *cpu, int cpu_id) cpu->exception_stack = (unsigned long)memalign_pages(SZ_4K, SZ_64K); cpu->exception_stack += SZ_64K - 64; cpu->pgtable = NULL; + cpu->in_user = false; } +bool is_hvmode; + void setup(const void *fdt) { void *freemem = &stacktop; @@ -219,8 +222,6 @@ void setup(const void *fdt) u32 fdt_size; int ret; - cpu_has_hv = !!(mfmsr() & (1ULL << MSR_HV_BIT)); - memset(cpus, 0xff, sizeof(cpus)); cpu = &cpus[0]; @@ -228,10 +229,13 @@ void setup(const void *fdt) cpu->exception_stack = (unsigned long)boot_exception_stack; cpu->exception_stack += EXCEPTION_STACK_SIZE - 64; cpu->pgtable = NULL; + cpu->in_user = false; mtspr(SPR_SPRG0, (unsigned long)cpu); __current_cpu = cpu; + cpu_has_hv = !!(mfmsr() & (1ULL << MSR_HV_BIT)); + enable_mcheck(); /* diff --git a/lib/powerpc/spinlock.c b/lib/powerpc/spinlock.c index 623a1f2c1..2c4904a33 100644 --- a/lib/powerpc/spinlock.c +++ b/lib/powerpc/spinlock.c @@ -9,6 +9,8 @@ */ void spin_lock(struct spinlock *lock) { + assert(!in_usermode()); + if (!multithreaded) { assert(lock->v == 0); lock->v = 1; @@ -20,7 +22,9 @@ void spin_lock(struct spinlock *lock) void spin_unlock(struct spinlock *lock) { + assert(!in_usermode()); assert(lock->v == 1); + if (!multithreaded) { lock->v = 0; } else { diff --git a/lib/ppc64/mmu.c b/lib/ppc64/mmu.c index 84be31752..bdc5e4637 100644 --- a/lib/ppc64/mmu.c +++ b/lib/ppc64/mmu.c @@ -42,6 +42,7 @@ void mmu_enable(pgd_t *pgtable) cpu->pgtable = pgtable; + assert(!in_usermode()); mtmsr(mfmsr() | (MSR_IR|MSR_DR)); } @@ -51,6 +52,7 @@ void mmu_disable(void) cpu->pgtable = NULL; + assert(!in_usermode()); mtmsr(mfmsr() & ~(MSR_IR|MSR_DR)); } diff --git a/powerpc/interrupts.c b/powerpc/interrupts.c index 6bed26e41..ba965ff76 100644 --- a/powerpc/interrupts.c +++ b/powerpc/interrupts.c @@ -326,6 +326,33 @@ static void test_illegal(void) report_prefix_pop(); } +static void dec_ignore_handler(struct pt_regs *regs, void *data) +{ + mtspr(SPR_DEC, 0x7fffffff); +} + +static void test_privileged(void) +{ + unsigned long msr; + + if (!mmu_enabled()) + return; + + report_prefix_push("privileged instruction"); + + handle_exception(0x700, &program_handler, NULL); + handle_exception(0x900, &dec_ignore_handler, NULL); + enter_usermode(); + asm volatile("mfmsr %0" : "=r"(msr) :: "memory"); + exit_usermode(); + report(got_interrupt, "interrupt on privileged instruction"); + got_interrupt = false; + handle_exception(0x900, NULL, NULL); + handle_exception(0x700, NULL, NULL); + + report_prefix_pop(); +} + static void sc_handler(struct pt_regs *regs, void *data) { got_interrupt = true; @@ -478,6 +505,7 @@ int main(int argc, char **argv) test_mce(); test_mmu(); test_illegal(); + test_privileged(); test_dec(); test_sc(); test_trace(); From patchwork Sat May 4 12:28:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931295 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=lQqI/3Ck; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWnY24tzjz1yb7 for ; Sat, 4 May 2024 22:48:54 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=lQqI/3Ck; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWnY23Vdyz3fnN for ; Sat, 4 May 2024 22:48:54 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=lQqI/3Ck; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42f; helo=mail-pf1-x42f.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn7x6tSmz3blN for ; Sat, 4 May 2024 22:30:37 +1000 (AEST) Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6f44390e328so524837b3a.2 for ; Sat, 04 May 2024 05:30:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825836; x=1715430636; darn=lists.ozlabs.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=QsZlFwW7h4DCUQN/Gl4varHGtv/jKCd9/B5bTeoYI8o=; b=lQqI/3Ck8Y+JUhpI13OjJyC6gAe1H/wIzElhqRVM7VBQInDPsp2+vA86XLNLU904iA aDVD2g+ZivwnVc+f8yU1+XcAozY8rlzfpAWfq2DfRCzWgN3hmXQPuFXCVDEe3p62M36B B0QDW6pXP1zXe4QlpSrqLFbfU6XwDBBwjoE6t/+d6Fg9bbEeBoQtQCjJONJIXn+kdBMW mnZw12ODXprkIlb+XhKrHhbspaQxS9EutO4Bqts93rRaywNbLdjq6LrdAwuHoIYDGMtU 6J/KMb5gFbo4t4rghgYmOIDKyDQkr1Im/NYebg3sJte//yiRZkSFiZZMsDBA2wlAoQqs rLkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825836; x=1715430636; 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=QsZlFwW7h4DCUQN/Gl4varHGtv/jKCd9/B5bTeoYI8o=; b=TD0wlEWDX3O6H20PFiWfktcUmqudaw6eRrcvav2OgHsu5o5wht2Rj0E//3HmI7CHcD QyKauNy3swfqWis4y11Eq0Tf7rFVp/kAgabBY9xrrVxjBH3anoPG74OtVEfjj/wyxUKi J5cjFl5onP4GDFoXVWVffYD/9cghG9Ns1Xj4N/4TuEyyAxEVm65w2a0ioT5DYZz4k09j 3UXUoE9XYurdive2owAFp+9yjYTkuEcSfUi4XTOR7BhdJv36YZYu/EQr+fNO/N/xrkgN CFGR1fUBg3KMi+axOj+E2qIhr7mVf0JbV/8WzTBuOteGPU+ViV8rrVHPuHWSuWynboL1 Kj6g== X-Forwarded-Encrypted: i=1; AJvYcCVKlXqxIH/ci+hLDKgpFusdQOyuFDre1AzU2LQTmomPgnP8eDYlOCvZy6ygYvRw+d2nVwkjWVWu+G67pj8RkqhYhOlOBUYslbGr/57GVg== X-Gm-Message-State: AOJu0Yw82g4ir+1jdbKiTvwjTR0BH1hO5OgaNwh2IHyPZ6MySJllqIqc KVQcw+Ba5atkZQM2l5NOaCH90C+ZKGNxvwjZDphgpiwdwxx6RIcA X-Google-Smtp-Source: AGHT+IGJM1UubTAKforbo16wYZ83p1O4NLj4HW6CIPZ6YqmqMlyZScft4Sck/78ju4/Is6sEWFwIrg== X-Received: by 2002:a05:6a00:2d97:b0:6f3:c10a:7bdd with SMTP id fb23-20020a056a002d9700b006f3c10a7bddmr5738289pfb.18.1714825836129; Sat, 04 May 2024 05:30:36 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.30.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:30:35 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 27/31] powerpc: add pmu tests Date: Sat, 4 May 2024 22:28:33 +1000 Message-ID: <20240504122841.1177683-28-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Add some initial PMU testing. - PMC5/6 tests - PMAE / PMI test - BHRB basic tests Signed-off-by: Nicholas Piggin --- lib/powerpc/asm/processor.h | 2 + lib/powerpc/asm/reg.h | 9 + lib/powerpc/asm/setup.h | 1 + lib/powerpc/setup.c | 23 ++ powerpc/Makefile.common | 3 +- powerpc/pmu.c | 403 ++++++++++++++++++++++++++++++++++++ powerpc/unittests.cfg | 3 + 7 files changed, 443 insertions(+), 1 deletion(-) create mode 100644 powerpc/pmu.c diff --git a/lib/powerpc/asm/processor.h b/lib/powerpc/asm/processor.h index 749155696..28239c610 100644 --- a/lib/powerpc/asm/processor.h +++ b/lib/powerpc/asm/processor.h @@ -14,6 +14,8 @@ extern bool cpu_has_hv; extern bool cpu_has_power_mce; extern bool cpu_has_siar; extern bool cpu_has_heai; +extern bool cpu_has_bhrb; +extern bool cpu_has_p10_bhrb; extern bool cpu_has_radix; extern bool cpu_has_prefix; extern bool cpu_has_sc_lev; diff --git a/lib/powerpc/asm/reg.h b/lib/powerpc/asm/reg.h index 69ef21adb..602fba1b6 100644 --- a/lib/powerpc/asm/reg.h +++ b/lib/powerpc/asm/reg.h @@ -40,10 +40,19 @@ #define SPR_LPIDR 0x13f #define SPR_HEIR 0x153 #define SPR_PTCR 0x1d0 +#define SPR_MMCRA 0x312 +#define MMCRA_BHRBRD UL(0x0000002000000000) +#define MMCRA_IFM_MASK UL(0x00000000c0000000) +#define SPR_PMC5 0x317 +#define SPR_PMC6 0x318 #define SPR_MMCR0 0x31b #define MMCR0_FC UL(0x80000000) +#define MMCR0_FCP UL(0x20000000) #define MMCR0_PMAE UL(0x04000000) +#define MMCR0_BHRBA UL(0x00200000) +#define MMCR0_FCPC UL(0x00001000) #define MMCR0_PMAO UL(0x00000080) +#define MMCR0_FC56 UL(0x00000010) #define SPR_SIAR 0x31c /* Machine State Register definitions: */ diff --git a/lib/powerpc/asm/setup.h b/lib/powerpc/asm/setup.h index 9ca318ce6..8f0b58ed0 100644 --- a/lib/powerpc/asm/setup.h +++ b/lib/powerpc/asm/setup.h @@ -10,6 +10,7 @@ #define NR_CPUS 8 /* arbitrarily set for now */ extern uint64_t tb_hz; +extern uint64_t cpu_hz; #define NR_MEM_REGIONS 8 #define MR_F_PRIMARY (1U << 0) diff --git a/lib/powerpc/setup.c b/lib/powerpc/setup.c index a4ff678ce..8ff4939e2 100644 --- a/lib/powerpc/setup.c +++ b/lib/powerpc/setup.c @@ -33,6 +33,7 @@ u32 initrd_size; u32 cpu_to_hwid[NR_CPUS] = { [0 ... NR_CPUS-1] = (~0U) }; int nr_cpus_present; uint64_t tb_hz; +uint64_t cpu_hz; struct mem_region mem_regions[NR_MEM_REGIONS]; phys_addr_t __physical_start, __physical_end; @@ -42,6 +43,7 @@ struct cpu_set_params { unsigned icache_bytes; unsigned dcache_bytes; uint64_t tb_hz; + uint64_t cpu_hz; }; static void cpu_set(int fdtnode, u64 regval, void *info) @@ -95,6 +97,22 @@ static void cpu_set(int fdtnode, u64 regval, void *info) data = (u32 *)prop->data; params->tb_hz = fdt32_to_cpu(*data); + prop = fdt_get_property(dt_fdt(), fdtnode, + "ibm,extended-clock-frequency", NULL); + if (prop) { + data = (u32 *)prop->data; + params->cpu_hz = fdt32_to_cpu(*data); + params->cpu_hz <<= 32; + data = (u32 *)prop->data + 1; + params->cpu_hz |= fdt32_to_cpu(*data); + } else { + prop = fdt_get_property(dt_fdt(), fdtnode, + "clock-frequency", NULL); + assert(prop != NULL); + data = (u32 *)prop->data; + params->cpu_hz = fdt32_to_cpu(*data); + } + read_common_info = true; } } @@ -103,6 +121,8 @@ bool cpu_has_hv; bool cpu_has_power_mce; /* POWER CPU machine checks */ bool cpu_has_siar; bool cpu_has_heai; +bool cpu_has_bhrb; +bool cpu_has_p10_bhrb; bool cpu_has_radix; bool cpu_has_prefix; bool cpu_has_sc_lev; /* sc interrupt has LEV field in SRR1 */ @@ -119,12 +139,14 @@ static void cpu_init_params(void) __icache_bytes = params.icache_bytes; __dcache_bytes = params.dcache_bytes; tb_hz = params.tb_hz; + cpu_hz = params.cpu_hz; switch (mfspr(SPR_PVR) & PVR_VERSION_MASK) { case PVR_VER_POWER10: cpu_has_prefix = true; cpu_has_sc_lev = true; cpu_has_pause_short = true; + cpu_has_p10_bhrb = true; case PVR_VER_POWER9: cpu_has_radix = true; case PVR_VER_POWER8E: @@ -133,6 +155,7 @@ static void cpu_init_params(void) cpu_has_power_mce = true; cpu_has_heai = true; cpu_has_siar = true; + cpu_has_bhrb = true; break; default: break; diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common index b2e89e4fd..0255ca9e4 100644 --- a/powerpc/Makefile.common +++ b/powerpc/Makefile.common @@ -18,7 +18,8 @@ tests-common = \ $(TEST_DIR)/sprs.elf \ $(TEST_DIR)/timebase.elf \ $(TEST_DIR)/interrupts.elf \ - $(TEST_DIR)/mmu.elf + $(TEST_DIR)/mmu.elf \ + $(TEST_DIR)/pmu.elf tests-all = $(tests-common) $(tests) all: directories $(TEST_DIR)/boot_rom.bin $(tests-all) diff --git a/powerpc/pmu.c b/powerpc/pmu.c new file mode 100644 index 000000000..8b13ee4cd --- /dev/null +++ b/powerpc/pmu.c @@ -0,0 +1,403 @@ +/* SPDX-License-Identifier: LGPL-2.0-only */ +/* + * Test PMU + * + * Copyright 2024 Nicholas Piggin, IBM Corp. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "alloc_phys.h" +#include "vmalloc.h" + +static volatile bool got_interrupt; +static volatile struct pt_regs recorded_regs; +static volatile unsigned long recorded_mmcr0; + +static void illegal_handler(struct pt_regs *regs, void *data) +{ + got_interrupt = true; + regs_advance_insn(regs); +} + +static void sc_handler(struct pt_regs *regs, void *data) +{ + got_interrupt = true; +} + +static void reset_mmcr0(void) +{ + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) | (MMCR0_FC | MMCR0_FC56)); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) & ~(MMCR0_PMAE | MMCR0_PMAO)); +} + +static __attribute__((__noinline__)) unsigned long pmc5_count_nr_insns(unsigned long nr) +{ + reset_mmcr0(); + mtspr(SPR_PMC5, 0); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) & ~(MMCR0_FC | MMCR0_FC56)); + asm volatile("mtctr %0 ; 1: bdnz 1b" :: "r"(nr) : "ctr"); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) | (MMCR0_FC | MMCR0_FC56)); + + return mfspr(SPR_PMC5); +} + +static void test_pmc5_with_fault(void) +{ + unsigned long pmc5_1, pmc5_2; + + handle_exception(0x700, &illegal_handler, NULL); + handle_exception(0xe40, &illegal_handler, NULL); + + reset_mmcr0(); + mtspr(SPR_PMC5, 0); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) & ~(MMCR0_FC | MMCR0_FC56)); + asm volatile(".long 0x0" ::: "memory"); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) | (MMCR0_FC | MMCR0_FC56)); + assert(got_interrupt); + got_interrupt = false; + pmc5_1 = mfspr(SPR_PMC5); + + reset_mmcr0(); + mtspr(SPR_PMC5, 0); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) & ~(MMCR0_FC | MMCR0_FC56)); + asm volatile(".rep 20 ; nop ; .endr ; .long 0x0" ::: "memory"); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) | (MMCR0_FC | MMCR0_FC56)); + assert(got_interrupt); + got_interrupt = false; + pmc5_2 = mfspr(SPR_PMC5); + + /* TCG and POWER9 do not count instructions around faults correctly */ + report_kfail(true, pmc5_1 + 20 == pmc5_2, "PMC5 counts instructions with fault"); + + handle_exception(0x700, NULL, NULL); + handle_exception(0xe40, NULL, NULL); +} + +static void test_pmc5_with_sc(void) +{ + unsigned long pmc5_1, pmc5_2; + + handle_exception(0xc00, &sc_handler, NULL); + + reset_mmcr0(); + mtspr(SPR_PMC5, 0); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) & ~(MMCR0_FC | MMCR0_FC56)); + asm volatile("sc 0" ::: "memory"); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) | (MMCR0_FC | MMCR0_FC56)); + assert(got_interrupt); + got_interrupt = false; + pmc5_1 = mfspr(SPR_PMC5); + + reset_mmcr0(); + mtspr(SPR_PMC5, 0); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) & ~(MMCR0_FC | MMCR0_FC56)); + asm volatile(".rep 20 ; nop ; .endr ; sc 0" ::: "memory"); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) | (MMCR0_FC | MMCR0_FC56)); + assert(got_interrupt); + got_interrupt = false; + pmc5_2 = mfspr(SPR_PMC5); + + /* TCG does not count instructions around syscalls correctly */ + report_kfail(true, pmc5_1 + 20 == pmc5_2, "PMC5 counts instructions with syscall"); + + handle_exception(0xc00, NULL, NULL); +} + +static void test_pmc56(void) +{ + unsigned long tmp; + + report_prefix_push("pmc56"); + + reset_mmcr0(); + mtspr(SPR_PMC5, 0); + mtspr(SPR_PMC6, 0); + report(mfspr(SPR_PMC5) == 0, "PMC5 zeroed"); + report(mfspr(SPR_PMC6) == 0, "PMC6 zeroed"); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) & ~MMCR0_FC); + msleep(100); + report(mfspr(SPR_PMC5) == 0, "PMC5 frozen"); + report(mfspr(SPR_PMC6) == 0, "PMC6 frozen"); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) & ~MMCR0_FC56); + mdelay(100); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) | (MMCR0_FC | MMCR0_FC56)); + report(mfspr(SPR_PMC5) != 0, "PMC5 counting"); + report(mfspr(SPR_PMC6) != 0, "PMC6 counting"); + + /* Dynamic frequency scaling could cause to be out, so don't fail. */ + tmp = mfspr(SPR_PMC6); + report(true, "PMC6 ratio to reported clock frequency is %ld%%", tmp * 1000 / cpu_hz); + + tmp = pmc5_count_nr_insns(100); + tmp = pmc5_count_nr_insns(1000) - tmp; + report(tmp == 900, "PMC5 counts instructions precisely"); + + test_pmc5_with_fault(); + test_pmc5_with_sc(); + + report_prefix_pop(); +} + +static void dec_ignore_handler(struct pt_regs *regs, void *data) +{ + mtspr(SPR_DEC, 0x7fffffff); +} + +static void pmi_handler(struct pt_regs *regs, void *data) +{ + got_interrupt = true; + memcpy((void *)&recorded_regs, regs, sizeof(struct pt_regs)); + recorded_mmcr0 = mfspr(SPR_MMCR0); + if (mfspr(SPR_MMCR0) & MMCR0_PMAO) { + /* This may cause infinite interrupts, so clear it. */ + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) & ~MMCR0_PMAO); + } +} + +static void test_pmi(void) +{ + report_prefix_push("pmi"); + handle_exception(0x900, &dec_ignore_handler, NULL); + handle_exception(0xf00, &pmi_handler, NULL); + reset_mmcr0(); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) | MMCR0_PMAO); + mtmsr(mfmsr() | MSR_EE); + mtmsr(mfmsr() & ~MSR_EE); + report(got_interrupt, "PMAO caused interrupt"); + got_interrupt = false; + handle_exception(0xf00, NULL, NULL); + handle_exception(0x900, NULL, NULL); + report_prefix_pop(); +} + +static void clrbhrb(void) +{ + asm volatile("clrbhrb" ::: "memory"); +} + +static inline unsigned long mfbhrbe(int nr) +{ + unsigned long e; + + asm volatile("mfbhrbe %0,%1" : "=r"(e) : "i"(nr) : "memory"); + + return e; +} + +extern unsigned char dummy_branch_1[]; +extern unsigned char dummy_branch_2[]; + +static __attribute__((__noinline__)) void bhrb_dummy(int i) +{ + asm volatile( + " cmpdi %0,1 \n\t" + " beq 1f \n\t" + ".global dummy_branch_1 \n\t" + "dummy_branch_1: \n\t" + " b 2f \n\t" + "1: trap \n\t" + ".global dummy_branch_2 \n\t" + "dummy_branch_2: \n\t" + "2: bne 3f \n\t" + " trap \n\t" + "3: nop \n\t" + : : "r"(i)); +} + +#define NR_BHRBE 16 +static unsigned long bhrbe[NR_BHRBE]; +static int nr_bhrbe; + +static void run_and_load_bhrb(void) +{ + int i; + + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) & ~MMCR0_PMAE); + clrbhrb(); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) | MMCR0_BHRBA); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) & ~(MMCR0_FC | MMCR0_FCP | MMCR0_FCPC)); + mtspr(SPR_MMCRA, mfspr(SPR_MMCRA) & ~(MMCRA_BHRBRD | MMCRA_IFM_MASK)); + + if (cpu_has_p10_bhrb) { + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) | MMCR0_PMAE); + asm volatile("isync" ::: "memory"); + enter_usermode(); + bhrb_dummy(0); + exit_usermode(); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) & ~MMCR0_PMAE); + asm volatile("isync" ::: "memory"); + } else { + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) | MMCR0_PMAE); + asm volatile("isync" ::: "memory"); + mtmsr(mfmsr()); + asm volatile(".rept 100 ; nop ; .endr"); + bhrb_dummy(0); + mtspr(SPR_MMCR0, mfspr(SPR_MMCR0) & ~MMCR0_PMAE); + asm volatile("isync" ::: "memory"); + } + + bhrbe[0] = mfbhrbe(0); + bhrbe[1] = mfbhrbe(1); + bhrbe[2] = mfbhrbe(2); + bhrbe[3] = mfbhrbe(3); + bhrbe[4] = mfbhrbe(4); + bhrbe[5] = mfbhrbe(5); + bhrbe[6] = mfbhrbe(6); + bhrbe[7] = mfbhrbe(7); + bhrbe[8] = mfbhrbe(8); + bhrbe[9] = mfbhrbe(9); + bhrbe[10] = mfbhrbe(10); + bhrbe[11] = mfbhrbe(11); + bhrbe[12] = mfbhrbe(12); + bhrbe[13] = mfbhrbe(13); + bhrbe[14] = mfbhrbe(14); + bhrbe[15] = mfbhrbe(15); + + for (i = 0; i < NR_BHRBE; i++) { + bhrbe[i] &= ~0x1UL; /* remove prediction bit */ + if (!bhrbe[i]) + break; + } + nr_bhrbe = i; +} + +static void test_bhrb(void) +{ + int i; + + if (cpu_has_p10_bhrb && !vm_available()) + return; + + report_prefix_push("bhrb"); + + /* TCG doesn't impelment BHRB yet */ + handle_exception(0x700, &illegal_handler, NULL); + handle_exception(0xe40, &illegal_handler, NULL); + clrbhrb(); + handle_exception(0x700, NULL, NULL); + handle_exception(0xe40, NULL, NULL); + if (got_interrupt) { + got_interrupt = false; + report_skip("BHRB support missing"); + report_prefix_pop(); + return; + } + + if (vm_available()) { + handle_exception(0x900, &dec_ignore_handler, NULL); + setup_vm(); + } + reset_mmcr0(); + clrbhrb(); + if (cpu_has_p10_bhrb) { + enter_usermode(); + bhrb_dummy(0); + exit_usermode(); + } else { + bhrb_dummy(0); + } + report(mfbhrbe(0) == 0, "BHRB is frozen"); + + /* + * BHRB may be cleared at any time (e.g., by OS or hypervisor) + * so this test could be occasionally incorrect. Try several + * times before giving up... + */ + + if (cpu_has_p10_bhrb) { + /* + * BHRB should have 8 entries: + * 1. enter_usermode blr + * 2. enter_usermode blr target + * 3. bl dummy + * 4. dummy unconditional + * 5. dummy conditional + * 6. dummy blr + * 7. dummy blr target + * 8. exit_usermode bl + * + * POWER10 often gives 4 entries, if other threads are + * running on the core, it seems to struggle. + */ + for (i = 0; i < 200; i++) { + run_and_load_bhrb(); + if (nr_bhrbe == 8) + break; + if (i > 100 && nr_bhrbe == 4) + break; + } + report(nr_bhrbe, "BHRB has been written"); + report_kfail(true, nr_bhrbe == 8, "BHRB has written 8 entries"); + if (nr_bhrbe == 8) { + report(bhrbe[4] == (unsigned long)dummy_branch_1, + "correct unconditional branch address"); + report(bhrbe[3] == (unsigned long)dummy_branch_2, + "correct conditional branch address"); + } else if (nr_bhrbe == 4) { + /* POWER10 workaround */ + report(nr_bhrbe == 4, "BHRB has written 4 entries"); + report(bhrbe[3] == (unsigned long)dummy_branch_2, + "correct conditional branch address"); + } + } else { + /* + * BHRB should have 6 entries: + * 1. bl dummy + * 2. dummy unconditional + * 3. dummy conditional + * 4. dummy blr + * 5. dummy blr target + * 6. Final b loop before disabled. + * + * POWER9 often gives 4 entries, if other threads are + * running on the core, it seems to struggle. + */ + for (i = 0; i < 200; i++) { + run_and_load_bhrb(); + if (nr_bhrbe == 6) + break; + if (i > 100 && nr_bhrbe == 4) + break; + } + report(nr_bhrbe, "BHRB has been written"); + report_kfail(true, nr_bhrbe == 6, "BHRB has written 6 entries"); + if (nr_bhrbe == 6) { + report(bhrbe[4] == (unsigned long)dummy_branch_1, + "correct unconditional branch address"); + report(bhrbe[3] == (unsigned long)dummy_branch_2, + "correct conditional branch address"); + } else if (nr_bhrbe == 4) { + /* POWER9 workaround */ + report(nr_bhrbe == 4, "BHRB has written 4 entries"); + report(bhrbe[3] == (unsigned long)dummy_branch_2, + "correct conditional branch address"); + } + } + + handle_exception(0x900, NULL, NULL); + + report_prefix_pop(); +} + +int main(int argc, char **argv) +{ + report_prefix_push("pmu"); + + test_pmc56(); + test_pmi(); + if (cpu_has_bhrb) + test_bhrb(); + + report_prefix_pop(); + + return report_summary(); +} diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index c7cda819d..d767f5d68 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -73,6 +73,9 @@ file = interrupts.elf file = mmu.elf smp = $MAX_SMP +[pmu] +file = pmu.elf + [smp] file = smp.elf smp = 2 From patchwork Sat May 4 12:28:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931296 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=hf8+TlAy; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWnYq6qr7z1yb7 for ; Sat, 4 May 2024 22:49:35 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=hf8+TlAy; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWnYq3RHKz3fnv for ; Sat, 4 May 2024 22:49:35 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=hf8+TlAy; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42e; helo=mail-pf1-x42e.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn843Xq0z3cb1 for ; Sat, 4 May 2024 22:30:44 +1000 (AEST) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6f460e05101so115657b3a.1 for ; Sat, 04 May 2024 05:30:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825843; x=1715430643; darn=lists.ozlabs.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=5e7S6CmFvKeffkGPyTCOL8jP7a0oCwEqBFa0CpbZAAo=; b=hf8+TlAyWD7oN78LAHwEOa0ccmKFl1fB2tDxWXN5vkhMbzy92UBbpiy22aUBJrqzSG Nn01ISlIA6Ap4ysu6N6bA/WOpy91ATzB+oOii59BSOHWAA38sEPtokRVsOB8uxglLjCi YZ9lyM7pGQE2FHH+Te9H+MA7qOGzlnErxRRbvNBLmAMXiySbJofGwACWKUHxGmRCDYSs 7M5EMWFCS85ud+U/YOyGtyCRUdMSre0zDz1j9TQxhwmhvq8viZhAG6X6Lu0noRogKPMh xSVlwMYrfaViJNPANmfIp3KjVCAyK8G/HBzYMJOdGZ6EUS1KtIUWFNLG3ik944q0JcBx rjOQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825843; x=1715430643; 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=5e7S6CmFvKeffkGPyTCOL8jP7a0oCwEqBFa0CpbZAAo=; b=bloatVe58wpry8pGURcHZxCW675IT1JvfELJf5A9OCF3VIMSyHpVa3Q+y8dq/Cn4pd NXWrSAPNtC6P9ghfs7iSE9M/ztr/LQfHjmThwhxFVAjbxda7gcYMsY7hKOzUqVdnXNe1 lThY5aVZjqFjni0rtA0F8ZC2J6y1Okdx8yUQmeDOM724NmfEusbj58Z0LaPyDaSw/Ume xeHKZPNsEAwPdE9dd3bU7NLZggwWW7zsN4pV+RvUNEFrUA4D8UGY0eWp63LdbgbCvQu5 GoUMGANd2O+qKKONCGPquhkTd++0UQ1Iw9GHKgQR0Z4lbZwiswXyOJLdY9MKRbfuRkPS wxeQ== X-Forwarded-Encrypted: i=1; AJvYcCUxF0BQ3JgE40d3pR8023nOU4Jr5kzYFbVf5oNxukJwoiD+i0SnrEDk8CzNN6cOhv1+Dcw8zP8KYX2PKnyhG/tq8JVdUZEMheJLPPr4rg== X-Gm-Message-State: AOJu0YwFZums6l8E/43+1Qi9x6qo67DWSjSDjgMH1tBvU66+IBAvjvWN OVx4ijjjjpoiGkM5RJBGZUQB77cKZfsM2DnFe4eSixvhQiL18MUFwMxuJA== X-Google-Smtp-Source: AGHT+IFPZkfPU8Egb2mh6EBzGgW9QChyXJexPKHvEKB5uBRSLxU0nzgY3U6aLmK8CozI1eiDyMOazA== X-Received: by 2002:a05:6a20:8420:b0:1a3:b187:f261 with SMTP id c32-20020a056a20842000b001a3b187f261mr12634372pzd.29.1714825842756; Sat, 04 May 2024 05:30:42 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.30.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:30:42 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 28/31] configure: Make arch_libdir a first-class entity Date: Sat, 4 May 2024 22:28:34 +1000 Message-ID: <20240504122841.1177683-29-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , linux-s390@vger.kernel.org, =?utf-8?q?Nico_B=C3=B6hr?= , Janosch Frank , kvm@vger.kernel.org, David Hildenbrand , linuxppc-dev@lists.ozlabs.org, Nicholas Piggin , Andrew Jones , Eric Auger , kvm-riscv@lists.infradead.org, kvmarm@lists.linux.dev, Paolo Bonzini , Claudio Imbrenda , Alexandru Elisei Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" arch_libdir was brought in to improve the heuristic determination of the lib/ directory based on arch and testdir names, but it did not entirely clean that mess up. Remove the arch_libdir->arch->testdir heuristic and just require everybody sets arch_libdir correctly. Fail if the lib/arch or lib/arch/asm directories can not be found. Cc: Alexandru Elisei Cc: Claudio Imbrenda Cc: David Hildenbrand Cc: Eric Auger Cc: Janosch Frank Cc: Laurent Vivier Cc: Nico Böhr Cc: Paolo Bonzini Cc: Thomas Huth Cc: kvm@vger.kernel.org Cc: linux-s390@vger.kernel.org Cc: kvmarm@lists.linux.dev Cc: kvm-riscv@lists.infradead.org Cc: linuxppc-dev@lists.ozlabs.org Reviewed-by: Andrew Jones Signed-off-by: Nicholas Piggin --- Makefile | 2 +- configure | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 5b7998b79..7fe93dfd8 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ include config.mak VPATH = $(SRCDIR) libdirs-get = $(shell [ -d "lib/$(1)" ] && echo "lib/$(1) lib/$(1)/asm") -ARCH_LIBDIRS := $(call libdirs-get,$(ARCH_LIBDIR)) $(call libdirs-get,$(TEST_DIR)) +ARCH_LIBDIRS := $(call libdirs-get,$(ARCH_LIBDIR)) OBJDIRS := $(ARCH_LIBDIRS) DESTDIR := $(PREFIX)/share/kvm-unit-tests/ diff --git a/configure b/configure index d744ec4dc..2b788d0c8 100755 --- a/configure +++ b/configure @@ -216,7 +216,6 @@ fi arch_name=$arch [ "$arch" = "aarch64" ] && arch="arm64" [ "$arch_name" = "arm64" ] && arch_name="aarch64" -arch_libdir=$arch if [ "$arch" = "riscv" ]; then echo "riscv32 or riscv64 must be specified" @@ -284,8 +283,10 @@ fi if [ "$arch" = "i386" ] || [ "$arch" = "x86_64" ]; then testdir=x86 + arch_libdir=x86 elif [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then testdir=arm + arch_libdir=$arch if [ "$target" = "qemu" ]; then arm_uart_early_addr=0x09000000 elif [ "$target" = "kvmtool" ]; then @@ -334,6 +335,7 @@ elif [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then fi elif [ "$arch" = "ppc64" ]; then testdir=powerpc + arch_libdir=ppc64 firmware="$testdir/boot_rom.bin" if [ "$endian" != "little" ] && [ "$endian" != "big" ]; then echo "You must provide endianness (big or little)!" @@ -344,6 +346,7 @@ elif [ "$arch" = "riscv32" ] || [ "$arch" = "riscv64" ]; then arch_libdir=riscv elif [ "$arch" = "s390x" ]; then testdir=s390x + arch_libdir=s390x else echo "arch $arch is not supported!" arch= @@ -353,6 +356,10 @@ if [ ! -d "$srcdir/$testdir" ]; then echo "$srcdir/$testdir does not exist!" exit 1 fi +if [ ! -d "$srcdir/lib/$arch_libdir" ]; then + echo "$srcdir/lib/$arch_libdir does not exist!" + exit 1 +fi if [ "$efi" = "y" ] && [ -f "$srcdir/$testdir/efi/run" ]; then ln -fs "$srcdir/$testdir/efi/run" $testdir-run @@ -415,10 +422,11 @@ fi # link lib/asm for the architecture rm -f lib/asm asm="asm-generic" -if [ -d "$srcdir/lib/$arch/asm" ]; then - asm="$srcdir/lib/$arch/asm" -elif [ -d "$srcdir/lib/$testdir/asm" ]; then - asm="$srcdir/lib/$testdir/asm" +if [ -d "$srcdir/lib/$arch_libdir/asm" ]; then + asm="$srcdir/lib/$arch_libdir/asm" +else + echo "$srcdir/lib/$arch_libdir/asm does not exist" + exit 1 fi mkdir -p lib ln -sf "$asm" lib/asm From patchwork Sat May 4 12:28:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931297 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=ZoVR9kdJ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWnZc4b8xz1ybC for ; Sat, 4 May 2024 22:50:16 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=ZoVR9kdJ; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWnZb717Wz78MX for ; Sat, 4 May 2024 22:50:15 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=ZoVR9kdJ; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::431; helo=mail-pf1-x431.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn893THLz3cbt for ; Sat, 4 May 2024 22:30:49 +1000 (AEST) Received: by mail-pf1-x431.google.com with SMTP id d2e1a72fcca58-6f447976de7so457251b3a.1 for ; Sat, 04 May 2024 05:30:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825847; x=1715430647; darn=lists.ozlabs.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=X+qJzK9x4g2HNU4FIHdEW1W0hvBZCghz5m03Ne8RAv4=; b=ZoVR9kdJBrfTMjUbN/Eq0JS7fJGVj+mApHPSL7BzA64L8wGyQ1l418VAoOxkNh+VI+ GiC4Xg1W+rl+zezzGy8+lmNdM2iTEVpKgPMr8U739Z98stXWVfha31+5gAU/2qZUSTcg ZycXyoUvI7fJsGFR4JqJOmAvDE1LFDAeIqdw0W92sZCKWMWUcXK5gINsfzQX1rCSwQV3 dbHGhbmAbHno/sNkztqY9dk4JczWjuAGY3TvSjaDH4bvX2vs7SVsbWV+dvbFpcCT+6qk BBjzWlG9pK2iZHL3NE8X+3UScBkC0YOHJOtVwDVoUmYJrfTExYYuB2sxg0zMk8ei94WC z3QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825847; x=1715430647; 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=X+qJzK9x4g2HNU4FIHdEW1W0hvBZCghz5m03Ne8RAv4=; b=gZFOSd4660r/cIifSFGEdN6CswPd2CiOwBbCuRHnl863lV71bssqlT4BOnujw6JTew 38yFWwF5TrNtHMZSKX/FM0EZxjLr1alWoQ8G8aLAi5v3hSXpxQ+CQACTjWETlI8OrWsB y6sB/6MyrtglwDk6ipCmYd0L0FOP1q+Y4QrVFRQM+YGETiT0ikAXiTMfHhKnbwXylvuV sWuJWHNeHMe2aQdm4fiLv8i5+bqif0IK+wikrj3Tc6NftUEm/AQrqWPH+hD5Yhl++tIM cAC4BRjq3wbVCZi0sdBNnd/0crqFAaGKnANlrtKSrdEp5ACAExRvKfDV05QE3vAzrrfR Q9eA== X-Forwarded-Encrypted: i=1; AJvYcCXh9DTVtkBJx7bR+st4+H2x0g8O+TS5n5xU8gWQ80cQeiTAa2LD7AsX4Pi+rb40SHAnvMhbOM/sVdPfr/5y92F0TyCDPh/p2GdKZHHrWw== X-Gm-Message-State: AOJu0YwJKdoNnjBXGmbouaP0CdBMYMAbhmkcd/MFwRW2d7iAUbiD3N21 jq80R6b9gl7qFmEl/nR0EY0vBlJqll2XZ346ERYOt5oxe50YNqOF X-Google-Smtp-Source: AGHT+IHEtBsHCn1R5mKaNUjYdiJyjlu2QlQBKkCFbulBsGZiM7KWx2eBMFrLR4i5dy7lCQJq71P8eQ== X-Received: by 2002:a05:6a00:804:b0:6f3:ee60:54bd with SMTP id m4-20020a056a00080400b006f3ee6054bdmr6023976pfk.8.1714825846390; Sat, 04 May 2024 05:30:46 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.30.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:30:46 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 29/31] powerpc: Remove remnants of ppc64 directory and build structure Date: Sat, 4 May 2024 22:28:35 +1000 Message-ID: <20240504122841.1177683-30-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" This moves merges ppc64 directories and files into powerpc, and merges the 3 makefiles into one. The configure --arch=powerpc option is aliased to ppc64 for good measure. Signed-off-by: Nicholas Piggin Acked-by: Thomas Huth --- MAINTAINERS | 1 - configure | 3 +- lib/{ppc64 => powerpc}/asm-offsets.c | 0 lib/{ppc64 => powerpc}/asm/asm-offsets.h | 0 lib/{ppc64 => powerpc}/asm/atomic.h | 0 lib/{ppc64 => powerpc}/asm/barrier.h | 4 +- lib/{ppc64 => powerpc}/asm/bitops.h | 4 +- lib/{ppc64 => powerpc}/asm/io.h | 4 +- lib/{ppc64 => powerpc}/asm/mmu.h | 0 lib/{ppc64 => powerpc}/asm/opal.h | 4 +- lib/{ppc64 => powerpc}/asm/page.h | 6 +- lib/{ppc64 => powerpc}/asm/pgtable-hwdef.h | 6 +- lib/{ppc64 => powerpc}/asm/pgtable.h | 2 +- lib/{ppc64 => powerpc}/asm/ptrace.h | 6 +- lib/{ppc64 => powerpc}/asm/spinlock.h | 6 +- lib/powerpc/asm/stack.h | 3 + lib/{ppc64 => powerpc}/asm/vpa.h | 0 lib/{ppc64 => powerpc}/mmu.c | 0 lib/{ppc64 => powerpc}/opal-calls.S | 0 lib/{ppc64 => powerpc}/opal.c | 0 lib/{ppc64 => powerpc}/stack.c | 0 lib/ppc64/.gitignore | 1 - lib/ppc64/asm/handlers.h | 1 - lib/ppc64/asm/hcall.h | 1 - lib/ppc64/asm/memory_areas.h | 6 -- lib/ppc64/asm/ppc_asm.h | 1 - lib/ppc64/asm/processor.h | 1 - lib/ppc64/asm/reg.h | 1 - lib/ppc64/asm/rtas.h | 1 - lib/ppc64/asm/setup.h | 1 - lib/ppc64/asm/smp.h | 1 - lib/ppc64/asm/stack.h | 11 -- powerpc/Makefile | 112 ++++++++++++++++++++- powerpc/Makefile.common | 96 ------------------ powerpc/Makefile.ppc64 | 31 ------ 35 files changed, 137 insertions(+), 177 deletions(-) rename lib/{ppc64 => powerpc}/asm-offsets.c (100%) rename lib/{ppc64 => powerpc}/asm/asm-offsets.h (100%) rename lib/{ppc64 => powerpc}/asm/atomic.h (100%) rename lib/{ppc64 => powerpc}/asm/barrier.h (83%) rename lib/{ppc64 => powerpc}/asm/bitops.h (69%) rename lib/{ppc64 => powerpc}/asm/io.h (50%) rename lib/{ppc64 => powerpc}/asm/mmu.h (100%) rename lib/{ppc64 => powerpc}/asm/opal.h (90%) rename lib/{ppc64 => powerpc}/asm/page.h (94%) rename lib/{ppc64 => powerpc}/asm/pgtable-hwdef.h (93%) rename lib/{ppc64 => powerpc}/asm/pgtable.h (99%) rename lib/{ppc64 => powerpc}/asm/ptrace.h (89%) rename lib/{ppc64 => powerpc}/asm/spinlock.h (54%) rename lib/{ppc64 => powerpc}/asm/vpa.h (100%) rename lib/{ppc64 => powerpc}/mmu.c (100%) rename lib/{ppc64 => powerpc}/opal-calls.S (100%) rename lib/{ppc64 => powerpc}/opal.c (100%) rename lib/{ppc64 => powerpc}/stack.c (100%) delete mode 100644 lib/ppc64/.gitignore delete mode 100644 lib/ppc64/asm/handlers.h delete mode 100644 lib/ppc64/asm/hcall.h delete mode 100644 lib/ppc64/asm/memory_areas.h delete mode 100644 lib/ppc64/asm/ppc_asm.h delete mode 100644 lib/ppc64/asm/processor.h delete mode 100644 lib/ppc64/asm/reg.h delete mode 100644 lib/ppc64/asm/rtas.h delete mode 100644 lib/ppc64/asm/setup.h delete mode 100644 lib/ppc64/asm/smp.h delete mode 100644 lib/ppc64/asm/stack.h delete mode 100644 powerpc/Makefile.common delete mode 100644 powerpc/Makefile.ppc64 diff --git a/MAINTAINERS b/MAINTAINERS index a2fa437da..1309863f2 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -92,7 +92,6 @@ S: Maintained L: linuxppc-dev@lists.ozlabs.org F: powerpc/ F: lib/powerpc/ -F: lib/ppc64/ RISCV M: Andrew Jones diff --git a/configure b/configure index 2b788d0c8..77a0230fa 100755 --- a/configure +++ b/configure @@ -215,6 +215,7 @@ fi arch_name=$arch [ "$arch" = "aarch64" ] && arch="arm64" +[ "$arch" = "powerpc" ] && arch="ppc64" [ "$arch_name" = "arm64" ] && arch_name="aarch64" if [ "$arch" = "riscv" ]; then @@ -335,7 +336,7 @@ elif [ "$arch" = "arm" ] || [ "$arch" = "arm64" ]; then fi elif [ "$arch" = "ppc64" ]; then testdir=powerpc - arch_libdir=ppc64 + arch_libdir=powerpc firmware="$testdir/boot_rom.bin" if [ "$endian" != "little" ] && [ "$endian" != "big" ]; then echo "You must provide endianness (big or little)!" diff --git a/lib/ppc64/asm-offsets.c b/lib/powerpc/asm-offsets.c similarity index 100% rename from lib/ppc64/asm-offsets.c rename to lib/powerpc/asm-offsets.c diff --git a/lib/ppc64/asm/asm-offsets.h b/lib/powerpc/asm/asm-offsets.h similarity index 100% rename from lib/ppc64/asm/asm-offsets.h rename to lib/powerpc/asm/asm-offsets.h diff --git a/lib/ppc64/asm/atomic.h b/lib/powerpc/asm/atomic.h similarity index 100% rename from lib/ppc64/asm/atomic.h rename to lib/powerpc/asm/atomic.h diff --git a/lib/ppc64/asm/barrier.h b/lib/powerpc/asm/barrier.h similarity index 83% rename from lib/ppc64/asm/barrier.h rename to lib/powerpc/asm/barrier.h index 475434b6a..22349d691 100644 --- a/lib/ppc64/asm/barrier.h +++ b/lib/powerpc/asm/barrier.h @@ -1,5 +1,5 @@ -#ifndef _ASMPPC64_BARRIER_H_ -#define _ASMPPC64_BARRIER_H_ +#ifndef _ASMPOWERPC_BARRIER_H_ +#define _ASMPOWERPC_BARRIER_H_ #define cpu_relax() asm volatile("or 1,1,1 ; or 2,2,2" ::: "memory") #define pause_short() asm volatile(".long 0x7c40003c" ::: "memory") diff --git a/lib/ppc64/asm/bitops.h b/lib/powerpc/asm/bitops.h similarity index 69% rename from lib/ppc64/asm/bitops.h rename to lib/powerpc/asm/bitops.h index c93d64bb9..dc1b8cd3f 100644 --- a/lib/ppc64/asm/bitops.h +++ b/lib/powerpc/asm/bitops.h @@ -1,5 +1,5 @@ -#ifndef _ASMPPC64_BITOPS_H_ -#define _ASMPPC64_BITOPS_H_ +#ifndef _ASMPOWERPC_BITOPS_H_ +#define _ASMPOWERPC_BITOPS_H_ #ifndef _BITOPS_H_ #error only can be included directly diff --git a/lib/ppc64/asm/io.h b/lib/powerpc/asm/io.h similarity index 50% rename from lib/ppc64/asm/io.h rename to lib/powerpc/asm/io.h index 08d7297c3..cfe099f01 100644 --- a/lib/ppc64/asm/io.h +++ b/lib/powerpc/asm/io.h @@ -1,5 +1,5 @@ -#ifndef _ASMPPC64_IO_H_ -#define _ASMPPC64_IO_H_ +#ifndef _ASMPOWERPC_IO_H_ +#define _ASMPOWERPC_IO_H_ #define __iomem diff --git a/lib/ppc64/asm/mmu.h b/lib/powerpc/asm/mmu.h similarity index 100% rename from lib/ppc64/asm/mmu.h rename to lib/powerpc/asm/mmu.h diff --git a/lib/ppc64/asm/opal.h b/lib/powerpc/asm/opal.h similarity index 90% rename from lib/ppc64/asm/opal.h rename to lib/powerpc/asm/opal.h index 6c3e9ffe2..44e62d80d 100644 --- a/lib/ppc64/asm/opal.h +++ b/lib/powerpc/asm/opal.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-or-later */ -#ifndef _ASMPPC64_OPAL_H_ -#define _ASMPPC64_OPAL_H_ +#ifndef _ASMPOWERPC_OPAL_H_ +#define _ASMPOWERPC_OPAL_H_ #include diff --git a/lib/ppc64/asm/page.h b/lib/powerpc/asm/page.h similarity index 94% rename from lib/ppc64/asm/page.h rename to lib/powerpc/asm/page.h index c497d86b9..19bf9c677 100644 --- a/lib/ppc64/asm/page.h +++ b/lib/powerpc/asm/page.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ -#ifndef _ASMPPC64_PAGE_H_ -#define _ASMPPC64_PAGE_H_ +#ifndef _ASMPOWERPC_PAGE_H_ +#define _ASMPOWERPC_PAGE_H_ /* * Adapted from * lib/arm64/asm/page.h and Linux kernel defines. @@ -62,4 +62,4 @@ extern unsigned long __phys_to_virt(phys_addr_t addr); extern void *__ioremap(phys_addr_t phys_addr, size_t size); #endif /* !__ASSEMBLY__ */ -#endif /* _ASMPPC64_PAGE_H_ */ +#endif /* _ASMPOWERPC_PAGE_H_ */ diff --git a/lib/ppc64/asm/pgtable-hwdef.h b/lib/powerpc/asm/pgtable-hwdef.h similarity index 93% rename from lib/ppc64/asm/pgtable-hwdef.h rename to lib/powerpc/asm/pgtable-hwdef.h index 7cb2c7476..84618809d 100644 --- a/lib/ppc64/asm/pgtable-hwdef.h +++ b/lib/powerpc/asm/pgtable-hwdef.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ -#ifndef _ASMPPC64_PGTABLE_HWDEF_H_ -#define _ASMPPC64_PGTABLE_HWDEF_H_ +#ifndef _ASMPOWERPC_PGTABLE_HWDEF_H_ +#define _ASMPOWERPC_PGTABLE_HWDEF_H_ /* * Copyright (C) 2024, IBM Inc, Nicholas Piggin * @@ -63,4 +63,4 @@ #define PHYS_MASK_SHIFT (48) #define PHYS_MASK ((UL(1) << PHYS_MASK_SHIFT) - 1) -#endif /* _ASMPPC64_PGTABLE_HWDEF_H_ */ +#endif /* _ASMPOWERPC_PGTABLE_HWDEF_H_ */ diff --git a/lib/ppc64/asm/pgtable.h b/lib/powerpc/asm/pgtable.h similarity index 99% rename from lib/ppc64/asm/pgtable.h rename to lib/powerpc/asm/pgtable.h index a6ee0d4cd..d4f2c826a 100644 --- a/lib/ppc64/asm/pgtable.h +++ b/lib/powerpc/asm/pgtable.h @@ -122,4 +122,4 @@ static inline pte_t *pte_alloc(pmd_t *pmd, unsigned long addr) return pte_offset(pmd, addr); } -#endif /* _ASMPPC64_PGTABLE_H_ */ +#endif /* _ASMPOWERPC_PGTABLE_H_ */ diff --git a/lib/ppc64/asm/ptrace.h b/lib/powerpc/asm/ptrace.h similarity index 89% rename from lib/ppc64/asm/ptrace.h rename to lib/powerpc/asm/ptrace.h index db263a59e..39ea950e7 100644 --- a/lib/ppc64/asm/ptrace.h +++ b/lib/powerpc/asm/ptrace.h @@ -1,5 +1,5 @@ -#ifndef _ASMPPC64_PTRACE_H_ -#define _ASMPPC64_PTRACE_H_ +#ifndef _ASMPOWERPC_PTRACE_H_ +#define _ASMPOWERPC_PTRACE_H_ #define KERNEL_REDZONE_SIZE 288 #define STACK_FRAME_OVERHEAD 112 /* size of minimum stack frame */ @@ -38,4 +38,4 @@ static inline void regs_advance_insn(struct pt_regs *regs) #endif /* __ASSEMBLY__ */ -#endif /* _ASMPPC64_PTRACE_H_ */ +#endif /* _ASMPOWERPC_PTRACE_H_ */ diff --git a/lib/ppc64/asm/spinlock.h b/lib/powerpc/asm/spinlock.h similarity index 54% rename from lib/ppc64/asm/spinlock.h rename to lib/powerpc/asm/spinlock.h index b952386da..9dbe716fd 100644 --- a/lib/ppc64/asm/spinlock.h +++ b/lib/powerpc/asm/spinlock.h @@ -1,5 +1,5 @@ -#ifndef _ASMPPC64_SPINLOCK_H_ -#define _ASMPPC64_SPINLOCK_H_ +#ifndef _ASMPOWERPC_SPINLOCK_H_ +#define _ASMPOWERPC_SPINLOCK_H_ struct spinlock { unsigned int v; @@ -8,4 +8,4 @@ struct spinlock { void spin_lock(struct spinlock *lock); void spin_unlock(struct spinlock *lock); -#endif /* _ASMPPC64_SPINLOCK_H_ */ +#endif /* _ASMPOWERPC_SPINLOCK_H_ */ diff --git a/lib/powerpc/asm/stack.h b/lib/powerpc/asm/stack.h index e1c46ee09..eea139a45 100644 --- a/lib/powerpc/asm/stack.h +++ b/lib/powerpc/asm/stack.h @@ -5,4 +5,7 @@ #error Do not directly include . Just use . #endif +#define HAVE_ARCH_BACKTRACE +#define HAVE_ARCH_BACKTRACE_FRAME + #endif diff --git a/lib/ppc64/asm/vpa.h b/lib/powerpc/asm/vpa.h similarity index 100% rename from lib/ppc64/asm/vpa.h rename to lib/powerpc/asm/vpa.h diff --git a/lib/ppc64/mmu.c b/lib/powerpc/mmu.c similarity index 100% rename from lib/ppc64/mmu.c rename to lib/powerpc/mmu.c diff --git a/lib/ppc64/opal-calls.S b/lib/powerpc/opal-calls.S similarity index 100% rename from lib/ppc64/opal-calls.S rename to lib/powerpc/opal-calls.S diff --git a/lib/ppc64/opal.c b/lib/powerpc/opal.c similarity index 100% rename from lib/ppc64/opal.c rename to lib/powerpc/opal.c diff --git a/lib/ppc64/stack.c b/lib/powerpc/stack.c similarity index 100% rename from lib/ppc64/stack.c rename to lib/powerpc/stack.c diff --git a/lib/ppc64/.gitignore b/lib/ppc64/.gitignore deleted file mode 100644 index 84872bf19..000000000 --- a/lib/ppc64/.gitignore +++ /dev/null @@ -1 +0,0 @@ -asm-offsets.[hs] diff --git a/lib/ppc64/asm/handlers.h b/lib/ppc64/asm/handlers.h deleted file mode 100644 index 92e6fb247..000000000 --- a/lib/ppc64/asm/handlers.h +++ /dev/null @@ -1 +0,0 @@ -#include "../../powerpc/asm/handlers.h" diff --git a/lib/ppc64/asm/hcall.h b/lib/ppc64/asm/hcall.h deleted file mode 100644 index daabaca51..000000000 --- a/lib/ppc64/asm/hcall.h +++ /dev/null @@ -1 +0,0 @@ -#include "../../powerpc/asm/hcall.h" diff --git a/lib/ppc64/asm/memory_areas.h b/lib/ppc64/asm/memory_areas.h deleted file mode 100644 index b9fd46b9e..000000000 --- a/lib/ppc64/asm/memory_areas.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _ASMPPC64_MEMORY_AREAS_H_ -#define _ASMPPC64_MEMORY_AREAS_H_ - -#include - -#endif diff --git a/lib/ppc64/asm/ppc_asm.h b/lib/ppc64/asm/ppc_asm.h deleted file mode 100644 index e3929eeee..000000000 --- a/lib/ppc64/asm/ppc_asm.h +++ /dev/null @@ -1 +0,0 @@ -#include "../../powerpc/asm/ppc_asm.h" diff --git a/lib/ppc64/asm/processor.h b/lib/ppc64/asm/processor.h deleted file mode 100644 index 066a51a00..000000000 --- a/lib/ppc64/asm/processor.h +++ /dev/null @@ -1 +0,0 @@ -#include "../../powerpc/asm/processor.h" diff --git a/lib/ppc64/asm/reg.h b/lib/ppc64/asm/reg.h deleted file mode 100644 index bc407b555..000000000 --- a/lib/ppc64/asm/reg.h +++ /dev/null @@ -1 +0,0 @@ -#include "../../powerpc/asm/reg.h" diff --git a/lib/ppc64/asm/rtas.h b/lib/ppc64/asm/rtas.h deleted file mode 100644 index fe77f635c..000000000 --- a/lib/ppc64/asm/rtas.h +++ /dev/null @@ -1 +0,0 @@ -#include "../../powerpc/asm/rtas.h" diff --git a/lib/ppc64/asm/setup.h b/lib/ppc64/asm/setup.h deleted file mode 100644 index 201929859..000000000 --- a/lib/ppc64/asm/setup.h +++ /dev/null @@ -1 +0,0 @@ -#include "../../powerpc/asm/setup.h" diff --git a/lib/ppc64/asm/smp.h b/lib/ppc64/asm/smp.h deleted file mode 100644 index 67ced7567..000000000 --- a/lib/ppc64/asm/smp.h +++ /dev/null @@ -1 +0,0 @@ -#include "../../powerpc/asm/smp.h" diff --git a/lib/ppc64/asm/stack.h b/lib/ppc64/asm/stack.h deleted file mode 100644 index 94fd1021c..000000000 --- a/lib/ppc64/asm/stack.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef _ASMPPC64_STACK_H_ -#define _ASMPPC64_STACK_H_ - -#ifndef _STACK_H_ -#error Do not directly include . Just use . -#endif - -#define HAVE_ARCH_BACKTRACE -#define HAVE_ARCH_BACKTRACE_FRAME - -#endif diff --git a/powerpc/Makefile b/powerpc/Makefile index 8a007ab54..e4b5312a2 100644 --- a/powerpc/Makefile +++ b/powerpc/Makefile @@ -1 +1,111 @@ -include $(SRCDIR)/$(TEST_DIR)/Makefile.$(ARCH) +# +# powerpc makefile +# +# Authors: Andrew Jones +# +tests = \ + $(TEST_DIR)/selftest.elf \ + $(TEST_DIR)/selftest-migration.elf \ + $(TEST_DIR)/memory-verify.elf \ + $(TEST_DIR)/sieve.elf \ + $(TEST_DIR)/spapr_vpa.elf \ + $(TEST_DIR)/spapr_hcall.elf \ + $(TEST_DIR)/rtas.elf \ + $(TEST_DIR)/emulator.elf \ + $(TEST_DIR)/atomics.elf \ + $(TEST_DIR)/tm.elf \ + $(TEST_DIR)/smp.elf \ + $(TEST_DIR)/sprs.elf \ + $(TEST_DIR)/timebase.elf \ + $(TEST_DIR)/interrupts.elf \ + $(TEST_DIR)/mmu.elf \ + $(TEST_DIR)/pmu.elf + +all: directories $(TEST_DIR)/boot_rom.bin $(tests) + +cstart.o = $(TEST_DIR)/cstart64.o +reloc.o = $(TEST_DIR)/reloc64.o + +OBJDIRS += lib/powerpc +cflatobjs += lib/powerpc/stack.o +cflatobjs += lib/powerpc/mmu.o +cflatobjs += lib/powerpc/opal.o +cflatobjs += lib/powerpc/opal-calls.o +cflatobjs += lib/util.o +cflatobjs += lib/getchar.o +cflatobjs += lib/alloc_phys.o +cflatobjs += lib/alloc.o +cflatobjs += lib/alloc_page.o +cflatobjs += lib/vmalloc.o +cflatobjs += lib/devicetree.o +cflatobjs += lib/migrate.o +cflatobjs += lib/powerpc/io.o +cflatobjs += lib/powerpc/hcall.o +cflatobjs += lib/powerpc/setup.o +cflatobjs += lib/powerpc/rtas.o +cflatobjs += lib/powerpc/processor.o +cflatobjs += lib/powerpc/handlers.o +cflatobjs += lib/powerpc/smp.o +cflatobjs += lib/powerpc/spinlock.o + +################################################################## + +bits = 64 + +ifeq ($(ENDIAN),little) + arch_CFLAGS = -mlittle-endian + arch_LDFLAGS = -EL +else + arch_CFLAGS = -mbig-endian + arch_LDFLAGS = -EB +endif + +mabi_no_altivec := $(call cc-option,-mabi=no-altivec,"") + +CFLAGS += -std=gnu99 +CFLAGS += -ffreestanding +CFLAGS += -O2 -msoft-float -mno-altivec $(mabi_no_altivec) +CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt -I lib +CFLAGS += -Wa,-mregnames + +# We want to keep intermediate files +.PRECIOUS: %.o + +asm-offsets = lib/powerpc/asm-offsets.h +include $(SRCDIR)/scripts/asm-offsets.mak + +%.aux.o: $(SRCDIR)/lib/auxinfo.c + $(CC) $(CFLAGS) -c -o $@ $< -DPROGNAME=\"$(@:.aux.o=.elf)\" + +FLATLIBS = $(libcflat) $(LIBFDT_archive) +%.elf: CFLAGS += $(arch_CFLAGS) +%.elf: LDFLAGS += $(arch_LDFLAGS) -pie -n +%.elf: %.o $(FLATLIBS) $(SRCDIR)/powerpc/flat.lds $(cstart.o) $(reloc.o) %.aux.o + $(LD) $(LDFLAGS) -o $@ \ + -T $(SRCDIR)/powerpc/flat.lds --build-id=none \ + $(filter %.o, $^) $(FLATLIBS) + @chmod a-x $@ + @echo -n Checking $@ for unsupported reloc types... + @if $(OBJDUMP) -R $@ | grep R_ | grep -v R_PPC64_RELATIVE; then \ + false; \ + else \ + echo " looks good."; \ + fi + +$(TEST_DIR)/boot_rom.bin: $(TEST_DIR)/boot_rom.elf + dd if=/dev/zero of=$@ bs=256 count=1 + $(OBJCOPY) -O binary $^ $@.tmp + cat $@.tmp >> $@ + $(RM) $@.tmp + +$(TEST_DIR)/boot_rom.elf: CFLAGS = -mbig-endian +$(TEST_DIR)/boot_rom.elf: $(TEST_DIR)/boot_rom.o + $(LD) -EB -nostdlib -Ttext=0x100 --entry=start --build-id=none -o $@ $< + @chmod a-x $@ + +arch_clean: asm_offsets_clean + $(RM) $(TEST_DIR)/*.{o,elf} $(TEST_DIR)/boot_rom.bin \ + $(TEST_DIR)/.*.d lib/powerpc/.*.d + +generated-files = $(asm-offsets) +$(tests:.elf=.o) $(cstart.o) $(cflatobjs): $(generated-files) diff --git a/powerpc/Makefile.common b/powerpc/Makefile.common deleted file mode 100644 index 0255ca9e4..000000000 --- a/powerpc/Makefile.common +++ /dev/null @@ -1,96 +0,0 @@ -# -# powerpc common makefile -# -# Authors: Andrew Jones -# - -tests-common = \ - $(TEST_DIR)/selftest.elf \ - $(TEST_DIR)/selftest-migration.elf \ - $(TEST_DIR)/memory-verify.elf \ - $(TEST_DIR)/sieve.elf \ - $(TEST_DIR)/spapr_hcall.elf \ - $(TEST_DIR)/rtas.elf \ - $(TEST_DIR)/emulator.elf \ - $(TEST_DIR)/atomics.elf \ - $(TEST_DIR)/tm.elf \ - $(TEST_DIR)/smp.elf \ - $(TEST_DIR)/sprs.elf \ - $(TEST_DIR)/timebase.elf \ - $(TEST_DIR)/interrupts.elf \ - $(TEST_DIR)/mmu.elf \ - $(TEST_DIR)/pmu.elf - -tests-all = $(tests-common) $(tests) -all: directories $(TEST_DIR)/boot_rom.bin $(tests-all) - -################################################################## - -mabi_no_altivec := $(call cc-option,-mabi=no-altivec,"") - -CFLAGS += -std=gnu99 -CFLAGS += -ffreestanding -CFLAGS += -O2 -msoft-float -mno-altivec $(mabi_no_altivec) -CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt -I lib -CFLAGS += -Wa,-mregnames - -# We want to keep intermediate files -.PRECIOUS: %.o - -asm-offsets = lib/$(ARCH)/asm-offsets.h -include $(SRCDIR)/scripts/asm-offsets.mak - -cflatobjs += lib/util.o -cflatobjs += lib/getchar.o -cflatobjs += lib/alloc_phys.o -cflatobjs += lib/alloc.o -cflatobjs += lib/alloc_page.o -cflatobjs += lib/vmalloc.o -cflatobjs += lib/devicetree.o -cflatobjs += lib/migrate.o -cflatobjs += lib/powerpc/io.o -cflatobjs += lib/powerpc/hcall.o -cflatobjs += lib/powerpc/setup.o -cflatobjs += lib/powerpc/rtas.o -cflatobjs += lib/powerpc/processor.o -cflatobjs += lib/powerpc/handlers.o -cflatobjs += lib/powerpc/smp.o -cflatobjs += lib/powerpc/spinlock.o - -OBJDIRS += lib/powerpc - -%.aux.o: $(SRCDIR)/lib/auxinfo.c - $(CC) $(CFLAGS) -c -o $@ $< -DPROGNAME=\"$(@:.aux.o=.elf)\" - -FLATLIBS = $(libcflat) $(LIBFDT_archive) -%.elf: CFLAGS += $(arch_CFLAGS) -%.elf: LDFLAGS += $(arch_LDFLAGS) -pie -n -%.elf: %.o $(FLATLIBS) $(SRCDIR)/powerpc/flat.lds $(cstart.o) $(reloc.o) %.aux.o - $(LD) $(LDFLAGS) -o $@ \ - -T $(SRCDIR)/powerpc/flat.lds --build-id=none \ - $(filter %.o, $^) $(FLATLIBS) - @chmod a-x $@ - @echo -n Checking $@ for unsupported reloc types... - @if $(OBJDUMP) -R $@ | grep R_ | grep -v R_PPC64_RELATIVE; then \ - false; \ - else \ - echo " looks good."; \ - fi - -$(TEST_DIR)/boot_rom.bin: $(TEST_DIR)/boot_rom.elf - dd if=/dev/zero of=$@ bs=256 count=1 - $(OBJCOPY) -O binary $^ $@.tmp - cat $@.tmp >> $@ - $(RM) $@.tmp - -$(TEST_DIR)/boot_rom.elf: CFLAGS = -mbig-endian -$(TEST_DIR)/boot_rom.elf: $(TEST_DIR)/boot_rom.o - $(LD) -EB -nostdlib -Ttext=0x100 --entry=start --build-id=none -o $@ $< - @chmod a-x $@ - -powerpc_clean: asm_offsets_clean - $(RM) $(TEST_DIR)/*.{o,elf} $(TEST_DIR)/boot_rom.bin \ - $(TEST_DIR)/.*.d lib/powerpc/.*.d - -generated-files = $(asm-offsets) -$(tests-all:.elf=.o) $(cstart.o) $(cflatobjs): $(generated-files) diff --git a/powerpc/Makefile.ppc64 b/powerpc/Makefile.ppc64 deleted file mode 100644 index 2466471f9..000000000 --- a/powerpc/Makefile.ppc64 +++ /dev/null @@ -1,31 +0,0 @@ -# -# ppc64 makefile -# -# Authors: Andrew Jones -# -bits = 64 - -ifeq ($(ENDIAN),little) - arch_CFLAGS = -mlittle-endian - arch_LDFLAGS = -EL -else - arch_CFLAGS = -mbig-endian - arch_LDFLAGS = -EB -endif - -cstart.o = $(TEST_DIR)/cstart64.o -reloc.o = $(TEST_DIR)/reloc64.o - -OBJDIRS += lib/ppc64 -cflatobjs += lib/ppc64/stack.o -cflatobjs += lib/ppc64/mmu.o -cflatobjs += lib/ppc64/opal.o -cflatobjs += lib/ppc64/opal-calls.o - -# ppc64 specific tests -tests = $(TEST_DIR)/spapr_vpa.elf - -include $(SRCDIR)/$(TEST_DIR)/Makefile.common - -arch_clean: powerpc_clean - $(RM) lib/ppc64/.*.d From patchwork Sat May 4 12:28:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931298 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=JVFmvbsd; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWnbY0SXqz1ybC for ; Sat, 4 May 2024 22:51:05 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=JVFmvbsd; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWnbX6DGGz3gBd for ; Sat, 4 May 2024 22:51:04 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=JVFmvbsd; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42e; helo=mail-pf1-x42e.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn8C2rwMz3bs2 for ; Sat, 4 May 2024 22:30:51 +1000 (AEST) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6f4178aec15so461336b3a.0 for ; Sat, 04 May 2024 05:30:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825850; x=1715430650; darn=lists.ozlabs.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=/6KvNFDDT9boTvfk0g7Fu/0RZ+dy+RbVwyckvEdOV/A=; b=JVFmvbsdf1sfCUCsF8ySl7SNee1KFXDlFijyOkPvc2hd9bG+nKopbIQ0erYQz/NjfS VTKEcNMXNHxEi8PjbaotowcSgK7MuGdio03P22eeuNUvDJW/zYhP/h+pwR1TeMjGow3M v+2Ro/zdVSt4q/2Hm8rW/4YN//YSdKB0npREFwbKZ1i0zk0FDoL56Ap01q1Nba7y1aPr 0RbNNJne8akW8C5GD7hJmiwlMYGWPX44mJmYGP4FIfHiqKeMH93NAFm9jmAeF4fltkE5 cYkF3EeEyJAHw/axl0MF3kfE2GobmlyfhEmbzF5xXOZ2g3UQlv9rY8IofJu6SXRKnjHR lJKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825850; x=1715430650; 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=/6KvNFDDT9boTvfk0g7Fu/0RZ+dy+RbVwyckvEdOV/A=; b=VSLpTO83/uRZBHM8LNPITIFwNeD6SPAlKYz8MwWouQVWjRy+YdvYgWRACpoRAis9kE nOws8Rd3D7vrocaadkZnUThUQKRPaCvrYw+oujzT1ewYHIs6M8AMgA/LxHBc6LVouwCA C8/bqFEyIzYuXDPVlpkHEgnk31QM5M3dchDc9Jff6ik46w0hfPq4nindnTGIARn8ZhSu rQwm426SgfdVuDoZo8YCKraPgIDSHyCrTqEsyNg9gZXZholX/P7wn63eIT8/N3JlAWB3 Gdf+L6CP4lP614ct2p+jx0c0+Z6P/bK3iHqlGYz/4h3qY9huC9ueuGsPKWuluBWzkMPv 6NIg== X-Forwarded-Encrypted: i=1; AJvYcCXOZ/yxES8AyFeQJE61T0oAIJrr1QiKroy6EJsBgBIqXDvtH1gI6wlCg2RcjU4Fp8TPQjUgQBLohTIwZ13CG/HGTDou2uKM8WzC+G1l7g== X-Gm-Message-State: AOJu0YwCrqnBZpvzOQmMwhrhc7x0fvglRkf6OqZNbOsX41zpvmBK9A3V RymDR1zhLtJDOqP7/69HttrjLIYgL10cQtzRGOgPeF1fMcRNOkm7 X-Google-Smtp-Source: AGHT+IGiUp63wEQAX/25zlW8DnNsOdcroeS4VtV/DdyFyGXhh8WS73VQ1qY6UjK6KxrSgimj86sx7A== X-Received: by 2002:a05:6a20:320d:b0:1af:66e6:b1b2 with SMTP id hl13-20020a056a20320d00b001af66e6b1b2mr4860642pzc.1.1714825849815; Sat, 04 May 2024 05:30:49 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.30.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:30:49 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 30/31] powerpc: Add facility to query TCG or KVM host Date: Sat, 4 May 2024 22:28:36 +1000 Message-ID: <20240504122841.1177683-31-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Use device tree properties to determine whether KVM or TCG is in use. Logically these are not the inverse of one another, because KVM can be used on top of a TCG processor (if TCG is emulating HV mode, or if it provides a nested hypervisor interface with spapr). This can be a problem because some issues relate to TCG CPU emulation, and some to the spapr hypervisor implementation. At the moment there is no way to determine TCG is running a KVM host that is running the tests, but the two independent variables are added in case that is able to be determined in future. For now that case is just incorrectly considered to be kvm && !tcg. Use this facility to restrict some of the known test failures to TCG. Signed-off-by: Nicholas Piggin Reviewed-by: Thomas Huth --- lib/powerpc/asm/processor.h | 3 +++ lib/powerpc/setup.c | 25 +++++++++++++++++++++++++ powerpc/atomics.c | 2 +- powerpc/interrupts.c | 6 ++++-- powerpc/mmu.c | 2 +- powerpc/pmu.c | 6 +++--- powerpc/sprs.c | 2 +- powerpc/timebase.c | 4 ++-- powerpc/tm.c | 2 +- 9 files changed, 41 insertions(+), 11 deletions(-) diff --git a/lib/powerpc/asm/processor.h b/lib/powerpc/asm/processor.h index 28239c610..09535f8c3 100644 --- a/lib/powerpc/asm/processor.h +++ b/lib/powerpc/asm/processor.h @@ -10,6 +10,9 @@ void handle_exception(int trap, void (*func)(struct pt_regs *, void *), void *); void do_handle_exception(struct pt_regs *regs); #endif /* __ASSEMBLY__ */ +extern bool host_is_tcg; +extern bool host_is_kvm; + extern bool cpu_has_hv; extern bool cpu_has_power_mce; extern bool cpu_has_siar; diff --git a/lib/powerpc/setup.c b/lib/powerpc/setup.c index 8ff4939e2..2b9d67466 100644 --- a/lib/powerpc/setup.c +++ b/lib/powerpc/setup.c @@ -235,6 +235,8 @@ void cpu_init(struct cpu *cpu, int cpu_id) cpu->in_user = false; } +bool host_is_tcg; +bool host_is_kvm; bool is_hvmode; void setup(const void *fdt) @@ -290,6 +292,29 @@ void setup(const void *fdt) assert(ret == 0); freemem += fdt_size; + if (!fdt_node_check_compatible(fdt, 0, "qemu,pseries")) { + assert(!cpu_has_hv); + + /* + * host_is_tcg incorrectly does not get set when running + * KVM on a TCG host (using powernv HV emulation or spapr + * nested HV). + */ + ret = fdt_subnode_offset(fdt, 0, "hypervisor"); + if (ret < 0) { + host_is_tcg = true; + host_is_kvm = false; + } else { + /* KVM is the only supported hypervisor */ + assert(!fdt_node_check_compatible(fdt, ret, "linux,kvm")); + host_is_tcg = false; + host_is_kvm = true; + } + } else { + assert(cpu_has_hv); + host_is_tcg = true; + host_is_kvm = false; + } ret = dt_get_initrd(&tmp, &initrd_size); assert(ret == 0 || ret == -FDT_ERR_NOTFOUND); if (ret == 0) { diff --git a/powerpc/atomics.c b/powerpc/atomics.c index 975711fc8..7d6dfaed9 100644 --- a/powerpc/atomics.c +++ b/powerpc/atomics.c @@ -119,7 +119,7 @@ static void test_lwarx_stwcx(int argc, char *argv[]) "stwcx. %1,0,%3;" : "=&r"(old) : "r"(1), "r"(var), "r"((char *)var+1) : "cr0", "memory"); /* unaligned larx/stcx. is not required by the ISA to cause an exception, in TCG the stcx does not. */ - report_kfail(true, old == 0 && *var == 0 && got_interrupt && recorded_regs.trap == 0x600, "unaligned stwcx. causes fault"); + report_kfail(host_is_tcg, old == 0 && *var == 0 && got_interrupt && recorded_regs.trap == 0x600, "unaligned stwcx. causes fault"); got_interrupt = false; handle_exception(0x600, NULL, NULL); diff --git a/powerpc/interrupts.c b/powerpc/interrupts.c index ba965ff76..6511c76f2 100644 --- a/powerpc/interrupts.c +++ b/powerpc/interrupts.c @@ -78,7 +78,8 @@ static void test_mce(void) is_fetch = false; asm volatile("lbz %0,0(%1)" : "=r"(tmp) : "r"(addr)); - report(got_interrupt, "MCE on access to invalid real address"); + /* KVM does not MCE on access outside partition scope */ + report_kfail(host_is_kvm, got_interrupt, "MCE on access to invalid real address"); if (got_interrupt) { report(mfspr(SPR_DAR) == addr, "MCE sets DAR correctly"); if (cpu_has_power_mce) @@ -88,7 +89,8 @@ static void test_mce(void) is_fetch = true; asm volatile("mtctr %0 ; bctrl" :: "r"(addr) : "ctr", "lr"); - report(got_interrupt, "MCE on fetch from invalid real address"); + /* KVM does not MCE on access outside partition scope */ + report_kfail(host_is_kvm, got_interrupt, "MCE on fetch from invalid real address"); if (got_interrupt) { report(recorded_regs.nip == addr, "MCE sets SRR0 correctly"); if (cpu_has_power_mce) diff --git a/powerpc/mmu.c b/powerpc/mmu.c index fef790506..27220b71f 100644 --- a/powerpc/mmu.c +++ b/powerpc/mmu.c @@ -172,7 +172,7 @@ static void test_tlbie(int argc, char **argv) handle_exception(0x700, NULL, NULL); /* TCG has a known race invalidating other CPUs */ - report_kfail(true, !tlbie_test_failed, "tlbie"); + report_kfail(host_is_tcg, !tlbie_test_failed, "tlbie"); } #define THIS_ITERS 100000 diff --git a/powerpc/pmu.c b/powerpc/pmu.c index 8b13ee4cd..960f90787 100644 --- a/powerpc/pmu.c +++ b/powerpc/pmu.c @@ -107,7 +107,7 @@ static void test_pmc5_with_sc(void) pmc5_2 = mfspr(SPR_PMC5); /* TCG does not count instructions around syscalls correctly */ - report_kfail(true, pmc5_1 + 20 == pmc5_2, "PMC5 counts instructions with syscall"); + report_kfail(host_is_tcg, pmc5_1 + 20 == pmc5_2, "PMC5 counts instructions with syscall"); handle_exception(0xc00, NULL, NULL); } @@ -336,7 +336,7 @@ static void test_bhrb(void) break; } report(nr_bhrbe, "BHRB has been written"); - report_kfail(true, nr_bhrbe == 8, "BHRB has written 8 entries"); + report_kfail(!host_is_tcg, nr_bhrbe == 8, "BHRB has written 8 entries"); if (nr_bhrbe == 8) { report(bhrbe[4] == (unsigned long)dummy_branch_1, "correct unconditional branch address"); @@ -369,7 +369,7 @@ static void test_bhrb(void) break; } report(nr_bhrbe, "BHRB has been written"); - report_kfail(true, nr_bhrbe == 6, "BHRB has written 6 entries"); + report_kfail(!host_is_tcg, nr_bhrbe == 6, "BHRB has written 6 entries"); if (nr_bhrbe == 6) { report(bhrbe[4] == (unsigned long)dummy_branch_1, "correct unconditional branch address"); diff --git a/powerpc/sprs.c b/powerpc/sprs.c index c5844985a..c496efe9e 100644 --- a/powerpc/sprs.c +++ b/powerpc/sprs.c @@ -590,7 +590,7 @@ int main(int argc, char **argv) if (sprs[i].width == 32 && !(before[i] >> 32) && !(after[i] >> 32)) { /* known failure KVM migration of CTRL */ - report_kfail(true && i == 136, + report_kfail(host_is_kvm && i == 136, "%-10s(%4d):\t 0x%08lx <==> 0x%08lx", sprs[i].name, i, before[i], after[i]); diff --git a/powerpc/timebase.c b/powerpc/timebase.c index 02a4e33c0..b1378dd2b 100644 --- a/powerpc/timebase.c +++ b/powerpc/timebase.c @@ -94,7 +94,7 @@ static void test_dec(int argc, char **argv) break; } /* POWER CPUs can have a slight (few ticks) variation here */ - report_kfail(true, tb2 - tb1 >= dec_max - dec, "decrementer remains within TB after mtDEC"); + report_kfail(!host_is_tcg, tb2 - tb1 >= dec_max - dec, "decrementer remains within TB after mtDEC"); tb1 = get_tb(); mtspr(SPR_DEC, dec_max); @@ -159,7 +159,7 @@ static void test_dec(int argc, char **argv) local_irq_enable(); local_irq_disable(); /* TCG does not model this correctly */ - report_kfail(true, !got_interrupt, "no interrupt after wrap to positive"); + report_kfail(host_is_tcg, !got_interrupt, "no interrupt after wrap to positive"); got_interrupt = false; handle_exception(0x900, NULL, NULL); diff --git a/powerpc/tm.c b/powerpc/tm.c index 507eaf492..d4f436147 100644 --- a/powerpc/tm.c +++ b/powerpc/tm.c @@ -135,7 +135,7 @@ int main(int argc, char **argv) } /* kvm-unit-tests can limit number of CPUs present */ /* KVM does not report TM in secondary threads in POWER9 */ - report_kfail(true, cpus_with_tm >= nr_cpus_present, + report_kfail(host_is_kvm, cpus_with_tm >= nr_cpus_present, "TM available in all 'ibm,pa-features' properties"); all = argc == 1 || !strcmp(argv[1], "all"); From patchwork Sat May 4 12:28:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1931299 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=BqxSKNKz; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VWncK4PkLz1ybC for ; Sat, 4 May 2024 22:51:45 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=BqxSKNKz; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4VWncK2zlsz3gDV for ; Sat, 4 May 2024 22:51:45 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=BqxSKNKz; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::42b; helo=mail-pf1-x42b.google.com; envelope-from=npiggin@gmail.com; receiver=lists.ozlabs.org) Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4VWn8H45zTz3cg1 for ; Sat, 4 May 2024 22:30:55 +1000 (AEST) Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-6f30f69a958so410902b3a.1 for ; Sat, 04 May 2024 05:30:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714825854; x=1715430654; darn=lists.ozlabs.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=r8yFjHHWiVn05YU2Lfr80oawzBMI5TmP8UkXksKXrkY=; b=BqxSKNKzmn7zoEQWwDbRzbT4BvYXYDwa0De4H2gGbmTKnWUVzswOKil4LhOSrp0gZY 8ObpX9QCDEvcgl72dFwlisTibOpl14x5iT4LHE5qEVGtllvuzbwHh0QwZOotl9SlJCau 5P4V5bAQZz0rHVMp3Kn0vWUntZot3ot8RZVY5E7lT3GppvQF5deNQtMrVeo1+8XyBVW5 ngOxPzrBy7nLwe/IwqwMO+ljOhcInuEgebMxdojNuLnd7biHr/Ip8KoBrviyaplhQ13k 6LJebza3mc9QllQmpHKNpJHZw5FQuNpwIYrLSNpa3Ja135O9zlho2n6yhBWdZBPl1fdD TqIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714825854; x=1715430654; 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=r8yFjHHWiVn05YU2Lfr80oawzBMI5TmP8UkXksKXrkY=; b=N6nV+Un1xsAcSFeuCGM7+GQElqUVd0YQk9B2AIm+oQqV1OVHjqpRhM+Gl9gL1jdoai cDfT1EFE1VBoL2iF9Oe2+06/o0Cqt3Up8PzdcUmbLeDYmbCBHnpeCFd/3tJU+V8dnvVv 8+PD687r2goG18APc3Lz6zZJeSn8mbLm/BvRR4yuI62huc1oaiC6LfW2QnigObBqcHEv g43VkLGjOenSTNrtZn11sDRI3FNTYd8+TSEVUtJ8gZ13dN0UOX+OA+H5z+9Rbz0sQfBr SoQ3/cCZ87X5FHPARJSsHaWHVPQrHsqmIUGL6VRtB8UKsqYAWUFHTtwhSvkhnHVMPLeM LzTA== X-Forwarded-Encrypted: i=1; AJvYcCWi+AQH8DqUWwDtXpI4P3uLQ1PO+g/iSa6iaIhapbm/qWrPscztfazFdivMcCV9U2O7IdlqKBLVnS+K1BkoaJ4SaFPEW4p+vdVcZZqppA== X-Gm-Message-State: AOJu0YynVzzMon8DNjUhMgXtdWKie9S1nhEVtt9putgHCEpC51Pd1j/e H3mDfmuqQVdmDpQHDg9X1XQ4XK0DFG9fqAzqgFVy4e0UX+InfwV+ X-Google-Smtp-Source: AGHT+IFK1UoGsUuy1jTGZj15GLUUMj86a05csarOb+o+flJ9cXlyK08mpPMTmyD9G8IPIczuf3KW8g== X-Received: by 2002:a05:6a20:f3af:b0:1ac:423b:7c7a with SMTP id qr47-20020a056a20f3af00b001ac423b7c7amr5094243pzb.21.1714825853935; Sat, 04 May 2024 05:30:53 -0700 (PDT) Received: from wheely.local0.net (220-245-239-57.tpgi.com.au. [220.245.239.57]) by smtp.gmail.com with ESMTPSA id b16-20020a056a000a9000b006f4473daa38sm3480068pfl.128.2024.05.04.05.30.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 May 2024 05:30:53 -0700 (PDT) From: Nicholas Piggin To: Thomas Huth Subject: [kvm-unit-tests PATCH v9 31/31] powerpc: gitlab CI update Date: Sat, 4 May 2024 22:28:37 +1000 Message-ID: <20240504122841.1177683-32-npiggin@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240504122841.1177683-1-npiggin@gmail.com> References: <20240504122841.1177683-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org, Nicholas Piggin , Andrew Jones Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" This adds testing for the powernv machine, and adds a gitlab-ci test group instead of specifying all tests in .gitlab-ci.yml, and adds a few new tests (smp, atomics) that are known to work in CI. Signed-off-by: Nicholas Piggin --- .gitlab-ci.yml | 30 ++++++++---------------------- powerpc/unittests.cfg | 32 ++++++++++++++++++++++++++------ 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 23bb69e24..31a2a4e34 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -97,17 +97,10 @@ build-ppc64be: - cd build - ../configure --arch=ppc64 --endian=big --cross-prefix=powerpc64-linux-gnu- - make -j2 - - ACCEL=tcg ./run_tests.sh - selftest-setup - selftest-migration - selftest-migration-skip - spapr_hcall - rtas-get-time-of-day - rtas-get-time-of-day-base - rtas-set-time-of-day - emulator - | tee results.txt - - if grep -q FAIL results.txt ; then exit 1 ; fi + - ACCEL=tcg MAX_SMP=8 ./run_tests.sh -g gitlab-ci | tee results.txt + - grep -q PASS results.txt && ! grep -q FAIL results.txt + - ACCEL=tcg MAX_SMP=8 MACHINE=powernv ./run_tests.sh -g gitlab-ci | tee results.txt + - grep -q PASS results.txt && ! grep -q FAIL results.txt build-ppc64le: extends: .intree_template @@ -115,17 +108,10 @@ build-ppc64le: - dnf install -y qemu-system-ppc gcc-powerpc64-linux-gnu nmap-ncat - ./configure --arch=ppc64 --endian=little --cross-prefix=powerpc64-linux-gnu- - make -j2 - - ACCEL=tcg ./run_tests.sh - selftest-setup - selftest-migration - selftest-migration-skip - spapr_hcall - rtas-get-time-of-day - rtas-get-time-of-day-base - rtas-set-time-of-day - emulator - | tee results.txt - - if grep -q FAIL results.txt ; then exit 1 ; fi + - ACCEL=tcg MAX_SMP=8 ./run_tests.sh -g gitlab-ci | tee results.txt + - grep -q PASS results.txt && ! grep -q FAIL results.txt + - ACCEL=tcg MAX_SMP=8 MACHINE=powernv ./run_tests.sh -g gitlab-ci | tee results.txt + - grep -q PASS results.txt && ! grep -q FAIL results.txt # build-riscv32: # Fedora doesn't package a riscv32 compiler for QEMU. Oh, well. diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index d767f5d68..6fae688a8 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -16,17 +16,25 @@ file = selftest.elf smp = 2 extra_params = -m 1g -append 'setup smp=2 mem=1024' -groups = selftest +groups = selftest gitlab-ci [selftest-migration] file = selftest-migration.elf machine = pseries groups = selftest migration +# QEMU 7.0 (Fedora 37) in gitlab CI has known migration bugs in TCG, so +# make a kvm-only version for CI +[selftest-migration-ci] +file = selftest-migration.elf +machine = pseries +groups = nodefault selftest migration gitlab-ci +accel = kvm + [selftest-migration-skip] file = selftest-migration.elf machine = pseries -groups = selftest migration +groups = selftest migration gitlab-ci extra_params = -append "skip" [migration-memory] @@ -37,6 +45,7 @@ groups = migration [spapr_hcall] file = spapr_hcall.elf machine = pseries +groups = gitlab-ci [spapr_vpa] file = spapr_vpa.elf @@ -47,38 +56,43 @@ file = rtas.elf machine = pseries timeout = 5 extra_params = -append "get-time-of-day date=$(date +%s)" -groups = rtas +groups = rtas gitlab-ci [rtas-get-time-of-day-base] file = rtas.elf machine = pseries timeout = 5 extra_params = -rtc base="2006-06-17" -append "get-time-of-day date=$(date --date="2006-06-17 UTC" +%s)" -groups = rtas +groups = rtas gitlab-ci [rtas-set-time-of-day] file = rtas.elf machine = pseries extra_params = -append "set-time-of-day" timeout = 5 -groups = rtas +groups = rtas gitlab-ci [emulator] file = emulator.elf +groups = gitlab-ci +# QEMU 7.0 (Fedora 37) in gitlab CI fails this [interrupts] file = interrupts.elf +# QEMU 7.0 (Fedora 37) in gitlab CI fails this [mmu] file = mmu.elf smp = $MAX_SMP +# QEMU 7.0 (Fedora 37) in gitlab CI fails this [pmu] file = pmu.elf [smp] file = smp.elf smp = 2 +groups = gitlab-ci [smp-smt] file = smp.elf @@ -92,16 +106,19 @@ accel = tcg,thread=single [atomics] file = atomics.elf +groups = gitlab-ci [atomics-migration] file = atomics.elf machine = pseries extra_params = -append "migration -m" -groups = migration +groups = migration gitlab-ci +# QEMU 7.0 (Fedora 37) in gitlab CI fails this [timebase] file = timebase.elf +# QEMU 7.0 (Fedora 37) in gitlab CI fails this [timebase-icount] file = timebase.elf accel = tcg @@ -115,14 +132,17 @@ smp = 2,threads=2 extra_params = -machine cap-htm=on -append "h_cede_tm" groups = h_cede_tm +# QEMU 7.0 (Fedora 37) in gitlab CI fails this [sprs] file = sprs.elf +# QEMU 7.0 (Fedora 37) in gitlab CI fails this [sprs-migration] file = sprs.elf machine = pseries extra_params = -append '-w' groups = migration +# Too costly to run in CI [sieve] file = sieve.elf