Skip to contentSkip to conversation

powerpc improvements

PATCH Superseded Nicholas Piggin 4 participants 71 messages Feb 26, 2024 – Mar 5, 2024

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

v1 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

cover powerpc improvements

This is the same familiar set of powerpc patches, it's taken a while to get them merged. And unfortunately they keep growing with fixes and new tests.

This goes on top of the previous migration and other core patches. Full tree can be found here.

https://gitlab.com/npiggin/kvm-unit-tests/-/tree/powerpc?ref_type=heads

I have tried to test all combinations of KVM and TCG for P8/9/10 and powernv. There are a small number of failures, some due to bugs in TCG, QEMU, and KVM. I don't want to drop such test cases but xfail doesn't quite work because it will start failing if we fix implementation to now work AFAIKS. If there is concern about that, then maybe we could add a known-failure type of report that can document the reason and not fail the entire group of tests.

Since last posting, this adds several fixes to the start of the series, fixes a bunch of bugs in the SPRs and other tests that Joel and Thomas raised. Tidied up the new new SMP support and fixed a couple of issues there. Added MMU, usermode support, add atomics, timebase, PMU tests, and removes the ppc64 subdirectories.

Thanks,
Nick

Nicholas Piggin (32):
powerpc: Fix KVM caps on POWER9 hosts
powerpc: Fix pseries getchar return value
powerpc: Fix stack backtrace termination
powerpc: interrupt stack backtracing
powerpc: Cleanup SPR and MSR definitions
powerpc/sprs: Specify SPRs with data rather than code powerpc/sprs: Don't fail changed SPRs that are used by the test
harness
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
arch-run: Fix handling multiple exit status messages
powerpc: add SMP and IPI support
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: Fail on unknown arch
configure: Make arch_libdir a first-class entity
powerpc: Remove remnants of ppc64 directory and build structure
powerpc: gitlab CI update

 .gitlab-ci.yml                           |  16 +-
 MAINTAINERS                              |   1 -
 Makefile                                 |   2 +-
 common/sieve.c                           |  15 +-
 configure                                |  69 ++-
 lib/libcflat.h                           |   2 -
 lib/{ppc64 => powerpc}/asm-offsets.c     |   7 +
 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                   |  66 +++
 lib/powerpc/asm/pgtable-hwdef.h          |  67 +++
 lib/powerpc/asm/pgtable.h                | 126 +++++
 lib/powerpc/asm/ppc_asm.h                |   8 +-
 lib/powerpc/asm/processor.h              |  68 ++-
 lib/{ppc64 => powerpc}/asm/ptrace.h      |  22 +-
 lib/powerpc/asm/reg.h                    |  72 +++
 lib/powerpc/asm/rtas.h                   |   2 +
 lib/powerpc/asm/setup.h                  |   3 +-
 lib/powerpc/asm/smp.h                    |  50 +-
 lib/powerpc/asm/spinlock.h               |  11 +
 lib/powerpc/asm/stack.h                  |   3 +
 lib/powerpc/asm/time.h                   |   1 +
 lib/{ppc64 => powerpc}/asm/vpa.h         |   0
 lib/powerpc/hcall.c                      |   6 +-
 lib/powerpc/io.c                         |  41 +-
 lib/powerpc/io.h                         |   6 +
 lib/powerpc/mmu.c                        | 275 +++++++++
 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                      | 159 +++++-
 lib/powerpc/smp.c                        | 287 ++++++++--
 lib/powerpc/spinlock.c                   |  32 ++
 lib/powerpc/stack.c                      |  55 ++
 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/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                    |   8 -
 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                         | 111 +++-
 powerpc/Makefile.common                  |  86 ---
 powerpc/Makefile.ppc64                   |  27 -
 powerpc/atomics.c                        | 373 +++++++++++++
 powerpc/cstart64.S                       |  78 ++-
 powerpc/emulator.c                       |  21 +-
 powerpc/interrupts.c                     | 517 +++++++++++++++++
 powerpc/pmu.c                            | 337 +++++++++++
 powerpc/run                              |  42 +-
 powerpc/selftest.c                       |   4 +-
 powerpc/sieve.c                          |   1 +
 powerpc/smp.c                            | 349 ++++++++++++
 powerpc/sprs.c                           | 678 ++++++++++++++++-------
 powerpc/timebase.c                       | 330 +++++++++++
 powerpc/tm.c                             |   4 +-
 powerpc/unittests.cfg                    |  63 ++-
 s390x/mvpg.c                             |   1 +
 s390x/selftest.c                         |   1 +
 scripts/arch-run.bash                    |   2 +-
 scripts/common.bash                      |   8 +-
 scripts/runtime.bash                     |  20 +-
 x86/pmu.c                                |   1 +
 x86/pmu_lbr.c                            |   1 +
 x86/vmexit.c                             |   1 +
 x86/vmware_backdoors.c                   |   1 +
 84 files changed, 4400 insertions(+), 541 deletions(-)
 rename lib/{ppc64 => powerpc}/asm-offsets.c (94%)
 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/reg.h
 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
 create mode 100644 lib/powerpc/stack.c
 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/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/pmu.c
 create mode 120000 powerpc/sieve.c
 create mode 100644 powerpc/smp.c
 create mode 100644 powerpc/timebase.c
Signature · 1 line
2.42.0
#1 lore raw

PATCH 1/32 powerpc: Fix KVM caps on POWER9 hosts

KVM does not like to run on POWER9 hosts without cap-ccf-assist=off.

---
 powerpc/run | 2 ++
 1 file changed, 2 insertions(+)
powerpc/run +2 -0
index e469f1eb3..5cdb94194 100755
@@ -24,6 +24,8 @@ M+=",accel=$ACCEL$ACCEL_PROPS"
 
 if [[ "$ACCEL" == "tcg" ]] ; then
 	M+=",cap-cfpc=broken,cap-sbbc=broken,cap-ibs=broken,cap-ccf-assist=off"
+elif [[ "$ACCEL" == "kvm" ]] ; then
+	M+=",cap-ccf-assist=off"
 fi
 
 command="$qemu -nodefaults $M -bios $FIRMWARE"
Signature · 1 line
2.42.0
Reviewed-by on v1 1/32
#2 lore raw

Re: [kvm-unit-tests PATCH 01/32] powerpc: Fix KVM caps on POWER9 hosts

Quoted 12 lines · Nicholas Piggin

KVM does not like to run on POWER9 hosts without cap-ccf-assist=off.

---
  powerpc/run | 2 ++
  1 file changed, 2 insertions(+)
powerpc/run +0 -0
index e469f1eb3..5cdb94194 100755

powerpc/run M+=",accel=$ACCEL$ACCEL_PROPS" · line 29

Quoted 6 lines
powerpc/run +2 -0
@@ -24,6 +24,8 @@ M+=",accel=$ACCEL$ACCEL_PROPS"
 
  if [[ "$ACCEL" == "tcg" ]] ; then
  	M+=",cap-cfpc=broken,cap-sbbc=broken,cap-ibs=broken,cap-ccf-assist=off"
+elif [[ "$ACCEL" == "kvm" ]] ; then
+	M+=",cap-ccf-assist=off"
  fi

Since it is needed in both cases, you could also move it out of the if-statement and remove it from the tcg part.

Anyway,

#3 lore raw

PATCH 2/32 powerpc: Fix pseries getchar return value

In reply to Nicholas Piggin

getchar() didn't get the shift value correct and never returned the first character. This never really mattered since it was only ever used for press-a-key-to-continue prompts. but it tripped me up when debugging a QEMU console output problem.

---
 lib/powerpc/hcall.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/powerpc/hcall.c +1 -1
index 711cb1b0f..b4d39ac65 100644
@@ -43,5 +43,5 @@ int __getchar(void)
 	asm volatile (" sc 1 "  : "+r"(r3), "+r"(r4), "=r"(r5)
 				: "r"(r3),  "r"(r4));
 
-	return r3 == H_SUCCESS && r4 > 0 ? r5 >> 48 : -1;
+	return r3 == H_SUCCESS && r4 > 0 ? r5 >> 56 : -1;
 }
Signature · 1 line
2.42.0
Reviewed-by on v1 2/32
#4 lore raw

Re: [kvm-unit-tests PATCH 02/32] powerpc: Fix pseries getchar return value

Quoted 15 lines · Nicholas Piggin

getchar() didn't get the shift value correct and never returned the first character. This never really mattered since it was only ever used for press-a-key-to-continue prompts. but it tripped me up when debugging a QEMU console output problem.

---
  lib/powerpc/hcall.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
lib/powerpc/hcall.c +0 -0
index 711cb1b0f..b4d39ac65 100644

lib/powerpc/hcall.c int __getchar(void) · line 47

Quoted 6 lines
lib/powerpc/hcall.c +1 -1
@@ -43,5 +43,5 @@ int __getchar(void)
  	asm volatile (" sc 1 "  : "+r"(r3), "+r"(r4), "=r"(r5)
  				: "r"(r3),  "r"(r4));
 
-	return r3 == H_SUCCESS && r4 > 0 ? r5 >> 48 : -1;
+	return r3 == H_SUCCESS && r4 > 0 ? r5 >> 56 : -1;
  }
#5 lore raw

PATCH 3/32 powerpc: Fix stack backtrace termination

In reply to Nicholas Piggin

The backtrace handler terminates when it sees a NULL caller address, but the powerpc stack setup does not keep such a NULL caller frame at the start of the stack.

This happens to work on pseries because the memory at 0 is mapped and it contains 0 at the location of the return address pointer if it were a stack frame. But this is fragile, and does not work with powernv where address 0 contains firmware instructions.

Use the existing dummy frame on stack as the NULL caller, and create a new frame on stack for the entry code.

---
 powerpc/cstart64.S | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
powerpc/cstart64.S +10 -2
index e18ae9a22..14ab0c6c8 100644
@@ -46,8 +46,16 @@ start:
 	add	r1, r1, r31
 	add	r2, r2, r31
 
+	/* Zero backpointers in initial stack frame so backtrace() stops */
+	li	r0,0
+	std	r0,0(r1)
+	std	r0,16(r1)
+
+	/* Create entry frame */
+	stdu	r1,-INT_FRAME_SIZE(r1)
+
 	/* save DTB pointer */
-	std	r3, 56(r1)
+	SAVE_GPR(3,r1)
 
 	/*
 	 * Call relocate. relocate is C code, but careful to not use
@@ -101,7 +109,7 @@ start:
 	stw	r4, 0(r3)
 
 	/* complete setup */
-1:	ld	r3, 56(r1)
+1:	REST_GPR(3, r1)
 	bl	setup
 
 	/* run the test */
Signature · 1 line
2.42.0
#6 lore raw

Re: [kvm-unit-tests PATCH 03/32] powerpc: Fix stack backtrace termination

Quoted 9 lines · Nicholas Piggin

The backtrace handler terminates when it sees a NULL caller address, but the powerpc stack setup does not keep such a NULL caller frame at the start of the stack.

This happens to work on pseries because the memory at 0 is mapped and it contains 0 at the location of the return address pointer if it were a stack frame. But this is fragile, and does not work with powernv where address 0 contains firmware instructions.

Quoted 7 lines

Use the existing dummy frame on stack as the NULL caller, and create a new frame on stack for the entry code.

---
  powerpc/cstart64.S | 12 ++++++++++--
  1 file changed, 10 insertions(+), 2 deletions(-)

Thanks for tackling this! ... however, not doing powerpc work since years anymore, I have some ignorant questions below...

powerpc/cstart64.S start: · line 51

Quoted 11 lines
powerpc/cstart64.S +3 -0
index e18ae9a22..14ab0c6c8 100644
@@ -46,8 +46,16 @@ start:
  	add	r1, r1, r31
  	add	r2, r2, r31
 
+	/* Zero backpointers in initial stack frame so backtrace() stops */
+	li	r0,0
+	std	r0,0(r1)

0(r1) is the back chain pointer ...

powerpc/cstart64.S start: · line 52

Quoted 1 line
powerpc/cstart64.S +1 -0
+	std	r0,16(r1)

... but what is 16(r1) ? I suppose that should be the "LR save word" ? But isn't that at 8(r1) instead?? (not sure whether I'm looking at the right ELF abi spec right now...)

Anyway, a comment in the source would be helpful here.

powerpc/cstart64.S start: · line 55

Quoted 3 lines
powerpc/cstart64.S +3 -0
+
+	/* Create entry frame */
+	stdu	r1,-INT_FRAME_SIZE(r1)

Since we already create an initial frame via stackptr from powerpc/flat.lds, do we really need to create this additional one here? Or does the one from flat.lds have to be completely empty, i.e. also no DTB pointer in it?

powerpc/cstart64.S start: · line 58

