Skip to contentSkip to conversation

powerpc improvements

PATCH Superseded Nicholas Piggin 3 participants 74 messages May 4, 2024 – Jun 5, 2024

Subsystems (6)
KVM Kbuild Library code s390 +2 more subsystems

v9 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v9 cover powerpc improvements

Tree here
https://gitlab.com/npiggin/kvm-unit-tests/-/tree/powerpc

Since v8:
- Migration improvements merged and out of series.
- Rebased on upstream.
- Did some more splitting of patches to make review easier.
- Added a new kfail option for known failures because I add a bunch and I don't want to remove them but also don't want them to report as failing the test (at least until implementations can be improved).
- Added MMU tlb invalidation tests that trigger upstream QEMU bug.
- Added tcg/kvm host detection to help known-failure reporting.
- Fixed a few fails and marked a lot of known fails.

Thanks,
Nick

Nicholas Piggin (31):
doc: update unittests doc
report: Add known failure reporting option
powerpc: Mark known failing tests as kfail
powerpc: Update unittests for latest QEMU version powerpc/sprs: Specify SPRs with data rather than code powerpc/sprs: Avoid taking PMU interrupts caused by register fuzzing
scripts: allow machine option to be specified in unittests.cfg
scripts: Accommodate powerpc powernv machine differences
powerpc: Support powernv machine with QEMU TCG
powerpc: Fix emulator illegal instruction test for powernv powerpc/sprs: Test hypervisor registers on powernv machine
powerpc: general interrupt tests
powerpc: Add rtas stop-self support
powerpc: Remove broken SMP exception stack setup
powerpc: Enable page alloc operations
powerpc: add SMP and IPI support
powerpc: Add cpu_relax
powerpc: Permit ACCEL=tcg,thread=single
powerpc: Avoid using larx/stcx. in spinlocks when only one CPU is
running
powerpc: Add atomics tests
powerpc: Add timebase tests
powerpc: Add MMU support
common/sieve: Use vmalloc.h for setup_mmu definition common/sieve: Support machines without MMU
powerpc: Add sieve.c common test
powerpc: add usermode support
powerpc: add pmu tests
configure: Make arch_libdir a first-class entity
powerpc: Remove remnants of ppc64 directory and build structure
powerpc: Add facility to query TCG or KVM host
powerpc: gitlab CI update

 .gitlab-ci.yml                           |  30 +-
 MAINTAINERS                              |   1 -
 Makefile                                 |   2 +-
 common/sieve.c                           |  15 +-
 configure                                |  58 +-
 docs/unittests.txt                       |  19 +-
 lib/libcflat.h                           |   4 +-
 lib/{ppc64 => powerpc}/asm-offsets.c     |   9 +
 lib/{ppc64 => powerpc}/asm/asm-offsets.h |   0
 lib/powerpc/asm/atomic.h                 |   6 +
 lib/powerpc/asm/barrier.h                |  12 +
 lib/{ppc64 => powerpc}/asm/bitops.h      |   4 +-
 lib/powerpc/asm/hcall.h                  |   6 +
 lib/{ppc64 => powerpc}/asm/io.h          |   4 +-
 lib/powerpc/asm/mmu.h                    |  10 +
 lib/powerpc/asm/opal.h                   |  22 +
 lib/powerpc/asm/page.h                   |  65 +++
 lib/powerpc/asm/pgtable-hwdef.h          |  66 +++
 lib/powerpc/asm/pgtable.h                | 125 +++++
 lib/powerpc/asm/processor.h              |  66 +++
 lib/{ppc64 => powerpc}/asm/ptrace.h      |  22 +-
 lib/powerpc/asm/reg.h                    |  42 ++
 lib/powerpc/asm/rtas.h                   |   2 +
 lib/powerpc/asm/setup.h                  |   3 +-
 lib/powerpc/asm/smp.h                    |  48 +-
 lib/powerpc/asm/spinlock.h               |  11 +
 lib/powerpc/asm/stack.h                  |   3 +
 lib/{ppc64 => powerpc}/asm/vpa.h         |   0
 lib/powerpc/hcall.c                      |   4 +-
 lib/powerpc/io.c                         |  41 +-
 lib/powerpc/io.h                         |   6 +
 lib/powerpc/mmu.c                        | 283 ++++++++++
 lib/powerpc/opal-calls.S                 |  50 ++
 lib/powerpc/opal.c                       |  76 +++
 lib/powerpc/processor.c                  |  91 +++-
 lib/powerpc/rtas.c                       |  81 ++-
 lib/powerpc/setup.c                      | 192 ++++++-
 lib/powerpc/smp.c                        | 342 ++++++++++--
 lib/powerpc/spinlock.c                   |  33 ++
 lib/{ppc64 => powerpc}/stack.c           |   0
 lib/ppc64/.gitignore                     |   1 -
 lib/ppc64/asm/barrier.h                  |   9 -
 lib/ppc64/asm/handlers.h                 |   1 -
 lib/ppc64/asm/hcall.h                    |   1 -
 lib/ppc64/asm/memory_areas.h             |   6 -
 lib/ppc64/asm/page.h                     |   1 -
 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/spinlock.h                 |   6 -
 lib/ppc64/asm/stack.h                    |  11 -
 lib/report.c                             |  33 +-
 lib/s390x/io.c                           |   1 +
 lib/s390x/uv.h                           |   1 +
 lib/vmalloc.c                            |   7 +
 lib/vmalloc.h                            |   2 +
 lib/x86/vm.h                             |   1 +
 powerpc/Makefile                         | 112 +++-
 powerpc/Makefile.common                  |  86 ---
 powerpc/Makefile.ppc64                   |  28 -
 powerpc/atomics.c                        | 375 +++++++++++++
 powerpc/cstart64.S                       |  57 +-
 powerpc/emulator.c                       |  16 +
 powerpc/interrupts.c                     | 518 ++++++++++++++++++
 powerpc/mmu.c                            | 283 ++++++++++
 powerpc/pmu.c                            | 403 ++++++++++++++
 powerpc/run                              |  44 +-
 powerpc/selftest.c                       |   4 +-
 powerpc/sieve.c                          |   1 +
 powerpc/smp.c                            | 348 ++++++++++++
 powerpc/spapr_vpa.c                      |   3 +-
 powerpc/sprs.c                           | 662 ++++++++++++++++-------
 powerpc/timebase.c                       | 331 ++++++++++++
 powerpc/tm.c                             |   6 +-
 powerpc/unittests.cfg                    |  88 ++-
 s390x/mvpg.c                             |   1 +
 s390x/selftest.c                         |   1 +
 scripts/common.bash                      |   8 +-
 scripts/runtime.bash                     |  22 +-
 x86/pmu.c                                |   1 +
 x86/pmu_lbr.c                            |   1 +
 x86/vmexit.c                             |   1 +
 x86/vmware_backdoors.c                   |   1 +
 86 files changed, 4798 insertions(+), 544 deletions(-)
 rename lib/{ppc64 => powerpc}/asm-offsets.c (91%)
 rename lib/{ppc64 => powerpc}/asm/asm-offsets.h (100%)
 create mode 100644 lib/powerpc/asm/atomic.h
 create mode 100644 lib/powerpc/asm/barrier.h
 rename lib/{ppc64 => powerpc}/asm/bitops.h (69%)
 rename lib/{ppc64 => powerpc}/asm/io.h (50%)
 create mode 100644 lib/powerpc/asm/mmu.h
 create mode 100644 lib/powerpc/asm/opal.h
 create mode 100644 lib/powerpc/asm/page.h
 create mode 100644 lib/powerpc/asm/pgtable-hwdef.h
 create mode 100644 lib/powerpc/asm/pgtable.h
 rename lib/{ppc64 => powerpc}/asm/ptrace.h (59%)
 create mode 100644 lib/powerpc/asm/spinlock.h
 rename lib/{ppc64 => powerpc}/asm/vpa.h (100%)
 create mode 100644 lib/powerpc/mmu.c
 create mode 100644 lib/powerpc/opal-calls.S
 create mode 100644 lib/powerpc/opal.c
 create mode 100644 lib/powerpc/spinlock.c
 rename lib/{ppc64 => powerpc}/stack.c (100%)
 delete mode 100644 lib/ppc64/.gitignore
 delete mode 100644 lib/ppc64/asm/barrier.h
 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/page.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/spinlock.h
 delete mode 100644 lib/ppc64/asm/stack.h
 delete mode 100644 powerpc/Makefile.common
 delete mode 100644 powerpc/Makefile.ppc64
 create mode 100644 powerpc/atomics.c
 create mode 100644 powerpc/interrupts.c
 create mode 100644 powerpc/mmu.c
 create mode 100644 powerpc/pmu.c
 create mode 120000 powerpc/sieve.c
 create mode 100644 powerpc/smp.c
 create mode 100644 powerpc/timebase.c
Signature · 1 line
2.43.0
#1 lore raw

PATCH v9 1/31 doc: update unittests doc

This adds a few minor fixes.

---
 docs/unittests.txt | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
docs/unittests.txt +7 -5
index 3192a60ec..7cf2c55ad 100644
@@ -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 = <group_name1> <group_name2> ...
 
 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 = <path>=<<value>
+check = <path>=<value>
 
 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 <path>=<value>
+
+The path and value can not contain space, =, or shell wildcard characters.
Signature · 1 line
2.43.0
#2 lore raw

Re: [kvm-unit-tests PATCH v9 01/31] doc: update unittests doc

Quoted 35 lines · Nicholas Piggin

This adds a few minor fixes.

---
  docs/unittests.txt | 12 +++++++-----
  1 file changed, 7 insertions(+), 5 deletions(-)
docs/unittests.txt +4 -4
index 3192a60ec..7cf2c55ad 100644
@@ -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 = <group_name1> <group_name2> ...
 
  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.
 

docs/unittests.txt Optional timeout in seconds, after which the test will be killed and fail. · line 91

Quoted 10 lines
docs/unittests.txt +3 -1
  check
  -----
-check = <path>=<<value>
+check = <path>=<value>
 
  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 <path>=<value>
+
+The path and value can not contain space, =, or shell wildcard characters.

Could you comment on my feedback here, please:

https://lore.kernel.org/kvm/[email protected]/

Thanks,
Thomas

#3 lore raw

Re: [kvm-unit-tests PATCH v9 01/31] doc: update unittests doc

Quoted 49 lines · Thomas Huth
Quoted 35 lines · Nicholas Piggin

This adds a few minor fixes.

---
  docs/unittests.txt | 12 +++++++-----
  1 file changed, 7 insertions(+), 5 deletions(-)
docs/unittests.txt +4 -4
index 3192a60ec..7cf2c55ad 100644
@@ -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 = <group_name1> <group_name2> ...
 
  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.
 

docs/unittests.txt Optional timeout in seconds, after which the test will be killed and fail. · line 91

Quoted 10 lines
docs/unittests.txt +3 -1
  check
  -----
-check = <path>=<<value>
+check = <path>=<value>
 
  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 <path>=<value>
+
+The path and value can not contain space, =, or shell wildcard characters.

Could you comment on my feedback here, please:

Quoted 1 line

https://lore.kernel.org/kvm/[email protected]/

Sorry, missed that. I didn't mean to re-send this one.

Thanks,
Nick

Reviewed-by on v9 1/31
#4 lore raw

Re: [kvm-unit-tests PATCH v9 01/31] doc: update unittests doc

In reply to Nicholas Piggin
Quoted 48 lines · Nicholas Piggin

This adds a few minor fixes.

---
 docs/unittests.txt | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)
docs/unittests.txt +7 -5
index 3192a60ec..7cf2c55ad 100644
@@ -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 = <group_name1> <group_name2> ...
 
 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 = <path>=<<value>
+check = <path>=<value>
 
 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 <path>=<value>
+
+The path and value can not contain space, =, or shell wildcard characters.
Signature · 1 line
2.43.0
#5 lore raw

PATCH v9 2/31 report: Add known failure reporting option

In reply to Nicholas Piggin

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.

---
 lib/libcflat.h |  2 ++
 lib/report.c   | 33 +++++++++++++++++++++++++--------
 2 files changed, 27 insertions(+), 8 deletions(-)
lib/libcflat.h +2 -0
index 700f43527..ae3c2c6d0 100644
@@ -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));
lib/report.c +25 -8
index 8e9bff5b8..7f3c4f059 100644
@@ -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)
Signature · 1 line
2.43.0
#6 lore raw

Re: [kvm-unit-tests PATCH v9 02/31] report: Add known failure reporting option

Quoted 7 lines · Nicholas Piggin

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.

Actually, I wonder whether that's not rather a bug in report_xfail() instead. Currently, when you call report_xfail(true, ...), the result is *always* counted as a failure, either as an expected failure (if the test really failed), or as a normal failure (if the test succeeded). What's the point of counting a successful test as a failure??

Andrew, you've originally introduced report_xfail in commit a5af7b8a67e, could you please comment on this?

IMHO we should rather do something like this instead:

