From: Nicholas Piggin <npiggin@gmail.com>
To: Thomas Huth <thuth@redhat.com>
Cc: Laurent Vivier <lvivier@redhat.com>,
linuxppc-dev@lists.ozlabs.org, kvm@vger.kernel.org,
Nicholas Piggin <npiggin@gmail.com>,
Andrew Jones <andrew.jones@linux.dev>
Subject: [kvm-unit-tests PATCH v10 01/15] powerpc: Add facility to query TCG or KVM host
Date: Wed, 12 Jun 2024 15:23:06 +1000 [thread overview]
Message-ID: <20240612052322.218726-2-npiggin@gmail.com> (raw)
In-Reply-To: <20240612052322.218726-1-npiggin@gmail.com>
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 run
on a TCG processor (if TCG is emulating HV mode, or it is using the
nested hypervisor APIs in pseries / spapr). And kvm-unit-tests can run
on that KVM.
This can be a problem because some issues relate to TCG CPU emulation
some to the spapr hypervisor implementation, some to KVM, some to real
hardware, so the TCG test is best-effort for now and is set to the
opposite of KVM. The two independent variables are added because we may
be able to more accurately determine this in future.
Use this facility to restrict some of the known test failures to TCG.
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
lib/powerpc/asm/processor.h | 3 +++
lib/powerpc/setup.c | 26 ++++++++++++++++++++++++++
powerpc/interrupts.c | 6 ++++--
powerpc/sprs.c | 2 +-
powerpc/tm.c | 2 +-
5 files changed, 35 insertions(+), 4 deletions(-)
diff --git a/lib/powerpc/asm/processor.h b/lib/powerpc/asm/processor.h
index a3859b5d4..a660344cb 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 622b99e5d..86e2e144c 100644
--- a/lib/powerpc/setup.c
+++ b/lib/powerpc/setup.c
@@ -208,6 +208,9 @@ void cpu_init(struct cpu *cpu, int cpu_id)
cpu->exception_stack += SZ_64K - 64;
}
+bool host_is_tcg;
+bool host_is_kvm;
+
void setup(const void *fdt)
{
void *freemem = &stacktop;
@@ -259,6 +262,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/interrupts.c b/powerpc/interrupts.c
index 552c48ef2..3e3622e59 100644
--- a/powerpc/interrupts.c
+++ b/powerpc/interrupts.c
@@ -72,7 +72,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)
@@ -82,7 +83,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/sprs.c b/powerpc/sprs.c
index a85011ad5..dc810b8da 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(i == 136, pass,
+ report_kfail(host_is_kvm && i == 136, pass,
"%-10s(%4d):\t 0x%08lx <==> 0x%08lx",
sprs[i].name, i,
before[i], after[i]);
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");
--
2.45.1
next prev parent reply other threads:[~2024-06-12 5:24 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-12 5:23 [kvm-unit-tests PATCH v10 00/15] powerpc improvements Nicholas Piggin
2024-06-12 5:23 ` Nicholas Piggin [this message]
2024-06-12 5:23 ` [kvm-unit-tests PATCH v10 02/15] powerpc: Add atomics tests Nicholas Piggin
2024-06-12 5:23 ` [kvm-unit-tests PATCH v10 03/15] powerpc: Add timebase tests Nicholas Piggin
2024-06-12 5:23 ` [kvm-unit-tests PATCH v10 04/15] powerpc: Add MMU support Nicholas Piggin
2024-06-12 5:23 ` [kvm-unit-tests PATCH v10 05/15] common/sieve: Support machines without MMU Nicholas Piggin
2024-06-12 5:23 ` [kvm-unit-tests PATCH v10 06/15] powerpc: Add sieve.c common test Nicholas Piggin
2024-06-12 5:23 ` [kvm-unit-tests PATCH v10 07/15] powerpc: add usermode support Nicholas Piggin
2024-06-12 5:23 ` [kvm-unit-tests PATCH v10 08/15] powerpc: add pmu tests Nicholas Piggin
2024-06-18 15:20 ` Thomas Huth
2024-06-18 18:39 ` Thomas Huth
2024-06-25 1:56 ` Nicholas Piggin
2024-06-12 5:23 ` [kvm-unit-tests PATCH v10 09/15] configure: Make arch_libdir a first-class entity Nicholas Piggin
2024-06-12 5:23 ` [kvm-unit-tests PATCH v10 10/15] powerpc: Remove remnants of ppc64 directory and build structure Nicholas Piggin
2024-06-19 7:36 ` Thomas Huth
2024-06-12 5:23 ` [kvm-unit-tests PATCH v10 11/15] powerpc: gitlab CI update Nicholas Piggin
2024-06-12 5:23 ` [kvm-unit-tests PATCH v10 12/15] scripts/arch-run.bash: Fix run_panic() success exit status Nicholas Piggin
2024-06-12 7:26 ` Andrew Jones
2024-06-14 0:56 ` Nicholas Piggin
2024-06-17 14:12 ` Andrew Jones
2024-06-17 14:13 ` Andrew Jones
2024-06-12 5:23 ` [kvm-unit-tests PATCH v10 13/15] powerpc: Add a panic test Nicholas Piggin
2024-06-19 7:42 ` Thomas Huth
2024-06-12 5:23 ` [kvm-unit-tests PATCH v10 14/15] powerpc/gitlab-ci: Upgrade powerpc to Fedora 40 Nicholas Piggin
2024-06-19 7:35 ` Thomas Huth
2024-06-12 5:23 ` [kvm-unit-tests PATCH v10 15/15] powerpc/gitlab-ci: Enable more tests with " Nicholas Piggin
2024-06-19 7:44 ` Thomas Huth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240612052322.218726-2-npiggin@gmail.com \
--to=npiggin@gmail.com \
--cc=andrew.jones@linux.dev \
--cc=kvm@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=lvivier@redhat.com \
--cc=thuth@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).