Quoted 3 lines
powerpc/cstart64.S +1 -1
  	/* save DTB pointer */
-	std	r3, 56(r1)
+	SAVE_GPR(3,r1)

Isn't SAVE_GPR rather meant for the interrupt frame, not for the normal C calling convention frames?

Sorry for asking dumb questions ... I still have a hard time understanding the changes here... :-/

powerpc/cstart64.S start: · line 115

Quoted 11 lines
powerpc/cstart64.S +1 -1
  	/*
  	 * Call relocate. relocate is C code, but careful to not use
@@ -101,7 +109,7 @@ start:
  	stw	r4, 0(r3)
 
  	/* complete setup */
-1:	ld	r3, 56(r1)
+1:	REST_GPR(3, r1)
  	bl	setup
 
  	/* run the test */

Thomas

#7 lore raw

Re: [kvm-unit-tests PATCH 03/32] powerpc: Fix stack backtrace termination

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

The backtrace handler terminates when it sees a NULL caller address, but the powerpc stack setup does not keep such a NULL caller frame at the start of the stack.

This happens to work on pseries because the memory at 0 is mapped and it contains 0 at the location of the return address pointer if it were a stack frame. But this is fragile, and does not work with powernv where address 0 contains firmware instructions.

Quoted 7 lines

Use the existing dummy frame on stack as the NULL caller, and create a new frame on stack for the entry code.

---
  powerpc/cstart64.S | 12 ++++++++++--

  1 file changed, 10 insertions(+), 2 deletions(-)

Thanks for tackling this! ... however, not doing powerpc work since years anymore, I have some ignorant questions below...

Quoted 10 lines
powerpc/cstart64.S +0 -0
index e18ae9a22..14ab0c6c8 100644
@@ -46,8 +46,16 @@ start:

      add    r1, r1, r31
      add    r2, r2, r31
+    /* Zero backpointers in initial stack frame so backtrace() stops */ +    li    r0,0
+    std    r0,0(r1)

0(r1) is the back chain pointer ...

Quoted 3 lines
Quoted 1 line

+    std    r0,16(r1)

... but what is 16(r1) ? I suppose that should be the "LR save word" ? But isn't that at 8(r1) instead?? (not sure whether I'm looking at the right ELF abi spec right now...)

Ok, I was looking at the wrong ELF spec, indeed (it was an ancient 32-bit spec, not the 64-bit ABI). Sorry for the confusion. Having a proper #define or a comment for the 16 here would still be helpful, though.

Thomas

#8 lore raw

Re: [kvm-unit-tests PATCH 03/32] powerpc: Fix stack backtrace termination

Quoted 37 lines · Thomas Huth
Quoted 36 lines · Thomas Huth
Quoted 9 lines · Nicholas Piggin

The backtrace handler terminates when it sees a NULL caller address, but the powerpc stack setup does not keep such a NULL caller frame at the start of the stack.

This happens to work on pseries because the memory at 0 is mapped and it contains 0 at the location of the return address pointer if it were a stack frame. But this is fragile, and does not work with powernv where address 0 contains firmware instructions.

Quoted 7 lines

Use the existing dummy frame on stack as the NULL caller, and create a new frame on stack for the entry code.

---
  powerpc/cstart64.S | 12 ++++++++++--

  1 file changed, 10 insertions(+), 2 deletions(-)

Thanks for tackling this! ... however, not doing powerpc work since years anymore, I have some ignorant questions below...

Quoted 10 lines
powerpc/cstart64.S +0 -0
index e18ae9a22..14ab0c6c8 100644
@@ -46,8 +46,16 @@ start:

      add    r1, r1, r31
      add    r2, r2, r31
+    /* Zero backpointers in initial stack frame so backtrace() stops */ +    li    r0,0
+    std    r0,0(r1)

0(r1) is the back chain pointer ...

Quoted 1 line

+    std    r0,16(r1)

Quoted 7 lines
Quoted 3 lines

... but what is 16(r1) ? I suppose that should be the "LR save word" ? But isn't that at 8(r1) instead?? (not sure whether I'm looking at the right ELF abi spec right now...)

Ok, I was looking at the wrong ELF spec, indeed (it was an ancient 32-bit spec, not the 64-bit ABI). Sorry for the confusion. Having a proper #define or a comment for the 16 here would still be helpful, though.

Thanks for the deailed reviews as always. I've been a little busy with QEMU so may not get another series out for a bit. I'll probably wait for Andrew's stack backtrace changes to land too before resend.

But, yes a comment makes sense. I'll add.

Thanks,
Nick

#9 lore raw

Re: [kvm-unit-tests PATCH 03/32] powerpc: Fix stack backtrace termination

In reply to Thomas Huth
Quoted 43 lines · Thomas Huth
Quoted 9 lines · Nicholas Piggin

The backtrace handler terminates when it sees a NULL caller address, but the powerpc stack setup does not keep such a NULL caller frame at the start of the stack.

This happens to work on pseries because the memory at 0 is mapped and it contains 0 at the location of the return address pointer if it were a stack frame. But this is fragile, and does not work with powernv where address 0 contains firmware instructions.

Quoted 7 lines

Use the existing dummy frame on stack as the NULL caller, and create a new frame on stack for the entry code.

---
  powerpc/cstart64.S | 12 ++++++++++--
  1 file changed, 10 insertions(+), 2 deletions(-)

Thanks for tackling this! ... however, not doing powerpc work since years anymore, I have some ignorant questions below...

powerpc/cstart64.S start: · line 51

Quoted 11 lines
powerpc/cstart64.S +3 -0
index e18ae9a22..14ab0c6c8 100644
@@ -46,8 +46,16 @@ start:
  	add	r1, r1, r31
  	add	r2, r2, r31
 
+	/* Zero backpointers in initial stack frame so backtrace() stops */
+	li	r0,0
+	std	r0,0(r1)

0(r1) is the back chain pointer ...

powerpc/cstart64.S start: · line 52

Quoted 1 line
powerpc/cstart64.S +1 -0
+	std	r0,16(r1)

... but what is 16(r1) ? I suppose that should be the "LR save word" ? But isn't that at 8(r1) instead?? (not sure whether I'm looking at the right ELF abi spec right now...)

Anyway, a comment in the source would be helpful here.

Quoted 7 lines

powerpc/cstart64.S start: · line 55

Quoted 3 lines
powerpc/cstart64.S +3 -0
+
+	/* Create entry frame */
+	stdu	r1,-INT_FRAME_SIZE(r1)

Since we already create an initial frame via stackptr from powerpc/flat.lds, do we really need to create this additional one here? Or does the one from flat.lds have to be completely empty, i.e. also no DTB pointer in it?

Oh you already figured the above questions. For this, we do have one frame allocated already statically yes. But if we don't create another one here then our callee will store LR into it, but the unwinder only exits when it sees a NULL return address so it would keep trying to walk.

We could make it terminate on NULL back chain pointer, but that's a bit more change that also touches non-powerpc code in the generic unwinder, and still needs some changes here. Maybe we should do that after this series though. I'll include a comment to look at redoing it later.

Quoted 10 lines

powerpc/cstart64.S start: · line 58

Quoted 4 lines
powerpc/cstart64.S +1 -1
  	/* save DTB pointer */
-	std	r3, 56(r1)
+	SAVE_GPR(3,r1)

Isn't SAVE_GPR rather meant for the interrupt frame, not for the normal C calling convention frames?

Sorry for asking dumb questions ... I still have a hard time understanding the changes here... :-/

Ah, that was me being lazy and using an interrupt frame for the new frame.

Thanks,
Nick

Quoted 14 lines

powerpc/cstart64.S start: · line 115

Quoted 12 lines
powerpc/cstart64.S +1 -1
  	/*
  	 * Call relocate. relocate is C code, but careful to not use
@@ -101,7 +109,7 @@ start:
  	stw	r4, 0(r3)
 
  	/* complete setup */
-1:	ld	r3, 56(r1)
+1:	REST_GPR(3, r1)
  	bl	setup
 
  	/* run the test */

Thomas

#10 lore raw

Re: [kvm-unit-tests PATCH 03/32] powerpc: Fix stack backtrace termination

Quoted 2 lines · Nicholas Piggin
Quoted 1 line · Thomas Huth

On 26/02/2024 11.11, Nicholas Piggin wrote:

...

Quoted 7 lines
Quoted 7 lines

powerpc/cstart64.S start: · line 58

Quoted 3 lines
   	/* save DTB pointer */
powerpc/cstart64.S +1 -1
-	std	r3, 56(r1)
+	SAVE_GPR(3,r1)

Isn't SAVE_GPR rather meant for the interrupt frame, not for the normal C calling convention frames?

Quoted 5 lines
Quoted 2 lines

Sorry for asking dumb questions ... I still have a hard time understanding the changes here... :-/

Ah, that was me being lazy and using an interrupt frame for the new frame.

Ah, ok. It's super-confusing (at least for me) to see an interrupt frame here out of no reason... could you please either add proper comments here explaining this, or even better switch to a normal stack frame, please?

Thanks,
Thomas

#11 lore raw

PATCH 4/32 powerpc: interrupt stack backtracing

In reply to Nicholas Piggin

Add support for backtracing across interrupt stacks, and add interrupt frame backtrace for unhandled interrupts.

---
 lib/powerpc/processor.c |  4 ++-
 lib/ppc64/asm/stack.h   |  3 +++
 lib/ppc64/stack.c       | 55 +++++++++++++++++++++++++++++++++++++++++
 powerpc/Makefile.ppc64  |  1 +
 powerpc/cstart64.S      |  7 ++++--
 5 files changed, 67 insertions(+), 3 deletions(-)
 create mode 100644 lib/ppc64/stack.c
lib/powerpc/processor.c +3 -1
index ad0d95666..114584024 100644
@@ -51,7 +51,9 @@ 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 exception %#lx at NIA:0x%016lx MSR:0x%016lx\n",
+			regs->trap, regs->nip, regs->msr);
+	dump_frame_stack((void *)regs->nip, (void *)regs->gpr[1]);
 	abort();
 }
 
lib/ppc64/asm/stack.h +3 -0
index 9734bbb8f..94fd1021c 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/ppc64/stack.c new file +55 -0

55 lines not on this page · raw message

powerpc/Makefile.ppc64 +1 -0
index b0ed2b104..eb682c226 100644
@@ -17,6 +17,7 @@ cstart.o = $(TEST_DIR)/cstart64.o
 reloc.o  = $(TEST_DIR)/reloc64.o
 
 OBJDIRS += lib/ppc64
+cflatobjs += lib/ppc64/stack.o
 
 # ppc64 specific tests
 tests = $(TEST_DIR)/spapr_vpa.elf
powerpc/cstart64.S +5 -2
index 14ab0c6c8..278af84a6 100644
@@ -188,6 +188,7 @@ call_handler:
 	.endr
 	mfsprg1	r0
 	std	r0,GPR1(r1)
+	std	r0,0(r1)
 
 	/* lr, xer, ccr */
 
@@ -206,12 +207,12 @@ call_handler:
 	subi	r31, r31, 0b - start_text
 	ld	r2, (p_toc_text - start_text)(r31)
 
-	/* FIXME: build stack frame */
-
 	/* call generic handler */
 
 	addi	r3,r1,STACK_FRAME_OVERHEAD
 	bl	do_handle_exception
+	.global exception_stack_marker
+exception_stack_marker:
 
 	/* restore context */
 
@@ -321,6 +322,7 @@ handler_trampoline:
 	/* nip and msr */
 	mfsrr0	r0
 	std	r0, _NIP(r1)
+	std	r0, INT_FRAME_SIZE+16(r1)
 
 	mfsrr1	r0
 	std	r0, _MSR(r1)
@@ -337,6 +339,7 @@ handler_htrampoline:
 	/* nip and msr */
 	mfspr	r0, SPR_HSRR0
 	std	r0, _NIP(r1)
+	std	r0, INT_FRAME_SIZE+16(r1)
 
 	mfspr	r0, SPR_HSRR1
 	std	r0, _MSR(r1)
Signature · 1 line
2.42.0
#12 lore raw

Re: [kvm-unit-tests PATCH 04/32] powerpc: interrupt stack backtracing

Quoted 91 lines · Nicholas Piggin

Add support for backtracing across interrupt stacks, and add interrupt frame backtrace for unhandled interrupts.

---
 lib/powerpc/processor.c |  4 ++-
 lib/ppc64/asm/stack.h   |  3 +++
 lib/ppc64/stack.c       | 55 +++++++++++++++++++++++++++++++++++++++++
 powerpc/Makefile.ppc64  |  1 +
 powerpc/cstart64.S      |  7 ++++--
 5 files changed, 67 insertions(+), 3 deletions(-)
 create mode 100644 lib/ppc64/stack.c