lib/report.c +1 -1
@@ -98,7 +98,7 @@ static void va_report(const char *msg_fmt,
                skipped++;
        else if (xfail && !pass)
                xfailures++;
-       else if (xfail || !pass)
+       else if (!xfail && !pass)
                failures++;
 
        spin_unlock(&lock);

Thomas

#7 lore raw

Re: [kvm-unit-tests PATCH v9 02/31] report: Add known failure reporting option

Quoted 9 lines · Thomas Huth
Quoted 7 lines · Nicholas Piggin

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.

Quoted 9 lines

Actually, I wonder whether that's not rather a bug in report_xfail() instead. Currently, when you call report_xfail(true, ...), the result is *always* counted as a failure, either as an expected failure (if the test really failed), or as a normal failure (if the test succeeded). What's the point of counting a successful test as a failure??

Andrew, you've originally introduced report_xfail in commit a5af7b8a67e, could you please comment on this?

An expected failure passes when the test fails and fails when the test passes, i.e.

XFAIL == PASS (but separately accounted with 'xfailures') XPASS == FAIL

If we expect something to fail and it passes then this may be due to the thing being fixed, so we should change the test to expect success, or due to the test being written incorrectly for our expectations. Either way, when an expected failure doesn't fail, it means our expectations are wrong and we need to be alerted to that, hence a FAIL is reported.

Thanks,
drew

Quoted 17 lines

IMHO we should rather do something like this instead:

lib/report.c +1 -1
@@ -98,7 +98,7 @@ static void va_report(const char *msg_fmt,
                skipped++;
        else if (xfail && !pass)
                xfailures++;
-       else if (xfail || !pass)
+       else if (!xfail && !pass)
                failures++;
 
        spin_unlock(&lock);

Thomas

Reviewed-by
#8 lore raw

Re: [kvm-unit-tests PATCH v9 02/31] report: Add known failure reporting option

Quoted 23 lines · Andrew Jones
Quoted 9 lines · Thomas Huth
Quoted 7 lines · Nicholas Piggin

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.

Quoted 9 lines

Actually, I wonder whether that's not rather a bug in report_xfail() instead. Currently, when you call report_xfail(true, ...), the result is *always* counted as a failure, either as an expected failure (if the test really failed), or as a normal failure (if the test succeeded). What's the point of counting a successful test as a failure??

Andrew, you've originally introduced report_xfail in commit a5af7b8a67e, could you please comment on this?

An expected failure passes when the test fails and fails when the test passes, i.e.

Quoted 8 lines

XFAIL == PASS (but separately accounted with 'xfailures') XPASS == FAIL

If we expect something to fail and it passes then this may be due to the thing being fixed, so we should change the test to expect success, or due to the test being written incorrectly for our expectations. Either way, when an expected failure doesn't fail, it means our expectations are wrong and we need to be alerted to that, hence a FAIL is reported.

Ok, so this was on purpose, indeed. Maybe we should add this information in a comment right in front of the function, so that others don't scratch their head, too?

Anyway, this patch here is fine then:

#9 lore raw

PATCH v9 3/31 powerpc: Mark known failing tests as kfail

In reply to Nicholas Piggin

Mark the failing h_cede_tm and spapr_vpa tests as kfail.

---
 powerpc/spapr_vpa.c | 3 ++-
 powerpc/tm.c        | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
powerpc/spapr_vpa.c +2 -1
index c2075e157..46fa0485c 100644
@@ -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();
 }
powerpc/tm.c +2 -1
index 6b1ceeb6e..d9e7f455d 100644
@@ -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");
Signature · 1 line
2.43.0
#10 lore raw

Re: [kvm-unit-tests PATCH v9 03/31] powerpc: Mark known failing tests as kfail

Quoted 13 lines · Nicholas Piggin

Mark the failing h_cede_tm and spapr_vpa tests as kfail.

---
  powerpc/spapr_vpa.c | 3 ++-
  powerpc/tm.c        | 3 ++-
  2 files changed, 4 insertions(+), 2 deletions(-)
powerpc/spapr_vpa.c +0 -0
index c2075e157..46fa0485c 100644

powerpc/spapr_vpa.c static void test_vpa(void) · line 154

Quoted 6 lines
powerpc/spapr_vpa.c +2 -1
@@ -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");

Using "true" as first argument looks rather pointless - then you could also simply delete the test completely if it can never be tested reliably.

Thus could you please introduce a helper function is_tcg() that could be used to check whether we run under TCG (and not KVM)? I think you could check for "linux,kvm" in the "compatible" property in /hypervisor in the device tree to see whether we're running in KVM mode or in TCG mode.

Quoted 7 lines
powerpc/spapr_vpa.c +0 -0
  	report_prefix_pop();
  }
powerpc/tm.c +0 -0
index 6b1ceeb6e..d9e7f455d 100644

powerpc/tm.c int main(int argc, char **argv) · line 138

Quoted 7 lines
powerpc/tm.c +2 -1
@@ -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");

Could you check the PVR for POWER9 here instead of using "true" as first parameter?

Thomas

#11 lore raw

Re: [kvm-unit-tests PATCH v9 03/31] powerpc: Mark known failing tests as kfail

Quoted 24 lines · Thomas Huth
Quoted 13 lines · Nicholas Piggin

Mark the failing h_cede_tm and spapr_vpa tests as kfail.

---
  powerpc/spapr_vpa.c | 3 ++-
  powerpc/tm.c        | 3 ++-
  2 files changed, 4 insertions(+), 2 deletions(-)
powerpc/spapr_vpa.c +0 -0
index c2075e157..46fa0485c 100644

powerpc/spapr_vpa.c static void test_vpa(void) · line 154

Quoted 6 lines
powerpc/spapr_vpa.c +2 -1
@@ -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");

Using "true" as first argument looks rather pointless - then you could also simply delete the test completely if it can never be tested reliably.

Quoted 4 lines

Thus could you please introduce a helper function is_tcg() that could be used to check whether we run under TCG (and not KVM)? I think you could check for "linux,kvm" in the "compatible" property in /hypervisor in the device tree to see whether we're running in KVM mode or in TCG mode.

This I added in patch 30.

The reason for the suboptimal patch ordering was just me being lazy and avoiding rebasing annoyance. I'd written a bunch of failing test cases for QEMU work, but hadn't done the kvm/tcg test yet. It had a few conflicts so I put it at the end... can rebase if you'd really prefer.

Quoted 10 lines
Quoted 10 lines
powerpc/spapr_vpa.c +0 -0
  	report_prefix_pop();
  }
powerpc/tm.c +0 -0
index 6b1ceeb6e..d9e7f455d 100644
@@ -133,7 +133,8 @@ int main(int argc, char **argv)
  		report_skip("TM is not available");
  		goto done;
Quoted 8 lines

powerpc/tm.c int main(int argc, char **argv) · line 138

Quoted 5 lines
powerpc/tm.c +2 -1
  	}
-	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");

Could you check the PVR for POWER9 here instead of using "true" as first parameter?

Also covered in patch 30.

Thanks,
Nick

#12 lore raw

Re: [kvm-unit-tests PATCH v9 03/31] powerpc: Mark known failing tests as kfail

Quoted 30 lines · Nicholas Piggin
Quoted 24 lines · Thomas Huth
Quoted 13 lines · Nicholas Piggin

Mark the failing h_cede_tm and spapr_vpa tests as kfail.

---
   powerpc/spapr_vpa.c | 3 ++-
   powerpc/tm.c        | 3 ++-
   2 files changed, 4 insertions(+), 2 deletions(-)
powerpc/spapr_vpa.c +0 -0
index c2075e157..46fa0485c 100644

powerpc/spapr_vpa.c static void test_vpa(void) · line 154

Quoted 6 lines
powerpc/spapr_vpa.c +2 -1
@@ -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");

Using "true" as first argument looks rather pointless - then you could also simply delete the test completely if it can never be tested reliably.

Quoted 4 lines

Thus could you please introduce a helper function is_tcg() that could be used to check whether we run under TCG (and not KVM)? I think you could check for "linux,kvm" in the "compatible" property in /hypervisor in the device tree to see whether we're running in KVM mode or in TCG mode.

Quoted 6 lines

This I added in patch 30.

The reason for the suboptimal patch ordering was just me being lazy and avoiding rebasing annoyance. I'd written a bunch of failing test cases for QEMU work, but hadn't done the kvm/tcg test yet. It had a few conflicts so I put it at the end... can rebase if you'd really prefer.

Ah, ok, no need to rebase then, as long it's there in the end, it's fine.

Thanks,
Thomas

#13 lore raw

PATCH v9 4/31 powerpc: Update unittests for latest QEMU version

In reply to Nicholas Piggin

The latest QEMU fixes some known bugs in migration which allow some migration tests to be re-enabled on tcg.

---
 powerpc/unittests.cfg | 5 -----
 1 file changed, 5 deletions(-)
powerpc/unittests.cfg +0 -5
index 432c81d58..699736926 100644
@@ -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/[email protected]/
-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
 
Signature · 1 line
2.43.0
#14 lore raw

PATCH v9 5/31 powerpc/sprs: Specify SPRs with data rather than code

In reply to Nicholas Piggin

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.

---
 lib/powerpc/asm/reg.h |   2 +
 powerpc/sprs.c        | 650 +++++++++++++++++++++++++++++-------------
 2 files changed, 460 insertions(+), 192 deletions(-)
lib/powerpc/asm/reg.h +2 -0
index 6810c1d82..1f991288e 100644
@@ -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
powerpc/sprs.c +458 -192

712 lines not on this page · raw message

Signature · 1 line
2.43.0
#15 lore raw

PATCH v9 6/31 powerpc/sprs: Avoid taking PMU interrupts caused by register fuzzing

In reply to Nicholas Piggin

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.

---
 lib/powerpc/asm/reg.h |  4 ++++
 powerpc/sprs.c        | 17 +++++++++++------
 2 files changed, 15 insertions(+), 6 deletions(-)
lib/powerpc/asm/reg.h +4 -0
index 1f991288e..c80b32059 100644
@@ -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 */
powerpc/sprs.c +11 -6
index a6588ca63..c25dac1f6 100644
@@ -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 */
Signature · 1 line
2.43.0
#16 lore raw

PATCH v9 7/31 scripts: allow machine option to be specified in unittests.cfg

In reply to Nicholas Piggin

This allows different machines with different requirements to be supported by run_tests.sh, similarly to how different accelerators are handled.

---
 docs/unittests.txt   |  7 +++++++
 scripts/common.bash  |  8 ++++++--
 scripts/runtime.bash | 16 ++++++++++++----
 3 files changed, 25 insertions(+), 6 deletions(-)
docs/unittests.txt +7 -0
index 7cf2c55ad..6449efd78 100644
@@ -42,6 +42,13 @@ For <arch>/ 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 = <number>
scripts/common.bash +6 -2
index 5e9ad53e2..3aa557c8c 100644
@@ -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}<&-
 }
scripts/runtime.bash +12 -4
index 177b62166..0c96d6ea2 100644
@@ -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
Signature · 1 line
2.43.0
#17 lore raw

Re: [kvm-unit-tests PATCH v9 07/31] scripts: allow machine option to be specified in unittests.cfg

Quoted 109 lines · Nicholas Piggin

This allows different machines with different requirements to be supported by run_tests.sh, similarly to how different accelerators are handled.

---
  docs/unittests.txt   |  7 +++++++
  scripts/common.bash  |  8 ++++++--
  scripts/runtime.bash | 16 ++++++++++++----
  3 files changed, 25 insertions(+), 6 deletions(-)
docs/unittests.txt +7 -0
index 7cf2c55ad..6449efd78 100644
@@ -42,6 +42,13 @@ For <arch>/ 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 = <number>
scripts/common.bash +6 -2
index 5e9ad53e2..3aa557c8c 100644
@@ -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}<&-
  }
scripts/runtime.bash +5 -4
index 177b62166..0c96d6ea2 100644
@@ -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
 

scripts/runtime.bash function run() · line 129

Quoted 10 lines
scripts/runtime.bash +7 -0
+    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

For some reasons that I don't quite understand yet, this patch causes the "sieve" test to always timeout on the s390x runner, see e.g.:

https://gitlab.com/thuth/kvm-unit-tests/-/jobs/6798954987

Everything is fine in the previous patches (I pushed now the previous 5 patches to the repo):

https://gitlab.com/kvm-unit-tests/kvm-unit-tests/-/pipelines/1281919104

Could it be that he TIMEOUT gets messed up in certain cases?

Thomas

#18 lore raw

Re: [kvm-unit-tests PATCH v9 07/31] scripts: allow machine option to be specified in unittests.cfg

Quoted 124 lines · Thomas Huth
Quoted 109 lines · Nicholas Piggin

This allows different machines with different requirements to be supported by run_tests.sh, similarly to how different accelerators are handled.

---
  docs/unittests.txt   |  7 +++++++
  scripts/common.bash  |  8 ++++++--
  scripts/runtime.bash | 16 ++++++++++++----
  3 files changed, 25 insertions(+), 6 deletions(-)
