From patchwork Fri Mar 17 12:36:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13179024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6EC77C6FD1D for ; Fri, 17 Mar 2023 12:37:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230141AbjCQMhu (ORCPT ); Fri, 17 Mar 2023 08:37:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230162AbjCQMhq (ORCPT ); Fri, 17 Mar 2023 08:37:46 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D598C24134 for ; Fri, 17 Mar 2023 05:37:01 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id j13so4942722pjd.1 for ; Fri, 17 Mar 2023 05:37:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679056599; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=E5PF3sqkFmxXngJQJQHQ0RIO725f9lA9+mqcaHUiq3c=; b=EWpbQwx8Widt3BIdhrfMY5Nauao90WBf7m5d8GzkIFKqrtUuGdiWQETekCYtaXmZLc D5aHQ/9oQEJ70RzfGExhknVfs+KZJIB6Br0QZz/NfIaLTHVa9IPWnQChoYwSHQbLbnRV bBXet7j8G54dojD3aSSaxv2q3H2T1G7xE4oXlTZi/EfDxfkBAXDgCrAVi0pWqrui/KCp JNR6SWAM4b27n3pWPQmuGzqQqjkoMXShUFFfrbf5yJ79tY0/KhmYKqBG5c/PCnYchBBd AMGVxsdx06Mdxd3mOv+qikfYvjj8uufD39LKZMVCDbkQhhY8nvarPCJzYVeYVWA+qFRB wNIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679056599; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=E5PF3sqkFmxXngJQJQHQ0RIO725f9lA9+mqcaHUiq3c=; b=UuL2625LO3KLrPjZJ9hB1C9vPtox0r04fiHSkptrlY4/v5IayZMJevjnUEbzT6v6+j tg/rpttr3fCr/I7c008jjg/5tsA2Pxvub2q5F6QnXolZu7TpxRT9I88E8R6z7V3uu4OD MKq0ZneGCmF3Ce2DZBaJ1kLxk8oyW1lspV2eUnk3YEJm2wtK0LOhzr/jX/pt1yTJenBn DcgeljHm84O3Yq5uaJJysaJxKeoICrLgtz70fUke+VY9LOd6sfPiuhn+/uodzPAUby2R 3Q6ZGSbFMt9zXM542suOHis5i0JU52Jk1cNvF7A4OIIFYVkxt4gD07ZLzmYsgS5xPqyx gVDw== X-Gm-Message-State: AO0yUKVeTkePswnp9obGhmz3eji1gXe0T2qOQLgUg8u9PpOKuOWQKoFR ejYWQU7q3DJ274pD9hh9LzZVFNtnMSk= X-Google-Smtp-Source: AK7set/r/9tsLIqaVCwWrJ+ljYodip91oYy0rj6NR5ublKD7VENvXuoiFu7Ci7CtZmpPRDXWdlYjNg== X-Received: by 2002:a17:902:fa8b:b0:19d:14c:e590 with SMTP id lc11-20020a170902fa8b00b0019d014ce590mr5864922plb.9.1679056599077; Fri, 17 Mar 2023 05:36:39 -0700 (PDT) Received: from bobo.ozlabs.ibm.com (121-44-69-75.tpgi.com.au. [121.44.69.75]) by smtp.gmail.com with ESMTPSA id u4-20020a170902b28400b001a19d4592e1sm1430990plr.282.2023.03.17.05.36.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 05:36:38 -0700 (PDT) From: Nicholas Piggin To: kvm@vger.kernel.org Cc: Nicholas Piggin , linuxppc-dev@lists.ozlabs.org, Laurent Vivier , Thomas Huth Subject: [kvm-unit-tests PATCH 1/7] MAINTAINERS: Update powerpc list Date: Fri, 17 Mar 2023 22:36:08 +1000 Message-Id: <20230317123614.3687163-1-npiggin@gmail.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org KVM development on powerpc has moved to the Linux on Power mailing list, as per linux.git commit 19b27f37ca97d ("MAINTAINERS: Update powerpc KVM entry"). Signed-off-by: Nicholas Piggin --- MAINTAINERS | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MAINTAINERS b/MAINTAINERS index 649de50..b545a45 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -79,7 +79,7 @@ M: Laurent Vivier M: Thomas Huth S: Maintained L: kvm@vger.kernel.org -L: kvm-ppc@vger.kernel.org +L: linuxppc-dev@lists.ozlabs.org F: powerpc/ F: lib/powerpc/ F: lib/ppc64/ From patchwork Fri Mar 17 12:36:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13179023 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 96F52C7618B for ; Fri, 17 Mar 2023 12:37:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229658AbjCQMht (ORCPT ); Fri, 17 Mar 2023 08:37:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230163AbjCQMhr (ORCPT ); Fri, 17 Mar 2023 08:37:47 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BD0293C7 for ; Fri, 17 Mar 2023 05:37:02 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id ix20so5148274plb.3 for ; Fri, 17 Mar 2023 05:37:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679056602; 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=IGrixfxvALez5iC7y5jSzp88ksEIk5PU6pEUFuV6u+I=; b=l3n0YBijw6wscEwhxo3xJinQJ9wZs0xJPB12moudZQtIPDNfb3Lv4Z8KHFGw08/5Ca 6x3tAPZlR+UMqzZ16kCWQfSzAS75RQ+netKObgq+xJ7PMFHyLvt8meVOr4oFC65I+Vby XJzNQg2qOb6ZxLwwgpdtt81g23o8l13KRwt0CNhJtkaKSRGTQwdvTZo6gGNVyfAON4fl gedyafRgeyP+807zC6n/GGQIwlsxN48ru5w1UR34TCjf0kYziCL2cQViUC2hsxI0K4E2 0ZepkhwsyYEbD1H2faAGJnbif4po73rMfL8MJ3ngYIjFRYgzw8VpdfMBM2owi2QrDQSx pOlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679056602; 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=IGrixfxvALez5iC7y5jSzp88ksEIk5PU6pEUFuV6u+I=; b=y3EvtYA5T3fAFlgpNclueUrYGlsogso1ckvItxN7U+On2A0K5JgnKtGGqW6/4BW3oo +5p4x1a3aTbIynMil8pPMQktObqphsBtBHFzJbivdT0CGs9IJdENfFPTR/s9C5DDigFe YTMxoA7xyqaY/nyjN+pHZcCevZY0kkno+WMWFXXHJ3ks8mG+5wmEnnpLDhXQnaLTk4md txSuwTKdqU67O7bukxB9PwvNa9Ixrunc0YtiCXzaSAIwKsECbOQXTO0Epy9wiSZWxheL IiaEMpZvjzSEwmGIaAPUPrc6W8ga0gltMxCUCDhkcb7xMbnSh7poVTo2c6uype5KQyo3 PHAw== X-Gm-Message-State: AO0yUKUDqBxgjsCS9r9fMRJMacaCVAk/yyd9fwh3yZNKfInBKBtWAPwY mH/6zmdF64/a/rgAO74yQ+yJv4LHdHM= X-Google-Smtp-Source: AK7set8DOmchCV0AGBT2BTU5yIrD1m6yPwDMqTK5iiBDwDMPVSD6dfoqpYDRoYdj6kq34GTSj1v2Fg== X-Received: by 2002:a17:903:234c:b0:19e:8bfe:7d79 with SMTP id c12-20020a170903234c00b0019e8bfe7d79mr8892343plh.1.1679056602184; Fri, 17 Mar 2023 05:36:42 -0700 (PDT) Received: from bobo.ozlabs.ibm.com (121-44-69-75.tpgi.com.au. [121.44.69.75]) by smtp.gmail.com with ESMTPSA id u4-20020a170902b28400b001a19d4592e1sm1430990plr.282.2023.03.17.05.36.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 05:36:41 -0700 (PDT) From: Nicholas Piggin To: kvm@vger.kernel.org Cc: Nicholas Piggin , linuxppc-dev@lists.ozlabs.org, Laurent Vivier , Thomas Huth Subject: [kvm-unit-tests PATCH 2/7] powerpc: add local variant of SPR test Date: Fri, 17 Mar 2023 22:36:09 +1000 Message-Id: <20230317123614.3687163-2-npiggin@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230317123614.3687163-1-npiggin@gmail.com> References: <20230317123614.3687163-1-npiggin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This adds the non-migration variant of the SPR test to the matrix, which can be simpler to run and debug. Signed-off-by: Nicholas Piggin Reviewed-by: Thomas Huth --- powerpc/unittests.cfg | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/powerpc/unittests.cfg b/powerpc/unittests.cfg index 1e74948..3e41598 100644 --- a/powerpc/unittests.cfg +++ b/powerpc/unittests.cfg @@ -68,5 +68,9 @@ groups = h_cede_tm [sprs] file = sprs.elf +groups = sprs + +[sprs-migration] +file = sprs.elf extra_params = -append '-w' groups = migration From patchwork Fri Mar 17 12:36:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13179027 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86780C6FD1D for ; Fri, 17 Mar 2023 12:37:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230161AbjCQMhy (ORCPT ); Fri, 17 Mar 2023 08:37:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230248AbjCQMhs (ORCPT ); Fri, 17 Mar 2023 08:37:48 -0400 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBCB69271A for ; Fri, 17 Mar 2023 05:37:05 -0700 (PDT) Received: by mail-pj1-x102d.google.com with SMTP id p3-20020a17090a74c300b0023f69bc7a68so562491pjl.4 for ; Fri, 17 Mar 2023 05:37:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679056605; 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=+tTjZq7Z3XuFiNFhzKWYEU/rRE2o6iWMeH5Xuljn3+Q=; b=Ne3UNZCLGAwWcmVqOT78Mg3hkiCk35vhbBgIy3mt/mCTFBQbIjkWDwYjTM/E26b/bO 3ZVXvs/cf5aHpPqo/VGl9PN3m6ByXiMEjHZK362TZ8jDjHdcScuF3KexyQAiHWB/mMmu LytVw57nXtwqsxm5U7NxznXJ9w/pULIdsolov9xS76tPDhr/rfXDoXNTtsexbczWUxFi V7Nyz7RaUWvI1tG2sawf/cSvkCtvYq4fqCyE+ImZ7ffb4XyKPt58jAQ9bc0ilWh/cNsu lCc/mYiQKk9Olz5N8mU2P7zz6T3W9t7QWjg94oyFHqQ1yfNz7UJoAyrvpRBCNLV/yO/a r+vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679056605; 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=+tTjZq7Z3XuFiNFhzKWYEU/rRE2o6iWMeH5Xuljn3+Q=; b=r0XTtWZvoCyd04aQCIkTZySxAs4cJ/++1yS1yU7tToQmD5xPiIMNm8JkhaCu97eu/t geajxhfqAYMucT5GHVoxryoixaDMWNk59r8PeM/twuZ78O66lYYxfwah+WYfBwGGyT/3 YmsyPjm7PwdWaislRFjgfRaCJ0BcnYArO3CRVzCR7QfQjo9piJ5Uqt2wvF1qk9t+Lsu0 Tnu4nT6JGVhxE8r5jAmsgTyyZrNuEIhdx5e9/gvJE1iknISr8ToqTeu46QiMlgmlLRHb rdhu/OWoUKC0bEHtTGs70B853v1GlYszpwp7rkseB7GaSBOJ7b7Jn1aFL9g94lMOJWi+ 8A2g== X-Gm-Message-State: AO0yUKXq7LcHU87Ks4YjbuG/K36RH/YqZDHjKjO4CHDOuT7/GctgummJ 17tXfnHr6bsbn+H7XdNMW2+GjQBjADQ= X-Google-Smtp-Source: AK7set9TnyUdJAVUv9lK7slr27weM+mbnOsdUTUdrBpOI2GcH7cVe+u5jdT2N2vTyTuWaS/0bNGHyw== X-Received: by 2002:a17:90b:38d1:b0:234:b03:5a70 with SMTP id nn17-20020a17090b38d100b002340b035a70mr8134937pjb.35.1679056605187; Fri, 17 Mar 2023 05:36:45 -0700 (PDT) Received: from bobo.ozlabs.ibm.com (121-44-69-75.tpgi.com.au. [121.44.69.75]) by smtp.gmail.com with ESMTPSA id u4-20020a170902b28400b001a19d4592e1sm1430990plr.282.2023.03.17.05.36.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 05:36:44 -0700 (PDT) From: Nicholas Piggin To: kvm@vger.kernel.org Cc: Nicholas Piggin , linuxppc-dev@lists.ozlabs.org, Laurent Vivier , Thomas Huth Subject: [kvm-unit-tests PATCH 3/7] powerpc: abstract H_CEDE calls into a sleep() function Date: Fri, 17 Mar 2023 22:36:10 +1000 Message-Id: <20230317123614.3687163-3-npiggin@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230317123614.3687163-1-npiggin@gmail.com> References: <20230317123614.3687163-1-npiggin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This consolidates several implementations, and it no longer leaves MSR[EE] enabled after the decrementer interrupt is handled, but rather disables it on return. The handler no longer allows a continuous ticking, but rather dec has to be re-armed and EE re-enabled (e.g., via H_CEDE hcall) each time. Signed-off-by: Nicholas Piggin --- lib/powerpc/asm/handlers.h | 2 +- lib/powerpc/asm/ppc_asm.h | 1 + lib/powerpc/asm/processor.h | 1 + lib/powerpc/handlers.c | 10 ++++------ lib/powerpc/processor.c | 31 +++++++++++++++++++++++++++++++ powerpc/sprs.c | 6 +----- powerpc/tm.c | 20 +------------------- 7 files changed, 40 insertions(+), 31 deletions(-) diff --git a/lib/powerpc/asm/handlers.h b/lib/powerpc/asm/handlers.h index 64ba727..e4a0cd4 100644 --- a/lib/powerpc/asm/handlers.h +++ b/lib/powerpc/asm/handlers.h @@ -3,6 +3,6 @@ #include -void dec_except_handler(struct pt_regs *regs, void *data); +void dec_handler_oneshot(struct pt_regs *regs, void *data); #endif /* _ASMPOWERPC_HANDLERS_H_ */ diff --git a/lib/powerpc/asm/ppc_asm.h b/lib/powerpc/asm/ppc_asm.h index 1b85f6b..6299ff5 100644 --- a/lib/powerpc/asm/ppc_asm.h +++ b/lib/powerpc/asm/ppc_asm.h @@ -36,6 +36,7 @@ #endif /* __BYTE_ORDER__ */ /* Machine State Register definitions: */ +#define MSR_EE_BIT 15 /* External Interrupts Enable */ #define MSR_SF_BIT 63 /* 64-bit mode */ #endif /* _ASMPOWERPC_PPC_ASM_H */ diff --git a/lib/powerpc/asm/processor.h b/lib/powerpc/asm/processor.h index ac001e1..1467f2c 100644 --- a/lib/powerpc/asm/processor.h +++ b/lib/powerpc/asm/processor.h @@ -20,6 +20,7 @@ static inline uint64_t get_tb(void) extern void delay(uint64_t cycles); extern void udelay(uint64_t us); +extern void sleep(uint64_t cycles); static inline void mdelay(uint64_t ms) { diff --git a/lib/powerpc/handlers.c b/lib/powerpc/handlers.c index c8721e0..296f14f 100644 --- a/lib/powerpc/handlers.c +++ b/lib/powerpc/handlers.c @@ -9,15 +9,13 @@ #include #include #include +#include /* * Generic handler for decrementer exceptions (0x900) - * Just reset the decrementer back to the value specified when registering the - * handler + * Return with MSR[EE] disabled. */ -void dec_except_handler(struct pt_regs *regs __unused, void *data) +void dec_handler_oneshot(struct pt_regs *regs, void *data) { - uint64_t dec = *((uint64_t *) data); - - asm volatile ("mtdec %0" : : "r" (dec)); + regs->msr &= ~(1UL << MSR_EE_BIT); } diff --git a/lib/powerpc/processor.c b/lib/powerpc/processor.c index ec85b9d..f1fb50f 100644 --- a/lib/powerpc/processor.c +++ b/lib/powerpc/processor.c @@ -10,6 +10,8 @@ #include #include #include +#include +#include static struct { void (*func)(struct pt_regs *, void *data); @@ -54,3 +56,32 @@ void udelay(uint64_t us) { delay((us * tb_hz) / 1000000); } + +void sleep(uint64_t cycles) +{ + uint64_t start, end, now; + + start = now = get_tb(); + end = start + cycles; + + while (end > now) { + uint64_t left = end - now; + + /* Could support large decrementer */ + if (left > 0x7fffffff) + left = 0x7fffffff; + + asm volatile ("mtdec %0" : : "r" (left)); + handle_exception(0x900, &dec_handler_oneshot, NULL); + if (hcall(H_CEDE) != H_SUCCESS) { + printf("H_CEDE failed\n"); + abort(); + } + handle_exception(0x900, NULL, NULL); + + if (left < 0x7fffffff) + break; + + now = get_tb(); + } +} diff --git a/powerpc/sprs.c b/powerpc/sprs.c index 5cc1cd1..161a6ba 100644 --- a/powerpc/sprs.c +++ b/powerpc/sprs.c @@ -254,7 +254,6 @@ int main(int argc, char **argv) 0x1234567890ABCDEFULL, 0xFEDCBA0987654321ULL, -1ULL, }; - static uint64_t decr = 0x7FFFFFFF; /* Max value */ for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-w")) { @@ -288,10 +287,7 @@ int main(int argc, char **argv) if (pause) { migrate_once(); } else { - puts("Sleeping...\n"); - handle_exception(0x900, &dec_except_handler, &decr); - asm volatile ("mtdec %0" : : "r" (0x3FFFFFFF)); - hcall(H_CEDE); + sleep(0x10000000); } get_sprs(after); diff --git a/powerpc/tm.c b/powerpc/tm.c index 65cacdf..61bacf4 100644 --- a/powerpc/tm.c +++ b/powerpc/tm.c @@ -48,17 +48,6 @@ static int count_cpus_with_tm(void) return available; } -static int h_cede(void) -{ - register uint64_t r3 asm("r3") = H_CEDE; - - asm volatile ("sc 1" : "+r"(r3) : - : "r0", "r4", "r5", "r6", "r7", "r8", "r9", - "r10", "r11", "r12", "xer", "ctr", "cc"); - - return r3; -} - /* * Enable transactional memory * Returns: FALSE - Failure @@ -95,14 +84,10 @@ static bool enable_tm(void) static void test_h_cede_tm(int argc, char **argv) { int i; - static uint64_t decr = 0x3FFFFF; /* ~10ms */ if (argc > 2) report_abort("Unsupported argument: '%s'", argv[2]); - handle_exception(0x900, &dec_except_handler, &decr); - asm volatile ("mtdec %0" : : "r" (decr)); - if (!start_all_cpus(halt, 0)) report_abort("Failed to start secondary cpus"); @@ -120,10 +105,7 @@ static void test_h_cede_tm(int argc, char **argv) "bf 2,1b" : : : "cr0"); for (i = 0; i < 500; i++) { - uint64_t rval = h_cede(); - - if (rval != H_SUCCESS) - break; + sleep(0x3FFFFF); /* ~10ms */ mdelay(5); } From patchwork Fri Mar 17 12:36:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13179025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A568C7618B for ; Fri, 17 Mar 2023 12:37:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229729AbjCQMhv (ORCPT ); Fri, 17 Mar 2023 08:37:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230244AbjCQMhr (ORCPT ); Fri, 17 Mar 2023 08:37:47 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28A141E9C6 for ; Fri, 17 Mar 2023 05:37:06 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id u5so5135666plq.7 for ; Fri, 17 Mar 2023 05:37:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679056608; 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=BgrFyKL0mkQqzfd3lw9FAzsbWeu2gcn/ROX5EFuiTaU=; b=Qfpi+iuXM1w/WHrL+cK8ZdUQoGQX8+OPSP5cEF0YEEKWuMjtYcnnHG+G0UvJ4++W5r xvReBfEicKE/neiF01ppuDvK69IVL65w6AGVUYXilEl1mCUNxoo8L1qhywP2hGu4tufq TUvabdh+ryfldzUxWPY7bh5IchpNjjp8yLcRW9hHHh3rYSrJqr05ooMmHL4k8d/q9Hro 7WN03HM5houo1F0eG10L6LnW33u2ss8KpFTthTn4TxneRqmbbs+Rm0x6HsEYtHajmU+7 TthDQTWxKs7RHSm9mCl4y5MMEyJQl5P+bRfbnO0mq2lVhOR4ZIj0EDSNcfNCpXFoOuQh SQMw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679056608; 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=BgrFyKL0mkQqzfd3lw9FAzsbWeu2gcn/ROX5EFuiTaU=; b=A/7yHym2zk0WJnlmLFoYzd5tOYz1usXqoGbTorDJxXbxqTfPKM/xWrt44DGriAmcyr aRUXcjwiCycYGpBXky5/3AH0knevAbveDD2B18lqUcL2q9S3/Dta1FYjObH/yUzYDIkS 9wufUisOE+6HmHRlauwyhSfSiNESsnOHyKlwOCyvfcX0pOXT04RuToWsa/rPdyuOnH+w hlRVHMwoHJsXVJME/tvtegpab9jGFjCVOIVh34o70pkcQuc+8HpVv3GFzaNMAi++sBXA In9YTezPoerC/i3dx/kB1pOQ3KGrhi1M2lr/ulgUCKNoYGl8BOAwkT/AZYzfoFiv2chu lxAg== X-Gm-Message-State: AO0yUKXs/WNVJqoTPXHfKsn9XMsOmh7ZwDlsuTs1HRdF8fwhyCXWEuss NU4WAsdMIpxC+yICBPtfmMhFqhzuNrQ= X-Google-Smtp-Source: AK7set8VVnF/eahtQSwmgDCRAgLIrEC12yNJlSdMxmpFXMYod+HltJkz8Hu+U2tHN+Jo09C4DTe92w== X-Received: by 2002:a17:902:cecd:b0:19e:9f97:f427 with SMTP id d13-20020a170902cecd00b0019e9f97f427mr8445311plg.10.1679056608399; Fri, 17 Mar 2023 05:36:48 -0700 (PDT) Received: from bobo.ozlabs.ibm.com (121-44-69-75.tpgi.com.au. [121.44.69.75]) by smtp.gmail.com with ESMTPSA id u4-20020a170902b28400b001a19d4592e1sm1430990plr.282.2023.03.17.05.36.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 05:36:47 -0700 (PDT) From: Nicholas Piggin To: kvm@vger.kernel.org Cc: Nicholas Piggin , linuxppc-dev@lists.ozlabs.org, Laurent Vivier , Thomas Huth Subject: [kvm-unit-tests PATCH 4/7] powerpc: Add ISA v3.1 (POWER10) support to SPR test Date: Fri, 17 Mar 2023 22:36:11 +1000 Message-Id: <20230317123614.3687163-4-npiggin@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230317123614.3687163-1-npiggin@gmail.com> References: <20230317123614.3687163-1-npiggin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is a very basic detection that does not include all new SPRs. Signed-off-by: Nicholas Piggin Reviewed-by: Thomas Huth --- powerpc/sprs.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/powerpc/sprs.c b/powerpc/sprs.c index 161a6ba..45f77a5 100644 --- a/powerpc/sprs.c +++ b/powerpc/sprs.c @@ -117,6 +117,15 @@ static void set_sprs_book3s_300(uint64_t val) mtspr(823, val); /* PSSCR */ } +/* 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 */ +} + static void set_sprs(uint64_t val) { uint32_t pvr = mfspr(287); /* Processor Version Register */ @@ -137,6 +146,9 @@ static void set_sprs(uint64_t val) case 0x4e: /* POWER9 */ set_sprs_book3s_300(val); break; + case 0x80: /* POWER10 */ + set_sprs_book3s_31(val); + break; default: puts("Warning: Unknown processor version!\n"); } @@ -220,6 +232,13 @@ static void get_sprs_book3s_300(uint64_t *v) v[823] = mfspr(823); /* PSSCR */ } +static void get_sprs_book3s_31(uint64_t *v) +{ + get_sprs_book3s_207(v); + v[48] = mfspr(48); /* PIDR */ + v[823] = mfspr(823); /* PSSCR */ +} + static void get_sprs(uint64_t *v) { uint32_t pvr = mfspr(287); /* Processor Version Register */ @@ -240,6 +259,9 @@ static void get_sprs(uint64_t *v) case 0x4e: /* POWER9 */ get_sprs_book3s_300(v); break; + case 0x80: /* POWER10 */ + get_sprs_book3s_31(v); + break; } } From patchwork Fri Mar 17 12:36:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13179026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7CC57C74A5B for ; Fri, 17 Mar 2023 12:37:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230244AbjCQMhx (ORCPT ); Fri, 17 Mar 2023 08:37:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230135AbjCQMhs (ORCPT ); Fri, 17 Mar 2023 08:37:48 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70BC8763E5 for ; Fri, 17 Mar 2023 05:37:06 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id bc12so4535913plb.0 for ; Fri, 17 Mar 2023 05:37:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679056611; 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=/AACUrmAMGo0o1wCmGEVGbVl+4mMC8WBmeWeWuWQJ0Y=; b=mjFfOlZ8F96WpI3hvzMSdK12GHigb25umCbjPjzvfP9aFho4vWtGzUTLajEtXv5mwq yYCQRQHwr9TsxEMboiy9jv8SEsK+t7kRIZRfNX+qLDJP7AmjarKLC9AsknNFKVI3yFZb FbEjI7XgwZWSsnHqQkEZaKmvS4S7mwJNmQf3lmnDt7ccorG7PDyg7820+spFZs7sEcWO dUsgHOWTMDNuSiXIWQR3dSeTctH23E2B+BKdMOVqJRvGMVVHUeXBZ8wugma8/dE0bL80 z4XoaE58R2UXdeHrTd6XdO9SZQ3xEHQeta3aULQux26cKJoB5+vl59txr6rxVFgB9Pqq 3XhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679056611; 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=/AACUrmAMGo0o1wCmGEVGbVl+4mMC8WBmeWeWuWQJ0Y=; b=HD6WI3jGfCEBXZJtU4wbV6Hm7dpXTYGExXQJz/Pj2HtqRRPrr5uV2wFR9IFUDli9p+ wkOA9Ydk8AyqtgM/3eV1kfjTpZ3jLfLa+T2PecYdC1KyU02pAjvnMfgSZohoi9s6uv6y MJx/jkQr6YCavTW6cg29Vh3nFeVR6q8l55HO2y1mtmn3dLXo3gMnAU47LmRObyqgo8Ee Ky7W1nvnChCxeSGagdOJ2MeOEOCsg6KuU5wjhrB14WTCQUOkcZ+2XrdbLXn5lenZLHy1 6uwHZYBL1mAabzh9NDlxFL1J9LYNIGy4TH14Zl09OhG8zTXkFqT/nVdVCKBqxTxE2T0P B7vQ== X-Gm-Message-State: AO0yUKUXF56BdGpZxCkFlBaLe/hHF7gz0DsD/ExEQZJj/wpJ/Z6A1lZV sg6CNpZNUYyd1/t2+ewmWYRCbkrJ6/o= X-Google-Smtp-Source: AK7set+sRU0UVPfRE2oFtxnsyr487NYkwsRVS7PImembOt069bz92S4sX2mu13ois20T94SlQ5ZbRw== X-Received: by 2002:a17:903:186:b0:19e:6d83:8277 with SMTP id z6-20020a170903018600b0019e6d838277mr8450576plg.51.1679056611528; Fri, 17 Mar 2023 05:36:51 -0700 (PDT) Received: from bobo.ozlabs.ibm.com (121-44-69-75.tpgi.com.au. [121.44.69.75]) by smtp.gmail.com with ESMTPSA id u4-20020a170902b28400b001a19d4592e1sm1430990plr.282.2023.03.17.05.36.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 05:36:51 -0700 (PDT) From: Nicholas Piggin To: kvm@vger.kernel.org Cc: Nicholas Piggin , linuxppc-dev@lists.ozlabs.org, Laurent Vivier , Thomas Huth Subject: [kvm-unit-tests PATCH 5/7] powerpc: Indirect SPR accessor functions Date: Fri, 17 Mar 2023 22:36:12 +1000 Message-Id: <20230317123614.3687163-5-npiggin@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230317123614.3687163-1-npiggin@gmail.com> References: <20230317123614.3687163-1-npiggin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Make overly-clever SPR accessor functions that allow a non-constant SPR number to be specified. This will be used to restructure test in the next change. Signed-off-by: Nicholas Piggin --- powerpc/sprs.c | 63 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 9 deletions(-) diff --git a/powerpc/sprs.c b/powerpc/sprs.c index 45f77a5..b633ea8 100644 --- a/powerpc/sprs.c +++ b/powerpc/sprs.c @@ -28,21 +28,66 @@ #include #include -#define mfspr(nr) ({ \ - uint64_t ret; \ - asm volatile("mfspr %0,%1" : "=r"(ret) : "i"(nr)); \ - ret; \ -}) +/* "Indirect" mfspr/mtspr which accept a non-constant spr number */ +static uint64_t mfspr(unsigned spr) +{ + 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; +} -#define mtspr(nr, val) \ - asm volatile("mtspr %0,%1" : : "i"(nr), "r"(val)) +static void mtspr(unsigned spr, uint64_t val) +{ + 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"); +} uint64_t before[1024], after[1024]; /* Common SPRs for all PowerPC CPUs */ static void set_sprs_common(uint64_t val) { - mtspr(9, val); /* CTR */ + // mtspr(9, val); /* CTR */ /* Used by mfspr/mtspr */ // mtspr(273, val); /* SPRG1 */ /* Used by our exception handler */ mtspr(274, val); /* SPRG2 */ mtspr(275, val); /* SPRG3 */ @@ -156,7 +201,7 @@ static void set_sprs(uint64_t val) static void get_sprs_common(uint64_t *v) { - v[9] = mfspr(9); /* CTR */ + v[9] = mfspr(9); /* CTR */ /* Used by mfspr/mtspr */ // v[273] = mfspr(273); /* SPRG1 */ /* Used by our exception handler */ v[274] = mfspr(274); /* SPRG2 */ v[275] = mfspr(275); /* SPRG3 */ From patchwork Fri Mar 17 12:36:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13179028 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DC99C76195 for ; Fri, 17 Mar 2023 12:37:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230202AbjCQMhz (ORCPT ); Fri, 17 Mar 2023 08:37:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230133AbjCQMhu (ORCPT ); Fri, 17 Mar 2023 08:37:50 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0034C6C6AB for ; Fri, 17 Mar 2023 05:37:06 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id qe8-20020a17090b4f8800b0023f07253a2cso5045195pjb.3 for ; Fri, 17 Mar 2023 05:37:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679056615; 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=q5GaYgdhktF8TYNBWSQyuRZrMerFrhgeB6K29Y/bo4c=; b=NfGn0gSVQIIK7W/MvVQvB0ERfmSTuqBskqiWyfFiuGnSQfeK/xvnUOCul1CBSDKRyl klzj3bbuufpgfpm6Hs9G7jk5lOjIO/fOuvxns4rnITqIbCYhgXXs2p9M5dYzcZqOF+9t XKStNdpx14/jJfqEstq+luT1nFHPTdJwcQlVRrpGIWyO15Khn2LHz0zepyQOtieZ2n0J CN74IvNFPo3LksPAgcUo0znFuXeHLDOGxijw8zwlh99VJCkdafDCDkWnhAeMbUKD5HCL Du7Fl1FiF08v304U3Pp9PqhDKXK/pnWVw4fr6srsT20IJ1ctQfcIPLrsXQF6bJjywIA1 /hKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679056615; 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=q5GaYgdhktF8TYNBWSQyuRZrMerFrhgeB6K29Y/bo4c=; b=rokC2HjHAWMn0nDNHDshlLPP+7Thk0u+QLaJc1iaC51dbDgRVvGsuEmhzdBe0BJzlV 5IKfdWG0gtoQD0TbG6Tal7mKXjzyGRw7hNSbI6d5Vn++AVqISYRM0KMY9fceccoE8eUV 3Qq0rHBq6r83z+fxuLj6XL/0hlNi8CmbLBy1kS5N9F1JBVmmneBo6nZ1JJh1MbJZOXF+ J6Gi3Cq0+wt9E+K9sUIAKJcyWcS3lhThygAEmgv6V5k7iYDtwyrzQvAX4amsgVeTW1xT ZYiW6CbOSWri0fIYXmKAcsCnpMJvN5LHTA7GxVGmVf/6Goisqq6znbZE6z/ev0StRJCe Ua5w== X-Gm-Message-State: AO0yUKXoJAlRlXYypICm7ZMazPFsK21acnaAwaiOoVmmC5SvQrwoVGAa EDHI8k1YaLWo5SwE+93WX0au07Ayyvg= X-Google-Smtp-Source: AK7set/7hpdUMBIg9Dlq45A7buY5yeTNA4aE2OXrHG/ErUrAhwf4QzdXJ0aU4Xz+wBIkJ5jrrjD3Bw== X-Received: by 2002:a17:90b:1d06:b0:230:af67:b847 with SMTP id on6-20020a17090b1d0600b00230af67b847mr8309543pjb.31.1679056614724; Fri, 17 Mar 2023 05:36:54 -0700 (PDT) Received: from bobo.ozlabs.ibm.com (121-44-69-75.tpgi.com.au. [121.44.69.75]) by smtp.gmail.com with ESMTPSA id u4-20020a170902b28400b001a19d4592e1sm1430990plr.282.2023.03.17.05.36.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 05:36:54 -0700 (PDT) From: Nicholas Piggin To: kvm@vger.kernel.org Cc: Nicholas Piggin , linuxppc-dev@lists.ozlabs.org, Laurent Vivier , Thomas Huth Subject: [kvm-unit-tests PATCH 6/7] powerpc/sprs: Specify SPRs with data rather than code Date: Fri, 17 Mar 2023 22:36:13 +1000 Message-Id: <20230317123614.3687163-6-npiggin@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230317123614.3687163-1-npiggin@gmail.com> References: <20230317123614.3687163-1-npiggin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org 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. Signed-off-by: Nicholas Piggin --- This ended up a little over-engineered perhaps, but there are lots of SPRs, lots of access types, lots of changes between processor and ISA versions, and lots of places they are implemented and used, so lots of room for mistakes. There is not a good system in place to easily see that userspace, supervisor, etc., switches perform all the right SPR context switching so this is a nice test case to have. The sprs test quickly caught a few QEMU TCG SPR bugs which really demonstrates its value and motivated me to improve the SPR coverage a little. Thanks, Nick --- powerpc/sprs.c | 586 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 391 insertions(+), 195 deletions(-) diff --git a/powerpc/sprs.c b/powerpc/sprs.c index b633ea8..257903a 100644 --- a/powerpc/sprs.c +++ b/powerpc/sprs.c @@ -82,231 +82,404 @@ static void mtspr(unsigned spr, uint64_t val) : "lr", "ctr", "xer"); } -uint64_t before[1024], after[1024]; +static uint64_t before[1024], after[1024]; -/* Common SPRs for all PowerPC CPUs */ -static void set_sprs_common(uint64_t val) -{ - // mtspr(9, val); /* CTR */ /* Used by mfspr/mtspr */ - // mtspr(273, val); /* SPRG1 */ /* Used by our exception handler */ - mtspr(274, val); /* SPRG2 */ - mtspr(275, val); /* SPRG3 */ -} +#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, }, /* 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, }, /* Int stack */ +[273] = {"SPRG1", 64, OS_RW, SPR_HARNESS, }, /* 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 void set_sprs_book3s_201(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 */ -} +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 */ +[268] = {"TB", 64, RO, }, +[269] = {"TBU", 32, RO, }, +[284] = {"TBL", 32, HV_WO, }, +[285] = {"TBU", 32, HV_WO, }, +[310] = {"HDEC", 32, HV_RW, }, +[1013]= {"DABR", 64, HV_RW | OS_RO, }, +[1023]= {"PIR", 32, OS_RO, }, +}; + +static const struct spr sprs_970_pmu[1024] = { +/* POWER4+ PMU, should find PPC970 and confirm */ +[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, }, +}; + +static const struct spr sprs_tm[1024] = { +[128] = {"TFHAR", 64, RW, }, +[129] = {"TFIAR", 64, RW, }, +[130] = {"TEXASR", 64, RW, }, +[131] = {"TEXASRU", 32, RW, }, +}; /* 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, }, +}; /* 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, }, +[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, }, +[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 POWER10 User Manual */ +static const struct spr sprs_power10[1024] = { +[276] = {"SPRC", 64, HV_RW, }, +[266] = {"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] = {"SEIR2", 64, RO, }, +[737] = {"SEIR3", 64, RO, }, +[738] = {"MMCR3", 64, RO, }, +[752] = {"SEIR2", 64, OS_RW, }, +[753] = {"SEIR3", 64, OS_RW, }, +[754] = {"MMCR3", 64, OS_RW, }, +}; + +static struct spr sprs[1024]; + +static void setup_sprs(void) { uint32_t pvr = mfspr(287); /* Processor Version Register */ + int i; - set_sprs_common(val); + for (i = 0; i < 1024; i++) { + if (sprs_common[i].name) { + memcpy(&sprs[i], &sprs_common[i], sizeof(struct spr)); + } + } switch (pvr >> 16) { case 0x39: /* PPC970 */ case 0x3C: /* PPC970FX */ case 0x44: /* PPC970MP */ - set_sprs_book3s_201(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_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 0x4b: /* POWER8E */ case 0x4c: /* POWER8NVL */ case 0x4d: /* 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 0x4e: /* 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_power_common_pmu[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_power_common_pmu[i], sizeof(struct spr)); + } + } break; - case 0x80: /* POWER10 */ - set_sprs_book3s_31(val); + + case 0x80: /* POWER10 */ + 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_power10[i].name) { + assert(!sprs[i].name); + memcpy(&sprs[i], &sprs_power10[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 */ /* Used by mfspr/mtspr */ - // 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); + } } } @@ -343,7 +516,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)); @@ -355,16 +530,37 @@ int main(int argc, char **argv) migrate_once(); } else { sleep(0x10000000); + + /* Taking a dec updates SRR0, SRR1, SPRG1, so don't fail. */ + sprs[26].type |= SPR_ASYNC; + sprs[27].type |= SPR_ASYNC; + sprs[273].type |= SPR_ASYNC; } 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_ASYNC) && (before[i] != after[i])) + pass = false; + + if (sprs[i].width == 32) + report(pass, "%-10s(%4d):\t 0x%010lx <==> 0x%010lx", + sprs[i].name, i, + before[i], after[i]); + else + report(pass, "%-10s(%4d):\t0x%018lx <==> 0x%018lx", + sprs[i].name, i, + before[i], after[i]); } return report_summary(); From patchwork Fri Mar 17 12:36:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 13179029 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46DFAC6FD1D for ; Fri, 17 Mar 2023 12:37:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229760AbjCQMh6 (ORCPT ); Fri, 17 Mar 2023 08:37:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36348 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230252AbjCQMh5 (ORCPT ); Fri, 17 Mar 2023 08:37:57 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2F1AF72032 for ; Fri, 17 Mar 2023 05:37:16 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id ix20so5148916plb.3 for ; Fri, 17 Mar 2023 05:37:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679056618; 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=rnlFwsBqmpRmF2UIJI7+HJpv77h1Cu+aYPp5qdoB/DM=; b=CTc43NnKkrb5KMC7HsrEXEZLG76a3Do0la8POD5xoQc29NzAp8AQhREaStOZvOdPL8 6DVI+jUid0Mdggs3W2OAr1ED3OLSaad8fUI5qBVICvI3Cv58c/mVBXxS0b5Utod5jnKO cKCYI7zBkJqY+JKSc/5WH23mAPLkSM7QO/5SRQNq7Pfu7cXlO6YYbdyPniGpz11skQ7h zRoxl/0+5JXUKbjA3GrBcCoXdqzGLNCcAUNqrpLZnPK74XxYDCoCkWiXJlRIgq4foeBW IMfpOdRrijmNR+W6vOT434BIzVmDPyZq3tgbHvYxO6PdEWkv8dSZL7uF7aKbrwnSo9iw TKjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679056618; 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=rnlFwsBqmpRmF2UIJI7+HJpv77h1Cu+aYPp5qdoB/DM=; b=YA5vVQ6239oVWN7WpQHkcAtmwOtLDgBK4fZyL+tCA0QZQl5SusZmFlmoaV/t1wsWjG YU3xoufTyRkksaxdrXHRN26BOepPgXyPscAkzb2X7+1OJ79o4WXzJz/JRlNQhutBlx7/ Q4ez3yuhS69bhmkKcglTcPwOkBu/dYm8b+9wKZ696Zel7dadHqhy0N3Z225TfFpiT5cx j8tjOhCOZzfY1BG/k4/IdGU2sn17G58GBxQKCU1IXZ3a4yiO/dJH/ZT/B4TrjXFTR4jS b0Kz/MwMSxCc3l/3BRWNZON/jKUh5sfAEa0KFS58L1FHpOF8mGuTMFIxOOC1n8JhbFXI eDmQ== X-Gm-Message-State: AO0yUKXky2mzMnOv8Y0jqFiw9fbd3yURxS6L23/7eAykHhaYpWLjY9vz jCx5uFARgn9fxR3s2HQmNOqbD0wAWGo= X-Google-Smtp-Source: AK7set8siPI5N9JOwn9bcCm1VrgcgZM1WtkEV7BuX0YYjBBpdCsdUefgBS32TSMhso6MTUlfuwkDXg== X-Received: by 2002:a17:902:ce81:b0:1a0:7602:589e with SMTP id f1-20020a170902ce8100b001a07602589emr9144173plg.40.1679056617849; Fri, 17 Mar 2023 05:36:57 -0700 (PDT) Received: from bobo.ozlabs.ibm.com (121-44-69-75.tpgi.com.au. [121.44.69.75]) by smtp.gmail.com with ESMTPSA id u4-20020a170902b28400b001a19d4592e1sm1430990plr.282.2023.03.17.05.36.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Mar 2023 05:36:57 -0700 (PDT) From: Nicholas Piggin To: kvm@vger.kernel.org Cc: Nicholas Piggin , linuxppc-dev@lists.ozlabs.org, Laurent Vivier , Thomas Huth Subject: [kvm-unit-tests PATCH 7/7] powerpc/spapr_vpa: Add basic VPA tests Date: Fri, 17 Mar 2023 22:36:14 +1000 Message-Id: <20230317123614.3687163-7-npiggin@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230317123614.3687163-1-npiggin@gmail.com> References: <20230317123614.3687163-1-npiggin@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The VPA is a(n optional) memory structure shared between the hypervisor and operating system, defined by PAPR. This test defines the structure and adds registration, deregistration, and a few simple sanity tests. Signed-off-by: Nicholas Piggin --- lib/linux/compiler.h | 2 + lib/powerpc/asm/hcall.h | 1 + lib/ppc64/asm/vpa.h | 62 ++++++++++++++++++++++++++++ powerpc/Makefile.ppc64 | 2 +- powerpc/spapr_vpa.c | 90 +++++++++++++++++++++++++++++++++++++++++ 5 files changed, 156 insertions(+), 1 deletion(-) create mode 100644 lib/ppc64/asm/vpa.h create mode 100644 powerpc/spapr_vpa.c diff --git a/lib/linux/compiler.h b/lib/linux/compiler.h index 6f565e4..c9d205e 100644 --- a/lib/linux/compiler.h +++ b/lib/linux/compiler.h @@ -45,7 +45,9 @@ #define barrier() asm volatile("" : : : "memory") +#ifndef __always_inline #define __always_inline inline __attribute__((always_inline)) +#endif #define noinline __attribute__((noinline)) #define __unused __attribute__((__unused__)) diff --git a/lib/powerpc/asm/hcall.h b/lib/powerpc/asm/hcall.h index 1173fea..e0f5009 100644 --- a/lib/powerpc/asm/hcall.h +++ b/lib/powerpc/asm/hcall.h @@ -18,6 +18,7 @@ #define H_SET_SPRG0 0x24 #define H_SET_DABR 0x28 #define H_PAGE_INIT 0x2c +#define H_REGISTER_VPA 0xDC #define H_CEDE 0xE0 #define H_GET_TERM_CHAR 0x54 #define H_PUT_TERM_CHAR 0x58 diff --git a/lib/ppc64/asm/vpa.h b/lib/ppc64/asm/vpa.h new file mode 100644 index 0000000..11dde01 --- /dev/null +++ b/lib/ppc64/asm/vpa.h @@ -0,0 +1,62 @@ +#ifndef _ASMPOWERPC_VPA_H_ +#define _ASMPOWERPC_VPA_H_ +/* + * This work is licensed under the terms of the GNU LGPL, version 2. + */ + +#ifndef __ASSEMBLY__ + +struct vpa { + uint32_t descriptor; + uint16_t size; + uint8_t reserved1[3]; + uint8_t status; + uint8_t reserved2[14]; + uint32_t fru_node_id; + uint32_t fru_proc_id; + uint8_t reserved3[56]; + uint8_t vhpn_change_counters[8]; + uint8_t reserved4[80]; + uint8_t cede_latency; + uint8_t maintain_ebb; + uint8_t reserved5[6]; + uint8_t dtl_enable_mask; + uint8_t dedicated_cpu_donate; + uint8_t maintain_fpr; + uint8_t maintain_pmc; + uint8_t reserved6[28]; + uint64_t idle_estimate_purr; + uint8_t reserved7[28]; + uint16_t maintain_nr_slb; + uint8_t idle; + uint8_t maintain_vmx; + uint32_t vp_dispatch_count; + uint32_t vp_dispatch_dispersion; + uint64_t vp_fault_count; + uint64_t vp_fault_tb; + uint64_t purr_exprop_idle; + uint64_t spurr_exprop_idle; + uint64_t purr_exprop_busy; + uint64_t spurr_exprop_busy; + uint64_t purr_donate_idle; + uint64_t spurr_donate_idle; + uint64_t purr_donate_busy; + uint64_t spurr_donate_busy; + uint64_t vp_wait3_tb; + uint64_t vp_wait2_tb; + uint64_t vp_wait1_tb; + uint64_t purr_exprop_adjunct_busy; + uint64_t spurr_exprop_adjunct_busy; + uint32_t supervisor_pagein_count; + uint8_t reserved8[4]; + uint64_t purr_exprop_adjunct_idle; + uint64_t spurr_exprop_adjunct_idle; + uint64_t adjunct_insns_executed; + uint8_t reserved9[120]; + uint64_t dtl_index; + uint8_t reserved10[96]; +}; + +#endif /* __ASSEMBLY__ */ + +#endif /* _ASMPOWERPC_VPA_H_ */ diff --git a/powerpc/Makefile.ppc64 b/powerpc/Makefile.ppc64 index ea68447..b0ed2b1 100644 --- a/powerpc/Makefile.ppc64 +++ b/powerpc/Makefile.ppc64 @@ -19,7 +19,7 @@ reloc.o = $(TEST_DIR)/reloc64.o OBJDIRS += lib/ppc64 # ppc64 specific tests -tests = +tests = $(TEST_DIR)/spapr_vpa.elf include $(SRCDIR)/$(TEST_DIR)/Makefile.common diff --git a/powerpc/spapr_vpa.c b/powerpc/spapr_vpa.c new file mode 100644 index 0000000..a5047f1 --- /dev/null +++ b/powerpc/spapr_vpa.c @@ -0,0 +1,90 @@ +/* + * Test sPAPR hypervisor calls (aka. h-calls) + * + * This work is licensed under the terms of the GNU LGPL, version 2. + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include /* for endian accessors */ + +static void print_vpa(struct vpa *vpa) +{ + printf("VPA\n"); + printf("descriptor: 0x%08x\n", be32_to_cpu(vpa->descriptor)); + printf("size: 0x%04x\n", be16_to_cpu(vpa->size)); + printf("status: 0x%02x\n", vpa->status); + printf("fru_node_id: 0x%08x\n", be32_to_cpu(vpa->fru_node_id)); + printf("fru_proc_id: 0x%08x\n", be32_to_cpu(vpa->fru_proc_id)); + printf("vhpn_change_counters: 0x%02x %02x %02x %02x %02x %02x %02x %02x\n", vpa->vhpn_change_counters[0], vpa->vhpn_change_counters[1], vpa->vhpn_change_counters[2], vpa->vhpn_change_counters[3], vpa->vhpn_change_counters[4], vpa->vhpn_change_counters[5], vpa->vhpn_change_counters[6], vpa->vhpn_change_counters[7]); + printf("vp_dispatch_count: 0x%08x\n", be32_to_cpu(vpa->vp_dispatch_count)); + printf("vp_dispatch_dispersion: 0x%08x\n", be32_to_cpu(vpa->vp_dispatch_dispersion)); + printf("vp_fault_count: 0x%08lx\n", be64_to_cpu(vpa->vp_fault_count)); + printf("vp_fault_tb: 0x%08lx\n", be64_to_cpu(vpa->vp_fault_tb)); + printf("purr_exprop_idle: 0x%08lx\n", be64_to_cpu(vpa->purr_exprop_idle)); + printf("spurr_exprop_idle: 0x%08lx\n", be64_to_cpu(vpa->spurr_exprop_idle)); + printf("purr_exprop_busy: 0x%08lx\n", be64_to_cpu(vpa->purr_exprop_busy)); + printf("spurr_exprop_busy: 0x%08lx\n", be64_to_cpu(vpa->spurr_exprop_busy)); + printf("purr_donate_idle: 0x%08lx\n", be64_to_cpu(vpa->purr_donate_idle)); + printf("spurr_donate_idle: 0x%08lx\n", be64_to_cpu(vpa->spurr_donate_idle)); + printf("purr_donate_busy: 0x%08lx\n", be64_to_cpu(vpa->purr_donate_busy)); + printf("spurr_donate_busy: 0x%08lx\n", be64_to_cpu(vpa->spurr_donate_busy)); + printf("vp_wait3_tb: 0x%08lx\n", be64_to_cpu(vpa->vp_wait3_tb)); + printf("vp_wait2_tb: 0x%08lx\n", be64_to_cpu(vpa->vp_wait2_tb)); + printf("vp_wait1_tb: 0x%08lx\n", be64_to_cpu(vpa->vp_wait1_tb)); + printf("purr_exprop_adjunct_busy: 0x%08lx\n", be64_to_cpu(vpa->purr_exprop_adjunct_busy)); + printf("spurr_exprop_adjunct_busy: 0x%08lx\n", be64_to_cpu(vpa->spurr_exprop_adjunct_busy)); + printf("purr_exprop_adjunct_idle: 0x%08lx\n", be64_to_cpu(vpa->purr_exprop_adjunct_idle)); + printf("spurr_exprop_adjunct_idle: 0x%08lx\n", be64_to_cpu(vpa->spurr_exprop_adjunct_idle)); + printf("adjunct_insns_executed: 0x%08lx\n", be64_to_cpu(vpa->adjunct_insns_executed)); + printf("dtl_index: 0x%08lx\n", be64_to_cpu(vpa->dtl_index)); +} + +/** + * Test the H_REGISTER_VPA h-call register/deregister. + */ +static void register_vpa(struct vpa *vpa) +{ + uint32_t cpuid = fdt_boot_cpuid_phys(dt_fdt()); + int disp_count1, disp_count2; + int rc; + + rc = hcall(H_REGISTER_VPA, 1ULL << 45, cpuid, vpa); + report(rc == H_SUCCESS, "VPA registered"); + + print_vpa(vpa); + + disp_count1 = be32_to_cpu(vpa->vp_dispatch_count); + report(disp_count1 % 2 == 0, "Dispatch count is even while running"); + sleep(0x1000000); + disp_count2 = be32_to_cpu(vpa->vp_dispatch_count); + report(disp_count1 != disp_count2, "Dispatch count increments"); + + rc = hcall(H_REGISTER_VPA, 5ULL << 45, cpuid, vpa); + report(rc == H_SUCCESS, "VPA deregistered"); + + disp_count1 = be32_to_cpu(vpa->vp_dispatch_count); + report(disp_count1 % 2 == 1, "Dispatch count is odd after deregister"); +} + +int main(int argc, char **argv) +{ + struct vpa *vpa; + + vpa = memalign(4096, sizeof(*vpa)); + + memset(vpa, 0, sizeof(*vpa)); + + vpa->size = cpu_to_be16(sizeof(*vpa)); + + report_prefix_push("vpa"); + + register_vpa(vpa); + + return report_summary(); +}