lib/powerpc/processor.c +3 -1
index ad0d95666..114584024 100644
@@ -51,7 +51,9 @@ 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 exception %#lx at NIA:0x%016lx MSR:0x%016lx\n",
+			regs->trap, regs->nip, regs->msr);
+	dump_frame_stack((void *)regs->nip, (void *)regs->gpr[1]);
 	abort();
 }
 
lib/ppc64/asm/stack.h +3 -0
index 9734bbb8f..94fd1021c 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/ppc64/stack.c new file +45 -0
new file mode 100644
index 000000000..fcb7fa860
@@ -0,0 +1,55 @@
+#include <libcflat.h>
+#include <asm/ptrace.h>
+#include <stack.h>
+
+extern char exception_stack_marker[];
+
+int backtrace_frame(const void *frame, const void **return_addrs, int max_depth)
+{
+	static int walking;
+	int depth = 0;
+	const unsigned long *bp = (unsigned long *)frame;
+	void *return_addr;
+
+	asm volatile("" ::: "lr"); /* Force it to save LR */
+
+	if (walking) {
+		printf("RECURSIVE STACK WALK!!!\n");
+		return 0;
+	}
+	walking = 1;
+
+	bp = (unsigned long *)bp[0];
+	return_addr = (void *)bp[2];
+
+	for (depth = 0; bp && depth < max_depth; depth++) {
+		return_addrs[depth] = return_addr;
+		if (return_addrs[depth] == 0)
+			break;
+		if (return_addrs[depth] == exception_stack_marker) {
+			struct pt_regs *regs;
+
+			regs = (void *)bp + STACK_FRAME_OVERHEAD;
+			bp = (unsigned long *)bp[0];
+			/* Represent interrupt frame with vector number */
+			return_addr = (void *)regs->trap;
+			if (depth + 1 < max_depth) {
+				depth++;
+				return_addrs[depth] = return_addr;
+				return_addr = (void *)regs->nip;
+			}
+		} else {
+			bp = (unsigned long *)bp[0];
+			return_addr = (void *)bp[2];
+		}
+	}

lib/ppc64/stack.c line 55

Quoted 10 lines
lib/ppc64/stack.c new file +10 -0
+
+	walking = 0;
+	return depth;
+}
+
+int backtrace(const void **return_addrs, int max_depth)
+{
+	return backtrace_frame(__builtin_frame_address(0), return_addrs,
+			       max_depth);
+}

I'm about to post a series which has a couple treewide tracing changes in them. Depending on which series goes first the other will need to accommodate.

Thanks,
drew

#13 lore raw

Re: [kvm-unit-tests PATCH 04/32] powerpc: interrupt stack backtracing

Quoted 98 lines · Andrew Jones
Quoted 97 lines · Nicholas Piggin

Add support for backtracing across interrupt stacks, and add interrupt frame backtrace for unhandled interrupts.

---
 lib/powerpc/processor.c |  4 ++-
 lib/ppc64/asm/stack.h   |  3 +++
 lib/ppc64/stack.c       | 55 +++++++++++++++++++++++++++++++++++++++++
 powerpc/Makefile.ppc64  |  1 +
 powerpc/cstart64.S      |  7 ++++--
 5 files changed, 67 insertions(+), 3 deletions(-)
 create mode 100644 lib/ppc64/stack.c
lib/powerpc/processor.c +3 -1
index ad0d95666..114584024 100644
@@ -51,7 +51,9 @@ 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 exception %#lx at NIA:0x%016lx MSR:0x%016lx\n",
+			regs->trap, regs->nip, regs->msr);
+	dump_frame_stack((void *)regs->nip, (void *)regs->gpr[1]);
 	abort();
 }
 
lib/ppc64/asm/stack.h +3 -0
index 9734bbb8f..94fd1021c 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/ppc64/stack.c new file +51 -0
new file mode 100644
index 000000000..fcb7fa860
@@ -0,0 +1,55 @@
+#include <libcflat.h>
+#include <asm/ptrace.h>
+#include <stack.h>
+
+extern char exception_stack_marker[];
+
+int backtrace_frame(const void *frame, const void **return_addrs, int max_depth)
+{
+	static int walking;
+	int depth = 0;
+	const unsigned long *bp = (unsigned long *)frame;
+	void *return_addr;
+
+	asm volatile("" ::: "lr"); /* Force it to save LR */
+
+	if (walking) {
+		printf("RECURSIVE STACK WALK!!!\n");
+		return 0;
+	}
+	walking = 1;
+
+	bp = (unsigned long *)bp[0];
+	return_addr = (void *)bp[2];
+
+	for (depth = 0; bp && depth < max_depth; depth++) {
+		return_addrs[depth] = return_addr;
+		if (return_addrs[depth] == 0)
+			break;
+		if (return_addrs[depth] == exception_stack_marker) {
+			struct pt_regs *regs;
+
+			regs = (void *)bp + STACK_FRAME_OVERHEAD;
+			bp = (unsigned long *)bp[0];
+			/* Represent interrupt frame with vector number */
+			return_addr = (void *)regs->trap;
+			if (depth + 1 < max_depth) {
+				depth++;
+				return_addrs[depth] = return_addr;
+				return_addr = (void *)regs->nip;
+			}
+		} else {
+			bp = (unsigned long *)bp[0];
+			return_addr = (void *)bp[2];
+		}
+	}
+
+	walking = 0;
+	return depth;
+}
+
+int backtrace(const void **return_addrs, int max_depth)
Quoted 8 lines

lib/ppc64/stack.c line 55

Quoted 4 lines
lib/ppc64/stack.c new file +4 -0
+{
+	return backtrace_frame(__builtin_frame_address(0), return_addrs,
+			       max_depth);
+}

I'm about to post a series which has a couple treewide tracing changes in them. Depending on which series goes first the other will need to accommodate.

Yeah that's fine.

Thanks,
Nick

#14 lore raw

Re: [kvm-unit-tests PATCH 04/32] powerpc: interrupt stack backtracing

In reply to Nicholas Piggin
Quoted 141 lines · Nicholas Piggin

Add support for backtracing across interrupt stacks, and add interrupt frame backtrace for unhandled interrupts.

---
  lib/powerpc/processor.c |  4 ++-
  lib/ppc64/asm/stack.h   |  3 +++
  lib/ppc64/stack.c       | 55 +++++++++++++++++++++++++++++++++++++++++
  powerpc/Makefile.ppc64  |  1 +
  powerpc/cstart64.S      |  7 ++++--
  5 files changed, 67 insertions(+), 3 deletions(-)

create mode 100644 lib/ppc64/stack.c

lib/powerpc/processor.c +3 -1
index ad0d95666..114584024 100644
@@ -51,7 +51,9 @@ 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 exception %#lx at NIA:0x%016lx MSR:0x%016lx\n",
+			regs->trap, regs->nip, regs->msr);
+	dump_frame_stack((void *)regs->nip, (void *)regs->gpr[1]);
  	abort();
  }
 
lib/ppc64/asm/stack.h +3 -0
index 9734bbb8f..94fd1021c 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/ppc64/stack.c new file +55 -0
new file mode 100644
index 000000000..fcb7fa860
@@ -0,0 +1,55 @@
+#include <libcflat.h>
+#include <asm/ptrace.h>
+#include <stack.h>
+
+extern char exception_stack_marker[];
+
+int backtrace_frame(const void *frame, const void **return_addrs, int max_depth)
+{
+	static int walking;
+	int depth = 0;
+	const unsigned long *bp = (unsigned long *)frame;
+	void *return_addr;
+
+	asm volatile("" ::: "lr"); /* Force it to save LR */
+
+	if (walking) {
+		printf("RECURSIVE STACK WALK!!!\n");
+		return 0;
+	}
+	walking = 1;
+
+	bp = (unsigned long *)bp[0];
+	return_addr = (void *)bp[2];
+
+	for (depth = 0; bp && depth < max_depth; depth++) {
+		return_addrs[depth] = return_addr;
+		if (return_addrs[depth] == 0)
+			break;
+		if (return_addrs[depth] == exception_stack_marker) {
+			struct pt_regs *regs;
+
+			regs = (void *)bp + STACK_FRAME_OVERHEAD;
+			bp = (unsigned long *)bp[0];
+			/* Represent interrupt frame with vector number */
+			return_addr = (void *)regs->trap;
+			if (depth + 1 < max_depth) {
+				depth++;
+				return_addrs[depth] = return_addr;
+				return_addr = (void *)regs->nip;
+			}
+		} else {
+			bp = (unsigned long *)bp[0];
+			return_addr = (void *)bp[2];
+		}
+	}
+
+	walking = 0;
+	return depth;
+}
+
+int backtrace(const void **return_addrs, int max_depth)
+{
+	return backtrace_frame(__builtin_frame_address(0), return_addrs,
+			       max_depth);
+}
powerpc/Makefile.ppc64 +1 -0
index b0ed2b104..eb682c226 100644
@@ -17,6 +17,7 @@ cstart.o = $(TEST_DIR)/cstart64.o
  reloc.o  = $(TEST_DIR)/reloc64.o
 
  OBJDIRS += lib/ppc64
+cflatobjs += lib/ppc64/stack.o
 
  # ppc64 specific tests
  tests = $(TEST_DIR)/spapr_vpa.elf
powerpc/cstart64.S +3 -2
index 14ab0c6c8..278af84a6 100644
@@ -188,6 +188,7 @@ call_handler:
  	.endr
  	mfsprg1	r0
  	std	r0,GPR1(r1)
+	std	r0,0(r1)
 
  	/* lr, xer, ccr */
 
@@ -206,12 +207,12 @@ call_handler:
  	subi	r31, r31, 0b - start_text
  	ld	r2, (p_toc_text - start_text)(r31)
 
-	/* FIXME: build stack frame */
-
  	/* call generic handler */
 
  	addi	r3,r1,STACK_FRAME_OVERHEAD
  	bl	do_handle_exception
+	.global exception_stack_marker
+exception_stack_marker:
 
  	/* restore context */
 

powerpc/cstart64.S handler_trampoline: · line 325

Quoted 4 lines
powerpc/cstart64.S +1 -0
@@ -321,6 +322,7 @@ handler_trampoline:
  	/* nip and msr */
  	mfsrr0	r0
  	std	r0, _NIP(r1)
+	std	r0, INT_FRAME_SIZE+16(r1)

So if I got that right, INT_FRAME_SIZE+16 points to the stack frame of the function that was running before the interrupt handler? Is it such a good idea to change that here? Please add a comment here explaining this line. Thanks!

powerpc/cstart64.S handler_htrampoline: · line 342

Quoted 7 lines
powerpc/cstart64.S +1 -0
  	mfsrr1	r0
  	std	r0, _MSR(r1)
@@ -337,6 +339,7 @@ handler_htrampoline:
  	/* nip and msr */
  	mfspr	r0, SPR_HSRR0
  	std	r0, _NIP(r1)
+	std	r0, INT_FRAME_SIZE+16(r1)

dito.

powerpc/cstart64.S handler_htrampoline: · line 345

Quoted 2 lines
powerpc/cstart64.S +0 -0
  	mfspr	r0, SPR_HSRR1
  	std	r0, _MSR(r1)

Thomas

#15 lore raw

Re: [kvm-unit-tests PATCH 04/32] powerpc: interrupt stack backtracing

Quoted 141 lines · Thomas Huth
Quoted 140 lines · Nicholas Piggin

Add support for backtracing across interrupt stacks, and add interrupt frame backtrace for unhandled interrupts.

---
  lib/powerpc/processor.c |  4 ++-
  lib/ppc64/asm/stack.h   |  3 +++
  lib/ppc64/stack.c       | 55 +++++++++++++++++++++++++++++++++++++++++
  powerpc/Makefile.ppc64  |  1 +
  powerpc/cstart64.S      |  7 ++++--
  5 files changed, 67 insertions(+), 3 deletions(-)

create mode 100644 lib/ppc64/stack.c

lib/powerpc/processor.c +3 -1
index ad0d95666..114584024 100644
@@ -51,7 +51,9 @@ 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 exception %#lx at NIA:0x%016lx MSR:0x%016lx\n",
+			regs->trap, regs->nip, regs->msr);
+	dump_frame_stack((void *)regs->nip, (void *)regs->gpr[1]);
  	abort();
  }
 