docs/unittests.txt +7 -0
index 7cf2c55ad..6449efd78 100644
@@ -42,6 +42,13 @@ For <arch>/ 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 = <number>
scripts/common.bash +6 -2
index 5e9ad53e2..3aa557c8c 100644
@@ -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}<&-
  }
scripts/runtime.bash +5 -4
index 177b62166..0c96d6ea2 100644
@@ -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
 

scripts/runtime.bash function run() · line 129

Quoted 10 lines
scripts/runtime.bash +7 -0
+    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

For some reasons that I don't quite understand yet, this patch causes the "sieve" test to always timeout on the s390x runner, see e.g.:

Quoted 1 line

https://gitlab.com/thuth/kvm-unit-tests/-/jobs/6798954987

How do you use the s390x runner?

Quoted 7 lines

Everything is fine in the previous patches (I pushed now the previous 5 patches to the repo):

https://gitlab.com/kvm-unit-tests/kvm-unit-tests/-/pipelines/1281919104

Could it be that he TIMEOUT gets messed up in certain cases?

Hmm not sure yet. At least it got timeout right for the duration=90s message.

Thanks,
Nick

#19 lore raw

Re: [kvm-unit-tests PATCH v9 07/31] scripts: allow machine option to be specified in unittests.cfg

Quoted 133 lines · Nicholas Piggin
Quoted 124 lines · Thomas Huth
Quoted 109 lines · Nicholas Piggin

This allows different machines with different requirements to be supported by run_tests.sh, similarly to how different accelerators are handled.

---
   docs/unittests.txt   |  7 +++++++
   scripts/common.bash  |  8 ++++++--
   scripts/runtime.bash | 16 ++++++++++++----
   3 files changed, 25 insertions(+), 6 deletions(-)
docs/unittests.txt +7 -0
index 7cf2c55ad..6449efd78 100644
@@ -42,6 +42,13 @@ For <arch>/ 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 = <number>
scripts/common.bash +6 -2
index 5e9ad53e2..3aa557c8c 100644
@@ -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}<&-
   }
scripts/runtime.bash +5 -4
index 177b62166..0c96d6ea2 100644
@@ -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
 

scripts/runtime.bash function run() · line 129

Quoted 10 lines
scripts/runtime.bash +7 -0
+    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

For some reasons that I don't quite understand yet, this patch causes the "sieve" test to always timeout on the s390x runner, see e.g.:

Quoted 1 line
   https://gitlab.com/thuth/kvm-unit-tests/-/jobs/6798954987

How do you use the s390x runner?

Quoted 4 lines

Everything is fine in the previous patches (I pushed now the previous 5 patches to the repo):

Quoted 6 lines
Quoted 3 lines
   https://gitlab.com/kvm-unit-tests/kvm-unit-tests/-/pipelines/1281919104

Could it be that he TIMEOUT gets messed up in certain cases?

Hmm not sure yet. At least it got timeout right for the duration=90s message.

That seems to be wrong, the test is declared like this in s390x/unittests.cfg :

[sieve]
file = sieve.elf
groups = selftest

# can take fairly long when KVM is nested inside z/VM
timeout = 600

And indeed, it takes way longer than 90 seconds on that CI machine, so the timeout after 90 seconds should not occur here...

Thomas

#20 lore raw

Re: [kvm-unit-tests PATCH v9 07/31] scripts: allow machine option to be specified in unittests.cfg

Quoted 148 lines · Thomas Huth
Quoted 138 lines · Nicholas Piggin
Quoted 129 lines · Thomas Huth
Quoted 116 lines · Nicholas Piggin

This allows different machines with different requirements to be supported by run_tests.sh, similarly to how different accelerators are handled.

---
   docs/unittests.txt   |  7 +++++++
   scripts/common.bash  |  8 ++++++--
   scripts/runtime.bash | 16 ++++++++++++----

   3 files changed, 25 insertions(+), 6 deletions(-)
docs/unittests.txt +0 -0
index 7cf2c55ad..6449efd78 100644
@@ -42,6 +42,13 @@ For <arch>/ directories that support multiple 

architectures, this restricts
   the test to the specified arch. By default, the test will run on any architecture.

docs/unittests.txt +3 -0
+machine
+-------
+For those architectures that support multiple machine types, this 

restricts

docs/unittests.txt +4 -0
+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 = <number>

scripts/common.bash +0 -0
index 5e9ad53e2..3aa557c8c 100644
@@ -10,6 +10,7 @@ function for_each_unittest()

       local opts
       local groups
       local arch
+    local machine
       local check
       local accel
       local timeout

scripts/common.bash +0 -0
@@ -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

scripts/common.bash +0 -0
@@ -29,6 +30,7 @@ function for_each_unittest()

               opts=""
               groups=""
               arch=""
+            machine=""
               check=""
               accel=""
               timeout=""

scripts/common.bash +0 -0
@@ -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

scripts/common.bash +0 -0
@@ -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}<&-
   }

scripts/runtime.bash +0 -0
index 177b62166..0c96d6ea2 100644
@@ -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()

scripts/runtime.bash +0 -0
@@ -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}

scripts/runtime.bash +0 -0
@@ -116,6 +117,13 @@ function run()

           return 2
       fi
+    if [ -n "$machine" ] && [ -n "$MACHINE" ] && [ "$machine" != "$MACHINE" ]; then
+        print_result "SKIP" $testname "" "$machine only"

Quoted 8 lines

+        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

For some reasons that I don't quite understand yet, this patch causes the "sieve" test to always timeout on the s390x runner, see e.g.:

Quoted 1 line

   https://gitlab.com/thuth/kvm-unit-tests/-/jobs/6798954987

How do you use the s390x runner?

Quoted 4 lines

Everything is fine in the previous patches (I pushed now the previous 5 patches to the repo):

Quoted 6 lines
Quoted 3 lines

   https://gitlab.com/kvm-unit-tests/kvm-unit-tests/-/pipelines/1281919104

Could it be that he TIMEOUT gets messed up in certain cases?

Hmm not sure yet. At least it got timeout right for the duration=90s message.

That seems to be wrong, the test is declared like this in s390x/unittests.cfg :

Quoted 7 lines

[sieve]
file = sieve.elf
groups = selftest

# can take fairly long when KVM is nested inside z/VM
timeout = 600

And indeed, it takes way longer than 90 seconds on that CI machine, so the timeout after 90 seconds should not occur here...

I guess you need to adjust arch_cmd_s390x in scripts/s390x/func.bash to be aware of the new parameter, too?

Thomas

#21 lore raw

Re: [kvm-unit-tests PATCH v9 07/31] scripts: allow machine option to be specified in unittests.cfg

Quoted 155 lines · Thomas Huth
Quoted 154 lines · Thomas Huth
Quoted 138 lines · Nicholas Piggin
Quoted 129 lines · Thomas Huth
Quoted 116 lines · Nicholas Piggin

This allows different machines with different requirements to be supported by run_tests.sh, similarly to how different accelerators are handled.

---
   docs/unittests.txt   |  7 +++++++
   scripts/common.bash  |  8 ++++++--
   scripts/runtime.bash | 16 ++++++++++++----

   3 files changed, 25 insertions(+), 6 deletions(-)
docs/unittests.txt +0 -0
index 7cf2c55ad..6449efd78 100644
@@ -42,6 +42,13 @@ For <arch>/ directories that support multiple 

architectures, this restricts
   the test to the specified arch. By default, the test will run on any architecture.

docs/unittests.txt +3 -0
+machine
+-------
+For those architectures that support multiple machine types, this 

restricts

docs/unittests.txt +4 -0
+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 = <number>

scripts/common.bash +0 -0
index 5e9ad53e2..3aa557c8c 100644
@@ -10,6 +10,7 @@ function for_each_unittest()

       local opts
       local groups
       local arch
+    local machine
       local check
       local accel
       local timeout

scripts/common.bash +0 -0
@@ -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

scripts/common.bash +0 -0
@@ -29,6 +30,7 @@ function for_each_unittest()

               opts=""
               groups=""
               arch=""
+            machine=""
               check=""
               accel=""
               timeout=""

scripts/common.bash +0 -0
@@ -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

scripts/common.bash +0 -0
@@ -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}<&-
   }

scripts/runtime.bash +0 -0
index 177b62166..0c96d6ea2 100644
@@ -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()

scripts/runtime.bash +0 -0
@@ -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}

scripts/runtime.bash +0 -0
@@ -116,6 +117,13 @@ function run()

           return 2
       fi
+    if [ -n "$machine" ] && [ -n "$MACHINE" ] && [ "$machine" != "$MACHINE" ]; then
+        print_result "SKIP" $testname "" "$machine only"

Quoted 8 lines

+        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

For some reasons that I don't quite understand yet, this patch causes the "sieve" test to always timeout on the s390x runner, see e.g.:

Quoted 1 line

   https://gitlab.com/thuth/kvm-unit-tests/-/jobs/6798954987

How do you use the s390x runner?

Quoted 4 lines

Everything is fine in the previous patches (I pushed now the previous 5 patches to the repo):

Quoted 6 lines
Quoted 3 lines

   https://gitlab.com/kvm-unit-tests/kvm-unit-tests/-/pipelines/1281919104

Could it be that he TIMEOUT gets messed up in certain cases?

Hmm not sure yet. At least it got timeout right for the duration=90s message.

That seems to be wrong, the test is declared like this in s390x/unittests.cfg :

[sieve]
file = sieve.elf
groups = selftest

# can take fairly long when KVM is nested inside z/VM
timeout = 600
Quoted 3 lines
Quoted 1 line

And indeed, it takes way longer than 90 seconds on that CI machine, so the timeout after 90 seconds should not occur here...

I guess you need to adjust arch_cmd_s390x in scripts/s390x/func.bash to be aware of the new parameter, too?

This seems to fix the problem:

scripts/s390x/func.bash +5 -4
index fa47d019..6b817727 100644
@@ -13,12 +13,13 @@ function arch_cmd_s390x()
        local kernel=$5
        local opts=$6
        local arch=$7
-       local check=$8
-       local accel=$9
-       local timeout=${10}
+       local machine=$8
+       local check=$9
+       local accel=${10}
+       local timeout=${11}
 
        # run the normal test case
-       "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout"
+       "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$machine" "$check" "$accel" "$timeout"
 
        # run PV test case
        if [ "$accel" = 'tcg' ] || grep -q "migration" <<< "$groups"; then

If you don't like to respin, I can add it to the patch while picking it up?

Thomas

#22 lore raw

Re: [kvm-unit-tests PATCH v9 07/31] scripts: allow machine option to be specified in unittests.cfg

Quoted 159 lines · Thomas Huth
Quoted 158 lines · Thomas Huth
Quoted 157 lines · Thomas Huth
Quoted 140 lines · Nicholas Piggin
Quoted 131 lines · Thomas Huth
Quoted 118 lines · Nicholas Piggin

This allows different machines with different requirements to be supported by run_tests.sh, similarly to how different accelerators are handled.

---
   docs/unittests.txt   |  7 +++++++
   scripts/common.bash  |  8 ++++++--
   scripts/runtime.bash | 16 ++++++++++++----

   3 files changed, 25 insertions(+), 6 deletions(-)
docs/unittests.txt +0 -0
index 7cf2c55ad..6449efd78 100644
@@ -42,6 +42,13 @@ For <arch>/ directories that support multiple 

architectures, this restricts
   the test to the specified arch. By default, the test will run on any architecture.

docs/unittests.txt +3 -0
+machine
+-------
+For those architectures that support multiple machine types, this 

restricts

docs/unittests.txt +4 -0
+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 = <number>

scripts/common.bash +0 -0
index 5e9ad53e2..3aa557c8c 100644
@@ -10,6 +10,7 @@ function for_each_unittest()

       local opts
       local groups
       local arch
+    local machine
       local check
       local accel
       local timeout

scripts/common.bash +0 -0
@@ -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

scripts/common.bash +0 -0
@@ -29,6 +30,7 @@ function for_each_unittest()

               opts=""
               groups=""
               arch=""
+            machine=""
               check=""
               accel=""
               timeout=""

scripts/common.bash +0 -0
@@ -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

scripts/common.bash +0 -0
@@ -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}<&-
   }

scripts/runtime.bash +0 -0
index 177b62166..0c96d6ea2 100644
@@ -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()

scripts/runtime.bash +0 -0
@@ -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}

scripts/runtime.bash +0 -0
@@ -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

Quoted 8 lines

+        machine="$MACHINE"
+    fi
+
       if [ -n "$accel" ] && [ -n "$ACCEL" ] && [ "$accel" != "$ACCEL" ]; then
           print_result "SKIP" $testname "" "$accel only, but ACCEL=$ACCEL"
           return 2

For some reasons that I don't quite understand yet, this patch causes the "sieve" test to always timeout on the s390x runner, see e.g.:

Quoted 1 line

   https://gitlab.com/thuth/kvm-unit-tests/-/jobs/6798954987

How do you use the s390x runner?

Quoted 4 lines

Everything is fine in the previous patches (I pushed now the previous 5 patches to the repo):