lib/ppc64/asm/stack.h +3 -0
index 9734bbb8f..94fd1021c 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/ppc64/stack.c new file +55 -0
new file mode 100644
index 000000000..fcb7fa860
@@ -0,0 +1,55 @@
+#include <libcflat.h>
+#include <asm/ptrace.h>
+#include <stack.h>
+
+extern char exception_stack_marker[];
+
+int backtrace_frame(const void *frame, const void **return_addrs, int max_depth)
+{
+	static int walking;
+	int depth = 0;
+	const unsigned long *bp = (unsigned long *)frame;
+	void *return_addr;
+
+	asm volatile("" ::: "lr"); /* Force it to save LR */
+
+	if (walking) {
+		printf("RECURSIVE STACK WALK!!!\n");
+		return 0;
+	}
+	walking = 1;
+
+	bp = (unsigned long *)bp[0];
+	return_addr = (void *)bp[2];
+
+	for (depth = 0; bp && depth < max_depth; depth++) {
+		return_addrs[depth] = return_addr;
+		if (return_addrs[depth] == 0)
+			break;
+		if (return_addrs[depth] == exception_stack_marker) {
+			struct pt_regs *regs;
+
+			regs = (void *)bp + STACK_FRAME_OVERHEAD;
+			bp = (unsigned long *)bp[0];
+			/* Represent interrupt frame with vector number */
+			return_addr = (void *)regs->trap;
+			if (depth + 1 < max_depth) {
+				depth++;
+				return_addrs[depth] = return_addr;
+				return_addr = (void *)regs->nip;
+			}
+		} else {
+			bp = (unsigned long *)bp[0];
+			return_addr = (void *)bp[2];
+		}
+	}
+
+	walking = 0;
+	return depth;
+}
+
+int backtrace(const void **return_addrs, int max_depth)
+{
+	return backtrace_frame(__builtin_frame_address(0), return_addrs,
+			       max_depth);
+}
powerpc/Makefile.ppc64 +1 -0
index b0ed2b104..eb682c226 100644
@@ -17,6 +17,7 @@ cstart.o = $(TEST_DIR)/cstart64.o
  reloc.o  = $(TEST_DIR)/reloc64.o
 
  OBJDIRS += lib/ppc64
+cflatobjs += lib/ppc64/stack.o
 
  # ppc64 specific tests
  tests = $(TEST_DIR)/spapr_vpa.elf
powerpc/cstart64.S +3 -2
index 14ab0c6c8..278af84a6 100644
@@ -188,6 +188,7 @@ call_handler:
  	.endr
  	mfsprg1	r0
  	std	r0,GPR1(r1)
+	std	r0,0(r1)
 
  	/* lr, xer, ccr */
 
@@ -206,12 +207,12 @@ call_handler:
  	subi	r31, r31, 0b - start_text
  	ld	r2, (p_toc_text - start_text)(r31)
 
-	/* FIXME: build stack frame */
-
  	/* call generic handler */
 
  	addi	r3,r1,STACK_FRAME_OVERHEAD
  	bl	do_handle_exception
+	.global exception_stack_marker
+exception_stack_marker:
 
  	/* restore context */
 
Quoted 9 lines

powerpc/cstart64.S handler_trampoline: · line 325

Quoted 5 lines
powerpc/cstart64.S +1 -0
@@ -321,6 +322,7 @@ handler_trampoline:
  	/* nip and msr */
  	mfsrr0	r0
  	std	r0, _NIP(r1)
+	std	r0, INT_FRAME_SIZE+16(r1)

So if I got that right, INT_FRAME_SIZE+16 points to the stack frame of the function that was running before the interrupt handler? Is it such a good idea to change that here?

No, we switch to exception stack and don't support recursing interrupts on stack at the moment, so this goes into the initial frame.

Quoted 2 lines

Please add a comment here explaining this line.
Thanks!

Yes, good idea.

Thanks,
Nick

Quoted 16 lines

powerpc/cstart64.S handler_htrampoline: · line 342

Quoted 9 lines
powerpc/cstart64.S +1 -0
  	mfsrr1	r0
  	std	r0, _MSR(r1)
@@ -337,6 +339,7 @@ handler_htrampoline:
  	/* nip and msr */
  	mfspr	r0, SPR_HSRR0
  	std	r0, _NIP(r1)
+	std	r0, INT_FRAME_SIZE+16(r1)

dito.

powerpc/cstart64.S handler_htrampoline: · line 345

Quoted 2 lines
powerpc/cstart64.S +0 -0
  	mfspr	r0, SPR_HSRR1
  	std	r0, _MSR(r1)

Thomas

#16 lore raw

PATCH 5/32 powerpc: Cleanup SPR and MSR definitions

In reply to Nicholas Piggin

Move SPR and MSR defines out of ppc_asm.h and processor.h and into a new include, asm/reg.h.

Add a define for the PVR SPR and various processor versions, and replace the open coded numbers in the sprs.c test case.

---
 lib/powerpc/asm/ppc_asm.h   |  8 +-------
 lib/powerpc/asm/processor.h |  7 +------
 lib/powerpc/asm/reg.h       | 30 ++++++++++++++++++++++++++++++
 lib/powerpc/asm/time.h      |  1 +
 lib/ppc64/asm/reg.h         |  1 +
 powerpc/sprs.c              | 21 ++++++++++-----------
 6 files changed, 44 insertions(+), 24 deletions(-)
 create mode 100644 lib/powerpc/asm/reg.h
 create mode 100644 lib/ppc64/asm/reg.h
lib/powerpc/asm/ppc_asm.h +1 -7
index 46b4be009..52a42dfbe 100644
@@ -2,6 +2,7 @@
 #define _ASMPOWERPC_PPC_ASM_H
 
 #include <asm/asm-offsets.h>
+#include <asm/reg.h>
 
 #define SAVE_GPR(n, base)	std	n,GPR0+8*(n)(base)
 #define REST_GPR(n, base)	ld	n,GPR0+8*(n)(base)
@@ -35,11 +36,4 @@
 
 #endif /* __BYTE_ORDER__ */
 
-#define SPR_HSRR0	0x13A
-#define SPR_HSRR1	0x13B
-
-/* Machine State Register definitions: */
-#define MSR_EE_BIT	15			/* External Interrupts Enable */
-#define MSR_SF_BIT	63			/* 64-bit mode */
-
 #endif /* _ASMPOWERPC_PPC_ASM_H */
lib/powerpc/asm/processor.h +1 -6
index fe1052939..e415f9235 100644
@@ -3,18 +3,13 @@
 
 #include <libcflat.h>
 #include <asm/ptrace.h>
+#include <asm/reg.h>
 
 #ifndef __ASSEMBLY__
 void handle_exception(int trap, void (*func)(struct pt_regs *, void *), void *);
 void do_handle_exception(struct pt_regs *regs);
 #endif /* __ASSEMBLY__ */
 
-#define SPR_TB		0x10c
-#define SPR_SPRG0	0x110
-#define SPR_SPRG1	0x111
-#define SPR_SPRG2	0x112
-#define SPR_SPRG3	0x113
-
 static inline uint64_t mfspr(int nr)
 {
 	uint64_t ret;
lib/powerpc/asm/reg.h new file +30 -0
new file mode 100644
index 000000000..6810c1d82
@@ -0,0 +1,30 @@
+#ifndef _ASMPOWERPC_REG_H
+#define _ASMPOWERPC_REG_H
+
+#include <linux/const.h>
+
+#define UL(x) _AC(x, UL)
+
+#define SPR_TB		0x10c
+#define SPR_SPRG0	0x110
+#define SPR_SPRG1	0x111
+#define SPR_SPRG2	0x112
+#define SPR_SPRG3	0x113
+#define SPR_PVR		0x11f
+#define   PVR_VERSION_MASK	UL(0xffff0000)
+#define   PVR_VER_970		UL(0x00390000)
+#define   PVR_VER_970FX		UL(0x003c0000)
+#define   PVR_VER_970MP		UL(0x00440000)
+#define   PVR_VER_POWER8E	UL(0x004b0000)
+#define   PVR_VER_POWER8NVL	UL(0x004c0000)
+#define   PVR_VER_POWER8	UL(0x004d0000)
+#define   PVR_VER_POWER9	UL(0x004e0000)
+#define   PVR_VER_POWER10	UL(0x00800000)
+#define SPR_HSRR0	0x13a
+#define SPR_HSRR1	0x13b
+
+/* Machine State Register definitions: */
+#define MSR_EE_BIT	15			/* External Interrupts Enable */
+#define MSR_SF_BIT	63			/* 64-bit mode */
+
+#endif
lib/powerpc/asm/time.h +1 -0
index 72fcb1bd0..a1f072989 100644
@@ -3,6 +3,7 @@
 
 #include <libcflat.h>
 #include <asm/processor.h>
+#include <asm/reg.h>
 
 static inline uint64_t get_tb(void)
 {
lib/ppc64/asm/reg.h new file +1 -0
new file mode 100644
index 000000000..bc407b555
@@ -0,0 +1 @@
+#include "../../powerpc/asm/reg.h"
powerpc/sprs.c +10 -11
index 285976488..a19d80a1a 100644
@@ -23,6 +23,7 @@
 #include <util.h>
 #include <migrate.h>
 #include <alloc.h>
+#include <asm/ppc_asm.h>
 #include <asm/handlers.h>
 #include <asm/hcall.h>
 #include <asm/processor.h>
@@ -120,25 +121,23 @@ static void set_sprs_book3s_31(uint64_t val)
 
 static void set_sprs(uint64_t val)
 {
-	uint32_t pvr = mfspr(287);	/* Processor Version Register */
-
 	set_sprs_common(val);
 
-	switch (pvr >> 16) {
-	case 0x39:			/* PPC970 */
-	case 0x3C:			/* PPC970FX */
-	case 0x44:			/* PPC970MP */
+	switch (mfspr(SPR_PVR) & PVR_VERSION_MASK) {
+	case PVR_VER_970:
+	case PVR_VER_970FX:
+	case PVR_VER_970MP:
 		set_sprs_book3s_201(val);
 		break;
-	case 0x4b:			/* POWER8E */
-	case 0x4c:			/* POWER8NVL */
-	case 0x4d:			/* POWER8 */
+	case PVR_VER_POWER8E:
+	case PVR_VER_POWER8NVL:
+	case PVR_VER_POWER8:
 		set_sprs_book3s_207(val);
 		break;
-	case 0x4e:			/* POWER9 */
+	case PVR_VER_POWER9:
 		set_sprs_book3s_300(val);
 		break;
-	case 0x80:                      /* POWER10 */
+	case PVR_VER_POWER10:
 		set_sprs_book3s_31(val);
 		break;
 	default:
Signature · 1 line
2.42.0
Reviewed-by on v1 5/32
#17 lore raw

Re: [kvm-unit-tests PATCH 05/32] powerpc: Cleanup SPR and MSR definitions

Quoted 15 lines · Nicholas Piggin

Move SPR and MSR defines out of ppc_asm.h and processor.h and into a new include, asm/reg.h.

Add a define for the PVR SPR and various processor versions, and replace the open coded numbers in the sprs.c test case.

---
  lib/powerpc/asm/ppc_asm.h   |  8 +-------
  lib/powerpc/asm/processor.h |  7 +------
  lib/powerpc/asm/reg.h       | 30 ++++++++++++++++++++++++++++++
  lib/powerpc/asm/time.h      |  1 +
  lib/ppc64/asm/reg.h         |  1 +
  powerpc/sprs.c              | 21 ++++++++++-----------
  6 files changed, 44 insertions(+), 24 deletions(-)
Quoted 2 lines

create mode 100644 lib/powerpc/asm/reg.h
create mode 100644 lib/ppc64/asm/reg.h

#18 lore raw

PATCH 6/32 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        | 647 +++++++++++++++++++++++++++++-------------
 2 files changed, 457 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 +455 -192

709 lines not on this page · raw message

Signature · 1 line
2.42.0
#19 lore raw

PATCH 7/32 powerpc/sprs: Don't fail changed SPRs that are used by the test harness

In reply to Nicholas Piggin

SPRs annotated with SPR_HARNESS can change between consecutive reads because the test harness code has changed them. Avoid failing the test in this case.

---
 powerpc/sprs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
powerpc/sprs.c +1 -1
index 8253ea971..44edd0d7b 100644
@@ -563,7 +563,7 @@ int main(int argc, char **argv)
 			if (before[i] >> 32)
 				pass = false;
 		}
-		if (!(sprs[i].type & SPR_ASYNC) && (before[i] != after[i]))
+		if (!(sprs[i].type & (SPR_HARNESS|SPR_ASYNC)) && (before[i] != after[i]))
 			pass = false;
 
 		if (sprs[i].width == 32 && !(before[i] >> 32) && !(after[i] >> 32))
Signature · 1 line
2.42.0
Reviewed-by on v1 7/32
#20 lore raw

Re: [kvm-unit-tests PATCH 07/32] powerpc/sprs: Don't fail changed SPRs that are used by the test harness

Quoted 14 lines · Nicholas Piggin

SPRs annotated with SPR_HARNESS can change between consecutive reads because the test harness code has changed them. Avoid failing the test in this case.

---
  powerpc/sprs.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
powerpc/sprs.c +0 -0
index 8253ea971..44edd0d7b 100644

powerpc/sprs.c int main(int argc, char **argv) · line 569

Quoted 8 lines
powerpc/sprs.c +1 -1
@@ -563,7 +563,7 @@ int main(int argc, char **argv)
  			if (before[i] >> 32)
  				pass = false;
  		}
-		if (!(sprs[i].type & SPR_ASYNC) && (before[i] != after[i]))
+		if (!(sprs[i].type & (SPR_HARNESS|SPR_ASYNC)) && (before[i] != after[i]))
  			pass = false;
 
  		if (sprs[i].width == 32 && !(before[i] >> 32) && !(after[i] >> 32))

I guess you could also squash this into the previous patch (to avoid problems with bisecting later?) ...

Anyway:

#21 lore raw

Re: [kvm-unit-tests PATCH 07/32] powerpc/sprs: Don't fail changed SPRs that are used by the test harness

Quoted 22 lines · Thomas Huth
Quoted 21 lines · Nicholas Piggin

SPRs annotated with SPR_HARNESS can change between consecutive reads because the test harness code has changed them. Avoid failing the test in this case.

---
  powerpc/sprs.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
powerpc/sprs.c +1 -1
index 8253ea971..44edd0d7b 100644
@@ -563,7 +563,7 @@ int main(int argc, char **argv)
  			if (before[i] >> 32)
  				pass = false;
  		}
-		if (!(sprs[i].type & SPR_ASYNC) && (before[i] != after[i]))
+		if (!(sprs[i].type & (SPR_HARNESS|SPR_ASYNC)) && (before[i] != after[i]))
  			pass = false;
 
Quoted 4 lines

powerpc/sprs.c int main(int argc, char **argv) · line 569

Quoted 1 line
powerpc/sprs.c +0 -0
  		if (sprs[i].width == 32 && !(before[i] >> 32) && !(after[i] >> 32))

I guess you could also squash this into the previous patch (to avoid problems with bisecting later?) ...

Yeah, I guess it doesn't make much sense to split out since lots of other stuff changes in the previous patch too.

Quoted 3 lines

Anyway:

Thanks,
Nick

#22 lore raw

PATCH 8/32 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 44edd0d7b..cb1d6c980 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.42.0
Reviewed-by on v1 8/32
#23 lore raw

Re: [kvm-unit-tests PATCH 08/32] powerpc/sprs: Avoid taking PMU interrupts caused by register fuzzing

Quoted 9 lines · 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(-)
#24 lore raw

PATCH 9/32 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.

---
 scripts/common.bash  |  8 ++++++--
 scripts/runtime.bash | 16 ++++++++++++----
 2 files changed, 18 insertions(+), 6 deletions(-)
scripts/common.bash +6 -2
index b9413d683..ee1dd8659 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 c73fb0240..8f9672d0d 100644
@@ -30,7 +30,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()
@@ -78,9 +78,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}
@@ -114,6 +115,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.42.0
#25 lore raw

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

Quoted 10 lines · Nicholas Piggin

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

---
 scripts/common.bash  |  8 ++++++--
 scripts/runtime.bash | 16 ++++++++++++----
 2 files changed, 18 insertions(+), 6 deletions(-)

Please also update the unittests.cfg documentation. Currently that documentation lives in the header of each unittests.cfg file, but we could maybe change each file to have a single line which points at a single document.

Thanks,
drew

#26 lore raw

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

Quoted 5 lines · Andrew Jones
Quoted 4 lines · Nicholas Piggin

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

Quoted 8 lines
Quoted 6 lines
---
 scripts/common.bash  |  8 ++++++--
 scripts/runtime.bash | 16 ++++++++++++----
 2 files changed, 18 insertions(+), 6 deletions(-)

Please also update the unittests.cfg documentation.

Yeah good catch, I will do.

Quoted 4 lines

Currently that
documentation lives in the header of each unittests.cfg file, but we could maybe change each file to have a single line which points at a single document.

I'll take a look and do something if it's simple enough, otherwise I'll just update the unittests.cfg.

Thanks,
Nick

#27 lore raw

PATCH 10/32 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.

---
 scripts/runtime.bash | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/runtime.bash +2 -2
index 8f9672d0d..bb32c0d10 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
@@ -18,7 +18,7 @@ premature_failure()
     local 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" &&
+        grep -q -e "[Cc]ould not \(load\|open\) kernel" -e "error loading" &&
         return 1
 
     RUNTIME_log_stderr <<< "$log"
Signature · 1 line
2.42.0
Acked-by on v1 10/32
#28 lore raw

Re: [kvm-unit-tests PATCH 10/32] scripts: Accommodate powerpc powernv machine differences

Quoted 39 lines · 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.

---
 scripts/runtime.bash | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/runtime.bash +2 -2
index 8f9672d0d..bb32c0d10 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
@@ -18,7 +18,7 @@ premature_failure()
     local 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" &&
+        grep -q -e "[Cc]ould not \(load\|open\) kernel" -e "error loading" &&
         return 1
 
     RUNTIME_log_stderr <<< "$log"
Signature · 1 line
2.42.0
#29 lore raw

PATCH 11/32 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 278af84a6..5e091e325 100644
@@ -100,6 +100,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 fadd8dde6..41bb8a327 100644
@@ -33,11 +33,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]
@@ -55,24 +56,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
@@ -82,6 +88,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"
@@ -92,5 +99,6 @@ file = sprs.elf
 
 [sprs-migration]
 file = sprs.elf
+machine = pseries
 extra_params = -append '-w'
 groups = migration
Signature · 1 line
2.42.0
#30 lore raw

PATCH 12/32 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          | 21 ++++++++++++++++++++-
 3 files changed, 34 insertions(+), 1 deletion(-)
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 +20 -1
index 39dd59645..c9b17f742 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;
@@ -362,7 +376,12 @@ 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(0x700, program_check_handler, (void *)&is_invalid);
+	} else {
+		handle_exception(0x700, program_check_handler, (void *)&is_invalid);
+	}
 	handle_exception(0x600, alignment_handler, (void *)&alignment);
 
 	for (i = 1; i < argc; i++) {
Signature · 1 line
2.42.0
#31 lore raw

Re: [kvm-unit-tests PATCH 12/32] powerpc: Fix emulator illegal instruction test for powernv

Quoted 80 lines · 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          | 21 ++++++++++++++++++++-
  3 files changed, 34 insertions(+), 1 deletion(-)
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 +14 -0
index 39dd59645..c9b17f742 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;

powerpc/emulator.c int main(int argc, char **argv) · line 383

Quoted 9 lines
powerpc/emulator.c +5 -1
@@ -362,7 +376,12 @@ 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(0x700, program_check_handler, (void *)&is_invalid);
+	} else {
+		handle_exception(0x700, program_check_handler, (void *)&is_invalid);

The 0x700 line looks identical to the other part of the if-statement ... I'd suggest to leave it outside of the if-statement, drop the else-part and just set 0xe40 if cpu_has_heai.

Thomas

Quoted 4 lines
powerpc/emulator.c +1 -0
+	}
  	handle_exception(0x600, alignment_handler, (void *)&alignment);
 
  	for (i = 1; i < argc; i++) {
#32 lore raw

Re: [kvm-unit-tests PATCH 12/32] powerpc: Fix emulator illegal instruction test for powernv

Quoted 84 lines · Thomas Huth
Quoted 83 lines · 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          | 21 ++++++++++++++++++++-
  3 files changed, 34 insertions(+), 1 deletion(-)
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 +14 -0
index 39dd59645..c9b17f742 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;
@@ -362,7 +376,12 @@ int main(int argc, char **argv)
  {
  	int i;
 
Quoted 10 lines

powerpc/emulator.c int main(int argc, char **argv) · line 383

Quoted 6 lines
powerpc/emulator.c +5 -1
-	handle_exception(0x700, program_check_handler, (void *)&is_invalid);
+	if (cpu_has_heai) {
+		handle_exception(0xe40, heai_handler, (void *)&is_invalid);
+		handle_exception(0x700, program_check_handler, (void *)&is_invalid);
+	} else {
+		handle_exception(0x700, program_check_handler, (void *)&is_invalid);

The 0x700 line looks identical to the other part of the if-statement ... I'd suggest to leave it outside of the if-statement, drop the else-part and just set 0xe40 if cpu_has_heai.

Can do.

Thanks,
Nick

#33 lore raw

PATCH 13/32 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 cb1d6c980..0a82418d6 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.42.0
#34 lore raw

PATCH 14/32 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        | 415 ++++++++++++++++++++++++++++++++++++
 powerpc/unittests.cfg       |   3 +
 7 files changed, 468 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 +415 -0

415 lines not on this page · raw message

powerpc/unittests.cfg +3 -0
index 41bb8a327..93c54f52a 100644
@@ -86,6 +86,9 @@ groups = rtas
 [emulator]
 file = emulator.elf
 
+[interrupts]
+file = interrupts.elf
+
 [h_cede_tm]
 file = tm.elf
 machine = pseries
Signature · 1 line
2.42.0
#35 lore raw

Re: [kvm-unit-tests PATCH 14/32] powerpc: general interrupt tests

Quoted 5 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.

Two questions out of curiosity:

Any chance that this could be fixed easily in QEMU?

Or is there a way to detect TCG from within the test? (for example, we have a host_is_tcg() function for s390x so we can e.g. use report_xfail() for tests that are known to fail on TCG there)

Quoted 171 lines
---
  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        | 415 ++++++++++++++++++++++++++++++++++++
  powerpc/unittests.cfg       |   3 +
  7 files changed, 468 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 +0 -0
new file mode 100644
index 000000000..442f8c569

powerpc/interrupts.c line 6

Quoted 6 lines
powerpc/interrupts.c new file +6 -0
@@ -0,0 +1,415 @@
+/*
+ * Test interrupts
+ *
+ * Copyright 2024 Nicholas Piggin, IBM Corp.
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.

I know, we're using this line in a lot of source files ... but maybe we should do better for new files at least: "LGPL, version 2" is a little bit ambiguous: Does it mean the "Library GPL version 2.0" or the "Lesser GPL version 2.1"? Maybe you could clarify by additionally providing a SPDX identifier here, or by explicitly writing 2.0 or 2.1.

Thanks,
Thomas

#36 lore raw

Re: [kvm-unit-tests PATCH 14/32] powerpc: general interrupt tests

Quoted 7 lines · Thomas Huth
Quoted 5 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.

Quoted 7 lines

Two questions out of curiosity:

Any chance that this could be fixed easily in QEMU?

Or is there a way to detect TCG from within the test? (for example, we have a host_is_tcg() function for s390x so we can e.g. use report_xfail() for tests that are known to fail on TCG there)

If there's nothing better, then it should be possible to check the QEMU_ACCEL environment variable which will be there with the default environ.

Quoted 14 lines

powerpc/interrupts.c line 6

Quoted 8 lines
powerpc/interrupts.c new file +6 -0
@@ -0,0 +1,415 @@
+/*
+ * Test interrupts
+ *
+ * Copyright 2024 Nicholas Piggin, IBM Corp.
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.

I know, we're using this line in a lot of source files ... but maybe we should do better for new files at least: "LGPL, version 2" is a little bit
ambiguous: Does it mean the "Library GPL version 2.0" or the "Lesser GPL version 2.1"? Maybe you could clarify by additionally providing a SPDX identifier here, or by explicitly writing 2.0 or 2.1.

Let's only add SPDX identifiers to new files.

Thanks,
drew

#37 lore raw

Re: [kvm-unit-tests PATCH 14/32] powerpc: general interrupt tests

Quoted 12 lines · Andrew Jones
Quoted 11 lines · Thomas Huth
Quoted 5 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.

Two questions out of curiosity:

Any chance that this could be fixed easily in QEMU?

Quoted 7 lines
Quoted 3 lines

Or is there a way to detect TCG from within the test? (for example, we have a host_is_tcg() function for s390x so we can e.g. use report_xfail() for tests that are known to fail on TCG there)

If there's nothing better, then it should be possible to check the QEMU_ACCEL environment variable which will be there with the default environ.

Well, but that's only available from the host side, not within the test (i.e. the guest). So that does not help much with report_xfail... I was rather thinking of something like checking the device tree, e.g. for the compatible property in /hypervisor to see whether it's KVM or TCG...?

Thomas

#38 lore raw

Re: [kvm-unit-tests PATCH 14/32] powerpc: general interrupt tests

Quoted 17 lines · Thomas Huth
Quoted 16 lines · Andrew Jones
Quoted 14 lines · Thomas Huth
Quoted 5 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.

Two questions out of curiosity:

Any chance that this could be fixed easily in QEMU?

Or is there a way to detect TCG from within the test? (for example, we have a host_is_tcg() function for s390x so we can e.g. use report_xfail() for tests that are known to fail on TCG there)

Quoted 6 lines
Quoted 3 lines

If there's nothing better, then it should be possible to check the QEMU_ACCEL environment variable which will be there with the default environ.

Well, but that's only available from the host side, not within the test (i.e. the guest). So that does not help much with report_xfail...

powerpc has had environment variables in guests since commit f266c3e8ef15 ("powerpc: enable environ"). QEMU_ACCEL is one of the environment variables given to unit tests by default when ENVIRON_DEFAULT is 'yes', as is the default set in configure. But...

Quoted 2 lines

I was rather thinking of something like checking the device tree, e.g. for the compatible property in /hypervisor to see whether it's KVM or TCG...?

...while QEMU_ACCEL will work when the environ is present, DT will always be present, so checking the hypervisor node sounds better to me.

Thanks,
drew

#39 lore raw

Re: [kvm-unit-tests PATCH 14/32] powerpc: general interrupt tests

Quoted 30 lines · Andrew Jones
Quoted 17 lines · Thomas Huth
Quoted 16 lines · Andrew Jones
Quoted 14 lines · Thomas Huth
Quoted 5 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.

Two questions out of curiosity:

Any chance that this could be fixed easily in QEMU?

Or is there a way to detect TCG from within the test? (for example, we have a host_is_tcg() function for s390x so we can e.g. use report_xfail() for tests that are known to fail on TCG there)

Quoted 6 lines
Quoted 3 lines

If there's nothing better, then it should be possible to check the QEMU_ACCEL environment variable which will be there with the default environ.

Well, but that's only available from the host side, not within the test (i.e. the guest). So that does not help much with report_xfail...

powerpc has had environment variables in guests since commit f266c3e8ef15 ("powerpc: enable environ"). QEMU_ACCEL is one of the environment variables given to unit tests by default when ENVIRON_DEFAULT is 'yes', as is the default set in configure. But...

Quoted 5 lines
Quoted 2 lines

I was rather thinking of something like checking the device tree, e.g. for the compatible property in /hypervisor to see whether it's KVM or TCG...?

...while QEMU_ACCEL will work when the environ is present, DT will always be present, so checking the hypervisor node sounds better to me.

Yeah I got that.

One issue with xfail I noted when looking at this earlier, is that it *always* expects a fail, and fails if it succeeds. So if you fix a QEMU bug then you introduce a fail to kvm-unit-tests. So we really want a report_known_bug(cond, "SPRs look sane", "QEMU TCG before v9.0 and POWER9 DD2.0 is known to fail..."); and that could report a maybe-fail that doesn't make the test group fail.

Thanks,
Nick

#40 lore raw

Re: [kvm-unit-tests PATCH 14/32] powerpc: general interrupt tests

In reply to Andrew Jones
Quoted 35 lines · Andrew Jones
Quoted 7 lines · Thomas Huth
Quoted 5 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.

Quoted 7 lines

Two questions out of curiosity:

Any chance that this could be fixed easily in QEMU?

Or is there a way to detect TCG from within the test? (for example, we have a host_is_tcg() function for s390x so we can e.g. use report_xfail() for tests that are known to fail on TCG there)

If there's nothing better, then it should be possible to check the QEMU_ACCEL environment variable which will be there with the default environ.

Quoted 14 lines

powerpc/interrupts.c line 6

Quoted 8 lines
powerpc/interrupts.c new file +6 -0
@@ -0,0 +1,415 @@
+/*
+ * Test interrupts
+ *
+ * Copyright 2024 Nicholas Piggin, IBM Corp.
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.

I know, we're using this line in a lot of source files ... but maybe we should do better for new files at least: "LGPL, version 2" is a little bit
ambiguous: Does it mean the "Library GPL version 2.0" or the "Lesser GPL version 2.1"? Maybe you could clarify by additionally providing a SPDX identifier here, or by explicitly writing 2.0 or 2.1.

Quoted 1 line

Let's only add SPDX identifiers to new files.

+1

Speaking of which, a bunch of these just got inherited from the file that was copied to begin with (I tried not to remove copyright notices unless there was really nothing of the original remaining). So for new code/files, is there any particular preference for the license to use? I don't much mind between the *GPL*. Looks like almost all the SPDX code use GPL 2.0 only, but that could be just from coming from Linux. I might just go with that.

Thanks,
Nick

#41 lore raw

Re: [kvm-unit-tests PATCH 14/32] powerpc: general interrupt tests

Quoted 40 lines · Nicholas Piggin
Quoted 35 lines · Andrew Jones
Quoted 7 lines · Thomas Huth
Quoted 5 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.

Quoted 7 lines

Two questions out of curiosity:

Any chance that this could be fixed easily in QEMU?

Or is there a way to detect TCG from within the test? (for example, we have a host_is_tcg() function for s390x so we can e.g. use report_xfail() for tests that are known to fail on TCG there)

If there's nothing better, then it should be possible to check the QEMU_ACCEL environment variable which will be there with the default environ.

Quoted 14 lines

powerpc/interrupts.c line 6

Quoted 8 lines
powerpc/interrupts.c new file +6 -0
@@ -0,0 +1,415 @@
+/*
+ * Test interrupts
+ *
+ * Copyright 2024 Nicholas Piggin, IBM Corp.
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.

I know, we're using this line in a lot of source files ... but maybe we should do better for new files at least: "LGPL, version 2" is a little bit
ambiguous: Does it mean the "Library GPL version 2.0" or the "Lesser GPL version 2.1"? Maybe you could clarify by additionally providing a SPDX identifier here, or by explicitly writing 2.0 or 2.1.

Quoted 1 line

Let's only add SPDX identifiers to new files.

+1

Quoted 7 lines

Speaking of which, a bunch of these just got inherited from the file that was copied to begin with (I tried not to remove copyright notices unless there was really nothing of the original remaining). So for new code/files, is there any particular preference for the license to use? I don't much mind between the *GPL*. Looks like almost all the SPDX code use GPL 2.0 only, but that could be just from coming from Linux. I might just go with that.

k-u-t were originally licensed under the LGPL, but in the course of time, code has been copied from the Linux kernel here and there, so we updated the license to GPL 2.
So yes, for code that might have been copied from the kernel, we have to use GPL 2. For other code, it's up to the author to chose. (IIRC we once discussed that LGPL would be nice for the files in the lib/ directory, while GPL is fine for the other folders, but my memory might fail here and it was never written in stone anyway)

Thomas

#42 lore raw

Re: [kvm-unit-tests PATCH 14/32] powerpc: general interrupt tests

In reply to Thomas Huth
Quoted 10 lines · Thomas Huth
Quoted 5 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.

Two questions out of curiosity:

Any chance that this could be fixed easily in QEMU?

Yes I have a fix on the mailing list. It should get into 9.0 and probably stable.

Quoted 3 lines

Or is there a way to detect TCG from within the test? (for example, we have a host_is_tcg() function for s390x so we can e.g. use report_xfail() for tests that are known to fail on TCG there)

I do have a half-done patch which adds exactly this.

One (minor) annoyance is that it doesn't seem possible to detect QEMU version to add workarounds. E.g., we would like to test the fixed functionality, but older qemu should not. Maybe that's going too much into a rabbit hole. We *could* put a QEMU version into device tree to deal with this though...

Thanks,
Nick

Quoted 176 lines
Quoted 176 lines
---
  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        | 415 ++++++++++++++++++++++++++++++++++++
  powerpc/unittests.cfg       |   3 +
  7 files changed, 468 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 +4 -0
new file mode 100644
index 000000000..442f8c569
@@ -0,0 +1,415 @@
+/*
+ * Test interrupts
+ *
+ * Copyright 2024 Nicholas Piggin, IBM Corp.
Quoted 8 lines

powerpc/interrupts.c line 6

Quoted 2 lines
powerpc/interrupts.c new file +2 -0
+ *
+ * This work is licensed under the terms of the GNU LGPL, version 2.

I know, we're using this line in a lot of source files ... but maybe we should do better for new files at least: "LGPL, version 2" is a little bit
ambiguous: Does it mean the "Library GPL version 2.0" or the "Lesser GPL version 2.1"? Maybe you could clarify by additionally providing a SPDX identifier here, or by explicitly writing 2.0 or 2.1.

Sure I'll try to improve this for all the new files.

Thanks,
Nick

#43 lore raw

Re: [kvm-unit-tests PATCH 14/32] powerpc: general interrupt tests

Quoted 8 lines · Nicholas Piggin
Quoted 7 lines · Thomas Huth
Quoted 5 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.

Quoted 6 lines
Quoted 3 lines

Two questions out of curiosity:

Any chance that this could be fixed easily in QEMU?

Yes I have a fix on the mailing list. It should get into 9.0 and probably stable.

Ok, then it's IMHO not worth the effort to make the k-u-t work around this bug in older QEMU versions.

Quoted 11 lines
Quoted 3 lines

Or is there a way to detect TCG from within the test? (for example, we have a host_is_tcg() function for s390x so we can e.g. use report_xfail() for tests that are known to fail on TCG there)

I do have a half-done patch which adds exactly this.

One (minor) annoyance is that it doesn't seem possible to detect QEMU version to add workarounds. E.g., we would like to test the fixed functionality, but older qemu should not. Maybe that's going too much into a rabbit hole. We *could* put a QEMU version into device tree to deal with this though...

No, let's better not do this - hardwired version checks are often a bad idea, e.g. when a bug is in QEMU 8.0.0 and 8.1.0, it could be fixed in 8.0.1 and then it could get really messy with the version checks...

Thomas

#44 lore raw

Re: [kvm-unit-tests PATCH 14/32] powerpc: general interrupt tests

Quoted 31 lines · Thomas Huth
Quoted 8 lines · Nicholas Piggin
Quoted 7 lines · Thomas Huth
Quoted 5 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.

Quoted 6 lines
Quoted 3 lines

Two questions out of curiosity:

Any chance that this could be fixed easily in QEMU?

Yes I have a fix on the mailing list. It should get into 9.0 and probably stable.

Ok, then it's IMHO not worth the effort to make the k-u-t work around this bug in older QEMU versions.

Quoted 11 lines
Quoted 3 lines

Or is there a way to detect TCG from within the test? (for example, we have a host_is_tcg() function for s390x so we can e.g. use report_xfail() for tests that are known to fail on TCG there)

I do have a half-done patch which adds exactly this.

One (minor) annoyance is that it doesn't seem possible to detect QEMU version to add workarounds. E.g., we would like to test the fixed functionality, but older qemu should not. Maybe that's going too much into a rabbit hole. We *could* put a QEMU version into device tree to deal with this though...

Quoted 4 lines

No, let's better not do this - hardwired version checks are often a bad idea, e.g. when a bug is in QEMU 8.0.0 and 8.1.0, it could be fixed in 8.0.1 and then it could get really messy with the version checks...

We've tried to address this type of issue (but for KVM, so kernel versions instead of QEMU versions) in the past by inventing the errata framework, which is based on environment variables. Instead of checking for versions, we check for a hash (which is just the commit hash of the fix). While we do guess that the fix is present by version number, it can always be manually set as present as well. In any case, the test is simply skipped when the errata environment variable isn't present, so in the worst case we lose some coverage we could have had, but the rest of the tests still complete and we don't get the same failures over and over. An example of its use is in arm/psci.c. Look for the ERRATA() calls.

We could extend the errata framework for QEMU/TCG. We just need to add another bit of data to the errata.txt file for it to know it should check QEMU versions instead of kernel versions for those errata. We can also ignore the errata framework and just create the errata environment variable which would by 'n' by default now and later, after distros have fixes, it could be changed to 'y'.

Thanks,
drew

#45 lore raw

PATCH 15/32 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.42.0
#46 lore raw

PATCH 16/32 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..496af40f8 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));
+
 	enable_mcheck();
 
 	/*
Signature · 1 line
2.42.0
#47 lore raw

PATCH 17/32 arch-run: Fix handling multiple exit status messages

In reply to Nicholas Piggin

In SMP tests, it's possible for multiple CPUs to print an exit message if they abort concurrently, confusing the harness:

EXIT: STATUS=127

EXIT: STATUS=127
scripts/arch-run.bash: line 85: [: too many arguments scripts/arch-run.bash: line 93: return: too many arguments

lib/arch code should probably serialise this to prevent it, but at the moment not all do. So make the parser handle this by just looking at the first EXIT.

---
 scripts/arch-run.bash | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/arch-run.bash +1 -1
index 5c7e72036..4af670f1c 100644
@@ -79,7 +79,7 @@ run_qemu_status ()
 	exec {stdout}>&-
 
 	if [ $ret -eq 1 ]; then
-		testret=$(grep '^EXIT: ' <<<"$lines" | sed 's/.*STATUS=\([0-9][0-9]*\).*/\1/')
+		testret=$(grep '^EXIT: ' <<<"$lines" | head -n1 | sed 's/.*STATUS=\([0-9][0-9]*\).*/\1/')
 		if [ "$testret" ]; then
 			if [ $testret -eq 1 ]; then
 				ret=0
Signature · 1 line
2.42.0
Acked-by on v1 17/32
#48 lore raw

Re: [kvm-unit-tests PATCH 17/32] arch-run: Fix handling multiple exit status messages

Quoted 38 lines · Nicholas Piggin

In SMP tests, it's possible for multiple CPUs to print an exit message if they abort concurrently, confusing the harness:

EXIT: STATUS=127

EXIT: STATUS=127
scripts/arch-run.bash: line 85: [: too many arguments scripts/arch-run.bash: line 93: return: too many arguments

lib/arch code should probably serialise this to prevent it, but at the moment not all do. So make the parser handle this by just looking at the first EXIT.

---
 scripts/arch-run.bash | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
scripts/arch-run.bash +1 -1
index 5c7e72036..4af670f1c 100644
@@ -79,7 +79,7 @@ run_qemu_status ()
 	exec {stdout}>&-
 
 	if [ $ret -eq 1 ]; then
-		testret=$(grep '^EXIT: ' <<<"$lines" | sed 's/.*STATUS=\([0-9][0-9]*\).*/\1/')
+		testret=$(grep '^EXIT: ' <<<"$lines" | head -n1 | sed 's/.*STATUS=\([0-9][0-9]*\).*/\1/')
 		if [ "$testret" ]; then
 			if [ $testret -eq 1 ]; then
 				ret=0
Signature · 1 line
2.42.0
#49 lore raw

PATCH 18/32 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       |  46 +++--
 lib/powerpc/io.c            |  15 +-
 lib/powerpc/processor.c     |   7 +-
 lib/powerpc/setup.c         |  90 +++++++---
 lib/powerpc/smp.c           | 282 +++++++++++++++++++++++++----
 lib/ppc64/asm-offsets.c     |   7 +
 lib/ppc64/asm/atomic.h      |   6 +
 lib/ppc64/asm/barrier.h     |   3 +
 lib/ppc64/asm/opal.h        |   7 +
 powerpc/Makefile.common     |   1 +
 powerpc/cstart64.S          |  52 +++++-
 powerpc/selftest.c          |   4 +-
 powerpc/smp.c               | 349 ++++++++++++++++++++++++++++++++++++
 powerpc/tm.c                |   4 +-
 powerpc/unittests.cfg       |   8 +
 18 files changed, 822 insertions(+), 85 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 +35 -11

56 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 +246 -36

341 lines not on this page · raw message

lib/ppc64/asm-offsets.c +7 -0
index 7843a20b4..0ac2c9a75 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,10 @@ 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(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 +3 -0
index 76f6efa78..475434b6a 100644
@@ -1,6 +1,9 @@
 #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")
 #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 68165fc25..744dfc1f7 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 +50 -2

70 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 +349 -0

349 lines not on this page · raw message

powerpc/tm.c +2 -2
index 6b1ceeb6e..efbcf1f12 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,7 +133,7 @@ int main(int argc, char **argv)
 		report_skip("TM is not available");
 		goto done;
 	}
-	report(cpus_with_tm == nr_cpus,
+	report(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 93c54f52a..97a549c0d 100644
@@ -89,6 +89,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.42.0
#50 lore raw

PATCH 19/32 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 97a549c0d..915b6a482 100644
@@ -97,6 +97,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.42.0
#51 lore raw

PATCH 20/32 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   | 28 ++++++++++++++++++++++++++++
 lib/ppc64/asm/spinlock.h |  7 ++++++-
 powerpc/Makefile.common  |  1 +
 5 files changed, 41 insertions(+), 1 deletion(-)
 create mode 100644 lib/powerpc/spinlock.c
lib/powerpc/asm/smp.h +1 -0
index 4519e5436..6ef3ae521 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 a3bf85d44..f3b2a3faf 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);
@@ -308,8 +311,10 @@ bool start_all_cpus(secondary_entry_fn entry)
 
 void stop_all_cpus(void)
 {
+	assert(multithreaded);
 	while (nr_cpus_online > 1)
 		cpu_relax();
 	mb();
 	nr_started = 1;
+	multithreaded = false;
 }
lib/powerpc/spinlock.c new file +28 -0
new file mode 100644
index 000000000..238549f12
@@ -0,0 +1,28 @@
+#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 744dfc1f7..02af54b83 100644
@@ -48,6 +48,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.42.0
#52 lore raw

PATCH 21/32 powerpc: Add atomics tests

In reply to Nicholas Piggin
---
 powerpc/Makefile.common |   1 +
 powerpc/atomics.c       | 373 ++++++++++++++++++++++++++++++++++++++++
 powerpc/unittests.cfg   |   9 +
 3 files changed, 383 insertions(+)
 create mode 100644 powerpc/atomics.c
powerpc/Makefile.common +1 -0
index 02af54b83..b6f9b3b85 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 +373 -0

373 lines not on this page · raw message

powerpc/unittests.cfg +9 -0
index 915b6a482..f8d43c220 100644
@@ -103,6 +103,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.42.0
#53 lore raw

PATCH 22/32 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      | 330 ++++++++++++++++++++++++++++++++++++++++
 powerpc/unittests.cfg   |   8 +
 4 files changed, 340 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 b6f9b3b85..1348f658b 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 +330 -0

330 lines not on this page · raw message

powerpc/unittests.cfg +8 -0
index f8d43c220..3ebdf9dd3 100644
@@ -112,6 +112,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.42.0
#54 lore raw

PATCH 23/32 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           |   4 +
 lib/ppc64/asm/mmu.h           |  11 ++
 lib/ppc64/asm/page.h          |  67 ++++++++-
 lib/ppc64/asm/pgtable-hwdef.h |  67 +++++++++
 lib/ppc64/asm/pgtable.h       | 126 ++++++++++++++++
 lib/ppc64/mmu.c               | 273 ++++++++++++++++++++++++++++++++++
 lib/ppc64/opal-calls.S        |   4 +-
 powerpc/Makefile.common       |   2 +
 powerpc/Makefile.ppc64        |   1 +
 powerpc/interrupts.c          |  96 ++++++++++--
 16 files changed, 684 insertions(+), 27 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
configure +26 -13
index 05e6702ea..6907ccbbb 100755
@@ -222,29 +222,35 @@ fi
 if [ -z "$page_size" ]; then
     if [ "$efi" = 'y' ] && [ "$arch" = "arm64" ]; then
         page_size="4096"
-    elif [ "$arch" = "arm64" ]; then
+    elif [ "$arch" = "arm64" ] || [ "$arch" = "ppc64" ]; then
         page_size="65536"
     elif [ "$arch" = "arm" ]; then
         page_size="4096"
     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"
@@ -444,6 +450,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 6ef3ae521..820c05e9e 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;
 } __attribute__((packed)); /* used by asm */
 
 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 +4 -0
index 16f009152..ba659cc2b 100644
@@ -102,6 +102,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;
@@ -124,6 +125,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:
@@ -198,6 +200,7 @@ void cpu_init(struct cpu *cpu, int cpu_id)
 	cpu->stack += SZ_64K - 64;
 	cpu->exception_stack = (unsigned long)memalign(SZ_4K, SZ_64K);
 	cpu->exception_stack += SZ_64K - 64;
+	cpu->pgtable = NULL;
 }
 
 void setup(const void *fdt)
@@ -216,6 +219,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 += SZ_64K - 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 +66 -1

67 lines not on this page · raw message

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

67 lines not on this page · raw message

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

126 lines not on this page · raw message

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

273 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 +2 -0
index 1348f658b..5871da47a 100644
@@ -41,6 +41,8 @@ cflatobjs += lib/util.o
 cflatobjs += lib/getchar.o
 cflatobjs += lib/alloc_phys.o
 cflatobjs += lib/alloc.o
+cflatobjs += lib/alloc_page.o
+cflatobjs += lib/vmalloc.o
 cflatobjs += lib/devicetree.o
 cflatobjs += lib/migrate.o
 cflatobjs += lib/powerpc/io.o
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

Signature · 1 line
2.42.0
#55 lore raw

Re: [kvm-unit-tests PATCH 23/32] powerpc: Add MMU support

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

---
 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           |   4 +
 lib/ppc64/asm/mmu.h           |  11 ++
 lib/ppc64/asm/page.h          |  67 ++++++++-
 lib/ppc64/asm/pgtable-hwdef.h |  67 +++++++++
 lib/ppc64/asm/pgtable.h       | 126 ++++++++++++++++
 lib/ppc64/mmu.c               | 273 ++++++++++++++++++++++++++++++++++
 lib/ppc64/opal-calls.S        |   4 +-
 powerpc/Makefile.common       |   2 +
 powerpc/Makefile.ppc64        |   1 +
 powerpc/interrupts.c          |  96 ++++++++++--
 16 files changed, 684 insertions(+), 27 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
configure +19 -13
index 05e6702ea..6907ccbbb 100755
@@ -222,29 +222,35 @@ fi
 if [ -z "$page_size" ]; then
     if [ "$efi" = 'y' ] && [ "$arch" = "arm64" ]; then
         page_size="4096"
-    elif [ "$arch" = "arm64" ]; then
+    elif [ "$arch" = "arm64" ] || [ "$arch" = "ppc64" ]; then
         page_size="65536"
     elif [ "$arch" = "arm" ]; then
         page_size="4096"
     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"
@@ -444,6 +450,13 @@ cat <<EOF >> lib/config.h
 
 #define CONFIG_UART_EARLY_BASE ${arm_uart_early_addr}
 #define CONFIG_ERRATA_FORCE ${errata_force}

configure cat <<EOF >> lib/config.h · line 462

Quoted 10 lines
configure +7 -0
+
+EOF
+fi
+
+if [ "$arch" = "arm" ] || [ "$arch" = "arm64" ] || [ "$arch" = "ppc64" ]; then
+cat <<EOF >> lib/config.h
+
 #define CONFIG_PAGE_SIZE _AC(${page_size}, UL)
 
 EOF

Ack for the configure changes.

Thanks,
drew

#56 lore raw

PATCH 24/32 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 Andrew Jones <[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 700f43527..8c8dd0286 100644
@@ -152,8 +152,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 296338d4f..a0cfc575a 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.42.0
Acked-by on v1 24/32
#57 lore raw

Re: [kvm-unit-tests PATCH 24/32] 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 Andrew Jones <[email protected]>
Cc Janosch Frank <[email protected]>
Cc Claudio Imbrenda <[email protected]>
Cc Nico Böhr <[email protected]>
Cc David Hildenbrand <[email protected]>
Quoted 14 lines
---
 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(-)
#58 lore raw

PATCH 25/32 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 6adf94151..f1219033a 100644
@@ -24,7 +24,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.42.0
Reviewed-by on v1 25/32
#59 lore raw

Re: [kvm-unit-tests PATCH 25/32] common/sieve: Support machines without MMU

Quoted 8 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.

Quoted 8 lines
---
 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(-)
#60 lore raw

PATCH 26/32 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 5871da47a..410a675d9 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 3ebdf9dd3..008559b43 100644
@@ -136,3 +136,6 @@ file = sprs.elf
 machine = pseries
 extra_params = -append '-w'
 groups = migration
+
+[sieve]
+file = sieve.elf
Signature · 1 line
2.42.0
#61 lore raw

PATCH 27/32 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 820c05e9e..b96a55903 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;
 } __attribute__((packed)); /* used by asm */
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 ba659cc2b..30b988a5c 100644
@@ -201,8 +201,11 @@ void cpu_init(struct cpu *cpu, int cpu_id)
 	cpu->exception_stack = (unsigned long)memalign(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;
@@ -211,8 +214,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];
@@ -220,10 +221,13 @@ void setup(const void *fdt)
 	cpu->exception_stack = (unsigned long)boot_exception_stack;
 	cpu->exception_stack += SZ_64K - 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 238549f12..59dc4fbb5 100644
@@ -8,6 +8,8 @@
  */
 void spin_lock(struct spinlock *lock)
 {
+	assert(!in_usermode());
+
 	if (!multithreaded) {
 		assert(lock->v == 0);
 		lock->v = 1;
@@ -19,7 +21,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 f1219033a..313da6e78 100644
@@ -43,6 +43,7 @@ void mmu_enable(pgd_t *pgtable)
 
 	cpu->pgtable = pgtable;
 
+	assert(!in_usermode());
 	mtmsr(mfmsr() | (MSR_IR|MSR_DR));
 }
 
@@ -52,6 +53,7 @@ void mmu_disable(void)
 
 	cpu->pgtable = NULL;
 
+	assert(!in_usermode());
 	mtmsr(mfmsr() & ~(MSR_IR|MSR_DR));
 }
 
powerpc/interrupts.c +28 -0
index 35a47581c..1f5f7cfcd 100644
@@ -327,6 +327,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;
@@ -479,6 +506,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.42.0
#62 lore raw

PATCH 28/32 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               | 337 ++++++++++++++++++++++++++++++++++++
 powerpc/unittests.cfg       |   3 +
 7 files changed, 377 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 30b988a5c..42ba06ad1 100644
@@ -32,6 +32,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;
@@ -41,6 +42,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)
@@ -94,6 +96,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;
 	}
 }