Quoted 6 lines
Quoted 3 lines

   https://gitlab.com/kvm-unit-tests/kvm-unit-tests/-/pipelines/1281919104

Could it be that he TIMEOUT gets messed up in certain cases?

Hmm not sure yet. At least it got timeout right for the duration=90s message.

That seems to be wrong, the test is declared like this in s390x/unittests.cfg :

[sieve]
file = sieve.elf
groups = selftest

# can take fairly long when KVM is nested inside z/VM
timeout = 600
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

And indeed, it takes way longer than 90 seconds on that CI machine, so the timeout after 90 seconds should not occur here...

I guess you need to adjust arch_cmd_s390x in scripts/s390x/func.bash to be aware of the new parameter, too?

This seems to fix the problem:

Thanks, that looks good.

Quoted 23 lines
scripts/s390x/func.bash +5 -4
index fa47d019..6b817727 100644
@@ -13,12 +13,13 @@ function arch_cmd_s390x()
         local kernel=$5
         local opts=$6
         local arch=$7
-       local check=$8
-       local accel=$9
-       local timeout=${10}
+       local machine=$8
+       local check=$9
+       local accel=${10}
+       local timeout=${11}
 
         # run the normal test case
-       "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$check" "$accel" "$timeout"
+       "$cmd" "$testname" "$groups" "$smp" "$kernel" "$opts" "$arch" "$machine" "$check" "$accel" "$timeout"
 
         # run PV test case
         if [ "$accel" = 'tcg' ] || grep -q "migration" <<< "$groups"; then
Quoted 1 line

If you don't like to respin, I can add it to the patch while picking it up?

Yeah I shouldn't resend the full series just for this. If you're happy to squash it in that would be good.

Thanks,
Nick

#23 lore raw

PATCH v9 8/31 scripts: Accommodate powerpc powernv machine differences

In reply to Nicholas Piggin

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.

---
 powerpc/unittests.cfg | 1 +
 scripts/runtime.bash  | 6 ++++--
 2 files changed, 5 insertions(+), 2 deletions(-)
powerpc/unittests.cfg +1 -0
index 699736926..f562de9f4 100644
@@ -4,6 +4,7 @@
 # powerpc specifics:
 #
 # file = <name>.elf             # powerpc uses .elf files
+# machine = pseries|powernv
 ##############################################################################
 
 #
scripts/runtime.bash +4 -2
index 0c96d6ea2..4b9c7d6b7 100644
@@ -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"
Signature · 1 line
2.43.0
#24 lore raw

PATCH v9 9/31 powerpc: Support powernv machine with QEMU TCG

In reply to Nicholas Piggin

Add support for QEMU's powernv machine. This uses standard firmware (skiboot) rather than a minimal firmware shim.

---
 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
lib/powerpc/asm/processor.h +23 -0
index e415f9235..9d8061962 100644
@@ -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_ */
lib/powerpc/asm/reg.h +4 -0
index c80b32059..782e75527 100644
@@ -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
lib/powerpc/hcall.c +2 -2
index b4d39ac65..45f201315 100644
@@ -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 */
lib/powerpc/io.c +25 -2
index a381688bc..ab7bb843c 100644
@@ -9,13 +9,33 @@
 #include <asm/spinlock.h>
 #include <asm/rtas.h>
 #include <asm/setup.h>
+#include <asm/processor.h>
 #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();
 }
lib/powerpc/io.h +6 -0
index d4f21ba15..943bf142b 100644
@@ -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
lib/powerpc/processor.c +37 -0
index 114584024..1b4bb0d61 100644
@@ -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);
+}
lib/powerpc/setup.c +11 -3
index d98f66fae..89e5157f2 100644
@@ -19,6 +19,7 @@
 #include <asm/setup.h>
 #include <asm/page.h>
 #include <asm/ptrace.h>
+#include <asm/processor.h>
 #include <asm/hcall.h>
 #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
lib/ppc64/asm/opal.h new file +15 -0
new file mode 100644
index 000000000..de64e2c8d
@@ -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
lib/ppc64/opal-calls.S new file +50 -0

50 lines not on this page · raw message

lib/ppc64/opal.c new file +76 -0

76 lines not on this page · raw message

powerpc/Makefile.ppc64 +2 -0
index eb682c226..a18a9628f 100644
@@ -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
powerpc/cstart64.S +7 -0
index 07d297f61..405cb0561 100644
@@ -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
powerpc/run +34 -8

63 lines not on this page · raw message

powerpc/unittests.cfg +9 -1
index f562de9f4..4c0c6ddea 100644
@@ -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
Signature · 1 line
2.43.0
#25 lore raw

PATCH v9 10/31 powerpc: Fix emulator illegal instruction test for powernv

In reply to Nicholas Piggin

Illegal instructions cause 0xe40 (HEAI) interrupts rather than program interrupts.

---
 lib/powerpc/asm/processor.h |  1 +
 lib/powerpc/setup.c         | 13 +++++++++++++
 powerpc/emulator.c          | 16 ++++++++++++++++
 3 files changed, 30 insertions(+)
lib/powerpc/asm/processor.h +1 -0
index 9d8061962..cf1b9d8ff 100644
@@ -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)
 {
lib/powerpc/setup.c +13 -0
index 89e5157f2..3c81aee9e 100644
@@ -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)
powerpc/emulator.c +16 -0
index 39dd59645..af5174944 100644
@@ -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++) {
Signature · 1 line
2.43.0
#26 lore raw

PATCH v9 11/31 powerpc/sprs: Test hypervisor registers on powernv machine

In reply to Nicholas Piggin

This enables HV privilege registers to be tested with the powernv machine.

---
 powerpc/sprs.c | 33 +++++++++++++++++++++++++--------
 1 file changed, 25 insertions(+), 8 deletions(-)
powerpc/sprs.c +25 -8
index c25dac1f6..de9e87a21 100644
@@ -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) {
Signature · 1 line
2.43.0
#27 lore raw

PATCH v9 12/31 powerpc: general interrupt tests

In reply to Nicholas Piggin

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.

---
 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
lib/powerpc/asm/processor.h +4 -0
index cf1b9d8ff..eed37d1f4 100644
@@ -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)
 {
lib/powerpc/asm/reg.h +17 -0
index 782e75527..d6097f48f 100644
@@ -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
lib/powerpc/setup.c +11 -0
index 3c81aee9e..9b665f59c 100644
@@ -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)
lib/ppc64/asm/ptrace.h +16 -0
index 12de7499b..db263a59e 100644
@@ -5,6 +5,9 @@
 #define STACK_FRAME_OVERHEAD    112     /* size of minimum stack frame */
 
 #ifndef __ASSEMBLY__
+
+#include <asm/reg.h>
+
 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)
 
powerpc/Makefile.common +2 -1
index 1e181da69..68165fc25 100644
@@ -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)
powerpc/interrupts.c new file +414 -0

414 lines not on this page · raw message

powerpc/unittests.cfg +3 -0
index 4c0c6ddea..03d7b60e5 100644
@@ -66,6 +66,9 @@ groups = rtas
 [emulator]
 file = emulator.elf
 
+[interrupts]
+file = interrupts.elf
+
 [h_cede_tm]
 file = tm.elf
 machine = pseries
Signature · 1 line
2.43.0
Acked-by on v9 12/31
#28 lore raw

Re: [kvm-unit-tests PATCH v9 12/31] powerpc: general interrupt tests

Quoted 16 lines · Nicholas Piggin

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.

---
  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(-)
Quoted 1 line

create mode 100644 powerpc/interrupts.c

#29 lore raw

PATCH v9 13/31 powerpc: Add rtas stop-self support

In reply to Nicholas Piggin

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.

---
 lib/powerpc/asm/rtas.h |  2 ++
 lib/powerpc/rtas.c     | 78 +++++++++++++++++++++++++++++++++---------
 2 files changed, 64 insertions(+), 16 deletions(-)
lib/powerpc/asm/rtas.h +2 -0
index 6fb407a18..364bf9355 100644
@@ -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
lib/powerpc/rtas.c +62 -16

108 lines not on this page · raw message

Signature · 1 line
2.43.0
#30 lore raw

PATCH v9 14/31 powerpc: Remove broken SMP exception stack setup

In reply to Nicholas Piggin

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.

---
 lib/powerpc/setup.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
lib/powerpc/setup.c +8 -8
index 9b665f59c..58be93f08 100644
@@ -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();
 
 	/*
Signature · 1 line
2.43.0
Reviewed-by on v9 14/31
#31 lore raw

Re: [kvm-unit-tests PATCH v9 14/31] powerpc: Remove broken SMP exception stack setup

Quoted 4 lines · Nicholas Piggin

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.

So secondary CPUs currently must not run into any exceptions?

Quoted 8 lines

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.

---
  lib/powerpc/setup.c | 16 ++++++++--------
  1 file changed, 8 insertions(+), 8 deletions(-)
#32 lore raw

Re: [kvm-unit-tests PATCH v9 14/31] powerpc: Remove broken SMP exception stack setup

Quoted 7 lines · Thomas Huth
Quoted 4 lines · Nicholas Piggin

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.

So secondary CPUs currently must not run into any exceptions?

Yes, at the moment. It was broken anyway.

Patch 16 creates a proper environment for secondaries, including taking interrupts.

Thanks,
Nick

Quoted 11 lines
Quoted 9 lines

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.

---
  lib/powerpc/setup.c | 16 ++++++++--------
  1 file changed, 8 insertions(+), 8 deletions(-)
#33 lore raw

PATCH v9 15/31 powerpc: Enable page alloc operations

In reply to Nicholas Piggin

These will be used for stack allocation for secondary CPUs.

---
 lib/powerpc/setup.c     | 8 ++++++++
 powerpc/Makefile.common | 1 +
 2 files changed, 9 insertions(+)
lib/powerpc/setup.c +8 -0
index 58be93f08..73ca2f931 100644
@@ -15,6 +15,7 @@
 #include <devicetree.h>
 #include <alloc.h>
 #include <alloc_phys.h>
+#include <alloc_page.h>
 #include <argv.h>
 #include <asm/setup.h>
 #include <asm/page.h>
@@ -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
powerpc/Makefile.common +1 -0
index 68165fc25..6374418d2 100644
@@ -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
Signature · 1 line
2.43.0
#35 lore raw

PATCH v9 16/31 powerpc: add SMP and IPI support

In reply to Nicholas Piggin

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.

---
 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
lib/powerpc/asm/processor.h +23 -0
index eed37d1f4..a3859b5d4 100644
@@ -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.
lib/powerpc/asm/reg.h +1 -0
index d6097f48f..d2ca964c4 100644
@@ -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)
lib/powerpc/asm/setup.h +0 -2
index cc7cf5e25..9ca318ce6 100644
@@ -8,8 +8,6 @@
 #include <libcflat.h>
 
 #define NR_CPUS			8	/* arbitrarily set for now */
-extern u32 cpus[NR_CPUS];
-extern int nr_cpus;
 
 extern uint64_t tb_hz;
 
lib/powerpc/asm/smp.h +34 -10

55 lines not on this page · raw message

lib/powerpc/io.c +10 -5
index ab7bb843c..cb7f2f050 100644
@@ -10,6 +10,7 @@
 #include <asm/rtas.h>
 #include <asm/setup.h>
 #include <asm/processor.h>
+#include <asm/atomic.h>
 #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();
 }
lib/powerpc/processor.c +5 -2
index 1b4bb0d61..a6ce3c905 100644
@@ -13,6 +13,7 @@
 #include <asm/barrier.h>
 #include <asm/hcall.h>
 #include <asm/handlers.h>
+#include <asm/smp.h>
 
 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();
 }
lib/powerpc/setup.c +66 -24

159 lines not on this page · raw message

lib/powerpc/smp.c +301 -36

396 lines not on this page · raw message

lib/ppc64/asm-offsets.c +9 -0
index 7843a20b4..ba1a045df 100644
@@ -6,6 +6,8 @@
 #include <libcflat.h>
 #include <kbuild.h>
 #include <asm/ptrace.h>
+#include <asm/setup.h>
+#include <asm/smp.h>
 
 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;
 }
lib/ppc64/asm/atomic.h new file +6 -0
new file mode 100644
index 000000000..0f461b9ce
@@ -0,0 +1,6 @@
+#ifndef _POWERPC_ATOMIC_H_
+#define _POWERPC_ATOMIC_H_
+
+#include "asm-generic/atomic.h"
+
+#endif /* _POWERPC_ATOMIC_H_ */
lib/ppc64/asm/barrier.h +2 -0
index 76f6efa78..d2df29520 100644
@@ -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")
lib/ppc64/asm/opal.h +7 -0
index de64e2c8d..6c3e9ffe2 100644
@@ -2,14 +2,21 @@
 #ifndef _ASMPPC64_OPAL_H_
 #define _ASMPPC64_OPAL_H_
 
+#include <stdint.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_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
powerpc/Makefile.common +1 -0
index 6374418d2..b98f71c2f 100644
@@ -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
 
powerpc/cstart64.S +48 -2

68 lines not on this page · raw message