@@ -102,6 +120,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 */
@@ -118,12 +138,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:
@@ -132,6 +154,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 410a675d9..64a3d93e4 100644
@@ -17,7 +17,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)/pmu.elf
 
 tests-all = $(tests-common) $(tests)
 all: directories $(TEST_DIR)/boot_rom.bin $(tests-all)
powerpc/pmu.c new file +337 -0

337 lines not on this page · raw message

powerpc/unittests.cfg +3 -0
index 008559b43..e275f389b 100644
@@ -89,6 +89,9 @@ file = emulator.elf
 [interrupts]
 file = interrupts.elf
 
+[pmu]
+file = pmu.elf
+
 [smp]
 file = smp.elf
 smp = 2
Signature · 1 line
2.42.0
#63 lore raw

PATCH 29/32 configure: Fail on unknown arch

In reply to Nicholas Piggin

configure will accept an unknown arch, and if it is the name of a directory in the source tree the command will silently succeed. Make it only accept supported arch names.

Also print the full path of a missing test directory to disambiguate the error in out of tree builds.

Cc Alexandru Elisei <[email protected]>
Cc Andrew Jones <[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
---
 configure | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
configure +8 -3
index 6907ccbbb..ae522c556 100755
@@ -45,7 +45,8 @@ usage() {
 	Usage: $0 [options]
 
 	Options include:
-	    --arch=ARCH            architecture to compile for ($arch)
+	    --arch=ARCH            architecture to compile for ($arch). ARCH can be one of:
+	                           arm, arm64, i386, ppc64, riscv32, riscv64, s390x, x86_64
 	    --processor=PROCESSOR  processor to compile for ($arch)
 	    --target=TARGET        target platform that the tests will be running on (qemu or
 	                           kvmtool, default is qemu) (arm/arm64 only)
@@ -321,11 +322,15 @@ elif [ "$arch" = "ppc64" ]; then
 elif [ "$arch" = "riscv32" ] || [ "$arch" = "riscv64" ]; then
     testdir=riscv
     arch_libdir=riscv
+elif [ "$arch" = "s390x" ]; then
+    testdir=s390x
 else
-    testdir=$arch
+    echo "arch $arch is not supported!"
+    arch=
+    usage
 fi
 if [ ! -d "$srcdir/$testdir" ]; then
-    echo "$testdir does not exist!"
+    echo "$srcdir/$testdir does not exist!"
     exit 1
 fi
 
Signature · 1 line
2.42.0
Reviewed-by on v1 29/32
#64 lore raw

Re: [kvm-unit-tests PATCH 29/32] configure: Fail on unknown arch

Quoted 62 lines · Nicholas Piggin

configure will accept an unknown arch, and if it is the name of a directory in the source tree the command will silently succeed. Make it only accept supported arch names.

Also print the full path of a missing test directory to disambiguate the error in out of tree builds.

Cc Alexandru Elisei <[email protected]>
Cc Andrew Jones <[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
---
 configure | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
configure +8 -3
index 6907ccbbb..ae522c556 100755
@@ -45,7 +45,8 @@ usage() {
 	Usage: $0 [options]
 
 	Options include:
-	    --arch=ARCH            architecture to compile for ($arch)
+	    --arch=ARCH            architecture to compile for ($arch). ARCH can be one of:
+	                           arm, arm64, i386, ppc64, riscv32, riscv64, s390x, x86_64
 	    --processor=PROCESSOR  processor to compile for ($arch)
 	    --target=TARGET        target platform that the tests will be running on (qemu or
 	                           kvmtool, default is qemu) (arm/arm64 only)
@@ -321,11 +322,15 @@ elif [ "$arch" = "ppc64" ]; then
 elif [ "$arch" = "riscv32" ] || [ "$arch" = "riscv64" ]; then
     testdir=riscv
     arch_libdir=riscv
+elif [ "$arch" = "s390x" ]; then
+    testdir=s390x
 else
-    testdir=$arch
+    echo "arch $arch is not supported!"
+    arch=
+    usage
 fi
 if [ ! -d "$srcdir/$testdir" ]; then
-    echo "$testdir does not exist!"
+    echo "$srcdir/$testdir does not exist!"
     exit 1
 fi
 
Signature · 1 line
2.42.0
#65 lore raw

PATCH 30/32 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 Andrew Jones <[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 4f35fffc6..4e0f54543 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 ae522c556..8c0e3506f 100755
@@ -199,7 +199,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"
@@ -264,8 +263,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
@@ -314,6 +315,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)!"
@@ -324,6 +326,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=
@@ -333,6 +336,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
@@ -395,10 +402,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.42.0
Reviewed-by on v1 30/32
#66 lore raw

Re: [kvm-unit-tests PATCH 30/32] configure: Make arch_libdir a first-class entity

Quoted 74 lines · 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 Andrew Jones <[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 4f35fffc6..4e0f54543 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 +3 -1
index ae522c556..8c0e3506f 100755
@@ -199,7 +199,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"
@@ -264,8 +263,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
@@ -314,6 +315,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)!"

configure elif [ "$arch" = "riscv32" ] || [ "$arch" = "riscv64" ]; then · line 329

Quoted 4 lines
configure +1 -0
@@ -324,6 +326,7 @@ elif [ "$arch" = "riscv32" ] || [ "$arch" = "riscv64" ]; then
     arch_libdir=riscv
 elif [ "$arch" = "s390x" ]; then
     testdir=s390x
+    arch_libdir=s390x

Probably could have left the arch_libdir=$arch above and only added the ppc64 line, but either way.

Quoted 34 lines
configure +9 -4
 else
     echo "arch $arch is not supported!"
     arch=
@@ -333,6 +336,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
@@ -395,10 +402,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.42.0

Thanks,
drew

#67 lore raw

PATCH 31/32 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                           | 111 ++++++++++++++++++++-
 powerpc/Makefile.common                    |  95 ------------------
 powerpc/Makefile.ppc64                     |  31 ------
 35 files changed, 136 insertions(+), 176 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 8c0e3506f..2dbc101cb 100755
@@ -198,6 +198,7 @@ fi
 
 arch_name=$arch
 [ "$arch" = "aarch64" ] && arch="arm64"
+[ "$arch" = "powerpc" ] && arch="ppc64"
 [ "$arch_name" = "arm64" ] && arch_name="aarch64"
 
 if [ "$arch" = "riscv" ]; then
@@ -315,7 +316,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 95d5131cc..85292f738 100644
@@ -1,5 +1,5 @@
-#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.
@@ -63,4 +63,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 6b20eaf09..fce62b89a 100644
@@ -1,5 +1,5 @@
-#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]>
  *
@@ -64,4 +64,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 c8a081543..7e49de59d 100644
@@ -123,4 +123,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 +110 -1

111 lines not on this page · raw message

powerpc/Makefile.common deleted +0 -95

95 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.42.0
#68 lore raw

PATCH 32/32 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.

---
 .gitlab-ci.yml        | 16 ++++++----------
 powerpc/unittests.cfg | 15 ++++++++-------
 2 files changed, 14 insertions(+), 17 deletions(-)
.gitlab-ci.yml +6 -10
index 61f196d5d..51a593021 100644
@@ -69,11 +69,9 @@ 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
+ - ACCEL=tcg MAX_SMP=8 ./run_tests.sh -g gitlab-ci | tee results.txt
+ - if grep -q FAIL results.txt ; then exit 1 ; fi
+ - ACCEL=tcg MAX_SMP=8 MACHINE=powernv ./run_tests.sh -g gitlab-ci | tee results.txt
  - if grep -q FAIL results.txt ; then exit 1 ; fi
 
 build-ppc64le:
@@ -82,11 +80,9 @@ 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
+ - ACCEL=tcg MAX_SMP=8 ./run_tests.sh -g gitlab-ci | tee results.txt
+ - if grep -q FAIL results.txt ; then exit 1 ; fi
+ - ACCEL=tcg MAX_SMP=8 MACHINE=powernv ./run_tests.sh -g gitlab-ci | tee results.txt
  - if grep -q FAIL results.txt ; then exit 1 ; fi
 
 # build-riscv32:
powerpc/unittests.cfg +8 -7
index e275f389b..21071a1a1 100644
@@ -34,17 +34,17 @@
 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
+groups = selftest migration gitlab-ci
 
 [selftest-migration-skip]
 file = selftest-migration.elf
 machine = pseries
-groups = selftest migration
+groups = selftest migration gitlab-ci
 extra_params = -append "skip"
 
 # This fails due to a QEMU TCG bug so KVM-only until QEMU is fixed upstream
@@ -56,7 +56,7 @@ groups = migration
 
 [spapr_hcall]
 file = spapr_hcall.elf
-machine = pseries
+machine = pseries gitlab-ci
 
 [spapr_vpa]
 file = spapr_vpa.elf
@@ -67,24 +67,25 @@ 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
 
 [interrupts]
 file = interrupts.elf
Signature · 1 line
2.42.0
#69 lore raw

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

Quoted 32 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.

---
 .gitlab-ci.yml        | 16 ++++++----------
 powerpc/unittests.cfg | 15 ++++++++-------
 2 files changed, 14 insertions(+), 17 deletions(-)
.gitlab-ci.yml +3 -5
index 61f196d5d..51a593021 100644
@@ -69,11 +69,9 @@ 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
+ - ACCEL=tcg MAX_SMP=8 ./run_tests.sh -g gitlab-ci | tee results.txt
+ - if grep -q FAIL results.txt ; then exit 1 ; fi
+ - ACCEL=tcg MAX_SMP=8 MACHINE=powernv ./run_tests.sh -g gitlab-ci | tee results.txt
  - if grep -q FAIL results.txt ; then exit 1 ; fi
 
 build-ppc64le:
@@ -82,11 +80,9 @@ 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

.gitlab-ci.yml build-ppc64le: · line 87

Quoted 10 lines
.gitlab-ci.yml +3 -5
- - 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
+ - ACCEL=tcg MAX_SMP=8 ./run_tests.sh -g gitlab-ci | tee results.txt
+ - if grep -q FAIL results.txt ; then exit 1 ; fi
+ - ACCEL=tcg MAX_SMP=8 MACHINE=powernv ./run_tests.sh -g gitlab-ci | tee results.txt
  - if grep -q FAIL results.txt ; then exit 1 ; fi
 

We're slowly migrating all tests like these to

grep -q PASS results.txt && ! grep -q FAIL results.txt

Here's a good opportunity to change ppc's.

Thanks,
drew

#70 lore raw

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

Quoted 46 lines · Andrew Jones
Quoted 32 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.

---
 .gitlab-ci.yml        | 16 ++++++----------
 powerpc/unittests.cfg | 15 ++++++++-------
 2 files changed, 14 insertions(+), 17 deletions(-)
.gitlab-ci.yml +3 -5
index 61f196d5d..51a593021 100644
@@ -69,11 +69,9 @@ 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
+ - ACCEL=tcg MAX_SMP=8 ./run_tests.sh -g gitlab-ci | tee results.txt
+ - if grep -q FAIL results.txt ; then exit 1 ; fi
+ - ACCEL=tcg MAX_SMP=8 MACHINE=powernv ./run_tests.sh -g gitlab-ci | tee results.txt
  - if grep -q FAIL results.txt ; then exit 1 ; fi
 
 build-ppc64le:
@@ -82,11 +80,9 @@ 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

.gitlab-ci.yml build-ppc64le: · line 87

Quoted 10 lines
.gitlab-ci.yml +3 -5
- - 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
+ - ACCEL=tcg MAX_SMP=8 ./run_tests.sh -g gitlab-ci | tee results.txt
+ - if grep -q FAIL results.txt ; then exit 1 ; fi
+ - ACCEL=tcg MAX_SMP=8 MACHINE=powernv ./run_tests.sh -g gitlab-ci | tee results.txt
  - if grep -q FAIL results.txt ; then exit 1 ; fi
 

We're slowly migrating all tests like these to

Quoted 3 lines

grep -q PASS results.txt && ! grep -q FAIL results.txt

Here's a good opportunity to change ppc's.

Sure, I'll do that.

Thanks,
Nick