powerpc/selftest.c +3 -1
index 7acff7104..8d1a2c767 100644
@@ -8,6 +8,7 @@
 #include <libcflat.h>
 #include <util.h>
 #include <asm/setup.h>
+#include <asm/smp.h>
 
 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;
 		}
 
powerpc/smp.c new file +348 -0

348 lines not on this page · raw message

powerpc/tm.c +3 -2
index d9e7f455d..507eaf492 100644
@@ -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");
powerpc/unittests.cfg +8 -0
index 03d7b60e5..aa707e0f3 100644
@@ -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
Signature · 1 line
2.43.0
Acked-by on v9 16/31
#36 lore raw

Re: [kvm-unit-tests PATCH v9 16/31] powerpc: add SMP and IPI support

Quoted 8 lines · Nicholas Piggin

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.

I now skimmed through the patch and it looks fine so far:

#37 lore raw

PATCH v9 17/31 powerpc: Add cpu_relax

In reply to Nicholas Piggin

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.

---
 lib/ppc64/asm/barrier.h | 1 +
 powerpc/sprs.c          | 4 ++--
 2 files changed, 3 insertions(+), 2 deletions(-)
lib/ppc64/asm/barrier.h +1 -0
index d2df29520..475434b6a 100644
@@ -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")
powerpc/sprs.c +2 -2
index de9e87a21..c5844985a 100644
@@ -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 */
 };
 
Signature · 1 line
2.43.0
Reviewed-by on v9 17/31
#38 lore raw

Re: [kvm-unit-tests PATCH v9 17/31] powerpc: Add cpu_relax

Quoted 9 lines · Nicholas Piggin

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.

---
  lib/ppc64/asm/barrier.h | 1 +
  powerpc/sprs.c          | 4 ++--
  2 files changed, 3 insertions(+), 2 deletions(-)
#39 lore raw

PATCH v9 18/31 powerpc: Permit ACCEL=tcg,thread=single

In reply to Nicholas Piggin

Modify run script to permit single vs mttcg threading, add a thread=single smp case to unittests.cfg.

---
 powerpc/run           | 4 ++--
 powerpc/unittests.cfg | 6 ++++++
 2 files changed, 8 insertions(+), 2 deletions(-)
powerpc/run +2 -2
index 172f32a46..27abf1ef6 100755
@@ -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"
 
powerpc/unittests.cfg +6 -0
index aa707e0f3..5c458996b 100644
@@ -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
Signature · 1 line
2.43.0
Reviewed-by on v9 18/31
#40 lore raw

Re: [kvm-unit-tests PATCH v9 18/31] powerpc: Permit ACCEL=tcg,thread=single

Quoted 8 lines · Nicholas Piggin

Modify run script to permit single vs mttcg threading, add a thread=single smp case to unittests.cfg.

---
  powerpc/run           | 4 ++--
  powerpc/unittests.cfg | 6 ++++++
  2 files changed, 8 insertions(+), 2 deletions(-)
#41 lore raw

PATCH v9 19/31 powerpc: Avoid using larx/stcx. in spinlocks when only one CPU is running

In reply to Nicholas Piggin

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.

---
 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
lib/powerpc/asm/smp.h +1 -0
index c45988bfa..66188b9dd 100644
@@ -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");
lib/powerpc/smp.c +5 -0
index 27b169841..73c0ef214 100644
@@ -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;
 }
lib/powerpc/spinlock.c new file +29 -0
new file mode 100644
index 000000000..623a1f2c1
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: LGPL-2.0 */
+#include <asm/spinlock.h>
+#include <asm/smp.h>
+
+/*
+ * 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);
+	}
+}
lib/ppc64/asm/spinlock.h +6 -1
index f59eed191..b952386da 100644
@@ -1,6 +1,11 @@
 #ifndef _ASMPPC64_SPINLOCK_H_
 #define _ASMPPC64_SPINLOCK_H_
 
-#include <asm-generic/spinlock.h>
+struct spinlock {
+	unsigned int v;
+};
+
+void spin_lock(struct spinlock *lock);
+void spin_unlock(struct spinlock *lock);
 
 #endif /* _ASMPPC64_SPINLOCK_H_ */
powerpc/Makefile.common +1 -0
index b98f71c2f..1ee9c25d6 100644
@@ -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
 
Signature · 1 line
2.43.0
#42 lore raw

Re: [kvm-unit-tests PATCH v9 19/31] powerpc: Avoid using larx/stcx. in spinlocks when only one CPU is running

Quoted 3 lines · Nicholas Piggin

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.

I'm having a hard time to understand that patch description. Maybe you could rephrase it / elaborate what's the exact problem here?

Thanks,
Thomas

Quoted 120 lines
---
  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

lib/powerpc/asm/smp.h +1 -0
index c45988bfa..66188b9dd 100644
@@ -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");
lib/powerpc/smp.c +5 -0
index 27b169841..73c0ef214 100644
@@ -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;
  }
lib/powerpc/spinlock.c new file +29 -0
new file mode 100644
index 000000000..623a1f2c1
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: LGPL-2.0 */
+#include <asm/spinlock.h>
+#include <asm/smp.h>
+
+/*
+ * 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);
+	}
+}
lib/ppc64/asm/spinlock.h +6 -1
index f59eed191..b952386da 100644
@@ -1,6 +1,11 @@
  #ifndef _ASMPPC64_SPINLOCK_H_
  #define _ASMPPC64_SPINLOCK_H_
 
-#include <asm-generic/spinlock.h>
+struct spinlock {
+	unsigned int v;
+};
+
+void spin_lock(struct spinlock *lock);
+void spin_unlock(struct spinlock *lock);
 
  #endif /* _ASMPPC64_SPINLOCK_H_ */
powerpc/Makefile.common +1 -0
index b98f71c2f..1ee9c25d6 100644
@@ -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
 
#43 lore raw

Re: [kvm-unit-tests PATCH v9 19/31] powerpc: Avoid using larx/stcx. in spinlocks when only one CPU is running

Quoted 7 lines · Thomas Huth
Quoted 3 lines · Nicholas Piggin

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.

I'm having a hard time to understand that patch description. Maybe you could rephrase it / elaborate what's the exact problem here?

Yeah that's wrong, "harness uses spinlocks *which are* implemented with larx/stcx."

The problem IIRC was only testing migration of reservations, so I should be explicit about that in the changelog.

You could leave this out for now.

Thanks,
Nick

#44 lore raw

PATCH v9 20/31 powerpc: Add atomics tests

In reply to 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
powerpc/Makefile.common +1 -0
index 1ee9c25d6..420103c87 100644
@@ -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 \
powerpc/atomics.c new file +375 -0

375 lines not on this page · raw message

powerpc/unittests.cfg +9 -0
index 5c458996b..a4210ab2a 100644
@@ -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
Signature · 1 line
2.43.0
#45 lore raw

Re: [kvm-unit-tests PATCH v9 20/31] powerpc: Add atomics tests

Quoted 2 lines · Nicholas Piggin

---

Please provide at least a short patch description about what is being tested here!

Thanks,
Thomas

#46 lore raw

Re: [kvm-unit-tests PATCH v9 20/31] powerpc: Add atomics tests

Quoted 6 lines · Thomas Huth
Quoted 2 lines · Nicholas Piggin

---

Please provide at least a short patch description about what is being tested here!

Will do.

Thanks,
Nick

#47 lore raw

PATCH v9 21/31 powerpc: Add timebase tests

In reply to Nicholas Piggin

This has a known failure on QEMU TCG machines where the decrementer interrupt is not lowered when the DEC wraps from -ve to +ve.

---
 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
lib/powerpc/asm/reg.h +1 -0
index d2ca964c4..12f9e8ac6 100644
@@ -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)
powerpc/Makefile.common +1 -0
index 420103c87..b273033d1 100644
@@ -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)
powerpc/timebase.c new file +331 -0

331 lines not on this page · raw message

powerpc/unittests.cfg +8 -0
index a4210ab2a..39e6dea3c 100644
@@ -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
Signature · 1 line
2.43.0
#48 lore raw

Re: [kvm-unit-tests PATCH v9 21/31] powerpc: Add timebase tests

Quoted 2 lines · Nicholas Piggin

This has a known failure on QEMU TCG machines where the decrementer interrupt is not lowered when the DEC wraps from -ve to +ve.

Would it then make sense to mark the test with accel = kvm to avoid the test failure when running with TCG?

Quoted 40 lines
powerpc/timebase.c new file +34 -0
new file mode 100644
index 000000000..02a4e33c0
@@ -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 <libcflat.h>
+#include <util.h>
+#include <migrate.h>
+#include <alloc.h>
+#include <asm/handlers.h>
+#include <devicetree.h>
+#include <asm/hcall.h>
+#include <asm/processor.h>
+#include <asm/time.h>
+#include <asm/barrier.h>
+
+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);

powerpc/timebase.c line 44

Quoted 10 lines
powerpc/timebase.c new file +10 -0
+
+	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);

What sense does it make to run this for each CPU node if the cpu_dec_bits function always overwrites the global dec_bits variable? Wouldn't it be sufficient to run this for the first node only? Or should the cpu_dec_bits function maybe check that all nodes have the same value?

Quoted 12 lines
powerpc/timebase.c new file +12 -0
+	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;

powerpc/timebase.c line 66

Quoted 10 lines
powerpc/timebase.c new file +10 -0
+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");

If you use >= for testing, it could also mean that the TB stays at the same value, so "timebase is incrementing" sounds misleading. Maybe rather "timebase is not decreasing" ? Or wait a little bit, then check with ">" only ?

Quoted 97 lines
powerpc/timebase.c new file +97 -0
+}
+
+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;

powerpc/timebase.c line 173

Quoted 10 lines
powerpc/timebase.c new file +10 -0
+
+	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");

I'd rather say "not running on powernv machine"

powerpc/timebase.c line 175

Quoted 2 lines
powerpc/timebase.c new file +2 -0
+		return;
+	}

Thomas

#49 lore raw

Re: [kvm-unit-tests PATCH v9 21/31] powerpc: Add timebase tests

Quoted 6 lines · Thomas Huth
Quoted 2 lines · Nicholas Piggin

This has a known failure on QEMU TCG machines where the decrementer interrupt is not lowered when the DEC wraps from -ve to +ve.

Would it then make sense to mark the test with accel = kvm to avoid the test failure when running with TCG?

Still want to test it with TCG though, which had quite a few bugs I used these tests to fix. It is marked as known fail for TCG (once the later host accel patch is merged).

Quoted 11 lines

powerpc/timebase.c line 44

Quoted 6 lines
powerpc/timebase.c new file +6 -0
+/* 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);

What sense does it make to run this for each CPU node if the cpu_dec_bits function always overwrites the global dec_bits variable? Wouldn't it be sufficient to run this for the first node only? Or should the cpu_dec_bits function maybe check that all nodes have the same value?

Yeah it could use first subnode.

Quoted 18 lines
Quoted 18 lines
powerpc/timebase.c new file +18 -0
+	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;
+
Quoted 8 lines

powerpc/timebase.c line 66

Quoted 4 lines
powerpc/timebase.c new file +4 -0
+	tb = get_tb();
+	if (do_migrate)
+		migrate();
+	report(get_tb() >= tb, "timebase is incrementing");

If you use >= for testing, it could also mean that the TB stays at the same value, so "timebase is incrementing" sounds misleading. Maybe rather "timebase is not decreasing" ? Or wait a little bit, then check with ">" only ?

Yeah, maybe first immediate test could ensure it doesn't go backward, then wait a bit and check it increments.

Quoted 101 lines
Quoted 101 lines
powerpc/timebase.c new file +101 -0
+}
+
+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);
+}
+
Quoted 8 lines

powerpc/timebase.c line 173

Quoted 6 lines
powerpc/timebase.c new file +6 -0
+static void test_hdec(int argc, char **argv)
+{
+	uint64_t tb1, tb2, hdec;
+
+	if (!machine_is_powernv()) {
+		report_skip("skipping on !powernv machine");

I'd rather say "not running on powernv machine"

Okay.

Thanks,
Nick

#50 lore raw

PATCH v9 22/31 powerpc: Add MMU support

In reply to Nicholas Piggin

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).

---
 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
configure +27 -12
index 0e0a28825..d744ec4dc 100755
@@ -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 <<EOF >> 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 <<EOF >> lib/config.h
+
 #define CONFIG_PAGE_SIZE _AC(${page_size}, UL)
 
 EOF
lib/powerpc/asm/hcall.h +6 -0
index e0f5009e3..3b44dd204 100644
@@ -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)
lib/powerpc/asm/processor.h +1 -0
index a3859b5d4..d348239c5 100644
@@ -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;
lib/powerpc/asm/reg.h +3 -0
index 12f9e8ac6..b2fab4313 100644
@@ -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)
lib/powerpc/asm/smp.h +2 -0
index 66188b9dd..3d7d3d08f 100644
@@ -3,6 +3,7 @@
 
 #include <libcflat.h>
 #include <asm/processor.h>
+#include <asm/page.h>
 
 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;
lib/powerpc/processor.c +9 -0
index a6ce3c905..09f6bb9d8 100644
@@ -13,6 +13,7 @@
 #include <asm/barrier.h>
 #include <asm/hcall.h>
 #include <asm/handlers.h>
+#include <asm/mmu.h>
 #include <asm/smp.h>
 
 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) {
lib/powerpc/setup.c +6 -2
index 622b99e5d..53ecbb830 100644
@@ -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;
lib/ppc64/asm/mmu.h new file +11 -0
new file mode 100644
index 000000000..fadeee4bc
@@ -0,0 +1,11 @@
+#ifndef _ASMPOWERPC_MMU_H_
+#define _ASMPOWERPC_MMU_H_
+
+#include <asm/pgtable.h>
+
+bool vm_available(void);
+bool mmu_enabled(void);
+void mmu_enable(pgd_t *pgtable);
+void mmu_disable(void);
+
+#endif
lib/ppc64/asm/page.h +65 -1

66 lines not on this page · raw message

lib/ppc64/asm/pgtable-hwdef.h new file +66 -0

66 lines not on this page · raw message

lib/ppc64/asm/pgtable.h new file +125 -0

125 lines not on this page · raw message

lib/ppc64/mmu.c new file +281 -0

281 lines not on this page · raw message

lib/ppc64/opal-calls.S +2 -2
index 8cb4c3e91..bc9c51f84 100644
@@ -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
powerpc/Makefile.common +3 -1
index b273033d1..7378b1137 100644
@@ -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
powerpc/Makefile.ppc64 +1 -0
index a18a9628f..2466471f9 100644
@@ -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
 
powerpc/interrupts.c +85 -11

160 lines not on this page · raw message

powerpc/mmu.c new file +283 -0

283 lines not on this page · raw message

powerpc/unittests.cfg +4 -0
index 39e6dea3c..286e11782 100644
@@ -69,6 +69,10 @@ file = emulator.elf
 [interrupts]
 file = interrupts.elf
 
+[mmu]
+file = mmu.elf
+smp = $MAX_SMP
+
 [smp]
 file = smp.elf
 smp = 2
Signature · 1 line
2.43.0
#51 lore raw

Re: [kvm-unit-tests PATCH v9 22/31] powerpc: Add MMU support

Quoted 9 lines · Nicholas Piggin

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).

---

...

Quoted 55 lines
lib/ppc64/mmu.c new file +49 -0
new file mode 100644
index 000000000..5307cd862
@@ -0,0 +1,281 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Radix MMU support
+ *
+ * Copyright (C) 2024, IBM Inc, Nicholas Piggin <[email protected]>
+ *
+ * Derived from Linux kernel MMU code.
+ */
+#include <asm/mmu.h>
+#include <asm/setup.h>
+#include <asm/smp.h>
+#include <asm/page.h>
+#include <asm/io.h>
+#include <asm/processor.h>
+#include <asm/hcall.h>
+
+#include "alloc_page.h"
+#include "vmalloc.h"
+#include <asm/pgtable-hwdef.h>
+#include <asm/pgtable.h>
+
+#include <linux/compiler.h>
+
+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)
+{

lib/ppc64/mmu.c line 59

Quoted 10 lines
lib/ppc64/mmu.c new file +10 -0
+	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");

That's a very long line, please split it up after every assembly instruction (using \n for new lines).

Quoted 1 line
lib/ppc64/mmu.c new file +1 -0
+}

...

Quoted 17 lines
powerpc/mmu.c new file +11 -0
new file mode 100644
index 000000000..fef790506
@@ -0,0 +1,283 @@
+/* SPDX-License-Identifier: LGPL-2.0-only */
+/*
+ * MMU Tests
+ *
+ * Copyright 2024 Nicholas Piggin, IBM Corp.
+ */
+#include <libcflat.h>
+#include <asm/atomic.h>
+#include <asm/barrier.h>
+#include <asm/processor.h>
+#include <asm/mmu.h>

powerpc/mmu.c line 21

Quoted 10 lines
powerpc/mmu.c new file +10 -0
+#include <asm/smp.h>
+#include <asm/setup.h>
+#include <asm/ppc_asm.h>
+#include <vmalloc.h>
+#include <devicetree.h>
+
+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");
+}

Same function again? Maybe it could go into mmu.h instead?

powerpc/mmu.c line 26

Quoted 4 lines
powerpc/mmu.c new file +4 -0
+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");
+}

Please also split up the above long line.

It would also be cool if you could get one of the other ppc guys at IBM to review this patch, since I don't have a clue about this MMU stuff at all.

Thanks,
Thomas

#52 lore raw

Re: [kvm-unit-tests PATCH v9 22/31] powerpc: Add MMU support

Quoted 112 lines · Thomas Huth
Quoted 9 lines · Nicholas Piggin

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).

---

...

Quoted 55 lines
lib/ppc64/mmu.c new file +49 -0
new file mode 100644
index 000000000..5307cd862
@@ -0,0 +1,281 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Radix MMU support
+ *
+ * Copyright (C) 2024, IBM Inc, Nicholas Piggin <[email protected]>
+ *
+ * Derived from Linux kernel MMU code.
+ */
+#include <asm/mmu.h>
+#include <asm/setup.h>
+#include <asm/smp.h>
+#include <asm/page.h>
+#include <asm/io.h>
+#include <asm/processor.h>
+#include <asm/hcall.h>
+
+#include "alloc_page.h"
+#include "vmalloc.h"
+#include <asm/pgtable-hwdef.h>
+#include <asm/pgtable.h>
+
+#include <linux/compiler.h>
+
+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)
+{

lib/ppc64/mmu.c line 59

Quoted 10 lines
lib/ppc64/mmu.c new file +10 -0
+	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");

That's a very long line, please split it up after every assembly instruction (using \n for new lines).

Quoted 1 line
lib/ppc64/mmu.c new file +1 -0
+}

...

Quoted 17 lines
powerpc/mmu.c new file +11 -0
new file mode 100644
index 000000000..fef790506
@@ -0,0 +1,283 @@
+/* SPDX-License-Identifier: LGPL-2.0-only */
+/*
+ * MMU Tests
+ *
+ * Copyright 2024 Nicholas Piggin, IBM Corp.
+ */
+#include <libcflat.h>
+#include <asm/atomic.h>
+#include <asm/barrier.h>
+#include <asm/processor.h>
+#include <asm/mmu.h>

powerpc/mmu.c line 21

Quoted 10 lines
powerpc/mmu.c new file +10 -0
+#include <asm/smp.h>
+#include <asm/setup.h>
+#include <asm/ppc_asm.h>
+#include <vmalloc.h>
+#include <devicetree.h>
+
+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");
+}

Same function again? Maybe it could go into mmu.h instead?

Quoted 6 lines

powerpc/mmu.c line 26

Quoted 4 lines
powerpc/mmu.c new file +4 -0
+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");
+}

Please also split up the above long line.

I'll try to improve the lines.

Quoted 2 lines

It would also be cool if you could get one of the other ppc guys at IBM to review this patch, since I don't have a clue about this MMU stuff at all.

It would be.

Thanks,
Nick

#53 lore raw

PATCH v9 23/31 common/sieve: Use vmalloc.h for setup_mmu definition

In reply to Nicholas Piggin

There is no good reason to put setup_vm in libcflat.h when it's defined in vmalloc.h.

Cc Paolo Bonzini <[email protected]>
Cc Thomas Huth <[email protected]>
Cc Janosch Frank <[email protected]>
Cc Claudio Imbrenda <[email protected]>
Cc Nico Böhr <[email protected]>
Cc David Hildenbrand <[email protected]>
---
 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(-)
common/sieve.c +1 -0
index 8150f2d98..8fe05ef13 100644
@@ -1,5 +1,6 @@
 #include "alloc.h"
 #include "libcflat.h"
+#include "vmalloc.h"
 
 static int sieve(char* data, int size)
 {
lib/libcflat.h +0 -2
index ae3c2c6d0..16a838808 100644
@@ -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)
lib/s390x/io.c +1 -0
index fb7b7ddaa..2b28ccaa0 100644
@@ -10,6 +10,7 @@
  */
 #include <libcflat.h>
 #include <argv.h>
+#include <vmalloc.h>
 #include <asm/spinlock.h>
 #include <asm/facility.h>
 #include <asm/sigp.h>
lib/s390x/uv.h +1 -0
index 286933caa..00a370410 100644
@@ -4,6 +4,7 @@
 
 #include <sie.h>
 #include <asm/pgtable.h>
+#include <vmalloc.h>
 
 bool uv_os_is_guest(void);
 bool uv_os_is_host(void);
lib/x86/vm.h +1 -0
index 4b714bad7..cf39787aa 100644
@@ -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"
s390x/mvpg.c +1 -0
index 62d42e364..10909fb7a 100644
@@ -15,6 +15,7 @@
 #include <asm/page.h>
 #include <asm/facility.h>
 #include <asm/mem.h>
+#include <vmalloc.h>
 #include <alloc_page.h>
 #include <bitops.h>
 #include <hardware.h>
s390x/selftest.c +1 -0
index 92ed4e5d3..3eaae9b06 100644
@@ -9,6 +9,7 @@
 #include <libcflat.h>
 #include <util.h>
 #include <alloc.h>
+#include <vmalloc.h>
 #include <asm/interrupt.h>
 #include <asm/barrier.h>
 #include <asm/pgtable.h>
x86/pmu.c +1 -0
index 47a1a602a..7062c1ad9 100644
@@ -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"
x86/pmu_lbr.c +1 -0
index 40b63fa3d..c6f010847 100644
@@ -2,6 +2,7 @@
 #include "x86/processor.h"
 #include "x86/pmu.h"
 #include "x86/desc.h"
+#include "vmalloc.h"
 
 #define N 1000000
 
x86/vmexit.c +1 -0
index eb5d3023a..48a38f60f 100644
@@ -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"
x86/vmware_backdoors.c +1 -0
index bc1002056..f8cf7ecb1 100644
@@ -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"
Signature · 1 line
2.43.0
Reviewed-by on v9 23/31
#54 lore raw

Re: [kvm-unit-tests PATCH v9 23/31] common/sieve: Use vmalloc.h for setup_mmu definition

Quoted 13 lines · Nicholas Piggin

There is no good reason to put setup_vm in libcflat.h when it's defined in vmalloc.h.

Cc Paolo Bonzini <[email protected]>
Cc Thomas Huth <[email protected]>
Cc Janosch Frank <[email protected]>
Cc Claudio Imbrenda <[email protected]>
Cc Nico Böhr <[email protected]>
Cc David Hildenbrand <[email protected]>
Quoted 1 line

---

#55 lore raw

PATCH v9 24/31 common/sieve: Support machines without MMU

In reply to Nicholas Piggin

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.

---
 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(-)
common/sieve.c +8 -6
index 8fe05ef13..db084691a 100644
@@ -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;
lib/ppc64/asm/mmu.h +0 -1
index fadeee4bc..eaff0f1f7 100644
@@ -3,7 +3,6 @@
 
 #include <asm/pgtable.h>
 
-bool vm_available(void);
 bool mmu_enabled(void);
 void mmu_enable(pgd_t *pgtable);
 void mmu_disable(void);
lib/ppc64/mmu.c +1 -1
index 5307cd862..84be31752 100644
@@ -23,7 +23,7 @@
 
 static pgd_t *identity_pgd;
 
-bool vm_available(void)
+bool vm_available(void) /* weak override */
 {
 	return cpu_has_radix;
 }
lib/vmalloc.c +7 -0
index 572682576..cf2ef7a70 100644
@@ -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;
 
lib/vmalloc.h +2 -0
index 0269fdde9..e81be39f4 100644
@@ -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 */
Signature · 1 line
2.43.0
Reviewed-by on v9 24/31
#56 lore raw

Re: [kvm-unit-tests PATCH v9 24/31] common/sieve: Support machines without MMU

Quoted 9 lines · Nicholas Piggin

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.

---

#57 lore raw

PATCH v9 25/31 powerpc: Add sieve.c common test

In reply to Nicholas Piggin

Now that sieve copes with lack of MMU support, it can be run by powerpc.

---
 powerpc/Makefile.common | 1 +
 powerpc/sieve.c         | 1 +
 powerpc/unittests.cfg   | 3 +++
 3 files changed, 5 insertions(+)
 create mode 120000 powerpc/sieve.c
powerpc/Makefile.common +1 -0
index 7378b1137..b2e89e4fd 100644
@@ -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 \
powerpc/sieve.c new file +1 -0
new file mode 120000
index 000000000..fe299f309
@@ -0,0 +1 @@
+../common/sieve.c
\ No newline at end of file
powerpc/unittests.cfg +3 -0
index 286e11782..c7cda819d 100644
@@ -120,3 +120,6 @@ file = sprs.elf
 machine = pseries
 extra_params = -append '-w'
 groups = migration
+
+[sieve]
+file = sieve.elf
Signature · 1 line
2.43.0
Reviewed-by on v9 25/31
#58 lore raw

Re: [kvm-unit-tests PATCH v9 25/31] powerpc: Add sieve.c common test

Quoted 10 lines · Nicholas Piggin

Now that sieve copes with lack of MMU support, it can be run by powerpc.

---
  powerpc/Makefile.common | 1 +
  powerpc/sieve.c         | 1 +
  powerpc/unittests.cfg   | 3 +++
  3 files changed, 5 insertions(+)

create mode 120000 powerpc/sieve.c

#59 lore raw

PATCH v9 26/31 powerpc: add usermode support

In reply to Nicholas Piggin

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.

---
 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(-)
lib/powerpc/asm/processor.h +9 -0
index d348239c5..749155696 100644
@@ -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_ */
lib/powerpc/asm/reg.h +1 -0
index b2fab4313..69ef21adb 100644
@@ -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
lib/powerpc/asm/smp.h +1 -0
index 3d7d3d08f..e591f6ab0 100644
@@ -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;
 };
lib/powerpc/io.c +7 -0
index cb7f2f050..5c2810884 100644
@@ -11,6 +11,7 @@
 #include <asm/setup.h>
 #include <asm/processor.h>
 #include <asm/atomic.h>
+#include <asm/smp.h>
 #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();
 }
 
 /*
lib/powerpc/processor.c +38 -0
index 09f6bb9d8..6c3000d5c 100644
@@ -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));
+}
lib/powerpc/rtas.c +3 -0
index b477a38e0..9c1e0affc 100644
@@ -9,6 +9,7 @@
 #include <libfdt/libfdt.h>
 #include <devicetree.h>
 #include <asm/spinlock.h>
+#include <asm/smp.h>
 #include <asm/hcall.h>
 #include <asm/io.h>
 #include <asm/rtas.h>
@@ -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);
lib/powerpc/setup.c +6 -2
index 53ecbb830..a4ff678ce 100644
@@ -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();
 
 	/*
lib/powerpc/spinlock.c +4 -0
index 623a1f2c1..2c4904a33 100644
@@ -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 {
lib/ppc64/mmu.c +2 -0
index 84be31752..bdc5e4637 100644
@@ -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));
 }
 
powerpc/interrupts.c +28 -0
index 6bed26e41..ba965ff76 100644
@@ -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();
Signature · 1 line
2.43.0
Reviewed-by on v9 26/31
#60 lore raw

Re: [kvm-unit-tests PATCH v9 26/31] powerpc: add usermode support

Quoted 11 lines · Nicholas Piggin

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.

---

#61 lore raw

PATCH v9 27/31 powerpc: add pmu tests

In reply to Nicholas Piggin

Add some initial PMU testing.

- PMC5/6 tests
- PMAE / PMI test
- BHRB basic tests

---
 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
lib/powerpc/asm/processor.h +2 -0
index 749155696..28239c610 100644
@@ -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;
lib/powerpc/asm/reg.h +9 -0
index 69ef21adb..602fba1b6 100644
@@ -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: */
lib/powerpc/asm/setup.h +1 -0
index 9ca318ce6..8f0b58ed0 100644
@@ -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)
lib/powerpc/setup.c +23 -0
index a4ff678ce..8ff4939e2 100644
@@ -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;
powerpc/Makefile.common +2 -1
index b2e89e4fd..0255ca9e4 100644
@@ -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)
powerpc/pmu.c new file +403 -0

403 lines not on this page · raw message

powerpc/unittests.cfg +3 -0
index c7cda819d..d767f5d68 100644
@@ -73,6 +73,9 @@ file = interrupts.elf
 file = mmu.elf
 smp = $MAX_SMP
 
+[pmu]
+file = pmu.elf
+
 [smp]
 file = smp.elf
 smp = 2
Signature · 1 line
2.43.0
#62 lore raw

Re: [kvm-unit-tests PATCH v9 27/31] powerpc: add pmu tests

Quoted 8 lines · Nicholas Piggin

Add some initial PMU testing.

- PMC5/6 tests
- PMAE / PMI test
- BHRB basic tests

---

...

Quoted 22 lines
lib/powerpc/setup.c +2 -0
index a4ff678ce..8ff4939e2 100644
@@ -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;

lib/powerpc/setup.c static void cpu_set(int fdtnode, u64 regval, void *info) · line 107

Quoted 10 lines
lib/powerpc/setup.c +8 -0
  		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);

Why don't you simply cast to (u64 *) and use fdt64_to_cpu() here instead?

...

Quoted 6 lines
powerpc/pmu.c new file +0 -0
new file mode 100644
index 000000000..8b13ee4cd
@@ -0,0 +1,403 @@

...

Quoted 17 lines
powerpc/pmu.c new file +17 -0
+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();

powerpc/pmu.c line 79

Quoted 10 lines
powerpc/pmu.c new file +10 -0
+	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");

It would be nice to have the TCG detection patch before this patch, so you could use the right condition here right from the start.

Quoted 20 lines
powerpc/pmu.c new file +20 -0
+	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();

powerpc/pmu.c line 110

Quoted 10 lines
powerpc/pmu.c new file +10 -0
+	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");

dito

Quoted 17 lines
powerpc/pmu.c new file +17 -0
+	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");

powerpc/pmu.c line 138

Quoted 10 lines
powerpc/pmu.c new file +10 -0
+	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);

report(true, ...) looks weird. Use report_info() instead?

Thomas

#63 lore raw

Re: [kvm-unit-tests PATCH v9 27/31] powerpc: add pmu tests

Quoted 34 lines · Thomas Huth
Quoted 8 lines · Nicholas Piggin

Add some initial PMU testing.

- PMC5/6 tests
- PMAE / PMI test
- BHRB basic tests

---

...

Quoted 24 lines
lib/powerpc/setup.c +2 -0
index a4ff678ce..8ff4939e2 100644
@@ -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);
 
Quoted 10 lines

lib/powerpc/setup.c static void cpu_set(int fdtnode, u64 regval, void *info) · line 107

Quoted 8 lines
lib/powerpc/setup.c +8 -0
+		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);

Why don't you simply cast to (u64 *) and use fdt64_to_cpu() here instead?

Hmm... probably because I copied from somewhere. Good idea though.

Quoted 31 lines

...

Quoted 6 lines
powerpc/pmu.c new file +0 -0
new file mode 100644
index 000000000..8b13ee4cd
@@ -0,0 +1,403 @@

...

Quoted 22 lines
powerpc/pmu.c new file +22 -0
+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);
Quoted 8 lines

powerpc/pmu.c line 79

Quoted 5 lines
powerpc/pmu.c new file +5 -0
+	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");

It would be nice to have the TCG detection patch before this patch, so you could use the right condition here right from the start.

Yeah, it turned out to be a bit annoying to rebase. We already have some kfail(true in the tree but I will remove those at least toward the end of the series.

I might take another look at reordering it after I rebase what you have merged.

Quoted 55 lines
Quoted 21 lines
powerpc/pmu.c new file +20 -0
+	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();

powerpc/pmu.c line 110

Quoted 10 lines
powerpc/pmu.c new file +10 -0
+	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");

dito

Quoted 21 lines
powerpc/pmu.c new file +21 -0
+	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));
Quoted 8 lines

powerpc/pmu.c line 138

Quoted 6 lines
powerpc/pmu.c new file +6 -0
+	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);

report(true, ...) looks weird. Use report_info() instead?

Ah yes that's better. I was going to do a pass/fail threshold but that gets pretty arbitrary depending on DVFS.. I guess for TCG we could report a pass/fail.

Thanks,
Nick

#64 lore raw

PATCH v9 28/31 configure: Make arch_libdir a first-class entity

In reply to Nicholas Piggin

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 <[email protected]>
Cc Claudio Imbrenda <[email protected]>
Cc David Hildenbrand <[email protected]>
Cc Eric Auger <[email protected]>
Cc Janosch Frank <[email protected]>
Cc Laurent Vivier <[email protected]>
Cc Nico B?hr <[email protected]>
Cc Paolo Bonzini <[email protected]>
Cc Thomas Huth <[email protected]>
Cc kvm at vger.kernel.org
Cc linux-s390 at vger.kernel.org
Cc kvmarm at lists.linux.dev
Cc kvm-riscv at lists.infradead.org
Cc linuxppc-dev at lists.ozlabs.org
---
 Makefile  |  2 +-
 configure | 18 +++++++++++++-----
 2 files changed, 14 insertions(+), 6 deletions(-)
Makefile +1 -1
index 5b7998b79..7fe93dfd8 100644
@@ -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/
configure +13 -5
index d744ec4dc..2b788d0c8 100755
@@ -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
Signature · 1 line
2.43.0
#65 lore raw

PATCH v9 29/31 powerpc: Remove remnants of ppc64 directory and build structure

In reply to Nicholas Piggin

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.

---
 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
MAINTAINERS +0 -1
index a2fa437da..1309863f2 100644
@@ -92,7 +92,6 @@ S: Maintained
 L: [email protected]
 F: powerpc/
 F: lib/powerpc/
-F: lib/ppc64/
 
 RISCV
 M: Andrew Jones <[email protected]>
configure +2 -1
index 2b788d0c8..77a0230fa 100755
@@ -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)!"
lib/powerpc/asm-offsets.c renamed from lib/ppc64/asm-offsets.c +0 -0
similarity index 100%
rename from lib/ppc64/asm-offsets.c
rename to lib/powerpc/asm-offsets.c
lib/powerpc/asm/asm-offsets.h renamed from lib/ppc64/asm/asm-offsets.h +0 -0
similarity index 100%
rename from lib/ppc64/asm/asm-offsets.h
rename to lib/powerpc/asm/asm-offsets.h
lib/powerpc/asm/atomic.h renamed from lib/ppc64/asm/atomic.h +0 -0
similarity index 100%
rename from lib/ppc64/asm/atomic.h
rename to lib/powerpc/asm/atomic.h
lib/powerpc/asm/barrier.h renamed from lib/ppc64/asm/barrier.h +2 -2
similarity index 83%
rename from lib/ppc64/asm/barrier.h
rename to lib/powerpc/asm/barrier.h
index 475434b6a..22349d691 100644
@@ -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")
lib/powerpc/asm/bitops.h renamed from lib/ppc64/asm/bitops.h +2 -2
similarity index 69%
rename from lib/ppc64/asm/bitops.h
rename to lib/powerpc/asm/bitops.h
index c93d64bb9..dc1b8cd3f 100644
@@ -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 <bitops.h> can be included directly
lib/powerpc/asm/io.h renamed from lib/ppc64/asm/io.h +2 -2
similarity index 50%
rename from lib/ppc64/asm/io.h
rename to lib/powerpc/asm/io.h
index 08d7297c3..cfe099f01 100644
@@ -1,5 +1,5 @@
-#ifndef _ASMPPC64_IO_H_
-#define _ASMPPC64_IO_H_
+#ifndef _ASMPOWERPC_IO_H_
+#define _ASMPOWERPC_IO_H_
 
 #define __iomem
 
lib/powerpc/asm/mmu.h renamed from lib/ppc64/asm/mmu.h +0 -0
similarity index 100%
rename from lib/ppc64/asm/mmu.h
rename to lib/powerpc/asm/mmu.h
lib/powerpc/asm/opal.h renamed from lib/ppc64/asm/opal.h +2 -2
similarity index 90%
rename from lib/ppc64/asm/opal.h
rename to lib/powerpc/asm/opal.h
index 6c3e9ffe2..44e62d80d 100644
@@ -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 <stdint.h>
 
lib/powerpc/asm/page.h renamed from lib/ppc64/asm/page.h +3 -3
similarity index 94%
rename from lib/ppc64/asm/page.h
rename to lib/powerpc/asm/page.h
index c497d86b9..19bf9c677 100644
@@ -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_ */
lib/powerpc/asm/pgtable-hwdef.h renamed from lib/ppc64/asm/pgtable-hwdef.h +3 -3
similarity index 93%
rename from lib/ppc64/asm/pgtable-hwdef.h
rename to lib/powerpc/asm/pgtable-hwdef.h
index 7cb2c7476..84618809d 100644
@@ -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 <[email protected]>
  *
@@ -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_ */
lib/powerpc/asm/pgtable.h renamed from lib/ppc64/asm/pgtable.h +1 -1
similarity index 99%
rename from lib/ppc64/asm/pgtable.h
rename to lib/powerpc/asm/pgtable.h
index a6ee0d4cd..d4f2c826a 100644
@@ -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_ */
lib/powerpc/asm/ptrace.h renamed from lib/ppc64/asm/ptrace.h +3 -3
similarity index 89%
rename from lib/ppc64/asm/ptrace.h
rename to lib/powerpc/asm/ptrace.h
index db263a59e..39ea950e7 100644
@@ -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_ */
lib/powerpc/asm/spinlock.h renamed from lib/ppc64/asm/spinlock.h +3 -3
similarity index 54%
rename from lib/ppc64/asm/spinlock.h
rename to lib/powerpc/asm/spinlock.h
index b952386da..9dbe716fd 100644
@@ -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_ */
lib/powerpc/asm/stack.h +3 -0
index e1c46ee09..eea139a45 100644
@@ -5,4 +5,7 @@
 #error Do not directly include <asm/stack.h>. Just use <stack.h>.
 #endif
 
+#define HAVE_ARCH_BACKTRACE
+#define HAVE_ARCH_BACKTRACE_FRAME
+
 #endif
lib/powerpc/asm/vpa.h renamed from lib/ppc64/asm/vpa.h +0 -0
similarity index 100%
rename from lib/ppc64/asm/vpa.h
rename to lib/powerpc/asm/vpa.h
lib/powerpc/mmu.c renamed from lib/ppc64/mmu.c +0 -0
similarity index 100%
rename from lib/ppc64/mmu.c
rename to lib/powerpc/mmu.c
lib/powerpc/opal-calls.S renamed from lib/ppc64/opal-calls.S +0 -0
similarity index 100%
rename from lib/ppc64/opal-calls.S
rename to lib/powerpc/opal-calls.S
lib/powerpc/opal.c renamed from lib/ppc64/opal.c +0 -0
similarity index 100%
rename from lib/ppc64/opal.c
rename to lib/powerpc/opal.c
lib/powerpc/stack.c renamed from lib/ppc64/stack.c +0 -0
similarity index 100%
rename from lib/ppc64/stack.c
rename to lib/powerpc/stack.c
lib/ppc64/.gitignore deleted +0 -1
deleted file mode 100644
index 84872bf19..000000000
@@ -1 +0,0 @@
-asm-offsets.[hs]
lib/ppc64/asm/handlers.h deleted +0 -1
deleted file mode 100644
index 92e6fb247..000000000
@@ -1 +0,0 @@
-#include "../../powerpc/asm/handlers.h"
lib/ppc64/asm/hcall.h deleted +0 -1
deleted file mode 100644
index daabaca51..000000000
@@ -1 +0,0 @@
-#include "../../powerpc/asm/hcall.h"
lib/ppc64/asm/memory_areas.h deleted +0 -6
deleted file mode 100644
index b9fd46b9e..000000000
@@ -1,6 +0,0 @@
-#ifndef _ASMPPC64_MEMORY_AREAS_H_
-#define _ASMPPC64_MEMORY_AREAS_H_
-
-#include <asm-generic/memory_areas.h>
-
-#endif
lib/ppc64/asm/ppc_asm.h deleted +0 -1
deleted file mode 100644
index e3929eeee..000000000
@@ -1 +0,0 @@
-#include "../../powerpc/asm/ppc_asm.h"
lib/ppc64/asm/processor.h deleted +0 -1
deleted file mode 100644
index 066a51a00..000000000
@@ -1 +0,0 @@
-#include "../../powerpc/asm/processor.h"
lib/ppc64/asm/reg.h deleted +0 -1
deleted file mode 100644
index bc407b555..000000000
@@ -1 +0,0 @@
-#include "../../powerpc/asm/reg.h"
lib/ppc64/asm/rtas.h deleted +0 -1
deleted file mode 100644
index fe77f635c..000000000
@@ -1 +0,0 @@
-#include "../../powerpc/asm/rtas.h"
lib/ppc64/asm/setup.h deleted +0 -1
deleted file mode 100644
index 201929859..000000000
@@ -1 +0,0 @@
-#include "../../powerpc/asm/setup.h"
lib/ppc64/asm/smp.h deleted +0 -1
deleted file mode 100644
index 67ced7567..000000000
@@ -1 +0,0 @@
-#include "../../powerpc/asm/smp.h"
lib/ppc64/asm/stack.h deleted +0 -11
deleted file mode 100644
index 94fd1021c..000000000
@@ -1,11 +0,0 @@
-#ifndef _ASMPPC64_STACK_H_
-#define _ASMPPC64_STACK_H_
-
-#ifndef _STACK_H_
-#error Do not directly include <asm/stack.h>. Just use <stack.h>.
-#endif
-
-#define HAVE_ARCH_BACKTRACE
-#define HAVE_ARCH_BACKTRACE_FRAME
-
-#endif
powerpc/Makefile +111 -1

112 lines not on this page · raw message

powerpc/Makefile.common deleted +0 -96

96 lines not on this page · raw message

powerpc/Makefile.ppc64 deleted +0 -31
deleted file mode 100644
index 2466471f9..000000000
@@ -1,31 +0,0 @@
-#
-# ppc64 makefile
-#
-# Authors: Andrew Jones <[email protected]>
-#
-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
Signature · 1 line
2.43.0
Acked-by on v9 29/31
#66 lore raw

Re: [kvm-unit-tests PATCH v9 29/31] powerpc: Remove remnants of ppc64 directory and build structure

Quoted 8 lines · Nicholas Piggin

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.

---

...

powerpc/Makefile line 4

Quoted 10 lines
powerpc/Makefile +4 -1
index 8a007ab54..e4b5312a2 100644
@@ -1 +1,111 @@
-include $(SRCDIR)/$(TEST_DIR)/Makefile.$(ARCH)
+#
+# powerpc makefile
+#
+# Authors: Andrew Jones <[email protected]>

I'd maybe drop that e-mail address now since it it not valid anymore. Andrew, do want to see your new mail address here?

Apart from that:

#67 lore raw

Re: [kvm-unit-tests PATCH v9 29/31] powerpc: Remove remnants of ppc64 directory and build structure

Quoted 10 lines · Thomas Huth
Quoted 8 lines · Nicholas Piggin

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.

---

...

Quoted 13 lines

powerpc/Makefile line 4

Quoted 10 lines
powerpc/Makefile +4 -1
index 8a007ab54..e4b5312a2 100644
@@ -1 +1,111 @@
-include $(SRCDIR)/$(TEST_DIR)/Makefile.$(ARCH)
+#
+# powerpc makefile
+#
+# Authors: Andrew Jones <[email protected]>

I'd maybe drop that e-mail address now since it it not valid anymore. Andrew, do want to see your new mail address here?

No need to change to my new email address. We can either keep it as is for historical records, and as part of faithful code move, or just drop it.

Thanks,
drew

Quoted 4 lines

Apart from that:

#68 lore raw

Re: [kvm-unit-tests PATCH v9 29/31] powerpc: Remove remnants of ppc64 directory and build structure

Quoted 25 lines · Andrew Jones
Quoted 10 lines · Thomas Huth
Quoted 8 lines · Nicholas Piggin

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.

---

...

Quoted 13 lines

powerpc/Makefile line 4

Quoted 10 lines
powerpc/Makefile +4 -1
index 8a007ab54..e4b5312a2 100644
@@ -1 +1,111 @@
-include $(SRCDIR)/$(TEST_DIR)/Makefile.$(ARCH)
+#
+# powerpc makefile
+#
+# Authors: Andrew Jones <[email protected]>

I'd maybe drop that e-mail address now since it it not valid anymore. Andrew, do want to see your new mail address here?

Quoted 2 lines

No need to change to my new email address. We can either keep it as is for historical records, and as part of faithful code move, or just drop it.

I'll leave it, and leave it up to you to send an update email address patch if and when you decide.

Thanks,
Nick

#69 lore raw

PATCH v9 30/31 powerpc: Add facility to query TCG or KVM host

In reply to Nicholas Piggin

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.

---
 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(-)
lib/powerpc/asm/processor.h +3 -0
index 28239c610..09535f8c3 100644
@@ -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;
lib/powerpc/setup.c +25 -0
index 8ff4939e2..2b9d67466 100644
@@ -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) {
powerpc/atomics.c +1 -1
index 975711fc8..7d6dfaed9 100644
@@ -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);
powerpc/interrupts.c +4 -2
index ba965ff76..6511c76f2 100644
@@ -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)
powerpc/mmu.c +1 -1
index fef790506..27220b71f 100644
@@ -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
powerpc/pmu.c +3 -3
index 8b13ee4cd..960f90787 100644
@@ -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");
powerpc/sprs.c +1 -1
index c5844985a..c496efe9e 100644
@@ -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]);
powerpc/timebase.c +2 -2
index 02a4e33c0..b1378dd2b 100644
@@ -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);
powerpc/tm.c +1 -1
index 507eaf492..d4f436147 100644
@@ -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");
Signature · 1 line
2.43.0
Reviewed-by on v9 30/31
#70 lore raw

Re: [kvm-unit-tests PATCH v9 30/31] powerpc: Add facility to query TCG or KVM host

Quoted 16 lines · Nicholas Piggin

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.

Quoted 11 lines
---
  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(-)

As mentioned elsewhere, it would be nice to have this earlier in the series so you could use the conditions in the earlier patches already (but if it is too cumbersome to rework, I don't insist on that).

#71 lore raw

PATCH v9 31/31 powerpc: gitlab CI update

In reply to Nicholas Piggin

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.

---
 .gitlab-ci.yml        | 30 ++++++++----------------------
 powerpc/unittests.cfg | 32 ++++++++++++++++++++++++++------
 2 files changed, 34 insertions(+), 28 deletions(-)
.gitlab-ci.yml +8 -22
index 23bb69e24..31a2a4e34 100644
@@ -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.
powerpc/unittests.cfg +26 -6
index d767f5d68..6fae688a8 100644
@@ -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
Signature · 1 line
2.43.0
#72 lore raw

Re: [kvm-unit-tests PATCH v9 31/31] powerpc: gitlab CI update

Quoted 170 lines · Nicholas Piggin

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.

---
  .gitlab-ci.yml        | 30 ++++++++----------------------
  powerpc/unittests.cfg | 32 ++++++++++++++++++++++++++------
  2 files changed, 34 insertions(+), 28 deletions(-)
.gitlab-ci.yml +8 -22
index 23bb69e24..31a2a4e34 100644
@@ -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.
powerpc/unittests.cfg +23 -6
index d767f5d68..6fae688a8 100644
@@ -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
 

powerpc/unittests.cfg smp = 2,threads=2 · line 144

Quoted 10 lines
powerpc/unittests.cfg +2 -0
+# 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

Have any of the failures been fixed in newer versions of QEMU? If so, you could also update the ppc jobs to fedora:40:

.gitlab-ci.yml +2 -0
@@ -91,6 +91,7 @@ build-arm:
 
 build-ppc64be:
  extends: .outoftree_template
+ image: fedora:40
  script:
  - dnf install -y qemu-system-ppc gcc-powerpc64-linux-gnu nmap-ncat
  - mkdir build
@@ -111,6 +112,7 @@ build-ppc64be:
 
 build-ppc64le:
  extends: .intree_template
+ image: fedora:40
  script:
  - dnf install -y qemu-system-ppc gcc-powerpc64-linux-gnu nmap-ncat
  - ./configure --arch=ppc64 --endian=little --cross-prefix=powerpc64-linux-gnu-

I also had a patch somewhere that updates all jobs, it just needs some polishing to get finished ... maybe a good point in time to do this now.

Thomas

#73 lore raw

Re: [kvm-unit-tests PATCH v9 31/31] powerpc: gitlab CI update

Quoted 175 lines · Thomas Huth
Quoted 174 lines · Nicholas Piggin

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.

---
  .gitlab-ci.yml        | 30 ++++++++----------------------
  powerpc/unittests.cfg | 32 ++++++++++++++++++++++++++------
  2 files changed, 34 insertions(+), 28 deletions(-)
.gitlab-ci.yml +8 -22
index 23bb69e24..31a2a4e34 100644
@@ -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.
powerpc/unittests.cfg +24 -6
index d767f5d68..6fae688a8 100644
@@ -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
 
Quoted 8 lines

powerpc/unittests.cfg smp = 2,threads=2 · line 144

Quoted 6 lines
powerpc/unittests.cfg +1 -0
+# QEMU 7.0 (Fedora 37) in gitlab CI fails this
  [sprs-migration]
  file = sprs.elf
  machine = pseries
  extra_params = -append '-w'
  groups = migration

Have any of the failures been fixed in newer versions of QEMU?

Yes, I think all (maybe with the exception of the migration dirty bitmap bug) are fixed in 40. I did try that but x86 got some new failures. Doing f40 for ppc specific would be another option but if you have fixes for the x86 fails we could update it all at once?

Quoted 1 line

If so, you could also update the ppc jobs to fedora:40:

Good idea, I'll add an optional patch at the end to just update ppc, if the other patches aren't polished yet.

Thanks,
Nick

Quoted 25 lines
.gitlab-ci.yml +2 -0
@@ -91,6 +91,7 @@ build-arm:
 
  build-ppc64be:
   extends: .outoftree_template
+ image: fedora:40
   script:
   - dnf install -y qemu-system-ppc gcc-powerpc64-linux-gnu nmap-ncat
   - mkdir build
@@ -111,6 +112,7 @@ build-ppc64be:
 
  build-ppc64le:
   extends: .intree_template
+ image: fedora:40
   script:
   - dnf install -y qemu-system-ppc gcc-powerpc64-linux-gnu nmap-ncat
   - ./configure --arch=ppc64 --endian=little --cross-prefix=powerpc64-linux-gnu-

I also had a patch somewhere that updates all jobs, it just needs some polishing to get finished ... maybe a good point in time to do this now.

Thomas